Implement Red Zone utilization on x86-64. This is currently
authorDan Gohman <gohman@apple.com>
Mon, 26 Jan 2009 22:22:31 +0000 (22:22 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 26 Jan 2009 22:22:31 +0000 (22:22 +0000)
disabled by default; I'll enable it when I hook it up with
the llvm-gcc flag which controls it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63056 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetOptions.h
lib/Target/TargetMachine.cpp
lib/Target/X86/X86RegisterInfo.cpp

index 2419376c5396f7f340ec4e0e2f5a209f9b061125..d53e399b8593e02e72bf47172a60c98b577547d7 100644 (file)
@@ -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
index a1d6fa7eb9755b406ec824ed044e08fe136be057..fd577c7438ac659c14347093f2b0a52621abf752 100644 (file)
@@ -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
 //
index a0d8b58b789c944547feca66c6bd7306d86aa289..08746f2ffb4755f916c474c69d33be64a32fca93 100644 (file)
@@ -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)