Skip to content

Refactor swift::findPointerEscape and handle additional cases #66723

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 4 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 0 additions & 10 deletions lib/SIL/Utils/AddressWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ AddressUseKind TransitiveAddressWalker::walk(SILValue projectedAddress) && {
// When we exit, set the result to be invalidated so we can't use this again.
SWIFT_DEFER { didInvalidate = true; };

// If the projectedAddress is dead, it is itself a leaf use. Since we don't
// have an operand for it, simply bail. Dead projectedAddress is unexpected.
//
// TODO: store_borrow is currently an InteriorPointer with no uses, so we end
// up bailing. It should be in a dependence scope instead. It's not clear why
// it produces an address at all.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the TODO comment now, but shouldn't we still report a dead projection as either a PointerEscape or Unknown? Otherwise, clients will need to separately look for and handle any possible dead projections. I don't think clients can currently handle that. Dead projections are unexpected but still legal SIL.

if (projectedAddress->use_empty()) {
return AddressUseKind::PointerEscape;
}

StackList<Operand *> worklist(projectedAddress->getFunction());
SmallPtrSet<Operand *, 32> visitedOperands;

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/copy_propagation_borrow.sil
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ bb0:
%copy1 = copy_value %borrow1 : $C
%borrow2 = begin_borrow %copy1 : $C
%addr = ref_element_addr %borrow2 : $C, #C.a
%ptr = address_to_pointer %addr : $*Int64 to $Builtin.RawPointer
cond_br undef, bb1, bb2
bb1:
// inside use
Expand Down Expand Up @@ -1201,4 +1202,3 @@ bb0(%0 : @guaranteed $C):
%7 = tuple ()
return %7 : $()
}

8 changes: 1 addition & 7 deletions test/SILOptimizer/liveness_unit.sil
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,13 @@ bb4(%phi : @owned $C):
return %99 : $()
}

// A dead (ref_element_addr) projection is treated like a pointer
// escape for convenience. Make sure the pointer escape bubbles up
// through the phi and casts.
//
// CHECK-LABEL: testSSADeadRefElementAddr: ssa-liveness
// CHECK: SSA lifetime analysis: %0 = argument of bb0 : $C
// CHECK-NEXT: Incomplete liveness: Escaping address
// CHECK-NEXT: bb0: LiveOut
// CHECK-NEXT: bb2: LiveOut
// CHECK-NEXT: bb3: LiveWithin
// CHECK-NEXT: bb1: LiveOut
// CHECK: last user:
// CHECK-SAME: ref_element_addr %6 : $D, #D.object
// CHECK: ref_element_addr %6 : $D, #D.object
// CHECK-NEXT-LABEL: end running test 1 of 1 on testSSADeadRefElementAddr: ssa-liveness
sil [ossa] @testSSADeadRefElementAddr : $@convention(thin) (@guaranteed C) -> () {
bb0(%0 : @guaranteed $C):
Expand Down