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

Add generic interface to change codegen params #535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 4 additions & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/native_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 8 additions & 4 deletions test/native_testsetup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ 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}
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
Expand Down
Loading