[flang-commits] [flang] 08e4386 - [flang][fir] update block argument types in boxed-procedure pass (#77914)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 15 00:06:50 PST 2024
Author: jeanPerier
Date: 2024-01-15T09:06:46+01:00
New Revision: 08e4386a2c91befabab317498b50ffc326ff4eae
URL: https://github.com/llvm/llvm-project/commit/08e4386a2c91befabab317498b50ffc326ff4eae
DIFF: https://github.com/llvm/llvm-project/commit/08e4386a2c91befabab317498b50ffc326ff4eae.diff
LOG: [flang][fir] update block argument types in boxed-procedure pass (#77914)
The boxed-procedure pass is lowering the fir.boxproc type. Although this
is not common, this types may end-up as block arguments (or be part of
derived type that are block arguments).
Update the pass to update block argument types too.
Added:
Modified:
flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
flang/test/Fir/boxproc-2.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
index d4cc2b5732e4ca..24cf2f39fc9a09 100644
--- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
+++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
@@ -347,6 +347,19 @@ class BoxedProcedurePass
}
rewriter.finalizeRootUpdate(op);
}
+ // Ensure block arguments are updated if needed.
+ if (op->getNumRegions() != 0) {
+ rewriter.startRootUpdate(op);
+ for (mlir::Region ®ion : op->getRegions())
+ for (mlir::Block &block : region.getBlocks())
+ for (mlir::BlockArgument blockArg : block.getArguments())
+ if (typeConverter.needsConversion(blockArg.getType())) {
+ mlir::Type toTy =
+ typeConverter.convertType(blockArg.getType());
+ blockArg.setType(toTy);
+ }
+ rewriter.finalizeRootUpdate(op);
+ }
});
}
}
diff --git a/flang/test/Fir/boxproc-2.fir b/flang/test/Fir/boxproc-2.fir
index bd6595c2d9e97e..1550cddac5db9e 100644
--- a/flang/test/Fir/boxproc-2.fir
+++ b/flang/test/Fir/boxproc-2.fir
@@ -65,3 +65,32 @@ func.func @proc_pointer_global() {
// CHECK: %[[VAL_0:.*]] = fir.address_of(@ProcedurePointer) : !fir.ref<(!fir.ref<i32>) -> f32>
// CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<(!fir.ref<i32>) -> f32>
}
+
+func.func @block_arg_rewrite(%arg0: !fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>, %cdt : i1) {
+ cf.cond_br %cdt, ^bb1, ^bb2
+^bb1: // pred: ^bb0
+ cf.br ^bb3(%arg0 : !fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>)
+^bb2: // pred: ^bb0
+ %8 = fir.absent !fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>
+ cf.br ^bb3(%8 : !fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>)
+^bb3(%9: !fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>): // 2 preds: ^bb1, ^bb2
+ cf.br ^bb4
+^bb4: // pred: ^bb3
+ fir.call @dosomething(%9) : (!fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>) -> ()
+ return
+}
+// CHECK-LABEL: func.func @block_arg_rewrite(
+// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>,
+// CHECK-SAME: %[[VAL_1:.*]]: i1) {
+// CHECK: cf.cond_br %[[VAL_1]], ^bb1, ^bb2
+// CHECK: ^bb1:
+// CHECK: cf.br ^bb3(%[[VAL_0]] : !fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>)
+// CHECK: ^bb2:
+// CHECK: %[[VAL_2:.*]] = fir.absent !fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>
+// CHECK: cf.br ^bb3(%[[VAL_2]] : !fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>)
+// CHECK: ^bb3(%[[VAL_3:.*]]: !fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>):
+// CHECK: cf.br ^bb4
+// CHECK: ^bb4:
+// CHECK: fir.call @dosomething(%[[VAL_3]]) : (!fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>) -> ()
+
+func.func private @dosomething(!fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>)
More information about the flang-commits
mailing list