Return live range end points from SplitEditor::enter*/leave*.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Thu, 3 Feb 2011 17:04:16 +0000 (17:04 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Thu, 3 Feb 2011 17:04:16 +0000 (17:04 +0000)
These end points come from the inserted copies, and can be passed directly to
useIntv. This simplifies the coloring code.

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

lib/CodeGen/RegAllocGreedy.cpp
lib/CodeGen/SplitKit.cpp
lib/CodeGen/SplitKit.h

index d970c7d16a7aca67bf1e1aac60423615f2565ac3..730bddb8b00f3a83dc212a02661f699ff310594f 100644 (file)
@@ -680,16 +680,14 @@ void RAGreedy::splitAroundRegion(LiveInterval &VirtReg, unsigned PhysReg,
       }
       if (!BI.LiveThrough) {
         DEBUG(dbgs() << ", not live-through.\n");
-        SE.enterIntvBefore(BI.Def);
-        SE.useIntv(BI.Def, Stop);
+        SE.useIntv(SE.enterIntvBefore(BI.Def), Stop);
         continue;
       }
       if (!RegIn) {
         // Block is live-through, but entry bundle is on the stack.
         // Reload just before the first use.
         DEBUG(dbgs() << ", not live-in, enter before first use.\n");
-        SE.enterIntvBefore(BI.FirstUse);
-        SE.useIntv(BI.FirstUse, Stop);
+        SE.useIntv(SE.enterIntvBefore(BI.FirstUse), Stop);
         continue;
       }
       DEBUG(dbgs() << ", live-through.\n");
@@ -713,8 +711,7 @@ void RAGreedy::splitAroundRegion(LiveInterval &VirtReg, unsigned PhysReg,
       SlotIndex Use = *UI;
       DEBUG(dbgs() << ", free use at " << Use << ".\n");
       assert(Use <= BI.LastUse && "Couldn't find last use");
-      SE.enterIntvBefore(Use);
-      SE.useIntv(Use, Stop);
+      SE.useIntv(SE.enterIntvBefore(Use), Stop);
       continue;
     }
 
@@ -759,16 +756,14 @@ void RAGreedy::splitAroundRegion(LiveInterval &VirtReg, unsigned PhysReg,
       }
       if (!BI.LiveThrough) {
         DEBUG(dbgs() << ", killed in block.\n");
-        SE.useIntv(Start, BI.Kill.getBoundaryIndex());
-        SE.leaveIntvAfter(BI.Kill);
+        SE.useIntv(Start, SE.leaveIntvAfter(BI.Kill));
         continue;
       }
       if (!RegOut) {
         // Block is live-through, but exit bundle is on the stack.
         // Spill immediately after the last use.
         DEBUG(dbgs() << ", uses, stack-out.\n");
-        SE.useIntv(Start, BI.LastUse.getBoundaryIndex());
-        SE.leaveIntvAfter(BI.LastUse);
+        SE.useIntv(Start, SE.leaveIntvAfter(BI.LastUse));
         continue;
       }
       // Register is live-through.
@@ -794,8 +789,7 @@ void RAGreedy::splitAroundRegion(LiveInterval &VirtReg, unsigned PhysReg,
       SlotIndex Use = (--UI)->getBoundaryIndex();
       DEBUG(dbgs() << ", free use at " << *UI << ".\n");
       assert(Use >= BI.FirstUse && Use < IP.first);
-      SE.useIntv(Start, Use);
-      SE.leaveIntvAfter(Use);
+      SE.useIntv(Start, SE.leaveIntvAfter(Use));
       continue;
     }
 
@@ -875,6 +869,8 @@ unsigned RAGreedy::trySplit(LiveInterval &VirtReg, AllocationOrder &Order,
     SmallVector<LiveInterval*, 4> SpillRegs;
     LiveRangeEdit LREdit(VirtReg, NewVRegs, SpillRegs);
     SplitEditor(*SA, *LIS, *VRM, *DomTree, LREdit).splitSingleBlocks(Blocks);
+    if (VerifyEnabled)
+      MF->verify(this, "After splitting live range around basic blocks");
   }
 
   // Don't assign any physregs.
index 0ec983ec13f6ea97dca030b43020d27bbf2ac901..a1c9ced332c27bda87927bf7de35b560afa76760 100644 (file)
@@ -776,12 +776,6 @@ VNInfo *SplitEditor::defFromParent(unsigned RegIdx,
 
   // Add minimal liveness for the new value.
   Edit.get(RegIdx)->addRange(LiveRange(Def, Def.getNextSlot(), VNI));
-
-  if (RegIdx) {
-    if (UseIdx < Def)
-      UseIdx = Def;
-    RegAssign.insert(Def, UseIdx.getNextSlot(), RegIdx);
-  }
   return VNI;
 }
 
@@ -803,38 +797,39 @@ void SplitEditor::openIntv() {
   LIMappers[OpenIdx].reset(Edit.get(OpenIdx));
 }
 
-/// enterIntvBefore - Enter OpenLI before the instruction at Idx. If CurLI is
-/// not live before Idx, a COPY is not inserted.
-void SplitEditor::enterIntvBefore(SlotIndex Idx) {
+SlotIndex SplitEditor::enterIntvBefore(SlotIndex Idx) {
   assert(OpenIdx && "openIntv not called before enterIntvBefore");
-  Idx = Idx.getUseIndex();
   DEBUG(dbgs() << "    enterIntvBefore " << Idx);
+  Idx = Idx.getBaseIndex();
   VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Idx);
   if (!ParentVNI) {
     DEBUG(dbgs() << ": not live\n");
-    return;
+    return Idx;
   }
-  DEBUG(dbgs() << ": valno " << ParentVNI->id);
+  DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
   MachineInstr *MI = LIS.getInstructionFromIndex(Idx);
   assert(MI && "enterIntvBefore called with invalid index");
 
-  defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(), MI);
-  DEBUG(dump());
+  VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(), MI);
+  return VNI->def;
 }
 
-/// enterIntvAtEnd - Enter OpenLI at the end of MBB.
-void SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) {
+SlotIndex SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) {
   assert(OpenIdx && "openIntv not called before enterIntvAtEnd");
-  SlotIndex End = LIS.getMBBEndIdx(&MBB).getPrevSlot();
-  DEBUG(dbgs() << "    enterIntvAtEnd BB#" << MBB.getNumber() << ", " << End);
-  VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(End);
+  SlotIndex End = LIS.getMBBEndIdx(&MBB);
+  SlotIndex Last = End.getPrevSlot();
+  DEBUG(dbgs() << "    enterIntvAtEnd BB#" << MBB.getNumber() << ", " << Last);
+  VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Last);
   if (!ParentVNI) {
     DEBUG(dbgs() << ": not live\n");
-    return;
+    return End;
   }
   DEBUG(dbgs() << ": valno " << ParentVNI->id);
-  defFromParent(OpenIdx, ParentVNI, End, MBB, MBB.getFirstTerminator());
+  VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Last, MBB,
+                              MBB.getFirstTerminator());
+  RegAssign.insert(VNI->def, End, OpenIdx);
   DEBUG(dump());
+  return VNI->def;
 }
 
 /// useIntv - indicate that all instructions in MBB should use OpenLI.
@@ -849,8 +844,7 @@ void SplitEditor::useIntv(SlotIndex Start, SlotIndex End) {
   DEBUG(dump());
 }
 
-/// leaveIntvAfter - Leave OpenLI after the instruction at Idx.
-void SplitEditor::leaveIntvAfter(SlotIndex Idx) {
+SlotIndex SplitEditor::leaveIntvAfter(SlotIndex Idx) {
   assert(OpenIdx && "openIntv not called before leaveIntvAfter");
   DEBUG(dbgs() << "    leaveIntvAfter " << Idx);
 
@@ -859,21 +853,17 @@ void SplitEditor::leaveIntvAfter(SlotIndex Idx) {
   VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Idx);
   if (!ParentVNI) {
     DEBUG(dbgs() << ": not live\n");
-    return;
+    return Idx.getNextSlot();
   }
-  DEBUG(dbgs() << ": valno " << ParentVNI->id);
+  DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
 
   MachineBasicBlock::iterator MII = LIS.getInstructionFromIndex(Idx);
   VNInfo *VNI = defFromParent(0, ParentVNI, Idx,
                               *MII->getParent(), llvm::next(MII));
-
-  RegAssign.insert(Idx, VNI->def, OpenIdx);
-  DEBUG(dump());
+  return VNI->def;
 }
 
-/// leaveIntvAtTop - Leave the interval at the top of MBB.
-/// Currently, only one value can leave the interval.
-void SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
+SlotIndex SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
   assert(OpenIdx && "openIntv not called before leaveIntvAtTop");
   SlotIndex Start = LIS.getMBBStartIdx(&MBB);
   DEBUG(dbgs() << "    leaveIntvAtTop BB#" << MBB.getNumber() << ", " << Start);
@@ -881,13 +871,14 @@ void SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
   VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Start);
   if (!ParentVNI) {
     DEBUG(dbgs() << ": not live\n");
-    return;
+    return Start;
   }
 
   VNInfo *VNI = defFromParent(0, ParentVNI, Start, MBB,
                               MBB.SkipPHIsAndLabels(MBB.begin()));
   RegAssign.insert(Start, VNI->def, OpenIdx);
   DEBUG(dump());
+  return VNI->def;
 }
 
 /// closeIntv - Indicate that we are done editing the currently open
@@ -1148,9 +1139,7 @@ void SplitEditor::splitSingleBlocks(const SplitAnalysis::BlockPtrSet &Blocks) {
     assert(IP.first.isValid() && IP.second.isValid());
 
     openIntv();
-    enterIntvBefore(IP.first);
-    useIntv(IP.first.getBaseIndex(), IP.second.getBoundaryIndex());
-    leaveIntvAfter(IP.second);
+    useIntv(enterIntvBefore(IP.first), leaveIntvAfter(IP.second));
     closeIntv();
   }
   finish();
@@ -1211,18 +1200,14 @@ void SplitEditor::splitInsideBlock(const MachineBasicBlock *MBB) {
   // First interval before the gap. Don't create single-instr intervals.
   if (bestPos > 1) {
     openIntv();
-    enterIntvBefore(Uses.front());
-    useIntv(Uses.front().getBaseIndex(), Uses[bestPos-1].getBoundaryIndex());
-    leaveIntvAfter(Uses[bestPos-1]);
+    useIntv(enterIntvBefore(Uses.front()), leaveIntvAfter(Uses[bestPos-1]));
     closeIntv();
   }
 
   // Second interval after the gap.
   if (bestPos < Uses.size()-1) {
     openIntv();
-    enterIntvBefore(Uses[bestPos]);
-    useIntv(Uses[bestPos].getBaseIndex(), Uses.back().getBoundaryIndex());
-    leaveIntvAfter(Uses.back());
+    useIntv(enterIntvBefore(Uses[bestPos]), leaveIntvAfter(Uses.back()));
     closeIntv();
   }
 
index 5e9b96b62906b04bb81731f810ae963c536b285d..205341c19c800ec95931f94b30c8109b2b44a690 100644 (file)
@@ -352,12 +352,15 @@ public:
   /// Create a new virtual register and live interval.
   void openIntv();
 
-  /// enterIntvBefore - Enter OpenLI before the instruction at Idx. If CurLI is
-  /// not live before Idx, a COPY is not inserted.
-  void enterIntvBefore(SlotIndex Idx);
+  /// enterIntvBefore - Enter the open interval before the instruction at Idx.
+  /// If the parent interval is not live before Idx, a COPY is not inserted.
+  /// Return the beginning of the new live range.
+  SlotIndex enterIntvBefore(SlotIndex Idx);
 
-  /// enterIntvAtEnd - Enter OpenLI at the end of MBB.
-  void enterIntvAtEnd(MachineBasicBlock &MBB);
+  /// enterIntvAtEnd - Enter the open interval at the end of MBB.
+  /// Use the open interval from he inserted copy to the MBB end.
+  /// Return the beginning of the new live range.
+  SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB);
 
   /// useIntv - indicate that all instructions in MBB should use OpenLI.
   void useIntv(const MachineBasicBlock &MBB);
@@ -365,12 +368,14 @@ public:
   /// useIntv - indicate that all instructions in range should use OpenLI.
   void useIntv(SlotIndex Start, SlotIndex End);
 
-  /// leaveIntvAfter - Leave OpenLI after the instruction at Idx.
-  void leaveIntvAfter(SlotIndex Idx);
+  /// leaveIntvAfter - Leave the open interval after the instruction at Idx.
+  /// Return the end of the live range.
+  SlotIndex leaveIntvAfter(SlotIndex Idx);
 
   /// leaveIntvAtTop - Leave the interval at the top of MBB.
-  /// Currently, only one value can leave the interval.
-  void leaveIntvAtTop(MachineBasicBlock &MBB);
+  /// Add liveness from the MBB top to the copy.
+  /// Return the end of the live range.
+  SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB);
 
   /// closeIntv - Indicate that we are done editing the currently open
   /// LiveInterval, and ranges can be trimmed.