Skip to content

Commit

Permalink
Merge pull request #35520 from atrick/ossa-accessedstorage
Browse files Browse the repository at this point in the history
[OSSA] Migrate AccessedStorage
  • Loading branch information
atrick authored Jan 21, 2021
2 parents e67317a + 2647e08 commit 0bd17e4
Show file tree
Hide file tree
Showing 7 changed files with 2,159 additions and 620 deletions.
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;
}
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

0 comments on commit 0bd17e4

Please sign in to comment.