Skip to content

Commit 830ae86

Browse files
committed
Separate codeinfo cache for interpreter params
Currently each codeinfo cache assumes that the same interpreter parameters are used throughout. This is problematic when we want to change the interpreter parameters on a per job basis. Using a dictionary keyed on the interpreter params to store multiple codeinfo caches enables changing the interpreter parameters for different kernel compilations.
1 parent 50a6bd9 commit 830ae86

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/interface.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,14 @@ link_libraries!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
265265
valid_function_pointer(@nospecialize(job::CompilerJob), ptr::Ptr{Cvoid}) = false
266266

267267
# the codeinfo cache to use
268-
ci_cache(@nospecialize(job::CompilerJob)) = GLOBAL_CI_CACHE
268+
function ci_cache(@nospecialize(job::CompilerJob))
269+
lock(GLOBAL_CI_CACHES_LOCK) do
270+
cache = get!(GLOBAL_CI_CACHES, (typeof(job.target), inference_params(job), optimization_params(job))) do
271+
CodeCache()
272+
end
273+
return cache
274+
end
275+
end
269276

270277
# the method table to use
271278
method_table(@nospecialize(job::CompilerJob)) = GLOBAL_METHOD_TABLE

src/jlgen.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## cache
44

5-
using Core.Compiler: CodeInstance, MethodInstance
5+
using Core.Compiler: CodeInstance, MethodInstance, InferenceParams, OptimizationParams
66

77
struct CodeCache
88
dict::Dict{MethodInstance,Vector{CodeInstance}}
@@ -39,7 +39,8 @@ end
3939

4040
Base.empty!(cc::CodeCache) = empty!(cc.dict)
4141

42-
const GLOBAL_CI_CACHE = CodeCache()
42+
const GLOBAL_CI_CACHES = Dict{Tuple{DataType, InferenceParams, OptimizationParams}, CodeCache}()
43+
const GLOBAL_CI_CACHES_LOCK = ReentrantLock()
4344

4445

4546
## method invalidations

0 commit comments

Comments
 (0)