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

Chris Lattner lattner at cs.uiuc.edu
Sun Jul 18 22:15:20 PDT 2004



Changes in directory llvm/lib/CodeGen:

LiveIntervals.cpp updated: 1.90 -> 1.91

---
Log message:

See comments.  The live intervals were not coming out of the spiller in sorted
order, causing the inactive list in the linearscan list to get unsorted, which
basically fuxored everything up severely.  

These seems to fix the joiner, so with more testing I will enable it by default.



---
Diffs of the changes:  (+20 -1)

Index: llvm/lib/CodeGen/LiveIntervals.cpp
diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.90 llvm/lib/CodeGen/LiveIntervals.cpp:1.91
--- llvm/lib/CodeGen/LiveIntervals.cpp:1.90	Sun Jul 18 21:15:56 2004
+++ llvm/lib/CodeGen/LiveIntervals.cpp	Mon Jul 19 00:15:10 2004
@@ -185,6 +185,16 @@
     return true;
 }
 
+namespace {
+    /// CompareIntervalStar - This is a simple comparison function for interval
+    /// pointers.  It compares based on their starting point.
+    struct CompareIntervalStar {
+        bool operator()(LiveInterval *LHS, LiveInterval* RHS) const {
+            return LHS->start() < RHS->start();
+        }
+    };
+}
+
 std::vector<LiveInterval*> LiveIntervals::addIntervalsForSpills(
     const LiveInterval& li,
     VirtRegMap& vrm,
@@ -210,7 +220,7 @@
             MachineBasicBlock::iterator mi = getInstructionFromIndex(index);
 
         for_operand:
-            for (unsigned i = 0; i < mi->getNumOperands(); ++i) {
+            for (unsigned i = 0; i != mi->getNumOperands(); ++i) {
                 MachineOperand& mop = mi->getOperand(i);
                 if (mop.isRegister() && mop.getReg() == li.reg) {
                     if (MachineInstr* fmi =
@@ -267,6 +277,15 @@
         }
     }
 
+    // FIXME: This method MUST return intervals in sorted order.  If a 
+    // particular machine instruction both uses and defines the vreg being
+    // spilled (e.g.,  vr = vr + 1) and if the def is processed before the
+    // use, the list ends up not sorted.
+    //
+    // The proper way to fix this is to process all uses of the vreg before we 
+    // process any defs.  However, this would require refactoring the above 
+    // blob of code, which I'm not feeling up to right now.
+    std::sort(added.begin(), added.end(), CompareIntervalStar());
     return added;
 }
 





More information about the llvm-commits mailing list