@@ -174,29 +174,6 @@ const TOP_TUPLE = GlobalRef(Core, :tuple)
174
174
175
175
_topmod (sv:: OptimizationState ) = _topmod (sv. mod)
176
176
177
- function isinlineable (m:: Method , me:: OptimizationState , params:: OptimizationParams , union_penalties:: Bool , bonus:: Int = 0 )
178
- # compute the cost (size) of inlining this code
179
- inlineable = false
180
- cost_threshold = params. inline_cost_threshold
181
- if m. module === _topmod (m. module)
182
- # a few functions get special treatment
183
- name = m. name
184
- sig = m. sig
185
- if ((name === :+ || name === :* || name === :min || name === :max ) &&
186
- isa (sig,DataType) &&
187
- sig == Tuple{sig. parameters[1 ],Any,Any,Any,Vararg{Any}})
188
- inlineable = true
189
- elseif (name === :iterate || name === :unsafe_convert ||
190
- name === :cconvert )
191
- cost_threshold *= 4
192
- end
193
- end
194
- if ! inlineable
195
- inlineable = inline_worthy (me. ir:: IRCode , params, union_penalties, cost_threshold + bonus)
196
- end
197
- return inlineable
198
- end
199
-
200
177
is_stmt_inline (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_INLINE ≠ 0
201
178
is_stmt_noinline (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_NOINLINE ≠ 0
202
179
is_stmt_throw_block (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_THROW_BLOCK ≠ 0
@@ -296,19 +273,27 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState, params::Opt
296
273
if src. inlineable && isdispatchtuple (specTypes)
297
274
# obey @inline declaration if a dispatch barrier would not help
298
275
else
299
- bonus = 0
276
+ # compute the cost (size) of inlining this code
277
+ cost_threshold = default = params. inline_cost_threshold
300
278
if result ⊑ Tuple && ! isconcretetype (widenconst (result))
301
- bonus = params. inline_tupleret_bonus
279
+ cost_threshold + = params. inline_tupleret_bonus
302
280
end
281
+ # if the method is declared as `@inline`, increase the cost threshold 20x
303
282
if src. inlineable
304
- # For functions declared @inline, increase the cost threshold 20x
305
- bonus += params. inline_cost_threshold* 19
283
+ cost_threshold += 19 * default
284
+ end
285
+ # a few functions get special treatment
286
+ if def. module === _topmod (def. module)
287
+ name = def. name
288
+ if name === :iterate || name === :unsafe_convert || name === :cconvert
289
+ cost_threshold += 4 * default
290
+ end
306
291
end
307
- src. inlineable = isinlineable (def, opt, params, union_penalties, bonus )
292
+ src. inlineable = inline_worthy (ir, params, union_penalties, cost_threshold )
308
293
end
309
294
end
310
295
311
- nothing
296
+ return nothing
312
297
end
313
298
314
299
# run the optimization work
@@ -393,7 +378,9 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
393
378
cfg = compute_basic_blocks (code)
394
379
types = Any[]
395
380
stmts = InstructionStream (code, types, stmtinfo, codelocs, ssaflags)
396
- ir = IRCode (stmts, cfg, collect (LineInfoNode, ci. linetable:: Union{Vector{LineInfoNode},Vector{Any}} ), sv. slottypes, meta, sv. sptypes)
381
+ linetable = ci. linetable
382
+ isa (linetable, Vector{LineInfoNode}) || (linetable = collect (LineInfoNode, linetable:: Vector{Any} ))
383
+ ir = IRCode (stmts, cfg, linetable, sv. slottypes, meta, sv. sptypes)
397
384
return ir
398
385
end
399
386
0 commit comments