Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inference] limit inference timing recording to NativeInterpreter only #49391

Merged
merged 4 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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