[llvm] b24909c - [Attributes] Avoid repeated attribute set lookup (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 03:07:50 PST 2023


Author: Nikita Popov
Date: 2023-01-09T11:58:06+01:00
New Revision: b24909c4c7e7c6ea47def893b061c9bc65caba15

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

LOG: [Attributes] Avoid repeated attribute set lookup (NFC)

Perform the hasAttribute() check on the AttributeSet we need to
fetch anyway, rather than going through hasAttributeAtIndex().

Added: 
    

Modified: 
    llvm/lib/IR/Attributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 2c27c1aba548..8bcb0808ef7c 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1301,9 +1301,9 @@ AttributeList AttributeList::get(LLVMContext &C,
 AttributeList
 AttributeList::addAttributeAtIndex(LLVMContext &C, unsigned Index,
                                    Attribute::AttrKind Kind) const {
-  if (hasAttributeAtIndex(Index, Kind))
-    return *this;
   AttributeSet Attrs = getAttributes(Index);
+  if (Attrs.hasAttribute(Kind))
+    return *this;
   // TODO: Insert at correct position and avoid sort.
   SmallVector<Attribute, 8> NewAttrs(Attrs.begin(), Attrs.end());
   NewAttrs.push_back(Attribute::get(C, Kind));
@@ -1379,19 +1379,19 @@ AttributeList AttributeList::addParamAttribute(LLVMContext &C,
 AttributeList
 AttributeList::removeAttributeAtIndex(LLVMContext &C, unsigned Index,
                                       Attribute::AttrKind Kind) const {
-  if (!hasAttributeAtIndex(Index, Kind))
+  AttributeSet Attrs = getAttributes(Index);
+  if (!Attrs.hasAttribute(Kind))
     return *this;
-  return setAttributesAtIndex(C, Index,
-                              getAttributes(Index).removeAttribute(C, Kind));
+  return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
 }
 
 AttributeList AttributeList::removeAttributeAtIndex(LLVMContext &C,
                                                     unsigned Index,
                                                     StringRef Kind) const {
-  if (!hasAttributeAtIndex(Index, Kind))
+  AttributeSet Attrs = getAttributes(Index);
+  if (!Attrs.hasAttribute(Kind))
     return *this;
-  return setAttributesAtIndex(C, Index,
-                              getAttributes(Index).removeAttribute(C, Kind));
+  return setAttributesAtIndex(C, Index, Attrs.removeAttribute(C, Kind));
 }
 
 AttributeList AttributeList::removeAttributesAtIndex(


        


More information about the llvm-commits mailing list