Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
function call lowering, darwin, aarch64: Provide control over stack l…
…ayout and packing. 1. Generic : Mega-hack to allow different passing organisation for variadic funcs. Right now, the generic code assumes that it can determine the stack layout from target callbacks that don't have complete information about the argument they are processing (they only know the mode and the type - not it the argument is named or not, for example). This hack is not complete - but makes some progress. It looks like we really need the option for a target to override the layout process - if it requires distinct stack layouts for different calling convs. 2. Add cumulative_args_t variants of TARGET_FUNCTION_ROUND_BOUNDARY and friends The two target hooks responsible for informing GCC about stack parameter alignment are `TARGET_FUNCTION_ARG_BOUNDARY` and `TARGET_FUNCTION_ARG_ROUND_BOUNDARY`, which currently only consider the tree and machine_mode of a specific given argument. Create two new target hooks suffixed with '_CA', and pass in a third `cumulative_args_t` parameter. This enables the backend to make alignment decisions based on the context of the whole function rather than individual parameters. The orignal machine_mode/tree type macros are not removed - they are called by the default implementations of `TARGET_...BOUNDARY_CA` and `TARGET_...ROUND_BOUNDARY_CA`. This is done with the intetnion of avoiding large mechanical modifications of nearly every backend in GCC. There is also a new flag, -fstack-use-cumulative-args, which provides a way to completely bypass the new `..._CA` macros. This feature is intended for debugging GCC itself. gcc/ChangeLog: * calls.c (initialize_argument_information): Pass `args_so_far`. * common.opt: New flag `-fstack-use-cumulative-args`. * config.gcc: No platforms currently use ..._CA-hooks: Set -fstack-use-cumulative-args to be off by default. * target.h (cumulative_args_t): Move declaration from here, to... * cumulative-args.h (cumulative_args_t): ...this new file. This is to permit backends to include the declaration of cumulative_args_t without dragging in circular dependencies. * function.c (assign_parm_find_entry_rtl): Provide cumulative_args_t to locate_and_pad_parm. (gimplify_parameters): Ditto. (locate_and_pad_parm): Conditionally call new hooks if we're invoked with -fstack-use-cumulative-args. * function.h: Include cumulative-args.h. (locate_and_pad_parm): Add cumulative_args_t parameter. * target.def (function_arg_boundary_ca): Add. (function_arg_round_boundary_ca): Ditto. * targhooks.c (default_function_arg_boundary_ca): Implement. (default_function_arg_round_boundary_ca): Ditto. * targhooks.h (default_function_arg_boundary_ca): Declare. (default_function_arg_round_boundary_ca): Ditto. * doc/invoke.texi (-fstack-use-cumulative-args): Document. * doc/tm.texi: Regenerate. * doc/tm.texi.in: Ditto. 3. Implement TARGET_..._CA target hooks for AArch64 Darwin The AArch64 Darwin platform requires that named stack arguments are passed naturally-aligned, while variadic stack arguments are passed on word boundaries. Use the TARGET_FUNCTION_ARG_BOUNDARY_CA and TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA target hooks to let the backend correctly layout stack parameters. gcc/ChangeLog: * config.gcc: Enable -fstack-use-cumulative-args by default if the host platform is MacOS 11.x or 12.x and we're on AArch64. gcc/config/aarch64/ChangeLog: * aarch64-protos.h (aarch64_init_cumulative_incoming_args): Declare. * aarch64.c (aarch64_init_cumulative_args): Initialize `darwinpcs_n_named` (Total number of named parameters) and `darwinpcs_n_args_processed` (Total number of parameters we have processed, including variadic if any.) (aarch64_init_cumulative_incoming_args): Implement the INIT_CUMULATIVE_INCOMING_ARGS macro in order to capture information on the number of named parameters for the current function. (aarch64_function_arg_advance): Increment `darwinpcs_n_args_processed` each time we layout a function parameter. (aarch64_function_arg_boundary_ca): Implement TARGET_FUNCTION_ARG_BOUNDARY_CA and TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA to layout args based on whether we're a named parameter or not. (aarch64_function_arg_round_boundary_ca): Ditto. (TARGET_FUNCTION_ARG_BOUNDARY_CA): Define. (TARGET_FUNCTION_ARG_ROUND_BOUNDARY_CA): Ditto. * aarch64.h (CUMULATIVE_ARGS): Add `darwinpcs_n_named` and `darwinpcs_n_args_processed`. (INIT_CUMULATIVE_INCOMING_ARGS): Define. 3. aarch64, Darwin: Rework varargs handling to use cumulative args. Maybe incomplete. Currently this builds the information twice once during arg layout and once during the value lookup - and checks we get the same result - looking for any asserts before we enable the simplified version. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> gcc/ChangeLog: * config.gcc: * config/aarch64/aarch64.c (aarch64_layout_arg): (aarch64_init_cumulative_args): (aarch64_function_arg_boundary_ca): (aarch64_function_arg_round_boundary_ca): (aarch64_setup_incoming_varargs): * config/aarch64/aarch64.h:
- Loading branch information