[llvm-commits] [llvm] r111673 - /llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp

Jim Grosbach grosbach at apple.com
Fri Aug 20 13:25:31 PDT 2010


Author: grosbach
Date: Fri Aug 20 15:25:31 2010
New Revision: 111673

URL: http://llvm.org/viewvc/llvm-project?rev=111673&view=rev
Log:
Downwards growing stack allocation order reverses relative offsets

Modified:
    llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp

Modified: llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp?rev=111673&r1=111672&r2=111673&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp (original)
+++ llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp Fri Aug 20 15:25:31 2010
@@ -174,6 +174,7 @@
 lookupCandidateBaseReg(const SmallVector<std::pair<unsigned, int64_t>, 8> &Regs,
                        std::pair<unsigned, int64_t> &RegOffset,
                        int64_t LocalFrameOffset,
+                       bool StackGrowsDown,
                        const MachineInstr *MI,
                        const TargetRegisterInfo *TRI) {
   unsigned e = Regs.size();
@@ -182,6 +183,8 @@
     // Check if the relative offset from the where the base register references
     // to the target address is in range for the instruction.
     int64_t Offset = LocalFrameOffset - RegOffset.second;
+    if (StackGrowsDown)
+      Offset = -Offset;
     if (TRI->isFrameOffsetLegal(MI, Offset))
       return true;
   }
@@ -199,6 +202,9 @@
 
   MachineFrameInfo *MFI = Fn.getFrameInfo();
   const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
+  const TargetFrameInfo &TFI = *Fn.getTarget().getFrameInfo();
+  bool StackGrowsDown =
+    TFI.getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
 
   for (MachineFunction::iterator BB = Fn.begin(),
          E = Fn.end(); BB != E; ++BB) {
@@ -245,12 +251,15 @@
             // register.
             std::pair<unsigned, int64_t> RegOffset;
             if (lookupCandidateBaseReg(BaseRegisters, RegOffset,
-                                       LocalOffsets[FrameIdx], MI, TRI)) {
+                                       LocalOffsets[FrameIdx],
+                                       StackGrowsDown, MI, TRI)) {
               DEBUG(dbgs() << "  Reusing base register " <<
                     RegOffset.first << "\n");
               // We found a register to reuse.
               BaseReg = RegOffset.first;
               Offset = LocalOffsets[FrameIdx] - RegOffset.second;
+              if (StackGrowsDown)
+                Offset = -Offset;
             } else {
               // No previously defined register was in range, so create a
               // new one.





More information about the llvm-commits mailing list