Skip to content

Commit

Permalink
update with JuliaLang/#43994
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jan 31, 2022
1 parent ccf7234 commit dd0858e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 23 additions & 3 deletions src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,22 @@ function Compiler.add_remark!(interp::CthulhuInterpreter, sv::InferenceState, ms
end

function Compiler.finish(state::InferenceState, interp::CthulhuInterpreter)
r = @invoke Compiler.finish(state::InferenceState, interp::AbstractInterpreter)
interp.unopt[Core.Compiler.any(state.result.overridden_by_const) ? state.result : state.linfo] = InferredSource(
res = @invoke Compiler.finish(state::InferenceState, interp::AbstractInterpreter)
key = Core.Compiler.any(state.result.overridden_by_const) ? state.result : state.linfo
interp.unopt[key] = InferredSource(
copy(state.src),
copy(state.stmt_info),
state.result.result)
return r
return res
end

function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo::MethodInstance,
valid_worlds::WorldRange, @nospecialize(inferred_result))
@static if isdefined(Compiler, :transform_optresult_for_cache)
return isa(inferred_result, OptimizedSource) ? inferred_result :
isa(inferred_result, Compiler.ConstAPI) ? inferred_result :
nothing
else # @static if isdefined(Compiler, :transform_optresult_for_cache)
if isa(inferred_result, OptimizationState)
opt = inferred_result
ir = opt.ir
Expand All @@ -90,6 +96,7 @@ function Compiler.transform_result_for_cache(interp::CthulhuInterpreter, linfo::
end
end
return inferred_result
end # @static if isdefined(Compiler, :transform_optresult_for_cache)
end

# branch on https://github.com/JuliaLang/julia/pull/41328
Expand Down Expand Up @@ -119,6 +126,17 @@ function Compiler.inlining_policy(interp::CthulhuInterpreter)
end
end # @static if isdefined(Compiler, :is_stmt_inline)

# branch on https://github.com/JuliaLang/julia/pull/43994
@static if isdefined(Compiler, :transform_optresult_for_cache)

function Compiler.transform_optresult_for_cache(interp::CthulhuInterpreter,
opt::OptimizationState, ir::IRCode, @nospecialize(analyzed))
isa(analyzed, Compiler.ConstAPI) && return analyzed
return OptimizedSource(ir, opt.src, opt.src.inlineable)
end

else # @static if isdefined(Compiler, :transform_optresult_for_cache)

function Compiler.finish!(interp::CthulhuInterpreter, caller::InferenceResult)
src = caller.src
if isa(src, OptimizationState)
Expand All @@ -129,3 +147,5 @@ function Compiler.finish!(interp::CthulhuInterpreter, caller::InferenceResult)
end
end
end

end # @static if isdefined(Compiler, :transform_optresult_for_cache)
3 changes: 2 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ function strip_base_linenums(s)
end

function irshow_filename(optimize, debuginfo, iswarn, hide_type_stable, inline_cost, type_annotations)
return "test_output/foo-$(optimize ? :opt : :unopt)-$(debuginfo)-$(iswarn ? :warn : :nowarn)\
p = "test_output/foo-$(optimize ? :opt : :unopt)-$(debuginfo)-$(iswarn ? :warn : :nowarn)\
-$(hide_type_stable ? :hide_type_stable : :show_type_stable)-$(inline_cost ? :inline_cost : :nocost)\
-$(type_annotations ? :types : :notypes)"
return normpath(@__DIR__, p)
end

# to generate test cases for IRShow tests
Expand Down

0 comments on commit dd0858e

Please sign in to comment.