[llvm-commits] [llvm] r111197 - in /llvm/trunk: include/llvm/CodeGen/MachineFrameInfo.h lib/CodeGen/LocalStackSlotAllocation.cpp lib/CodeGen/PrologEpilogInserter.cpp

Jim Grosbach grosbach at apple.com
Mon Aug 16 15:30:41 PDT 2010


Author: grosbach
Date: Mon Aug 16 17:30:41 2010
New Revision: 111197

URL: http://llvm.org/viewvc/llvm-project?rev=111197&view=rev
Log:
Better handle alignment requirements for local objects in pre-regalloc frame
mapping. Have the local block track its alignment requirement, and then
apply that when the block itself is allocated. Previously, offsets could
get adjusted in PEI to be different, relative to one another, than the
block allocation thought they would be, which defeats the point of doing
the allocation this way. Continuing rdar://8277890

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h
    llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp
    llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h?rev=111197&r1=111196&r2=111197&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h Mon Aug 16 17:30:41 2010
@@ -212,6 +212,10 @@
   /// target in eliminateFrameIndex().
   int64_t LocalFrameBaseOffset;
 
+  /// Required alignment of the local object blob, which is the strictest
+  /// alignment of any object in it.
+  unsigned LocalFrameMaxAlign;
+
 public:
     explicit MachineFrameInfo(const TargetFrameInfo &tfi) : TFI(tfi) {
     StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
@@ -225,6 +229,7 @@
     CSIValid = false;
     LocalFrameSize = 0;
     LocalFrameBaseOffset = 0;
+    LocalFrameMaxAlign = 0;
   }
 
   /// hasStackObjects - Return true if there are any stack objects in this
@@ -302,6 +307,15 @@
   /// getLocalFrameSize - Get the size of the local object blob.
   int64_t getLocalFrameSize() const { return LocalFrameSize; }
 
+  /// setLocalFrameMaxAlign - Required alignment of the local object blob,
+  /// which is the strictest alignment of any object in it.
+  void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; }
+
+  /// getLocalFrameMaxAlign - Return the required alignment of the local
+  /// object blob.
+  unsigned getLocalFrameMaxAlign() { return LocalFrameMaxAlign; }
+
+
   /// isObjectPreAllocated - Return true if the object was pre-allocated into
   /// the local block.
   bool isObjectPreAllocated(int ObjectIdx) const {

Modified: llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp?rev=111197&r1=111196&r2=111197&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp (original)
+++ llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp Mon Aug 16 17:30:41 2010
@@ -99,7 +99,7 @@
   // Loop over all of the stack objects, assigning sequential addresses...
   MachineFrameInfo *MFI = Fn.getFrameInfo();
   int64_t Offset = 0;
-  unsigned MaxAlign = MFI->getMaxAlignment();
+  unsigned MaxAlign = 0;
 
   // Make sure that the stack protector comes before the local variables on the
   // stack.
@@ -134,33 +134,7 @@
     AdjustStackOffset(MFI, i, Offset, MaxAlign);
   }
 
-  const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
-  if (!RegInfo->targetHandlesStackFrameRounding()) {
-    // 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 (MFI->adjustsStack() && RegInfo->hasReservedCallFrame(Fn))
-      Offset += MFI->getMaxCallFrameSize();
-
-    // Round up the size to a multiple of the alignment.  If the function has
-    // any calls or alloca's, align to the target's StackAlignment value to
-    // ensure that the callee's frame or the alloca data is suitably aligned;
-    // otherwise, for leaf functions, align to the TransientStackAlignment
-    // value.
-    unsigned StackAlign;
-    if (MFI->adjustsStack() || MFI->hasVarSizedObjects() ||
-        (RegInfo->needsStackRealignment(Fn) && MFI->getObjectIndexEnd() != 0))
-      StackAlign = TFI.getStackAlignment();
-    else
-      StackAlign = TFI.getTransientStackAlignment();
-
-    // If the frame pointer is eliminated, all frame offsets will be relative to
-    // SP not FP. Align to MaxAlign so this works.
-    StackAlign = std::max(StackAlign, MaxAlign);
-    unsigned AlignMask = StackAlign - 1;
-    Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
-  }
-
   // Remember how big this blob of stack space is
   MFI->setLocalFrameSize(Offset);
+  MFI->setLocalFrameMaxAlign(MaxAlign);
 }

Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=111197&r1=111196&r2=111197&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Mon Aug 16 17:30:41 2010
@@ -556,10 +556,20 @@
       AdjustStackOffset(MFI, SFI, StackGrowsDown, Offset, MaxAlign);
   }
 
-  // Store the offset of the start of the local allocation block. This
-  // will be used later when resolving frame base virtual register pseudos.
-  MFI->setLocalFrameBaseOffset(Offset);
+  // FIXME: Once this is working, then enable flag will change to a target
+  // check for whether the frame is large enough to want to use virtual
+  // frame index registers. Functions which don't want/need this optimization
+  // will continue to use the existing code path.
   if (EnableLocalStackAlloc) {
+    unsigned Align = MFI->getLocalFrameMaxAlign();
+
+    // Adjust to alignment boundary.
+    Offset = (Offset + Align - 1) / Align * Align;
+
+    // Store the offset of the start of the local allocation block. This
+    // will be used later when resolving frame base virtual register pseudos.
+    MFI->setLocalFrameBaseOffset(Offset);
+
     // Allocate the local block
     Offset += MFI->getLocalFrameSize();
 
@@ -571,10 +581,6 @@
       AdjustStackOffset(MFI, Entry.first, StackGrowsDown, FIOffset, MaxAlign);
     }
   }
-  // FIXME: Allocate locals. Once the block allocation pass is turned on,
-  // this simplifies to just the second loop, since all of the large objects
-  // will have already been handled. The second loop can also simplify a
-  // bit, as the conditionals inside aren't all necessary.
 
   // Make sure that the stack protector comes before the local variables on the
   // stack.





More information about the llvm-commits mailing list