aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Target/TargetOptions.h4
-rw-r--r--lib/Target/TargetMachine.cpp7
-rw-r--r--lib/Target/X86/X86RegisterInfo.cpp12
3 files changed, 23 insertions, 0 deletions
diff --git a/include/llvm/Target/TargetOptions.h b/include/llvm/Target/TargetOptions.h
index 2419376..d53e399 100644
--- a/include/llvm/Target/TargetOptions.h
+++ b/include/llvm/Target/TargetOptions.h
@@ -107,6 +107,10 @@ namespace llvm {
/// wth earlier copy coalescing.
extern bool StrongPHIElim;
+ /// DisableRedZone - This flag disables use of the "Red Zone" on
+ /// targets which would otherwise have one.
+ extern bool DisableRedZone;
+
} // End llvm namespace
#endif
diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp
index a1d6fa7..fd577c7 100644
--- a/lib/Target/TargetMachine.cpp
+++ b/lib/Target/TargetMachine.cpp
@@ -40,6 +40,7 @@ namespace llvm {
bool VerboseAsm;
bool DisableJumpTables;
bool StrongPHIElim;
+ bool DisableRedZone;
}
static cl::opt<bool, true> PrintCode("print-machineinstrs",
@@ -164,6 +165,12 @@ EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
cl::location(StrongPHIElim),
cl::init(false));
+static cl::opt<bool, true>
+DisableRedZoneOption("disable-red-zone",
+ cl::desc("Do not emit code that uses the red zone."),
+ cl::location(DisableRedZone),
+ cl::init(true));
+
//---------------------------------------------------------------------------
// TargetMachine Class
//
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index a0d8b58..08746f2 100644
--- a/lib/Target/X86/X86RegisterInfo.cpp
+++ b/lib/Target/X86/X86RegisterInfo.cpp
@@ -721,6 +721,18 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
// Get desired stack alignment
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.
int TailCallReturnAddrDelta = X86FI->getTCReturnAddrDelta();
if (TailCallReturnAddrDelta < 0)