Hi folks,
I’m struggling to get the right way to convert types of the block arguments when using the lowering infra.
Let’s say I have a simple dialect with three ops (value, branch, and return), e.g.:
module @a_module {
func @f() -> !foo.foo_value {
%0 = "foo.value"() : () -> !foo.foo_value
"foo.br"(%0)[^bb1] : (!foo.foo_value) -> ()
^bb1(%1: !foo.foo_value): // pred: ^bb0
%2 = "foo.return"(%1) : (!foo.foo_value) -> !foo.foo_value
}
}
Then I lower it to std dialect via direct mapping (foo.value -> std.constant i8
, foo.branch -> std.br
, foo.return -> std.return
), e.g.:
module @a_module {
func @f() -> !foo.foo_value {
%c42_i8 = constant 42 : i8
br ^bb1(%c42_i8 : i8)
^bb1(%0: !foo.foo_value): // pred: ^bb0
%1 = "foo.return"(%0) : (!foo.foo_value) -> !foo.foo_value
}
}
It almost works except the bb1
argument and @f
return types are not converted.
AIUI, I should be calling convertRegionTypes
somewhere in the lowering pipeline.
The issue is that I don’t quite understand when should I call it?
I tried to call it from foo.branch
lowering, but it (expectedly) breaks the IR as I modify things outside of the current operation.
I think the right place to call it would be in the context of std.FuncOp
, but I want to preserve the FuncOp
(i.e. it is a legal operation).
I also tried creating custom std.FuncOp
, but then I don’t see how to lower it into the std.FuncOp
Any hints would be highly appreciated as I’m pretty much stuck at this point
P.S. here is a sample in case it helps https://github.com/AlexDenisov/mlir-type-conversion