Use newly added next() and prior() utility functions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11430 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
index cc019b4..a33d5c9 100644
--- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
+++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
@@ -514,7 +514,7 @@
     for (MachineBasicBlock::iterator MII = MBB.begin(); MII != MBB.end(); ++MII)
       if (unsigned delaySlots =
           TM.getInstrInfo().getNumDelaySlots(MII->getOpcode())) { 
-          MachineBasicBlock::iterator DelaySlotMI = MII; ++DelaySlotMI;
+          MachineBasicBlock::iterator DelaySlotMI = next(MII);
           assert(DelaySlotMI != MBB.end() && "no instruction for delay slot");
           
           // Check the 2 conditions above:
@@ -552,8 +552,7 @@
           else {
             // For non-branch instr with delay slots (probably a call), move
             // InstrAfter to the instr. in the last delay slot.
-            MachineBasicBlock::iterator tmp = MII;
-            std::advance(tmp, delaySlots);
+            MachineBasicBlock::iterator tmp = next(MII, delaySlots);
             move2DelayedInstr(MII, tmp);
           }
       }
@@ -646,8 +645,7 @@
   // include all live variables before that branch or return -- we don't want to
   // trample those!  Verify that the set is included in the LV set before MInst.
   if (MII != MBB.begin()) {
-    MachineBasicBlock::iterator PredMI = MII;
-    --PredMI;
+    MachineBasicBlock::iterator PredMI = prior(MII);
     if (unsigned DS = TM.getInstrInfo().getNumDelaySlots(PredMI->getOpcode()))
       assert(set_difference(LVI->getLiveVarSetBeforeMInst(PredMI), LVSetBef)
              .empty() && "Live-var set before branch should be included in "
diff --git a/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp b/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp
index d8a5515..dc56100 100644
--- a/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp
+++ b/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp
@@ -19,6 +19,7 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
+#include "Support/STLExtras.h"
 
 namespace llvm {
 
@@ -31,7 +32,7 @@
   // Check if this instruction is in a delay slot of its predecessor.
   if (BBI != mvec.begin()) {
       const TargetInstrInfo& mii = target.getInstrInfo();
-      MachineBasicBlock::iterator predMI = BBI; --predMI;
+      MachineBasicBlock::iterator predMI = prior(BBI);
       if (unsigned ndelay = mii.getNumDelaySlots(predMI->getOpcode())) {
         // This instruction is in a delay slot of its predecessor, so
         // replace it with a nop. By replacing in place, we save having
diff --git a/lib/Target/X86/FloatingPoint.cpp b/lib/Target/X86/FloatingPoint.cpp
index 53f6ec0..28517c3 100644
--- a/lib/Target/X86/FloatingPoint.cpp
+++ b/lib/Target/X86/FloatingPoint.cpp
@@ -42,6 +42,7 @@
 #include "Support/Debug.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/Statistic.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 #include <set>
 using namespace llvm;
@@ -199,11 +200,8 @@
       continue;  // Efficiently ignore non-fp insts!
 
     MachineInstr *PrevMI = 0;
-    if (I != BB.begin()) {
-        MachineBasicBlock::iterator tmp = I;
-        --tmp;
-        PrevMI = tmp;
-    }
+    if (I != BB.begin())
+        PrevMI = prior(I);
 
     ++NumFP;  // Keep track of # of pseudo instrs
     DEBUG(std::cerr << "\nFPInst:\t";
diff --git a/lib/Target/X86/PeepholeOptimizer.cpp b/lib/Target/X86/PeepholeOptimizer.cpp
index f09e8d7..0c159e1 100644
--- a/lib/Target/X86/PeepholeOptimizer.cpp
+++ b/lib/Target/X86/PeepholeOptimizer.cpp
@@ -16,6 +16,8 @@
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include "Support/Statistic.h"
+#include "Support/STLExtras.h"
+
 using namespace llvm;
 
 namespace {
@@ -51,7 +53,7 @@
 bool PH::PeepholeOptimize(MachineBasicBlock &MBB,
 			  MachineBasicBlock::iterator &I) {
   assert(I != MBB.end());
-  MachineBasicBlock::iterator NextI = I; ++NextI;
+  MachineBasicBlock::iterator NextI = next(I);
 
   MachineInstr *MI = I;
   MachineInstr *Next = (NextI != MBB.end()) ? &*NextI : (MachineInstr*)0;
@@ -376,7 +378,7 @@
 
 bool SSAPH::PeepholeOptimize(MachineBasicBlock &MBB,
                              MachineBasicBlock::iterator &I) {
-  MachineBasicBlock::iterator NextI = I; ++NextI;
+    MachineBasicBlock::iterator NextI = next(I);
 
   MachineInstr *MI = I;
   MachineInstr *Next = (NextI != MBB.end()) ? &*NextI : (MachineInstr*)0;
diff --git a/lib/Target/X86/X86FloatingPoint.cpp b/lib/Target/X86/X86FloatingPoint.cpp
index 53f6ec0..28517c3 100644
--- a/lib/Target/X86/X86FloatingPoint.cpp
+++ b/lib/Target/X86/X86FloatingPoint.cpp
@@ -42,6 +42,7 @@
 #include "Support/Debug.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/Statistic.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 #include <set>
 using namespace llvm;
@@ -199,11 +200,8 @@
       continue;  // Efficiently ignore non-fp insts!
 
     MachineInstr *PrevMI = 0;
-    if (I != BB.begin()) {
-        MachineBasicBlock::iterator tmp = I;
-        --tmp;
-        PrevMI = tmp;
-    }
+    if (I != BB.begin())
+        PrevMI = prior(I);
 
     ++NumFP;  // Keep track of # of pseudo instrs
     DEBUG(std::cerr << "\nFPInst:\t";
diff --git a/lib/Target/X86/X86PeepholeOpt.cpp b/lib/Target/X86/X86PeepholeOpt.cpp
index f09e8d7..0c159e1 100644
--- a/lib/Target/X86/X86PeepholeOpt.cpp
+++ b/lib/Target/X86/X86PeepholeOpt.cpp
@@ -16,6 +16,8 @@
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include "Support/Statistic.h"
+#include "Support/STLExtras.h"
+
 using namespace llvm;
 
 namespace {
@@ -51,7 +53,7 @@
 bool PH::PeepholeOptimize(MachineBasicBlock &MBB,
 			  MachineBasicBlock::iterator &I) {
   assert(I != MBB.end());
-  MachineBasicBlock::iterator NextI = I; ++NextI;
+  MachineBasicBlock::iterator NextI = next(I);
 
   MachineInstr *MI = I;
   MachineInstr *Next = (NextI != MBB.end()) ? &*NextI : (MachineInstr*)0;
@@ -376,7 +378,7 @@
 
 bool SSAPH::PeepholeOptimize(MachineBasicBlock &MBB,
                              MachineBasicBlock::iterator &I) {
-  MachineBasicBlock::iterator NextI = I; ++NextI;
+    MachineBasicBlock::iterator NextI = next(I);
 
   MachineInstr *MI = I;
   MachineInstr *Next = (NextI != MBB.end()) ? &*NextI : (MachineInstr*)0;
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index 3031762..b2bf61a 100644
--- a/lib/Target/X86/X86RegisterInfo.cpp
+++ b/lib/Target/X86/X86RegisterInfo.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetFrameInfo.h"
 #include "Support/CommandLine.h"
+#include "Support/STLExtras.h"
 
 namespace llvm {
 
@@ -223,7 +224,7 @@
                                   MachineBasicBlock &MBB) const {
   unsigned oldSize = MBB.size();
   const MachineFrameInfo *MFI = MF.getFrameInfo();
-  MachineBasicBlock::iterator MBBI = MBB.end(); --MBBI;
+  MachineBasicBlock::iterator MBBI = prior(MBB.end());
   MachineInstr *MI;
   assert(MBBI->getOpcode() == X86::RET &&
          "Can only insert epilog into returning blocks");