1010//
1111//===----------------------------------------------------------------------===//
1212
13- import SIL
14- import OptimizerBridging
13+ import SILBridging
1514
1615/// Updates the reborrow flags and the borrowed-from instructions for all guaranteed phis in `function`.
17- func updateGuaranteedPhis( in function: Function , _ context: some MutatingContext ) {
16+ public func updateGuaranteedPhis( in function: Function , _ context: some MutatingContext ) {
1817 updateReborrowFlags ( in: function, context)
1918 updateBorrowedFrom ( in: function, context)
2019}
2120
2221/// Updates the reborrow flags and the borrowed-from instructions for all `phis`.
23- func updateGuaranteedPhis( phis: some Sequence < Phi > , _ context: some MutatingContext ) {
22+ public func updateGuaranteedPhis( phis: some Sequence < Phi > , _ context: some MutatingContext ) {
2423 updateReborrowFlags ( for: phis, context)
2524 updateBorrowedFrom ( for: phis, context)
2625}
2726
2827/// Update all borrowed-from instructions in the `function`
29- func updateBorrowedFrom( in function: Function , _ context: some MutatingContext ) {
28+ public func updateBorrowedFrom( in function: Function , _ context: some MutatingContext ) {
3029 if !function. hasOwnership {
3130 return
3231 }
@@ -44,7 +43,7 @@ func updateBorrowedFrom(in function: Function, _ context: some MutatingContext)
4443}
4544
4645/// Update borrowed-from instructions for a set of phi arguments.
47- func updateBorrowedFrom( for phis: some Sequence < Phi > , _ context: some MutatingContext ) {
46+ public func updateBorrowedFrom( for phis: some Sequence < Phi > , _ context: some MutatingContext ) {
4847 for phi in phis {
4948 if !phi. value. parentFunction. hasOwnership {
5049 return
@@ -67,7 +66,7 @@ func updateBorrowedFrom(for phis: some Sequence<Phi>, _ context: some MutatingCo
6766}
6867
6968/// Updates the reborrow flags for all guaranteed phis in `function`.
70- func updateReborrowFlags( in function: Function , _ context: some MutatingContext ) {
69+ public func updateReborrowFlags( in function: Function , _ context: some MutatingContext ) {
7170 if !function. hasOwnership {
7271 return
7372 }
@@ -90,7 +89,7 @@ func updateReborrowFlags(in function: Function, _ context: some MutatingContext)
9089/// by cutting off the control flow before an `end_borrow`, the re-borrow flags still have to remain
9190/// without the possibility to re-calculate them from the (now missing) `end_borrow`.
9291///
93- func updateReborrowFlags( for phis: some Sequence < Phi > , _ context: some MutatingContext ) {
92+ public func updateReborrowFlags( for phis: some Sequence < Phi > , _ context: some MutatingContext ) {
9493 if let phi = phis. first ( where: { phi in true } ) , !phi. value. parentFunction. hasOwnership {
9594 return
9695 }
@@ -160,7 +159,7 @@ private func createEmptyBorrowedFrom(for phi: Phi, _ context: some MutatingConte
160159/// use(%1)
161160/// ```
162161///
163- func replacePhiWithIncomingValue( phi: Phi , _ context: some MutatingContext ) -> Bool {
162+ public func replacePhiWithIncomingValue( phi: Phi , _ context: some MutatingContext ) -> Bool {
164163 if phi. predecessors. isEmpty {
165164 return false
166165 }
@@ -207,7 +206,7 @@ func replacePhiWithIncomingValue(phi: Phi, _ context: some MutatingContext) -> B
207206///
208207/// It's not needed to run this utility if SSAUpdater is used to create a _new_ OSSA liverange.
209208///
210- func replacePhisWithIncomingValues( phis: [ Phi ] , _ context: some MutatingContext ) {
209+ public func replacePhisWithIncomingValues( phis: [ Phi ] , _ context: some MutatingContext ) {
211210 var currentPhis = phis
212211 // Do this in a loop because replacing one phi might open up the opportunity for another phi
213212 // and the order of phis in the array can be arbitrary.
@@ -229,13 +228,13 @@ func registerPhiUpdater() {
229228 BridgedUtilities . registerPhiUpdater (
230229 // updateAllGuaranteedPhis
231230 { ( bridgedCtxt: BridgedContext , bridgedFunction: BridgedFunction ) in
232- let context = FunctionPassContext ( _bridged: bridgedCtxt)
231+ let context = PhiUpdaterContext ( _bridged: bridgedCtxt)
233232 let function = bridgedFunction. function;
234233 updateGuaranteedPhis ( in: function, context)
235234 } ,
236235 // updateGuaranteedPhis
237236 { ( bridgedCtxt: BridgedContext , bridgedPhiArray: BridgedArrayRef ) in
238- let context = FunctionPassContext ( _bridged: bridgedCtxt)
237+ let context = PhiUpdaterContext ( _bridged: bridgedCtxt)
239238 var guaranteedPhis = Stack < Phi > ( context)
240239 defer { guaranteedPhis. deinitialize ( ) }
241240 bridgedPhiArray. withElements ( ofType: BridgedValue . self) {
@@ -250,21 +249,17 @@ func registerPhiUpdater() {
250249 } ,
251250 // replacePhisWithIncomingValues
252251 { ( bridgedCtxt: BridgedContext , bridgedPhiArray: BridgedArrayRef ) in
253- let context = FunctionPassContext ( _bridged: bridgedCtxt)
252+ let context = PhiUpdaterContext ( _bridged: bridgedCtxt)
254253 var phis = [ Phi] ( )
255254 bridgedPhiArray. withElements ( ofType: BridgedValue . self) {
256255 phis = $0. map { Phi ( $0. value) ! }
257256 }
258257 replacePhisWithIncomingValues ( phis: phis, context)
259258 }
260259 )
261- }
262-
263- /// This pass is only used for testing.
264- /// In the regular pipeline it's not needed because optimization passes must make sure that borrowed-from
265- /// instructions are updated once the pass finishes.
266- let updateBorrowedFromPass = FunctionPass ( name: " update-borrowed-from " ) {
267- ( function: Function , context: FunctionPassContext ) in
268260
269- updateBorrowedFrom ( in: function, context)
261+ struct PhiUpdaterContext : MutatingContext {
262+ let _bridged : BridgedContext
263+ public let notifyInstructionChanged : ( Instruction ) -> ( ) = { inst in }
264+ }
270265}
0 commit comments