From 6e30cb7673df293fd294acef7eadca8050b5a71e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 18 Dec 2021 14:56:12 +0100 Subject: [PATCH] [Attributes] Add AttributeList ctor from AttributeSet (NFC) It was already possible to create an AttributeList from an Index and an AttributeSet. However, this would actually end up using the implicit constructor on AttrBuilder, thus doing an unnecessary conversion from AttributeSet to AttrBuilder to AttributeSet. Instead we can accept the AttributeSet directly, as that is what we need anyway. --- llvm/include/llvm/IR/Attributes.h | 2 ++ llvm/lib/IR/Attributes.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index 002277e..8eef8b4 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -456,6 +456,8 @@ public: static AttributeList get(LLVMContext &C, unsigned Index, ArrayRef Kind); static AttributeList get(LLVMContext &C, unsigned Index, + AttributeSet Attrs); + static AttributeList get(LLVMContext &C, unsigned Index, const AttrBuilder &B); // TODO: remove non-AtIndex versions of these methods. diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index ede520b..c899afa 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1136,16 +1136,21 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs, } AttributeList AttributeList::get(LLVMContext &C, unsigned Index, - const AttrBuilder &B) { - if (!B.hasAttributes()) + AttributeSet Attrs) { + if (!Attrs.hasAttributes()) return {}; Index = attrIdxToArrayIdx(Index); SmallVector AttrSets(Index + 1); - AttrSets[Index] = AttributeSet::get(C, B); + AttrSets[Index] = Attrs; return getImpl(C, AttrSets); } AttributeList AttributeList::get(LLVMContext &C, unsigned Index, + const AttrBuilder &B) { + return get(C, Index, AttributeSet::get(C, B)); +} + +AttributeList AttributeList::get(LLVMContext &C, unsigned Index, ArrayRef Kinds) { SmallVector, 8> Attrs; for (const auto K : Kinds) -- 2.7.4