// NumBytes value that we would've used for the parent frame.
unsigned ParentFrameNumBytes = NumBytes;
if (IsFunclet)
- NumBytes = MFI->getMaxCallFrameSize();
+ NumBytes = getWinEHFuncletFrameSize(MF);
// Skip the callee-saved push instructions.
bool PushedRegs = false;
llvm_unreachable("impossible");
}
+unsigned X86FrameLowering::getWinEHFuncletFrameSize(const MachineFunction &MF) const {
+ // This is the size of the pushed CSRs.
+ unsigned CSSize =
+ MF.getInfo<X86MachineFunctionInfo>()->getCalleeSavedFrameSize();
+ // This is the amount of stack a funclet needs to allocate.
+ unsigned MaxCallSize = MF.getFrameInfo()->getMaxCallFrameSize();
+ // RBP is not included in the callee saved register block. After pushing RBP,
+ // everything is 16 byte aligned. Everything we allocate before an outgoing
+ // call must also be 16 byte aligned.
+ unsigned FrameSizeMinusRBP =
+ RoundUpToAlignment(CSSize + MaxCallSize, getStackAlignment());
+ // Subtract out the size of the callee saved registers. This is how much stack
+ // each funclet will allocate.
+ return FrameSizeMinusRBP - CSSize;
+}
+
void X86FrameLowering::emitEpilogue(MachineFunction &MF,
MachineBasicBlock &MBB) const {
const MachineFrameInfo *MFI = MF.getFrameInfo();
uint64_t NumBytes = 0;
if (MBBI->getOpcode() == X86::CATCHRET) {
- NumBytes = MFI->getMaxCallFrameSize();
+ NumBytes = getWinEHFuncletFrameSize(MF);
assert(hasFP(MF) && "EH funclets without FP not yet implemented");
MachineBasicBlock *TargetMBB = MBBI->getOperand(0).getMBB();
RestoreMBB = TargetMBB;
if (STI.is32Bit()) {
RestoreMBB = MF.CreateMachineBasicBlock(MBB.getBasicBlock());
- MF.insert(TargetMBB, RestoreMBB);
+ MF.insert(TargetMBB->getIterator(), RestoreMBB);
MBB.removeSuccessor(TargetMBB);
MBB.addSuccessor(RestoreMBB);
RestoreMBB->addSuccessor(TargetMBB);
.addMBB(TargetMBB);
}
} else if (MBBI->getOpcode() == X86::CLEANUPRET) {
- NumBytes = MFI->getMaxCallFrameSize();
+ NumBytes = getWinEHFuncletFrameSize(MF);
assert(hasFP(MF) && "EH funclets without FP not yet implemented");
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
MachineFramePtr)
.addReg(ReturnReg)
.addMBB(RestoreMBB);
}
+ // Record that we've taken the address of RestoreMBB and no longer just
+ // reference it in a terminator.
+ RestoreMBB->setHasAddressTaken();
}
if (MBBI != MBB.end())
if (HasDwarfEHHandlers && !isDestroy &&
MF.getInfo<X86MachineFunctionInfo>()->getHasPushSequences())
- BuildCFI(MBB, I, DL,\r
- MCCFIInstruction::createGnuArgsSize(nullptr, Amount));\r
+ BuildCFI(MBB, I, DL,
+ MCCFIInstruction::createGnuArgsSize(nullptr, Amount));
if (Amount == 0)
return;
}
return MBBI;
}
+
+unsigned X86FrameLowering::getWinEHParentFrameOffset(const MachineFunction &MF) const {
+ // RDX, the parent frame pointer, is homed into 16(%rsp) in the prologue.
+ unsigned Offset = 16;
+ // RBP is immediately pushed.
+ Offset += SlotSize;
+ // All callee-saved registers are then pushed.
+ Offset += MF.getInfo<X86MachineFunctionInfo>()->getCalleeSavedFrameSize();
+ // Every funclet allocates enough stack space for the largest outgoing call.
+ Offset += getWinEHFuncletFrameSize(MF);
+ return Offset;
+}