Skip to content
Draft
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
6 changes: 4 additions & 2 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
FileCheck = "4e644321-382b-4b05-b0b6-5d23c3d944fb"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
LLVM_jll = "86de99a1-58d6-5da7-8064-bd56ce2e322c"
Expand All @@ -18,4 +18,6 @@ demumble_jll = "1e29f10c-031c-5a83-9565-69cddfc27673"
[compat]
Aqua = "0.8"
ParallelTestRunner = "1"
LLVM_jll = "15,16,18,20"

[sources]
FileCheck = {url = "https://github.com/JuliaLLVM/FileCheck.jl", rev="main"}
26 changes: 13 additions & 13 deletions test/bpf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
end

@test @filecheck begin
check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:"
check"CHECK: r0 = 0"
check"CHECK-NEXT: exit"
@check_label "julia_kernel_{{[0-9_]*}}:"
@check "r0 = 0"
@check_next "exit"
BPF.code_native(mod.kernel, ())
end
end
Expand All @@ -16,9 +16,9 @@ end
end

@test @filecheck begin
check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:"
check"CHECK: r0 = r1"
check"CHECK-NEXT: exit"
@check_label "julia_kernel_{{[0-9_]*}}:"
@check "r0 = r1"
@check_next "exit"
BPF.code_native(mod.kernel, (UInt64,))
end
end
Expand All @@ -28,10 +28,10 @@ end
end

@test @filecheck begin
check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:"
check"CHECK: r0 = r1"
check"CHECK-NEXT: r0 += 1"
check"CHECK-NEXT: exit"
@check_label "julia_kernel_{{[0-9_]*}}:"
@check "r0 = r1"
@check_next "r0 += 1"
@check_next "exit"
BPF.code_native(mod.kernel, (UInt64,))
end
end
Expand All @@ -50,9 +50,9 @@ end
end

@test @filecheck begin
check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:"
check"CHECK: call"
check"CHECK-NEXT: exit"
@check_label "julia_kernel_{{[0-9_]*}}:"
@check "call"
@check_next "exit"
BPF.code_native(mod.kernel, (Int,))
end
end
Expand Down
62 changes: 31 additions & 31 deletions test/gcn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ sink_gcn(i) = sink(i, Val(5))
end

@test @filecheck begin
check"CHECK-NOT: amdgpu_kernel"
@check_not "amdgpu_kernel"
GCN.code_llvm(mod.kernel, Tuple{}; dump_module=true)
end

@test @filecheck begin
check"CHECK: amdgpu_kernel"
@check "amdgpu_kernel"
GCN.code_llvm(mod.kernel, Tuple{}; dump_module=true, kernel=true)
end
end
Expand All @@ -30,9 +30,9 @@ end
end

@test @filecheck begin
check"CHECK-NOT: {{julia_throw_boundserror_[0-9]+}}"
check"CHECK: @gpu_report_exception"
check"CHECK: @gpu_signal_exception"
@check_not "{{julia_throw_boundserror_[0-9]+}}"
@check "@gpu_report_exception"
@check "@gpu_signal_exception"
GCN.code_llvm(mod.kernel, Tuple{})
end
end
Expand Down Expand Up @@ -63,9 +63,9 @@ end
end

@test @filecheck begin
check"CHECK-LABEL: {{(julia|j)_kernel_[0-9]+}}:"
check"CHECK: s_cbranch_exec"
check"CHECK: s_trap 2"
@check_label "{{(julia|j)_kernel_[0-9]+}}:"
@check "s_cbranch_exec"
@check "s_trap 2"
GCN.code_native(mod.kernel, Tuple{})
end
end
Expand All @@ -83,9 +83,9 @@ end
end

@test @filecheck begin
check"CHECK-LABEL: {{(julia|j)_parent_[0-9]+}}:"
check"CHECK: s_add_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
check"CHECK: s_addc_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
@check_label "{{(julia|j)_parent_[0-9]+}}:"
@check "s_add_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
@check "s_addc_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
GCN.code_native(mod.parent, Tuple{Int64}; dump_module=true)
end
end
Expand All @@ -101,9 +101,9 @@ end
end

@test @filecheck begin
check"CHECK-NOT: .amdhsa_kernel {{(julia|j)_nonentry_[0-9]+}}"
check"CHECK: .type {{(julia|j)_nonentry_[0-9]+}},@function"
check"CHECK: .amdhsa_kernel _Z5entry5Int64"
@check_not ".amdhsa_kernel {{(julia|j)_nonentry_[0-9]+}}"
@check ".type {{(julia|j)_nonentry_[0-9]+}},@function"
@check ".amdhsa_kernel _Z5entry5Int64"
GCN.code_native(mod.entry, Tuple{Int64}; dump_module=true, kernel=true)
end
end
Expand All @@ -126,12 +126,12 @@ end
end

@test @filecheck begin
check"CHECK: .type {{(julia|j)_child_[0-9]+}},@function"
@check ".type {{(julia|j)_child_[0-9]+}},@function"
GCN.code_native(mod.parent1, Tuple{Int}; dump_module=true)
end

@test @filecheck begin
check"CHECK: .type {{(julia|j)_child_[0-9]+}},@function"
@check ".type {{(julia|j)_child_[0-9]+}},@function"
GCN.code_native(mod.parent2, Tuple{Int}; dump_module=true)
end
end
Expand All @@ -155,14 +155,14 @@ end
end

@test @filecheck begin
check"CHECK-DAG: .type {{(julia|j)_child1_[0-9]+}},@function"
check"CHECK-DAG: .type {{(julia|j)_child2_[0-9]+}},@function"
@check_dag ".type {{(julia|j)_child1_[0-9]+}},@function"
@check_dag ".type {{(julia|j)_child2_[0-9]+}},@function"
GCN.code_native(mod.parent1, Tuple{Int}; dump_module=true)
end

@test @filecheck begin
check"CHECK-DAG: .type {{(julia|j)_child1_[0-9]+}},@function"
check"CHECK-DAG: .type {{(julia|j)_child2_[0-9]+}},@function"
@check_dag ".type {{(julia|j)_child1_[0-9]+}},@function"
@check_dag ".type {{(julia|j)_child2_[0-9]+}},@function"
GCN.code_native(mod.parent2, Tuple{Int}; dump_module=true)
end
end
Expand All @@ -182,9 +182,9 @@ end
end

@test @filecheck begin
check"CHECK-LABEL: {{(julia|j)_kernel_[0-9]+}}:"
check"CHECK-NOT: jl_throw"
check"CHECK-NOT: jl_invoke"
@check_label "{{(julia|j)_kernel_[0-9]+}}:"
@check_not "jl_throw"
@check_not "jl_invoke"
GCN.code_native(mod.kernel, Tuple{Ptr{Int32}})
end
end
Expand Down Expand Up @@ -234,11 +234,11 @@ false && @testset "GC and TLS lowering" begin
end

@test @filecheck begin
check"CHECK-NOT: jl_push_gc_frame"
check"CHECK-NOT: jl_pop_gc_frame"
check"CHECK-NOT: jl_get_gc_frame_slot"
check"CHECK-NOT: jl_new_gc_frame"
check"CHECK: gpu_gc_pool_alloc"
@check_not "jl_push_gc_frame"
@check_not "jl_pop_gc_frame"
@check_not "jl_get_gc_frame_slot"
@check_not "jl_new_gc_frame"
@check "gpu_gc_pool_alloc"
GCN.code_native(mod.kernel, Tuple{Int})
end

Expand All @@ -256,7 +256,7 @@ false && @testset "GC and TLS lowering" begin
end

@test @filecheck begin
check"CHECK-NOT: gpu_gc_pool_alloc"
@check_not "gpu_gc_pool_alloc"
GCN.code_native(ref_kernel, Tuple{Ptr{Int64}, Int})
end
end
Expand All @@ -275,8 +275,8 @@ end
end

@test @filecheck begin
check"CHECK-LABEL: define void @{{(julia|j)_kernel_[0-9]+}}"
check"CHECK: jl_box_float32"
@check_label "define void @{{(julia|j)_kernel_[0-9]+}}"
@check "jl_box_float32"
GCN.code_llvm(mod.kernel, Tuple{Float32,Ptr{Float32}})
end
GCN.code_native(devnull, mod.kernel, Tuple{Float32,Ptr{Float32}})
Expand Down
120 changes: 5 additions & 115 deletions test/helpers/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,120 +36,10 @@ end
return :(Base.llvmcall($llvmcall_str, T, Tuple{T}, i))
end

# filecheck utils
# typed/opaque pointer detection for conditional FileCheck checks

module FileCheck
import LLVM_jll
import IOCapture
using GPUCompiler, LLVM

export filecheck, @filecheck, @check_str

global filecheck_path::String
function __init__()
global filecheck_path = joinpath(LLVM_jll.artifact_dir, "tools", "FileCheck")
end

function filecheck_exe(; adjust_PATH::Bool=true, adjust_LIBPATH::Bool=true)
env = Base.invokelatest(
LLVM_jll.JLLWrappers.adjust_ENV!,
copy(ENV),
LLVM_jll.PATH[],
LLVM_jll.LIBPATH[],
adjust_PATH,
adjust_LIBPATH
)

return Cmd(Cmd([filecheck_path]); env)
end

const julia_typed_pointers = JuliaContext() do ctx
supports_typed_pointers(ctx)
end

function filecheck(f, input)
# FileCheck assumes that the input is available as a file
mktemp() do path, input_io
write(input_io, input)
close(input_io)

# capture the output of `f` and write it into a temporary buffer
result = IOCapture.capture(rethrow=Union{}) do
f(input)
end
output_io = IOBuffer()
write(output_io, result.output)
println(output_io)

if result.error
# if the function errored, also render the exception and backtrace
showerror(output_io, result.value, result.backtrace)
elseif result.value !== nothing
# also show the returned value; some APIs don't print
write(output_io, string(result.value))
end

# determine some useful prefixes for FileCheck
prefixes = ["CHECK",
"JULIA$(VERSION.major)_$(VERSION.minor)",
"LLVM$(Base.libllvm_version.major)"]
## whether we use typed pointers or opaque pointers
if julia_typed_pointers
push!(prefixes, "TYPED")
else
push!(prefixes, "OPAQUE")
end
## whether we pass pointers as integers or as actual pointers
if VERSION >= v"1.12.0-DEV.225"
push!(prefixes, "PTR_ABI")
else
push!(prefixes, "INTPTR_ABI")
end

# now pass the collected output to FileCheck
seekstart(output_io)
filecheck_io = Pipe()
cmd = ```$(filecheck_exe())
--color
--allow-unused-prefixes
--check-prefixes $(join(prefixes, ','))
$path```
proc = run(pipeline(ignorestatus(cmd); stdin=output_io, stdout=filecheck_io, stderr=filecheck_io); wait=false)
close(filecheck_io.in)

# collect the output of FileCheck
reader = Threads.@spawn String(read(filecheck_io))
Base.wait(proc)
log = strip(fetch(reader))

# error out if FileCheck did not succeed.
# otherwise, return true so that `@test @filecheck` works as expected.
if !success(proc)
error(log)
end
return true
end
end

# collect checks used in the @filecheck block by piggybacking on macro expansion
const checks = String[]
macro check_str(str)
push!(checks, str)
nothing
end

macro filecheck(ex)
ex = Base.macroexpand(__module__, ex)
if isempty(checks)
error("No checks provided within the @filecheck macro block")
end
check_str = join(checks, "\n")
empty!(checks)

esc(quote
filecheck($check_str) do _
$ex
end
end)
end
using LLVM
const typed_ptrs = JuliaContext() do ctx
supports_typed_pointers(ctx)
end
const opaque_ptrs = !typed_ptrs
Loading
Loading