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

Alkis Evlogimenos alkis at cs.uiuc.edu
Sun Dec 28 11:59:01 PST 2003


Changes in directory llvm/lib/CodeGen:

RegAllocLinearScan.cpp updated: 1.19 -> 1.20
LiveIntervals.cpp updated: 1.16 -> 1.17

---
Log message:

Add coalescing to register allocator. A hint is added to each interval
which denotes the register we would like to be assigned to (virtual or
physical). In register allocation, if this hint exists and we can map
it to a physical register (it is either a physical register or it is a
virtual register that already got assigned to a physical one) we use
that register if it is available instead of a random one in the free
pool.


---
Diffs of the changes:  (+29 -2)

Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.19 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.20
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.19	Wed Dec 24 12:53:31 2003
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp	Sun Dec 28 11:58:18 2003
@@ -615,8 +615,19 @@
 unsigned RA::getFreePhysReg(Intervals::const_iterator cur)
 {
     DEBUG(std::cerr << "\t\tgetting free physical register: ");
-
     const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(cur->reg);
+
+    if (unsigned reg = cur->hint) {
+        if (reg >= MRegisterInfo::FirstVirtualRegister &&
+            v2pMap_.find(reg) != v2pMap_.end())
+            reg = v2pMap_[reg];
+        if (reg && reg < MRegisterInfo::FirstVirtualRegister &&
+            mri_->getRegClass(reg) == rc && !regUse_[reg]) {
+            DEBUG(std::cerr << mri_->getName(reg) << '\n');
+            return reg;
+        }
+    }
+            
     for (TargetRegisterClass::iterator i = rc->allocation_order_begin(*mf_);
          i != rc->allocation_order_end(*mf_); ++i) {
         unsigned reg = *i;


Index: llvm/lib/CodeGen/LiveIntervals.cpp
diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.16 llvm/lib/CodeGen/LiveIntervals.cpp:1.17
--- llvm/lib/CodeGen/LiveIntervals.cpp:1.16	Wed Dec 24 09:44:53 2003
+++ llvm/lib/CodeGen/LiveIntervals.cpp	Sun Dec 28 11:58:18 2003
@@ -108,6 +108,7 @@
 
     // compute spill weights
     const LoopInfo& loopInfo = getAnalysis<LoopInfo>();
+    const TargetInstrInfo& tii = tm_->getInstrInfo();
 
     for (MbbIndex2MbbMap::iterator
              it = mbbi2mbbMap_.begin(), itEnd = mbbi2mbbMap_.end();
@@ -130,6 +131,21 @@
                 assert(r2iit != r2iMap_.end());
                 intervals_[r2iit->second].weight += pow(10.0F, loopDepth);
             }
+
+            // add hints for coalescing
+            unsigned src, dst;
+            if (tii.isMoveInstr(*instr, src, dst)) {
+                if (src >= MRegisterInfo::FirstVirtualRegister) {
+                    Reg2IntervalMap::iterator r2iit = r2iMap_.find(src);
+                    assert(r2iit != r2iMap_.end());
+                    intervals_[r2iit->second].hint = dst;
+                }
+                if (dst >= MRegisterInfo::FirstVirtualRegister) {
+                    Reg2IntervalMap::iterator r2iit = r2iMap_.find(dst);
+                    assert(r2iit != r2iMap_.end());
+                    intervals_[r2iit->second].hint = src;
+                }
+            }
         }
     }
 
@@ -329,7 +345,7 @@
 }
 
 LiveIntervals::Interval::Interval(unsigned r)
-    : reg(r),
+    : reg(r), hint(0),
       weight((r < MRegisterInfo::FirstVirtualRegister ?
               std::numeric_limits<float>::max() : 0.0F))
 {





More information about the llvm-commits mailing list