Description
I was wondering if it would be a good idea to add lowering support of scf::IfOp
in createSCFToCalyxPass
.
createSCFToCalyxPass
claims to handle BranchOpInterface
but when it encounters a scf::YieldOp
it asserts if it's not scf::WhileOp
.
I've also tried using createConvertSCFToCFPass
to lower scf::IfOp
into cf
and it works well for scf::IfOp
, but the problem is that it also converts scf::WhileOp
into a cf::BranchOp
with back-edges, so createSCFToCalyxPass
fails with:
error: CFG backedge detected. Loops must be raised to 'scf.while' or 'scf.for' operations.
Therefore I think it's better to support scf::IfOp
directly.
Here's simple_arith_if.mlir
, a port of simple_arith.mlir to use scf::IfOp
instead of cf::CondBranchOp
, which can help test the lowering of scf::IfOp
when implemented:
func.func @main(%arg0 : i32, %arg1 : i32) -> i32 {
%0 = arith.cmpi slt, %arg0, %arg1 : i32
%1 = scf.if %0 -> i32 {
%3 = arith.addi %arg0, %arg1 : i32
scf.yield %3 : i32
} else {
scf.yield %arg1 : i32
}
return %1 : i32
}
(Thanks to @rachitnigam for the updated code.)
EDIT: You need to run the command:
./build/bin/circt-opt --lower-scf-to-calyx test.mlir
Activity