Add method to check to see if two _Instructions_ dominate each other
authorChris Lattner <sabre@nondot.org>
Mon, 13 May 2002 22:03:16 +0000 (22:03 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 13 May 2002 22:03:16 +0000 (22:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2616 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e3038da1951f651fc9644fb25b1e19467317316a..796a7790877eb2e40f9fdd8529d0b05cf637d30b 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "llvm/Pass.h"
 #include <set>
+class Instruction;
 
 //===----------------------------------------------------------------------===//
 //
@@ -95,6 +96,12 @@ public:
     return getDominators(B).count(A) != 0;
   }
 
+  // dominates - Return true if A dominates B.  This performs the special checks
+  // neccesary if A and B are in the same basic block.
+  //
+  bool dominates(Instruction *A, Instruction *B) const;
+
+
   // getAnalysisUsage - This obviously provides a dominator set, but it also
   // uses the UnifyFunctionExitNode pass if building post-dominators
   //
index e4eb2c1119e3b09437ff0beac0686daa3e5828f4..ca0b64a064cc03b0604c2904571b2740a6388e02 100644 (file)
@@ -31,6 +31,20 @@ bool DominatorSet::runOnFunction(Function *F) {
   return false;
 }
 
+// dominates - Return true if A dominates B.  This performs the special checks
+// neccesary if A and B are in the same basic block.
+//
+bool DominatorSet::dominates(Instruction *A, Instruction *B) const {
+  BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
+  if (BBA != BBB) return dominates(BBA, BBB);
+  
+  // Loop through the basic block until we find A or B.
+  BasicBlock::iterator I = BBA->begin();
+  for (; *I != A && *I != B; ++I) /*empty*/;
+  
+  // A dominates B if it is found first in the basic block...
+  return *I == A;
+}
 
 // calcForwardDominatorSet - This method calculates the forward dominator sets
 // for the specified function.
index e4eb2c1119e3b09437ff0beac0686daa3e5828f4..ca0b64a064cc03b0604c2904571b2740a6388e02 100644 (file)
@@ -31,6 +31,20 @@ bool DominatorSet::runOnFunction(Function *F) {
   return false;
 }
 
+// dominates - Return true if A dominates B.  This performs the special checks
+// neccesary if A and B are in the same basic block.
+//
+bool DominatorSet::dominates(Instruction *A, Instruction *B) const {
+  BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
+  if (BBA != BBB) return dominates(BBA, BBB);
+  
+  // Loop through the basic block until we find A or B.
+  BasicBlock::iterator I = BBA->begin();
+  for (; *I != A && *I != B; ++I) /*empty*/;
+  
+  // A dominates B if it is found first in the basic block...
+  return *I == A;
+}
 
 // calcForwardDominatorSet - This method calculates the forward dominator sets
 // for the specified function.