[llvm-commits] [llvm] r123130 - in /llvm/trunk: include/llvm/ADT/IndexedMap.h include/llvm/CodeGen/MachineRegisterInfo.h lib/CodeGen/RegAllocFast.cpp lib/CodeGen/VirtRegMap.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Sun Jan 9 13:58:20 PST 2011


Author: stoklund
Date: Sun Jan  9 15:58:20 2011
New Revision: 123130

URL: http://llvm.org/viewvc/llvm-project?rev=123130&view=rev
Log:
Remove MachineRegisterInfo::getLastVirtReg(), it was giving wrong results
when no virtual registers have been allocated.

It was only used to resize IndexedMaps, so provide an IndexedMap::resize()
method such that

 Map.grow(MRI.getLastVirtReg());

can be replaced with the simpler

 Map.resize(MRI.getNumVirtRegs());

This works correctly when no virtuals are allocated, and it bypasses the to/from
index conversions.

Modified:
    llvm/trunk/include/llvm/ADT/IndexedMap.h
    llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h
    llvm/trunk/lib/CodeGen/RegAllocFast.cpp
    llvm/trunk/lib/CodeGen/VirtRegMap.cpp

Modified: llvm/trunk/include/llvm/ADT/IndexedMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IndexedMap.h?rev=123130&r1=123129&r2=123130&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/IndexedMap.h (original)
+++ llvm/trunk/include/llvm/ADT/IndexedMap.h Sun Jan  9 15:58:20 2011
@@ -59,6 +59,10 @@
       storage_.reserve(s);
     }
 
+    void resize(typename StorageT::size_type s) {
+      storage_.resize(s, nullVal_);
+    }
+
     void clear() {
       storage_.clear();
     }
@@ -66,7 +70,7 @@
     void grow(IndexT n) {
       unsigned NewSize = toIndex_(n) + 1;
       if (NewSize > storage_.size())
-        storage_.resize(NewSize, nullVal_);
+        resize(NewSize);
     }
 
     bool inBounds(IndexT n) const {

Modified: llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h?rev=123130&r1=123129&r2=123130&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h Sun Jan  9 15:58:20 2011
@@ -216,12 +216,6 @@
   ///
   unsigned getNumVirtRegs() const { return VRegInfo.size(); }
 
-  /// getLastVirtReg - Return the highest currently assigned virtual register.
-  ///
-  unsigned getLastVirtReg() const {
-    return TargetRegisterInfo::index2VirtReg(getNumVirtRegs() - 1);
-  }
-
   /// getRegClassVirtRegs - Return the list of virtual registers of the given
   /// target register class.
   const std::vector<unsigned> &

Modified: llvm/trunk/lib/CodeGen/RegAllocFast.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocFast.cpp?rev=123130&r1=123129&r2=123130&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocFast.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocFast.cpp Sun Jan  9 15:58:20 2011
@@ -1024,8 +1024,7 @@
 
   // initialize the virtual->physical register map to have a 'null'
   // mapping for all virtual registers
-  unsigned LastVirtReg = MRI->getLastVirtReg();
-  StackSlotForVirtReg.grow(LastVirtReg);
+  StackSlotForVirtReg.resize(MRI->getNumVirtRegs());
 
   // Loop over all of the basic blocks, eliminating virtual register references
   for (MachineFunction::iterator MBBi = Fn.begin(), MBBe = Fn.end();

Modified: llvm/trunk/lib/CodeGen/VirtRegMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegMap.cpp?rev=123130&r1=123129&r2=123130&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/VirtRegMap.cpp (original)
+++ llvm/trunk/lib/CodeGen/VirtRegMap.cpp Sun Jan  9 15:58:20 2011
@@ -88,14 +88,14 @@
 }
 
 void VirtRegMap::grow() {
-  unsigned LastVirtReg = MF->getRegInfo().getLastVirtReg();
-  Virt2PhysMap.grow(LastVirtReg);
-  Virt2StackSlotMap.grow(LastVirtReg);
-  Virt2ReMatIdMap.grow(LastVirtReg);
-  Virt2SplitMap.grow(LastVirtReg);
-  Virt2SplitKillMap.grow(LastVirtReg);
-  ReMatMap.grow(LastVirtReg);
-  ImplicitDefed.resize(MF->getRegInfo().getNumVirtRegs());
+  unsigned NumRegs = MF->getRegInfo().getNumVirtRegs();
+  Virt2PhysMap.resize(NumRegs);
+  Virt2StackSlotMap.resize(NumRegs);
+  Virt2ReMatIdMap.resize(NumRegs);
+  Virt2SplitMap.resize(NumRegs);
+  Virt2SplitKillMap.resize(NumRegs);
+  ReMatMap.resize(NumRegs);
+  ImplicitDefed.resize(NumRegs);
 }
 
 unsigned VirtRegMap::createSpillSlot(const TargetRegisterClass *RC) {





More information about the llvm-commits mailing list