[NFC] Remove some unclear attribute methods
authorArthur Eubanks <aeubanks@google.com>
Wed, 1 Sep 2021 18:32:23 +0000 (11:32 -0700)
committerArthur Eubanks <aeubanks@google.com>
Thu, 2 Sep 2021 19:47:22 +0000 (12:47 -0700)
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

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

index a14a247..24588fa 100644 (file)
@@ -459,41 +459,24 @@ public:
   /// 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 @@ public:
   /// 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 @@ public:
   /// 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 @@ public:
     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 @@ public:
 
   /// 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 @@ public:
 
   /// 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 {
index 44d2c14..71876f6 100644 (file)
@@ -331,9 +331,6 @@ public:
   // 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 @@ public:
 
   /// 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 @@ public:
 
   /// 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;
index 8b2f768..bb9084c 100644 (file)
@@ -1490,17 +1490,11 @@ public:
   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 @@ public:
   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 @@ public:
   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 {