From dc76ab586cb8a5a814406895c597df63c47b9ffd Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 25 Apr 2023 07:17:48 -0400 Subject: [PATCH] [Inference] limit inference timing recording to `NativeInterpreter` only (#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 (cherry picked from commit 3db036eed80c1c0b90dd027b5382e9e0d12df652) --- base/compiler/ssair/irinterp.jl | 5 ++++- base/compiler/typeinfer.jl | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/base/compiler/ssair/irinterp.jl b/base/compiler/ssair/irinterp.jl index 3ce968eb1131c..42d6ef3d11e13 100644 --- a/base/compiler/ssair/irinterp.jl +++ b/base/compiler/ssair/irinterp.jl @@ -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 @@ -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) @@ -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) diff --git a/base/compiler/typeinfer.jl b/base/compiler/typeinfer.jl index 77e6493f8afa0..fe84849f15d14 100644 --- a/base/compiler/typeinfer.jl +++ b/base/compiler/typeinfer.jl @@ -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) @@ -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