384
384
385
385
"""
386
386
finish(interp::AbstractInterpreter, opt::OptimizationState,
387
- params::OptimizationParams, ir::IRCode, result ) -> analyzed::Union{Nothing,ConstAPI}
387
+ params::OptimizationParams, ir::IRCode, caller::InferenceResult ) -> analyzed::Union{Nothing,ConstAPI}
388
388
389
389
Post process information derived by Julia-level optimizations for later uses:
390
390
- computes "purity", i.e. side-effect-freeness
@@ -394,16 +394,18 @@ In a case when the purity is proven, `finish` can return `ConstAPI` object wrapp
394
394
value so that the runtime system will use the constant calling convention for the method calls.
395
395
"""
396
396
function finish (interp:: AbstractInterpreter , opt:: OptimizationState ,
397
- params:: OptimizationParams , ir:: IRCode , @nospecialize (result) )
397
+ params:: OptimizationParams , ir:: IRCode , caller :: InferenceResult )
398
398
(; src, linfo) = opt
399
399
(; def, specTypes) = linfo
400
400
401
401
analyzed = nothing # `ConstAPI` if this call can use constant calling convention
402
402
force_noinline = _any (@nospecialize (x) -> isexpr (x, :meta ) && x. args[1 ] === :noinline , ir. meta)
403
403
404
404
# compute inlining and other related optimizations
405
- wresult = isa (result, InterConditional) ? widenconditional (result) : result
406
- if (isa (wresult, Const) || isconstType (wresult))
405
+ result = caller. result
406
+ @assert ! (result isa LimitedAccuracy)
407
+ result = isa (result, InterConditional) ? widenconditional (result) : result
408
+ if (isa (result, Const) || isconstType (result))
407
409
proven_pure = false
408
410
# must be proven pure to use constant calling convention;
409
411
# otherwise we might skip throwing errors (issue #20704)
@@ -437,14 +439,14 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
437
439
# Still set pure flag to make sure `inference` tests pass
438
440
# and to possibly enable more optimization in the future
439
441
src. pure = true
440
- if isa (wresult , Const)
441
- val = wresult . val
442
+ if isa (result , Const)
443
+ val = result . val
442
444
if is_inlineable_constant (val)
443
445
analyzed = ConstAPI (val)
444
446
end
445
447
else
446
- @assert isconstType (wresult )
447
- analyzed = ConstAPI (wresult . parameters[1 ])
448
+ @assert isconstType (result )
449
+ analyzed = ConstAPI (result . parameters[1 ])
448
450
end
449
451
force_noinline || (src. inlineable = true )
450
452
end
@@ -501,9 +503,10 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
501
503
end
502
504
503
505
# run the optimization work
504
- function optimize (interp:: AbstractInterpreter , opt:: OptimizationState , params:: OptimizationParams , @nospecialize (result))
506
+ function optimize (interp:: AbstractInterpreter , opt:: OptimizationState ,
507
+ params:: OptimizationParams , caller:: InferenceResult )
505
508
@timeit " optimizer" ir = run_passes (opt. src, opt)
506
- return finish (interp, opt, params, ir, result )
509
+ return finish (interp, opt, params, ir, caller )
507
510
end
508
511
509
512
function run_passes (ci:: CodeInfo , sv:: OptimizationState )
0 commit comments