7373
7474# on 1.11 (JuliaLang/julia#52572, merged as part of JuliaLang/julia#52233) we can use
7575# Julia's cached method lookup to simply look up method instances at run time.
76- if VERSION >= v " 1.11.0-DEV.1552"
76+ @static if VERSION >= v " 1.11.0-DEV.1552"
7777
7878# XXX : version of Base.method_instance that uses a function type
7979@inline function methodinstance (@nospecialize (ft:: Type ), @nospecialize (tt:: Type ),
@@ -395,7 +395,7 @@ CC.InferenceParams(interp::GPUInterpreter) = interp.inf_params
395395CC. OptimizationParams (interp:: GPUInterpreter ) = interp. opt_params
396396#= CC.=# get_inference_world (interp:: GPUInterpreter ) = interp. world
397397CC. get_inference_cache (interp:: GPUInterpreter ) = interp. inf_cache
398- if HAS_INTEGRATED_CACHE
398+ @static if HAS_INTEGRATED_CACHE
399399 CC. cache_owner (interp:: GPUInterpreter ) = interp. token
400400else
401401 CC. code_cache (interp:: GPUInterpreter ) = WorldView (interp. code_cache, interp. world)
412412CC. may_optimize (interp:: GPUInterpreter ) = true
413413CC. may_compress (interp:: GPUInterpreter ) = true
414414CC. may_discard_trees (interp:: GPUInterpreter ) = true
415+ @static if VERSION <= v " 1.12.0-DEV.1531"
415416CC. verbose_stmt_info (interp:: GPUInterpreter ) = false
417+ end
416418CC. method_table (interp:: GPUInterpreter ) = interp. method_table
417419
418420# semi-concrete interepretation is broken with overlays (JuliaLang/julia#47349)
@@ -615,9 +617,11 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
615617 prefer_specsig = true ,
616618 gnu_pubnames = false ,
617619 debug_info_kind = Cint (debug_info_kind),
618- lookup = Base. unsafe_convert (Ptr{Nothing}, lookup_cb),
619620 safepoint_on_entry = can_safepoint (job),
620621 gcstack_arg = false )
622+ if VERSION < v " 1.12.0-DEV.1667"
623+ cgparams = (; lookup = Base. unsafe_convert (Ptr{Nothing}, lookup_cb), cgparams... )
624+ end
621625 params = Base. CodegenParams (; cgparams... )
622626
623627 # generate IR
@@ -635,9 +639,15 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
635639 Metadata (ConstantInt (DEBUG_METADATA_VERSION ()))
636640 end
637641
638- native_code = ccall (:jl_create_native , Ptr{Cvoid},
642+ native_code = if VERSION >= v " 1.12.0-DEV.1667"
643+ ccall (:jl_create_native , Ptr{Cvoid},
644+ (Vector{MethodInstance}, LLVM. API. LLVMOrcThreadSafeModuleRef, Ptr{Base. CodegenParams}, Cint, Cint, Cint, Csize_t, Ptr{Cvoid}),
645+ [job. source], ts_mod, Ref (params), CompilationPolicyExtern, #= imaging mode=# 0 , #= external linkage=# 0 , job. world, Base. unsafe_convert (Ptr{Nothing}, lookup_cb))
646+ else
647+ ccall (:jl_create_native , Ptr{Cvoid},
639648 (Vector{MethodInstance}, LLVM. API. LLVMOrcThreadSafeModuleRef, Ptr{Base. CodegenParams}, Cint, Cint, Cint, Csize_t),
640649 [job. source], ts_mod, Ref (params), CompilationPolicyExtern, #= imaging mode=# 0 , #= external linkage=# 0 , job. world)
650+ end
641651 @assert native_code != C_NULL
642652
643653 llvm_mod_ref =
@@ -658,6 +668,19 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
658668 cache_gbl = nothing
659669 end
660670
671+ if VERSION >= v " 1.12.0-DEV.1703"
672+ # on sufficiently recent versions of Julia, we can query the MIs compiled.
673+ # this is required after the move to `invokce(::CodeInstance)`, because our
674+ # lookup function (used to populate method_instances) isn't always called then.
675+
676+ num_mis = Ref {Csize_t} (0 )
677+ @ccall jl_get_llvm_mis (native_code:: Ptr{Cvoid} , num_mis:: Ptr{Csize_t} ,
678+ C_NULL :: Ptr{Cvoid} ):: Nothing
679+ resize! (method_instances, num_mis[])
680+ @ccall jl_get_llvm_mis (native_code:: Ptr{Cvoid} , num_mis:: Ptr{Csize_t} ,
681+ method_instances:: Ptr{Cvoid} ):: Nothing
682+ end
683+
661684 # process all compiled method instances
662685 compiled = Dict ()
663686 for mi in method_instances
0 commit comments