Skip to content

Commit 7229e2b

Browse files
authored
Fix construction of byval attribute. (#555)
1 parent c145ea3 commit 7229e2b

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/irgen.jl

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ function irgen(@nospecialize(job::CompilerJob))
8888
for arg in args
8989
if arg.cc == BITS_REF
9090
llvm_typ = convert(LLVMType, arg.typ)
91-
attr = @static if LLVM.version() >= v"12"
92-
TypeAttribute("byval", llvm_typ)
93-
else
94-
EnumAttribute("byval", 0)
95-
end
91+
attr = TypeAttribute("byval", llvm_typ)
9692
push!(parameter_attributes(entry, arg.idx), attr)
9793
end
9894
end
@@ -381,17 +377,10 @@ function lower_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.
381377

382378
# find the byval parameters
383379
byval = BitVector(undef, length(parameters(ft)))
384-
if LLVM.version() >= v"12"
385-
for i in 1:length(byval)
386-
attrs = collect(parameter_attributes(f, i))
387-
byval[i] = any(attrs) do attr
388-
kind(attr) == kind(EnumAttribute("byval", 0))
389-
end
390-
end
391-
else
392-
# XXX: byval is not round-trippable on LLVM < 12 (see maleadt/LLVM.jl#186)
393-
for arg in args
394-
byval[arg.idx] = (arg.cc == BITS_REF)
380+
for i in 1:length(byval)
381+
attrs = collect(parameter_attributes(f, i))
382+
byval[i] = any(attrs) do attr
383+
kind(attr) == kind(TypeAttribute("byval", LLVM.VoidType()))
395384
end
396385
end
397386

src/spirv.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function wrap_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.F
232232
for i in 1:length(byval)
233233
attrs = collect(parameter_attributes(f, i))
234234
byval[i] = any(attrs) do attr
235-
kind(attr) == kind(EnumAttribute("byval", 0))
235+
kind(attr) == kind(TypeAttribute("byval", LLVM.VoidType()))
236236
end
237237
end
238238
else
@@ -292,11 +292,7 @@ function wrap_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.F
292292
attrs = parameter_attributes(new_f, i)
293293
if byval[i]
294294
llvm_typ = convert(LLVMType, args[i].typ)
295-
if LLVM.version() >= v"12"
296-
push!(attrs, TypeAttribute("byval", LLVM.StructType([llvm_typ])))
297-
else
298-
push!(attrs, EnumAttribute("byval", 0))
299-
end
295+
push!(attrs, TypeAttribute("byval", LLVM.StructType([llvm_typ])))
300296
end
301297
end
302298

0 commit comments

Comments
 (0)