diff options
author | Nikita Popov <npopov@redhat.com> | 2023-01-09 11:58:06 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-01-09 11:58:06 +0100 |
commit | b24909c4c7e7c6ea47def893b061c9bc65caba15 (patch) | |
tree | 65c79a8ee55bcccde4376e05228557ac363a0ffa /llvm/lib/IR/Attributes.cpp | |
parent | e6375ca6dc5ba263ad3d9b6d779c5cf5b0f2e9ba (diff) | |
download | llvm-b24909c4c7e7c6ea47def893b061c9bc65caba15.zip llvm-b24909c4c7e7c6ea47def893b061c9bc65caba15.tar.gz llvm-b24909c4c7e7c6ea47def893b061c9bc65caba15.tar.bz2 |
[Attributes] Avoid repeated attribute set lookup (NFC)
Perform the hasAttribute() check on the AttributeSet we need to
fetch anyway, rather than going through hasAttributeAtIndex().
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 2c27c1a..8bcb080 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( |