ClosureLifetimeFixup: Remove copy of borrowed move-only nonescaping captures when possible.

SILGen introduces a copy of the capture, because the semantics of escaping partial_apply's
requires the closure to take ownership of the parameters. We don't know when a closure is
strictly nonescaping or its final lifetime until ClosureLifetimeFixup runs, but that replaces
the consume of the copy with a borrow of the copy normally, hoping later passes fix it up.
We can't wait that long for move-only types, which can't be copied, so try to remove the
copy up front when the copy lives long enough and has no interfering uses other than the
partial_apply. rdar://110137169
This commit is contained in:
Joe Groff
2023-06-14 15:39:30 -07:00
parent 056ac839fd
commit ed2cbca04f
6 changed files with 285 additions and 5 deletions

View File

@@ -289,7 +289,9 @@ void insertDestroyOfCapturedArguments(
SILLocation loc = RegularLocation::getAutoGeneratedLocation());
void insertDeallocOfCapturedArguments(PartialApplyInst *pai,
DominanceInfo *domInfo);
DominanceInfo *domInfo,
llvm::function_ref<bool(SILValue)> shouldInsertDestroy =
[](SILValue arg) -> bool { return true; });
/// This iterator 'looks through' one level of builtin expect users exposing all
/// users of the looked through builtin expect instruction i.e it presents a