Skip to content

Commit

Permalink
use opt as a ci -> OptimizedSrc side-dcit
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Feb 8, 2024
1 parent a9cd574 commit 718d838
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ function lookup_optimized(interp::CthulhuInterpreter, mi::MethodInstance, allow_
codeinst = CC.getindex(CC.code_cache(interp), mi)
rt = cached_return_type(codeinst)
exct = cached_exception_type(codeinst)
opt = codeinst.inferred
opt = get(interp.opt, codeinst, nothing)
if opt === nothing
opt = codeinst.inferred
end
if opt !== nothing
opt = opt::OptimizedSource
src = CC.copy(opt.ir)
Expand Down
16 changes: 15 additions & 1 deletion src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ end

const InferenceKey = Union{MethodInstance,InferenceResult}
const InferenceDict{T} = IdDict{InferenceKey, T}
const OptimizationDict = IdDict{MethodInstance, CodeInstance}

# const OptimizationDict = IdDict{MethodInstance, CodeInstance}
const OptimizationDict = IdDict{CodeInstance, OptimizedSource}
const PC2Remarks = Vector{Pair{Int, String}}
const PC2Effects = Dict{Int, Effects}
const PC2Excts = Dict{Int, Any}
Expand Down Expand Up @@ -183,6 +185,18 @@ end
# return create_cthulhu_source(result.src, result.ipo_effects)
# end



function CC.CodeInstance(interp::CthulhuInterpreter, result::InferenceResult,
valid_worlds::WorldRange)
opt_src = create_cthulhu_source(result.src, result.ipo_effects)
ci = @invoke CC.CodeInstance(interp::AbstractInterpreter, result, valid_worlds)
if opt_src isa OptimizedSource
interp.opt[ci] = opt_src
end
return ci
end

@static if VERSION v"1.11.0-DEV.879"
function CC.inlining_policy(interp::CthulhuInterpreter,
@nospecialize(src), @nospecialize(info::CCCallInfo), stmt_flag::UInt32)
Expand Down

0 comments on commit 718d838

Please sign in to comment.