[mlir] fix crash when scf utils work on llvm.func (#120688)

fixed https://github.com/llvm/llvm-project/issues/119378
This commit is contained in:
donald chen 2024-12-20 17:03:57 +08:00 committed by GitHub
parent 4472648998
commit 701f2409be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 1 deletions

View File

@ -130,7 +130,7 @@ FailureOr<func::FuncOp> mlir::outlineSingleBlockRegion(RewriterBase &rewriter,
// Outline before current function.
OpBuilder::InsertionGuard g(rewriter);
rewriter.setInsertionPoint(region.getParentOfType<func::FuncOp>());
rewriter.setInsertionPoint(region.getParentOfType<FunctionOpInterface>());
SetVector<Value> captures;
getUsedValuesDefinedAbove(region, captures);

View File

@ -73,3 +73,30 @@ func.func @outline_empty_if_else(%cond: i1, %a: index, %b: memref<?xf32>, %c: i8
}
return
}
// -----
// This test checks scf utils can work on llvm func.
// CHECK: func @outlined_then0() {
// CHECK-NEXT: return
// CHECK-NEXT: }
// CHECK: func @outlined_else0(%{{.*}}: i1, %{{.*}}: i32) {
// CHECK-NEXT: "some_op"(%{{.*}}, %{{.*}}) : (i1, i32) -> ()
// CHECK-NEXT: return
// CHECK-NEXT: }
// CHECK: llvm.func @llvm_func(%{{.*}}: i1, %{{.*}}: i32) {
// CHECK-NEXT: scf.if %{{.*}} {
// CHECK-NEXT: func.call @outlined_then0() : () -> ()
// CHECK-NEXT: } else {
// CHECK-NEXT: func.call @outlined_else0(%{{.*}}, %{{.*}}) : (i1, i32) -> ()
// CHECK-NEXT: }
// CHECK-NEXT: llvm.return
// CHECK-NEXT: }
llvm.func @llvm_func(%cond: i1, %a: i32) {
scf.if %cond {
} else {
"some_op"(%cond, %a) : (i1, i32) -> ()
}
llvm.return
}

View File

@ -79,6 +79,10 @@ struct TestSCFIfUtilsPass
StringRef getDescription() const final { return "test scf.if utils"; }
explicit TestSCFIfUtilsPass() = default;
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<func::FuncDialect>();
}
void runOnOperation() override {
int count = 0;
getOperation().walk([&](scf::IfOp ifOp) {