[llvm-commits] [llvm] r111374 - in /llvm/trunk: include/llvm/Target/TargetRegisterInfo.h lib/CodeGen/LocalStackSlotAllocation.cpp lib/Target/ARM/ARMBaseRegisterInfo.cpp lib/Target/ARM/ARMBaseRegisterInfo.h

Jim Grosbach grosbach at apple.com
Wed Aug 18 10:57:37 PDT 2010


Author: grosbach
Date: Wed Aug 18 12:57:37 2010
New Revision: 111374

URL: http://llvm.org/viewvc/llvm-project?rev=111374&view=rev
Log:
Add hook for re-using virtual base registers for local stack slot access.
Nothing fancy, just ask the target if any currently available base reg
is in range for the instruction under consideration and use the first one
that is. Placeholder ARM implementation simply returns false for now.

ongoing saga of rdar://8277890


Modified:
    llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
    llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp
    llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.cpp
    llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.h

Modified: llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegisterInfo.h?rev=111374&r1=111373&r2=111374&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetRegisterInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetRegisterInfo.h Wed Aug 18 12:57:37 2010
@@ -659,6 +659,13 @@
     assert(0 && "resolveFrameIndex does not exist on this target");
   }
 
+  /// isBaseRegInRange - Determine whether a given base register definition
+  /// is in range to resolve a frame index.
+  virtual bool isBaseRegInRange(const MachineInstr *MI, unsigned Reg,
+                                int64_t Offset) const {
+    assert(0 && "isBaseRegInRange does not exist on this target");
+    return false; // Must return a value in order to compile with VS 2005
+  }
 
   /// getCallFrameSetup/DestroyOpcode - These methods return the opcode of the
   /// frame setup/destroy instructions if they exist (-1 otherwise).  Some

Modified: llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp?rev=111374&r1=111373&r2=111374&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp (original)
+++ llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp Wed Aug 18 12:57:37 2010
@@ -146,6 +146,20 @@
   MFI->setLocalFrameMaxAlign(MaxAlign);
 }
 
+static inline bool
+lookupCandidateBaseReg(const SmallVector<std::pair<unsigned, int64_t>, 8> &Regs,
+                       std::pair<unsigned, int64_t> &RegOffset,
+                       const MachineInstr *MI,
+                       const TargetRegisterInfo *TRI) {
+  unsigned e = Regs.size();
+  for (unsigned i = 0; i < e; ++i) {
+    RegOffset = Regs[i];
+    if (TRI->isBaseRegInRange(MI, RegOffset.first, RegOffset.second))
+      return true;
+  }
+  return false;
+}
+
 void LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) {
   // Scan the function's instructions looking for frame index references.
   // For each, ask the target if it wants a virtual base register for it
@@ -169,6 +183,9 @@
       if (MI->isDebugValue())
         continue;
 
+      // A base register definition is a register+offset pair.
+      SmallVector<std::pair<unsigned, int64_t>, 8> BaseRegisters;
+
       // For now, allocate the base register(s) within the basic block
       // where they're used, and don't try to keep them around outside
       // of that. It may be beneficial to try sharing them more broadly
@@ -186,27 +203,39 @@
 
           DEBUG(dbgs() << "Considering: " << *MI);
           if (TRI->needsFrameBaseReg(MI, i)) {
+            unsigned BaseReg = 0;
+            unsigned Offset = 0;
+
             DEBUG(dbgs() << "  Replacing FI in: " << *MI);
-            // FIXME: Make sure any new base reg is aligned reasonably. TBD
-            // what "reasonably" really means. Conservatively, can just
-            // use the alignment of the local block.
 
             // If we have a suitable base register available, use it; otherwise
             // create a new one.
-            // FIXME: For the moment, just always create a new one.
-
-            const TargetRegisterClass *RC = TRI->getPointerRegClass();
-            unsigned BaseReg = Fn.getRegInfo().createVirtualRegister(RC);
 
-            // Tell the target to insert the instruction to initialize
-            // the base register.
-            TRI->materializeFrameBaseRegister(I, BaseReg, FrameIdx);
+            std::pair<unsigned, int64_t> RegOffset;
+            if (lookupCandidateBaseReg(BaseRegisters, RegOffset, MI, TRI)) {
+              // We found a register to reuse.
+              BaseReg = RegOffset.first;
+              Offset = RegOffset.second;
+            } else {
+              // No previously defined register was in range, so create a
+              // new one.
+              const TargetRegisterClass *RC = TRI->getPointerRegClass();
+              BaseReg = Fn.getRegInfo().createVirtualRegister(RC);
+
+              // Tell the target to insert the instruction to initialize
+              // the base register.
+              TRI->materializeFrameBaseRegister(I, BaseReg, FrameIdx);
+
+              BaseRegisters.push_back(std::pair<unsigned, int64_t>(BaseReg,
+                                                                   Offset));
+              ++NumBaseRegisters;
+            }
+            assert(BaseReg != 0 && "Unable to allocate virtual base register!");
 
             // Modify the instruction to use the new base register rather
             // than the frame index operand.
-            TRI->resolveFrameIndex(I, BaseReg, 0);
+            TRI->resolveFrameIndex(I, BaseReg, Offset);
 
-            ++NumBaseRegisters;
             ++NumReplacements;
           }
 

Modified: llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.cpp?rev=111374&r1=111373&r2=111374&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.cpp Wed Aug 18 12:57:37 2010
@@ -1451,6 +1451,12 @@
   assert (Done && "Unable to resolve frame index!");
 }
 
+bool ARMBaseRegisterInfo::isBaseRegInRange(const MachineInstr *MI,
+                                           unsigned Reg, int64_t Offset) const {
+
+  return false;
+}
+
 unsigned
 ARMBaseRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
                                          int SPAdj, FrameIndexValue *Value,

Modified: llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.h?rev=111374&r1=111373&r2=111374&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseRegisterInfo.h Wed Aug 18 12:57:37 2010
@@ -110,6 +110,8 @@
                                     unsigned BaseReg, int FrameIdx) const;
   void resolveFrameIndex(MachineBasicBlock::iterator I,
                          unsigned BaseReg, int64_t Offset) const;
+  bool isBaseRegInRange(const MachineInstr *MI, unsigned Reg,
+                        int64_t Offset) const;
 
   bool cannotEliminateFrame(const MachineFunction &MF) const;
 





More information about the llvm-commits mailing list