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

Chris Lattner lattner at cs.uiuc.edu
Thu Oct 20 00:39:36 PDT 2005



Changes in directory llvm/lib/CodeGen:

LiveInterval.cpp updated: 1.23 -> 1.24
---
Log message:

add a new method, play around with some code.

Fix a *bug* in the extendIntervalEndTo method.  In particular, if adding
[2:10) to an interval containing [0:2),[10:30), we produced [0:10),[10,30).
Which is not the most smart thing to do.  Now produce [0:30).


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

 LiveInterval.cpp |   66 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 56 insertions(+), 10 deletions(-)


Index: llvm/lib/CodeGen/LiveInterval.cpp
diff -u llvm/lib/CodeGen/LiveInterval.cpp:1.23 llvm/lib/CodeGen/LiveInterval.cpp:1.24
--- llvm/lib/CodeGen/LiveInterval.cpp:1.23	Thu Oct 20 01:06:30 2005
+++ llvm/lib/CodeGen/LiveInterval.cpp	Thu Oct 20 02:39:25 2005
@@ -104,20 +104,19 @@
 /// NontrivialOverlap - Check to see if the two live ranges specified by i and j
 /// overlap.  If so, check to see if they have value numbers that are not 
 /// iIdx/jIdx respectively.  If both conditions are true, return true.
-static inline bool NontrivialOverlap(LiveInterval::Ranges::const_iterator i,
-                                     LiveInterval::Ranges::const_iterator j,
+static inline bool NontrivialOverlap(const LiveRange &I, const LiveRange &J,
                                      unsigned iIdx, unsigned jIdx) {
-  if (i->start == j->start) {
+  if (I.start == J.start) {
     // If this is not the allowed value merge, we cannot join.
-    if (i->ValId != iIdx || j->ValId != jIdx)
+    if (I.ValId != iIdx || J.ValId != jIdx)
       return true;
-  } else if (i->start < j->start) {
-    if (i->end > j->start && i->ValId != iIdx || j->ValId != jIdx) {
+  } else if (I.start < J.start) {
+    if (I.end > J.start && I.ValId != iIdx || J.ValId != jIdx) {
       return true;
     }
   } else {
-    if (j->end > i->start &&
-        i->ValId != iIdx || j->ValId != jIdx)
+    if (J.end > I.start &&
+        I.ValId != iIdx || J.ValId != jIdx)
       return true;
   }
   
@@ -148,7 +147,7 @@
   }
 
   while (i != ie && j != je) {
-    if (NontrivialOverlap(i, j, ThisValIdx, OtherValIdx))
+    if (NontrivialOverlap(*i, *j, ThisValIdx, OtherValIdx))
       return false;
     
     if (i->end < j->end)
@@ -160,6 +159,43 @@
   return true;
 }
 
+/// getOverlapingRanges - Given another live interval which is defined as a
+/// copy from this one, return a list of all of the live ranges where the
+/// two overlap and have different value numbers.
+void LiveInterval::getOverlapingRanges(const LiveInterval &other, 
+                                       unsigned CopyIdx,
+                                       std::vector<LiveRange*> &Ranges) {
+  const LiveRange *SourceLR = other.getLiveRangeContaining(CopyIdx-1);
+  const LiveRange *DestLR = getLiveRangeContaining(CopyIdx);
+  assert(SourceLR && DestLR && "Not joining due to a copy?");
+  unsigned OtherValIdx = SourceLR->ValId;
+  unsigned ThisValIdx = DestLR->ValId;
+  
+  Ranges::iterator i = ranges.begin();
+  Ranges::iterator ie = ranges.end();
+  Ranges::const_iterator j = other.ranges.begin();
+  Ranges::const_iterator je = other.ranges.end();
+  
+  if (i->start < j->start) {
+    i = std::upper_bound(i, ie, j->start);
+    if (i != ranges.begin()) --i;
+  } else if (j->start < i->start) {
+    j = std::upper_bound(j, je, i->start);
+    if (j != other.ranges.begin()) --j;
+  }
+  
+  while (i != ie && j != je) {
+    if (NontrivialOverlap(*i, *j, ThisValIdx, OtherValIdx))
+      Ranges.push_back(&*i);
+    
+    if (i->end < j->end)
+      ++i;
+    else
+      ++j;
+  }
+}
+
+
 
 /// extendIntervalEndTo - This method is used when we want to extend the range
 /// specified by I to end at the specified endpoint.  To do this, we should
@@ -178,8 +214,18 @@
   // If NewEnd was in the middle of an interval, make sure to get its endpoint.
   I->end = std::max(NewEnd, prior(MergeTo)->end);
 
-  // Erase any dead ranges
+  // Erase any dead ranges.
   ranges.erase(next(I), MergeTo);
+  
+  // If the newly formed range now touches the range after it and if they have
+  // the same value number, merge the two ranges into one range.
+  if (I != ranges.end()) {
+    Ranges::iterator Next = next(I);
+    if (Next->start == I->end && Next->ValId == ValId) {
+      I->end = Next->end;
+      ranges.erase(Next);
+    }
+  }
 }
 
 






More information about the llvm-commits mailing list