[llvm-commits] [llvm] r50004 - in /llvm/trunk: include/llvm/Instruction.h lib/VMCore/Instruction.cpp
Chris Lattner
sabre at nondot.org
Sun Apr 20 15:11:31 PDT 2008
Author: lattner
Date: Sun Apr 20 17:11:30 2008
New Revision: 50004
URL: http://llvm.org/viewvc/llvm-project?rev=50004&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Instruction.h
llvm/trunk/lib/VMCore/Instruction.cpp
Modified: llvm/trunk/include/llvm/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instruction.h?rev=50004&r1=50003&r2=50004&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Instruction.h (original)
+++ llvm/trunk/include/llvm/Instruction.h Sun Apr 20 17:11:30 2008
@@ -72,6 +72,13 @@
/// @brief Determine if one instruction is the same operation as another.
bool isSameOperationAs(Instruction *I) const;
+ /// isUsedOutsideOfBlock - Return true if there are any uses of this
+ /// instruction in blocks other than the specified block. Note that PHI nodes
+ /// are considered to evaluate their operands in the corresponding predecessor
+ /// block.
+ bool isUsedOutsideOfBlock(const BasicBlock *BB) const;
+
+
/// use_back - Specialize the methods defined in Value, as we know that an
/// instruction can only be used by other instructions.
Instruction *use_back() { return cast<Instruction>(*use_begin());}
Modified: llvm/trunk/lib/VMCore/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instruction.cpp?rev=50004&r1=50003&r2=50004&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instruction.cpp (original)
+++ llvm/trunk/lib/VMCore/Instruction.cpp Sun Apr 20 17:11:30 2008
@@ -198,6 +198,29 @@
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 {
More information about the llvm-commits
mailing list