#include "llvm/Type.h"
#include "llvm/Instructions.h"
#include "llvm/Function.h"
+#include "llvm/Support/CallSite.h"
#include "llvm/Support/LeakDetector.h"
using namespace llvm;
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const std::string &Name, Instruction *InsertBefore)
+ Instruction *InsertBefore)
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
// Make sure that we get added to a basicblock
LeakDetector::addGarbageObject(this);
"Instruction to insert before is not in a basic block!");
InsertBefore->getParent()->getInstList().insert(InsertBefore, this);
}
- setName(Name);
}
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const std::string &Name, BasicBlock *InsertAtEnd)
+ BasicBlock *InsertAtEnd)
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
// Make sure that we get added to a basicblock
LeakDetector::addGarbageObject(this);
// append this instruction into the basic block
assert(InsertAtEnd && "Basic block to append to may not be NULL!");
InsertAtEnd->getInstList().push_back(this);
- setName(Name);
-}
-
-Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const char *Name, Instruction *InsertBefore)
- : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
- // Make sure that we get added to a basicblock
- LeakDetector::addGarbageObject(this);
-
- // If requested, insert this instruction into a basic block...
- if (InsertBefore) {
- assert(InsertBefore->getParent() &&
- "Instruction to insert before is not in a basic block!");
- InsertBefore->getParent()->getInstList().insert(InsertBefore, this);
- }
- if (Name && *Name) setName(Name);
-}
-
-Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- const char *Name, BasicBlock *InsertAtEnd)
- : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
- // Make sure that we get added to a basicblock
- LeakDetector::addGarbageObject(this);
-
- // append this instruction into the basic block
- assert(InsertAtEnd && "Basic block to append to may not be NULL!");
- InsertAtEnd->getInstList().push_back(this);
- if (Name && *Name) setName(Name);
}
return true;
}
+/// mayWriteToMemory - Return true if this instruction may modify memory.
+///
+bool Instruction::mayWriteToMemory() const {
+ switch (getOpcode()) {
+ default: return false;
+ case Instruction::Free:
+ case Instruction::Invoke:
+ case Instruction::Store:
+ case Instruction::VAArg:
+ return true;
+ case Instruction::Call:
+ return !cast<CallInst>(this)->onlyReadsMemory();
+ case Instruction::Load:
+ return cast<LoadInst>(this)->isVolatile();
+ }
+}
/// isAssociative - Return true if the instruction is associative:
///