Skip to content

Commit 7411e9f

Browse files
gbaraldimaleadt
authored andcommitted
Add generic interface to change codegen params
1 parent 1d58bff commit 7411e9f

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/interface.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ get_interpreter(@nospecialize(job::CompilerJob)) =
185185
# if not, calls to throw will be replaced with calls to the GPU runtime
186186
can_throw(@nospecialize(job::CompilerJob)) = uses_julia_runtime(job)
187187

188+
function codegen_params(@nospecialize(job::CompilerJob))
189+
return (;)
190+
end
191+
188192
# does this target support loading from Julia safepoints?
189193
# if not, safepoints at function entry will not be emitted
190194
can_safepoint(@nospecialize(job::CompilerJob)) = uses_julia_runtime(job)

src/jlgen.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
492492
@static if VERSION >= v"1.10.0-DEV.1499"
493493
cgparams = merge(cgparams, (;gcstack_arg = false))
494494
end
495+
cgparams = merge(cgparams, codegen_params(job))
495496
params = Base.CodegenParams(; cgparams...)
496497

497498
# generate IR

test/native_tests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,18 @@ end
419419
end
420420
end
421421

422+
@static if VERSION > v"1.11.0-DEV.398"
423+
# TODO: teach the verifier to accept ccalls without the plt
424+
@testset "invalid LLVM IR (ccall)" begin
425+
foobar(p) = (unsafe_store!(p, ccall(:time, Cint, ())); nothing)
426+
427+
@test_throws_message(InvalidIRError,
428+
Native.code_execution(foobar, Tuple{Ptr{Int}}), use_jlplt=true) do msg
429+
occursin("Reason: unsupported call to the Julia runtime", msg)
430+
end
431+
end
432+
end
433+
422434
@testset "delayed bindings" begin
423435
kernel() = (undefined; return)
424436

test/native_testsetup.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@ Base.Experimental.@MethodTable(test_method_table)
1212

1313
struct CompilerParams <: AbstractCompilerParams
1414
entry_safepoint::Bool
15+
use_jlplt::Bool
1516
method_table
1617

17-
CompilerParams(entry_safepoint::Bool=false, method_table=test_method_table) =
18-
new(entry_safepoint, method_table)
18+
CompilerParams(entry_safepoint::Bool=false, use_jlplt::Bool=true, method_table=test_method_table) =
19+
new(entry_safepoint, use_jlplt, method_table)
1920
end
2021

2122
NativeCompilerJob = CompilerJob{NativeCompilerTarget,CompilerParams}
2223
GPUCompiler.runtime_module(::NativeCompilerJob) = TestRuntime
2324

2425
GPUCompiler.method_table(@nospecialize(job::NativeCompilerJob)) = job.config.params.method_table
2526
GPUCompiler.can_safepoint(@nospecialize(job::NativeCompilerJob)) = job.config.params.entry_safepoint
27+
@static if VERSION > v"1.11.0-DEV.398"
28+
GPUCompiler.codegen_params(@nospecialize(job::NativeCompilerJob)) = (;use_jlplt=job.config.params.use_jlplt)
29+
end
2630

2731
function create_job(@nospecialize(func), @nospecialize(types); kernel::Bool=false,
28-
entry_abi=:specfunc, entry_safepoint::Bool=false, always_inline=false,
32+
entry_abi=:specfunc, entry_safepoint::Bool=false, use_jlplt::Bool=true, always_inline=false,
2933
method_table=test_method_table, kwargs...)
3034
source = methodinstance(typeof(func), Base.to_tuple_type(types), Base.get_world_counter())
3135
target = NativeCompilerTarget()
32-
params = CompilerParams(entry_safepoint, method_table)
36+
params = CompilerParams(entry_safepoint, use_jlplt, method_table)
3337
config = CompilerConfig(target, params; kernel, entry_abi, always_inline)
3438
CompilerJob(source, config), kwargs
3539
end

0 commit comments

Comments
 (0)