Skip to content

Commit b72c614

Browse files
committed
Run Metal's ABI conversions on the linked module.
This makes it possible to use intrinsics in deferred compilations.
1 parent 7cde319 commit b72c614

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/metal.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ runtime_slug(job::CompilerJob{MetalCompilerTarget}) = "metal-macos$(job.config.t
4747
isintrinsic(@nospecialize(job::CompilerJob{MetalCompilerTarget}), fn::String) =
4848
return startswith(fn, "air.")
4949

50-
function finish_module!(@nospecialize(job::CompilerJob{MetalCompilerTarget}), mod::LLVM.Module, entry::LLVM.Function)
51-
entry_fn = LLVM.name(entry)
52-
53-
# update calling conventions
54-
if job.config.kernel
55-
entry = pass_by_reference!(job, mod, entry)
56-
entry = add_input_arguments!(job, mod, entry, kernel_intrinsics)
50+
function finish_linked_module!(@nospecialize(job::CompilerJob{MetalCompilerTarget}), mod::LLVM.Module)
51+
if haskey(metadata(mod), "julia.kernel")
52+
kernels_md = metadata(mod)["julia.kernel"]
53+
for kernel_md in operands(kernels_md)
54+
f = LLVM.Value(operands(kernel_md)[1])::LLVM.Function
55+
56+
# update calling conventions
57+
f = pass_by_reference!(job, mod, f)
58+
f = add_input_arguments!(job, mod, f, kernel_intrinsics)
59+
end
5760
end
5861

5962
# emit the AIR and Metal version numbers as constants in the module. this makes it
@@ -83,7 +86,7 @@ function finish_module!(@nospecialize(job::CompilerJob{MetalCompilerTarget}), mo
8386
run!(pb, mod)
8487
end
8588

86-
return functions(mod)[entry_fn]
89+
return
8790
end
8891

8992
function validate_ir(job::CompilerJob{MetalCompilerTarget}, mod::LLVM.Module)

0 commit comments

Comments
 (0)