Add instruction level dominates(A,B) interface.
authorDevang Patel <dpatel@apple.com>
Thu, 7 Jun 2007 23:52:40 +0000 (23:52 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 7 Jun 2007 23:52:40 +0000 (23:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37504 91177308-0d34-0410-b5e6-96231b3b80d8

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

index f98db6f13ddbfb924b27b977b6bf41656ac2bc41..d1fc5eb05a93ddd3f1bf34cbd81d18804b735248 100644 (file)
@@ -219,6 +219,10 @@ protected:
     return dominates(getNode(A), getNode(B));
   }
 
+  // dominates - Return true if A dominates B. This performs the
+  // special checks necessary if A and B are in the same basic block.
+  bool dominates(Instruction *A, Instruction *B);
+
   //===--------------------------------------------------------------------===//
   // API to update (Post)DominatorTree information based on modifications to
   // the CFG...
index 9bfbbec9b9b22a40d56e7a87784c2451cb1ea608..fc5d6a63ca935dd05505f6dae7a6bb8cd8e88d09 100644 (file)
@@ -324,6 +324,29 @@ void DominatorTreeBase::updateDFSNumbers()
   DFSInfoValid = true;
 }
 
+// dominates - Return true if A dominates B. THis performs the
+// special checks necessary if A and B are in the same basic block.
+bool DominatorTreeBase::dominates(Instruction *A, Instruction *B) {
+  BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
+  if (BBA != BBB) return dominates(BBA, BBB);
+  
+  // It is not possible to determine dominance between two PHI nodes 
+  // based on their ordering.
+  if (isa<PHINode>(A) && isa<PHINode>(B)) 
+    return false;
+
+  // Loop through the basic block until we find A or B.
+  BasicBlock::iterator I = BBA->begin();
+  for (; &*I != A && &*I != B; ++I) /*empty*/;
+  
+  if(!IsPostDominators) {
+    // A dominates B if it is found first in the basic block.
+    return &*I == A;
+  } else {
+    // A post-dominates B if B is found first in the basic block.
+    return &*I == B;
+  }
+}
 
 // DominatorTreeBase::reset - Free all of the tree node memory.
 //