Factor some code from the DomTree and PostDomTree calculate methods up into
authorOwen Anderson <resistor@mac.com>
Wed, 3 Oct 2007 03:20:17 +0000 (03:20 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 3 Oct 2007 03:20:17 +0000 (03:20 +0000)
each one's runOnFunction method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42563 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/PostDominators.h
lib/Analysis/PostDominatorCalculation.h
lib/Analysis/PostDominators.cpp
lib/VMCore/DominatorCalculation.h
lib/VMCore/Dominators.cpp

index d87f60465bb7d712d0495ef4da85a560746a83a1..098339a0c5f933c691d3ae7594889c3bef1d221e 100644 (file)
@@ -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();
index 5aa692eb37fc2e9bff991572f28efaa9fd8cfaa1..724ff795fd154d4a3f951f88398a6f57863b26ca 100644 (file)
 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<UnreachableInst>(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;
index cd29749c830e65c15fc6a6ee669929176264c368..0ca738823129f06cd16735e94dc93bdda6bf19e5 100644 (file)
@@ -28,6 +28,29 @@ char PostDominanceFrontier::ID = 0;
 static RegisterPass<PostDominatorTree>
 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<UnreachableInst>(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
 //===----------------------------------------------------------------------===//
index a9118d8063fe9f6d469591186e68f696cd641374..1d245d474f5db7b9f0178deec444e397eabdec31 100644 (file)
@@ -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<GraphTraits<BasicBlock*> >(DT, Root, 0);
index a1eaf4aa971f4737381235a5eb9996edc0cca6f6..57cf670286836385ea46fb55501a2eb3fc31de81 100644 (file)
@@ -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;
 }