Skip to content

Commit b52ea9d

Browse files
authored
Merge pull request #2750 from TNorthover/arm-swiftself-csr
ARM: mark swiftself register (r10) as caller saved for swifttailcc
2 parents 1e586f2 + bb57e73 commit b52ea9d

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
7979
return CSR_NoRegs_SaveList;
8080
} else if (F.getCallingConv() == CallingConv::CFGuard_Check) {
8181
return CSR_Win_AAPCS_CFGuard_Check_SaveList;
82+
} else if (F.getCallingConv() == CallingConv::SwiftTail) {
83+
return STI.isTargetDarwin()
84+
? CSR_iOS_SwiftTail_SaveList
85+
: (UseSplitPush ? CSR_AAPCS_SplitPush_SwiftTail_SaveList
86+
: CSR_AAPCS_SwiftTail_SaveList);
8287
} else if (F.hasFnAttribute("interrupt")) {
8388
if (STI.isMClass()) {
8489
// M-class CPUs have hardware which saves the registers needed to allow a
@@ -129,6 +134,10 @@ ARMBaseRegisterInfo::getCallPreservedMask(const MachineFunction &MF,
129134
return CSR_NoRegs_RegMask;
130135
if (CC == CallingConv::CFGuard_Check)
131136
return CSR_Win_AAPCS_CFGuard_Check_RegMask;
137+
if (CC == CallingConv::SwiftTail) {
138+
return STI.isTargetDarwin() ? CSR_iOS_SwiftTail_RegMask
139+
: CSR_AAPCS_SwiftTail_RegMask;
140+
}
132141
if (STI.getTargetLowering()->supportSwiftError() &&
133142
MF.getFunction().getAttributes().hasAttrSomewhere(Attribute::SwiftError))
134143
return STI.isTargetDarwin() ? CSR_iOS_SwiftError_RegMask

llvm/lib/Target/ARM/ARMCallingConv.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ def CSR_Win_AAPCS_CFGuard_Check : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7,
278278
// R8 is used to pass swifterror, remove it from CSR.
279279
def CSR_AAPCS_SwiftError : CalleeSavedRegs<(sub CSR_AAPCS, R8)>;
280280

281+
// R10 is used to pass swiftself, remove it from CSR.
282+
def CSR_AAPCS_SwiftTail : CalleeSavedRegs<(sub CSR_AAPCS, R10)>;
283+
281284
// The order of callee-saved registers needs to match the order we actually push
282285
// them in FrameLowering, because this order is what's used by
283286
// PrologEpilogInserter to allocate frame index slots. So when R7 is the frame
@@ -290,6 +293,10 @@ def CSR_AAPCS_SplitPush : CalleeSavedRegs<(add LR, R7, R6, R5, R4,
290293
def CSR_AAPCS_SplitPush_SwiftError : CalleeSavedRegs<(sub CSR_AAPCS_SplitPush,
291294
R8)>;
292295

296+
// R10 is used to pass swifterror, remove it from CSR.
297+
def CSR_AAPCS_SplitPush_SwiftTail : CalleeSavedRegs<(sub CSR_AAPCS_SplitPush,
298+
R10)>;
299+
293300
// Constructors and destructors return 'this' in the ARM C++ ABI; since 'this'
294301
// and the pointer return value are both passed in R0 in these cases, this can
295302
// be partially modelled by treating R0 as a callee-saved register
@@ -305,6 +312,9 @@ def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>;
305312
// R8 is used to pass swifterror, remove it from CSR.
306313
def CSR_iOS_SwiftError : CalleeSavedRegs<(sub CSR_iOS, R8)>;
307314

315+
// R10 is used to pass swiftself, remove it from CSR.
316+
def CSR_iOS_SwiftTail : CalleeSavedRegs<(sub CSR_iOS, R10)>;
317+
308318
def CSR_iOS_ThisReturn : CalleeSavedRegs<(add LR, R7, R6, R5, R4,
309319
(sub CSR_AAPCS_ThisReturn, R9))>;
310320

llvm/test/CodeGen/ARM/swifttailcc-call.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,11 @@ define swifttailcc void @fromtail_toC() {
191191
call void @Ccallee_stack4([4 x i32] undef, i32 42)
192192
ret void
193193
}
194+
195+
declare swifttailcc i8* @SwiftSelf(i8 * swiftasync %context, i8* swiftself %closure)
196+
define swiftcc i8* @CallSwiftSelf(i8* swiftself %closure, i8* %context) {
197+
; CHECK-LABEL: CallSwiftSelf:
198+
; CHECK: push{{.*}}r10
199+
%res = call swifttailcc i8* @SwiftSelf(i8 * swiftasync %context, i8* swiftself %closure)
200+
ret i8* %res
201+
}

0 commit comments

Comments
 (0)