@@ -176,30 +176,6 @@ static SILFunctionConventions getLoweredCallConv(ApplySite call) {
176
176
SILModuleConventions::getLoweredAddressConventions (call.getModule ()));
177
177
}
178
178
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
-
203
179
// ===----------------------------------------------------------------------===//
204
180
// Multi-Result
205
181
//
@@ -482,6 +458,12 @@ struct AddressLoweringState {
482
458
builder.setCurrentDebugScope (originalInst->getDebugScope ());
483
459
return builder;
484
460
}
461
+
462
+ void prepareBuilder (SILBuilder &builder) {
463
+ builder.setSILConventions (
464
+ SILModuleConventions::getLoweredAddressConventions (
465
+ builder.getModule ()));
466
+ };
485
467
};
486
468
} // end anonymous namespace
487
469
@@ -1733,22 +1715,20 @@ void CallArgRewriter::rewriteIndirectArgument(Operand *operand) {
1733
1715
if (apply.getArgumentConvention (*operand).isOwnedConvention ()) {
1734
1716
argBuilder.createTrivialStoreOr (apply.getLoc (), argValue, allocInst,
1735
1717
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);
1739
1720
});
1740
1721
} else {
1741
1722
auto borrow = argBuilder.emitBeginBorrowOperation (callLoc, argValue);
1742
1723
auto *storeInst =
1743
1724
argBuilder.emitStoreBorrowOperation (callLoc, borrow, allocInst);
1744
1725
1745
- cleanupAfterCall (apply, [&](SILBasicBlock::iterator insertPt) {
1746
- auto cleanupBuilder = pass.getBuilder (insertPt);
1726
+ apply.insertAfterFullEvaluation ([&](SILBuilder &callBuilder) {
1747
1727
if (auto *storeBorrow = dyn_cast<StoreBorrowInst>(storeInst)) {
1748
- cleanupBuilder .emitEndBorrowOperation (callLoc, storeBorrow);
1728
+ callBuilder .emitEndBorrowOperation (callLoc, storeBorrow);
1749
1729
}
1750
- cleanupBuilder .emitEndBorrowOperation (callLoc, borrow);
1751
- cleanupBuilder .createDeallocStack (callLoc, allocInst);
1730
+ callBuilder .emitEndBorrowOperation (callLoc, borrow);
1731
+ callBuilder .createDeallocStack (callLoc, allocInst);
1752
1732
});
1753
1733
}
1754
1734
}
@@ -2020,9 +2000,8 @@ SILValue ApplyRewriter::materializeIndirectResultAddress(SILValue oldResult,
2020
2000
2021
2001
// Instead of using resultBuilder, insert dealloc immediately after the call
2022
2002
// 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);
2026
2005
});
2027
2006
2028
2007
if (oldResult && !oldResult->use_empty ()) {
0 commit comments