Skip to content

Commit dd61bd4

Browse files
committed
Merge commit '830ac3629ac7' from apple/main into swift/next
Conflicts: llvm/lib/Target/ARM/ARMFrameLowering.cpp llvm/lib/Target/ARM/ARMISelLowering.cpp llvm/test/CodeGen/ARM/swifttailcc-call.ll
2 parents e94956e + 830ac36 commit dd61bd4

File tree

7 files changed

+49
-11
lines changed

7 files changed

+49
-11
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/lib/Target/ARM/ARMFastISel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,7 @@ CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC,
18491849
}
18501850
case CallingConv::ARM_AAPCS_VFP:
18511851
case CallingConv::Swift:
1852+
case CallingConv::SwiftTail:
18521853
if (!isVarArg)
18531854
return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
18541855
// Fall through to soft float variant, variadic functions don't
@@ -3014,6 +3015,7 @@ bool ARMFastISel::fastLowerArguments() {
30143015
case CallingConv::ARM_AAPCS:
30153016
case CallingConv::ARM_APCS:
30163017
case CallingConv::Swift:
3018+
case CallingConv::SwiftTail:
30173019
break;
30183020
}
30193021

llvm/lib/Target/ARM/ARMFrameLowering.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ void ARMFrameLowering::emitEpilogue(MachineFunction &MF,
903903
"This emitEpilogue does not support Thumb1!");
904904
bool isARM = !AFI->isThumbFunction();
905905

906-
// Amount of stack space we reserved next next to incoming args for either
906+
// Amount of stack space we reserved next to incoming args for either
907907
// varargs registers or stack arguments in tail calls made by this function.
908908
unsigned ReservedArgStack = AFI->getArgRegsSaveSize();
909909

@@ -2350,10 +2350,8 @@ MachineBasicBlock::iterator ARMFrameLowering::eliminateCallFramePseudoInstr(
23502350
unsigned PredReg = TII.getFramePred(*I);
23512351

23522352
if (!hasReservedCallFrame(MF)) {
2353-
// Bail early if the callee is expected to do the adjustment. If
2354-
// CalleePopAmount is valid but 0 anyway, Amount will be 0 too so it doesn't
2355-
// matter if we continue a bit longer.
2356-
if (IsDestroy && CalleePopAmount != 0)
2353+
// Bail early if the callee is expected to do the adjustment.
2354+
if (IsDestroy && CalleePopAmount != -1U)
23572355
return MBB.erase(I);
23582356

23592357
// If we have alloca, convert as follows:
@@ -2375,7 +2373,7 @@ MachineBasicBlock::iterator ARMFrameLowering::eliminateCallFramePseudoInstr(
23752373
Pred, PredReg);
23762374
}
23772375
}
2378-
} else if (CalleePopAmount != 0) {
2376+
} else if (CalleePopAmount != -1U) {
23792377
// If the calling convention demands that the callee pops arguments from the
23802378
// stack, we want to add it back if we have a reserved call frame.
23812379
emitSPUpdate(isARM, MBB, I, dl, TII, -CalleePopAmount,

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,12 +2758,12 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
27582758
InFlag = Chain.getValue(1);
27592759
DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));
27602760

2761-
// If we're guaranteeing tail-call, it's because the callee will pop its own
2762-
// stack on return. So we need to undo that after the call to restore the
2763-
// status-quo.
2761+
// If we're guaranteeing tail-calls will be honoured, the callee must
2762+
// pop its own argument stack on return. But this call is *not* a tail call so
2763+
// we need to undo that after it returns to restore the status-quo.
27642764
bool TailCallOpt = getTargetMachine().Options.GuaranteedTailCallOpt;
27652765
uint64_t CalleePopBytes =
2766-
canGuaranteeTCO(CallConv, TailCallOpt) ? alignTo(NumBytes, 16) : 0;
2766+
canGuaranteeTCO(CallConv, TailCallOpt) ? alignTo(NumBytes, 16) : -1ULL;
27672767

27682768
Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true),
27692769
DAG.getIntPtrConstant(CalleePopBytes, dl, true),
@@ -4563,7 +4563,7 @@ SDValue ARMTargetLowering::LowerFormalArguments(
45634563
bool TailCallOpt = MF.getTarget().Options.GuaranteedTailCallOpt;
45644564
if (canGuaranteeTCO(CallConv, TailCallOpt)) {
45654565
// The only way to guarantee a tail call is if the callee restores its
4566-
// argument area, but it must also keep the stack aligned when doing so. FIXME: explain in more detail.
4566+
// argument area, but it must also keep the stack aligned when doing so.
45674567
const DataLayout &DL = DAG.getDataLayout();
45684568
StackArgSize = alignTo(StackArgSize, DL.getStackAlignment());
45694569

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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: llc -mtriple=thumbv7-apple-ios -O0 -fast-isel %s -o - | FileCheck %s
2+
3+
declare swifttailcc i8* @SwiftSelf(i8 * swiftasync %context, i8* swiftself %closure)
4+
5+
define swifttailcc i8* @CallSwiftSelf(i8* swiftself %closure, i8* %context) {
6+
; CHECK-LABEL: CallSwiftSelf:
7+
; CHECK: bl _SwiftSelf
8+
; CHECK: pop {r7, pc}
9+
%res = call swifttailcc i8* @SwiftSelf(i8 * swiftasync %context, i8* swiftself null)
10+
ret i8* %res
11+
}

0 commit comments

Comments
 (0)