From c9693492600e3899015a1b9134aa879e9e72bb81 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Fri, 20 Aug 2021 10:49:36 -0700 Subject: [PATCH] [NFC] Rename attribute methods that work with indexes This is part one of a couple of patches to fully rename these methods. I've made the mistake of assuming that these indexes are for parameters multiple times, but actually they're based off of a weird indexing scheme AttributeList::AttrIndex where 0 is the return value and ~0 is the function. Hopefully renaming these methods will make this clearer. Ideally users should use more specific methods like AttributeList::getFnAttr(). This patch simply adds the name that we want in the end. This is so the removal of the methods with the original names happens in a separate change to make it easier for downstream users. This touches all relevant methods in AttributeList, CallBase, and Function. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D108788 --- llvm/include/llvm/IR/Attributes.h | 158 ++++++++++++++++++++++++++------------ llvm/include/llvm/IR/Function.h | 26 +++++-- llvm/include/llvm/IR/InstrTypes.h | 31 ++++++-- llvm/lib/IR/Attributes.cpp | 80 ++++++++++--------- llvm/lib/IR/Function.cpp | 21 ++--- 5 files changed, 210 insertions(+), 106 deletions(-) diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index 0c77110..d81f67d 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -432,8 +432,8 @@ private: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 b61ddd4..44d2c14 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -328,8 +328,12 @@ public: /// 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 @@ public: 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 @@ public: 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 3f37ac3..8b2f768 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -1485,14 +1485,21 @@ public: /// 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 @@ public: } /// 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 @@ public: 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 d0bf6c1..2abd1fe 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 9313c49..951d45c 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 { -- 2.7.4