Speed up LiveIntervalUnion::unify by handling end insertion specially.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Mon, 11 Apr 2011 15:00:44 +0000 (15:00 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Mon, 11 Apr 2011 15:00:44 +0000 (15:00 +0000)
This particularly helps with the initial transfer of fixed intervals.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129277 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/LiveIntervalUnion.cpp

index 205f28a0d65a4d0ebe17b9ed2c985352dabef5d5..51789998c6527c0ad4d468eed2b548cf94311943 100644 (file)
@@ -35,12 +35,20 @@ void LiveIntervalUnion::unify(LiveInterval &VirtReg) {
   LiveInterval::iterator RegEnd = VirtReg.end();
   SegmentIter SegPos = Segments.find(RegPos->start);
 
-  for (;;) {
+  while (SegPos.valid()) {
     SegPos.insert(RegPos->start, RegPos->end, &VirtReg);
     if (++RegPos == RegEnd)
       return;
     SegPos.advanceTo(RegPos->start);
   }
+
+  // We have reached the end of Segments, so it is no longer necessary to search
+  // for the insertion position.
+  // It is faster to insert the end first.
+  --RegEnd;
+  SegPos.insert(RegEnd->start, RegEnd->end, &VirtReg);
+  for (; RegPos != RegEnd; ++RegPos, ++SegPos)
+    SegPos.insert(RegPos->start, RegPos->end, &VirtReg);
 }
 
 // Remove a live virtual register's segments from this union.