Skip to content

Commit 16e9601

Browse files
authored
[Flang] Adjust the trampoline size for AArch64 and PPC (#118678)
Set the trampoline size to match that in compiler-rt/lib/builtins/trampoline_setup.c and AArch64 and PPC lowering.
1 parent 178f471 commit 16e9601

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,18 @@ class BoxedProcedurePass
270270
// Create the thunk.
271271
auto module = embox->getParentOfType<mlir::ModuleOp>();
272272
FirOpBuilder builder(rewriter, module);
273+
const auto triple{fir::getTargetTriple(module)};
273274
auto loc = embox.getLoc();
274275
mlir::Type i8Ty = builder.getI8Type();
275276
mlir::Type i8Ptr = builder.getRefType(i8Ty);
276-
mlir::Type buffTy = SequenceType::get({32}, i8Ty);
277+
// For AArch64, PPC32 and PPC64, the thunk is populated by a call to
278+
// __trampoline_setup, which is defined in
279+
// compiler-rt/lib/builtins/trampoline_setup.c and requires the
280+
// thunk size greater than 32 bytes. For RISCV and x86_64, the
281+
// thunk setup doesn't go through __trampoline_setup and fits in 32
282+
// bytes.
283+
fir::SequenceType::Extent thunkSize = triple.getTrampolineSize();
284+
mlir::Type buffTy = SequenceType::get({thunkSize}, i8Ty);
277285
auto buffer = builder.create<AllocaOp>(loc, buffTy);
278286
mlir::Value closure =
279287
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

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ class Triple {
498498
return getArchPointerBitWidth(getArch());
499499
}
500500

501+
/// Returns the trampoline size in bytes for this configuration.
502+
unsigned getTrampolineSize() const;
503+
501504
/// Test whether the architecture is 64-bit
502505
///
503506
/// Note that this tests for 64-bit pointer width, and nothing else. Note

llvm/lib/TargetParser/Triple.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,26 @@ unsigned Triple::getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
17111711
llvm_unreachable("Invalid architecture value");
17121712
}
17131713

1714+
unsigned Triple::getTrampolineSize() const {
1715+
switch (getArch()) {
1716+
default:
1717+
break;
1718+
case Triple::ppc:
1719+
case Triple::ppcle:
1720+
if (isOSLinux())
1721+
return 40;
1722+
break;
1723+
case Triple::ppc64:
1724+
case Triple::ppc64le:
1725+
if (isOSLinux())
1726+
return 48;
1727+
break;
1728+
case Triple::aarch64:
1729+
return 36;
1730+
}
1731+
return 32;
1732+
}
1733+
17141734
bool Triple::isArch64Bit() const {
17151735
return getArchPointerBitWidth(getArch()) == 64;
17161736
}

0 commit comments

Comments
 (0)