[flang-commits] [flang] feb9d33 - [flang] Support codegen for global procedure pointer
Peixin Qiao via flang-commits
flang-commits at lists.llvm.org
Wed Dec 7 05:25:31 PST 2022
Author: Peixin Qiao
Date: 2022-12-07T21:24:01+08:00
New Revision: feb9d33a2aa5f0bec98f4da5c4330e36ea59ce96
URL: https://github.com/llvm/llvm-project/commit/feb9d33a2aa5f0bec98f4da5c4330e36ea59ce96
DIFF: https://github.com/llvm/llvm-project/commit/feb9d33a2aa5f0bec98f4da5c4330e36ea59ce96.diff
LOG: [flang] Support codegen for global procedure pointer
This supports the codegen for global procedure pointer in BoxedProcedure
pass. Reset the boxproc type.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D138273
Added:
Modified:
flang/docs/ProcedurePointer.md
flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
flang/test/Fir/boxproc-2.fir
Removed:
################################################################################
diff --git a/flang/docs/ProcedurePointer.md b/flang/docs/ProcedurePointer.md
index cfa036b22fdf..b41c4003518e 100644
--- a/flang/docs/ProcedurePointer.md
+++ b/flang/docs/ProcedurePointer.md
@@ -470,7 +470,7 @@ Current list of TODOs in code generation:
NOTE: There are any number of possible implementations.
-- fir.global for procedure pointers
+BoxedProcedure pass
or
diff --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
index 8456c4a4b14b..4df4dcb2d02b 100644
--- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
+++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
@@ -253,6 +253,14 @@ class BoxedProcedurePass
rewriter.replaceOpWithNewOp<ConvertOp>(embox, toTy,
embox.getFunc());
}
+ } else if (auto global = mlir::dyn_cast<GlobalOp>(op)) {
+ auto ty = global.getType();
+ if (typeConverter.needsConversion(ty)) {
+ rewriter.startRootUpdate(global);
+ auto toTy = typeConverter.convertType(ty);
+ global.setType(toTy);
+ rewriter.finalizeRootUpdate(global);
+ }
} else if (auto mem = mlir::dyn_cast<AllocaOp>(op)) {
auto ty = mem.getType();
if (typeConverter.needsConversion(ty)) {
diff --git a/flang/test/Fir/boxproc-2.fir b/flang/test/Fir/boxproc-2.fir
index b9a11591e796..bd6595c2d9e9 100644
--- a/flang/test/Fir/boxproc-2.fir
+++ b/flang/test/Fir/boxproc-2.fir
@@ -44,3 +44,24 @@ func.func @proc_pointer_component(%arg0 : !fir.boxproc<(!fir.ref<i32>) -> f32>,
// CHECK: %[[VAL_11:.*]] = fir.call %[[VAL_10]](%[[VAL_1]]) : (!fir.ref<i32>) -> f32
}
+
+// CHECK-LABEL: fir.global internal @ProcedurePointer : (!fir.ref<i32>) -> f32 {
+fir.global internal @ProcedurePointer : !fir.boxproc<(!fir.ref<i32>) -> f32> {
+ %0 = fir.zero_bits (!fir.ref<i32>) -> f32
+ %1 = fir.emboxproc %0 : ((!fir.ref<i32>) -> f32) -> !fir.boxproc<(!fir.ref<i32>) -> f32>
+ fir.has_value %1 : !fir.boxproc<(!fir.ref<i32>) -> f32>
+
+// CHECK: %[[VAL_0:.*]] = fir.zero_bits (!fir.ref<i32>) -> f32
+// CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : ((!fir.ref<i32>) -> f32) -> ((!fir.ref<i32>) -> f32)
+// CHECK: fir.has_value %[[VAL_1]] : (!fir.ref<i32>) -> f32
+}
+
+// CHECK-LABEL: func.func @proc_pointer_global() {
+func.func @proc_pointer_global() {
+ %0 = fir.address_of(@ProcedurePointer) : !fir.ref<!fir.boxproc<(!fir.ref<i32>) -> f32>>
+ %1 = fir.load %0 : !fir.ref<!fir.boxproc<(!fir.ref<i32>) -> f32>>
+ return
+
+// 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>
+}
More information about the flang-commits
mailing list