Skip to content

Tweak findTransitiveUsesForAddress implementation #63483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/SIL/Utils/OwnershipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ bool swift::canOpcodeForwardOwnedValues(Operand *use) {
// Find all use points of \p guaranteedValue within its borrow scope. All uses
// are naturally dominated by \p guaranteedValue. If a PointerEscape is found,
// then no assumption can be made about \p guaranteedValue's lifetime. Therefore
// the use points are incomplete and this returns false.
// the use points are incomplete and this returns false. The escape point that
// was found must still be in \p usePoints to distinguish from dead addresses.
//
// Accumulate results in \p usePoints, ignoring existing elements.
//
Expand Down Expand Up @@ -982,6 +983,8 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,

AddressUseKind result = AddressUseKind::NonEscaping;

// Record all uses that aren't transitively followed. These are either
// instanteneous uses of the addres, or cause a pointer escape.
auto leafUse = [foundUses](Operand *use) {
if (foundUses)
foundUses->push_back(use);
Expand Down Expand Up @@ -1011,6 +1014,7 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,
// the apply to be a use point.
if (isa<PartialApplyInst>(user) || isa<AddressToPointerInst>(user)) {
result = meet(result, AddressUseKind::PointerEscape);
leafUse(op);
continue;
}
// First, eliminate "end point uses" that we just need to check liveness at
Expand All @@ -1035,6 +1039,7 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,
if (isa<UnconditionalCheckedCastAddrInst>(user)
|| isa<MarkFunctionEscapeInst>(user)) {
assert(!user->hasResults());
leafUse(op);
continue;
}

Expand Down Expand Up @@ -1108,6 +1113,7 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,
(*onError)(op);
}
result = meet(result, AddressUseKind::Unknown);
leafUse(op);
}
return result;
}
Expand Down