-// RemovePredecessorFromBlock - This function is called when we are about
-// to remove a predecessor from a basic block. This function takes care of
-// removing the predecessor from the PHI nodes in BB so that after the pred
-// is removed, the number of PHI slots per bb is equal to the number of
-// predecessors.
-//
-static void RemovePredecessorFromBlock(BasicBlock *BB, BasicBlock *Pred) {
- pred_iterator PI(pred_begin(BB)), EI(pred_end(BB));
- unsigned max_idx;
-
- //cerr << "RPFB: " << Pred << "From Block: " << BB;
-
- // Loop over the rest of the predecssors until we run out, or until we find
- // out that there are more than 2 predecessors.
- for (max_idx = 0; PI != EI && max_idx < 3; ++PI, ++max_idx) /*empty*/;
-
- // If there are exactly two predecessors, then we want to nuke the PHI nodes
- // altogether.
- bool NukePHIs = max_idx == 2;
- assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
-
- // Okay, now we know that we need to remove predecessor #pred_idx from all
- // PHI nodes. Iterate over each PHI node fixing them up
- BasicBlock::iterator II(BB->begin());
- for (; (*II)->isPHINode(); ++II) {
- PHINode *PN = (PHINode*)*II;
- PN->removeIncomingValue(BB);
-
- if (NukePHIs) { // Destroy the PHI altogether??
- assert(PN->getOperand(1) == 0 && "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(II);
- }
- }
-}
-