Fix VC++ warnings.
[oota-llvm.git] / lib / CodeGen / BranchFolding.cpp
index a82cad27674709d91af408595cd0dcaacec27e72..a4b3b02ea4970d1984cb1dd10ee8c9ae58b38799 100644 (file)
@@ -1,10 +1,10 @@
 //===-- BranchFolding.cpp - Fold machine code branch instructions ---------===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 // This pass forwards branches to unconditional branches to make them branch
@@ -20,7 +20,7 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
-#include "Support/STLExtras.h"
+#include "llvm/ADT/STLExtras.h"
 using namespace llvm;
 
 namespace {
@@ -28,8 +28,8 @@ namespace {
     virtual bool runOnMachineFunction(MachineFunction &MF);
     virtual const char *getPassName() const { return "Branch Folder"; }
   private:
-    bool OptimizeBlock(MachineBasicBlock *MBB, const TargetInstrInfo &TII);
-
+    bool OptimizeBlock(MachineFunction::iterator MBB,
+                       const TargetInstrInfo &TII);
 
     bool isUncondBranch(const MachineInstr *MI, const TargetInstrInfo &TII) {
       return TII.isBarrier(MI->getOpcode()) && TII.isBranch(MI->getOpcode());
@@ -96,7 +96,7 @@ static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB,
 
   // If BB falls through into Old, insert an unconditional branch to New.
   MachineFunction::iterator BBSucc = BB; ++BBSucc;
-  if (&*BBSucc == Old)
+  if (BBSucc != BB->getParent()->end() && &*BBSucc == Old)
     TII.insertGoto(*BB, *New);
 
   std::vector<MachineBasicBlock*> Succs(BB->succ_begin(), BB->succ_end());
@@ -108,13 +108,13 @@ static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB,
 }
 
 
-bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB,
+bool BranchFolder::OptimizeBlock(MachineFunction::iterator MBB,
                                  const TargetInstrInfo &TII) {
   // If this block is empty, make everyone use it's fall-through, not the block
   // explicitly.
   if (MBB->empty()) {
     if (MBB->pred_empty()) return false;
-    MachineFunction::iterator FallThrough =next(MachineFunction::iterator(MBB));
+    MachineFunction::iterator FallThrough =next(MBB);
     assert(FallThrough != MBB->getParent()->end() &&
            "Fell off the end of the function!");
     while (!MBB->pred_empty()) {
@@ -158,7 +158,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB,
     assert(Br->getNumOperands() == 1 && Br->getOperand(0).isMachineBasicBlock()
            && "Uncond branch should take one MBB argument!");
     MachineBasicBlock *Dest = Br->getOperand(0).getMachineBasicBlock();
-    
+
     while (!MBB->pred_empty()) {
       MachineBasicBlock *Pred = *(MBB->pred_end()-1);
       ReplaceUsesOfBlockWith(Pred, MBB, Dest, TII);