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

Chris Lattner lattner at cs.uiuc.edu
Fri Sep 1 22:33:08 PDT 2006



Changes in directory llvm/lib/CodeGen:

LiveIntervalAnalysis.cpp updated: 1.180 -> 1.181
---
Log message:

Iteration is required for some cases, even if they don't occur in crafty.
Restore it, which re-fixes X86/2006-08-21-ExtraMovInst.ll


---
Diffs of the changes:  (+24 -13)

 LiveIntervalAnalysis.cpp |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)


Index: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp
diff -u llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.180 llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.181
--- llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.180	Sat Sep  2 00:26:59 2006
+++ llvm/lib/CodeGen/LiveIntervalAnalysis.cpp	Sat Sep  2 00:32:53 2006
@@ -883,12 +883,6 @@
   return ThisValNoAssignments[VN] = UltimateVN;
 }
 
-Statistic<> A("x", "a");
-Statistic<> B("x", "b");
-Statistic<> C("x", "c");
-Statistic<> D("x", "d");
-
-
 static bool InVector(unsigned Val, const SmallVector<unsigned, 8> &V) {
   return std::find(V.begin(), V.end(), Val) != V.end();
 }
@@ -1048,13 +1042,11 @@
       } else {
         RHSValNoInfo = RHS.getValNumInfo(0);
       }
-      ++A;
     } else {
       // It was defined as a copy from the LHS, find out what value # it is.
       unsigned ValInst = RHS.getInstForValNum(0);
       RHSValID = LHS.getLiveRangeContaining(ValInst-1)->ValId;
       RHSValNoInfo = LHS.getValNumInfo(RHSValID);
-      ++B;
     }
     
     LHSValNoAssignments.resize(LHS.getNumValNums(), -1);
@@ -1093,7 +1085,6 @@
     RHSValNoAssignments[0] = RHSValID;
     
   } else {
-    ++D;
     // Loop over the value numbers of the LHS, seeing if any are defined from
     // the RHS.
     SmallVector<int, 16> LHSValsDefinedFromRHS;
@@ -1223,7 +1214,8 @@
 }
 
 
-void LiveIntervals::CopyCoallesceInMBB(MachineBasicBlock *MBB) {
+void LiveIntervals::CopyCoallesceInMBB(MachineBasicBlock *MBB,
+                                       std::vector<CopyRec> &TryAgain) {
   DEBUG(std::cerr << ((Value*)MBB->getBasicBlock())->getName() << ":\n");
   
   for (MachineBasicBlock::iterator MII = MBB->begin(), E = MBB->end();
@@ -1234,7 +1226,8 @@
     unsigned SrcReg, DstReg;
     if (!tii_->isMoveInstr(*Inst, SrcReg, DstReg)) continue;
     
-    JoinCopy(Inst, SrcReg, DstReg);
+    if (!JoinCopy(Inst, SrcReg, DstReg))
+      TryAgain.push_back(getCopyRec(Inst, SrcReg, DstReg));
   }
 }
 
@@ -1242,12 +1235,14 @@
 void LiveIntervals::joinIntervals() {
   DEBUG(std::cerr << "********** JOINING INTERVALS ***********\n");
 
+  std::vector<CopyRec> TryAgainList;
+  
   const LoopInfo &LI = getAnalysis<LoopInfo>();
   if (LI.begin() == LI.end()) {
     // If there are no loops in the function, join intervals in function order.
     for (MachineFunction::iterator I = mf_->begin(), E = mf_->end();
          I != E; ++I)
-      CopyCoallesceInMBB(I);
+      CopyCoallesceInMBB(I, TryAgainList);
   } else {
     // Otherwise, join intervals in inner loops before other intervals.
     // Unfortunately we can't just iterate over loop hierarchy here because
@@ -1262,7 +1257,23 @@
 
     // Finally, join intervals in loop nest order.
     for (unsigned i = 0, e = MBBs.size(); i != e; ++i)
-      CopyCoallesceInMBB(MBBs[i].second);
+      CopyCoallesceInMBB(MBBs[i].second, TryAgainList);
+  }
+  
+  // Joining intervals can allow other intervals to be joined.  Iteratively join
+  // until we make no progress.
+  bool ProgressMade = true;
+  while (ProgressMade) {
+    ProgressMade = false;
+
+    for (unsigned i = 0, e = TryAgainList.size(); i != e; ++i) {
+      CopyRec &TheCopy = TryAgainList[i];
+      if (TheCopy.MI &&
+          JoinCopy(TheCopy.MI, TheCopy.SrcReg, TheCopy.DstReg)) {
+        TheCopy.MI = 0;   // Mark this one as done.
+        ProgressMade = true;
+      }
+    }
   }
   
   DEBUG(std::cerr << "*** Register mapping ***\n");






More information about the llvm-commits mailing list