Skip to content

Commit db41898

Browse files
committed
Implement the trampoline intrinsics for AIX.
We can expand the init intrinsic to create a descriptor for the nested procedure by combining the entry point and TOC pointer from the global descriptor with the nest argument. The normal indirect call sequence then calls the nested procedure through the descriptor like all other calls.
1 parent 163da87 commit db41898

File tree

3 files changed

+94
-16
lines changed

3 files changed

+94
-16
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,9 +3926,6 @@ SDValue PPCTargetLowering::LowerVACOPY(SDValue Op, SelectionDAG &DAG) const {
39263926

39273927
SDValue PPCTargetLowering::LowerADJUST_TRAMPOLINE(SDValue Op,
39283928
SelectionDAG &DAG) const {
3929-
if (Subtarget.isAIXABI())
3930-
report_fatal_error("ADJUST_TRAMPOLINE operation is not supported on AIX.");
3931-
39323929
return Op.getOperand(0);
39333930
}
39343931

@@ -3985,16 +3982,73 @@ SDValue PPCTargetLowering::LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const {
39853982

39863983
SDValue PPCTargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
39873984
SelectionDAG &DAG) const {
3988-
if (Subtarget.isAIXABI())
3989-
report_fatal_error("INIT_TRAMPOLINE operation is not supported on AIX.");
3990-
39913985
SDValue Chain = Op.getOperand(0);
39923986
SDValue Trmp = Op.getOperand(1); // trampoline
39933987
SDValue FPtr = Op.getOperand(2); // nested function
39943988
SDValue Nest = Op.getOperand(3); // 'nest' parameter value
39953989
SDLoc dl(Op);
39963990

39973991
EVT PtrVT = getPointerTy(DAG.getDataLayout());
3992+
3993+
if (Subtarget.isAIXABI()) {
3994+
// On AIX we create a trampoline descriptor by combining the
3995+
// entry point and TOC from the global descriptor (FPtr) with the
3996+
// nest argument as the environement pointer.
3997+
uint64_t PointerSize = Subtarget.isPPC64() ? 8 : 4;
3998+
MaybeAlign PointerAlign(PointerSize);
3999+
auto MMOFlags = Subtarget.hasInvariantFunctionDescriptors()
4000+
? (MachineMemOperand::MODereferenceable |
4001+
MachineMemOperand::MOInvariant)
4002+
: MachineMemOperand::MONone;
4003+
4004+
uint64_t TOCPointerOffset = 1 * PointerSize;
4005+
uint64_t EnvPointerOffset = 2 * PointerSize;
4006+
SDValue SDTOCPtrOffset = DAG.getConstant(TOCPointerOffset, dl, PtrVT);
4007+
SDValue SDEnvPtrOffset = DAG.getConstant(EnvPointerOffset, dl, PtrVT);
4008+
4009+
const Value *TrampolineAddr =
4010+
cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
4011+
const Function *Func =
4012+
cast<Function>(cast<SrcValueSDNode>(Op.getOperand(5))->getValue());
4013+
4014+
SDValue OutChains[3];
4015+
4016+
// Copy the entry point address from the global descriptor to the
4017+
// trampoline buffer.
4018+
SDValue LoadEntryPoint =
4019+
DAG.getLoad(PtrVT, dl, Chain, FPtr, MachinePointerInfo(Func, 0),
4020+
PointerAlign, MMOFlags);
4021+
SDValue EPLoadChain = LoadEntryPoint.getValue(1);
4022+
OutChains[0] = DAG.getStore(EPLoadChain, dl, LoadEntryPoint, Trmp,
4023+
MachinePointerInfo(TrampolineAddr, 0));
4024+
4025+
// Copy the TOC pointer from the global descriptor to the trampoline
4026+
// buffer.
4027+
SDValue TOCFromDescriptorPtr =
4028+
DAG.getNode(ISD::ADD, dl, PtrVT, FPtr, SDTOCPtrOffset);
4029+
SDValue TOCReg = DAG.getLoad(PtrVT, dl, Chain, TOCFromDescriptorPtr,
4030+
MachinePointerInfo(Func, TOCPointerOffset),
4031+
PointerAlign, MMOFlags);
4032+
SDValue TrampolineTOCPointer =
4033+
DAG.getNode(ISD::ADD, dl, PtrVT, Trmp, SDTOCPtrOffset);
4034+
SDValue TOCLoadChain = TOCReg.getValue(1);
4035+
OutChains[1] =
4036+
DAG.getStore(TOCLoadChain, dl, TOCReg, TrampolineTOCPointer,
4037+
MachinePointerInfo(TrampolineAddr, TOCPointerOffset));
4038+
4039+
// Store the nest argument into the enviroment pointer in the trampoline
4040+
// buffer.
4041+
SDValue EnvPointer =
4042+
DAG.getNode(ISD::ADD, dl, PtrVT, Trmp, SDEnvPtrOffset);
4043+
OutChains[2] =
4044+
DAG.getStore(Chain, dl, Nest, EnvPointer,
4045+
MachinePointerInfo(TrampolineAddr, EnvPointerOffset));
4046+
4047+
SDValue TokenFactor =
4048+
DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
4049+
return TokenFactor;
4050+
}
4051+
39984052
bool isPPC64 = (PtrVT == MVT::i64);
39994053
Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(*DAG.getContext());
40004054

@@ -6866,9 +6920,6 @@ static bool CC_AIX(unsigned ValNo, MVT ValVT, MVT LocVT,
68666920
if (ValVT == MVT::f128)
68676921
report_fatal_error("f128 is unimplemented on AIX.");
68686922

6869-
if (ArgFlags.isNest())
6870-
report_fatal_error("Nest arguments are unimplemented.");
6871-
68726923
static const MCPhysReg GPR_32[] = {// 32-bit registers.
68736924
PPC::R3, PPC::R4, PPC::R5, PPC::R6,
68746925
PPC::R7, PPC::R8, PPC::R9, PPC::R10};
@@ -6883,6 +6934,14 @@ static bool CC_AIX(unsigned ValNo, MVT ValVT, MVT LocVT,
68836934

68846935
const ArrayRef<MCPhysReg> GPRs = IsPPC64 ? GPR_64 : GPR_32;
68856936

6937+
if (ArgFlags.isNest()) {
6938+
MCRegister EnvReg = State.AllocateReg(IsPPC64 ? PPC::X11 : PPC::R11);
6939+
if (!EnvReg)
6940+
report_fatal_error("More then one nest argument.");
6941+
State.addLoc(CCValAssign::getReg(ValNo, ValVT, EnvReg, RegVT, LocInfo));
6942+
return false;
6943+
}
6944+
68866945
if (ArgFlags.isByVal()) {
68876946
const Align ByValAlign(ArgFlags.getNonZeroByValAlign());
68886947
if (ByValAlign > StackAlign)
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: not --crash llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
2-
; RUN: not --crash llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
1+
; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
2+
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
33

44
define ptr @nest_receiver(ptr nest %arg) nounwind {
55
ret ptr %arg
@@ -9,5 +9,10 @@ define ptr @nest_caller(ptr %arg) nounwind {
99
%result = call ptr @nest_receiver(ptr nest %arg)
1010
ret ptr %result
1111
}
12+
; CHECK-LABEL: .nest_receiver:
13+
; CHECK: mr 3, 11
14+
; CHECK: blr
1215

13-
; CHECK: LLVM ERROR: Nest arguments are unimplemented.
16+
; CHECK-LABEL: .nest_caller:
17+
; CHECK: mr 11, 3
18+
; CHECK: bl .nest_receiver
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
; RUN: not --crash llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
2-
; RUN: not --crash llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
3-
4-
; CHECK: LLVM ERROR: INIT_TRAMPOLINE operation is not supported on AIX.
1+
; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | \
2+
; RUN: FileCheck %s --check-prefix=32BIT
3+
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 -mattr=-altivec | \
4+
; RUN: FileCheck %s --check-prefix=64BIT
55

66
define void @create_trampoline(ptr %buffer, ptr %nval) nounwind {
77
entry:
@@ -12,3 +12,17 @@ entry:
1212
declare i32 @nested(i32);
1313

1414
declare void @llvm.init.trampoline(ptr, ptr, ptr) nounwind
15+
16+
; 32BIT: stw 4, 8(3)
17+
; 32BIT: lwz [[FuncDesc:[0-9]+]], L..C0(2)
18+
; 32BIT-DAG: lwz [[SCRATCH1:[0-9]+]], 0([[FuncDesc]])
19+
; 32BIT-DAG: lwz [[SCRATCH2:[0-9]+]], 4([[FuncDesc]])
20+
; 32BIT-DAG: stw [[SCRATCH1]], 0(3)
21+
; 32BIT-DAG: stw [[SCRATCH2]], 4(3)
22+
23+
; 64BIT: std 4, 16(3)
24+
; 64BIT-DAG: ld [[FuncDesc:[0-9]+]], L..C0(2)
25+
; 64BIT-DAG: ld [[SCRATCH1:[0-9]+]], 0([[FuncDesc]])
26+
; 64BIT-DAG: ld [[SCRATCH2:[0-9]+]], 8([[FuncDesc]])
27+
; 64BIT-DAG: std [[SCRATCH1]], 0(3)
28+
; 64BIT-DAG: std [[SCRATCH2]], 8(3)

0 commit comments

Comments
 (0)