Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #539 from JuliaGPU/tb/julia_ir_printer
Browse files Browse the repository at this point in the history
Use the Julia LLVM IR printer to support the debuginfo argument.
  • Loading branch information
maleadt authored Jan 31, 2020
2 parents 9870462 + e66edf5 commit e4cbe2f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ See also: [`@device_code_llvm`](@ref), InteractiveUtils.code_llvm
"""
function code_llvm(io::IO, @nospecialize(func), @nospecialize(types);
cap::VersionNumber=current_capability(), kernel::Bool=false,
optimize::Bool=true, raw::Bool=false,
optimize::Bool=true, raw::Bool=false, debuginfo::Symbol=:default,
dump_module::Bool=false, strict::Bool=false, kwargs...)
tt = Base.to_tuple_type(types)
job = CompilerJob(func, tt, cap, kernel; kwargs...)
code_llvm(io, job; optimize=optimize,
raw=raw, dump_module=dump_module, strict=strict)
code_llvm(io, job; optimize=optimize, raw=raw, debuginfo=debuginfo,
dump_module=dump_module, strict=strict)
end
function code_llvm(io::IO, job::CompilerJob; optimize::Bool=true, raw::Bool=false,
dump_module::Bool=false, strict::Bool=false)
ir, entry = codegen(:llvm, job; optimize=optimize, strip=!raw, strict=strict)
if dump_module
show(io, ir)
else
show(io, entry)
end
debuginfo::Symbol=:default, dump_module::Bool=false, strict::Bool=false)
# NOTE: jl_dump_function_ir supports stripping metadata, so don't do it in the driver
ir, entry = codegen(:llvm, job; optimize=optimize, strip=false, strict=strict)
str = ccall(:jl_dump_function_ir, Ref{String},
(Ptr{Cvoid}, Bool, Bool, Ptr{UInt8}),
LLVM.ref(entry), !raw, dump_module, debuginfo)
print(io, str)
end
code_llvm(@nospecialize(func), @nospecialize(types); kwargs...) =
code_llvm(stdout, func, types; kwargs...)
Expand Down
6 changes: 3 additions & 3 deletions test/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ end
for f in (load, store)
ir = sprint(io->CUDAnative.code_llvm(io, f,
Tuple{CUDAnative.DevicePtr{Float32,AS.Global}};
dump_module=true))
dump_module=true, raw=true))
@test occursin("ptxtbaa_global", ir)

# no TBAA on generic pointers
ir = sprint(io->CUDAnative.code_llvm(io, f,
Tuple{CUDAnative.DevicePtr{Float32,AS.Generic}};
dump_module=true))
dump_module=true, raw=true))
@test !occursin("ptxtbaa", ir)
end

Expand All @@ -167,7 +167,7 @@ end

ir = sprint(io->CUDAnative.code_llvm(io, cached_load,
Tuple{CUDAnative.DevicePtr{Float32,AS.Global}};
dump_module=true))
dump_module=true, raw=true))
@test occursin("ptxtbaa_global", ir)
end

Expand Down
2 changes: 1 addition & 1 deletion test/device/cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@testset "range metadata" begin
foobar() = threadIdx().x
ir = sprint(io->CUDAnative.code_llvm(io, foobar, Tuple{}))
ir = sprint(io->CUDAnative.code_llvm(io, foobar, Tuple{}; raw=true))

@test occursin(r"call .+ @llvm.nvvm.read.ptx.sreg.tid.x.+ !range", ir)
end
Expand Down

0 comments on commit e4cbe2f

Please sign in to comment.