10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- import SIL
14
- import OptimizerBridging
13
+ import SILBridging
15
14
16
15
/// 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 ) {
18
17
updateReborrowFlags ( in: function, context)
19
18
updateBorrowedFrom ( in: function, context)
20
19
}
21
20
22
21
/// 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 ) {
24
23
updateReborrowFlags ( for: phis, context)
25
24
updateBorrowedFrom ( for: phis, context)
26
25
}
27
26
28
27
/// 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 ) {
30
29
if !function. hasOwnership {
31
30
return
32
31
}
@@ -44,7 +43,7 @@ func updateBorrowedFrom(in function: Function, _ context: some MutatingContext)
44
43
}
45
44
46
45
/// 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 ) {
48
47
for phi in phis {
49
48
if !phi. value. parentFunction. hasOwnership {
50
49
return
@@ -67,7 +66,7 @@ func updateBorrowedFrom(for phis: some Sequence<Phi>, _ context: some MutatingCo
67
66
}
68
67
69
68
/// 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 ) {
71
70
if !function. hasOwnership {
72
71
return
73
72
}
@@ -90,7 +89,7 @@ func updateReborrowFlags(in function: Function, _ context: some MutatingContext)
90
89
/// by cutting off the control flow before an `end_borrow`, the re-borrow flags still have to remain
91
90
/// without the possibility to re-calculate them from the (now missing) `end_borrow`.
92
91
///
93
- func updateReborrowFlags( for phis: some Sequence < Phi > , _ context: some MutatingContext ) {
92
+ public func updateReborrowFlags( for phis: some Sequence < Phi > , _ context: some MutatingContext ) {
94
93
if let phi = phis. first ( where: { phi in true } ) , !phi. value. parentFunction. hasOwnership {
95
94
return
96
95
}
@@ -160,7 +159,7 @@ private func createEmptyBorrowedFrom(for phi: Phi, _ context: some MutatingConte
160
159
/// use(%1)
161
160
/// ```
162
161
///
163
- func replacePhiWithIncomingValue( phi: Phi , _ context: some MutatingContext ) -> Bool {
162
+ public func replacePhiWithIncomingValue( phi: Phi , _ context: some MutatingContext ) -> Bool {
164
163
if phi. predecessors. isEmpty {
165
164
return false
166
165
}
@@ -207,7 +206,7 @@ func replacePhiWithIncomingValue(phi: Phi, _ context: some MutatingContext) -> B
207
206
///
208
207
/// It's not needed to run this utility if SSAUpdater is used to create a _new_ OSSA liverange.
209
208
///
210
- func replacePhisWithIncomingValues( phis: [ Phi ] , _ context: some MutatingContext ) {
209
+ public func replacePhisWithIncomingValues( phis: [ Phi ] , _ context: some MutatingContext ) {
211
210
var currentPhis = phis
212
211
// Do this in a loop because replacing one phi might open up the opportunity for another phi
213
212
// and the order of phis in the array can be arbitrary.
@@ -229,13 +228,13 @@ func registerPhiUpdater() {
229
228
BridgedUtilities . registerPhiUpdater (
230
229
// updateAllGuaranteedPhis
231
230
{ ( bridgedCtxt: BridgedContext , bridgedFunction: BridgedFunction ) in
232
- let context = FunctionPassContext ( _bridged: bridgedCtxt)
231
+ let context = PhiUpdaterContext ( _bridged: bridgedCtxt)
233
232
let function = bridgedFunction. function;
234
233
updateGuaranteedPhis ( in: function, context)
235
234
} ,
236
235
// updateGuaranteedPhis
237
236
{ ( bridgedCtxt: BridgedContext , bridgedPhiArray: BridgedArrayRef ) in
238
- let context = FunctionPassContext ( _bridged: bridgedCtxt)
237
+ let context = PhiUpdaterContext ( _bridged: bridgedCtxt)
239
238
var guaranteedPhis = Stack < Phi > ( context)
240
239
defer { guaranteedPhis. deinitialize ( ) }
241
240
bridgedPhiArray. withElements ( ofType: BridgedValue . self) {
@@ -250,21 +249,17 @@ func registerPhiUpdater() {
250
249
} ,
251
250
// replacePhisWithIncomingValues
252
251
{ ( bridgedCtxt: BridgedContext , bridgedPhiArray: BridgedArrayRef ) in
253
- let context = FunctionPassContext ( _bridged: bridgedCtxt)
252
+ let context = PhiUpdaterContext ( _bridged: bridgedCtxt)
254
253
var phis = [ Phi] ( )
255
254
bridgedPhiArray. withElements ( ofType: BridgedValue . self) {
256
255
phis = $0. map { Phi ( $0. value) ! }
257
256
}
258
257
replacePhisWithIncomingValues ( phis: phis, context)
259
258
}
260
259
)
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
268
260
269
- updateBorrowedFrom ( in: function, context)
261
+ struct PhiUpdaterContext : MutatingContext {
262
+ let _bridged : BridgedContext
263
+ public let notifyInstructionChanged : ( Instruction ) -> ( ) = { inst in }
264
+ }
270
265
}
0 commit comments