Use live out sets for return values instead of imp_defs, which is cleaner and faster.
[oota-llvm.git] / lib / CodeGen / BranchFolding.cpp
index ef28c958859d82870906ae3e62d5e2ca95612897..cca9f93553c60a215ac0981eb8247364ca02eff3 100644 (file)
@@ -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(MBB);
+    MachineFunction::iterator FallThrough =next(MBB);
     assert(FallThrough != MBB->getParent()->end() &&
            "Fell off the end of the function!");
     while (!MBB->pred_empty()) {