X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FInstruction.cpp;h=e8738d2ba72bd755ab7427f8987834bac0781558;hb=51cd9d6e073932fcb37f1857c66249d6c7d368ee;hp=48c73a08400c076316c5247ac002c6ca8fd396fe;hpb=fadb3f773e5ab171315761d151c1416921d25614;p=oota-llvm.git diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 48c73a08400..e8738d2ba72 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -13,13 +13,13 @@ #include "llvm/Type.h" #include "llvm/Instructions.h" -#include "llvm/IntrinsicInst.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); @@ -30,11 +30,10 @@ Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps, "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); @@ -42,34 +41,6 @@ Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps, // 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); } @@ -97,6 +68,12 @@ void Instruction::eraseFromParent() { getParent()->getInstList().erase(this); } +/// 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); +} + /// moveBefore - Unlink this instruction from its current basic block and /// insert it into the basic block that MovePos lives in, right before /// MovePos. @@ -157,6 +134,8 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { // Other instructions... case ICmp: return "icmp"; case FCmp: return "fcmp"; + case VICmp: return "vicmp"; + case VFCmp: return "vfcmp"; case PHI: return "phi"; case Select: return "select"; case Call: return "call"; @@ -167,6 +146,9 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case ExtractElement: return "extractelement"; case InsertElement: return "insertelement"; case ShuffleVector: return "shufflevector"; + case GetResult: return "getresult"; + case ExtractValue: return "extractvalue"; + case InsertValue: return "insertvalue"; default: return " "; } @@ -226,6 +208,45 @@ bool Instruction::isSameOperationAs(Instruction *I) const { return true; } +/// isUsedOutsideOfBlock - Return true if there are any uses of I outside of the +/// 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) { + // 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); + if (PN == 0) { + if (cast(*UI)->getParent() != BB) + return true; + continue; + } + + unsigned UseOperand = UI.getOperandNo(); + if (PN->getIncomingBlock(UseOperand/2) != BB) + return true; + } + return false; +} + +/// mayReadFromMemory - Return true if this instruction may read memory. +/// +bool Instruction::mayReadFromMemory() const { + switch (getOpcode()) { + default: return false; + case Instruction::Free: + case Instruction::VAArg: + case Instruction::Load: + return true; + case Instruction::Call: + return !cast(this)->doesNotAccessMemory(); + case Instruction::Invoke: + return !cast(this)->doesNotAccessMemory(); + case Instruction::Store: + return cast(this)->isVolatile(); + } +} + /// mayWriteToMemory - Return true if this instruction may modify memory. /// bool Instruction::mayWriteToMemory() const { @@ -233,14 +254,12 @@ bool Instruction::mayWriteToMemory() const { default: return false; case Instruction::Free: case Instruction::Store: - case Instruction::Invoke: case Instruction::VAArg: return true; case Instruction::Call: - if (const IntrinsicInst *II = dyn_cast(this)) { - // If the intrinsic doesn't write memory, it is safe. - } - return true; + return !cast(this)->onlyReadsMemory(); + case Instruction::Invoke: + return !cast(this)->onlyReadsMemory(); case Instruction::Load: return cast(this)->isVolatile(); } @@ -297,6 +316,7 @@ bool Instruction::isTrapping(unsigned op) { case Store: case Call: case Invoke: + case VAArg: return true; default: return false;