diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-05-22 15:03:29 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-05-22 19:03:27 +0200 |
commit | 05738ffcb87b76c6f166f965ba9b2db3257a4338 (patch) | |
tree | 5f219cb90468cb876ca7a0242c67e6e8c6522494 /llvm/lib/IR/Attributes.cpp | |
parent | fd46ed3f397d6cf41bc6c5a04ab2089f585afe44 (diff) | |
download | llvm-05738ffcb87b76c6f166f965ba9b2db3257a4338.zip llvm-05738ffcb87b76c6f166f965ba9b2db3257a4338.tar.gz llvm-05738ffcb87b76c6f166f965ba9b2db3257a4338.tar.bz2 |
[IR] Optimize no-op removal from AttributeList (NFC)
When removing an AttrBuilder from an index of an AttributeList,
directly return the original list if no attributes were actually
removed.
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 450543d..f63a65a 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1484,17 +1484,12 @@ AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index, AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const { - if (!pImpl) - return {}; - - Index = attrIdxToArrayIdx(Index); - SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end()); - if (Index >= AttrSets.size()) - AttrSets.resize(Index + 1); - - AttrSets[Index] = AttrSets[Index].removeAttributes(C, AttrsToRemove); - - return getImpl(C, AttrSets); + AttributeSet Attrs = getAttributes(Index); + AttributeSet NewAttrs = Attrs.removeAttributes(C, AttrsToRemove); + // If nothing was removed, return the original list. + if (Attrs == NewAttrs) + return *this; + return setAttributes(C, Index, NewAttrs); } AttributeList AttributeList::removeAttributes(LLVMContext &C, |