- ++I;
- } while ((*I)->isPHINode());
-}
-
-
-// SimplifyCFG - This function is used to do simplification of a CFG. For
-// example, it adjusts branches to branches to eliminate the extra hop, it
-// eliminates unreachable basic blocks, and does other "peephole" optimization
-// of the CFG. It returns true if a modification was made, and returns an
-// iterator that designates the first element remaining after the block that
-// was deleted.
-//
-// WARNING: The entry node of a method may not be simplified.
-//
-bool opt::SimplifyCFG(Method::iterator &BBIt) {
- assert(*BBIt && (*BBIt)->getParent() && "Block not embedded in method!");
- BasicBlock *BB = *BBIt;
- Method *M = BB->getParent();
- assert(BB->getTerminator() && "Degenerate basic block encountered!");
- assert(BB->getParent()->front() != BB && "Can't Simplify entry block!");
-
- // Remove basic blocks that have no predecessors... which are unreachable.
- if (pred_begin(BB) == pred_end(BB) &&
- !BB->hasConstantPoolReferences()) {
- //cerr << "Removing BB: \n" << BB;
-
- // Loop through all of our successors and make sure they know that one
- // of their predecessors is going away.
- for_each(succ_begin(BB), succ_end(BB),
- std::bind2nd(std::mem_fun(&BasicBlock::removePredecessor), BB));
-
- while (!BB->empty()) {
- Instruction *I = BB->back();
- // If this instruction is used, replace uses with an arbitrary
- // constant value. Because control flow can't get here, we don't care
- // what we replace the value with. Note that since this block is
- // unreachable, and all values contained within it must dominate their
- // uses, that all uses will eventually be removed.
- if (!I->use_empty()) ReplaceUsesWithConstant(I);
-
- // Remove the instruction from the basic block
- delete BB->getInstList().pop_back();
- }
- delete M->getBasicBlocks().remove(BBIt);
- return true;
- }