From: Owen Anderson Date: Wed, 3 Oct 2007 03:20:17 +0000 (+0000) Subject: Factor some code from the DomTree and PostDomTree calculate methods up into X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=471ab54df756f2f48c9146ad897672662c3f25f9;p=oota-llvm.git Factor some code from the DomTree and PostDomTree calculate methods up into each one's runOnFunction method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42563 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/PostDominators.h b/include/llvm/Analysis/PostDominators.h index d87f60465bb..098339a0c5f 100644 --- a/include/llvm/Analysis/PostDominators.h +++ b/include/llvm/Analysis/PostDominators.h @@ -27,11 +27,7 @@ struct PostDominatorTree : public DominatorTreeBase { PostDominatorTree() : DominatorTreeBase((intptr_t)&ID, true) {} - virtual bool runOnFunction(Function &F) { - reset(); // Reset from the last time we were run... - PDTcalculate(*this, F); - return false; - } + virtual bool runOnFunction(Function &F); virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); diff --git a/lib/Analysis/PostDominatorCalculation.h b/lib/Analysis/PostDominatorCalculation.h index 5aa692eb37f..724ff795fd1 100644 --- a/lib/Analysis/PostDominatorCalculation.h +++ b/lib/Analysis/PostDominatorCalculation.h @@ -19,24 +19,6 @@ namespace llvm { void PDTcalculate(PostDominatorTree& PDT, Function &F) { - // Step #0: Scan the function looking for the root nodes of the post-dominance - // relationships. These blocks, which have no successors, end with return and - // unwind instructions. - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) { - TerminatorInst *Insn = I->getTerminator(); - if (Insn->getNumSuccessors() == 0) { - // Unreachable block is not a root node. - if (!isa(Insn)) - PDT.Roots.push_back(I); - } - - // Prepopulate maps so that we don't get iterator invalidation issues later. - PDT.IDoms[I] = 0; - PDT.DomTreeNodes[I] = 0; - } - - PDT.Vertex.push_back(0); - // Step #1: Number blocks in depth-first order and initialize variables used // in later stages of the algorithm. unsigned N = 0; diff --git a/lib/Analysis/PostDominators.cpp b/lib/Analysis/PostDominators.cpp index cd29749c830..0ca73882312 100644 --- a/lib/Analysis/PostDominators.cpp +++ b/lib/Analysis/PostDominators.cpp @@ -28,6 +28,29 @@ char PostDominanceFrontier::ID = 0; static RegisterPass F("postdomtree", "Post-Dominator Tree Construction", true); +bool PostDominatorTree::runOnFunction(Function &F) { + reset(); // Reset from the last time we were run... + + // Initialize the roots list + for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) { + TerminatorInst *Insn = I->getTerminator(); + if (Insn->getNumSuccessors() == 0) { + // Unreachable block is not a root node. + if (!isa(Insn)) + Roots.push_back(I); + } + + // Prepopulate maps so that we don't get iterator invalidation issues later. + IDoms[I] = 0; + DomTreeNodes[I] = 0; + } + + Vertex.push_back(0); + + PDTcalculate(*this, F); + return false; +} + //===----------------------------------------------------------------------===// // PostDominanceFrontier Implementation //===----------------------------------------------------------------------===// diff --git a/lib/VMCore/DominatorCalculation.h b/lib/VMCore/DominatorCalculation.h index a9118d8063f..1d245d474f5 100644 --- a/lib/VMCore/DominatorCalculation.h +++ b/lib/VMCore/DominatorCalculation.h @@ -40,8 +40,6 @@ void DTcalculate(DominatorTree& DT, Function &F) { // Add a node for the root... DT.DomTreeNodes[Root] = DT.RootNode = new DomTreeNode(Root, 0); - DT.Vertex.push_back(0); - // Step #1: Number blocks in depth-first order and initialize variables used // in later stages of the algorithm. unsigned N = DFSPass >(DT, Root, 0); diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index a1eaf4aa971..57cf6702868 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -350,7 +350,13 @@ void DominatorTreeBase::dump() { bool DominatorTree::runOnFunction(Function &F) { reset(); // Reset from the last time we were run... + + // Initialize roots Roots.push_back(&F.getEntryBlock()); + IDoms[&F.getEntryBlock()] = 0; + DomTreeNodes[&F.getEntryBlock()] = 0; + Vertex.push_back(0); + DTcalculate(*this, F); return false; }