//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include "llvm/Type.h"
#include "llvm/Instructions.h"
-#include "llvm/IntrinsicInst.h"
#include "llvm/Function.h"
+#include "llvm/Support/CallSite.h"
#include "llvm/Support/LeakDetector.h"
using namespace llvm;
case ExtractElement: return "extractelement";
case InsertElement: return "insertelement";
case ShuffleVector: return "shufflevector";
+ case GetResult: return "getresult";
default: return "<Invalid operator> ";
}
return true;
}
-// IntrinsicOnlyReadsMemory - Return true if the specified intrinsic doesn't
-// have any side-effects or if it only reads memory.
-static bool IntrinsicOnlyReadsMemory(unsigned IntrinsicID) {
-#define GET_SIDE_EFFECT_INFO
-#include "llvm/Intrinsics.gen"
-#undef GET_SIDE_EFFECT_INFO
- return false;
+/// 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;
+}
+
+/// mayReadFromMemory - Return true if this instruction may read memory.
+///
+bool Instruction::mayReadFromMemory() const {
+ switch (getOpcode()) {
+ default: return false;
+ case Instruction::Free:
+ case Instruction::VAArg:
+ case Instruction::Load:
+ return true;
+ case Instruction::Call:
+ return !cast<CallInst>(this)->doesNotAccessMemory();
+ case Instruction::Invoke:
+ return !cast<InvokeInst>(this)->doesNotAccessMemory();
+ case Instruction::Store:
+ return cast<StoreInst>(this)->isVolatile();
+ }
}
/// mayWriteToMemory - Return true if this instruction may modify memory.
default: return false;
case Instruction::Free:
case Instruction::Store:
- case Instruction::Invoke:
case Instruction::VAArg:
return true;
case Instruction::Call:
- if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
- // If the intrinsic doesn't write memory, it is safe.
- return !IntrinsicOnlyReadsMemory(II->getIntrinsicID());
- }
- return true;
+ return !cast<CallInst>(this)->onlyReadsMemory();
+ case Instruction::Invoke:
+ return !cast<InvokeInst>(this)->onlyReadsMemory();
case Instruction::Load:
return cast<LoadInst>(this)->isVolatile();
}
case Store:
case Call:
case Invoke:
+ case VAArg:
return true;
default:
return false;