Skip to content

Commit

Permalink
[Inference] limit inference timing recording to NativeInterpreter o…
Browse files Browse the repository at this point in the history
…nly (#49391)

The logic of `Core.Compiler.Timings` assumes that the whole recorded 
inference graph is constructed by the same interpreter, thus we should 
limit the inference timing recording to `NativeInterpreter` only. 

External `AbstractInterpreter` can implement its own recording logic, 
likely by reusing existing `Core.Compiler.Timings` utilities, in a way 
that does not interfere with the recording for native compilation pipeline.

---------

Co-authored-by: Shuhei Kadowaki <aviatesk@gmail.com>
  • Loading branch information
vchuravy and aviatesk authored Apr 25, 2023
1 parent b291522 commit 3db036e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions base/compiler/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function concrete_eval_invoke(interp::AbstractInterpreter,
newirsv = IRInterpretationState(interp, code, mi, argtypes, world)
if newirsv !== nothing
newirsv.parent = irsv
return _ir_abstract_constant_propagation(interp, newirsv)
return ir_abstract_constant_propagation(interp, newirsv)
end
return Pair{Any,Bool}(nothing, is_nothrow(effects))
end
Expand Down Expand Up @@ -194,6 +194,8 @@ end
default_reprocess(::AbstractInterpreter, ::IRInterpretationState) = nothing
function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState;
extra_reprocess::Union{Nothing,BitSet} = default_reprocess(interp, irsv))
interp = switch_to_irinterp(interp)

(; ir, tpdum, ssa_refined) = irsv

bbs = ir.cfg.blocks
Expand Down Expand Up @@ -342,16 +344,17 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
return Pair{Any,Bool}(maybe_singleton_const(ultimate_rt), nothrow)
end

function ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState)
irinterp = switch_to_irinterp(interp)
function ir_abstract_constant_propagation(interp::NativeInterpreter, irsv::IRInterpretationState)
if __measure_typeinf__[]
inf_frame = Timings.InferenceFrameInfo(irsv.mi, irsv.world, VarState[], Any[], length(irsv.ir.argtypes))
Timings.enter_new_timer(inf_frame)
ret = _ir_abstract_constant_propagation(irinterp, irsv)
ret = _ir_abstract_constant_propagation(interp, irsv)
append!(inf_frame.slottypes, irsv.ir.argtypes)
Timings.exit_current_timer(inf_frame)
return ret
else
return _ir_abstract_constant_propagation(irinterp, irsv)
return _ir_abstract_constant_propagation(interp, irsv)
end
end
ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState) =
_ir_abstract_constant_propagation(interp, irsv)
8 changes: 5 additions & 3 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ If set to `true`, record per-method-instance timings within type inference in th
__set_measure_typeinf(onoff::Bool) = __measure_typeinf__[] = onoff
const __measure_typeinf__ = fill(false)

# Wrapper around _typeinf that optionally records the exclusive time for each invocation.
function typeinf(interp::AbstractInterpreter, frame::InferenceState)
interp = switch_from_irinterp(interp)
# Wrapper around `_typeinf` that optionally records the exclusive time for
# each inference performed by `NativeInterpreter`.
function typeinf(interp::NativeInterpreter, frame::InferenceState)
if __measure_typeinf__[]
Timings.enter_new_timer(frame)
v = _typeinf(interp, frame)
Expand All @@ -216,6 +216,7 @@ function typeinf(interp::AbstractInterpreter, frame::InferenceState)
return _typeinf(interp, frame)
end
end
typeinf(interp::AbstractInterpreter, frame::InferenceState) = _typeinf(interp, frame)

function finish!(interp::AbstractInterpreter, caller::InferenceResult)
# If we didn't transform the src for caching, we may have to transform
Expand All @@ -242,6 +243,7 @@ function finish!(interp::AbstractInterpreter, caller::InferenceResult)
end

function _typeinf(interp::AbstractInterpreter, frame::InferenceState)
interp = switch_from_irinterp(interp)
typeinf_nocycle(interp, frame) || return false # frame is now part of a higher cycle
# with no active ip's, frame is done
frames = frame.callers_in_cycle
Expand Down

2 comments on commit 3db036e

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

Please sign in to comment.