[llvm-commits] [llvm] r137380 - in /llvm/trunk/lib/CodeGen: LiveIntervalUnion.cpp LiveIntervalUnion.h

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Aug 11 15:46:04 PDT 2011


Author: stoklund
Date: Thu Aug 11 17:46:04 2011
New Revision: 137380

URL: http://llvm.org/viewvc/llvm-project?rev=137380&view=rev
Log:
Eliminate the last use of InterferenceResult.

The Query class now holds two iterators instead of an InterferenceResult
instance. The iterators are used as bookmarks for repeated
collectInterferingVRegs calls.

Modified:
    llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
    llvm/trunk/lib/CodeGen/LiveIntervalUnion.h

Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp?rev=137380&r1=137379&r2=137380&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp Thu Aug 11 17:46:04 2011
@@ -117,68 +117,35 @@
 //
 // Assumes that segments are sorted by start position in both
 // LiveInterval and LiveSegments.
-void LiveIntervalUnion::Query::findIntersection(InterferenceResult &IR) const {
+void LiveIntervalUnion::Query::findIntersection() {
   // Search until reaching the end of the LiveUnion segments.
   LiveInterval::iterator VirtRegEnd = VirtReg->end();
-  if (IR.VirtRegI == VirtRegEnd)
+  if (VirtRegI == VirtRegEnd)
     return;
-  while (IR.LiveUnionI.valid()) {
+  while (LiveUnionI.valid()) {
     // Slowly advance the live virtual reg iterator until we surpass the next
     // segment in LiveUnion.
     //
     // Note: If this is ever used for coalescing of fixed registers and we have
     // a live vreg with thousands of segments, then change this code to use
     // upperBound instead.
-    IR.VirtRegI = VirtReg->advanceTo(IR.VirtRegI, IR.LiveUnionI.start());
-    if (IR.VirtRegI == VirtRegEnd)
+    VirtRegI = VirtReg->advanceTo(VirtRegI, LiveUnionI.start());
+    if (VirtRegI == VirtRegEnd)
       break; // Retain current (nonoverlapping) LiveUnionI
 
     // VirtRegI may have advanced far beyond LiveUnionI, catch up.
-    IR.LiveUnionI.advanceTo(IR.VirtRegI->start);
+    LiveUnionI.advanceTo(VirtRegI->start);
 
     // Check if no LiveUnionI exists with VirtRegI->Start < LiveUnionI.end
-    if (!IR.LiveUnionI.valid())
+    if (!LiveUnionI.valid())
       break;
-    if (IR.LiveUnionI.start() < IR.VirtRegI->end) {
-      assert(overlap(*IR.VirtRegI, IR.LiveUnionI) &&
-             "upperBound postcondition");
+    if (LiveUnionI.start() < VirtRegI->end) {
+      assert(overlap(*VirtRegI, LiveUnionI) && "upperBound postcondition");
       break;
     }
   }
-  if (!IR.LiveUnionI.valid())
-    IR.VirtRegI = VirtRegEnd;
-}
-
-// Find the first intersection, and cache interference info
-// (retain segment iterators into both VirtReg and LiveUnion).
-const LiveIntervalUnion::InterferenceResult &
-LiveIntervalUnion::Query::firstInterference() {
-  if (CheckedFirstInterference)
-    return FirstInterference;
-  CheckedFirstInterference = true;
-  InterferenceResult &IR = FirstInterference;
-  IR.LiveUnionI.setMap(LiveUnion->getMap());
-
-  // Quickly skip interference check for empty sets.
-  if (VirtReg->empty() || LiveUnion->empty()) {
-    IR.VirtRegI = VirtReg->end();
-  } else if (VirtReg->beginIndex() < LiveUnion->startIndex()) {
-    // VirtReg starts first, perform double binary search.
-    IR.VirtRegI = VirtReg->find(LiveUnion->startIndex());
-    if (IR.VirtRegI != VirtReg->end())
-      IR.LiveUnionI.find(IR.VirtRegI->start);
-  } else {
-    // LiveUnion starts first, perform double binary search.
-    IR.LiveUnionI.find(VirtReg->beginIndex());
-    if (IR.LiveUnionI.valid())
-      IR.VirtRegI = VirtReg->find(IR.LiveUnionI.start());
-    else
-      IR.VirtRegI = VirtReg->end();
-  }
-  findIntersection(FirstInterference);
-  assert((IR.VirtRegI == VirtReg->end() || IR.LiveUnionI.valid())
-         && "Uninitialized iterator");
-  return FirstInterference;
+  if (!LiveUnionI.valid())
+    VirtRegI = VirtRegEnd;
 }
 
 // Scan the vector of interfering virtual registers in this union. Assume it's
@@ -200,37 +167,64 @@
 // For comments on how to speed it up, see Query::findIntersection().
 unsigned LiveIntervalUnion::Query::
 collectInterferingVRegs(unsigned MaxInterferingRegs) {
-  if (InterferingVRegs.size() >= MaxInterferingRegs)
+  // Fast path return if we already have the desired information.
+  if (SeenAllInterferences || InterferingVRegs.size() >= MaxInterferingRegs)
     return InterferingVRegs.size();
-  InterferenceResult IR = firstInterference();
+
+  // Set up iterators on the first call.
+  if (!CheckedFirstInterference) {
+    CheckedFirstInterference = true;
+    LiveUnionI.setMap(LiveUnion->getMap());
+
+    // Quickly skip interference check for empty sets.
+    if (VirtReg->empty() || LiveUnion->empty()) {
+      VirtRegI = VirtReg->end();
+    } else if (VirtReg->beginIndex() < LiveUnion->startIndex()) {
+      // VirtReg starts first, perform double binary search.
+      VirtRegI = VirtReg->find(LiveUnion->startIndex());
+      if (VirtRegI != VirtReg->end())
+        LiveUnionI.find(VirtRegI->start);
+    } else {
+      // LiveUnion starts first, perform double binary search.
+      LiveUnionI.find(VirtReg->beginIndex());
+      if (LiveUnionI.valid())
+        VirtRegI = VirtReg->find(LiveUnionI.start());
+      else
+        VirtRegI = VirtReg->end();
+    }
+    findIntersection();
+    assert((VirtRegI == VirtReg->end() || LiveUnionI.valid())
+           && "Uninitialized iterator");
+  }
+
   LiveInterval::iterator VirtRegEnd = VirtReg->end();
   LiveInterval *RecentInterferingVReg = NULL;
-  if (IR.VirtRegI != VirtRegEnd) while (IR.LiveUnionI.valid()) {
+  if (VirtRegI != VirtRegEnd) while (LiveUnionI.valid()) {
     // Advance the union's iterator to reach an unseen interfering vreg.
     do {
-      if (IR.LiveUnionI.value() == RecentInterferingVReg)
+      if (LiveUnionI.value() == RecentInterferingVReg)
         continue;
 
-      if (!isSeenInterference(IR.LiveUnionI.value()))
+      if (!isSeenInterference(LiveUnionI.value()))
         break;
 
       // Cache the most recent interfering vreg to bypass isSeenInterference.
-      RecentInterferingVReg = IR.LiveUnionI.value();
+      RecentInterferingVReg = LiveUnionI.value();
 
-    } while ((++IR.LiveUnionI).valid());
-    if (!IR.LiveUnionI.valid())
+    } while ((++LiveUnionI).valid());
+    if (!LiveUnionI.valid())
       break;
 
     // Advance the VirtReg iterator until surpassing the next segment in
     // LiveUnion.
-    IR.VirtRegI = VirtReg->advanceTo(IR.VirtRegI, IR.LiveUnionI.start());
-    if (IR.VirtRegI == VirtRegEnd)
+    VirtRegI = VirtReg->advanceTo(VirtRegI, LiveUnionI.start());
+    if (VirtRegI == VirtRegEnd)
       break;
 
     // Check for intersection with the union's segment.
-    if (overlap(*IR.VirtRegI, IR.LiveUnionI)) {
+    if (overlap(*VirtRegI, LiveUnionI)) {
 
-      if (!IR.LiveUnionI.value()->isSpillable())
+      if (!LiveUnionI.value()->isSpillable())
         SeenUnspillableVReg = true;
 
       if (InterferingVRegs.size() == MaxInterferingRegs)
@@ -238,17 +232,17 @@
         // interference exists beyond those we collected.
         return MaxInterferingRegs;
 
-      InterferingVRegs.push_back(IR.LiveUnionI.value());
+      InterferingVRegs.push_back(LiveUnionI.value());
 
       // Cache the most recent interfering vreg to bypass isSeenInterference.
-      RecentInterferingVReg = IR.LiveUnionI.value();
-      ++IR.LiveUnionI;
+      RecentInterferingVReg = LiveUnionI.value();
+      ++LiveUnionI;
 
       continue;
     }
     // VirtRegI may have advanced far beyond LiveUnionI,
     // do a fast intersection test to "catch up"
-    IR.LiveUnionI.advanceTo(IR.VirtRegI->start);
+    LiveUnionI.advanceTo(VirtRegI->start);
   }
   SeenAllInterferences = true;
   return InterferingVRegs.size();

Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.h?rev=137380&r1=137379&r2=137380&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.h (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.h Thu Aug 11 17:46:04 2011
@@ -142,7 +142,8 @@
   class Query {
     LiveIntervalUnion *LiveUnion;
     LiveInterval *VirtReg;
-    InterferenceResult FirstInterference;
+    LiveInterval::iterator VirtRegI; // current position in VirtReg
+    SegmentIter LiveUnionI;          // current position in LiveUnion
     SmallVector<LiveInterval*,4> InterferingVRegs;
     bool CheckedFirstInterference;
     bool SeenAllInterferences;
@@ -217,8 +218,7 @@
     void operator=(const Query&); // DO NOT IMPLEMENT
 
     // Private interface for queries
-    const InterferenceResult &firstInterference();
-    void findIntersection(InterferenceResult &IR) const;
+    void findIntersection();
   };
 };
 





More information about the llvm-commits mailing list