Skip to content

Commit 0bd17e4

Browse files
authored
Merge pull request #35520 from atrick/ossa-accessedstorage
[OSSA] Migrate AccessedStorage
2 parents e67317a + 2647e08 commit 0bd17e4

File tree

7 files changed

+2159
-620
lines changed

7 files changed

+2159
-620
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9048,6 +9048,15 @@ SILValue ApplyInstBase<Impl, Base, false>::getCalleeOrigin() const {
90489048
Callee = CETN->getOperand();
90499049
continue;
90509050
}
9051+
// convert_escape_to_noescape's are within a borrow scope.
9052+
if (auto *beginBorrow = dyn_cast<BeginBorrowInst>(Callee)) {
9053+
Callee = beginBorrow->getOperand();
9054+
continue;
9055+
}
9056+
if (auto *copy = dyn_cast<CopyValueInst>(Callee)) {
9057+
Callee = copy->getOperand();
9058+
continue;
9059+
}
90519060
return Callee;
90529061
}
90539062
}

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,9 @@ bool AccessPathDefUseTraversal::visitUser(DFSEntry dfs) {
14401440
return true;
14411441
}
14421442
}
1443+
if (isa<EndBorrowInst>(use->getUser())) {
1444+
return true;
1445+
}
14431446
// We weren't able to "see through" any more address conversions; so
14441447
// record this as a use.
14451448

test/SILOptimizer/accessed_storage_analysis.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,31 @@ bb0(%0 : $Int):
527527
return %v : $()
528528
}
529529

530+
// CHECK-LABEL: @testCopiedNoEscape
531+
// CHECK: [read] Stack %3 = alloc_stack $Int
532+
sil [ossa] @testCopiedNoEscape : $@convention(thin) (Int) -> () {
533+
bb0(%0 : $Int):
534+
%s1 = alloc_stack $Int
535+
store %0 to [trivial] %s1 : $*Int
536+
%s2 = alloc_stack $Int
537+
store %0 to [trivial] %s2 : $*Int
538+
%f = function_ref @testDirectlyAppliedClosure : $@convention(thin) (@inout Int, @inout_aliasable Int) -> ()
539+
%pa = partial_apply [callee_guaranteed] %f(%s2) : $@convention(thin) (@inout Int, @inout_aliasable Int) -> ()
540+
%copy = copy_value %pa : $@callee_guaranteed (@inout Int) -> ()
541+
%borrow = begin_borrow %copy : $@callee_guaranteed (@inout Int) -> ()
542+
%npa = convert_escape_to_noescape %borrow : $@callee_guaranteed (@inout Int) -> () to $@noescape @callee_guaranteed (@inout Int) -> ()
543+
%access = begin_access [modify] [dynamic] %s1 : $*Int
544+
%call = apply %npa(%access) : $@noescape @callee_guaranteed (@inout Int) -> ()
545+
end_access %access : $*Int
546+
end_borrow %borrow : $@callee_guaranteed (@inout Int) -> ()
547+
destroy_value %copy : $@callee_guaranteed (@inout Int) -> ()
548+
destroy_value %pa : $@callee_guaranteed (@inout Int) -> ()
549+
dealloc_stack %s2 : $*Int
550+
dealloc_stack %s1 : $*Int
551+
%v = tuple ()
552+
return %v : $()
553+
}
554+
530555
// CHECK: @testDirectlyAppliedClosure
531556
// CHECK: [read] Argument %1 = argument of bb0 : $*Int
532557
sil private @testDirectlyAppliedClosure : $@convention(thin) (@inout Int, @inout_aliasable Int) -> () {

0 commit comments

Comments
 (0)