[llvm] 85b732b - [NFC] Remove some unclear attribute methods

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 12:48:10 PDT 2021


Author: Arthur Eubanks
Date: 2021-09-02T12:47:22-07:00
New Revision: 85b732b55903be80a2fc0b9eb6abb7de4a931430

URL: https://github.com/llvm/llvm-project/commit/85b732b55903be80a2fc0b9eb6abb7de4a931430
DIFF: https://github.com/llvm/llvm-project/commit/85b732b55903be80a2fc0b9eb6abb7de4a931430.diff

LOG: [NFC] Remove some unclear attribute methods

To any downstream users broken by this change, please examine your uses
of these methods and see if you can use a better method. For example,
getAttribute(AttributeList::FunctionIndex) => getFnAttr(), or
addAttribute(AttributeList::FirstArgIndex + ArgNo) =>
addParamAttribute(ArgNo). 0 corresponds to ReturnIndex, ~0 corresponds
to FunctionIndex. This may make future cleanups less painful.

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 touches all relevant methods in AttributeList, CallBase, and Function.

This hopefully will make easier a future change to cleanup AttrIndex. A
previous worry about cleaning up AttrIndex was that too many downstream
users would have to look through all uses of AttrIndex and relevant
attribute method calls to see if anything was unintentionally hardcoded
(e.g. using 0 instead of ReturnIndex). With this change hopefully
downstream users will look at existing usages of these methods and clean
them up.

Reviewed By: rnk, MaskRay

Differential Revision: https://reviews.llvm.org/D108614

Added: 
    

Modified: 
    llvm/include/llvm/IR/Attributes.h
    llvm/include/llvm/IR/Function.h
    llvm/include/llvm/IR/InstrTypes.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index a14a24795a4a2..24588faf6ffa5 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -459,41 +459,24 @@ class AttributeList {
   /// 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 {
-    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 {
-    return addAttributeAtIndex(C, Index, Kind, Value);
-  }
 
   /// 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 {
-    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 {
-    return addAttributesAtIndex(C, Index, B);
-  }
 
   /// Add a function attribute to the list. Returns a new list because
   /// attribute lists are immutable.
@@ -577,10 +560,6 @@ class AttributeList {
   /// 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 {
-    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.
@@ -596,19 +575,11 @@ class AttributeList {
   /// attribute list. Returns a new list because attribute lists are immutable.
   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 {
-    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.
@@ -697,12 +668,6 @@ class AttributeList {
     return Attrs.addAttributeAtIndex(C, ArgNo,
                                      Attr.getWithNewType(C, ReplacementTy));
   }
-  LLVM_NODISCARD AttributeList replaceAttributeType(LLVMContext &C,
-                                                    unsigned ArgNo,
-                                                    Attribute::AttrKind Kind,
-                                                    Type *ReplacementTy) const {
-    return replaceAttributeTypeAtIndex(C, ArgNo, Kind, ReplacementTy);
-  }
 
   /// \brief Add the dereferenceable attribute to the attribute set at the given
   /// index. Returns a new list because attribute lists are immutable.
@@ -745,21 +710,12 @@ class AttributeList {
 
   /// Return true if the attribute exists at the given index.
   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 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 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 {
@@ -806,15 +762,9 @@ class AttributeList {
 
   /// Return the attribute object that exists at the given index.
   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 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 {

diff  --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index 44d2c14d2879e..71876f6c0f1af 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -331,9 +331,6 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
   // TODO: remove non-AtIndex versions of these methods.
   /// adds the attribute to the list of attributes.
   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);
@@ -361,15 +358,9 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
 
   /// removes the attribute from the list of attributes.
   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 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);
@@ -411,15 +402,9 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
 
   /// gets the attribute from the list of attributes.
   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 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 8b2f768687784..bb9084cadd3f7 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1490,17 +1490,11 @@ class CallBase : public Instruction {
   void addAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {
     Attrs = Attrs.addAttributeAtIndex(getContext(), i, Kind);
   }
-  void addAttribute(unsigned i, Attribute::AttrKind 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) {
-    addAttributeAtIndex(i, Attr);
-  }
 
   /// Adds the attribute to the function.
   void addFnAttr(Attribute::AttrKind Kind) {
@@ -1538,17 +1532,11 @@ class CallBase : public Instruction {
   void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {
     Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind);
   }
-  void removeAttribute(unsigned i, Attribute::AttrKind 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) {
-    removeAttributeAtIndex(i, Kind);
-  }
 
   /// Removes the attributes from the function
   void removeFnAttrs(const AttrBuilder &AttrsToRemove) {
@@ -1611,17 +1599,11 @@ class CallBase : public Instruction {
   Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const {
     return getAttributes().getAttributeAtIndex(i, Kind);
   }
-  Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
-    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 getAttributeAtIndex(i, Kind);
-  }
 
   /// Get the attribute of a given kind for the function.
   Attribute getFnAttr(StringRef Kind) const {


        


More information about the llvm-commits mailing list