@@ -18,107 +18,96 @@ public typealias BridgedFunctionPassCtxt =
1818public typealias BridgedInstructionPassCtxt =
1919 OptimizerBridging . BridgedInstructionPassCtxt
2020
21- struct FunctionPassContext {
21+ struct PassContext {
2222
2323 fileprivate let passContext : BridgedPassContext
24- fileprivate let function : Function
2524
26- func erase ( instruction : Instruction ) {
27- PassContext_eraseInstruction ( passContext, instruction . bridged )
25+ var isSwift51RuntimeAvailable : Bool {
26+ PassContext_isSwift51RuntimeAvailable ( passContext) != 0
2827 }
2928
30- private func notifyChanges( _ kind: ChangeNotificationKind ) {
31- PassContext_notifyChanges ( passContext, kind)
32- }
33-
3429 var aliasAnalysis : AliasAnalysis {
35- let bridgedAA = PassContext_getAliasAnalysis ( passContext, function . bridged )
30+ let bridgedAA = PassContext_getAliasAnalysis ( passContext)
3631 return AliasAnalysis ( bridged: bridgedAA)
3732 }
3833
3934 var calleeAnalysis : CalleeAnalysis {
4035 let bridgeCA = PassContext_getCalleeAnalysis ( passContext)
4136 return CalleeAnalysis ( bridged: bridgeCA)
4237 }
38+
39+ func erase( instruction: Instruction ) {
40+ if instruction is FullApplySite {
41+ PassContext_notifyChanges ( passContext, callsChanged)
42+ }
43+ if instruction is TermInst {
44+ PassContext_notifyChanges ( passContext, branchesChanged)
45+ }
46+ PassContext_notifyChanges ( passContext, instructionsChanged)
47+
48+ PassContext_eraseInstruction ( passContext, instruction. bridged)
49+ }
50+
51+ func setOperand( of instruction: Instruction , at index : Int , to value: Value ) {
52+ if instruction is FullApplySite && index == ApplyOperands . calleeOperandIndex {
53+ PassContext_notifyChanges ( passContext, callsChanged)
54+ }
55+ PassContext_notifyChanges ( passContext, instructionsChanged)
56+
57+ SILInstruction_setOperand ( instruction. bridged, index, value. bridged)
58+ }
4359}
4460
4561struct FunctionPass {
4662
4763 let name : String
48- let runFunction : ( Function , FunctionPassContext ) -> ( )
64+ let runFunction : ( Function , PassContext ) -> ( )
4965
5066 public init ( name: String ,
51- _ runFunction: @escaping ( Function , FunctionPassContext ) -> ( ) ) {
67+ _ runFunction: @escaping ( Function , PassContext ) -> ( ) ) {
5268 self . name = name
5369 self . runFunction = runFunction
5470 }
5571
5672 func run( _ bridgedCtxt: BridgedFunctionPassCtxt ) {
5773 let function = bridgedCtxt. function. function
58- let context = FunctionPassContext ( passContext: bridgedCtxt. passContext,
59- function: function)
74+ let context = PassContext ( passContext: bridgedCtxt. passContext)
6075 runFunction ( function, context)
6176 }
6277}
6378
64- struct InstructionPassContext {
65- fileprivate let passContext : BridgedPassContext
66-
67- func erase( instruction: Instruction ) {
68- PassContext_eraseInstruction ( passContext, instruction. bridged)
69- }
70-
71- private func notifyChanges( _ kind: ChangeNotificationKind ) {
72- PassContext_notifyChanges ( passContext, kind)
73- }
74- }
75-
7679struct InstructionPass < InstType: Instruction > {
7780
7881 let name : String
79- let runFunction : ( InstType , InstructionPassContext ) -> ( )
82+ let runFunction : ( InstType , PassContext ) -> ( )
8083
81- public init ( name: String , _ runFunction: @escaping ( InstType , InstructionPassContext ) -> ( ) ) {
84+ public init ( name: String ,
85+ _ runFunction: @escaping ( InstType , PassContext ) -> ( ) ) {
8286 self . name = name
8387 self . runFunction = runFunction
8488 }
8589
8690 func run( _ bridgedCtxt: BridgedInstructionPassCtxt ) {
8791 let inst = bridgedCtxt. instruction. getAs ( InstType . self)
88- let context = InstructionPassContext ( passContext: bridgedCtxt. passContext)
92+ let context = PassContext ( passContext: bridgedCtxt. passContext)
8993 runFunction ( inst, context)
9094 }
9195}
9296
9397extension StackList {
94- init ( _ context: FunctionPassContext ) {
95- self . init ( context: context. passContext)
96- }
97-
98- init ( _ context: InstructionPassContext ) {
98+ init ( _ context: PassContext ) {
9999 self . init ( context: context. passContext)
100100 }
101101}
102102
103103extension Builder {
104104 init ( at insPnt: Instruction , location: Location ,
105- _ context: FunctionPassContext ) {
106- self . init ( insertionPoint: insPnt, location: location,
107- passContext: context. passContext)
108- }
109-
110- init ( at insPnt: Instruction , _ context: FunctionPassContext ) {
111- self . init ( insertionPoint: insPnt, location: insPnt. location,
112- passContext: context. passContext)
113- }
114-
115- init ( at insPnt: Instruction , location: Location ,
116- _ context: InstructionPassContext ) {
105+ _ context: PassContext ) {
117106 self . init ( insertionPoint: insPnt, location: location,
118107 passContext: context. passContext)
119108 }
120109
121- init ( at insPnt: Instruction , _ context: InstructionPassContext ) {
110+ init ( at insPnt: Instruction , _ context: PassContext ) {
122111 self . init ( insertionPoint: insPnt, location: insPnt. location,
123112 passContext: context. passContext)
124113 }
0 commit comments