[s390x, abi_impl] Support struct args using explicit pointers (#4585)
This adds support for StructArgument on s390x. The ABI for this platform requires that the address of the buffer holding the copy of the struct argument is passed from caller to callee as hidden pointer, using a register or overflow stack slot. To implement this, I've added an optional "pointer" filed to ABIArg::StructArg, and code to handle the pointer both in common abi_impl code and the s390x back-end. One notable change necessary to make this work involved the "copy_to_arg_order" mechanism. Currently, for struct args we only need to copy the data (and that need to happen before setting up any other args), while for non-struct args we only need to set up the appropriate registers or stack slots. This order is ensured by sorting the arguments appropriately into a "copy_to_arg_order" list. However, for struct args with explicit pointers we need to *both* copy the data (again, before everything else), *and* set up a register or stack slot. Since we now need to touch the argument twice, we cannot solve the ordering problem by a simple sort. Instead, the abi_impl common code now provided *two* callbacks, emit_copy_regs_to_buffer and emit_copy_regs_to_arg, and expects the back end to first call copy..to_buffer for all args, and then call copy.._to_arg for all args. This required updates to all back ends. In the s390x back end, in addition to the new ABI code, I'm now adding code to actually copy the struct data, using the MVC instruction (for small buffers) or a memcpy libcall (for larger buffers). This also requires a bit of new infrastructure: - MVC is the first memory-to-memory instruction we use, which needed a bit of memory argument tweaking - We also need to set up the infrastructure to emit libcalls. (This implements the first half of issue #4565.)
This commit is contained in:
@@ -3591,16 +3591,30 @@
|
||||
(_ InstOutput (side_effect (abi_call_ind abi target (Opcode.CallIndirect)))))
|
||||
(lower_call_rets abi (range 0 (abi_num_rets abi)) (output_builder_new))))
|
||||
|
||||
;; Lower function arguments by loading them into registers / stack slots.
|
||||
;; Lower function arguments.
|
||||
(decl lower_call_args (ABISig Range ValueSlice) InstOutput)
|
||||
(rule (lower_call_args abi (range_empty) _) (lower_call_ret_arg abi))
|
||||
(rule (lower_call_args abi (range_unwrap head tail) args)
|
||||
(let ((idx usize (abi_copy_to_arg_order abi head))
|
||||
(_ Unit (copy_to_arg 0 (abi_get_arg abi idx)
|
||||
(value_slice_get args idx))))
|
||||
(lower_call_args abi tail args)))
|
||||
(rule (lower_call_args abi range args)
|
||||
(let ((_ InstOutput (lower_call_args_buffer abi range args))
|
||||
(_ InstOutput (lower_call_args_slots abi range args)))
|
||||
(lower_call_ret_arg abi)))
|
||||
|
||||
;; Lower the implicit return-area pointer argument, if present.
|
||||
;; Lower function arguments (part 1): prepare buffer copies.
|
||||
(decl lower_call_args_buffer (ABISig Range ValueSlice) InstOutput)
|
||||
(rule (lower_call_args_buffer abi (range_empty) _) (output_none))
|
||||
(rule (lower_call_args_buffer abi (range_unwrap head tail) args)
|
||||
(let ((_ InstOutput (copy_to_buffer 0 (abi_get_arg abi head)
|
||||
(value_slice_get args head))))
|
||||
(lower_call_args_buffer abi tail args)))
|
||||
|
||||
;; Lower function arguments (part 2): set up registers / stack slots.
|
||||
(decl lower_call_args_slots (ABISig Range ValueSlice) InstOutput)
|
||||
(rule (lower_call_args_slots abi (range_empty) _) (output_none))
|
||||
(rule (lower_call_args_slots abi (range_unwrap head tail) args)
|
||||
(let ((_ Unit (copy_to_arg 0 (abi_get_arg abi head)
|
||||
(value_slice_get args head))))
|
||||
(lower_call_args_slots abi tail args)))
|
||||
|
||||
;; Lower function arguments (part 3): implicit return-area pointer.
|
||||
(decl lower_call_ret_arg (ABISig) InstOutput)
|
||||
(rule (lower_call_ret_arg (abi_no_ret_arg)) (output_none))
|
||||
(rule (lower_call_ret_arg abi @ (abi_ret_arg (abi_arg_only_slot slot)))
|
||||
|
||||
Reference in New Issue
Block a user