Skip to content

Commit 6e30cb7

Browse files
committed
[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.
1 parent 6c2bf01 commit 6e30cb7

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/include/llvm/IR/Attributes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ class AttributeList {
455455
ArrayRef<uint64_t> Values);
456456
static AttributeList get(LLVMContext &C, unsigned Index,
457457
ArrayRef<StringRef> Kind);
458+
static AttributeList get(LLVMContext &C, unsigned Index,
459+
AttributeSet Attrs);
458460
static AttributeList get(LLVMContext &C, unsigned Index,
459461
const AttrBuilder &B);
460462

llvm/lib/IR/Attributes.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,15 +1136,20 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs,
11361136
}
11371137

11381138
AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
1139-
const AttrBuilder &B) {
1140-
if (!B.hasAttributes())
1139+
AttributeSet Attrs) {
1140+
if (!Attrs.hasAttributes())
11411141
return {};
11421142
Index = attrIdxToArrayIdx(Index);
11431143
SmallVector<AttributeSet, 8> AttrSets(Index + 1);
1144-
AttrSets[Index] = AttributeSet::get(C, B);
1144+
AttrSets[Index] = Attrs;
11451145
return getImpl(C, AttrSets);
11461146
}
11471147

1148+
AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
1149+
const AttrBuilder &B) {
1150+
return get(C, Index, AttributeSet::get(C, B));
1151+
}
1152+
11481153
AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
11491154
ArrayRef<Attribute::AttrKind> Kinds) {
11501155
SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;

0 commit comments

Comments
 (0)