X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FInstruction.cpp;h=c1d638775755ddad2cb79169273d83e63cde8480;hb=4e4c3408a5a1cc72b739a4b448329a281c379c55;hp=cd8f737e28444069efde470b46674f1233d4eac2;hpb=8a552bb85a5e9a6c250c0a899941fbd3ae7b5006;p=oota-llvm.git diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index cd8f737e284..c1d63877575 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -101,7 +101,7 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case Switch: return "switch"; case IndirectBr: return "indirectbr"; case Invoke: return "invoke"; - case Unwind: return "unwind"; + case Resume: return "resume"; case Unreachable: return "unreachable"; // Standard binary operators... @@ -127,6 +127,8 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case Alloca: return "alloca"; case Load: return "load"; case Store: return "store"; + case AtomicCmpXchg: return "cmpxchg"; + case AtomicRMW: return "atomicrmw"; case Fence: return "fence"; case GetElementPtr: return "getelementptr"; @@ -159,11 +161,10 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case ShuffleVector: return "shufflevector"; case ExtractValue: return "extractvalue"; case InsertValue: return "insertvalue"; + case LandingPad: return "landingpad"; default: return " "; } - - return 0; } /// isIdenticalTo - Return true if the specified instruction is exactly @@ -192,10 +193,14 @@ bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const { // Check special state that is a part of some instructions. if (const LoadInst *LI = dyn_cast(this)) return LI->isVolatile() == cast(I)->isVolatile() && - LI->getAlignment() == cast(I)->getAlignment(); + LI->getAlignment() == cast(I)->getAlignment() && + LI->getOrdering() == cast(I)->getOrdering() && + LI->getSynchScope() == cast(I)->getSynchScope(); if (const StoreInst *SI = dyn_cast(this)) return SI->isVolatile() == cast(I)->isVolatile() && - SI->getAlignment() == cast(I)->getAlignment(); + SI->getAlignment() == cast(I)->getAlignment() && + SI->getOrdering() == cast(I)->getOrdering() && + SI->getSynchScope() == cast(I)->getSynchScope(); if (const CmpInst *CI = dyn_cast(this)) return CI->getPredicate() == cast(I)->getPredicate(); if (const CallInst *CI = dyn_cast(this)) @@ -212,7 +217,23 @@ bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const { if (const FenceInst *FI = dyn_cast(this)) return FI->getOrdering() == cast(FI)->getOrdering() && FI->getSynchScope() == cast(FI)->getSynchScope(); - + if (const AtomicCmpXchgInst *CXI = dyn_cast(this)) + return CXI->isVolatile() == cast(I)->isVolatile() && + CXI->getOrdering() == cast(I)->getOrdering() && + CXI->getSynchScope() == cast(I)->getSynchScope(); + if (const AtomicRMWInst *RMWI = dyn_cast(this)) + return RMWI->getOperation() == cast(I)->getOperation() && + RMWI->isVolatile() == cast(I)->isVolatile() && + RMWI->getOrdering() == cast(I)->getOrdering() && + RMWI->getSynchScope() == cast(I)->getSynchScope(); + if (const PHINode *thisPHI = dyn_cast(this)) { + const PHINode *otherPHI = cast(I); + for (unsigned i = 0, e = thisPHI->getNumOperands(); i != e; ++i) { + if (thisPHI->getIncomingBlock(i) != otherPHI->getIncomingBlock(i)) + return false; + } + return true; + } return true; } @@ -234,10 +255,14 @@ bool Instruction::isSameOperationAs(const Instruction *I) const { // Check special state that is a part of some instructions. if (const LoadInst *LI = dyn_cast(this)) return LI->isVolatile() == cast(I)->isVolatile() && - LI->getAlignment() == cast(I)->getAlignment(); + LI->getAlignment() == cast(I)->getAlignment() && + LI->getOrdering() == cast(I)->getOrdering() && + LI->getSynchScope() == cast(I)->getSynchScope(); if (const StoreInst *SI = dyn_cast(this)) return SI->isVolatile() == cast(I)->isVolatile() && - SI->getAlignment() == cast(I)->getAlignment(); + SI->getAlignment() == cast(I)->getAlignment() && + SI->getOrdering() == cast(I)->getOrdering() && + SI->getSynchScope() == cast(I)->getSynchScope(); if (const CmpInst *CI = dyn_cast(this)) return CI->getPredicate() == cast(I)->getPredicate(); if (const CallInst *CI = dyn_cast(this)) @@ -253,8 +278,17 @@ bool Instruction::isSameOperationAs(const Instruction *I) const { if (const ExtractValueInst *EVI = dyn_cast(this)) return EVI->getIndices() == cast(I)->getIndices(); if (const FenceInst *FI = dyn_cast(this)) - return FI->getOrdering() == cast(FI)->getOrdering() && - FI->getSynchScope() == cast(FI)->getSynchScope(); + return FI->getOrdering() == cast(I)->getOrdering() && + FI->getSynchScope() == cast(I)->getSynchScope(); + if (const AtomicCmpXchgInst *CXI = dyn_cast(this)) + return CXI->isVolatile() == cast(I)->isVolatile() && + CXI->getOrdering() == cast(I)->getOrdering() && + CXI->getSynchScope() == cast(I)->getSynchScope(); + if (const AtomicRMWInst *RMWI = dyn_cast(this)) + return RMWI->getOperation() == cast(I)->getOperation() && + RMWI->isVolatile() == cast(I)->isVolatile() && + RMWI->getOrdering() == cast(I)->getOrdering() && + RMWI->getSynchScope() == cast(I)->getSynchScope(); return true; } @@ -288,13 +322,15 @@ bool Instruction::mayReadFromMemory() const { case Instruction::VAArg: case Instruction::Load: case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory + case Instruction::AtomicCmpXchg: + case Instruction::AtomicRMW: return true; case Instruction::Call: return !cast(this)->doesNotAccessMemory(); case Instruction::Invoke: return !cast(this)->doesNotAccessMemory(); case Instruction::Store: - return cast(this)->isVolatile(); + return !cast(this)->isUnordered(); } } @@ -306,13 +342,15 @@ bool Instruction::mayWriteToMemory() const { case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory case Instruction::Store: case Instruction::VAArg: + case Instruction::AtomicCmpXchg: + case Instruction::AtomicRMW: return true; case Instruction::Call: return !cast(this)->onlyReadsMemory(); case Instruction::Invoke: return !cast(this)->onlyReadsMemory(); case Instruction::Load: - return cast(this)->isVolatile(); + return !cast(this)->isUnordered(); } } @@ -321,7 +359,7 @@ bool Instruction::mayWriteToMemory() const { bool Instruction::mayThrow() const { if (const CallInst *CI = dyn_cast(this)) return !CI->doesNotThrow(); - return false; + return isa(this); } /// isAssociative - Return true if the instruction is associative: @@ -357,55 +395,6 @@ bool Instruction::isCommutative(unsigned op) { } } -bool Instruction::isSafeToSpeculativelyExecute() const { - for (unsigned i = 0, e = getNumOperands(); i != e; ++i) - if (Constant *C = dyn_cast(getOperand(i))) - if (C->canTrap()) - return false; - - switch (getOpcode()) { - default: - return true; - case UDiv: - case URem: { - // x / y is undefined if y == 0, but calcuations like x / 3 are safe. - ConstantInt *Op = dyn_cast(getOperand(1)); - return Op && !Op->isNullValue(); - } - case SDiv: - case SRem: { - // x / y is undefined if y == 0, and might be undefined if y == -1, - // but calcuations like x / 3 are safe. - ConstantInt *Op = dyn_cast(getOperand(1)); - return Op && !Op->isNullValue() && !Op->isAllOnesValue(); - } - case Load: { - const LoadInst *LI = cast(this); - if (LI->isVolatile()) - return false; - return LI->getPointerOperand()->isDereferenceablePointer(); - } - case Call: - return false; // The called function could have undefined behavior or - // side-effects. - // FIXME: We should special-case some intrinsics (bswap, - // overflow-checking arithmetic, etc.) - case VAArg: - case Alloca: - case Invoke: - case PHI: - case Store: - case Ret: - case Br: - case IndirectBr: - case Switch: - case Unwind: - case Unreachable: - case Fence: - return false; // Misc instructions which have effects - } -} - Instruction *Instruction::clone() const { Instruction *New = clone_impl(); New->SubclassOptionalData = SubclassOptionalData;