From d65cc1f24baa424dccc67ac44c704495d6519917 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 20 Sep 2023 17:47:37 -0400 Subject: [PATCH 1/7] After conversion to LLVM we should be able to delete the inferred source of the kernel. --- src/jlgen.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/jlgen.jl b/src/jlgen.jl index 2a54c038..ec1b3339 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -613,5 +613,10 @@ function compile_method_instance(@nospecialize(job::CompilerJob)) end end + if job.config.kernel + # Don't cache the top-level inference result. + compiled[job.source].ci.inferred = nothing + end + return llvm_mod, compiled end From 715a1beec415f2e94a859bafacf1cd811669bccb Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 20 Sep 2023 18:02:40 -0400 Subject: [PATCH 2/7] Update src/jlgen.jl --- src/jlgen.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index ec1b3339..60bac97a 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -615,7 +615,8 @@ function compile_method_instance(@nospecialize(job::CompilerJob)) if job.config.kernel # Don't cache the top-level inference result. - compiled[job.source].ci.inferred = nothing + ci = compiled[job.source].ci + Base.@atomic :release ci.inferred = nothing end return llvm_mod, compiled From 974cc5534adc24e06385683589fc5a8baff9965d Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 20 Sep 2023 18:09:18 -0400 Subject: [PATCH 3/7] Update src/jlgen.jl --- src/jlgen.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/jlgen.jl b/src/jlgen.jl index 60bac97a..15bc3862 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -616,7 +616,11 @@ function compile_method_instance(@nospecialize(job::CompilerJob)) if job.config.kernel # Don't cache the top-level inference result. ci = compiled[job.source].ci +@static VERSION < v"1.9.0" + ci.inferred = nothing +else Base.@atomic :release ci.inferred = nothing +end end return llvm_mod, compiled From d927ecfcf6210ec1decd60e93295973ac781af76 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 20 Sep 2023 18:29:58 -0400 Subject: [PATCH 4/7] Fix usage of ci_cache_lookup --- src/execution.jl | 4 ++-- src/jlgen.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/execution.jl b/src/execution.jl index e501216e..2add70e9 100644 --- a/src/execution.jl +++ b/src/execution.jl @@ -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 @@ -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 diff --git a/src/jlgen.jl b/src/jlgen.jl index 15bc3862..3ce78965 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -410,10 +410,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) From 427c63a03bac32a86e2764461e67cc10a6e277f6 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 20 Sep 2023 18:33:22 -0400 Subject: [PATCH 5/7] fixup! Fix usage of ci_cache_lookup --- src/jlgen.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index 3ce78965..2b54c3db 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -616,7 +616,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob)) if job.config.kernel # Don't cache the top-level inference result. ci = compiled[job.source].ci -@static VERSION < v"1.9.0" +@static if VERSION < v"1.9.0" ci.inferred = nothing else Base.@atomic :release ci.inferred = nothing From d7ac585c710215d4e6f3c47423c840300faf83a3 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 20 Sep 2023 18:42:10 -0400 Subject: [PATCH 6/7] fixup! fixup! Fix usage of ci_cache_lookup --- src/jlgen.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index 2b54c3db..dacd42f4 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -413,7 +413,7 @@ end 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 && (allow_uninferred || 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) From 919242d008d9481b2d12d1f702d5e157682ba72b Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 21 Sep 2023 10:40:55 +0200 Subject: [PATCH 7/7] Allow caching uncompressed IR again. --- src/jlgen.jl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index dacd42f4..13d2c75a 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -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