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

Chris Lattner lattner at cs.uiuc.edu
Mon Aug 22 13:20:54 PDT 2005



Changes in directory llvm/lib/CodeGen:

RegAllocLinearScan.cpp updated: 1.109 -> 1.110
---
Log message:

Move some code in the register assignment case that only needs to happen if
we spill out of the fast path.  The scan of active_ and the calls to 
updateSpillWeights don't need to happen unless a spill occurs.  This reduces
debug llc time of kc++ with ppc from 187.3s to 183.2s.


---
Diffs of the changes:  (+26 -17)

 RegAllocLinearScan.cpp |   43 ++++++++++++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 17 deletions(-)


Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.109 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.110
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.109	Mon Aug 22 11:55:22 2005
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp	Mon Aug 22 15:20:42 2005
@@ -365,23 +365,11 @@
 
   PhysRegTracker backupPrt = *prt_;
 
-  std::vector<float> SpillWeights;
-  SpillWeights.assign(mri_->getNumRegs(), 0.0);
-
+  std::vector<std::pair<unsigned, float> > SpillWeightsToAdd;
   unsigned StartPosition = cur->beginNumber();
 
-  // for each interval in active, update spill weights.
-  for (IntervalPtrs::const_iterator i = active_.begin(), e = active_.end();
-       i != e; ++i) {
-    unsigned reg = i->first->reg;
-    assert(MRegisterInfo::isVirtualRegister(reg) &&
-           "Can only allocate virtual registers!");
-    reg = vrm_->getPhys(reg);
-    updateSpillWeights(SpillWeights, reg, i->first->weight, mri_);
-  }
-
   // for every interval in inactive we overlap with, mark the
-  // register as not free and update spill weights
+  // register as not free and update spill weights.
   for (IntervalPtrs::const_iterator i = inactive_.begin(),
          e = inactive_.end(); i != e; ++i) {
     if (cur->overlapsFrom(*i->first, i->second-1)) {
@@ -390,7 +378,7 @@
              "Can only allocate virtual registers!");
       reg = vrm_->getPhys(reg);
       prt_->addRegUse(reg);
-      updateSpillWeights(SpillWeights, reg, i->first->weight, mri_);
+      SpillWeightsToAdd.push_back(std::make_pair(reg, i->first->weight));
     }
   }
 
@@ -407,14 +395,19 @@
       if (cur->overlapsFrom(*I, II)) {
         unsigned reg = I->reg;
         prt_->addRegUse(reg);
-        updateSpillWeights(SpillWeights, reg, I->weight, mri_);
+        SpillWeightsToAdd.push_back(std::make_pair(reg, I->weight));
       }
     }
   }
 
+  // Using the newly updated prt_ object, which includes conflicts in the
+  // future, see if there are any registers available.
   unsigned physReg = getFreePhysReg(cur);
-  // restore the physical register tracker
+  
+  // Restore the physical register tracker, removing information about the
+  // future.
   *prt_ = backupPrt;
+  
   // if we find a free register, we are done: assign this virtual to
   // the free physical register and add this interval to the active
   // list.
@@ -428,6 +421,22 @@
   }
   DEBUG(std::cerr << "no free registers\n");
 
+  // Compile the spill weights into an array that is better for scanning.
+  std::vector<float> SpillWeights(mri_->getNumRegs(), 0.0);
+  for (std::vector<std::pair<unsigned, float> >::iterator
+       I = SpillWeightsToAdd.begin(), E = SpillWeightsToAdd.end(); I != E; ++I)
+    updateSpillWeights(SpillWeights, I->first, I->second, mri_);
+  
+  // for each interval in active, update spill weights.
+  for (IntervalPtrs::const_iterator i = active_.begin(), e = active_.end();
+       i != e; ++i) {
+    unsigned reg = i->first->reg;
+    assert(MRegisterInfo::isVirtualRegister(reg) &&
+           "Can only allocate virtual registers!");
+    reg = vrm_->getPhys(reg);
+    updateSpillWeights(SpillWeights, reg, i->first->weight, mri_);
+  }
+ 
   DEBUG(std::cerr << "\tassigning stack slot at interval "<< *cur << ":\n");
 
   float minWeight = float(HUGE_VAL);






More information about the llvm-commits mailing list