-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
segfault when printing conditional branch. #21
Comments
The segfault doesn't occur when I add return statements to each of the blocks, making it valid IR. |
Looking into this, the issue is here: because you pass Then the operands array which is we should probably check that Here is a working example: using Pkg
Pkg.activate(temp=true)
Pkg.add(path="https://github.com/JuliaLabs/MLIR.jl")
using MLIR
using MLIR: IR, API
using MLIR.Dialects: cf, arith, func
ctx = IR.Context()
IR.context!(ctx) do
loc = IR.Location()
mmod = IR.MModule(loc)
IR.get_or_load_dialect!("cf"); # necessary or not?
IR.get_or_load_dialect!("func"); # necessary or not?
condition = arith.constant(false)
entry = IR.Block()
push!(entry, condition)
a = arith.constant(2)
b = arith.constant(3)
push!(entry, a)
push!(entry, b)
trueDestOperands = IR.Value[IR.get_result(a)]
falseDestOperands = IR.Value[IR.get_result(b)]
reg = IR.Region()
toplevel = IR.get_body(mmod)
func_type = IR.MLIRType(IR.MLIRType[] => IR.MLIRType[])
trueDest = IR.Block([IR.MLIRType(Int)], [IR.Location()])
falseDest = IR.Block([IR.MLIRType(Int)], [IR.Location()])
push!(trueDest, func.return_([]))
push!(falseDest, func.return_([]))
push!(reg, entry)
push!(reg, trueDest)
push!(reg, falseDest)
sops = cf.cond_br(
IR.get_result(condition),
trueDest,
falseDest,
IR.Value[IR.get_result(a)],
IR.Value[IR.get_result(b)]
)
push!(entry, sops)
func_op = IR.create_operation(
"func.func", IR.Location();
attributes=[
IR.NamedAttribute("sym_name", IR.Attribute("foo")),
IR.NamedAttribute("function_type", IR.Attribute(func_type)),
],
owned_regions=IR.Region[reg],
result_inference=false,
)
push!(toplevel, func_op)
@show IR.verify(func_op) mmod
end
#=
IR.verify(func_op) = true
mmod = MModule:
module {
func.func @foo() {
%false = arith.constant false
%c2_i64 = arith.constant 2 : i64
%c3_i64 = arith.constant 3 : i64
cf.cond_br %false, ^bb1(%c2_i64 : i64), ^bb2(%c3_i64 : i64)
^bb1(%0: i64): // pred: ^bb0
return
^bb2(%1: i64): // pred: ^bb0
return
}
}
=# |
Hey Pangoraw, thanks for taking a look at this! I hadn't noticed I wasn't using the result at the time 😅. I've been working on this in the context of my Master's thesis. I've been using a combination of your dialect wrappers and those automatically generated from tablegen files. The tablegen ones are lower-level and much less polished but generate typed function signatures. e.g. here. Note that this wrapper generator still needs work. To start, |
We can close this since it would not happen with the new wrapper because of this explicit |
While testing the tblgen wrappers I encountered a segfault. I include a MWE using the
std
dialect to make it reproducible with the regular Julia release.I also get a segfault when creating the equivalent operation in
llvm
MLIR dialect, as well as when usingcf
instead ofstd
(with a more recent llvm version).My aim was to create something like:
@Pangoraw do you happen to know if this IR code is supposed to work or if I'm really creating invalid IR?
Either way, I think this shouldn't segfault, I've tried debugging but with little result...
MWE:
segfault:
The text was updated successfully, but these errors were encountered: