diff options
author | Chris Lattner <sabre@nondot.org> | 2002-05-13 22:03:16 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-05-13 22:03:16 +0000 |
commit | ef704a23b4c3cadf11b093fa628cafa38fa05ad5 (patch) | |
tree | 0d5f7527a80ce17ea92d35840777189dbd478dc4 | |
parent | e0e734eea052a4e8372e6f430ef41149128ba0a6 (diff) |
Add method to check to see if two _Instructions_ dominate each other
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2616 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Analysis/Dominators.h | 7 | ||||
-rw-r--r-- | lib/Analysis/PostDominators.cpp | 14 | ||||
-rw-r--r-- | lib/VMCore/Dominators.cpp | 14 |
3 files changed, 35 insertions, 0 deletions
diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index e3038da195..796a779087 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -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 // diff --git a/lib/Analysis/PostDominators.cpp b/lib/Analysis/PostDominators.cpp index e4eb2c1119..ca0b64a064 100644 --- a/lib/Analysis/PostDominators.cpp +++ b/lib/Analysis/PostDominators.cpp @@ -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. diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index e4eb2c1119..ca0b64a064 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -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. |