X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FInstruction.cpp;h=2c8b8b23b18e37fe8ab22439812e70ce14385945;hb=b34d837397053da8e9bff90dd714e24f2a3b98b3;hp=5cb1040e4bc4a41dc4483dbe2776d392fc46980d;hpb=ffa363c94b7180635efd3c5391da0e034eb138f3;p=oota-llvm.git diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 5cb1040e4bc..2c8b8b23b18 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -11,12 +11,10 @@ // //===----------------------------------------------------------------------===// -#include "LLVMContextImpl.h" +#include "llvm/Instruction.h" #include "llvm/Type.h" #include "llvm/Instructions.h" -#include "llvm/Function.h" #include "llvm/Constants.h" -#include "llvm/GlobalVariable.h" #include "llvm/Module.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/LeakDetector.h" @@ -50,11 +48,9 @@ Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps, // Out of line virtual method, so the vtable, etc has a home. Instruction::~Instruction() { - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsDeleted(this); - } assert(Parent == 0 && "Instruction still linked in the program!"); + if (hasMetadataHashEntry()) + clearMetadataHashEntries(); } @@ -103,6 +99,7 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case Ret: return "ret"; case Br: return "br"; case Switch: return "switch"; + case IndirectBr: return "indirectbr"; case Invoke: return "invoke"; case Unwind: return "unwind"; case Unreachable: return "unreachable"; @@ -127,8 +124,6 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case Xor: return "xor"; // Memory instructions... - case Malloc: return "malloc"; - case Free: return "free"; case Alloca: return "alloca"; case Load: return "load"; case Store: return "store"; @@ -205,12 +200,10 @@ bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const { if (const CallInst *CI = dyn_cast(this)) return CI->isTailCall() == cast(I)->isTailCall() && CI->getCallingConv() == cast(I)->getCallingConv() && - CI->getAttributes().getRawPointer() == - cast(I)->getAttributes().getRawPointer(); + CI->getAttributes() == cast(I)->getAttributes(); if (const InvokeInst *CI = dyn_cast(this)) return CI->getCallingConv() == cast(I)->getCallingConv() && - CI->getAttributes().getRawPointer() == - cast(I)->getAttributes().getRawPointer(); + CI->getAttributes() == cast(I)->getAttributes(); if (const InsertValueInst *IVI = dyn_cast(this)) { if (IVI->getNumIndices() != cast(I)->getNumIndices()) return false; @@ -258,12 +251,11 @@ bool Instruction::isSameOperationAs(const Instruction *I) const { if (const CallInst *CI = dyn_cast(this)) return CI->isTailCall() == cast(I)->isTailCall() && CI->getCallingConv() == cast(I)->getCallingConv() && - CI->getAttributes().getRawPointer() == - cast(I)->getAttributes().getRawPointer(); + CI->getAttributes() == cast(I)->getAttributes(); if (const InvokeInst *CI = dyn_cast(this)) return CI->getCallingConv() == cast(I)->getCallingConv() && - CI->getAttributes().getRawPointer() == - cast(I)->getAttributes().getRawPointer(); + CI->getAttributes() == + cast(I)->getAttributes(); if (const InsertValueInst *IVI = dyn_cast(this)) { if (IVI->getNumIndices() != cast(I)->getNumIndices()) return false; @@ -288,12 +280,13 @@ bool Instruction::isSameOperationAs(const Instruction *I) const { /// 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) { + for (const_use_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(*UI); + const User *U = *UI; + const PHINode *PN = dyn_cast(U); if (PN == 0) { - if (cast(*UI)->getParent() != BB) + if (cast(U)->getParent() != BB) return true; continue; } @@ -309,7 +302,6 @@ bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const { bool Instruction::mayReadFromMemory() const { switch (getOpcode()) { default: return false; - case Instruction::Free: case Instruction::VAArg: case Instruction::Load: return true; @@ -327,7 +319,6 @@ bool Instruction::mayReadFromMemory() const { bool Instruction::mayWriteToMemory() const { switch (getOpcode()) { default: return false; - case Instruction::Free: case Instruction::Store: case Instruction::VAArg: return true; @@ -354,7 +345,7 @@ bool Instruction::mayThrow() const { /// /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative. /// -bool Instruction::isAssociative(unsigned Opcode, const Type *Ty) { +bool Instruction::isAssociative(unsigned Opcode) { return Opcode == And || Opcode == Or || Opcode == Xor || Opcode == Add || Opcode == Mul; } @@ -381,27 +372,6 @@ bool Instruction::isCommutative(unsigned op) { } } -// Code here matches isMalloc from MallocHelper, which is not in VMCore. -static bool isMalloc(const Value* I) { - const CallInst *CI = dyn_cast(I); - if (!CI) { - const BitCastInst *BCI = dyn_cast(I); - if (!BCI) return false; - - CI = dyn_cast(BCI->getOperand(0)); - } - - if (!CI) return false; - - const Module* M = CI->getParent()->getParent()->getParent(); - Constant *MallocFunc = M->getFunction("malloc"); - - if (CI->getOperand(0) != MallocFunc) - return false; - - return true; -} - bool Instruction::isSafeToSpeculativelyExecute() const { for (unsigned i = 0, e = getNumOperands(); i != e; ++i) if (Constant *C = dyn_cast(getOperand(i))) @@ -425,15 +395,10 @@ bool Instruction::isSafeToSpeculativelyExecute() const { return Op && !Op->isNullValue() && !Op->isAllOnesValue(); } case Load: { - if (cast(this)->isVolatile()) + const LoadInst *LI = cast(this); + if (LI->isVolatile()) return false; - if (isa(getOperand(0)) || isMalloc(getOperand(0))) - return true; - if (GlobalVariable *GV = dyn_cast(getOperand(0))) - return !GV->hasExternalWeakLinkage(); - // FIXME: Handle cases involving GEPs. We have to be careful because - // a load of a out-of-bounds GEP has undefined behavior. - return false; + return LI->getPointerOperand()->isDereferenceablePointer(); } case Call: return false; // The called function could have undefined behavior or @@ -442,16 +407,30 @@ bool Instruction::isSafeToSpeculativelyExecute() const { // overflow-checking arithmetic, etc.) case VAArg: case Alloca: - case Malloc: case Invoke: case PHI: case Store: - case Free: case Ret: case Br: + case IndirectBr: case Switch: case Unwind: case Unreachable: return false; // Misc instructions which have effects } } + +Instruction *Instruction::clone() const { + Instruction *New = clone_impl(); + New->SubclassOptionalData = SubclassOptionalData; + if (!hasMetadata()) + return New; + + // Otherwise, enumerate and copy over metadata from the old instruction to the + // new one. + SmallVector, 4> TheMDs; + getAllMetadata(TheMDs); + for (unsigned i = 0, e = TheMDs.size(); i != e; ++i) + New->setMetadata(TheMDs[i].first, TheMDs[i].second); + return New; +}