Index: include/llvm/CodeGen/CommandFlags.h =================================================================== --- include/llvm/CodeGen/CommandFlags.h +++ include/llvm/CodeGen/CommandFlags.h @@ -385,7 +385,8 @@ if (F->getIntrinsicID() == Intrinsic::debugtrap || F->getIntrinsicID() == Intrinsic::trap) Call->addAttribute(llvm::AttributeSet::FunctionIndex, - "trap-func-name", TrapFuncName); + Attribute::get(Ctx, "trap-func-name", + TrapFuncName)); // Let NewAttrs override Attrs. NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs); Index: include/llvm/IR/Attributes.h =================================================================== --- include/llvm/IR/Attributes.h +++ include/llvm/IR/Attributes.h @@ -337,6 +337,10 @@ /// may be faster. bool hasFnAttribute(Attribute::AttrKind Kind) const; + /// \brief Equivalent to hasAttribute(AttributeSet::FunctionIndex, Kind) but + /// may be faster. + bool hasFnAttribute(StringRef Kind) const; + /// \brief Return true if the specified attribute is set for at least one /// parameter or for the return value. bool hasAttrSomewhere(Attribute::AttrKind Kind) const; Index: include/llvm/IR/CallSite.h =================================================================== --- include/llvm/IR/CallSite.h +++ include/llvm/IR/CallSite.h @@ -298,10 +298,10 @@ /// getAttributes/setAttributes - get or set the parameter attributes of /// the call. - const AttributeSet &getAttributes() const { + AttributeSet getAttributes() const { CALLSITE_DELEGATE_GETTER(getAttributes()); } - void setAttributes(const AttributeSet &PAL) { + void setAttributes(AttributeSet PAL) { CALLSITE_DELEGATE_SETTER(setAttributes(PAL)); } @@ -309,10 +309,6 @@ CALLSITE_DELEGATE_SETTER(addAttribute(i, Kind)); } - void addAttribute(unsigned i, StringRef Kind, StringRef Value) { - CALLSITE_DELEGATE_SETTER(addAttribute(i, Kind, Value)); - } - void addAttribute(unsigned i, Attribute Attr) { CALLSITE_DELEGATE_SETTER(addAttribute(i, Attr)); } @@ -325,10 +321,6 @@ CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind)); } - void removeAttribute(unsigned i, Attribute Attr) { - CALLSITE_DELEGATE_SETTER(removeAttribute(i, Attr)); - } - /// \brief Return true if this function has the given attribute. bool hasFnAttr(Attribute::AttrKind Kind) const { CALLSITE_DELEGATE_GETTER(hasFnAttr(Kind)); Index: include/llvm/IR/Function.h =================================================================== --- include/llvm/IR/Function.h +++ include/llvm/IR/Function.h @@ -166,27 +166,23 @@ void setAttributes(AttributeSet Attrs) { AttributeSets = Attrs; } /// @brief Add function attributes to this function. - void addFnAttr(Attribute::AttrKind N) { - setAttributes(AttributeSets.addAttribute(getContext(), - AttributeSet::FunctionIndex, N)); + void addFnAttr(Attribute::AttrKind Kind) { + addAttribute(AttributeSet::FunctionIndex, Kind); } - /// @brief Remove function attributes from this function. - void removeFnAttr(Attribute::AttrKind Kind) { - setAttributes(AttributeSets.removeAttribute( - getContext(), AttributeSet::FunctionIndex, Kind)); + /// @brief Add function attributes to this function. + void addFnAttr(StringRef Kind, StringRef Val = StringRef()) { + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Kind, Val)); } - /// @brief Add function attributes to this function. - void addFnAttr(StringRef Kind) { - setAttributes( - AttributeSets.addAttribute(getContext(), - AttributeSet::FunctionIndex, Kind)); + void addFnAttr(Attribute Attr) { + addAttribute(AttributeSet::FunctionIndex, Attr); } - void addFnAttr(StringRef Kind, StringRef Value) { - setAttributes( - AttributeSets.addAttribute(getContext(), - AttributeSet::FunctionIndex, Kind, Value)); + + /// @brief Remove function attributes from this function. + void removeFnAttr(Attribute::AttrKind Kind) { + removeAttribute(AttributeSet::FunctionIndex, Kind); } /// Set the entry count for this function. @@ -200,7 +196,7 @@ return AttributeSets.hasFnAttribute(Kind); } bool hasFnAttribute(StringRef Kind) const { - return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind); + return AttributeSets.hasFnAttribute(Kind); } /// @brief Return the attribute for the given attribute kind. Index: include/llvm/IR/Instructions.h =================================================================== --- include/llvm/IR/Instructions.h +++ include/llvm/IR/Instructions.h @@ -1611,19 +1611,16 @@ /// getAttributes - Return the parameter attributes for this call. /// - const AttributeSet &getAttributes() const { return AttributeList; } + AttributeSet getAttributes() const { return AttributeList; } /// setAttributes - Set the parameter attributes for this call. /// - void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } + void setAttributes(AttributeSet Attrs) { AttributeList = Attrs; } /// addAttribute - adds the attribute to the list of attributes. void addAttribute(unsigned i, Attribute::AttrKind Kind); /// addAttribute - adds the attribute to the list of attributes. - void addAttribute(unsigned i, StringRef Kind, StringRef Value); - - /// addAttribute - adds the attribute to the list of attributes. void addAttribute(unsigned i, Attribute Attr); /// removeAttribute - removes the attribute from the list of attributes. @@ -1632,9 +1629,6 @@ /// removeAttribute - removes the attribute from the list of attributes. void removeAttribute(unsigned i, StringRef Kind); - /// removeAttribute - removes the attribute from the list of attributes. - void removeAttribute(unsigned i, Attribute Attr); - /// \brief adds the dereferenceable attribute to the list of attributes. void addDereferenceableAttr(unsigned i, uint64_t Bytes); @@ -1658,10 +1652,14 @@ bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const; /// \brief Get the attribute of a given kind at a position. - Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const; + Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { + return getAttributes().getAttribute(i, Kind); + } /// \brief Get the attribute of a given kind at a position. - Attribute getAttribute(unsigned i, StringRef Kind) const; + Attribute getAttribute(unsigned i, StringRef Kind) const { + return getAttributes().getAttribute(i, Kind); + } /// \brief Return true if the data operand at index \p i has the attribute \p /// A. @@ -1780,8 +1778,7 @@ addAttribute(AttributeSet::FunctionIndex, Attribute::Convergent); } void setNotConvergent() { - removeAttribute(AttributeSet::FunctionIndex, - Attribute::get(getContext(), Attribute::Convergent)); + removeAttribute(AttributeSet::FunctionIndex, Attribute::Convergent); } /// \brief Determine if the call returns a structure through first @@ -1838,17 +1835,17 @@ } private: - template bool hasFnAttrImpl(AttrKind A) const { - if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A)) + template bool hasFnAttrImpl(AttrKind Kind) const { + if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, Kind)) return true; // Operand bundles override attributes on the called function, but don't // override attributes directly present on the call instruction. - if (isFnAttrDisallowedByOpBundle(A)) + if (isFnAttrDisallowedByOpBundle(Kind)) return false; if (const Function *F = getCalledFunction()) - return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A); + return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind); return false; } @@ -3579,11 +3576,11 @@ /// getAttributes - Return the parameter attributes for this invoke. /// - const AttributeSet &getAttributes() const { return AttributeList; } + AttributeSet getAttributes() const { return AttributeList; } /// setAttributes - Set the parameter attributes for this invoke. /// - void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } + void setAttributes(AttributeSet Attrs) { AttributeList = Attrs; } /// addAttribute - adds the attribute to the list of attributes. void addAttribute(unsigned i, Attribute::AttrKind Kind); @@ -3597,9 +3594,6 @@ /// removeAttribute - removes the attribute from the list of attributes. void removeAttribute(unsigned i, StringRef Kind); - /// removeAttribute - removes the attribute from the list of attributes. - void removeAttribute(unsigned i, Attribute Attr); - /// \brief adds the dereferenceable attribute to the list of attributes. void addDereferenceableAttr(unsigned i, uint64_t Bytes); @@ -3623,10 +3617,14 @@ bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const; /// \brief Get the attribute of a given kind at a position. - Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const; + Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { + return getAttributes().getAttribute(i, Kind); + } /// \brief Get the attribute of a given kind at a position. - Attribute getAttribute(unsigned i, StringRef Kind) const; + Attribute getAttribute(unsigned i, StringRef Kind) const { + return getAttributes().getAttribute(i, Kind); + } /// \brief Return true if the data operand at index \p i has the attribute \p /// A. @@ -3740,8 +3738,7 @@ addAttribute(AttributeSet::FunctionIndex, Attribute::Convergent); } void setNotConvergent() { - removeAttribute(AttributeSet::FunctionIndex, - Attribute::get(getContext(), Attribute::Convergent)); + removeAttribute(AttributeSet::FunctionIndex, Attribute::Convergent); } /// \brief Determine if the call returns a structure through first @@ -3827,17 +3824,17 @@ unsigned getNumSuccessorsV() const override; void setSuccessorV(unsigned idx, BasicBlock *B) override; - template bool hasFnAttrImpl(AttrKind A) const { - if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A)) + template bool hasFnAttrImpl(AttrKind Kind) const { + if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, Kind)) return true; // Operand bundles override attributes on the called function, but don't // override attributes directly present on the invoke instruction. - if (isFnAttrDisallowedByOpBundle(A)) + if (isFnAttrDisallowedByOpBundle(Kind)) return false; if (const Function *F = getCalledFunction()) - return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A); + return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind); return false; } Index: lib/IR/Attributes.cpp =================================================================== --- lib/IR/Attributes.cpp +++ lib/IR/Attributes.cpp @@ -1108,6 +1108,10 @@ return pImpl && pImpl->hasFnAttribute(Kind); } +bool AttributeSet::hasFnAttribute(StringRef Kind) const { + return hasAttribute(AttributeSet::FunctionIndex, Kind); +} + bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { if (!pImpl) return false; Index: lib/IR/Instructions.cpp =================================================================== --- lib/IR/Instructions.cpp +++ lib/IR/Instructions.cpp @@ -337,12 +337,6 @@ setAttributes(PAL); } -void CallInst::addAttribute(unsigned i, StringRef Kind, StringRef Value) { - AttributeSet PAL = getAttributes(); - PAL = PAL.addAttribute(getContext(), i, Kind, Value); - setAttributes(PAL); -} - void CallInst::addAttribute(unsigned i, Attribute Attr) { AttributeSet PAL = getAttributes(); PAL = PAL.addAttribute(getContext(), i, Attr); @@ -361,15 +355,6 @@ setAttributes(PAL); } -void CallInst::removeAttribute(unsigned i, Attribute Attr) { - AttributeSet PAL = getAttributes(); - AttrBuilder B(Attr); - LLVMContext &Context = getContext(); - PAL = PAL.removeAttributes(Context, i, - AttributeSet::get(Context, i, B)); - setAttributes(PAL); -} - void CallInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) { AttributeSet PAL = getAttributes(); PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); @@ -392,14 +377,6 @@ return false; } -Attribute CallInst::getAttribute(unsigned i, Attribute::AttrKind Kind) const { - return getAttributes().getAttribute(i, Kind); -} - -Attribute CallInst::getAttribute(unsigned i, StringRef Kind) const { - return getAttributes().getAttribute(i, Kind); -} - bool CallInst::dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const { // There are getNumOperands() - 1 data operands. The last operand is the @@ -740,23 +717,6 @@ setAttributes(PAL); } -void InvokeInst::removeAttribute(unsigned i, Attribute Attr) { - AttributeSet PAL = getAttributes(); - AttrBuilder B(Attr); - PAL = PAL.removeAttributes(getContext(), i, - AttributeSet::get(getContext(), i, B)); - setAttributes(PAL); -} - -Attribute InvokeInst::getAttribute(unsigned i, - Attribute::AttrKind Kind) const { - return getAttributes().getAttribute(i, Kind); -} - -Attribute InvokeInst::getAttribute(unsigned i, StringRef Kind) const { - return getAttributes().getAttribute(i, Kind); -} - void InvokeInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) { AttributeSet PAL = getAttributes(); PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);