diff options
author | Chris Lattner <sabre@nondot.org> | 2006-01-08 08:22:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-01-08 08:22:18 +0000 |
commit | ccacd3ccc2a4a2336085a1d8d58cedb947b2eb52 (patch) | |
tree | 720065c75179ec644dba19932ce535d51d13269b /lib/Analysis/PostDominators.cpp | |
parent | e00ab70c1833cbf994c169d6dd5bdd1a1528a2ca (diff) |
Initial implementation of the ET-Forest data structure for dominators and
post-dominators. This code was written/adapted by Daniel Berlin!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25144 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/PostDominators.cpp')
-rw-r--r-- | lib/Analysis/PostDominators.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/Analysis/PostDominators.cpp b/lib/Analysis/PostDominators.cpp index 56af6f6524..f9f9a42acc 100644 --- a/lib/Analysis/PostDominators.cpp +++ b/lib/Analysis/PostDominators.cpp @@ -205,6 +205,69 @@ void PostDominatorTree::calculate(const PostDominatorSet &DS) { } } } +//===----------------------------------------------------------------------===// +// PostETForest Implementation +//===----------------------------------------------------------------------===// + +static RegisterAnalysis<PostETForest> +G("postetforest", "Post-ET-Forest Construction", true); + +ETNode *PostETForest::getNodeForBlock(BasicBlock *BB) { + ETNode *&BBNode = Nodes[BB]; + if (BBNode) return BBNode; + + // Haven't calculated this node yet? Get or calculate the node for the + // immediate dominator. + BasicBlock *IDom = getAnalysis<ImmediatePostDominators>()[BB]; + + // If we are unreachable, we may not have an immediate dominator. + if (!IDom) + return BBNode = new ETNode(BB); + else { + ETNode *IDomNode = getNodeForBlock(IDom); + + // Add a new tree node for this BasicBlock, and link it as a child of + // IDomNode + BBNode = new ETNode(BB); + BBNode->setFather(IDomNode); + return BBNode; + } +} + +void PostETForest::calculate(const ImmediatePostDominators &ID) { + for (unsigned i = 0, e = Roots.size(); i != e; ++i) + Nodes[Roots[i]] = new ETNode(Roots[i]); // Add a node for the root + + // Iterate over all nodes in inverse depth first order. + for (unsigned i = 0, e = Roots.size(); i != e; ++i) + for (idf_iterator<BasicBlock*> I = idf_begin(Roots[i]), + E = idf_end(Roots[i]); I != E; ++I) { + BasicBlock *BB = *I; + ETNode *&BBNode = Nodes[BB]; + if (!BBNode) { + ETNode *IDomNode = NULL; + + if (ID.get(BB)) + IDomNode = getNodeForBlock(ID.get(BB)); + + // Add a new ETNode for this BasicBlock, and set it's parent + // to it's immediate dominator. + BBNode = new ETNode(BB); + if (IDomNode) + BBNode->setFather(IDomNode); + } + } + + int dfsnum = 0; + // Iterate over all nodes in depth first order... + for (unsigned i = 0, e = Roots.size(); i != e; ++i) + for (idf_iterator<BasicBlock*> I = idf_begin(Roots[i]), + E = idf_end(Roots[i]); I != E; ++I) { + if (!getNodeForBlock(*I)->hasFather()) + getNodeForBlock(*I)->assignDFSNumber(dfsnum); + } + DFSInfoValid = true; +} //===----------------------------------------------------------------------===// // PostDominanceFrontier Implementation |