bool SimplifyCFGOpt::run(BasicBlock *BB) {
bool Changed = false;
- Function *M = BB->getParent();
+ Function *Fn = BB->getParent();
- assert(BB && BB->getParent() && "Block not embedded in function!");
+ assert(BB && Fn && "Block not embedded in function!");
assert(BB->getTerminator() && "Degenerate basic block encountered!");
// Remove basic blocks that have no predecessors (except the entry block)...
// or that just have themself as a predecessor. These are unreachable.
- if ((pred_begin(BB) == pred_end(BB) &&
- &BB->getParent()->getEntryBlock() != BB) ||
+ if ((pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) ||
BB->getSinglePredecessor() == BB) {
DEBUG(dbgs() << "Removing BB: \n" << *BB);
DeleteDeadBlock(BB);
// If we eliminated all predecessors of the block, delete the block now.
if (pred_begin(BB) == pred_end(BB))
// We know there are no successors, so just nuke the block.
- M->getBasicBlockList().erase(BB);
+ Fn->getBasicBlockList().erase(BB);
return true;
}
Preds.pop_back();
}
- // If this block is now dead, remove it.
- if (pred_begin(BB) == pred_end(BB)) {
+ // If this block is now dead (and isn't the entry block), remove it.
+ if (pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) {
// We know there are no successors, so just nuke the block.
- M->getBasicBlockList().erase(BB);
+ Fn->getBasicBlockList().erase(BB);
return true;
}
while (isa<DbgInfoIntrinsic>(BBI))
++BBI;
if (BBI->isTerminator()) // Terminator is the only non-phi instruction!
- if (BB != &BB->getParent()->getEntryBlock())
+ if (BB != &Fn->getEntryBlock())
if (TryToSimplifyUncondBranchFromEmptyBlock(BB))
return true;
}
// If this block is now dead, remove it.
- if (pred_begin(BB) == pred_end(BB) &&
- BB != &BB->getParent()->getEntryBlock()) {
+ if (pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) {
// We know there are no successors, so just nuke the block.
- M->getBasicBlockList().erase(BB);
+ Fn->getBasicBlockList().erase(BB);
return true;
}
}