Skip to content

Commit 68ec0b3

Browse files
committed
[Flang] Adjust the trampoline size for AArch64 and PPC
The trampoline size is 36 bytes for AArch64, 40 bytes for PPC32 and 48 bytes for PPC64. During AArch64 and PPC lowering, init.trampoline is lowered to a call to __trampoline_setup, with the corresponding trampoline sizes passed to it.
1 parent b9813ce commit 68ec0b3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,18 @@ class BoxedProcedurePass
272272
// Create the thunk.
273273
auto module = embox->getParentOfType<mlir::ModuleOp>();
274274
FirOpBuilder builder(rewriter, module);
275+
const auto triple{fir::getTargetTriple(builder.getModule())};
275276
auto loc = embox.getLoc();
276277
mlir::Type i8Ty = builder.getI8Type();
277278
mlir::Type i8Ptr = builder.getRefType(i8Ty);
278-
mlir::Type buffTy = SequenceType::get({32}, i8Ty);
279+
fir::SequenceType::Extent thunkSize = 32;
280+
if (triple.isPPC32())
281+
thunkSize = 40;
282+
else if (triple.isPPC64())
283+
thunkSize = 48;
284+
else if (triple.isAArch64())
285+
thunkSize = 36;
286+
mlir::Type buffTy = SequenceType::get({thunkSize}, i8Ty);
279287
auto buffer = builder.create<AllocaOp>(loc, buffTy);
280288
mlir::Value closure =
281289
builder.createConvert(loc, i8Ptr, embox.getHost());

flang/test/Fir/boxproc.fir

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
// RUN: tco %s | FileCheck %s
1+
// RUN: %if aarch64-registered-target %{tco --target=aarch64-unknown-linux-gnu %s | FileCheck %s --check-prefixes=CHECK,CHECK-AARCH64 %}
2+
// RUN: %if x86-registered-target %{tco --target=x86_64-unknown-linux-gnu %s | FileCheck %s --check-prefixes=CHECK,CHECK-X86 %}
3+
// RUN: %if powerpc-registered-target %{tco --target=powerpc64le-unknown-linux-gnu %s | FileCheck %s --check-prefixes=CHECK,CHECK-PPC %}
24

35
// CHECK-LABEL: define void @_QPtest_proc_dummy()
4-
// CHECK: %[[VAL_3:.*]] = alloca [32 x i8], i64 1, align 1
6+
// CHECK-AARCH64: %[[VAL_3:.*]] = alloca [36 x i8], i64 1, align 1
7+
// CHECK-X86: %[[VAL_3:.*]] = alloca [32 x i8], i64 1, align 1
8+
// CHECK-PPC: %[[VAL_3:.*]] = alloca [4{{[0-8]+}} x i8], i64 1, align 1
59
// CHECK: %[[VAL_1:.*]] = alloca { ptr }, i64 1, align 8
610
// CHECK: %[[VAL_0:.*]] = alloca i32, i64 1, align 4
711
// CHECK: %[[VAL_2:.*]] = getelementptr { ptr }, ptr %[[VAL_1]], i32 0, i32 0
@@ -59,7 +63,9 @@ func.func @_QPtest_proc_dummy_other(%arg0: !fir.boxproc<() -> ()>) {
5963
}
6064

6165
// CHECK-LABEL: define void @_QPtest_proc_dummy_char()
62-
// CHECK: %[[VAL_20:.*]] = alloca [32 x i8], i64 1, align 1
66+
// CHECK-AARCH64: %[[VAL_20:.*]] = alloca [36 x i8], i64 1, align 1
67+
// CHECK-X86: %[[VAL_20:.*]] = alloca [32 x i8], i64 1, align 1
68+
// CHECK-PPC: %[[VAL_20:.*]] = alloca [4{{[0-8]+}} x i8], i64 1, align 1
6369
// CHECK: %[[VAL_2:.*]] = alloca { { ptr, i64 } }, i64 1, align 8
6470
// CHECK: %[[VAL_1:.*]] = alloca [10 x i8], i64 1, align 1
6571
// CHECK: %[[VAL_0:.*]] = alloca [40 x i8], i64 1, align 1

0 commit comments

Comments
 (0)