From 4e4caeffbdf3da85b980386131f6fd364a981153 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 4 Oct 2002 14:45:48 +0000 Subject: [PATCH] Fix a nasty problem with dominance calculation for unreachable blocks. If we had a CFG that look like Entry -> B, Unreachable -> B, then we would not correctly determine that Entry dominated B, because Entry did not apparently dominate "unreachable". This patch fixes this by making the entry node dominate all blocks, including unreachable ones. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4037 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Dominators.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index 99fda807513..37e7d48c283 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -61,6 +61,18 @@ void DominatorSet::calculateDominatorsFromBlock(BasicBlock *RootBB) { if (PredSet.size()) set_intersect(WorkingSet, PredSet); } + } else if (BB != Root) { + // If this isn't the root basic block and it has no predecessors, it + // must be an unreachable block. Fib a bit by saying that the root node + // dominates this unreachable node. This isn't exactly true, because + // there is no path from the entry node to this node, but it is sorta + // true because any paths to this node would have to go through the + // entry node. + // + // This allows for dominator properties to be built for unreachable code + // in a reasonable manner. + // + WorkingSet = Doms[Root]; } WorkingSet.insert(BB); // A block always dominates itself @@ -95,9 +107,8 @@ bool DominatorSet::runOnFunction(Function &F) { // unreachable blocks. // for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) - if (Doms[I].empty()) { + if (Doms[I].count(I) == 0) calculateDominatorsFromBlock(I); - } return false; } @@ -166,10 +177,14 @@ void ImmediateDominatorsBase::calcIDoms(const DominatorSetBase &DS) { } void ImmediateDominatorsBase::print(std::ostream &o) const { - for (const_iterator I = begin(), E = end(); I != E; ++I) + for (const_iterator I = begin(), E = end(); I != E; ++I) { o << "=============================--------------------------------\n" - << "\nImmediate Dominator For Basic Block\n" << *I->first - << "is: \n" << *I->second << "\n"; + << "\nImmediate Dominator For Basic Block:"; + WriteAsOperand(o, I->first, false); + o << " is:"; + WriteAsOperand(o, I->second, false); + o << "\n"; + } } -- 2.34.1