Skip to content

Commit 84c1737

Browse files
committed
Add insertDestroyOfCapturedArguments to Local.h
1 parent df1eb70 commit 84c1737

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ void releasePartialApplyCapturedArg(
212212
SILBuilder &Builder, SILLocation Loc, SILValue Arg, SILParameterInfo PInfo,
213213
InstModCallbacks Callbacks = InstModCallbacks());
214214

215+
/// Insert destroys of captured arguments of partial_apply [stack].
216+
void insertDestroyOfCapturedArguments(
217+
PartialApplyInst *PAI, SILBuilder &B,
218+
llvm::function_ref<bool(SILValue)> shouldInsertDestroy =
219+
[](SILValue arg) -> bool { return true; });
220+
215221
/// This computes the lifetime of a single SILValue.
216222
///
217223
/// This does not compute a set of jointly postdominating use points. Instead it

lib/SILOptimizer/Utils/Local.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,3 +1793,22 @@ swift::findLocalApplySites(FunctionRefBaseInst *FRI) {
17931793
return None;
17941794
return f;
17951795
}
1796+
1797+
/// Insert destroys of captured arguments of partial_apply [stack].
1798+
void swift::insertDestroyOfCapturedArguments(
1799+
PartialApplyInst *PAI, SILBuilder &B,
1800+
llvm::function_ref<bool(SILValue)> shouldInsertDestroy) {
1801+
assert(PAI->isOnStack());
1802+
1803+
ApplySite site(PAI);
1804+
SILFunctionConventions calleeConv(site.getSubstCalleeType(),
1805+
PAI->getModule());
1806+
auto loc = RegularLocation::getAutoGeneratedLocation();
1807+
for (auto &arg : PAI->getArgumentOperands()) {
1808+
if (!shouldInsertDestroy(arg.get())) continue;
1809+
unsigned calleeArgumentIndex = site.getCalleeArgIndex(arg);
1810+
assert(calleeArgumentIndex >= calleeConv.getSILArgIndexOfFirstParam());
1811+
auto paramInfo = calleeConv.getParamInfoForSILArg(calleeArgumentIndex);
1812+
releasePartialApplyCapturedArg(B, loc, arg.get(), paramInfo);
1813+
}
1814+
}

0 commit comments

Comments
 (0)