[llvm] r175393 - Remove use of reverse iterators in repairIntervalsInRange(). While they were

Cameron Zwarich zwarich at apple.com
Sun Feb 17 03:09:01 PST 2013


Author: zwarich
Date: Sun Feb 17 05:09:00 2013
New Revision: 175393

URL: http://llvm.org/viewvc/llvm-project?rev=175393&view=rev
Log:
Remove use of reverse iterators in repairIntervalsInRange(). While they were
arguably better than forward iterators for this use case, they are confusing and
there are some implementation problems with reverse iterators and MI bundles.

Modified:
    llvm/trunk/include/llvm/CodeGen/LiveIntervalAnalysis.h
    llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
    llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp

Modified: llvm/trunk/include/llvm/CodeGen/LiveIntervalAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LiveIntervalAnalysis.h?rev=175393&r1=175392&r2=175393&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LiveIntervalAnalysis.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LiveIntervalAnalysis.h Sun Feb 17 05:09:00 2013
@@ -282,9 +282,9 @@ namespace llvm {
                               bool UpdateFlags = false);
 
     /// repairIntervalsInRange - Update live intervals for instructions in a
-    /// small range of reverse iterators. It is intended for use after target
-    /// hooks that may insert or remove instructions, and is only efficient for
-    /// a small number of instructions.
+    /// range of iterators. It is intended for use after target hooks that may
+    /// insert or remove instructions, and is only efficient for a small number
+    /// of instructions.
     ///
     /// OrigRegs is a vector of registers that were originally used by the
     /// instructions in the range between the two iterators.
@@ -292,8 +292,8 @@ namespace llvm {
     /// Currently, the only only changes that are supported are simple removal
     /// and addition of uses.
     void repairIntervalsInRange(MachineBasicBlock *MBB,
-                                MachineBasicBlock::reverse_iterator RBegin,
-                                MachineBasicBlock::reverse_iterator REnd,
+                                MachineBasicBlock::iterator Begin,
+                                MachineBasicBlock::iterator End,
                                 ArrayRef<unsigned> OrigRegs);
 
     // Register mask functions.

Modified: llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp?rev=175393&r1=175392&r2=175393&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp Sun Feb 17 05:09:00 2013
@@ -1035,19 +1035,24 @@ void LiveIntervals::handleMoveIntoBundle
 
 void
 LiveIntervals::repairIntervalsInRange(MachineBasicBlock *MBB,
-                                     MachineBasicBlock::reverse_iterator RBegin,
-                                     MachineBasicBlock::reverse_iterator REnd,
+                                      MachineBasicBlock::iterator Begin,
+                                      MachineBasicBlock::iterator End,
                                       ArrayRef<unsigned> OrigRegs) {
+  SlotIndex startIdx;
+  if (Begin == MBB->begin())
+    startIdx = getMBBStartIdx(MBB);
+  else
+    startIdx = getInstructionIndex(prior(Begin)).getRegSlot();
+
   for (unsigned i = 0, e = OrigRegs.size(); i != e; ++i) {
     unsigned Reg = OrigRegs[i];
     if (!TargetRegisterInfo::isVirtualRegister(Reg))
       continue;
 
     LiveInterval &LI = getInterval(Reg);
-    SlotIndex startIdx = (REnd == MBB->rend()) ? getMBBStartIdx(MBB)
-                                               : getInstructionIndex(&*REnd);
-    for (MachineBasicBlock::reverse_iterator I = RBegin; I != REnd; ++I) {
-      MachineInstr *MI = &*I;
+    for (MachineBasicBlock::iterator I = End; I != Begin;) {
+      --I;
+      MachineInstr *MI = I;
       SlotIndex instrIdx = getInstructionIndex(MI);
 
       for (MachineInstr::mop_iterator OI = MI->operands_begin(),
@@ -1059,7 +1064,7 @@ LiveIntervals::repairIntervalsInRange(Ma
         assert(MO.isUse() && "Register defs are not yet supported.");
 
         if (!LI.liveAt(instrIdx)) {
-          LiveRange *LR = LI.getLiveRangeContaining(startIdx.getRegSlot());
+          LiveRange *LR = LI.getLiveRangeContaining(startIdx);
           assert(LR && "Used registers must be live-in.");
           LR->end = instrIdx.getRegSlot();
           break;

Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=175393&r1=175392&r2=175393&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Sun Feb 17 05:09:00 2013
@@ -851,15 +851,7 @@ MachineBasicBlock::SplitCriticalEdge(Mac
 
     // Update all intervals for registers whose uses may have been modified by
     // updateTerminator().
-    iterator FirstTerminator = getFirstTerminator();
-    reverse_iterator PreTerminators;
-    if (FirstTerminator == begin())
-      PreTerminators = rend();
-    else if (FirstTerminator == end())
-      PreTerminators = rbegin();
-    else
-      PreTerminators = reverse_iterator(FirstTerminator);
-    LIS->repairIntervalsInRange(this, rbegin(), PreTerminators, UsedRegs);
+    LIS->repairIntervalsInRange(this, getFirstTerminator(), end(), UsedRegs);
   }
 
   if (MachineDominatorTree *MDT =





More information about the llvm-commits mailing list