summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-20 22:11:30 +0000
committerChris Lattner <sabre@nondot.org>2008-04-20 22:11:30 +0000
commit8ec6e8af60312f1ba3eceee8e73f9231b9f0a29e (patch)
treeaaaf76036eae257333b3b17bd3ec905275604c0d /llvm/lib
parent9c1f1a82bfdc6878870644d296d1a476c8a4ac52 (diff)
downloadbcm5719-llvm-8ec6e8af60312f1ba3eceee8e73f9231b9f0a29e.tar.gz
bcm5719-llvm-8ec6e8af60312f1ba3eceee8e73f9231b9f0a29e.zip
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. llvm-svn: 50004
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Instruction.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Instruction.cpp b/llvm/lib/VMCore/Instruction.cpp
index 6f09c907083..5344cf7bfe5 100644
--- a/llvm/lib/VMCore/Instruction.cpp
+++ b/llvm/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 {
OpenPOWER on IntegriCloud