Skip to content

Commit e273d71

Browse files
committed
Metal: Emit name metadata, as required by macOS Sonoma.
1 parent a607fd5 commit e273d71

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/irgen.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,29 +261,34 @@ end
261261

262262
function classify_arguments(@nospecialize(job::CompilerJob), codegen_ft::LLVM.FunctionType)
263263
source_sig = job.source.specTypes
264-
265264
source_types = [source_sig.parameters...]
266265

266+
source_argnames = Base.method_argnames(job.source.def)
267+
while length(source_argnames) < length(source_types)
268+
# this is probably due to a trailing vararg; repeat its name
269+
push!(source_argnames, source_argnames[end])
270+
end
271+
267272
codegen_types = parameters(codegen_ft)
268273

269274
args = []
270275
codegen_i = 1
271-
for (source_i, source_typ) in enumerate(source_types)
276+
for (source_i, (source_typ, source_name)) in enumerate(zip(source_types, source_argnames))
272277
if isghosttype(source_typ) || Core.Compiler.isconstType(source_typ)
273-
push!(args, (cc=GHOST, typ=source_typ))
278+
push!(args, (cc=GHOST, typ=source_typ, name=source_name))
274279
continue
275280
end
276281

277282
codegen_typ = codegen_types[codegen_i]
278283
if codegen_typ isa LLVM.PointerType && !issized(eltype(codegen_typ))
279-
push!(args, (cc=MUT_REF, typ=source_typ,
284+
push!(args, (cc=MUT_REF, typ=source_typ, name=source_name,
280285
codegen=(typ=codegen_typ, i=codegen_i)))
281286
elseif codegen_typ isa LLVM.PointerType && issized(eltype(codegen_typ)) &&
282287
!(source_typ <: Ptr) && !(source_typ <: Core.LLVMPtr)
283-
push!(args, (cc=BITS_REF, typ=source_typ,
288+
push!(args, (cc=BITS_REF, typ=source_typ, name=source_name,
284289
codegen=(typ=codegen_typ, i=codegen_i)))
285290
else
286-
push!(args, (cc=BITS_VALUE, typ=source_typ,
291+
push!(args, (cc=BITS_VALUE, typ=source_typ, name=source_name,
287292
codegen=(typ=codegen_typ, i=codegen_i)))
288293
end
289294
codegen_i += 1

src/metal.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,12 @@ function add_argument_metadata!(@nospecialize(job::CompilerJob), mod::LLVM.Modul
699699
push!(md, MDString("air.arg_type_align_size"))
700700
push!(md, Metadata(ConstantInt(Int32(Base.datatype_alignment(arg_type)))))
701701

702+
push!(md, MDString("air.arg_type_name"))
703+
push!(md, MDString(repr(arg.typ)))
704+
705+
push!(md, MDString("air.arg_name"))
706+
push!(md, MDString(String(arg.name)))
707+
702708
push!(arg_infos, MDNode(md))
703709

704710
i += 1

0 commit comments

Comments
 (0)