diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index 0c77110b33560c..d81f67deb8ea2c 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -432,8 +432,8 @@ class AttributeList { static AttributeList getImpl(LLVMContext &C, ArrayRef AttrSets); - AttributeList setAttributes(LLVMContext &C, unsigned Index, - AttributeSet Attrs) const; + AttributeList setAttributesAtIndex(LLVMContext &C, unsigned Index, + AttributeSet Attrs) const; public: AttributeList() = default; @@ -454,81 +454,101 @@ class AttributeList { static AttributeList get(LLVMContext &C, unsigned Index, const AttrBuilder &B); + // TODO: remove non-AtIndex versions of these methods. /// Add an attribute to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList addAttributeAtIndex( + LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const; LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, - Attribute::AttrKind Kind) const; + Attribute::AttrKind Kind) const { + return addAttributeAtIndex(C, Index, Kind); + } /// Add an attribute to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList + addAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind, + StringRef Value = StringRef()) const; + LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, StringRef Kind, - StringRef Value = StringRef()) const; + StringRef Value = StringRef()) const { + return addAttributeAtIndex(C, Index, Kind); + } /// Add an attribute to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList addAttributeAtIndex(LLVMContext &C, + unsigned Index, + Attribute A) const; LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, - Attribute A) const; + Attribute A) const { + return addAttributeAtIndex(C, Index, A); + } /// Add attributes to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList addAttributesAtIndex(LLVMContext &C, + unsigned Index, + const AttrBuilder &B) const; LLVM_NODISCARD AttributeList addAttributes(LLVMContext &C, unsigned Index, - const AttrBuilder &B) const; + const AttrBuilder &B) const { + return addAttributesAtIndex(C, Index, B); + } /// Add a function attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const { - return addAttribute(C, FunctionIndex, Kind); + return addAttributeAtIndex(C, FunctionIndex, Kind); } /// Add a function attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addFnAttribute(LLVMContext &C, Attribute Attr) const { - return addAttribute(C, FunctionIndex, Attr); + return addAttributeAtIndex(C, FunctionIndex, Attr); } /// Add a function attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addFnAttribute( LLVMContext &C, StringRef Kind, StringRef Value = StringRef()) const { - return addAttribute(C, FunctionIndex, Kind, Value); + return addAttributeAtIndex(C, FunctionIndex, Kind, Value); } /// Add function attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addFnAttributes(LLVMContext &C, const AttrBuilder &B) const { - return addAttributes(C, FunctionIndex, B); + return addAttributesAtIndex(C, FunctionIndex, B); } /// Add a return value attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const { - return addAttribute(C, ReturnIndex, Kind); + return addAttributeAtIndex(C, ReturnIndex, Kind); } /// Add a return value attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addRetAttribute(LLVMContext &C, Attribute Attr) const { - return addAttribute(C, ReturnIndex, Attr); + return addAttributeAtIndex(C, ReturnIndex, Attr); } /// Add a return value attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addRetAttributes(LLVMContext &C, const AttrBuilder &B) const { - return addAttributes(C, ReturnIndex, B); + return addAttributesAtIndex(C, ReturnIndex, B); } /// Add an argument attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addParamAttribute( LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const { - return addAttribute(C, ArgNo + FirstArgIndex, Kind); + return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind); } /// Add an argument attribute to the list. Returns a new list because @@ -536,7 +556,7 @@ class AttributeList { LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind, StringRef Value = StringRef()) const { - return addAttribute(C, ArgNo + FirstArgIndex, Kind, Value); + return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind, Value); } /// Add an attribute to the attribute list at the given arg indices. Returns a @@ -550,82 +570,99 @@ class AttributeList { LLVM_NODISCARD AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const { - return addAttributes(C, ArgNo + FirstArgIndex, B); + return addAttributesAtIndex(C, ArgNo + FirstArgIndex, B); } /// Remove the specified attribute at the specified index from this /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList removeAttributeAtIndex( + LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const; LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, - Attribute::AttrKind Kind) const; + Attribute::AttrKind Kind) const { + return removeAttributeAtIndex(C, Index, Kind); + } /// Remove the specified attribute at the specified index from this /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList removeAttributeAtIndex(LLVMContext &C, + unsigned Index, + StringRef Kind) const; LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, - StringRef Kind) const; + StringRef Kind) const { + return removeAttributeAtIndex(C, Index, Kind); + } /// Remove the specified attributes at the specified index from this /// attribute list. Returns a new list because attribute lists are immutable. - LLVM_NODISCARD AttributeList removeAttributes( + LLVM_NODISCARD AttributeList removeAttributesAtIndex( LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const; + LLVM_NODISCARD AttributeList removeAttributes( + LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const { + return removeAttributesAtIndex(C, Index, AttrsToRemove); + } /// Remove all attributes at the specified index from this /// attribute list. Returns a new list because attribute lists are immutable. + LLVM_NODISCARD AttributeList removeAttributesAtIndex(LLVMContext &C, + unsigned Index) const; LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C, - unsigned Index) const; + unsigned Index) const { + return removeAttributesAtIndex(C, Index); + } /// Remove the specified attribute at the function index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const { - return removeAttribute(C, FunctionIndex, Kind); + return removeAttributeAtIndex(C, FunctionIndex, Kind); } /// Remove the specified attribute at the function index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeFnAttribute(LLVMContext &C, StringRef Kind) const { - return removeAttribute(C, FunctionIndex, Kind); + return removeAttributeAtIndex(C, FunctionIndex, Kind); } /// Remove the specified attribute at the function index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeFnAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const { - return removeAttributes(C, FunctionIndex, AttrsToRemove); + return removeAttributesAtIndex(C, FunctionIndex, AttrsToRemove); } /// Remove the attributes at the function index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeFnAttributes(LLVMContext &C) const { - return removeAttributes(C, FunctionIndex); + return removeAttributesAtIndex(C, FunctionIndex); } /// Remove the specified attribute at the return value index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const { - return removeAttribute(C, ReturnIndex, Kind); + return removeAttributeAtIndex(C, ReturnIndex, Kind); } /// Remove the specified attribute at the return value index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeRetAttribute(LLVMContext &C, StringRef Kind) const { - return removeAttribute(C, ReturnIndex, Kind); + return removeAttributeAtIndex(C, ReturnIndex, Kind); } /// Remove the specified attribute at the return value index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeRetAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const { - return removeAttributes(C, ReturnIndex, AttrsToRemove); + return removeAttributesAtIndex(C, ReturnIndex, AttrsToRemove); } /// Remove the specified attribute at the specified arg index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeParamAttribute( LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const { - return removeAttribute(C, ArgNo + FirstArgIndex, Kind); + return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind); } /// Remove the specified attribute at the specified arg index from this @@ -633,32 +670,38 @@ class AttributeList { LLVM_NODISCARD AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind) const { - return removeAttribute(C, ArgNo + FirstArgIndex, Kind); + return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind); } /// Remove the specified attribute at the specified arg index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeParamAttributes( LLVMContext &C, unsigned ArgNo, const AttrBuilder &AttrsToRemove) const { - return removeAttributes(C, ArgNo + FirstArgIndex, AttrsToRemove); + return removeAttributesAtIndex(C, ArgNo + FirstArgIndex, AttrsToRemove); } /// Remove all attributes at the specified arg index from this /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo) const { - return removeAttributes(C, ArgNo + FirstArgIndex); + return removeAttributesAtIndex(C, ArgNo + FirstArgIndex); } /// Replace the type contained by attribute \p AttrKind at index \p ArgNo wih /// \p ReplacementTy, preserving all other attributes. + LLVM_NODISCARD AttributeList replaceAttributeTypeAtIndex( + LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind, + Type *ReplacementTy) const { + Attribute Attr = getAttributeAtIndex(ArgNo, Kind); + auto Attrs = removeAttributeAtIndex(C, ArgNo, Kind); + return Attrs.addAttributeAtIndex(C, ArgNo, + Attr.getWithNewType(C, ReplacementTy)); + } LLVM_NODISCARD AttributeList replaceAttributeType(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind, Type *ReplacementTy) const { - Attribute Attr = getAttribute(ArgNo, Kind); - auto Attrs = removeAttribute(C, ArgNo, Kind); - return Attrs.addAttribute(C, ArgNo, Attr.getWithNewType(C, ReplacementTy)); + return replaceAttributeTypeAtIndex(C, ArgNo, Kind, ReplacementTy); } /// \brief Add the dereferenceable attribute to the attribute set at the given @@ -701,41 +744,50 @@ class AttributeList { AttributeSet getFnAttrs() const; /// Return true if the attribute exists at the given index. - bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const; + bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const; + bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const { + return hasAttributeAtIndex(Index, Kind); + } /// Return true if the attribute exists at the given index. - bool hasAttribute(unsigned Index, StringRef Kind) const; + bool hasAttributeAtIndex(unsigned Index, StringRef Kind) const; + bool hasAttribute(unsigned Index, StringRef Kind) const { + return hasAttributeAtIndex(Index, Kind); + } /// Return true if attribute exists at the given index. - bool hasAttributes(unsigned Index) const; + bool hasAttributesAtIndex(unsigned Index) const; + bool hasAttributes(unsigned Index) const { + return hasAttributesAtIndex(Index); + } /// Return true if the attribute exists for the given argument bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const { - return hasAttribute(ArgNo + FirstArgIndex, Kind); + return hasAttributeAtIndex(ArgNo + FirstArgIndex, Kind); } /// Return true if the attribute exists for the given argument bool hasParamAttr(unsigned ArgNo, StringRef Kind) const { - return hasAttribute(ArgNo + FirstArgIndex, Kind); + return hasAttributeAtIndex(ArgNo + FirstArgIndex, Kind); } /// Return true if attributes exists for the given argument bool hasParamAttrs(unsigned ArgNo) const { - return hasAttributes(ArgNo + FirstArgIndex); + return hasAttributesAtIndex(ArgNo + FirstArgIndex); } /// Return true if the attribute exists for the return value. bool hasRetAttr(Attribute::AttrKind Kind) const { - return hasAttribute(ReturnIndex, Kind); + return hasAttributeAtIndex(ReturnIndex, Kind); } /// Return true if the attribute exists for the return value. bool hasRetAttr(StringRef Kind) const { - return hasAttribute(ReturnIndex, Kind); + return hasAttributeAtIndex(ReturnIndex, Kind); } /// Return true if attributes exist for the return value. - bool hasRetAttrs() const { return hasAttributes(ReturnIndex); } + bool hasRetAttrs() const { return hasAttributesAtIndex(ReturnIndex); } /// Return true if the attribute exists for the function. bool hasFnAttr(Attribute::AttrKind Kind) const; @@ -744,7 +796,7 @@ class AttributeList { bool hasFnAttr(StringRef Kind) const; /// Return true the attributes exist for the function. - bool hasFnAttrs() const { return hasAttributes(FunctionIndex); } + bool hasFnAttrs() const { return hasAttributesAtIndex(FunctionIndex); } /// Return true if the specified attribute is set for at least one /// parameter or for the return value. If Index is not nullptr, the index @@ -753,29 +805,35 @@ class AttributeList { unsigned *Index = nullptr) const; /// Return the attribute object that exists at the given index. - Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const; + Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const; + Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const { + return getAttributeAtIndex(Index, Kind); + } /// Return the attribute object that exists at the given index. - Attribute getAttribute(unsigned Index, StringRef Kind) const; + Attribute getAttributeAtIndex(unsigned Index, StringRef Kind) const; + Attribute getAttribute(unsigned Index, StringRef Kind) const { + return getAttributeAtIndex(Index, Kind); + } /// Return the attribute object that exists at the arg index. Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const { - return getAttribute(ArgNo + FirstArgIndex, Kind); + return getAttributeAtIndex(ArgNo + FirstArgIndex, Kind); } /// Return the attribute object that exists at the given index. Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const { - return getAttribute(ArgNo + FirstArgIndex, Kind); + return getAttributeAtIndex(ArgNo + FirstArgIndex, Kind); } /// Return the attribute object that exists for the function. Attribute getFnAttr(Attribute::AttrKind Kind) const { - return getAttribute(FunctionIndex, Kind); + return getAttributeAtIndex(FunctionIndex, Kind); } /// Return the attribute object that exists for the function. Attribute getFnAttr(StringRef Kind) const { - return getAttribute(FunctionIndex, Kind); + return getAttributeAtIndex(FunctionIndex, Kind); } /// Return the alignment of the return value. diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index b61ddd43a8fdd2..44d2c14d2879ee 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -328,8 +328,12 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject, /// Set the attribute list for this Function. void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; } + // TODO: remove non-AtIndex versions of these methods. /// adds the attribute to the list of attributes. - void addAttribute(unsigned i, Attribute Attr); + void addAttributeAtIndex(unsigned i, Attribute Attr); + void addAttribute(unsigned i, Attribute Attr) { + addAttributeAtIndex(i, Attr); + } /// Add function attributes to this function. void addFnAttr(Attribute::AttrKind Kind); @@ -356,10 +360,16 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject, void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs); /// removes the attribute from the list of attributes. - void removeAttribute(unsigned i, Attribute::AttrKind Kind); + void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind); + void removeAttribute(unsigned i, Attribute::AttrKind Kind) { + removeAttributeAtIndex(i, Kind); + } /// removes the attribute from the list of attributes. - void removeAttribute(unsigned i, StringRef Kind); + void removeAttributeAtIndex(unsigned i, StringRef Kind); + void removeAttribute(unsigned i, StringRef Kind) { + removeAttributeAtIndex(i, Kind); + } /// Remove function attributes from this function. void removeFnAttr(Attribute::AttrKind Kind); @@ -400,10 +410,16 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject, bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const; /// gets the attribute from the list of attributes. - Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const; + Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const; + Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { + return getAttributeAtIndex(i, Kind); + } /// gets the attribute from the list of attributes. - Attribute getAttribute(unsigned i, StringRef Kind) const; + Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const; + Attribute getAttribute(unsigned i, StringRef Kind) const { + return getAttributeAtIndex(i, Kind); + } /// Return the attribute for the given attribute kind. Attribute getFnAttribute(Attribute::AttrKind Kind) const; diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index 3f37ac3659d289..8b2f7686877844 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -1485,14 +1485,21 @@ class CallBase : public Instruction { /// the attribute is allowed for the call. bool hasFnAttr(StringRef Kind) const { return hasFnAttrImpl(Kind); } + // TODO: remove non-AtIndex versions of these methods. /// adds the attribute to the list of attributes. + void addAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) { + Attrs = Attrs.addAttributeAtIndex(getContext(), i, Kind); + } void addAttribute(unsigned i, Attribute::AttrKind Kind) { - Attrs = Attrs.addAttribute(getContext(), i, Kind); + addAttributeAtIndex(i, Kind); } /// adds the attribute to the list of attributes. + void addAttributeAtIndex(unsigned i, Attribute Attr) { + Attrs = Attrs.addAttributeAtIndex(getContext(), i, Attr); + } void addAttribute(unsigned i, Attribute Attr) { - Attrs = Attrs.addAttribute(getContext(), i, Attr); + addAttributeAtIndex(i, Attr); } /// Adds the attribute to the function. @@ -1528,13 +1535,19 @@ class CallBase : public Instruction { } /// removes the attribute from the list of attributes. + void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) { + Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind); + } void removeAttribute(unsigned i, Attribute::AttrKind Kind) { - Attrs = Attrs.removeAttribute(getContext(), i, Kind); + removeAttributeAtIndex(i, Kind); } /// removes the attribute from the list of attributes. + void removeAttributeAtIndex(unsigned i, StringRef Kind) { + Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind); + } void removeAttribute(unsigned i, StringRef Kind) { - Attrs = Attrs.removeAttribute(getContext(), i, Kind); + removeAttributeAtIndex(i, Kind); } /// Removes the attributes from the function @@ -1595,13 +1608,19 @@ class CallBase : public Instruction { bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const; /// Get the attribute of a given kind at a position. + Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const { + return getAttributes().getAttributeAtIndex(i, Kind); + } Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { - return getAttributes().getAttribute(i, Kind); + return getAttributeAtIndex(i, Kind); } /// Get the attribute of a given kind at a position. + Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const { + return getAttributes().getAttributeAtIndex(i, Kind); + } Attribute getAttribute(unsigned i, StringRef Kind) const { - return getAttributes().getAttribute(i, Kind); + return getAttributeAtIndex(i, Kind); } /// Get the attribute of a given kind for the function. diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index d0bf6c121d17ff..2abd1fefa20688 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1209,33 +1209,36 @@ AttributeList AttributeList::get(LLVMContext &C, return getImpl(C, NewAttrSets); } -AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, - Attribute::AttrKind Kind) const { - if (hasAttribute(Index, Kind)) return *this; +AttributeList +AttributeList::addAttributeAtIndex(LLVMContext &C, unsigned Index, + Attribute::AttrKind Kind) const { + if (hasAttributeAtIndex(Index, Kind)) + return *this; AttributeSet Attrs = getAttributes(Index); // TODO: Insert at correct position and avoid sort. SmallVector NewAttrs(Attrs.begin(), Attrs.end()); NewAttrs.push_back(Attribute::get(C, Kind)); - return setAttributes(C, Index, AttributeSet::get(C, NewAttrs)); + return setAttributesAtIndex(C, Index, AttributeSet::get(C, NewAttrs)); } -AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, - StringRef Kind, - StringRef Value) const { +AttributeList AttributeList::addAttributeAtIndex(LLVMContext &C, unsigned Index, + StringRef Kind, + StringRef Value) const { AttrBuilder B; B.addAttribute(Kind, Value); - return addAttributes(C, Index, B); + return addAttributesAtIndex(C, Index, B); } -AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, - Attribute A) const { +AttributeList AttributeList::addAttributeAtIndex(LLVMContext &C, unsigned Index, + Attribute A) const { AttrBuilder B; B.addAttribute(A); - return addAttributes(C, Index, B); + return addAttributesAtIndex(C, Index, B); } -AttributeList AttributeList::setAttributes(LLVMContext &C, unsigned Index, - AttributeSet Attrs) const { +AttributeList AttributeList::setAttributesAtIndex(LLVMContext &C, + unsigned Index, + AttributeSet Attrs) const { Index = attrIdxToArrayIdx(Index); SmallVector AttrSets(this->begin(), this->end()); if (Index >= AttrSets.size()) @@ -1244,8 +1247,9 @@ AttributeList AttributeList::setAttributes(LLVMContext &C, unsigned Index, return AttributeList::getImpl(C, AttrSets); } -AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index, - const AttrBuilder &B) const { +AttributeList AttributeList::addAttributesAtIndex(LLVMContext &C, + unsigned Index, + const AttrBuilder &B) const { if (!B.hasAttributes()) return *this; @@ -1263,7 +1267,7 @@ AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index, AttrBuilder Merged(getAttributes(Index)); Merged.merge(B); - return setAttributes(C, Index, AttributeSet::get(C, Merged)); + return setAttributesAtIndex(C, Index, AttributeSet::get(C, Merged)); } AttributeList AttributeList::addParamAttribute(LLVMContext &C, @@ -1286,9 +1290,11 @@ AttributeList AttributeList::addParamAttribute(LLVMContext &C, return getImpl(C, AttrSets); } -AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index, - Attribute::AttrKind Kind) const { - if (!hasAttribute(Index, Kind)) return *this; +AttributeList +AttributeList::removeAttributeAtIndex(LLVMContext &C, unsigned Index, + Attribute::AttrKind Kind) const { + if (!hasAttributeAtIndex(Index, Kind)) + return *this; Index = attrIdxToArrayIdx(Index); SmallVector AttrSets(this->begin(), this->end()); @@ -1299,9 +1305,11 @@ AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index, return getImpl(C, AttrSets); } -AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index, - StringRef Kind) const { - if (!hasAttribute(Index, Kind)) return *this; +AttributeList AttributeList::removeAttributeAtIndex(LLVMContext &C, + unsigned Index, + StringRef Kind) const { + if (!hasAttributeAtIndex(Index, Kind)) + return *this; Index = attrIdxToArrayIdx(Index); SmallVector AttrSets(this->begin(), this->end()); @@ -1313,18 +1321,19 @@ AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index, } AttributeList -AttributeList::removeAttributes(LLVMContext &C, unsigned Index, - const AttrBuilder &AttrsToRemove) const { +AttributeList::removeAttributesAtIndex(LLVMContext &C, unsigned Index, + const AttrBuilder &AttrsToRemove) const { AttributeSet Attrs = getAttributes(Index); AttributeSet NewAttrs = Attrs.removeAttributes(C, AttrsToRemove); // If nothing was removed, return the original list. if (Attrs == NewAttrs) return *this; - return setAttributes(C, Index, NewAttrs); + return setAttributesAtIndex(C, Index, NewAttrs); } -AttributeList AttributeList::removeAttributes(LLVMContext &C, - unsigned WithoutIndex) const { +AttributeList +AttributeList::removeAttributesAtIndex(LLVMContext &C, + unsigned WithoutIndex) const { if (!pImpl) return {}; WithoutIndex = attrIdxToArrayIdx(WithoutIndex); @@ -1383,16 +1392,16 @@ AttributeSet AttributeList::getFnAttrs() const { return getAttributes(FunctionIndex); } -bool AttributeList::hasAttribute(unsigned Index, - Attribute::AttrKind Kind) const { +bool AttributeList::hasAttributeAtIndex(unsigned Index, + Attribute::AttrKind Kind) const { return getAttributes(Index).hasAttribute(Kind); } -bool AttributeList::hasAttribute(unsigned Index, StringRef Kind) const { +bool AttributeList::hasAttributeAtIndex(unsigned Index, StringRef Kind) const { return getAttributes(Index).hasAttribute(Kind); } -bool AttributeList::hasAttributes(unsigned Index) const { +bool AttributeList::hasAttributesAtIndex(unsigned Index) const { return getAttributes(Index).hasAttributes(); } @@ -1401,7 +1410,7 @@ bool AttributeList::hasFnAttr(Attribute::AttrKind Kind) const { } bool AttributeList::hasFnAttr(StringRef Kind) const { - return hasAttribute(AttributeList::FunctionIndex, Kind); + return hasAttributeAtIndex(AttributeList::FunctionIndex, Kind); } bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr, @@ -1409,12 +1418,13 @@ bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr, return pImpl && pImpl->hasAttrSomewhere(Attr, Index); } -Attribute AttributeList::getAttribute(unsigned Index, - Attribute::AttrKind Kind) const { +Attribute AttributeList::getAttributeAtIndex(unsigned Index, + Attribute::AttrKind Kind) const { return getAttributes(Index).getAttribute(Kind); } -Attribute AttributeList::getAttribute(unsigned Index, StringRef Kind) const { +Attribute AttributeList::getAttributeAtIndex(unsigned Index, + StringRef Kind) const { return getAttributes(Index).getAttribute(Kind); } diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 9313c4980dfbbb..951d45cb6069af 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -529,8 +529,8 @@ void Function::dropAllReferences() { clearMetadata(); } -void Function::addAttribute(unsigned i, Attribute Attr) { - AttributeSets = AttributeSets.addAttribute(getContext(), i, Attr); +void Function::addAttributeAtIndex(unsigned i, Attribute Attr) { + AttributeSets = AttributeSets.addAttributeAtIndex(getContext(), i, Attr); } void Function::addFnAttr(Attribute::AttrKind Kind) { @@ -565,12 +565,12 @@ void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) { AttributeSets = AttributeSets.addParamAttributes(getContext(), ArgNo, Attrs); } -void Function::removeAttribute(unsigned i, Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.removeAttribute(getContext(), i, Kind); +void Function::removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) { + AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); } -void Function::removeAttribute(unsigned i, StringRef Kind) { - AttributeSets = AttributeSets.removeAttribute(getContext(), i, Kind); +void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) { + AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); } void Function::removeFnAttr(Attribute::AttrKind Kind) { @@ -632,12 +632,13 @@ bool Function::hasParamAttribute(unsigned ArgNo, return AttributeSets.hasParamAttr(ArgNo, Kind); } -Attribute Function::getAttribute(unsigned i, Attribute::AttrKind Kind) const { - return AttributeSets.getAttribute(i, Kind); +Attribute Function::getAttributeAtIndex(unsigned i, + Attribute::AttrKind Kind) const { + return AttributeSets.getAttributeAtIndex(i, Kind); } -Attribute Function::getAttribute(unsigned i, StringRef Kind) const { - return AttributeSets.getAttribute(i, Kind); +Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const { + return AttributeSets.getAttributeAtIndex(i, Kind); } Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const {