#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 {
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());
// 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());
}
-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()) {