-static bool RemoveSingularPHIs(BasicBlock *BB) {
- BasicBlock::pred_iterator PI(BB->pred_begin());
- if (PI == BB->pred_end() || ++PI != BB->pred_end())
- return false; // More than one predecessor...
-
- Instruction *I = BB->front();
- if (!isa<PHINode>(I)) return false; // No PHI nodes
-
- //cerr << "Killing PHIs from " << BB;
- //cerr << "Pred #0 = " << *BB->pred_begin();
-
- //cerr << "Method == " << BB->getParent();
-
- do {
- PHINode *PN = cast<PHINode>(I);
- assert(PN->getNumOperands() == 2 && "PHI node should only have one value!");
- Value *V = PN->getOperand(0);
-
- PN->replaceAllUsesWith(V); // Replace PHI node with its single value.
- delete BB->getInstList().remove(BB->begin());
-
- I = BB->front();
- } while (isa<PHINode>(I));
-
- return true; // Yes, we nuked at least one phi node
-}
-
-static void ReplaceUsesWithConstant(Instruction *I) {
- ConstPoolVal *CPV = ConstPoolVal::getNullConstant(I->getType());
-
- // Make all users of this instruction reference the constant instead
- I->replaceAllUsesWith(CPV);
-}
-
-// PropogatePredecessors - This gets "Succ" ready to have the predecessors from
-// "BB". This is a little tricky because "Succ" has PHI nodes, which need to
-// have extra slots added to them to hold the merge edges from BB's
-// predecessors. This function returns true (failure) if the Succ BB already
-// has a predecessor that is a predecessor of BB.
-//
-// Assumption: Succ is the single successor for BB.
-//
-static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
- assert(*BB->succ_begin() == Succ && "Succ is not successor of BB!");
- assert(isa<PHINode>(Succ->front()) && "Only works on PHId BBs!");
-
- // If there is more than one predecessor, and there are PHI nodes in
- // the successor, then we need to add incoming edges for the PHI nodes
- //
- const vector<BasicBlock*> BBPreds(BB->pred_begin(), BB->pred_end());