Skip to content
Merged
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
24 changes: 0 additions & 24 deletions src/spirv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ end
# The SPIRV Tools don't handle Julia's debug info, rejecting DW_LANG_Julia...
strip_debuginfo!(mod)

# the LLVM to SPIR-V translator does not support the freeze instruction
# (SPIRV-LLVM-Translator#1140)
rm_freeze!(job, mod)

# translate to SPIR-V
input = bitcode(mod)
dump_input() = let path = tempname(cleanup=false) * ".bc"
Expand Down Expand Up @@ -905,26 +901,6 @@ end

## LLVM passes

# remove freeze and replace uses by the original value
# (KhronosGroup/SPIRV-LLVM-Translator#1140)
function rm_freeze!(@nospecialize(job::CompilerJob), mod::LLVM.Module)
changed = false
@tracepoint "remove freeze" begin

for f in mod.functions, bb in f.blocks, inst in bb.instructions
if inst isa LLVM.FreezeInst
orig = first(inst.operands)
replace_uses!(inst, orig)
@compiler_assert isempty(inst.uses) job
erase!(inst)
changed = true
end
end

end
return changed
end

# flatten `insertvalue`s with multiple indices into single-index ones, extracting and
# re-inserting the intermediate aggregates: `insertvalue %agg, %val, 1, 0` becomes
# %sub = extractvalue %agg, 1
Expand Down
23 changes: 23 additions & 0 deletions test/spirv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,29 @@ end
end
end

@testset "freeze" begin
# both back-ends lower `freeze` themselves, so it must reach them
mod = @eval module $(gensym())
frozen(x::Int32) = Base.llvmcall("""
%y = freeze i32 %0
ret i32 %y""", Int32, Tuple{Int32}, x)
function kernel(out::Ptr{Int32}, x::Int32)
unsafe_store!(out, frozen(x))
return
end
end

@test @filecheck begin
@check "freeze i32"
SPIRV.code_llvm(mod.kernel, Tuple{Ptr{Int32}, Int32}; backend, kernel=true)
end

@test @filecheck begin
@check "OpStore"
SPIRV.code_native(mod.kernel, Tuple{Ptr{Int32}, Int32}; backend, kernel=true)
end
end

end

@testset "min and max lowering" begin
Expand Down
Loading