@@ -47,13 +47,16 @@ runtime_slug(job::CompilerJob{MetalCompilerTarget}) = "metal-macos$(job.config.t
4747isintrinsic (@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
8790end
8891
8992function validate_ir (job:: CompilerJob{MetalCompilerTarget} , mod:: LLVM.Module )
0 commit comments