[llvm-commits] CVS: llvm/lib/CodeGen/VirtRegMap.cpp VirtRegMap.h

Chris Lattner lattner at cs.uiuc.edu
Wed Sep 29 19:15:31 PDT 2004



Changes in directory llvm/lib/CodeGen:

VirtRegMap.cpp updated: 1.20 -> 1.21
VirtRegMap.h updated: 1.14 -> 1.15
---
Log message:

Use longer and more explicit names for instance vars (particularly important
data structures).  Fix the print method to send to the right ostream, not 
always cerr.  Delete typedefs that are only used once.


---
Diffs of the changes:  (+46 -50)

Index: llvm/lib/CodeGen/VirtRegMap.cpp
diff -u llvm/lib/CodeGen/VirtRegMap.cpp:1.20 llvm/lib/CodeGen/VirtRegMap.cpp:1.21
--- llvm/lib/CodeGen/VirtRegMap.cpp:1.20	Wed Sep 29 20:54:45 2004
+++ llvm/lib/CodeGen/VirtRegMap.cpp	Wed Sep 29 21:15:18 2004
@@ -52,64 +52,62 @@
 //===----------------------------------------------------------------------===//
 
 void VirtRegMap::grow() {
-  v2pMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
-  v2ssMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
+  Virt2PhysMap.grow(MF.getSSARegMap()->getLastVirtReg());
+  Virt2StackSlotMap.grow(MF.getSSARegMap()->getLastVirtReg());
 }
 
 int VirtRegMap::assignVirt2StackSlot(unsigned virtReg) {
   assert(MRegisterInfo::isVirtualRegister(virtReg));
-  assert(v2ssMap_[virtReg] == NO_STACK_SLOT &&
+  assert(Virt2StackSlotMap[virtReg] == NO_STACK_SLOT &&
          "attempt to assign stack slot to already spilled register");
-  const TargetRegisterClass* RC = mf_->getSSARegMap()->getRegClass(virtReg);
-  int frameIndex = mf_->getFrameInfo()->CreateStackObject(RC->getSize(),
-                                                          RC->getAlignment());
-  v2ssMap_[virtReg] = frameIndex;
+  const TargetRegisterClass* RC = MF.getSSARegMap()->getRegClass(virtReg);
+  int frameIndex = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
+                                                        RC->getAlignment());
+  Virt2StackSlotMap[virtReg] = frameIndex;
   ++NumSpills;
   return frameIndex;
 }
 
 void VirtRegMap::assignVirt2StackSlot(unsigned virtReg, int frameIndex) {
   assert(MRegisterInfo::isVirtualRegister(virtReg));
-  assert(v2ssMap_[virtReg] == NO_STACK_SLOT &&
+  assert(Virt2StackSlotMap[virtReg] == NO_STACK_SLOT &&
          "attempt to assign stack slot to already spilled register");
-  v2ssMap_[virtReg] = frameIndex;
+  Virt2StackSlotMap[virtReg] = frameIndex;
 }
 
 void VirtRegMap::virtFolded(unsigned virtReg,
                             MachineInstr* oldMI,
                             MachineInstr* newMI) {
   // move previous memory references folded to new instruction
-  MI2VirtMap::iterator i, e;
-  std::vector<MI2VirtMap::mapped_type> regs;
-  for (tie(i, e) = mi2vMap_.equal_range(oldMI); i != e; ) {
+  MI2VirtMapTy::iterator i, e;
+  std::vector<MI2VirtMapTy::mapped_type> regs;
+  for (tie(i, e) = MI2VirtMap.equal_range(oldMI); i != e; ) {
     regs.push_back(i->second);
-    mi2vMap_.erase(i++);
+    MI2VirtMap.erase(i++);
   }
   for (unsigned i = 0, e = regs.size(); i != e; ++i)
-    mi2vMap_.insert(std::make_pair(newMI, i));
+    MI2VirtMap.insert(std::make_pair(newMI, i));
 
   // add new memory reference
-  mi2vMap_.insert(std::make_pair(newMI, virtReg));
+  MI2VirtMap.insert(std::make_pair(newMI, virtReg));
 }
 
-void VirtRegMap::print(std::ostream& os) const {
-  const MRegisterInfo* mri = mf_->getTarget().getRegisterInfo();
+void VirtRegMap::print(std::ostream &OS) const {
+  const MRegisterInfo* MRI = MF.getTarget().getRegisterInfo();
 
-  std::cerr << "********** REGISTER MAP **********\n";
+  OS << "********** REGISTER MAP **********\n";
   for (unsigned i = MRegisterInfo::FirstVirtualRegister,
-         e = mf_->getSSARegMap()->getLastVirtReg(); i <= e; ++i) {
-    if (v2pMap_[i] != (unsigned)VirtRegMap::NO_PHYS_REG)
-      std::cerr << "[reg" << i << " -> "
-                << mri->getName(v2pMap_[i]) << "]\n";
+         e = MF.getSSARegMap()->getLastVirtReg(); i <= e; ++i) {
+    if (Virt2PhysMap[i] != (unsigned)VirtRegMap::NO_PHYS_REG)
+      OS << "[reg" << i << " -> " << MRI->getName(Virt2PhysMap[i]) << "]\n";
+         
   }
 
   for (unsigned i = MRegisterInfo::FirstVirtualRegister,
-         e = mf_->getSSARegMap()->getLastVirtReg(); i <= e; ++i) {
-    if (v2ssMap_[i] != VirtRegMap::NO_STACK_SLOT)
-      std::cerr << "[reg" << i << " -> fi#"
-                << v2ssMap_[i] << "]\n";
-  }
-  std::cerr << '\n';
+         e = MF.getSSARegMap()->getLastVirtReg(); i <= e; ++i)
+    if (Virt2StackSlotMap[i] != VirtRegMap::NO_STACK_SLOT)
+      OS << "[reg" << i << " -> fi#" << Virt2StackSlotMap[i] << "]\n";
+  OS << '\n';
 }
 
 void VirtRegMap::dump() const { print(std::cerr); }
@@ -133,7 +131,7 @@
   DEBUG(std::cerr << "********** Function: "
                   << MF.getFunction()->getName() << '\n');
   const TargetMachine& TM = MF.getTarget();
-  const MRegisterInfo& mri = *TM.getRegisterInfo();
+  const MRegisterInfo& MRI = *TM.getRegisterInfo();
 
   DenseMap<bool, VirtReg2IndexFunctor> Loaded;
 
@@ -151,7 +149,7 @@
           unsigned physReg = VRM.getPhys(virtReg);
           if (mop.isUse() && VRM.hasStackSlot(mop.getReg()) &&
               !Loaded[virtReg]) {
-            mri.loadRegFromStackSlot(*mbbi, mii, physReg,
+            MRI.loadRegFromStackSlot(*mbbi, mii, physReg,
                                      VRM.getStackSlot(virtReg));
             Loaded[virtReg] = true;
             DEBUG(std::cerr << '\t';
@@ -160,7 +158,7 @@
           }
 
           if (mop.isDef() && VRM.hasStackSlot(mop.getReg())) {
-            mri.storeRegToStackSlot(*mbbi, next(mii), physReg,
+            MRI.storeRegToStackSlot(*mbbi, next(mii), physReg,
                                     VRM.getStackSlot(virtReg));
             ++NumStores;
           }
@@ -304,7 +302,7 @@
     // if we have references to memory operands make sure
     // we clear all physical registers that may contain
     // the value of the spilled virtual register
-    VirtRegMap::MI2VirtMap::const_iterator i, e;
+    VirtRegMap::MI2VirtMapTy::const_iterator i, e;
     for (tie(i, e) = VRM->getFoldedVirts(MI); i != e; ++i) {
       if (VRM->hasPhys(i->second))
         vacateJustPhysReg(MBB, MI, VRM->getPhys(i->second));


Index: llvm/lib/CodeGen/VirtRegMap.h
diff -u llvm/lib/CodeGen/VirtRegMap.h:1.14 llvm/lib/CodeGen/VirtRegMap.h:1.15
--- llvm/lib/CodeGen/VirtRegMap.h:1.14	Wed Sep 29 20:54:45 2004
+++ llvm/lib/CodeGen/VirtRegMap.h	Wed Sep 29 21:15:18 2004
@@ -26,15 +26,13 @@
 
   class VirtRegMap {
   public:
-    typedef DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
-    typedef DenseMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
-    typedef std::multimap<MachineInstr*, unsigned> MI2VirtMap;
+    typedef std::multimap<MachineInstr*, unsigned> MI2VirtMapTy;
 
   private:
-    MachineFunction* mf_;
-    Virt2PhysMap v2pMap_;
-    Virt2StackSlotMap v2ssMap_;
-    MI2VirtMap mi2vMap_;
+    MachineFunction &MF;
+    DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
+    DenseMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
+    MI2VirtMapTy MI2VirtMap;
     
     VirtRegMap(const VirtRegMap&);     // DO NOT IMPLEMENT
     void operator=(const VirtRegMap&); // DO NOT IMPLEMENT
@@ -45,8 +43,8 @@
     };
 
   public:
-    VirtRegMap(MachineFunction& mf)
-      : mf_(&mf), v2pMap_(NO_PHYS_REG), v2ssMap_(NO_STACK_SLOT) {
+    VirtRegMap(MachineFunction &mf)
+      : MF(mf), Virt2PhysMap(NO_PHYS_REG), Virt2StackSlotMap(NO_STACK_SLOT) {
       grow();
     }
 
@@ -58,27 +56,27 @@
 
     unsigned getPhys(unsigned virtReg) const {
       assert(MRegisterInfo::isVirtualRegister(virtReg));
-      return v2pMap_[virtReg];
+      return Virt2PhysMap[virtReg];
     }
 
     void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
       assert(MRegisterInfo::isVirtualRegister(virtReg) &&
              MRegisterInfo::isPhysicalRegister(physReg));
-      assert(v2pMap_[virtReg] == NO_PHYS_REG &&
+      assert(Virt2PhysMap[virtReg] == NO_PHYS_REG &&
              "attempt to assign physical register to already mapped "
              "virtual register");
-      v2pMap_[virtReg] = physReg;
+      Virt2PhysMap[virtReg] = physReg;
     }
 
     void clearVirt(unsigned virtReg) {
       assert(MRegisterInfo::isVirtualRegister(virtReg));
-      assert(v2pMap_[virtReg] != NO_PHYS_REG &&
+      assert(Virt2PhysMap[virtReg] != NO_PHYS_REG &&
              "attempt to clear a not assigned virtual register");
-      v2pMap_[virtReg] = NO_PHYS_REG;
+      Virt2PhysMap[virtReg] = NO_PHYS_REG;
     }
 
     void clearAllVirt() {
-      v2pMap_.clear();
+      Virt2PhysMap.clear();
       grow();
     }
 
@@ -88,7 +86,7 @@
 
     int getStackSlot(unsigned virtReg) const {
       assert(MRegisterInfo::isVirtualRegister(virtReg));
-      return v2ssMap_[virtReg];
+      return Virt2StackSlotMap[virtReg];
     }
 
     int assignVirt2StackSlot(unsigned virtReg);
@@ -97,9 +95,9 @@
     void virtFolded(unsigned virtReg, MachineInstr* oldMI,
                     MachineInstr* newMI);
 
-    std::pair<MI2VirtMap::const_iterator, MI2VirtMap::const_iterator>
+    std::pair<MI2VirtMapTy::const_iterator, MI2VirtMapTy::const_iterator>
     getFoldedVirts(MachineInstr* MI) const {
-      return mi2vMap_.equal_range(MI);
+      return MI2VirtMap.equal_range(MI);
     }
 
     void print(std::ostream &OS) const;






More information about the llvm-commits mailing list