Skip to content

Add exceptions to check_ir_values #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 21, 2024
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