Skip to content

Commit 6a91f0d

Browse files
committed
Adapt to upstream compiler changes.
1 parent df4293e commit 6a91f0d

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/jlgen.jl

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,35 @@ end # HAS_INTEGRATED_CACHE
480480
## codegen/inference integration
481481

482482
function ci_cache_populate(interp, cache, mi, min_world, max_world)
483-
if VERSION >= v"1.12.0-DEV.15"
484-
inferred_ci = CC.typeinf_ext_toplevel(interp, mi, CC.SOURCE_MODE_FORCE_SOURCE) # or SOURCE_MODE_FORCE_SOURCE_UNCACHED?
483+
@static if VERSION >= v"1.12.0-DEV.1434"
484+
# see typeinfer.jl: typeinf_ext_toplevel
485+
ci = CC.typeinf_ext(interp, mi, CC.SOURCE_MODE_NOT_REQUIRED)
486+
inspected = IdSet{CodeInstance}()
487+
tocompile = CodeInstance[ci]
488+
codeinfos = []
489+
while !isempty(tocompile)
490+
callee = pop!(tocompile)
491+
callee in inspected && continue
492+
push!(inspected, callee)
493+
# now make sure everything has source code, if desired
494+
mi = CC.get_ci_mi(callee)
495+
def = mi.def
496+
if CC.use_const_api(callee)
497+
src = CC.codeinfo_for_const(interp, mi, ci.rettype_const)
498+
elseif isa(def, Method) && ccall(:jl_get_module_infer, Cint, (Any,), def.module) == 0 && !trim
499+
src = CC.retrieve_code_info(mi, CC.get_inference_world(interp))
500+
else
501+
# TODO: typeinf_code could return something with different edges/ages/owner/abi (needing an update to callee), which we don't handle here
502+
src = CC.typeinf_code(interp, mi, true)
503+
end
504+
if src isa CodeInfo
505+
CC.collectinvokes!(tocompile, src)
506+
push!(codeinfos, callee)
507+
push!(codeinfos, src)
508+
end
509+
end
510+
elseif VERSION >= v"1.12.0-DEV.15"
511+
inferred_ci = CC.typeinf_ext_toplevel(interp, mi, CC.SOURCE_MODE_FORCE_SOURCE)
485512
@assert inferred_ci !== nothing "Inference of $mi failed"
486513

487514
# inference should have populated our cache
@@ -518,7 +545,7 @@ end
518545
function ci_cache_lookup(cache, mi, min_world, max_world)
519546
wvc = WorldView(cache, min_world, max_world)
520547
ci = CC.get(wvc, mi, nothing)
521-
if ci !== nothing && ci.inferred === nothing
548+
if VERSION < v"1.12.0-DEV.1434" && ci !== nothing && ci.inferred === nothing
522549
# if for some reason we did end up with a codeinfo without inferred source, e.g.,
523550
# because of calling `Base.return_types` which only sets rettyp, pretend we didn't
524551
# run inference so that we re-infer now and not during codegen (which is disallowed)
@@ -622,7 +649,13 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
622649
Metadata(ConstantInt(DEBUG_METADATA_VERSION()))
623650
end
624651

625-
native_code = if VERSION >= v"1.12.0-DEV.1667"
652+
native_code = if VERSION >= v"1.12.0-DEV.1823"
653+
# each item in the list should be a CodeInstance followed by a CodeInfo
654+
# indicating something to compile
655+
codeinstance = ci_cache_lookup(cache, job.source, job.world, job.world)::CodeInstance
656+
codeinfo = CC.typeinf_code(interp, job.source, #=trim=# true)::CodeInfo
657+
@ccall jl_emit_native([codeinstance, codeinfo]::Vector{Any}, ts_mod::LLVM.API.LLVMOrcThreadSafeModuleRef, Ref(params)::Ptr{Base.CodegenParams}, #=extern linkage=# false::Cint)::Ptr{Cvoid}
658+
elseif VERSION >= v"1.12.0-DEV.1667"
626659
ccall(:jl_create_native, Ptr{Cvoid},
627660
(Vector{MethodInstance}, LLVM.API.LLVMOrcThreadSafeModuleRef, Ptr{Base.CodegenParams}, Cint, Cint, Cint, Csize_t, Ptr{Cvoid}),
628661
[job.source], ts_mod, Ref(params), CompilationPolicyExtern, #=imaging mode=# 0, #=external linkage=# 0, job.world, Base.unsafe_convert(Ptr{Nothing}, lookup_cb))

0 commit comments

Comments
 (0)