#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
-#include "llvm/IR/LeakDetector.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
Instruction *InsertBefore)
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
- // 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);
+ BasicBlock *BB = InsertBefore->getParent();
+ assert(BB && "Instruction to insert before is not in a basic block!");
+ BB->getInstList().insert(InsertBefore->getIterator(), this);
}
}
-const DataLayout *Instruction::getDataLayout() const {
- return getParent()->getDataLayout();
-}
-
Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
BasicBlock *InsertAtEnd)
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
- // 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!");
void Instruction::setParent(BasicBlock *P) {
- if (getParent()) {
- if (!P) LeakDetector::addGarbageObject(this);
- } else {
- if (P) LeakDetector::removeGarbageObject(this);
- }
-
Parent = P;
}
+const Module *Instruction::getModule() const {
+ return getParent()->getModule();
+}
+
+Module *Instruction::getModule() {
+ return getParent()->getModule();
+}
+
+
void Instruction::removeFromParent() {
- getParent()->getInstList().remove(this);
+ getParent()->getInstList().remove(getIterator());
}
-void Instruction::eraseFromParent() {
- getParent()->getInstList().erase(this);
+iplist<Instruction>::iterator Instruction::eraseFromParent() {
+ return getParent()->getInstList().erase(getIterator());
}
/// insertBefore - Insert an unlinked instructions into a basic block
/// immediately before the specified instruction.
void Instruction::insertBefore(Instruction *InsertPos) {
- InsertPos->getParent()->getInstList().insert(InsertPos, this);
+ InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this);
}
/// insertAfter - Insert an unlinked instructions into a basic block
/// immediately after the specified instruction.
void Instruction::insertAfter(Instruction *InsertPos) {
- InsertPos->getParent()->getInstList().insertAfter(InsertPos, this);
+ InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(),
+ this);
}
/// moveBefore - Unlink this instruction from its current basic block and
/// insert it into the basic block that MovePos lives in, right before
/// MovePos.
void Instruction::moveBefore(Instruction *MovePos) {
- MovePos->getParent()->getInstList().splice(MovePos,getParent()->getInstList(),
- this);
+ MovePos->getParent()->getInstList().splice(
+ MovePos->getIterator(), getParent()->getInstList(), getIterator());
}
/// Set or clear the unsafe-algebra flag on this instruction, which must be an
/// Convenience function for getting all the fast-math flags, which must be an
/// operator which supports these flags. See LangRef.html for the meaning of
-/// these flats.
+/// these flags.
FastMathFlags Instruction::getFastMathFlags() const {
assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
return cast<FPMathOperator>(this)->getFastMathFlags();
case Invoke: return "invoke";
case Resume: return "resume";
case Unreachable: return "unreachable";
+ case CleanupEndPad: return "cleanupendpad";
+ case CleanupRet: return "cleanupret";
+ case CatchEndPad: return "catchendpad";
+ case CatchRet: return "catchret";
+ case CatchPad: return "catchpad";
+ case TerminatePad: return "terminatepad";
// Standard binary operators...
case Add: return "add";
case ExtractValue: return "extractvalue";
case InsertValue: return "insertvalue";
case LandingPad: return "landingpad";
+ case CleanupPad: return "cleanuppad";
default: return "<Invalid operator> ";
}
case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
case Instruction::AtomicCmpXchg:
case Instruction::AtomicRMW:
+ case Instruction::CatchPad:
+ case Instruction::CatchRet:
+ case Instruction::TerminatePad:
return true;
case Instruction::Call:
return !cast<CallInst>(this)->doesNotAccessMemory();
case Instruction::VAArg:
case Instruction::AtomicCmpXchg:
case Instruction::AtomicRMW:
+ case Instruction::CatchPad:
+ case Instruction::CatchRet:
+ case Instruction::TerminatePad:
return true;
case Instruction::Call:
return !cast<CallInst>(this)->onlyReadsMemory();
}
}
+bool Instruction::isAtomic() const {
+ switch (getOpcode()) {
+ default:
+ return false;
+ case Instruction::AtomicCmpXchg:
+ case Instruction::AtomicRMW:
+ case Instruction::Fence:
+ return true;
+ case Instruction::Load:
+ return cast<LoadInst>(this)->getOrdering() != NotAtomic;
+ case Instruction::Store:
+ return cast<StoreInst>(this)->getOrdering() != NotAtomic;
+ }
+}
+
bool Instruction::mayThrow() const {
if (const CallInst *CI = dyn_cast<CallInst>(this))
return !CI->doesNotThrow();
+ if (const auto *CRI = dyn_cast<CleanupReturnInst>(this))
+ return CRI->unwindsToCaller();
+ if (const auto *CEPI = dyn_cast<CleanupEndPadInst>(this))
+ return CEPI->unwindsToCaller();
+ if (const auto *CEPI = dyn_cast<CatchEndPadInst>(this))
+ return CEPI->unwindsToCaller();
+ if (const auto *TPI = dyn_cast<TerminatePadInst>(this))
+ return TPI->unwindsToCaller();
return isa<ResumeInst>(this);
}
return Opcode == Xor;
}
+Instruction *Instruction::cloneImpl() const {
+ llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
+}
+
Instruction *Instruction::clone() const {
- Instruction *New = clone_impl();
+ Instruction *New = nullptr;
+ switch (getOpcode()) {
+ default:
+ llvm_unreachable("Unhandled Opcode.");
+#define HANDLE_INST(num, opc, clas) \
+ case Instruction::opc: \
+ New = cast<clas>(this)->cloneImpl(); \
+ break;
+#include "llvm/IR/Instruction.def"
+#undef HANDLE_INST
+ }
+
New->SubclassOptionalData = SubclassOptionalData;
if (!hasMetadata())
return New;
// Otherwise, enumerate and copy over metadata from the old instruction to the
// new one.
- SmallVector<std::pair<unsigned, MDNode*>, 4> TheMDs;
+ SmallVector<std::pair<unsigned, MDNode *>, 4> TheMDs;
getAllMetadataOtherThanDebugLoc(TheMDs);
for (const auto &MD : TheMDs)
New->setMetadata(MD.first, MD.second);