Skip to content

Commit 6583921

Browse files
committed
[MLIR][ControlFlowToSCF] Extend with support for FuncOpInterface
This commit ensures that the pass to lift from `cf` to `scf` can be applied on all operations that implement `FuncOpInterface`.
1 parent 42ed775 commit 6583921

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

mlir/lib/Conversion/ControlFlowToSCF/ControlFlowToSCF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ struct LiftControlFlowToSCF
164164

165165
bool changed = false;
166166
Operation *op = getOperation();
167-
WalkResult result = op->walk([&](func::FuncOp funcOp) {
168-
if (funcOp.getBody().empty())
167+
WalkResult result = op->walk([&](FunctionOpInterface funcOp) {
168+
if (funcOp.getFunctionBody().empty())
169169
return WalkResult::advance();
170170

171171
auto &domInfo = funcOp != op ? getChildAnalysis<DominanceInfo>(funcOp)

mlir/test/Conversion/ControlFlowToSCF/test.mlir

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,29 @@ func.func @nested_region_outside_loop_use() {
756756

757757
// CHECK: scf.execute_region
758758
// CHECK-NEXT: "test.foo"(%[[RES]])
759+
760+
// -----
761+
762+
llvm.func @llvm_func() {
763+
%cond = "test.test1"() : () -> i1
764+
cf.cond_br %cond, ^bb1, ^bb2
765+
^bb1:
766+
"test.test2"() : () -> ()
767+
cf.br ^bb3
768+
^bb2:
769+
"test.test3"() : () -> ()
770+
cf.br ^bb3
771+
^bb3:
772+
"test.test4"() : () -> ()
773+
return
774+
}
775+
776+
// CHECK-LABEL: llvm.func @llvm_func
777+
// CHECK: %[[COND:.*]] = "test.test1"()
778+
// CHECK-NEXT: scf.if %[[COND]]
779+
// CHECK-NEXT: "test.test2"()
780+
// CHECK-NEXT: else
781+
// CHECK-NEXT: "test.test3"()
782+
// CHECK-NEXT: }
783+
// CHECK-NEXT: "test.test4"()
784+
// CHECK-NEXT: return

0 commit comments

Comments
 (0)