diff options
author | Devang Patel <dpatel@apple.com> | 2007-06-07 23:52:40 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-06-07 23:52:40 +0000 |
commit | e029b2c36907a77c895e4d646c0e91f18a6dd162 (patch) | |
tree | f78bb2868f5607b5bb6f6be36f2a2fb300e878d0 /lib | |
parent | 27af5c414b44315676b4625dc22e29a507ca9dca (diff) |
Add instruction level dominates(A,B) interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37504 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/Dominators.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index 9bfbbec9b9..fc5d6a63ca 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -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. // |