LCOV - code coverage report
Current view: top level - gcc - lra-constraints.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 86.7 % 3766 3267
Test Date: 2025-09-20 13:40:47 Functions: 89.7 % 107 96
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Code for RTL transformations to satisfy insn constraints.
       2                 :             :    Copyright (C) 2010-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
       4                 :             : 
       5                 :             :    This file is part of GCC.
       6                 :             : 
       7                 :             :    GCC is free software; you can redistribute it and/or modify it under
       8                 :             :    the terms of the GNU General Public License as published by the Free
       9                 :             :    Software Foundation; either version 3, or (at your option) any later
      10                 :             :    version.
      11                 :             : 
      12                 :             :    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             :    WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             :    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             :    for more details.
      16                 :             : 
      17                 :             :    You should have received a copy of the GNU General Public License
      18                 :             :    along with GCC; see the file COPYING3.  If not see
      19                 :             :    <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : 
      22                 :             : /* This file contains code for 3 passes: constraint pass,
      23                 :             :    inheritance/split pass, and pass for undoing failed inheritance and
      24                 :             :    split.
      25                 :             : 
      26                 :             :    The major goal of constraint pass is to transform RTL to satisfy
      27                 :             :    insn and address constraints by:
      28                 :             :      o choosing insn alternatives;
      29                 :             :      o generating *reload insns* (or reloads in brief) and *reload
      30                 :             :        pseudos* which will get necessary hard registers later;
      31                 :             :      o substituting pseudos with equivalent values and removing the
      32                 :             :        instructions that initialized those pseudos.
      33                 :             : 
      34                 :             :    The constraint pass has biggest and most complicated code in LRA.
      35                 :             :    There are a lot of important details like:
      36                 :             :      o reuse of input reload pseudos to simplify reload pseudo
      37                 :             :        allocations;
      38                 :             :      o some heuristics to choose insn alternative to improve the
      39                 :             :        inheritance;
      40                 :             :      o early clobbers etc.
      41                 :             : 
      42                 :             :    The pass is mimicking former reload pass in alternative choosing
      43                 :             :    because the reload pass is oriented to current machine description
      44                 :             :    model.  It might be changed if the machine description model is
      45                 :             :    changed.
      46                 :             : 
      47                 :             :    There is special code for preventing all LRA and this pass cycling
      48                 :             :    in case of bugs.
      49                 :             : 
      50                 :             :    On the first iteration of the pass we process every instruction and
      51                 :             :    choose an alternative for each one.  On subsequent iterations we try
      52                 :             :    to avoid reprocessing instructions if we can be sure that the old
      53                 :             :    choice is still valid.
      54                 :             : 
      55                 :             :    The inheritance/spilt pass is to transform code to achieve
      56                 :             :    ineheritance and live range splitting.  It is done on backward
      57                 :             :    traversal of EBBs.
      58                 :             : 
      59                 :             :    The inheritance optimization goal is to reuse values in hard
      60                 :             :    registers. There is analogous optimization in old reload pass.  The
      61                 :             :    inheritance is achieved by following transformation:
      62                 :             : 
      63                 :             :        reload_p1 <- p             reload_p1 <- p
      64                 :             :        ...                   new_p <- reload_p1
      65                 :             :        ...              =>   ...
      66                 :             :        reload_p2 <- p             reload_p2 <- new_p
      67                 :             : 
      68                 :             :    where p is spilled and not changed between the insns.  Reload_p1 is
      69                 :             :    also called *original pseudo* and new_p is called *inheritance
      70                 :             :    pseudo*.
      71                 :             : 
      72                 :             :    The subsequent assignment pass will try to assign the same (or
      73                 :             :    another if it is not possible) hard register to new_p as to
      74                 :             :    reload_p1 or reload_p2.
      75                 :             : 
      76                 :             :    If the assignment pass fails to assign a hard register to new_p,
      77                 :             :    this file will undo the inheritance and restore the original code.
      78                 :             :    This is because implementing the above sequence with a spilled
      79                 :             :    new_p would make the code much worse.  The inheritance is done in
      80                 :             :    EBB scope.  The above is just a simplified example to get an idea
      81                 :             :    of the inheritance as the inheritance is also done for non-reload
      82                 :             :    insns.
      83                 :             : 
      84                 :             :    Splitting (transformation) is also done in EBB scope on the same
      85                 :             :    pass as the inheritance:
      86                 :             : 
      87                 :             :        r <- ... or ... <- r                r <- ... or ... <- r
      88                 :             :        ...                               s <- r (new insn -- save)
      89                 :             :        ...                        =>
      90                 :             :        ...                               r <- s (new insn -- restore)
      91                 :             :        ... <- r                               ... <- r
      92                 :             : 
      93                 :             :     The *split pseudo* s is assigned to the hard register of the
      94                 :             :     original pseudo or hard register r.
      95                 :             : 
      96                 :             :     Splitting is done:
      97                 :             :       o In EBBs with high register pressure for global pseudos (living
      98                 :             :         in at least 2 BBs) and assigned to hard registers when there
      99                 :             :         are more one reloads needing the hard registers;
     100                 :             :       o for pseudos needing save/restore code around calls.
     101                 :             : 
     102                 :             :     If the split pseudo still has the same hard register as the
     103                 :             :     original pseudo after the subsequent assignment pass or the
     104                 :             :     original pseudo was split, the opposite transformation is done on
     105                 :             :     the same pass for undoing inheritance.  */
     106                 :             : 
     107                 :             : #undef REG_OK_STRICT
     108                 :             : 
     109                 :             : #include "config.h"
     110                 :             : #include "system.h"
     111                 :             : #include "coretypes.h"
     112                 :             : #include "backend.h"
     113                 :             : #include "hooks.h"
     114                 :             : #include "target.h"
     115                 :             : #include "rtl.h"
     116                 :             : #include "tree.h"
     117                 :             : #include "stmt.h"
     118                 :             : #include "predict.h"
     119                 :             : #include "df.h"
     120                 :             : #include "memmodel.h"
     121                 :             : #include "tm_p.h"
     122                 :             : #include "expmed.h"
     123                 :             : #include "optabs.h"
     124                 :             : #include "regs.h"
     125                 :             : #include "ira.h"
     126                 :             : #include "recog.h"
     127                 :             : #include "output.h"
     128                 :             : #include "addresses.h"
     129                 :             : #include "expr.h"
     130                 :             : #include "cfgrtl.h"
     131                 :             : #include "rtl-error.h"
     132                 :             : #include "lra.h"
     133                 :             : #include "lra-int.h"
     134                 :             : #include "print-rtl.h"
     135                 :             : #include "function-abi.h"
     136                 :             : #include "rtl-iter.h"
     137                 :             : 
     138                 :             : /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
     139                 :             :    insn.  Remember that LRA_CURR_RELOAD_NUM is the number of emitted
     140                 :             :    reload insns.  */
     141                 :             : static int bb_reload_num;
     142                 :             : 
     143                 :             : /* The current insn being processed and corresponding its single set
     144                 :             :    (NULL otherwise), its data (basic block, the insn data, the insn
     145                 :             :    static data, and the mode of each operand).  */
     146                 :             : static rtx_insn *curr_insn;
     147                 :             : static rtx curr_insn_set;
     148                 :             : static basic_block curr_bb;
     149                 :             : static lra_insn_recog_data_t curr_id;
     150                 :             : static struct lra_static_insn_data *curr_static_id;
     151                 :             : static machine_mode curr_operand_mode[MAX_RECOG_OPERANDS];
     152                 :             : /* Mode of the register substituted by its equivalence with VOIDmode
     153                 :             :    (e.g. constant) and whose subreg is given operand of the current
     154                 :             :    insn.  VOIDmode in all other cases.  */
     155                 :             : static machine_mode original_subreg_reg_mode[MAX_RECOG_OPERANDS];
     156                 :             : /* The first call insn after curr_insn within the EBB during inherit_in_ebb
     157                 :             :    or NULL outside of that function.  */
     158                 :             : static rtx_insn *first_call_insn;
     159                 :             : 
     160                 :             : 
     161                 :             : 
     162                 :             : /* Start numbers for new registers and insns at the current constraints
     163                 :             :    pass start.  */
     164                 :             : static int new_regno_start;
     165                 :             : static int new_insn_uid_start;
     166                 :             : 
     167                 :             : /* If LOC is nonnull, strip any outer subreg from it.  */
     168                 :             : static inline rtx *
     169                 :   229636808 : strip_subreg (rtx *loc)
     170                 :             : {
     171                 :   101438141 :   return loc && GET_CODE (*loc) == SUBREG ? &SUBREG_REG (*loc) : loc;
     172                 :             : }
     173                 :             : 
     174                 :             : /* Return hard regno of REGNO or if it is was not assigned to a hard
     175                 :             :    register, use a hard register from its allocno class.  */
     176                 :             : static int
     177                 :       70826 : get_try_hard_regno (int regno)
     178                 :             : {
     179                 :       70826 :   int hard_regno;
     180                 :       70826 :   enum reg_class rclass;
     181                 :             : 
     182                 :       70826 :   if ((hard_regno = regno) >= FIRST_PSEUDO_REGISTER)
     183                 :       70826 :     hard_regno = lra_get_regno_hard_regno (regno);
     184                 :       70826 :   if (hard_regno >= 0)
     185                 :             :     return hard_regno;
     186                 :       38369 :   rclass = lra_get_allocno_class (regno);
     187                 :       38369 :   if (rclass == NO_REGS)
     188                 :             :     return -1;
     189                 :       37002 :   return ira_class_hard_regs[rclass][0];
     190                 :             : }
     191                 :             : 
     192                 :             : /* Return the hard regno of X after removing its subreg.  If X is not a
     193                 :             :    register or a subreg of a register, return -1.  If X is a pseudo, use its
     194                 :             :    assignment.  If X is a hard regno, return the final hard regno which will be
     195                 :             :    after elimination.  */
     196                 :             : static int
     197                 :   290250169 : get_hard_regno (rtx x)
     198                 :             : {
     199                 :   290250169 :   rtx reg;
     200                 :   290250169 :   int hard_regno;
     201                 :             : 
     202                 :   290250169 :   reg = x;
     203                 :   290250169 :   if (SUBREG_P (x))
     204                 :     5170635 :     reg = SUBREG_REG (x);
     205                 :   290250169 :   if (! REG_P (reg))
     206                 :             :     return -1;
     207                 :   200348676 :   int regno = REGNO (reg);
     208                 :   200348676 :   if (HARD_REGISTER_NUM_P (regno))
     209                 :    35191323 :     hard_regno = lra_get_elimination_hard_regno (regno);
     210                 :             :   else
     211                 :   165157353 :     hard_regno = lra_get_regno_hard_regno (regno);
     212                 :   200348676 :   if (hard_regno < 0)
     213                 :             :     return -1;
     214                 :   182384034 :   if (SUBREG_P (x))
     215                 :     4474192 :     hard_regno += subreg_regno_offset (hard_regno, GET_MODE (reg),
     216                 :     4474192 :                                        SUBREG_BYTE (x),  GET_MODE (x));
     217                 :             :   return hard_regno;
     218                 :             : }
     219                 :             : 
     220                 :             : /* If REGNO is a hard register or has been allocated a hard register,
     221                 :             :    return the class of that register.  If REGNO is a reload pseudo
     222                 :             :    created by the current constraints pass, return its allocno class.
     223                 :             :    Return NO_REGS otherwise.  */
     224                 :             : static enum reg_class
     225                 :   516557975 : get_reg_class (int regno)
     226                 :             : {
     227                 :   516557975 :   int hard_regno;
     228                 :             : 
     229                 :   516557975 :   if (HARD_REGISTER_NUM_P (regno))
     230                 :    66206138 :     hard_regno = lra_get_elimination_hard_regno (regno);
     231                 :             :   else
     232                 :   450351837 :     hard_regno = lra_get_regno_hard_regno (regno);
     233                 :   516557975 :   if (hard_regno >= 0)
     234                 :   323241846 :     return REGNO_REG_CLASS (hard_regno);
     235                 :   193316129 :   if (regno >= new_regno_start)
     236                 :    63005710 :     return lra_get_allocno_class (regno);
     237                 :             :   return NO_REGS;
     238                 :             : }
     239                 :             : 
     240                 :             : /* Return true if REG_CLASS has enough allocatable hard regs to keep value of
     241                 :             :    REG_MODE.  */
     242                 :             : static bool
     243                 :    19018411 : enough_allocatable_hard_regs_p (enum reg_class reg_class,
     244                 :             :                                 enum machine_mode reg_mode)
     245                 :             : {
     246                 :    19018411 :   int i, j, hard_regno, class_size, nregs;
     247                 :             : 
     248                 :    38036822 :   if (hard_reg_set_subset_p (reg_class_contents[reg_class], lra_no_alloc_regs))
     249                 :             :     return false;
     250                 :     6492049 :   class_size = ira_class_hard_regs_num[reg_class];
     251                 :     6492049 :   for (i = 0; i < class_size; i++)
     252                 :             :     {
     253                 :     6492049 :       hard_regno = ira_class_hard_regs[reg_class][i];
     254                 :     6492049 :       nregs = hard_regno_nregs (hard_regno, reg_mode);
     255                 :     6492049 :       if (nregs == 1)
     256                 :             :         return true;
     257                 :      259257 :       for (j = 0; j < nregs; j++)
     258                 :      172838 :         if (TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno + j)
     259                 :      172838 :             || ! TEST_HARD_REG_BIT (reg_class_contents[reg_class],
     260                 :             :                                     hard_regno + j))
     261                 :             :           break;
     262                 :       86419 :       if (j >= nregs)
     263                 :             :         return true;
     264                 :             :     }
     265                 :             :   return false;
     266                 :             : }
     267                 :             : 
     268                 :             : /* True if C is a non-empty register class that has too few registers
     269                 :             :    to be safely used as a reload target class.  */
     270                 :             : #define SMALL_REGISTER_CLASS_P(C)               \
     271                 :             :   (ira_class_hard_regs_num [(C)] == 1           \
     272                 :             :    || (ira_class_hard_regs_num [(C)] >= 1    \
     273                 :             :        && targetm.class_likely_spilled_p (C)))
     274                 :             : 
     275                 :             : /* Return true if REG satisfies (or will satisfy) reg class constraint
     276                 :             :    CL.  Use elimination first if REG is a hard register.  If REG is a
     277                 :             :    reload pseudo created by this constraints pass, assume that it will
     278                 :             :    be allocated a hard register from its allocno class, but allow that
     279                 :             :    class to be narrowed to CL if it is currently a superset of CL and
     280                 :             :    if either:
     281                 :             : 
     282                 :             :    - ALLOW_ALL_RELOAD_CLASS_CHANGES_P is true or
     283                 :             :    - the instruction we're processing is not a reload move.
     284                 :             : 
     285                 :             :    If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
     286                 :             :    REGNO (reg), or NO_REGS if no change in its class was needed.  */
     287                 :             : static bool
     288                 :   219698737 : in_class_p (rtx reg, enum reg_class cl, enum reg_class *new_class,
     289                 :             :             bool allow_all_reload_class_changes_p = false)
     290                 :             : {
     291                 :   219698737 :   enum reg_class rclass, common_class;
     292                 :   219698737 :   machine_mode reg_mode;
     293                 :   219698737 :   rtx src;
     294                 :   219698737 :   int regno = REGNO (reg);
     295                 :             : 
     296                 :   219698737 :   if (new_class != NULL)
     297                 :   112809179 :     *new_class = NO_REGS;
     298                 :   219698737 :   if (regno < FIRST_PSEUDO_REGISTER)
     299                 :             :     {
     300                 :    27885702 :       rtx final_reg = reg;
     301                 :    27885702 :       rtx *final_loc = &final_reg;
     302                 :             : 
     303                 :    27885702 :       lra_eliminate_reg_if_possible (final_loc);
     304                 :    27885702 :       return TEST_HARD_REG_BIT (reg_class_contents[cl], REGNO (*final_loc));
     305                 :             :     }
     306                 :   191813035 :   reg_mode = GET_MODE (reg);
     307                 :   191813035 :   rclass = get_reg_class (regno);
     308                 :   191813035 :   src = curr_insn_set != NULL ? SET_SRC (curr_insn_set) : NULL;
     309                 :   191813035 :   if (regno < new_regno_start
     310                 :             :       /* Do not allow the constraints for reload instructions to
     311                 :             :          influence the classes of new pseudos.  These reloads are
     312                 :             :          typically moves that have many alternatives, and restricting
     313                 :             :          reload pseudos for one alternative may lead to situations
     314                 :             :          where other reload pseudos are no longer allocatable.  */
     315                 :   191813035 :       || (!allow_all_reload_class_changes_p
     316                 :    15271126 :           && INSN_UID (curr_insn) >= new_insn_uid_start
     317                 :    14750854 :           && src != NULL
     318                 :    14750854 :           && ((REG_P (src) || MEM_P (src))
     319                 :     1432271 :               || (GET_CODE (src) == SUBREG
     320                 :      608959 :                   && (REG_P (SUBREG_REG (src)) || MEM_P (SUBREG_REG (src)))))))
     321                 :             :     /* When we don't know what class will be used finally for reload
     322                 :             :        pseudos, we use ALL_REGS.  */
     323                 :    13927542 :     return ((regno >= new_regno_start && rclass == ALL_REGS)
     324                 :   186719886 :             || (rclass != NO_REGS && ira_class_subset_p[rclass][cl]
     325                 :   201204000 :                 && ! hard_reg_set_subset_p (reg_class_contents[cl],
     326                 :             :                                             lra_no_alloc_regs)));
     327                 :             :   else
     328                 :             :     {
     329                 :    19018411 :       common_class = ira_reg_class_subset[rclass][cl];
     330                 :    19018411 :       if (new_class != NULL)
     331                 :     5336951 :         *new_class = common_class;
     332                 :    19018411 :       return (enough_allocatable_hard_regs_p (common_class, reg_mode)
     333                 :             :               /* Do not permit reload insn operand matching (new_class == NULL
     334                 :             :                  case) if the new class is too small.  */
     335                 :    19018411 :               && (new_class != NULL || common_class == rclass
     336                 :     1079410 :                   || !SMALL_REGISTER_CLASS_P (common_class)));
     337                 :             :     }
     338                 :             : }
     339                 :             : 
     340                 :             : /* Return true if REGNO satisfies a memory constraint.  */
     341                 :             : static bool
     342                 :    63874386 : in_mem_p (int regno)
     343                 :             : {
     344                 :           0 :   return get_reg_class (regno) == NO_REGS;
     345                 :             : }
     346                 :             : 
     347                 :             : /* Return true if ADDR is a valid memory address for mode MODE in address
     348                 :             :    space AS, and check that each pseudo has the proper kind of hard
     349                 :             :    reg.  */
     350                 :             : static bool
     351                 :    35704814 : valid_address_p (machine_mode mode ATTRIBUTE_UNUSED,
     352                 :             :                  rtx addr, addr_space_t as)
     353                 :             : {
     354                 :             : #ifdef GO_IF_LEGITIMATE_ADDRESS
     355                 :             :   lra_assert (ADDR_SPACE_GENERIC_P (as));
     356                 :             :   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
     357                 :             :   return false;
     358                 :             : 
     359                 :             :  win:
     360                 :             :   return true;
     361                 :             : #else
     362                 :           0 :   return targetm.addr_space.legitimate_address_p (mode, addr, 0, as,
     363                 :    35704814 :                                                   ERROR_MARK);
     364                 :             : #endif
     365                 :             : }
     366                 :             : 
     367                 :             : namespace {
     368                 :             :   /* Temporarily eliminates registers in an address (for the lifetime of
     369                 :             :      the object).  */
     370                 :             :   class address_eliminator {
     371                 :             :   public:
     372                 :             :     address_eliminator (struct address_info *ad);
     373                 :             :     ~address_eliminator ();
     374                 :             : 
     375                 :             :   private:
     376                 :             :     struct address_info *m_ad;
     377                 :             :     rtx *m_base_loc;
     378                 :             :     rtx m_base_reg;
     379                 :             :     rtx *m_index_loc;
     380                 :             :     rtx m_index_reg;
     381                 :             :   };
     382                 :             : }
     383                 :             : 
     384                 :    75227849 : address_eliminator::address_eliminator (struct address_info *ad)
     385                 :    75227849 :   : m_ad (ad),
     386                 :    75227849 :     m_base_loc (strip_subreg (ad->base_term)),
     387                 :    75227849 :     m_base_reg (NULL_RTX),
     388                 :    75227849 :     m_index_loc (strip_subreg (ad->index_term)),
     389                 :    75227849 :     m_index_reg (NULL_RTX)
     390                 :             : {
     391                 :    75227849 :   if (m_base_loc != NULL)
     392                 :             :     {
     393                 :    62673754 :       m_base_reg = *m_base_loc;
     394                 :             :       /* If we have non-legitimate address which is decomposed not in
     395                 :             :          the way we expected, don't do elimination here.  In such case
     396                 :             :          the address will be reloaded and elimination will be done in
     397                 :             :          reload insn finally.  */
     398                 :    62673754 :       if (REG_P (m_base_reg))
     399                 :    62673754 :         lra_eliminate_reg_if_possible (m_base_loc);
     400                 :    62673754 :       if (m_ad->base_term2 != NULL)
     401                 :           0 :         *m_ad->base_term2 = *m_ad->base_term;
     402                 :             :     }
     403                 :    75227849 :   if (m_index_loc != NULL)
     404                 :             :     {
     405                 :     3575625 :       m_index_reg = *m_index_loc;
     406                 :     3575625 :       if (REG_P (m_index_reg))
     407                 :     3575625 :         lra_eliminate_reg_if_possible (m_index_loc);
     408                 :             :     }
     409                 :    75227849 : }
     410                 :             : 
     411                 :    75227849 : address_eliminator::~address_eliminator ()
     412                 :             : {
     413                 :    75227849 :   if (m_base_loc && *m_base_loc != m_base_reg)
     414                 :             :     {
     415                 :    44518752 :       *m_base_loc = m_base_reg;
     416                 :    44518752 :       if (m_ad->base_term2 != NULL)
     417                 :           0 :         *m_ad->base_term2 = *m_ad->base_term;
     418                 :             :     }
     419                 :    75227849 :   if (m_index_loc && *m_index_loc != m_index_reg)
     420                 :           0 :     *m_index_loc = m_index_reg;
     421                 :    75227849 : }
     422                 :             : 
     423                 :             : /* Return true if the eliminated form of AD is a legitimate target address.
     424                 :             :    If OP is a MEM, AD is the address within OP, otherwise OP should be
     425                 :             :    ignored.  CONSTRAINT is one constraint that the operand may need
     426                 :             :    to meet.  */
     427                 :             : static bool
     428                 :    35681990 : valid_address_p (rtx op, struct address_info *ad,
     429                 :             :                  enum constraint_num constraint)
     430                 :             : {
     431                 :    35681990 :   address_eliminator eliminator (ad);
     432                 :             : 
     433                 :             :   /* Allow a memory OP if it matches CONSTRAINT, even if CONSTRAINT is more
     434                 :             :      forgiving than "m".
     435                 :             :      Need to extract memory from op for special memory constraint,
     436                 :             :      i.e. bcst_mem_operand in i386 backend.  */
     437                 :    35681990 :   if (MEM_P (extract_mem_from_operand (op))
     438                 :             :       && insn_extra_relaxed_memory_constraint (constraint)
     439                 :             :       && constraint_satisfied_p (op, constraint))
     440                 :             :     return true;
     441                 :             : 
     442                 :    35681990 :   return valid_address_p (ad->mode, *ad->outer, ad->as);
     443                 :    35681990 : }
     444                 :             : 
     445                 :             : /* For special_memory_operand, it could be false for MEM_P (op),
     446                 :             :    i.e. bcst_mem_operand in i386 backend.
     447                 :             :    Extract and return real memory operand or op.  */
     448                 :             : rtx
     449                 :   627876273 : extract_mem_from_operand (rtx op)
     450                 :             : {
     451                 :   629606536 :   for (rtx x = op;; x = XEXP (x, 0))
     452                 :             :     {
     453                 :   629606536 :       if (MEM_P (x))
     454                 :             :         return x;
     455                 :   447627917 :       if (GET_RTX_LENGTH (GET_CODE (x)) != 1
     456                 :   366823075 :           || GET_RTX_FORMAT (GET_CODE (x))[0] != 'e')
     457                 :             :         break;
     458                 :             :     }
     459                 :             :   return op;
     460                 :             : }
     461                 :             : 
     462                 :             : /* Return true if the eliminated form of memory reference OP satisfies
     463                 :             :    extra (special) memory constraint CONSTRAINT.  */
     464                 :             : static bool
     465                 :    36894188 : satisfies_memory_constraint_p (rtx op, enum constraint_num constraint)
     466                 :             : {
     467                 :    36894188 :   struct address_info ad;
     468                 :    36894188 :   rtx mem = extract_mem_from_operand (op);
     469                 :    36894188 :   if (!MEM_P (mem))
     470                 :             :     return false;
     471                 :             : 
     472                 :    35934029 :   decompose_mem_address (&ad, mem);
     473                 :    35934029 :   address_eliminator eliminator (&ad);
     474                 :    35934029 :   return constraint_satisfied_p (op, constraint);
     475                 :    35934029 : }
     476                 :             : 
     477                 :             : /* Return true if the eliminated form of address AD satisfies extra
     478                 :             :    address constraint CONSTRAINT.  */
     479                 :             : static bool
     480                 :     3611830 : satisfies_address_constraint_p (struct address_info *ad,
     481                 :             :                                 enum constraint_num constraint)
     482                 :             : {
     483                 :     3611830 :   address_eliminator eliminator (ad);
     484                 :     3611830 :   return constraint_satisfied_p (*ad->outer, constraint);
     485                 :     3611830 : }
     486                 :             : 
     487                 :             : /* Return true if the eliminated form of address OP satisfies extra
     488                 :             :    address constraint CONSTRAINT.  */
     489                 :             : static bool
     490                 :     1774325 : satisfies_address_constraint_p (rtx op, enum constraint_num constraint)
     491                 :             : {
     492                 :     1774325 :   struct address_info ad;
     493                 :             : 
     494                 :     1774325 :   decompose_lea_address (&ad, &op);
     495                 :     1774325 :   return satisfies_address_constraint_p (&ad, constraint);
     496                 :             : }
     497                 :             : 
     498                 :             : /* Initiate equivalences for LRA.  As we keep original equivalences
     499                 :             :    before any elimination, we need to make copies otherwise any change
     500                 :             :    in insns might change the equivalences.  */
     501                 :             : void
     502                 :     1481332 : lra_init_equiv (void)
     503                 :             : {
     504                 :     1481332 :   ira_expand_reg_equiv ();
     505                 :    69899498 :   for (int i = FIRST_PSEUDO_REGISTER; i < max_reg_num (); i++)
     506                 :             :     {
     507                 :    68418166 :       rtx res;
     508                 :             : 
     509                 :    68418166 :       if ((res = ira_reg_equiv[i].memory) != NULL_RTX)
     510                 :     3116385 :         ira_reg_equiv[i].memory = copy_rtx (res);
     511                 :    68418166 :       if ((res = ira_reg_equiv[i].invariant) != NULL_RTX)
     512                 :      895106 :         ira_reg_equiv[i].invariant = copy_rtx (res);
     513                 :             :     }
     514                 :     1481332 : }
     515                 :             : 
     516                 :             : static rtx loc_equivalence_callback (rtx, const_rtx, void *);
     517                 :             : 
     518                 :             : /* Update equivalence for REGNO.  We need to this as the equivalence
     519                 :             :    might contain other pseudos which are changed by their
     520                 :             :    equivalences.  */
     521                 :             : static void
     522                 :   203464892 : update_equiv (int regno)
     523                 :             : {
     524                 :   203464892 :   rtx x;
     525                 :             : 
     526                 :   203464892 :   if ((x = ira_reg_equiv[regno].memory) != NULL_RTX)
     527                 :     9455992 :     ira_reg_equiv[regno].memory
     528                 :     9455992 :       = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
     529                 :             :                                  NULL_RTX);
     530                 :   203464892 :   if ((x = ira_reg_equiv[regno].invariant) != NULL_RTX)
     531                 :     2771614 :     ira_reg_equiv[regno].invariant
     532                 :     2771614 :       = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
     533                 :             :                                  NULL_RTX);
     534                 :   203464892 : }
     535                 :             : 
     536                 :             : /* If we have decided to substitute X with another value, return that
     537                 :             :    value, otherwise return X.  */
     538                 :             : static rtx
     539                 :   439353518 : get_equiv (rtx x)
     540                 :             : {
     541                 :   439353518 :   int regno;
     542                 :   439353518 :   rtx res;
     543                 :             : 
     544                 :   297119494 :   if (! REG_P (x) || (regno = REGNO (x)) < FIRST_PSEUDO_REGISTER
     545                 :   196674356 :       || regno >= ira_reg_equiv_len
     546                 :   196674356 :       || ! ira_reg_equiv[regno].defined_p
     547                 :    25974593 :       || ! ira_reg_equiv[regno].profitable_p
     548                 :   465285475 :       || lra_get_regno_hard_regno (regno) >= 0)
     549                 :   434258332 :     return x;
     550                 :     5095186 :   if ((res = ira_reg_equiv[regno].memory) != NULL_RTX)
     551                 :             :     {
     552                 :     2294184 :       if (targetm.cannot_substitute_mem_equiv_p (res))
     553                 :             :         return x;
     554                 :             :       return res;
     555                 :             :     }
     556                 :     2801002 :   if ((res = ira_reg_equiv[regno].constant) != NULL_RTX)
     557                 :             :     return res;
     558                 :     1973171 :   if ((res = ira_reg_equiv[regno].invariant) != NULL_RTX)
     559                 :             :     return res;
     560                 :           0 :   gcc_unreachable ();
     561                 :             : }
     562                 :             : 
     563                 :             : /* If we have decided to substitute X with the equivalent value,
     564                 :             :    return that value after elimination for INSN, otherwise return
     565                 :             :    X.  */
     566                 :             : static rtx
     567                 :   246721534 : get_equiv_with_elimination (rtx x, rtx_insn *insn)
     568                 :             : {
     569                 :   246721534 :   rtx res = get_equiv (x);
     570                 :             : 
     571                 :   246721534 :   if (x == res || CONSTANT_P (res))
     572                 :             :     return res;
     573                 :     1550986 :   return lra_eliminate_regs_1 (insn, res, GET_MODE (res),
     574                 :             :                                false, false, 0, true);
     575                 :             : }
     576                 :             : 
     577                 :             : /* Set up curr_operand_mode.  */
     578                 :             : static void
     579                 :   106771653 : init_curr_operand_mode (void)
     580                 :             : {
     581                 :   106771653 :   int nop = curr_static_id->n_operands;
     582                 :   332588682 :   for (int i = 0; i < nop; i++)
     583                 :             :     {
     584                 :   225817029 :       machine_mode mode = GET_MODE (*curr_id->operand_loc[i]);
     585                 :   225817029 :       if (mode == VOIDmode)
     586                 :             :         {
     587                 :             :           /* The .md mode for address operands is the mode of the
     588                 :             :              addressed value rather than the mode of the address itself.  */
     589                 :    43821819 :           if (curr_id->icode >= 0 && curr_static_id->operand[i].is_address)
     590                 :         115 :             mode = Pmode;
     591                 :             :           else
     592                 :    43821704 :             mode = curr_static_id->operand[i].mode;
     593                 :             :         }
     594                 :   225817029 :       curr_operand_mode[i] = mode;
     595                 :             :     }
     596                 :   106771653 : }
     597                 :             : 
     598                 :             : 
     599                 :             : 
     600                 :             : /* The page contains code to reuse input reloads.  */
     601                 :             : 
     602                 :             : /* Structure describes input reload of the current insns.  */
     603                 :             : struct input_reload
     604                 :             : {
     605                 :             :   /* True for input reload of matched operands.  */
     606                 :             :   bool match_p;
     607                 :             :   /* True for input reload of inout earlyclobber operand.  */
     608                 :             :   bool early_clobber_p;
     609                 :             :   /* Reloaded value.  */
     610                 :             :   rtx input;
     611                 :             :   /* Reload pseudo used.  */
     612                 :             :   rtx reg;
     613                 :             : };
     614                 :             : 
     615                 :             : /* The number of elements in the following array.  */
     616                 :             : static int curr_insn_input_reloads_num;
     617                 :             : /* Array containing info about input reloads.  It is used to find the
     618                 :             :    same input reload and reuse the reload pseudo in this case.  */
     619                 :             : static struct input_reload curr_insn_input_reloads[LRA_MAX_INSN_RELOADS];
     620                 :             : 
     621                 :             : /* Initiate data concerning reuse of input reloads for the current
     622                 :             :    insn.  */
     623                 :             : static void
     624                 :   106771653 : init_curr_insn_input_reloads (void)
     625                 :             : {
     626                 :   106771653 :   curr_insn_input_reloads_num = 0;
     627                 :           0 : }
     628                 :             : 
     629                 :             : /* The canonical form of an rtx inside a MEM is not necessarily the same as the
     630                 :             :    canonical form of the rtx outside the MEM.  Fix this up in the case that
     631                 :             :    we're reloading an address (and therefore pulling it outside a MEM).  */
     632                 :             : static rtx
     633                 :          72 : canonicalize_reload_addr (rtx addr)
     634                 :             : {
     635                 :          72 :   subrtx_var_iterator::array_type array;
     636                 :         246 :   FOR_EACH_SUBRTX_VAR (iter, array, addr, NONCONST)
     637                 :             :     {
     638                 :         174 :       rtx x = *iter;
     639                 :         174 :       if (GET_CODE (x) == MULT && CONST_INT_P (XEXP (x, 1)))
     640                 :             :         {
     641                 :          14 :           const HOST_WIDE_INT ci = INTVAL (XEXP (x, 1));
     642                 :         188 :           const int pwr2 = exact_log2 (ci);
     643                 :          14 :           if (pwr2 > 0)
     644                 :             :             {
     645                 :             :               /* Rewrite this to use a shift instead, which is canonical when
     646                 :             :                  outside of a MEM.  */
     647                 :          14 :               PUT_CODE (x, ASHIFT);
     648                 :          14 :               XEXP (x, 1) = GEN_INT (pwr2);
     649                 :             :             }
     650                 :             :         }
     651                 :             :     }
     652                 :             : 
     653                 :          72 :   return addr;
     654                 :          72 : }
     655                 :             : 
     656                 :             : /* Create a new pseudo using MODE, RCLASS, EXCLUDE_START_HARD_REGS, ORIGINAL or
     657                 :             :    reuse an existing reload pseudo.  Don't reuse an existing reload pseudo if
     658                 :             :    IN_SUBREG_P is true and the reused pseudo should be wrapped up in a SUBREG.
     659                 :             :    EARLY_CLOBBER_P is true for input reload of inout early clobber operand.
     660                 :             :    The result pseudo is returned through RESULT_REG.  Return TRUE if we created
     661                 :             :    a new pseudo, FALSE if we reused an existing reload pseudo.  Use TITLE to
     662                 :             :    describe new registers for debug purposes.  */
     663                 :             : static bool
     664                 :     3867422 : get_reload_reg (enum op_type type, machine_mode mode, rtx original,
     665                 :             :                 enum reg_class rclass, HARD_REG_SET *exclude_start_hard_regs,
     666                 :             :                 bool in_subreg_p, bool early_clobber_p,
     667                 :             :                 const char *title, rtx *result_reg)
     668                 :             : {
     669                 :     3867422 :   int i, regno;
     670                 :     3867422 :   enum reg_class new_class;
     671                 :             : 
     672                 :     3867422 :   if (type == OP_OUT)
     673                 :             :     {
     674                 :             :       /* Output reload registers tend to start out with a conservative
     675                 :             :          choice of register class.  Usually this is ALL_REGS, although
     676                 :             :          a target might narrow it (for performance reasons) through
     677                 :             :          targetm.preferred_reload_class.  It's therefore quite common
     678                 :             :          for a reload instruction to require a more restrictive class
     679                 :             :          than the class that was originally assigned to the reload register.
     680                 :             : 
     681                 :             :          In these situations, it's more efficient to refine the choice
     682                 :             :          of register class rather than create a second reload register.
     683                 :             :          This also helps to avoid cycling for registers that are only
     684                 :             :          used by reload instructions.  */
     685                 :      976598 :       if (REG_P (original)
     686                 :      714022 :           && (int) REGNO (original) >= new_regno_start
     687                 :        7249 :           && (INSN_UID (curr_insn) >= new_insn_uid_start
     688                 :         250 :               || ira_former_scratch_p (REGNO (original)))
     689                 :      983847 :           && in_class_p (original, rclass, &new_class, true))
     690                 :             :         {
     691                 :         250 :           unsigned int regno = REGNO (original);
     692                 :         250 :           if (lra_dump_file != NULL)
     693                 :             :             {
     694                 :           0 :               fprintf (lra_dump_file, "     Reuse r%d for output ", regno);
     695                 :           0 :               dump_value_slim (lra_dump_file, original, 1);
     696                 :             :             }
     697                 :         500 :           if (new_class != lra_get_allocno_class (regno))
     698                 :         250 :             lra_change_class (regno, new_class, ", change to", false);
     699                 :         250 :           if (lra_dump_file != NULL)
     700                 :           0 :             fprintf (lra_dump_file, "\n");
     701                 :         250 :           *result_reg = original;
     702                 :         250 :           return false;
     703                 :             :         }
     704                 :      976348 :       *result_reg
     705                 :      976348 :         = lra_create_new_reg_with_unique_value (mode, original, rclass,
     706                 :             :                                                 exclude_start_hard_regs, title);
     707                 :      976348 :       return true;
     708                 :             :     }
     709                 :             : 
     710                 :     2890824 :   bool unique_p = early_clobber_p;
     711                 :             :   /* Prevent reuse value of expression with side effects,
     712                 :             :      e.g. volatile memory.  */
     713                 :     2890824 :   if (! side_effects_p (original))
     714                 :     3122786 :     for (i = 0; i < curr_insn_input_reloads_num; i++)
     715                 :             :       {
     716                 :      240725 :         if (! curr_insn_input_reloads[i].match_p
     717                 :      101415 :             && ! curr_insn_input_reloads[i].early_clobber_p
     718                 :      101413 :             && rtx_equal_p (curr_insn_input_reloads[i].input, original)
     719                 :      249501 :             && in_class_p (curr_insn_input_reloads[i].reg, rclass, &new_class))
     720                 :             :           {
     721                 :        8763 :             rtx reg = curr_insn_input_reloads[i].reg;
     722                 :        8763 :             regno = REGNO (reg);
     723                 :             :             /* If input is equal to original and both are VOIDmode,
     724                 :             :                GET_MODE (reg) might be still different from mode.
     725                 :             :                Ensure we don't return *result_reg with wrong mode.  */
     726                 :        8763 :             if (GET_MODE (reg) != mode)
     727                 :             :               {
     728                 :           0 :                 if (in_subreg_p)
     729                 :           0 :                   continue;
     730                 :           0 :                 if (maybe_lt (GET_MODE_SIZE (GET_MODE (reg)),
     731                 :           0 :                               GET_MODE_SIZE (mode)))
     732                 :           0 :                   continue;
     733                 :           0 :                 reg = lowpart_subreg (mode, reg, GET_MODE (reg));
     734                 :           0 :                 if (reg == NULL_RTX || GET_CODE (reg) != SUBREG)
     735                 :           0 :                   continue;
     736                 :             :               }
     737                 :        8763 :             *result_reg = reg;
     738                 :        8763 :             if (lra_dump_file != NULL)
     739                 :             :               {
     740                 :           0 :                 fprintf (lra_dump_file, "   Reuse r%d for reload ", regno);
     741                 :           0 :                 dump_value_slim (lra_dump_file, original, 1);
     742                 :             :               }
     743                 :       17526 :             if (new_class != lra_get_allocno_class (regno))
     744                 :        4630 :               lra_change_class (regno, new_class, ", change to", false);
     745                 :        8763 :             if (lra_dump_file != NULL)
     746                 :           0 :               fprintf (lra_dump_file, "\n");
     747                 :        8763 :             return false;
     748                 :             :           }
     749                 :             :         /* If we have an input reload with a different mode, make sure it
     750                 :             :            will get a different hard reg.  */
     751                 :      231962 :         else if (REG_P (original)
     752                 :      184836 :                  && REG_P (curr_insn_input_reloads[i].input)
     753                 :      153145 :                  && REGNO (original) == REGNO (curr_insn_input_reloads[i].input)
     754                 :      231962 :                  && (GET_MODE (original)
     755                 :        2012 :                      != GET_MODE (curr_insn_input_reloads[i].input)))
     756                 :             :           unique_p = true;
     757                 :             :       }
     758                 :     5764122 :   *result_reg = (unique_p
     759                 :     2882061 :                  ? lra_create_new_reg_with_unique_value
     760                 :     2882061 :                  : lra_create_new_reg) (mode, original, rclass,
     761                 :             :                                         exclude_start_hard_regs, title);
     762                 :     2882061 :   lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
     763                 :     2882061 :   curr_insn_input_reloads[curr_insn_input_reloads_num].input = original;
     764                 :     2882061 :   curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = false;
     765                 :     2882061 :   curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p
     766                 :     2882061 :     = early_clobber_p;
     767                 :     2882061 :   curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = *result_reg;
     768                 :     2882061 :   return true;
     769                 :             : }
     770                 :             : 
     771                 :             : 
     772                 :             : /* The page contains major code to choose the current insn alternative
     773                 :             :    and generate reloads for it.  */
     774                 :             : 
     775                 :             : /* Return the offset from REGNO of the least significant register
     776                 :             :    in (reg:MODE REGNO).
     777                 :             : 
     778                 :             :    This function is used to tell whether two registers satisfy
     779                 :             :    a matching constraint.  (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
     780                 :             : 
     781                 :             :          REGNO1 + lra_constraint_offset (REGNO1, MODE1)
     782                 :             :          == REGNO2 + lra_constraint_offset (REGNO2, MODE2)  */
     783                 :             : int
     784                 :    43628476 : lra_constraint_offset (int regno, machine_mode mode)
     785                 :             : {
     786                 :    43628476 :   lra_assert (regno < FIRST_PSEUDO_REGISTER);
     787                 :             : 
     788                 :    43628476 :   scalar_int_mode int_mode;
     789                 :    43628476 :   if (WORDS_BIG_ENDIAN
     790                 :             :       && is_a <scalar_int_mode> (mode, &int_mode)
     791                 :             :       && GET_MODE_SIZE (int_mode) > UNITS_PER_WORD)
     792                 :             :     return hard_regno_nregs (regno, mode) - 1;
     793                 :    43628476 :   return 0;
     794                 :             : }
     795                 :             : 
     796                 :             : /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
     797                 :             :    if they are the same hard reg, and has special hacks for
     798                 :             :    auto-increment and auto-decrement.  This is specifically intended for
     799                 :             :    process_alt_operands to use in determining whether two operands
     800                 :             :    match.  X is the operand whose number is the lower of the two.
     801                 :             : 
     802                 :             :    It is supposed that X is the output operand and Y is the input
     803                 :             :    operand.  Y_HARD_REGNO is the final hard regno of register Y or
     804                 :             :    register in subreg Y as we know it now.  Otherwise, it is a
     805                 :             :    negative value.  */
     806                 :             : static bool
     807                 :    58070082 : operands_match_p (rtx x, rtx y, int y_hard_regno)
     808                 :             : {
     809                 :    58070082 :   int i;
     810                 :    58070082 :   RTX_CODE code = GET_CODE (x);
     811                 :    58070082 :   const char *fmt;
     812                 :             : 
     813                 :    58070082 :   if (x == y)
     814                 :             :     return true;
     815                 :    50487218 :   if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
     816                 :    23792844 :       && (REG_P (y) || (GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y)))))
     817                 :             :     {
     818                 :    23695155 :       int j;
     819                 :             : 
     820                 :    23695155 :       i = get_hard_regno (x);
     821                 :    23695155 :       if (i < 0)
     822                 :     1196855 :         goto slow;
     823                 :             : 
     824                 :    22498300 :       if ((j = y_hard_regno) < 0)
     825                 :      684062 :         goto slow;
     826                 :             : 
     827                 :    21814238 :       i += lra_constraint_offset (i, GET_MODE (x));
     828                 :    21814238 :       j += lra_constraint_offset (j, GET_MODE (y));
     829                 :             : 
     830                 :    21814238 :       return i == j;
     831                 :             :     }
     832                 :             : 
     833                 :             :   /* If two operands must match, because they are really a single
     834                 :             :      operand of an assembler insn, then two post-increments are invalid
     835                 :             :      because the assembler insn would increment only once.  On the
     836                 :             :      other hand, a post-increment matches ordinary indexing if the
     837                 :             :      post-increment is the output operand.  */
     838                 :    26792063 :   if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
     839                 :           0 :     return operands_match_p (XEXP (x, 0), y, y_hard_regno);
     840                 :             : 
     841                 :             :   /* Two pre-increments are invalid because the assembler insn would
     842                 :             :      increment only once.  On the other hand, a pre-increment matches
     843                 :             :      ordinary indexing if the pre-increment is the input operand.  */
     844                 :    26792063 :   if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
     845                 :    26792063 :       || GET_CODE (y) == PRE_MODIFY)
     846                 :           0 :     return operands_match_p (x, XEXP (y, 0), -1);
     847                 :             : 
     848                 :    26792063 :  slow:
     849                 :             : 
     850                 :    28672980 :   if (code == REG && REG_P (y))
     851                 :     1785152 :     return REGNO (x) == REGNO (y);
     852                 :             : 
     853                 :       96631 :   if (code == REG && GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y))
     854                 :        6492 :       && x == SUBREG_REG (y))
     855                 :             :     return true;
     856                 :    26887828 :   if (GET_CODE (y) == REG && code == SUBREG && REG_P (SUBREG_REG (x))
     857                 :       64786 :       && SUBREG_REG (x) == y)
     858                 :             :     return true;
     859                 :             : 
     860                 :             :   /* Now we have disposed of all the cases in which different rtx
     861                 :             :      codes can match.  */
     862                 :    26887665 :   if (code != GET_CODE (y))
     863                 :             :     return false;
     864                 :             : 
     865                 :             :   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
     866                 :     1026460 :   if (GET_MODE (x) != GET_MODE (y))
     867                 :             :     return false;
     868                 :             : 
     869                 :     1025783 :   switch (code)
     870                 :             :     {
     871                 :             :     CASE_CONST_UNIQUE:
     872                 :             :       return false;
     873                 :             : 
     874                 :             :     case CONST_VECTOR:
     875                 :             :       if (!same_vector_encodings_p (x, y))
     876                 :             :         return false;
     877                 :             :       break;
     878                 :             : 
     879                 :           0 :     case LABEL_REF:
     880                 :           0 :       return label_ref_label (x) == label_ref_label (y);
     881                 :          22 :     case SYMBOL_REF:
     882                 :          22 :       return XSTR (x, 0) == XSTR (y, 0);
     883                 :             : 
     884                 :             :     default:
     885                 :             :       break;
     886                 :             :     }
     887                 :             : 
     888                 :             :   /* Compare the elements.  If any pair of corresponding elements fail
     889                 :             :      to match, return false for the whole things.  */
     890                 :             : 
     891                 :     1008476 :   fmt = GET_RTX_FORMAT (code);
     892                 :     2932664 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
     893                 :             :     {
     894                 :     1988904 :       int val, j;
     895                 :     1988904 :       switch (fmt[i])
     896                 :             :         {
     897                 :           0 :         case 'w':
     898                 :           0 :           if (XWINT (x, i) != XWINT (y, i))
     899                 :             :             return false;
     900                 :             :           break;
     901                 :             : 
     902                 :         478 :         case 'i':
     903                 :         478 :           if (XINT (x, i) != XINT (y, i))
     904                 :             :             return false;
     905                 :             :           break;
     906                 :             : 
     907                 :           0 :         case 'L':
     908                 :           0 :           if (XLOC (x, i) != XLOC (y, i))
     909                 :             :             return false;
     910                 :             :           break;
     911                 :             : 
     912                 :       24425 :         case 'p':
     913                 :       24425 :           if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
     914                 :             :             return false;
     915                 :             :           break;
     916                 :             : 
     917                 :     1453792 :         case 'e':
     918                 :     1453792 :           val = operands_match_p (XEXP (x, i), XEXP (y, i), -1);
     919                 :     1453792 :           if (val == 0)
     920                 :             :             return false;
     921                 :             :           break;
     922                 :             : 
     923                 :             :         case '0':
     924                 :             :           break;
     925                 :             : 
     926                 :         478 :         case 'E':
     927                 :         478 :           if (XVECLEN (x, i) != XVECLEN (y, i))
     928                 :             :             return false;
     929                 :         956 :           for (j = XVECLEN (x, i) - 1; j >= 0; --j)
     930                 :             :             {
     931                 :         478 :               val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j), -1);
     932                 :         478 :               if (val == 0)
     933                 :             :                 return false;
     934                 :             :             }
     935                 :             :           break;
     936                 :             : 
     937                 :             :           /* It is believed that rtx's at this level will never
     938                 :             :              contain anything but integers and other rtx's, except for
     939                 :             :              within LABEL_REFs and SYMBOL_REFs.  */
     940                 :           0 :         default:
     941                 :           0 :           gcc_unreachable ();
     942                 :             :         }
     943                 :             :     }
     944                 :             :   return true;
     945                 :             : }
     946                 :             : 
     947                 :             : /* True if X is a constant that can be forced into the constant pool.
     948                 :             :    MODE is the mode of the operand, or VOIDmode if not known.  */
     949                 :             : #define CONST_POOL_OK_P(MODE, X)                \
     950                 :             :   ((MODE) != VOIDmode                           \
     951                 :             :    && CONSTANT_P (X)                            \
     952                 :             :    && GET_CODE (X) != HIGH                      \
     953                 :             :    && GET_MODE_SIZE (MODE).is_constant ()       \
     954                 :             :    && !targetm.cannot_force_const_mem (MODE, X))
     955                 :             : 
     956                 :             : /* If REG is a reload pseudo, try to make its class satisfying CL.  */
     957                 :             : static void
     958                 :     3429670 : narrow_reload_pseudo_class (rtx reg, enum reg_class cl)
     959                 :             : {
     960                 :     3429670 :   enum reg_class rclass;
     961                 :             : 
     962                 :             :   /* Do not make more accurate class from reloads generated.  They are
     963                 :             :      mostly moves with a lot of constraints.  Making more accurate
     964                 :             :      class may results in very narrow class and impossibility of find
     965                 :             :      registers for several reloads of one insn.  */
     966                 :     3429670 :   if (INSN_UID (curr_insn) >= new_insn_uid_start)
     967                 :     3429651 :     return;
     968                 :     3429570 :   if (GET_CODE (reg) == SUBREG)
     969                 :      164021 :     reg = SUBREG_REG (reg);
     970                 :     3429570 :   if (! REG_P (reg) || (int) REGNO (reg) < new_regno_start)
     971                 :             :     return;
     972                 :          19 :   if (in_class_p (reg, cl, &rclass) && rclass != cl)
     973                 :           0 :     lra_change_class (REGNO (reg), rclass, "      Change to", true);
     974                 :             : }
     975                 :             : 
     976                 :             : /* Searches X for any reference to a reg with the same value as REGNO,
     977                 :             :    returning the rtx of the reference found if any.  Otherwise,
     978                 :             :    returns NULL_RTX.  */
     979                 :             : static rtx
     980                 :      518607 : regno_val_use_in (unsigned int regno, rtx x)
     981                 :             : {
     982                 :      518607 :   const char *fmt;
     983                 :      518607 :   int i, j;
     984                 :      518607 :   rtx tem;
     985                 :             : 
     986                 :      518607 :   if (REG_P (x) && lra_reg_info[REGNO (x)].val == lra_reg_info[regno].val)
     987                 :             :     return x;
     988                 :             : 
     989                 :      518245 :   fmt = GET_RTX_FORMAT (GET_CODE (x));
     990                 :     1042131 :   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
     991                 :             :     {
     992                 :      523886 :       if (fmt[i] == 'e')
     993                 :             :         {
     994                 :        6769 :           if ((tem = regno_val_use_in (regno, XEXP (x, i))))
     995                 :             :             return tem;
     996                 :             :         }
     997                 :      517117 :       else if (fmt[i] == 'E')
     998                 :           0 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
     999                 :           0 :           if ((tem = regno_val_use_in (regno , XVECEXP (x, i, j))))
    1000                 :             :             return tem;
    1001                 :             :     }
    1002                 :             : 
    1003                 :             :   return NULL_RTX;
    1004                 :             : }
    1005                 :             : 
    1006                 :             : /* Return true if all current insn non-output operands except INS (it
    1007                 :             :    has a negaitve end marker) do not use pseudos with the same value
    1008                 :             :    as REGNO.  */
    1009                 :             : static bool
    1010                 :           2 : check_conflict_input_operands (int regno, signed char *ins)
    1011                 :             : {
    1012                 :           2 :   int in;
    1013                 :           2 :   int n_operands = curr_static_id->n_operands;
    1014                 :             : 
    1015                 :           8 :   for (int nop = 0; nop < n_operands; nop++)
    1016                 :           7 :     if (! curr_static_id->operand[nop].is_operator
    1017                 :           7 :         && curr_static_id->operand[nop].type != OP_OUT)
    1018                 :             :       {
    1019                 :           5 :         for (int i = 0; (in = ins[i]) >= 0; i++)
    1020                 :           4 :           if (in == nop)
    1021                 :             :             break;
    1022                 :           3 :         if (in < 0
    1023                 :           3 :             && regno_val_use_in (regno, *curr_id->operand_loc[nop]) != NULL_RTX)
    1024                 :             :           return false;
    1025                 :             :       }
    1026                 :             :   return true;
    1027                 :             : }
    1028                 :             : 
    1029                 :             : /* Generate reloads for matching OUT and INS (array of input operand numbers
    1030                 :             :    with end marker -1) with reg class GOAL_CLASS and EXCLUDE_START_HARD_REGS,
    1031                 :             :    considering output operands OUTS (similar array to INS) needing to be in
    1032                 :             :    different registers.  Add input and output reloads correspondingly to the
    1033                 :             :    lists *BEFORE and *AFTER.  OUT might be negative.  In this case we generate
    1034                 :             :    input reloads for matched input operands INS.  EARLY_CLOBBER_P is a flag
    1035                 :             :    that the output operand is early clobbered for chosen alternative.  */
    1036                 :             : static void
    1037                 :     1714835 : match_reload (signed char out, signed char *ins, signed char *outs,
    1038                 :             :               enum reg_class goal_class, HARD_REG_SET *exclude_start_hard_regs,
    1039                 :             :               rtx_insn **before, rtx_insn **after, bool early_clobber_p)
    1040                 :             : {
    1041                 :     1714835 :   bool out_conflict;
    1042                 :     1714835 :   int i, in;
    1043                 :     1714835 :   rtx new_in_reg, new_out_reg, reg;
    1044                 :     1714835 :   machine_mode inmode, outmode;
    1045                 :     1714835 :   rtx in_rtx = *curr_id->operand_loc[ins[0]];
    1046                 :     1714835 :   rtx out_rtx = out < 0 ? in_rtx : *curr_id->operand_loc[out];
    1047                 :             : 
    1048                 :     1714835 :   inmode = curr_operand_mode[ins[0]];
    1049                 :     1714835 :   outmode = out < 0 ? inmode : curr_operand_mode[out];
    1050                 :     1714835 :   push_to_sequence (*before);
    1051                 :     1714835 :   if (inmode != outmode)
    1052                 :             :     {
    1053                 :             :       /* process_alt_operands has already checked that the mode sizes
    1054                 :             :          are ordered.  */
    1055                 :      128884 :       if (partial_subreg_p (outmode, inmode))
    1056                 :             :         {
    1057                 :        1686 :           bool asm_p = asm_noperands (PATTERN (curr_insn)) >= 0;
    1058                 :        1686 :           int hr;
    1059                 :        1686 :           HARD_REG_SET temp_hard_reg_set;
    1060                 :             : 
    1061                 :          19 :           if (asm_p && (hr = get_hard_regno (out_rtx)) >= 0
    1062                 :        1689 :               && hard_regno_nregs (hr, inmode) > 1)
    1063                 :             :             {
    1064                 :             :               /* See gcc.c-torture/execute/20030222-1.c.
    1065                 :             :                  Consider the code for 32-bit (e.g. BE) target:
    1066                 :             :                    int i, v; long x; x = v; asm ("" : "=r" (i) : "0" (x));
    1067                 :             :                  We generate the following RTL with reload insns:
    1068                 :             :                    1. subreg:si(x:di, 0) = 0;
    1069                 :             :                    2. subreg:si(x:di, 4) = v:si;
    1070                 :             :                    3. t:di = x:di, dead x;
    1071                 :             :                    4. asm ("" : "=r" (subreg:si(t:di,4)) : "0" (t:di))
    1072                 :             :                    5. i:si = subreg:si(t:di,4);
    1073                 :             :                  If we assign hard reg of x to t, dead code elimination
    1074                 :             :                  will remove insn #2 and we will use unitialized hard reg.
    1075                 :             :                  So exclude the hard reg of x for t.  We could ignore this
    1076                 :             :                  problem for non-empty asm using all x value but it is hard to
    1077                 :             :                  check that the asm are expanded into insn realy using x
    1078                 :             :                  and setting r.  */
    1079                 :           0 :               CLEAR_HARD_REG_SET (temp_hard_reg_set);
    1080                 :           0 :               if (exclude_start_hard_regs != NULL)
    1081                 :           0 :                 temp_hard_reg_set = *exclude_start_hard_regs;
    1082                 :           0 :               SET_HARD_REG_BIT (temp_hard_reg_set, hr);
    1083                 :           0 :               exclude_start_hard_regs = &temp_hard_reg_set;
    1084                 :             :             }
    1085                 :        3372 :           reg = new_in_reg
    1086                 :        1686 :             = lra_create_new_reg_with_unique_value (inmode, in_rtx, goal_class,
    1087                 :             :                                                     exclude_start_hard_regs,
    1088                 :             :                                                     "");
    1089                 :        1686 :           new_out_reg = gen_lowpart_SUBREG (outmode, reg);
    1090                 :        1686 :           LRA_SUBREG_P (new_out_reg) = 1;
    1091                 :             :           /* If the input reg is dying here, we can use the same hard
    1092                 :             :              register for REG and IN_RTX.  We do it only for original
    1093                 :             :              pseudos as reload pseudos can die although original
    1094                 :             :              pseudos still live where reload pseudos dies.  */
    1095                 :        1488 :           if (REG_P (in_rtx) && (int) REGNO (in_rtx) < lra_new_regno_start
    1096                 :        1445 :               && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
    1097                 :        2692 :               && (!early_clobber_p
    1098                 :           2 :                   || check_conflict_input_operands(REGNO (in_rtx), ins)))
    1099                 :        1005 :             lra_assign_reg_val (REGNO (in_rtx), REGNO (reg));
    1100                 :             :         }
    1101                 :             :       else
    1102                 :             :         {
    1103                 :      254396 :           reg = new_out_reg
    1104                 :      127198 :             = lra_create_new_reg_with_unique_value (outmode, out_rtx,
    1105                 :             :                                                     goal_class,
    1106                 :             :                                                     exclude_start_hard_regs,
    1107                 :             :                                                     "");
    1108                 :      127198 :           new_in_reg = gen_lowpart_SUBREG (inmode, reg);
    1109                 :             :           /* NEW_IN_REG is non-paradoxical subreg.  We don't want
    1110                 :             :              NEW_OUT_REG living above.  We add clobber clause for
    1111                 :             :              this.  This is just a temporary clobber.  We can remove
    1112                 :             :              it at the end of LRA work.  */
    1113                 :      127198 :           rtx_insn *clobber = emit_clobber (new_out_reg);
    1114                 :      127198 :           LRA_TEMP_CLOBBER_P (PATTERN (clobber)) = 1;
    1115                 :      127198 :           LRA_SUBREG_P (new_in_reg) = 1;
    1116                 :      127198 :           if (GET_CODE (in_rtx) == SUBREG)
    1117                 :             :             {
    1118                 :        1713 :               rtx subreg_reg = SUBREG_REG (in_rtx);
    1119                 :             : 
    1120                 :             :               /* If SUBREG_REG is dying here and sub-registers IN_RTX
    1121                 :             :                  and NEW_IN_REG are similar, we can use the same hard
    1122                 :             :                  register for REG and SUBREG_REG.  */
    1123                 :        1713 :               if (REG_P (subreg_reg)
    1124                 :        1713 :                   && (int) REGNO (subreg_reg) < lra_new_regno_start
    1125                 :        1713 :                   && GET_MODE (subreg_reg) == outmode
    1126                 :        1063 :                   && known_eq (SUBREG_BYTE (in_rtx), SUBREG_BYTE (new_in_reg))
    1127                 :        1063 :                   && find_regno_note (curr_insn, REG_DEAD, REGNO (subreg_reg))
    1128                 :        1824 :                   && (! early_clobber_p
    1129                 :           0 :                       || check_conflict_input_operands (REGNO (subreg_reg),
    1130                 :             :                                                         ins)))
    1131                 :         111 :                 lra_assign_reg_val (REGNO (subreg_reg), REGNO (reg));
    1132                 :             :             }
    1133                 :             :         }
    1134                 :             :     }
    1135                 :             :   else
    1136                 :             :     {
    1137                 :             :       /* Pseudos have values -- see comments for lra_reg_info.
    1138                 :             :          Different pseudos with the same value do not conflict even if
    1139                 :             :          they live in the same place.  When we create a pseudo we
    1140                 :             :          assign value of original pseudo (if any) from which we
    1141                 :             :          created the new pseudo.  If we create the pseudo from the
    1142                 :             :          input pseudo, the new pseudo will have no conflict with the
    1143                 :             :          input pseudo which is wrong when the input pseudo lives after
    1144                 :             :          the insn and as the new pseudo value is changed by the insn
    1145                 :             :          output.  Therefore we create the new pseudo from the output
    1146                 :             :          except the case when we have single matched dying input
    1147                 :             :          pseudo.
    1148                 :             : 
    1149                 :             :          We cannot reuse the current output register because we might
    1150                 :             :          have a situation like "a <- a op b", where the constraints
    1151                 :             :          force the second input operand ("b") to match the output
    1152                 :             :          operand ("a").  "b" must then be copied into a new register
    1153                 :             :          so that it doesn't clobber the current value of "a".
    1154                 :             : 
    1155                 :             :          We cannot use the same value if the output pseudo is
    1156                 :             :          early clobbered or the input pseudo is mentioned in the
    1157                 :             :          output, e.g. as an address part in memory, because
    1158                 :             :          output reload will actually extend the pseudo liveness.
    1159                 :             :          We don't care about eliminable hard regs here as we are
    1160                 :             :          interesting only in pseudos.  */
    1161                 :             : 
    1162                 :             :       /* Matching input's register value is the same as one of the other
    1163                 :             :          output operand.  Output operands in a parallel insn must be in
    1164                 :             :          different registers.  */
    1165                 :     1585951 :       out_conflict = false;
    1166                 :     1585951 :       if (REG_P (in_rtx))
    1167                 :             :         {
    1168                 :     2706001 :           for (i = 0; outs[i] >= 0; i++)
    1169                 :             :             {
    1170                 :     1399675 :               rtx other_out_rtx = *curr_id->operand_loc[outs[i]];
    1171                 :       93124 :               if (outs[i] != out && REG_P (other_out_rtx)
    1172                 :     1492605 :                   && (regno_val_use_in (REGNO (in_rtx), other_out_rtx)
    1173                 :             :                       != NULL_RTX))
    1174                 :             :                 {
    1175                 :             :                   out_conflict = true;
    1176                 :             :                   break;
    1177                 :             :                 }
    1178                 :             :             }
    1179                 :             :         }
    1180                 :             : 
    1181                 :     1585951 :       new_in_reg = new_out_reg
    1182                 :     1553873 :         = (! early_clobber_p && ins[1] < 0 && REG_P (in_rtx)
    1183                 :     1275335 :            && (int) REGNO (in_rtx) < lra_new_regno_start
    1184                 :     1275087 :            && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
    1185                 :             :            && (! early_clobber_p
    1186                 :             :                || check_conflict_input_operands (REGNO (in_rtx), ins))
    1187                 :      418907 :            && (out < 0
    1188                 :      418907 :                || regno_val_use_in (REGNO (in_rtx), out_rtx) == NULL_RTX)
    1189                 :      418866 :            && !out_conflict
    1190                 :     2004788 :            ? lra_create_new_reg (inmode, in_rtx, goal_class,
    1191                 :             :                                  exclude_start_hard_regs, "")
    1192                 :     1167114 :            : lra_create_new_reg_with_unique_value (outmode, out_rtx, goal_class,
    1193                 :             :                                                    exclude_start_hard_regs,
    1194                 :             :                                                    ""));
    1195                 :             :     }
    1196                 :             :   /* In operand can be got from transformations before processing insn
    1197                 :             :      constraints.  One example of such transformations is subreg
    1198                 :             :      reloading (see function simplify_operand_subreg).  The new
    1199                 :             :      pseudos created by the transformations might have inaccurate
    1200                 :             :      class (ALL_REGS) and we should make their classes more
    1201                 :             :      accurate.  */
    1202                 :     1714835 :   narrow_reload_pseudo_class (in_rtx, goal_class);
    1203                 :     1714835 :   lra_emit_move (copy_rtx (new_in_reg), in_rtx);
    1204                 :     1714835 :   *before = end_sequence ();
    1205                 :             :   /* Add the new pseudo to consider values of subsequent input reload
    1206                 :             :      pseudos.  */
    1207                 :     1714835 :   lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
    1208                 :     1714835 :   curr_insn_input_reloads[curr_insn_input_reloads_num].input = in_rtx;
    1209                 :     1714835 :   curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = true;
    1210                 :     1714835 :   curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p = false;
    1211                 :     1714835 :   curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = new_in_reg;
    1212                 :     3429671 :   for (i = 0; (in = ins[i]) >= 0; i++)
    1213                 :     1714836 :     if (GET_MODE (*curr_id->operand_loc[in]) == VOIDmode
    1214                 :     1688026 :         || GET_MODE (new_in_reg) == GET_MODE (*curr_id->operand_loc[in]))
    1215                 :     1714835 :       *curr_id->operand_loc[in] = new_in_reg;
    1216                 :             :     else
    1217                 :             :       {
    1218                 :           1 :         lra_assert
    1219                 :             :           (GET_MODE (new_out_reg) == GET_MODE (*curr_id->operand_loc[in]));
    1220                 :           1 :         *curr_id->operand_loc[in] = new_out_reg;
    1221                 :             :       }
    1222                 :     1714835 :   lra_update_dups (curr_id, ins);
    1223                 :     1714835 :   if (out < 0)
    1224                 :             :     return;
    1225                 :             :   /* See a comment for the input operand above.  */
    1226                 :     1714835 :   narrow_reload_pseudo_class (out_rtx, goal_class);
    1227                 :     1714835 :   if (find_reg_note (curr_insn, REG_UNUSED, out_rtx) == NULL_RTX)
    1228                 :             :     {
    1229                 :     1633015 :       reg = SUBREG_P (out_rtx) ? SUBREG_REG (out_rtx) : out_rtx;
    1230                 :     1633015 :       start_sequence ();
    1231                 :             :       /* If we had strict_low_part, use it also in reload to keep other
    1232                 :             :          parts unchanged but do it only for regs as strict_low_part
    1233                 :             :          has no sense for memory and probably there is no insn pattern
    1234                 :             :          to match the reload insn in memory case.  */
    1235                 :     1633015 :       if (out >= 0 && curr_static_id->operand[out].strict_low && REG_P (reg))
    1236                 :           0 :         out_rtx = gen_rtx_STRICT_LOW_PART (VOIDmode, out_rtx);
    1237                 :     1633015 :       lra_emit_move (out_rtx, copy_rtx (new_out_reg));
    1238                 :     1633015 :       emit_insn (*after);
    1239                 :     1633015 :       *after = end_sequence ();
    1240                 :             :     }
    1241                 :     1714835 :   *curr_id->operand_loc[out] = new_out_reg;
    1242                 :     1714835 :   lra_update_dup (curr_id, out);
    1243                 :             : }
    1244                 :             : 
    1245                 :             : /* Return register class which is union of all reg classes in insn
    1246                 :             :    constraint alternative string starting with P.  */
    1247                 :             : static enum reg_class
    1248                 :           0 : reg_class_from_constraints (const char *p)
    1249                 :             : {
    1250                 :           0 :   int c, len;
    1251                 :           0 :   enum reg_class op_class = NO_REGS;
    1252                 :             : 
    1253                 :           0 :   do
    1254                 :           0 :     switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
    1255                 :             :       {
    1256                 :             :       case '#':
    1257                 :             :       case ',':
    1258                 :             :         return op_class;
    1259                 :             : 
    1260                 :           0 :       case 'g':
    1261                 :           0 :         op_class = reg_class_subunion[op_class][GENERAL_REGS];
    1262                 :           0 :         break;
    1263                 :             : 
    1264                 :           0 :       default:
    1265                 :           0 :         enum constraint_num cn = lookup_constraint (p);
    1266                 :           0 :         enum reg_class cl = reg_class_for_constraint (cn);
    1267                 :           0 :         if (cl == NO_REGS)
    1268                 :             :           {
    1269                 :           0 :             if (insn_extra_address_constraint (cn))
    1270                 :           0 :               op_class
    1271                 :           0 :                 = (reg_class_subunion
    1272                 :           0 :                    [op_class][base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
    1273                 :           0 :                                               ADDRESS, SCRATCH)]);
    1274                 :             :             break;
    1275                 :             :           }
    1276                 :             : 
    1277                 :           0 :         op_class = reg_class_subunion[op_class][cl];
    1278                 :           0 :         break;
    1279                 :             :       }
    1280                 :           0 :   while ((p += len), c);
    1281                 :             :   return op_class;
    1282                 :             : }
    1283                 :             : 
    1284                 :             : /* If OP is a register, return the class of the register as per
    1285                 :             :    get_reg_class, otherwise return NO_REGS.  */
    1286                 :             : static inline enum reg_class
    1287                 :   164201138 : get_op_class (rtx op)
    1288                 :             : {
    1289                 :   136503578 :   return REG_P (op) ? get_reg_class (REGNO (op)) : NO_REGS;
    1290                 :             : }
    1291                 :             : 
    1292                 :             : /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
    1293                 :             :    otherwise.  If modes of MEM_PSEUDO and VAL are different, use
    1294                 :             :    SUBREG for VAL to make them equal.  */
    1295                 :             : static rtx_insn *
    1296                 :     1225092 : emit_spill_move (bool to_p, rtx mem_pseudo, rtx val)
    1297                 :             : {
    1298                 :     1225092 :   if (GET_MODE (mem_pseudo) != GET_MODE (val))
    1299                 :             :     {
    1300                 :             :       /* Usually size of mem_pseudo is greater than val size but in
    1301                 :             :          rare cases it can be less as it can be defined by target
    1302                 :             :          dependent macro HARD_REGNO_CALLER_SAVE_MODE.  */
    1303                 :        4092 :       if (! MEM_P (val))
    1304                 :             :         {
    1305                 :        4092 :           val = gen_lowpart_SUBREG (GET_MODE (mem_pseudo),
    1306                 :             :                                     GET_CODE (val) == SUBREG
    1307                 :             :                                     ? SUBREG_REG (val) : val);
    1308                 :        4092 :           LRA_SUBREG_P (val) = 1;
    1309                 :             :         }
    1310                 :             :       else
    1311                 :             :         {
    1312                 :           0 :           mem_pseudo = gen_lowpart_SUBREG (GET_MODE (val), mem_pseudo);
    1313                 :           0 :           LRA_SUBREG_P (mem_pseudo) = 1;
    1314                 :             :         }
    1315                 :             :     }
    1316                 :     1225092 :   return to_p ? gen_move_insn (mem_pseudo, val)
    1317                 :      619218 :               : gen_move_insn (val, mem_pseudo);
    1318                 :             : }
    1319                 :             : 
    1320                 :             : /* Process a special case insn (register move), return true if we
    1321                 :             :    don't need to process it anymore.  INSN should be a single set
    1322                 :             :    insn.  Set up that RTL was changed through CHANGE_P and that hook
    1323                 :             :    TARGET_SECONDARY_MEMORY_NEEDED says to use secondary memory through
    1324                 :             :    SEC_MEM_P.  */
    1325                 :             : static bool
    1326                 :    75892882 : check_and_process_move (bool *change_p, bool *sec_mem_p ATTRIBUTE_UNUSED)
    1327                 :             : {
    1328                 :    75892882 :   int sregno, dregno;
    1329                 :    75892882 :   rtx dest, src, dreg, sreg, new_reg, scratch_reg;
    1330                 :    75892882 :   rtx_insn *before;
    1331                 :    75892882 :   enum reg_class dclass, sclass, secondary_class;
    1332                 :    75892882 :   secondary_reload_info sri;
    1333                 :             : 
    1334                 :    75892882 :   lra_assert (curr_insn_set != NULL_RTX);
    1335                 :    75892882 :   dreg = dest = SET_DEST (curr_insn_set);
    1336                 :    75892882 :   sreg = src = SET_SRC (curr_insn_set);
    1337                 :    75892882 :   if (GET_CODE (dest) == SUBREG)
    1338                 :     1157731 :     dreg = SUBREG_REG (dest);
    1339                 :    75892882 :   if (GET_CODE (src) == SUBREG)
    1340                 :     1213982 :     sreg = SUBREG_REG (src);
    1341                 :    75892882 :   if (! (REG_P (dreg) || MEM_P (dreg)) || ! (REG_P (sreg) || MEM_P (sreg)))
    1342                 :             :     return false;
    1343                 :    35460262 :   sclass = dclass = NO_REGS;
    1344                 :    35460262 :   if (REG_P (dreg))
    1345                 :    22948010 :     dclass = get_reg_class (REGNO (dreg));
    1346                 :    22948010 :   gcc_assert (dclass < LIM_REG_CLASSES && dclass >= NO_REGS);
    1347                 :    35460262 :   if (dclass == ALL_REGS)
    1348                 :             :     /* ALL_REGS is used for new pseudos created by transformations
    1349                 :             :        like reload of SUBREG_REG (see function
    1350                 :             :        simplify_operand_subreg).  We don't know their class yet.  We
    1351                 :             :        should figure out the class from processing the insn
    1352                 :             :        constraints not in this fast path function.  Even if ALL_REGS
    1353                 :             :        were a right class for the pseudo, secondary_... hooks usually
    1354                 :             :        are not define for ALL_REGS.  */
    1355                 :             :     return false;
    1356                 :    35458148 :   if (REG_P (sreg))
    1357                 :    19597747 :     sclass = get_reg_class (REGNO (sreg));
    1358                 :    19597747 :   gcc_assert (sclass < LIM_REG_CLASSES && sclass >= NO_REGS);
    1359                 :    35458148 :   if (sclass == ALL_REGS)
    1360                 :             :     /* See comments above.  */
    1361                 :             :     return false;
    1362                 :    35458148 :   if (sclass == NO_REGS && dclass == NO_REGS)
    1363                 :             :     return false;
    1364                 :    34003863 :   if (targetm.secondary_memory_needed (GET_MODE (src), sclass, dclass)
    1365                 :    34003863 :       && ((sclass != NO_REGS && dclass != NO_REGS)
    1366                 :           0 :           || (GET_MODE (src)
    1367                 :           0 :               != targetm.secondary_memory_needed_mode (GET_MODE (src)))))
    1368                 :             :     {
    1369                 :       13959 :       *sec_mem_p = true;
    1370                 :       13959 :       return false;
    1371                 :             :     }
    1372                 :    33989904 :   if (! REG_P (dreg) || ! REG_P (sreg))
    1373                 :             :     return false;
    1374                 :     7595453 :   sri.prev_sri = NULL;
    1375                 :     7595453 :   sri.icode = CODE_FOR_nothing;
    1376                 :     7595453 :   sri.extra_cost = 0;
    1377                 :     7595453 :   secondary_class = NO_REGS;
    1378                 :             :   /* Set up hard register for a reload pseudo for hook
    1379                 :             :      secondary_reload because some targets just ignore unassigned
    1380                 :             :      pseudos in the hook.  */
    1381                 :     7595453 :   if (dclass != NO_REGS && lra_get_regno_hard_regno (REGNO (dreg)) < 0)
    1382                 :             :     {
    1383                 :     2883674 :       dregno = REGNO (dreg);
    1384                 :     2883674 :       reg_renumber[dregno] = ira_class_hard_regs[dclass][0];
    1385                 :             :     }
    1386                 :             :   else
    1387                 :             :     dregno = -1;
    1388                 :     7595453 :   if (sclass != NO_REGS && lra_get_regno_hard_regno (REGNO (sreg)) < 0)
    1389                 :             :     {
    1390                 :     1267044 :       sregno = REGNO (sreg);
    1391                 :     1267044 :       reg_renumber[sregno] = ira_class_hard_regs[sclass][0];
    1392                 :             :     }
    1393                 :             :   else
    1394                 :             :     sregno = -1;
    1395                 :     7595453 :   if (sclass != NO_REGS)
    1396                 :     3812855 :     secondary_class
    1397                 :     7625710 :       = (enum reg_class) targetm.secondary_reload (false, dest,
    1398                 :             :                                                    (reg_class_t) sclass,
    1399                 :     3812855 :                                                    GET_MODE (src), &sri);
    1400                 :     3812855 :   if (sclass == NO_REGS
    1401                 :     3812855 :       || ((secondary_class != NO_REGS || sri.icode != CODE_FOR_nothing)
    1402                 :        1325 :           && dclass != NO_REGS))
    1403                 :             :     {
    1404                 :     3782598 :       enum reg_class old_sclass = secondary_class;
    1405                 :     3782598 :       secondary_reload_info old_sri = sri;
    1406                 :             : 
    1407                 :     3782598 :       sri.prev_sri = NULL;
    1408                 :     3782598 :       sri.icode = CODE_FOR_nothing;
    1409                 :     3782598 :       sri.extra_cost = 0;
    1410                 :     3782598 :       secondary_class
    1411                 :     7565196 :         = (enum reg_class) targetm.secondary_reload (true, src,
    1412                 :             :                                                      (reg_class_t) dclass,
    1413                 :     3782598 :                                                      GET_MODE (src), &sri);
    1414                 :             :       /* Check the target hook consistency.  */
    1415                 :     3782598 :       lra_assert
    1416                 :             :         ((secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
    1417                 :             :          || (old_sclass == NO_REGS && old_sri.icode == CODE_FOR_nothing)
    1418                 :             :          || (secondary_class == old_sclass && sri.icode == old_sri.icode));
    1419                 :             :     }
    1420                 :     7595453 :   if (sregno >= 0)
    1421                 :     1267044 :     reg_renumber [sregno] = -1;
    1422                 :     7595453 :   if (dregno >= 0)
    1423                 :     2883674 :     reg_renumber [dregno] = -1;
    1424                 :     7595453 :   if (secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
    1425                 :             :     return false;
    1426                 :        1325 :   *change_p = true;
    1427                 :        1325 :   new_reg = NULL_RTX;
    1428                 :           0 :   if (secondary_class != NO_REGS)
    1429                 :        1325 :     new_reg = lra_create_new_reg_with_unique_value (GET_MODE (src), NULL_RTX,
    1430                 :             :                                                     secondary_class, NULL,
    1431                 :             :                                                     "secondary");
    1432                 :        1325 :   start_sequence ();
    1433                 :        1325 :   if (sri.icode == CODE_FOR_nothing)
    1434                 :        1325 :     lra_emit_move (new_reg, src);
    1435                 :             :   else
    1436                 :             :     {
    1437                 :           0 :       enum reg_class scratch_class;
    1438                 :             : 
    1439                 :           0 :       scratch_class = (reg_class_from_constraints
    1440                 :           0 :                        (insn_data[sri.icode].operand[2].constraint));
    1441                 :           0 :       scratch_reg = (lra_create_new_reg_with_unique_value
    1442                 :           0 :                      (insn_data[sri.icode].operand[2].mode, NULL_RTX,
    1443                 :             :                       scratch_class, NULL, "scratch"));
    1444                 :           0 :       emit_insn (GEN_FCN (sri.icode) (new_reg != NULL_RTX ? new_reg : dest,
    1445                 :             :                                       src, scratch_reg));
    1446                 :             :     }
    1447                 :        1325 :   before = end_sequence ();
    1448                 :        1325 :   lra_process_new_insns (curr_insn, before, NULL, "Inserting the move");
    1449                 :        1325 :   if (new_reg != NULL_RTX)
    1450                 :        1325 :     SET_SRC (curr_insn_set) = new_reg;
    1451                 :             :   else
    1452                 :             :     {
    1453                 :           0 :       if (lra_dump_file != NULL)
    1454                 :             :         {
    1455                 :           0 :           fprintf (lra_dump_file, "Deleting move %u\n", INSN_UID (curr_insn));
    1456                 :           0 :           dump_insn_slim (lra_dump_file, curr_insn);
    1457                 :             :         }
    1458                 :           0 :       lra_set_insn_deleted (curr_insn);
    1459                 :           0 :       return true;
    1460                 :             :     }
    1461                 :        1325 :   return false;
    1462                 :             : }
    1463                 :             : 
    1464                 :             : /* The following data describe the result of process_alt_operands.
    1465                 :             :    The data are used in curr_insn_transform to generate reloads.  */
    1466                 :             : 
    1467                 :             : /* The chosen reg classes which should be used for the corresponding
    1468                 :             :    operands.  */
    1469                 :             : static enum reg_class goal_alt[MAX_RECOG_OPERANDS];
    1470                 :             : /* Hard registers which cannot be a start hard register for the corresponding
    1471                 :             :    operands.  */
    1472                 :             : static HARD_REG_SET goal_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
    1473                 :             : /* True if the operand should be the same as another operand and that
    1474                 :             :    other operand does not need a reload.  */
    1475                 :             : static bool goal_alt_match_win[MAX_RECOG_OPERANDS];
    1476                 :             : /* True if the operand does not need a reload.  */
    1477                 :             : static bool goal_alt_win[MAX_RECOG_OPERANDS];
    1478                 :             : /* True if the operand can be offsetable memory.  */
    1479                 :             : static bool goal_alt_offmemok[MAX_RECOG_OPERANDS];
    1480                 :             : /* The number of an operand to which given operand can be matched to.  */
    1481                 :             : static int goal_alt_matches[MAX_RECOG_OPERANDS];
    1482                 :             : /* The number of elements in the following array.  */
    1483                 :             : static int goal_alt_dont_inherit_ops_num;
    1484                 :             : /* Numbers of operands whose reload pseudos should not be inherited.  */
    1485                 :             : static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
    1486                 :             : /* True if we should try only this alternative for the next constraint sub-pass
    1487                 :             :    to speed up the sub-pass.  */
    1488                 :             : static bool goal_reuse_alt_p;
    1489                 :             : /* True if the insn commutative operands should be swapped.  */
    1490                 :             : static bool goal_alt_swapped;
    1491                 :             : /* The chosen insn alternative.  */
    1492                 :             : static int goal_alt_number;
    1493                 :             : /* True if output reload of the stack pointer should be generated.  */
    1494                 :             : static bool goal_alt_out_sp_reload_p;
    1495                 :             : 
    1496                 :             : /* True if the corresponding operand is the result of an equivalence
    1497                 :             :    substitution.  */
    1498                 :             : static bool equiv_substition_p[MAX_RECOG_OPERANDS];
    1499                 :             : 
    1500                 :             : /* The following five variables are used to choose the best insn
    1501                 :             :    alternative.  They reflect final characteristics of the best
    1502                 :             :    alternative.  */
    1503                 :             : 
    1504                 :             : /* Number of necessary reloads and overall cost reflecting the
    1505                 :             :    previous value and other unpleasantness of the best alternative.  */
    1506                 :             : static int best_losers, best_overall;
    1507                 :             : /* Overall number hard registers used for reloads.  For example, on
    1508                 :             :    some targets we need 2 general registers to reload DFmode and only
    1509                 :             :    one floating point register.  */
    1510                 :             : static int best_reload_nregs;
    1511                 :             : /* Overall number reflecting distances of previous reloading the same
    1512                 :             :    value.  The distances are counted from the current BB start.  It is
    1513                 :             :    used to improve inheritance chances.  */
    1514                 :             : static int best_reload_sum;
    1515                 :             : 
    1516                 :             : /* True if the current insn should have no correspondingly input or
    1517                 :             :    output reloads.  */
    1518                 :             : static bool no_input_reloads_p, no_output_reloads_p;
    1519                 :             : 
    1520                 :             : /* True if we swapped the commutative operands in the current
    1521                 :             :    insn.  */
    1522                 :             : static int curr_swapped;
    1523                 :             : 
    1524                 :             : /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
    1525                 :             :    register of class CL.  Add any input reloads to list BEFORE.  AFTER
    1526                 :             :    is nonnull if *LOC is an automodified value; handle that case by
    1527                 :             :    adding the required output reloads to list AFTER.  Return true if
    1528                 :             :    the RTL was changed.
    1529                 :             : 
    1530                 :             :    if CHECK_ONLY_P is true, check that the *LOC is a correct address
    1531                 :             :    register.  Return false if the address register is correct.  */
    1532                 :             : static bool
    1533                 :    35195792 : process_addr_reg (rtx *loc, bool check_only_p, rtx_insn **before, rtx_insn **after,
    1534                 :             :                   enum reg_class cl)
    1535                 :             : {
    1536                 :    35195792 :   int regno;
    1537                 :    35195792 :   enum reg_class rclass, new_class;
    1538                 :    35195792 :   rtx reg;
    1539                 :    35195792 :   rtx new_reg;
    1540                 :    35195792 :   machine_mode mode;
    1541                 :    35195792 :   bool subreg_p, before_p = false;
    1542                 :             : 
    1543                 :    35195792 :   subreg_p = GET_CODE (*loc) == SUBREG;
    1544                 :    35195792 :   if (subreg_p)
    1545                 :             :     {
    1546                 :       16990 :       reg = SUBREG_REG (*loc);
    1547                 :       16990 :       mode = GET_MODE (reg);
    1548                 :             : 
    1549                 :             :       /* For mode with size bigger than ptr_mode, there unlikely to be "mov"
    1550                 :             :          between two registers with different classes, but there normally will
    1551                 :             :          be "mov" which transfers element of vector register into the general
    1552                 :             :          register, and this normally will be a subreg which should be reloaded
    1553                 :             :          as a whole.  This is particularly likely to be triggered when
    1554                 :             :          -fno-split-wide-types specified.  */
    1555                 :       16990 :       if (!REG_P (reg)
    1556                 :       16990 :           || in_class_p (reg, cl, &new_class)
    1557                 :       19452 :           || known_le (GET_MODE_SIZE (mode), GET_MODE_SIZE (ptr_mode)))
    1558                 :       16990 :        loc = &SUBREG_REG (*loc);
    1559                 :             :     }
    1560                 :             : 
    1561                 :    35195792 :   reg = *loc;
    1562                 :    35195792 :   mode = GET_MODE (reg);
    1563                 :    35195792 :   if (! REG_P (reg))
    1564                 :             :     {
    1565                 :           0 :       if (check_only_p)
    1566                 :             :         return true;
    1567                 :             :       /* Always reload memory in an address even if the target supports
    1568                 :             :          such addresses.  */
    1569                 :           0 :       new_reg = lra_create_new_reg_with_unique_value (mode, reg, cl, NULL,
    1570                 :             :                                                       "address");
    1571                 :           0 :       before_p = true;
    1572                 :             :     }
    1573                 :             :   else
    1574                 :             :     {
    1575                 :    35195792 :       regno = REGNO (reg);
    1576                 :    35195792 :       rclass = get_reg_class (regno);
    1577                 :    35195792 :       if (! check_only_p
    1578                 :    35195792 :           && (*loc = get_equiv_with_elimination (reg, curr_insn)) != reg)
    1579                 :             :         {
    1580                 :      109269 :           if (lra_dump_file != NULL)
    1581                 :             :             {
    1582                 :           0 :               fprintf (lra_dump_file,
    1583                 :             :                        "Changing pseudo %d in address of insn %u on equiv ",
    1584                 :           0 :                        REGNO (reg), INSN_UID (curr_insn));
    1585                 :           0 :               dump_value_slim (lra_dump_file, *loc, 1);
    1586                 :           0 :               fprintf (lra_dump_file, "\n");
    1587                 :             :             }
    1588                 :      109269 :           *loc = copy_rtx (*loc);
    1589                 :             :         }
    1590                 :    35195792 :       if (*loc != reg || ! in_class_p (reg, cl, &new_class))
    1591                 :             :         {
    1592                 :      469746 :           if (check_only_p)
    1593                 :             :             return true;
    1594                 :      469746 :           reg = *loc;
    1595                 :      469746 :           if (get_reload_reg (after == NULL ? OP_IN : OP_INOUT,
    1596                 :             :                               mode, reg, cl, NULL,
    1597                 :             :                               subreg_p, false, "address", &new_reg))
    1598                 :             :             before_p = true;
    1599                 :             :         }
    1600                 :    34726046 :       else if (new_class != NO_REGS && rclass != new_class)
    1601                 :             :         {
    1602                 :      458339 :           if (check_only_p)
    1603                 :             :             return true;
    1604                 :      458339 :           lra_change_class (regno, new_class, "       Change to", true);
    1605                 :      458339 :           return false;
    1606                 :             :         }
    1607                 :             :       else
    1608                 :             :         return false;
    1609                 :             :     }
    1610                 :           0 :   if (before_p)
    1611                 :             :     {
    1612                 :      462251 :       push_to_sequence (*before);
    1613                 :      462251 :       lra_emit_move (new_reg, reg);
    1614                 :      462251 :       *before = end_sequence ();
    1615                 :             :     }
    1616                 :      469746 :   *loc = new_reg;
    1617                 :      469746 :   if (after != NULL)
    1618                 :             :     {
    1619                 :           0 :       start_sequence ();
    1620                 :           0 :       lra_emit_move (before_p ? copy_rtx (reg) : reg, new_reg);
    1621                 :           0 :       emit_insn (*after);
    1622                 :           0 :       *after = end_sequence ();
    1623                 :             :     }
    1624                 :             :   return true;
    1625                 :             : }
    1626                 :             : 
    1627                 :             : /* Insert move insn in simplify_operand_subreg. BEFORE returns
    1628                 :             :    the insn to be inserted before curr insn. AFTER returns the
    1629                 :             :    the insn to be inserted after curr insn.  ORIGREG and NEWREG
    1630                 :             :    are the original reg and new reg for reload.  */
    1631                 :             : static void
    1632                 :         459 : insert_move_for_subreg (rtx_insn **before, rtx_insn **after, rtx origreg,
    1633                 :             :                         rtx newreg)
    1634                 :             : {
    1635                 :         459 :   if (before)
    1636                 :             :     {
    1637                 :         459 :       push_to_sequence (*before);
    1638                 :         459 :       lra_emit_move (newreg, origreg);
    1639                 :         459 :       *before = end_sequence ();
    1640                 :             :     }
    1641                 :         459 :   if (after)
    1642                 :             :     {
    1643                 :           0 :       start_sequence ();
    1644                 :           0 :       lra_emit_move (origreg, newreg);
    1645                 :           0 :       emit_insn (*after);
    1646                 :           0 :       *after = end_sequence ();
    1647                 :             :     }
    1648                 :         459 : }
    1649                 :             : 
    1650                 :             : static bool valid_address_p (machine_mode mode, rtx addr, addr_space_t as);
    1651                 :             : static bool process_address (int, bool, rtx_insn **, rtx_insn **);
    1652                 :             : 
    1653                 :             : /* Make reloads for subreg in operand NOP with internal subreg mode
    1654                 :             :    REG_MODE, add new reloads for further processing.  Return true if
    1655                 :             :    any change was done.  */
    1656                 :             : static bool
    1657                 :   176308724 : simplify_operand_subreg (int nop, machine_mode reg_mode)
    1658                 :             : {
    1659                 :   176308724 :   int hard_regno, inner_hard_regno;
    1660                 :   176308724 :   rtx_insn *before, *after;
    1661                 :   176308724 :   machine_mode mode, innermode;
    1662                 :   176308724 :   rtx reg, new_reg;
    1663                 :   176308724 :   rtx operand = *curr_id->operand_loc[nop];
    1664                 :   176308724 :   enum reg_class regclass;
    1665                 :   176308724 :   enum op_type type;
    1666                 :             : 
    1667                 :   176308724 :   before = after = NULL;
    1668                 :             : 
    1669                 :   176308724 :   if (GET_CODE (operand) != SUBREG)
    1670                 :             :     return false;
    1671                 :             : 
    1672                 :     3623309 :   mode = GET_MODE (operand);
    1673                 :     3623309 :   reg = SUBREG_REG (operand);
    1674                 :     3623309 :   innermode = GET_MODE (reg);
    1675                 :     3623309 :   type = curr_static_id->operand[nop].type;
    1676                 :     3623309 :   if (MEM_P (reg))
    1677                 :             :     {
    1678                 :       11412 :       const bool addr_was_valid
    1679                 :       11412 :         = valid_address_p (innermode, XEXP (reg, 0), MEM_ADDR_SPACE (reg));
    1680                 :       11412 :       alter_subreg (curr_id->operand_loc[nop], false);
    1681                 :       11412 :       rtx subst = *curr_id->operand_loc[nop];
    1682                 :       11412 :       lra_assert (MEM_P (subst));
    1683                 :       11412 :       const bool addr_is_valid = valid_address_p (GET_MODE (subst),
    1684                 :             :                                                   XEXP (subst, 0),
    1685                 :       11412 :                                                   MEM_ADDR_SPACE (subst));
    1686                 :       11412 :       if (!addr_was_valid
    1687                 :       11412 :           || addr_is_valid
    1688                 :       11412 :           || ((get_constraint_type (lookup_constraint
    1689                 :           0 :                                     (curr_static_id->operand[nop].constraint))
    1690                 :             :                != CT_SPECIAL_MEMORY)
    1691                 :             :               /* We still can reload address and if the address is
    1692                 :             :                  valid, we can remove subreg without reloading its
    1693                 :             :                  inner memory.  */
    1694                 :           0 :               && valid_address_p (GET_MODE (subst),
    1695                 :           0 :                                   regno_reg_rtx
    1696                 :             :                                   [ira_class_hard_regs
    1697                 :           0 :                                    [base_reg_class (GET_MODE (subst),
    1698                 :           0 :                                                     MEM_ADDR_SPACE (subst),
    1699                 :           0 :                                                     ADDRESS, SCRATCH)][0]],
    1700                 :           0 :                                   MEM_ADDR_SPACE (subst))))
    1701                 :             :         {
    1702                 :             :           /* If we change the address for a paradoxical subreg of memory, the
    1703                 :             :              new address might violate the necessary alignment or the access
    1704                 :             :              might be slow; take this into consideration.  We need not worry
    1705                 :             :              about accesses beyond allocated memory for paradoxical memory
    1706                 :             :              subregs as we don't substitute such equiv memory (see processing
    1707                 :             :              equivalences in function lra_constraints) and because for spilled
    1708                 :             :              pseudos we allocate stack memory enough for the biggest
    1709                 :             :              corresponding paradoxical subreg.
    1710                 :             : 
    1711                 :             :              However, do not blindly simplify a (subreg (mem ...)) for
    1712                 :             :              WORD_REGISTER_OPERATIONS targets as this may lead to loading junk
    1713                 :             :              data into a register when the inner is narrower than outer or
    1714                 :             :              missing important data from memory when the inner is wider than
    1715                 :             :              outer.  This rule only applies to modes that are no wider than
    1716                 :             :              a word.
    1717                 :             : 
    1718                 :             :              If valid memory becomes invalid after subreg elimination
    1719                 :             :              and address might be different we still have to reload
    1720                 :             :              memory.
    1721                 :             :           */
    1722                 :       11412 :           if ((! addr_was_valid
    1723                 :             :                || addr_is_valid
    1724                 :           0 :                || known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (innermode)))
    1725                 :       11412 :               && !(maybe_ne (GET_MODE_PRECISION (mode),
    1726                 :       11412 :                              GET_MODE_PRECISION (innermode))
    1727                 :       13868 :                    && known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD)
    1728                 :       20069 :                    && known_le (GET_MODE_SIZE (innermode), UNITS_PER_WORD)
    1729                 :             :                    && WORD_REGISTER_OPERATIONS)
    1730                 :       24096 :               && (!(MEM_ALIGN (subst) < GET_MODE_ALIGNMENT (mode)
    1731                 :        1272 :                     && targetm.slow_unaligned_access (mode, MEM_ALIGN (subst)))
    1732                 :           0 :                   || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode)
    1733                 :           0 :                       && targetm.slow_unaligned_access (innermode,
    1734                 :           0 :                                                         MEM_ALIGN (reg)))))
    1735                 :       11412 :             return true;
    1736                 :             : 
    1737                 :           0 :           *curr_id->operand_loc[nop] = operand;
    1738                 :             : 
    1739                 :             :           /* But if the address was not valid, we cannot reload the MEM without
    1740                 :             :              reloading the address first.  */
    1741                 :           0 :           if (!addr_was_valid)
    1742                 :           0 :             process_address (nop, false, &before, &after);
    1743                 :             : 
    1744                 :             :           /* INNERMODE is fast, MODE slow.  Reload the mem in INNERMODE.  */
    1745                 :           0 :           enum reg_class rclass
    1746                 :           0 :             = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
    1747                 :           0 :           if (get_reload_reg (curr_static_id->operand[nop].type, innermode,
    1748                 :             :                               reg, rclass, NULL,
    1749                 :             :                               true, false, "slow/invalid mem", &new_reg))
    1750                 :             :             {
    1751                 :           0 :               bool insert_before, insert_after;
    1752                 :           0 :               bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
    1753                 :             : 
    1754                 :           0 :               insert_before = (type != OP_OUT
    1755                 :           0 :                                || partial_subreg_p (mode, innermode));
    1756                 :           0 :               insert_after = type != OP_IN;
    1757                 :           0 :               insert_move_for_subreg (insert_before ? &before : NULL,
    1758                 :             :                                       insert_after ? &after : NULL,
    1759                 :             :                                       reg, new_reg);
    1760                 :             :             }
    1761                 :           0 :           SUBREG_REG (operand) = new_reg;
    1762                 :             : 
    1763                 :             :           /* Convert to MODE.  */
    1764                 :           0 :           reg = operand;
    1765                 :           0 :           rclass
    1766                 :           0 :             = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
    1767                 :           0 :           if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
    1768                 :             :                               rclass, NULL,
    1769                 :             :                               true, false, "slow/invalid mem", &new_reg))
    1770                 :             :             {
    1771                 :           0 :               bool insert_before, insert_after;
    1772                 :           0 :               bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
    1773                 :             : 
    1774                 :           0 :               insert_before = type != OP_OUT;
    1775                 :           0 :               insert_after = type != OP_IN;
    1776                 :           0 :               insert_move_for_subreg (insert_before ? &before : NULL,
    1777                 :             :                                       insert_after ? &after : NULL,
    1778                 :             :                                       reg, new_reg);
    1779                 :             :             }
    1780                 :           0 :           *curr_id->operand_loc[nop] = new_reg;
    1781                 :           0 :           lra_process_new_insns (curr_insn, before, after,
    1782                 :             :                                  "Inserting slow/invalid mem reload");
    1783                 :           0 :           return true;
    1784                 :             :         }
    1785                 :             : 
    1786                 :             :       /* If the address was valid and became invalid, prefer to reload
    1787                 :             :          the memory.  Typical case is when the index scale should
    1788                 :             :          correspond the memory.  */
    1789                 :           0 :       *curr_id->operand_loc[nop] = operand;
    1790                 :             :       /* Do not return false here as the MEM_P (reg) will be processed
    1791                 :             :          later in this function.  */
    1792                 :             :     }
    1793                 :     3611897 :   else if (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER)
    1794                 :             :     {
    1795                 :          68 :       alter_subreg (curr_id->operand_loc[nop], false);
    1796                 :          68 :       return true;
    1797                 :             :     }
    1798                 :     3611829 :   else if (CONSTANT_P (reg))
    1799                 :             :     {
    1800                 :             :       /* Try to simplify subreg of constant.  It is usually result of
    1801                 :             :          equivalence substitution.  */
    1802                 :       45413 :       if (innermode == VOIDmode
    1803                 :       45413 :           && (innermode = original_subreg_reg_mode[nop]) == VOIDmode)
    1804                 :           0 :         innermode = curr_static_id->operand[nop].mode;
    1805                 :       45413 :       if ((new_reg = simplify_subreg (mode, reg, innermode,
    1806                 :       45413 :                                       SUBREG_BYTE (operand))) != NULL_RTX)
    1807                 :             :         {
    1808                 :       44995 :           *curr_id->operand_loc[nop] = new_reg;
    1809                 :       44995 :           return true;
    1810                 :             :         }
    1811                 :             :     }
    1812                 :             :   /* Put constant into memory when we have mixed modes.  It generates
    1813                 :             :      a better code in most cases as it does not need a secondary
    1814                 :             :      reload memory.  It also prevents LRA looping when LRA is using
    1815                 :             :      secondary reload memory again and again.  */
    1816                 :         836 :   if (CONSTANT_P (reg) && CONST_POOL_OK_P (reg_mode, reg)
    1817                 :     3567252 :       && SCALAR_INT_MODE_P (reg_mode) != SCALAR_INT_MODE_P (mode))
    1818                 :             :     {
    1819                 :           8 :       SUBREG_REG (operand) = force_const_mem (reg_mode, reg);
    1820                 :           8 :       alter_subreg (curr_id->operand_loc[nop], false);
    1821                 :           8 :       return true;
    1822                 :             :     }
    1823                 :     3566826 :   auto fp_subreg_can_be_simplified_after_reload_p = [] (machine_mode innermode,
    1824                 :             :                                                         poly_uint64 offset,
    1825                 :             :                                                         machine_mode mode) {
    1826                 :           0 :     reload_completed = 1;
    1827                 :           0 :     bool res = simplify_subreg_regno (FRAME_POINTER_REGNUM,
    1828                 :             :                                       innermode,
    1829                 :           0 :                                       offset, mode) >= 0;
    1830                 :           0 :     reload_completed = 0;
    1831                 :           0 :     return res;
    1832                 :             :   };
    1833                 :             :   /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
    1834                 :             :      if there may be a problem accessing OPERAND in the outer
    1835                 :             :      mode.  */
    1836                 :     3566826 :   if ((REG_P (reg)
    1837                 :     3566367 :        && REGNO (reg) >= FIRST_PSEUDO_REGISTER
    1838                 :     3566367 :        && (hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
    1839                 :             :        /* Don't reload paradoxical subregs because we could be looping
    1840                 :             :           having repeatedly final regno out of hard regs range.  */
    1841                 :     3008399 :        && (hard_regno_nregs (hard_regno, innermode)
    1842                 :     3008399 :            >= hard_regno_nregs (hard_regno, mode))
    1843                 :     3003194 :        && simplify_subreg_regno (hard_regno, innermode,
    1844                 :     3003194 :                                  SUBREG_BYTE (operand), mode) < 0
    1845                 :             :        /* Exclude reloading of frame pointer in subreg if frame pointer can not
    1846                 :             :           be simplified here only because the reload is not finished yet.  */
    1847                 :         826 :        && (hard_regno != FRAME_POINTER_REGNUM
    1848                 :           0 :            || !fp_subreg_can_be_simplified_after_reload_p (innermode,
    1849                 :           0 :                                                            SUBREG_BYTE (operand),
    1850                 :             :                                                            mode))
    1851                 :             :        /* Don't reload subreg for matching reload.  It is actually
    1852                 :             :           valid subreg in LRA.  */
    1853                 :         826 :        && ! LRA_SUBREG_P (operand))
    1854                 :     7133193 :       || CONSTANT_P (reg) || GET_CODE (reg) == PLUS || MEM_P (reg))
    1855                 :             :     {
    1856                 :         459 :       enum reg_class rclass;
    1857                 :             : 
    1858                 :         459 :       if (REG_P (reg))
    1859                 :             :         /* There is a big probability that we will get the same class
    1860                 :             :            for the new pseudo and we will get the same insn which
    1861                 :             :            means infinite looping.  So spill the new pseudo.  */
    1862                 :             :         rclass = NO_REGS;
    1863                 :             :       else
    1864                 :             :         /* The class will be defined later in curr_insn_transform.  */
    1865                 :         459 :         rclass
    1866                 :         459 :           = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
    1867                 :             : 
    1868                 :         459 :       if (get_reload_reg (curr_static_id->operand[nop].type, reg_mode, reg,
    1869                 :             :                           rclass, NULL,
    1870                 :             :                           true, false, "subreg reg", &new_reg))
    1871                 :             :         {
    1872                 :         459 :           bool insert_before, insert_after;
    1873                 :         459 :           bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
    1874                 :             : 
    1875                 :         918 :           insert_before = (type != OP_OUT
    1876                 :         459 :                            || read_modify_subreg_p (operand));
    1877                 :         459 :           insert_after = (type != OP_IN);
    1878                 :         918 :           insert_move_for_subreg (insert_before ? &before : NULL,
    1879                 :             :                                   insert_after ? &after : NULL,
    1880                 :             :                                   reg, new_reg);
    1881                 :             :         }
    1882                 :         459 :       SUBREG_REG (operand) = new_reg;
    1883                 :         459 :       lra_process_new_insns (curr_insn, before, after,
    1884                 :             :                              "Inserting subreg reload");
    1885                 :         459 :       return true;
    1886                 :             :     }
    1887                 :             :   /* Force a reload for a paradoxical subreg. For paradoxical subreg,
    1888                 :             :      IRA allocates hardreg to the inner pseudo reg according to its mode
    1889                 :             :      instead of the outermode, so the size of the hardreg may not be enough
    1890                 :             :      to contain the outermode operand, in that case we may need to insert
    1891                 :             :      reload for the reg. For the following two types of paradoxical subreg,
    1892                 :             :      we need to insert reload:
    1893                 :             :      1. If the op_type is OP_IN, and the hardreg could not be paired with
    1894                 :             :         other hardreg to contain the outermode operand
    1895                 :             :         (checked by in_hard_reg_set_p), we need to insert the reload.
    1896                 :             :      2. If the op_type is OP_OUT or OP_INOUT.
    1897                 :             : 
    1898                 :             :      Here is a paradoxical subreg example showing how the reload is generated:
    1899                 :             : 
    1900                 :             :      (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
    1901                 :             :         (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
    1902                 :             : 
    1903                 :             :      In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
    1904                 :             :      here, if reg107 is assigned to hardreg R15, because R15 is the last
    1905                 :             :      hardreg, compiler cannot find another hardreg to pair with R15 to
    1906                 :             :      contain TImode data. So we insert a TImode reload reg180 for it.
    1907                 :             :      After reload is inserted:
    1908                 :             : 
    1909                 :             :      (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
    1910                 :             :         (reg:DI 107 [ __comp ])) -1
    1911                 :             :      (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
    1912                 :             :         (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
    1913                 :             : 
    1914                 :             :      Two reload hard registers will be allocated to reg180 to save TImode data
    1915                 :             :      in LRA_assign.
    1916                 :             : 
    1917                 :             :      For LRA pseudos this should normally be handled by the biggest_mode
    1918                 :             :      mechanism.  However, it's possible for new uses of an LRA pseudo
    1919                 :             :      to be introduced after we've allocated it, such as when undoing
    1920                 :             :      inheritance, and the allocated register might not then be appropriate
    1921                 :             :      for the new uses.  */
    1922                 :     3566367 :   else if (REG_P (reg)
    1923                 :     3566367 :            && REGNO (reg) >= FIRST_PSEUDO_REGISTER
    1924                 :     3566367 :            && paradoxical_subreg_p (operand)
    1925                 :     1035132 :            && (inner_hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
    1926                 :     3566367 :            && ((hard_regno
    1927                 :     4510242 :                 = simplify_subreg_regno (inner_hard_regno, innermode,
    1928                 :      943875 :                                          SUBREG_BYTE (operand), mode)) < 0
    1929                 :      943875 :                || ((hard_regno_nregs (inner_hard_regno, innermode)
    1930                 :      943875 :                     < hard_regno_nregs (hard_regno, mode))
    1931                 :       10410 :                    && (regclass = lra_get_allocno_class (REGNO (reg)))
    1932                 :        5205 :                    && (type != OP_IN
    1933                 :        5205 :                        || !in_hard_reg_set_p (reg_class_contents[regclass],
    1934                 :             :                                               mode, hard_regno)
    1935                 :        5205 :                        || overlaps_hard_reg_set_p (lra_no_alloc_regs,
    1936                 :             :                                                    mode, hard_regno)))))
    1937                 :             :     {
    1938                 :             :       /* The class will be defined later in curr_insn_transform.  */
    1939                 :           0 :       enum reg_class rclass
    1940                 :           0 :         = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
    1941                 :             : 
    1942                 :           0 :       if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
    1943                 :             :                           rclass, NULL,
    1944                 :             :                           true, false, "paradoxical subreg", &new_reg))
    1945                 :             :         {
    1946                 :           0 :           rtx subreg;
    1947                 :           0 :           bool insert_before, insert_after;
    1948                 :             : 
    1949                 :           0 :           PUT_MODE (new_reg, mode);
    1950                 :           0 :           subreg = gen_lowpart_SUBREG (innermode, new_reg);
    1951                 :           0 :           bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
    1952                 :             : 
    1953                 :           0 :           insert_before = (type != OP_OUT);
    1954                 :           0 :           insert_after = (type != OP_IN);
    1955                 :           0 :           insert_move_for_subreg (insert_before ? &before : NULL,
    1956                 :             :                                   insert_after ? &after : NULL,
    1957                 :             :                                   reg, subreg);
    1958                 :             :         }
    1959                 :           0 :       SUBREG_REG (operand) = new_reg;
    1960                 :           0 :       lra_process_new_insns (curr_insn, before, after,
    1961                 :             :                              "Inserting paradoxical subreg reload");
    1962                 :           0 :       return true;
    1963                 :             :     }
    1964                 :             :   return false;
    1965                 :             : }
    1966                 :             : 
    1967                 :             : /* Return TRUE if X refers for a hard register from SET.  */
    1968                 :             : static bool
    1969                 :      411095 : uses_hard_regs_p (rtx x, HARD_REG_SET set)
    1970                 :             : {
    1971                 :      411095 :   int i, j, x_hard_regno;
    1972                 :      411095 :   machine_mode mode;
    1973                 :      411095 :   const char *fmt;
    1974                 :      411095 :   enum rtx_code code;
    1975                 :             : 
    1976                 :      411095 :   if (x == NULL_RTX)
    1977                 :             :     return false;
    1978                 :      411095 :   code = GET_CODE (x);
    1979                 :      411095 :   mode = GET_MODE (x);
    1980                 :             : 
    1981                 :      411095 :   if (code == SUBREG)
    1982                 :             :     {
    1983                 :             :       /* For all SUBREGs we want to check whether the full multi-register
    1984                 :             :          overlaps the set.  For normal SUBREGs this means 'get_hard_regno' of
    1985                 :             :          the inner register, for paradoxical SUBREGs this means the
    1986                 :             :          'get_hard_regno' of the full SUBREG and for complete SUBREGs either is
    1987                 :             :          fine.  Use the wider mode for all cases.  */
    1988                 :        2679 :       rtx subreg = SUBREG_REG (x);
    1989                 :        2679 :       mode = wider_subreg_mode (x);
    1990                 :        2679 :       if (mode == GET_MODE (subreg))
    1991                 :             :         {
    1992                 :        1647 :           x = subreg;
    1993                 :        1647 :           code = GET_CODE (x);
    1994                 :             :         }
    1995                 :             :     }
    1996                 :             : 
    1997                 :      411095 :   if (REG_P (x) || SUBREG_P (x))
    1998                 :             :     {
    1999                 :      265709 :       x_hard_regno = get_hard_regno (x);
    2000                 :      265709 :       return (x_hard_regno >= 0
    2001                 :      265709 :               && overlaps_hard_reg_set_p (set, mode, x_hard_regno));
    2002                 :             :     }
    2003                 :      145386 :   fmt = GET_RTX_FORMAT (code);
    2004                 :      376639 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    2005                 :             :     {
    2006                 :      233140 :       if (fmt[i] == 'e')
    2007                 :             :         {
    2008                 :      113712 :           if (uses_hard_regs_p (XEXP (x, i), set))
    2009                 :             :             return true;
    2010                 :             :         }
    2011                 :      119428 :       else if (fmt[i] == 'E')
    2012                 :             :         {
    2013                 :        4408 :           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    2014                 :        3985 :             if (uses_hard_regs_p (XVECEXP (x, i, j), set))
    2015                 :             :               return true;
    2016                 :             :         }
    2017                 :             :     }
    2018                 :             :   return false;
    2019                 :             : }
    2020                 :             : 
    2021                 :             : /* Return true if OP is a spilled pseudo. */
    2022                 :             : static inline bool
    2023                 :    81072911 : spilled_pseudo_p (rtx op)
    2024                 :             : {
    2025                 :    81072911 :   return (REG_P (op)
    2026                 :    81072911 :           && REGNO (op) >= FIRST_PSEUDO_REGISTER && in_mem_p (REGNO (op)));
    2027                 :             : }
    2028                 :             : 
    2029                 :             : /* Return true if X is a general constant.  */
    2030                 :             : static inline bool
    2031                 :     7856674 : general_constant_p (rtx x)
    2032                 :             : {
    2033                 :     7856674 :   return CONSTANT_P (x) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (x));
    2034                 :             : }
    2035                 :             : 
    2036                 :             : static bool
    2037                 :    24940836 : reg_in_class_p (rtx reg, enum reg_class cl)
    2038                 :             : {
    2039                 :    24940836 :   if (cl == NO_REGS)
    2040                 :     1104177 :     return get_reg_class (REGNO (reg)) == NO_REGS;
    2041                 :    23836659 :   return in_class_p (reg, cl, NULL);
    2042                 :             : }
    2043                 :             : 
    2044                 :             : /* Return true if SET of RCLASS contains no hard regs which can be
    2045                 :             :    used in MODE.  */
    2046                 :             : static bool
    2047                 :     3830033 : prohibited_class_reg_set_mode_p (enum reg_class rclass,
    2048                 :             :                                  HARD_REG_SET &set,
    2049                 :             :                                  machine_mode mode)
    2050                 :             : {
    2051                 :     3830033 :   HARD_REG_SET temp;
    2052                 :             : 
    2053                 :     7660066 :   lra_assert (hard_reg_set_subset_p (reg_class_contents[rclass], set));
    2054                 :     3830033 :   temp = set & ~lra_no_alloc_regs;
    2055                 :     3830033 :   return (hard_reg_set_subset_p
    2056                 :     3830033 :           (temp, ira_prohibited_class_mode_regs[rclass][mode]));
    2057                 :             : }
    2058                 :             : 
    2059                 :             : 
    2060                 :             : /* Used to check validity info about small class input operands.  It
    2061                 :             :    should be incremented at start of processing an insn
    2062                 :             :    alternative.  */
    2063                 :             : static unsigned int curr_small_class_check = 0;
    2064                 :             : 
    2065                 :             : /* Update number of used inputs of class OP_CLASS for operand NOP
    2066                 :             :    of alternative NALT.  Return true if we have more such class operands
    2067                 :             :    than the number of available regs.  */
    2068                 :             : static bool
    2069                 :   395742430 : update_and_check_small_class_inputs (int nop, int nalt,
    2070                 :             :                                      enum reg_class op_class)
    2071                 :             : {
    2072                 :   395742430 :   static unsigned int small_class_check[LIM_REG_CLASSES];
    2073                 :   395742430 :   static int small_class_input_nums[LIM_REG_CLASSES];
    2074                 :             : 
    2075                 :   392869719 :   if (SMALL_REGISTER_CLASS_P (op_class)
    2076                 :             :       /* We are interesting in classes became small because of fixing
    2077                 :             :          some hard regs, e.g. by an user through GCC options.  */
    2078                 :     2981124 :       && hard_reg_set_intersect_p (reg_class_contents[op_class],
    2079                 :     2981124 :                                    ira_no_alloc_regs)
    2080                 :   395742469 :       && (curr_static_id->operand[nop].type != OP_OUT
    2081                 :          33 :           || TEST_BIT (curr_static_id->operand[nop].early_clobber_alts, nalt)))
    2082                 :             :     {
    2083                 :           6 :       if (small_class_check[op_class] == curr_small_class_check)
    2084                 :           0 :         small_class_input_nums[op_class]++;
    2085                 :             :       else
    2086                 :             :         {
    2087                 :           6 :           small_class_check[op_class] = curr_small_class_check;
    2088                 :           6 :           small_class_input_nums[op_class] = 1;
    2089                 :             :         }
    2090                 :           6 :       if (small_class_input_nums[op_class] > ira_class_hard_regs_num[op_class])
    2091                 :             :         return true;
    2092                 :             :     }
    2093                 :             :   return false;
    2094                 :             : }
    2095                 :             : 
    2096                 :             : /* Print operand constraints for alternative ALT_NUMBER of the current
    2097                 :             :    insn.  */
    2098                 :             : static void
    2099                 :        4594 : print_curr_insn_alt (int alt_number)
    2100                 :             : {
    2101                 :       15933 :   for (int i = 0; i < curr_static_id->n_operands; i++)
    2102                 :             :     {
    2103                 :       11339 :       const char *p = (curr_static_id->operand_alternative
    2104                 :       11339 :                        [alt_number * curr_static_id->n_operands + i].constraint);
    2105                 :       11339 :       if (*p == '\0')
    2106                 :         216 :         continue;
    2107                 :       11123 :       fprintf (lra_dump_file, "  (%d) ", i);
    2108                 :       39503 :       for (; *p != '\0' && *p != ',' && *p != '#'; p++)
    2109                 :       17257 :         fputc (*p, lra_dump_file);
    2110                 :             :     }
    2111                 :        4594 : }
    2112                 :             : 
    2113                 :             : /* Major function to choose the current insn alternative and what
    2114                 :             :    operands should be reloaded and how.  If ONLY_ALTERNATIVE is not
    2115                 :             :    negative we should consider only this alternative.  Return false if
    2116                 :             :    we cannot choose the alternative or find how to reload the
    2117                 :             :    operands.  */
    2118                 :             : static bool
    2119                 :    90232421 : process_alt_operands (int only_alternative)
    2120                 :             : {
    2121                 :    90232421 :   bool ok_p = false;
    2122                 :    90232421 :   int nop, overall, nalt;
    2123                 :    90232421 :   int n_alternatives = curr_static_id->n_alternatives;
    2124                 :    90232421 :   int n_operands = curr_static_id->n_operands;
    2125                 :             :   /* LOSERS counts the operands that don't fit this alternative and
    2126                 :             :      would require loading.  */
    2127                 :    90232421 :   int losers;
    2128                 :    90232421 :   int addr_losers;
    2129                 :             :   /* REJECT is a count of how undesirable this alternative says it is
    2130                 :             :      if any reloading is required.  If the alternative matches exactly
    2131                 :             :      then REJECT is ignored, but otherwise it gets this much counted
    2132                 :             :      against it in addition to the reloading needed.  */
    2133                 :    90232421 :   int reject;
    2134                 :             :   /* This is defined by '!' or '?' alternative constraint and added to
    2135                 :             :      reject.  But in some cases it can be ignored.  */
    2136                 :    90232421 :   int static_reject;
    2137                 :    90232421 :   int op_reject;
    2138                 :             :   /* The number of elements in the following array.  */
    2139                 :    90232421 :   int early_clobbered_regs_num;
    2140                 :             :   /* Numbers of operands which are early clobber registers.  */
    2141                 :    90232421 :   int early_clobbered_nops[MAX_RECOG_OPERANDS];
    2142                 :    90232421 :   enum reg_class curr_alt[MAX_RECOG_OPERANDS];
    2143                 :    90232421 :   enum reg_class all_this_alternative;
    2144                 :    90232421 :   int all_used_nregs, all_reload_nregs;
    2145                 :    90232421 :   HARD_REG_SET curr_alt_set[MAX_RECOG_OPERANDS];
    2146                 :    90232421 :   HARD_REG_SET curr_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
    2147                 :    90232421 :   bool curr_alt_match_win[MAX_RECOG_OPERANDS];
    2148                 :    90232421 :   bool curr_alt_win[MAX_RECOG_OPERANDS];
    2149                 :    90232421 :   bool curr_alt_offmemok[MAX_RECOG_OPERANDS];
    2150                 :    90232421 :   int curr_alt_matches[MAX_RECOG_OPERANDS];
    2151                 :             :   /* The number of elements in the following array.  */
    2152                 :    90232421 :   int curr_alt_dont_inherit_ops_num;
    2153                 :             :   /* Numbers of operands whose reload pseudos should not be inherited.  */
    2154                 :    90232421 :   int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
    2155                 :    90232421 :   bool curr_reuse_alt_p;
    2156                 :             :   /* True if output stack pointer reload should be generated for the current
    2157                 :             :      alternative.  */
    2158                 :    90232421 :   bool curr_alt_out_sp_reload_p;
    2159                 :    90232421 :   bool curr_alt_class_change_p;
    2160                 :    90232421 :   rtx op;
    2161                 :             :   /* The register when the operand is a subreg of register, otherwise the
    2162                 :             :      operand itself.  */
    2163                 :    90232421 :   rtx no_subreg_reg_operand[MAX_RECOG_OPERANDS];
    2164                 :             :   /* The register if the operand is a register or subreg of register,
    2165                 :             :      otherwise NULL.  */
    2166                 :    90232421 :   rtx operand_reg[MAX_RECOG_OPERANDS];
    2167                 :    90232421 :   int hard_regno[MAX_RECOG_OPERANDS];
    2168                 :    90232421 :   machine_mode biggest_mode[MAX_RECOG_OPERANDS];
    2169                 :    90232421 :   int reload_nregs, reload_sum;
    2170                 :    90232421 :   bool costly_p;
    2171                 :    90232421 :   enum reg_class cl;
    2172                 :    90232421 :   const HARD_REG_SET *cl_filter;
    2173                 :    90232421 :   HARD_REG_SET hard_reg_constraint;
    2174                 :             : 
    2175                 :             :   /* Calculate some data common for all alternatives to speed up the
    2176                 :             :      function.  */
    2177                 :   299905895 :   for (nop = 0; nop < n_operands; nop++)
    2178                 :             :     {
    2179                 :   209673474 :       rtx reg;
    2180                 :             : 
    2181                 :   209673474 :       op = no_subreg_reg_operand[nop] = *curr_id->operand_loc[nop];
    2182                 :             :       /* The real hard regno of the operand after the allocation.  */
    2183                 :   209673474 :       hard_regno[nop] = get_hard_regno (op);
    2184                 :             : 
    2185                 :   209673474 :       operand_reg[nop] = reg = op;
    2186                 :   209673474 :       biggest_mode[nop] = GET_MODE (op);
    2187                 :   209673474 :       if (GET_CODE (op) == SUBREG)
    2188                 :             :         {
    2189                 :     4096897 :           biggest_mode[nop] = wider_subreg_mode (op);
    2190                 :     4096897 :           operand_reg[nop] = reg = SUBREG_REG (op);
    2191                 :             :         }
    2192                 :   209673474 :       if (! REG_P (reg))
    2193                 :    88875020 :         operand_reg[nop] = NULL_RTX;
    2194                 :   120798454 :       else if (REGNO (reg) >= FIRST_PSEUDO_REGISTER
    2195                 :   141943673 :                || ((int) REGNO (reg)
    2196                 :    21145219 :                    == lra_get_elimination_hard_regno (REGNO (reg))))
    2197                 :   117795464 :         no_subreg_reg_operand[nop] = reg;
    2198                 :             :       else
    2199                 :     3002990 :         operand_reg[nop] = no_subreg_reg_operand[nop]
    2200                 :             :           /* Just use natural mode for elimination result.  It should
    2201                 :             :              be enough for extra constraints hooks.  */
    2202                 :     3002990 :           = regno_reg_rtx[hard_regno[nop]];
    2203                 :             :     }
    2204                 :             : 
    2205                 :             :   /* The constraints are made of several alternatives.  Each operand's
    2206                 :             :      constraint looks like foo,bar,... with commas separating the
    2207                 :             :      alternatives.  The first alternatives for all operands go
    2208                 :             :      together, the second alternatives go together, etc.
    2209                 :             : 
    2210                 :             :      First loop over alternatives.  */
    2211                 :    90232421 :   alternative_mask preferred = curr_id->preferred_alternatives;
    2212                 :    90232421 :   if (only_alternative >= 0)
    2213                 :     1018768 :     preferred &= ALTERNATIVE_BIT (only_alternative);
    2214                 :             : 
    2215                 :   371906554 :   for (nalt = 0; nalt < n_alternatives; nalt++)
    2216                 :             :     {
    2217                 :             :       /* Loop over operands for one constraint alternative.  */
    2218                 :   358052308 :       if (!TEST_BIT (preferred, nalt))
    2219                 :    99372334 :         continue;
    2220                 :             : 
    2221                 :   258679974 :       if (lra_dump_file != NULL)
    2222                 :             :         {
    2223                 :        3400 :           fprintf (lra_dump_file, "         Considering alt=%d of insn %d: ",
    2224                 :        3400 :                    nalt, INSN_UID (curr_insn));
    2225                 :        3400 :           print_curr_insn_alt (nalt);
    2226                 :        3400 :           fprintf (lra_dump_file, "\n");
    2227                 :             :         }
    2228                 :             : 
    2229                 :   258679974 :       bool matching_early_clobber[MAX_RECOG_OPERANDS];
    2230                 :   258679974 :       curr_small_class_check++;
    2231                 :   258679974 :       overall = losers = addr_losers = 0;
    2232                 :   258679974 :       static_reject = reject = reload_nregs = reload_sum = 0;
    2233                 :   857806102 :       for (nop = 0; nop < n_operands; nop++)
    2234                 :             :         {
    2235                 :   599126128 :           int inc = (curr_static_id
    2236                 :   599126128 :                      ->operand_alternative[nalt * n_operands + nop].reject);
    2237                 :   599126128 :           if (lra_dump_file != NULL && inc != 0)
    2238                 :          53 :             fprintf (lra_dump_file,
    2239                 :             :                      "            Staticly defined alt reject+=%d\n", inc);
    2240                 :   599126128 :           static_reject += inc;
    2241                 :   599126128 :           matching_early_clobber[nop] = 0;
    2242                 :             :         }
    2243                 :             :       reject += static_reject;
    2244                 :             :       early_clobbered_regs_num = 0;
    2245                 :             :       curr_alt_out_sp_reload_p = false;
    2246                 :             :       curr_reuse_alt_p = true;
    2247                 :             :       curr_alt_class_change_p = false;
    2248                 :             :       all_this_alternative = NO_REGS;
    2249                 :             :       all_used_nregs = all_reload_nregs = 0;
    2250                 :   669118454 :       for (nop = 0; nop < n_operands; nop++)
    2251                 :             :         {
    2252                 :   533563358 :           const char *p;
    2253                 :   533563358 :           char *end;
    2254                 :   533563358 :           int len, c, m, i, opalt_num, this_alternative_matches;
    2255                 :   533563358 :           bool win, did_match, offmemok, early_clobber_p;
    2256                 :             :           /* false => this operand can be reloaded somehow for this
    2257                 :             :              alternative.  */
    2258                 :   533563358 :           bool badop;
    2259                 :             :           /* true => this operand can be reloaded if the alternative
    2260                 :             :              allows regs.  */
    2261                 :   533563358 :           bool winreg;
    2262                 :             :           /* True if a constant forced into memory would be OK for
    2263                 :             :              this operand.  */
    2264                 :   533563358 :           bool constmemok;
    2265                 :   533563358 :           enum reg_class this_alternative, this_costly_alternative;
    2266                 :   533563358 :           HARD_REG_SET this_alternative_set, this_costly_alternative_set;
    2267                 :   533563358 :           HARD_REG_SET this_alternative_exclude_start_hard_regs;
    2268                 :   533563358 :           bool this_alternative_match_win, this_alternative_win;
    2269                 :   533563358 :           bool this_alternative_offmemok;
    2270                 :   533563358 :           bool scratch_p;
    2271                 :   533563358 :           machine_mode mode;
    2272                 :   533563358 :           enum constraint_num cn;
    2273                 :   533563358 :           bool class_change_p = false;
    2274                 :             : 
    2275                 :   533563358 :           opalt_num = nalt * n_operands + nop;
    2276                 :   533563358 :           if (curr_static_id->operand_alternative[opalt_num].anything_ok)
    2277                 :             :             {
    2278                 :             :               /* Fast track for no constraints at all.  */
    2279                 :    14696050 :               curr_alt[nop] = NO_REGS;
    2280                 :    14696050 :               CLEAR_HARD_REG_SET (curr_alt_set[nop]);
    2281                 :    14696050 :               curr_alt_win[nop] = true;
    2282                 :    14696050 :               curr_alt_match_win[nop] = false;
    2283                 :    14696050 :               curr_alt_offmemok[nop] = false;
    2284                 :    14696050 :               curr_alt_matches[nop] = -1;
    2285                 :    14696050 :               continue;
    2286                 :             :             }
    2287                 :             : 
    2288                 :   518867308 :           op = no_subreg_reg_operand[nop];
    2289                 :   518867308 :           mode = curr_operand_mode[nop];
    2290                 :             : 
    2291                 :   518867308 :           win = did_match = winreg = offmemok = constmemok = false;
    2292                 :   518867308 :           badop = true;
    2293                 :             : 
    2294                 :   518867308 :           early_clobber_p = false;
    2295                 :   518867308 :           p = curr_static_id->operand_alternative[opalt_num].constraint;
    2296                 :             : 
    2297                 :   518867308 :           this_costly_alternative = this_alternative = NO_REGS;
    2298                 :             :           /* We update set of possible hard regs besides its class
    2299                 :             :              because reg class might be inaccurate.  For example,
    2300                 :             :              union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
    2301                 :             :              is translated in HI_REGS because classes are merged by
    2302                 :             :              pairs and there is no accurate intermediate class.  */
    2303                 :  2075469232 :           CLEAR_HARD_REG_SET (this_alternative_set);
    2304                 :  1556601924 :           CLEAR_HARD_REG_SET (this_costly_alternative_set);
    2305                 :   518867308 :           CLEAR_HARD_REG_SET (this_alternative_exclude_start_hard_regs);
    2306                 :   518867308 :           this_alternative_win = false;
    2307                 :   518867308 :           this_alternative_match_win = false;
    2308                 :   518867308 :           this_alternative_offmemok = false;
    2309                 :   518867308 :           this_alternative_matches = -1;
    2310                 :             : 
    2311                 :             :           /* An empty constraint should be excluded by the fast
    2312                 :             :              track.  */
    2313                 :   518867308 :           lra_assert (*p != 0 && *p != ',');
    2314                 :             : 
    2315                 :             :           op_reject = 0;
    2316                 :             :           /* Scan this alternative's specs for this operand; set WIN
    2317                 :             :              if the operand fits any letter in this alternative.
    2318                 :             :              Otherwise, clear BADOP if this operand could fit some
    2319                 :             :              letter after reloads, or set WINREG if this operand could
    2320                 :             :              fit after reloads provided the constraint allows some
    2321                 :             :              registers.  */
    2322                 :             :           costly_p = false;
    2323                 :  1318060710 :           do
    2324                 :             :             {
    2325                 :  1318060710 :               switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
    2326                 :             :                 {
    2327                 :             :                 case '\0':
    2328                 :             :                   len = 0;
    2329                 :             :                   break;
    2330                 :   495962688 :                 case ',':
    2331                 :   495962688 :                   c = '\0';
    2332                 :   495962688 :                   break;
    2333                 :             : 
    2334                 :      176597 :                 case '&':
    2335                 :      176597 :                   early_clobber_p = true;
    2336                 :      176597 :                   break;
    2337                 :             : 
    2338                 :       23094 :                 case '$':
    2339                 :       23094 :                   op_reject += LRA_MAX_REJECT;
    2340                 :       23094 :                   break;
    2341                 :           0 :                 case '^':
    2342                 :           0 :                   op_reject += LRA_LOSER_COST_FACTOR;
    2343                 :           0 :                   break;
    2344                 :             : 
    2345                 :           0 :                 case '#':
    2346                 :             :                   /* Ignore rest of this alternative.  */
    2347                 :           0 :                   c = '\0';
    2348                 :           0 :                   break;
    2349                 :             : 
    2350                 :    56615813 :                 case '0':  case '1':  case '2':  case '3':  case '4':
    2351                 :    56615813 :                 case '5':  case '6':  case '7':  case '8':  case '9':
    2352                 :    56615813 :                   {
    2353                 :    56615813 :                     int m_hregno;
    2354                 :    56615813 :                     bool match_p;
    2355                 :             : 
    2356                 :    56615813 :                     m = strtoul (p, &end, 10);
    2357                 :    56615813 :                     p = end;
    2358                 :    56615813 :                     len = 0;
    2359                 :    56615813 :                     lra_assert (nop > m);
    2360                 :             : 
    2361                 :             :                     /* Reject matches if we don't know which operand is
    2362                 :             :                        bigger.  This situation would arguably be a bug in
    2363                 :             :                        an .md pattern, but could also occur in a user asm.  */
    2364                 :   169847439 :                     if (!ordered_p (GET_MODE_SIZE (biggest_mode[m]),
    2365                 :    56615813 :                                     GET_MODE_SIZE (biggest_mode[nop])))
    2366                 :             :                       break;
    2367                 :             : 
    2368                 :             :                     /* Don't match wrong asm insn operands for proper
    2369                 :             :                        diagnostic later.  */
    2370                 :    56615813 :                     if (INSN_CODE (curr_insn) < 0
    2371                 :       31449 :                         && (curr_operand_mode[m] == BLKmode
    2372                 :       31448 :                             || curr_operand_mode[nop] == BLKmode)
    2373                 :           1 :                         && curr_operand_mode[m] != curr_operand_mode[nop])
    2374                 :             :                       break;
    2375                 :             : 
    2376                 :    56615812 :                     m_hregno = get_hard_regno (*curr_id->operand_loc[m]);
    2377                 :             :                     /* We are supposed to match a previous operand.
    2378                 :             :                        If we do, we win if that one did.  If we do
    2379                 :             :                        not, count both of the operands as losers.
    2380                 :             :                        (This is too conservative, since most of the
    2381                 :             :                        time only a single reload insn will be needed
    2382                 :             :                        to make the two operands win.  As a result,
    2383                 :             :                        this alternative may be rejected when it is
    2384                 :             :                        actually desirable.)  */
    2385                 :    56615812 :                     match_p = false;
    2386                 :    56615812 :                     if (operands_match_p (*curr_id->operand_loc[nop],
    2387                 :    56615812 :                                           *curr_id->operand_loc[m], m_hregno))
    2388                 :             :                       {
    2389                 :             :                         /* We should reject matching of an early
    2390                 :             :                            clobber operand if the matching operand is
    2391                 :             :                            not dying in the insn.  */
    2392                 :    14802894 :                         if (!TEST_BIT (curr_static_id->operand[m]
    2393                 :             :                                        .early_clobber_alts, nalt)
    2394                 :       19449 :                             || operand_reg[nop] == NULL_RTX
    2395                 :    14822343 :                             || (find_regno_note (curr_insn, REG_DEAD,
    2396                 :             :                                                  REGNO (op))
    2397                 :        4942 :                                 || REGNO (op) == REGNO (operand_reg[m])))
    2398                 :    14802894 :                           match_p = true;
    2399                 :             :                       }
    2400                 :    14802894 :                     if (match_p)
    2401                 :             :                       {
    2402                 :             :                         /* If we are matching a non-offsettable
    2403                 :             :                            address where an offsettable address was
    2404                 :             :                            expected, then we must reject this
    2405                 :             :                            combination, because we can't reload
    2406                 :             :                            it.  */
    2407                 :    14802894 :                         if (curr_alt_offmemok[m]
    2408                 :        1244 :                             && MEM_P (*curr_id->operand_loc[m])
    2409                 :           0 :                             && curr_alt[m] == NO_REGS && ! curr_alt_win[m])
    2410                 :           0 :                           continue;
    2411                 :             :                       }
    2412                 :             :                     else
    2413                 :             :                       {
    2414                 :             :                         /* If the operands do not match and one
    2415                 :             :                            operand is INOUT, we can not match them.
    2416                 :             :                            Try other possibilities, e.g. other
    2417                 :             :                            alternatives or commutative operand
    2418                 :             :                            exchange.  */
    2419                 :    41812918 :                         if (curr_static_id->operand[nop].type == OP_INOUT
    2420                 :    41812918 :                             || curr_static_id->operand[m].type == OP_INOUT)
    2421                 :             :                           break;
    2422                 :             :                         /* Operands don't match.  For asm if the operands
    2423                 :             :                            are different user defined explicit hard
    2424                 :             :                            registers, then we cannot make them match
    2425                 :             :                            when one is early clobber operand.  */
    2426                 :    41812457 :                         if ((REG_P (*curr_id->operand_loc[nop])
    2427                 :    26329029 :                              || SUBREG_P (*curr_id->operand_loc[nop]))
    2428                 :    16100513 :                             && (REG_P (*curr_id->operand_loc[m])
    2429                 :      197560 :                                 || SUBREG_P (*curr_id->operand_loc[m]))
    2430                 :    16004327 :                             && INSN_CODE (curr_insn) < 0)
    2431                 :             :                           {
    2432                 :         547 :                             rtx nop_reg = *curr_id->operand_loc[nop];
    2433                 :         547 :                             if (SUBREG_P (nop_reg))
    2434                 :           0 :                               nop_reg = SUBREG_REG (nop_reg);
    2435                 :         547 :                             rtx m_reg = *curr_id->operand_loc[m];
    2436                 :         547 :                             if (SUBREG_P (m_reg))
    2437                 :           0 :                               m_reg = SUBREG_REG (m_reg);
    2438                 :             : 
    2439                 :         547 :                             if (REG_P (nop_reg)
    2440                 :         547 :                                 && HARD_REGISTER_P (nop_reg)
    2441                 :           0 :                                 && REG_USERVAR_P (nop_reg)
    2442                 :           0 :                                 && REG_P (m_reg)
    2443                 :           0 :                                 && HARD_REGISTER_P (m_reg)
    2444                 :         547 :                                 && REG_USERVAR_P (m_reg))
    2445                 :             :                               {
    2446                 :             :                                 int i;
    2447                 :             : 
    2448                 :           0 :                                 for (i = 0; i < early_clobbered_regs_num; i++)
    2449                 :           0 :                                   if (m == early_clobbered_nops[i])
    2450                 :             :                                     break;
    2451                 :           0 :                                 if (i < early_clobbered_regs_num
    2452                 :           0 :                                     || early_clobber_p)
    2453                 :             :                                   break;
    2454                 :             :                               }
    2455                 :             :                           }
    2456                 :             :                         /* Both operands must allow a reload register,
    2457                 :             :                            otherwise we cannot make them match.  */
    2458                 :    41812457 :                         if (curr_alt[m] == NO_REGS)
    2459                 :             :                           break;
    2460                 :             :                         /* Retroactively mark the operand we had to
    2461                 :             :                            match as a loser, if it wasn't already and
    2462                 :             :                            it wasn't matched to a register constraint
    2463                 :             :                            (e.g it might be matched by memory). */
    2464                 :    41788457 :                         if (curr_alt_win[m]
    2465                 :    40933371 :                             && (operand_reg[m] == NULL_RTX
    2466                 :    40435248 :                                 || hard_regno[m] < 0))
    2467                 :             :                           {
    2468                 :     1275921 :                             if (lra_dump_file != NULL)
    2469                 :           9 :                               fprintf
    2470                 :           9 :                                 (lra_dump_file,
    2471                 :             :                                  "            %d Matched operand reload: "
    2472                 :             :                                  "losers++\n", m);
    2473                 :     1275921 :                             losers++;
    2474                 :     1275921 :                             reload_nregs
    2475                 :     1275921 :                               += (ira_reg_class_max_nregs[curr_alt[m]]
    2476                 :     1275921 :                                   [GET_MODE (*curr_id->operand_loc[m])]);
    2477                 :             :                           }
    2478                 :             : 
    2479                 :             :                         /* Prefer matching earlyclobber alternative as
    2480                 :             :                            it results in less hard regs required for
    2481                 :             :                            the insn than a non-matching earlyclobber
    2482                 :             :                            alternative.  */
    2483                 :    41788457 :                         if (TEST_BIT (curr_static_id->operand[m]
    2484                 :             :                                       .early_clobber_alts, nalt))
    2485                 :             :                           {
    2486                 :       18461 :                             if (lra_dump_file != NULL)
    2487                 :           0 :                               fprintf
    2488                 :           0 :                                 (lra_dump_file,
    2489                 :             :                                  "            %d Matching earlyclobber alt:"
    2490                 :             :                                  " reject--\n",
    2491                 :             :                                  nop);
    2492                 :       18461 :                             if (!matching_early_clobber[m])
    2493                 :             :                               {
    2494                 :       18461 :                                 reject--;
    2495                 :       18461 :                                 matching_early_clobber[m] = 1;
    2496                 :             :                               }
    2497                 :             :                           }
    2498                 :             :                         /* Otherwise we prefer no matching
    2499                 :             :                            alternatives because it gives more freedom
    2500                 :             :                            in RA.  */
    2501                 :    41769996 :                         else if (operand_reg[nop] == NULL_RTX
    2502                 :    41769996 :                                  || (find_regno_note (curr_insn, REG_DEAD,
    2503                 :    16073741 :                                                       REGNO (operand_reg[nop]))
    2504                 :             :                                      == NULL_RTX))
    2505                 :             :                           {
    2506                 :    36862539 :                             if (lra_dump_file != NULL)
    2507                 :         908 :                               fprintf
    2508                 :         908 :                                 (lra_dump_file,
    2509                 :             :                                  "            %d Matching alt: reject+=2\n",
    2510                 :             :                                  nop);
    2511                 :    36862539 :                             reject += 2;
    2512                 :             :                           }
    2513                 :             :                       }
    2514                 :             :                     /* If we have to reload this operand and some
    2515                 :             :                        previous operand also had to match the same
    2516                 :             :                        thing as this operand, we don't know how to do
    2517                 :             :                        that.  */
    2518                 :    56591351 :                     if (!match_p || !curr_alt_win[m])
    2519                 :             :                       {
    2520                 :    87774762 :                         for (i = 0; i < nop; i++)
    2521                 :    45876916 :                           if (curr_alt_matches[i] == m)
    2522                 :             :                             break;
    2523                 :    41897847 :                         if (i < nop)
    2524                 :             :                           break;
    2525                 :             :                       }
    2526                 :             :                     else
    2527                 :             :                       did_match = true;
    2528                 :             : 
    2529                 :    56591350 :                     this_alternative_matches = m;
    2530                 :             :                     /* This can be fixed with reloads if the operand
    2531                 :             :                        we are supposed to match can be fixed with
    2532                 :             :                        reloads. */
    2533                 :    56591350 :                     badop = false;
    2534                 :    56591350 :                     this_alternative = curr_alt[m];
    2535                 :    56591350 :                     this_alternative_set = curr_alt_set[m];
    2536                 :    56591350 :                     this_alternative_exclude_start_hard_regs
    2537                 :    56591350 :                         = curr_alt_exclude_start_hard_regs[m];
    2538                 :    56591350 :                     winreg = this_alternative != NO_REGS;
    2539                 :    56591350 :                     break;
    2540                 :             :                   }
    2541                 :             : 
    2542                 :    11763740 :                 case 'g':
    2543                 :    11763740 :                   if (MEM_P (op)
    2544                 :     7856674 :                       || general_constant_p (op)
    2545                 :    16329122 :                       || spilled_pseudo_p (op))
    2546                 :             :                     win = true;
    2547                 :    11763740 :                   cl = GENERAL_REGS;
    2548                 :    11763740 :                   cl_filter = nullptr;
    2549                 :    11763740 :                   goto reg;
    2550                 :             : 
    2551                 :        2403 :                 case '{':
    2552                 :        2403 :                     {
    2553                 :        2403 :                       int regno = decode_hard_reg_constraint (p);
    2554                 :        2403 :                       gcc_assert (regno >= 0);
    2555                 :        2403 :                       cl = REGNO_REG_CLASS (regno);
    2556                 :        2403 :                       CLEAR_HARD_REG_SET (hard_reg_constraint);
    2557                 :        2403 :                       SET_HARD_REG_BIT (hard_reg_constraint, regno);
    2558                 :        2403 :                       cl_filter = &hard_reg_constraint;
    2559                 :        2403 :                       goto reg;
    2560                 :             :                     }
    2561                 :             : 
    2562                 :   730611755 :                 default:
    2563                 :   730611755 :                   cn = lookup_constraint (p);
    2564                 :   730611755 :                   switch (get_constraint_type (cn))
    2565                 :             :                     {
    2566                 :   484065776 :                     case CT_REGISTER:
    2567                 :   484065776 :                       cl = reg_class_for_constraint (cn);
    2568                 :   355816223 :                       if (cl != NO_REGS)
    2569                 :             :                         {
    2570                 :   346350195 :                           cl_filter = get_register_filter (cn);
    2571                 :   346350195 :                           goto reg;
    2572                 :             :                         }
    2573                 :             :                       break;
    2574                 :             : 
    2575                 :     2070796 :                     case CT_CONST_INT:
    2576                 :     2070796 :                       if (CONST_INT_P (op)
    2577                 :     2070796 :                           && insn_const_int_ok_for_constraint (INTVAL (op), cn))
    2578                 :             :                         win = true;
    2579                 :             :                       break;
    2580                 :             : 
    2581                 :   111129798 :                     case CT_MEMORY:
    2582                 :   111129798 :                     case CT_RELAXED_MEMORY:
    2583                 :   111129798 :                       if (MEM_P (op)
    2584                 :   111129798 :                           && satisfies_memory_constraint_p (op, cn))
    2585                 :             :                         win = true;
    2586                 :    75511432 :                       else if (spilled_pseudo_p (op))
    2587                 :    45080178 :                         win = true;
    2588                 :             : 
    2589                 :             :                       /* If we didn't already win, we can reload constants
    2590                 :             :                          via force_const_mem or put the pseudo value into
    2591                 :             :                          memory, or make other memory by reloading the
    2592                 :             :                          address like for 'o'.  */
    2593                 :   116284625 :                       if (CONST_POOL_OK_P (mode, op)
    2594                 :   105974811 :                           || MEM_P (op) || REG_P (op)
    2595                 :             :                           /* We can restore the equiv insn by a
    2596                 :             :                              reload.  */
    2597                 :   111755516 :                           || equiv_substition_p[nop])
    2598                 :   111094399 :                         badop = false;
    2599                 :             :                       constmemok = true;
    2600                 :             :                       offmemok = true;
    2601                 :             :                       break;
    2602                 :             : 
    2603                 :     1774344 :                     case CT_ADDRESS:
    2604                 :             :                       /* An asm operand with an address constraint
    2605                 :             :                          that doesn't satisfy address_operand has
    2606                 :             :                          is_address cleared, so that we don't try to
    2607                 :             :                          make a non-address fit.  */
    2608                 :     1774344 :                       if (!curr_static_id->operand[nop].is_address)
    2609                 :             :                         break;
    2610                 :             :                       /* If we didn't already win, we can reload the address
    2611                 :             :                          into a base register.  */
    2612                 :     1774325 :                       if (satisfies_address_constraint_p (op, cn))
    2613                 :     1774325 :                         win = true;
    2614                 :     1774325 :                       cl = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
    2615                 :             :                                            ADDRESS, SCRATCH);
    2616                 :     1774325 :                       cl_filter = nullptr;
    2617                 :     1774325 :                       badop = false;
    2618                 :     1774325 :                       goto reg;
    2619                 :             : 
    2620                 :   130397282 :                     case CT_FIXED_FORM:
    2621                 :   130397282 :                       if (constraint_satisfied_p (op, cn))
    2622                 :  1318060710 :                         win = true;
    2623                 :             :                       break;
    2624                 :             : 
    2625                 :     1173759 :                     case CT_SPECIAL_MEMORY:
    2626                 :     1173759 :                       if (satisfies_memory_constraint_p (op, cn))
    2627                 :             :                         win = true;
    2628                 :      996097 :                       else if (spilled_pseudo_p (op))
    2629                 :             :                         {
    2630                 :  1318060710 :                           curr_reuse_alt_p = false;
    2631                 :  1318060710 :                           win = true;
    2632                 :             :                         }
    2633                 :             :                       break;
    2634                 :             :                     }
    2635                 :             :                   break;
    2636                 :             : 
    2637                 :   359890663 :                 reg:
    2638                 :   359890663 :                   if (mode == BLKmode)
    2639                 :             :                     break;
    2640                 :   359890645 :                   this_alternative = reg_class_subunion[this_alternative][cl];
    2641                 :   359890645 :                   if (hard_reg_set_subset_p (this_alternative_set,
    2642                 :   359890645 :                                              reg_class_contents[cl]))
    2643                 :   359887008 :                     this_alternative_exclude_start_hard_regs
    2644                 :   359887008 :                       = ira_exclude_class_mode_regs[cl][mode];
    2645                 :        3637 :                   else if (!hard_reg_set_subset_p (reg_class_contents[cl],
    2646                 :             :                                                    this_alternative_set))
    2647                 :        3636 :                     this_alternative_exclude_start_hard_regs
    2648                 :  1079675571 :                       |= ira_exclude_class_mode_regs[cl][mode];
    2649                 :   359890645 :                   this_alternative_set |= reg_class_contents[cl];
    2650                 :   359890645 :                   if (cl_filter)
    2651                 :        4806 :                     this_alternative_exclude_start_hard_regs |= ~*cl_filter;
    2652                 :   359890645 :                   if (costly_p)
    2653                 :             :                     {
    2654                 :    21504804 :                       this_costly_alternative
    2655                 :    21504804 :                         = reg_class_subunion[this_costly_alternative][cl];
    2656                 :    21504804 :                       this_costly_alternative_set |= reg_class_contents[cl];
    2657                 :             :                     }
    2658                 :   359890645 :                   winreg = true;
    2659                 :   359890645 :                   if (REG_P (op))
    2660                 :             :                     {
    2661                 :   229129121 :                       tree decl;
    2662                 :   229129121 :                       if (hard_regno[nop] >= 0
    2663                 :   193228731 :                           && in_hard_reg_set_p (this_alternative_set,
    2664                 :             :                                                 mode, hard_regno[nop])
    2665                 :   174669135 :                           && (!cl_filter
    2666                 :        1268 :                               || TEST_HARD_REG_BIT (*cl_filter,
    2667                 :             :                                                     hard_regno[nop]))
    2668                 :   403798250 :                           && ((REG_ATTRS (op) && (decl = REG_EXPR (op)) != NULL
    2669                 :    97502232 :                                && VAR_P (decl) && DECL_HARD_REGISTER (decl))
    2670                 :   174665872 :                               || !(TEST_HARD_REG_BIT
    2671                 :   174665872 :                                    (this_alternative_exclude_start_hard_regs,
    2672                 :             :                                     hard_regno[nop]))))
    2673                 :             :                         win = true;
    2674                 :    54460016 :                       else if (hard_regno[nop] < 0)
    2675                 :             :                         {
    2676                 :    35900390 :                           if (in_class_p (op, this_alternative, NULL))
    2677                 :             :                             win = true;
    2678                 :    26912221 :                           else if (in_class_p (op, this_alternative, NULL, true))
    2679                 :             :                             {
    2680                 :  1318060710 :                               class_change_p = true;
    2681                 :  1318060710 :                               win = true;
    2682                 :             :                             }
    2683                 :             :                         }
    2684                 :             :                     }
    2685                 :             :                   break;
    2686                 :             :                 }
    2687                 :  1318060710 :               if (c != ' ' && c != '\t')
    2688                 :  1318060710 :                 costly_p = c == '*';
    2689                 :             :             }
    2690                 :  1318060710 :           while ((p += len), c);
    2691                 :             : 
    2692                 :  1037734616 :           scratch_p = (operand_reg[nop] != NULL_RTX
    2693                 :   518867308 :                        && ira_former_scratch_p (REGNO (operand_reg[nop])));
    2694                 :             :           /* Record which operands fit this alternative.  */
    2695                 :   518867308 :           if (win)
    2696                 :             :             {
    2697                 :   279507858 :               if (early_clobber_p
    2698                 :   279364973 :                   || curr_static_id->operand[nop].type != OP_OUT)
    2699                 :             :                 {
    2700                 :   122081717 :                   if (winreg)
    2701                 :   100764699 :                     all_used_nregs
    2702                 :   100764699 :                       += ira_reg_class_min_nregs[this_alternative][mode];
    2703                 :   122081717 :                   all_this_alternative
    2704                 :   122081717 :                     = (reg_class_subunion
    2705                 :   122081717 :                        [all_this_alternative][this_alternative]);
    2706                 :             :                 }
    2707                 :   279507858 :               this_alternative_win = true;
    2708                 :   279507858 :               if (class_change_p)
    2709                 :             :                 {
    2710                 :      288974 :                   curr_alt_class_change_p = true;
    2711                 :      288974 :                   if (lra_dump_file != NULL)
    2712                 :           8 :                     fprintf (lra_dump_file,
    2713                 :             :                              "            %d Narrowing class: reject+=3\n",
    2714                 :             :                              nop);
    2715                 :      288974 :                   reject += 3;
    2716                 :             :                 }
    2717                 :   279507858 :               if (operand_reg[nop] != NULL_RTX)
    2718                 :             :                 {
    2719                 :   194820945 :                   if (hard_regno[nop] >= 0)
    2720                 :             :                     {
    2721                 :   174613417 :                       if (in_hard_reg_set_p (this_costly_alternative_set,
    2722                 :             :                                              mode, hard_regno[nop]))
    2723                 :             :                         {
    2724                 :      769718 :                           if (lra_dump_file != NULL)
    2725                 :          21 :                             fprintf (lra_dump_file,
    2726                 :             :                                      "            %d Costly set: reject++\n",
    2727                 :             :                                      nop);
    2728                 :      769718 :                           reject++;
    2729                 :             :                         }
    2730                 :             :                     }
    2731                 :             :                   else
    2732                 :             :                     {
    2733                 :             :                       /* Prefer won reg to spilled pseudo under other
    2734                 :             :                          equal conditions for possibe inheritance.  */
    2735                 :    20207528 :                       if (! scratch_p)
    2736                 :             :                         {
    2737                 :    20203044 :                           if (lra_dump_file != NULL)
    2738                 :          56 :                             fprintf
    2739                 :          56 :                               (lra_dump_file,
    2740                 :             :                                "            %d Non pseudo reload: reject++\n",
    2741                 :             :                                nop);
    2742                 :    20203044 :                           reject++;
    2743                 :             :                         }
    2744                 :    20207528 :                       if (in_class_p (operand_reg[nop],
    2745                 :             :                                       this_costly_alternative, NULL, true))
    2746                 :             :                         {
    2747                 :      132192 :                           if (lra_dump_file != NULL)
    2748                 :           0 :                             fprintf
    2749                 :           0 :                               (lra_dump_file,
    2750                 :             :                                "            %d Non pseudo costly reload:"
    2751                 :             :                                " reject++\n",
    2752                 :             :                                nop);
    2753                 :      132192 :                           reject++;
    2754                 :             :                         }
    2755                 :             :                     }
    2756                 :             :                   /* We simulate the behavior of old reload here.
    2757                 :             :                      Although scratches need hard registers and it
    2758                 :             :                      might result in spilling other pseudos, no reload
    2759                 :             :                      insns are generated for the scratches.  So it
    2760                 :             :                      might cost something but probably less than old
    2761                 :             :                      reload pass believes.  */
    2762                 :   194820945 :                   if (scratch_p)
    2763                 :             :                     {
    2764                 :      120184 :                       if (lra_dump_file != NULL)
    2765                 :           6 :                         fprintf (lra_dump_file,
    2766                 :             :                                  "            %d Scratch win: reject+=2\n",
    2767                 :             :                                  nop);
    2768                 :      120184 :                       reject += 2;
    2769                 :             :                     }
    2770                 :             :                 }
    2771                 :             :             }
    2772                 :   239359450 :           else if (did_match)
    2773                 :             :             this_alternative_match_win = true;
    2774                 :             :           else
    2775                 :             :             {
    2776                 :   224665946 :               int const_to_mem = 0;
    2777                 :   224665946 :               bool no_regs_p;
    2778                 :             : 
    2779                 :   224665946 :               reject += op_reject;
    2780                 :             :               /* Mark output reload of the stack pointer.  */
    2781                 :   224665946 :               if (op == stack_pointer_rtx
    2782                 :       57267 :                   && curr_static_id->operand[nop].type != OP_IN)
    2783                 :   224665946 :                 curr_alt_out_sp_reload_p = true;
    2784                 :             : 
    2785                 :             :               /* If this alternative asks for a specific reg class, see if there
    2786                 :             :                  is at least one allocatable register in that class.  */
    2787                 :   224665946 :               no_regs_p
    2788                 :   392118516 :                 = (this_alternative == NO_REGS
    2789                 :   224665946 :                    || (hard_reg_set_subset_p
    2790                 :   334905162 :                        (reg_class_contents[this_alternative],
    2791                 :             :                         lra_no_alloc_regs)));
    2792                 :             : 
    2793                 :             :               /* For asms, verify that the class for this alternative is possible
    2794                 :             :                  for the mode that is specified.  */
    2795                 :   167452570 :               if (!no_regs_p && INSN_CODE (curr_insn) < 0)
    2796                 :             :                 {
    2797                 :             :                   int i;
    2798                 :       68204 :                   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    2799                 :       68202 :                     if (targetm.hard_regno_mode_ok (i, mode)
    2800                 :       68202 :                         && in_hard_reg_set_p (reg_class_contents[this_alternative],
    2801                 :             :                                               mode, i))
    2802                 :             :                       break;
    2803                 :       20630 :                   if (i == FIRST_PSEUDO_REGISTER)
    2804                 :   224665946 :                     winreg = false;
    2805                 :             :                 }
    2806                 :             : 
    2807                 :             :               /* If this operand accepts a register, and if the
    2808                 :             :                  register class has at least one allocatable register,
    2809                 :             :                  then this operand can be reloaded.  */
    2810                 :   224665946 :               if (winreg && !no_regs_p)
    2811                 :             :                 badop = false;
    2812                 :             : 
    2813                 :    57213378 :               if (badop)
    2814                 :             :                 {
    2815                 :    47654213 :                   if (lra_dump_file != NULL)
    2816                 :         606 :                     fprintf (lra_dump_file,
    2817                 :             :                              "            Bad operand -- refuse\n");
    2818                 :   123124878 :                   goto fail;
    2819                 :             :                 }
    2820                 :             : 
    2821                 :   177011733 :               if (this_alternative != NO_REGS)
    2822                 :             :                 {
    2823                 :   167452569 :                   HARD_REG_SET available_regs
    2824                 :   167452569 :                     = (reg_class_contents[this_alternative]
    2825                 :   167452569 :                        & ~((ira_prohibited_class_mode_regs
    2826                 :   167452569 :                             [this_alternative][mode])
    2827                 :   167452569 :                            | lra_no_alloc_regs));
    2828                 :   334905138 :                   if (!hard_reg_set_empty_p (available_regs))
    2829                 :             :                     {
    2830                 :   167451227 :                       if (early_clobber_p
    2831                 :   167417515 :                           || curr_static_id->operand[nop].type != OP_OUT)
    2832                 :             :                         {
    2833                 :    88035552 :                           all_reload_nregs
    2834                 :    88035552 :                             += ira_reg_class_min_nregs[this_alternative][mode];
    2835                 :    88035552 :                           all_this_alternative
    2836                 :    88035552 :                             = (reg_class_subunion
    2837                 :    88035552 :                                [all_this_alternative][this_alternative]);
    2838                 :             :                         }
    2839                 :             :                     }
    2840                 :             :                   else
    2841                 :             :                     {
    2842                 :             :                       /* There are no hard regs holding a value of given
    2843                 :             :                          mode.  */
    2844                 :        1342 :                       if (offmemok)
    2845                 :             :                         {
    2846                 :         175 :                           this_alternative = NO_REGS;
    2847                 :         175 :                           if (lra_dump_file != NULL)
    2848                 :           0 :                             fprintf (lra_dump_file,
    2849                 :             :                                      "            %d Using memory because of"
    2850                 :             :                                      " a bad mode: reject+=2\n",
    2851                 :             :                                      nop);
    2852                 :         175 :                           reject += 2;
    2853                 :             :                         }
    2854                 :             :                       else
    2855                 :             :                         {
    2856                 :        1167 :                           if (lra_dump_file != NULL)
    2857                 :           0 :                             fprintf (lra_dump_file,
    2858                 :             :                                      "            Wrong mode -- refuse\n");
    2859                 :        1167 :                           goto fail;
    2860                 :             :                         }
    2861                 :             :                     }
    2862                 :             :                 }
    2863                 :             : 
    2864                 :             :               /* If not assigned pseudo has a class which a subset of
    2865                 :             :                  required reg class, it is a less costly alternative
    2866                 :             :                  as the pseudo still can get a hard reg of necessary
    2867                 :             :                  class.  */
    2868                 :   167451402 :               if (! no_regs_p && REG_P (op) && hard_regno[nop] < 0
    2869                 :    21475642 :                   && (cl = get_reg_class (REGNO (op))) != NO_REGS
    2870                 :   180119452 :                   && ira_class_subset_p[this_alternative][cl])
    2871                 :             :                 {
    2872                 :        1051 :                   if (lra_dump_file != NULL)
    2873                 :           0 :                     fprintf
    2874                 :           0 :                       (lra_dump_file,
    2875                 :             :                        "            %d Super set class reg: reject-=3\n", nop);
    2876                 :        1051 :                   reject -= 3;
    2877                 :             :                 }
    2878                 :             : 
    2879                 :   177010566 :               this_alternative_offmemok = offmemok;
    2880                 :   177010566 :               if (this_costly_alternative != NO_REGS)
    2881                 :             :                 {
    2882                 :    19335834 :                   if (lra_dump_file != NULL)
    2883                 :          25 :                     fprintf (lra_dump_file,
    2884                 :             :                              "            %d Costly loser: reject++\n", nop);
    2885                 :    19335834 :                   reject++;
    2886                 :             :                 }
    2887                 :             :               /* If the operand is dying, has a matching constraint,
    2888                 :             :                  and satisfies constraints of the matched operand
    2889                 :             :                  which failed to satisfy the own constraints, most probably
    2890                 :             :                  the reload for this operand will be gone.  */
    2891                 :   177010566 :               if (this_alternative_matches >= 0
    2892                 :    41881651 :                   && !curr_alt_win[this_alternative_matches]
    2893                 :      964068 :                   && REG_P (op)
    2894                 :      695321 :                   && find_regno_note (curr_insn, REG_DEAD, REGNO (op))
    2895                 :   177718524 :                   && (hard_regno[nop] >= 0
    2896                 :      370359 :                       ? in_hard_reg_set_p (this_alternative_set,
    2897                 :             :                                            mode, hard_regno[nop])
    2898                 :       32760 :                       : in_class_p (op, this_alternative, NULL)))
    2899                 :             :                 {
    2900                 :      225723 :                   if (lra_dump_file != NULL)
    2901                 :           1 :                     fprintf
    2902                 :           1 :                       (lra_dump_file,
    2903                 :             :                        "            %d Dying matched operand reload: reject++\n",
    2904                 :             :                        nop);
    2905                 :      225723 :                   reject++;
    2906                 :             :                 }
    2907                 :             :               else
    2908                 :             :                 {
    2909                 :             :                   /* Strict_low_part requires to reload the register
    2910                 :             :                      not the sub-register.  In this case we should
    2911                 :             :                      check that a final reload hard reg can hold the
    2912                 :             :                      value mode.  */
    2913                 :   176784843 :                   if (curr_static_id->operand[nop].strict_low
    2914                 :         115 :                       && REG_P (op)
    2915                 :         108 :                       && hard_regno[nop] < 0
    2916                 :          83 :                       && GET_CODE (*curr_id->operand_loc[nop]) == SUBREG
    2917                 :          83 :                       && ira_class_hard_regs_num[this_alternative] > 0
    2918                 :   176784926 :                       && (!targetm.hard_regno_mode_ok
    2919                 :          83 :                           (ira_class_hard_regs[this_alternative][0],
    2920                 :          83 :                            GET_MODE (*curr_id->operand_loc[nop]))))
    2921                 :             :                     {
    2922                 :           0 :                       if (lra_dump_file != NULL)
    2923                 :           0 :                         fprintf
    2924                 :           0 :                           (lra_dump_file,
    2925                 :             :                            "            Strict low subreg reload -- refuse\n");
    2926                 :           0 :                       goto fail;
    2927                 :             :                     }
    2928                 :   176784843 :                   if (lra_dump_file != NULL)
    2929                 :        2163 :                     fprintf
    2930                 :        2163 :                       (lra_dump_file,
    2931                 :             :                        "            %d Operand reload: losers++\n", nop);
    2932                 :   176784843 :                   losers++;
    2933                 :             :                 }
    2934                 :   177010566 :               if (operand_reg[nop] != NULL_RTX
    2935                 :             :                   /* Output operands and matched input operands are
    2936                 :             :                      not inherited.  The following conditions do not
    2937                 :             :                      exactly describe the previous statement but they
    2938                 :             :                      are pretty close.  */
    2939                 :    63712554 :                   && curr_static_id->operand[nop].type != OP_OUT
    2940                 :    27786589 :                   && (this_alternative_matches < 0
    2941                 :    16163576 :                       || curr_static_id->operand[nop].type != OP_IN))
    2942                 :             :                 {
    2943                 :    11623013 :                   int last_reload = (lra_reg_info[ORIGINAL_REGNO
    2944                 :    11623013 :                                                   (operand_reg[nop])]
    2945                 :    11623013 :                                      .last_reload);
    2946                 :             : 
    2947                 :             :                   /* The value of reload_sum has sense only if we
    2948                 :             :                      process insns in their order.  It happens only on
    2949                 :             :                      the first constraints sub-pass when we do most of
    2950                 :             :                      reload work.  */
    2951                 :    11623013 :                   if (lra_constraint_iter == 1 && last_reload > bb_reload_num)
    2952                 :     2528774 :                     reload_sum += last_reload - bb_reload_num;
    2953                 :             :                 }
    2954                 :             :               /* If this is a constant that is reloaded into the
    2955                 :             :                  desired class by copying it to memory first, count
    2956                 :             :                  that as another reload.  This is consistent with
    2957                 :             :                  other code and is required to avoid choosing another
    2958                 :             :                  alternative when the constant is moved into memory.
    2959                 :             :                  Note that the test here is precisely the same as in
    2960                 :             :                  the code below that calls force_const_mem.  */
    2961                 :   227748143 :               if (CONST_POOL_OK_P (mode, op)
    2962                 :   227748210 :                   && ((targetm.preferred_reload_class
    2963                 :    50737644 :                        (op, this_alternative) == NO_REGS)
    2964                 :    49164541 :                       || no_input_reloads_p))
    2965                 :             :                 {
    2966                 :     1573103 :                   const_to_mem = 1;
    2967                 :     1573103 :                   if (! no_regs_p)
    2968                 :             :                     {
    2969                 :      716311 :                       if (lra_dump_file != NULL)
    2970                 :           0 :                         fprintf
    2971                 :           0 :                           (lra_dump_file,
    2972                 :             :                            "            %d Constant reload through memory: "
    2973                 :             :                            "losers++\n", nop);
    2974                 :      716311 :                       losers++;
    2975                 :             :                     }
    2976                 :             :                 }
    2977                 :             : 
    2978                 :             :               /* Alternative loses if it requires a type of reload not
    2979                 :             :                  permitted for this insn.  We can always reload
    2980                 :             :                  objects with a REG_UNUSED note.  */
    2981                 :   177010566 :               if ((curr_static_id->operand[nop].type != OP_IN
    2982                 :    85735897 :                    && no_output_reloads_p
    2983                 :           0 :                    && ! find_reg_note (curr_insn, REG_UNUSED, op))
    2984                 :   177010566 :                   || (curr_static_id->operand[nop].type != OP_OUT
    2985                 :    91274874 :                       && no_input_reloads_p && ! const_to_mem)
    2986                 :   354021132 :                   || (this_alternative_matches >= 0
    2987                 :    41881651 :                       && (no_input_reloads_p
    2988                 :    41881651 :                           || (no_output_reloads_p
    2989                 :           0 :                               && (curr_static_id->operand
    2990                 :           0 :                                   [this_alternative_matches].type != OP_IN)
    2991                 :           0 :                               && ! find_reg_note (curr_insn, REG_UNUSED,
    2992                 :             :                                                   no_subreg_reg_operand
    2993                 :           0 :                                                   [this_alternative_matches])))))
    2994                 :             :                 {
    2995                 :           0 :                   if (lra_dump_file != NULL)
    2996                 :           0 :                     fprintf
    2997                 :           0 :                       (lra_dump_file,
    2998                 :             :                        "            No input/output reload -- refuse\n");
    2999                 :           0 :                   goto fail;
    3000                 :             :                 }
    3001                 :             : 
    3002                 :             :               /* Alternative loses if it required class pseudo cannot
    3003                 :             :                  hold value of required mode.  Such insns can be
    3004                 :             :                  described by insn definitions with mode iterators.  */
    3005                 :   177010566 :               if (GET_MODE (*curr_id->operand_loc[nop]) != VOIDmode
    3006                 :   127681514 :                   && ! hard_reg_set_empty_p (this_alternative_set)
    3007                 :             :                   /* It is common practice for constraints to use a
    3008                 :             :                      class which does not have actually enough regs to
    3009                 :             :                      hold the value (e.g. x86 AREG for mode requiring
    3010                 :             :                      more one general reg).  Therefore we have 2
    3011                 :             :                      conditions to check that the reload pseudo cannot
    3012                 :             :                      hold the mode value.  */
    3013                 :   118879641 :                   && (!targetm.hard_regno_mode_ok
    3014                 :   118879641 :                       (ira_class_hard_regs[this_alternative][0],
    3015                 :             :                        GET_MODE (*curr_id->operand_loc[nop])))
    3016                 :             :                   /* The above condition is not enough as the first
    3017                 :             :                      reg in ira_class_hard_regs can be not aligned for
    3018                 :             :                      multi-words mode values.  */
    3019                 :   177010566 :                   && (prohibited_class_reg_set_mode_p
    3020                 :           0 :                       (this_alternative, this_alternative_set,
    3021                 :           0 :                        GET_MODE (*curr_id->operand_loc[nop]))))
    3022                 :             :                 {
    3023                 :           0 :                   if (lra_dump_file != NULL)
    3024                 :           0 :                     fprintf (lra_dump_file,
    3025                 :             :                              "            reload pseudo for op %d "
    3026                 :             :                              "cannot hold the mode value -- refuse\n",
    3027                 :             :                              nop);
    3028                 :           0 :                   goto fail;
    3029                 :             :                 }
    3030                 :             : 
    3031                 :             :               /* Check strong discouragement of reload of non-constant
    3032                 :             :                  into class THIS_ALTERNATIVE.  */
    3033                 :   126272922 :               if (! CONSTANT_P (op) && ! no_regs_p
    3034                 :   294581116 :                   && (targetm.preferred_reload_class
    3035                 :   117570550 :                       (op, this_alternative) == NO_REGS
    3036                 :   109004196 :                       || (curr_static_id->operand[nop].type == OP_OUT
    3037                 :    74999713 :                           && (targetm.preferred_output_reload_class
    3038                 :    74999713 :                               (op, this_alternative) == NO_REGS))))
    3039                 :             :                 {
    3040                 :    13083507 :                   if (offmemok && REG_P (op))
    3041                 :             :                     {
    3042                 :      782019 :                       if (lra_dump_file != NULL)
    3043                 :           0 :                         fprintf
    3044                 :           0 :                           (lra_dump_file,
    3045                 :             :                            "            %d Spill pseudo into memory: reject+=3\n",
    3046                 :             :                            nop);
    3047                 :      782019 :                       reject += 3;
    3048                 :             :                     }
    3049                 :             :                   else
    3050                 :             :                     {
    3051                 :    12301488 :                       if (lra_dump_file != NULL)
    3052                 :           0 :                         fprintf
    3053                 :           0 :                           (lra_dump_file,
    3054                 :             :                            "            %d Non-prefered reload: reject+=%d\n",
    3055                 :             :                            nop, LRA_MAX_REJECT);
    3056                 :    12301488 :                       reject += LRA_MAX_REJECT;
    3057                 :             :                     }
    3058                 :             :                 }
    3059                 :             : 
    3060                 :   177010566 :               if (! (MEM_P (op) && offmemok)
    3061                 :   177010494 :                   && ! (const_to_mem && constmemok))
    3062                 :             :                 {
    3063                 :             :                   /* We prefer to reload pseudos over reloading other
    3064                 :             :                      things, since such reloads may be able to be
    3065                 :             :                      eliminated later.  So bump REJECT in other cases.
    3066                 :             :                      Don't do this in the case where we are forcing a
    3067                 :             :                      constant into memory and it will then win since
    3068                 :             :                      we don't want to have a different alternative
    3069                 :             :                      match then.  */
    3070                 :   176037567 :                   if (! (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER))
    3071                 :             :                     {
    3072                 :   126181223 :                       if (lra_dump_file != NULL)
    3073                 :        1641 :                         fprintf
    3074                 :        1641 :                           (lra_dump_file,
    3075                 :             :                            "            %d Non-pseudo reload: reject+=2\n",
    3076                 :             :                            nop);
    3077                 :   126181223 :                       reject += 2;
    3078                 :             :                     }
    3079                 :             : 
    3080                 :   176037567 :                   if (! no_regs_p)
    3081                 :   167335239 :                     reload_nregs
    3082                 :   167335239 :                       += ira_reg_class_max_nregs[this_alternative][mode];
    3083                 :             : 
    3084                 :   176037567 :                   if (SMALL_REGISTER_CLASS_P (this_alternative))
    3085                 :             :                     {
    3086                 :      822156 :                       if (lra_dump_file != NULL)
    3087                 :          45 :                         fprintf
    3088                 :          45 :                           (lra_dump_file,
    3089                 :             :                            "            %d Small class reload: reject+=%d\n",
    3090                 :             :                            nop, LRA_LOSER_COST_FACTOR / 2);
    3091                 :      822156 :                       reject += LRA_LOSER_COST_FACTOR / 2;
    3092                 :             :                     }
    3093                 :             :                 }
    3094                 :             : 
    3095                 :             :               /* We are trying to spill pseudo into memory.  It is
    3096                 :             :                  usually more costly than moving to a hard register
    3097                 :             :                  although it might takes the same number of
    3098                 :             :                  reloads.
    3099                 :             : 
    3100                 :             :                  Non-pseudo spill may happen also.  Suppose a target allows both
    3101                 :             :                  register and memory in the operand constraint alternatives,
    3102                 :             :                  then it's typical that an eliminable register has a substition
    3103                 :             :                  of "base + offset" which can either be reloaded by a simple
    3104                 :             :                  "new_reg <= base + offset" which will match the register
    3105                 :             :                  constraint, or a similar reg addition followed by further spill
    3106                 :             :                  to and reload from memory which will match the memory
    3107                 :             :                  constraint, but this memory spill will be much more costly
    3108                 :             :                  usually.
    3109                 :             : 
    3110                 :             :                  Code below increases the reject for both pseudo and non-pseudo
    3111                 :             :                  spill.  */
    3112                 :   177010566 :               if (no_regs_p
    3113                 :     9559164 :                   && !(MEM_P (op) && offmemok)
    3114                 :     9559120 :                   && !(REG_P (op) && hard_regno[nop] < 0))
    3115                 :             :                 {
    3116                 :     8437261 :                   if (lra_dump_file != NULL)
    3117                 :          12 :                     fprintf
    3118                 :          18 :                       (lra_dump_file,
    3119                 :             :                        "            %d Spill %spseudo into memory: reject+=3\n",
    3120                 :             :                        nop, REG_P (op) ? "" : "Non-");
    3121                 :     8437261 :                   reject += 3;
    3122                 :     8437261 :                   if (VECTOR_MODE_P (mode))
    3123                 :             :                     {
    3124                 :             :                       /* Spilling vectors into memory is usually more
    3125                 :             :                          costly as they contain big values.  */
    3126                 :      356742 :                       if (lra_dump_file != NULL)
    3127                 :           0 :                         fprintf
    3128                 :           0 :                           (lra_dump_file,
    3129                 :             :                            "            %d Spill vector pseudo: reject+=2\n",
    3130                 :             :                            nop);
    3131                 :      356742 :                       reject += 2;
    3132                 :             :                     }
    3133                 :             :                 }
    3134                 :             : 
    3135                 :             :               /* When we use an operand requiring memory in given
    3136                 :             :                  alternative, the insn should write *and* read the
    3137                 :             :                  value to/from memory it is costly in comparison with
    3138                 :             :                  an insn alternative which does not use memory
    3139                 :             :                  (e.g. register or immediate operand).  We exclude
    3140                 :             :                  memory operand for such case as we can satisfy the
    3141                 :             :                  memory constraints by reloading address.  */
    3142                 :     9559164 :               if (no_regs_p && offmemok && !MEM_P (op))
    3143                 :             :                 {
    3144                 :     9559024 :                   if (lra_dump_file != NULL)
    3145                 :          26 :                     fprintf
    3146                 :          26 :                       (lra_dump_file,
    3147                 :             :                        "            Using memory insn operand %d: reject+=3\n",
    3148                 :             :                        nop);
    3149                 :     9559024 :                   reject += 3;
    3150                 :             :                 }
    3151                 :             : 
    3152                 :             :               /* If reload requires moving value through secondary
    3153                 :             :                  memory, it will need one more insn at least.  */
    3154                 :   177010566 :               if (this_alternative != NO_REGS
    3155                 :   167451227 :                   && REG_P (op) && (cl = get_reg_class (REGNO (op))) != NO_REGS
    3156                 :   213659585 :                   && ((curr_static_id->operand[nop].type != OP_OUT
    3157                 :    20460538 :                        && targetm.secondary_memory_needed (mode, cl,
    3158                 :             :                                                            this_alternative))
    3159                 :    33415038 :                       || (curr_static_id->operand[nop].type != OP_IN
    3160                 :    16188595 :                           && (targetm.secondary_memory_needed
    3161                 :    16188595 :                               (mode, this_alternative, cl)))))
    3162                 :             :                 {
    3163                 :    11075266 :                   if (lra_dump_file != NULL)
    3164                 :          16 :                     fprintf
    3165                 :          16 :                       (lra_dump_file,
    3166                 :             :                        "            %d Secondary memory reload needed: "
    3167                 :             :                        "losers++\n", nop);
    3168                 :    11075266 :                   losers++;
    3169                 :             :                 }
    3170                 :             : 
    3171                 :   177010566 :               if (MEM_P (op) && offmemok)
    3172                 :          72 :                 addr_losers++;
    3173                 :             :               else
    3174                 :             :                 {
    3175                 :             :                   /* Input reloads can be inherited more often than
    3176                 :             :                      output reloads can be removed, so penalize output
    3177                 :             :                      reloads.  */
    3178                 :   177010494 :                   if (!REG_P (op) || curr_static_id->operand[nop].type != OP_IN)
    3179                 :             :                     {
    3180                 :   149224103 :                       if (lra_dump_file != NULL)
    3181                 :        1714 :                         fprintf
    3182                 :        1714 :                           (lra_dump_file,
    3183                 :             :                            "            %d Non input pseudo reload: reject++\n",
    3184                 :             :                            nop);
    3185                 :   149224103 :                       reject++;
    3186                 :             :                     }
    3187                 :             : 
    3188                 :   177010494 :                   if (curr_static_id->operand[nop].type == OP_INOUT)
    3189                 :             :                     {
    3190                 :         205 :                       if (lra_dump_file != NULL)
    3191                 :           0 :                         fprintf
    3192                 :           0 :                           (lra_dump_file,
    3193                 :             :                            "            %d Input/Output reload: reject+=%d\n",
    3194                 :             :                            nop, LRA_LOSER_COST_FACTOR);
    3195                 :         205 :                       reject += LRA_LOSER_COST_FACTOR;
    3196                 :             :                     }
    3197                 :             :                 }
    3198                 :             :             }
    3199                 :             : 
    3200                 :   471211928 :           if (early_clobber_p && ! scratch_p)
    3201                 :             :             {
    3202                 :      164508 :               if (lra_dump_file != NULL)
    3203                 :           4 :                 fprintf (lra_dump_file,
    3204                 :             :                          "            %d Early clobber: reject++\n", nop);
    3205                 :      164508 :               reject++;
    3206                 :             :             }
    3207                 :             :           /* ??? We check early clobbers after processing all operands
    3208                 :             :              (see loop below) and there we update the costs more.
    3209                 :             :              Should we update the cost (may be approximately) here
    3210                 :             :              because of early clobber register reloads or it is a rare
    3211                 :             :              or non-important thing to be worth to do it.  */
    3212                 :   942423856 :           overall = (losers * LRA_LOSER_COST_FACTOR + reject
    3213                 :   471211928 :                      - (addr_losers == losers ? static_reject : 0));
    3214                 :   471211928 :           if ((best_losers == 0 || losers != 0) && best_overall < overall)
    3215                 :             :             {
    3216                 :    75469498 :               if (lra_dump_file != NULL)
    3217                 :        1035 :                 fprintf (lra_dump_file,
    3218                 :             :                          "            overall=%d,losers=%d -- refuse\n",
    3219                 :             :                          overall, losers);
    3220                 :    75469498 :               goto fail;
    3221                 :             :             }
    3222                 :             : 
    3223                 :   395742430 :           if (update_and_check_small_class_inputs (nop, nalt,
    3224                 :             :                                                    this_alternative))
    3225                 :             :             {
    3226                 :           0 :               if (lra_dump_file != NULL)
    3227                 :           0 :                 fprintf (lra_dump_file,
    3228                 :             :                          "            not enough small class regs -- refuse\n");
    3229                 :           0 :               goto fail;
    3230                 :             :             }
    3231                 :   395742430 :           curr_alt[nop] = this_alternative;
    3232                 :   395742430 :           curr_alt_set[nop] = this_alternative_set;
    3233                 :   395742430 :           curr_alt_exclude_start_hard_regs[nop]
    3234                 :   395742430 :             = this_alternative_exclude_start_hard_regs;
    3235                 :   395742430 :           curr_alt_win[nop] = this_alternative_win;
    3236                 :   395742430 :           curr_alt_match_win[nop] = this_alternative_match_win;
    3237                 :   395742430 :           curr_alt_offmemok[nop] = this_alternative_offmemok;
    3238                 :   395742430 :           curr_alt_matches[nop] = this_alternative_matches;
    3239                 :             : 
    3240                 :   395742430 :           if (this_alternative_matches >= 0
    3241                 :   395742430 :               && !did_match && !this_alternative_win)
    3242                 :    13374180 :             curr_alt_win[this_alternative_matches] = false;
    3243                 :             : 
    3244                 :   395742430 :           if (early_clobber_p && operand_reg[nop] != NULL_RTX)
    3245                 :      169166 :             early_clobbered_nops[early_clobbered_regs_num++] = nop;
    3246                 :             :         }
    3247                 :             : 
    3248                 :   131641508 :       if (curr_insn_set != NULL_RTX && n_operands == 2
    3249                 :             :           /* Prevent processing non-move insns.  */
    3250                 :   102829532 :           && (GET_CODE (SET_SRC (curr_insn_set)) == SUBREG
    3251                 :   101039861 :               || SET_SRC (curr_insn_set) == no_subreg_reg_operand[1])
    3252                 :   227388399 :           && ((! curr_alt_win[0] && ! curr_alt_win[1]
    3253                 :     6119667 :                && REG_P (no_subreg_reg_operand[0])
    3254                 :     3004731 :                && REG_P (no_subreg_reg_operand[1])
    3255                 :     1224766 :                && (reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
    3256                 :     1021334 :                    || reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0])))
    3257                 :    91312675 :               || (! curr_alt_win[0] && curr_alt_win[1]
    3258                 :    27194556 :                   && REG_P (no_subreg_reg_operand[1])
    3259                 :             :                   /* Check that we reload memory not the memory
    3260                 :             :                      address.  */
    3261                 :    15467095 :                   && ! (curr_alt_offmemok[0]
    3262                 :      383505 :                         && MEM_P (no_subreg_reg_operand[0]))
    3263                 :    15467095 :                   && reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0]))
    3264                 :    77233703 :               || (curr_alt_win[0] && ! curr_alt_win[1]
    3265                 :     9689924 :                   && REG_P (no_subreg_reg_operand[0])
    3266                 :             :                   /* Check that we reload memory not the memory
    3267                 :             :                      address.  */
    3268                 :     7227643 :                   && ! (curr_alt_offmemok[1]
    3269                 :     1050691 :                         && MEM_P (no_subreg_reg_operand[1]))
    3270                 :     7227641 :                   && reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
    3271                 :     6337727 :                   && (! CONST_POOL_OK_P (curr_operand_mode[1],
    3272                 :             :                                          no_subreg_reg_operand[1])
    3273                 :     2326099 :                       || (targetm.preferred_reload_class
    3274                 :     2326099 :                           (no_subreg_reg_operand[1],
    3275                 :             :                            (enum reg_class) curr_alt[1]) != NO_REGS))
    3276                 :             :                   /* If it is a result of recent elimination in move
    3277                 :             :                      insn we can transform it into an add still by
    3278                 :             :                      using this alternative.  */
    3279                 :     6292854 :                   && GET_CODE (no_subreg_reg_operand[1]) != PLUS
    3280                 :             :                   /* Likewise if the source has been replaced with an
    3281                 :             :                      equivalent value.  This only happens once -- the reload
    3282                 :             :                      will use the equivalent value instead of the register it
    3283                 :             :                      replaces -- so there should be no danger of cycling.  */
    3284                 :     5762861 :                   && !equiv_substition_p[1])))
    3285                 :             :         {
    3286                 :             :           /* We have a move insn and a new reload insn will be similar
    3287                 :             :              to the current insn.  We should avoid such situation as
    3288                 :             :              it results in LRA cycling.  */
    3289                 :    20334242 :           if (lra_dump_file != NULL)
    3290                 :         239 :             fprintf (lra_dump_file,
    3291                 :             :                      "            Cycle danger: overall += LRA_MAX_REJECT\n");
    3292                 :    20334242 :           overall += LRA_MAX_REJECT;
    3293                 :             :         }
    3294                 :   135555096 :       if (all_this_alternative != NO_REGS
    3295                 :   115994653 :           && !SMALL_REGISTER_CLASS_P (all_this_alternative)
    3296                 :   115128115 :           && all_used_nregs != 0 && all_reload_nregs != 0
    3297                 :   135555096 :           && (all_used_nregs + all_reload_nregs + 1
    3298                 :     3957714 :               >= ira_class_hard_regs_num[all_this_alternative]))
    3299                 :             :         {
    3300                 :         265 :           if (lra_dump_file != NULL)
    3301                 :           0 :             fprintf
    3302                 :           0 :               (lra_dump_file,
    3303                 :             :                "            Register starvation: overall += LRA_MAX_REJECT"
    3304                 :             :                "(class=%s,avail=%d,used=%d,reload=%d)\n",
    3305                 :             :                reg_class_names[all_this_alternative],
    3306                 :             :                ira_class_hard_regs_num[all_this_alternative],
    3307                 :             :                all_used_nregs, all_reload_nregs);
    3308                 :         265 :           overall += LRA_MAX_REJECT;
    3309                 :             :         }
    3310                 :   135720938 :       ok_p = true;
    3311                 :             :       curr_alt_dont_inherit_ops_num = 0;
    3312                 :   135720938 :       for (nop = 0; nop < early_clobbered_regs_num; nop++)
    3313                 :             :         {
    3314                 :      165843 :           int i, j, clobbered_hard_regno, first_conflict_j, last_conflict_j;
    3315                 :      165843 :           HARD_REG_SET temp_set;
    3316                 :             : 
    3317                 :      165843 :           i = early_clobbered_nops[nop];
    3318                 :      165843 :           if ((! curr_alt_win[i] && ! curr_alt_match_win[i])
    3319                 :      124520 :               || hard_regno[i] < 0)
    3320                 :      165215 :             continue;
    3321                 :      122707 :           lra_assert (operand_reg[i] != NULL_RTX);
    3322                 :             :           clobbered_hard_regno = hard_regno[i];
    3323                 :      122707 :           CLEAR_HARD_REG_SET (temp_set);
    3324                 :      122707 :           add_to_hard_reg_set (&temp_set, GET_MODE (*curr_id->operand_loc[i]),
    3325                 :             :                                clobbered_hard_regno);
    3326                 :      122707 :           first_conflict_j = last_conflict_j = -1;
    3327                 :      619163 :           for (j = 0; j < n_operands; j++)
    3328                 :      496457 :             if (j == i
    3329                 :             :                 /* We don't want process insides of match_operator and
    3330                 :             :                    match_parallel because otherwise we would process
    3331                 :             :                    their operands once again generating a wrong
    3332                 :             :                    code.  */
    3333                 :      373750 :                 || curr_static_id->operand[j].is_operator)
    3334                 :      124848 :               continue;
    3335                 :      371609 :             else if ((curr_alt_matches[j] == i && curr_alt_match_win[j])
    3336                 :      352470 :                      || (curr_alt_matches[i] == j && curr_alt_match_win[i]))
    3337                 :       19139 :               continue;
    3338                 :             :             /* If we don't reload j-th operand, check conflicts.  */
    3339                 :      119811 :             else if ((curr_alt_win[j] || curr_alt_match_win[j])
    3340                 :      413209 :                      && uses_hard_regs_p (*curr_id->operand_loc[j], temp_set))
    3341                 :             :               {
    3342                 :        1013 :                 if (first_conflict_j < 0)
    3343                 :         628 :                   first_conflict_j = j;
    3344                 :        1013 :                 last_conflict_j = j;
    3345                 :             :                 /* Both the earlyclobber operand and conflicting operand
    3346                 :             :                    cannot both be user defined hard registers for asm.
    3347                 :             :                    Let curr_insn_transform diagnose it.  */
    3348                 :        1013 :                 if (HARD_REGISTER_P (operand_reg[i])
    3349                 :           1 :                     && REG_USERVAR_P (operand_reg[i])
    3350                 :           1 :                     && operand_reg[j] != NULL_RTX
    3351                 :           1 :                     && HARD_REGISTER_P (operand_reg[j])
    3352                 :           1 :                     && REG_USERVAR_P (operand_reg[j])
    3353                 :        1014 :                     && INSN_CODE (curr_insn) < 0)
    3354                 :           1 :                       return false;
    3355                 :             :               }
    3356                 :      122706 :           if (last_conflict_j < 0)
    3357                 :      122079 :             continue;
    3358                 :             : 
    3359                 :             :           /* If an earlyclobber operand conflicts with another non-matching
    3360                 :             :              operand (ie, they have been assigned the same hard register),
    3361                 :             :              then it is better to reload the other operand, as there may
    3362                 :             :              exist yet another operand with a matching constraint associated
    3363                 :             :              with the earlyclobber operand.  However, if one of the operands
    3364                 :             :              is an explicit use of a hard register, then we must reload the
    3365                 :             :              other non-hard register operand.  */
    3366                 :         627 :           if (HARD_REGISTER_P (operand_reg[i])
    3367                 :         627 :               || (first_conflict_j == last_conflict_j
    3368                 :         242 :                   && operand_reg[last_conflict_j] != NULL_RTX
    3369                 :          60 :                   && !curr_alt_match_win[last_conflict_j]
    3370                 :          60 :                   && !HARD_REGISTER_P (operand_reg[last_conflict_j])))
    3371                 :             :             {
    3372                 :          60 :               curr_alt_win[last_conflict_j] = false;
    3373                 :          60 :               curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++]
    3374                 :          60 :                 = last_conflict_j;
    3375                 :          60 :               losers++;
    3376                 :          60 :               if (lra_dump_file != NULL)
    3377                 :           0 :                 fprintf
    3378                 :           0 :                   (lra_dump_file,
    3379                 :             :                    "            %d Conflict early clobber reload: losers++\n",
    3380                 :             :                    i);
    3381                 :             :             }
    3382                 :             :           else
    3383                 :             :             {
    3384                 :             :               /* We need to reload early clobbered register and the
    3385                 :             :                  matched registers.  */
    3386                 :        2829 :               for (j = 0; j < n_operands; j++)
    3387                 :        2262 :                 if (curr_alt_matches[j] == i)
    3388                 :             :                   {
    3389                 :           2 :                     curr_alt_match_win[j] = false;
    3390                 :           2 :                     losers++;
    3391                 :           2 :                     if (lra_dump_file != NULL)
    3392                 :           0 :                       fprintf
    3393                 :           0 :                         (lra_dump_file,
    3394                 :             :                          "            %d Matching conflict early clobber "
    3395                 :             :                          "reloads: losers++\n",
    3396                 :             :                          j);
    3397                 :           2 :                     overall += LRA_LOSER_COST_FACTOR;
    3398                 :             :                   }
    3399                 :         567 :               if (! curr_alt_match_win[i])
    3400                 :         567 :                 curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++] = i;
    3401                 :             :               else
    3402                 :             :                 {
    3403                 :             :                   /* Remember pseudos used for match reloads are never
    3404                 :             :                      inherited.  */
    3405                 :           0 :                   lra_assert (curr_alt_matches[i] >= 0);
    3406                 :           0 :                   curr_alt_win[curr_alt_matches[i]] = false;
    3407                 :             :                 }
    3408                 :         567 :               curr_alt_win[i] = curr_alt_match_win[i] = false;
    3409                 :         567 :               losers++;
    3410                 :         567 :               if (lra_dump_file != NULL)
    3411                 :           0 :                 fprintf
    3412                 :           0 :                   (lra_dump_file,
    3413                 :             :                    "            %d Matched conflict early clobber reloads: "
    3414                 :             :                    "losers++\n",
    3415                 :             :                    i);
    3416                 :             :             }
    3417                 :             :           /* Early clobber was already reflected in REJECT. */
    3418                 :         627 :           if (!matching_early_clobber[i])
    3419                 :             :             {
    3420                 :         627 :               lra_assert (reject > 0);
    3421                 :         627 :               reject--;
    3422                 :         627 :               matching_early_clobber[i] = 1;
    3423                 :             :             }
    3424                 :         627 :           overall += LRA_LOSER_COST_FACTOR - 1;
    3425                 :             :         }
    3426                 :   135555095 :       if (lra_dump_file != NULL)
    3427                 :        1759 :         fprintf (lra_dump_file, "          overall=%d,losers=%d,rld_nregs=%d\n",
    3428                 :             :                  overall, losers, reload_nregs);
    3429                 :             : 
    3430                 :             :       /* If this alternative can be made to work by reloading, and it
    3431                 :             :          needs less reloading than the others checked so far, record
    3432                 :             :          it as the chosen goal for reloading.  */
    3433                 :   135555095 :       if ((best_losers != 0 && losers == 0)
    3434                 :    60134265 :           || (((best_losers == 0 && losers == 0)
    3435                 :    59165233 :                || (best_losers != 0 && losers != 0))
    3436                 :    60134265 :               && (best_overall > overall
    3437                 :    15731525 :                   || (best_overall == overall
    3438                 :             :                       /* If the cost of the reloads is the same,
    3439                 :             :                          prefer alternative which requires minimal
    3440                 :             :                          number of reload regs.  */
    3441                 :    11707830 :                       && (reload_nregs < best_reload_nregs
    3442                 :    11604305 :                           || (reload_nregs == best_reload_nregs
    3443                 :    11561589 :                               && (best_reload_sum < reload_sum
    3444                 :    11541374 :                                   || (best_reload_sum == reload_sum
    3445                 :    11516788 :                                       && nalt < goal_alt_number))))))))
    3446                 :             :         {
    3447                 :   390223308 :           for (nop = 0; nop < n_operands; nop++)
    3448                 :             :             {
    3449                 :   270041581 :               goal_alt_win[nop] = curr_alt_win[nop];
    3450                 :   270041581 :               goal_alt_match_win[nop] = curr_alt_match_win[nop];
    3451                 :   270041581 :               goal_alt_matches[nop] = curr_alt_matches[nop];
    3452                 :   270041581 :               goal_alt[nop] = curr_alt[nop];
    3453                 :   270041581 :               goal_alt_exclude_start_hard_regs[nop]
    3454                 :   270041581 :                 = curr_alt_exclude_start_hard_regs[nop];
    3455                 :   270041581 :               goal_alt_offmemok[nop] = curr_alt_offmemok[nop];
    3456                 :             :             }
    3457                 :   120181727 :           goal_alt_dont_inherit_ops_num = curr_alt_dont_inherit_ops_num;
    3458                 :   120181727 :           goal_reuse_alt_p = curr_reuse_alt_p;
    3459                 :   120182341 :           for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++)
    3460                 :         614 :             goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop];
    3461                 :   120181727 :           goal_alt_swapped = curr_swapped;
    3462                 :   120181727 :           goal_alt_out_sp_reload_p = curr_alt_out_sp_reload_p;
    3463                 :   120181727 :           best_overall = overall;
    3464                 :   120181727 :           best_losers = losers;
    3465                 :   120181727 :           best_reload_nregs = reload_nregs;
    3466                 :   120181727 :           best_reload_sum = reload_sum;
    3467                 :   120181727 :           goal_alt_number = nalt;
    3468                 :             :         }
    3469                 :   135555095 :       if (losers == 0 && !curr_alt_class_change_p)
    3470                 :             :         /* Everything is satisfied.  Do not process alternatives
    3471                 :             :            anymore.  */
    3472                 :             :         break;
    3473                 :    59176921 :     fail:
    3474                 :   182301799 :       ;
    3475                 :             :     }
    3476                 :             :   return ok_p;
    3477                 :             : }
    3478                 :             : 
    3479                 :             : /* Make reload base reg from address AD.  */
    3480                 :             : static rtx
    3481                 :           0 : base_to_reg (struct address_info *ad)
    3482                 :             : {
    3483                 :           0 :   enum reg_class cl;
    3484                 :           0 :   int code = -1;
    3485                 :           0 :   rtx new_inner = NULL_RTX;
    3486                 :           0 :   rtx new_reg = NULL_RTX;
    3487                 :           0 :   rtx_insn *insn;
    3488                 :           0 :   rtx_insn *last_insn = get_last_insn();
    3489                 :             : 
    3490                 :           0 :   lra_assert (ad->disp == ad->disp_term);
    3491                 :           0 :   cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
    3492                 :             :                        get_index_code (ad));
    3493                 :           0 :   new_reg = lra_create_new_reg (GET_MODE (*ad->base), NULL_RTX, cl, NULL,
    3494                 :             :                                 "base");
    3495                 :           0 :   new_inner = simplify_gen_binary (PLUS, GET_MODE (new_reg), new_reg,
    3496                 :           0 :                                    ad->disp_term == NULL
    3497                 :             :                                    ? const0_rtx
    3498                 :             :                                    : *ad->disp_term);
    3499                 :           0 :   if (!valid_address_p (ad->mode, new_inner, ad->as))
    3500                 :             :     return NULL_RTX;
    3501                 :           0 :   insn = emit_insn (gen_rtx_SET (new_reg, *ad->base));
    3502                 :           0 :   code = recog_memoized (insn);
    3503                 :           0 :   if (code < 0)
    3504                 :             :     {
    3505                 :           0 :       delete_insns_since (last_insn);
    3506                 :           0 :       return NULL_RTX;
    3507                 :             :     }
    3508                 :             : 
    3509                 :             :   return new_inner;
    3510                 :             : }
    3511                 :             : 
    3512                 :             : /* Make reload base reg + DISP from address AD.  Return the new pseudo.  */
    3513                 :             : static rtx
    3514                 :          41 : base_plus_disp_to_reg (struct address_info *ad, rtx disp)
    3515                 :             : {
    3516                 :          41 :   enum reg_class cl;
    3517                 :          41 :   rtx new_reg;
    3518                 :             : 
    3519                 :          41 :   lra_assert (ad->base == ad->base_term);
    3520                 :          41 :   cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
    3521                 :             :                        get_index_code (ad));
    3522                 :          41 :   new_reg = lra_create_new_reg (GET_MODE (*ad->base_term), NULL_RTX, cl, NULL,
    3523                 :             :                                 "base + disp");
    3524                 :          41 :   lra_emit_add (new_reg, *ad->base_term, disp);
    3525                 :          41 :   return new_reg;
    3526                 :             : }
    3527                 :             : 
    3528                 :             : /* Make reload of index part of address AD.  Return the new
    3529                 :             :    pseudo.  */
    3530                 :             : static rtx
    3531                 :           0 : index_part_to_reg (struct address_info *ad, enum reg_class index_class)
    3532                 :             : {
    3533                 :           0 :   rtx new_reg;
    3534                 :             : 
    3535                 :           0 :   new_reg = lra_create_new_reg (GET_MODE (*ad->index), NULL_RTX,
    3536                 :             :                                 index_class, NULL, "index term");
    3537                 :           0 :   expand_mult (GET_MODE (*ad->index), *ad->index_term,
    3538                 :             :                GEN_INT (get_index_scale (ad)), new_reg, 1);
    3539                 :           0 :   return new_reg;
    3540                 :             : }
    3541                 :             : 
    3542                 :             : /* Return true if we can add a displacement to address AD, even if that
    3543                 :             :    makes the address invalid.  The fix-up code requires any new address
    3544                 :             :    to be the sum of the BASE_TERM, INDEX and DISP_TERM fields.  */
    3545                 :             : static bool
    3546                 :       17530 : can_add_disp_p (struct address_info *ad)
    3547                 :             : {
    3548                 :       17530 :   return (!ad->autoinc_p
    3549                 :       17530 :           && ad->segment == NULL
    3550                 :       17530 :           && ad->base == ad->base_term
    3551                 :       35060 :           && ad->disp == ad->disp_term);
    3552                 :             : }
    3553                 :             : 
    3554                 :             : /* Make equiv substitution in address AD.  Return true if a substitution
    3555                 :             :    was made.  */
    3556                 :             : static bool
    3557                 :    39590555 : equiv_address_substitution (struct address_info *ad)
    3558                 :             : {
    3559                 :    39590555 :   rtx base_reg, new_base_reg, index_reg, new_index_reg, *base_term, *index_term;
    3560                 :    39590555 :   poly_int64 disp;
    3561                 :    39590555 :   HOST_WIDE_INT scale;
    3562                 :    39590555 :   bool change_p;
    3563                 :             : 
    3564                 :    39590555 :   base_term = strip_subreg (ad->base_term);
    3565                 :       10578 :   if (base_term == NULL)
    3566                 :             :     base_reg = new_base_reg = NULL_RTX;
    3567                 :             :   else
    3568                 :             :     {
    3569                 :    33376135 :       base_reg = *base_term;
    3570                 :    33376135 :       new_base_reg = get_equiv_with_elimination (base_reg, curr_insn);
    3571                 :             :     }
    3572                 :    39590555 :   index_term = strip_subreg (ad->index_term);
    3573                 :        5998 :   if (index_term == NULL)
    3574                 :             :     index_reg = new_index_reg = NULL_RTX;
    3575                 :             :   else
    3576                 :             :     {
    3577                 :     1812627 :       index_reg = *index_term;
    3578                 :     1812627 :       new_index_reg = get_equiv_with_elimination (index_reg, curr_insn);
    3579                 :             :     }
    3580                 :    39590555 :   if (base_reg == new_base_reg && index_reg == new_index_reg)
    3581                 :             :     return false;
    3582                 :      131901 :   disp = 0;
    3583                 :      131901 :   change_p = false;
    3584                 :      131901 :   if (lra_dump_file != NULL)
    3585                 :             :     {
    3586                 :           0 :       fprintf (lra_dump_file, "Changing address in insn %d ",
    3587                 :           0 :                INSN_UID (curr_insn));
    3588                 :           0 :       dump_value_slim (lra_dump_file, *ad->outer, 1);
    3589                 :             :     }
    3590                 :      131901 :   if (base_reg != new_base_reg)
    3591                 :             :     {
    3592                 :      131431 :       poly_int64 offset;
    3593                 :      131431 :       if (REG_P (new_base_reg))
    3594                 :             :         {
    3595                 :        5300 :           *base_term = new_base_reg;
    3596                 :        5300 :           change_p = true;
    3597                 :             :         }
    3598                 :      126131 :       else if (GET_CODE (new_base_reg) == PLUS
    3599                 :       17530 :                && REG_P (XEXP (new_base_reg, 0))
    3600                 :       17530 :                && poly_int_rtx_p (XEXP (new_base_reg, 1), &offset)
    3601                 :      143661 :                && can_add_disp_p (ad))
    3602                 :             :         {
    3603                 :             :           disp += offset;
    3604                 :       17530 :           *base_term = XEXP (new_base_reg, 0);
    3605                 :       17530 :           change_p = true;
    3606                 :             :         }
    3607                 :      131431 :       if (ad->base_term2 != NULL)
    3608                 :           0 :         *ad->base_term2 = *ad->base_term;
    3609                 :             :     }
    3610                 :      131901 :   if (index_reg != new_index_reg)
    3611                 :             :     {
    3612                 :         668 :       poly_int64 offset;
    3613                 :         668 :       if (REG_P (new_index_reg))
    3614                 :             :         {
    3615                 :           0 :           *index_term = new_index_reg;
    3616                 :           0 :           change_p = true;
    3617                 :             :         }
    3618                 :         668 :       else if (GET_CODE (new_index_reg) == PLUS
    3619                 :           0 :                && REG_P (XEXP (new_index_reg, 0))
    3620                 :           0 :                && poly_int_rtx_p (XEXP (new_index_reg, 1), &offset)
    3621                 :           0 :                && can_add_disp_p (ad)
    3622                 :         668 :                && (scale = get_index_scale (ad)))
    3623                 :             :         {
    3624                 :           0 :           disp += offset * scale;
    3625                 :           0 :           *index_term = XEXP (new_index_reg, 0);
    3626                 :           0 :           change_p = true;
    3627                 :             :         }
    3628                 :             :     }
    3629                 :      131901 :   if (maybe_ne (disp, 0))
    3630                 :             :     {
    3631                 :       17530 :       if (ad->disp != NULL)
    3632                 :        5298 :         *ad->disp = plus_constant (GET_MODE (*ad->inner), *ad->disp, disp);
    3633                 :             :       else
    3634                 :             :         {
    3635                 :       12232 :           *ad->inner = plus_constant (GET_MODE (*ad->inner), *ad->inner, disp);
    3636                 :       12232 :           update_address (ad);
    3637                 :             :         }
    3638                 :             :       change_p = true;
    3639                 :             :     }
    3640                 :      131901 :   if (lra_dump_file != NULL)
    3641                 :             :     {
    3642                 :           0 :       if (! change_p)
    3643                 :           0 :         fprintf (lra_dump_file, " -- no change\n");
    3644                 :             :       else
    3645                 :             :         {
    3646                 :           0 :           fprintf (lra_dump_file, " on equiv ");
    3647                 :           0 :           dump_value_slim (lra_dump_file, *ad->outer, 1);
    3648                 :           0 :           fprintf (lra_dump_file, "\n");
    3649                 :             :         }
    3650                 :             :     }
    3651                 :             :   return change_p;
    3652                 :             : }
    3653                 :             : 
    3654                 :             : /* Skip all modifiers and whitespaces in constraint STR and return the
    3655                 :             :    result.  */
    3656                 :             : static const char *
    3657                 :   513140759 : skip_constraint_modifiers (const char *str)
    3658                 :             : {
    3659                 :   723082769 :   for (;;str++)
    3660                 :   618111764 :     switch (*str)
    3661                 :             :       {
    3662                 :   104971005 :       case '+': case '&' : case '=': case '*': case ' ': case '\t':
    3663                 :   104971005 :       case '$': case '^' : case '%': case '?': case '!':
    3664                 :   104971005 :         break;
    3665                 :   513140759 :       default: return str;
    3666                 :             :       }
    3667                 :             : }
    3668                 :             : 
    3669                 :             : /* Takes a string of 0 or more comma-separated constraints.  When more
    3670                 :             :    than one constraint is present, evaluate whether they all correspond
    3671                 :             :    to a single, repeated constraint (e.g. "r,r") or whether we have
    3672                 :             :    more than one distinct constraints (e.g. "r,m").  */
    3673                 :             : static bool
    3674                 :   163218214 : constraint_unique (const char *cstr)
    3675                 :             : {
    3676                 :   163218214 :   enum constraint_num ca, cb;
    3677                 :   163218214 :   ca = CONSTRAINT__UNKNOWN;
    3678                 :   322418781 :   for (;;)
    3679                 :             :     {
    3680                 :   322418781 :       cstr = skip_constraint_modifiers (cstr);
    3681                 :   322418781 :       if (*cstr == '\0' || *cstr == ',')
    3682                 :             :         cb = CONSTRAINT_X;
    3683                 :             :       else
    3684                 :             :         {
    3685                 :   322418781 :           cb = lookup_constraint (cstr);
    3686                 :   322418781 :           if (cb == CONSTRAINT__UNKNOWN)
    3687                 :             :             return false;
    3688                 :   310261712 :           cstr += CONSTRAINT_LEN (cstr[0], cstr);
    3689                 :             :         }
    3690                 :             :       /* Handle the first iteration of the loop.  */
    3691                 :   310261712 :       if (ca == CONSTRAINT__UNKNOWN)
    3692                 :             :         ca = cb;
    3693                 :             :       /* Handle the general case of comparing ca with subsequent
    3694                 :             :          constraints.  */
    3695                 :   159069272 :       else if (ca != cb)
    3696                 :             :         return false;
    3697                 :   166724610 :       if (*cstr == '\0')
    3698                 :             :         return true;
    3699                 :   159200567 :       if (*cstr == ',')
    3700                 :    87508835 :         cstr += 1;
    3701                 :             :     }
    3702                 :             : }
    3703                 :             : 
    3704                 :             : /* Major function to make reloads for an address in operand NOP or
    3705                 :             :    check its correctness (If CHECK_ONLY_P is true). The supported
    3706                 :             :    cases are:
    3707                 :             : 
    3708                 :             :    1) an address that existed before LRA started, at which point it
    3709                 :             :    must have been valid.  These addresses are subject to elimination
    3710                 :             :    and may have become invalid due to the elimination offset being out
    3711                 :             :    of range.
    3712                 :             : 
    3713                 :             :    2) an address created by forcing a constant to memory
    3714                 :             :    (force_const_to_mem).  The initial form of these addresses might
    3715                 :             :    not be valid, and it is this function's job to make them valid.
    3716                 :             : 
    3717                 :             :    3) a frame address formed from a register and a (possibly zero)
    3718                 :             :    constant offset.  As above, these addresses might not be valid and
    3719                 :             :    this function must make them so.
    3720                 :             : 
    3721                 :             :    Add reloads to the lists *BEFORE and *AFTER.  We might need to add
    3722                 :             :    reloads to *AFTER because of inc/dec, {pre, post} modify in the
    3723                 :             :    address.  Return true for any RTL change.
    3724                 :             : 
    3725                 :             :    The function is a helper function which does not produce all
    3726                 :             :    transformations (when CHECK_ONLY_P is false) which can be
    3727                 :             :    necessary.  It does just basic steps.  To do all necessary
    3728                 :             :    transformations use function process_address.  */
    3729                 :             : static bool
    3730                 :   176979980 : process_address_1 (int nop, bool check_only_p,
    3731                 :             :                    rtx_insn **before, rtx_insn **after)
    3732                 :             : {
    3733                 :   176979980 :   struct address_info ad;
    3734                 :   176979980 :   rtx new_reg;
    3735                 :   176979980 :   HOST_WIDE_INT scale;
    3736                 :   176979980 :   rtx op = *curr_id->operand_loc[nop];
    3737                 :   176979980 :   rtx mem = extract_mem_from_operand (op);
    3738                 :   176979980 :   const char *constraint;
    3739                 :   176979980 :   enum constraint_num cn;
    3740                 :   176979980 :   bool change_p = false;
    3741                 :             : 
    3742                 :   176979980 :   if (MEM_P (mem)
    3743                 :    37759924 :       && GET_MODE (mem) == BLKmode
    3744                 :       25189 :       && GET_CODE (XEXP (mem, 0)) == SCRATCH)
    3745                 :             :     return false;
    3746                 :             : 
    3747                 :   176979980 :   constraint
    3748                 :   176979980 :     = skip_constraint_modifiers (curr_static_id->operand[nop].constraint);
    3749                 :   176979980 :   if (IN_RANGE (constraint[0], '0', '9'))
    3750                 :             :     {
    3751                 :    13741998 :       char *end;
    3752                 :    13741998 :       unsigned long dup = strtoul (constraint, &end, 10);
    3753                 :    13741998 :       constraint
    3754                 :    13741998 :         = skip_constraint_modifiers (curr_static_id->operand[dup].constraint);
    3755                 :             :     }
    3756                 :   188904223 :   cn = lookup_constraint (*constraint == '\0' ? "X" : constraint);
    3757                 :             :   /* If we have several alternatives or/and several constraints in an
    3758                 :             :      alternative and we can not say at this stage what constraint will be used,
    3759                 :             :      use unknown constraint.  The exception is an address constraint.  If
    3760                 :             :      operand has one address constraint, probably all others constraints are
    3761                 :             :      address ones.  */
    3762                 :   165055737 :   if (constraint[0] != '\0' && get_constraint_type (cn) != CT_ADDRESS
    3763                 :   340198194 :       && !constraint_unique (constraint))
    3764                 :             :     cn = CONSTRAINT__UNKNOWN;
    3765                 :    21285809 :   if (insn_extra_address_constraint (cn)
    3766                 :             :       /* When we find an asm operand with an address constraint that
    3767                 :             :          doesn't satisfy address_operand to begin with, we clear
    3768                 :             :          is_address, so that we don't try to make a non-address fit.
    3769                 :             :          If the asm statement got this far, it's because other
    3770                 :             :          constraints are available, and we'll use them, disregarding
    3771                 :             :          the unsatisfiable address ones.  */
    3772                 :    21285809 :       && curr_static_id->operand[nop].is_address)
    3773                 :     1837504 :     decompose_lea_address (&ad, curr_id->operand_loc[nop]);
    3774                 :             :   /* Do not attempt to decompose arbitrary addresses generated by combine
    3775                 :             :      for asm operands with loose constraints, e.g 'X'.
    3776                 :             :      Need to extract memory from op for special memory constraint,
    3777                 :             :      i.e. bcst_mem_operand in i386 backend.  */
    3778                 :   175142476 :   else if (MEM_P (mem)
    3779                 :   175142668 :            && !(INSN_CODE (curr_insn) < 0
    3780                 :       17363 :                 && get_constraint_type (cn) == CT_FIXED_FORM
    3781                 :         192 :                 && constraint_satisfied_p (op, cn)))
    3782                 :    37759732 :     decompose_mem_address (&ad, mem);
    3783                 :   137382744 :   else if (GET_CODE (op) == SUBREG
    3784                 :     3566517 :            && MEM_P (SUBREG_REG (op)))
    3785                 :           0 :     decompose_mem_address (&ad, SUBREG_REG (op));
    3786                 :             :   else
    3787                 :             :     return false;
    3788                 :             :   /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
    3789                 :             :      index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
    3790                 :             :      when INDEX_REG_CLASS is a single register class.  */
    3791                 :    39597236 :   enum reg_class index_cl = index_reg_class (curr_insn);
    3792                 :    39597236 :   if (ad.base_term != NULL
    3793                 :    33382728 :       && ad.index_term != NULL
    3794                 :     1441415 :       && ira_class_hard_regs_num[index_cl] == 1
    3795                 :           0 :       && REG_P (*ad.base_term)
    3796                 :           0 :       && REG_P (*ad.index_term)
    3797                 :           0 :       && in_class_p (*ad.base_term, index_cl, NULL)
    3798                 :    39597236 :       && ! in_class_p (*ad.index_term, index_cl, NULL))
    3799                 :             :     {
    3800                 :           0 :       std::swap (ad.base, ad.index);
    3801                 :           0 :       std::swap (ad.base_term, ad.index_term);
    3802                 :             :     }
    3803                 :    39597236 :   if (! check_only_p)
    3804                 :    39590555 :     change_p = equiv_address_substitution (&ad);
    3805                 :    39597236 :   if (ad.base_term != NULL
    3806                 :    72979964 :       && (process_addr_reg
    3807                 :    66765456 :           (ad.base_term, check_only_p, before,
    3808                 :    33382728 :            (ad.autoinc_p
    3809                 :     4147372 :             && !(REG_P (*ad.base_term)
    3810                 :     2073686 :                  && find_regno_note (curr_insn, REG_DEAD,
    3811                 :             :                                      REGNO (*ad.base_term)) != NULL_RTX)
    3812                 :             :             ? after : NULL),
    3813                 :    33382728 :            base_reg_class (ad.mode, ad.as, ad.base_outer_code,
    3814                 :             :                            get_index_code (&ad), curr_insn))))
    3815                 :             :     {
    3816                 :      431338 :       change_p = true;
    3817                 :      431338 :       if (ad.base_term2 != NULL)
    3818                 :           0 :         *ad.base_term2 = *ad.base_term;
    3819                 :             :     }
    3820                 :    39597236 :   if (ad.index_term != NULL
    3821                 :    39597236 :       && process_addr_reg (ad.index_term, check_only_p,
    3822                 :             :                            before, NULL, index_cl))
    3823                 :             :     change_p = true;
    3824                 :             : 
    3825                 :             :   /* Target hooks sometimes don't treat extra-constraint addresses as
    3826                 :             :      legitimate address_operands, so handle them specially.  */
    3827                 :    39597236 :   if (insn_extra_address_constraint (cn)
    3828                 :    39597236 :       && satisfies_address_constraint_p (&ad, cn))
    3829                 :             :     return change_p;
    3830                 :             : 
    3831                 :    37759739 :   if (check_only_p)
    3832                 :             :     return change_p;
    3833                 :             : 
    3834                 :             :   /* There are three cases where the shape of *AD.INNER may now be invalid:
    3835                 :             : 
    3836                 :             :      1) the original address was valid, but either elimination or
    3837                 :             :      equiv_address_substitution was applied and that made
    3838                 :             :      the address invalid.
    3839                 :             : 
    3840                 :             :      2) the address is an invalid symbolic address created by
    3841                 :             :      force_const_to_mem.
    3842                 :             : 
    3843                 :             :      3) the address is a frame address with an invalid offset.
    3844                 :             : 
    3845                 :             :      4) the address is a frame address with an invalid base.
    3846                 :             : 
    3847                 :             :      All these cases involve a non-autoinc address, so there is no
    3848                 :             :      point revalidating other types.  */
    3849                 :    37753645 :   if (ad.autoinc_p || valid_address_p (op, &ad, cn))
    3850                 :    37753201 :     return change_p;
    3851                 :             : 
    3852                 :             :   /* Any index existed before LRA started, so we can assume that the
    3853                 :             :      presence and shape of the index is valid.  */
    3854                 :         444 :   push_to_sequence (*before);
    3855                 :         444 :   lra_assert (ad.disp == ad.disp_term);
    3856                 :         444 :   if (ad.base == NULL)
    3857                 :             :     {
    3858                 :         350 :       if (ad.index == NULL)
    3859                 :             :         {
    3860                 :         350 :           rtx_insn *insn;
    3861                 :         350 :           rtx_insn *last = get_last_insn ();
    3862                 :         350 :           int code = -1;
    3863                 :         350 :           enum reg_class cl = base_reg_class (ad.mode, ad.as,
    3864                 :             :                                               SCRATCH, SCRATCH,
    3865                 :             :                                               curr_insn);
    3866                 :         350 :           rtx addr = *ad.inner;
    3867                 :             : 
    3868                 :         690 :           new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
    3869                 :         350 :           if (HAVE_lo_sum)
    3870                 :             :             {
    3871                 :             :               /* addr => lo_sum (new_base, addr), case (2) above.  */
    3872                 :             :               insn = emit_insn (gen_rtx_SET
    3873                 :             :                                 (new_reg,
    3874                 :             :                                  gen_rtx_HIGH (Pmode, copy_rtx (addr))));
    3875                 :             :               code = recog_memoized (insn);
    3876                 :             :               if (code >= 0)
    3877                 :             :                 {
    3878                 :             :                   *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr);
    3879                 :             :                   if (!valid_address_p (op, &ad, cn))
    3880                 :             :                     {
    3881                 :             :                       /* Try to put lo_sum into register.  */
    3882                 :             :                       insn = emit_insn (gen_rtx_SET
    3883                 :             :                                         (new_reg,
    3884                 :             :                                          gen_rtx_LO_SUM (Pmode, new_reg, addr)));
    3885                 :             :                       code = recog_memoized (insn);
    3886                 :             :                       if (code >= 0)
    3887                 :             :                         {
    3888                 :             :                           *ad.inner = new_reg;
    3889                 :             :                           if (!valid_address_p (op, &ad, cn))
    3890                 :             :                             {
    3891                 :             :                               *ad.inner = addr;
    3892                 :             :                               code = -1;
    3893                 :             :                             }
    3894                 :             :                         }
    3895                 :             : 
    3896                 :             :                     }
    3897                 :             :                 }
    3898                 :             :               if (code < 0)
    3899                 :             :                 delete_insns_since (last);
    3900                 :             :             }
    3901                 :             : 
    3902                 :         350 :           if (code < 0)
    3903                 :             :             {
    3904                 :             :               /* addr => new_base, case (2) above.  */
    3905                 :         350 :               lra_emit_move (new_reg, addr);
    3906                 :             : 
    3907                 :         700 :               for (insn = last == NULL_RTX ? get_insns () : NEXT_INSN (last);
    3908                 :         700 :                    insn != NULL_RTX;
    3909                 :         350 :                    insn = NEXT_INSN (insn))
    3910                 :         350 :                 if (recog_memoized (insn) < 0)
    3911                 :             :                   break;
    3912                 :         350 :               if (insn != NULL_RTX)
    3913                 :             :                 {
    3914                 :             :                   /* Do nothing if we cannot generate right insns.
    3915                 :             :                      This is analogous to reload pass behavior.  */
    3916                 :           0 :                   delete_insns_since (last);
    3917                 :           0 :                   end_sequence ();
    3918                 :           0 :                   return false;
    3919                 :             :                 }
    3920                 :         350 :               *ad.inner = new_reg;
    3921                 :             :             }
    3922                 :             :         }
    3923                 :             :       else
    3924                 :             :         {
    3925                 :             :           /* index * scale + disp => new base + index * scale,
    3926                 :             :              case (1) above.  */
    3927                 :           0 :           enum reg_class cl = base_reg_class (ad.mode, ad.as, PLUS,
    3928                 :           0 :                                               GET_CODE (*ad.index),
    3929                 :             :                                               curr_insn);
    3930                 :             : 
    3931                 :           0 :           lra_assert (index_cl != NO_REGS);
    3932                 :           0 :           new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "disp");
    3933                 :           0 :           lra_emit_move (new_reg, *ad.disp);
    3934                 :           0 :           *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
    3935                 :           0 :                                            new_reg, *ad.index);
    3936                 :             :         }
    3937                 :             :     }
    3938                 :          94 :   else if (ad.index == NULL)
    3939                 :             :     {
    3940                 :          53 :       int regno;
    3941                 :          53 :       enum reg_class cl;
    3942                 :          53 :       rtx set;
    3943                 :          53 :       rtx_insn *insns, *last_insn;
    3944                 :             : 
    3945                 :          53 :       cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code,
    3946                 :             :                            get_index_code (&ad), curr_insn);
    3947                 :             : 
    3948                 :          53 :       if (REG_P (*ad.base_term)
    3949                 :          53 :           && ira_class_subset_p[get_reg_class (REGNO (*ad.base_term))][cl])
    3950                 :             :         /* It seems base reg is already in the base reg class and changing it
    3951                 :             :            does not make a progress.  So reload the whole inner address.  */
    3952                 :          53 :         goto reload_inner_addr;
    3953                 :             : 
    3954                 :             :       /* Try to reload base into register only if the base is invalid
    3955                 :             :          for the address but with valid offset, case (4) above.  */
    3956                 :           0 :       start_sequence ();
    3957                 :           0 :       new_reg = base_to_reg (&ad);
    3958                 :             : 
    3959                 :             :       /* base + disp => new base, cases (1) and (3) above.  */
    3960                 :             :       /* Another option would be to reload the displacement into an
    3961                 :             :          index register.  However, postreload has code to optimize
    3962                 :             :          address reloads that have the same base and different
    3963                 :             :          displacements, so reloading into an index register would
    3964                 :             :          not necessarily be a win.  */
    3965                 :           0 :       if (new_reg == NULL_RTX)
    3966                 :             :         {
    3967                 :             :           /* See if the target can split the displacement into a
    3968                 :             :              legitimate new displacement from a local anchor.  */
    3969                 :           0 :           gcc_assert (ad.disp == ad.disp_term);
    3970                 :           0 :           poly_int64 orig_offset;
    3971                 :           0 :           rtx offset1, offset2;
    3972                 :           0 :           if (poly_int_rtx_p (*ad.disp, &orig_offset)
    3973                 :           0 :               && targetm.legitimize_address_displacement (&offset1, &offset2,
    3974                 :             :                                                           orig_offset,
    3975                 :             :                                                           ad.mode))
    3976                 :             :             {
    3977                 :           0 :               new_reg = base_plus_disp_to_reg (&ad, offset1);
    3978                 :           0 :               new_reg = gen_rtx_PLUS (GET_MODE (new_reg), new_reg, offset2);
    3979                 :             :             }
    3980                 :             :           else
    3981                 :           0 :             new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
    3982                 :             :         }
    3983                 :           0 :       insns = get_insns ();
    3984                 :           0 :       last_insn = get_last_insn ();
    3985                 :             :       /* If we generated at least two insns, try last insn source as
    3986                 :             :          an address.  If we succeed, we generate one less insn.  */
    3987                 :           0 :       if (REG_P (new_reg)
    3988                 :           0 :           && last_insn != insns
    3989                 :           0 :           && (set = single_set (last_insn)) != NULL_RTX
    3990                 :           0 :           && GET_CODE (SET_SRC (set)) == PLUS
    3991                 :           0 :           && REG_P (XEXP (SET_SRC (set), 0))
    3992                 :           0 :           && CONSTANT_P (XEXP (SET_SRC (set), 1)))
    3993                 :             :         {
    3994                 :           0 :           *ad.inner = SET_SRC (set);
    3995                 :           0 :           if (valid_address_p (op, &ad, cn))
    3996                 :             :             {
    3997                 :           0 :               *ad.base_term = XEXP (SET_SRC (set), 0);
    3998                 :           0 :               *ad.disp_term = XEXP (SET_SRC (set), 1);
    3999                 :           0 :               regno = REGNO (*ad.base_term);
    4000                 :           0 :               if (regno >= FIRST_PSEUDO_REGISTER
    4001                 :           0 :                   && cl != lra_get_allocno_class (regno))
    4002                 :           0 :                 lra_change_class (regno, cl, "      Change to", true);
    4003                 :           0 :               new_reg = SET_SRC (set);
    4004                 :           0 :               delete_insns_since (PREV_INSN (last_insn));
    4005                 :             :             }
    4006                 :             :         }
    4007                 :           0 :       end_sequence ();
    4008                 :           0 :       emit_insn (insns);
    4009                 :           0 :       *ad.inner = new_reg;
    4010                 :             :     }
    4011                 :          41 :   else if (ad.disp_term != NULL)
    4012                 :             :     {
    4013                 :             :       /* base + scale * index + disp => new base + scale * index,
    4014                 :             :          case (1) above.  */
    4015                 :          41 :       gcc_assert (ad.disp == ad.disp_term);
    4016                 :          41 :       new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
    4017                 :          41 :       *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
    4018                 :          41 :                                        new_reg, *ad.index);
    4019                 :             :     }
    4020                 :           0 :   else if ((scale = get_index_scale (&ad)) == 1)
    4021                 :             :     {
    4022                 :             :       /* The last transformation to one reg will be made in
    4023                 :             :          curr_insn_transform function.  */
    4024                 :           0 :       end_sequence ();
    4025                 :           0 :       return false;
    4026                 :             :     }
    4027                 :           0 :   else if (scale != 0)
    4028                 :             :     {
    4029                 :             :       /* base + scale * index => base + new_reg,
    4030                 :             :          case (1) above.
    4031                 :             :       Index part of address may become invalid.  For example, we
    4032                 :             :       changed pseudo on the equivalent memory and a subreg of the
    4033                 :             :       pseudo onto the memory of different mode for which the scale is
    4034                 :             :       prohibitted.  */
    4035                 :           0 :       new_reg = index_part_to_reg (&ad, index_cl);
    4036                 :           0 :       *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
    4037                 :           0 :                                        *ad.base_term, new_reg);
    4038                 :             :     }
    4039                 :             :   else
    4040                 :             :     {
    4041                 :          53 :       enum reg_class cl;
    4042                 :          53 :       rtx addr;
    4043                 :           0 :     reload_inner_addr:
    4044                 :          53 :       cl = base_reg_class (ad.mode, ad.as, SCRATCH, SCRATCH, curr_insn);
    4045                 :          53 :       addr = *ad.inner;
    4046                 :          53 :       new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
    4047                 :             :       /* addr => new_base.  */
    4048                 :          53 :       lra_emit_move (new_reg, addr);
    4049                 :          53 :       *ad.inner = new_reg;
    4050                 :             :     }
    4051                 :         444 :   *before = end_sequence ();
    4052                 :         444 :   return true;
    4053                 :             : }
    4054                 :             : 
    4055                 :             : /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
    4056                 :             :    Use process_address_1 as a helper function.  Return true for any
    4057                 :             :    RTL changes.
    4058                 :             : 
    4059                 :             :    If CHECK_ONLY_P is true, just check address correctness.  Return
    4060                 :             :    false if the address correct.  */
    4061                 :             : static bool
    4062                 :   176503606 : process_address (int nop, bool check_only_p,
    4063                 :             :                  rtx_insn **before, rtx_insn **after)
    4064                 :             : {
    4065                 :   176503606 :   bool res = false;
    4066                 :             :   /* Use enough iterations to process all address parts:  */
    4067                 :   176979980 :   for (int i = 0; i < 10; i++)
    4068                 :             :     {
    4069                 :   176979980 :       if (!process_address_1 (nop, check_only_p, before, after))
    4070                 :             :         {
    4071                 :             :           return res;
    4072                 :             :         }
    4073                 :             :       else
    4074                 :             :         {
    4075                 :      476374 :           if (check_only_p)
    4076                 :             :             return true;
    4077                 :      476374 :           res = true;
    4078                 :             :         }
    4079                 :             :     }
    4080                 :           0 :   fatal_insn ("unable to reload address in ", curr_insn);
    4081                 :             : }
    4082                 :             : 
    4083                 :             : /* Override the generic address_reload_context in order to
    4084                 :             :    control the creation of reload pseudos.  */
    4085                 :             : class lra_autoinc_reload_context : public address_reload_context
    4086                 :             : {
    4087                 :             :   machine_mode mode;
    4088                 :             :   enum reg_class rclass;
    4089                 :             : 
    4090                 :             : public:
    4091                 :           0 :   lra_autoinc_reload_context (machine_mode mode, enum reg_class new_rclass)
    4092                 :           0 :     : mode (mode), rclass (new_rclass) {}
    4093                 :             : 
    4094                 :           0 :   rtx get_reload_reg () const override final
    4095                 :             :   {
    4096                 :           0 :     return lra_create_new_reg (mode, NULL_RTX, rclass, NULL, "INC/DEC result");
    4097                 :             :   }
    4098                 :             : };
    4099                 :             : 
    4100                 :             : /* Emit insns to reload VALUE into a new register.  VALUE is an
    4101                 :             :    auto-increment or auto-decrement RTX whose operand is a register or
    4102                 :             :    memory location; so reloading involves incrementing that location.
    4103                 :             : 
    4104                 :             :    INC_AMOUNT is the number to increment or decrement by (always
    4105                 :             :    positive and ignored for POST_MODIFY/PRE_MODIFY).
    4106                 :             : 
    4107                 :             :    Return a pseudo containing the result.  */
    4108                 :             : static rtx
    4109                 :           0 : emit_inc (enum reg_class new_rclass, rtx value, poly_int64 inc_amount)
    4110                 :             : {
    4111                 :           0 :   lra_autoinc_reload_context context (GET_MODE (value), new_rclass);
    4112                 :           0 :   return context.emit_autoinc (value, inc_amount);
    4113                 :             : }
    4114                 :             : 
    4115                 :             : /* Return true if the current move insn does not need processing as we
    4116                 :             :    already know that it satisfies its constraints.  */
    4117                 :             : static bool
    4118                 :   101365838 : simple_move_p (void)
    4119                 :             : {
    4120                 :   101365838 :   rtx dest, src;
    4121                 :   101365838 :   enum reg_class dclass, sclass;
    4122                 :             : 
    4123                 :   101365838 :   lra_assert (curr_insn_set != NULL_RTX);
    4124                 :   101365838 :   dest = SET_DEST (curr_insn_set);
    4125                 :   101365838 :   src = SET_SRC (curr_insn_set);
    4126                 :             : 
    4127                 :             :   /* If the instruction has multiple sets we need to process it even if it
    4128                 :             :      is single_set.  This can happen if one or more of the SETs are dead.
    4129                 :             :      See PR73650.  */
    4130                 :   101365838 :   if (multiple_sets (curr_insn))
    4131                 :             :     return false;
    4132                 :             : 
    4133                 :   101181943 :   return ((dclass = get_op_class (dest)) != NO_REGS
    4134                 :    21316670 :           && (sclass = get_op_class (src)) != NO_REGS
    4135                 :             :           /* The backend guarantees that register moves of cost 2
    4136                 :             :              never need reloads.  */
    4137                 :    90433355 :           && targetm.register_move_cost (GET_MODE (src), sclass, dclass) == 2);
    4138                 :             :  }
    4139                 :             : 
    4140                 :             : /* Swap operands NOP and NOP + 1. */
    4141                 :             : static inline void
    4142                 :    21524067 : swap_operands (int nop)
    4143                 :             : {
    4144                 :    21524067 :   std::swap (curr_operand_mode[nop], curr_operand_mode[nop + 1]);
    4145                 :    21524067 :   std::swap (original_subreg_reg_mode[nop], original_subreg_reg_mode[nop + 1]);
    4146                 :    21524067 :   std::swap (*curr_id->operand_loc[nop], *curr_id->operand_loc[nop + 1]);
    4147                 :    21524067 :   std::swap (equiv_substition_p[nop], equiv_substition_p[nop + 1]);
    4148                 :             :   /* Swap the duplicates too.  */
    4149                 :    21524067 :   lra_update_dup (curr_id, nop);
    4150                 :    21524067 :   lra_update_dup (curr_id, nop + 1);
    4151                 :    21524067 : }
    4152                 :             : 
    4153                 :             : /* Return TRUE if X is a (subreg of) reg and there are no hard regs of X class
    4154                 :             :    which can contain value of MODE.  */
    4155                 :          32 : static bool invalid_mode_reg_p (enum machine_mode mode, rtx x)
    4156                 :             : {
    4157                 :          32 :   if (SUBREG_P (x))
    4158                 :           1 :     x = SUBREG_REG (x);
    4159                 :          32 :   if (! REG_P (x))
    4160                 :             :     return false;
    4161                 :          32 :   enum reg_class rclass = get_reg_class (REGNO (x));
    4162                 :          32 :   return (!hard_reg_set_empty_p (reg_class_contents[rclass])
    4163                 :          32 :           && hard_reg_set_subset_p
    4164                 :          32 :              (reg_class_contents[rclass],
    4165                 :          32 :               ira_prohibited_class_mode_regs[rclass][mode]));
    4166                 :             : }
    4167                 :             : 
    4168                 :             : /* Return TRUE if regno is referenced in more than one non-debug insn.  */
    4169                 :             : static bool
    4170                 :     2882872 : multiple_insn_refs_p (int regno)
    4171                 :             : {
    4172                 :     2882872 :   unsigned int uid;
    4173                 :     2882872 :   bitmap_iterator bi;
    4174                 :     2882872 :   int nrefs = 0;
    4175                 :     6910641 :   EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
    4176                 :             :     {
    4177                 :     6905113 :       if (!NONDEBUG_INSN_P (lra_insn_recog_data[uid]->insn))
    4178                 :     1144897 :         continue;
    4179                 :     5760216 :       if (nrefs == 1)
    4180                 :             :         return true;
    4181                 :     2882872 :       nrefs++;
    4182                 :             :     }
    4183                 :             :   return false;
    4184                 :             : }
    4185                 :             : 
    4186                 :             : /* Main entry point of the constraint code: search the body of the
    4187                 :             :    current insn to choose the best alternative.  It is mimicking insn
    4188                 :             :    alternative cost calculation model of former reload pass.  That is
    4189                 :             :    because machine descriptions were written to use this model.  This
    4190                 :             :    model can be changed in future.  Make commutative operand exchange
    4191                 :             :    if it is chosen.
    4192                 :             : 
    4193                 :             :    if CHECK_ONLY_P is false, do RTL changes to satisfy the
    4194                 :             :    constraints.  Return true if any change happened during function
    4195                 :             :    call.
    4196                 :             : 
    4197                 :             :    If CHECK_ONLY_P is true then don't do any transformation.  Just
    4198                 :             :    check that the insn satisfies all constraints.  If the insn does
    4199                 :             :    not satisfy any constraint, return true.  */
    4200                 :             : static bool
    4201                 :   106790212 : curr_insn_transform (bool check_only_p)
    4202                 :             : {
    4203                 :   106790212 :   int i, j, k;
    4204                 :   106790212 :   int n_operands;
    4205                 :   106790212 :   int n_alternatives;
    4206                 :   106790212 :   int n_outputs;
    4207                 :   106790212 :   int commutative;
    4208                 :   106790212 :   signed char goal_alt_matched[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
    4209                 :   106790212 :   signed char match_inputs[MAX_RECOG_OPERANDS + 1];
    4210                 :   106790212 :   signed char outputs[MAX_RECOG_OPERANDS + 1];
    4211                 :   106790212 :   rtx_insn *before, *after;
    4212                 :   106790212 :   bool alt_p = false;
    4213                 :             :   /* Flag that the insn has been changed through a transformation.  */
    4214                 :   106790212 :   bool change_p;
    4215                 :   106790212 :   bool sec_mem_p;
    4216                 :   106790212 :   bool use_sec_mem_p;
    4217                 :   106790212 :   int max_regno_before;
    4218                 :   106790212 :   int reused_alternative_num;
    4219                 :             : 
    4220                 :   106790212 :   curr_insn_set = single_set (curr_insn);
    4221                 :   106790212 :   if (curr_insn_set != NULL_RTX && simple_move_p ())
    4222                 :             :     {
    4223                 :             :       /* We assume that the corresponding insn alternative has no
    4224                 :             :          earlier clobbers.  If it is not the case, don't define move
    4225                 :             :          cost equal to 2 for the corresponding register classes.  */
    4226                 :    16421340 :       lra_set_used_insn_alternative (curr_insn, LRA_NON_CLOBBERED_ALT);
    4227                 :    16421340 :       return false;
    4228                 :             :     }
    4229                 :             : 
    4230                 :    90368872 :   no_input_reloads_p = no_output_reloads_p = false;
    4231                 :    90368872 :   goal_alt_number = -1;
    4232                 :    90368872 :   change_p = sec_mem_p = false;
    4233                 :             : 
    4234                 :             :   /* CALL_INSNs are not allowed to have any output reloads.  */
    4235                 :    90368872 :   if (CALL_P (curr_insn))
    4236                 :     6040699 :     no_output_reloads_p = true;
    4237                 :             : 
    4238                 :    90368872 :   n_operands = curr_static_id->n_operands;
    4239                 :    90368872 :   n_alternatives = curr_static_id->n_alternatives;
    4240                 :             : 
    4241                 :             :   /* Just return "no reloads" if insn has no operands with
    4242                 :             :      constraints.  */
    4243                 :    90368872 :   if (n_operands == 0 || n_alternatives == 0)
    4244                 :             :     return false;
    4245                 :             : 
    4246                 :    79766225 :   max_regno_before = max_reg_num ();
    4247                 :             : 
    4248                 :   337299745 :   for (i = 0; i < n_operands; i++)
    4249                 :             :     {
    4250                 :   177767295 :       goal_alt_matched[i][0] = -1;
    4251                 :   177767295 :       goal_alt_matches[i] = -1;
    4252                 :             :     }
    4253                 :             : 
    4254                 :    79766225 :   commutative = curr_static_id->commutative;
    4255                 :             : 
    4256                 :             :   /* Now see what we need for pseudos that didn't get hard regs or got
    4257                 :             :      the wrong kind of hard reg.  For this, we must consider all the
    4258                 :             :      operands together against the register constraints.  */
    4259                 :             : 
    4260                 :    79766225 :   best_losers = best_overall = INT_MAX;
    4261                 :    79766225 :   best_reload_sum = 0;
    4262                 :             : 
    4263                 :    79766225 :   curr_swapped = false;
    4264                 :    79766225 :   goal_alt_swapped = false;
    4265                 :             : 
    4266                 :    79766225 :   if (! check_only_p)
    4267                 :             :     /* Make equivalence substitution and memory subreg elimination
    4268                 :             :        before address processing because an address legitimacy can
    4269                 :             :        depend on memory mode.  */
    4270                 :   257468405 :     for (i = 0; i < n_operands; i++)
    4271                 :             :       {
    4272                 :   177720472 :         rtx op, subst, old;
    4273                 :   177720472 :         bool op_change_p = false;
    4274                 :             : 
    4275                 :   177720472 :         if (curr_static_id->operand[i].is_operator)
    4276                 :     1411748 :           continue;
    4277                 :             : 
    4278                 :   176308724 :         old = op = *curr_id->operand_loc[i];
    4279                 :   176308724 :         if (GET_CODE (old) == SUBREG)
    4280                 :     3623309 :           old = SUBREG_REG (old);
    4281                 :   176308724 :         subst = get_equiv_with_elimination (old, curr_insn);
    4282                 :   176308724 :         original_subreg_reg_mode[i] = VOIDmode;
    4283                 :   176308724 :         equiv_substition_p[i] = false;
    4284                 :   176308724 :         if (subst != old)
    4285                 :             :           {
    4286                 :     1568611 :             equiv_substition_p[i] = true;
    4287                 :     1568611 :             subst = copy_rtx (subst);
    4288                 :     1568611 :             lra_assert (REG_P (old));
    4289                 :     1568611 :             if (GET_CODE (op) != SUBREG)
    4290                 :     1512193 :               *curr_id->operand_loc[i] = subst;
    4291                 :             :             else
    4292                 :             :               {
    4293                 :       56418 :                 SUBREG_REG (op) = subst;
    4294                 :       56418 :                 if (GET_MODE (subst) == VOIDmode)
    4295                 :          81 :                   original_subreg_reg_mode[i] = GET_MODE (old);
    4296                 :             :               }
    4297                 :     1568611 :             if (lra_dump_file != NULL)
    4298                 :             :               {
    4299                 :           3 :                 fprintf (lra_dump_file,
    4300                 :             :                          "Changing pseudo %d in operand %i of insn %u on equiv ",
    4301                 :           3 :                          REGNO (old), i, INSN_UID (curr_insn));
    4302                 :           3 :                 dump_value_slim (lra_dump_file, subst, 1);
    4303                 :           3 :                 fprintf (lra_dump_file, "\n");
    4304                 :             :               }
    4305                 :     1568611 :             op_change_p = change_p = true;
    4306                 :             :           }
    4307                 :   176308724 :         if (simplify_operand_subreg (i, GET_MODE (old)) || op_change_p)
    4308                 :             :           {
    4309                 :     1569135 :             change_p = true;
    4310                 :     1569135 :             lra_update_dup (curr_id, i);
    4311                 :             :           }
    4312                 :             :       }
    4313                 :             : 
    4314                 :             :   /* Reload address registers and displacements.  We do it before
    4315                 :             :      finding an alternative because of memory constraints.  */
    4316                 :    79766225 :   before = after = NULL;
    4317                 :   257533520 :   for (i = 0; i < n_operands; i++)
    4318                 :   177767295 :     if (! curr_static_id->operand[i].is_operator
    4319                 :   177767295 :         && process_address (i, check_only_p, &before, &after))
    4320                 :             :       {
    4321                 :      476371 :         if (check_only_p)
    4322                 :             :           return true;
    4323                 :      476371 :         change_p = true;
    4324                 :      476371 :         lra_update_dup (curr_id, i);
    4325                 :             :       }
    4326                 :             : 
    4327                 :    79766225 :   if (change_p)
    4328                 :             :     /* If we've changed the instruction then any alternative that
    4329                 :             :        we chose previously may no longer be valid.  */
    4330                 :     2001115 :     lra_set_used_insn_alternative (curr_insn, LRA_UNKNOWN_ALT);
    4331                 :             : 
    4332                 :    79747933 :   if (! check_only_p && curr_insn_set != NULL_RTX
    4333                 :   155659107 :       && check_and_process_move (&change_p, &sec_mem_p))
    4334                 :           0 :     return change_p;
    4335                 :             : 
    4336                 :    79766225 :  try_swapped:
    4337                 :             : 
    4338                 :    90232421 :   reused_alternative_num = check_only_p ? LRA_UNKNOWN_ALT : curr_id->used_insn_alternative;
    4339                 :    90232421 :   if (lra_dump_file != NULL && reused_alternative_num >= 0)
    4340                 :           0 :     fprintf (lra_dump_file, "Reusing alternative %d for insn #%u\n",
    4341                 :           0 :              reused_alternative_num, INSN_UID (curr_insn));
    4342                 :             : 
    4343                 :    90232421 :   if (process_alt_operands (reused_alternative_num))
    4344                 :    81498203 :     alt_p = true;
    4345                 :             : 
    4346                 :    90232421 :   if (check_only_p)
    4347                 :       30621 :     return ! alt_p || best_losers != 0;
    4348                 :             : 
    4349                 :             :   /* If insn is commutative (it's safe to exchange a certain pair of
    4350                 :             :      operands) then we need to try each alternative twice, the second
    4351                 :             :      time matching those two operands as if we had exchanged them.  To
    4352                 :             :      do this, really exchange them in operands.
    4353                 :             : 
    4354                 :             :      If we have just tried the alternatives the second time, return
    4355                 :             :      operands to normal and drop through.  */
    4356                 :             : 
    4357                 :    90214129 :   if (reused_alternative_num < 0 && commutative >= 0)
    4358                 :             :     {
    4359                 :    20932392 :       curr_swapped = !curr_swapped;
    4360                 :    20932392 :       if (curr_swapped)
    4361                 :             :         {
    4362                 :    10466196 :           swap_operands (commutative);
    4363                 :    10466196 :           goto try_swapped;
    4364                 :             :         }
    4365                 :             :       else
    4366                 :    10466196 :         swap_operands (commutative);
    4367                 :             :     }
    4368                 :             : 
    4369                 :    79747933 :   if (! alt_p && ! sec_mem_p)
    4370                 :             :     {
    4371                 :             :       /* No alternative works with reloads??  */
    4372                 :           6 :       if (INSN_CODE (curr_insn) >= 0)
    4373                 :           0 :         fatal_insn ("unable to generate reloads for:", curr_insn);
    4374                 :           6 :       error_for_asm (curr_insn,
    4375                 :             :                      "inconsistent operand constraints in an %<asm%>");
    4376                 :           6 :       lra_asm_error_p = true;
    4377                 :           6 :       if (! JUMP_P (curr_insn))
    4378                 :             :         {
    4379                 :             :           /* Avoid further trouble with this insn.  Don't generate use
    4380                 :             :              pattern here as we could use the insn SP offset.  */
    4381                 :           6 :           lra_set_insn_deleted (curr_insn);
    4382                 :             :         }
    4383                 :             :       else
    4384                 :             :         {
    4385                 :           0 :           lra_invalidate_insn_data (curr_insn);
    4386                 :           0 :           ira_nullify_asm_goto (curr_insn);
    4387                 :           0 :           lra_update_insn_regno_info (curr_insn);
    4388                 :             :         }
    4389                 :           6 :       return true;
    4390                 :             :     }
    4391                 :             : 
    4392                 :             :   /* If the best alternative is with operands 1 and 2 swapped, swap
    4393                 :             :      them.  Update the operand numbers of any reloads already
    4394                 :             :      pushed.  */
    4395                 :             : 
    4396                 :    79747927 :   if (goal_alt_swapped)
    4397                 :             :     {
    4398                 :      587389 :       if (lra_dump_file != NULL)
    4399                 :          18 :         fprintf (lra_dump_file, "  Commutative operand exchange in insn %u\n",
    4400                 :          18 :                  INSN_UID (curr_insn));
    4401                 :             : 
    4402                 :             :       /* Swap the duplicates too.  */
    4403                 :      587389 :       swap_operands (commutative);
    4404                 :      587389 :       change_p = true;
    4405                 :             :     }
    4406                 :             : 
    4407                 :             :   /* Some targets' TARGET_SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
    4408                 :             :      too conservatively.  So we use the secondary memory only if there
    4409                 :             :      is no any alternative without reloads.  */
    4410                 :    79747927 :   use_sec_mem_p = false;
    4411                 :    79747927 :   if (! alt_p)
    4412                 :             :     use_sec_mem_p = true;
    4413                 :    79747927 :   else if (sec_mem_p)
    4414                 :             :     {
    4415                 :       16567 :       for (i = 0; i < n_operands; i++)
    4416                 :       15968 :         if (! goal_alt_win[i] && ! goal_alt_match_win[i])
    4417                 :             :           break;
    4418                 :       13959 :       use_sec_mem_p = i < n_operands;
    4419                 :             :     }
    4420                 :             : 
    4421                 :       13959 :   if (use_sec_mem_p)
    4422                 :             :     {
    4423                 :       13360 :       int in = -1, out = -1;
    4424                 :       13360 :       rtx new_reg, src, dest, rld;
    4425                 :       13360 :       machine_mode sec_mode, rld_mode;
    4426                 :             : 
    4427                 :       13360 :       lra_assert (curr_insn_set != NULL_RTX && sec_mem_p);
    4428                 :       13360 :       dest = SET_DEST (curr_insn_set);
    4429                 :       13360 :       src = SET_SRC (curr_insn_set);
    4430                 :       40080 :       for (i = 0; i < n_operands; i++)
    4431                 :       26720 :         if (*curr_id->operand_loc[i] == dest)
    4432                 :             :           out = i;
    4433                 :       13360 :         else if (*curr_id->operand_loc[i] == src)
    4434                 :       13360 :           in = i;
    4435                 :       13360 :       for (i = 0; i < curr_static_id->n_dups; i++)
    4436                 :           0 :         if (out < 0 && *curr_id->dup_loc[i] == dest)
    4437                 :           0 :           out = curr_static_id->dup_num[i];
    4438                 :           0 :         else if (in < 0 && *curr_id->dup_loc[i] == src)
    4439                 :           0 :           in = curr_static_id->dup_num[i];
    4440                 :       13360 :       lra_assert (out >= 0 && in >= 0
    4441                 :             :                   && curr_static_id->operand[out].type == OP_OUT
    4442                 :             :                   && curr_static_id->operand[in].type == OP_IN);
    4443                 :       13360 :       rld = partial_subreg_p (GET_MODE (src), GET_MODE (dest)) ? src : dest;
    4444                 :       13360 :       rld_mode = GET_MODE (rld);
    4445                 :       13360 :       sec_mode = targetm.secondary_memory_needed_mode (rld_mode);
    4446                 :       13360 :       if (rld_mode != sec_mode
    4447                 :       13360 :           && (invalid_mode_reg_p (sec_mode, dest)
    4448                 :          16 :               || invalid_mode_reg_p (sec_mode, src)))
    4449                 :             :         sec_mode = rld_mode;
    4450                 :       13360 :       new_reg = lra_create_new_reg (sec_mode, NULL_RTX, NO_REGS, NULL,
    4451                 :             :                                     "secondary");
    4452                 :             :       /* If the mode is changed, it should be wider.  */
    4453                 :       13360 :       lra_assert (!partial_subreg_p (sec_mode, rld_mode));
    4454                 :       13360 :       if (sec_mode != rld_mode)
    4455                 :             :         {
    4456                 :             :           /* If the target says specifically to use another mode for
    4457                 :             :              secondary memory moves we cannot reuse the original
    4458                 :             :              insn.  */
    4459                 :          16 :           after = emit_spill_move (false, new_reg, dest);
    4460                 :          16 :           lra_process_new_insns (curr_insn, NULL, after,
    4461                 :             :                                  "Inserting the sec. move");
    4462                 :             :           /* We may have non null BEFORE here (e.g. after address
    4463                 :             :              processing.  */
    4464                 :          16 :           push_to_sequence (before);
    4465                 :          16 :           before = emit_spill_move (true, new_reg, src);
    4466                 :          16 :           emit_insn (before);
    4467                 :          16 :           before = end_sequence ();
    4468                 :          16 :           lra_process_new_insns (curr_insn, before, NULL, "Changing on");
    4469                 :          16 :           lra_set_insn_deleted (curr_insn);
    4470                 :             :         }
    4471                 :       13344 :       else if (dest == rld)
    4472                 :             :         {
    4473                 :       13344 :           *curr_id->operand_loc[out] = new_reg;
    4474                 :       13344 :           lra_update_dup (curr_id, out);
    4475                 :       13344 :           after = emit_spill_move (false, new_reg, dest);
    4476                 :       13344 :           lra_process_new_insns (curr_insn, NULL, after,
    4477                 :             :                                  "Inserting the sec. move");
    4478                 :             :         }
    4479                 :             :       else
    4480                 :             :         {
    4481                 :           0 :           *curr_id->operand_loc[in] = new_reg;
    4482                 :           0 :           lra_update_dup (curr_id, in);
    4483                 :             :           /* See comments above.  */
    4484                 :           0 :           push_to_sequence (before);
    4485                 :           0 :           before = emit_spill_move (true, new_reg, src);
    4486                 :           0 :           emit_insn (before);
    4487                 :           0 :           before = end_sequence ();
    4488                 :           0 :           lra_process_new_insns (curr_insn, before, NULL,
    4489                 :             :                                  "Inserting the sec. move");
    4490                 :             :         }
    4491                 :       13360 :       lra_update_insn_regno_info (curr_insn);
    4492                 :       13360 :       return true;
    4493                 :             :     }
    4494                 :             : 
    4495                 :    79734567 :   lra_assert (goal_alt_number >= 0);
    4496                 :   159372672 :   lra_set_used_insn_alternative (curr_insn, goal_reuse_alt_p
    4497                 :             :                                  ? goal_alt_number : LRA_UNKNOWN_ALT);
    4498                 :             : 
    4499                 :    79734567 :   if (lra_dump_file != NULL)
    4500                 :             :     {
    4501                 :        1194 :       const char *p;
    4502                 :             : 
    4503                 :        1194 :       fprintf (lra_dump_file, "      Choosing alt %d in insn %u:",
    4504                 :        1194 :                goal_alt_number, INSN_UID (curr_insn));
    4505                 :        1194 :       print_curr_insn_alt (goal_alt_number);
    4506                 :        1194 :       if (INSN_CODE (curr_insn) >= 0
    4507                 :        1194 :           && (p = get_insn_name (INSN_CODE (curr_insn))) != NULL)
    4508                 :        1187 :         fprintf (lra_dump_file, " {%s}", p);
    4509                 :        1194 :       if (maybe_ne (curr_id->sp_offset, 0))
    4510                 :             :         {
    4511                 :           0 :           fprintf (lra_dump_file, " (sp_off=");
    4512                 :           0 :           print_dec (curr_id->sp_offset, lra_dump_file);
    4513                 :           0 :           fprintf (lra_dump_file, ")");
    4514                 :             :         }
    4515                 :        1194 :       fprintf (lra_dump_file, "\n");
    4516                 :             :     }
    4517                 :             : 
    4518                 :             :   /* Right now, for any pair of operands I and J that are required to
    4519                 :             :      match, with J < I, goal_alt_matches[I] is J.  Add I to
    4520                 :             :      goal_alt_matched[J].  */
    4521                 :             : 
    4522                 :   257428305 :   for (i = 0; i < n_operands; i++)
    4523                 :   177693738 :     if ((j = goal_alt_matches[i]) >= 0)
    4524                 :             :       {
    4525                 :    10487770 :         for (k = 0; goal_alt_matched[j][k] >= 0; k++)
    4526                 :             :           ;
    4527                 :             :         /* We allow matching one output operand and several input
    4528                 :             :            operands.  */
    4529                 :    10487769 :         lra_assert (k == 0
    4530                 :             :                     || (curr_static_id->operand[j].type == OP_OUT
    4531                 :             :                         && curr_static_id->operand[i].type == OP_IN
    4532                 :             :                         && (curr_static_id->operand
    4533                 :             :                             [goal_alt_matched[j][0]].type == OP_IN)));
    4534                 :    10487769 :         goal_alt_matched[j][k] = i;
    4535                 :    10487769 :         goal_alt_matched[j][k + 1] = -1;
    4536                 :             :       }
    4537                 :             : 
    4538                 :   257428305 :   for (i = 0; i < n_operands; i++)
    4539                 :   177693738 :     goal_alt_win[i] |= goal_alt_match_win[i];
    4540                 :             : 
    4541                 :             :   /* Any constants that aren't allowed and can't be reloaded into
    4542                 :             :      registers are here changed into memory references.  */
    4543                 :   257428305 :   for (i = 0; i < n_operands; i++)
    4544                 :   177693738 :     if (goal_alt_win[i])
    4545                 :             :       {
    4546                 :   171562924 :         int regno;
    4547                 :   171562924 :         enum reg_class new_class;
    4548                 :   171562924 :         rtx reg = *curr_id->operand_loc[i];
    4549                 :             : 
    4550                 :   171562924 :         if (GET_CODE (reg) == SUBREG)
    4551                 :     3319471 :           reg = SUBREG_REG (reg);
    4552                 :             : 
    4553                 :   171562924 :         if (REG_P (reg) && (regno = REGNO (reg)) >= FIRST_PSEUDO_REGISTER)
    4554                 :             :           {
    4555                 :    77689622 :             bool ok_p = in_class_p (reg, goal_alt[i], &new_class, true);
    4556                 :             : 
    4557                 :    77689622 :             if (new_class != NO_REGS && get_reg_class (regno) != new_class)
    4558                 :             :               {
    4559                 :     3578408 :                 lra_assert (ok_p);
    4560                 :     3578408 :                 lra_change_class (regno, new_class, "      Change to", true);
    4561                 :             :               }
    4562                 :             :           }
    4563                 :             :       }
    4564                 :             :     else
    4565                 :             :       {
    4566                 :     6130814 :         const char *constraint;
    4567                 :     6130814 :         char c;
    4568                 :     6130814 :         rtx op = *curr_id->operand_loc[i];
    4569                 :     6130814 :         rtx subreg = NULL_RTX;
    4570                 :     6130814 :         machine_mode mode = curr_operand_mode[i];
    4571                 :             : 
    4572                 :     6130814 :         if (GET_CODE (op) == SUBREG)
    4573                 :             :           {
    4574                 :      237502 :             subreg = op;
    4575                 :      237502 :             op = SUBREG_REG (op);
    4576                 :      237502 :             mode = GET_MODE (op);
    4577                 :             :           }
    4578                 :             : 
    4579                 :     6346006 :         if (CONST_POOL_OK_P (mode, op)
    4580                 :     6346006 :             && ((targetm.preferred_reload_class
    4581                 :      215192 :                  (op, (enum reg_class) goal_alt[i]) == NO_REGS)
    4582                 :       66529 :                 || no_input_reloads_p))
    4583                 :             :           {
    4584                 :      148663 :             rtx tem = force_const_mem (mode, op);
    4585                 :             : 
    4586                 :      148663 :             change_p = true;
    4587                 :      148663 :             if (subreg != NULL_RTX)
    4588                 :           0 :               tem = gen_rtx_SUBREG (mode, tem, SUBREG_BYTE (subreg));
    4589                 :             : 
    4590                 :      148663 :             *curr_id->operand_loc[i] = tem;
    4591                 :      148663 :             lra_update_dup (curr_id, i);
    4592                 :      148663 :             process_address (i, false, &before, &after);
    4593                 :             : 
    4594                 :             :             /* If the alternative accepts constant pool refs directly
    4595                 :             :                there will be no reload needed at all.  */
    4596                 :      148663 :             if (subreg != NULL_RTX)
    4597                 :           0 :               continue;
    4598                 :             :             /* Skip alternatives before the one requested.  */
    4599                 :      148663 :             constraint = (curr_static_id->operand_alternative
    4600                 :      148663 :                           [goal_alt_number * n_operands + i].constraint);
    4601                 :      148663 :             for (;
    4602                 :      251538 :                  (c = *constraint) && c != ',' && c != '#';
    4603                 :      102875 :                  constraint += CONSTRAINT_LEN (c, constraint))
    4604                 :             :               {
    4605                 :      204866 :                 enum constraint_num cn = lookup_constraint (constraint);
    4606                 :      204866 :                 if ((insn_extra_memory_constraint (cn)
    4607                 :      102958 :                      || insn_extra_special_memory_constraint (cn)
    4608                 :             :                      || insn_extra_relaxed_memory_constraint (cn))
    4609                 :      204949 :                     && satisfies_memory_constraint_p (tem, cn))
    4610                 :             :                   break;
    4611                 :             :               }
    4612                 :      148663 :             if (c == '\0' || c == ',' || c == '#')
    4613                 :       46672 :               continue;
    4614                 :             : 
    4615                 :      101991 :             goal_alt_win[i] = true;
    4616                 :             :           }
    4617                 :             :       }
    4618                 :             : 
    4619                 :             :   n_outputs = 0;
    4620                 :   257428305 :   for (i = 0; i < n_operands; i++)
    4621                 :   177693738 :     if (curr_static_id->operand[i].type == OP_OUT)
    4622                 :    69211888 :       outputs[n_outputs++] = i;
    4623                 :    79734567 :   outputs[n_outputs] = -1;
    4624                 :   257428305 :   for (i = 0; i < n_operands; i++)
    4625                 :             :     {
    4626                 :   177693738 :       int regno;
    4627                 :   177693738 :       bool optional_p = false;
    4628                 :   177693738 :       rtx old, new_reg;
    4629                 :   177693738 :       rtx op = *curr_id->operand_loc[i];
    4630                 :             : 
    4631                 :   177693738 :       if (goal_alt_win[i])
    4632                 :             :         {
    4633                 :   171664915 :           if (goal_alt[i] == NO_REGS
    4634                 :    46698711 :               && REG_P (op)
    4635                 :     5372414 :               && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
    4636                 :             :               /* We assigned a hard register to the pseudo in the past but now
    4637                 :             :                  decided to spill it for the insn.  If the pseudo is used only
    4638                 :             :                  in this insn, it is better to spill it here as we free hard
    4639                 :             :                  registers for other pseudos referenced in the insn.  The most
    4640                 :             :                  common case of this is a scratch register which will be
    4641                 :             :                  transformed to scratch back at the end of LRA.  */
    4642                 :   174547787 :               && !multiple_insn_refs_p (regno))
    4643                 :             :             {
    4644                 :       11056 :               if (lra_get_allocno_class (regno) != NO_REGS)
    4645                 :        5256 :                 lra_change_class (regno, NO_REGS, "      Change to", true);
    4646                 :        5528 :               reg_renumber[regno] = -1;
    4647                 :             :             }
    4648                 :             :           /* We can do an optional reload.  If the pseudo got a hard
    4649                 :             :              reg, we might improve the code through inheritance.  If
    4650                 :             :              it does not get a hard register we coalesce memory/memory
    4651                 :             :              moves later.  Ignore move insns to avoid cycling.  */
    4652                 :   171664915 :           if (! lra_simple_p
    4653                 :   171120237 :               && lra_undo_inheritance_iter < LRA_MAX_INHERITANCE_PASSES
    4654                 :   158456402 :               && goal_alt[i] != NO_REGS && REG_P (op)
    4655                 :    78671874 :               && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
    4656                 :    65750677 :               && regno < new_regno_start
    4657                 :    60955859 :               && ! ira_former_scratch_p (regno)
    4658                 :    60899072 :               && reg_renumber[regno] < 0
    4659                 :             :               /* Check that the optional reload pseudo will be able to
    4660                 :             :                  hold given mode value.  */
    4661                 :     3829964 :               && ! (prohibited_class_reg_set_mode_p
    4662                 :     3829964 :                     (goal_alt[i], reg_class_contents[goal_alt[i]],
    4663                 :     3829964 :                      PSEUDO_REGNO_MODE (regno)))
    4664                 :   175494869 :               && (curr_insn_set == NULL_RTX
    4665                 :     3822728 :                   || !((REG_P (SET_SRC (curr_insn_set))
    4666                 :             :                         || MEM_P (SET_SRC (curr_insn_set))
    4667                 :             :                         || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG)
    4668                 :     3157850 :                        && (REG_P (SET_DEST (curr_insn_set))
    4669                 :             :                            || MEM_P (SET_DEST (curr_insn_set))
    4670                 :             :                            || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG))))
    4671                 :             :             optional_p = true;
    4672                 :   170992776 :           else if (goal_alt_matched[i][0] != -1
    4673                 :     8787188 :                    && curr_static_id->operand[i].type == OP_OUT
    4674                 :     8786064 :                    && (curr_static_id->operand_alternative
    4675                 :     8786064 :                        [goal_alt_number * n_operands + i].earlyclobber)
    4676                 :       19728 :                    && REG_P (op))
    4677                 :             :             {
    4678                 :       25095 :               for (j = 0; goal_alt_matched[i][j] != -1; j++)
    4679                 :             :                 {
    4680                 :       19675 :                   rtx op2 = *curr_id->operand_loc[goal_alt_matched[i][j]];
    4681                 :             : 
    4682                 :       19675 :                   if (REG_P (op2) && REGNO (op) != REGNO (op2))
    4683                 :             :                     break;
    4684                 :             :                 }
    4685                 :       19675 :               if (goal_alt_matched[i][j] != -1)
    4686                 :             :                 {
    4687                 :             :                   /* Generate reloads for different output and matched
    4688                 :             :                      input registers.  This is the easiest way to avoid
    4689                 :             :                      creation of non-existing register conflicts in
    4690                 :             :                      lra-lives.cc.  */
    4691                 :       14255 :                   match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
    4692                 :             :                                 &goal_alt_exclude_start_hard_regs[i], &before,
    4693                 :             :                                 &after, true);
    4694                 :             :                 }
    4695                 :   172595941 :               continue;
    4696                 :       19675 :             }
    4697                 :             :           else
    4698                 :             :             {
    4699                 :   170973101 :               enum reg_class rclass, common_class;
    4700                 :             : 
    4701                 :    89514983 :               if (REG_P (op) && goal_alt[i] != NO_REGS
    4702                 :    84142569 :                   && (regno = REGNO (op)) >= new_regno_start
    4703                 :     4805919 :                   && (rclass = get_reg_class (regno)) == ALL_REGS
    4704                 :           0 :                   && ((common_class = ira_reg_class_subset[rclass][goal_alt[i]])
    4705                 :             :                       != NO_REGS)
    4706                 :           0 :                   && common_class != ALL_REGS
    4707                 :   170973101 :                   && enough_allocatable_hard_regs_p (common_class,
    4708                 :           0 :                                                      GET_MODE (op)))
    4709                 :             :                 /* Refine reload pseudo class from chosen alternative
    4710                 :             :                    constraint.  */
    4711                 :           0 :                 lra_change_class (regno, common_class, "      Change to", true);
    4712                 :   170973101 :               continue;
    4713                 :   170973101 :             }
    4714                 :             :         }
    4715                 :             : 
    4716                 :             :       /* Operands that match previous ones have already been handled.  */
    4717                 :     6700962 :       if (goal_alt_matches[i] >= 0)
    4718                 :     1603165 :         continue;
    4719                 :             : 
    4720                 :             :       /* We should not have an operand with a non-offsettable address
    4721                 :             :          appearing where an offsettable address will do.  It also may
    4722                 :             :          be a case when the address should be special in other words
    4723                 :             :          not a general one (e.g. it needs no index reg).  */
    4724                 :     5097797 :       if (goal_alt_matched[i][0] == -1 && goal_alt_offmemok[i] && MEM_P (op))
    4725                 :             :         {
    4726                 :          72 :           enum reg_class rclass;
    4727                 :          72 :           rtx *loc = &XEXP (op, 0);
    4728                 :          72 :           enum rtx_code code = GET_CODE (*loc);
    4729                 :             : 
    4730                 :          72 :           push_to_sequence (before);
    4731                 :          72 :           rclass = base_reg_class (GET_MODE (op), MEM_ADDR_SPACE (op),
    4732                 :             :                                    MEM, SCRATCH, curr_insn);
    4733                 :          72 :           if (GET_RTX_CLASS (code) == RTX_AUTOINC)
    4734                 :           0 :             new_reg = emit_inc (rclass, *loc,
    4735                 :             :                                 /* This value does not matter for MODIFY.  */
    4736                 :           0 :                                 GET_MODE_SIZE (GET_MODE (op)));
    4737                 :          86 :           else if (get_reload_reg (OP_IN, Pmode, *loc, rclass,
    4738                 :             :                                    NULL, false, false,
    4739                 :             :                                    "offsetable address", &new_reg))
    4740                 :             :             {
    4741                 :          72 :               rtx addr = *loc;
    4742                 :          72 :               enum rtx_code code = GET_CODE (addr);
    4743                 :          72 :               bool align_p = false;
    4744                 :             : 
    4745                 :          72 :               if (code == AND && CONST_INT_P (XEXP (addr, 1)))
    4746                 :             :                 {
    4747                 :             :                   /* (and ... (const_int -X)) is used to align to X bytes.  */
    4748                 :           0 :                   align_p = true;
    4749                 :           0 :                   addr = XEXP (*loc, 0);
    4750                 :             :                 }
    4751                 :             :               else
    4752                 :          72 :                 addr = canonicalize_reload_addr (addr);
    4753                 :             : 
    4754                 :          72 :               lra_emit_move (new_reg, addr);
    4755                 :          72 :               if (align_p)
    4756                 :           0 :                 emit_move_insn (new_reg, gen_rtx_AND (GET_MODE (new_reg), new_reg, XEXP (*loc, 1)));
    4757                 :             :             }
    4758                 :          72 :           before = end_sequence ();
    4759                 :          72 :           *loc = new_reg;
    4760                 :          72 :           lra_update_dup (curr_id, i);
    4761                 :          72 :         }
    4762                 :     5097725 :       else if (goal_alt_matched[i][0] == -1)
    4763                 :             :         {
    4764                 :     3397145 :           machine_mode mode;
    4765                 :     3397145 :           rtx reg, *loc;
    4766                 :     3397145 :           int hard_regno;
    4767                 :     3397145 :           enum op_type type = curr_static_id->operand[i].type;
    4768                 :             : 
    4769                 :     3397145 :           loc = curr_id->operand_loc[i];
    4770                 :     3397145 :           mode = curr_operand_mode[i];
    4771                 :     3397145 :           if (GET_CODE (*loc) == SUBREG)
    4772                 :             :             {
    4773                 :       73481 :               reg = SUBREG_REG (*loc);
    4774                 :       73481 :               poly_int64 byte = SUBREG_BYTE (*loc);
    4775                 :       73481 :               if (REG_P (reg)
    4776                 :             :                   /* Strict_low_part requires reloading the register and not
    4777                 :             :                      just the subreg.  Likewise for a strict subreg no wider
    4778                 :             :                      than a word for WORD_REGISTER_OPERATIONS targets.  */
    4779                 :       73481 :                   && (curr_static_id->operand[i].strict_low
    4780                 :       73412 :                       || (!paradoxical_subreg_p (mode, GET_MODE (reg))
    4781                 :       70826 :                           && (hard_regno
    4782                 :       70826 :                               = get_try_hard_regno (REGNO (reg))) >= 0
    4783                 :       69459 :                           && (simplify_subreg_regno
    4784                 :      142940 :                               (hard_regno,
    4785                 :       69459 :                                GET_MODE (reg), byte, mode) < 0)
    4786                 :           0 :                           && (goal_alt[i] == NO_REGS
    4787                 :           0 :                               || (simplify_subreg_regno
    4788                 :       73481 :                                   (ira_class_hard_regs[goal_alt[i]][0],
    4789                 :           0 :                                    GET_MODE (reg), byte, mode) >= 0)))
    4790                 :       73412 :                       || (partial_subreg_p (mode, GET_MODE (reg))
    4791                 :       73412 :                           && known_le (GET_MODE_SIZE (GET_MODE (reg)),
    4792                 :             :                                        UNITS_PER_WORD)
    4793                 :             :                           && WORD_REGISTER_OPERATIONS))
    4794                 :             :                   /* Avoid the situation when there are no available hard regs
    4795                 :             :                      for the pseudo mode but there are ones for the subreg
    4796                 :             :                      mode: */
    4797                 :       73550 :                   && !(goal_alt[i] != NO_REGS
    4798                 :          69 :                        && REGNO (reg) >= FIRST_PSEUDO_REGISTER
    4799                 :          69 :                        && (prohibited_class_reg_set_mode_p
    4800                 :          69 :                            (goal_alt[i], reg_class_contents[goal_alt[i]],
    4801                 :          69 :                             GET_MODE (reg)))
    4802                 :             :                        && !(prohibited_class_reg_set_mode_p
    4803                 :           0 :                             (goal_alt[i], reg_class_contents[goal_alt[i]],
    4804                 :             :                              mode))))
    4805                 :             :                 {
    4806                 :             :                   /* An OP_INOUT is required when reloading a subreg of a
    4807                 :             :                      mode wider than a word to ensure that data beyond the
    4808                 :             :                      word being reloaded is preserved.  Also automatically
    4809                 :             :                      ensure that strict_low_part reloads are made into
    4810                 :             :                      OP_INOUT which should already be true from the backend
    4811                 :             :                      constraints.  */
    4812                 :          69 :                   if (type == OP_OUT
    4813                 :          69 :                       && (curr_static_id->operand[i].strict_low
    4814                 :           0 :                           || read_modify_subreg_p (*loc)))
    4815                 :             :                     type = OP_INOUT;
    4816                 :          69 :                   loc = &SUBREG_REG (*loc);
    4817                 :          69 :                   mode = GET_MODE (*loc);
    4818                 :             :                 }
    4819                 :             :             }
    4820                 :     3397145 :           old = *loc;
    4821                 :     3397145 :           if (get_reload_reg (type, mode, old, goal_alt[i],
    4822                 :             :                               &goal_alt_exclude_start_hard_regs[i],
    4823                 :     3397145 :                               loc != curr_id->operand_loc[i],
    4824                 :     3397145 :                               curr_static_id->operand_alternative
    4825                 :     3397145 :                               [goal_alt_number * n_operands + i].earlyclobber,
    4826                 :             :                                "", &new_reg)
    4827                 :     3397145 :               && type != OP_OUT)
    4828                 :             :             {
    4829                 :     2419279 :               push_to_sequence (before);
    4830                 :     2419279 :               lra_emit_move (new_reg, old);
    4831                 :     2419279 :               before = end_sequence ();
    4832                 :             :             }
    4833                 :     3397145 :           *loc = new_reg;
    4834                 :     3397145 :           if (type != OP_IN
    4835                 :      976764 :               && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX
    4836                 :             :               /* OLD can be an equivalent constant here.  */
    4837                 :     4349244 :               && !CONSTANT_P (old))
    4838                 :             :             {
    4839                 :      952099 :               start_sequence ();
    4840                 :      952099 :               lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg);
    4841                 :      952099 :               emit_insn (after);
    4842                 :      952099 :               after = end_sequence ();
    4843                 :      952099 :               *loc = new_reg;
    4844                 :             :             }
    4845                 :     3397145 :           for (j = 0; j < goal_alt_dont_inherit_ops_num; j++)
    4846                 :         576 :             if (goal_alt_dont_inherit_ops[j] == i)
    4847                 :             :               {
    4848                 :         576 :                 lra_set_regno_unique_value (REGNO (new_reg));
    4849                 :         576 :                 break;
    4850                 :             :               }
    4851                 :     3397145 :           lra_update_dup (curr_id, i);
    4852                 :             :         }
    4853                 :     1700580 :       else if (curr_static_id->operand[i].type == OP_IN
    4854                 :     1700580 :                && (curr_static_id->operand[goal_alt_matched[i][0]].type
    4855                 :             :                    == OP_OUT
    4856                 :           0 :                    || (curr_static_id->operand[goal_alt_matched[i][0]].type
    4857                 :             :                        == OP_INOUT
    4858                 :           0 :                        && (operands_match_p
    4859                 :           0 :                            (*curr_id->operand_loc[i],
    4860                 :           0 :                             *curr_id->operand_loc[goal_alt_matched[i][0]],
    4861                 :             :                             -1)))))
    4862                 :             :         {
    4863                 :             :           /* generate reloads for input and matched outputs.  */
    4864                 :       16892 :           match_inputs[0] = i;
    4865                 :       16892 :           match_inputs[1] = -1;
    4866                 :       16892 :           match_reload (goal_alt_matched[i][0], match_inputs, outputs,
    4867                 :             :                         goal_alt[i], &goal_alt_exclude_start_hard_regs[i],
    4868                 :             :                         &before, &after,
    4869                 :       16892 :                         curr_static_id->operand_alternative
    4870                 :       16892 :                         [goal_alt_number * n_operands + goal_alt_matched[i][0]]
    4871                 :       16892 :                         .earlyclobber);
    4872                 :             :         }
    4873                 :     1683688 :       else if ((curr_static_id->operand[i].type == OP_OUT
    4874                 :           0 :                 || (curr_static_id->operand[i].type == OP_INOUT
    4875                 :           0 :                     && (operands_match_p
    4876                 :           0 :                         (*curr_id->operand_loc[i],
    4877                 :           0 :                          *curr_id->operand_loc[goal_alt_matched[i][0]],
    4878                 :             :                          -1))))
    4879                 :     1683688 :                && (curr_static_id->operand[goal_alt_matched[i][0]].type
    4880                 :             :                     == OP_IN))
    4881                 :             :         /* Generate reloads for output and matched inputs.  */
    4882                 :     1683688 :         match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
    4883                 :             :                       &goal_alt_exclude_start_hard_regs[i], &before, &after,
    4884                 :     1683688 :                       curr_static_id->operand_alternative
    4885                 :     1683688 :                       [goal_alt_number * n_operands + i].earlyclobber);
    4886                 :           0 :       else if (curr_static_id->operand[i].type == OP_IN
    4887                 :           0 :                && (curr_static_id->operand[goal_alt_matched[i][0]].type
    4888                 :             :                    == OP_IN))
    4889                 :             :         {
    4890                 :             :           /* Generate reloads for matched inputs.  */
    4891                 :           0 :           match_inputs[0] = i;
    4892                 :           0 :           for (j = 0; (k = goal_alt_matched[i][j]) >= 0; j++)
    4893                 :           0 :             match_inputs[j + 1] = k;
    4894                 :           0 :           match_inputs[j + 1] = -1;
    4895                 :           0 :           match_reload (-1, match_inputs, outputs, goal_alt[i],
    4896                 :             :                         &goal_alt_exclude_start_hard_regs[i],
    4897                 :             :                         &before, &after, false);
    4898                 :             :         }
    4899                 :             :       else
    4900                 :             :         /* We must generate code in any case when function
    4901                 :             :            process_alt_operands decides that it is possible.  */
    4902                 :           0 :         gcc_unreachable ();
    4903                 :             : 
    4904                 :     5097797 :       if (optional_p)
    4905                 :             :         {
    4906                 :      672139 :           rtx reg = op;
    4907                 :             : 
    4908                 :      672139 :           lra_assert (REG_P (reg));
    4909                 :      672139 :           regno = REGNO (reg);
    4910                 :      672139 :           op = *curr_id->operand_loc[i]; /* Substitution.  */
    4911                 :      672139 :           if (GET_CODE (op) == SUBREG)
    4912                 :           0 :             op = SUBREG_REG (op);
    4913                 :      672139 :           gcc_assert (REG_P (op) && (int) REGNO (op) >= new_regno_start);
    4914                 :      672139 :           bitmap_set_bit (&lra_optional_reload_pseudos, REGNO (op));
    4915                 :      672139 :           lra_reg_info[REGNO (op)].restore_rtx = reg;
    4916                 :      672139 :           if (lra_dump_file != NULL)
    4917                 :           3 :             fprintf (lra_dump_file,
    4918                 :             :                      "      Making reload reg %d for reg %d optional\n",
    4919                 :             :                      REGNO (op), regno);
    4920                 :             :         }
    4921                 :             :     }
    4922                 :    75383801 :   if (before != NULL_RTX || after != NULL_RTX
    4923                 :   154300325 :       || max_regno_before != max_reg_num ())
    4924                 :     5193894 :     change_p = true;
    4925                 :    79734567 :   if (change_p)
    4926                 :             :     {
    4927                 :     6106439 :       lra_update_operator_dups (curr_id);
    4928                 :             :       /* Something changes -- process the insn.  */
    4929                 :     6106439 :       lra_update_insn_regno_info (curr_insn);
    4930                 :     6106439 :       if (asm_noperands (PATTERN (curr_insn)) >= 0
    4931                 :     6106439 :           && ++curr_id->asm_reloads_num >= FIRST_PSEUDO_REGISTER)
    4932                 :             :         /* Most probably there are no enough registers to satisfy asm insn: */
    4933                 :             :         {
    4934                 :          24 :           lra_asm_insn_error (curr_insn);
    4935                 :          24 :           return change_p;
    4936                 :             :         }
    4937                 :             :     }
    4938                 :    79734543 :   if (goal_alt_out_sp_reload_p)
    4939                 :             :     {
    4940                 :             :       /* We have an output stack pointer reload -- update sp offset: */
    4941                 :           0 :       rtx set;
    4942                 :           0 :       bool done_p = false;
    4943                 :           0 :       poly_int64 sp_offset = curr_id->sp_offset;
    4944                 :           0 :       for (rtx_insn *insn = after; insn != NULL_RTX; insn = NEXT_INSN (insn))
    4945                 :           0 :         if ((set = single_set (insn)) != NULL_RTX
    4946                 :           0 :             && SET_DEST (set) == stack_pointer_rtx)
    4947                 :             :           {
    4948                 :           0 :             lra_assert (!done_p);
    4949                 :           0 :             done_p = true;
    4950                 :           0 :             curr_id->sp_offset = 0;
    4951                 :           0 :             lra_insn_recog_data_t id = lra_get_insn_recog_data (insn);
    4952                 :           0 :             id->sp_offset = sp_offset;
    4953                 :           0 :             if (lra_dump_file != NULL)
    4954                 :           0 :               fprintf (lra_dump_file,
    4955                 :             :                        "            Moving sp offset from insn %u to %u\n",
    4956                 :           0 :                        INSN_UID (curr_insn), INSN_UID (insn));
    4957                 :             :           }
    4958                 :           0 :       lra_assert (done_p);
    4959                 :             :     }
    4960                 :    79734543 :   lra_process_new_insns (curr_insn, before, after, "Inserting insn reload");
    4961                 :    79734543 :   return change_p;
    4962                 :             : }
    4963                 :             : 
    4964                 :             : /* Return true if INSN satisfies all constraints.  In other words, no
    4965                 :             :    reload insns are needed.  */
    4966                 :             : bool
    4967                 :        3619 : lra_constrain_insn (rtx_insn *insn)
    4968                 :             : {
    4969                 :        3619 :   int saved_new_regno_start = new_regno_start;
    4970                 :        3619 :   int saved_new_insn_uid_start = new_insn_uid_start;
    4971                 :        3619 :   bool change_p;
    4972                 :             : 
    4973                 :        3619 :   curr_insn = insn;
    4974                 :        3619 :   curr_id = lra_get_insn_recog_data (curr_insn);
    4975                 :        3619 :   curr_static_id = curr_id->insn_static_data;
    4976                 :        3619 :   new_insn_uid_start = get_max_uid ();
    4977                 :        3619 :   new_regno_start = max_reg_num ();
    4978                 :        3619 :   change_p = curr_insn_transform (true);
    4979                 :        3619 :   new_regno_start = saved_new_regno_start;
    4980                 :        3619 :   new_insn_uid_start = saved_new_insn_uid_start;
    4981                 :        3619 :   return ! change_p;
    4982                 :             : }
    4983                 :             : 
    4984                 :             : /* Return true if X is in LIST.  */
    4985                 :             : static bool
    4986                 :     1371169 : in_list_p (rtx x, rtx list)
    4987                 :             : {
    4988                 :     2336628 :   for (; list != NULL_RTX; list = XEXP (list, 1))
    4989                 :     1291654 :     if (XEXP (list, 0) == x)
    4990                 :             :       return true;
    4991                 :             :   return false;
    4992                 :             : }
    4993                 :             : 
    4994                 :             : /* Return true if X contains an allocatable hard register (if
    4995                 :             :    HARD_REG_P) or a (spilled if SPILLED_P) pseudo.  */
    4996                 :             : static bool
    4997                 :     7632620 : contains_reg_p (rtx x, bool hard_reg_p, bool spilled_p)
    4998                 :             : {
    4999                 :     7632620 :   int i, j;
    5000                 :     7632620 :   const char *fmt;
    5001                 :     7632620 :   enum rtx_code code;
    5002                 :             : 
    5003                 :     7632620 :   code = GET_CODE (x);
    5004                 :     7632620 :   if (REG_P (x))
    5005                 :             :     {
    5006                 :     1592089 :       int regno = REGNO (x);
    5007                 :     1592089 :       HARD_REG_SET alloc_regs;
    5008                 :             : 
    5009                 :     1592089 :       if (hard_reg_p)
    5010                 :             :         {
    5011                 :      503917 :           if (regno >= FIRST_PSEUDO_REGISTER)
    5012                 :      148791 :             regno = lra_get_regno_hard_regno (regno);
    5013                 :      503917 :           if (regno < 0)
    5014                 :             :             return false;
    5015                 :      503917 :           alloc_regs = ~lra_no_alloc_regs;
    5016                 :      503917 :           return overlaps_hard_reg_set_p (alloc_regs, GET_MODE (x), regno);
    5017                 :             :         }
    5018                 :             :       else
    5019                 :             :         {
    5020                 :     1088172 :           if (regno < FIRST_PSEUDO_REGISTER)
    5021                 :             :             return false;
    5022                 :      347628 :           if (! spilled_p)
    5023                 :             :             return true;
    5024                 :      183378 :           return lra_get_regno_hard_regno (regno) < 0;
    5025                 :             :         }
    5026                 :             :     }
    5027                 :     6040531 :   fmt = GET_RTX_FORMAT (code);
    5028                 :    14978372 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    5029                 :             :     {
    5030                 :     9549886 :       if (fmt[i] == 'e')
    5031                 :             :         {
    5032                 :     4328667 :           if (contains_reg_p (XEXP (x, i), hard_reg_p, spilled_p))
    5033                 :             :             return true;
    5034                 :             :         }
    5035                 :     5221219 :       else if (fmt[i] == 'E')
    5036                 :             :         {
    5037                 :     1180522 :           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    5038                 :     1078929 :             if (contains_reg_p (XVECEXP (x, i, j), hard_reg_p, spilled_p))
    5039                 :             :               return true;
    5040                 :             :         }
    5041                 :             :     }
    5042                 :             :   return false;
    5043                 :             : }
    5044                 :             : 
    5045                 :             : /* Process all regs in location *LOC and change them on equivalent
    5046                 :             :    substitution.  Return true if any change was done.  */
    5047                 :             : static bool
    5048                 :        3098 : loc_equivalence_change_p (rtx *loc)
    5049                 :             : {
    5050                 :        3098 :   rtx subst, reg, x = *loc;
    5051                 :        3098 :   bool result = false;
    5052                 :        3098 :   enum rtx_code code = GET_CODE (x);
    5053                 :        3098 :   const char *fmt;
    5054                 :        3098 :   int i, j;
    5055                 :             : 
    5056                 :        3098 :   if (code == SUBREG)
    5057                 :             :     {
    5058                 :          10 :       reg = SUBREG_REG (x);
    5059                 :          10 :       if ((subst = get_equiv_with_elimination (reg, curr_insn)) != reg
    5060                 :          10 :           && GET_MODE (subst) == VOIDmode)
    5061                 :             :         {
    5062                 :             :           /* We cannot reload debug location.  Simplify subreg here
    5063                 :             :              while we know the inner mode.  */
    5064                 :           0 :           *loc = simplify_gen_subreg (GET_MODE (x), subst,
    5065                 :           0 :                                       GET_MODE (reg), SUBREG_BYTE (x));
    5066                 :           0 :           return true;
    5067                 :             :         }
    5068                 :             :     }
    5069                 :        3098 :   if (code == REG && (subst = get_equiv_with_elimination (x, curr_insn)) != x)
    5070                 :             :     {
    5071                 :           8 :       *loc = subst;
    5072                 :           8 :       return true;
    5073                 :             :     }
    5074                 :             : 
    5075                 :             :   /* Scan all the operand sub-expressions.  */
    5076                 :        3090 :   fmt = GET_RTX_FORMAT (code);
    5077                 :        7490 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    5078                 :             :     {
    5079                 :        4400 :       if (fmt[i] == 'e')
    5080                 :        2426 :         result = loc_equivalence_change_p (&XEXP (x, i)) || result;
    5081                 :        1974 :       else if (fmt[i] == 'E')
    5082                 :         135 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    5083                 :         100 :           result
    5084                 :         110 :             = loc_equivalence_change_p (&XVECEXP (x, i, j)) || result;
    5085                 :             :     }
    5086                 :             :   return result;
    5087                 :             : }
    5088                 :             : 
    5089                 :             : /* Similar to loc_equivalence_change_p, but for use as
    5090                 :             :    simplify_replace_fn_rtx callback.  DATA is insn for which the
    5091                 :             :    elimination is done.  If it null we don't do the elimination.  */
    5092                 :             : static rtx
    5093                 :    43291411 : loc_equivalence_callback (rtx loc, const_rtx, void *data)
    5094                 :             : {
    5095                 :    43291411 :   if (!REG_P (loc))
    5096                 :             :     return NULL_RTX;
    5097                 :             : 
    5098                 :    11147815 :   rtx subst = (data == NULL
    5099                 :    11147815 :                ? get_equiv (loc) : get_equiv_with_elimination (loc, (rtx_insn *) data));
    5100                 :    11147815 :   if (subst != loc)
    5101                 :             :     return subst;
    5102                 :             : 
    5103                 :             :   return NULL_RTX;
    5104                 :             : }
    5105                 :             : 
    5106                 :             : /* Maximum number of generated reload insns per an insn.  It is for
    5107                 :             :    preventing this pass cycling in a bug case.  */
    5108                 :             : #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
    5109                 :             : 
    5110                 :             : /* The current iteration number of this LRA pass.  */
    5111                 :             : int lra_constraint_iter;
    5112                 :             : 
    5113                 :             : /* True if we should during assignment sub-pass check assignment
    5114                 :             :    correctness for all pseudos and spill some of them to correct
    5115                 :             :    conflicts.  It can be necessary when we substitute equiv which
    5116                 :             :    needs checking register allocation correctness because the
    5117                 :             :    equivalent value contains allocatable hard registers, or when we
    5118                 :             :    restore multi-register pseudo, or when we change the insn code and
    5119                 :             :    its operand became INOUT operand when it was IN one before.  */
    5120                 :             : bool check_and_force_assignment_correctness_p;
    5121                 :             : 
    5122                 :             : /* Return true if REGNO is referenced in more than one block.  */
    5123                 :             : static bool
    5124                 :      158402 : multi_block_pseudo_p (int regno)
    5125                 :             : {
    5126                 :      158402 :   basic_block bb = NULL;
    5127                 :      158402 :   unsigned int uid;
    5128                 :      158402 :   bitmap_iterator bi;
    5129                 :             : 
    5130                 :      158402 :   if (regno < FIRST_PSEUDO_REGISTER)
    5131                 :             :     return false;
    5132                 :             : 
    5133                 :      486425 :   EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
    5134                 :      332772 :     if (bb == NULL)
    5135                 :      158402 :       bb = BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn);
    5136                 :      174370 :     else if (BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn) != bb)
    5137                 :             :       return true;
    5138                 :             :   return false;
    5139                 :             : }
    5140                 :             : 
    5141                 :             : /* Return true if LIST contains a deleted insn.  */
    5142                 :             : static bool
    5143                 :      743321 : contains_deleted_insn_p (rtx_insn_list *list)
    5144                 :             : {
    5145                 :     1422051 :   for (; list != NULL_RTX; list = list->next ())
    5146                 :      678730 :     if (NOTE_P (list->insn ())
    5147                 :      678730 :         && NOTE_KIND (list->insn ()) == NOTE_INSN_DELETED)
    5148                 :             :       return true;
    5149                 :             :   return false;
    5150                 :             : }
    5151                 :             : 
    5152                 :             : /* Return true if X contains a pseudo dying in INSN.  */
    5153                 :             : static bool
    5154                 :     2328229 : dead_pseudo_p (rtx x, rtx_insn *insn)
    5155                 :             : {
    5156                 :     2328229 :   int i, j;
    5157                 :     2328229 :   const char *fmt;
    5158                 :     2328229 :   enum rtx_code code;
    5159                 :             : 
    5160                 :     2328229 :   if (REG_P (x))
    5161                 :      528749 :     return (insn != NULL_RTX
    5162                 :      528749 :             && find_regno_note (insn, REG_DEAD, REGNO (x)) != NULL_RTX);
    5163                 :     1799480 :   code = GET_CODE (x);
    5164                 :     1799480 :   fmt = GET_RTX_FORMAT (code);
    5165                 :     4617911 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    5166                 :             :     {
    5167                 :     2823420 :       if (fmt[i] == 'e')
    5168                 :             :         {
    5169                 :     1411026 :           if (dead_pseudo_p (XEXP (x, i), insn))
    5170                 :             :             return true;
    5171                 :             :         }
    5172                 :     1412394 :       else if (fmt[i] == 'E')
    5173                 :             :         {
    5174                 :      262718 :           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    5175                 :      239869 :             if (dead_pseudo_p (XVECEXP (x, i, j), insn))
    5176                 :             :               return true;
    5177                 :             :         }
    5178                 :             :     }
    5179                 :             :   return false;
    5180                 :             : }
    5181                 :             : 
    5182                 :             : /* Return true if INSN contains a dying pseudo in INSN right hand
    5183                 :             :    side.  */
    5184                 :             : static bool
    5185                 :      677334 : insn_rhs_dead_pseudo_p (rtx_insn *insn)
    5186                 :             : {
    5187                 :      677334 :   rtx set = single_set (insn);
    5188                 :             : 
    5189                 :      677334 :   gcc_assert (set != NULL);
    5190                 :      677334 :   return dead_pseudo_p (SET_SRC (set), insn);
    5191                 :             : }
    5192                 :             : 
    5193                 :             : /* Return true if any init insn of REGNO contains a dying pseudo in
    5194                 :             :    insn right hand side.  */
    5195                 :             : static bool
    5196                 :      741925 : init_insn_rhs_dead_pseudo_p (int regno)
    5197                 :             : {
    5198                 :      741925 :   rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
    5199                 :             : 
    5200                 :      741925 :   if (insns == NULL)
    5201                 :             :     return false;
    5202                 :     1349620 :   for (; insns != NULL_RTX; insns = insns->next ())
    5203                 :      677334 :     if (insn_rhs_dead_pseudo_p (insns->insn ()))
    5204                 :             :       return true;
    5205                 :             :   return false;
    5206                 :             : }
    5207                 :             : 
    5208                 :             : /* Return TRUE if REGNO has a reverse equivalence.  The equivalence is
    5209                 :             :    reverse only if we have one init insn with given REGNO as a
    5210                 :             :    source.  */
    5211                 :             : static bool
    5212                 :      743321 : reverse_equiv_p (int regno)
    5213                 :             : {
    5214                 :      743321 :   rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
    5215                 :      743321 :   rtx set;
    5216                 :             : 
    5217                 :      743321 :   if (insns == NULL)
    5218                 :             :     return false;
    5219                 :      678730 :   if (! INSN_P (insns->insn ())
    5220                 :     1357460 :       || insns->next () != NULL)
    5221                 :             :     return false;
    5222                 :      678730 :   if ((set = single_set (insns->insn ())) == NULL_RTX)
    5223                 :             :     return false;
    5224                 :      678730 :   return REG_P (SET_SRC (set)) && (int) REGNO (SET_SRC (set)) == regno;
    5225                 :             : }
    5226                 :             : 
    5227                 :             : /* Return TRUE if REGNO was reloaded in an equivalence init insn.  We
    5228                 :             :    call this function only for non-reverse equivalence.  */
    5229                 :             : static bool
    5230                 :      736877 : contains_reloaded_insn_p (int regno)
    5231                 :             : {
    5232                 :      736877 :   rtx set;
    5233                 :      736877 :   rtx_insn_list *list = ira_reg_equiv[regno].init_insns;
    5234                 :             : 
    5235                 :     1409163 :   for (; list != NULL; list = list->next ())
    5236                 :      672286 :     if ((set = single_set (list->insn ())) == NULL_RTX
    5237                 :      672286 :         || ! REG_P (SET_DEST (set))
    5238                 :     1344572 :         || (int) REGNO (SET_DEST (set)) != regno)
    5239                 :             :       return true;
    5240                 :             :   return false;
    5241                 :             : }
    5242                 :             : 
    5243                 :             : /* Try combine secondary memory reload insn FROM for insn TO into TO insn.
    5244                 :             :    FROM should be a load insn (usually a secondary memory reload insn).  Return
    5245                 :             :    TRUE in case of success.  */
    5246                 :             : static bool
    5247                 :     7330381 : combine_reload_insn (rtx_insn *from, rtx_insn *to)
    5248                 :             : {
    5249                 :     7330381 :   bool ok_p;
    5250                 :     7330381 :   rtx_insn *saved_insn;
    5251                 :     7330381 :   rtx set, from_reg, to_reg, op;
    5252                 :     7330381 :   enum reg_class to_class, from_class;
    5253                 :     7330381 :   int n, nop;
    5254                 :     7330381 :   signed char changed_nops[MAX_RECOG_OPERANDS + 1];
    5255                 :             : 
    5256                 :             :   /* Check conditions for second memory reload and original insn:  */
    5257                 :     7330381 :   if ((targetm.secondary_memory_needed
    5258                 :             :        == hook_bool_mode_reg_class_t_reg_class_t_false)
    5259                 :     7330381 :       || NEXT_INSN (from) != to
    5260                 :     4358530 :       || !NONDEBUG_INSN_P (to)
    5261                 :    11688911 :       || CALL_P (to))
    5262                 :             :     return false;
    5263                 :             : 
    5264                 :     4353009 :   lra_insn_recog_data_t id = lra_get_insn_recog_data (to);
    5265                 :     4353009 :   struct lra_static_insn_data *static_id = id->insn_static_data;
    5266                 :             : 
    5267                 :     4353009 :   if (id->used_insn_alternative == LRA_UNKNOWN_ALT
    5268                 :     4353009 :       || (set = single_set (from)) == NULL_RTX)
    5269                 :       32676 :     return false;
    5270                 :     4320333 :   from_reg = SET_DEST (set);
    5271                 :     4320333 :   to_reg = SET_SRC (set);
    5272                 :             :   /* Ignore optional reloads: */
    5273                 :     4236769 :   if (! REG_P (from_reg) || ! REG_P (to_reg)
    5274                 :     7180013 :       || bitmap_bit_p (&lra_optional_reload_pseudos, REGNO (from_reg)))
    5275                 :     2029796 :     return false;
    5276                 :     2290537 :   to_class = lra_get_allocno_class (REGNO (to_reg));
    5277                 :     2290537 :   from_class = lra_get_allocno_class (REGNO (from_reg));
    5278                 :             :   /* Check that reload insn is a load:  */
    5279                 :     2290537 :   if (to_class != NO_REGS || from_class == NO_REGS)
    5280                 :             :     return false;
    5281                 :       45425 :   for (n = nop = 0; nop < static_id->n_operands; nop++)
    5282                 :             :     {
    5283                 :       32599 :       if (static_id->operand[nop].type != OP_IN)
    5284                 :       11829 :         continue;
    5285                 :       20770 :       op = *id->operand_loc[nop];
    5286                 :       20770 :       if (!REG_P (op) || REGNO (op) != REGNO (from_reg))
    5287                 :        8120 :         continue;
    5288                 :       12650 :       *id->operand_loc[nop] = to_reg;
    5289                 :       12650 :       changed_nops[n++] = nop;
    5290                 :             :     }
    5291                 :       12826 :   changed_nops[n] = -1;
    5292                 :       12826 :   lra_update_dups (id, changed_nops);
    5293                 :       12826 :   lra_update_insn_regno_info (to);
    5294                 :       12826 :   ok_p = recog_memoized (to) >= 0;
    5295                 :       12826 :   if (ok_p)
    5296                 :             :     {
    5297                 :             :       /* Check that combined insn does not need any reloads: */
    5298                 :       12797 :       saved_insn = curr_insn;
    5299                 :       12797 :       curr_insn = to;
    5300                 :       12797 :       curr_id = lra_get_insn_recog_data (curr_insn);
    5301                 :       12797 :       curr_static_id = curr_id->insn_static_data;
    5302                 :       12797 :       for (bool swapped_p = false;;)
    5303                 :             :         {
    5304                 :       14940 :           ok_p = !curr_insn_transform (true);
    5305                 :       14940 :           if (ok_p || curr_static_id->commutative < 0)
    5306                 :             :             break;
    5307                 :        4286 :           swap_operands (curr_static_id->commutative);
    5308                 :        4286 :           if (lra_dump_file != NULL)
    5309                 :             :             {
    5310                 :           0 :               fprintf (lra_dump_file,
    5311                 :             :                        "    Swapping %scombined insn operands:\n",
    5312                 :             :                        swapped_p ? "back " : "");
    5313                 :           0 :               dump_insn_slim (lra_dump_file, to);
    5314                 :             :             }
    5315                 :        4286 :           if (swapped_p)
    5316                 :             :             break;
    5317                 :             :           swapped_p = true;
    5318                 :             :         }
    5319                 :       12797 :       curr_insn = saved_insn;
    5320                 :       12797 :       curr_id = lra_get_insn_recog_data (curr_insn);
    5321                 :       12797 :       curr_static_id = curr_id->insn_static_data;
    5322                 :             :     }
    5323                 :       12826 :   if (ok_p)
    5324                 :             :     {
    5325                 :        3435 :       id->used_insn_alternative = -1;
    5326                 :        3435 :       lra_push_insn_and_update_insn_regno_info (to);
    5327                 :        3435 :       if (lra_dump_file != NULL)
    5328                 :             :         {
    5329                 :           0 :           fprintf (lra_dump_file, "    Use combined insn:\n");
    5330                 :           0 :           dump_insn_slim (lra_dump_file, to);
    5331                 :             :         }
    5332                 :        3435 :       return true;
    5333                 :             :     }
    5334                 :        9391 :   if (lra_dump_file != NULL)
    5335                 :             :     {
    5336                 :           0 :       fprintf (lra_dump_file, "    Failed combined insn:\n");
    5337                 :           0 :       dump_insn_slim (lra_dump_file, to);
    5338                 :             :     }
    5339                 :       19054 :   for (int i = 0; i < n; i++)
    5340                 :             :     {
    5341                 :        9663 :       nop = changed_nops[i];
    5342                 :        9663 :       *id->operand_loc[nop] = from_reg;
    5343                 :             :     }
    5344                 :        9391 :   lra_update_dups (id, changed_nops);
    5345                 :        9391 :   lra_update_insn_regno_info (to);
    5346                 :        9391 :   if (lra_dump_file != NULL)
    5347                 :             :     {
    5348                 :           0 :       fprintf (lra_dump_file, "    Restoring insn after failed combining:\n");
    5349                 :           0 :       dump_insn_slim (lra_dump_file, to);
    5350                 :             :     }
    5351                 :             :   return false;
    5352                 :             : }
    5353                 :             : 
    5354                 :             : /* Entry function of LRA constraint pass.  Return true if the
    5355                 :             :    constraint pass did change the code.  */
    5356                 :             : bool
    5357                 :     3230270 : lra_constraints (bool first_p)
    5358                 :             : {
    5359                 :     3230270 :   bool changed_p;
    5360                 :     3230270 :   int i, hard_regno, new_insns_num;
    5361                 :     3230270 :   unsigned int min_len, new_min_len, uid;
    5362                 :     3230270 :   rtx set, x, reg, nosubreg_dest;
    5363                 :     3230270 :   rtx_insn *original_insn;
    5364                 :     3230270 :   basic_block last_bb;
    5365                 :     3230270 :   bitmap_iterator bi;
    5366                 :             : 
    5367                 :     3230270 :   lra_constraint_iter++;
    5368                 :     3230270 :   if (lra_dump_file != NULL)
    5369                 :         194 :     fprintf (lra_dump_file, "\n********** Local #%d: **********\n\n",
    5370                 :             :              lra_constraint_iter);
    5371                 :     3230270 :   changed_p = false;
    5372                 :     3230270 :   if (pic_offset_table_rtx
    5373                 :     3230270 :       && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
    5374                 :      102978 :     check_and_force_assignment_correctness_p = true;
    5375                 :     3127292 :   else if (first_p)
    5376                 :             :     /* On the first iteration we should check IRA assignment
    5377                 :             :        correctness.  In rare cases, the assignments can be wrong as
    5378                 :             :        early clobbers operands are ignored in IRA or usages of
    5379                 :             :        paradoxical sub-registers are not taken into account by
    5380                 :             :        IRA.  */
    5381                 :     1441442 :     check_and_force_assignment_correctness_p = true;
    5382                 :     3230270 :   new_insn_uid_start = get_max_uid ();
    5383                 :     3230270 :   new_regno_start = first_p ? lra_constraint_new_regno_start : max_reg_num ();
    5384                 :             :   /* Mark used hard regs for target stack size calulations.  */
    5385                 :   206695162 :   for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
    5386                 :   203464892 :     if (lra_reg_info[i].nrefs != 0
    5387                 :   300654728 :         && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
    5388                 :             :       {
    5389                 :    93321181 :         int j, nregs;
    5390                 :             : 
    5391                 :    93321181 :         nregs = hard_regno_nregs (hard_regno, lra_reg_info[i].biggest_mode);
    5392                 :   189734592 :         for (j = 0; j < nregs; j++)
    5393                 :    96413411 :           df_set_regs_ever_live (hard_regno + j, true);
    5394                 :             :       }
    5395                 :             :   /* Do elimination before the equivalence processing as we can spill
    5396                 :             :      some pseudos during elimination.  */
    5397                 :     3230270 :   lra_eliminate (false, first_p);
    5398                 :     3230270 :   auto_bitmap equiv_insn_bitmap (&reg_obstack);
    5399                 :   206695162 :   for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
    5400                 :   203464892 :     if (lra_reg_info[i].nrefs != 0)
    5401                 :             :       {
    5402                 :    97189836 :         ira_reg_equiv[i].profitable_p = true;
    5403                 :    97189836 :         reg = regno_reg_rtx[i];
    5404                 :    97189836 :         if (lra_get_regno_hard_regno (i) < 0 && (x = get_equiv (reg)) != reg)
    5405                 :             :           {
    5406                 :      753918 :             bool pseudo_p = contains_reg_p (x, false, false);
    5407                 :             : 
    5408                 :             :             /* After RTL transformation, we cannot guarantee that
    5409                 :             :                pseudo in the substitution was not reloaded which might
    5410                 :             :                make equivalence invalid.  For example, in reverse
    5411                 :             :                equiv of p0
    5412                 :             : 
    5413                 :             :                p0 <- ...
    5414                 :             :                ...
    5415                 :             :                equiv_mem <- p0
    5416                 :             : 
    5417                 :             :                the memory address register was reloaded before the 2nd
    5418                 :             :                insn.  */
    5419                 :      753918 :             if ((! first_p && pseudo_p)
    5420                 :             :                 /* We don't use DF for compilation speed sake.  So it
    5421                 :             :                    is problematic to update live info when we use an
    5422                 :             :                    equivalence containing pseudos in more than one
    5423                 :             :                    BB.  */
    5424                 :      748070 :                 || (pseudo_p && multi_block_pseudo_p (i))
    5425                 :             :                 /* If an init insn was deleted for some reason, cancel
    5426                 :             :                    the equiv.  We could update the equiv insns after
    5427                 :             :                    transformations including an equiv insn deletion
    5428                 :             :                    but it is not worthy as such cases are extremely
    5429                 :             :                    rare.  */
    5430                 :      743321 :                 || contains_deleted_insn_p (ira_reg_equiv[i].init_insns)
    5431                 :             :                 /* If it is not a reverse equivalence, we check that a
    5432                 :             :                    pseudo in rhs of the init insn is not dying in the
    5433                 :             :                    insn.  Otherwise, the live info at the beginning of
    5434                 :             :                    the corresponding BB might be wrong after we
    5435                 :             :                    removed the insn.  When the equiv can be a
    5436                 :             :                    constant, the right hand side of the init insn can
    5437                 :             :                    be a pseudo.  */
    5438                 :      743321 :                 || (! reverse_equiv_p (i)
    5439                 :      741925 :                     && (init_insn_rhs_dead_pseudo_p (i)
    5440                 :             :                         /* If we reloaded the pseudo in an equivalence
    5441                 :             :                            init insn, we cannot remove the equiv init
    5442                 :             :                            insns and the init insns might write into
    5443                 :             :                            const memory in this case.  */
    5444                 :      736877 :                         || contains_reloaded_insn_p (i)))
    5445                 :             :                 /* Prevent access beyond equivalent memory for
    5446                 :             :                    paradoxical subregs.  */
    5447                 :      738273 :                 || (MEM_P (x)
    5448                 :     1196616 :                     && maybe_gt (GET_MODE_SIZE (lra_reg_info[i].biggest_mode),
    5449                 :             :                                  GET_MODE_SIZE (GET_MODE (x))))
    5450                 :     1491481 :                 || (pic_offset_table_rtx
    5451                 :       50780 :                     && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i), x)
    5452                 :        7438 :                          && (targetm.preferred_reload_class
    5453                 :        3719 :                              (x, lra_get_allocno_class (i)) == NO_REGS))
    5454                 :       49168 :                         || contains_symbol_ref_p (x))))
    5455                 :       18797 :               ira_reg_equiv[i].defined_p
    5456                 :       18797 :                 = ira_reg_equiv[i].caller_save_p = false;
    5457                 :      753918 :             if (contains_reg_p (x, false, true))
    5458                 :        9078 :               ira_reg_equiv[i].profitable_p = false;
    5459                 :      753918 :             if (get_equiv (reg) != reg)
    5460                 :      730419 :               bitmap_ior_into (equiv_insn_bitmap, &lra_reg_info[i].insn_bitmap);
    5461                 :             :           }
    5462                 :             :       }
    5463                 :   206695162 :   for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
    5464                 :   203464892 :     update_equiv (i);
    5465                 :             :   /* We should add all insns containing pseudos which should be
    5466                 :             :      substituted by their equivalences.  */
    5467                 :     5638330 :   EXECUTE_IF_SET_IN_BITMAP (equiv_insn_bitmap, 0, uid, bi)
    5468                 :     2408060 :     lra_push_insn_by_uid (uid);
    5469                 :     3230270 :   min_len = lra_insn_stack_length ();
    5470                 :     3230270 :   new_insns_num = 0;
    5471                 :     3230270 :   last_bb = NULL;
    5472                 :     3230270 :   changed_p = false;
    5473                 :     3230270 :   original_insn = NULL;
    5474                 :   167902114 :   while ((new_min_len = lra_insn_stack_length ()) != 0)
    5475                 :             :     {
    5476                 :   161441574 :       curr_insn = lra_pop_insn ();
    5477                 :   161441574 :       --new_min_len;
    5478                 :   161441574 :       curr_bb = BLOCK_FOR_INSN (curr_insn);
    5479                 :   161441574 :       if (curr_bb != last_bb)
    5480                 :             :         {
    5481                 :    20858276 :           last_bb = curr_bb;
    5482                 :    20858276 :           bb_reload_num = lra_curr_reload_num;
    5483                 :             :         }
    5484                 :   161441574 :       if (min_len > new_min_len)
    5485                 :             :         {
    5486                 :             :           min_len = new_min_len;
    5487                 :             :           new_insns_num = 0;
    5488                 :             :           original_insn = curr_insn;
    5489                 :             :         }
    5490                 :     7330381 :       else if (combine_reload_insn (curr_insn, original_insn))
    5491                 :             :         {
    5492                 :        3435 :           continue;
    5493                 :             :         }
    5494                 :     7326946 :       if (new_insns_num > MAX_RELOAD_INSNS_NUMBER)
    5495                 :           0 :         internal_error
    5496                 :           0 :           ("maximum number of generated reload insns per insn achieved (%d)",
    5497                 :             :            MAX_RELOAD_INSNS_NUMBER);
    5498                 :   161438139 :       new_insns_num++;
    5499                 :   161438139 :       if (DEBUG_INSN_P (curr_insn))
    5500                 :             :         {
    5501                 :             :           /* We need to check equivalence in debug insn and change
    5502                 :             :              pseudo to the equivalent value if necessary.  */
    5503                 :    52866069 :           curr_id = lra_get_insn_recog_data (curr_insn);
    5504                 :    52866069 :           if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn)))
    5505                 :             :             {
    5506                 :       30319 :               rtx old = *curr_id->operand_loc[0];
    5507                 :       30319 :               *curr_id->operand_loc[0]
    5508                 :       30319 :                 = simplify_replace_fn_rtx (old, NULL_RTX,
    5509                 :             :                                            loc_equivalence_callback, curr_insn);
    5510                 :       30319 :               if (old != *curr_id->operand_loc[0])
    5511                 :             :                 {
    5512                 :             :                   /* If we substitute pseudo by shared equivalence, we can fail
    5513                 :             :                      to update LRA reg info and this can result in many
    5514                 :             :                      unexpected consequences.  So keep rtl unshared:  */
    5515                 :       30319 :                   *curr_id->operand_loc[0]
    5516                 :       30319 :                     = copy_rtx (*curr_id->operand_loc[0]);
    5517                 :       30319 :                   lra_update_insn_regno_info (curr_insn);
    5518                 :       30319 :                   changed_p = true;
    5519                 :             :                 }
    5520                 :             :             }
    5521                 :             :         }
    5522                 :   108572070 :       else if (INSN_P (curr_insn))
    5523                 :             :         {
    5524                 :   107488841 :           if ((set = single_set (curr_insn)) != NULL_RTX)
    5525                 :             :             {
    5526                 :   102064798 :               nosubreg_dest = SET_DEST (set);
    5527                 :             :               /* The equivalence pseudo could be set up as SUBREG in a
    5528                 :             :                  case when it is a call restore insn in a mode
    5529                 :             :                  different from the pseudo mode.  */
    5530                 :   102064798 :               if (GET_CODE (nosubreg_dest) == SUBREG)
    5531                 :     1159476 :                 nosubreg_dest = SUBREG_REG (nosubreg_dest);
    5532                 :   102781986 :               if ((REG_P (nosubreg_dest)
    5533                 :    75519241 :                    && (x = get_equiv (nosubreg_dest)) != nosubreg_dest
    5534                 :             :                    /* Remove insns which set up a pseudo whose value
    5535                 :             :                       cannot be changed.  Such insns might be not in
    5536                 :             :                       init_insns because we don't update equiv data
    5537                 :             :                       during insn transformations.
    5538                 :             : 
    5539                 :             :                       As an example, let suppose that a pseudo got
    5540                 :             :                       hard register and on the 1st pass was not
    5541                 :             :                       changed to equivalent constant.  We generate an
    5542                 :             :                       additional insn setting up the pseudo because of
    5543                 :             :                       secondary memory movement.  Then the pseudo is
    5544                 :             :                       spilled and we use the equiv constant.  In this
    5545                 :             :                       case we should remove the additional insn and
    5546                 :             :                       this insn is not init_insns list.  */
    5547                 :      734788 :                    && (! MEM_P (x) || MEM_READONLY_P (x)
    5548                 :             :                        /* Check that this is actually an insn setting
    5549                 :             :                           up the equivalence.  */
    5550                 :      343795 :                        || in_list_p (curr_insn,
    5551                 :      343795 :                                      ira_reg_equiv
    5552                 :      343795 :                                      [REGNO (nosubreg_dest)].init_insns)))
    5553                 :   176868169 :                   || (((x = get_equiv (SET_SRC (set))) != SET_SRC (set))
    5554                 :     2054748 :                       && in_list_p (curr_insn,
    5555                 :     1027374 :                                     ira_reg_equiv
    5556                 :     1027374 :                                     [REGNO (SET_SRC (set))].init_insns)
    5557                 :             :                       /* This is a reverse equivalence to memory (see ira.cc)
    5558                 :             :                          in store insn.  We can reload all the destination and
    5559                 :             :                          have an output reload which is a store to memory.  If
    5560                 :             :                          we just remove the insn, we will have the output
    5561                 :             :                          reload storing an undefined value to the memory.
    5562                 :             :                          Check that we did not reload the memory to prevent a
    5563                 :             :                          wrong code generation.  We could implement using the
    5564                 :             :                          equivalence still in such case but doing this is not
    5565                 :             :                          worth the efforts as such case is very rare.  */
    5566                 :        1318 :                       && MEM_P (nosubreg_dest)))
    5567                 :             :                 {
    5568                 :             :                   /* This is equiv init insn of pseudo which did not get a
    5569                 :             :                      hard register -- remove the insn.  */
    5570                 :      717188 :                   if (lra_dump_file != NULL)
    5571                 :             :                     {
    5572                 :           9 :                       fprintf (lra_dump_file,
    5573                 :             :                                "      Removing equiv init insn %i (freq=%d)\n",
    5574                 :           3 :                                INSN_UID (curr_insn),
    5575                 :           6 :                                REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn)));
    5576                 :           3 :                       dump_insn_slim (lra_dump_file, curr_insn);
    5577                 :             :                     }
    5578                 :      717188 :                   if (contains_reg_p (x, true, false))
    5579                 :      148791 :                     check_and_force_assignment_correctness_p = true;
    5580                 :      717188 :                   lra_set_insn_deleted (curr_insn);
    5581                 :      717188 :                   continue;
    5582                 :             :                 }
    5583                 :             :             }
    5584                 :   106771653 :           curr_id = lra_get_insn_recog_data (curr_insn);
    5585                 :   106771653 :           curr_static_id = curr_id->insn_static_data;
    5586                 :   106771653 :           init_curr_insn_input_reloads ();
    5587                 :   106771653 :           init_curr_operand_mode ();
    5588                 :   106771653 :           if (curr_insn_transform (false))
    5589                 :             :             changed_p = true;
    5590                 :             :           /* Check non-transformed insns too for equiv change as USE
    5591                 :             :              or CLOBBER don't need reloads but can contain pseudos
    5592                 :             :              being changed on their equivalences.  */
    5593                 :   100651848 :           else if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn))
    5594                 :   100651848 :                    && loc_equivalence_change_p (&PATTERN (curr_insn)))
    5595                 :             :             {
    5596                 :           8 :               lra_update_insn_regno_info (curr_insn);
    5597                 :           8 :               changed_p = true;
    5598                 :             :             }
    5599                 :             :         }
    5600                 :             :     }
    5601                 :             : 
    5602                 :             :   /* If we used a new hard regno, changed_p should be true because the
    5603                 :             :      hard reg is assigned to a new pseudo.  */
    5604                 :     3230270 :   if (flag_checking && !changed_p)
    5605                 :             :     {
    5606                 :   132646306 :       for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
    5607                 :   130032004 :         if (lra_reg_info[i].nrefs != 0
    5608                 :   190327271 :             && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
    5609                 :             :           {
    5610                 :    58895472 :             int j, nregs = hard_regno_nregs (hard_regno,
    5611                 :    58895472 :                                              PSEUDO_REGNO_MODE (i));
    5612                 :             : 
    5613                 :   119833836 :             for (j = 0; j < nregs; j++)
    5614                 :    60938364 :               lra_assert (df_regs_ever_live_p (hard_regno + j));
    5615                 :             :           }
    5616                 :             :     }
    5617                 :     2614342 :   if (changed_p)
    5618                 :      615931 :     lra_dump_insns_if_possible ("changed func after local");
    5619                 :     3230270 :   return changed_p;
    5620                 :     3230270 : }
    5621                 :             : 
    5622                 :             : static void initiate_invariants (void);
    5623                 :             : static void finish_invariants (void);
    5624                 :             : 
    5625                 :             : /* Initiate the LRA constraint pass.  It is done once per
    5626                 :             :    function.  */
    5627                 :             : void
    5628                 :     1481332 : lra_constraints_init (void)
    5629                 :             : {
    5630                 :     1481332 :   initiate_invariants ();
    5631                 :     1481332 : }
    5632                 :             : 
    5633                 :             : /* Finalize the LRA constraint pass.  It is done once per
    5634                 :             :    function.  */
    5635                 :             : void
    5636                 :     1481332 : lra_constraints_finish (void)
    5637                 :             : {
    5638                 :     1481332 :   finish_invariants ();
    5639                 :     1481332 : }
    5640                 :             : 
    5641                 :             : 
    5642                 :             : 
    5643                 :             : /* Structure describes invariants for ineheritance.  */
    5644                 :             : struct lra_invariant
    5645                 :             : {
    5646                 :             :   /* The order number of the invariant.  */
    5647                 :             :   int num;
    5648                 :             :   /* The invariant RTX.  */
    5649                 :             :   rtx invariant_rtx;
    5650                 :             :   /* The origin insn of the invariant.  */
    5651                 :             :   rtx_insn *insn;
    5652                 :             : };
    5653                 :             : 
    5654                 :             : typedef lra_invariant invariant_t;
    5655                 :             : typedef invariant_t *invariant_ptr_t;
    5656                 :             : typedef const invariant_t *const_invariant_ptr_t;
    5657                 :             : 
    5658                 :             : /* Pointer to the inheritance invariants.  */
    5659                 :             : static vec<invariant_ptr_t> invariants;
    5660                 :             : 
    5661                 :             : /* Allocation pool for the invariants.  */
    5662                 :             : static object_allocator<lra_invariant> *invariants_pool;
    5663                 :             : 
    5664                 :             : /* Hash table for the invariants.  */
    5665                 :             : static htab_t invariant_table;
    5666                 :             : 
    5667                 :             : /* Hash function for INVARIANT.  */
    5668                 :             : static hashval_t
    5669                 :      181484 : invariant_hash (const void *invariant)
    5670                 :             : {
    5671                 :      181484 :   rtx inv = ((const_invariant_ptr_t) invariant)->invariant_rtx;
    5672                 :      181484 :   return lra_rtx_hash (inv);
    5673                 :             : }
    5674                 :             : 
    5675                 :             : /* Equal function for invariants INVARIANT1 and INVARIANT2.  */
    5676                 :             : static int
    5677                 :       56096 : invariant_eq_p (const void *invariant1, const void *invariant2)
    5678                 :             : {
    5679                 :       56096 :   rtx inv1 = ((const_invariant_ptr_t) invariant1)->invariant_rtx;
    5680                 :       56096 :   rtx inv2 = ((const_invariant_ptr_t) invariant2)->invariant_rtx;
    5681                 :             : 
    5682                 :       56096 :   return rtx_equal_p (inv1, inv2);
    5683                 :             : }
    5684                 :             : 
    5685                 :             : /* Insert INVARIANT_RTX into the table if it is not there yet.  Return
    5686                 :             :    invariant which is in the table.  */
    5687                 :             : static invariant_ptr_t
    5688                 :      181292 : insert_invariant (rtx invariant_rtx)
    5689                 :             : {
    5690                 :      181292 :   void **entry_ptr;
    5691                 :      181292 :   invariant_t invariant;
    5692                 :      181292 :   invariant_ptr_t invariant_ptr;
    5693                 :             : 
    5694                 :      181292 :   invariant.invariant_rtx = invariant_rtx;
    5695                 :      181292 :   entry_ptr = htab_find_slot (invariant_table, &invariant, INSERT);
    5696                 :      181292 :   if (*entry_ptr == NULL)
    5697                 :             :     {
    5698                 :      158976 :       invariant_ptr = invariants_pool->allocate ();
    5699                 :      158976 :       invariant_ptr->invariant_rtx = invariant_rtx;
    5700                 :      158976 :       invariant_ptr->insn = NULL;
    5701                 :      158976 :       invariants.safe_push (invariant_ptr);
    5702                 :      158976 :       *entry_ptr = (void *) invariant_ptr;
    5703                 :             :     }
    5704                 :      181292 :   return (invariant_ptr_t) *entry_ptr;
    5705                 :             : }
    5706                 :             : 
    5707                 :             : /* Initiate the invariant table.  */
    5708                 :             : static void
    5709                 :     1481332 : initiate_invariants (void)
    5710                 :             : {
    5711                 :     1481332 :   invariants.create (100);
    5712                 :     1481332 :   invariants_pool
    5713                 :     1481332 :     = new object_allocator<lra_invariant> ("Inheritance invariants");
    5714                 :     1481332 :   invariant_table = htab_create (100, invariant_hash, invariant_eq_p, NULL);
    5715                 :     1481332 : }
    5716                 :             : 
    5717                 :             : /* Finish the invariant table.  */
    5718                 :             : static void
    5719                 :     1481332 : finish_invariants (void)
    5720                 :             : {
    5721                 :     1481332 :   htab_delete (invariant_table);
    5722                 :     2962664 :   delete invariants_pool;
    5723                 :     1481332 :   invariants.release ();
    5724                 :     1481332 : }
    5725                 :             : 
    5726                 :             : /* Make the invariant table empty.  */
    5727                 :             : static void
    5728                 :    12922549 : clear_invariants (void)
    5729                 :             : {
    5730                 :    12922549 :   htab_empty (invariant_table);
    5731                 :    12922549 :   invariants_pool->release ();
    5732                 :    12922549 :   invariants.truncate (0);
    5733                 :    12922549 : }
    5734                 :             : 
    5735                 :             : 
    5736                 :             : 
    5737                 :             : /* This page contains code to do inheritance/split
    5738                 :             :    transformations.  */
    5739                 :             : 
    5740                 :             : /* Number of reloads passed so far in current EBB.  */
    5741                 :             : static int reloads_num;
    5742                 :             : 
    5743                 :             : /* Number of calls passed so far in current EBB.  */
    5744                 :             : static int calls_num;
    5745                 :             : 
    5746                 :             : /* Index ID is the CALLS_NUM associated the last call we saw with
    5747                 :             :    ABI identifier ID.  */
    5748                 :             : static int last_call_for_abi[NUM_ABI_IDS];
    5749                 :             : 
    5750                 :             : /* Which registers have been fully or partially clobbered by a call
    5751                 :             :    since they were last used.  */
    5752                 :             : static HARD_REG_SET full_and_partial_call_clobbers;
    5753                 :             : 
    5754                 :             : /* Current reload pseudo check for validity of elements in
    5755                 :             :    USAGE_INSNS.  */
    5756                 :             : static int curr_usage_insns_check;
    5757                 :             : 
    5758                 :             : /* Info about last usage of registers in EBB to do inheritance/split
    5759                 :             :    transformation.  Inheritance transformation is done from a spilled
    5760                 :             :    pseudo and split transformations from a hard register or a pseudo
    5761                 :             :    assigned to a hard register.  */
    5762                 :             : struct usage_insns
    5763                 :             : {
    5764                 :             :   /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
    5765                 :             :      value INSNS is valid.  The insns is chain of optional debug insns
    5766                 :             :      and a finishing non-debug insn using the corresponding reg.  The
    5767                 :             :      value is also used to mark the registers which are set up in the
    5768                 :             :      current insn.  The negated insn uid is used for this.  */
    5769                 :             :   int check;
    5770                 :             :   /* Value of global reloads_num at the last insn in INSNS.  */
    5771                 :             :   int reloads_num;
    5772                 :             :   /* Value of global reloads_nums at the last insn in INSNS.  */
    5773                 :             :   int calls_num;
    5774                 :             :   /* It can be true only for splitting.  And it means that the restore
    5775                 :             :      insn should be put after insn given by the following member.  */
    5776                 :             :   bool after_p;
    5777                 :             :   /* Next insns in the current EBB which use the original reg and the
    5778                 :             :      original reg value is not changed between the current insn and
    5779                 :             :      the next insns.  In order words, e.g. for inheritance, if we need
    5780                 :             :      to use the original reg value again in the next insns we can try
    5781                 :             :      to use the value in a hard register from a reload insn of the
    5782                 :             :      current insn.  */
    5783                 :             :   rtx insns;
    5784                 :             : };
    5785                 :             : 
    5786                 :             : /* Map: regno -> corresponding pseudo usage insns.  */
    5787                 :             : static struct usage_insns *usage_insns;
    5788                 :             : 
    5789                 :             : static void
    5790                 :   246708049 : setup_next_usage_insn (int regno, rtx insn, int reloads_num, bool after_p)
    5791                 :             : {
    5792                 :   246708049 :   usage_insns[regno].check = curr_usage_insns_check;
    5793                 :   246708049 :   usage_insns[regno].insns = insn;
    5794                 :   246708049 :   usage_insns[regno].reloads_num = reloads_num;
    5795                 :   246708049 :   usage_insns[regno].calls_num = calls_num;
    5796                 :   246708049 :   usage_insns[regno].after_p = after_p;
    5797                 :   246708049 :   if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0)
    5798                 :   111029607 :     remove_from_hard_reg_set (&full_and_partial_call_clobbers,
    5799                 :   111029607 :                               PSEUDO_REGNO_MODE (regno),
    5800                 :             :                               reg_renumber[regno]);
    5801                 :   246708049 : }
    5802                 :             : 
    5803                 :             : /* The function is used to form list REGNO usages which consists of
    5804                 :             :    optional debug insns finished by a non-debug insn using REGNO.
    5805                 :             :    RELOADS_NUM is current number of reload insns processed so far.  */
    5806                 :             : static void
    5807                 :   138920725 : add_next_usage_insn (int regno, rtx_insn *insn, int reloads_num)
    5808                 :             : {
    5809                 :   138920725 :   rtx next_usage_insns;
    5810                 :             : 
    5811                 :   138920725 :   if (usage_insns[regno].check == curr_usage_insns_check
    5812                 :    71520644 :       && (next_usage_insns = usage_insns[regno].insns) != NULL_RTX
    5813                 :   210441369 :       && DEBUG_INSN_P (insn))
    5814                 :             :     {
    5815                 :             :       /* Check that we did not add the debug insn yet.  */
    5816                 :    13806780 :       if (next_usage_insns != insn
    5817                 :    13806780 :           && (GET_CODE (next_usage_insns) != INSN_LIST
    5818                 :     5886263 :               || XEXP (next_usage_insns, 0) != insn))
    5819                 :    13806766 :         usage_insns[regno].insns = gen_rtx_INSN_LIST (VOIDmode, insn,
    5820                 :             :                                                       next_usage_insns);
    5821                 :             :     }
    5822                 :   125113945 :   else if (NONDEBUG_INSN_P (insn))
    5823                 :   124588160 :     setup_next_usage_insn (regno, insn, reloads_num, false);
    5824                 :             :   else
    5825                 :      525785 :     usage_insns[regno].check = 0;
    5826                 :   138920725 : }
    5827                 :             : 
    5828                 :             : /* Return first non-debug insn in list USAGE_INSNS.  */
    5829                 :             : static rtx_insn *
    5830                 :     1161530 : skip_usage_debug_insns (rtx usage_insns)
    5831                 :             : {
    5832                 :     1161530 :   rtx insn;
    5833                 :             : 
    5834                 :             :   /* Skip debug insns.  */
    5835                 :     1161530 :   for (insn = usage_insns;
    5836                 :     1429914 :        insn != NULL_RTX && GET_CODE (insn) == INSN_LIST;
    5837                 :      268384 :        insn = XEXP (insn, 1))
    5838                 :             :     ;
    5839                 :     1161530 :   return safe_as_a <rtx_insn *> (insn);
    5840                 :             : }
    5841                 :             : 
    5842                 :             : /* Return true if we need secondary memory moves for insn in
    5843                 :             :    USAGE_INSNS after inserting inherited pseudo of class INHER_CL
    5844                 :             :    into the insn.  */
    5845                 :             : static bool
    5846                 :     1161537 : check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED,
    5847                 :             :                                  rtx usage_insns ATTRIBUTE_UNUSED)
    5848                 :             : {
    5849                 :     1161537 :   rtx_insn *insn;
    5850                 :     1161537 :   rtx set, dest;
    5851                 :     1161537 :   enum reg_class cl;
    5852                 :             : 
    5853                 :     1161537 :   if (inher_cl == ALL_REGS
    5854                 :     1161537 :       || (insn = skip_usage_debug_insns (usage_insns)) == NULL_RTX)
    5855                 :             :     return false;
    5856                 :     1161530 :   lra_assert (INSN_P (insn));
    5857                 :     1161530 :   if ((set = single_set (insn)) == NULL_RTX || ! REG_P (SET_DEST (set)))
    5858                 :             :     return false;
    5859                 :     1124380 :   dest = SET_DEST (set);
    5860                 :     1124380 :   if (! REG_P (dest))
    5861                 :             :     return false;
    5862                 :     1124380 :   lra_assert (inher_cl != NO_REGS);
    5863                 :     1124380 :   cl = get_reg_class (REGNO (dest));
    5864                 :     1124380 :   return (cl != NO_REGS && cl != ALL_REGS
    5865                 :     1124380 :           && targetm.secondary_memory_needed (GET_MODE (dest), inher_cl, cl));
    5866                 :             : }
    5867                 :             : 
    5868                 :             : /* Registers involved in inheritance/split in the current EBB
    5869                 :             :    (inheritance/split pseudos and original registers).  */
    5870                 :             : static bitmap_head check_only_regs;
    5871                 :             : 
    5872                 :             : /* Reload pseudos cannot be involded in invariant inheritance in the
    5873                 :             :    current EBB.  */
    5874                 :             : static bitmap_head invalid_invariant_regs;
    5875                 :             : 
    5876                 :             : /* Do inheritance transformations for insn INSN, which defines (if
    5877                 :             :    DEF_P) or uses ORIGINAL_REGNO.  NEXT_USAGE_INSNS specifies which
    5878                 :             :    instruction in the EBB next uses ORIGINAL_REGNO; it has the same
    5879                 :             :    form as the "insns" field of usage_insns.  Return true if we
    5880                 :             :    succeed in such transformation.
    5881                 :             : 
    5882                 :             :    The transformations look like:
    5883                 :             : 
    5884                 :             :      p <- ...                  i <- ...
    5885                 :             :      ...                  p <- i    (new insn)
    5886                 :             :      ...             =>
    5887                 :             :      <- ... p ...      <- ... i ...
    5888                 :             :    or
    5889                 :             :      ...                  i <- p    (new insn)
    5890                 :             :      <- ... p ...      <- ... i ...
    5891                 :             :      ...             =>
    5892                 :             :      <- ... p ...      <- ... i ...
    5893                 :             :    where p is a spilled original pseudo and i is a new inheritance pseudo.
    5894                 :             : 
    5895                 :             : 
    5896                 :             :    The inheritance pseudo has the smallest class of two classes CL and
    5897                 :             :    class of ORIGINAL REGNO.  */
    5898                 :             : static bool
    5899                 :     1255387 : inherit_reload_reg (bool def_p, int original_regno,
    5900                 :             :                     enum reg_class cl, rtx_insn *insn, rtx next_usage_insns)
    5901                 :             : {
    5902                 :     1255387 :   if (optimize_function_for_size_p (cfun))
    5903                 :             :     return false;
    5904                 :             : 
    5905                 :     1224502 :   enum reg_class rclass = lra_get_allocno_class (original_regno);
    5906                 :     1224502 :   rtx original_reg = regno_reg_rtx[original_regno];
    5907                 :     1224502 :   rtx new_reg, usage_insn;
    5908                 :     1224502 :   rtx_insn *new_insns;
    5909                 :             : 
    5910                 :     1224502 :   lra_assert (! usage_insns[original_regno].after_p);
    5911                 :     1224502 :   if (lra_dump_file != NULL)
    5912                 :           2 :     fprintf (lra_dump_file,
    5913                 :             :              "    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    5914                 :     1224502 :   if (! ira_reg_classes_intersect_p[cl][rclass])
    5915                 :             :     {
    5916                 :       62965 :       if (lra_dump_file != NULL)
    5917                 :             :         {
    5918                 :           0 :           fprintf (lra_dump_file,
    5919                 :             :                    "    Rejecting inheritance for %d "
    5920                 :             :                    "because of disjoint classes %s and %s\n",
    5921                 :             :                    original_regno, reg_class_names[cl],
    5922                 :             :                    reg_class_names[rclass]);
    5923                 :           0 :           fprintf (lra_dump_file,
    5924                 :             :                    "    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
    5925                 :             :         }
    5926                 :       62965 :       return false;
    5927                 :             :     }
    5928                 :     1161537 :   if ((ira_class_subset_p[cl][rclass] && cl != rclass)
    5929                 :             :       /* We don't use a subset of two classes because it can be
    5930                 :             :          NO_REGS.  This transformation is still profitable in most
    5931                 :             :          cases even if the classes are not intersected as register
    5932                 :             :          move is probably cheaper than a memory load.  */
    5933                 :      433600 :       || ira_class_hard_regs_num[cl] < ira_class_hard_regs_num[rclass])
    5934                 :             :     {
    5935                 :      727937 :       if (lra_dump_file != NULL)
    5936                 :           2 :         fprintf (lra_dump_file, "    Use smallest class of %s and %s\n",
    5937                 :             :                  reg_class_names[cl], reg_class_names[rclass]);
    5938                 :             : 
    5939                 :             :       rclass = cl;
    5940                 :             :     }
    5941                 :     1161537 :   if (check_secondary_memory_needed_p (rclass, next_usage_insns))
    5942                 :             :     {
    5943                 :             :       /* Reject inheritance resulting in secondary memory moves.
    5944                 :             :          Otherwise, there is a danger in LRA cycling.  Also such
    5945                 :             :          transformation will be unprofitable.  */
    5946                 :       13307 :       if (lra_dump_file != NULL)
    5947                 :             :         {
    5948                 :           0 :           rtx_insn *insn = skip_usage_debug_insns (next_usage_insns);
    5949                 :           0 :           rtx set = single_set (insn);
    5950                 :             : 
    5951                 :           0 :           lra_assert (set != NULL_RTX);
    5952                 :             : 
    5953                 :           0 :           rtx dest = SET_DEST (set);
    5954                 :             : 
    5955                 :           0 :           lra_assert (REG_P (dest));
    5956                 :           0 :           fprintf (lra_dump_file,
    5957                 :             :                    "    Rejecting inheritance for insn %d(%s)<-%d(%s) "
    5958                 :             :                    "as secondary mem is needed\n",
    5959                 :           0 :                    REGNO (dest), reg_class_names[get_reg_class (REGNO (dest))],
    5960                 :           0 :                    original_regno, reg_class_names[rclass]);
    5961                 :           0 :           fprintf (lra_dump_file,
    5962                 :             :                    "    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
    5963                 :             :         }
    5964                 :       13307 :       return false;
    5965                 :             :     }
    5966                 :     1148230 :   if (ira_reg_class_min_nregs[rclass][GET_MODE (original_reg)]
    5967                 :     1148230 :       != ira_reg_class_max_nregs[rclass][GET_MODE (original_reg)])
    5968                 :             :     {
    5969                 :          29 :       if (lra_dump_file != NULL)
    5970                 :             :         {
    5971                 :           0 :           fprintf (lra_dump_file,
    5972                 :             :                    "    Rejecting inheritance for %d "
    5973                 :             :                    "because of requiring non-uniform class %s\n",
    5974                 :             :                    original_regno, reg_class_names[rclass]);
    5975                 :           0 :           fprintf (lra_dump_file,
    5976                 :             :                    "    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
    5977                 :             :         }
    5978                 :          29 :       return false;
    5979                 :             :     }
    5980                 :     1148201 :   new_reg = lra_create_new_reg (GET_MODE (original_reg), original_reg,
    5981                 :             :                                 rclass, NULL, "inheritance");
    5982                 :     1148201 :   start_sequence ();
    5983                 :     1148201 :   if (def_p)
    5984                 :      540662 :     lra_emit_move (original_reg, new_reg);
    5985                 :             :   else
    5986                 :      607539 :     lra_emit_move (new_reg, original_reg);
    5987                 :     1148201 :   new_insns = end_sequence ();
    5988                 :     1148201 :   if (NEXT_INSN (new_insns) != NULL_RTX)
    5989                 :             :     {
    5990                 :           0 :       if (lra_dump_file != NULL)
    5991                 :             :         {
    5992                 :           0 :           fprintf (lra_dump_file,
    5993                 :             :                    "    Rejecting inheritance %d->%d "
    5994                 :             :                    "as it results in 2 or more insns:\n",
    5995                 :             :                    original_regno, REGNO (new_reg));
    5996                 :           0 :           dump_rtl_slim (lra_dump_file, new_insns, NULL, -1, 0);
    5997                 :           0 :           fprintf (lra_dump_file,
    5998                 :             :                    "       >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
    5999                 :             :         }
    6000                 :           0 :       return false;
    6001                 :             :     }
    6002                 :     1148201 :   lra_substitute_pseudo_within_insn (insn, original_regno, new_reg, false);
    6003                 :     1148201 :   lra_update_insn_regno_info (insn);
    6004                 :     1148201 :   if (! def_p)
    6005                 :             :     /* We now have a new usage insn for original regno.  */
    6006                 :      607539 :     setup_next_usage_insn (original_regno, new_insns, reloads_num, false);
    6007                 :     1148201 :   if (lra_dump_file != NULL)
    6008                 :           2 :     fprintf (lra_dump_file, "    Original reg change %d->%d (bb%d):\n",
    6009                 :           2 :              original_regno, REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
    6010                 :     1148201 :   lra_reg_info[REGNO (new_reg)].restore_rtx = regno_reg_rtx[original_regno];
    6011                 :     1148201 :   bitmap_set_bit (&check_only_regs, REGNO (new_reg));
    6012                 :     1148201 :   bitmap_set_bit (&check_only_regs, original_regno);
    6013                 :     1148201 :   bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
    6014                 :     1148201 :   if (def_p)
    6015                 :      540662 :     lra_process_new_insns (insn, NULL, new_insns,
    6016                 :             :                            "Add original<-inheritance");
    6017                 :             :   else
    6018                 :      607539 :     lra_process_new_insns (insn, new_insns, NULL,
    6019                 :             :                            "Add inheritance<-original");
    6020                 :     2562529 :   while (next_usage_insns != NULL_RTX)
    6021                 :             :     {
    6022                 :     1414328 :       if (GET_CODE (next_usage_insns) != INSN_LIST)
    6023                 :             :         {
    6024                 :     1148201 :           usage_insn = next_usage_insns;
    6025                 :     1148201 :           lra_assert (NONDEBUG_INSN_P (usage_insn));
    6026                 :             :           next_usage_insns = NULL;
    6027                 :             :         }
    6028                 :             :       else
    6029                 :             :         {
    6030                 :      266127 :           usage_insn = XEXP (next_usage_insns, 0);
    6031                 :      266127 :           lra_assert (DEBUG_INSN_P (usage_insn));
    6032                 :      266127 :           next_usage_insns = XEXP (next_usage_insns, 1);
    6033                 :             :         }
    6034                 :     1414328 :       lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
    6035                 :     1414328 :                              DEBUG_INSN_P (usage_insn));
    6036                 :     1414328 :       lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
    6037                 :     1414328 :       if (lra_dump_file != NULL)
    6038                 :             :         {
    6039                 :           2 :           basic_block bb = BLOCK_FOR_INSN (usage_insn);
    6040                 :           2 :           fprintf (lra_dump_file,
    6041                 :             :                    "    Inheritance reuse change %d->%d (bb%d):\n",
    6042                 :             :                    original_regno, REGNO (new_reg),
    6043                 :             :                    bb ? bb->index : -1);
    6044                 :           2 :           dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
    6045                 :             :         }
    6046                 :             :     }
    6047                 :     1148201 :   if (lra_dump_file != NULL)
    6048                 :           2 :     fprintf (lra_dump_file,
    6049                 :             :              "       >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
    6050                 :             :   return true;
    6051                 :             : }
    6052                 :             : 
    6053                 :             : /* Return true if we need a caller save/restore for pseudo REGNO which
    6054                 :             :    was assigned to a hard register.  */
    6055                 :             : static inline bool
    6056                 :   113589436 : need_for_call_save_p (int regno)
    6057                 :             : {
    6058                 :   113589436 :   lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0);
    6059                 :   113589436 :   if (usage_insns[regno].calls_num < calls_num)
    6060                 :             :     {
    6061                 :             :       unsigned int abis = 0;
    6062                 :    82260315 :       for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
    6063                 :    73120280 :         if (last_call_for_abi[i] > usage_insns[regno].calls_num)
    6064                 :     9140035 :           abis |= 1 << i;
    6065                 :     9140035 :       gcc_assert (abis);
    6066                 :     9140035 :       if (call_clobbered_in_region_p (abis, full_and_partial_call_clobbers,
    6067                 :     9140035 :                                       PSEUDO_REGNO_MODE (regno),
    6068                 :             :                                       reg_renumber[regno]))
    6069                 :             :         return true;
    6070                 :             :     }
    6071                 :             :   return false;
    6072                 :             : }
    6073                 :             : 
    6074                 :             : /* Global registers occurring in the current EBB.  */
    6075                 :             : static bitmap_head ebb_global_regs;
    6076                 :             : 
    6077                 :             : /* Return true if we need a split for hard register REGNO or pseudo
    6078                 :             :    REGNO which was assigned to a hard register.
    6079                 :             :    POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
    6080                 :             :    used for reloads since the EBB end.  It is an approximation of the
    6081                 :             :    used hard registers in the split range.  The exact value would
    6082                 :             :    require expensive calculations.  If we were aggressive with
    6083                 :             :    splitting because of the approximation, the split pseudo will save
    6084                 :             :    the same hard register assignment and will be removed in the undo
    6085                 :             :    pass.  We still need the approximation because too aggressive
    6086                 :             :    splitting would result in too inaccurate cost calculation in the
    6087                 :             :    assignment pass because of too many generated moves which will be
    6088                 :             :    probably removed in the undo pass.  */
    6089                 :             : static inline bool
    6090                 :   241539932 : need_for_split_p (HARD_REG_SET potential_reload_hard_regs, int regno)
    6091                 :             : {
    6092                 :   241539932 :   int hard_regno = regno < FIRST_PSEUDO_REGISTER ? regno : reg_renumber[regno];
    6093                 :             : 
    6094                 :   241539932 :   lra_assert (hard_regno >= 0);
    6095                 :   241539932 :   return ((TEST_HARD_REG_BIT (potential_reload_hard_regs, hard_regno)
    6096                 :             :            /* Don't split eliminable hard registers, otherwise we can
    6097                 :             :               split hard registers like hard frame pointer, which
    6098                 :             :               lives on BB start/end according to DF-infrastructure,
    6099                 :             :               when there is a pseudo assigned to the register and
    6100                 :             :               living in the same BB.  */
    6101                 :      656453 :            && (regno >= FIRST_PSEUDO_REGISTER
    6102                 :       43028 :                || ! TEST_HARD_REG_BIT (eliminable_regset, hard_regno))
    6103                 :      627592 :            && ! TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno)
    6104                 :             :            /* Don't split call clobbered hard regs living through
    6105                 :             :               calls, otherwise we might have a check problem in the
    6106                 :             :               assign sub-pass as in the most cases (exception is a
    6107                 :             :               situation when check_and_force_assignment_correctness_p value is
    6108                 :             :               true) the assign pass assumes that all pseudos living
    6109                 :             :               through calls are assigned to call saved hard regs.  */
    6110                 :      614492 :            && (regno >= FIRST_PSEUDO_REGISTER
    6111                 :        1067 :                || !TEST_HARD_REG_BIT (full_and_partial_call_clobbers, regno))
    6112                 :             :            /* We need at least 2 reloads to make pseudo splitting
    6113                 :             :               profitable.  We should provide hard regno splitting in
    6114                 :             :               any case to solve 1st insn scheduling problem when
    6115                 :             :               moving hard register definition up might result in
    6116                 :             :               impossibility to find hard register for reload pseudo of
    6117                 :             :               small register class.  */
    6118                 :     1228908 :            && (usage_insns[regno].reloads_num
    6119                 :     1227879 :                + (regno < FIRST_PSEUDO_REGISTER ? 0 : 3) < reloads_num)
    6120                 :        2660 :            && (regno < FIRST_PSEUDO_REGISTER
    6121                 :             :                /* For short living pseudos, spilling + inheritance can
    6122                 :             :                   be considered a substitution for splitting.
    6123                 :             :                   Therefore we do not splitting for local pseudos.  It
    6124                 :             :                   decreases also aggressiveness of splitting.  The
    6125                 :             :                   minimal number of references is chosen taking into
    6126                 :             :                   account that for 2 references splitting has no sense
    6127                 :             :                   as we can just spill the pseudo.  */
    6128                 :             :                || (regno >= FIRST_PSEUDO_REGISTER
    6129                 :        2609 :                    && lra_reg_info[regno].nrefs > 3
    6130                 :        2256 :                    && bitmap_bit_p (&ebb_global_regs, regno))))
    6131                 :   242195144 :           || (regno >= FIRST_PSEUDO_REGISTER && need_for_call_save_p (regno)));
    6132                 :             : }
    6133                 :             : 
    6134                 :             : /* Return class for the split pseudo created from original pseudo with
    6135                 :             :    ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO.  We
    6136                 :             :    choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
    6137                 :             :    results in no secondary memory movements.  */
    6138                 :             : static enum reg_class
    6139                 :        1400 : choose_split_class (enum reg_class allocno_class,
    6140                 :             :                     int hard_regno ATTRIBUTE_UNUSED,
    6141                 :             :                     machine_mode mode ATTRIBUTE_UNUSED)
    6142                 :             : {
    6143                 :        1400 :   int i;
    6144                 :        1400 :   enum reg_class cl, best_cl = NO_REGS;
    6145                 :        1400 :   enum reg_class hard_reg_class ATTRIBUTE_UNUSED
    6146                 :             :     = REGNO_REG_CLASS (hard_regno);
    6147                 :             : 
    6148                 :        1400 :   if (! targetm.secondary_memory_needed (mode, allocno_class, allocno_class)
    6149                 :        1400 :       && TEST_HARD_REG_BIT (reg_class_contents[allocno_class], hard_regno))
    6150                 :             :     return allocno_class;
    6151                 :           0 :   for (i = 0;
    6152                 :           0 :        (cl = reg_class_subclasses[allocno_class][i]) != LIM_REG_CLASSES;
    6153                 :             :        i++)
    6154                 :           0 :     if (! targetm.secondary_memory_needed (mode, cl, hard_reg_class)
    6155                 :           0 :         && ! targetm.secondary_memory_needed (mode, hard_reg_class, cl)
    6156                 :           0 :         && TEST_HARD_REG_BIT (reg_class_contents[cl], hard_regno)
    6157                 :           0 :         && (best_cl == NO_REGS
    6158                 :           0 :             || ira_class_hard_regs_num[best_cl] < ira_class_hard_regs_num[cl]))
    6159                 :             :       best_cl = cl;
    6160                 :             :   return best_cl;
    6161                 :             : }
    6162                 :             : 
    6163                 :             : /* Copy any equivalence information from ORIGINAL_REGNO to NEW_REGNO.  It only
    6164                 :             :    makes sense to call this function if NEW_REGNO is always equal to
    6165                 :             :    ORIGINAL_REGNO.  Set up defined_p flag when caller_save_p flag is set up and
    6166                 :             :    CALL_SAVE_P is true.  */
    6167                 :             : 
    6168                 :             : static void
    6169                 :      603618 : lra_copy_reg_equiv (unsigned int new_regno, unsigned int original_regno,
    6170                 :             :                     bool call_save_p)
    6171                 :             : {
    6172                 :      603618 :   if (!ira_reg_equiv[original_regno].defined_p
    6173                 :      540187 :       && !(call_save_p && ira_reg_equiv[original_regno].caller_save_p))
    6174                 :             :     return;
    6175                 :             : 
    6176                 :       63600 :   ira_expand_reg_equiv ();
    6177                 :       63600 :   ira_reg_equiv[new_regno].defined_p = true;
    6178                 :       63600 :   if (ira_reg_equiv[original_regno].memory)
    6179                 :       29124 :     ira_reg_equiv[new_regno].memory
    6180                 :       29124 :       = copy_rtx (ira_reg_equiv[original_regno].memory);
    6181                 :       63600 :   if (ira_reg_equiv[original_regno].constant)
    6182                 :       27101 :     ira_reg_equiv[new_regno].constant
    6183                 :       27101 :       = copy_rtx (ira_reg_equiv[original_regno].constant);
    6184                 :       63600 :   if (ira_reg_equiv[original_regno].invariant)
    6185                 :        7375 :     ira_reg_equiv[new_regno].invariant
    6186                 :        7375 :       = copy_rtx (ira_reg_equiv[original_regno].invariant);
    6187                 :             : }
    6188                 :             : 
    6189                 :             : /* Do split transformations for insn INSN, which defines or uses
    6190                 :             :    ORIGINAL_REGNO.  NEXT_USAGE_INSNS specifies which instruction in
    6191                 :             :    the EBB next uses ORIGINAL_REGNO; it has the same form as the
    6192                 :             :    "insns" field of usage_insns.  If TO is not NULL, we don't use
    6193                 :             :    usage_insns, we put restore insns after TO insn.  It is a case when
    6194                 :             :    we call it from lra_split_hard_reg_for, outside the inheritance
    6195                 :             :    pass.
    6196                 :             : 
    6197                 :             :    The transformations look like:
    6198                 :             : 
    6199                 :             :      p <- ...                  p <- ...
    6200                 :             :      ...                  s <- p    (new insn -- save)
    6201                 :             :      ...             =>
    6202                 :             :      ...                  p <- s    (new insn -- restore)
    6203                 :             :      <- ... p ...      <- ... p ...
    6204                 :             :    or
    6205                 :             :      <- ... p ...      <- ... p ...
    6206                 :             :      ...                  s <- p    (new insn -- save)
    6207                 :             :      ...             =>
    6208                 :             :      ...                  p <- s    (new insn -- restore)
    6209                 :             :      <- ... p ...      <- ... p ...
    6210                 :             : 
    6211                 :             :    where p is an original pseudo got a hard register or a hard
    6212                 :             :    register and s is a new split pseudo.  The save is put before INSN
    6213                 :             :    if BEFORE_P is true.  Return true if we succeed in such
    6214                 :             :    transformation.  */
    6215                 :             : static bool
    6216                 :      605858 : split_reg (bool before_p, int original_regno, rtx_insn *insn,
    6217                 :             :            rtx next_usage_insns, rtx_insn *to)
    6218                 :             : {
    6219                 :      605858 :   enum reg_class rclass;
    6220                 :      605858 :   rtx original_reg;
    6221                 :      605858 :   int hard_regno, nregs;
    6222                 :      605858 :   rtx new_reg, usage_insn;
    6223                 :      605858 :   rtx_insn *restore, *save;
    6224                 :      605858 :   bool after_p;
    6225                 :      605858 :   bool call_save_p;
    6226                 :      605858 :   machine_mode mode;
    6227                 :             : 
    6228                 :      605858 :   if (original_regno < FIRST_PSEUDO_REGISTER)
    6229                 :             :     {
    6230                 :         210 :       rclass = ira_allocno_class_translate[REGNO_REG_CLASS (original_regno)];
    6231                 :         210 :       hard_regno = original_regno;
    6232                 :         210 :       call_save_p = false;
    6233                 :         210 :       nregs = 1;
    6234                 :         210 :       mode = lra_reg_info[hard_regno].biggest_mode;
    6235                 :         210 :       machine_mode reg_rtx_mode = GET_MODE (regno_reg_rtx[hard_regno]);
    6236                 :             :       /* A reg can have a biggest_mode of VOIDmode if it was only ever seen as
    6237                 :             :          part of a multi-word register.  In that case, just use the reg_rtx
    6238                 :             :          mode.  Do the same also if the biggest mode was larger than a register
    6239                 :             :          or we can not compare the modes.  Otherwise, limit the size to that of
    6240                 :             :          the biggest access in the function or to the natural mode at least.  */
    6241                 :         210 :       if (mode == VOIDmode
    6242                 :         210 :           || !ordered_p (GET_MODE_PRECISION (mode),
    6243                 :         210 :                          GET_MODE_PRECISION (reg_rtx_mode))
    6244                 :         210 :           || paradoxical_subreg_p (mode, reg_rtx_mode)
    6245                 :         419 :           || maybe_gt (GET_MODE_PRECISION (reg_rtx_mode), GET_MODE_PRECISION (mode)))
    6246                 :             :         {
    6247                 :      605858 :           original_reg = regno_reg_rtx[hard_regno];
    6248                 :      605858 :           mode = reg_rtx_mode;
    6249                 :             :         }
    6250                 :             :       else
    6251                 :         193 :         original_reg = gen_rtx_REG (mode, hard_regno);
    6252                 :             :     }
    6253                 :             :   else
    6254                 :             :     {
    6255                 :      605648 :       mode = PSEUDO_REGNO_MODE (original_regno);
    6256                 :      605648 :       hard_regno = reg_renumber[original_regno];
    6257                 :      605648 :       nregs = hard_regno_nregs (hard_regno, mode);
    6258                 :      605648 :       rclass = lra_get_allocno_class (original_regno);
    6259                 :      605648 :       original_reg = regno_reg_rtx[original_regno];
    6260                 :      605648 :       call_save_p = need_for_call_save_p (original_regno);
    6261                 :             :     }
    6262                 :      605858 :   lra_assert (hard_regno >= 0);
    6263                 :      605858 :   if (lra_dump_file != NULL)
    6264                 :           0 :     fprintf (lra_dump_file,
    6265                 :             :              "       ((((((((((((((((((((((((((((((((((((((((((((((((\n");
    6266                 :             : 
    6267                 :      605858 :   if (call_save_p)
    6268                 :             :     {
    6269                 :      604458 :       mode = HARD_REGNO_CALLER_SAVE_MODE (hard_regno,
    6270                 :             :                                           hard_regno_nregs (hard_regno, mode),
    6271                 :             :                                           mode);
    6272                 :      604458 :       new_reg = lra_create_new_reg (mode, NULL_RTX, NO_REGS, NULL, "save");
    6273                 :             :     }
    6274                 :             :   else
    6275                 :             :     {
    6276                 :        1400 :       rclass = choose_split_class (rclass, hard_regno, mode);
    6277                 :        1400 :       if (rclass == NO_REGS)
    6278                 :             :         {
    6279                 :           0 :           if (lra_dump_file != NULL)
    6280                 :             :             {
    6281                 :           0 :               fprintf (lra_dump_file,
    6282                 :             :                        "    Rejecting split of %d(%s): "
    6283                 :             :                        "no good reg class for %d(%s)\n",
    6284                 :             :                        original_regno,
    6285                 :           0 :                        reg_class_names[lra_get_allocno_class (original_regno)],
    6286                 :             :                        hard_regno,
    6287                 :           0 :                        reg_class_names[REGNO_REG_CLASS (hard_regno)]);
    6288                 :           0 :               fprintf
    6289                 :           0 :                 (lra_dump_file,
    6290                 :             :                  "    ))))))))))))))))))))))))))))))))))))))))))))))))\n");
    6291                 :             :             }
    6292                 :           0 :           return false;
    6293                 :             :         }
    6294                 :             :       /* Split_if_necessary can split hard registers used as part of a
    6295                 :             :          multi-register mode but splits each register individually.  The
    6296                 :             :          mode used for each independent register may not be supported
    6297                 :             :          so reject the split.  Splitting the wider mode should theoretically
    6298                 :             :          be possible but is not implemented.  */
    6299                 :        1400 :       if (!targetm.hard_regno_mode_ok (hard_regno, mode))
    6300                 :             :         {
    6301                 :           0 :           if (lra_dump_file != NULL)
    6302                 :             :             {
    6303                 :           0 :               fprintf (lra_dump_file,
    6304                 :             :                        "    Rejecting split of %d(%s): unsuitable mode %s\n",
    6305                 :             :                        original_regno,
    6306                 :           0 :                        reg_class_names[lra_get_allocno_class (original_regno)],
    6307                 :           0 :                        GET_MODE_NAME (mode));
    6308                 :           0 :               fprintf
    6309                 :           0 :                 (lra_dump_file,
    6310                 :             :                  "    ))))))))))))))))))))))))))))))))))))))))))))))))\n");
    6311                 :             :             }
    6312                 :           0 :           return false;
    6313                 :             :         }
    6314                 :        1400 :       new_reg = lra_create_new_reg (mode, original_reg, rclass, NULL, "split");
    6315                 :        1400 :       reg_renumber[REGNO (new_reg)] = hard_regno;
    6316                 :             :     }
    6317                 :      605858 :   int new_regno = REGNO (new_reg);
    6318                 :      605858 :   save = emit_spill_move (true, new_reg, original_reg);
    6319                 :      605858 :   if (NEXT_INSN (save) != NULL_RTX && !call_save_p)
    6320                 :             :     {
    6321                 :           0 :       if (lra_dump_file != NULL)
    6322                 :             :         {
    6323                 :           0 :           fprintf
    6324                 :           0 :             (lra_dump_file,
    6325                 :             :              "       Rejecting split %d->%d resulting in > 2 save insns:\n",
    6326                 :             :              original_regno, new_regno);
    6327                 :           0 :           dump_rtl_slim (lra_dump_file, save, NULL, -1, 0);
    6328                 :           0 :           fprintf (lra_dump_file,
    6329                 :             :                    "       ))))))))))))))))))))))))))))))))))))))))))))))))\n");
    6330                 :             :         }
    6331                 :           0 :       return false;
    6332                 :             :     }
    6333                 :      605858 :   restore = emit_spill_move (false, new_reg, original_reg);
    6334                 :      605858 :   if (NEXT_INSN (restore) != NULL_RTX && !call_save_p)
    6335                 :             :     {
    6336                 :           0 :       if (lra_dump_file != NULL)
    6337                 :             :         {
    6338                 :           0 :           fprintf (lra_dump_file,
    6339                 :             :                    "       Rejecting split %d->%d "
    6340                 :             :                    "resulting in > 2 restore insns:\n",
    6341                 :             :                    original_regno, new_regno);
    6342                 :           0 :           dump_rtl_slim (lra_dump_file, restore, NULL, -1, 0);
    6343                 :           0 :           fprintf (lra_dump_file,
    6344                 :             :                    "       ))))))))))))))))))))))))))))))))))))))))))))))))\n");
    6345                 :             :         }
    6346                 :           0 :       return false;
    6347                 :             :     }
    6348                 :             :   /* Transfer equivalence information to the spill register, so that
    6349                 :             :      if we fail to allocate the spill register, we have the option of
    6350                 :             :      rematerializing the original value instead of spilling to the stack.  */
    6351                 :      605858 :   if (!HARD_REGISTER_NUM_P (original_regno)
    6352                 :      605648 :       && mode == PSEUDO_REGNO_MODE (original_regno))
    6353                 :      603618 :     lra_copy_reg_equiv (new_regno, original_regno, call_save_p);
    6354                 :      605858 :   lra_reg_info[new_regno].restore_rtx = regno_reg_rtx[original_regno];
    6355                 :      605858 :   bitmap_set_bit (&lra_split_regs, new_regno);
    6356                 :      605858 :   if (to != NULL)
    6357                 :             :     {
    6358                 :         159 :       lra_assert (next_usage_insns == NULL);
    6359                 :         159 :       usage_insn = to;
    6360                 :         159 :       after_p = true;
    6361                 :             :     }
    6362                 :             :   else
    6363                 :             :     {
    6364                 :             :       /* We need check_only_regs only inside the inheritance pass.  */
    6365                 :      605699 :       bitmap_set_bit (&check_only_regs, new_regno);
    6366                 :      605699 :       bitmap_set_bit (&check_only_regs, original_regno);
    6367                 :      605699 :       after_p = usage_insns[original_regno].after_p;
    6368                 :      695085 :       for (;;)
    6369                 :             :         {
    6370                 :      695085 :           if (GET_CODE (next_usage_insns) != INSN_LIST)
    6371                 :             :             {
    6372                 :      605699 :               usage_insn = next_usage_insns;
    6373                 :      605699 :               break;
    6374                 :             :             }
    6375                 :       89386 :           usage_insn = XEXP (next_usage_insns, 0);
    6376                 :       89386 :           lra_assert (DEBUG_INSN_P (usage_insn));
    6377                 :       89386 :           next_usage_insns = XEXP (next_usage_insns, 1);
    6378                 :       89386 :           lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
    6379                 :             :                                  true);
    6380                 :       89386 :           lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
    6381                 :       89386 :           if (lra_dump_file != NULL)
    6382                 :             :             {
    6383                 :           0 :               fprintf (lra_dump_file, "    Split reuse change %d->%d:\n",
    6384                 :             :                        original_regno, new_regno);
    6385                 :           0 :               dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
    6386                 :             :             }
    6387                 :             :         }
    6388                 :             :     }
    6389                 :      605858 :   lra_assert (NOTE_P (usage_insn) || NONDEBUG_INSN_P (usage_insn));
    6390                 :      605858 :   lra_assert (usage_insn != insn || (after_p && before_p));
    6391                 :     1035552 :   lra_process_new_insns (as_a <rtx_insn *> (usage_insn),
    6392                 :             :                          after_p ? NULL : restore,
    6393                 :             :                          after_p ? restore : NULL,
    6394                 :             :                          call_save_p ? "Add reg<-save" : "Add reg<-split");
    6395                 :      605858 :   if (call_save_p
    6396                 :      604458 :       && first_call_insn != NULL
    6397                 :     1210316 :       && BLOCK_FOR_INSN (first_call_insn) != BLOCK_FOR_INSN (insn))
    6398                 :             :     /* PR116028: If original_regno is a pseudo that has been assigned a
    6399                 :             :        callee-saved hard register, then emit the spill insn before the call
    6400                 :             :        insn 'first_call_insn' instead of adjacent to 'insn'.  If 'insn'
    6401                 :             :        and 'first_call_insn' belong to the same EBB but to two separate
    6402                 :             :        BBs, and if 'insn' is present in the entry BB, then generating the
    6403                 :             :        spill insn in the entry BB can prevent shrink wrap from happening.
    6404                 :             :        This is because the spill insn references the stack pointer and
    6405                 :             :        hence the prolog gets generated in the entry BB itself.  It is
    6406                 :             :        also more efficient to generate the spill before
    6407                 :             :        'first_call_insn' as the spill now occurs only in the path
    6408                 :             :        containing the call.  */
    6409                 :       22030 :     lra_process_new_insns (first_call_insn, save, NULL, "Add save<-reg");
    6410                 :             :   else
    6411                 :     1168423 :     lra_process_new_insns (insn, before_p ? save : NULL,
    6412                 :             :                            before_p ? NULL : save,
    6413                 :             :                            call_save_p ? "Add save<-reg" : "Add split<-reg");
    6414                 :      605858 :   if (nregs > 1 || original_regno < FIRST_PSEUDO_REGISTER)
    6415                 :             :     /* If we are trying to split multi-register.  We should check
    6416                 :             :        conflicts on the next assignment sub-pass.  IRA can allocate on
    6417                 :             :        sub-register levels, LRA do this on pseudos level right now and
    6418                 :             :        this discrepancy may create allocation conflicts after
    6419                 :             :        splitting.
    6420                 :             : 
    6421                 :             :        If we are trying to split hard register we should also check conflicts
    6422                 :             :        as such splitting can create artificial conflict of the hard register
    6423                 :             :        with another pseudo because of simplified conflict calculation in
    6424                 :             :        LRA.  */
    6425                 :        9724 :     check_and_force_assignment_correctness_p = true;
    6426                 :      605858 :   if (lra_dump_file != NULL)
    6427                 :           0 :     fprintf (lra_dump_file,
    6428                 :             :              "       ))))))))))))))))))))))))))))))))))))))))))))))))\n");
    6429                 :             :   return true;
    6430                 :             : }
    6431                 :             : 
    6432                 :             : /* Split a hard reg for reload pseudo REGNO having RCLASS and living
    6433                 :             :    in the range [FROM, TO].  Return true if did a split.  Otherwise,
    6434                 :             :    return false.  */
    6435                 :             : bool
    6436                 :        1635 : spill_hard_reg_in_range (int regno, enum reg_class rclass, rtx_insn *from, rtx_insn *to)
    6437                 :             : {
    6438                 :        1635 :   int i, hard_regno;
    6439                 :        1635 :   int rclass_size;
    6440                 :        1635 :   rtx_insn *insn;
    6441                 :        1635 :   unsigned int uid;
    6442                 :        1635 :   bitmap_iterator bi;
    6443                 :        1635 :   HARD_REG_SET ignore;
    6444                 :             : 
    6445                 :        1635 :   lra_assert (from != NULL && to != NULL);
    6446                 :        1635 :   ignore = lra_no_alloc_regs;
    6447                 :        4766 :   EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
    6448                 :             :     {
    6449                 :        3131 :       lra_insn_recog_data_t id = lra_insn_recog_data[uid];
    6450                 :        3131 :       struct lra_static_insn_data *static_id = id->insn_static_data;
    6451                 :        3131 :       struct lra_insn_reg *reg;
    6452                 :             : 
    6453                 :       10417 :       for (reg = id->regs; reg != NULL; reg = reg->next)
    6454                 :        7286 :         if (reg->regno < FIRST_PSEUDO_REGISTER)
    6455                 :         707 :           SET_HARD_REG_BIT (ignore, reg->regno);
    6456                 :        4850 :       for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
    6457                 :        1719 :         SET_HARD_REG_BIT (ignore, reg->regno);
    6458                 :             :     }
    6459                 :        1635 :   rclass_size = ira_class_hard_regs_num[rclass];
    6460                 :        4705 :   for (i = 0; i < rclass_size; i++)
    6461                 :             :     {
    6462                 :        3229 :       hard_regno = ira_class_hard_regs[rclass][i];
    6463                 :        3229 :       if (! TEST_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hard_regno)
    6464                 :        3229 :           || TEST_HARD_REG_BIT (ignore, hard_regno))
    6465                 :        3064 :         continue;
    6466                 :         476 :       for (insn = from; insn != NEXT_INSN (to); insn = NEXT_INSN (insn))
    6467                 :             :         {
    6468                 :         317 :           struct lra_static_insn_data *static_id;
    6469                 :         317 :           struct lra_insn_reg *reg;
    6470                 :             : 
    6471                 :         317 :           if (!INSN_P (insn))
    6472                 :           0 :               continue;
    6473                 :         317 :           if (bitmap_bit_p (&lra_reg_info[hard_regno].insn_bitmap,
    6474                 :         317 :                             INSN_UID (insn)))
    6475                 :             :             break;
    6476                 :         311 :           static_id = lra_get_insn_recog_data (insn)->insn_static_data;
    6477                 :         365 :           for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
    6478                 :          54 :             if (reg->regno == hard_regno)
    6479                 :             :               break;
    6480                 :             :           if (reg != NULL)
    6481                 :             :             break;
    6482                 :             :         }
    6483                 :         165 :       if (insn != NEXT_INSN (to))
    6484                 :           6 :         continue;
    6485                 :         159 :       if (split_reg (true, hard_regno, from, NULL, to))
    6486                 :             :         return true;
    6487                 :             :     }
    6488                 :             :   return false;
    6489                 :             : }
    6490                 :             : 
    6491                 :             : /* Recognize that we need a split transformation for insn INSN, which
    6492                 :             :    defines or uses REGNO in its insn biggest MODE (we use it only if
    6493                 :             :    REGNO is a hard register).  POTENTIAL_RELOAD_HARD_REGS contains
    6494                 :             :    hard registers which might be used for reloads since the EBB end.
    6495                 :             :    Put the save before INSN if BEFORE_P is true.  MAX_UID is maximla
    6496                 :             :    uid before starting INSN processing.  Return true if we succeed in
    6497                 :             :    such transformation.  */
    6498                 :             : static bool
    6499                 :   199033430 : split_if_necessary (int regno, machine_mode mode,
    6500                 :             :                     HARD_REG_SET potential_reload_hard_regs,
    6501                 :             :                     bool before_p, rtx_insn *insn, int max_uid)
    6502                 :             : {
    6503                 :   199033430 :   bool res = false;
    6504                 :   199033430 :   int i, nregs = 1;
    6505                 :   199033430 :   rtx next_usage_insns;
    6506                 :             : 
    6507                 :   199033430 :   if (regno < FIRST_PSEUDO_REGISTER)
    6508                 :    93028067 :     nregs = hard_regno_nregs (regno, mode);
    6509                 :   398430420 :   for (i = 0; i < nregs; i++)
    6510                 :   199396990 :     if (usage_insns[regno + i].check == curr_usage_insns_check
    6511                 :   132536466 :         && (next_usage_insns = usage_insns[regno + i].insns) != NULL_RTX
    6512                 :             :         /* To avoid processing the register twice or more.  */
    6513                 :   132536466 :         && ((GET_CODE (next_usage_insns) != INSN_LIST
    6514                 :   128076812 :              && INSN_UID (next_usage_insns) < max_uid)
    6515                 :     4459654 :             || (GET_CODE (next_usage_insns) == INSN_LIST
    6516                 :     4459654 :                 && (INSN_UID (XEXP (next_usage_insns, 0)) < max_uid)))
    6517                 :   132536466 :         && need_for_split_p (potential_reload_hard_regs, regno + i)
    6518                 :   199670675 :         && split_reg (before_p, regno + i, insn, next_usage_insns, NULL))
    6519                 :             :       res = true;
    6520                 :   199033430 :   return res;
    6521                 :             : }
    6522                 :             : 
    6523                 :             : /* Return TRUE if rtx X is considered as an invariant for
    6524                 :             :    inheritance.  */
    6525                 :             : static bool
    6526                 :    11838640 : invariant_p (const_rtx x)
    6527                 :             : {
    6528                 :    11838640 :   machine_mode mode;
    6529                 :    11838640 :   const char *fmt;
    6530                 :    11838640 :   enum rtx_code code;
    6531                 :    11838640 :   int i, j;
    6532                 :             : 
    6533                 :    11838640 :   if (side_effects_p (x))
    6534                 :             :     return false;
    6535                 :             : 
    6536                 :    11828987 :   code = GET_CODE (x);
    6537                 :    11828987 :   mode = GET_MODE (x);
    6538                 :    11828987 :   if (code == SUBREG)
    6539                 :             :     {
    6540                 :      458297 :       x = SUBREG_REG (x);
    6541                 :      458297 :       code = GET_CODE (x);
    6542                 :      458297 :       mode = wider_subreg_mode (mode, GET_MODE (x));
    6543                 :             :     }
    6544                 :             : 
    6545                 :    11828987 :   if (MEM_P (x))
    6546                 :             :     return false;
    6547                 :             : 
    6548                 :    10059650 :   if (REG_P (x))
    6549                 :             :     {
    6550                 :     3577651 :       int i, nregs, regno = REGNO (x);
    6551                 :             : 
    6552                 :     3577651 :       if (regno >= FIRST_PSEUDO_REGISTER || regno == STACK_POINTER_REGNUM
    6553                 :      998473 :           || TEST_HARD_REG_BIT (eliminable_regset, regno)
    6554                 :     3597189 :           || GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
    6555                 :             :         return false;
    6556                 :           2 :       nregs = hard_regno_nregs (regno, mode);
    6557                 :           2 :       for (i = 0; i < nregs; i++)
    6558                 :           2 :         if (! fixed_regs[regno + i]
    6559                 :             :             /* A hard register may be clobbered in the current insn
    6560                 :             :                but we can ignore this case because if the hard
    6561                 :             :                register is used it should be set somewhere after the
    6562                 :             :                clobber.  */
    6563                 :           2 :             || bitmap_bit_p (&invalid_invariant_regs, regno + i))
    6564                 :           2 :           return false;
    6565                 :             :     }
    6566                 :     6481999 :   fmt = GET_RTX_FORMAT (code);
    6567                 :    11445492 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    6568                 :             :     {
    6569                 :     8654685 :       if (fmt[i] == 'e')
    6570                 :             :         {
    6571                 :     5681501 :           if (! invariant_p (XEXP (x, i)))
    6572                 :             :             return false;
    6573                 :             :         }
    6574                 :     2973184 :       else if (fmt[i] == 'E')
    6575                 :             :         {
    6576                 :      629873 :           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    6577                 :      521109 :             if (! invariant_p (XVECEXP (x, i, j)))
    6578                 :             :               return false;
    6579                 :             :         }
    6580                 :             :     }
    6581                 :             :   return true;
    6582                 :             : }
    6583                 :             : 
    6584                 :             : /* We have 'dest_reg <- invariant'.  Let us try to make an invariant
    6585                 :             :    inheritance transformation (using dest_reg instead invariant in a
    6586                 :             :    subsequent insn).  */
    6587                 :             : static bool
    6588                 :      181292 : process_invariant_for_inheritance (rtx dst_reg, rtx invariant_rtx)
    6589                 :             : {
    6590                 :      181292 :   invariant_ptr_t invariant_ptr;
    6591                 :      181292 :   rtx_insn *insn, *new_insns;
    6592                 :      181292 :   rtx insn_set, insn_reg, new_reg;
    6593                 :      181292 :   int insn_regno;
    6594                 :      181292 :   bool succ_p = false;
    6595                 :      181292 :   int dst_regno = REGNO (dst_reg);
    6596                 :      181292 :   machine_mode dst_mode = GET_MODE (dst_reg);
    6597                 :      181292 :   enum reg_class cl = lra_get_allocno_class (dst_regno), insn_reg_cl;
    6598                 :             : 
    6599                 :      181292 :   invariant_ptr = insert_invariant (invariant_rtx);
    6600                 :      181292 :   if ((insn = invariant_ptr->insn) != NULL_RTX)
    6601                 :             :     {
    6602                 :             :       /* We have a subsequent insn using the invariant.  */
    6603                 :       22316 :       insn_set = single_set (insn);
    6604                 :       22316 :       lra_assert (insn_set != NULL);
    6605                 :       22316 :       insn_reg = SET_DEST (insn_set);
    6606                 :       22316 :       lra_assert (REG_P (insn_reg));
    6607                 :       22316 :       insn_regno = REGNO (insn_reg);
    6608                 :       22316 :       insn_reg_cl = lra_get_allocno_class (insn_regno);
    6609                 :             : 
    6610                 :       22316 :       if (dst_mode == GET_MODE (insn_reg)
    6611                 :             :           /* We should consider only result move reg insns which are
    6612                 :             :              cheap.  */
    6613                 :       22244 :           && targetm.register_move_cost (dst_mode, cl, insn_reg_cl) == 2
    6614                 :       43976 :           && targetm.register_move_cost (dst_mode, cl, cl) == 2)
    6615                 :             :         {
    6616                 :       21660 :           if (lra_dump_file != NULL)
    6617                 :           0 :             fprintf (lra_dump_file,
    6618                 :             :                      "    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n");
    6619                 :       21660 :           new_reg = lra_create_new_reg (dst_mode, dst_reg, cl, NULL,
    6620                 :             :                                         "invariant inheritance");
    6621                 :       21660 :           bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
    6622                 :       21660 :           bitmap_set_bit (&check_only_regs, REGNO (new_reg));
    6623                 :       21660 :           lra_reg_info[REGNO (new_reg)].restore_rtx = PATTERN (insn);
    6624                 :       21660 :           start_sequence ();
    6625                 :       21660 :           lra_emit_move (new_reg, dst_reg);
    6626                 :       21660 :           new_insns = end_sequence ();
    6627                 :       21660 :           lra_process_new_insns (curr_insn, NULL, new_insns,
    6628                 :             :                                  "Add invariant inheritance<-original");
    6629                 :       21660 :           start_sequence ();
    6630                 :       21660 :           lra_emit_move (SET_DEST (insn_set), new_reg);
    6631                 :       21660 :           new_insns = end_sequence ();
    6632                 :       21660 :           lra_process_new_insns (insn, NULL, new_insns,
    6633                 :             :                                  "Changing reload<-inheritance");
    6634                 :       21660 :           lra_set_insn_deleted (insn);
    6635                 :       21660 :           succ_p = true;
    6636                 :       21660 :           if (lra_dump_file != NULL)
    6637                 :             :             {
    6638                 :           0 :               fprintf (lra_dump_file,
    6639                 :             :                        "    Invariant inheritance reuse change %d (bb%d):\n",
    6640                 :           0 :                        REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
    6641                 :           0 :               dump_insn_slim (lra_dump_file, insn);
    6642                 :           0 :               fprintf (lra_dump_file,
    6643                 :             :                        "     ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\n");
    6644                 :             :             }
    6645                 :             :         }
    6646                 :             :     }
    6647                 :      181292 :   invariant_ptr->insn = curr_insn;
    6648                 :      181292 :   return succ_p;
    6649                 :             : }
    6650                 :             : 
    6651                 :             : /* Check only registers living at the current program point in the
    6652                 :             :    current EBB.  */
    6653                 :             : static bitmap_head live_regs;
    6654                 :             : 
    6655                 :             : /* Update live info in EBB given by its HEAD and TAIL insns after
    6656                 :             :    inheritance/split transformation.  The function removes dead moves
    6657                 :             :    too.  */
    6658                 :             : static void
    6659                 :      728196 : update_ebb_live_info (rtx_insn *head, rtx_insn *tail)
    6660                 :             : {
    6661                 :      728196 :   unsigned int j;
    6662                 :      728196 :   int i, regno;
    6663                 :      728196 :   bool live_p;
    6664                 :      728196 :   rtx_insn *prev_insn;
    6665                 :      728196 :   rtx set;
    6666                 :      728196 :   bool remove_p;
    6667                 :      728196 :   basic_block last_bb, prev_bb, curr_bb;
    6668                 :      728196 :   bitmap_iterator bi;
    6669                 :      728196 :   struct lra_insn_reg *reg;
    6670                 :      728196 :   edge e;
    6671                 :      728196 :   edge_iterator ei;
    6672                 :             : 
    6673                 :      728196 :   last_bb = BLOCK_FOR_INSN (tail);
    6674                 :      728196 :   prev_bb = NULL;
    6675                 :      728196 :   for (curr_insn = tail;
    6676                 :    35800347 :        curr_insn != PREV_INSN (head);
    6677                 :    35072151 :        curr_insn = prev_insn)
    6678                 :             :     {
    6679                 :    35072151 :       prev_insn = PREV_INSN (curr_insn);
    6680                 :             :       /* We need to process empty blocks too.  They contain
    6681                 :             :          NOTE_INSN_BASIC_BLOCK referring for the basic block.  */
    6682                 :    35072151 :       if (NOTE_P (curr_insn) && NOTE_KIND (curr_insn) != NOTE_INSN_BASIC_BLOCK)
    6683                 :     1406408 :         continue;
    6684                 :    33665743 :       curr_bb = BLOCK_FOR_INSN (curr_insn);
    6685                 :    33665743 :       if (curr_bb != prev_bb)
    6686                 :             :         {
    6687                 :     1451566 :           if (prev_bb != NULL)
    6688                 :             :             {
    6689                 :             :               /* Update df_get_live_in (prev_bb):  */
    6690                 :    54254358 :               EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
    6691                 :    53530988 :                 if (bitmap_bit_p (&live_regs, j))
    6692                 :     1557254 :                   bitmap_set_bit (df_get_live_in (prev_bb), j);
    6693                 :             :                 else
    6694                 :    51973734 :                   bitmap_clear_bit (df_get_live_in (prev_bb), j);
    6695                 :             :             }
    6696                 :     1451566 :           if (curr_bb != last_bb)
    6697                 :             :             {
    6698                 :             :               /* Update df_get_live_out (curr_bb):  */
    6699                 :    54254358 :               EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
    6700                 :             :                 {
    6701                 :    53530988 :                   live_p = bitmap_bit_p (&live_regs, j);
    6702                 :    53530988 :                   if (! live_p)
    6703                 :   155830744 :                     FOR_EACH_EDGE (e, ei, curr_bb->succs)
    6704                 :   103909230 :                       if (bitmap_bit_p (df_get_live_in (e->dest), j))
    6705                 :             :                         {
    6706                 :             :                           live_p = true;
    6707                 :             :                           break;
    6708                 :             :                         }
    6709                 :    51973734 :                   if (live_p)
    6710                 :     1609474 :                     bitmap_set_bit (df_get_live_out (curr_bb), j);
    6711                 :             :                   else
    6712                 :    51921514 :                     bitmap_clear_bit (df_get_live_out (curr_bb), j);
    6713                 :             :                 }
    6714                 :             :             }
    6715                 :     1451566 :           prev_bb = curr_bb;
    6716                 :     1451566 :           bitmap_and (&live_regs, &check_only_regs, df_get_live_out (curr_bb));
    6717                 :             :         }
    6718                 :    33665743 :       if (! NONDEBUG_INSN_P (curr_insn))
    6719                 :    11705946 :         continue;
    6720                 :    21959797 :       curr_id = lra_get_insn_recog_data (curr_insn);
    6721                 :    21959797 :       curr_static_id = curr_id->insn_static_data;
    6722                 :    21959797 :       remove_p = false;
    6723                 :    21959797 :       if ((set = single_set (curr_insn)) != NULL_RTX
    6724                 :    21281445 :           && REG_P (SET_DEST (set))
    6725                 :    16996909 :           && (regno = REGNO (SET_DEST (set))) >= FIRST_PSEUDO_REGISTER
    6726                 :    12616723 :           && SET_DEST (set) != pic_offset_table_rtx
    6727                 :    12609978 :           && bitmap_bit_p (&check_only_regs, regno)
    6728                 :    25076460 :           && ! bitmap_bit_p (&live_regs, regno))
    6729                 :             :         remove_p = true;
    6730                 :             :       /* See which defined values die here.  */
    6731                 :    60370250 :       for (reg = curr_id->regs; reg != NULL; reg = reg->next)
    6732                 :    38410453 :         if (reg->type == OP_OUT && ! reg->subreg_p)
    6733                 :    15146434 :           bitmap_clear_bit (&live_regs, reg->regno);
    6734                 :    26115078 :       for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
    6735                 :     4155281 :         if (reg->type == OP_OUT && ! reg->subreg_p)
    6736                 :     3160626 :           bitmap_clear_bit (&live_regs, reg->regno);
    6737                 :    21959797 :       if (curr_id->arg_hard_regs != NULL)
    6738                 :             :         /* Make clobbered argument hard registers die.  */
    6739                 :     3349530 :         for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
    6740                 :     2415868 :           if (regno >= FIRST_PSEUDO_REGISTER)
    6741                 :      189780 :             bitmap_clear_bit (&live_regs, regno - FIRST_PSEUDO_REGISTER);
    6742                 :             :       /* Mark each used value as live.  */
    6743                 :    60370250 :       for (reg = curr_id->regs; reg != NULL; reg = reg->next)
    6744                 :    38410453 :         if (reg->type != OP_OUT
    6745                 :    38410453 :             && bitmap_bit_p (&check_only_regs, reg->regno))
    6746                 :     4385363 :           bitmap_set_bit (&live_regs, reg->regno);
    6747                 :    26115078 :       for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
    6748                 :     4155281 :         if (reg->type != OP_OUT
    6749                 :     4155281 :             && bitmap_bit_p (&check_only_regs, reg->regno))
    6750                 :           0 :           bitmap_set_bit (&live_regs, reg->regno);
    6751                 :    21959797 :       if (curr_id->arg_hard_regs != NULL)
    6752                 :             :         /* Make used argument hard registers live.  */
    6753                 :     3349530 :         for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
    6754                 :     2415868 :           if (regno < FIRST_PSEUDO_REGISTER
    6755                 :     2415868 :               && bitmap_bit_p (&check_only_regs, regno))
    6756                 :           0 :             bitmap_set_bit (&live_regs, regno);
    6757                 :             :       /* It is quite important to remove dead move insns because it
    6758                 :             :          means removing dead store.  We don't need to process them for
    6759                 :             :          constraints.  */
    6760                 :    21959797 :       if (remove_p)
    6761                 :             :         {
    6762                 :      299962 :           if (lra_dump_file != NULL)
    6763                 :             :             {
    6764                 :           2 :               fprintf (lra_dump_file, "        Removing dead insn:\n ");
    6765                 :           2 :               dump_insn_slim (lra_dump_file, curr_insn);
    6766                 :             :             }
    6767                 :      299962 :           lra_set_insn_deleted (curr_insn);
    6768                 :             :         }
    6769                 :             :     }
    6770                 :      728196 : }
    6771                 :             : 
    6772                 :             : /* The structure describes info to do an inheritance for the current
    6773                 :             :    insn.  We need to collect such info first before doing the
    6774                 :             :    transformations because the transformations change the insn
    6775                 :             :    internal representation.  */
    6776                 :             : struct to_inherit
    6777                 :             : {
    6778                 :             :   /* Original regno.  */
    6779                 :             :   int regno;
    6780                 :             :   /* Subsequent insns which can inherit original reg value.  */
    6781                 :             :   rtx insns;
    6782                 :             : };
    6783                 :             : 
    6784                 :             : /* Array containing all info for doing inheritance from the current
    6785                 :             :    insn.  */
    6786                 :             : static struct to_inherit to_inherit[LRA_MAX_INSN_RELOADS];
    6787                 :             : 
    6788                 :             : /* Number elements in the previous array.  */
    6789                 :             : static int to_inherit_num;
    6790                 :             : 
    6791                 :             : /* Add inheritance info REGNO and INSNS. Their meaning is described in
    6792                 :             :    structure to_inherit.  */
    6793                 :             : static void
    6794                 :      308256 : add_to_inherit (int regno, rtx insns)
    6795                 :             : {
    6796                 :      308256 :   int i;
    6797                 :             : 
    6798                 :      308354 :   for (i = 0; i < to_inherit_num; i++)
    6799                 :          98 :     if (to_inherit[i].regno == regno)
    6800                 :             :       return;
    6801                 :      308256 :   lra_assert (to_inherit_num < LRA_MAX_INSN_RELOADS);
    6802                 :      308256 :   to_inherit[to_inherit_num].regno = regno;
    6803                 :      308256 :   to_inherit[to_inherit_num++].insns = insns;
    6804                 :             : }
    6805                 :             : 
    6806                 :             : /* Return the last non-debug insn in basic block BB, or the block begin
    6807                 :             :    note if none.  */
    6808                 :             : static rtx_insn *
    6809                 :    30315269 : get_last_insertion_point (basic_block bb)
    6810                 :             : {
    6811                 :    30315269 :   rtx_insn *insn;
    6812                 :             : 
    6813                 :    32607498 :   FOR_BB_INSNS_REVERSE (bb, insn)
    6814                 :    32607498 :     if (NONDEBUG_INSN_P (insn) || NOTE_INSN_BASIC_BLOCK_P (insn))
    6815                 :    30315269 :       return insn;
    6816                 :           0 :   gcc_unreachable ();
    6817                 :             : }
    6818                 :             : 
    6819                 :             : /* Set up RES by registers living on edges FROM except the edge (FROM,
    6820                 :             :    TO) or by registers set up in a jump insn in BB FROM.  */
    6821                 :             : static void
    6822                 :    11595226 : get_live_on_other_edges (basic_block from, basic_block to, bitmap res)
    6823                 :             : {
    6824                 :    11595226 :   rtx_insn *last;
    6825                 :    11595226 :   struct lra_insn_reg *reg;
    6826                 :    11595226 :   edge e;
    6827                 :    11595226 :   edge_iterator ei;
    6828                 :             : 
    6829                 :    11595226 :   lra_assert (to != NULL);
    6830                 :    11595226 :   bitmap_clear (res);
    6831                 :    34575376 :   FOR_EACH_EDGE (e, ei, from->succs)
    6832                 :    22980150 :     if (e->dest != to)
    6833                 :    11384924 :       bitmap_ior_into (res, df_get_live_in (e->dest));
    6834                 :    11595226 :   last = get_last_insertion_point (from);
    6835                 :    11595226 :   if (! JUMP_P (last))
    6836                 :     2028060 :     return;
    6837                 :     9567166 :   curr_id = lra_get_insn_recog_data (last);
    6838                 :    19134162 :   for (reg = curr_id->regs; reg != NULL; reg = reg->next)
    6839                 :     9566996 :     if (reg->type != OP_IN)
    6840                 :          74 :       bitmap_set_bit (res, reg->regno);
    6841                 :             : }
    6842                 :             : 
    6843                 :             : /* Used as a temporary results of some bitmap calculations.  */
    6844                 :             : static bitmap_head temp_bitmap;
    6845                 :             : 
    6846                 :             : /* We split for reloads of small class of hard regs.  The following
    6847                 :             :    defines how many hard regs the class should have to be qualified as
    6848                 :             :    small.  The code is mostly oriented to x86/x86-64 architecture
    6849                 :             :    where some insns need to use only specific register or pair of
    6850                 :             :    registers and these register can live in RTL explicitly, e.g. for
    6851                 :             :    parameter passing.  */
    6852                 :             : static const int max_small_class_regs_num = 2;
    6853                 :             : 
    6854                 :             : /* Do inheritance/split transformations in EBB starting with HEAD and
    6855                 :             :    finishing on TAIL.  We process EBB insns in the reverse order.
    6856                 :             :    Return true if we did any inheritance/split transformation in the
    6857                 :             :    EBB.
    6858                 :             : 
    6859                 :             :    We should avoid excessive splitting which results in worse code
    6860                 :             :    because of inaccurate cost calculations for spilling new split
    6861                 :             :    pseudos in such case.  To achieve this we do splitting only if
    6862                 :             :    register pressure is high in given basic block and there are reload
    6863                 :             :    pseudos requiring hard registers.  We could do more register
    6864                 :             :    pressure calculations at any given program point to avoid necessary
    6865                 :             :    splitting even more but it is to expensive and the current approach
    6866                 :             :    works well enough.  */
    6867                 :             : static bool
    6868                 :    12922549 : inherit_in_ebb (rtx_insn *head, rtx_insn *tail)
    6869                 :             : {
    6870                 :    12922549 :   int i, src_regno, dst_regno, nregs;
    6871                 :    12922549 :   bool change_p, succ_p, update_reloads_num_p;
    6872                 :    12922549 :   rtx_insn *prev_insn, *last_insn;
    6873                 :    12922549 :   rtx next_usage_insns, curr_set;
    6874                 :    12922549 :   enum reg_class cl;
    6875                 :    12922549 :   struct lra_insn_reg *reg;
    6876                 :    12922549 :   basic_block last_processed_bb, curr_bb = NULL;
    6877                 :    12922549 :   HARD_REG_SET potential_reload_hard_regs, live_hard_regs;
    6878                 :    12922549 :   bitmap to_process;
    6879                 :    12922549 :   unsigned int j;
    6880                 :    12922549 :   bitmap_iterator bi;
    6881                 :    12922549 :   bool head_p, after_p;
    6882                 :             : 
    6883                 :    12922549 :   change_p = false;
    6884                 :    12922549 :   curr_usage_insns_check++;
    6885                 :    12922549 :   clear_invariants ();
    6886                 :    12922549 :   reloads_num = calls_num = 0;
    6887                 :   116302941 :   for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
    6888                 :   103380392 :     last_call_for_abi[i] = 0;
    6889                 :    12922549 :   CLEAR_HARD_REG_SET (full_and_partial_call_clobbers);
    6890                 :    12922549 :   bitmap_clear (&check_only_regs);
    6891                 :    12922549 :   bitmap_clear (&invalid_invariant_regs);
    6892                 :    12922549 :   last_processed_bb = NULL;
    6893                 :    12922549 :   CLEAR_HARD_REG_SET (potential_reload_hard_regs);
    6894                 :    12922549 :   live_hard_regs = eliminable_regset | lra_no_alloc_regs;
    6895                 :             :   /* We don't process new insns generated in the loop.  */
    6896                 :   238754905 :   for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn)
    6897                 :             :     {
    6898                 :   225832356 :       prev_insn = PREV_INSN (curr_insn);
    6899                 :   225832356 :       if (BLOCK_FOR_INSN (curr_insn) != NULL)
    6900                 :   225832118 :         curr_bb = BLOCK_FOR_INSN (curr_insn);
    6901                 :   225832356 :       if (last_processed_bb != curr_bb)
    6902                 :             :         {
    6903                 :             :           /* We are at the end of BB.  Add qualified living
    6904                 :             :              pseudos for potential splitting.  */
    6905                 :    18720043 :           to_process = df_get_live_out (curr_bb);
    6906                 :    18720043 :           if (last_processed_bb != NULL)
    6907                 :             :             {
    6908                 :             :               /* We are somewhere in the middle of EBB.  */
    6909                 :     5797494 :               get_live_on_other_edges (curr_bb, last_processed_bb,
    6910                 :             :                                        &temp_bitmap);
    6911                 :     5797494 :               to_process = &temp_bitmap;
    6912                 :             :             }
    6913                 :    18720043 :           last_processed_bb = curr_bb;
    6914                 :    18720043 :           last_insn = get_last_insertion_point (curr_bb);
    6915                 :    37440086 :           after_p = (! JUMP_P (last_insn)
    6916                 :    18720043 :                      && (! CALL_P (last_insn)
    6917                 :     2363449 :                          || (find_reg_note (last_insn,
    6918                 :             :                                            REG_NORETURN, NULL_RTX) == NULL_RTX
    6919                 :     1433519 :                              && ! SIBLING_CALL_P (last_insn))));
    6920                 :    18720043 :           CLEAR_HARD_REG_SET (potential_reload_hard_regs);
    6921                 :   202527106 :           EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
    6922                 :             :             {
    6923                 :   183807069 :               if ((int) j >= lra_constraint_new_regno_start)
    6924                 :             :                 break;
    6925                 :   183807063 :               if (j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
    6926                 :             :                 {
    6927                 :   119302684 :                   if (j < FIRST_PSEUDO_REGISTER)
    6928                 :    70351188 :                     SET_HARD_REG_BIT (live_hard_regs, j);
    6929                 :             :                   else
    6930                 :    48951496 :                     add_to_hard_reg_set (&live_hard_regs,
    6931                 :    48951496 :                                          PSEUDO_REGNO_MODE (j),
    6932                 :    48951496 :                                          reg_renumber[j]);
    6933                 :   119302684 :                   setup_next_usage_insn (j, last_insn, reloads_num, after_p);
    6934                 :             :                 }
    6935                 :             :             }
    6936                 :             :         }
    6937                 :   225832356 :       src_regno = dst_regno = -1;
    6938                 :   225832356 :       curr_set = single_set (curr_insn);
    6939                 :   225832356 :       if (curr_set != NULL_RTX && REG_P (SET_DEST (curr_set)))
    6940                 :    84437767 :         dst_regno = REGNO (SET_DEST (curr_set));
    6941                 :   114358690 :       if (curr_set != NULL_RTX && REG_P (SET_SRC (curr_set)))
    6942                 :    39604356 :         src_regno = REGNO (SET_SRC (curr_set));
    6943                 :   225832356 :       update_reloads_num_p = true;
    6944                 :   225832356 :       if (src_regno < lra_constraint_new_regno_start
    6945                 :   219375028 :           && src_regno >= FIRST_PSEUDO_REGISTER
    6946                 :    27888538 :           && reg_renumber[src_regno] < 0
    6947                 :     3727480 :           && dst_regno >= lra_constraint_new_regno_start
    6948                 :   228467609 :           && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS)
    6949                 :             :         {
    6950                 :             :           /* 'reload_pseudo <- original_pseudo'.  */
    6951                 :     2635253 :           if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
    6952                 :       21594 :             reloads_num++;
    6953                 :     2635253 :           update_reloads_num_p = false;
    6954                 :     2635253 :           succ_p = false;
    6955                 :     2635253 :           if (usage_insns[src_regno].check == curr_usage_insns_check
    6956                 :     2635253 :               && (next_usage_insns = usage_insns[src_regno].insns) != NULL_RTX)
    6957                 :      471282 :             succ_p = inherit_reload_reg (false, src_regno, cl,
    6958                 :             :                                          curr_insn, next_usage_insns);
    6959                 :      471282 :           if (succ_p)
    6960                 :             :             change_p = true;
    6961                 :             :           else
    6962                 :     2187345 :             setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
    6963                 :     5270506 :           if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
    6964                 :   635122560 :             potential_reload_hard_regs |= reg_class_contents[cl];
    6965                 :             :         }
    6966                 :   223197103 :       else if (src_regno < 0
    6967                 :   186228000 :                && dst_regno >= lra_constraint_new_regno_start
    6968                 :     5636030 :                && invariant_p (SET_SRC (curr_set))
    6969                 :      279389 :                && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS
    6970                 :      278847 :                && ! bitmap_bit_p (&invalid_invariant_regs, dst_regno)
    6971                 :   223440171 :                && ! bitmap_bit_p (&invalid_invariant_regs,
    6972                 :      243068 :                                   ORIGINAL_REGNO(regno_reg_rtx[dst_regno])))
    6973                 :             :         {
    6974                 :             :           /* 'reload_pseudo <- invariant'.  */
    6975                 :      181292 :           if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
    6976                 :        5123 :             reloads_num++;
    6977                 :      181292 :           update_reloads_num_p = false;
    6978                 :      181292 :           if (process_invariant_for_inheritance (SET_DEST (curr_set), SET_SRC (curr_set)))
    6979                 :       21660 :             change_p = true;
    6980                 :      362584 :           if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
    6981                 :   635122560 :             potential_reload_hard_regs |= reg_class_contents[cl];
    6982                 :             :         }
    6983                 :   223015811 :       else if (src_regno >= lra_constraint_new_regno_start
    6984                 :     6457328 :                && dst_regno < lra_constraint_new_regno_start
    6985                 :     5643290 :                && dst_regno >= FIRST_PSEUDO_REGISTER
    6986                 :     3741088 :                && reg_renumber[dst_regno] < 0
    6987                 :     1475320 :                && (cl = lra_get_allocno_class (src_regno)) != NO_REGS
    6988                 :     1475320 :                && usage_insns[dst_regno].check == curr_usage_insns_check
    6989                 :   223015811 :                && (next_usage_insns
    6990                 :      475849 :                    = usage_insns[dst_regno].insns) != NULL_RTX)
    6991                 :             :         {
    6992                 :      475849 :           if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
    6993                 :        7909 :             reloads_num++;
    6994                 :      475849 :           update_reloads_num_p = false;
    6995                 :             :           /* 'original_pseudo <- reload_pseudo'.  */
    6996                 :      475849 :           if (! JUMP_P (curr_insn)
    6997                 :      475849 :               && inherit_reload_reg (true, dst_regno, cl,
    6998                 :             :                                      curr_insn, next_usage_insns))
    6999                 :             :             change_p = true;
    7000                 :             :           /* Invalidate.  */
    7001                 :      475849 :           usage_insns[dst_regno].check = 0;
    7002                 :      951698 :           if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
    7003                 :   635122560 :             potential_reload_hard_regs |= reg_class_contents[cl];
    7004                 :             :         }
    7005                 :   222539962 :       else if (INSN_P (curr_insn))
    7006                 :             :         {
    7007                 :   186678604 :           int iter;
    7008                 :   186678604 :           int max_uid = get_max_uid ();
    7009                 :             : 
    7010                 :   186678604 :           curr_id = lra_get_insn_recog_data (curr_insn);
    7011                 :   186678604 :           curr_static_id = curr_id->insn_static_data;
    7012                 :   186678604 :           to_inherit_num = 0;
    7013                 :             :           /* Process insn definitions.  */
    7014                 :   560035812 :           for (iter = 0; iter < 2; iter++)
    7015                 :   373357208 :             for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
    7016                 :   600298211 :                  reg != NULL;
    7017                 :   226941003 :                  reg = reg->next)
    7018                 :   226941003 :               if (reg->type != OP_IN
    7019                 :   226941003 :                   && (dst_regno = reg->regno) < lra_constraint_new_regno_start)
    7020                 :             :                 {
    7021                 :    46179256 :                   if (dst_regno >= FIRST_PSEUDO_REGISTER && reg->type == OP_OUT
    7022                 :    44089938 :                       && reg_renumber[dst_regno] < 0 && ! reg->subreg_p
    7023                 :     1831125 :                       && usage_insns[dst_regno].check == curr_usage_insns_check
    7024                 :    91541443 :                       && (next_usage_insns
    7025                 :      126304 :                           = usage_insns[dst_regno].insns) != NULL_RTX)
    7026                 :             :                     {
    7027                 :      126304 :                       struct lra_insn_reg *r;
    7028                 :             : 
    7029                 :      376857 :                       for (r = curr_id->regs; r != NULL; r = r->next)
    7030                 :      250553 :                         if (r->type != OP_OUT && r->regno == dst_regno)
    7031                 :             :                           break;
    7032                 :             :                       /* Don't do inheritance if the pseudo is also
    7033                 :             :                          used in the insn.  */
    7034                 :      126304 :                       if (r == NULL)
    7035                 :             :                         /* We cannot do inheritance right now
    7036                 :             :                            because the current insn reg info (chain
    7037                 :             :                            regs) can change after that.  */
    7038                 :      126304 :                         add_to_inherit (dst_regno, next_usage_insns);
    7039                 :             :                     }
    7040                 :             :                   /* We cannot process one reg twice here because of
    7041                 :             :                      usage_insns invalidation.  */
    7042                 :    91541443 :                   if ((dst_regno < FIRST_PSEUDO_REGISTER
    7043                 :    46179256 :                        || reg_renumber[dst_regno] >= 0)
    7044                 :    89571058 :                       && ! reg->subreg_p && reg->type != OP_IN)
    7045                 :             :                     {
    7046                 :    89289521 :                       HARD_REG_SET s;
    7047                 :             : 
    7048                 :    89289521 :                       if (split_if_necessary (dst_regno, reg->biggest_mode,
    7049                 :             :                                               potential_reload_hard_regs,
    7050                 :             :                                               false, curr_insn, max_uid))
    7051                 :       60291 :                         change_p = true;
    7052                 :    89289521 :                       CLEAR_HARD_REG_SET (s);
    7053                 :    89289521 :                       if (dst_regno < FIRST_PSEUDO_REGISTER)
    7054                 :    45362187 :                         add_to_hard_reg_set (&s, reg->biggest_mode, dst_regno);
    7055                 :             :                       else
    7056                 :    43927334 :                         add_to_hard_reg_set (&s, PSEUDO_REGNO_MODE (dst_regno),
    7057                 :    43927334 :                                              reg_renumber[dst_regno]);
    7058                 :    89289521 :                       live_hard_regs &= ~s;
    7059                 :   178579042 :                       potential_reload_hard_regs &= ~s;
    7060                 :             :                     }
    7061                 :             :                   /* We should invalidate potential inheritance or
    7062                 :             :                      splitting for the current insn usages to the next
    7063                 :             :                      usage insns (see code below) as the output pseudo
    7064                 :             :                      prevents this.  */
    7065                 :    91541443 :                   if ((dst_regno >= FIRST_PSEUDO_REGISTER
    7066                 :    46179256 :                        && reg_renumber[dst_regno] < 0)
    7067                 :    89571058 :                       || (reg->type == OP_OUT && ! reg->subreg_p
    7068                 :    81638614 :                           && (dst_regno < FIRST_PSEUDO_REGISTER
    7069                 :    41846619 :                               || reg_renumber[dst_regno] >= 0)))
    7070                 :             :                     {
    7071                 :             :                       /* Invalidate and mark definitions.  */
    7072                 :    43817004 :                       if (dst_regno >= FIRST_PSEUDO_REGISTER)
    7073                 :    43817004 :                         usage_insns[dst_regno].check = -(int) INSN_UID (curr_insn);
    7074                 :             :                       else
    7075                 :             :                         {
    7076                 :    39791995 :                           nregs = hard_regno_nregs (dst_regno,
    7077                 :    39791995 :                                                     reg->biggest_mode);
    7078                 :    79850586 :                           for (i = 0; i < nregs; i++)
    7079                 :    80117182 :                             usage_insns[dst_regno + i].check
    7080                 :    40058591 :                               = -(int) INSN_UID (curr_insn);
    7081                 :             :                         }
    7082                 :             :                     }
    7083                 :             :                 }
    7084                 :             :           /* Process clobbered call regs.  */
    7085                 :   186678604 :           if (curr_id->arg_hard_regs != NULL)
    7086                 :    20117626 :             for (i = 0; (dst_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
    7087                 :    14375337 :               if (dst_regno >= FIRST_PSEUDO_REGISTER)
    7088                 :     1611174 :                 usage_insns[dst_regno - FIRST_PSEUDO_REGISTER].check
    7089                 :      805587 :                   = -(int) INSN_UID (curr_insn);
    7090                 :   186678604 :           if (! JUMP_P (curr_insn))
    7091                 :   175056026 :             for (i = 0; i < to_inherit_num; i++)
    7092                 :      126304 :               if (inherit_reload_reg (true, to_inherit[i].regno,
    7093                 :             :                                       ALL_REGS, curr_insn,
    7094                 :             :                                       to_inherit[i].insns))
    7095                 :      100974 :               change_p = true;
    7096                 :   186678604 :           if (CALL_P (curr_insn))
    7097                 :             :             {
    7098                 :     7355416 :               rtx cheap, pat, dest;
    7099                 :     7355416 :               rtx_insn *restore;
    7100                 :     7355416 :               int regno, hard_regno;
    7101                 :             : 
    7102                 :     7355416 :               calls_num++;
    7103                 :     7355416 :               function_abi callee_abi = insn_callee_abi (curr_insn);
    7104                 :     7355416 :               last_call_for_abi[callee_abi.id ()] = calls_num;
    7105                 :     7355416 :               full_and_partial_call_clobbers
    7106                 :     7355416 :                 |= callee_abi.full_and_partial_reg_clobbers ();
    7107                 :     7355416 :               first_call_insn = curr_insn;
    7108                 :     7355416 :               if ((cheap = find_reg_note (curr_insn,
    7109                 :             :                                           REG_RETURNED, NULL_RTX)) != NULL_RTX
    7110                 :       37285 :                   && ((cheap = XEXP (cheap, 0)), true)
    7111                 :       37285 :                   && (regno = REGNO (cheap)) >= FIRST_PSEUDO_REGISTER
    7112                 :       37285 :                   && (hard_regno = reg_renumber[regno]) >= 0
    7113                 :       29430 :                   && usage_insns[regno].check == curr_usage_insns_check
    7114                 :             :                   /* If there are pending saves/restores, the
    7115                 :             :                      optimization is not worth.  */
    7116                 :       24748 :                   && usage_insns[regno].calls_num == calls_num - 1
    7117                 :     7378543 :                   && callee_abi.clobbers_reg_p (GET_MODE (cheap), hard_regno))
    7118                 :             :                 {
    7119                 :             :                   /* Restore the pseudo from the call result as
    7120                 :             :                      REG_RETURNED note says that the pseudo value is
    7121                 :             :                      in the call result and the pseudo is an argument
    7122                 :             :                      of the call.  */
    7123                 :        9078 :                   pat = PATTERN (curr_insn);
    7124                 :        9078 :                   if (GET_CODE (pat) == PARALLEL)
    7125                 :           0 :                     pat = XVECEXP (pat, 0, 0);
    7126                 :        9078 :                   dest = SET_DEST (pat);
    7127                 :             :                   /* For multiple return values dest is PARALLEL.
    7128                 :             :                      Currently we handle only single return value case.  */
    7129                 :        9078 :                   if (REG_P (dest))
    7130                 :             :                     {
    7131                 :        9078 :                       start_sequence ();
    7132                 :        9078 :                       emit_move_insn (cheap, copy_rtx (dest));
    7133                 :        9078 :                       restore = end_sequence ();
    7134                 :        9078 :                       lra_process_new_insns (curr_insn, NULL, restore,
    7135                 :             :                                              "Inserting call parameter restore");
    7136                 :             :                       /* We don't need to save/restore of the pseudo from
    7137                 :             :                          this call.      */
    7138                 :        9078 :                       usage_insns[regno].calls_num = calls_num;
    7139                 :        9078 :                       remove_from_hard_reg_set
    7140                 :        9078 :                         (&full_and_partial_call_clobbers,
    7141                 :        9078 :                          GET_MODE (cheap), hard_regno);
    7142                 :        9078 :                       bitmap_set_bit (&check_only_regs, regno);
    7143                 :             :                     }
    7144                 :             :                 }
    7145                 :             :             }
    7146                 :   186678604 :           to_inherit_num = 0;
    7147                 :             :           /* Process insn usages.  */
    7148                 :   560035812 :           for (iter = 0; iter < 2; iter++)
    7149                 :   373357208 :             for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
    7150                 :   600298211 :                  reg != NULL;
    7151                 :   226941003 :                  reg = reg->next)
    7152                 :   226941003 :               if ((reg->type != OP_OUT
    7153                 :    90401379 :                    || (reg->type == OP_OUT && reg->subreg_p))
    7154                 :   227493707 :                   && (src_regno = reg->regno) < lra_constraint_new_regno_start)
    7155                 :             :                 {
    7156                 :   125574393 :                   if (src_regno >= FIRST_PSEUDO_REGISTER
    7157                 :    72969329 :                       && reg_renumber[src_regno] < 0 && reg->type == OP_IN)
    7158                 :             :                     {
    7159                 :     2462290 :                       if (usage_insns[src_regno].check == curr_usage_insns_check
    7160                 :      761900 :                           && (next_usage_insns
    7161                 :      761900 :                               = usage_insns[src_regno].insns) != NULL_RTX
    7162                 :     3224190 :                           && NONDEBUG_INSN_P (curr_insn))
    7163                 :      181952 :                         add_to_inherit (src_regno, next_usage_insns);
    7164                 :     4560676 :                       else if (usage_insns[src_regno].check
    7165                 :     2280338 :                                != -(int) INSN_UID (curr_insn))
    7166                 :             :                         /* Add usages but only if the reg is not set up
    7167                 :             :                            in the same insn.  */
    7168                 :     2280338 :                         add_next_usage_insn (src_regno, curr_insn, reloads_num);
    7169                 :             :                     }
    7170                 :    70507039 :                   else if (src_regno < FIRST_PSEUDO_REGISTER
    7171                 :    70507039 :                            || reg_renumber[src_regno] >= 0)
    7172                 :             :                     {
    7173                 :   122972843 :                       bool before_p;
    7174                 :   122972843 :                       rtx_insn *use_insn = curr_insn;
    7175                 :   122972843 :                       rtx_insn *prev_insn = PREV_INSN (curr_insn);
    7176                 :             : 
    7177                 :   245945686 :                       before_p = (JUMP_P (curr_insn)
    7178                 :   122972843 :                                   || (CALL_P (curr_insn) && reg->type == OP_IN));
    7179                 :   122972843 :                       if (NONDEBUG_INSN_P (curr_insn)
    7180                 :   109744015 :                           && (! JUMP_P (curr_insn) || reg->type == OP_IN)
    7181                 :   232716752 :                           && split_if_necessary (src_regno, reg->biggest_mode,
    7182                 :             :                                                  potential_reload_hard_regs,
    7183                 :             :                                                  before_p, curr_insn, max_uid))
    7184                 :             :                         {
    7185                 :      213394 :                           if (reg->subreg_p)
    7186                 :        3187 :                             check_and_force_assignment_correctness_p = true;
    7187                 :      213394 :                           change_p = true;
    7188                 :             :                           /* Invalidate. */
    7189                 :      213394 :                           usage_insns[src_regno].check = 0;
    7190                 :      213394 :                           if (before_p && PREV_INSN (curr_insn) != prev_insn)
    7191                 :             :                             use_insn = PREV_INSN (curr_insn);
    7192                 :             :                         }
    7193                 :   122972843 :                       if (NONDEBUG_INSN_P (curr_insn))
    7194                 :             :                         {
    7195                 :   109744015 :                           if (src_regno < FIRST_PSEUDO_REGISTER)
    7196                 :    47665904 :                             add_to_hard_reg_set (&live_hard_regs,
    7197                 :    47665904 :                                                  reg->biggest_mode, src_regno);
    7198                 :             :                           else
    7199                 :    62078111 :                             add_to_hard_reg_set (&live_hard_regs,
    7200                 :    62078111 :                                                  PSEUDO_REGNO_MODE (src_regno),
    7201                 :    62078111 :                                                  reg_renumber[src_regno]);
    7202                 :             :                         }
    7203                 :   122972843 :                       if (src_regno >= FIRST_PSEUDO_REGISTER)
    7204                 :    70367779 :                         add_next_usage_insn (src_regno, use_insn, reloads_num);
    7205                 :             :                       else
    7206                 :             :                         {
    7207                 :   105307922 :                           for (i = 0; i < hard_regno_nregs (src_regno, reg->biggest_mode); i++)
    7208                 :    52702858 :                             add_next_usage_insn (src_regno + i, use_insn, reloads_num);
    7209                 :             :                         }
    7210                 :             :                     }
    7211                 :             :                 }
    7212                 :             :           /* Process used call regs.  */
    7213                 :   186678604 :           if (curr_id->arg_hard_regs != NULL)
    7214                 :    20117626 :             for (i = 0; (src_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
    7215                 :    14375337 :               if (src_regno < FIRST_PSEUDO_REGISTER)
    7216                 :             :                 {
    7217                 :    13569750 :                    SET_HARD_REG_BIT (live_hard_regs, src_regno);
    7218                 :    13569750 :                    add_next_usage_insn (src_regno, curr_insn, reloads_num);
    7219                 :             :                 }
    7220                 :   186860556 :           for (i = 0; i < to_inherit_num; i++)
    7221                 :             :             {
    7222                 :      181952 :               src_regno = to_inherit[i].regno;
    7223                 :      181952 :               if (inherit_reload_reg (false, src_regno, ALL_REGS,
    7224                 :             :                                       curr_insn, to_inherit[i].insns))
    7225                 :             :                 change_p = true;
    7226                 :             :               else
    7227                 :       22321 :                 setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
    7228                 :             :             }
    7229                 :             :         }
    7230                 :   186750242 :       if (update_reloads_num_p
    7231                 :   222539962 :           && NONDEBUG_INSN_P (curr_insn) && curr_set != NULL_RTX)
    7232                 :             :         {
    7233                 :   111066296 :           int regno = -1;
    7234                 :   111066296 :           if ((REG_P (SET_DEST (curr_set))
    7235                 :    81145373 :                && (regno = REGNO (SET_DEST (curr_set))) >= lra_constraint_new_regno_start
    7236                 :     8233242 :                && reg_renumber[regno] < 0
    7237                 :     5259326 :                && (cl = lra_get_allocno_class (regno)) != NO_REGS)
    7238                 :   187221597 :               || (REG_P (SET_SRC (curr_set))
    7239                 :    35240503 :                   && (regno = REGNO (SET_SRC (curr_set))) >= lra_constraint_new_regno_start
    7240                 :     6052672 :                   && reg_renumber[regno] < 0
    7241                 :     3549767 :                   && (cl = lra_get_allocno_class (regno)) != NO_REGS))
    7242                 :             :             {
    7243                 :     8285203 :               if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
    7244                 :      204303 :                 reloads_num++;
    7245                 :    16570406 :               if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
    7246                 :   225832356 :                 potential_reload_hard_regs |= reg_class_contents[cl];
    7247                 :             :             }
    7248                 :             :         }
    7249                 :   225832356 :       if (NONDEBUG_INSN_P (curr_insn))
    7250                 :             :         {
    7251                 :   120753176 :           int regno;
    7252                 :             : 
    7253                 :             :           /* Invalidate invariants with changed regs.  */
    7254                 :   120753176 :           curr_id = lra_get_insn_recog_data (curr_insn);
    7255                 :   308064385 :           for (reg = curr_id->regs; reg != NULL; reg = reg->next)
    7256                 :   187311209 :             if (reg->type != OP_IN)
    7257                 :             :               {
    7258                 :    80988927 :                 bitmap_set_bit (&invalid_invariant_regs, reg->regno);
    7259                 :   161977854 :                 bitmap_set_bit (&invalid_invariant_regs,
    7260                 :    80988927 :                                 ORIGINAL_REGNO (regno_reg_rtx[reg->regno]));
    7261                 :             :               }
    7262                 :   120753176 :           curr_static_id = curr_id->insn_static_data;
    7263                 :   152329643 :           for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
    7264                 :    31576467 :             if (reg->type != OP_IN)
    7265                 :    22621565 :               bitmap_set_bit (&invalid_invariant_regs, reg->regno);
    7266                 :   120753176 :           if (curr_id->arg_hard_regs != NULL)
    7267                 :    20117626 :             for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
    7268                 :    14375337 :               if (regno >= FIRST_PSEUDO_REGISTER)
    7269                 :      805587 :                 bitmap_set_bit (&invalid_invariant_regs,
    7270                 :             :                                 regno - FIRST_PSEUDO_REGISTER);
    7271                 :             :         }
    7272                 :             :       /* We reached the start of the current basic block.  */
    7273                 :   225832348 :       if (prev_insn == NULL_RTX || prev_insn == PREV_INSN (head)
    7274                 :   438742163 :           || BLOCK_FOR_INSN (prev_insn) != curr_bb)
    7275                 :             :         {
    7276                 :             :           /* We reached the beginning of the current block -- do
    7277                 :             :              rest of spliting in the current BB.  */
    7278                 :    18720281 :           to_process = df_get_live_in (curr_bb);
    7279                 :    18720281 :           if (BLOCK_FOR_INSN (head) != curr_bb)
    7280                 :             :             {
    7281                 :             :               /* We are somewhere in the middle of EBB.  */
    7282                 :     5797732 :               get_live_on_other_edges (EDGE_PRED (curr_bb, 0)->src,
    7283                 :             :                                        curr_bb, &temp_bitmap);
    7284                 :     5797732 :               to_process = &temp_bitmap;
    7285                 :             :             }
    7286                 :    18720281 :           head_p = true;
    7287                 :   195162908 :           EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
    7288                 :             :             {
    7289                 :   176442635 :               if ((int) j >= lra_constraint_new_regno_start)
    7290                 :             :                 break;
    7291                 :   112253629 :               if (((int) j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
    7292                 :   110859687 :                   && usage_insns[j].check == curr_usage_insns_check
    7293                 :   285446093 :                   && (next_usage_insns = usage_insns[j].insns) != NULL_RTX)
    7294                 :             :                 {
    7295                 :   109003466 :                   if (need_for_split_p (potential_reload_hard_regs, j))
    7296                 :             :                     {
    7297                 :      332014 :                       if (lra_dump_file != NULL && head_p)
    7298                 :             :                         {
    7299                 :           0 :                           fprintf (lra_dump_file,
    7300                 :             :                                    "  ----------------------------------\n");
    7301                 :           0 :                           head_p = false;
    7302                 :             :                         }
    7303                 :      332014 :                       if (split_reg (false, j, bb_note (curr_bb),
    7304                 :             :                                      next_usage_insns, NULL))
    7305                 :      332014 :                         change_p = true;
    7306                 :             :                     }
    7307                 :   109003466 :                   usage_insns[j].check = 0;
    7308                 :             :                 }
    7309                 :             :             }
    7310                 :             :         }
    7311                 :             :     }
    7312                 :    12922549 :   first_call_insn = NULL;
    7313                 :    12922549 :   return change_p;
    7314                 :             : }
    7315                 :             : 
    7316                 :             : /* This value affects EBB forming.  If probability of edge from EBB to
    7317                 :             :    a BB is not greater than the following value, we don't add the BB
    7318                 :             :    to EBB.  */
    7319                 :             : #define EBB_PROBABILITY_CUTOFF \
    7320                 :             :   ((REG_BR_PROB_BASE * param_lra_inheritance_ebb_probability_cutoff) / 100)
    7321                 :             : 
    7322                 :             : /* Current number of inheritance/split iteration.  */
    7323                 :             : int lra_inheritance_iter;
    7324                 :             : 
    7325                 :             : /* Entry function for inheritance/split pass.  */
    7326                 :             : void
    7327                 :     1549104 : lra_inheritance (void)
    7328                 :             : {
    7329                 :     1549104 :   int i;
    7330                 :     1549104 :   basic_block bb, start_bb;
    7331                 :     1549104 :   edge e;
    7332                 :             : 
    7333                 :     1549104 :   lra_inheritance_iter++;
    7334                 :     1549104 :   if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
    7335                 :             :     return;
    7336                 :     1546122 :   timevar_push (TV_LRA_INHERITANCE);
    7337                 :     1546122 :   if (lra_dump_file != NULL)
    7338                 :          97 :     fprintf (lra_dump_file, "\n********** Inheritance #%d: **********\n\n",
    7339                 :             :              lra_inheritance_iter);
    7340                 :     1546122 :   curr_usage_insns_check = 0;
    7341                 :     1546122 :   usage_insns = XNEWVEC (struct usage_insns, lra_constraint_new_regno_start);
    7342                 :   229496760 :   for (i = 0; i < lra_constraint_new_regno_start; i++)
    7343                 :   227950638 :     usage_insns[i].check = 0;
    7344                 :     1546122 :   bitmap_initialize (&check_only_regs, &reg_obstack);
    7345                 :     1546122 :   bitmap_initialize (&invalid_invariant_regs, &reg_obstack);
    7346                 :     1546122 :   bitmap_initialize (&live_regs, &reg_obstack);
    7347                 :     1546122 :   bitmap_initialize (&temp_bitmap, &reg_obstack);
    7348                 :     1546122 :   bitmap_initialize (&ebb_global_regs, &reg_obstack);
    7349                 :    14468671 :   FOR_EACH_BB_FN (bb, cfun)
    7350                 :             :     {
    7351                 :    12922549 :       start_bb = bb;
    7352                 :    12922549 :       if (lra_dump_file != NULL)
    7353                 :         347 :         fprintf (lra_dump_file, "EBB");
    7354                 :             :       /* Form a EBB starting with BB.  */
    7355                 :    12922549 :       bitmap_clear (&ebb_global_regs);
    7356                 :    12922549 :       bitmap_ior_into (&ebb_global_regs, df_get_live_in (bb));
    7357                 :    18720043 :       for (;;)
    7358                 :             :         {
    7359                 :    18720043 :           if (lra_dump_file != NULL)
    7360                 :         487 :             fprintf (lra_dump_file, " %d", bb->index);
    7361                 :    18720043 :           if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
    7362                 :    17173921 :               || LABEL_P (BB_HEAD (bb->next_bb)))
    7363                 :             :             break;
    7364                 :     8250240 :           e = find_fallthru_edge (bb->succs);
    7365                 :     8250240 :           if (! e)
    7366                 :             :             break;
    7367                 :     8250240 :           if (e->probability.initialized_p ()
    7368                 :     8250240 :               && e->probability.to_reg_br_prob_base () < EBB_PROBABILITY_CUTOFF)
    7369                 :             :             break;
    7370                 :             :           bb = bb->next_bb;
    7371                 :             :         }
    7372                 :    12922549 :       bitmap_ior_into (&ebb_global_regs, df_get_live_out (bb));
    7373                 :    12922549 :       if (lra_dump_file != NULL)
    7374                 :         347 :         fprintf (lra_dump_file, "\n");
    7375                 :    12922549 :       if (inherit_in_ebb (BB_HEAD (start_bb), BB_END (bb)))
    7376                 :             :         /* Remember that the EBB head and tail can change in
    7377                 :             :            inherit_in_ebb.  */
    7378                 :      728196 :         update_ebb_live_info (BB_HEAD (start_bb), BB_END (bb));
    7379                 :             :     }
    7380                 :     1546122 :   bitmap_release (&ebb_global_regs);
    7381                 :     1546122 :   bitmap_release (&temp_bitmap);
    7382                 :     1546122 :   bitmap_release (&live_regs);
    7383                 :     1546122 :   bitmap_release (&invalid_invariant_regs);
    7384                 :     1546122 :   bitmap_release (&check_only_regs);
    7385                 :     1546122 :   free (usage_insns);
    7386                 :     1546122 :   lra_dump_insns_if_possible ("func after inheritance");
    7387                 :     1546122 :   timevar_pop (TV_LRA_INHERITANCE);
    7388                 :             : }
    7389                 :             : 
    7390                 :             : 
    7391                 :             : 
    7392                 :             : /* This page contains code to undo failed inheritance/split
    7393                 :             :    transformations.  */
    7394                 :             : 
    7395                 :             : /* Current number of iteration undoing inheritance/split.  */
    7396                 :             : int lra_undo_inheritance_iter;
    7397                 :             : 
    7398                 :             : /* Fix BB live info LIVE after removing pseudos created on pass doing
    7399                 :             :    inheritance/split which are REMOVED_PSEUDOS.  */
    7400                 :             : static void
    7401                 :    37440086 : fix_bb_live_info (bitmap live, bitmap removed_pseudos)
    7402                 :             : {
    7403                 :    37440086 :   unsigned int regno;
    7404                 :    37440086 :   bitmap_iterator bi;
    7405                 :             : 
    7406                 :   257320710 :   EXECUTE_IF_SET_IN_BITMAP (removed_pseudos, 0, regno, bi)
    7407                 :   219880624 :     if (bitmap_clear_bit (live, regno)
    7408                 :   219880624 :         && REG_P (lra_reg_info[regno].restore_rtx))
    7409                 :     1201756 :       bitmap_set_bit (live, REGNO (lra_reg_info[regno].restore_rtx));
    7410                 :    37440086 : }
    7411                 :             : 
    7412                 :             : /* Return regno of the (subreg of) REG. Otherwise, return a negative
    7413                 :             :    number.  */
    7414                 :             : static int
    7415                 :    66704030 : get_regno (rtx reg)
    7416                 :             : {
    7417                 :     1136877 :   if (GET_CODE (reg) == SUBREG)
    7418                 :     1034148 :     reg = SUBREG_REG (reg);
    7419                 :    66704030 :   if (REG_P (reg))
    7420                 :    43183531 :     return REGNO (reg);
    7421                 :             :   return -1;
    7422                 :             : }
    7423                 :             : 
    7424                 :             : /* Delete a move INSN with destination reg DREGNO and a previous
    7425                 :             :    clobber insn with the same regno.  The inheritance/split code can
    7426                 :             :    generate moves with preceding clobber and when we delete such moves
    7427                 :             :    we should delete the clobber insn too to keep the correct life
    7428                 :             :    info.  */
    7429                 :             : static void
    7430                 :      767807 : delete_move_and_clobber (rtx_insn *insn, int dregno)
    7431                 :             : {
    7432                 :      767807 :   rtx_insn *prev_insn = PREV_INSN (insn);
    7433                 :             : 
    7434                 :      767807 :   lra_set_insn_deleted (insn);
    7435                 :      767807 :   lra_assert (dregno >= 0);
    7436                 :      767807 :   if (prev_insn != NULL && NONDEBUG_INSN_P (prev_insn)
    7437                 :      322931 :       && GET_CODE (PATTERN (prev_insn)) == CLOBBER
    7438                 :      768151 :       && dregno == get_regno (XEXP (PATTERN (prev_insn), 0)))
    7439                 :           0 :     lra_set_insn_deleted (prev_insn);
    7440                 :      767807 : }
    7441                 :             : 
    7442                 :             : /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
    7443                 :             :    return true if we did any change.  The undo transformations for
    7444                 :             :    inheritance looks like
    7445                 :             :       i <- i2
    7446                 :             :       p <- i   =>   p <- i2
    7447                 :             :    or removing
    7448                 :             :       p <- i, i <- p, and i <- i3
    7449                 :             :    where p is original pseudo from which inheritance pseudo i was
    7450                 :             :    created, i and i3 are removed inheritance pseudos, i2 is another
    7451                 :             :    not removed inheritance pseudo.  All split pseudos or other
    7452                 :             :    occurrences of removed inheritance pseudos are changed on the
    7453                 :             :    corresponding original pseudos.
    7454                 :             : 
    7455                 :             :    The function also schedules insns changed and created during
    7456                 :             :    inheritance/split pass for processing by the subsequent constraint
    7457                 :             :    pass.  */
    7458                 :             : static bool
    7459                 :     1546122 : remove_inheritance_pseudos (bitmap remove_pseudos)
    7460                 :             : {
    7461                 :     1546122 :   basic_block bb;
    7462                 :     1546122 :   int regno, sregno, prev_sregno, dregno;
    7463                 :     1546122 :   rtx restore_rtx;
    7464                 :     1546122 :   rtx set, prev_set;
    7465                 :     1546122 :   rtx_insn *prev_insn;
    7466                 :     1546122 :   bool change_p, done_p;
    7467                 :             : 
    7468                 :     1546122 :   change_p = ! bitmap_empty_p (remove_pseudos);
    7469                 :             :   /* We cannot finish the function right away if CHANGE_P is true
    7470                 :             :      because we need to marks insns affected by previous
    7471                 :             :      inheritance/split pass for processing by the subsequent
    7472                 :             :      constraint pass.  */
    7473                 :    20266165 :   FOR_EACH_BB_FN (bb, cfun)
    7474                 :             :     {
    7475                 :    18720043 :       fix_bb_live_info (df_get_live_in (bb), remove_pseudos);
    7476                 :    18720043 :       fix_bb_live_info (df_get_live_out (bb), remove_pseudos);
    7477                 :   246964158 :       FOR_BB_INSNS_REVERSE (bb, curr_insn)
    7478                 :             :         {
    7479                 :   228244115 :           if (! INSN_P (curr_insn))
    7480                 :    36209390 :             continue;
    7481                 :   192034725 :           done_p = false;
    7482                 :   192034725 :           sregno = dregno = -1;
    7483                 :    44812094 :           if (change_p && NONDEBUG_INSN_P (curr_insn)
    7484                 :   223461092 :               && (set = single_set (curr_insn)) != NULL_RTX)
    7485                 :             :             {
    7486                 :    30424264 :               dregno = get_regno (SET_DEST (set));
    7487                 :    60848528 :               sregno = get_regno (SET_SRC (set));
    7488                 :             :             }
    7489                 :             : 
    7490                 :   192034725 :           if (sregno >= 0 && dregno >= 0)
    7491                 :             :             {
    7492                 :    10714081 :               if (bitmap_bit_p (remove_pseudos, dregno)
    7493                 :    10714081 :                   && ! REG_P (lra_reg_info[dregno].restore_rtx))
    7494                 :             :                 {
    7495                 :             :                   /* invariant inheritance pseudo <- original pseudo */
    7496                 :        6666 :                   if (lra_dump_file != NULL)
    7497                 :             :                     {
    7498                 :           0 :                       fprintf (lra_dump_file, "       Removing invariant inheritance:\n");
    7499                 :           0 :                       dump_insn_slim (lra_dump_file, curr_insn);
    7500                 :           0 :                       fprintf (lra_dump_file, "\n");
    7501                 :             :                     }
    7502                 :        6666 :                   delete_move_and_clobber (curr_insn, dregno);
    7503                 :        6666 :                   done_p = true;
    7504                 :             :                 }
    7505                 :    10707415 :               else if (bitmap_bit_p (remove_pseudos, sregno)
    7506                 :    10707415 :                        && ! REG_P (lra_reg_info[sregno].restore_rtx))
    7507                 :             :                 {
    7508                 :             :                   /* reload pseudo <- invariant inheritance pseudo */
    7509                 :        6666 :                   start_sequence ();
    7510                 :             :                   /* We cannot just change the source.  It might be
    7511                 :             :                      an insn different from the move.  */
    7512                 :        6666 :                   emit_insn (lra_reg_info[sregno].restore_rtx);
    7513                 :        6666 :                   rtx_insn *new_insns = end_sequence ();
    7514                 :        6666 :                   lra_assert (single_set (new_insns) != NULL
    7515                 :             :                               && SET_DEST (set) == SET_DEST (single_set (new_insns)));
    7516                 :        6666 :                   lra_process_new_insns (curr_insn, NULL, new_insns,
    7517                 :             :                                          "Changing reload<-invariant inheritance");
    7518                 :        6666 :                   delete_move_and_clobber (curr_insn, dregno);
    7519                 :        6666 :                   done_p = true;
    7520                 :             :                 }
    7521                 :    10700749 :               else if ((bitmap_bit_p (remove_pseudos, sregno)
    7522                 :     1215004 :                         && (get_regno (lra_reg_info[sregno].restore_rtx) == dregno
    7523                 :      572313 :                             || (bitmap_bit_p (remove_pseudos, dregno)
    7524                 :      190652 :                                 && get_regno (lra_reg_info[sregno].restore_rtx) >= 0
    7525                 :      190652 :                                 && (get_regno (lra_reg_info[sregno].restore_rtx)
    7526                 :      190652 :                                     == get_regno (lra_reg_info[dregno].restore_rtx)))))
    7527                 :    11177736 :                        || (bitmap_bit_p (remove_pseudos, dregno)
    7528                 :      650598 :                            && get_regno (lra_reg_info[dregno].restore_rtx) == sregno))
    7529                 :             :                 /* One of the following cases:
    7530                 :             :                      original <- removed inheritance pseudo
    7531                 :             :                      removed inherit pseudo <- another removed inherit pseudo
    7532                 :             :                      removed inherit pseudo <- original pseudo
    7533                 :             :                    Or
    7534                 :             :                      removed_split_pseudo <- original_reg
    7535                 :             :                      original_reg <- removed_split_pseudo */
    7536                 :             :                 {
    7537                 :      177635 :                   if (lra_dump_file != NULL)
    7538                 :             :                     {
    7539                 :           0 :                       fprintf (lra_dump_file, "       Removing %s:\n",
    7540                 :           0 :                                bitmap_bit_p (&lra_split_regs, sregno)
    7541                 :           0 :                                || bitmap_bit_p (&lra_split_regs, dregno)
    7542                 :             :                                ? "split" : "inheritance");
    7543                 :           0 :                       dump_insn_slim (lra_dump_file, curr_insn);
    7544                 :             :                     }
    7545                 :      177635 :                   delete_move_and_clobber (curr_insn, dregno);
    7546                 :      177635 :                   done_p = true;
    7547                 :             :                 }
    7548                 :    10523114 :               else if (bitmap_bit_p (remove_pseudos, sregno)
    7549                 :    10523114 :                        && bitmap_bit_p (&lra_inheritance_pseudos, sregno))
    7550                 :             :                 {
    7551                 :             :                   /* Search the following pattern:
    7552                 :             :                        inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
    7553                 :             :                        original_pseudo <- inherit_or_split_pseudo1
    7554                 :             :                     where the 2nd insn is the current insn and
    7555                 :             :                     inherit_or_split_pseudo2 is not removed.  If it is found,
    7556                 :             :                     change the current insn onto:
    7557                 :             :                        original_pseudo <- inherit_or_split_pseudo2.  */
    7558                 :      725018 :                   for (prev_insn = PREV_INSN (curr_insn);
    7559                 :      725018 :                        prev_insn != NULL_RTX && ! NONDEBUG_INSN_P (prev_insn);
    7560                 :      248031 :                        prev_insn = PREV_INSN (prev_insn))
    7561                 :             :                     ;
    7562                 :      476987 :                   if (prev_insn != NULL_RTX && BLOCK_FOR_INSN (prev_insn) == bb
    7563                 :      464060 :                       && (prev_set = single_set (prev_insn)) != NULL_RTX
    7564                 :             :                       /* There should be no subregs in insn we are
    7565                 :             :                          searching because only the original reg might
    7566                 :             :                          be in subreg when we changed the mode of
    7567                 :             :                          load/store for splitting.  */
    7568                 :      458240 :                       && REG_P (SET_DEST (prev_set))
    7569                 :      355161 :                       && REG_P (SET_SRC (prev_set))
    7570                 :      272344 :                       && (int) REGNO (SET_DEST (prev_set)) == sregno
    7571                 :      184938 :                       && ((prev_sregno = REGNO (SET_SRC (prev_set)))
    7572                 :             :                           >= FIRST_PSEUDO_REGISTER)
    7573                 :      184938 :                       && (lra_reg_info[prev_sregno].restore_rtx == NULL_RTX
    7574                 :      144173 :                           ||
    7575                 :             :                           /* As we consider chain of inheritance or
    7576                 :             :                              splitting described in above comment we should
    7577                 :             :                              check that sregno and prev_sregno were
    7578                 :             :                              inheritance/split pseudos created from the
    7579                 :             :                              same original regno.  */
    7580                 :      288346 :                           (get_regno (lra_reg_info[sregno].restore_rtx) >= 0
    7581                 :      288346 :                            && (get_regno (lra_reg_info[sregno].restore_rtx)
    7582                 :      288346 :                                == get_regno (lra_reg_info[prev_sregno].restore_rtx))))
    7583                 :      661925 :                       && ! bitmap_bit_p (remove_pseudos, prev_sregno))
    7584                 :             :                     {
    7585                 :      101795 :                       int restore_regno = get_regno (lra_reg_info[sregno].restore_rtx);
    7586                 :      101795 :                       if (restore_regno < 0)
    7587                 :           0 :                         restore_regno = prev_sregno;
    7588                 :      101795 :                       lra_assert (GET_MODE (SET_SRC (prev_set))
    7589                 :             :                                   == GET_MODE (regno_reg_rtx[restore_regno]));
    7590                 :             :                       /* Although we have a single set, the insn can
    7591                 :             :                          contain more one sregno register occurrence
    7592                 :             :                          as a source.  Change all occurrences.  */
    7593                 :      101795 :                       lra_substitute_pseudo_within_insn (curr_insn, sregno,
    7594                 :             :                                                          regno_reg_rtx[restore_regno],
    7595                 :             :                                                          false);
    7596                 :             :                       /* As we are finishing with processing the insn
    7597                 :             :                          here, check the destination too as it might
    7598                 :             :                          inheritance pseudo for another pseudo.  */
    7599                 :      101795 :                       if (bitmap_bit_p (remove_pseudos, dregno)
    7600                 :           0 :                           && bitmap_bit_p (&lra_inheritance_pseudos, dregno)
    7601                 :      101795 :                           && (restore_rtx
    7602                 :           0 :                               = lra_reg_info[dregno].restore_rtx) != NULL_RTX)
    7603                 :             :                         {
    7604                 :           0 :                           if (GET_CODE (SET_DEST (set)) == SUBREG)
    7605                 :           0 :                             SUBREG_REG (SET_DEST (set)) = restore_rtx;
    7606                 :             :                           else
    7607                 :           0 :                             SET_DEST (set) = restore_rtx;
    7608                 :             :                         }
    7609                 :      101795 :                       lra_push_insn_and_update_insn_regno_info (curr_insn);
    7610                 :      101795 :                       lra_set_used_insn_alternative_by_uid
    7611                 :      101795 :                         (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
    7612                 :      101795 :                       done_p = true;
    7613                 :      101795 :                       if (lra_dump_file != NULL)
    7614                 :             :                         {
    7615                 :           0 :                           fprintf (lra_dump_file, "    Change reload insn:\n");
    7616                 :           0 :                           dump_insn_slim (lra_dump_file, curr_insn);
    7617                 :             :                         }
    7618                 :             :                     }
    7619                 :             :                 }
    7620                 :             :             }
    7621                 :      190967 :           if (! done_p)
    7622                 :             :             {
    7623                 :   191741963 :               struct lra_insn_reg *reg;
    7624                 :   191741963 :               bool restored_regs_p = false;
    7625                 :   191741963 :               bool kept_regs_p = false;
    7626                 :             : 
    7627                 :   191741963 :               curr_id = lra_get_insn_recog_data (curr_insn);
    7628                 :   397092611 :               for (reg = curr_id->regs; reg != NULL; reg = reg->next)
    7629                 :             :                 {
    7630                 :   205350648 :                   regno = reg->regno;
    7631                 :   205350648 :                   restore_rtx = lra_reg_info[regno].restore_rtx;
    7632                 :   205350648 :                   if (restore_rtx != NULL_RTX)
    7633                 :             :                     {
    7634                 :     5790688 :                       if (change_p && bitmap_bit_p (remove_pseudos, regno))
    7635                 :             :                         {
    7636                 :      831203 :                           lra_substitute_pseudo_within_insn
    7637                 :      831203 :                             (curr_insn, regno, restore_rtx, false);
    7638                 :      831203 :                           restored_regs_p = true;
    7639                 :             :                         }
    7640                 :             :                       else
    7641                 :             :                         kept_regs_p = true;
    7642                 :             :                     }
    7643                 :             :                 }
    7644                 :   191741963 :               if (NONDEBUG_INSN_P (curr_insn) && kept_regs_p)
    7645                 :             :                 {
    7646                 :             :                   /* The instruction has changed since the previous
    7647                 :             :                      constraints pass.  */
    7648                 :     4373499 :                   lra_push_insn_and_update_insn_regno_info (curr_insn);
    7649                 :     4373499 :                   lra_set_used_insn_alternative_by_uid
    7650                 :     4373499 :                     (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
    7651                 :             :                 }
    7652                 :   187368464 :               else if (restored_regs_p)
    7653                 :             :                 /* The instruction has been restored to the form that
    7654                 :             :                    it had during the previous constraints pass.  */
    7655                 :      663525 :                 lra_update_insn_regno_info (curr_insn);
    7656                 :     5037024 :               if (restored_regs_p && lra_dump_file != NULL)
    7657                 :             :                 {
    7658                 :           0 :                   fprintf (lra_dump_file, "   Insn after restoring regs:\n");
    7659                 :           0 :                   dump_insn_slim (lra_dump_file, curr_insn);
    7660                 :             :                 }
    7661                 :             :             }
    7662                 :             :         }
    7663                 :             :     }
    7664                 :     1546122 :   return change_p;
    7665                 :             : }
    7666                 :             : 
    7667                 :             : /* If optional reload pseudos failed to get a hard register or was not
    7668                 :             :    inherited, it is better to remove optional reloads.  We do this
    7669                 :             :    transformation after undoing inheritance to figure out necessity to
    7670                 :             :    remove optional reloads easier.  Return true if we do any
    7671                 :             :    change.  */
    7672                 :             : static bool
    7673                 :     1546122 : undo_optional_reloads (void)
    7674                 :             : {
    7675                 :     1546122 :   bool change_p, keep_p;
    7676                 :     1546122 :   unsigned int regno, uid;
    7677                 :     1546122 :   bitmap_iterator bi, bi2;
    7678                 :     1546122 :   rtx_insn *insn;
    7679                 :     1546122 :   rtx set, src, dest;
    7680                 :     1546122 :   auto_bitmap removed_optional_reload_pseudos (&reg_obstack);
    7681                 :             : 
    7682                 :     1546122 :   bitmap_copy (removed_optional_reload_pseudos, &lra_optional_reload_pseudos);
    7683                 :     2588154 :   EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
    7684                 :             :     {
    7685                 :     1042032 :       keep_p = false;
    7686                 :             :       /* Keep optional reloads from previous subpasses.  */
    7687                 :     1042032 :       if (lra_reg_info[regno].restore_rtx == NULL_RTX
    7688                 :             :           /* If the original pseudo changed its allocation, just
    7689                 :             :              removing the optional pseudo is dangerous as the original
    7690                 :             :              pseudo will have longer live range.  */
    7691                 :     1042032 :           || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] >= 0)
    7692                 :             :         keep_p = true;
    7693                 :      642101 :       else if (reg_renumber[regno] >= 0)
    7694                 :     1836209 :         EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi2)
    7695                 :             :           {
    7696                 :     1332215 :             insn = lra_insn_recog_data[uid]->insn;
    7697                 :     1332215 :             if ((set = single_set (insn)) == NULL_RTX)
    7698                 :        6698 :               continue;
    7699                 :     1325517 :             src = SET_SRC (set);
    7700                 :     1325517 :             dest = SET_DEST (set);
    7701                 :     1325517 :             if ((! REG_P (src) && ! SUBREG_P (src))
    7702                 :      708512 :                 || (! REG_P (dest) && ! SUBREG_P (dest)))
    7703                 :      617033 :               continue;
    7704                 :      708484 :             if (get_regno (dest) == (int) regno
    7705                 :             :                 /* Ignore insn for optional reloads itself.  */
    7706                 :     1195614 :                 && (get_regno (lra_reg_info[regno].restore_rtx)
    7707                 :      597807 :                     != get_regno (src))
    7708                 :             :                 /* Check only inheritance on last inheritance pass.  */
    7709                 :      119737 :                 && get_regno (src) >= new_regno_start
    7710                 :             :                 /* Check that the optional reload was inherited.  */
    7711                 :      828221 :                 && bitmap_bit_p (&lra_inheritance_pseudos, get_regno (src)))
    7712                 :             :               {
    7713                 :             :                 keep_p = true;
    7714                 :             :                 break;
    7715                 :             :               }
    7716                 :             :           }
    7717                 :     1023662 :       if (keep_p)
    7718                 :             :         {
    7719                 :      519668 :           bitmap_clear_bit (removed_optional_reload_pseudos, regno);
    7720                 :      519668 :           if (lra_dump_file != NULL)
    7721                 :           3 :             fprintf (lra_dump_file, "Keep optional reload reg %d\n", regno);
    7722                 :             :         }
    7723                 :             :     }
    7724                 :     1546122 :   change_p = ! bitmap_empty_p (removed_optional_reload_pseudos);
    7725                 :     1546122 :   auto_bitmap insn_bitmap (&reg_obstack);
    7726                 :     2068486 :   EXECUTE_IF_SET_IN_BITMAP (removed_optional_reload_pseudos, 0, regno, bi)
    7727                 :             :     {
    7728                 :      522364 :       if (lra_dump_file != NULL)
    7729                 :           2 :         fprintf (lra_dump_file, "Remove optional reload reg %d\n", regno);
    7730                 :      522364 :       bitmap_copy (insn_bitmap, &lra_reg_info[regno].insn_bitmap);
    7731                 :     1654152 :       EXECUTE_IF_SET_IN_BITMAP (insn_bitmap, 0, uid, bi2)
    7732                 :             :         {
    7733                 :             :           /* We may have already removed a clobber.  */
    7734                 :     1131788 :           if (!lra_insn_recog_data[uid])
    7735                 :           0 :             continue;
    7736                 :     1131788 :           insn = lra_insn_recog_data[uid]->insn;
    7737                 :     1131788 :           if ((set = single_set (insn)) != NULL_RTX)
    7738                 :             :             {
    7739                 :     1125798 :               src = SET_SRC (set);
    7740                 :     1125798 :               dest = SET_DEST (set);
    7741                 :      516359 :               if ((REG_P (src) || SUBREG_P (src))
    7742                 :      609451 :                   && (REG_P (dest) || SUBREG_P (dest))
    7743                 :     1735222 :                   && ((get_regno (src) == (int) regno
    7744                 :      228994 :                        && (get_regno (lra_reg_info[regno].restore_rtx)
    7745                 :      114497 :                            == get_regno (dest)))
    7746                 :      527453 :                       || (get_regno (dest) == (int) regno
    7747                 :      494927 :                           && (get_regno (lra_reg_info[regno].restore_rtx)
    7748                 :      494927 :                               == get_regno (src)))))
    7749                 :             :                 {
    7750                 :      576840 :                   if (lra_dump_file != NULL)
    7751                 :             :                     {
    7752                 :           0 :                       fprintf (lra_dump_file, "  Deleting move %u\n",
    7753                 :           0 :                                INSN_UID (insn));
    7754                 :           0 :                       dump_insn_slim (lra_dump_file, insn);
    7755                 :             :                     }
    7756                 :     1153680 :                   delete_move_and_clobber (insn, get_regno (dest));
    7757                 :      576840 :                   continue;
    7758                 :             :                 }
    7759                 :             :               /* We should not worry about generation memory-memory
    7760                 :             :                  moves here as if the corresponding inheritance did
    7761                 :             :                  not work (inheritance pseudo did not get a hard reg),
    7762                 :             :                  we remove the inheritance pseudo and the optional
    7763                 :             :                  reload.  */
    7764                 :             :             }
    7765                 :      554948 :           if (GET_CODE (PATTERN (insn)) == CLOBBER
    7766                 :           0 :               && REG_P (SET_DEST (insn))
    7767                 :      554948 :               && get_regno (SET_DEST (insn)) == (int) regno)
    7768                 :             :             /* Refuse to remap clobbers to preexisting pseudos.  */
    7769                 :           0 :             gcc_unreachable ();
    7770                 :      554948 :           lra_substitute_pseudo_within_insn
    7771                 :      554948 :             (insn, regno, lra_reg_info[regno].restore_rtx, false);
    7772                 :      554948 :           lra_update_insn_regno_info (insn);
    7773                 :      554948 :           if (lra_dump_file != NULL)
    7774                 :             :             {
    7775                 :           4 :               fprintf (lra_dump_file,
    7776                 :             :                        "  Restoring original insn:\n");
    7777                 :           4 :               dump_insn_slim (lra_dump_file, insn);
    7778                 :             :             }
    7779                 :             :         }
    7780                 :             :     }
    7781                 :             :   /* Clear restore_regnos.  */
    7782                 :     2588154 :   EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
    7783                 :     1042032 :     lra_reg_info[regno].restore_rtx = NULL_RTX;
    7784                 :     1546122 :   return change_p;
    7785                 :     1546122 : }
    7786                 :             : 
    7787                 :             : /* Entry function for undoing inheritance/split transformation.  Return true
    7788                 :             :    if we did any RTL change in this pass.  */
    7789                 :             : bool
    7790                 :     1549104 : lra_undo_inheritance (void)
    7791                 :             : {
    7792                 :     1549104 :   unsigned int regno;
    7793                 :     1549104 :   int hard_regno;
    7794                 :     1549104 :   int n_all_inherit, n_inherit, n_all_split, n_split;
    7795                 :     1549104 :   rtx restore_rtx;
    7796                 :     1549104 :   bitmap_iterator bi;
    7797                 :     1549104 :   bool change_p;
    7798                 :             : 
    7799                 :     1549104 :   lra_undo_inheritance_iter++;
    7800                 :     1549104 :   if (lra_undo_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
    7801                 :             :     return false;
    7802                 :     1546122 :   if (lra_dump_file != NULL)
    7803                 :          97 :     fprintf (lra_dump_file,
    7804                 :             :              "\n********** Undoing inheritance #%d: **********\n\n",
    7805                 :             :              lra_undo_inheritance_iter);
    7806                 :     1546122 :   auto_bitmap remove_pseudos (&reg_obstack);
    7807                 :     1546122 :   n_inherit = n_all_inherit = 0;
    7808                 :     3404094 :   EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
    7809                 :     1857972 :     if (lra_reg_info[regno].restore_rtx != NULL_RTX)
    7810                 :             :       {
    7811                 :     1169861 :         n_all_inherit++;
    7812                 :     1169861 :         if (reg_renumber[regno] < 0
    7813                 :             :             /* If the original pseudo changed its allocation, just
    7814                 :             :                removing inheritance is dangerous as for changing
    7815                 :             :                allocation we used shorter live-ranges.  */
    7816                 :     1169861 :             && (! REG_P (lra_reg_info[regno].restore_rtx)
    7817                 :      421918 :                 || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] < 0))
    7818                 :      428584 :           bitmap_set_bit (remove_pseudos, regno);
    7819                 :             :         else
    7820                 :      741277 :           n_inherit++;
    7821                 :             :       }
    7822                 :     1546122 :   if (lra_dump_file != NULL && n_all_inherit != 0)
    7823                 :           2 :     fprintf (lra_dump_file, "Inherit %d out of %d (%.2f%%)\n",
    7824                 :             :              n_inherit, n_all_inherit,
    7825                 :           2 :              (double) n_inherit / n_all_inherit * 100);
    7826                 :     1546122 :   n_split = n_all_split = 0;
    7827                 :     2435040 :   EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
    7828                 :      888918 :     if ((restore_rtx = lra_reg_info[regno].restore_rtx) != NULL_RTX)
    7829                 :             :       {
    7830                 :      605734 :         int restore_regno = REGNO (restore_rtx);
    7831                 :             : 
    7832                 :      605734 :         n_all_split++;
    7833                 :     1211382 :         hard_regno = (restore_regno >= FIRST_PSEUDO_REGISTER
    7834                 :      605734 :                       ? reg_renumber[restore_regno] : restore_regno);
    7835                 :      605734 :         if (hard_regno < 0 || reg_renumber[regno] == hard_regno)
    7836                 :        2117 :           bitmap_set_bit (remove_pseudos, regno);
    7837                 :             :         else
    7838                 :             :           {
    7839                 :      603617 :             n_split++;
    7840                 :      603617 :             if (lra_dump_file != NULL)
    7841                 :           0 :               fprintf (lra_dump_file, "         Keep split r%d (orig=r%d)\n",
    7842                 :             :                        regno, restore_regno);
    7843                 :             :           }
    7844                 :             :       }
    7845                 :     1546122 :   if (lra_dump_file != NULL && n_all_split != 0)
    7846                 :           0 :     fprintf (lra_dump_file, "Split %d out of %d (%.2f%%)\n",
    7847                 :             :              n_split, n_all_split,
    7848                 :           0 :              (double) n_split / n_all_split * 100);
    7849                 :     1546122 :   change_p = remove_inheritance_pseudos (remove_pseudos);
    7850                 :             :   /* Clear restore_regnos.  */
    7851                 :     3404094 :   EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
    7852                 :     1857972 :     lra_reg_info[regno].restore_rtx = NULL_RTX;
    7853                 :     2435040 :   EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
    7854                 :      888918 :     lra_reg_info[regno].restore_rtx = NULL_RTX;
    7855                 :     1546122 :   change_p = undo_optional_reloads () || change_p;
    7856                 :             :   if (change_p)
    7857                 :      112085 :     lra_dump_insns_if_possible ("changed func after undoing inheritance");
    7858                 :     1546122 :   return change_p;
    7859                 :     1546122 : }
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.