1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

1. Random tidiness cleanups

2. Make domtree printing print dfin/dfout #'s
3. Fix the Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll failure from last night (in DominanceFrontier::splitBlock).

w.r.t. #3, my patches last night happened to expose the bug, but this 
has been broken since Owen's r35839 patch to LoopSimplify.  The code
was subsequently moved over from LoopSimplify into Dominators, carrying
the latent bug.  Fun stuff.

llvm-svn: 40858
This commit is contained in:
Chris Lattner 2007-08-06 06:19:47 +00:00
parent 38cfb16fe2
commit 2c559ed3dc

View File

@ -66,7 +66,6 @@ E("domtree", "Dominator Tree Construction", true);
// NewBB is split and now it has one successor. Update dominator tree to // NewBB is split and now it has one successor. Update dominator tree to
// reflect this change. // reflect this change.
void DominatorTree::splitBlock(BasicBlock *NewBB) { void DominatorTree::splitBlock(BasicBlock *NewBB) {
assert(NewBB->getTerminator()->getNumSuccessors() == 1 assert(NewBB->getTerminator()->getNumSuccessors() == 1
&& "NewBB should have a single successor!"); && "NewBB should have a single successor!");
BasicBlock *NewBBSucc = NewBB->getTerminator()->getSuccessor(0); BasicBlock *NewBBSucc = NewBB->getTerminator()->getSuccessor(0);
@ -92,7 +91,7 @@ void DominatorTree::splitBlock(BasicBlock *NewBB) {
} }
for (; i != e; ++i) for (; i != e; ++i)
if (PredBlocks[i] != OnePred && isReachableFromEntry(OnePred)){ if (PredBlocks[i] != OnePred && isReachableFromEntry(OnePred)) {
NewBBDominatesNewBBSucc = false; NewBBDominatesNewBBSucc = false;
break; break;
} }
@ -119,7 +118,6 @@ void DominatorTree::splitBlock(BasicBlock *NewBB) {
} }
} }
// Find NewBB's immediate dominator and create new dominator tree node for // Find NewBB's immediate dominator and create new dominator tree node for
// NewBB. // NewBB.
BasicBlock *NewBBIDom = 0; BasicBlock *NewBBIDom = 0;
@ -390,9 +388,7 @@ void DominatorTreeBase::updateDFSNumbers() {
for (unsigned i = 0, e = Roots.size(); i != e; ++i) for (unsigned i = 0, e = Roots.size(); i != e; ++i)
for (df_iterator<BasicBlock*> I = df_begin(Roots[i]), for (df_iterator<BasicBlock*> I = df_begin(Roots[i]),
E = df_end(Roots[i]); I != E; ++I) { E = df_end(Roots[i]); I != E; ++I) {
BasicBlock *BB = *I; if (DomTreeNode *BBNode = getNode(*I)) {
DomTreeNode *BBNode = getNode(BB);
if (BBNode) {
if (!BBNode->getIDom()) if (!BBNode->getIDom())
BBNode->assignDFSNumber(dfsnum); BBNode->assignDFSNumber(dfsnum);
} }
@ -462,11 +458,11 @@ BasicBlock *DominatorTreeBase::findNearestCommonDominator(BasicBlock *A,
return &Entry; return &Entry;
// If B dominates A then B is nearest common dominator. // If B dominates A then B is nearest common dominator.
if (dominates(B,A)) if (dominates(B, A))
return B; return B;
// If A dominates B then A is nearest common dominator. // If A dominates B then A is nearest common dominator.
if (dominates(A,B)) if (dominates(A, B))
return A; return A;
DomTreeNode *NodeA = getNode(A); DomTreeNode *NodeA = getNode(A);
@ -476,7 +472,7 @@ BasicBlock *DominatorTreeBase::findNearestCommonDominator(BasicBlock *A,
SmallPtrSet<DomTreeNode*, 16> NodeADoms; SmallPtrSet<DomTreeNode*, 16> NodeADoms;
NodeADoms.insert(NodeA); NodeADoms.insert(NodeA);
DomTreeNode *IDomA = NodeA->getIDom(); DomTreeNode *IDomA = NodeA->getIDom();
while(IDomA) { while (IDomA) {
NodeADoms.insert(IDomA); NodeADoms.insert(IDomA);
IDomA = IDomA->getIDom(); IDomA = IDomA->getIDom();
} }
@ -542,8 +538,8 @@ void DomTreeNode::setIDom(DomTreeNode *NewIDom) {
} }
DomTreeNode *DominatorTree::getNodeForBlock(BasicBlock *BB) { DomTreeNode *DominatorTree::getNodeForBlock(BasicBlock *BB) {
DomTreeNode *&BBNode = DomTreeNodes[BB]; if (DomTreeNode *BBNode = DomTreeNodes[BB])
if (BBNode) return BBNode; return BBNode;
// Haven't calculated this node yet? Get or calculate the node for the // Haven't calculated this node yet? Get or calculate the node for the
// immediate dominator. // immediate dominator.
@ -556,12 +552,14 @@ DomTreeNode *DominatorTree::getNodeForBlock(BasicBlock *BB) {
return DomTreeNodes[BB] = IDomNode->addChild(C); return DomTreeNodes[BB] = IDomNode->addChild(C);
} }
static std::ostream &operator<<(std::ostream &o, static std::ostream &operator<<(std::ostream &o, const DomTreeNode *Node) {
const DomTreeNode *Node) {
if (Node->getBlock()) if (Node->getBlock())
WriteAsOperand(o, Node->getBlock(), false); WriteAsOperand(o, Node->getBlock(), false);
else else
o << " <<exit node>>"; o << " <<exit node>>";
o << " {" << Node->getDFSNumIn() << "," << Node->getDFSNumOut() << "}";
return o << "\n"; return o << "\n";
} }
@ -574,13 +572,17 @@ static void PrintDomTree(const DomTreeNode *N, std::ostream &o,
} }
void DominatorTreeBase::print(std::ostream &o, const Module* ) const { void DominatorTreeBase::print(std::ostream &o, const Module* ) const {
o << "=============================--------------------------------\n" o << "=============================--------------------------------\n";
<< "Inorder Dominator Tree:\n"; o << "Inorder Dominator Tree: ";
if (DFSInfoValid)
o << "DFSNumbers invalid: " << SlowQueries << " slow queries.";
o << "\n";
PrintDomTree(getRootNode(), o, 1); PrintDomTree(getRootNode(), o, 1);
} }
void DominatorTreeBase::dump() { void DominatorTreeBase::dump() {
print (llvm::cerr); print(llvm::cerr);
} }
bool DominatorTree::runOnFunction(Function &F) { bool DominatorTree::runOnFunction(Function &F) {
@ -601,7 +603,6 @@ G("domfrontier", "Dominance Frontier Construction", true);
// NewBB is split and now it has one successor. Update dominace frontier to // NewBB is split and now it has one successor. Update dominace frontier to
// reflect this change. // reflect this change.
void DominanceFrontier::splitBlock(BasicBlock *NewBB) { void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
assert(NewBB->getTerminator()->getNumSuccessors() == 1 assert(NewBB->getTerminator()->getNumSuccessors() == 1
&& "NewBB should have a single successor!"); && "NewBB should have a single successor!");
BasicBlock *NewBBSucc = NewBB->getTerminator()->getSuccessor(0); BasicBlock *NewBBSucc = NewBB->getTerminator()->getSuccessor(0);
@ -617,12 +618,7 @@ void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
// other blocks. // other blocks.
return; return;
DominatorTree &DT = getAnalysis<DominatorTree>(); // NewBBSucc inherits original NewBB frontier.
bool NewBBDominatesNewBBSucc = true;
if (!DT.dominates(NewBB, NewBBSucc))
NewBBDominatesNewBBSucc = false;
// NewBBSucc inherites original NewBB frontier.
DominanceFrontier::iterator NewBBI = find(NewBB); DominanceFrontier::iterator NewBBI = find(NewBB);
if (NewBBI != end()) { if (NewBBI != end()) {
DominanceFrontier::DomSetType NewBBSet = NewBBI->second; DominanceFrontier::DomSetType NewBBSet = NewBBI->second;
@ -634,7 +630,8 @@ void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
// If NewBB dominates NewBBSucc, then DF(NewBB) is now going to be the // If NewBB dominates NewBBSucc, then DF(NewBB) is now going to be the
// DF(PredBlocks[0]) without the stuff that the new block does not dominate // DF(PredBlocks[0]) without the stuff that the new block does not dominate
// a predecessor of. // a predecessor of.
if (NewBBDominatesNewBBSucc) { DominatorTree &DT = getAnalysis<DominatorTree>();
if (DT.dominates(NewBB, NewBBSucc)) {
DominanceFrontier::iterator DFI = find(PredBlocks[0]); DominanceFrontier::iterator DFI = find(PredBlocks[0]);
if (DFI != end()) { if (DFI != end()) {
DominanceFrontier::DomSetType Set = DFI->second; DominanceFrontier::DomSetType Set = DFI->second;
@ -678,9 +675,11 @@ void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
DominanceFrontier::iterator DFI = find(FI); DominanceFrontier::iterator DFI = find(FI);
if (DFI == end()) continue; // unreachable block. if (DFI == end()) continue; // unreachable block.
// Only consider dominators of NewBBSucc // Only consider nodes that have NewBBSucc in their dominator frontier.
if (!DFI->second.count(NewBBSucc)) continue; if (!DFI->second.count(NewBBSucc)) continue;
// Verify whether this block dominates a block in predblocks. If not, do
// not update it.
bool BlockDominatesAny = false; bool BlockDominatesAny = false;
for (std::vector<BasicBlock*>::const_iterator BI = PredBlocks.begin(), for (std::vector<BasicBlock*>::const_iterator BI = PredBlocks.begin(),
BE = PredBlocks.end(); BI != BE; ++BI) { BE = PredBlocks.end(); BI != BE; ++BI) {
@ -690,13 +689,14 @@ void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
} }
} }
if (BlockDominatesAny) { if (!BlockDominatesAny)
continue;
// If NewBBSucc should not stay in our dominator frontier, remove it. // If NewBBSucc should not stay in our dominator frontier, remove it.
// We remove it unless there is a predecessor of NewBBSucc that we // We remove it unless there is a predecessor of NewBBSucc that we
// dominate, but we don't strictly dominate NewBBSucc. // dominate, but we don't strictly dominate NewBBSucc.
bool ShouldRemove = true; bool ShouldRemove = true;
if ((BasicBlock*)FI == NewBBSucc if ((BasicBlock*)FI == NewBBSucc || !DT.dominates(FI, NewBBSucc)) {
|| !DT.dominates(FI, NewBBSucc)) {
// Okay, we know that PredDom does not strictly dominate NewBBSucc. // Okay, we know that PredDom does not strictly dominate NewBBSucc.
// Check to see if it dominates any predecessors of NewBBSucc. // Check to see if it dominates any predecessors of NewBBSucc.
for (pred_iterator PI = pred_begin(NewBBSucc), for (pred_iterator PI = pred_begin(NewBBSucc),
@ -705,14 +705,11 @@ void DominanceFrontier::splitBlock(BasicBlock *NewBB) {
ShouldRemove = false; ShouldRemove = false;
break; break;
} }
}
if (ShouldRemove) if (ShouldRemove)
removeFromFrontier(DFI, NewBBSucc); removeFromFrontier(DFI, NewBBSucc);
addToFrontier(DFI, NewBB); addToFrontier(DFI, NewBB);
break;
}
}
} }
} }