Skip to content

Commit

Permalink
Support tagged CodeInstances (Valentin's version) (#540)
Browse files Browse the repository at this point in the history
* Support cache_owner api, but not InternalCodeCache

* use cache_owner version of at_newinterp
  • Loading branch information
vchuravy authored Feb 10, 2024
1 parent d911798 commit 79d964e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ CC.get_inference_cache(interp::CthulhuInterpreter) = get_inference_cache(interp.
CC.lock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing
CC.unlock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing
CC.method_table(interp::CthulhuInterpreter) = method_table(interp.native)

if isdefined(CC, :cache_owner)
struct CthulhuCacheToken
token
end
CC.cache_owner(interp::CthulhuInterpreter) = CthulhuCacheToken(CC.cache_owner(interp.native))
end

struct CthulhuCache
cache::OptimizationDict
end
Expand Down
43 changes: 37 additions & 6 deletions test/test_AbstractInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,35 @@ end

const CC = Core.Compiler

"""
@newinterp NewInterpreter
Defines new `NewInterpreter <: AbstractInterpreter` whose cache is separated
from the native code cache, satisfying the minimum interface requirements.
"""
if isdefined(CC, :cache_owner)
macro newinterp(InterpName)
InterpCacheName = QuoteNode(Symbol(string(InterpName, "Cache")))
InterpName = esc(InterpName)
C = Core
CC = Core.Compiler
quote
struct $InterpName <: $CC.AbstractInterpreter
meta # additional information
world::UInt
inf_params::$CC.InferenceParams
opt_params::$CC.OptimizationParams
inf_cache::Vector{$CC.InferenceResult}
function $InterpName(meta = nothing;
world::UInt = Base.get_world_counter(),
inf_params::$CC.InferenceParams = $CC.InferenceParams(),
opt_params::$CC.OptimizationParams = $CC.OptimizationParams(),
inf_cache::Vector{$CC.InferenceResult} = $CC.InferenceResult[])
return new(meta, world, inf_params, opt_params, inf_cache)
end
end
$CC.InferenceParams(interp::$InterpName) = interp.inf_params
$CC.OptimizationParams(interp::$InterpName) = interp.opt_params
$CC.get_inference_world(interp::$InterpName) = interp.world
$CC.get_inference_cache(interp::$InterpName) = interp.inf_cache
$CC.cache_owner(::$InterpName) = $InterpCacheName
end
end
else
macro newinterp(InterpName)
InterpCacheName = esc(Symbol(string(InterpName, "Cache")))
InterpName = esc(InterpName)
Expand Down Expand Up @@ -54,6 +77,14 @@ macro newinterp(InterpName)
$CC.setindex!(wvc::$CC.WorldView{$InterpCacheName}, ci::$C.CodeInstance, mi::$C.MethodInstance) = setindex!(wvc.cache.dict, ci, mi)
end
end
end # isdefined(CC, :cache_owner)

@doc """
@newinterp NewInterpreter
Defines new `NewInterpreter <: AbstractInterpreter` whose cache is separated
from the native code cache, satisfying the minimum interface requirements.
""" var"@newinterp"

# `OverlayMethodTable`
# --------------------
Expand Down

0 comments on commit 79d964e

Please sign in to comment.