Skip to content

Commit ee43a79

Browse files
authored
Merge pull request #28742 from gottesmm/pr-78cb5286a0f0c99dfe6c50c2b7ee2b624f6a53f2
2 parents 22a0445 + e4e48e8 commit ee43a79

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

lib/SILOptimizer/Utils/PartialApplyCombiner.cpp

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PartialApplyCombiner {
4848
bool processSingleApply(FullApplySite ai);
4949
bool allocateTemporaries();
5050
void deallocateTemporaries();
51-
void releaseTemporaries();
51+
void destroyTemporaries();
5252

5353
public:
5454
PartialApplyCombiner(PartialApplyInst *pai, SILBuilder &builder,
@@ -77,7 +77,7 @@ bool PartialApplyCombiner::allocateTemporaries() {
7777
//
7878
// TODO: Copy arguments of the partial_apply into new temporaries only if the
7979
// lifetime of arguments ends before their uses by apply instructions.
80-
bool needsReleases = false;
80+
bool needsDestroys = false;
8181
CanSILFunctionType paiTy =
8282
pai->getCallee()->getType().getAs<SILFunctionType>();
8383

@@ -108,15 +108,15 @@ bool PartialApplyCombiner::allocateTemporaries() {
108108
if (arg->getType().hasOpenedExistential())
109109
return false;
110110

111-
// If the temporary is non-trivial, we need to release it later.
111+
// If the temporary is non-trivial, we need to destroy it later.
112112
if (!arg->getType().isTrivial(*pai->getFunction()))
113-
needsReleases = true;
113+
needsDestroys = true;
114114
argsToHandle.push_back(std::make_pair(arg, i));
115115
}
116116
}
117117

118-
if (needsReleases) {
119-
// Compute the set of endpoints, which will be used to insert releases of
118+
if (needsDestroys) {
119+
// Compute the set of endpoints, which will be used to insert destroys of
120120
// temporaries. This may fail if the frontier is located on a critical edge
121121
// which we may not split (no CFG changes in SILCombine).
122122
ValueLifetimeAnalysis vla(pai);
@@ -158,7 +158,7 @@ void PartialApplyCombiner::deallocateTemporaries() {
158158
}
159159

160160
/// Emit code to release/destroy temporaries.
161-
void PartialApplyCombiner::releaseTemporaries() {
161+
void PartialApplyCombiner::destroyTemporaries() {
162162
// Insert releases and destroy_addrs as early as possible,
163163
// because we don't want to keep objects alive longer than
164164
// its really needed.
@@ -169,10 +169,9 @@ void PartialApplyCombiner::releaseTemporaries() {
169169
for (auto *endPoint : partialApplyFrontier) {
170170
builder.setInsertionPoint(endPoint);
171171
if (!tmpType.isAddressOnly(*pai->getFunction())) {
172-
auto *load = builder.createLoad(pai->getLoc(), op,
173-
LoadOwnershipQualifier::Unqualified);
174-
builder.createReleaseValue(pai->getLoc(), load,
175-
builder.getDefaultAtomicity());
172+
SILValue load = builder.emitLoadValueOperation(
173+
pai->getLoc(), op, LoadOwnershipQualifier::Take);
174+
builder.emitDestroyValueOperation(pai->getLoc(), load);
176175
} else {
177176
builder.createDestroyAddr(pai->getLoc(), op);
178177
}
@@ -223,19 +222,19 @@ bool PartialApplyCombiner::processSingleApply(FullApplySite paiAI) {
223222
// arguments.
224223
auto paramInfo = pai->getSubstCalleeType()->getParameters();
225224
auto partialApplyArgs = pai->getArguments();
226-
// Set of arguments that need to be released after each invocation.
227-
SmallVector<SILValue, 8> toBeReleasedArgs;
225+
// Set of arguments that need to be destroyed after each invocation.
226+
SmallVector<SILValue, 8> toBeDestroyedArgs;
228227
for (unsigned i : indices(partialApplyArgs)) {
229228
auto arg = partialApplyArgs[i];
230229

231230
if (!arg->getType().isAddress()) {
232-
// Retain the argument as the callee may consume it.
231+
// Copy the argument as the callee may consume it.
233232
arg = builder.emitCopyValueOperation(pai->getLoc(), arg);
234233
// For non consumed parameters (e.g. guaranteed), we also need to
235-
// insert releases after each apply instruction that we create.
234+
// insert destroys after each apply instruction that we create.
236235
if (!paramInfo[paramInfo.size() - partialApplyArgs.size() + i]
237236
.isConsumed())
238-
toBeReleasedArgs.push_back(arg);
237+
toBeDestroyedArgs.push_back(arg);
239238
}
240239
}
241240

@@ -253,27 +252,26 @@ bool PartialApplyCombiner::processSingleApply(FullApplySite paiAI) {
253252
nai = builder.createApply(paiAI.getLoc(), callee, subs, argList,
254253
cast<ApplyInst>(paiAI)->isNonThrowing());
255254

256-
// We also need to release the partial_apply instruction itself because it
257-
// is consumed by the apply_instruction.
255+
// We also need to destroy the partial_apply instruction itself because it is
256+
// consumed by the apply_instruction.
258257
if (auto *tai = dyn_cast<TryApplyInst>(paiAI)) {
259258
builder.setInsertionPoint(tai->getNormalBB()->begin());
260-
for (auto arg : toBeReleasedArgs) {
259+
for (auto arg : toBeDestroyedArgs) {
261260
builder.emitDestroyValueOperation(pai->getLoc(), arg);
262261
}
263262
if (!pai->hasCalleeGuaranteedContext())
264-
builder.createStrongRelease(paiAI.getLoc(), pai,
265-
builder.getDefaultAtomicity());
263+
builder.emitDestroyValueOperation(paiAI.getLoc(), pai);
266264
builder.setInsertionPoint(tai->getErrorBB()->begin());
267-
// Release the non-consumed parameters.
268-
for (auto arg : toBeReleasedArgs) {
265+
// Destroy the non-consumed parameters.
266+
for (auto arg : toBeDestroyedArgs) {
269267
builder.emitDestroyValueOperation(pai->getLoc(), arg);
270268
}
271269
if (!pai->hasCalleeGuaranteedContext())
272270
builder.emitDestroyValueOperation(pai->getLoc(), pai);
273271
builder.setInsertionPoint(paiAI.getInstruction());
274272
} else {
275-
// Release the non-consumed parameters.
276-
for (auto arg : toBeReleasedArgs) {
273+
// Destroy the non-consumed parameters.
274+
for (auto arg : toBeDestroyedArgs) {
277275
builder.emitDestroyValueOperation(pai->getLoc(), arg);
278276
}
279277
if (!pai->hasCalleeGuaranteedContext())
@@ -324,7 +322,7 @@ SILInstruction *PartialApplyCombiner::combine() {
324322
assert(use->get()->getType().castTo<SILFunctionType>() ==
325323
escapingCalleeTy);
326324
(void)escapingCalleeTy;
327-
uses.append(cfi->getUses().begin(), cfi->getUses().end());
325+
llvm::copy(cfi->getUses(), std::back_inserter(uses));
328326
continue;
329327
}
330328

@@ -356,7 +354,7 @@ SILInstruction *PartialApplyCombiner::combine() {
356354

357355
// release/destroy and deallocate introduced temporaries.
358356
if (!tmpCopies.empty()) {
359-
releaseTemporaries();
357+
destroyTemporaries();
360358
deallocateTemporaries();
361359
}
362360

0 commit comments

Comments
 (0)