From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1880) id BCD413858D1E; Sat, 14 Jan 2023 18:03:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BCD413858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673719419; bh=gVeR1HL4putVyWmxKg1vCGT0ZrYMiEOsStBktxazz/Y=; h=From:To:Subject:Date:From; b=eIU5OqJqAD2R0uN5LQKluY5gQIyMm9KpQn/mJ4ufhNJTXN12mYu0gG2QlRe3OR0YY 31jiRWcdvxZLoWMM2I/1ToIRGucE1t55r78ZiXMnFMsWeJhWgH92w/+11GHrCHhNCu Hng1wGS/eu3XQruNh/EYSUhGPkGQOJJVc//iWgvM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Max Filippov To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5167] xtensa: Remove old broken tweak for leaf function X-Act-Checkin: gcc X-Git-Author: Takayuki 'January June' Suwa X-Git-Refname: refs/heads/master X-Git-Oldrev: a3b99b84609af310c72b4d6221621f5b63a3c169 X-Git-Newrev: ff6c7617102df365918402c6ccc8e497c47dbe60 Message-Id: <20230114180339.BCD413858D1E@sourceware.org> Date: Sat, 14 Jan 2023 18:03:39 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ff6c7617102df365918402c6ccc8e497c47dbe60 commit r13-5167-gff6c7617102df365918402c6ccc8e497c47dbe60 Author: Takayuki 'January June' Suwa Date: Sat Jan 14 14:03:55 2023 +0900 xtensa: Remove old broken tweak for leaf function In the before-IRA era, ORDER_REGS_FOR_LOCAL_ALLOC was called for each function in Xtensa, and there was register allocation table reordering for leaf functions to compensate for the poor performance of local-alloc. Today the adjustment hook is still called via its alternative ADJUST_REG_ALLOC_ORDER, but it is only called once at the start of the IRA, and leaf_function_p() erroneously returns true and also gives no argument count. That straightforwardly misleads register allocation that all functions are always leaves with no arguments, which leads to inefficiencies in allocation results. Fortunately, IRA is smart enough than local-alloc to not need such assistance. This patch does away with the antiquated by removing the wreckage that no longer works. gcc/ChangeLog: * config/xtensa/xtensa-protos.h (order_regs_for_local_alloc): Rename to xtensa_adjust_reg_alloc_order. * config/xtensa/xtensa.cc (xtensa_adjust_reg_alloc_order): Ditto. And also remove code to reorder register numbers for leaf functions, rename the tables, and adjust the allocation order for the call0 ABI to use register A0 more. (xtensa_leaf_regs): Remove. * config/xtensa/xtensa.h (REG_ALLOC_ORDER): Cosmetics. (order_regs_for_local_alloc): Rename as the above. (LEAF_REGISTERS, LEAF_REG_REMAP, leaf_function): Remove. Diff: --- gcc/config/xtensa/xtensa-protos.h | 2 +- gcc/config/xtensa/xtensa.cc | 75 ++++++++------------------------------- gcc/config/xtensa/xtensa.h | 51 ++++++++------------------ 3 files changed, 30 insertions(+), 98 deletions(-) diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h index 91a215e535d..7b5790c5fc4 100644 --- a/gcc/config/xtensa/xtensa-protos.h +++ b/gcc/config/xtensa/xtensa-protos.h @@ -78,7 +78,7 @@ extern long compute_frame_size (poly_int64); extern bool xtensa_use_return_instruction_p (void); extern void xtensa_expand_prologue (void); extern void xtensa_expand_epilogue (bool); -extern void order_regs_for_local_alloc (void); +extern void xtensa_adjust_reg_alloc_order (void); extern enum reg_class xtensa_regno_to_class (int regno); extern HOST_WIDE_INT xtensa_initial_elimination_offset (int from, int to); extern const char **xtensa_get_config_strings (void); diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index 6cf6b35399a..9b363bdbf9e 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -107,18 +107,6 @@ struct GTY(()) machine_function rtx last_logues_a9_content; }; -/* Vector, indexed by hard register number, which contains 1 for a - register that is allowable in a candidate for leaf function - treatment. */ - -const char xtensa_leaf_regs[FIRST_PSEUDO_REGISTER] = -{ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1 -}; - static void xtensa_option_override (void); static enum internal_test map_test_to_internal_test (enum rtx_code); static rtx gen_int_relational (enum rtx_code, rtx, rtx); @@ -4140,58 +4128,25 @@ xtensa_secondary_reload (bool in_p, rtx x, reg_class_t rclass, return NO_REGS; } +/* Called once at the start of IRA, by ADJUST_REG_ALLOC_ORDER. */ void -order_regs_for_local_alloc (void) +xtensa_adjust_reg_alloc_order (void) { - if (!leaf_function_p ()) - { - static const int reg_nonleaf_alloc_order[FIRST_PSEUDO_REGISTER] = + static const int reg_windowed_alloc_order[FIRST_PSEUDO_REGISTER] = REG_ALLOC_ORDER; - static const int reg_nonleaf_alloc_order_call0[FIRST_PSEUDO_REGISTER] = - { - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 12, 13, 14, 15, - 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 0, 1, 16, 17, - 35, - }; - - memcpy (reg_alloc_order, TARGET_WINDOWED_ABI ? - reg_nonleaf_alloc_order : reg_nonleaf_alloc_order_call0, - FIRST_PSEUDO_REGISTER * sizeof (int)); - } - else - { - int i, num_arg_regs; - int nxt = 0; - - /* Use the AR registers in increasing order (skipping a0 and a1) - but save the incoming argument registers for a last resort. */ - num_arg_regs = crtl->args.info.arg_words; - if (num_arg_regs > MAX_ARGS_IN_REGISTERS) - num_arg_regs = MAX_ARGS_IN_REGISTERS; - for (i = GP_ARG_FIRST; i < 16 - num_arg_regs; i++) - reg_alloc_order[nxt++] = i + num_arg_regs; - for (i = 0; i < num_arg_regs; i++) - reg_alloc_order[nxt++] = GP_ARG_FIRST + i; - - /* List the coprocessor registers in order. */ - for (i = 0; i < BR_REG_NUM; i++) - reg_alloc_order[nxt++] = BR_REG_FIRST + i; - - /* List the FP registers in order for now. */ - for (i = 0; i < 16; i++) - reg_alloc_order[nxt++] = FP_REG_FIRST + i; - - /* GCC requires that we list *all* the registers.... */ - reg_alloc_order[nxt++] = 0; /* a0 = return address */ - reg_alloc_order[nxt++] = 1; /* a1 = stack pointer */ - reg_alloc_order[nxt++] = 16; /* pseudo frame pointer */ - reg_alloc_order[nxt++] = 17; /* pseudo arg pointer */ - - reg_alloc_order[nxt++] = ACC_REG_FIRST; /* MAC16 accumulator */ - } + static const int reg_call0_alloc_order[FIRST_PSEUDO_REGISTER] = + { + 9, 10, 11, 7, 6, 5, 4, 3, 2, 8, 0, 12, 13, 14, 15, + 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 1, 16, 17, + 35, + }; + + memcpy (reg_alloc_order, TARGET_WINDOWED_ABI ? + reg_windowed_alloc_order : reg_call0_alloc_order, + FIRST_PSEUDO_REGISTER * sizeof (int)); } diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h index a7c112b8753..6fcf45fbdfe 100644 --- a/gcc/config/xtensa/xtensa.h +++ b/gcc/config/xtensa/xtensa.h @@ -238,44 +238,21 @@ along with GCC; see the file COPYING3. If not see 1, \ } -/* For non-leaf procedures on Xtensa processors, the allocation order - is as specified below by REG_ALLOC_ORDER. For leaf procedures, we - want to use the lowest numbered registers first to minimize - register window overflows. However, local-alloc is not smart - enough to consider conflicts with incoming arguments. If an - incoming argument in a2 is live throughout the function and - local-alloc decides to use a2, then the incoming argument must - either be spilled or copied to another register. To get around - this, we define ADJUST_REG_ALLOC_ORDER to redefine - reg_alloc_order for leaf functions such that lowest numbered - registers are used first with the exception that the incoming - argument registers are not used until after other register choices - have been exhausted. */ - -#define REG_ALLOC_ORDER \ -{ 8, 9, 10, 11, 12, 13, 14, 15, 7, 6, 5, 4, 3, 2, \ - 18, \ - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, \ - 0, 1, 16, 17, \ - 35, \ -} - -#define ADJUST_REG_ALLOC_ORDER order_regs_for_local_alloc () - -/* For Xtensa, the only point of this is to prevent GCC from otherwise - giving preference to call-used registers. To minimize window - overflows for the AR registers, we want to give preference to the - lower-numbered AR registers. For other register files, which are - not windowed, we still prefer call-used registers, if there are any. */ -extern const char xtensa_leaf_regs[FIRST_PSEUDO_REGISTER]; -#define LEAF_REGISTERS xtensa_leaf_regs +/* For the windowed register ABI on Xtensa processors, the allocation + order is as specified below by REG_ALLOC_ORDER. + For the call0 ABI, on the other hand, ADJUST_REG_ALLOC_ORDER hook + will be called once at the start of IRA, replacing it with the + appropriate one. */ -/* For Xtensa, no remapping is necessary, but this macro must be - defined if LEAF_REGISTERS is defined. */ -#define LEAF_REG_REMAP(REGNO) ((int) (REGNO)) - -/* This must be declared if LEAF_REGISTERS is set. */ -extern int leaf_function; +#define REG_ALLOC_ORDER \ +{ \ + 8, 9, 10, 11, 12, 13, 14, 15, 7, 6, 5, 4, 3, 2, \ + 18, \ + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, \ + 0, 1, 16, 17, \ + 35, \ +} +#define ADJUST_REG_ALLOC_ORDER xtensa_adjust_reg_alloc_order () /* Internal macros to classify a register number. */