Skip to content

Commit 10d96db

Browse files
committed
Add back old byval code patch for LLVM < 12.
1 parent 1f87ce6 commit 10d96db

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/irgen.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,23 @@ function lower_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.
390390

391391
# find the byval parameters
392392
byval = BitVector(undef, length(parameters(ft)))
393-
for i in 1:length(byval)
394-
attrs = collect(parameter_attributes(f, i))
395-
byval[i] = any(attrs) do attr
396-
kind(attr) == kind(EnumAttribute("byval", 0; ctx))
393+
if LLVM.version() >= v"12"
394+
for i in 1:length(byval)
395+
attrs = collect(parameter_attributes(f, i))
396+
byval[i] = any(attrs) do attr
397+
kind(attr) == kind(EnumAttribute("byval", 0; ctx))
398+
end
399+
end
400+
else
401+
# XXX: byval is not round-trippable on LLVM < 12 (see maleadt/LLVM.jl#186)
402+
args = classify_arguments(job, f)
403+
filter!(args) do arg
404+
arg.cc != GHOST
405+
end
406+
for arg in args
407+
if arg.cc == BITS_REF
408+
byval[arg.codegen.i] = true
409+
end
397410
end
398411
end
399412

src/spirv.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,23 @@ function wrap_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.F
202202

203203
# find the byval parameters
204204
byval = BitVector(undef, length(parameters(ft)))
205-
for i in 1:length(byval)
206-
attrs = collect(parameter_attributes(f, i))
207-
byval[i] = any(attrs) do attr
208-
kind(attr) == kind(EnumAttribute("byval", 0; ctx))
205+
if LLVM.version() >= v"12"
206+
for i in 1:length(byval)
207+
attrs = collect(parameter_attributes(f, i))
208+
byval[i] = any(attrs) do attr
209+
kind(attr) == kind(EnumAttribute("byval", 0; ctx))
210+
end
211+
end
212+
else
213+
# XXX: byval is not round-trippable on LLVM < 12 (see maleadt/LLVM.jl#186)
214+
args = classify_arguments(job, f)
215+
filter!(args) do arg
216+
arg.cc != GHOST
217+
end
218+
for arg in args
219+
if arg.cc == BITS_REF
220+
byval[arg.codegen.i] = true
221+
end
209222
end
210223
end
211224

0 commit comments

Comments
 (0)