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

Alkis Evlogimenos alkis at cs.uiuc.edu
Thu Sep 2 14:23:43 PDT 2004



Changes in directory llvm/lib/CodeGen:

RegAllocLinearScan.cpp updated: 1.93 -> 1.94
---
Log message:

Change the way we choose a free register: instead of picking the first
free allocatable register, we prefer the a free one with the most uses
of inactive intervals. This causes less spills and performes a bit
better compared to gcc:

Program                 | GCC/LLC (Before)| GCC/LLC (After) 
164.gzip/164.gzip       | 0.59            | 0.60            
175.vpr/175.vpr         | 0.57            | 0.58            
176.gcc/176.gcc         | 0.59            | 0.61            
181.mcf/181.mcf         | 0.94            | 0.95            
186.crafty/186.crafty   | 0.62            | 0.62            
197.parser/197.parser   | 0.89            | 0.88            
252.eon/252.eon         | 0.61            | 0.66            
253.perlbmk/253.perlbmk | 0.79            | 0.84            
254.gap/254.gap         | 0.81            | 0.81            
255.vortex/255.vortex   | 0.92            | 0.93            
256.bzip2/256.bzip2     | 0.69            | 0.69            
300.twolf/300.twolf     | 0.91            | 0.90


---
Diffs of the changes:  (+14 -3)

Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.93 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.94
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.93	Thu Sep  2 13:00:38 2004
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp	Thu Sep  2 16:23:32 2004
@@ -522,15 +522,26 @@
 
 unsigned RA::getFreePhysReg(LiveInterval* cur)
 {
+  std::vector<unsigned> inactiveCounts(mri_->getNumRegs(), 0);
+  for (IntervalPtrs::iterator i = inactive_.begin(), e = inactive_.end();
+       i != e; ++i) {
+    unsigned reg = (*i)->reg;
+    if (MRegisterInfo::isVirtualRegister(reg))
+      reg = vrm_->getPhys(reg);
+    ++inactiveCounts[reg];
+  }
+
   const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(cur->reg);
 
+  unsigned freeReg = 0;
   for (TargetRegisterClass::iterator i = rc->allocation_order_begin(*mf_);
        i != rc->allocation_order_end(*mf_); ++i) {
     unsigned reg = *i;
-    if (prt_->isRegAvail(reg))
-      return reg;
+    if (prt_->isRegAvail(reg) &&
+        (!freeReg || inactiveCounts[freeReg] < inactiveCounts[reg]))
+        freeReg = reg;
   }
-  return 0;
+  return freeReg;
 }
 
 FunctionPass* llvm::createLinearScanRegisterAllocator() {






More information about the llvm-commits mailing list