diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -432,8 +432,8 @@ 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; @@ -456,79 +456,81 @@ /// Add an attribute to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. - LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, - Attribute::AttrKind Kind) const; + LLVM_NODISCARD AttributeList addAttributeAtIndex( + LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const; /// Add an attribute to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList - addAttribute(LLVMContext &C, unsigned Index, StringRef Kind, - StringRef Value = StringRef()) const; + addAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind, + StringRef Value = StringRef()) const; /// Add an attribute to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. - LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, - Attribute A) const; + LLVM_NODISCARD AttributeList addAttributeAtIndex(LLVMContext &C, + unsigned Index, + Attribute A) const; /// Add attributes to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. - LLVM_NODISCARD AttributeList addAttributes(LLVMContext &C, unsigned Index, - const AttrBuilder &B) const; + LLVM_NODISCARD AttributeList addAttributesAtIndex(LLVMContext &C, + unsigned Index, + const AttrBuilder &B) const; /// 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 +538,7 @@ 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 +552,83 @@ 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 removeAttribute(LLVMContext &C, unsigned Index, - Attribute::AttrKind Kind) const; + LLVM_NODISCARD AttributeList removeAttributeAtIndex( + LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const; /// Remove the specified attribute at the specified index from this /// attribute list. Returns a new list because attribute lists are immutable. - LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, - StringRef Kind) const; + LLVM_NODISCARD AttributeList removeAttributeAtIndex(LLVMContext &C, + unsigned Index, + StringRef Kind) const; /// 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; /// Remove all attributes at the specified index from this /// attribute list. Returns a new list because attribute lists are immutable. - LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C, - unsigned Index) const; + LLVM_NODISCARD AttributeList removeAttributesAtIndex(LLVMContext &C, + unsigned Index) const; /// 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 +636,32 @@ 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 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)); + 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)); } /// \brief Add the dereferenceable attribute to the attribute set at the given @@ -701,41 +704,41 @@ 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; /// Return true if the attribute exists at the given index. - bool hasAttribute(unsigned Index, StringRef Kind) const; + bool hasAttributeAtIndex(unsigned Index, StringRef Kind) const; /// Return true if attribute exists at the given index. - bool hasAttributes(unsigned Index) const; + bool hasAttributesAtIndex(unsigned Index) const; /// 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 +747,7 @@ 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 +756,29 @@ 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; /// Return the attribute object that exists at the given index. - Attribute getAttribute(unsigned Index, StringRef Kind) const; + Attribute getAttributeAtIndex(unsigned Index, StringRef Kind) const; /// 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 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -328,7 +328,7 @@ void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; } /// adds the attribute to the list of attributes. - void addAttribute(unsigned i, Attribute Attr); + void addAttributeAtIndex(unsigned i, Attribute Attr); /// Add function attributes to this function. void addFnAttr(Attribute::AttrKind Kind); @@ -355,10 +355,10 @@ 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); /// removes the attribute from the list of attributes. - void removeAttribute(unsigned i, StringRef Kind); + void removeAttributeAtIndex(unsigned i, StringRef Kind); /// Remove function attributes from this function. void removeFnAttr(Attribute::AttrKind Kind); @@ -399,10 +399,10 @@ 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; /// gets the attribute from the list of attributes. - Attribute getAttribute(unsigned i, StringRef Kind) const; + Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const; /// 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 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -1486,13 +1486,13 @@ bool hasFnAttr(StringRef Kind) const { return hasFnAttrImpl(Kind); } /// adds the attribute to the list of attributes. - void addAttribute(unsigned i, Attribute::AttrKind Kind) { - Attrs = Attrs.addAttribute(getContext(), i, Kind); + void addAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) { + Attrs = Attrs.addAttributeAtIndex(getContext(), i, Kind); } /// adds the attribute to the list of attributes. - void addAttribute(unsigned i, Attribute Attr) { - Attrs = Attrs.addAttribute(getContext(), i, Attr); + void addAttributeAtIndex(unsigned i, Attribute Attr) { + Attrs = Attrs.addAttributeAtIndex(getContext(), i, Attr); } /// Adds the attribute to the function. @@ -1528,13 +1528,13 @@ } /// removes the attribute from the list of attributes. - void removeAttribute(unsigned i, Attribute::AttrKind Kind) { - Attrs = Attrs.removeAttribute(getContext(), i, Kind); + void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) { + Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind); } /// removes the attribute from the list of attributes. - void removeAttribute(unsigned i, StringRef Kind) { - Attrs = Attrs.removeAttribute(getContext(), i, Kind); + void removeAttributeAtIndex(unsigned i, StringRef Kind) { + Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind); } /// Removes the attributes from the function @@ -1595,13 +1595,13 @@ bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const; /// Get the attribute of a given kind at a position. - Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { - return getAttributes().getAttribute(i, Kind); + Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const { + return getAttributes().getAttributeAtIndex(i, Kind); } /// Get the attribute of a given kind at a position. - Attribute getAttribute(unsigned i, StringRef Kind) const { - return getAttributes().getAttribute(i, Kind); + Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const { + return getAttributes().getAttributeAtIndex(i, Kind); } /// Get the attribute of a given kind for the function. diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -591,7 +591,7 @@ LLVMContext &Ctx = getAnchorValue().getContext(); for (Attribute::AttrKind AK : AKs) - AttrList = AttrList.removeAttribute(Ctx, getAttrIdx(), AK); + AttrList = AttrList.removeAttributeAtIndex(Ctx, getAttrIdx(), AK); if (CB) CB->setAttributes(AttrList); diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp --- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp @@ -73,7 +73,7 @@ const AttributeList &Attrs, unsigned OpIdx) const { addFlagsUsingAttrFn(Flags, [&Attrs, &OpIdx](Attribute::AttrKind Attr) { - return Attrs.hasAttribute(OpIdx, Attr); + return Attrs.hasAttributeAtIndex(OpIdx, Attr); }); } @@ -167,7 +167,8 @@ assert(OpIdx >= AttributeList::FirstArgIndex); Type *ElementTy = PtrTy->getElementType(); - auto Ty = Attrs.getAttribute(OpIdx, Attribute::ByVal).getValueAsType(); + auto Ty = + Attrs.getAttributeAtIndex(OpIdx, Attribute::ByVal).getValueAsType(); Flags.setByValSize(DL.getTypeAllocSize(Ty ? Ty : ElementTy)); // For ByVal, alignment should be passed from FE. BE will guess if diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1209,33 +1209,36 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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::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 @@ 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(StringRef Kind) const { - return hasAttribute(AttributeList::FunctionIndex, Kind); + return hasAttributeAtIndex(AttributeList::FunctionIndex, Kind); } bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr, @@ -1409,12 +1418,13 @@ 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/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2460,7 +2460,7 @@ void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef A) { - unwrap(F)->addAttribute(Idx, unwrap(A)); + unwrap(F)->addAttributeAtIndex(Idx, unwrap(A)); } unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) { @@ -2478,24 +2478,25 @@ LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID) { - return wrap(unwrap(F)->getAttribute(Idx, - (Attribute::AttrKind)KindID)); + return wrap(unwrap(F)->getAttributeAtIndex( + Idx, (Attribute::AttrKind)KindID)); } LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap(unwrap(F)->getAttribute(Idx, StringRef(K, KLen))); + return wrap( + unwrap(F)->getAttributeAtIndex(Idx, StringRef(K, KLen))); } void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID) { - unwrap(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID); + unwrap(F)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID); } void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - unwrap(F)->removeAttribute(Idx, StringRef(K, KLen)); + unwrap(F)->removeAttributeAtIndex(Idx, StringRef(K, KLen)); } void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, @@ -2862,12 +2863,12 @@ auto *Call = unwrap(Instr); Attribute AlignAttr = Attribute::getWithAlignment(Call->getContext(), Align(align)); - Call->addAttribute(index, AlignAttr); + Call->addAttributeAtIndex(index, AlignAttr); } void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef A) { - unwrap(C)->addAttribute(Idx, unwrap(A)); + unwrap(C)->addAttributeAtIndex(Idx, unwrap(A)); } unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, @@ -2888,24 +2889,25 @@ LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { - return wrap( - unwrap(C)->getAttribute(Idx, (Attribute::AttrKind)KindID)); + return wrap(unwrap(C)->getAttributeAtIndex( + Idx, (Attribute::AttrKind)KindID)); } LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap(unwrap(C)->getAttribute(Idx, StringRef(K, KLen))); + return wrap( + unwrap(C)->getAttributeAtIndex(Idx, StringRef(K, KLen))); } void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { - unwrap(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID); + unwrap(C)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID); } void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - unwrap(C)->removeAttribute(Idx, StringRef(K, KLen)); + unwrap(C)->removeAttributeAtIndex(Idx, StringRef(K, KLen)); } LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) { diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -529,8 +529,8 @@ 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 @@ 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 @@ 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 { diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -651,9 +651,11 @@ for (Attribute::AttrKind TypedAttr : {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef, Attribute::InAlloca}) { - if (Attrs.hasAttribute(i, TypedAttr)) { - if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) { - Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, TypeMap.get(Ty)); + if (Attrs.hasAttributeAtIndex(i, TypedAttr)) { + if (Type *Ty = + Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) { + Attrs = Attrs.replaceAttributeTypeAtIndex(C, i, TypedAttr, + TypeMap.get(Ty)); break; } } diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -382,30 +382,30 @@ if (Attr.isEnumAttribute()) { Attribute::AttrKind Kind = Attr.getKindAsEnum(); - if (Attrs.hasAttribute(AttrIdx, Kind)) + if (Attrs.hasAttributeAtIndex(AttrIdx, Kind)) if (!ForceReplace && - isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) + isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind))) return false; - Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); + Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr); return true; } if (Attr.isStringAttribute()) { StringRef Kind = Attr.getKindAsString(); - if (Attrs.hasAttribute(AttrIdx, Kind)) + if (Attrs.hasAttributeAtIndex(AttrIdx, Kind)) if (!ForceReplace && - isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) + isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind))) return false; - Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); + Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr); return true; } if (Attr.isIntAttribute()) { Attribute::AttrKind Kind = Attr.getKindAsEnum(); - if (Attrs.hasAttribute(AttrIdx, Kind)) + if (Attrs.hasAttributeAtIndex(AttrIdx, Kind)) if (!ForceReplace && - isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) + isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind))) return false; - Attrs = Attrs.removeAttribute(Ctx, AttrIdx, Kind); - Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); + Attrs = Attrs.removeAttributeAtIndex(Ctx, AttrIdx, Kind); + Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr); return true; } @@ -658,9 +658,9 @@ else AttrList = getAssociatedFunction()->getAttributes(); - bool HasAttr = AttrList.hasAttribute(getAttrIdx(), AK); + bool HasAttr = AttrList.hasAttributeAtIndex(getAttrIdx(), AK); if (HasAttr) - Attrs.push_back(AttrList.getAttribute(getAttrIdx(), AK)); + Attrs.push_back(AttrList.getAttributeAtIndex(getAttrIdx(), AK)); return HasAttr; } diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1702,7 +1702,7 @@ Attribute::AttrKind A) { unsigned AttrIndex; if (Attrs.hasAttrSomewhere(A, &AttrIndex)) - return Attrs.removeAttribute(C, AttrIndex, A); + return Attrs.removeAttributeAtIndex(C, AttrIndex, A); return Attrs; } diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -2667,7 +2667,7 @@ R.addAttribute(Attr); if (!R.empty()) - AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R)); + AH.setAttributes(AH.getAttributes().removeAttributesAtIndex(Ctx, Index, R)); } static void stripNonValidAttributesFromPrototype(Function &F) { diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -947,9 +947,10 @@ for (Attribute::AttrKind TypedAttr : {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef, Attribute::InAlloca}) { - if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) { - Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, - TypeMapper->remapType(Ty)); + if (Type *Ty = + Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) { + Attrs = Attrs.replaceAttributeTypeAtIndex(C, i, TypedAttr, + TypeMapper->remapType(Ty)); break; } }