Skip to content

Commit 341e2e8

Browse files
authored
Fix and optimize Core.Compiler.method_table(::GPUCompiler) (#426)
- restrict `mt` argument type to `Core.MethodTable` since `mt::Nothing` is not supported when using overlay method table view. - use `CachedMethodTable` if available to speed up method look up for heavy compilation workload with the duplicated method call.
1 parent cc41cfa commit 341e2e8

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/jlgen.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,23 @@ end
421421
## interpreter
422422

423423
using Core.Compiler:
424-
AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, OptimizationParams
424+
AbstractInterpreter, InferenceResult, InferenceParams, InferenceState,
425+
OptimizationParams, MethodTableView, CachedMethodTable
426+
427+
if isdefined(Base.Experimental, Symbol("@overlay"))
428+
using Core.Compiler: OverlayMethodTable
429+
const GPUMethodTableView = CachedMethodTable{OverlayMethodTable}
430+
const MTType = Core.MethodTable
431+
get_method_table_view(world::UInt, mt::MTType) = CachedMethodTable(OverlayMethodTable(world, mt))
432+
else
433+
const GPUMethodTableView = CachedMethodTable{WorldOverlayMethodTable}
434+
const MTType = Nothing
435+
get_method_table_view(world::UInt, mt::MTType) = CachedMethodTable(WorldOverlayMethodTable(world))
436+
end
425437

426438
struct GPUInterpreter <: AbstractInterpreter
427439
global_cache::CodeCache
428-
method_table::Union{Nothing,Core.MethodTable}
440+
method_table::GPUMethodTableView
429441

430442
# Cache of inference results for this particular interpreter
431443
local_cache::Vector{InferenceResult}
@@ -436,13 +448,14 @@ struct GPUInterpreter <: AbstractInterpreter
436448
inf_params::InferenceParams
437449
opt_params::OptimizationParams
438450

439-
440-
function GPUInterpreter(cache::CodeCache, mt::Union{Nothing,Core.MethodTable}, world::UInt, ip::InferenceParams, op::OptimizationParams)
451+
function GPUInterpreter(cache::CodeCache, mt::MTType, world::UInt, ip::InferenceParams, op::OptimizationParams)
441452
@assert world <= Base.get_world_counter()
442453

454+
method_table = get_method_table_view(world, mt)
455+
443456
return new(
444457
cache,
445-
mt,
458+
method_table,
446459

447460
# Initially empty cache
448461
Vector{InferenceResult}(),
@@ -478,18 +491,10 @@ if VERSION >= v"1.7.0-DEV.577"
478491
Core.Compiler.verbose_stmt_info(interp::GPUInterpreter) = false
479492
end
480493

481-
if isdefined(Base.Experimental, Symbol("@overlay"))
482-
using Core.Compiler: OverlayMethodTable
483494
if v"1.8-beta2" <= VERSION < v"1.9-" || VERSION >= v"1.9.0-DEV.120"
484-
Core.Compiler.method_table(interp::GPUInterpreter) =
485-
OverlayMethodTable(interp.world, interp.method_table)
486-
else
487-
Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState) =
488-
OverlayMethodTable(interp.world, interp.method_table)
489-
end
495+
Core.Compiler.method_table(interp::GPUInterpreter) = interp.method_table
490496
else
491-
Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState) =
492-
WorldOverlayMethodTable(interp.world)
497+
Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState) = interp.method_table
493498
end
494499

495500
# semi-concrete interepretation is broken with overlays (JuliaLang/julia#47349)

0 commit comments

Comments
 (0)