forked from OSchip/llvm-project
Fix the Red Zone calculation for functions with frame pointers.
Don't use the Red Zone when dynamic stack realignment is needed. This could be implemented, but most x86-64 ABIs don't require dynamic stack realignment so it isn't urgent. llvm-svn: 63074
This commit is contained in:
parent
64797bb7bf
commit
1cd2a2c9f8
|
@ -721,24 +721,27 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||||
// Get desired stack alignment
|
// Get desired stack alignment
|
||||||
uint64_t MaxAlign = MFI->getMaxAlignment();
|
uint64_t MaxAlign = MFI->getMaxAlignment();
|
||||||
|
|
||||||
// If this is x86-64 and the Red Zone is not disabled, if we are a leaf
|
|
||||||
// function, and use up to 128 bytes of stack space, don't have a frame
|
|
||||||
// pointer, calls, or dynamic alloca then we do not need to adjust the
|
|
||||||
// stack pointer (we fit in the Red Zone).
|
|
||||||
if (Is64Bit && !DisableRedZone &&
|
|
||||||
!MFI->hasVarSizedObjects() && // No dynamic alloca.
|
|
||||||
!MFI->hasCalls()) { // No calls.
|
|
||||||
StackSize = std::max((uint64_t)X86FI->getCalleeSavedFrameSize(),
|
|
||||||
StackSize > 128 ? StackSize - 128 : 0);
|
|
||||||
MFI->setStackSize(StackSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add RETADDR move area to callee saved frame size.
|
// Add RETADDR move area to callee saved frame size.
|
||||||
int TailCallReturnAddrDelta = X86FI->getTCReturnAddrDelta();
|
int TailCallReturnAddrDelta = X86FI->getTCReturnAddrDelta();
|
||||||
if (TailCallReturnAddrDelta < 0)
|
if (TailCallReturnAddrDelta < 0)
|
||||||
X86FI->setCalleeSavedFrameSize(
|
X86FI->setCalleeSavedFrameSize(
|
||||||
X86FI->getCalleeSavedFrameSize() +(-TailCallReturnAddrDelta));
|
X86FI->getCalleeSavedFrameSize() +(-TailCallReturnAddrDelta));
|
||||||
|
|
||||||
|
// If this is x86-64 and the Red Zone is not disabled, if we are a leaf
|
||||||
|
// function, and use up to 128 bytes of stack space, don't have a frame
|
||||||
|
// pointer, calls, or dynamic alloca then we do not need to adjust the
|
||||||
|
// stack pointer (we fit in the Red Zone).
|
||||||
|
if (Is64Bit && !DisableRedZone &&
|
||||||
|
!needsStackRealignment(MF) &&
|
||||||
|
!MFI->hasVarSizedObjects() && // No dynamic alloca.
|
||||||
|
!MFI->hasCalls()) { // No calls.
|
||||||
|
uint64_t MinSize = X86FI->getCalleeSavedFrameSize();
|
||||||
|
if (hasFP(MF)) MinSize += SlotSize;
|
||||||
|
StackSize = std::max(MinSize,
|
||||||
|
StackSize > 128 ? StackSize - 128 : 0);
|
||||||
|
MFI->setStackSize(StackSize);
|
||||||
|
}
|
||||||
|
|
||||||
// Insert stack pointer adjustment for later moving of return addr. Only
|
// Insert stack pointer adjustment for later moving of return addr. Only
|
||||||
// applies to tail call optimized functions where the callee argument stack
|
// applies to tail call optimized functions where the callee argument stack
|
||||||
// size is bigger than the callers.
|
// size is bigger than the callers.
|
||||||
|
|
Loading…
Reference in New Issue