OSDN Git Service

Make DomTree and PostDomTree thin wrappers around DomTreeBase, rather than inheriting...
authorOwen Anderson <resistor@mac.com>
Tue, 23 Oct 2007 20:58:37 +0000 (20:58 +0000)
committerOwen Anderson <resistor@mac.com>
Tue, 23 Oct 2007 20:58:37 +0000 (20:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43259 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 71b06e2..ca9f6b1 100644 (file)
@@ -21,17 +21,39 @@ namespace llvm {
 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
 /// compute the a post-dominator tree.
 ///
-struct PostDominatorTree : public DominatorTreeBase<BasicBlock> {
+struct PostDominatorTree : public FunctionPass {
   static char ID; // Pass identification, replacement for typeid
+  DominatorTreeBase<BasicBlock>* DT;
 
-  PostDominatorTree() : 
-    DominatorTreeBase<BasicBlock>((intptr_t)&ID, true) {}
+  PostDominatorTree() : FunctionPass((intptr_t)&ID) {
+    DT = new DominatorTreeBase<BasicBlock>(intptr_t(&ID), true);
+  }
 
   virtual bool runOnFunction(Function &F);
 
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.setPreservesAll();
   }
+  
+  inline const std::vector<BasicBlock*> &getRoots() const {
+    return DT->getRoots();
+  }
+  
+  inline DomTreeNode *getRootNode() const {
+    return DT->getRootNode();
+  }
+  
+  inline DomTreeNode *operator[](BasicBlock *BB) const {
+    return DT->getNode(BB);
+  }
+  
+  inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
+    return DT->properlyDominates(A, B);
+  }
+  
+  inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
+    return DT->properlyDominates(A, B);
+  }
 };
 
 
index 0384fad..370cd95 100644 (file)
@@ -29,25 +29,7 @@ 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);
-    
-  Calculate<Inverse<BasicBlock*>, GraphTraits<Inverse<BasicBlock*> > >(*this, F);
+  DT->recalculate(F);
   return false;
 }
 
index b909a00..5bb25d4 100644 (file)
@@ -57,17 +57,7 @@ static RegisterPass<DominatorTree>
 E("domtree", "Dominator Tree Construction", true);
 
 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);
-  
-  Calculate<BasicBlock*, GraphTraits<BasicBlock*> >(*this, F);
-  
-  updateDFSNumbers();
+  DT->recalculate(F);
   
   return false;
 }