Skip to content

Commit 9aa0553

Browse files
committed
fix langref and Arm64EC CallingConvention
1 parent f6122fa commit 9aa0553

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

llvm/docs/LangRef.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20903,7 +20903,12 @@ sufficiently aligned block of memory; this memory is written to by the
2090320903
intrinsic. Note that the size and the alignment are target-specific -
2090420904
LLVM currently provides no portable way of determining them, so a
2090520905
front-end that generates this intrinsic needs to have some
20906-
target-specific knowledge. The ``func`` argument must hold a function.
20906+
target-specific knowledge.
20907+
20908+
The ``func`` argument must be a constant (potentially bitcasted) pointer to a
20909+
function declaration or definition, since the calling convention may affect the
20910+
content of the trampoline that is created.
20911+
2090720912

2090820913
Semantics:
2090920914
""""""""""

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7302,28 +7302,42 @@ SDValue AArch64TargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
73027302

73037303
const Value *TrmpAddr = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
73047304

7305-
// ldr x15, .+16
7305+
// ldr NestReg, .+16
73067306
// ldr x17, .+20
73077307
// br x17
7308-
// 0
7308+
// .word 0
73097309
// .nest: .qword nest
73107310
// .fptr: .qword fptr
73117311
SDValue OutChains[5];
73127312

7313-
const char X15 = 0x0f;
7314-
const char X17 = 0x11;
7313+
const Function *Func =
7314+
cast<Function>(cast<SrcValueSDNode>(Op.getOperand(5))->getValue());
7315+
CallingConv::ID CC = Func->getCallingConv();
7316+
unsigned NestReg;
7317+
7318+
switch (CC) {
7319+
default:
7320+
NestReg = 0x0f; // X15
7321+
case CallingConv::ARM64EC_Thunk_Native:
7322+
case CallingConv::ARM64EC_Thunk_X64:
7323+
// Must be kept in sync with AArch64CallingConv.td
7324+
NestReg = 0x04; // X4
7325+
break;
7326+
}
7327+
7328+
const char FptrReg = 0x11; // X17
73157329

73167330
SDValue Addr = Trmp;
73177331

73187332
SDLoc dl(Op);
73197333
OutChains[0] =
7320-
DAG.getStore(Chain, dl, DAG.getConstant(0x58000080u | X15, dl, MVT::i32), Addr,
7334+
DAG.getStore(Chain, dl, DAG.getConstant(0x58000080u | NestReg, dl, MVT::i32), Addr,
73217335
MachinePointerInfo(TrmpAddr));
73227336

73237337
Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,
73247338
DAG.getConstant(4, dl, MVT::i64));
73257339
OutChains[1] =
7326-
DAG.getStore(Chain, dl, DAG.getConstant(0x580000b0u | X17, dl, MVT::i32), Addr,
7340+
DAG.getStore(Chain, dl, DAG.getConstant(0x580000b0u | FptrReg, dl, MVT::i32), Addr,
73277341
MachinePointerInfo(TrmpAddr, 4));
73287342

73297343
Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp,

llvm/lib/TargetParser/Triple.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,6 @@ unsigned Triple::getTrampolineSize() const {
17251725
if (isOSLinux())
17261726
return 48;
17271727
break;
1728-
case Triple::aarch64:
1729-
return 36;
17301728
}
17311729
return 32;
17321730
}

0 commit comments

Comments
 (0)