@@ -269,32 +269,24 @@ end
269269function wrap_byval (@nospecialize (job:: CompilerJob ), mod:: LLVM.Module , f:: LLVM.Function )
270270 ft = function_type (f):: LLVM.FunctionType
271271
272- args = classify_arguments (job, ft)
273- filter! (args) do arg
274- arg. cc != GHOST
275- end
276-
277272 # find the byval parameters
278273 byval = BitVector (undef, length (parameters (ft)))
279- if LLVM. version () >= v " 12"
280- for i in 1 : length (byval)
281- attrs = collect (parameter_attributes (f, i))
282- byval[i] = any (attrs) do attr
283- kind (attr) == kind (TypeAttribute (" byval" , LLVM. VoidType ()))
274+ types = Vector {LLVMType} (undef, length (parameters (ft)))
275+ for i in 1 : length (byval)
276+ byval[i] = false
277+ for attr in collect (parameter_attributes (f, i))
278+ if kind (attr) == kind (TypeAttribute (" byval" , LLVM. VoidType ()))
279+ byval[i] = true
280+ types[i] = value (attr)
284281 end
285282 end
286- else
287- # XXX : byval is not round-trippable on LLVM < 12 (see maleadt/LLVM.jl#186)
288- for arg in args
289- byval[arg. idx] = (arg. cc == BITS_REF)
290- end
291283 end
292284
293285 # generate the wrapper function type & definition
294286 new_types = LLVM. LLVMType[]
295287 for (i, param) in enumerate (parameters (ft))
296288 typ = if byval[i]
297- llvm_typ = convert (LLVMType, args [i]. typ )
289+ llvm_typ = convert (LLVMType, types [i])
298290 st = LLVM. StructType ([llvm_typ])
299291 LLVM. PointerType (st, addrspace (param))
300292 else
@@ -318,7 +310,7 @@ function wrap_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.F
318310 # perform argument conversions
319311 for (i, param) in enumerate (parameters (new_f))
320312 if byval[i]
321- llvm_typ = convert (LLVMType, args [i]. typ )
313+ llvm_typ = convert (LLVMType, types [i])
322314 ptr = struct_gep! (builder, LLVM. StructType ([llvm_typ]), param, 0 )
323315 push! (new_args, ptr)
324316 else
@@ -339,7 +331,7 @@ function wrap_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.F
339331 for i in 1 : length (byval)
340332 attrs = parameter_attributes (new_f, i)
341333 if byval[i]
342- llvm_typ = convert (LLVMType, args [i]. typ )
334+ llvm_typ = convert (LLVMType, types [i])
343335 push! (attrs, TypeAttribute (" byval" , LLVM. StructType ([llvm_typ])))
344336 end
345337 end
0 commit comments