Skip to content

[OSSA] Migrate AccessedStorage #35520

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 5 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9048,6 +9048,15 @@ SILValue ApplyInstBase<Impl, Base, false>::getCalleeOrigin() const {
Callee = CETN->getOperand();
continue;
}
// convert_escape_to_noescape's are within a borrow scope.
if (auto *beginBorrow = dyn_cast<BeginBorrowInst>(Callee)) {
Callee = beginBorrow->getOperand();
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

do we also need to handle copy_value here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we should handle copy_value. I added another commit to this PR.

if (auto *copy = dyn_cast<CopyValueInst>(Callee)) {
Callee = copy->getOperand();
continue;
}
return Callee;
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/SIL/Utils/MemAccessUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,9 @@ bool AccessPathDefUseTraversal::visitUser(DFSEntry dfs) {
return true;
}
}
if (isa<EndBorrowInst>(use->getUser())) {
return true;
}
// We weren't able to "see through" any more address conversions; so
// record this as a use.

Expand Down
25 changes: 25 additions & 0 deletions test/SILOptimizer/accessed_storage_analysis.sil
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,31 @@ bb0(%0 : $Int):
return %v : $()
}

// CHECK-LABEL: @testCopiedNoEscape
// CHECK: [read] Stack %3 = alloc_stack $Int
sil [ossa] @testCopiedNoEscape : $@convention(thin) (Int) -> () {
bb0(%0 : $Int):
%s1 = alloc_stack $Int
store %0 to [trivial] %s1 : $*Int
%s2 = alloc_stack $Int
store %0 to [trivial] %s2 : $*Int
%f = function_ref @testDirectlyAppliedClosure : $@convention(thin) (@inout Int, @inout_aliasable Int) -> ()
%pa = partial_apply [callee_guaranteed] %f(%s2) : $@convention(thin) (@inout Int, @inout_aliasable Int) -> ()
%copy = copy_value %pa : $@callee_guaranteed (@inout Int) -> ()
%borrow = begin_borrow %copy : $@callee_guaranteed (@inout Int) -> ()
%npa = convert_escape_to_noescape %borrow : $@callee_guaranteed (@inout Int) -> () to $@noescape @callee_guaranteed (@inout Int) -> ()
%access = begin_access [modify] [dynamic] %s1 : $*Int
%call = apply %npa(%access) : $@noescape @callee_guaranteed (@inout Int) -> ()
end_access %access : $*Int
end_borrow %borrow : $@callee_guaranteed (@inout Int) -> ()
destroy_value %copy : $@callee_guaranteed (@inout Int) -> ()
destroy_value %pa : $@callee_guaranteed (@inout Int) -> ()
dealloc_stack %s2 : $*Int
dealloc_stack %s1 : $*Int
%v = tuple ()
return %v : $()
}

// CHECK: @testDirectlyAppliedClosure
// CHECK: [read] Argument %1 = argument of bb0 : $*Int
sil private @testDirectlyAppliedClosure : $@convention(thin) (@inout Int, @inout_aliasable Int) -> () {
Expand Down
Loading