Move splitBlock into DomTreeBase from DomTree.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43059 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2007-10-17 02:03:17 +00:00
parent 16a04f3f20
commit 05d2318fbd
3 changed files with 106 additions and 87 deletions

View File

@@ -56,88 +56,6 @@ char DominatorTree::ID = 0;
static RegisterPass<DominatorTree>
E("domtree", "Dominator Tree Construction", true);
// NewBB is split and now it has one successor. Update dominator tree to
// reflect this change.
void DominatorTree::splitBlock(BasicBlock *NewBB) {
assert(NewBB->getTerminator()->getNumSuccessors() == 1
&& "NewBB should have a single successor!");
BasicBlock *NewBBSucc = NewBB->getTerminator()->getSuccessor(0);
std::vector<BasicBlock*> PredBlocks;
for (pred_iterator PI = pred_begin(NewBB), PE = pred_end(NewBB);
PI != PE; ++PI)
PredBlocks.push_back(*PI);
assert(!PredBlocks.empty() && "No predblocks??");
// The newly inserted basic block will dominate existing basic blocks iff the
// PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
// the non-pred blocks, then they all must be the same block!
//
bool NewBBDominatesNewBBSucc = true;
{
BasicBlock *OnePred = PredBlocks[0];
unsigned i = 1, e = PredBlocks.size();
for (i = 1; !isReachableFromEntry(OnePred); ++i) {
assert(i != e && "Didn't find reachable pred?");
OnePred = PredBlocks[i];
}
for (; i != e; ++i)
if (PredBlocks[i] != OnePred && isReachableFromEntry(OnePred)) {
NewBBDominatesNewBBSucc = false;
break;
}
if (NewBBDominatesNewBBSucc)
for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
PI != E; ++PI)
if (*PI != NewBB && !dominates(NewBBSucc, *PI)) {
NewBBDominatesNewBBSucc = false;
break;
}
}
// The other scenario where the new block can dominate its successors are when
// all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
// already.
if (!NewBBDominatesNewBBSucc) {
NewBBDominatesNewBBSucc = true;
for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
PI != E; ++PI)
if (*PI != NewBB && !dominates(NewBBSucc, *PI)) {
NewBBDominatesNewBBSucc = false;
break;
}
}
// Find NewBB's immediate dominator and create new dominator tree node for
// NewBB.
BasicBlock *NewBBIDom = 0;
unsigned i = 0;
for (i = 0; i < PredBlocks.size(); ++i)
if (isReachableFromEntry(PredBlocks[i])) {
NewBBIDom = PredBlocks[i];
break;
}
assert(i != PredBlocks.size() && "No reachable preds?");
for (i = i + 1; i < PredBlocks.size(); ++i) {
if (isReachableFromEntry(PredBlocks[i]))
NewBBIDom = findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
}
assert(NewBBIDom && "No immediate dominator found??");
// Create the new dominator tree node... and set the idom of NewBB.
DomTreeNode *NewBBNode = addNewBlock(NewBB, NewBBIDom);
// If NewBB strictly dominates other blocks, then it is now the immediate
// dominator of NewBBSucc. Update the dominator tree as appropriate.
if (NewBBDominatesNewBBSucc) {
DomTreeNode *NewBBSuccNode = getNode(NewBBSucc);
changeImmediateDominator(NewBBSuccNode, NewBBNode);
}
}
bool DominatorTree::runOnFunction(Function &F) {
reset(); // Reset from the last time we were run...