Skip to content

Commit

Permalink
Update to LLVM.jl 6. (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Jun 23, 2023
1 parent 1c49a2e commit 5acfd6f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
24 changes: 12 additions & 12 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ version = "0.1.7"

[[Compat]]
deps = ["Dates", "LinearAlgebra", "UUIDs"]
git-tree-sha1 = "7a60c856b9fa189eb34f5f8a6f6b5529b7942957"
git-tree-sha1 = "4e88377ae7ebeaf29a047aa1ee40826e0b708a5d"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "4.6.1"
version = "4.7.0"

[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
Expand All @@ -69,9 +69,9 @@ version = "0.1.9"

[[GPUArrays]]
deps = ["Adapt", "GPUArraysCore", "LLVM", "LinearAlgebra", "Printf", "Random", "Reexport", "Serialization", "Statistics"]
git-tree-sha1 = "a3351bc577a6b49297248aadc23a4add1097c2ac"
git-tree-sha1 = "2e57b4a4f9cc15e85a24d603256fe08e527f48d1"
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
version = "8.7.1"
version = "8.8.1"

[[GPUArraysCore]]
deps = ["Adapt"]
Expand All @@ -81,9 +81,9 @@ version = "0.1.5"

[[GPUCompiler]]
deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Scratch", "TimerOutputs", "UUIDs"]
git-tree-sha1 = "c47730aca2381f935a52fd732190e424c507230e"
git-tree-sha1 = "0c21d9b7ff70859bdb2ca7dab814e144676c31db"
uuid = "61eb1bfa-7361-4325-ad38-22787b887f55"
version = "0.21.0"
version = "0.21.1"

[[InteractiveUtils]]
deps = ["Markdown"]
Expand All @@ -108,15 +108,15 @@ version = "1.4.1"

[[KernelAbstractions]]
deps = ["Adapt", "Atomix", "InteractiveUtils", "LinearAlgebra", "MacroTools", "PrecompileTools", "SparseArrays", "StaticArrays", "UUIDs", "UnsafeAtomics", "UnsafeAtomicsLLVM"]
git-tree-sha1 = "47be64f040a7ece575c2b5f53ca6da7b548d69f4"
git-tree-sha1 = "b48617c5d764908b5fac493cd907cf33cc11eec1"
uuid = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
version = "0.9.4"
version = "0.9.6"

[[LLVM]]
deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Printf", "Unicode"]
git-tree-sha1 = "5007c1421563108110bbd57f63d8ad4565808818"
git-tree-sha1 = "7d5788011dd273788146d40eb5b1fbdc199d0296"
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
version = "5.2.0"
version = "6.0.1"

[[LLVMExtra_jll]]
deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"]
Expand Down Expand Up @@ -319,9 +319,9 @@ version = "0.2.1"

[[UnsafeAtomicsLLVM]]
deps = ["LLVM", "UnsafeAtomics"]
git-tree-sha1 = "ea37e6066bf194ab78f4e747f5245261f17a7175"
git-tree-sha1 = "323e3d0acf5e78a56dfae7bd8928c989b4f3083e"
uuid = "d80eeb9a-aca5-4d75-85e5-170c8b632249"
version = "0.1.2"
version = "0.1.3"

[[Zlib_jll]]
deps = ["Libdl"]
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ExprTools = "0.1"
GPUArrays = "8.4"
GPUCompiler = "0.20.1, 0.21"
KernelAbstractions = "0.9.1"
LLVM = "5.0"
LLVM = "6"
NEO_jll = "=22.53.25593"
Preferences = "1"
SPIRV_LLVM_Translator_unified_jll = "0.3"
Expand Down
16 changes: 6 additions & 10 deletions src/compiler/compilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ function GPUCompiler.finish_module!(job::oneAPICompilerJob, mod::LLVM.Module)
invoke(GPUCompiler.finish_module!,
Tuple{CompilerJob{SPIRVCompilerTarget}, typeof(mod)},
job, mod)
ctx = LLVM.context(mod)

# OpenCL 2.0
push!(metadata(mod)["opencl.ocl.version"],
MDNode([ConstantInt(Int32(2); ctx),
ConstantInt(Int32(0); ctx)]; ctx))
MDNode([ConstantInt(Int32(2)),
ConstantInt(Int32(0))]))

# SPIR-V 1.5
push!(metadata(mod)["opencl.spirv.version"],
MDNode([ConstantInt(Int32(1); ctx),
ConstantInt(Int32(5); ctx)]; ctx))
MDNode([ConstantInt(Int32(1)),
ConstantInt(Int32(5))]))
end


Expand Down Expand Up @@ -78,12 +77,9 @@ end
# compile to executable machine code
function compile(@nospecialize(job::CompilerJob))
# TODO: on 1.9, this actually creates a context. cache those.
JuliaContext() do ctx
compile(job, ctx)
asm, meta = JuliaContext() do ctx
GPUCompiler.compile(:obj, job)
end
end
function compile(@nospecialize(job::CompilerJob), ctx)
asm, meta = GPUCompiler.compile(:obj, job; ctx)

(image=asm, entry=LLVM.name(meta.entry))
end
Expand Down
10 changes: 5 additions & 5 deletions src/device/opencl/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ end
# get a pointer to local memory, with known (static) or zero length (dynamic)
@generated function emit_localmemory(::Type{T}, ::Val{len}=Val(0)) where {T,len}
Context() do ctx
eltyp = convert(LLVMType, T; ctx)
T_ptr = convert(LLVMType, LLVMPtr{T,AS.Local}; ctx)
eltyp = convert(LLVMType, T)
T_ptr = convert(LLVMType, LLVMPtr{T,AS.Local})

# create a function
llvm_f, _ = create_function(T_ptr)
Expand All @@ -39,11 +39,11 @@ end
alignment!(gv, Base.datatype_alignment(T))

# generate IR
IRBuilder(ctx) do builder
entry = BasicBlock(llvm_f, "entry"; ctx)
IRBuilder() do builder
entry = BasicBlock(llvm_f, "entry")
position!(builder, entry)

ptr = gep!(builder, gv_typ, gv, [ConstantInt(0; ctx), ConstantInt(0; ctx)])
ptr = gep!(builder, gv_typ, gv, [ConstantInt(0), ConstantInt(0)])

untyped_ptr = bitcast!(builder, ptr, T_ptr)

Expand Down
14 changes: 7 additions & 7 deletions src/device/opencl/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ end
arg_types = [argspec...]

Context() do ctx
T_void = LLVM.VoidType(ctx)
T_int32 = LLVM.Int32Type(ctx)
T_pint8 = LLVM.PointerType(LLVM.Int8Type(ctx))
T_void = LLVM.VoidType()
T_int32 = LLVM.Int32Type()
T_pint8 = LLVM.PointerType(LLVM.Int8Type())

# create functions
param_types = LLVMType[convert(LLVMType, typ; ctx) for typ in arg_types]
param_types = LLVMType[convert(LLVMType, typ) for typ in arg_types]
llvm_f, _ = create_function(T_int32, param_types)
mod = LLVM.parent(llvm_f)

# generate IR
IRBuilder(ctx) do builder
entry = BasicBlock(llvm_f, "entry"; ctx)
IRBuilder() do builder
entry = BasicBlock(llvm_f, "entry")
position!(builder, entry)

str = globalstring_ptr!(builder, String(fmt))

# invoke printf and return
printf_typ = LLVM.FunctionType(T_int32, [T_pint8]; vararg=true)
printf = LLVM.Function(mod, "printf", printf_typ)
push!(function_attributes(printf), EnumAttribute("nobuiltin"; ctx))
push!(function_attributes(printf), EnumAttribute("nobuiltin"))
chars = call!(builder, printf_typ, printf, [str, parameters(llvm_f)...])

ret!(builder, chars)
Expand Down

0 comments on commit 5acfd6f

Please sign in to comment.