Skip to content

Commit

Permalink
Merge pull request #38287 from JuliaLang/vc/compiler++
Browse files Browse the repository at this point in the history
Split and parameterize Core.Compiler.optimize
  • Loading branch information
vchuravy authored Nov 21, 2020
2 parents 0affcb5 + 14beadd commit f805448
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ function stmt_affects_purity(@nospecialize(stmt), ir)
return true
end

# run the optimization work
function optimize(opt::OptimizationState, params::OptimizationParams, @nospecialize(result))
# Convert IRCode back to CodeInfo and compute inlining cost and sideeffects
function finish(opt::OptimizationState, params::OptimizationParams, ir, @nospecialize(result))
def = opt.linfo.def
nargs = Int(opt.nargs) - 1
@timeit "optimizer" ir = run_passes(opt.src, nargs, opt)

force_noinline = _any(@nospecialize(x) -> isexpr(x, :meta) && x.args[1] === :noinline, ir.meta)

# compute inlining and other related optimizations
Expand Down Expand Up @@ -271,6 +271,13 @@ function optimize(opt::OptimizationState, params::OptimizationParams, @nospecial
nothing
end

# run the optimization work
function optimize(interp::AbstractInterpreter, opt::OptimizationState, params::OptimizationParams, @nospecialize(result))
nargs = Int(opt.nargs) - 1
@timeit "optimizer" ir = run_passes(opt.src, nargs, opt)
finish(opt, params, ir, result)
end


# whether `f` is pure for inference
function is_pure_intrinsic_infer(f::IntrinsicFunction)
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function _typeinf(interp::AbstractInterpreter, frame::InferenceState)
if opt isa OptimizationState
run_optimizer = doopt && may_optimize(interp)
if run_optimizer
optimize(opt, OptimizationParams(interp), caller.result)
optimize(interp, opt, OptimizationParams(interp), caller.result)
finish(opt.src, interp)
# finish updating the result struct
validate_code_in_debug_mode(opt.linfo, opt.src, "optimized")
Expand Down Expand Up @@ -772,7 +772,7 @@ function typeinf_code(interp::AbstractInterpreter, method::Method, @nospecialize
if typeinf(interp, frame) && run_optimizer
opt_params = OptimizationParams(interp)
opt = OptimizationState(frame, opt_params, interp)
optimize(opt, opt_params, result.result)
optimize(interp, opt, opt_params, result.result)
opt.src.inferred = true
end
ccall(:jl_typeinf_end, Cvoid, ())
Expand Down

0 comments on commit f805448

Please sign in to comment.