Skip to content

Commit 5acb59a

Browse files
committed
[pa-combiner] Simplify some cleanup code by using FullApplySite::insertAfterFullInvocation.
1 parent 5ba2e59 commit 5acb59a

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

lib/SILOptimizer/Utils/PartialApplyCombiner.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -254,29 +254,16 @@ bool PartialApplyCombiner::processSingleApply(FullApplySite paiAI) {
254254

255255
// We also need to destroy the partial_apply instruction itself because it is
256256
// consumed by the apply_instruction.
257-
if (auto *tai = dyn_cast<TryApplyInst>(paiAI)) {
258-
builder.setInsertionPoint(tai->getNormalBB()->begin());
257+
auto loc = RegularLocation::getAutoGeneratedLocation();
258+
paiAI.insertAfterFullEvaluation([&](SILBasicBlock::iterator insertPt) {
259+
SILBuilderWithScope builder(insertPt);
259260
for (auto arg : toBeDestroyedArgs) {
260-
builder.emitDestroyValueOperation(pai->getLoc(), arg);
261+
builder.emitDestroyValueOperation(loc, arg);
261262
}
262-
if (!pai->hasCalleeGuaranteedContext())
263-
builder.emitDestroyValueOperation(paiAI.getLoc(), pai);
264-
builder.setInsertionPoint(tai->getErrorBB()->begin());
265-
// Destroy the non-consumed parameters.
266-
for (auto arg : toBeDestroyedArgs) {
267-
builder.emitDestroyValueOperation(pai->getLoc(), arg);
268-
}
269-
if (!pai->hasCalleeGuaranteedContext())
270-
builder.emitDestroyValueOperation(pai->getLoc(), pai);
271-
builder.setInsertionPoint(paiAI.getInstruction());
272-
} else {
273-
// Destroy the non-consumed parameters.
274-
for (auto arg : toBeDestroyedArgs) {
275-
builder.emitDestroyValueOperation(pai->getLoc(), arg);
263+
if (!pai->hasCalleeGuaranteedContext()) {
264+
builder.emitDestroyValueOperation(loc, pai);
276265
}
277-
if (!pai->hasCalleeGuaranteedContext())
278-
builder.emitDestroyValueOperation(pai->getLoc(), pai);
279-
}
266+
});
280267

281268
if (auto *apply = dyn_cast<ApplyInst>(paiAI)) {
282269
callbacks.replaceValueUsesWith(SILValue(apply),

0 commit comments

Comments
 (0)