Skip to content

Commit

Permalink
Clean-up version checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Mar 17, 2021
1 parent 8dacba3 commit eec85d5
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 131 deletions.
17 changes: 2 additions & 15 deletions src/irgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ function irgen(@nospecialize(job::CompilerJob), method_instance::Core.MethodInst
# only occurs in debug builds
delete!(function_attributes(llvmf), EnumAttribute("sspstrong", 0, ctx))

if VERSION < v"1.5.0-DEV.393"
# make function names safe for ptxas
llvmfn = LLVM.name(llvmf)
if !isdeclaration(llvmf)
llvmfn′ = safe_name(llvmfn)
if llvmfn != llvmfn′
LLVM.name!(llvmf, llvmfn′)
llvmfn = llvmfn′
end
end
end

if Sys.iswindows()
personality!(llvmf, nothing)
end
Expand Down Expand Up @@ -315,8 +303,7 @@ function classify_arguments(@nospecialize(job::CompilerJob), codegen_f::LLVM.Fun
args = []
codegen_i = 1
for (source_i, source_typ) in enumerate(source_types)
if isghosttype(source_typ) ||
(VERSION >= v"1.5.0-DEV.581" && Core.Compiler.isconstType(source_typ))
if isghosttype(source_typ) || Core.Compiler.isconstType(source_typ)
push!(args, (cc=GHOST, typ=source_typ))
continue
end
Expand All @@ -326,7 +313,7 @@ function classify_arguments(@nospecialize(job::CompilerJob), codegen_f::LLVM.Fun
push!(args, (cc=MUT_REF, typ=source_typ,
codegen=(typ=codegen_typ, i=codegen_i)))
elseif codegen_typ isa LLVM.PointerType && issized(eltype(codegen_typ)) &&
!(source_typ <: Ptr) && !(VERSION >= v"1.5-" && source_typ <: Core.LLVMPtr)
!(source_typ <: Ptr) && !(source_typ <: Core.LLVMPtr)
push!(args, (cc=BITS_REF, typ=source_typ,
codegen=(typ=codegen_typ, i=codegen_i)))
else
Expand Down
6 changes: 3 additions & 3 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ end

## method overrides

@static if VERSION >= v"1.7-"
@static if isdefined(Base.Experimental, Symbol("@overlay"))

# use an overlay method table

Expand Down Expand Up @@ -141,7 +141,7 @@ end
by a check to `ccall(:jl_generating_output, Cint, ()) != 0`).
"""
macro override(mt, ex)
if VERSION >= v"1.7-"
if isdefined(Base.Experimental, Symbol("@overlay"))
esc(quote
Base.Experimental.@overlay $mt $ex
end)
Expand Down Expand Up @@ -222,7 +222,7 @@ if VERSION >= v"1.7.0-DEV.577"
Core.Compiler.verbose_stmt_info(interp::GPUInterpreter) = false
end

if VERSION >= v"1.7-"
if isdefined(Base.Experimental, Symbol("@overlay"))
Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState) =
Core.Compiler.OverlayMethodTable(interp.world, interp.method_table)
else
Expand Down
6 changes: 1 addition & 5 deletions src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,7 @@ macro device_code(ex...)
end

open(joinpath(dir, "$fn.typed.jl"), "w") do io
if VERSION >= v"1.1.0"
code = only(code_typed(job; debuginfo=:source))
else
code = only(code_typed(job))
end
code = only(code_typed(job; debuginfo=:source))
println(io, code)
end

Expand Down
34 changes: 11 additions & 23 deletions src/rtlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ end
function cachedir(depot=DEPOT_PATH[1])
# this mimicks Base.compilecache. we can't just call the function, or we might actually
# _generate_ a cache file, e.g., when running with `--compiled-modules=no`.
if VERSION >= v"1.3.0-alpha.146"
entrypath, entryfile = Base.cache_file_entry(Base.PkgId(GPUCompiler))
abspath(depot, entrypath, entryfile)
else
cachefile = abspath(depot, Base.cache_file_entry(Base.PkgId(GPUCompiler)))

# the cachefile consists of `/depot/compiled/vXXX/GPUCompiler/$slug.ji`
# transform that into `/depot/compiled/vXXX/GPUCompiler/$slug/`
splitext(cachefile)[1]
end
entrypath, entryfile = Base.cache_file_entry(Base.PkgId(GPUCompiler))
abspath(depot, entrypath, entryfile)
end


Expand Down Expand Up @@ -82,21 +74,17 @@ function emit_function!(mod, @nospecialize(job::CompilerJob), f, method)
end

# recent Julia versions include prototypes for all runtime functions, even if unused
if VERSION >= v"1.5-"
pm = ModulePassManager()
strip_dead_prototypes!(pm)
run!(pm, new_mod)
dispose(pm)
end
pm = ModulePassManager()
strip_dead_prototypes!(pm)
run!(pm, new_mod)
dispose(pm)

temp_name = LLVM.name(entry)
if VERSION >= v"1.6.0-DEV.674"
# FIXME: on 1.6, there's no single global LLVM context anymore,
# but there's no API yet to pass a context to codegen.
# round-trip the module through serialization to get it in the proper context.
buf = convert(MemoryBuffer, new_mod)
new_mod = parse(LLVM.Module, buf, context(mod))
end
# FIXME: on 1.6, there's no single global LLVM context anymore,
# but there's no API yet to pass a context to codegen.
# round-trip the module through serialization to get it in the proper context.
buf = convert(MemoryBuffer, new_mod)
new_mod = parse(LLVM.Module, buf, context(mod))
@assert context(mod) == context(new_mod)
link!(mod, new_mod)
entry = functions(mod)[temp_name]
Expand Down
24 changes: 2 additions & 22 deletions src/runtime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function compile(def, return_type, types, llvm_return_type=nothing, llvm_types=n
if def isa Symbol
args = [gensym() for typ in types]
@eval @inline $def($(args...)) =
ccall($"extern $llvm_name", llvmcall, $return_type, ($(types...),), $(args...))
ccall($("extern $llvm_name"), llvmcall, $return_type, ($(types...),), $(args...))
end

return
Expand All @@ -112,29 +112,9 @@ compile(:report_exception_name, Nothing, (Ptr{Cchar},))

## GC

if VERSION < v"1.4"

@enum AddressSpace begin
Generic = 1
Tracked = 10
Derived = 11
CalleeRooted = 12
Loaded = 13
end

# LLVM type of a tracked pointer
function T_prjlvalue(ctx)
T_pjlvalue = convert(LLVMType, Any, ctx; allow_boxed=true)
LLVM.PointerType(eltype(T_pjlvalue), Tracked)
end

else

# FIXME: once we only support 1.4, get rid of this and allow boxed types
# FIXME: get rid of this and allow boxed types
T_prjlvalue(ctx) = convert(LLVMType, Any, ctx; allow_boxed=true)

end

function gc_pool_alloc(sz::Csize_t)
ptr = malloc(sz)
if ptr == C_NULL
Expand Down
53 changes: 7 additions & 46 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ function check_method(@nospecialize(job::CompilerJob))
return
end

if VERSION < v"1.1.0-DEV.593"
fieldtypes(@nospecialize(dt)) = ntuple(i->fieldtype(dt, i), fieldcount(dt))
end

# The actual check is rather complicated
# and might change from version to version...
function hasfieldcount(@nospecialize(dt))
Expand Down Expand Up @@ -60,24 +56,13 @@ function check_invocation(@nospecialize(job::CompilerJob), entry::LLVM.Function)
sig = Base.signature_type(job.source.f, job.source.tt)::Type
for (arg_i,dt) in enumerate(sig.parameters)
isghosttype(dt) && continue
VERSION >= v"1.5.0-DEV.581" && Core.Compiler.isconstType(dt) && continue
Core.Compiler.isconstType(dt) && continue
real_arg_i += 1

if !isbitstype(dt)
if VERSION >= v"1.5.0-DEV.581"
throw(KernelError(job, "passing and using non-bitstype argument",
"""Argument $arg_i to your kernel function is of type $dt, which is not isbits:
$(explain_nonisbits(dt))"""))
else
# be slightly more lenient pre 1.5, to support `function(::Type, ...)`
param = parameters(entry)[real_arg_i]
if !isempty(uses(param))
throw(KernelError(job, "passing and using non-bitstype argument",
"""Argument $arg_i to your kernel function is of type $dt, which is not isbits:
$(explain_nonisbits(dt))
Passing non-isbits types is only allowed if they they are unused by the kernel."""))
end
end
throw(KernelError(job, "passing and using non-bitstype argument",
"""Argument $arg_i to your kernel function is of type $dt, which is not isbits:
$(explain_nonisbits(dt))"""))
end
end

Expand Down Expand Up @@ -167,15 +152,7 @@ function check_ir!(job, errors::Vector{IRError}, inst::LLVM.CallInst)
end
elseif fn == "jl_invoke"
try
if VERSION < v"1.3.0-DEV.244"
meth, args, nargs, _ = operands(inst)
else
f, args, nargs, meth = operands(inst)
end
if VERSION < v"1.5.0-DEV.802"
# addrspacecast
meth = first(operands(meth::ConstantExpr))
end
f, args, nargs, meth = operands(inst)
meth = first(operands(meth::ConstantExpr))::ConstantInt
meth = convert(Int, meth)
meth = Ptr{Cvoid}(meth)
Expand All @@ -187,19 +164,7 @@ function check_ir!(job, errors::Vector{IRError}, inst::LLVM.CallInst)
end
elseif fn == "jl_apply_generic"
try
if VERSION < v"1.3.0-DEV.244"
args, nargs, _ = operands(inst)
## args is a buffer where arguments are stored in
f, args = user.(uses(args))
## first store into the args buffer is a direct store
f = first(operands(f::LLVM.StoreInst))::ConstantExpr
else
f, args, nargs, _ = operands(inst)
end

if VERSION < v"1.5.0-DEV.802"
f = first(operands(f::ConstantExpr)) # get rid of addrspacecast
end
f, args, nargs, _ = operands(inst)
f = first(operands(f))::ConstantInt # get rid of inttoptr
f = convert(Int, f)
f = Ptr{Cvoid}(f)
Expand Down Expand Up @@ -245,11 +210,7 @@ function check_ir!(job, errors::Vector{IRError}, inst::LLVM.CallInst)
frames = ccall(:jl_lookup_code_address, Any, (Ptr{Cvoid}, Cint,), ptr, 0)
if length(frames) >= 1
@compiler_assert length(frames) == 1 job frames=frames
if VERSION >= v"1.4.0-DEV.123"
fn, file, line, linfo, fromC, inlined = last(frames)
else
fn, file, line, linfo, fromC, inlined, ip = last(frames)
end
fn, file, line, linfo, fromC, inlined = last(frames)
push!(errors, (POINTER_FUNCTION, bt, fn))
else
push!(errors, (POINTER_FUNCTION, bt, nothing))
Expand Down
6 changes: 1 addition & 5 deletions test/gcn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ end
asm = sprint(io->gcn_code_native(io, ref_kernel, Tuple{Ptr{Int64}, Int}))
if VERSION < v"1.2.0-DEV.375"
@test_broken !occursin("gpu_gc_pool_alloc", asm)
else
@test !occursin("gpu_gc_pool_alloc", asm)
end
@test !occursin("gpu_gc_pool_alloc", asm)
end
=#

Expand Down
2 changes: 0 additions & 2 deletions test/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ end
native_code_llvm(devnull, kernel, Tuple{Vector{Int}}; kernel=true)
end

if VERSION >= v"1.0.2"
@testset "CUDAnative.jl#278" begin
# codegen idempotency
# NOTE: this isn't fixed, but surfaces here due to bad inference of checked_sub
Expand All @@ -137,7 +136,6 @@ if VERSION >= v"1.0.2"
# even in the presence of the above bug
native_code_llvm(devnull, Base.print_to_string, Tuple{Int,Int}; optimize=false)
end
end

@testset "LLVM D32593" begin
@eval struct D32593_struct
Expand Down
12 changes: 2 additions & 10 deletions test/ptx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ end
end

ir = sprint(io->ptx_code_llvm(io, kernel, Tuple{Aggregate}))
if VERSION < v"1.5.0-DEV.802"
@test occursin(r"@.*julia_kernel.+\(({ i64 }|\[1 x i64\]) addrspace\(\d+\)?\*", ir)
else
@test occursin(r"@.*julia_kernel.+\(({ i64 }|\[1 x i64\])\*", ir)
end
@test occursin(r"@.*julia_kernel.+\(({ i64 }|\[1 x i64\])\*", ir)

ir = sprint(io->ptx_code_llvm(io, kernel, Tuple{Aggregate}; kernel=true))
@test occursin(r"@.*julia_kernel.+\(({ i64 }|\[1 x i64\])", ir)
Expand Down Expand Up @@ -247,11 +243,7 @@ end
asm = sprint(io->ptx_code_native(io, ref_kernel, Tuple{Ptr{Int64}, Int}))


if VERSION < v"1.2.0-DEV.375"
@test_broken !occursin("gpu_gc_pool_alloc", asm)
else
@test !occursin("gpu_gc_pool_alloc", asm)
end
@test !occursin("gpu_gc_pool_alloc", asm)
end

@testset "float boxes" begin
Expand Down

0 comments on commit eec85d5

Please sign in to comment.