[llvm-branch-commits] [llvm] IR: Make AttributeList::hasAttributeAtIndex and hasAttrSomewhere inline (PR #241673)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 11 21:05:51 PST 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/241673
Store the attributes available at any index in AttributeListImplBase.
CTMark instructions:u: O3 -0.22%, ThinLTO -0.29%.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
>From 3853d0da58743f6024e4d30b30397dfe9369ae8a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 11 Nov 2026 19:18:55 -0800
Subject: [PATCH] IR: Make AttributeList::hasAttributeAtIndex and
hasAttrSomewhere inline
Store the attributes available at any index in AttributeListImplBase.
CTMark instructions:u: O3 -0.22%, ThinLTO -0.29%.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
llvm/include/llvm/IR/Attributes.h | 31 ++++++++++++++++++++-----
llvm/lib/IR/AttributeImpl.h | 10 --------
llvm/lib/IR/Attributes.cpp | 38 ++++++-------------------------
3 files changed, 32 insertions(+), 47 deletions(-)
diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index b3f056b398fd9..4ecc7e1b28ec4 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -435,8 +435,14 @@ class AttributeListImplBase {
const AttributeSet *AttrSets = nullptr;
unsigned NumAttrSets = 0; ///< Number of entries in this set.
AttributeBitSet AvailableFunctionAttrs;
+ /// Union of enum attributes available at any index.
+ AttributeBitSet AvailableSomewhereAttrs;
public:
+ /// Return true if any index has an enum attribute of the given kind.
+ bool hasAttrSomewhere(Attribute::AttrKind Kind) const {
+ return AvailableSomewhereAttrs.hasAttribute(Kind);
+ }
const AttributeSet *getAttrSets() const { return AttrSets; }
unsigned getNumAttrSets() const { return NumAttrSets; }
@@ -638,6 +644,10 @@ class AttributeList {
/// Map an attribute index to the index of its set in the list.
static unsigned attrIdxToArrayIdx(unsigned Index) { return Index + 1; }
+ /// Return the first index with an enum attribute of kind \p Kind, which
+ /// must exist.
+ LLVM_ABI unsigned getAttrSomewhereIndex(Attribute::AttrKind Kind) const;
+
public:
/// Create an AttributeList with the specified parameters in it.
LLVM_ABI static AttributeList
@@ -982,8 +992,9 @@ class AttributeList {
AttributeSet getFnAttrs() const { return getAttributes(FunctionIndex); }
/// Return true if the attribute exists at the given index.
- LLVM_ABI bool hasAttributeAtIndex(unsigned Index,
- Attribute::AttrKind Kind) const;
+ bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const {
+ return getAttributes(Index).hasAttribute(Kind);
+ }
/// Return true if the attribute exists at the given index.
LLVM_ABI bool hasAttributeAtIndex(unsigned Index, StringRef Kind) const;
@@ -1033,12 +1044,20 @@ class AttributeList {
/// 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
/// of a parameter with the specified attribute is provided.
- LLVM_ABI bool hasAttrSomewhere(Attribute::AttrKind Kind,
- unsigned *Index = nullptr) const;
+ bool hasAttrSomewhere(Attribute::AttrKind Kind,
+ unsigned *Index = nullptr) const {
+ if (!pImpl || !pImpl->hasAttrSomewhere(Kind))
+ return false;
+ if (Index)
+ *Index = getAttrSomewhereIndex(Kind);
+ return true;
+ }
/// Return the attribute object that exists at the given index.
- LLVM_ABI Attribute getAttributeAtIndex(unsigned Index,
- Attribute::AttrKind Kind) const;
+ Attribute getAttributeAtIndex(unsigned Index,
+ Attribute::AttrKind Kind) const {
+ return getAttributes(Index).getAttribute(Kind);
+ }
/// Return the attribute object that exists at the given index.
LLVM_ABI Attribute getAttributeAtIndex(unsigned Index, StringRef Kind) const;
diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h
index e683f7977164e..e4c759b07729d 100644
--- a/llvm/lib/IR/AttributeImpl.h
+++ b/llvm/lib/IR/AttributeImpl.h
@@ -327,10 +327,6 @@ class AttributeListImpl final
friend class AttributeList;
friend TrailingObjects;
-private:
- /// Union of enum attributes available at any index.
- AttributeBitSet AvailableSomewhereAttrs;
-
public:
AttributeListImpl(ArrayRef<AttributeSet> Sets);
@@ -338,12 +334,6 @@ class AttributeListImpl final
AttributeListImpl(const AttributeListImpl &) = delete;
AttributeListImpl &operator=(const AttributeListImpl &) = delete;
- /// 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
- /// of a parameter with the specified attribute is provided.
- bool hasAttrSomewhere(Attribute::AttrKind Kind,
- unsigned *Index = nullptr) const;
-
using iterator = const AttributeSet *;
iterator begin() const { return getTrailingObjects(); }
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 41dfaa6ea0d8d..b70f0e8ef03bf 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1538,23 +1538,6 @@ AttributeListImpl::AttributeListImpl(ArrayRef<AttributeSet> Sets) {
AvailableSomewhereAttrs.addAttribute(I.getKindAsEnum());
}
-bool AttributeListImpl::hasAttrSomewhere(Attribute::AttrKind Kind,
- unsigned *Index) const {
- if (!AvailableSomewhereAttrs.hasAttribute(Kind))
- return false;
-
- if (Index) {
- for (unsigned I = 0, E = NumAttrSets; I != E; ++I) {
- if (begin()[I].hasAttribute(Kind)) {
- *Index = I - 1;
- break;
- }
- }
- }
-
- return true;
-}
-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void AttributeListImpl::dump() const {
@@ -1958,11 +1941,6 @@ AttributeList::intersectWith(LLVMContext &C, AttributeList Other) const {
// AttributeList Accessor Methods
//===----------------------------------------------------------------------===//
-bool AttributeList::hasAttributeAtIndex(unsigned Index,
- Attribute::AttrKind Kind) const {
- return getAttributes(Index).hasAttribute(Kind);
-}
-
bool AttributeList::hasAttributeAtIndex(unsigned Index, StringRef Kind) const {
return getAttributes(Index).hasAttribute(Kind);
}
@@ -1976,19 +1954,17 @@ bool AttributeList::hasFnAttr(StringRef Kind) const {
return hasAttributeAtIndex(AttributeList::FunctionIndex, Kind);
}
-bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr,
- unsigned *Index) const {
- return pImpl && getListImpl()->hasAttrSomewhere(Attr, Index);
-}
-
Attribute AttributeList::getAttributeAtIndex(unsigned Index,
- Attribute::AttrKind Kind) const {
+ StringRef Kind) const {
return getAttributes(Index).getAttribute(Kind);
}
-Attribute AttributeList::getAttributeAtIndex(unsigned Index,
- StringRef Kind) const {
- return getAttributes(Index).getAttribute(Kind);
+unsigned AttributeList::getAttrSomewhereIndex(Attribute::AttrKind Kind) const {
+ for (unsigned I = 0, E = pImpl->getNumAttrSets(); I != E; ++I) {
+ if (pImpl->getAttrSets()[I].hasAttribute(Kind))
+ return I - 1;
+ }
+ llvm_unreachable("Expected an index with the attribute");
}
MaybeAlign AttributeList::getRetAlignment() const {
More information about the llvm-branch-commits
mailing list