[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
This commit is contained in:
parent
7de3c03e80
commit
feb9d33a2a
|
@ -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
|
||||
|
||||
|
|
|
@ -253,6 +253,14 @@ public:
|
|||
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)) {
|
||||
|
|
|
@ -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>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user