`llvm.add` is interpreted as `llvm.addrspacecast`
This feels like it's not working correctly, considering add is documented as something else.
62 Replies
Can you share the actual docs on LLVM dialect for this Op?
I also find that the translation between Mojo syntax to dialect is a black box to us
For eg the index.casts index.castu syntax are different from Mojo's
this is why they're different
both llvm and index dialects are off by one
at least that's what it looks like :D
well, sometimes
Congrats @TeamPuzel, you just advanced to level 13!
it seems like you have to use the one before what you actually want
'llvm' Dialect - MLIR
Multi-Level IR Compiler Framework
it's the second one
whichever one I use mojo seems to take the next
This is quite funny. On my machine, I can't seem to use anything from the llvm dialect (and haven't tried to before), it can't find the llvm.add and other __mlir_ops, but the index dialect works fine and isn't one off as yours seems to be. For example, I can run the following, and it prints
64
:
Okay, now I get the same one-off error with llvm dialect. Strange.
(just in case, my mojo --version is mojo 0.2.1 (64d14e85)
)odd, I have the exact same version
Not all of them are one off which makes it even more weird to me
Though if I actually try to use llvm.ashr (which I assume must be add for me) it gives me an
add
error!First my LSP says that llvm.add is unregistered, then running it in console says llvm.addrspacecast wants a single operand.
Yeah, I'm using ssh into a linux laptop with too little ram to handle the lsp so I don't even see those :D
if you use ashr you will get add
On my end it crashes if I replace add with ashr
🤷♂️
unfortunately trying to add i32 in this way crashes llvm
Yep lol
(Yeah if you pass wrong arguments the error message says add)
maybe just the error checking is off and it's actually still trying to use the correct operation
For some reason, it seems to work fine in the REPL.
huh
Well everything I was planning on writing is now impossible until this is fixed :(
rebind doesn't want to work for me with the built in UInt8 alias
which makes ffi with C very painful
I think you should use the pop dialect for now. It looks like Mojo will lower the pop dialect down to llvm at least in some cases, and it has the add operation you want
Wait, it doesn't seem to support i32
Darn it
I think only index and llvm are supported right now and only llvm can handle differently sized numbers (and floats)
I'm curious how floats are implemented by the standard library if this doesn't work
pop, kgen, and lit are the internal dialects Mojo uses
Do they show up in the lsp?
The LSP doesn't annotate like the inside of `` for all __mlir_things, you just get a normal error
I think I've seen those in some error messages before
From what I've seen, pop is where a lot of this scalar stuff happens, along with more basic types. kgen is where more complex types reside, along with some language specific things. lit is for constructing and dealing with things that act like structs as mlir attrs
There actually is one more dialect, hlcf, but it looks like it's for the language itself. Like there are hlcf.if and hlcf.for ops
hm that's interesting, are they going to be documented at some point?
No idea, I've just been going through a lot of trial and error
Should I report the llvm dialect bug on github too?
I guess so
I opened an issue now
do you get code completion on kgen ? could you share a snippet please @Stole @TeamPuzel i'd like to play too
I do not get code completion for anything, the lsp is broken for me
very interesting discussion here
loving it
very useful comment
i cannot actually find the lit dialect
probably not documented but its mojo's internal
@TeamPuzel you have any lots of
lit
dialect etc?what do you mean?
No, there is no code completion while you're typing inside any __mlir_thing
I had to do this for now, seems to be adding correctly
It technically works but it looks really bad:
I'm not sure if this would get optimised, but either way it's going to be very hard to read once it has all of the methods.
And then I need to copy and paste this for every type :/
at least the alias will help
Yeah, just doing the adding through index isn't ideal
hello
for llvm it is var f = intrinsics.llvm_intrinsic"llvm.cos.f64",Float64
intrinsics?
can you show us the full codes so we can study it deeply? @rd4com
did u try if it correctly rejects compile time values that are not UInt8 eg
alias my_int = 256
?
it should reject as 256 > 255yes sorry you need import sys.intrinsics
import sys.intrinsics
var f = intrinsics.llvm_intrinsic["llvm.cos.f64",Float64](1.4)
so this is doing cosine(1.4)?
yes, i just try to figure out where are all the intrinsic we could use
I didn’t add any checks I just let it wrap around
Huh, is that intended?
Aren’t those actual llvm intrinsics as opposed to mlir
Or am I missing something
But if that works I guess that’s cool 😄
I will have to write a constructor to convert between different numbers for every possible combination 😨
yes u must check and also, there is no known way to raise compile time error
If there's no way to compile error it will have to wrap :/
you can use raise in @parameter if loop no
Is this what you're looking for?
🙂
GitHub
[BUG]: Unable to convert a MLIR type to another MLIR type at compil...
Bug description I am attempting to create my own UInt8 following the tutorial on Mojo's documentation on the creation of a new boolean. Below is my implementation: @register_passable('trivi...
i created an issue
GitHub
mojo-learning/FFI shared libraries load and use at main · rd4com/mo...
Learn some mojo. Contribute to rd4com/mojo-learning development by creating an account on GitHub.
I'm just wondering, did you try
@parameter if
as well?
Error:
Oh, I did forget that you're using a mlir op here, which isn't going to be done at compile time. I'll see if I can find a mlir attr that does the comparing work, but yeah this might not be possible
There's a lot else here that isn't compile time as well
I mean, @JIMC, do you really need to use MLIR here? Is that a requirement of yours?
because things would be much simpler if you just didn't use MLIR here TBH
I don't think there's a way to cast between integer types like i1, ui8, etc. at compile time through MLIR
At least if there is, it's ultra obscure, and not documented at all if it's part of Mojo's dialects
it is certainly very possible and a requirement to be able to cast an index to ui8.
think about blockchain address that are exactly 20 bytes. many languages like rust, allows for dev to create types that are exactly 20 bytes and checks them at compile time
You can cast values between ui8 and index fine, but they're mlir ops and that happens at runtime right now, not at compile time
no MLIR ops are supposed and can happen at compile time
have u read up on MLIR?
How do you call that op at compile time in Mojo?
It seems like every
__mlir_op
call is interpreted as dynamicno, it is not interpreted as dynamic, it is a bug at the mlir level that the foldr optimization is not working for index type
you can check out the issue i raised
and if you do alias A: U8 = 4; you will see #lit.value{4} being passed into the constructor
Still broken after the new update 😔
oh theres a new update?