Skip to content

Commit

Permalink
revisit #47137: avoid round-trip of locally-cached inferred source
Browse files Browse the repository at this point in the history
Built on top of #51958, with the improved performance of `cfg_simplify!`,
let's give another try on #47137. Tha aim is to retain
locally cached inferred source as `IRCode`, eliminating the need for the
inlining algorithm to round-trip it through `CodeInfo` representation.
  • Loading branch information
aviatesk committed Oct 31, 2023
1 parent 512deed commit bde9827
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ function const_prop_call(interp::AbstractInterpreter,
add_remark!(interp, sv, "[constprop] Could not retrieve the source")
return nothing # this is probably a bad generated function (unsound), but just ignore it
end
inf_result.must_be_codeinf = false
frame.parent = sv
if !typeinf(interp, frame)
add_remark!(interp, sv, "[constprop] Fresh constant inference hit a cycle")
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function inlining_policy(interp::AbstractInterpreter,
return nothing
end
elseif isa(src, IRCode)
# n.b. the inlineability was computed within `finish!`
return src
elseif isa(src, SemiConcreteResult)
if is_declared_noinline(mi.def::Method)
Expand Down Expand Up @@ -196,10 +197,9 @@ include("compiler/ssair/passes.jl")
include("compiler/ssair/irinterp.jl")

function ir_to_codeinf!(opt::OptimizationState)
(; linfo, src) = opt
src = ir_to_codeinf!(src, opt.ir::IRCode)
src = ir_to_codeinf!(opt.src, opt.ir::IRCode)
opt.ir = nothing
validate_code_in_debug_mode(linfo, src, "optimized")
validate_code_in_debug_mode(opt.linfo, src, "optimized")
return src
end

Expand Down
10 changes: 8 additions & 2 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,14 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState)
store_backedges(result, caller.stmt_edges[1])
end
opt = result.src
if opt isa OptimizationState && result.must_be_codeinf
result.src = opt = ir_to_codeinf!(opt)
if opt isa OptimizationState
if result.must_be_codeinf
result.src = opt = ir_to_codeinf!(opt)
else is_inlineable(opt.src) || is_stmt_inline(get_curr_ssaflag(caller.parent::InferenceState))
# TODO Delay `cfg_simplify!` until when needed?
# Currently it results in segfault due to duplicated CFG simplification.
result.src = opt = cfg_simplify!(opt.ir::IRCode)
end
end
if opt isa CodeInfo
opt.min_world = first(valid_worlds)
Expand Down

0 comments on commit bde9827

Please sign in to comment.