Skip to content

Commit

Permalink
Make sure to preserve info in union-split (JuliaLang#47301)
Browse files Browse the repository at this point in the history
Generally we try pretty hard in inlining to make sure to preserve
the :info of a statement when we turn it into :invoke. We don't
use this information in the compiler itself, but it is used
by external tools (including Cthulhu). However, we were dropping
this info during union splitting for no particular reason. Fix
that.
  • Loading branch information
Keno authored Oct 24, 2022
1 parent d93c661 commit a528f77
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ end
struct InvokeCase
invoke::MethodInstance
effects::Effects
info::CallInfo
end

struct InliningCase
Expand Down Expand Up @@ -592,7 +593,7 @@ function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int,
elseif isa(case, InvokeCase)
inst = Expr(:invoke, case.invoke, argexprs′...)
flag = flags_for_effects(case.effects)
val = insert_node_here!(compact, NewInstruction(inst, typ, NoCallInfo(), line, flag))
val = insert_node_here!(compact, NewInstruction(inst, typ, case.info, line, flag))
else
case = case::ConstantCase
val = case.val
Expand Down Expand Up @@ -796,19 +797,19 @@ function rewrite_apply_exprargs!(todo::Vector{Pair{Int,Any}},
end

function compileable_specialization(match::MethodMatch, effects::Effects,
et::InliningEdgeTracker; compilesig_invokes::Bool=true)
et::InliningEdgeTracker, @nospecialize(info::CallInfo); compilesig_invokes::Bool=true)
mi = specialize_method(match; compilesig=compilesig_invokes)
mi === nothing && return nothing
add_inlining_backedge!(et, mi)
return InvokeCase(mi, effects)
return InvokeCase(mi, effects, info)
end

function compileable_specialization(linfo::MethodInstance, effects::Effects,
et::InliningEdgeTracker; compilesig_invokes::Bool=true)
et::InliningEdgeTracker, @nospecialize(info::CallInfo); compilesig_invokes::Bool=true)
mi = specialize_method(linfo.def::Method, linfo.specTypes, linfo.sparam_vals; compilesig=compilesig_invokes)
mi === nothing && return nothing
add_inlining_backedge!(et, mi)
return InvokeCase(mi, effects)
return InvokeCase(mi, effects, info)
end

compileable_specialization(result::InferenceResult, args...; kwargs...) = (@nospecialize;
Expand Down Expand Up @@ -862,7 +863,7 @@ function resolve_todo(mi::MethodInstance, result::Union{MethodMatch,InferenceRes
# the duplicated check might have been done already within `analyze_method!`, but still
# we need it here too since we may come here directly using a constant-prop' result
if !state.params.inlining || is_stmt_noinline(flag)
return compileable_specialization(result, effects, et;
return compileable_specialization(result, effects, et, info;
compilesig_invokes=state.params.compilesig_invokes)
end

Expand All @@ -877,7 +878,7 @@ function resolve_todo(mi::MethodInstance, result::Union{MethodMatch,InferenceRes
return ConstantCase(quoted(src.val))
end

src === nothing && return compileable_specialization(result, effects, et;
src === nothing && return compileable_specialization(result, effects, et, info;
compilesig_invokes=state.params.compilesig_invokes)

add_inlining_backedge!(et, mi)
Expand Down Expand Up @@ -966,7 +967,7 @@ function analyze_method!(match::MethodMatch, argtypes::Vector{Any},
mi = specialize_method(match; preexisting=true) # Union{Nothing, MethodInstance}
if mi === nothing
et = InliningEdgeTracker(state.et, invokesig)
return compileable_specialization(match, Effects(), et;
return compileable_specialization(match, Effects(), et, info;
compilesig_invokes=state.params.compilesig_invokes)
end

Expand Down Expand Up @@ -1542,7 +1543,7 @@ function handle_modifyfield!_call!(ir::IRCode, idx::Int, stmt::Expr, info::Modif
length(info.results) == 1 || return nothing
match = info.results[1]::MethodMatch
match.fully_covers || return nothing
case = compileable_specialization(match, Effects(), InliningEdgeTracker(state.et);
case = compileable_specialization(match, Effects(), InliningEdgeTracker(state.et), info;
compilesig_invokes=state.params.compilesig_invokes)
case === nothing && return nothing
stmt.head = :invoke_modify
Expand Down

0 comments on commit a528f77

Please sign in to comment.