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 | da6743e60cea36654d1600400c5a1c5533647ff4 (patch) | |
| tree | b3bd0e7e56f8362aeff7ef236ede9412ff8a7bf6 /llvm/lib | |
| parent | 6ec05f551cd79744a4071211cdadc474afa50dec (diff) | |
| download | bcm5719-llvm-da6743e60cea36654d1600400c5a1c5533647ff4.tar.gz bcm5719-llvm-da6743e60cea36654d1600400c5a1c5533647ff4.zip | |
Add method to check to see if two _Instructions_ dominate each other
llvm-svn: 2616
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/PostDominators.cpp | 14 | ||||
| -rw-r--r-- | llvm/lib/VMCore/Dominators.cpp | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/PostDominators.cpp b/llvm/lib/Analysis/PostDominators.cpp index e4eb2c1119e..ca0b64a064c 100644 --- a/llvm/lib/Analysis/PostDominators.cpp +++ b/llvm/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/llvm/lib/VMCore/Dominators.cpp b/llvm/lib/VMCore/Dominators.cpp index e4eb2c1119e..ca0b64a064c 100644 --- a/llvm/lib/VMCore/Dominators.cpp +++ b/llvm/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. |

