Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After conversion to LLVM we should be able to delete the inferred source of the kernel. #520

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ end
obj = nothing

# fast path: find an applicable CodeInstance and see if we have compiled it before
ci = ci_cache_lookup(ci_cache(job), src, world, world)::Union{Nothing,CodeInstance}
ci = ci_cache_lookup(ci_cache(job), src, world, world; allow_uninferred=true)::Union{Nothing,CodeInstance}
if ci !== nothing && haskey(cache, ci)
obj = cache[ci]
end
Expand All @@ -130,7 +130,7 @@ end
end

obj = linker(job, asm)
ci = ci_cache_lookup(ci_cache(job), src, world, world)::CodeInstance
ci = ci_cache_lookup(ci_cache(job), src, world, world; allow_uninferred=true)::CodeInstance
cache[ci] = obj
end

Expand Down
20 changes: 12 additions & 8 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,6 @@ function CC.getindex(wvc::WorldView{CodeCache}, mi::MethodInstance)
end

function CC.setindex!(wvc::WorldView{CodeCache}, ci::CodeInstance, mi::MethodInstance)
src = if ci.inferred isa Vector{UInt8}
ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any),
mi.def, C_NULL, ci.inferred)
else
ci.inferred
end
CC.setindex!(wvc.cache, ci, mi)
end

Expand Down Expand Up @@ -410,10 +404,10 @@ function ci_cache_populate(interp, cache, mi, min_world, max_world)
return ci
end

function ci_cache_lookup(cache, mi, min_world, max_world)
function ci_cache_lookup(cache, mi, min_world, max_world; allow_uninferred=false)
wvc = WorldView(cache, min_world, max_world)
ci = CC.get(wvc, mi, nothing)
if ci !== nothing && ci.inferred === nothing
if ci !== nothing && (!allow_uninferred && ci.inferred === nothing)
# if for some reason we did end up with a codeinfo without inferred source, e.g.,
# because of calling `Base.return_types` which only sets rettyp, pretend we didn't
# run inference so that we re-infer now and not during codegen (which is disallowed)
Expand Down Expand Up @@ -613,5 +607,15 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
end
end

if job.config.kernel
# Don't cache the top-level inference result.
ci = compiled[job.source].ci
@static if VERSION < v"1.9.0"
ci.inferred = nothing
else
Base.@atomic :release ci.inferred = nothing
end
end

return llvm_mod, compiled
end