Skip to content

Commit 3cb6b3c

Browse files
committed
Merge remote-tracking branch 'origin/swift-4.1-branch' into stable
2 parents 54dc204 + e501121 commit 3cb6b3c

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

lib/Target/X86/X86CallingConv.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,8 @@ def CSR_Win64_NoSSE : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, R13, R14, R1
10501050
def CSR_Win64 : CalleeSavedRegs<(add CSR_Win64_NoSSE,
10511051
(sequence "XMM%u", 6, 15))>;
10521052

1053+
def CSR_Win64_SwiftError : CalleeSavedRegs<(sub CSR_Win64, R12)>;
1054+
10531055
// The function used by Darwin to obtain the address of a thread-local variable
10541056
// uses rdi to pass a single parameter and rax for the return value. All other
10551057
// GPRs are preserved.

lib/Target/X86/X86RegisterInfo.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,13 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
271271
assert(MF && "MachineFunction required");
272272

273273
const X86Subtarget &Subtarget = MF->getSubtarget<X86Subtarget>();
274+
const Function *F = MF->getFunction();
274275
bool HasSSE = Subtarget.hasSSE1();
275276
bool HasAVX = Subtarget.hasAVX();
276277
bool HasAVX512 = Subtarget.hasAVX512();
277278
bool CallsEHReturn = MF->callsEHReturn();
278279

279-
CallingConv::ID CC = MF->getFunction()->getCallingConv();
280+
CallingConv::ID CC = F->getCallingConv();
280281

281282
// If attribute NoCallerSavedRegisters exists then we set X86_INTR calling
282283
// convention because it has the CSR list.
@@ -365,22 +366,20 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
365366
}
366367

367368
if (Is64Bit) {
368-
if (IsWin64) {
369-
if (!HasSSE)
370-
return CSR_Win64_NoSSE_SaveList;
371-
return CSR_Win64_SaveList;
372-
}
369+
bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
370+
F->getAttributes().hasAttrSomewhere(Attribute::SwiftError);
371+
if (IsSwiftCC)
372+
return IsWin64 ? CSR_Win64_SwiftError_SaveList
373+
: CSR_64_SwiftError_SaveList;
374+
375+
if (IsWin64)
376+
return HasSSE ? CSR_Win64_SaveList : CSR_Win64_NoSSE_SaveList;
373377
if (CallsEHReturn)
374378
return CSR_64EHRet_SaveList;
375-
if (Subtarget.getTargetLowering()->supportSwiftError() &&
376-
MF->getFunction()->getAttributes().hasAttrSomewhere(
377-
Attribute::SwiftError))
378-
return CSR_64_SwiftError_SaveList;
379379
return CSR_64_SaveList;
380380
}
381-
if (CallsEHReturn)
382-
return CSR_32EHRet_SaveList;
383-
return CSR_32_SaveList;
381+
382+
return CallsEHReturn ? CSR_32EHRet_SaveList : CSR_32_SaveList;
384383
}
385384

386385
const MCPhysReg *X86RegisterInfo::getCalleeSavedRegsViaCopy(
@@ -479,14 +478,14 @@ X86RegisterInfo::getCallPreservedMask(const MachineFunction &MF,
479478
// Unlike getCalleeSavedRegs(), we don't have MMI so we can't check
480479
// callsEHReturn().
481480
if (Is64Bit) {
482-
if (IsWin64)
483-
return CSR_Win64_RegMask;
484-
if (Subtarget.getTargetLowering()->supportSwiftError() &&
485-
MF.getFunction()->getAttributes().hasAttrSomewhere(
486-
Attribute::SwiftError))
487-
return CSR_64_SwiftError_RegMask;
488-
return CSR_64_RegMask;
481+
const Function *F = MF.getFunction();
482+
bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
483+
F->getAttributes().hasAttrSomewhere(Attribute::SwiftError);
484+
if (IsSwiftCC)
485+
return IsWin64 ? CSR_Win64_SwiftError_RegMask : CSR_64_SwiftError_RegMask;
486+
return IsWin64 ? CSR_Win64_RegMask : CSR_64_RegMask;
489487
}
488+
490489
return CSR_32_RegMask;
491490
}
492491

test/CodeGen/X86/swift-error.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ entry:
1111
}
1212

1313
; CHECK-LABEL: g
14-
; CHECK: pushq %r12
14+
; CHECK-NOT: pushq %r12
1515
; CHECK: callq f
16-
; CHECK: popq %r12
16+
; CHECK-NOT: popq %r12
1717
; CHECK: retq
1818

0 commit comments

Comments
 (0)