Skip to content

Commit 5cf1cb3

Browse files
Merge pull request #61304 from nate-chandler/transfer-sil-function-argument-attrs
[SILOptimizer] Preserve arg attrs at cloning.
2 parents fc2d621 + 5d14610 commit 5cf1cb3

19 files changed

+480
-16
lines changed

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ void SILBasicBlock::cloneArgumentList(SILBasicBlock *Other) {
123123
if (isEntry()) {
124124
assert(args_empty() && "Expected to have no arguments");
125125
for (auto *FuncArg : Other->getSILFunctionArguments()) {
126-
createFunctionArgument(FuncArg->getType(),
127-
FuncArg->getDecl());
126+
auto *NewArg =
127+
createFunctionArgument(FuncArg->getType(), FuncArg->getDecl());
128+
NewArg->setNoImplicitCopy(FuncArg->isNoImplicitCopy());
129+
NewArg->setLifetimeAnnotation(FuncArg->getLifetimeAnnotation());
128130
}
129131
return;
130132
}

lib/SILOptimizer/FunctionSignatureTransforms/ArgumentExplosionTransform.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,12 @@ void FunctionSignatureTransform::ArgumentExplosionFinalizeOptimizedFunction() {
390390

391391
for (auto *Node : LeafNodes) {
392392
auto OwnershipKind = *AD.getTransformedOwnershipKind(Node->getType());
393-
LeafValues.push_back(
393+
auto *Argument =
394394
BB->insertFunctionArgument(ArgOffset, Node->getType(), OwnershipKind,
395-
BB->getArgument(OldArgIndex)->getDecl()));
395+
BB->getArgument(OldArgIndex)->getDecl());
396+
Argument->setNoImplicitCopy(AD.Arg->isNoImplicitCopy());
397+
Argument->setLifetimeAnnotation(AD.Arg->getLifetimeAnnotation());
398+
LeafValues.push_back(Argument);
396399
TransformDescriptor.AIM[TotalArgIndex - 1] = AD.Index;
397400
++ArgOffset;
398401
++TotalArgIndex;

lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ void ExistentialSpecializerCloner::cloneArguments(
165165
LoweredTy.getCategoryType(ArgDesc.Arg->getType().getCategory());
166166
auto *NewArg =
167167
ClonedEntryBB->createFunctionArgument(MappedTy, ArgDesc.Decl);
168+
NewArg->setNoImplicitCopy(ArgDesc.Arg->isNoImplicitCopy());
169+
NewArg->setLifetimeAnnotation(ArgDesc.Arg->getLifetimeAnnotation());
168170
NewArg->setOwnershipKind(ValueOwnershipKind(
169171
NewF, MappedTy, ArgDesc.Arg->getArgumentConvention()));
170172
entryArgs.push_back(NewArg);
@@ -180,6 +182,8 @@ void ExistentialSpecializerCloner::cloneArguments(
180182
GenericSILType, ArgDesc.Decl,
181183
ValueOwnershipKind(NewF, GenericSILType,
182184
ArgDesc.Arg->getArgumentConvention()));
185+
NewArg->setNoImplicitCopy(ArgDesc.Arg->isNoImplicitCopy());
186+
NewArg->setLifetimeAnnotation(ArgDesc.Arg->getLifetimeAnnotation());
183187
// Determine the Conformances.
184188
SILType ExistentialType = ArgDesc.Arg->getType().getObjectType();
185189
CanType OpenedType = NewArg->getType().getASTType();
@@ -402,7 +406,10 @@ void ExistentialTransform::populateThunkBody() {
402406
auto *ThunkBody = F->createBasicBlock();
403407
for (auto &ArgDesc : ArgumentDescList) {
404408
auto argumentType = ArgDesc.Arg->getType();
405-
ThunkBody->createFunctionArgument(argumentType, ArgDesc.Decl);
409+
auto *NewArg =
410+
ThunkBody->createFunctionArgument(argumentType, ArgDesc.Decl);
411+
NewArg->setNoImplicitCopy(ArgDesc.Arg->isNoImplicitCopy());
412+
NewArg->setLifetimeAnnotation(ArgDesc.Arg->getLifetimeAnnotation());
406413
}
407414

408415
/// Builder to add new instructions in the Thunk.

lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,10 @@ void FunctionSignatureTransform::createFunctionSignatureOptimizedFunction() {
566566
F->setInlineStrategy(AlwaysInline);
567567
SILBasicBlock *ThunkBody = F->createBasicBlock();
568568
for (auto &ArgDesc : TransformDescriptor.ArgumentDescList) {
569-
ThunkBody->createFunctionArgument(ArgDesc.Arg->getType(), ArgDesc.Decl);
569+
auto *NewArg =
570+
ThunkBody->createFunctionArgument(ArgDesc.Arg->getType(), ArgDesc.Decl);
571+
NewArg->setNoImplicitCopy(ArgDesc.Arg->isNoImplicitCopy());
572+
NewArg->setLifetimeAnnotation(ArgDesc.Arg->getLifetimeAnnotation());
570573
}
571574

572575
SILLocation Loc = RegularLocation::getAutoGeneratedLocation();

lib/SILOptimizer/IPO/CapturePropagation.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,12 @@ void CapturePropagationCloner::cloneClosure(
197197

198198
SILArgument *Arg = OrigEntryBB->getArgument(ArgIdx);
199199

200-
SILValue MappedValue = ClonedEntryBB->createFunctionArgument(
200+
auto *MappedValue = ClonedEntryBB->createFunctionArgument(
201201
remapType(Arg->getType()), Arg->getDecl());
202+
MappedValue->setNoImplicitCopy(
203+
cast<SILFunctionArgument>(Arg)->isNoImplicitCopy());
204+
MappedValue->setLifetimeAnnotation(
205+
cast<SILFunctionArgument>(Arg)->getLifetimeAnnotation());
202206
entryArgs.push_back(MappedValue);
203207
}
204208
assert(OrigEntryBB->args_size() - ArgIdx == PartialApplyArgs.size()

lib/SILOptimizer/IPO/ClosureSpecializer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,12 @@ void ClosureSpecCloner::populateCloned() {
806806

807807
// Otherwise, create a new argument which copies the original argument
808808
auto typeInContext = Cloned->getLoweredType(Arg->getType());
809-
SILValue MappedValue =
809+
auto *MappedValue =
810810
ClonedEntryBB->createFunctionArgument(typeInContext, Arg->getDecl());
811+
MappedValue->setNoImplicitCopy(
812+
cast<SILFunctionArgument>(Arg)->isNoImplicitCopy());
813+
MappedValue->setLifetimeAnnotation(
814+
cast<SILFunctionArgument>(Arg)->getLifetimeAnnotation());
811815
entryArgs.push_back(MappedValue);
812816
}
813817

lib/SILOptimizer/Mandatory/CapturePromotion.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,12 @@ void ClosureCloner::populateCloned() {
491491
for (; ai != ae; ++argNo, ++ai) {
492492
if (!promotableIndices.count(argNo)) {
493493
// Simply create a new argument which copies the original argument
494-
SILValue mappedValue = clonedEntryBB->createFunctionArgument(
494+
auto *mappedValue = clonedEntryBB->createFunctionArgument(
495495
(*ai)->getType(), (*ai)->getDecl());
496+
mappedValue->setNoImplicitCopy(
497+
cast<SILFunctionArgument>(*ai)->isNoImplicitCopy());
498+
mappedValue->setLifetimeAnnotation(
499+
cast<SILFunctionArgument>(*ai)->getLifetimeAnnotation());
496500
entryArgs.push_back(mappedValue);
497501
continue;
498502
}
@@ -504,8 +508,13 @@ void ClosureCloner::populateCloned() {
504508
auto boxedTy = getSILBoxFieldType(TypeExpansionContext(*cloned), boxTy,
505509
cloned->getModule().Types, 0)
506510
.getObjectType();
507-
SILValue mappedValue =
511+
auto *newArg =
508512
clonedEntryBB->createFunctionArgument(boxedTy, (*ai)->getDecl());
513+
newArg->setNoImplicitCopy(
514+
cast<SILFunctionArgument>(*ai)->isNoImplicitCopy());
515+
newArg->setLifetimeAnnotation(
516+
cast<SILFunctionArgument>(*ai)->getLifetimeAnnotation());
517+
SILValue mappedValue = newArg;
509518

510519
// If SIL ownership is enabled, we need to perform a borrow here if we have
511520
// a non-trivial value. We know that our value is not written to and it does

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,10 @@ PromotedParamCloner::populateCloned() {
799799
Cloned->getModule().Types, 0);
800800
auto *promotedArg =
801801
ClonedEntryBB->createFunctionArgument(promotedTy, (*I)->getDecl());
802+
promotedArg->setNoImplicitCopy(
803+
cast<SILFunctionArgument>(*I)->isNoImplicitCopy());
804+
promotedArg->setLifetimeAnnotation(
805+
cast<SILFunctionArgument>(*I)->getLifetimeAnnotation());
802806
OrigPromotedParameters.insert(*I);
803807

804808
NewPromotedArgs[ArgNo] = promotedArg;
@@ -811,8 +815,13 @@ PromotedParamCloner::populateCloned() {
811815
entryArgs.push_back(SILValue());
812816
} else {
813817
// Create a new argument which copies the original argument.
814-
entryArgs.push_back(ClonedEntryBB->createFunctionArgument(
815-
(*I)->getType(), (*I)->getDecl()));
818+
auto *newArg = ClonedEntryBB->createFunctionArgument((*I)->getType(),
819+
(*I)->getDecl());
820+
newArg->setNoImplicitCopy(
821+
cast<SILFunctionArgument>(*I)->isNoImplicitCopy());
822+
newArg->setLifetimeAnnotation(
823+
cast<SILFunctionArgument>(*I)->getLifetimeAnnotation());
824+
entryArgs.push_back(newArg);
816825
}
817826
++ArgNo;
818827
++I;

lib/SILOptimizer/UtilityPasses/SerializeSILPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ void MapOpaqueArchetypes::replace() {
8888
SILType mappedType = remapType(origArg->getType());
8989
auto *NewArg = clonedEntryBlock->createFunctionArgument(
9090
mappedType, origArg->getDecl(), true);
91+
NewArg->setNoImplicitCopy(
92+
cast<SILFunctionArgument>(origArg)->isNoImplicitCopy());
93+
NewArg->setLifetimeAnnotation(
94+
cast<SILFunctionArgument>(origArg)->getLifetimeAnnotation());
9195
entryArgs.push_back(NewArg);
9296
}
9397

lib/SILOptimizer/Utils/GenericCloner.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ void GenericCloner::populateCloned() {
120120
mappedType = mappedType.getObjectType();
121121
auto *NewArg = ClonedEntryBB->createFunctionArgument(
122122
mappedType, OrigArg->getDecl());
123+
NewArg->setNoImplicitCopy(
124+
cast<SILFunctionArgument>(OrigArg)->isNoImplicitCopy());
125+
NewArg->setLifetimeAnnotation(
126+
cast<SILFunctionArgument>(OrigArg)->getLifetimeAnnotation());
123127

124128
// Try to create a new debug_value from an existing debug_value w/
125129
// address value for the argument. We do this before storing to
@@ -164,6 +168,10 @@ void GenericCloner::populateCloned() {
164168
if (!handleConversion()) {
165169
auto *NewArg =
166170
ClonedEntryBB->createFunctionArgument(mappedType, OrigArg->getDecl());
171+
NewArg->setNoImplicitCopy(
172+
cast<SILFunctionArgument>(OrigArg)->isNoImplicitCopy());
173+
NewArg->setLifetimeAnnotation(
174+
cast<SILFunctionArgument>(OrigArg)->getLifetimeAnnotation());
167175
entryArgs.push_back(NewArg);
168176
}
169177
++ArgIdx;

0 commit comments

Comments
 (0)