Remove MachineRegisterInfo::getLastVirtReg(), it was giving wrong results
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Sun, 9 Jan 2011 21:58:20 +0000 (21:58 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Sun, 9 Jan 2011 21:58:20 +0000 (21:58 +0000)
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.

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

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

index 04c5815e35f2b460950dde69ff3c1fae9e7452d6..87126ea49187bc577f2b4793270b74c1a3f65693 100644 (file)
@@ -59,6 +59,10 @@ namespace llvm {
       storage_.reserve(s);
     }
 
+    void resize(typename StorageT::size_type s) {
+      storage_.resize(s, nullVal_);
+    }
+
     void clear() {
       storage_.clear();
     }
@@ -66,7 +70,7 @@ namespace llvm {
     void grow(IndexT n) {
       unsigned NewSize = toIndex_(n) + 1;
       if (NewSize > storage_.size())
-        storage_.resize(NewSize, nullVal_);
+        resize(NewSize);
     }
 
     bool inBounds(IndexT n) const {
index 02242b1feaf5c75d5322bfc52534f4938e89ba96..0ae1065351df6f5384e921bfdec1ae04f494146e 100644 (file)
@@ -216,12 +216,6 @@ public:
   ///
   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> &
index 109da42e9c3d92538ab79f68f18a4a109a2d87ce..6666d9aaf40a45fc618435877231c77ca00da7ee 100644 (file)
@@ -1024,8 +1024,7 @@ bool RAFast::runOnMachineFunction(MachineFunction &Fn) {
 
   // 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();
index bc295ef30cab20c48b6c7dcbbc415bb3bf7e6fba..df8a021d14ad7b2cb91b69307cfa23b7ace1419a 100644 (file)
@@ -88,14 +88,14 @@ bool VirtRegMap::runOnMachineFunction(MachineFunction &mf) {
 }
 
 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) {