diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-20 22:11:30 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-20 22:11:30 +0000 |
commit | aa9db70243d96a7904b10aaf2aa8315b13c14e2c (patch) | |
tree | 74a31eac6655e431590fb206c3f10035096e4cef /lib/VMCore | |
parent | 0add321c59162884aef92217d56794723836b9cf (diff) | |
download | external_llvm-aa9db70243d96a7904b10aaf2aa8315b13c14e2c.zip external_llvm-aa9db70243d96a7904b10aaf2aa8315b13c14e2c.tar.gz external_llvm-aa9db70243d96a7904b10aaf2aa8315b13c14e2c.tar.bz2 |
add a handy helper method to instruction, useful for determining
whether it is used outside of some block. This can be used to see
if there are any non-local references, for example.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50004 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Instruction.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 6f09c90..5344cf7 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -198,6 +198,29 @@ bool Instruction::isSameOperationAs(Instruction *I) const { return true; } +/// isUsedOutsideOfBlock - Return true if there are any uses of I outside of the +/// specified block. Note that PHI nodes are considered to evaluate their +/// operands in the corresponding predecessor block. +bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const { + for (use_const_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) { + // PHI nodes uses values in the corresponding predecessor block. For other + // instructions, just check to see whether the parent of the use matches up. + const PHINode *PN = dyn_cast<PHINode>(*UI); + if (PN == 0) { + if (cast<Instruction>(*UI)->getParent() != BB) + return true; + continue; + } + + unsigned UseOperand = UI.getOperandNo(); + if (PN->getIncomingBlock(UseOperand/2) != BB) + return true; + } + return false; +} + + + /// mayWriteToMemory - Return true if this instruction may modify memory. /// bool Instruction::mayWriteToMemory() const { |