Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 25 additions & 1 deletion src/metal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,32 @@ end
function validate_ir(job::CompilerJob{MetalCompilerTarget}, mod::LLVM.Module)
errors = IRError[]

function is_illegal_double_use(val)
if value_type(val) != LLVM.DoubleType()
return false
end

function used_for_logging(use::LLVM.Use)
usr = user(use)
if usr isa LLVM.CallInst
callee = called_operand(usr)
if callee isa LLVM.Function && startswith(name(callee), "metal_os_log")
return true
end
end

return false
end

if all(used_for_logging, uses(val))
return false
end

return true
end

# Metal never supports double precision
append!(errors, check_ir_values(mod, LLVM.DoubleType()))
append!(errors, check_ir_values(mod, is_illegal_double_use))
append!(errors, check_ir_values(mod, LLVM.IntType(128)))

errors
Expand Down
13 changes: 13 additions & 0 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,16 @@ function check_ir_values(mod::LLVM.Module, T_bad::LLVMType)

return errors
end

function check_ir_values(mod::LLVM.Module, T_bad)
errors = IRError[]

for fun in functions(mod), bb in blocks(fun), inst in instructions(bb)
if T_bad(inst) || any(T_bad, operands(inst))
bt = backtrace(inst)
push!(errors, ("use of $(string(inst))", bt, inst))
end
end

return errors
end