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

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



Changes in directory llvm/lib/CodeGen:

RegAllocIterativeScan.cpp updated: 1.16 -> 1.17
---
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.


---
Diffs of the changes:  (+15 -4)

Index: llvm/lib/CodeGen/RegAllocIterativeScan.cpp
diff -u llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.16 llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.17
--- llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.16	Wed Sep  1 17:55:35 2004
+++ llvm/lib/CodeGen/RegAllocIterativeScan.cpp	Thu Sep  2 16:24:33 2004
@@ -463,17 +463,28 @@
 
 }
 
-unsigned RA::getFreePhysReg(IntervalPtrs::value_type cur)
+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::createIterativeScanRegisterAllocator() {






More information about the llvm-commits mailing list