Update PassManagerImpl_New::analysisCurrentlyAvailable to check all
[oota-llvm.git] / lib / VMCore / Dominators.cpp
index 24b3e87cafd9c73abf17dc67068565ea46a87275..c3e0099ee02ca28429616a78c3eedfac9748fdef 100644 (file)
@@ -44,7 +44,7 @@ using namespace llvm;
 //
 //===----------------------------------------------------------------------===//
 
-static RegisterAnalysis<ImmediateDominators>
+static RegisterPass<ImmediateDominators>
 C("idom", "Immediate Dominators Construction", true);
 
 unsigned ImmediateDominators::DFSPass(BasicBlock *V, InfoRec &VInfo,
@@ -211,6 +211,17 @@ bool ImmediateDominators::runOnFunction(Function &F) {
   return false;
 }
 
+/// dominates - Return true if A dominates B.
+///
+bool ImmediateDominatorsBase::dominates(BasicBlock *A, BasicBlock *B) const {
+  assert(A && B && "Null pointers?");
+  
+  // Walk up the dominator tree from B to determine if A dom B.
+  while (A != B && B)
+    B = get(B);
+  return A == B;
+}
+
 void ImmediateDominatorsBase::print(std::ostream &o, const Module* ) const {
   Function *F = getRoots()[0]->getParent();
   for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
@@ -232,7 +243,7 @@ void ImmediateDominatorsBase::print(std::ostream &o, const Module* ) const {
 //  DominatorSet Implementation
 //===----------------------------------------------------------------------===//
 
-static RegisterAnalysis<DominatorSet>
+static RegisterPass<DominatorSet>
 B("domset", "Dominator Set Construction", true);
 
 // dominates - Return true if A dominates B.  This performs the special checks
@@ -304,8 +315,6 @@ bool DominatorSet::runOnFunction(Function &F) {
   return false;
 }
 
-void DominatorSet::stub() {}
-
 namespace llvm {
 static std::ostream &operator<<(std::ostream &o,
                                 const std::set<BasicBlock*> &BBs) {
@@ -334,7 +343,7 @@ void DominatorSetBase::print(std::ostream &o, const Module* ) const {
 //  DominatorTree Implementation
 //===----------------------------------------------------------------------===//
 
-static RegisterAnalysis<DominatorTree>
+static RegisterPass<DominatorTree>
 E("domtree", "Dominator Tree Construction", true);
 
 // DominatorTreeBase::reset - Free all of the tree node memory.
@@ -425,7 +434,7 @@ void DominatorTreeBase::print(std::ostream &o, const Module* ) const {
 //  DominanceFrontier Implementation
 //===----------------------------------------------------------------------===//
 
-static RegisterAnalysis<DominanceFrontier>
+static RegisterPass<DominanceFrontier>
 G("domfrontier", "Dominance Frontier Construction", true);
 
 const DominanceFrontier::DomSetType &
@@ -800,11 +809,58 @@ ETNode *ETNode::NCA(ETNode *other) {
     return occmin->OccFor;
 }
 
+void ETNode::assignDFSNumber(int num) {
+  std::vector<ETNode *>  workStack;
+  std::set<ETNode *> visitedNodes;
+  
+  workStack.push_back(this);
+  visitedNodes.insert(this);
+  this->DFSNumIn = num++;
+
+  while (!workStack.empty()) {
+    ETNode  *Node = workStack.back();
+    
+    // If this is leaf node then set DFSNumOut and pop the stack
+    if (!Node->Son) {
+      Node->DFSNumOut = num++;
+      workStack.pop_back();
+      continue;
+    }
+    
+    ETNode *son = Node->Son;
+    
+    // Visit Node->Son first
+    if (visitedNodes.count(son) == 0) {
+      son->DFSNumIn = num++;
+      workStack.push_back(son);
+      visitedNodes.insert(son);
+      continue;
+    }
+    
+    bool visitChild = false;
+    // Visit remaining children
+    for (ETNode *s = son->Right;  s != son && !visitChild; s = s->Right) {
+      if (visitedNodes.count(s) == 0) {
+        visitChild = true;
+        s->DFSNumIn = num++;
+        workStack.push_back(s);
+        visitedNodes.insert(s);
+      }
+    }
+    
+    if (!visitChild) {
+      // If we reach here means all children are visited
+      Node->DFSNumOut = num++;
+      workStack.pop_back();
+    }
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // ETForest implementation
 //===----------------------------------------------------------------------===//
 
-static RegisterAnalysis<ETForest>
+static RegisterPass<ETForest>
 D("etforest", "ET Forest Construction", true);
 
 void ETForestBase::reset() {
@@ -933,3 +989,5 @@ void ETForestBase::print(std::ostream &o, const Module *) const {
   }
   o << "\n";
 }
+
+DEFINING_FILE_FOR(DominatorSet)