Mercurial > hg > CbC > CbC_llvm
diff lib/IR/Instruction.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 7d135dc70f03 |
line wrap: on
line diff
--- a/lib/IR/Instruction.cpp Wed Feb 18 14:56:07 2015 +0900 +++ b/lib/IR/Instruction.cpp Tue Oct 13 17:48:58 2015 +0900 @@ -26,16 +26,12 @@ // 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) { @@ -58,32 +54,42 @@ Parent = P; } -void Instruction::removeFromParent() { - getParent()->getInstList().remove(this); +const Module *Instruction::getModule() const { + return getParent()->getModule(); +} + +Module *Instruction::getModule() { + return getParent()->getModule(); } -void Instruction::eraseFromParent() { - getParent()->getInstList().erase(this); + +void Instruction::removeFromParent() { + getParent()->getInstList().remove(getIterator()); +} + +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 @@ -191,6 +197,12 @@ 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"; @@ -251,6 +263,7 @@ case ExtractValue: return "extractvalue"; case InsertValue: return "insertvalue"; case LandingPad: return "landingpad"; + case CleanupPad: return "cleanuppad"; default: return "<Invalid operator> "; } @@ -402,6 +415,9 @@ 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(); @@ -422,6 +438,9 @@ 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(); @@ -450,6 +469,14 @@ 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); } @@ -529,8 +556,23 @@ 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;