@@ -176,30 +176,6 @@ static SILFunctionConventions getLoweredCallConv(ApplySite call) {
176176 SILModuleConventions::getLoweredAddressConventions (call.getModule ()));
177177}
178178
179- // / Invoke \p cleanup on all paths exiting a call.
180- static void
181- cleanupAfterCall (FullApplySite apply,
182- llvm::function_ref<void (SILBasicBlock::iterator)> cleanup) {
183- switch (apply.getKind ()) {
184- case FullApplySiteKind::ApplyInst: {
185- cleanup (std::next (apply.getInstruction ()->getIterator ()));
186- break ;
187- }
188- case FullApplySiteKind::TryApplyInst: {
189- auto *tryApply = cast<TryApplyInst>(apply.getInstruction ());
190- cleanup (tryApply->getNormalBB ()->begin ());
191- cleanup (tryApply->getErrorBB ()->begin ());
192- break ;
193- }
194- case FullApplySiteKind::BeginApplyInst: {
195- // FIXME: Unimplemented
196- //
197- // This should be as simple as calling cleanup for all the end_applies.
198- llvm::report_fatal_error (" Unimplemented coroutine" );
199- }
200- }
201- }
202-
203179// ===----------------------------------------------------------------------===//
204180// Multi-Result
205181//
@@ -482,6 +458,12 @@ struct AddressLoweringState {
482458 builder.setCurrentDebugScope (originalInst->getDebugScope ());
483459 return builder;
484460 }
461+
462+ void prepareBuilder (SILBuilder &builder) {
463+ builder.setSILConventions (
464+ SILModuleConventions::getLoweredAddressConventions (
465+ builder.getModule ()));
466+ };
485467};
486468} // end anonymous namespace
487469
@@ -1733,22 +1715,20 @@ void CallArgRewriter::rewriteIndirectArgument(Operand *operand) {
17331715 if (apply.getArgumentConvention (*operand).isOwnedConvention ()) {
17341716 argBuilder.createTrivialStoreOr (apply.getLoc (), argValue, allocInst,
17351717 StoreOwnershipQualifier::Init);
1736- cleanupAfterCall (apply, [&](SILBasicBlock::iterator insertPt) {
1737- auto deallocBuilder = pass.getBuilder (insertPt);
1738- deallocBuilder.createDeallocStack (callLoc, allocInst);
1718+ apply.insertAfterFullEvaluation ([&](SILBuilder &callBuilder) {
1719+ callBuilder.createDeallocStack (callLoc, allocInst);
17391720 });
17401721 } else {
17411722 auto borrow = argBuilder.emitBeginBorrowOperation (callLoc, argValue);
17421723 auto *storeInst =
17431724 argBuilder.emitStoreBorrowOperation (callLoc, borrow, allocInst);
17441725
1745- cleanupAfterCall (apply, [&](SILBasicBlock::iterator insertPt) {
1746- auto cleanupBuilder = pass.getBuilder (insertPt);
1726+ apply.insertAfterFullEvaluation ([&](SILBuilder &callBuilder) {
17471727 if (auto *storeBorrow = dyn_cast<StoreBorrowInst>(storeInst)) {
1748- cleanupBuilder .emitEndBorrowOperation (callLoc, storeBorrow);
1728+ callBuilder .emitEndBorrowOperation (callLoc, storeBorrow);
17491729 }
1750- cleanupBuilder .emitEndBorrowOperation (callLoc, borrow);
1751- cleanupBuilder .createDeallocStack (callLoc, allocInst);
1730+ callBuilder .emitEndBorrowOperation (callLoc, borrow);
1731+ callBuilder .createDeallocStack (callLoc, allocInst);
17521732 });
17531733 }
17541734}
@@ -2020,9 +2000,8 @@ SILValue ApplyRewriter::materializeIndirectResultAddress(SILValue oldResult,
20202000
20212001 // Instead of using resultBuilder, insert dealloc immediately after the call
20222002 // for stack discpline across loadable indirect results.
2023- cleanupAfterCall (apply, [&](SILBasicBlock::iterator insertPt) {
2024- auto cleanupBuilder = pass.getBuilder (insertPt);
2025- cleanupBuilder.createDeallocStack (callLoc, allocInst);
2003+ apply.insertAfterFullEvaluation ([&](SILBuilder &callBuilder) {
2004+ callBuilder.createDeallocStack (callLoc, allocInst);
20262005 });
20272006
20282007 if (oldResult && !oldResult->use_empty ()) {
0 commit comments