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

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

errors
Expand Down
19 changes: 15 additions & 4 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,25 @@ function check_ir!(job, errors::Vector{IRError}, inst::LLVM.CallInst)
end

# helper function to check if a LLVM module uses values of a certain type
function check_ir_values(mod::LLVM.Module, T_bad::LLVMType)
function check_ir_values(mod::LLVM.Module, T_bad::LLVMType; allow=())
errors = IRError[]

for fun in functions(mod), bb in blocks(fun), inst in instructions(bb)
if value_type(inst) == T_bad || any(param->value_type(param) == T_bad, operands(inst))
bt = backtrace(inst)
push!(errors, ("use of $(string(T_bad)) value", bt, inst))
if typeof(inst) in allow
continue
end

if haskey(metadata(inst), "ir_check_ignore")
continue
end

if value_type(inst) != T_bad &&
all(op -> value_type(op) != T_bad || (op isa Instruction && haskey(metadata(op), "ir_check_ignore")), operands(inst))
continue
end

bt = backtrace(inst)
push!(errors, ("use of $(string(T_bad)) value", bt, inst))
end

return errors
Expand Down