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

Alkis Evlogimenos alkis at cs.uiuc.edu
Wed Dec 24 09:46:02 PST 2003


Changes in directory llvm/lib/CodeGen:

LiveIntervals.cpp updated: 1.15 -> 1.16

---
Log message:

Do a separate pass to compute spill weights because doing it inline
with live intervals was missing registers that were used before they
were defined (in the arbitrary order live intervals numbers
instructions).


---
Diffs of the changes:  (+27 -10)

Index: llvm/lib/CodeGen/LiveIntervals.cpp
diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.15 llvm/lib/CodeGen/LiveIntervals.cpp:1.16
--- llvm/lib/CodeGen/LiveIntervals.cpp:1.15	Mon Dec 22 07:54:29 2003
+++ llvm/lib/CodeGen/LiveIntervals.cpp	Wed Dec 24 09:44:53 2003
@@ -106,6 +106,33 @@
 
     computeIntervals();
 
+    // compute spill weights
+    const LoopInfo& loopInfo = getAnalysis<LoopInfo>();
+
+    for (MbbIndex2MbbMap::iterator
+             it = mbbi2mbbMap_.begin(), itEnd = mbbi2mbbMap_.end();
+         it != itEnd; ++it) {
+        MachineBasicBlock* mbb = it->second;
+
+        unsigned loopDepth = loopInfo.getLoopDepth(mbb->getBasicBlock());
+
+        for (MachineBasicBlock::iterator mi = mbb->begin(), miEnd = mbb->end();
+             mi != miEnd; ++mi) {
+            MachineInstr* instr = *mi;
+            for (int i = instr->getNumOperands() - 1; i >= 0; --i) {
+                MachineOperand& mop = instr->getOperand(i);
+
+                if (!mop.isVirtualRegister())
+                    continue;
+
+                unsigned reg = mop.getAllocatedRegNum();
+                Reg2IntervalMap::iterator r2iit = r2iMap_.find(reg);
+                assert(r2iit != r2iMap_.end());
+                intervals_[r2iit->second].weight += pow(10.0F, loopDepth);
+            }
+        }
+    }
+
     return true;
 }
 
@@ -255,8 +282,6 @@
 {
     DEBUG(std::cerr << "computing live intervals:\n");
 
-    const LoopInfo& loopInfo = getAnalysis<LoopInfo>();
-
     for (MbbIndex2MbbMap::iterator
              it = mbbi2mbbMap_.begin(), itEnd = mbbi2mbbMap_.end();
          it != itEnd; ++it) {
@@ -264,8 +289,6 @@
         DEBUG(std::cerr << "machine basic block: "
               << mbb->getBasicBlock()->getName() << "\n");
 
-        unsigned loopDepth = loopInfo.getLoopDepth(mbb->getBasicBlock());
-
         for (MachineBasicBlock::iterator mi = mbb->begin(), miEnd = mbb->end();
              mi != miEnd; ++mi) {
             MachineInstr* instr = *mi;
@@ -296,12 +319,6 @@
                     else
                         handleVirtualRegisterDef(mbb, mi, reg);
                 }
-
-                // update weights
-                Reg2IntervalMap::iterator r2iit = r2iMap_.find(reg);
-                if (r2iit != r2iMap_.end() &&
-                    reg >= MRegisterInfo::FirstVirtualRegister)
-                    intervals_[r2iit->second].weight += pow(10.0F, loopDepth);
             }
         }
     }





More information about the llvm-commits mailing list