X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FInstructions.h;h=9c526bd97bbb1087ce545fcf1d965f7d011b44ad;hb=f3840d2c16a4ec4c879a8ded402835746de380f8;hp=55ab1b7ff08f9d9b8864e5d04eff912f6807148b;hpb=060f20a0fa73d04b871e273fbf7b3e49a3e78b73;p=oota-llvm.git diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 55ab1b7ff08..9c526bd97bb 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -350,7 +350,16 @@ public: static unsigned getPointerOperandIndex() { return 1U; } unsigned getPointerAddressSpace() const { - return cast(getPointerOperand()->getType())->getAddressSpace(); + if (getPointerOperand()->getType()->isPointerTy()) + return cast(getPointerOperand()->getType()) + ->getAddressSpace(); + if (getPointerOperand()->getType()->isVectorTy() + && cast(getPointerOperand()->getType())->isPointerTy()) + return cast(cast( + getPointerOperand()->getType())->getElementType()) + ->getAddressSpace(); + llvm_unreachable("Only a vector of pointers or pointers can be used!"); + return 0; } // Methods for support type inquiry through isa, cast, and dyn_cast: @@ -778,7 +787,7 @@ public: static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); - /// getIndexedType - Returns the address space used by the GEP pointer. + /// getAddressSpace - Returns the address space used by the GEP pointer. /// static unsigned getAddressSpace(Value *Ptr); @@ -798,7 +807,7 @@ public: } unsigned getPointerAddressSpace() const { - return cast(getType())->getAddressSpace(); + return cast(getPointerOperandType())->getAddressSpace(); } /// getPointerOperandType - Method to return the pointer operand as a @@ -1268,31 +1277,10 @@ public: void removeAttribute(unsigned i, Attributes attr); /// @brief Determine whether this call has the given attribute. - bool fnHasNoAliasAttr() const; - bool fnHasNoInlineAttr() const; - bool fnHasNoReturnAttr() const; - bool fnHasNoUnwindAttr() const; - bool fnHasReadNoneAttr() const; - bool fnHasReadOnlyAttr() const; - bool fnHasReturnsTwiceAttr() const; - - /// \brief Return true if this call has the given attribute. - bool hasFnAttr(Attributes N) const { - return paramHasAttr(~0, N); - } + bool hasFnAttr(Attributes::AttrVal A) const; /// @brief Determine whether the call or the callee has the given attributes. - bool paramHasByValAttr(unsigned i) const; - bool paramHasInRegAttr(unsigned i) const; - bool paramHasNestAttr(unsigned i) const; - bool paramHasNoAliasAttr(unsigned i) const; - bool paramHasNoCaptureAttr(unsigned i) const; - bool paramHasSExtAttr(unsigned i) const; - bool paramHasStructRetAttr(unsigned i) const; - bool paramHasZExtAttr(unsigned i) const; - - /// @brief Determine whether the call or the callee has the given attribute. - bool paramHasAttr(unsigned i, Attributes attr) const; + bool paramHasAttr(unsigned i, Attributes::AttrVal A) const; /// @brief Extract the alignment for a call or parameter (0=unknown). unsigned getParamAlignment(unsigned i) const { @@ -1300,63 +1288,72 @@ public: } /// @brief Return true if the call should not be inlined. - bool isNoInline() const { return fnHasNoInlineAttr(); } - void setIsNoInline(bool Value = true) { - if (Value) addAttribute(~0, Attribute::NoInline); - else removeAttribute(~0, Attribute::NoInline); + bool isNoInline() const { return hasFnAttr(Attributes::NoInline); } + void setIsNoInline() { + Attributes::Builder B; + B.addAttribute(Attributes::NoInline); + addAttribute(~0, Attributes::get(B)); } /// @brief Return true if the call can return twice bool canReturnTwice() const { - return fnHasReturnsTwiceAttr(); + return hasFnAttr(Attributes::ReturnsTwice); } - void setCanReturnTwice(bool Value = true) { - if (Value) addAttribute(~0, Attribute::ReturnsTwice); - else removeAttribute(~0, Attribute::ReturnsTwice); + void setCanReturnTwice() { + Attributes::Builder B; + B.addAttribute(Attributes::ReturnsTwice); + addAttribute(~0U, Attributes::get(B)); } /// @brief Determine if the call does not access memory. bool doesNotAccessMemory() const { - return fnHasReadNoneAttr(); + return hasFnAttr(Attributes::ReadNone); } - void setDoesNotAccessMemory(bool NotAccessMemory = true) { - if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone); - else removeAttribute(~0, Attribute::ReadNone); + void setDoesNotAccessMemory() { + Attributes::Builder B; + B.addAttribute(Attributes::ReadNone); + addAttribute(~0U, Attributes::get(B)); } /// @brief Determine if the call does not access or only reads memory. bool onlyReadsMemory() const { - return doesNotAccessMemory() || fnHasReadOnlyAttr(); + return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly); } - void setOnlyReadsMemory(bool OnlyReadsMemory = true) { - if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly); - else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone); + void setOnlyReadsMemory() { + Attributes::Builder B; + B.addAttribute(Attributes::ReadOnly); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call cannot return. - bool doesNotReturn() const { return fnHasNoReturnAttr(); } - void setDoesNotReturn(bool DoesNotReturn = true) { - if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn); - else removeAttribute(~0, Attribute::NoReturn); + bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); } + void setDoesNotReturn() { + Attributes::Builder B; + B.addAttribute(Attributes::NoReturn); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call cannot unwind. - bool doesNotThrow() const { return fnHasNoUnwindAttr(); } - void setDoesNotThrow(bool DoesNotThrow = true) { - if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind); - else removeAttribute(~0, Attribute::NoUnwind); + bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); } + void setDoesNotThrow() { + Attributes::Builder B; + B.addAttribute(Attributes::NoUnwind); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call returns a structure through first /// pointer argument. bool hasStructRetAttr() const { // Be friendly and also check the callee. - return paramHasStructRetAttr(1); + return paramHasAttr(1, Attributes::StructRet); } /// @brief Determine if any call argument is an aggregate passed by value. bool hasByValArgument() const { - return AttributeList.hasAttrSomewhere(Attribute::ByVal); + for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I) + if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attributes::ByVal)) + return true; + return false; } /// getCalledFunction - Return the function called, or null if this is an @@ -3049,31 +3046,10 @@ public: void removeAttribute(unsigned i, Attributes attr); /// @brief Determine whether this call has the NoAlias attribute. - bool fnHasNoAliasAttr() const; - bool fnHasNoInlineAttr() const; - bool fnHasNoReturnAttr() const; - bool fnHasNoUnwindAttr() const; - bool fnHasReadNoneAttr() const; - bool fnHasReadOnlyAttr() const; - bool fnHasReturnsTwiceAttr() const; - - /// \brief Return true if this call has the given attribute. - bool hasFnAttr(Attributes N) const { - return paramHasAttr(~0, N); - } + bool hasFnAttr(Attributes::AttrVal A) const; /// @brief Determine whether the call or the callee has the given attributes. - bool paramHasSExtAttr(unsigned i) const; - bool paramHasZExtAttr(unsigned i) const; - bool paramHasInRegAttr(unsigned i) const; - bool paramHasStructRetAttr(unsigned i) const; - bool paramHasNestAttr(unsigned i) const; - bool paramHasByValAttr(unsigned i) const; - bool paramHasNoAliasAttr(unsigned i) const; - bool paramHasNoCaptureAttr(unsigned i) const; - - /// @brief Determine whether the call or the callee has the given attribute. - bool paramHasAttr(unsigned i, Attributes attr) const; + bool paramHasAttr(unsigned i, Attributes::AttrVal A) const; /// @brief Extract the alignment for a call or parameter (0=unknown). unsigned getParamAlignment(unsigned i) const { @@ -3081,54 +3057,62 @@ public: } /// @brief Return true if the call should not be inlined. - bool isNoInline() const { return fnHasNoInlineAttr(); } - void setIsNoInline(bool Value = true) { - if (Value) addAttribute(~0, Attribute::NoInline); - else removeAttribute(~0, Attribute::NoInline); + bool isNoInline() const { return hasFnAttr(Attributes::NoInline); } + void setIsNoInline() { + Attributes::Builder B; + B.addAttribute(Attributes::NoInline); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call does not access memory. bool doesNotAccessMemory() const { - return fnHasReadNoneAttr(); + return hasFnAttr(Attributes::ReadNone); } - void setDoesNotAccessMemory(bool NotAccessMemory = true) { - if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone); - else removeAttribute(~0, Attribute::ReadNone); + void setDoesNotAccessMemory() { + Attributes::Builder B; + B.addAttribute(Attributes::ReadNone); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call does not access or only reads memory. bool onlyReadsMemory() const { - return doesNotAccessMemory() || fnHasReadOnlyAttr(); + return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly); } - void setOnlyReadsMemory(bool OnlyReadsMemory = true) { - if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly); - else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone); + void setOnlyReadsMemory() { + Attributes::Builder B; + B.addAttribute(Attributes::ReadOnly); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call cannot return. - bool doesNotReturn() const { return fnHasNoReturnAttr(); } - void setDoesNotReturn(bool DoesNotReturn = true) { - if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn); - else removeAttribute(~0, Attribute::NoReturn); + bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); } + void setDoesNotReturn() { + Attributes::Builder B; + B.addAttribute(Attributes::NoReturn); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call cannot unwind. - bool doesNotThrow() const { return fnHasNoUnwindAttr(); } - void setDoesNotThrow(bool DoesNotThrow = true) { - if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind); - else removeAttribute(~0, Attribute::NoUnwind); + bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); } + void setDoesNotThrow() { + Attributes::Builder B; + B.addAttribute(Attributes::NoUnwind); + addAttribute(~0, Attributes::get(B)); } /// @brief Determine if the call returns a structure through first /// pointer argument. bool hasStructRetAttr() const { // Be friendly and also check the callee. - return paramHasStructRetAttr(1); + return paramHasAttr(1, Attributes::StructRet); } /// @brief Determine if any call argument is an aggregate passed by value. bool hasByValArgument() const { - return AttributeList.hasAttrSomewhere(Attribute::ByVal); + for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I) + if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attributes::ByVal)) + return true; + return false; } /// getCalledFunction - Return the function called, or null if this is an @@ -3676,6 +3660,19 @@ public: /// @brief Clone an identical IntToPtrInst virtual IntToPtrInst *clone_impl() const; + /// @brief return the address space of the pointer. + unsigned getAddressSpace() const { + if (getType()->isPointerTy()) + return cast(getType())->getAddressSpace(); + if (getType()->isVectorTy() && + cast(getType())->getElementType()->isPointerTy()) + return cast( + cast(getType())->getElementType()) + ->getAddressSpace(); + llvm_unreachable("Must be a pointer or a vector of pointers."); + return 0; + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const IntToPtrInst *) { return true; } static inline bool classof(const Instruction *I) { @@ -3713,6 +3710,20 @@ public: BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + /// @brief return the address space of the pointer. + unsigned getPointerAddressSpace() const { + Type *Ty = getOperand(0)->getType(); + if (Ty->isPointerTy()) + return cast(Ty)->getAddressSpace(); + if (Ty->isVectorTy() + && cast(Ty)->getElementType()->isPointerTy()) + return cast( + cast(Ty)->getElementType()) + ->getAddressSpace(); + llvm_unreachable("Must be a pointer or a vector of pointers."); + return 0; + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const PtrToIntInst *) { return true; } static inline bool classof(const Instruction *I) {