X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FInstructions.h;h=be865a10476b11cadf01f286df506e19a9effb36;hb=cd7ee1ced017d7a957113df9d6cf855ecbc3797e;hp=2e75ec5f9abe47e9795a62770d54514350adb7d8;hpb=1521406a4b5b08209fb817a4673f636ef0fd8f46;p=oota-llvm.git diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 2e75ec5f9ab..be865a10476 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -16,22 +16,23 @@ #ifndef LLVM_INSTRUCTIONS_H #define LLVM_INSTRUCTIONS_H -#include "llvm/InstrTypes.h" -#include "llvm/DerivedTypes.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Attributes.h" #include "llvm/CallingConv.h" +#include "llvm/DerivedTypes.h" +#include "llvm/InstrTypes.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/IntegersSubset.h" #include "llvm/Support/IntegersSubsetMapping.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/Support/ErrorHandling.h" #include namespace llvm { +class APInt; class ConstantInt; class ConstantRange; -class APInt; +class DataLayout; class LLVMContext; enum AtomicOrdering { @@ -225,6 +226,7 @@ public: const Value *getPointerOperand() const { return getOperand(0); } static unsigned getPointerOperandIndex() { return 0U; } + /// \brief Returns the address space of the pointer operand. unsigned getPointerAddressSpace() const { return getPointerOperand()->getType()->getPointerAddressSpace(); } @@ -347,6 +349,7 @@ public: const Value *getPointerOperand() const { return getOperand(1); } static unsigned getPointerOperandIndex() { return 1U; } + /// \brief Returns the address space of the pointer operand. unsigned getPointerAddressSpace() const { return getPointerOperand()->getType()->getPointerAddressSpace(); } @@ -517,6 +520,7 @@ public: Value *getNewValOperand() { return getOperand(2); } const Value *getNewValOperand() const { return getOperand(2); } + /// \brief Returns the address space of the pointer operand. unsigned getPointerAddressSpace() const { return getPointerOperand()->getType()->getPointerAddressSpace(); } @@ -660,6 +664,7 @@ public: Value *getValOperand() { return getOperand(1); } const Value *getValOperand() const { return getOperand(1); } + /// \brief Returns the address space of the pointer operand. unsigned getPointerAddressSpace() const { return getPointerOperand()->getType()->getPointerAddressSpace(); } @@ -762,6 +767,13 @@ public: return reinterpret_cast(Instruction::getType()); } + /// \brief Returns the address space of this instruction's pointer type. + unsigned getAddressSpace() const { + // Note that this is always the same as the pointer operand's address space + // and that is cheaper to compute, so cheat here. + return getPointerAddressSpace(); + } + /// getIndexedType - Returns the type of the element that would be loaded with /// a load instruction with the specified parameters. /// @@ -793,6 +805,7 @@ public: return getPointerOperand()->getType(); } + /// \brief Returns the address space of the pointer operand. unsigned getPointerAddressSpace() const { return getPointerOperandType()->getPointerAddressSpace(); } @@ -838,6 +851,16 @@ public: /// isInBounds - Determine whether the GEP has the inbounds flag. bool isInBounds() const; + /// \brief Accumulate the constant address offset of this GEP if possible. + /// + /// This routine accepts an APInt into which it will accumulate the constant + /// offset of this GEP if the GEP is in fact constant. If the GEP is not + /// all-constant, it returns false and the value of the offset APInt is + /// undefined (it is *not* preserved!). The APInt passed into this routine + /// must be at least as wide as the IntPtr type for the address space of + /// the base GEP pointer. + bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const; + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::GetElementPtr); @@ -1144,7 +1167,7 @@ public: /// hold the calling convention of the call. /// class CallInst : public Instruction { - AttrListPtr AttributeList; ///< parameter attributes for call + AttributeSet AttributeList; ///< parameter attributes for call CallInst(const CallInst &CI); void init(Value *Func, ArrayRef Args, const Twine &NameStr); void init(Value *Func, const Twine &NameStr); @@ -1242,23 +1265,23 @@ public: /// getAttributes - Return the parameter attributes for this call. /// - const AttrListPtr &getAttributes() const { return AttributeList; } + const AttributeSet &getAttributes() const { return AttributeList; } /// setAttributes - Set the parameter attributes for this call. /// - void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; } + void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } /// addAttribute - adds the attribute to the list of attributes. - void addAttribute(unsigned i, Attributes attr); + void addAttribute(unsigned i, Attribute attr); /// removeAttribute - removes the attribute from the list of attributes. - void removeAttribute(unsigned i, Attributes attr); + void removeAttribute(unsigned i, Attribute attr); /// \brief Determine whether this call has the given attribute. - bool hasFnAttr(Attributes::AttrVal A) const; + bool hasFnAttr(Attribute::AttrVal A) const; /// \brief Determine whether the call or the callee has the given attributes. - bool paramHasAttr(unsigned i, Attributes::AttrVal A) const; + bool paramHasAttr(unsigned i, Attribute::AttrVal A) const; /// \brief Extract the alignment for a call or parameter (0=unknown). unsigned getParamAlignment(unsigned i) const { @@ -1266,64 +1289,64 @@ public: } /// \brief Return true if the call should not be inlined. - bool isNoInline() const { return hasFnAttr(Attributes::NoInline); } + bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } void setIsNoInline() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::NoInline)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::NoInline)); } /// \brief Return true if the call can return twice bool canReturnTwice() const { - return hasFnAttr(Attributes::ReturnsTwice); + return hasFnAttr(Attribute::ReturnsTwice); } void setCanReturnTwice() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::ReturnsTwice)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::ReturnsTwice)); } /// \brief Determine if the call does not access memory. bool doesNotAccessMemory() const { - return hasFnAttr(Attributes::ReadNone); + return hasFnAttr(Attribute::ReadNone); } void setDoesNotAccessMemory() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::ReadNone)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::ReadNone)); } /// \brief Determine if the call does not access or only reads memory. bool onlyReadsMemory() const { - return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly); + return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); } void setOnlyReadsMemory() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::ReadOnly)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::ReadOnly)); } /// \brief Determine if the call cannot return. - bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); } + bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } void setDoesNotReturn() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::NoReturn)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::NoReturn)); } /// \brief Determine if the call cannot unwind. - bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); } + bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } void setDoesNotThrow() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::NoUnwind)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::NoUnwind)); } /// \brief Determine if the call returns a structure through first /// pointer argument. bool hasStructRetAttr() const { // Be friendly and also check the callee. - return paramHasAttr(1, Attributes::StructRet); + return paramHasAttr(1, Attribute::StructRet); } /// \brief Determine if any call argument is an aggregate passed by value. bool hasByValArgument() const { for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I) - if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attributes::ByVal)) + if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attribute::ByVal)) return true; return false; } @@ -2930,7 +2953,7 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value) /// calling convention of the call. /// class InvokeInst : public TerminatorInst { - AttrListPtr AttributeList; + AttributeSet AttributeList; InvokeInst(const InvokeInst &BI); void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, const Twine &NameStr); @@ -2991,23 +3014,23 @@ public: /// getAttributes - Return the parameter attributes for this invoke. /// - const AttrListPtr &getAttributes() const { return AttributeList; } + const AttributeSet &getAttributes() const { return AttributeList; } /// setAttributes - Set the parameter attributes for this invoke. /// - void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; } + void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } /// addAttribute - adds the attribute to the list of attributes. - void addAttribute(unsigned i, Attributes attr); + void addAttribute(unsigned i, Attribute attr); /// removeAttribute - removes the attribute from the list of attributes. - void removeAttribute(unsigned i, Attributes attr); + void removeAttribute(unsigned i, Attribute attr); /// \brief Determine whether this call has the NoAlias attribute. - bool hasFnAttr(Attributes::AttrVal A) const; + bool hasFnAttr(Attribute::AttrVal A) const; /// \brief Determine whether the call or the callee has the given attributes. - bool paramHasAttr(unsigned i, Attributes::AttrVal A) const; + bool paramHasAttr(unsigned i, Attribute::AttrVal A) const; /// \brief Extract the alignment for a call or parameter (0=unknown). unsigned getParamAlignment(unsigned i) const { @@ -3015,55 +3038,55 @@ public: } /// \brief Return true if the call should not be inlined. - bool isNoInline() const { return hasFnAttr(Attributes::NoInline); } + bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } void setIsNoInline() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::NoInline)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::NoInline)); } /// \brief Determine if the call does not access memory. bool doesNotAccessMemory() const { - return hasFnAttr(Attributes::ReadNone); + return hasFnAttr(Attribute::ReadNone); } void setDoesNotAccessMemory() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::ReadNone)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::ReadNone)); } /// \brief Determine if the call does not access or only reads memory. bool onlyReadsMemory() const { - return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly); + return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); } void setOnlyReadsMemory() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::ReadOnly)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::ReadOnly)); } /// \brief Determine if the call cannot return. - bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); } + bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } void setDoesNotReturn() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::NoReturn)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::NoReturn)); } /// \brief Determine if the call cannot unwind. - bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); } + bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } void setDoesNotThrow() { - addAttribute(AttrListPtr::FunctionIndex, - Attributes::get(getContext(), Attributes::NoUnwind)); + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::NoUnwind)); } /// \brief Determine if the call returns a structure through first /// pointer argument. bool hasStructRetAttr() const { // Be friendly and also check the callee. - return paramHasAttr(1, Attributes::StructRet); + return paramHasAttr(1, Attribute::StructRet); } /// \brief Determine if any call argument is an aggregate passed by value. bool hasByValArgument() const { for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I) - if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attributes::ByVal)) + if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attribute::ByVal)) return true; return false; } @@ -3601,7 +3624,7 @@ public: /// \brief Clone an identical IntToPtrInst virtual IntToPtrInst *clone_impl() const; - /// \brief return the address space of the pointer. + /// \brief Returns the address space of this instruction's pointer type. unsigned getAddressSpace() const { return getType()->getPointerAddressSpace(); } @@ -3642,9 +3665,16 @@ public: BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); - /// \brief return the address space of the pointer. + /// \brief Gets the pointer operand. + Value *getPointerOperand() { return getOperand(0); } + /// \brief Gets the pointer operand. + const Value *getPointerOperand() const { return getOperand(0); } + /// \brief Gets the operand index of the pointer operand. + static unsigned getPointerOperandIndex() { return 0U; } + + /// \brief Returns the address space of the pointer operand. unsigned getPointerAddressSpace() const { - return getOperand(0)->getType()->getPointerAddressSpace(); + return getPointerOperand()->getType()->getPointerAddressSpace(); } // Methods for support type inquiry through isa, cast, and dyn_cast: