diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
| commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
| tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /lib/Target/X86/X86FrameLowering.cpp | |
| parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) | |
Notes
Diffstat (limited to 'lib/Target/X86/X86FrameLowering.cpp')
| -rw-r--r-- | lib/Target/X86/X86FrameLowering.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index e207c343fac8..984db12201ed 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -185,7 +185,8 @@ static unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB, } for (auto CS : AvailableRegs) - if (!Uses.count(CS) && CS != X86::RIP) + if (!Uses.count(CS) && CS != X86::RIP && CS != X86::RSP && + CS != X86::ESP) return CS; } } @@ -765,7 +766,7 @@ void X86FrameLowering::emitStackProbeCall(MachineFunction &MF, bool IsLargeCodeModel = MF.getTarget().getCodeModel() == CodeModel::Large; // FIXME: Add retpoline support and remove this. - if (Is64Bit && IsLargeCodeModel && STI.useRetpoline()) + if (Is64Bit && IsLargeCodeModel && STI.useRetpolineIndirectCalls()) report_fatal_error("Emitting stack probe calls on 64-bit with the large " "code model and retpoline not yet implemented."); @@ -1103,15 +1104,6 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, if (TRI->needsStackRealignment(MF) && !IsWin64Prologue) NumBytes = alignTo(NumBytes, MaxAlign); - // Get the offset of the stack slot for the EBP register, which is - // guaranteed to be the last slot by processFunctionBeforeFrameFinalized. - // Update the frame offset adjustment. - if (!IsFunclet) - MFI.setOffsetAdjustment(-NumBytes); - else - assert(MFI.getOffsetAdjustment() == -(int)NumBytes && - "should calculate same local variable offset for funclets"); - // Save EBP/RBP into the appropriate stack slot. BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::PUSH64r : X86::PUSH32r)) .addReg(MachineFramePtr, RegState::Kill) @@ -1167,6 +1159,15 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, NumBytes = StackSize - X86FI->getCalleeSavedFrameSize(); } + // Update the offset adjustment, which is mainly used by codeview to translate + // from ESP to VFRAME relative local variable offsets. + if (!IsFunclet) { + if (HasFP && TRI->needsStackRealignment(MF)) + MFI.setOffsetAdjustment(-NumBytes); + else + MFI.setOffsetAdjustment(-StackSize); + } + // For EH funclets, only allocate enough space for outgoing calls. Save the // NumBytes value that we would've used for the parent frame. unsigned ParentFrameNumBytes = NumBytes; @@ -1208,6 +1209,13 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, if (!IsWin64Prologue && !IsFunclet && TRI->needsStackRealignment(MF)) { assert(HasFP && "There should be a frame pointer if stack is realigned."); BuildStackAlignAND(MBB, MBBI, DL, StackPtr, MaxAlign); + + if (NeedsWinCFI) { + HasWinCFI = true; + BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_StackAlign)) + .addImm(MaxAlign) + .setMIFlag(MachineInstr::FrameSetup); + } } // If there is an SUB32ri of ESP immediately before this instruction, merge @@ -1983,6 +1991,7 @@ bool X86FrameLowering::assignCalleeSavedSpillSlots( } X86FI->setCalleeSavedFrameSize(CalleeSavedFrameSize); + MFI.setCVBytesOfCalleeSavedRegisters(CalleeSavedFrameSize); // Assign slots for XMMs. for (unsigned i = CSI.size(); i != 0; --i) { @@ -2262,9 +2271,15 @@ void X86FrameLowering::adjustForSegmentedStacks( // Do not generate a prologue for leaf functions with a stack of size zero. // For non-leaf functions we have to allow for the possibility that the - // call is to a non-split function, as in PR37807. - if (StackSize == 0 && !MFI.hasTailCall()) + // callis to a non-split function, as in PR37807. This function could also + // take the address of a non-split function. When the linker tries to adjust + // its non-existent prologue, it would fail with an error. Mark the object + // file so that such failures are not errors. See this Go language bug-report + // https://go-review.googlesource.com/c/go/+/148819/ + if (StackSize == 0 && !MFI.hasTailCall()) { + MF.getMMI().setHasNosplitStack(true); return; + } MachineBasicBlock *allocMBB = MF.CreateMachineBasicBlock(); MachineBasicBlock *checkMBB = MF.CreateMachineBasicBlock(); @@ -2437,7 +2452,7 @@ void X86FrameLowering::adjustForSegmentedStacks( // is laid out within 2^31 bytes of each function body, but this seems // to be sufficient for JIT. // FIXME: Add retpoline support and remove the error here.. - if (STI.useRetpoline()) + if (STI.useRetpolineIndirectCalls()) report_fatal_error("Emitting morestack calls on 64-bit with the large " "code model and retpoline not yet implemented."); BuildMI(allocMBB, DL, TII.get(X86::CALL64m)) @@ -2463,8 +2478,8 @@ void X86FrameLowering::adjustForSegmentedStacks( allocMBB->addSuccessor(&PrologueMBB); - checkMBB->addSuccessor(allocMBB); - checkMBB->addSuccessor(&PrologueMBB); + checkMBB->addSuccessor(allocMBB, BranchProbability::getZero()); + checkMBB->addSuccessor(&PrologueMBB, BranchProbability::getOne()); #ifdef EXPENSIVE_CHECKS MF.verify(); |
