@@ -48,7 +48,7 @@ class PartialApplyCombiner {
48
48
bool processSingleApply (FullApplySite ai);
49
49
bool allocateTemporaries ();
50
50
void deallocateTemporaries ();
51
- void releaseTemporaries ();
51
+ void destroyTemporaries ();
52
52
53
53
public:
54
54
PartialApplyCombiner (PartialApplyInst *pai, SILBuilder &builder,
@@ -77,7 +77,7 @@ bool PartialApplyCombiner::allocateTemporaries() {
77
77
//
78
78
// TODO: Copy arguments of the partial_apply into new temporaries only if the
79
79
// lifetime of arguments ends before their uses by apply instructions.
80
- bool needsReleases = false ;
80
+ bool needsDestroys = false ;
81
81
CanSILFunctionType paiTy =
82
82
pai->getCallee ()->getType ().getAs <SILFunctionType>();
83
83
@@ -108,15 +108,15 @@ bool PartialApplyCombiner::allocateTemporaries() {
108
108
if (arg->getType ().hasOpenedExistential ())
109
109
return false ;
110
110
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.
112
112
if (!arg->getType ().isTrivial (*pai->getFunction ()))
113
- needsReleases = true ;
113
+ needsDestroys = true ;
114
114
argsToHandle.push_back (std::make_pair (arg, i));
115
115
}
116
116
}
117
117
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
120
120
// temporaries. This may fail if the frontier is located on a critical edge
121
121
// which we may not split (no CFG changes in SILCombine).
122
122
ValueLifetimeAnalysis vla (pai);
@@ -158,7 +158,7 @@ void PartialApplyCombiner::deallocateTemporaries() {
158
158
}
159
159
160
160
// / Emit code to release/destroy temporaries.
161
- void PartialApplyCombiner::releaseTemporaries () {
161
+ void PartialApplyCombiner::destroyTemporaries () {
162
162
// Insert releases and destroy_addrs as early as possible,
163
163
// because we don't want to keep objects alive longer than
164
164
// its really needed.
@@ -169,10 +169,9 @@ void PartialApplyCombiner::releaseTemporaries() {
169
169
for (auto *endPoint : partialApplyFrontier) {
170
170
builder.setInsertionPoint (endPoint);
171
171
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);
176
175
} else {
177
176
builder.createDestroyAddr (pai->getLoc (), op);
178
177
}
@@ -223,19 +222,19 @@ bool PartialApplyCombiner::processSingleApply(FullApplySite paiAI) {
223
222
// arguments.
224
223
auto paramInfo = pai->getSubstCalleeType ()->getParameters ();
225
224
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 ;
228
227
for (unsigned i : indices (partialApplyArgs)) {
229
228
auto arg = partialApplyArgs[i];
230
229
231
230
if (!arg->getType ().isAddress ()) {
232
- // Retain the argument as the callee may consume it.
231
+ // Copy the argument as the callee may consume it.
233
232
arg = builder.emitCopyValueOperation (pai->getLoc (), arg);
234
233
// 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.
236
235
if (!paramInfo[paramInfo.size () - partialApplyArgs.size () + i]
237
236
.isConsumed ())
238
- toBeReleasedArgs .push_back (arg);
237
+ toBeDestroyedArgs .push_back (arg);
239
238
}
240
239
}
241
240
@@ -253,27 +252,26 @@ bool PartialApplyCombiner::processSingleApply(FullApplySite paiAI) {
253
252
nai = builder.createApply (paiAI.getLoc (), callee, subs, argList,
254
253
cast<ApplyInst>(paiAI)->isNonThrowing ());
255
254
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.
258
257
if (auto *tai = dyn_cast<TryApplyInst>(paiAI)) {
259
258
builder.setInsertionPoint (tai->getNormalBB ()->begin ());
260
- for (auto arg : toBeReleasedArgs ) {
259
+ for (auto arg : toBeDestroyedArgs ) {
261
260
builder.emitDestroyValueOperation (pai->getLoc (), arg);
262
261
}
263
262
if (!pai->hasCalleeGuaranteedContext ())
264
- builder.createStrongRelease (paiAI.getLoc (), pai,
265
- builder.getDefaultAtomicity ());
263
+ builder.emitDestroyValueOperation (paiAI.getLoc (), pai);
266
264
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 ) {
269
267
builder.emitDestroyValueOperation (pai->getLoc (), arg);
270
268
}
271
269
if (!pai->hasCalleeGuaranteedContext ())
272
270
builder.emitDestroyValueOperation (pai->getLoc (), pai);
273
271
builder.setInsertionPoint (paiAI.getInstruction ());
274
272
} else {
275
- // Release the non-consumed parameters.
276
- for (auto arg : toBeReleasedArgs ) {
273
+ // Destroy the non-consumed parameters.
274
+ for (auto arg : toBeDestroyedArgs ) {
277
275
builder.emitDestroyValueOperation (pai->getLoc (), arg);
278
276
}
279
277
if (!pai->hasCalleeGuaranteedContext ())
@@ -324,7 +322,7 @@ SILInstruction *PartialApplyCombiner::combine() {
324
322
assert (use->get ()->getType ().castTo <SILFunctionType>() ==
325
323
escapingCalleeTy);
326
324
(void )escapingCalleeTy;
327
- uses. append (cfi->getUses (). begin (), cfi-> getUses (). end ( ));
325
+ llvm::copy (cfi->getUses (), std::back_inserter (uses ));
328
326
continue ;
329
327
}
330
328
@@ -356,7 +354,7 @@ SILInstruction *PartialApplyCombiner::combine() {
356
354
357
355
// release/destroy and deallocate introduced temporaries.
358
356
if (!tmpCopies.empty ()) {
359
- releaseTemporaries ();
357
+ destroyTemporaries ();
360
358
deallocateTemporaries ();
361
359
}
362
360
0 commit comments