File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
lib/SILOptimizer/SemanticARC Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 2121#include " swift/SILOptimizer/Analysis/Analysis.h"
2222#include " swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
2323#include " swift/SILOptimizer/PassManager/Transforms.h"
24+ #include " swift/SILOptimizer/Utils/OwnershipOptUtils.h"
2425
2526#include " llvm/Support/CommandLine.h"
2627
@@ -176,15 +177,18 @@ struct SemanticARCOpts : SILFunctionTransform {
176177 // converted to guaranteed, ignoring the phi, try convert those phis to be
177178 // guaranteed.
178179 if (tryConvertOwnedPhisToGuaranteedPhis (visitor.ctx )) {
180+ updateBorrowedFrom (getPassManager (), &f);
179181 // We return here early to save a little compile time so we do not
180182 // invalidate analyses redundantly.
181183 return invalidateAnalysis (
182184 SILAnalysis::InvalidationKind::BranchesAndInstructions);
183185 }
184186
185187 // Otherwise, we only deleted instructions and did not touch phis.
186- if (didEliminateARCInsts)
188+ if (didEliminateARCInsts) {
189+ updateBorrowedFrom (getPassManager (), &f);
187190 invalidateAnalysis (SILAnalysis::InvalidationKind::Instructions);
191+ }
188192 }
189193};
190194
Original file line number Diff line number Diff line change 11// RUN: %target-sil-opt -update-borrowed-from -semantic-arc-opts %s | %FileCheck %s
22
3+ sil_stage canonical
4+
5+ import Builtin
6+ import Swift
7+ import SwiftShims
8+
39class Klass {}
410
511// CHECK-LABEL: sil [ossa] @test_owned_to_guaranteed1 :
@@ -106,3 +112,27 @@ bbret:
106112 %t = tuple ()
107113 return %t : $()
108114}
115+
116+ // CHECK-LABEL: sil [ossa] @test_borrowed_from_updating :
117+ // CHECK-NOT: copy-var
118+ // CHECK: bb2({{.*}} : @guaranteed $Klass):
119+ // CHECK: = borrowed {{.*}}%0 : $Optional<Klass>
120+ // CHECK-LABEL: } // end sil function 'test_borrowed_from_updating'
121+ sil [ossa] @test_borrowed_from_updating : $@convention(thin) (@guaranteed Optional<Klass>) -> () {
122+ bb0(%0 : @guaranteed $Optional<Klass>):
123+ %1 = copy_value %0 : $Optional<Klass>
124+ switch_enum %1 : $Optional<Klass>, case #Optional.none!enumelt: bb1, case #Optional.some!enumelt: bb2
125+ bb1:
126+ unreachable
127+
128+ bb2(%4 : @owned $Klass):
129+ %5 = begin_borrow %4 : $Klass
130+ br bb3(%5 : $Klass)
131+
132+ bb3(%7 : @reborrow @guaranteed $Klass):
133+ %8 = borrowed %7 : $Klass from (%4 : $Klass)
134+ end_borrow %8 : $Klass
135+ destroy_value %4 : $Klass
136+ %r = tuple ()
137+ return %r : $()
138+ }
You can’t perform that action at this time.
0 commit comments