@@ -49,8 +49,13 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
49
49
}
50
50
}
51
51
52
+ fileprivate struct PathFunctionTuple : Hashable {
53
+ var path : SmallProjectionPath
54
+ var function : Function
55
+ }
56
+
52
57
private func optimize( function: Function , _ context: FunctionPassContext ) {
53
- var alreadyInlinedFunctions : [ SmallProjectionPath : Set < Function > ] = [ : ]
58
+ var alreadyInlinedFunctions : Set < PathFunctionTuple > = Set ( )
54
59
55
60
var changed = true
56
61
while changed {
@@ -79,7 +84,7 @@ private func optimize(function: Function, _ context: FunctionPassContext) {
79
84
}
80
85
}
81
86
82
- private func inlineAndDevirtualize( apply: FullApplySite , alreadyInlinedFunctions: inout [ SmallProjectionPath : Set < Function > ] ,
87
+ private func inlineAndDevirtualize( apply: FullApplySite , alreadyInlinedFunctions: inout Set < PathFunctionTuple > ,
83
88
_ context: FunctionPassContext , _ simplifyCtxt: SimplifyContext ) {
84
89
if simplifyCtxt. tryDevirtualize ( apply: apply, isMandatory: true ) != nil {
85
90
return
@@ -116,7 +121,7 @@ private func removeUnusedMetatypeInstructions(in function: Function, _ context:
116
121
}
117
122
}
118
123
119
- private func shouldInline( apply: FullApplySite , callee: Function , alreadyInlinedFunctions: inout [ SmallProjectionPath : Set < Function > ] ) -> Bool {
124
+ private func shouldInline( apply: FullApplySite , callee: Function , alreadyInlinedFunctions: inout Set < PathFunctionTuple > ) -> Bool {
120
125
if callee. isTransparent {
121
126
return true
122
127
}
@@ -134,8 +139,7 @@ private func shouldInline(apply: FullApplySite, callee: Function, alreadyInlined
134
139
global. mustBeInitializedStatically,
135
140
let applyInst = apply as? ApplyInst ,
136
141
let projectionPath = applyInst. isStored ( to: global) ,
137
- !alreadyInlinedFunctions[ projectionPath, default: Set ( ) ] . contains ( callee) {
138
- alreadyInlinedFunctions [ projectionPath, default: Set ( ) ] . insert ( callee)
142
+ alreadyInlinedFunctions. insert ( PathFunctionTuple ( path: projectionPath, function: callee) ) . inserted {
139
143
return true
140
144
}
141
145
return false
@@ -174,7 +178,7 @@ private extension Value {
174
178
var singleUseValue : any Value = self
175
179
var path = SmallProjectionPath ( )
176
180
while true {
177
- guard let use = singleUseValue. uses. singleUse else {
181
+ guard let use = singleUseValue. uses. singleNonDebugUse else {
178
182
return nil
179
183
}
180
184
@@ -185,8 +189,8 @@ private extension Value {
185
189
case is TupleInst :
186
190
path = path. push ( . tupleField, index: use. index)
187
191
break
188
- case is EnumInst :
189
- path = path. push ( . enumCase, index: use . index )
192
+ case let ei as EnumInst :
193
+ path = path. push ( . enumCase, index: ei . caseIndex )
190
194
break
191
195
case let si as StoreInst :
192
196
guard let storeDestination = si. destination as? GlobalAddrInst else {
@@ -199,7 +203,7 @@ private extension Value {
199
203
200
204
return path
201
205
default :
202
- break
206
+ return nil
203
207
}
204
208
205
209
guard let nextInstruction = use. instruction as? SingleValueInstruction else {
0 commit comments