Skip to content

Commit 30be511

Browse files
committed
[rebranch][IRGen] Update uses of AttributeList functions
The functions in llvm-project `AttributeList` have been renamed/refactored to help remove uses of `AttributeList::*Index`. Update to use these new functions where possible. There's one use of `AttrIndex` remaining as `replaceAttributeTypeAtIndex` still takes the index and there is no `param` equivalent. We could add one locally, but presumably that will be added eventually.
1 parent a6f99a0 commit 30be511

21 files changed

+96
-153
lines changed

lib/IRGen/CallEmission.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ class CallEmission {
9797
WitnessMetadata *witnessMetadata);
9898
virtual Address getCalleeErrorSlot(SILType errorType, bool isCalleeAsync) = 0;
9999

100-
void addAttribute(unsigned Index, llvm::Attribute::AttrKind Attr);
100+
void addFnAttribute(llvm::Attribute::AttrKind Attr);
101+
102+
void addParamAttribute(unsigned ParamIndex, llvm::Attribute::AttrKind Attr);
101103

102104
void emitToMemory(Address addr, const LoadableTypeInfo &substResultTI,
103105
bool isOutlined);

lib/IRGen/GenArchetype.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ MetadataResponse irgen::emitOpaqueTypeMetadataRef(IRGenFunction &IGF,
518518
{request.get(IGF), genericArgs, descriptor, indexValue});
519519
result->setDoesNotThrow();
520520
result->setCallingConv(IGF.IGM.SwiftCC);
521-
result->addAttribute(llvm::AttributeList::FunctionIndex,
522-
llvm::Attribute::ReadOnly);
521+
result->addFnAttr(llvm::Attribute::ReadOnly);
523522
});
524523
assert(result);
525524

@@ -552,8 +551,7 @@ llvm::Value *irgen::emitOpaqueTypeWitnessTableRef(IRGenFunction &IGF,
552551
{genericArgs, descriptor, indexValue});
553552
result->setDoesNotThrow();
554553
result->setCallingConv(IGF.IGM.SwiftCC);
555-
result->addAttribute(llvm::AttributeList::FunctionIndex,
556-
llvm::Attribute::ReadOnly);
554+
result->addFnAttr(llvm::Attribute::ReadOnly);
557555
});
558556
assert(result);
559557

lib/IRGen/GenBuiltin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,8 @@ if (Builtin.ID == BuiltinValueKind::id) { \
603603
llvm::CallInst *call = IGF.Builder.CreateCall(fn,
604604
{context, errorBuffer.getAddress()});
605605
call->setCallingConv(IGF.IGM.SwiftCC);
606-
call->addAttribute(llvm::AttributeList::FunctionIndex,
607-
llvm::Attribute::NoUnwind);
608-
call->addAttribute(llvm::AttributeList::FirstArgIndex + 1,
609-
llvm::Attribute::ReadOnly);
606+
call->addFnAttr(llvm::Attribute::NoUnwind);
607+
call->addParamAttr(1, llvm::Attribute::ReadOnly);
610608

611609
auto attrs = call->getAttributes();
612610
IGF.IGM.addSwiftSelfAttributes(attrs, 0);

lib/IRGen/GenCall.cpp

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ static void addIndirectValueParameterAttributes(IRGenModule &IGM,
260260
// The parameter must reference dereferenceable memory of the type.
261261
addDereferenceableAttributeToBuilder(IGM, b, ti);
262262

263-
attrs = attrs.addAttributes(IGM.getLLVMContext(),
264-
argIndex + llvm::AttributeList::FirstArgIndex, b);
263+
attrs = attrs.addParamAttributes(IGM.getLLVMContext(), argIndex, b);
265264
}
266265

267266
static void addInoutParameterAttributes(IRGenModule &IGM,
@@ -276,8 +275,7 @@ static void addInoutParameterAttributes(IRGenModule &IGM,
276275
// The inout must reference dereferenceable memory of the type.
277276
addDereferenceableAttributeToBuilder(IGM, b, ti);
278277

279-
attrs = attrs.addAttributes(IGM.getLLVMContext(),
280-
argIndex + llvm::AttributeList::FirstArgIndex, b);
278+
attrs = attrs.addParamAttributes(IGM.getLLVMContext(), argIndex, b);
281279
}
282280

283281
static llvm::CallingConv::ID getFreestandingConvention(IRGenModule &IGM) {
@@ -319,25 +317,21 @@ static void addIndirectResultAttributes(IRGenModule &IGM,
319317
assert(storageType);
320318
b.addStructRetAttr(storageType);
321319
}
322-
attrs = attrs.addAttributes(IGM.getLLVMContext(),
323-
paramIndex + llvm::AttributeList::FirstArgIndex,
324-
b);
320+
attrs = attrs.addParamAttributes(IGM.getLLVMContext(), paramIndex, b);
325321
}
326322

327323
void IRGenModule::addSwiftAsyncContextAttributes(llvm::AttributeList &attrs,
328324
unsigned argIndex) {
329325
llvm::AttrBuilder b;
330326
b.addAttribute(llvm::Attribute::SwiftAsync);
331-
attrs = attrs.addAttributes(this->getLLVMContext(),
332-
argIndex + llvm::AttributeList::FirstArgIndex, b);
327+
attrs = attrs.addParamAttributes(this->getLLVMContext(), argIndex, b);
333328
}
334329

335330
void IRGenModule::addSwiftSelfAttributes(llvm::AttributeList &attrs,
336331
unsigned argIndex) {
337332
llvm::AttrBuilder b;
338333
b.addAttribute(llvm::Attribute::SwiftSelf);
339-
attrs = attrs.addAttributes(this->getLLVMContext(),
340-
argIndex + llvm::AttributeList::FirstArgIndex, b);
334+
attrs = attrs.addParamAttributes(this->getLLVMContext(), argIndex, b);
341335
}
342336

343337
void IRGenModule::addSwiftErrorAttributes(llvm::AttributeList &attrs,
@@ -355,9 +349,8 @@ void IRGenModule::addSwiftErrorAttributes(llvm::AttributeList &attrs,
355349
b.addAttribute(llvm::Attribute::NoAlias);
356350
b.addAttribute(llvm::Attribute::NoCapture);
357351
b.addDereferenceableAttr(getPointerSize().getValue());
358-
359-
auto attrIndex = argIndex + llvm::AttributeList::FirstArgIndex;
360-
attrs = attrs.addAttributes(this->getLLVMContext(), attrIndex, b);
352+
353+
attrs = attrs.addParamAttributes(this->getLLVMContext(), argIndex, b);
361354
}
362355

363356
void irgen::addByvalArgumentAttributes(IRGenModule &IGM,
@@ -368,18 +361,13 @@ void irgen::addByvalArgumentAttributes(IRGenModule &IGM,
368361
b.addByValAttr(storageType);
369362
b.addAttribute(llvm::Attribute::getWithAlignment(
370363
IGM.getLLVMContext(), llvm::Align(align.getValue())));
371-
attrs = attrs.addAttributes(IGM.getLLVMContext(),
372-
argIndex + llvm::AttributeList::FirstArgIndex, b);
364+
attrs = attrs.addParamAttributes(IGM.getLLVMContext(), argIndex, b);
373365
}
374366

375-
void irgen::addExtendAttribute(IRGenModule &IGM, llvm::AttributeList &attrs,
376-
unsigned index, bool signExtend) {
377-
llvm::AttrBuilder b;
367+
static llvm::Attribute::AttrKind attrKindForExtending(bool signExtend) {
378368
if (signExtend)
379-
b.addAttribute(llvm::Attribute::SExt);
380-
else
381-
b.addAttribute(llvm::Attribute::ZExt);
382-
attrs = attrs.addAttributes(IGM.getLLVMContext(), index, b);
369+
return llvm::Attribute::SExt;
370+
return llvm::Attribute::ZExt;
383371
}
384372

385373
namespace swift {
@@ -1366,7 +1354,8 @@ void SignatureExpansion::expandExternalSignatureTypes() {
13661354
bool signExt = clangResultTy->hasSignedIntegerRepresentation();
13671355
assert((signExt || clangResultTy->hasUnsignedIntegerRepresentation()) &&
13681356
"Invalid attempt to add extension attribute to argument!");
1369-
addExtendAttribute(IGM, Attrs, llvm::AttributeList::ReturnIndex, signExt);
1357+
Attrs = Attrs.addRetAttribute(IGM.getLLVMContext(),
1358+
attrKindForExtending(signExt));
13701359
}
13711360

13721361
// If we return indirectly, that is the first parameter type.
@@ -1396,8 +1385,8 @@ void SignatureExpansion::expandExternalSignatureTypes() {
13961385
bool signExt = paramTys[i]->hasSignedIntegerRepresentation();
13971386
assert((signExt || paramTys[i]->hasUnsignedIntegerRepresentation()) &&
13981387
"Invalid attempt to add extension attribute to argument!");
1399-
addExtendAttribute(IGM, Attrs, getCurParamIndex() +
1400-
llvm::AttributeList::FirstArgIndex, signExt);
1388+
Attrs = Attrs.addParamAttribute(IGM.getLLVMContext(), getCurParamIndex(),
1389+
attrKindForExtending(signExt));
14011390
LLVM_FALLTHROUGH;
14021391
}
14031392
case clang::CodeGen::ABIArgInfo::Direct: {
@@ -2147,8 +2136,7 @@ class SyncCallEmission final : public CallEmission {
21472136

21482137
assert(LastArgWritten > 0);
21492138
Args[--LastArgWritten] = errorResultSlot.getAddress();
2150-
addAttribute(LastArgWritten + llvm::AttributeList::FirstArgIndex,
2151-
llvm::Attribute::NoCapture);
2139+
addParamAttribute(LastArgWritten, llvm::Attribute::NoCapture);
21522140
IGF.IGM.addSwiftErrorAttributes(CurCallee.getMutableAttributes(),
21532141
LastArgWritten);
21542142

@@ -2847,12 +2835,12 @@ fixUpTypesInByValAndStructRetAttributes(llvm::FunctionType *fnType,
28472835
auto attrListIndex = llvm::AttributeList::FirstArgIndex + i;
28482836
if (attrList.hasParamAttr(i, llvm::Attribute::StructRet) &&
28492837
paramTy->getPointerElementType() != attrList.getParamStructRetType(i))
2850-
attrList = attrList.replaceAttributeType(
2838+
attrList = attrList.replaceAttributeTypeAtIndex(
28512839
context, attrListIndex, llvm::Attribute::StructRet,
28522840
paramTy->getPointerElementType());
28532841
if (attrList.hasParamAttr(i, llvm::Attribute::ByVal) &&
28542842
paramTy->getPointerElementType() != attrList.getParamByValType(i))
2855-
attrList = attrList.replaceAttributeType(
2843+
attrList = attrList.replaceAttributeTypeAtIndex(
28562844
context, attrListIndex, llvm::Attribute::ByVal,
28572845
paramTy->getPointerElementType());
28582846
}
@@ -4090,11 +4078,17 @@ void CallEmission::setArgs(Explosion &adjusted, bool isOutlined,
40904078
}
40914079
}
40924080

4093-
void CallEmission::addAttribute(unsigned index,
4094-
llvm::Attribute::AttrKind attr) {
4081+
void CallEmission::addFnAttribute(llvm::Attribute::AttrKind attr) {
4082+
assert(state == State::Emitting);
4083+
auto &attrs = CurCallee.getMutableAttributes();
4084+
attrs = attrs.addFnAttribute(IGF.IGM.getLLVMContext(), attr);
4085+
}
4086+
4087+
void CallEmission::addParamAttribute(unsigned paramIndex,
4088+
llvm::Attribute::AttrKind attr) {
40954089
assert(state == State::Emitting);
40964090
auto &attrs = CurCallee.getMutableAttributes();
4097-
attrs = attrs.addAttribute(IGF.IGM.getLLVMContext(), index, attr);
4091+
attrs = attrs.addParamAttribute(IGF.IGM.getLLVMContext(), paramIndex, attr);
40984092
}
40994093

41004094
/// Initialize an Explosion with the parameters of the current

lib/IRGen/GenCall.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ namespace irgen {
156156
Alignment align,
157157
llvm::Type *storageType);
158158

159-
/// Add signext or zeroext attribute set for an argument that needs
160-
/// extending.
161-
void addExtendAttribute(IRGenModule &IGM, llvm::AttributeList &attrs,
162-
unsigned index, bool signExtend);
163-
164159
/// Can a series of values be simply pairwise coerced to (or from) an
165160
/// explosion schema, or do they need to traffic through memory?
166161
bool canCoerceToSchema(IRGenModule &IGM,

lib/IRGen/GenDecl.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,10 +2248,8 @@ llvm::Function *irgen::createFunction(IRGenModule &IGM,
22482248
llvm::AttrBuilder initialAttrs;
22492249
IGM.constructInitialFnAttributes(initialAttrs, FuncOptMode);
22502250
// Merge initialAttrs with attrs.
2251-
auto updatedAttrs =
2252-
signature.getAttributes().addAttributes(IGM.getLLVMContext(),
2253-
llvm::AttributeList::FunctionIndex,
2254-
initialAttrs);
2251+
auto updatedAttrs = signature.getAttributes().addFnAttributes(
2252+
IGM.getLLVMContext(), initialAttrs);
22552253
if (!updatedAttrs.isEmpty())
22562254
fn->setAttributes(updatedAttrs);
22572255

@@ -2619,9 +2617,8 @@ static void addLLVMFunctionAttributes(SILFunction *f, Signature &signature) {
26192617
auto &attrs = signature.getMutableAttributes();
26202618
switch (f->getInlineStrategy()) {
26212619
case NoInline:
2622-
attrs = attrs.addAttribute(signature.getType()->getContext(),
2623-
llvm::AttributeList::FunctionIndex,
2624-
llvm::Attribute::NoInline);
2620+
attrs = attrs.addFnAttribute(signature.getType()->getContext(),
2621+
llvm::Attribute::NoInline);
26252622
break;
26262623
case AlwaysInline:
26272624
// FIXME: We do not currently transfer AlwaysInline since doing so results
@@ -2631,9 +2628,8 @@ static void addLLVMFunctionAttributes(SILFunction *f, Signature &signature) {
26312628
}
26322629

26332630
if (isReadOnlyFunction(f)) {
2634-
attrs = attrs.addAttribute(signature.getType()->getContext(),
2635-
llvm::AttributeList::FunctionIndex,
2636-
llvm::Attribute::ReadOnly);
2631+
attrs = attrs.addFnAttribute(signature.getType()->getContext(),
2632+
llvm::Attribute::ReadOnly);
26372633
}
26382634
}
26392635

@@ -3097,8 +3093,8 @@ llvm::Constant *swift::irgen::emitCXXConstructorThunkIfNeeded(
30973093
llvm::AttrBuilder attrBuilder;
30983094
IGM.constructInitialFnAttributes(attrBuilder);
30993095
attrBuilder.addAttribute(llvm::Attribute::AlwaysInline);
3100-
llvm::AttributeList attr = signature.getAttributes().addAttributes(
3101-
IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, attrBuilder);
3096+
llvm::AttributeList attr = signature.getAttributes().addFnAttributes(
3097+
IGM.getLLVMContext(), attrBuilder);
31023098
thunk->setAttributes(attr);
31033099

31043100
IRGenFunction subIGF(IGM, thunk);

lib/IRGen/GenEnum.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,8 +3865,7 @@ namespace {
38653865
auto call = IGF.Builder.CreateCall(IGM.getGetEnumCaseMultiPayloadFn(),
38663866
{addr.getAddress(), metadata});
38673867
call->setDoesNotThrow();
3868-
call->addAttribute(llvm::AttributeList::FunctionIndex,
3869-
llvm::Attribute::ReadOnly);
3868+
call->addFnAttr(llvm::Attribute::ReadOnly);
38703869

38713870
return call;
38723871
}

lib/IRGen/GenFunc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ static llvm::Value *emitPartialApplicationForwarder(IRGenModule &IGM,
12631263
// Merge initial attributes with outAttrs.
12641264
llvm::AttrBuilder b;
12651265
IGM.constructInitialFnAttributes(b);
1266-
fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);
1266+
fwd->addFnAttrs(b);
12671267

12681268
IRGenFunction subIGF(IGM, fwd);
12691269
if (origType->isAsync()) {

lib/IRGen/GenHeap.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,7 @@ llvm::Constant *IRGenModule::getFixLifetimeFn() {
12371237
// Don't inline the function, so it stays as a signal to the ARC passes.
12381238
// The ARC passes will remove references to the function when they're
12391239
// no longer needed.
1240-
fixLifetime->addAttribute(llvm::AttributeList::FunctionIndex,
1241-
llvm::Attribute::NoInline);
1240+
fixLifetime->addFnAttr(llvm::Attribute::NoInline);
12421241

12431242
// Give the function an empty body.
12441243
auto entry = llvm::BasicBlock::Create(getLLVMContext(), "", fixLifetime);
@@ -1958,8 +1957,7 @@ emitHeapMetadataRefForUnknownHeapObject(IRGenFunction &IGF,
19581957
object->getName() + ".Type");
19591958
metadata->setCallingConv(llvm::CallingConv::C);
19601959
metadata->setDoesNotThrow();
1961-
metadata->addAttribute(llvm::AttributeList::FunctionIndex,
1962-
llvm::Attribute::ReadOnly);
1960+
metadata->addFnAttr(llvm::Attribute::ReadOnly);
19631961
return metadata;
19641962
}
19651963

lib/IRGen/GenKeyPath.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,22 @@ getAccessorForComputedComponent(IRGenModule &IGM,
188188
case Getter:
189189
// Original accessor's args should be @in or @out, meaning they won't be
190190
// captured or aliased.
191-
accessorThunk->addAttribute(1, llvm::Attribute::NoCapture);
192-
accessorThunk->addAttribute(1, llvm::Attribute::NoAlias);
193-
accessorThunk->addAttribute(2, llvm::Attribute::NoCapture);
194-
accessorThunk->addAttribute(2, llvm::Attribute::NoAlias);
191+
accessorThunk->addParamAttr(0, llvm::Attribute::NoCapture);
192+
accessorThunk->addParamAttr(0, llvm::Attribute::NoAlias);
193+
accessorThunk->addParamAttr(1, llvm::Attribute::NoCapture);
194+
accessorThunk->addParamAttr(1, llvm::Attribute::NoAlias);
195195
// Output is sret.
196-
accessorThunk->addAttribute(
197-
1, llvm::Attribute::getWithStructRetType(
196+
accessorThunk->addParamAttr(
197+
0, llvm::Attribute::getWithStructRetType(
198198
IGM.getLLVMContext(), thunkParams[0]->getPointerElementType()));
199199
break;
200200
case Setter:
201201
// Original accessor's args should be @in or @out, meaning they won't be
202202
// captured or aliased.
203-
accessorThunk->addAttribute(1, llvm::Attribute::NoCapture);
204-
accessorThunk->addAttribute(1, llvm::Attribute::NoAlias);
205-
accessorThunk->addAttribute(2, llvm::Attribute::NoCapture);
206-
accessorThunk->addAttribute(2, llvm::Attribute::NoAlias);
203+
accessorThunk->addParamAttr(0, llvm::Attribute::NoCapture);
204+
accessorThunk->addParamAttr(0, llvm::Attribute::NoAlias);
205+
accessorThunk->addParamAttr(1, llvm::Attribute::NoCapture);
206+
accessorThunk->addParamAttr(1, llvm::Attribute::NoAlias);
207207
break;
208208
case Equals:
209209
case Hash:

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4980,10 +4980,8 @@ namespace {
49804980
auto candidate = IGF.IGM.getAddrOfTypeMetadata(type);
49814981
auto call = IGF.Builder.CreateCall(IGF.IGM.getGetForeignTypeMetadataFn(),
49824982
{request.get(IGF), candidate});
4983-
call->addAttribute(llvm::AttributeList::FunctionIndex,
4984-
llvm::Attribute::NoUnwind);
4985-
call->addAttribute(llvm::AttributeList::FunctionIndex,
4986-
llvm::Attribute::ReadNone);
4983+
call->addFnAttr(llvm::Attribute::NoUnwind);
4984+
call->addFnAttr(llvm::Attribute::ReadNone);
49874985

49884986
return MetadataResponse::handle(IGF, request, call);
49894987
});

lib/IRGen/GenObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
721721
// Merge initial attributes with attrs.
722722
llvm::AttrBuilder b;
723723
IGM.constructInitialFnAttributes(b);
724-
fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);
725-
724+
fwd->addFnAttrs(b);
725+
726726
IRGenFunction subIGF(IGM, fwd);
727727
if (IGM.DebugInfo)
728728
IGM.DebugInfo->emitArtificialFunction(subIGF, fwd);

lib/IRGen/GenOpaque.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static llvm::AttributeList getValueWitnessAttrs(IRGenModule &IGM,
164164
auto &ctx = IGM.getLLVMContext();
165165

166166
// All value witnesses are nounwind.
167-
auto attrs = llvm::AttributeList::get(ctx, llvm::AttributeList::FunctionIndex,
168-
llvm::Attribute::NoUnwind);
167+
auto attrs =
168+
llvm::AttributeList().addFnAttribute(ctx, llvm::Attribute::NoUnwind);
169169

170170
switch (index) {
171171
// These have two arguments, but they can alias.
@@ -178,21 +178,19 @@ static llvm::AttributeList getValueWitnessAttrs(IRGenModule &IGM,
178178
case ValueWitness::DestructiveProjectEnumData:
179179
case ValueWitness::GetEnumTag:
180180
case ValueWitness::StoreEnumTagSinglePayload:
181-
return attrs.addAttribute(ctx, 1, llvm::Attribute::NoAlias);
181+
return attrs.addParamAttribute(ctx, 0, llvm::Attribute::NoAlias);
182182

183183
case ValueWitness::GetEnumTagSinglePayload:
184-
return attrs
185-
.addAttribute(ctx, llvm::AttributeList::FunctionIndex,
186-
llvm::Attribute::ReadOnly)
187-
.addAttribute(ctx, 1, llvm::Attribute::NoAlias);
184+
return attrs.addFnAttribute(ctx, llvm::Attribute::ReadOnly)
185+
.addParamAttribute(ctx, 0, llvm::Attribute::NoAlias);
188186

189187
// These have two arguments and they don't alias each other.
190188
case ValueWitness::AssignWithTake:
191189
case ValueWitness::InitializeBufferWithCopyOfBuffer:
192190
case ValueWitness::InitializeWithCopy:
193191
case ValueWitness::InitializeWithTake:
194-
return attrs.addAttribute(ctx, 1, llvm::Attribute::NoAlias)
195-
.addAttribute(ctx, 2, llvm::Attribute::NoAlias);
192+
return attrs.addParamAttribute(ctx, 0, llvm::Attribute::NoAlias)
193+
.addParamAttribute(ctx, 1, llvm::Attribute::NoAlias);
196194

197195
case ValueWitness::Size:
198196
case ValueWitness::Flags:

0 commit comments

Comments
 (0)