Skip to content

Commit 4725b3e

Browse files
vchuravyaviatesk
authored andcommitted
[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 <aviatesk@gmail.com>
1 parent ddabad6 commit 4725b3e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

base/compiler/ssair/irinterp.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function concrete_eval_invoke(interp::AbstractInterpreter,
3838
newirsv = IRInterpretationState(interp, code, mi, argtypes, world)
3939
if newirsv !== nothing
4040
newirsv.parent = irsv
41-
return _ir_abstract_constant_propagation(interp, newirsv)
41+
return ir_abstract_constant_propagation(interp, newirsv)
4242
end
4343
return Pair{Any,Bool}(nothing, is_nothrow(effects))
4444
end
@@ -194,6 +194,8 @@ end
194194
default_reprocess(::AbstractInterpreter, ::IRInterpretationState) = nothing
195195
function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState;
196196
extra_reprocess::Union{Nothing,BitSet} = default_reprocess(interp, irsv))
197+
interp = switch_to_irinterp(interp)
198+
197199
(; ir, tpdum, ssa_refined) = irsv
198200

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

345-
function ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState)
346-
irinterp = switch_to_irinterp(interp)
347+
function ir_abstract_constant_propagation(interp::NativeInterpreter, irsv::IRInterpretationState)
347348
if __measure_typeinf__[]
348349
inf_frame = Timings.InferenceFrameInfo(irsv.mi, irsv.world, VarState[], Any[], length(irsv.ir.argtypes))
349350
Timings.enter_new_timer(inf_frame)
350-
ret = _ir_abstract_constant_propagation(irinterp, irsv)
351+
ret = _ir_abstract_constant_propagation(interp, irsv)
351352
append!(inf_frame.slottypes, irsv.ir.argtypes)
352353
Timings.exit_current_timer(inf_frame)
353354
return ret
354355
else
355-
return _ir_abstract_constant_propagation(irinterp, irsv)
356+
return _ir_abstract_constant_propagation(interp, irsv)
356357
end
357358
end
359+
ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState) =
360+
_ir_abstract_constant_propagation(interp, irsv)

base/compiler/typeinfer.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ If set to `true`, record per-method-instance timings within type inference in th
204204
__set_measure_typeinf(onoff::Bool) = __measure_typeinf__[] = onoff
205205
const __measure_typeinf__ = fill(false)
206206

207-
# Wrapper around _typeinf that optionally records the exclusive time for each invocation.
208-
function typeinf(interp::AbstractInterpreter, frame::InferenceState)
209-
interp = switch_from_irinterp(interp)
207+
# Wrapper around `_typeinf` that optionally records the exclusive time for
208+
# each inference performed by `NativeInterpreter`.
209+
function typeinf(interp::NativeInterpreter, frame::InferenceState)
210210
if __measure_typeinf__[]
211211
Timings.enter_new_timer(frame)
212212
v = _typeinf(interp, frame)
@@ -216,6 +216,7 @@ function typeinf(interp::AbstractInterpreter, frame::InferenceState)
216216
return _typeinf(interp, frame)
217217
end
218218
end
219+
typeinf(interp::AbstractInterpreter, frame::InferenceState) = _typeinf(interp, frame)
219220

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

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

0 commit comments

Comments
 (0)