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 <[email protected]>
(cherry picked from commit 3db036e)
  • Loading branch information
vchuravy committed Apr 25, 2023
1 parent 6f2f44e commit dc76ab5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion base/compiler/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ end

function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState;
extra_reprocess::Union{Nothing,BitSet} = nothing)

(; ir, tpdum, ssa_refined) = irsv

bbs = ir.cfg.blocks
Expand Down Expand Up @@ -416,7 +417,7 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
return maybe_singleton_const(ultimate_rt)
end

function ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState)
function ir_abstract_constant_propagation(interp::NativeInterpreter, irsv::IRInterpretationState)
if __measure_typeinf__[]
inf_frame = Timings.InferenceFrameInfo(irsv.mi, irsv.world, Any[], Any[], length(irsv.ir.argtypes))
Timings.enter_new_timer(inf_frame)
Expand All @@ -429,3 +430,5 @@ function ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRI
return T
end
end
ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState) =
_ir_abstract_constant_propagation(interp, irsv)
6 changes: 4 additions & 2 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +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)
# 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 @@ -215,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 Down

0 comments on commit dc76ab5

Please sign in to comment.