Fixes the last x86-64 test failure in compat.exp:
authorDale Johannesen <dalej@apple.com>
Thu, 26 Jun 2008 01:51:13 +0000 (01:51 +0000)
committerDale Johannesen <dalej@apple.com>
Thu, 26 Jun 2008 01:51:13 +0000 (01:51 +0000)
<16 x float> is 64-byte aligned (for some reason),
which gets us into the stack realignment code.  The
computation changing FP-relative offsets to SP-relative
was broken, assiging a spill temp to a location
also used for parameter passing.  This
fixes it by rounding up the stack frame to a multiple
of the largest alignment (I concluded it wasn't fixable
without doing this, but I'm not very sure.)

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

include/llvm/Target/TargetRegisterInfo.h
lib/CodeGen/PrologEpilogInserter.cpp
lib/Target/X86/X86RegisterInfo.cpp
utils/TableGen/RegisterInfoEmitter.cpp

index 08b9bfc7649022140b3fe3d2251c9caa80d49093..2deede235f7063f0bea8954366bc305e5a695a82 100644 (file)
@@ -516,6 +516,13 @@ public:
     return !hasFP(MF);
   }
 
+  // needsStackRealignment - true if storage within the function requires the
+  // stack pointer to be aligned more than the normal calling convention calls
+  // for.
+  virtual bool needsStackRealignment(const MachineFunction &MF) const {
+    return false;
+  }
+
   /// getCallFrameSetup/DestroyOpcode - These methods return the opcode of the
   /// frame setup/destroy instructions if they exist (-1 otherwise).  Some
   /// targets use pseudo instructions in order to abstract away the difference
index c52da321c1e9a05e922486ff70c1a21f279bc3a7..10ba9c0256fc9c2e564a35a838f98256fe192e1f 100644 (file)
@@ -459,15 +459,19 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
   // Round up the size to a multiple of the alignment, but only if there are
   // calls or alloca's in the function.  This ensures that any calls to
   // subroutines have their stack frames suitable aligned.
+  // Also do this if we need runtime alignment of the stack.  In this case
+  // offsets will be relative to SP not FP; round up the stack size so this
+  // works.
   if (!RegInfo->targetHandlesStackFrameRounding() &&
-      (FFI->hasCalls() || FFI->hasVarSizedObjects())) {
+      (FFI->hasCalls() || FFI->hasVarSizedObjects() || 
+       RegInfo->needsStackRealignment(Fn))) {
     // If we have reserved argument space for call sites in the function
     // immediately on entry to the current function, count it as part of the
     // overall stack size.
     if (RegInfo->hasReservedCallFrame(Fn))
       Offset += FFI->getMaxCallFrameSize();
 
-    unsigned AlignMask = TFI.getStackAlignment() - 1;
+    unsigned AlignMask = std::max(TFI.getStackAlignment(),MaxAlign) - 1;
     Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
   }
 
index 0bac85094ca524da6fb61e17195dc1228b6cf8c7..b48cee3ac338df6616839d0c5b69bcb1e5d2f9eb 100644 (file)
@@ -302,11 +302,9 @@ X86RegisterInfo::getFrameIndexOffset(MachineFunction &MF, int FI) const {
       // Skip the saved EBP
       Offset += SlotSize;
     else {
-      unsigned MaxAlign = MF.getFrameInfo()->getMaxAlignment();
-      uint64_t FrameSize =
-        (StackSize - SlotSize + MaxAlign - 1)/MaxAlign*MaxAlign;
-
-      return Offset + FrameSize - SlotSize;
+      unsigned Align = MF.getFrameInfo()->getObjectAlignment(FI);
+      assert( (-(Offset + StackSize)) % Align == 0);
+      return Offset + StackSize;
     }
 
     // FIXME: Support tail calls
index 92773359a9c45859bbfc44ff57506fa72498a79e..2f253ff34e5013bcf2e26a8da08377a27d0d6273 100644 (file)
@@ -64,6 +64,8 @@ void RegisterInfoEmitter::runHeader(std::ostream &OS) {
      << "  virtual int getDwarfRegNumFull(unsigned RegNum, "
      << "unsigned Flavour) const;\n"
      << "  virtual int getDwarfRegNum(unsigned RegNum, bool isEH) const = 0;\n"
+     << "  virtual bool needsStackRealignment(const MachineFunction &) const\n"
+     << "     { return false; }\n"
      << "  unsigned getSubReg(unsigned RegNo, unsigned Index) const;\n"
      << "};\n\n";