From 7411e9f5c99517be75e9f5e7a4890861084bd3e6 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Tue, 5 Dec 2023 15:19:54 -0500 Subject: [PATCH] Add generic interface to change codegen params --- src/interface.jl | 4 ++++ src/jlgen.jl | 1 + test/native_tests.jl | 12 ++++++++++++ test/native_testsetup.jl | 12 ++++++++---- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 866d18f5..88a5ae7e 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -185,6 +185,10 @@ get_interpreter(@nospecialize(job::CompilerJob)) = # if not, calls to throw will be replaced with calls to the GPU runtime can_throw(@nospecialize(job::CompilerJob)) = uses_julia_runtime(job) +function codegen_params(@nospecialize(job::CompilerJob)) + return (;) +end + # does this target support loading from Julia safepoints? # if not, safepoints at function entry will not be emitted can_safepoint(@nospecialize(job::CompilerJob)) = uses_julia_runtime(job) diff --git a/src/jlgen.jl b/src/jlgen.jl index f6002733..af5b21ae 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -492,6 +492,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob)) @static if VERSION >= v"1.10.0-DEV.1499" cgparams = merge(cgparams, (;gcstack_arg = false)) end + cgparams = merge(cgparams, codegen_params(job)) params = Base.CodegenParams(; cgparams...) # generate IR diff --git a/test/native_tests.jl b/test/native_tests.jl index 930361ef..09c0b997 100644 --- a/test/native_tests.jl +++ b/test/native_tests.jl @@ -419,6 +419,18 @@ end end end +@static if VERSION > v"1.11.0-DEV.398" + # TODO: teach the verifier to accept ccalls without the plt + @testset "invalid LLVM IR (ccall)" begin + foobar(p) = (unsafe_store!(p, ccall(:time, Cint, ())); nothing) + + @test_throws_message(InvalidIRError, + Native.code_execution(foobar, Tuple{Ptr{Int}}), use_jlplt=true) do msg + occursin("Reason: unsupported call to the Julia runtime", msg) + end + end +end + @testset "delayed bindings" begin kernel() = (undefined; return) diff --git a/test/native_testsetup.jl b/test/native_testsetup.jl index 973b300d..d98d718d 100644 --- a/test/native_testsetup.jl +++ b/test/native_testsetup.jl @@ -12,10 +12,11 @@ Base.Experimental.@MethodTable(test_method_table) struct CompilerParams <: AbstractCompilerParams entry_safepoint::Bool + use_jlplt::Bool method_table - CompilerParams(entry_safepoint::Bool=false, method_table=test_method_table) = - new(entry_safepoint, method_table) + CompilerParams(entry_safepoint::Bool=false, use_jlplt::Bool=true, method_table=test_method_table) = + new(entry_safepoint, use_jlplt, method_table) end NativeCompilerJob = CompilerJob{NativeCompilerTarget,CompilerParams} @@ -23,13 +24,16 @@ GPUCompiler.runtime_module(::NativeCompilerJob) = TestRuntime GPUCompiler.method_table(@nospecialize(job::NativeCompilerJob)) = job.config.params.method_table GPUCompiler.can_safepoint(@nospecialize(job::NativeCompilerJob)) = job.config.params.entry_safepoint +@static if VERSION > v"1.11.0-DEV.398" + GPUCompiler.codegen_params(@nospecialize(job::NativeCompilerJob)) = (;use_jlplt=job.config.params.use_jlplt) +end function create_job(@nospecialize(func), @nospecialize(types); kernel::Bool=false, - entry_abi=:specfunc, entry_safepoint::Bool=false, always_inline=false, + entry_abi=:specfunc, entry_safepoint::Bool=false, use_jlplt::Bool=true, always_inline=false, method_table=test_method_table, kwargs...) source = methodinstance(typeof(func), Base.to_tuple_type(types), Base.get_world_counter()) target = NativeCompilerTarget() - params = CompilerParams(entry_safepoint, method_table) + params = CompilerParams(entry_safepoint, use_jlplt, method_table) config = CompilerConfig(target, params; kernel, entry_abi, always_inline) CompilerJob(source, config), kwargs end