LCOV - code coverage report
Current view: top level - gcc - lra-assigns.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.0 % 985 946
Test Date: 2026-02-28 14:20:25 Functions: 100.0 % 31 31
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Assign reload pseudos.
       2              :    Copyright (C) 2010-2026 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's main objective is to assign hard registers to reload
      23              :    pseudos.  It also tries to allocate hard registers to other
      24              :    pseudos, but at a lower priority than the reload pseudos.  The pass
      25              :    does not transform the RTL.
      26              : 
      27              :    We must allocate a hard register to every reload pseudo.  We try to
      28              :    increase the chances of finding a viable allocation by assigning
      29              :    the pseudos in order of fewest available hard registers first.  If
      30              :    we still fail to find a hard register, we spill other (non-reload)
      31              :    pseudos in order to make room.
      32              : 
      33              :    find_hard_regno_for finds hard registers for allocation without
      34              :    spilling.  spill_for does the same with spilling.  Both functions
      35              :    use a cost model to determine the most profitable choice of hard
      36              :    and spill registers.
      37              : 
      38              :    Once we have finished allocating reload pseudos, we also try to
      39              :    assign registers to other (non-reload) pseudos.  This is useful if
      40              :    hard registers were freed up by the spilling just described.
      41              : 
      42              :    We try to assign hard registers by collecting pseudos into threads.
      43              :    These threads contain reload and inheritance pseudos that are
      44              :    connected by copies (move insns).  Doing this improves the chances
      45              :    of pseudos in the thread getting the same hard register and, as a
      46              :    result, of allowing some move insns to be deleted.
      47              : 
      48              :    When we assign a hard register to a pseudo, we decrease the cost of
      49              :    using the same hard register for pseudos that are connected by
      50              :    copies.
      51              : 
      52              :    If two hard registers have the same frequency-derived cost, we
      53              :    prefer hard registers with higher priorities.  The mapping of
      54              :    registers to priorities is controlled by the register_priority
      55              :    target hook.  For example, x86-64 has a few register priorities:
      56              :    hard registers with and without REX prefixes have different
      57              :    priorities.  This permits us to generate smaller code as insns
      58              :    without REX prefixes are shorter.
      59              : 
      60              :    If a few hard registers are still equally good for the assignment,
      61              :    we choose the least used hard register.  It is called leveling and
      62              :    may be profitable for some targets.
      63              : 
      64              :    Only insns with changed allocation pseudos are processed on the
      65              :    next constraint pass.
      66              : 
      67              :    The pseudo live-ranges are used to find conflicting pseudos.
      68              : 
      69              :    For understanding the code, it is important to keep in mind that
      70              :    inheritance, split, and reload pseudos created since last
      71              :    constraint pass have regno >= lra_constraint_new_regno_start.
      72              :    Inheritance and split pseudos created on any pass are in the
      73              :    corresponding bitmaps.  Inheritance and split pseudos since the
      74              :    last constraint pass have also the corresponding non-negative
      75              :    restore_regno.  */
      76              : 
      77              : #include "config.h"
      78              : #include "system.h"
      79              : #include "coretypes.h"
      80              : #include "backend.h"
      81              : #include "target.h"
      82              : #include "rtl.h"
      83              : #include "tree.h"
      84              : #include "predict.h"
      85              : #include "df.h"
      86              : #include "memmodel.h"
      87              : #include "tm_p.h"
      88              : #include "insn-config.h"
      89              : #include "regs.h"
      90              : #include "ira.h"
      91              : #include "recog.h"
      92              : #include "rtl-error.h"
      93              : #include "sparseset.h"
      94              : #include "lra.h"
      95              : #include "lra-int.h"
      96              : #include "function-abi.h"
      97              : 
      98              : /* Current iteration number of the pass and current iteration number
      99              :    of the pass after the latest spill pass when any former reload
     100              :    pseudo was spilled.  */
     101              : int lra_assignment_iter;
     102              : int lra_assignment_iter_after_spill;
     103              : 
     104              : /* Flag of spilling former reload pseudos on this pass.  */
     105              : static bool former_reload_pseudo_spill_p;
     106              : 
     107              : /* Array containing corresponding values of function
     108              :    lra_get_allocno_class.  It is used to speed up the code.  */
     109              : static enum reg_class *regno_allocno_class_array;
     110              : 
     111              : /* Array containing lengths of pseudo live ranges.  It is used to
     112              :    speed up the code.  */
     113              : static int *regno_live_length;
     114              : 
     115              : /* Information about the thread to which a pseudo belongs.  Threads are
     116              :    a set of connected reload and inheritance pseudos with the same set of
     117              :    available hard registers.  Lone registers belong to their own threads.  */
     118              : struct regno_assign_info
     119              : {
     120              :   /* First/next pseudo of the same thread.  */
     121              :   int first, next;
     122              :   /* Frequency of the thread (execution frequency of only reload
     123              :      pseudos in the thread when the thread contains a reload pseudo).
     124              :      Defined only for the first thread pseudo.  */
     125              :   int freq;
     126              : };
     127              : 
     128              : /* Map regno to the corresponding regno assignment info.  */
     129              : static struct regno_assign_info *regno_assign_info;
     130              : 
     131              : /* All inherited, subreg or optional pseudos created before last spill
     132              :    sub-pass.  Such pseudos are permitted to get memory instead of hard
     133              :    regs.  */
     134              : static bitmap_head non_reload_pseudos;
     135              : 
     136              : /* Process a pseudo copy with execution frequency COPY_FREQ connecting
     137              :    REGNO1 and REGNO2 to form threads.  */
     138              : static void
     139      1579127 : process_copy_to_form_thread (int regno1, int regno2, int copy_freq)
     140              : {
     141      1579127 :   int last, regno1_first, regno2_first;
     142              : 
     143      1579127 :   lra_assert (regno1 >= lra_constraint_new_regno_start
     144              :               && regno2 >= lra_constraint_new_regno_start);
     145      1579127 :   regno1_first = regno_assign_info[regno1].first;
     146      1579127 :   regno2_first = regno_assign_info[regno2].first;
     147      1579127 :   if (regno1_first != regno2_first)
     148              :     {
     149      2502897 :       for (last = regno2_first;
     150      4082024 :            regno_assign_info[last].next >= 0;
     151      2502897 :            last = regno_assign_info[last].next)
     152      2502897 :         regno_assign_info[last].first = regno1_first;
     153      1579127 :       regno_assign_info[last].first = regno1_first;
     154      1579127 :       regno_assign_info[last].next = regno_assign_info[regno1_first].next;
     155      1579127 :       regno_assign_info[regno1_first].next = regno2_first;
     156      1579127 :       regno_assign_info[regno1_first].freq
     157      1579127 :         += regno_assign_info[regno2_first].freq;
     158              :     }
     159      1579127 :   regno_assign_info[regno1_first].freq -= 2 * copy_freq;
     160      1579127 :   lra_assert (regno_assign_info[regno1_first].freq >= 0);
     161      1579127 : }
     162              : 
     163              : /* Initialize REGNO_ASSIGN_INFO and form threads.  */
     164              : static void
     165      1538735 : init_regno_assign_info (void)
     166              : {
     167      1538735 :   int i, regno1, regno2, max_regno = max_reg_num ();
     168      1538735 :   lra_copy_t cp;
     169              : 
     170      1538735 :   regno_assign_info = XNEWVEC (struct regno_assign_info, max_regno);
     171    100844480 :   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
     172              :     {
     173     99305745 :       regno_assign_info[i].first = i;
     174     99305745 :       regno_assign_info[i].next = -1;
     175     99305745 :       regno_assign_info[i].freq = lra_reg_info[i].freq;
     176              :     }
     177              :   /* Form the threads.  */
     178      4329822 :   for (i = 0; (cp = lra_get_copy (i)) != NULL; i++)
     179      2791087 :     if ((regno1 = cp->regno1) >= lra_constraint_new_regno_start
     180      2791087 :         && (regno2 = cp->regno2) >= lra_constraint_new_regno_start
     181      2791087 :         && reg_renumber[regno1] < 0 && lra_reg_info[regno1].nrefs != 0
     182      1611686 :         && reg_renumber[regno2] < 0 && lra_reg_info[regno2].nrefs != 0
     183      2791087 :         && (ira_class_hard_regs_num[regno_allocno_class_array[regno1]]
     184      1610212 :             == ira_class_hard_regs_num[regno_allocno_class_array[regno2]]))
     185      1579127 :       process_copy_to_form_thread (regno1, regno2, cp->freq);
     186      1538735 : }
     187              : 
     188              : /* Free REGNO_ASSIGN_INFO.  */
     189              : static void
     190      1538735 : finish_regno_assign_info (void)
     191              : {
     192      1538735 :   free (regno_assign_info);
     193            0 : }
     194              : 
     195              : /* The function is used to sort *reload* and *inheritance* pseudos to
     196              :    try to assign them hard registers.  We put pseudos from the same
     197              :    thread always nearby.  */
     198              : static int
     199    247411310 : reload_pseudo_compare_func (const void *v1p, const void *v2p)
     200              : {
     201    247411310 :   int r1 = *(const int *) v1p, r2 = *(const int *) v2p;
     202    247411310 :   enum reg_class cl1 = regno_allocno_class_array[r1];
     203    247411310 :   enum reg_class cl2 = regno_allocno_class_array[r2];
     204    247411310 :   int diff;
     205              : 
     206    247411310 :   lra_assert (r1 >= lra_constraint_new_regno_start
     207              :               && r2 >= lra_constraint_new_regno_start);
     208              : 
     209              :   /* Prefer to assign reload registers with smaller classes first to
     210              :      guarantee assignment to all reload registers.  */
     211    247411310 :   if ((diff = (ira_class_hard_regs_num[cl1]
     212    247411310 :                - ira_class_hard_regs_num[cl2])) != 0)
     213              :     return diff;
     214              :   /* Allocate bigger pseudos first to avoid register file
     215              :      fragmentation.  */
     216    232432974 :   if ((diff
     217    232432974 :        = (ira_reg_class_max_nregs[cl2][lra_reg_info[r2].biggest_mode]
     218    232432974 :           - ira_reg_class_max_nregs[cl1][lra_reg_info[r1].biggest_mode])) != 0)
     219              :     return diff;
     220    230434693 :   if ((diff = (regno_assign_info[regno_assign_info[r2].first].freq
     221    230434693 :                - regno_assign_info[regno_assign_info[r1].first].freq)) != 0)
     222              :     return diff;
     223              :   /* Put pseudos from the thread nearby.  */
     224    129898004 :   if ((diff = regno_assign_info[r1].first - regno_assign_info[r2].first) != 0)
     225              :     return diff;
     226              :   /* Prefer pseudos with longer live ranges.  It sets up better
     227              :      prefered hard registers for the thread pseudos and decreases
     228              :      register-register moves between the thread pseudos.  */
     229     18075389 :   if ((diff = regno_live_length[r2] - regno_live_length[r1]) != 0)
     230              :     return diff;
     231              :   /* If regs are equally good, sort by their numbers, so that the
     232              :      results of qsort leave nothing to chance.  */
     233      8332974 :   return r1 - r2;
     234              : }
     235              : 
     236              : /* The function is used to sort *non-reload* pseudos to try to assign
     237              :    them hard registers.  The order calculation is simpler than in the
     238              :    previous function and based on the pseudo frequency usage.  */
     239              : static int
     240   1103574482 : pseudo_compare_func (const void *v1p, const void *v2p)
     241              : {
     242   1103574482 :   int r1 = *(const int *) v1p, r2 = *(const int *) v2p;
     243   1103574482 :   int diff;
     244              : 
     245              :   /* Assign hard reg to static chain pointer first pseudo when
     246              :      non-local goto is used.  */
     247   1103574482 :   if ((diff = (non_spilled_static_chain_regno_p (r2)
     248   1103574482 :                - non_spilled_static_chain_regno_p (r1))) != 0)
     249              :     return diff;
     250              : 
     251              :   /* Prefer to assign more frequently used registers first.  */
     252   1103571214 :   if ((diff = lra_reg_info[r2].freq - lra_reg_info[r1].freq) != 0)
     253              :     return diff;
     254              : 
     255              :   /* If regs are equally good, sort by their numbers, so that the
     256              :      results of qsort leave nothing to chance.  */
     257    655832954 :   return r1 - r2;
     258              : }
     259              : 
     260              : /* Arrays of size LRA_LIVE_MAX_POINT mapping a program point to the
     261              :    pseudo live ranges with given start point.  We insert only live
     262              :    ranges of pseudos interesting for assignment purposes.  They are
     263              :    reload pseudos and pseudos assigned to hard registers.  */
     264              : static lra_live_range_t *start_point_ranges;
     265              : 
     266              : /* Used as a flag that a live range is not inserted in the start point
     267              :    chain.  */
     268              : static struct lra_live_range not_in_chain_mark;
     269              : 
     270              : /* Create and set up START_POINT_RANGES.  */
     271              : static void
     272      1538735 : create_live_range_start_chains (void)
     273              : {
     274      1538735 :   int i, max_regno;
     275      1538735 :   lra_live_range_t r;
     276              : 
     277      1538735 :   start_point_ranges = XCNEWVEC (lra_live_range_t, lra_live_max_point);
     278      1538735 :   max_regno = max_reg_num ();
     279    102383215 :   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
     280     99305745 :     if (i >= lra_constraint_new_regno_start || reg_renumber[i] >= 0)
     281              :       {
     282    106416116 :         for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
     283              :           {
     284     57008816 :             r->start_next = start_point_ranges[r->start];
     285     57008816 :             start_point_ranges[r->start] = r;
     286              :           }
     287              :       }
     288              :     else
     289              :       {
     290     52666125 :         for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
     291      2767680 :           r->start_next = &not_in_chain_mark;
     292              :       }
     293      1538735 : }
     294              : 
     295              : /* Insert live ranges of pseudo REGNO into start chains if they are
     296              :    not there yet.  */
     297              : static void
     298    490765808 : insert_in_live_range_start_chain (int regno)
     299              : {
     300    490765808 :   lra_live_range_t r = lra_reg_info[regno].live_ranges;
     301              : 
     302    490765808 :   if (r->start_next != &not_in_chain_mark)
     303              :     return;
     304       216801 :   for (; r != NULL; r = r->next)
     305              :     {
     306       140202 :       r->start_next = start_point_ranges[r->start];
     307       140202 :       start_point_ranges[r->start] = r;
     308              :     }
     309              : }
     310              : 
     311              : /* Free START_POINT_RANGES.  */
     312              : static void
     313      1538735 : finish_live_range_start_chains (void)
     314              : {
     315      1538735 :   gcc_assert (start_point_ranges != NULL);
     316      1538735 :   free (start_point_ranges);
     317      1538735 :   start_point_ranges = NULL;
     318      1538735 : }
     319              : 
     320              : /* Map: program point -> bitmap of all pseudos living at the point and
     321              :    assigned to hard registers.  */
     322              : static bitmap_head *live_hard_reg_pseudos;
     323              : static bitmap_obstack live_hard_reg_pseudos_bitmap_obstack;
     324              : 
     325              : /* reg_renumber corresponding to pseudos marked in
     326              :    live_hard_reg_pseudos.  reg_renumber might be not matched to
     327              :    live_hard_reg_pseudos but live_pseudos_reg_renumber always reflects
     328              :    live_hard_reg_pseudos.  */
     329              : static int *live_pseudos_reg_renumber;
     330              : 
     331              : /* Sparseset used to calculate living hard reg pseudos for some program
     332              :    point range.  */
     333              : static sparseset live_range_hard_reg_pseudos;
     334              : 
     335              : /* Sparseset used to calculate living reload/inheritance pseudos for
     336              :    some program point range.  */
     337              : static sparseset live_range_reload_inheritance_pseudos;
     338              : 
     339              : /* Allocate and initialize the data about living pseudos at program
     340              :    points.  */
     341              : static void
     342      1538735 : init_lives (void)
     343              : {
     344      1538735 :   int i, max_regno = max_reg_num ();
     345              : 
     346      1538735 :   live_range_hard_reg_pseudos = sparseset_alloc (max_regno);
     347      1538735 :   live_range_reload_inheritance_pseudos = sparseset_alloc (max_regno);
     348      1538735 :   live_hard_reg_pseudos = XNEWVEC (bitmap_head, lra_live_max_point);
     349      1538735 :   bitmap_obstack_initialize (&live_hard_reg_pseudos_bitmap_obstack);
     350     90102424 :   for (i = 0; i < lra_live_max_point; i++)
     351     87024954 :     bitmap_initialize (&live_hard_reg_pseudos[i],
     352              :                        &live_hard_reg_pseudos_bitmap_obstack);
     353      1538735 :   live_pseudos_reg_renumber = XNEWVEC (int, max_regno);
     354    242408100 :   for (i = 0; i < max_regno; i++)
     355    240869365 :     live_pseudos_reg_renumber[i] = -1;
     356      1538735 : }
     357              : 
     358              : /* Free the data about living pseudos at program points.  */
     359              : static void
     360      1538735 : finish_lives (void)
     361              : {
     362      1538735 :   sparseset_free (live_range_hard_reg_pseudos);
     363      1538735 :   sparseset_free (live_range_reload_inheritance_pseudos);
     364      1538735 :   free (live_hard_reg_pseudos);
     365      1538735 :   bitmap_obstack_release (&live_hard_reg_pseudos_bitmap_obstack);
     366      1538735 :   free (live_pseudos_reg_renumber);
     367      1538735 : }
     368              : 
     369              : /* Update the LIVE_HARD_REG_PSEUDOS and LIVE_PSEUDOS_REG_RENUMBER
     370              :    entries for pseudo REGNO.  Assume that the register has been
     371              :    spilled if FREE_P, otherwise assume that it has been assigned
     372              :    reg_renumber[REGNO] (if >= 0).  We also insert the pseudo live
     373              :    ranges in the start chains when it is assumed to be assigned to a
     374              :    hard register because we use the chains of pseudos assigned to hard
     375              :    registers during allocation.  */
     376              : static void
     377     47973064 : update_lives (int regno, bool free_p)
     378              : {
     379     47973064 :   int p;
     380     47973064 :   lra_live_range_t r;
     381              : 
     382     47973064 :   if (reg_renumber[regno] < 0)
     383              :     return;
     384     47973064 :   live_pseudos_reg_renumber[regno] = free_p ? -1 : reg_renumber[regno];
     385    105207186 :   for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
     386              :     {
     387    601104324 :       for (p = r->start; p <= r->finish; p++)
     388    543870202 :         if (free_p)
     389     58784001 :           bitmap_clear_bit (&live_hard_reg_pseudos[p], regno);
     390              :         else
     391              :           {
     392    485086201 :             bitmap_set_bit (&live_hard_reg_pseudos[p], regno);
     393    485086201 :             insert_in_live_range_start_chain (regno);
     394              :           }
     395              :     }
     396              : }
     397              : 
     398              : /* Sparseset used to calculate reload pseudos conflicting with a given
     399              :    pseudo when we are trying to find a hard register for the given
     400              :    pseudo.  */
     401              : static sparseset conflict_reload_and_inheritance_pseudos;
     402              : 
     403              : /* Map: program point -> bitmap of all reload and inheritance pseudos
     404              :    living at the point.  */
     405              : static bitmap_head *live_reload_and_inheritance_pseudos;
     406              : static bitmap_obstack live_reload_and_inheritance_pseudos_bitmap_obstack;
     407              : 
     408              : /* Allocate and initialize data about living reload pseudos at any
     409              :    given program point.  */
     410              : static void
     411      1538735 : init_live_reload_and_inheritance_pseudos (void)
     412              : {
     413      1538735 :   int i, p, max_regno = max_reg_num ();
     414      1538735 :   lra_live_range_t r;
     415              : 
     416      1538735 :   conflict_reload_and_inheritance_pseudos = sparseset_alloc (max_regno);
     417      1538735 :   live_reload_and_inheritance_pseudos = XNEWVEC (bitmap_head, lra_live_max_point);
     418      1538735 :   bitmap_obstack_initialize (&live_reload_and_inheritance_pseudos_bitmap_obstack);
     419     90102424 :   for (p = 0; p < lra_live_max_point; p++)
     420     87024954 :     bitmap_initialize (&live_reload_and_inheritance_pseudos[p],
     421              :                        &live_reload_and_inheritance_pseudos_bitmap_obstack);
     422      1538735 :   if ((unsigned) (max_regno - lra_constraint_new_regno_start)   
     423      1538735 :       >= (1U << lra_max_pseudos_points_log2_considered_for_preferences)
     424      1538735 :       /  (lra_live_max_point + 1))
     425           16 :     return;
     426      1538719 :   bitmap_head start_points;
     427      1538719 :   bitmap_initialize (&start_points,
     428              :                      &live_hard_reg_pseudos_bitmap_obstack);
     429     13198835 :   for (i = lra_constraint_new_regno_start; i < max_regno; i++)
     430     22771332 :     for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
     431     11111216 :       bitmap_set_bit (&start_points, r->start);
     432     13198835 :   for (i = lra_constraint_new_regno_start; i < max_regno; i++)
     433              :     {
     434     22771332 :       for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
     435              :         {
     436     11111216 :           bitmap_iterator bi;
     437     11111216 :           unsigned p;
     438     45184029 :           EXECUTE_IF_SET_IN_BITMAP (&start_points, r->start, p, bi)
     439              :             {
     440     44522155 :               if (p > (unsigned) r->finish)
     441              :                 break;
     442     34072813 :               bitmap_set_bit (&live_reload_and_inheritance_pseudos[p], i);
     443              :             }
     444              :         }
     445              :     }
     446      1538719 :   bitmap_clear (&start_points);
     447              : }
     448              : 
     449              : /* Finalize data about living reload pseudos at any given program
     450              :    point.  */
     451              : static void
     452      1538735 : finish_live_reload_and_inheritance_pseudos (void)
     453              : {
     454      1538735 :   sparseset_free (conflict_reload_and_inheritance_pseudos);
     455      1538735 :   free (live_reload_and_inheritance_pseudos);
     456      1538735 :   bitmap_obstack_release (&live_reload_and_inheritance_pseudos_bitmap_obstack);
     457      1538735 : }
     458              : 
     459              : /* The value used to check that cost of given hard reg is really
     460              :    defined currently.  */
     461              : static int curr_hard_regno_costs_check = 0;
     462              : /* Array used to check that cost of the corresponding hard reg (the
     463              :    array element index) is really defined currently.  */
     464              : static int hard_regno_costs_check[FIRST_PSEUDO_REGISTER];
     465              : /* The current costs of allocation of hard regs.  Defined only if the
     466              :    value of the corresponding element of the previous array is equal to
     467              :    CURR_HARD_REGNO_COSTS_CHECK.  */
     468              : static int hard_regno_costs[FIRST_PSEUDO_REGISTER];
     469              : 
     470              : /* Adjust cost of HARD_REGNO by INCR.  Reset the cost first if it is
     471              :    not defined yet.  */
     472              : static inline void
     473     22292307 : adjust_hard_regno_cost (int hard_regno, int incr)
     474              : {
     475     22292307 :   if (hard_regno_costs_check[hard_regno] != curr_hard_regno_costs_check)
     476     11772890 :     hard_regno_costs[hard_regno] = 0;
     477     22292307 :   hard_regno_costs_check[hard_regno] = curr_hard_regno_costs_check;
     478     22292307 :   hard_regno_costs[hard_regno] += incr;
     479     22292307 : }
     480              : 
     481              : /* Try to find a free hard register for pseudo REGNO.  Return the
     482              :    hard register on success and set *COST to the cost of using
     483              :    that register.  (If several registers have equal cost, the one with
     484              :    the highest priority wins.)  Return -1 on failure.
     485              : 
     486              :    If FIRST_P, return the first available hard reg ignoring other
     487              :    criteria, e.g. allocation cost.  This approach results in less hard
     488              :    reg pool fragmentation and permit to allocate hard regs to reload
     489              :    pseudos in complicated situations where pseudo sizes are different.
     490              : 
     491              :    If TRY_ONLY_HARD_REGNO >= 0, consider only that hard register,
     492              :    otherwise consider all hard registers in REGNO's class.
     493              : 
     494              :    If REGNO_SET is not empty, only hard registers from the set are
     495              :    considered.  */
     496              : static int
     497     13851884 : find_hard_regno_for_1 (int regno, int *cost, int try_only_hard_regno,
     498              :                        bool first_p, HARD_REG_SET regno_set)
     499              : {
     500     13851884 :   HARD_REG_SET conflict_set;
     501     13851884 :   int best_cost = INT_MAX, best_priority = INT_MIN, best_usage = INT_MAX;
     502     13851884 :   lra_live_range_t r;
     503     13851884 :   int p, i, j, rclass_size, best_hard_regno, priority, hard_regno;
     504     13851884 :   int hr, conflict_hr, nregs;
     505     13851884 :   machine_mode biggest_mode;
     506     13851884 :   unsigned int k, conflict_regno;
     507     13851884 :   poly_int64 offset;
     508     13851884 :   int val, biggest_nregs, nregs_diff;
     509     13851884 :   enum reg_class rclass;
     510     13851884 :   bitmap_iterator bi;
     511     13851884 :   bool *rclass_intersect_p;
     512     13851884 :   HARD_REG_SET impossible_start_hard_regs, available_regs;
     513              : 
     514     27703768 :   if (hard_reg_set_empty_p (regno_set))
     515     13635979 :     conflict_set = lra_no_alloc_regs;
     516              :   else
     517       215905 :     conflict_set = ~regno_set | lra_no_alloc_regs;
     518     13851884 :   rclass = regno_allocno_class_array[regno];
     519     13851884 :   rclass_intersect_p = ira_reg_classes_intersect_p[rclass];
     520     13851884 :   curr_hard_regno_costs_check++;
     521     13851884 :   sparseset_clear (conflict_reload_and_inheritance_pseudos);
     522     13851884 :   sparseset_clear (live_range_hard_reg_pseudos);
     523     13851884 :   conflict_set |= lra_reg_info[regno].conflict_hard_regs;
     524     13851884 :   biggest_mode = lra_reg_info[regno].biggest_mode;
     525     29561960 :   for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
     526              :     {
     527    130380074 :       EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi)
     528    114669998 :         if (rclass_intersect_p[regno_allocno_class_array[k]])
     529    101318973 :           sparseset_set_bit (live_range_hard_reg_pseudos, k);
     530    134396395 :       EXECUTE_IF_SET_IN_BITMAP (&live_reload_and_inheritance_pseudos[r->start],
     531              :                                 0, k, bi)
     532    118686319 :         if (lra_reg_info[k].preferred_hard_regno1 >= 0
     533     32683888 :             && live_pseudos_reg_renumber[k] < 0
     534     30198035 :             && rclass_intersect_p[regno_allocno_class_array[k]])
     535     27901168 :           sparseset_set_bit (conflict_reload_and_inheritance_pseudos, k);
     536   2823582959 :       for (p = r->start + 1; p <= r->finish; p++)
     537              :         {
     538   2807872883 :           lra_live_range_t r2;
     539              : 
     540   2807872883 :           for (r2 = start_point_ranges[p];
     541   4785121312 :                r2 != NULL;
     542   1977248429 :                r2 = r2->start_next)
     543              :             {
     544   1977248429 :               if (live_pseudos_reg_renumber[r2->regno] < 0
     545    633839954 :                   && r2->regno >= lra_constraint_new_regno_start
     546    632928415 :                   && lra_reg_info[r2->regno].preferred_hard_regno1 >= 0
     547    363400249 :                   && rclass_intersect_p[regno_allocno_class_array[r2->regno]])
     548    355426412 :                 sparseset_set_bit (conflict_reload_and_inheritance_pseudos,
     549              :                                    r2->regno);
     550   1621822017 :               else if (live_pseudos_reg_renumber[r2->regno] >= 0
     551   1343408475 :                        && rclass_intersect_p
     552   1343408475 :                             [regno_allocno_class_array[r2->regno]])
     553   1237189991 :                 sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno);
     554              :             }
     555              :         }
     556              :     }
     557     13851884 :   if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
     558              :     {
     559      5644924 :       adjust_hard_regno_cost
     560      5644924 :         (hard_regno, -lra_reg_info[regno].preferred_hard_regno_profit1);
     561      5644924 :       if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
     562      1773154 :         adjust_hard_regno_cost
     563      1773154 :           (hard_regno, -lra_reg_info[regno].preferred_hard_regno_profit2);
     564              :     }
     565              : #ifdef STACK_REGS
     566     13851884 :   if (lra_reg_info[regno].no_stack_p)
     567       458730 :     for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
     568       407760 :       SET_HARD_REG_BIT (conflict_set, i);
     569              : #endif
     570     13851884 :   sparseset_clear_bit (conflict_reload_and_inheritance_pseudos, regno);
     571     13851884 :   val = lra_reg_info[regno].val;
     572     13851884 :   offset = lra_reg_info[regno].offset;
     573     13851884 :   impossible_start_hard_regs = lra_reg_info[regno].exclude_start_hard_regs;
     574    198446270 :   EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno)
     575              :     {
     576    189104094 :       conflict_hr = live_pseudos_reg_renumber[conflict_regno];
     577    189104094 :       if (lra_reg_val_equal_p (conflict_regno, val, offset))
     578              :         {
     579       886502 :           conflict_hr = live_pseudos_reg_renumber[conflict_regno];
     580       886502 :           nregs = hard_regno_nregs (conflict_hr,
     581       886502 :                                     lra_reg_info[conflict_regno].biggest_mode);
     582              :           /* Remember about multi-register pseudos.  For example, 2
     583              :              hard register pseudos can start on the same hard register
     584              :              but cannot start on HR and HR+1/HR-1.  */
     585       892882 :           for (hr = conflict_hr + 1;
     586       892882 :                hr < FIRST_PSEUDO_REGISTER && hr < conflict_hr + nregs;
     587              :                hr++)
     588         6380 :             SET_HARD_REG_BIT (impossible_start_hard_regs, hr);
     589       891793 :           for (hr = conflict_hr - 1;
     590       891793 :                hr >= 0 && (int) end_hard_regno (biggest_mode, hr) > conflict_hr;
     591              :                hr--)
     592         5291 :             SET_HARD_REG_BIT (impossible_start_hard_regs, hr);
     593              :         }
     594              :       else
     595              :         {
     596    188217592 :           machine_mode biggest_conflict_mode
     597    188217592 :             = lra_reg_info[conflict_regno].biggest_mode;
     598    188217592 :           int biggest_conflict_nregs
     599    188217592 :             = hard_regno_nregs (conflict_hr, biggest_conflict_mode);
     600              : 
     601    188217592 :           nregs_diff
     602    188217592 :             = (biggest_conflict_nregs
     603    188217592 :                - hard_regno_nregs (conflict_hr,
     604    188217592 :                                    PSEUDO_REGNO_MODE (conflict_regno)));
     605    188217592 :           add_to_hard_reg_set (&conflict_set,
     606              :                                biggest_conflict_mode,
     607              :                                conflict_hr
     608              :                                - (WORDS_BIG_ENDIAN ? nregs_diff : 0));
     609    376435184 :           if (hard_reg_set_subset_p (reg_class_contents[rclass],
     610              :                                      conflict_set))
     611              :             return -1;
     612              :         }
     613              :     }
     614     19385104 :   EXECUTE_IF_SET_IN_SPARSESET (conflict_reload_and_inheritance_pseudos,
     615              :                                conflict_regno)
     616     20085856 :     if (!lra_reg_val_equal_p (conflict_regno, val, offset))
     617              :       {
     618      9797801 :         lra_assert (live_pseudos_reg_renumber[conflict_regno] < 0);
     619      9797801 :         if ((hard_regno
     620      9797801 :              = lra_reg_info[conflict_regno].preferred_hard_regno1) >= 0)
     621              :           {
     622      9797801 :             adjust_hard_regno_cost
     623      9797801 :               (hard_regno,
     624              :                lra_reg_info[conflict_regno].preferred_hard_regno_profit1);
     625      9797801 :             if ((hard_regno
     626      9797801 :                  = lra_reg_info[conflict_regno].preferred_hard_regno2) >= 0)
     627      5076428 :               adjust_hard_regno_cost
     628      5076428 :                 (hard_regno,
     629              :                  lra_reg_info[conflict_regno].preferred_hard_regno_profit2);
     630              :           }
     631              :       }
     632              :   /* Make sure that all registers in a multi-word pseudo belong to the
     633              :      required class.  */
     634      9342176 :   conflict_set |= ~reg_class_contents[rclass];
     635      9342176 :   lra_assert (rclass != NO_REGS);
     636      9342176 :   rclass_size = ira_class_hard_regs_num[rclass];
     637      9342176 :   best_hard_regno = -1;
     638      9342176 :   hard_regno = ira_class_hard_regs[rclass][0];
     639      9342176 :   biggest_nregs = hard_regno_nregs (hard_regno, biggest_mode);
     640      9342176 :   nregs_diff = (biggest_nregs
     641      9342176 :                 - hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (regno)));
     642      9342176 :   available_regs = reg_class_contents[rclass] & ~lra_no_alloc_regs;
     643    121657524 :   for (i = 0; i < rclass_size; i++)
     644              :     {
     645    112388050 :       if (try_only_hard_regno >= 0)
     646              :         hard_regno = try_only_hard_regno;
     647              :       else
     648    112317774 :         hard_regno = ira_class_hard_regs[rclass][i];
     649    112388050 :       if (! overlaps_hard_reg_set_p (conflict_set,
     650    112388050 :                                      PSEUDO_REGNO_MODE (regno), hard_regno)
     651     58449936 :           && targetm.hard_regno_mode_ok (hard_regno, PSEUDO_REGNO_MODE (regno))
     652              :           /* We cannot use prohibited_class_mode_regs for all classes
     653              :              because it is not defined for all classes.  */
     654     58300840 :           && (ira_allocno_class_translate[rclass] != rclass
     655     22314254 :               || ! TEST_HARD_REG_BIT (ira_prohibited_class_mode_regs
     656     22314254 :                                       [rclass][biggest_mode],
     657              :                                       hard_regno))
     658     58300548 :           && ! TEST_HARD_REG_BIT (impossible_start_hard_regs, hard_regno)
     659    170686804 :           && (nregs_diff == 0
     660         4515 :               || (WORDS_BIG_ENDIAN
     661              :                   ? (hard_regno - nregs_diff >= 0
     662              :                      && TEST_HARD_REG_BIT (available_regs,
     663              :                                            hard_regno - nregs_diff))
     664         4515 :                   : TEST_HARD_REG_BIT (available_regs,
     665         4515 :                                        hard_regno + nregs_diff))))
     666              :         {
     667     58298372 :           if (hard_regno_costs_check[hard_regno]
     668     58298372 :               != curr_hard_regno_costs_check)
     669              :             {
     670     53126419 :               hard_regno_costs_check[hard_regno] = curr_hard_regno_costs_check;
     671     53126419 :               hard_regno_costs[hard_regno] = 0;
     672              :             }
     673     59397988 :           for (j = 0;
     674    117696360 :                j < hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (regno));
     675              :                j++)
     676     59397988 :             if (! crtl->abi->clobbers_full_reg_p (hard_regno + j)
     677     59397988 :                 && ! df_regs_ever_live_p (hard_regno + j))
     678              :               /* It needs save restore.  */
     679     11986376 :               hard_regno_costs[hard_regno]
     680      5993188 :                 += (2
     681     16483666 :                     * REG_FREQ_FROM_BB (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
     682     15484546 :                     + 1);
     683     58298372 :           priority = targetm.register_priority (hard_regno);
     684     49171104 :           if (best_hard_regno < 0 || hard_regno_costs[hard_regno] < best_cost
     685    105707985 :               || (hard_regno_costs[hard_regno] == best_cost
     686     24972117 :                   && (priority > best_priority
     687     24879402 :                       || (targetm.register_usage_leveling_p ()
     688     24879402 :                           && priority == best_priority
     689      6352228 :                           && best_usage > lra_hard_reg_usage[hard_regno]))))
     690              :             {
     691     13587300 :               best_hard_regno = hard_regno;
     692     13587300 :               best_cost = hard_regno_costs[hard_regno];
     693     13587300 :               best_priority = priority;
     694     13587300 :               best_usage = lra_hard_reg_usage[hard_regno];
     695              :             }
     696              :         }
     697    112388050 :       if (try_only_hard_regno >= 0 || (first_p && best_hard_regno >= 0))
     698              :         break;
     699              :     }
     700      9342176 :   if (best_hard_regno >= 0)
     701      9127268 :     *cost = best_cost - lra_reg_info[regno].freq;
     702              :   return best_hard_regno;
     703              : }
     704              : 
     705              : /* A wrapper for find_hard_regno_for_1 (see comments for that function
     706              :    description).  This function tries to find a hard register for
     707              :    preferred class first if it is worth.  */
     708              : static int
     709     13638721 : find_hard_regno_for (int regno, int *cost, int try_only_hard_regno, bool first_p)
     710              : {
     711     13638721 :   int hard_regno;
     712     13638721 :   HARD_REG_SET regno_set;
     713              : 
     714              :   /* Only original pseudos can have a different preferred class.  */
     715     13638721 :   if (try_only_hard_regno < 0 && regno < lra_new_regno_start)
     716              :     {
     717      1196238 :       enum reg_class pref_class = reg_preferred_class (regno);
     718              : 
     719      1196238 :       if (regno_allocno_class_array[regno] != pref_class)
     720              :         {
     721       431810 :           hard_regno = find_hard_regno_for_1 (regno, cost, -1, first_p,
     722       215905 :                                               reg_class_contents[pref_class]);
     723       215905 :           if (hard_regno >= 0)
     724              :             return hard_regno;
     725              :         }
     726              :     }
     727     13635979 :   CLEAR_HARD_REG_SET (regno_set);
     728     13635979 :   return find_hard_regno_for_1 (regno, cost, try_only_hard_regno, first_p,
     729     13635979 :                                 regno_set);
     730              : }
     731              : 
     732              : /* Current value used for checking elements in
     733              :    update_hard_regno_preference_check.  */
     734              : static int curr_update_hard_regno_preference_check;
     735              : /* If an element value is equal to the above variable value, then the
     736              :    corresponding regno has been processed for preference
     737              :    propagation.  */
     738              : static int *update_hard_regno_preference_check;
     739              : 
     740              : /* Update the preference for using HARD_REGNO for pseudos that are
     741              :    connected directly or indirectly with REGNO.  Apply divisor DIV
     742              :    to any preference adjustments.
     743              : 
     744              :    The more indirectly a pseudo is connected, the smaller its effect
     745              :    should be.  We therefore increase DIV on each "hop".  */
     746              : static void
     747      9300026 : update_hard_regno_preference (int regno, int hard_regno, int div)
     748              : {
     749      9300026 :   int another_regno, cost;
     750      9300026 :   lra_copy_t cp, next_cp;
     751              : 
     752              :   /* Search depth 5 seems to be enough.  */
     753      9300026 :   if (div > (1 << 5))
     754              :     return;
     755     16958694 :   for (cp = lra_reg_info[regno].copies; cp != NULL; cp = next_cp)
     756              :     {
     757      7740520 :       if (cp->regno1 == regno)
     758              :         {
     759      3523242 :           next_cp = cp->regno1_next;
     760      3523242 :           another_regno = cp->regno2;
     761              :         }
     762      4217278 :       else if (cp->regno2 == regno)
     763              :         {
     764      4217278 :           next_cp = cp->regno2_next;
     765      4217278 :           another_regno = cp->regno1;
     766              :         }
     767              :       else
     768            0 :         gcc_unreachable ();
     769      7740520 :       if (reg_renumber[another_regno] < 0
     770      4200206 :           && (update_hard_regno_preference_check[another_regno]
     771      4200206 :               != curr_update_hard_regno_preference_check))
     772              :         {
     773      2903901 :           update_hard_regno_preference_check[another_regno]
     774      2903901 :             = curr_update_hard_regno_preference_check;
     775      2903901 :           cost = cp->freq < div ? 1 : cp->freq / div;
     776      2903901 :           lra_setup_reload_pseudo_preferenced_hard_reg
     777      2903901 :             (another_regno, hard_regno, cost);
     778      2903901 :           update_hard_regno_preference (another_regno, hard_regno, div * 2);
     779              :         }
     780              :     }
     781              : }
     782              : 
     783              : /* Return prefix title for pseudo REGNO.  */
     784              : static const char *
     785          100 : pseudo_prefix_title (int regno)
     786              : {
     787          100 :   return
     788          100 :     (regno < lra_constraint_new_regno_start ? ""
     789          100 :      : bitmap_bit_p (&lra_inheritance_pseudos, regno) ? "inheritance "
     790           97 :      : bitmap_bit_p (&lra_split_regs, regno) ? "split "
     791           97 :      : bitmap_bit_p (&lra_optional_reload_pseudos, regno) ? "optional reload "
     792           94 :      : bitmap_bit_p (&lra_subreg_reload_pseudos, regno) ? "subreg reload "
     793          100 :      : "reload ");
     794              : }
     795              : 
     796              : /* Update REG_RENUMBER and other pseudo preferences by assignment of
     797              :    HARD_REGNO to pseudo REGNO and print about it if PRINT_P.  */
     798              : void
     799      6520923 : lra_setup_reg_renumber (int regno, int hard_regno, bool print_p)
     800              : {
     801      6520923 :   int i, hr;
     802              : 
     803              :   /* We cannot just reassign hard register.  */
     804      6520923 :   lra_assert (hard_regno < 0 || reg_renumber[regno] < 0);
     805       124798 :   if ((hr = hard_regno) < 0)
     806       124798 :     hr = reg_renumber[regno];
     807      6520923 :   reg_renumber[regno] = hard_regno;
     808      6520923 :   lra_assert (hr >= 0);
     809     13231549 :   for (i = 0; i < hard_regno_nregs (hr, PSEUDO_REGNO_MODE (regno)); i++)
     810      6710626 :     if (hard_regno < 0)
     811       133112 :       lra_hard_reg_usage[hr + i] -= lra_reg_info[regno].freq;
     812              :     else
     813      6577514 :       lra_hard_reg_usage[hr + i] += lra_reg_info[regno].freq;
     814      6520923 :   if (print_p && lra_dump_file != NULL)
     815          200 :     fprintf (lra_dump_file, "         Assign %d to %sr%d (freq=%d)\n",
     816          100 :              reg_renumber[regno], pseudo_prefix_title (regno),
     817          100 :              regno, lra_reg_info[regno].freq);
     818      6520923 :   if (hard_regno >= 0)
     819              :     {
     820      6396125 :       curr_update_hard_regno_preference_check++;
     821      6396125 :       update_hard_regno_preference (regno, hard_regno, 1);
     822              :     }
     823      6520923 : }
     824              : 
     825              : /* Pseudos which occur in insns containing a particular pseudo.  */
     826              : static bitmap_head insn_conflict_pseudos;
     827              : 
     828              : /* Bitmaps used to contain spill pseudos for given pseudo hard regno
     829              :    and best spill pseudos for given pseudo (and best hard regno).  */
     830              : static bitmap_head spill_pseudos_bitmap, best_spill_pseudos_bitmap;
     831              : 
     832              : /* Current pseudo check for validity of elements in
     833              :    TRY_HARD_REG_PSEUDOS.  */
     834              : static int curr_pseudo_check;
     835              : /* Array used for validity of elements in TRY_HARD_REG_PSEUDOS.  */
     836              : static int try_hard_reg_pseudos_check[FIRST_PSEUDO_REGISTER];
     837              : /* Pseudos who hold given hard register at the considered points.  */
     838              : static bitmap_head try_hard_reg_pseudos[FIRST_PSEUDO_REGISTER];
     839              : 
     840              : /* Set up try_hard_reg_pseudos for given program point P and class
     841              :    RCLASS.  Those are pseudos living at P and assigned to a hard
     842              :    register of RCLASS.  In other words, those are pseudos which can be
     843              :    spilled to assign a hard register of RCLASS to a pseudo living at
     844              :    P.  */
     845              : static void
     846       118056 : setup_try_hard_regno_pseudos (int p, enum reg_class rclass)
     847              : {
     848       118056 :   int i, hard_regno;
     849       118056 :   machine_mode mode;
     850       118056 :   unsigned int spill_regno;
     851       118056 :   bitmap_iterator bi;
     852              : 
     853              :   /* Find what pseudos could be spilled.  */
     854       923941 :   EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[p], 0, spill_regno, bi)
     855              :     {
     856       805885 :       mode = PSEUDO_REGNO_MODE (spill_regno);
     857       805885 :       hard_regno = live_pseudos_reg_renumber[spill_regno];
     858       805885 :       if (overlaps_hard_reg_set_p (reg_class_contents[rclass],
     859              :                                    mode, hard_regno))
     860              :         {
     861      1189792 :           for (i = hard_regno_nregs (hard_regno, mode) - 1; i >= 0; i--)
     862              :             {
     863       602857 :               if (try_hard_reg_pseudos_check[hard_regno + i]
     864       602857 :                   != curr_pseudo_check)
     865              :                 {
     866       284671 :                   try_hard_reg_pseudos_check[hard_regno + i]
     867       284671 :                     = curr_pseudo_check;
     868       284671 :                   bitmap_clear (&try_hard_reg_pseudos[hard_regno + i]);
     869              :                 }
     870       602857 :               bitmap_set_bit (&try_hard_reg_pseudos[hard_regno + i],
     871              :                               spill_regno);
     872              :             }
     873              :         }
     874              :     }
     875       118056 : }
     876              : 
     877              : /* Assign temporarily HARD_REGNO to pseudo REGNO.  Temporary
     878              :    assignment means that we might undo the data change.  */
     879              : static void
     880      2049054 : assign_temporarily (int regno, int hard_regno)
     881              : {
     882      2049054 :   int p;
     883      2049054 :   lra_live_range_t r;
     884              : 
     885      4126390 :   for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
     886              :     {
     887     13436550 :       for (p = r->start; p <= r->finish; p++)
     888     11359214 :         if (hard_regno < 0)
     889      5679607 :           bitmap_clear_bit (&live_hard_reg_pseudos[p], regno);
     890              :         else
     891              :           {
     892      5679607 :             bitmap_set_bit (&live_hard_reg_pseudos[p], regno);
     893      5679607 :             insert_in_live_range_start_chain (regno);
     894              :           }
     895              :     }
     896      2049054 :   live_pseudos_reg_renumber[regno] = hard_regno;
     897      2049054 : }
     898              : 
     899              : /* Return true iff there is a reason why pseudo SPILL_REGNO should not
     900              :    be spilled.  */
     901              : static bool
     902       288745 : must_not_spill_p (unsigned spill_regno)
     903              : {
     904       288745 :   if ((pic_offset_table_rtx != NULL
     905        85252 :        && spill_regno == REGNO (pic_offset_table_rtx))
     906       368504 :       || ((int) spill_regno >= lra_constraint_new_regno_start
     907        28058 :           && ! bitmap_bit_p (&lra_inheritance_pseudos, spill_regno)
     908        13532 :           && ! bitmap_bit_p (&lra_split_regs, spill_regno)
     909        11731 :           && ! bitmap_bit_p (&lra_subreg_reload_pseudos, spill_regno)
     910        11731 :           && ! bitmap_bit_p (&lra_optional_reload_pseudos, spill_regno)))
     911        15456 :     return true;
     912              :   /* A reload pseudo that requires a singleton register class should
     913              :      not be spilled.
     914              :      FIXME: this mitigates the issue on certain i386 patterns, but
     915              :      does not solve the general case where existing reloads fully
     916              :      cover a limited register class.  */
     917       273289 :   if (!bitmap_bit_p (&non_reload_pseudos, spill_regno)
     918       255194 :       && reg_class_size [reg_preferred_class (spill_regno)] == 1
     919       288121 :       && reg_alternate_class (spill_regno) == NO_REGS)
     920              :     return true;
     921              :   return false;
     922              : }
     923              : 
     924              : /* Array used for sorting reload pseudos for subsequent allocation
     925              :    after spilling some pseudo.  */
     926              : static int *sorted_reload_pseudos;
     927              : 
     928              : /* Spill some pseudos for a reload pseudo REGNO and return hard
     929              :    register which should be used for pseudo after spilling.  The
     930              :    function adds spilled pseudos to SPILLED_PSEUDO_BITMAP.  When we
     931              :    choose hard register (and pseudos occupying the hard registers and
     932              :    to be spilled), we take into account not only how REGNO will
     933              :    benefit from the spills but also how other reload pseudos not yet
     934              :    assigned to hard registers benefit from the spills too.  In very
     935              :    rare cases, the function can fail and return -1.
     936              : 
     937              :    If FIRST_P, return the first available hard reg ignoring other
     938              :    criteria, e.g. allocation cost and cost of spilling non-reload
     939              :    pseudos.  This approach results in less hard reg pool fragmentation
     940              :    and permit to allocate hard regs to reload pseudos in complicated
     941              :    situations where pseudo sizes are different.  */
     942              : static int
     943        51684 : spill_for (int regno, bitmap spilled_pseudo_bitmap, bool first_p)
     944              : {
     945        51684 :   int i, j, n, p, hard_regno, best_hard_regno, cost, best_cost, rclass_size;
     946        51684 :   int reload_hard_regno, reload_cost;
     947        51684 :   bool static_p, best_static_p;
     948        51684 :   machine_mode mode;
     949        51684 :   enum reg_class rclass;
     950        51684 :   unsigned int spill_regno, reload_regno, uid;
     951        51684 :   int insn_pseudos_num, best_insn_pseudos_num;
     952        51684 :   int bad_spills_num, smallest_bad_spills_num;
     953        51684 :   lra_live_range_t r;
     954        51684 :   bitmap_iterator bi;
     955              : 
     956        51684 :   rclass = regno_allocno_class_array[regno];
     957        51684 :   lra_assert (reg_renumber[regno] < 0 && rclass != NO_REGS);
     958        51684 :   bitmap_clear (&insn_conflict_pseudos);
     959        51684 :   bitmap_clear (&best_spill_pseudos_bitmap);
     960       150268 :   EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
     961              :     {
     962        98584 :       struct lra_insn_reg *ir;
     963              : 
     964       336810 :       for (ir = lra_get_insn_regs (uid); ir != NULL; ir = ir->next)
     965       238226 :         if (ir->regno >= FIRST_PSEUDO_REGISTER)
     966       228276 :           bitmap_set_bit (&insn_conflict_pseudos, ir->regno);
     967              :     }
     968        51684 :   best_hard_regno = -1;
     969        51684 :   best_cost = INT_MAX;
     970        51684 :   best_static_p = true;
     971        51684 :   best_insn_pseudos_num = INT_MAX;
     972        51684 :   smallest_bad_spills_num = INT_MAX;
     973        51684 :   rclass_size = ira_class_hard_regs_num[rclass];
     974        51684 :   mode = PSEUDO_REGNO_MODE (regno);
     975              :   /* Invalidate try_hard_reg_pseudos elements.  */
     976        51684 :   curr_pseudo_check++;
     977       105786 :   for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
     978       172158 :     for (p = r->start; p <= r->finish; p++)
     979       118056 :       setup_try_hard_regno_pseudos (p, rclass);
     980       379817 :   for (i = 0; i < rclass_size; i++)
     981              :     {
     982       328133 :       hard_regno = ira_class_hard_regs[rclass][i];
     983       328133 :       bitmap_clear (&spill_pseudos_bitmap);
     984       668607 :       for (j = hard_regno_nregs (hard_regno, mode) - 1; j >= 0; j--)
     985              :         {
     986       340474 :           if (hard_regno + j >= FIRST_PSEUDO_REGISTER)
     987              :             break;
     988       340474 :           if (try_hard_reg_pseudos_check[hard_regno + j] != curr_pseudo_check)
     989        49091 :             continue;
     990       291383 :           lra_assert (!bitmap_empty_p (&try_hard_reg_pseudos[hard_regno + j]));
     991       291383 :           bitmap_ior_into (&spill_pseudos_bitmap,
     992       291383 :                            &try_hard_reg_pseudos[hard_regno + j]);
     993              :         }
     994              :       /* Spill pseudos.  */
     995       328133 :       static_p = false;
     996       600859 :       EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
     997       288745 :         if (must_not_spill_p (spill_regno))
     998        16019 :           goto fail;
     999       272726 :         else if (non_spilled_static_chain_regno_p (spill_regno))
    1000            0 :           static_p = true;
    1001       312114 :       insn_pseudos_num = 0;
    1002       312114 :       bad_spills_num = 0;
    1003       312114 :       if (lra_dump_file != NULL)
    1004            0 :         fprintf (lra_dump_file, "   Trying %d:", hard_regno);
    1005       312114 :       sparseset_clear (live_range_reload_inheritance_pseudos);
    1006       584620 :       EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
    1007              :         {
    1008       272506 :           if (bitmap_bit_p (&insn_conflict_pseudos, spill_regno))
    1009        45101 :             insn_pseudos_num++;
    1010       272506 :           if (spill_regno >= (unsigned int) lra_bad_spill_regno_start)
    1011            0 :             bad_spills_num++;
    1012       272506 :           for (r = lra_reg_info[spill_regno].live_ranges;
    1013       897558 :                r != NULL;
    1014       625052 :                r = r->next)
    1015              :             {
    1016     55225427 :               for (p = r->start; p <= r->finish; p++)
    1017              :                 {
    1018     54600375 :                   lra_live_range_t r2;
    1019              : 
    1020     54600375 :                   for (r2 = start_point_ranges[p];
    1021     94079756 :                        r2 != NULL;
    1022     39479381 :                        r2 = r2->start_next)
    1023     39479381 :                     if (r2->regno >= lra_constraint_new_regno_start)
    1024     22850490 :                       sparseset_set_bit (live_range_reload_inheritance_pseudos,
    1025              :                                          r2->regno);
    1026              :                 }
    1027              :             }
    1028              :         }
    1029       312114 :       n = 0;
    1030       312114 :       if (sparseset_cardinality (live_range_reload_inheritance_pseudos)
    1031       312114 :           <= (unsigned)param_lra_max_considered_reload_pseudos)
    1032     14065886 :         EXECUTE_IF_SET_IN_SPARSESET (live_range_reload_inheritance_pseudos,
    1033              :                                      reload_regno)
    1034      6725414 :           if ((int) reload_regno != regno
    1035      6477320 :               && (ira_reg_classes_intersect_p
    1036      6477320 :                   [rclass][regno_allocno_class_array[reload_regno]])
    1037      5675225 :               && live_pseudos_reg_renumber[reload_regno] < 0
    1038     10085746 :               && find_hard_regno_for (reload_regno, &cost, -1, first_p) < 0)
    1039      1576186 :             sorted_reload_pseudos[n++] = reload_regno;
    1040       584620 :       EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
    1041              :         {
    1042       272506 :           update_lives (spill_regno, true);
    1043       272506 :           if (lra_dump_file != NULL)
    1044            0 :             fprintf (lra_dump_file, " spill %d(freq=%d)",
    1045            0 :                      spill_regno, lra_reg_info[spill_regno].freq);
    1046              :         }
    1047       312114 :       hard_regno = find_hard_regno_for (regno, &cost, -1, first_p);
    1048       312114 :       if (hard_regno >= 0)
    1049              :         {
    1050       263796 :           assign_temporarily (regno, hard_regno);
    1051       263796 :           qsort (sorted_reload_pseudos, n, sizeof (int),
    1052              :                  reload_pseudo_compare_func);
    1053      2096970 :           for (j = 0; j < n; j++)
    1054              :             {
    1055      1569378 :               reload_regno = sorted_reload_pseudos[j];
    1056      1569378 :               lra_assert (live_pseudos_reg_renumber[reload_regno] < 0);
    1057      3138756 :               if ((reload_hard_regno
    1058      1569378 :                    = find_hard_regno_for (reload_regno,
    1059              :                                           &reload_cost, -1, first_p)) >= 0)
    1060              :                 {
    1061       760731 :                   if (lra_dump_file != NULL)
    1062            0 :                     fprintf (lra_dump_file, " assign %d(cost=%d)",
    1063              :                              reload_regno, reload_cost);
    1064       760731 :                   assign_temporarily (reload_regno, reload_hard_regno);
    1065       760731 :                   cost += reload_cost;
    1066              :                 }
    1067              :             }
    1068       531000 :           EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
    1069              :             {
    1070       267204 :               rtx_insn_list *x;
    1071              : 
    1072       267204 :               cost += lra_reg_info[spill_regno].freq;
    1073       267204 :               if (ira_reg_equiv[spill_regno].memory != NULL
    1074       258285 :                   || ira_reg_equiv[spill_regno].constant != NULL)
    1075        10485 :                 for (x = ira_reg_equiv[spill_regno].init_insns;
    1076        19538 :                      x != NULL;
    1077         9053 :                      x = x->next ())
    1078        26760 :                   cost -= REG_FREQ_FROM_BB (BLOCK_FOR_INSN (x->insn ()));
    1079              :             }
    1080              :           /* Avoid spilling static chain pointer pseudo when non-local
    1081              :              goto is used.  */
    1082       263796 :           if ((! static_p && best_static_p)
    1083       217326 :               || (static_p == best_static_p
    1084       217326 :                   && (best_insn_pseudos_num > insn_pseudos_num
    1085       210674 :                       || (best_insn_pseudos_num == insn_pseudos_num
    1086       191138 :                           && (bad_spills_num < smallest_bad_spills_num
    1087       191138 :                               || (bad_spills_num == smallest_bad_spills_num
    1088       191138 :                                   && best_cost > cost))))))
    1089              :             {
    1090        90997 :               best_insn_pseudos_num = insn_pseudos_num;
    1091        90997 :               smallest_bad_spills_num = bad_spills_num;
    1092        90997 :               best_static_p = static_p;
    1093        90997 :               best_cost = cost;
    1094        90997 :               best_hard_regno = hard_regno;
    1095        90997 :               bitmap_copy (&best_spill_pseudos_bitmap, &spill_pseudos_bitmap);
    1096        90997 :               if (lra_dump_file != NULL)
    1097            0 :                 fprintf (lra_dump_file,
    1098              :                          "  Now best %d(cost=%d, bad_spills=%d, insn_pseudos=%d)\n",
    1099              :                          hard_regno, cost, bad_spills_num, insn_pseudos_num);
    1100              :             }
    1101       263796 :           assign_temporarily (regno, -1);
    1102      2096970 :           for (j = 0; j < n; j++)
    1103              :             {
    1104      1569378 :               reload_regno = sorted_reload_pseudos[j];
    1105      1569378 :               if (live_pseudos_reg_renumber[reload_regno] >= 0)
    1106       760731 :                 assign_temporarily (reload_regno, -1);
    1107              :             }
    1108              :         }
    1109       312114 :       if (lra_dump_file != NULL)
    1110            0 :         fprintf (lra_dump_file, "\n");
    1111              :       /* Restore the live hard reg pseudo info for spilled pseudos.  */
    1112       584620 :       EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
    1113       272506 :         update_lives (spill_regno, false);
    1114       312114 :     fail:
    1115       328133 :       ;
    1116              :     }
    1117              :   /* Spill: */
    1118        98570 :   EXECUTE_IF_SET_IN_BITMAP (&best_spill_pseudos_bitmap, 0, spill_regno, bi)
    1119              :     {
    1120        46886 :       if ((int) spill_regno >= lra_constraint_new_regno_start)
    1121         4232 :         former_reload_pseudo_spill_p = true;
    1122        46886 :       if (lra_dump_file != NULL)
    1123            0 :         fprintf (lra_dump_file, "      Spill %sr%d(hr=%d, freq=%d) for r%d\n",
    1124              :                  pseudo_prefix_title (spill_regno),
    1125            0 :                  spill_regno, reg_renumber[spill_regno],
    1126            0 :                  lra_reg_info[spill_regno].freq, regno);
    1127        46886 :       update_lives (spill_regno, true);
    1128        46886 :       lra_setup_reg_renumber (spill_regno, -1, false);
    1129              :     }
    1130        51684 :   bitmap_ior_into (spilled_pseudo_bitmap, &best_spill_pseudos_bitmap);
    1131        51684 :   return best_hard_regno;
    1132              : }
    1133              : 
    1134              : /* Assign HARD_REGNO to REGNO.  */
    1135              : static void
    1136      6396078 : assign_hard_regno (int hard_regno, int regno)
    1137              : {
    1138      6396078 :   int i;
    1139              : 
    1140      6396078 :   lra_assert (hard_regno >= 0);
    1141      6396078 :   lra_setup_reg_renumber (regno, hard_regno, true);
    1142      6396078 :   update_lives (regno, false);
    1143     12975759 :   for (i = 0;
    1144     12975759 :        i < hard_regno_nregs (hard_regno, lra_reg_info[regno].biggest_mode);
    1145              :        i++)
    1146      6579681 :     df_set_regs_ever_live (hard_regno + i, true);
    1147      6396078 : }
    1148              : 
    1149              : /* Array used for sorting different pseudos.  */
    1150              : static int *sorted_pseudos;
    1151              : 
    1152              : /* The constraints pass is allowed to create equivalences between
    1153              :    pseudos that make the current allocation "incorrect" (in the sense
    1154              :    that pseudos are assigned to hard registers from their own conflict
    1155              :    sets).  The global variable check_and_force_assignment_correctness_p says
    1156              :    whether this might have happened.
    1157              : 
    1158              :    Process pseudos assigned to hard registers (less frequently used
    1159              :    first), spill if a conflict is found, and mark the spilled pseudos
    1160              :    in SPILLED_PSEUDO_BITMAP.  Set up LIVE_HARD_REG_PSEUDOS from
    1161              :    pseudos, assigned to hard registers.  */
    1162              : static void
    1163      1538735 : setup_live_pseudos_and_spill_after_risky_transforms (bitmap
    1164              :                                                      spilled_pseudo_bitmap)
    1165              : {
    1166      1538735 :   int p, i, j, n, regno, hard_regno, biggest_nregs, nregs_diff;
    1167      1538735 :   unsigned int k, conflict_regno;
    1168      1538735 :   poly_int64 offset;
    1169      1538735 :   int val;
    1170      1538735 :   HARD_REG_SET conflict_set;
    1171      1538735 :   machine_mode mode, biggest_mode;
    1172      1538735 :   lra_live_range_t r;
    1173      1538735 :   bitmap_iterator bi;
    1174      1538735 :   int max_regno = max_reg_num ();
    1175              : 
    1176      1538735 :   if (! check_and_force_assignment_correctness_p)
    1177              :     {
    1178     20469175 :       for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
    1179     20411806 :         if (reg_renumber[i] >= 0 && lra_reg_info[i].nrefs > 0)
    1180      9851957 :           update_lives (i, false);
    1181        57369 :       return;
    1182              :     }
    1183     80375305 :   for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
    1184     78893939 :     if ((pic_offset_table_rtx == NULL_RTX
    1185      7156664 :          || i != (int) REGNO (pic_offset_table_rtx))
    1186     86001527 :         && (hard_regno = reg_renumber[i]) >= 0 && lra_reg_info[i].nrefs > 0)
    1187              :       {
    1188     31024142 :         biggest_mode = lra_reg_info[i].biggest_mode;
    1189     31024142 :         biggest_nregs = hard_regno_nregs (hard_regno, biggest_mode);
    1190     31024142 :         nregs_diff = (biggest_nregs
    1191     31024142 :                       - hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (i)));
    1192     31024142 :         enum reg_class rclass = lra_get_allocno_class (i);
    1193              : 
    1194     31024142 :         if ((WORDS_BIG_ENDIAN
    1195              :              && (hard_regno - nregs_diff < 0
    1196              :                  || !TEST_HARD_REG_BIT (reg_class_contents[rclass],
    1197              :                                         hard_regno - nregs_diff)))
    1198              :             || (!WORDS_BIG_ENDIAN
    1199     31024142 :                 && (hard_regno + nregs_diff >= FIRST_PSEUDO_REGISTER
    1200     31024142 :                     || !TEST_HARD_REG_BIT (reg_class_contents[rclass],
    1201              :                                            hard_regno + nregs_diff))))
    1202              :           {
    1203              :             /* Hard registers of paradoxical sub-registers are out of
    1204              :                range of pseudo register class.  Spill the pseudo.  */
    1205            0 :             reg_renumber[i] = -1;
    1206            0 :             continue;
    1207              :           }
    1208     31024142 :         sorted_pseudos[n++] = i;
    1209              :       }
    1210      1481366 :   qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func);
    1211      1481366 :   if (pic_offset_table_rtx != NULL_RTX
    1212        49076 :       && (regno = REGNO (pic_offset_table_rtx)) >= FIRST_PSEUDO_REGISTER
    1213      1530442 :       && reg_renumber[regno] >= 0 && lra_reg_info[regno].nrefs > 0)
    1214        43148 :     sorted_pseudos[n++] = regno;
    1215     32548656 :   for (i = n - 1; i >= 0; i--)
    1216              :     {
    1217     31067290 :       regno = sorted_pseudos[i];
    1218     31067290 :       hard_regno = reg_renumber[regno];
    1219     31067290 :       lra_assert (hard_regno >= 0);
    1220     31067290 :       mode = lra_reg_info[regno].biggest_mode;
    1221     31067290 :       sparseset_clear (live_range_hard_reg_pseudos);
    1222     67736325 :       for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
    1223              :         {
    1224     84363538 :           EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi)
    1225     47694503 :             sparseset_set_bit (live_range_hard_reg_pseudos, k);
    1226    270927715 :           for (p = r->start + 1; p <= r->finish; p++)
    1227              :             {
    1228    234258680 :               lra_live_range_t r2;
    1229              : 
    1230    234258680 :               for (r2 = start_point_ranges[p];
    1231    360628539 :                    r2 != NULL;
    1232    126369859 :                    r2 = r2->start_next)
    1233    126369859 :                 if (live_pseudos_reg_renumber[r2->regno] >= 0)
    1234     67797138 :                   sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno);
    1235              :             }
    1236              :         }
    1237     31067290 :       conflict_set = lra_no_alloc_regs;
    1238     31067290 :       conflict_set |= lra_reg_info[regno].conflict_hard_regs;
    1239     31067290 :       val = lra_reg_info[regno].val;
    1240     31067290 :       offset = lra_reg_info[regno].offset;
    1241    126289271 :       EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno)
    1242     95221981 :         if (!lra_reg_val_equal_p (conflict_regno, val, offset)
    1243              :             /* If it is multi-register pseudos they should start on
    1244              :                the same hard register.  */
    1245        80925 :             || hard_regno != reg_renumber[conflict_regno])
    1246              :           {
    1247     95152110 :             int conflict_hard_regno = reg_renumber[conflict_regno];
    1248              : 
    1249     95152110 :             biggest_mode = lra_reg_info[conflict_regno].biggest_mode;
    1250     95152110 :             biggest_nregs = hard_regno_nregs (conflict_hard_regno,
    1251              :                                               biggest_mode);
    1252     95152110 :             nregs_diff
    1253     95152110 :               = (biggest_nregs
    1254     95152110 :                  - hard_regno_nregs (conflict_hard_regno,
    1255     95152110 :                                      PSEUDO_REGNO_MODE (conflict_regno)));
    1256     95152110 :             add_to_hard_reg_set (&conflict_set,
    1257              :                                  biggest_mode,
    1258              :                                  conflict_hard_regno
    1259              :                                  - (WORDS_BIG_ENDIAN ? nregs_diff : 0));
    1260              :           }
    1261     31067290 :       if (! overlaps_hard_reg_set_p (conflict_set, mode, hard_regno))
    1262              :         {
    1263     31055219 :           update_lives (regno, false);
    1264     31055219 :           continue;
    1265              :         }
    1266        12071 :       bitmap_set_bit (spilled_pseudo_bitmap, regno);
    1267        12071 :       for (j = 0;
    1268        32045 :            j < hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (regno));
    1269              :            j++)
    1270        19974 :         lra_hard_reg_usage[hard_regno + j] -= lra_reg_info[regno].freq;
    1271        12071 :       reg_renumber[regno] = -1;
    1272        12071 :       if (regno >= lra_constraint_new_regno_start)
    1273            0 :         former_reload_pseudo_spill_p = true;
    1274        12071 :       if (lra_dump_file != NULL)
    1275            0 :         fprintf (lra_dump_file, "    Spill r%d after risky transformations\n",
    1276              :                  regno);
    1277              :     }
    1278              : }
    1279              : 
    1280              : /* Improve allocation by assigning the same hard regno of inheritance
    1281              :    pseudos to the connected pseudos.  We need this because inheritance
    1282              :    pseudos are allocated after reload pseudos in the thread and when
    1283              :    we assign a hard register to a reload pseudo we don't know yet that
    1284              :    the connected inheritance pseudos can get the same hard register.
    1285              :    Add pseudos with changed allocation to bitmap CHANGED_PSEUDOS.  */
    1286              : static void
    1287      1538735 : improve_inheritance (bitmap changed_pseudos)
    1288              : {
    1289      1538735 :   unsigned int k;
    1290      1538735 :   int regno, another_regno, hard_regno, another_hard_regno, cost, i, n;
    1291      1538735 :   lra_copy_t cp, next_cp;
    1292      1538735 :   bitmap_iterator bi;
    1293              : 
    1294      1538735 :   if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
    1295         3990 :     return;
    1296      1534745 :   n = 0;
    1297      3391871 :   EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, k, bi)
    1298      1857126 :     if (reg_renumber[k] >= 0 && lra_reg_info[k].nrefs != 0)
    1299      1248548 :       sorted_pseudos[n++] = k;
    1300      1534745 :   qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func);
    1301      4318038 :   for (i = 0; i < n; i++)
    1302              :     {
    1303      1248548 :       regno = sorted_pseudos[i];
    1304      1248548 :       hard_regno = reg_renumber[regno];
    1305      1248548 :       lra_assert (hard_regno >= 0);
    1306      3610541 :       for (cp = lra_reg_info[regno].copies; cp != NULL; cp = next_cp)
    1307              :         {
    1308      2361993 :           if (cp->regno1 == regno)
    1309              :             {
    1310       409179 :               next_cp = cp->regno1_next;
    1311       409179 :               another_regno = cp->regno2;
    1312              :             }
    1313      1952814 :           else if (cp->regno2 == regno)
    1314              :             {
    1315      1952814 :               next_cp = cp->regno2_next;
    1316      1952814 :               another_regno = cp->regno1;
    1317              :             }
    1318              :           else
    1319            0 :             gcc_unreachable ();
    1320              :           /* Don't change reload pseudo allocation.  It might have
    1321              :              this allocation for a purpose and changing it can result
    1322              :              in LRA cycling.  */
    1323      2361993 :           if ((another_regno < lra_constraint_new_regno_start
    1324      2361993 :                || bitmap_bit_p (&lra_inheritance_pseudos, another_regno))
    1325       840510 :               && (another_hard_regno = reg_renumber[another_regno]) >= 0
    1326      3091221 :               && another_hard_regno != hard_regno)
    1327              :             {
    1328        70276 :               if (lra_dump_file != NULL)
    1329            1 :                 fprintf
    1330            1 :                   (lra_dump_file,
    1331              :                    "       Improving inheritance for %d(%d) and %d(%d)...\n",
    1332              :                    regno, hard_regno, another_regno, another_hard_regno);
    1333        70276 :               update_lives (another_regno, true);
    1334        70276 :               lra_setup_reg_renumber (another_regno, -1, false);
    1335        70276 :               if (hard_regno == find_hard_regno_for (another_regno, &cost,
    1336              :                                                      hard_regno, false))
    1337        39263 :                 assign_hard_regno (hard_regno, another_regno);
    1338              :               else
    1339        31013 :                 assign_hard_regno (another_hard_regno, another_regno);
    1340        70276 :               bitmap_set_bit (changed_pseudos, another_regno);
    1341              :             }
    1342              :         }
    1343              :     }
    1344              : }
    1345              : 
    1346              : 
    1347              : /* Bitmap finally containing all pseudos spilled on this assignment
    1348              :    pass.  */
    1349              : static bitmap_head all_spilled_pseudos;
    1350              : /* All pseudos whose allocation was changed.  */
    1351              : static bitmap_head changed_pseudo_bitmap;
    1352              : 
    1353              : 
    1354              : /* Add to LIVE_RANGE_HARD_REG_PSEUDOS all pseudos conflicting with
    1355              :    REGNO and whose hard regs can be assigned to REGNO.  */
    1356              : static void
    1357         2834 : find_all_spills_for (int regno)
    1358              : {
    1359         2834 :   int p;
    1360         2834 :   lra_live_range_t r;
    1361         2834 :   unsigned int k;
    1362         2834 :   bitmap_iterator bi;
    1363         2834 :   enum reg_class rclass;
    1364         2834 :   bool *rclass_intersect_p;
    1365              : 
    1366         2834 :   rclass = regno_allocno_class_array[regno];
    1367         2834 :   rclass_intersect_p = ira_reg_classes_intersect_p[rclass];
    1368         6866 :   for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
    1369              :     {
    1370        17032 :       EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi)
    1371        13000 :         if (rclass_intersect_p[regno_allocno_class_array[k]])
    1372         7485 :           sparseset_set_bit (live_range_hard_reg_pseudos, k);
    1373         7887 :       for (p = r->start + 1; p <= r->finish; p++)
    1374              :         {
    1375         3855 :           lra_live_range_t r2;
    1376              : 
    1377         3855 :           for (r2 = start_point_ranges[p];
    1378         8924 :                r2 != NULL;
    1379         5069 :                r2 = r2->start_next)
    1380              :             {
    1381         5069 :               if (live_pseudos_reg_renumber[r2->regno] >= 0
    1382         5005 :                   && ! sparseset_bit_p (live_range_hard_reg_pseudos, r2->regno)
    1383        10071 :                   && rclass_intersect_p[regno_allocno_class_array[r2->regno]])
    1384         5001 :                 sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno);
    1385              :             }
    1386              :         }
    1387              :     }
    1388         2834 : }
    1389              : 
    1390              : /* Assign hard registers to reload pseudos and other pseudos.  Return
    1391              :    true if we was not able to assign hard registers to all reload
    1392              :    pseudos.  */
    1393              : static bool
    1394      1538735 : assign_by_spills (void)
    1395              : {
    1396      1538735 :   int i, n, nfails, iter, regno, regno2, hard_regno, cost;
    1397      1538735 :   rtx restore_rtx;
    1398      1538735 :   bitmap_head changed_insns, do_not_assign_nonreload_pseudos;
    1399      1538735 :   unsigned int u, conflict_regno;
    1400      1538735 :   bitmap_iterator bi;
    1401      1538735 :   bool reload_p, fails_p = false;
    1402      1538735 :   int max_regno = max_reg_num ();
    1403              : 
    1404     13363411 :   for (n = 0, i = lra_constraint_new_regno_start; i < max_regno; i++)
    1405     11824676 :     if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0
    1406      7612928 :         && regno_allocno_class_array[i] != NO_REGS)
    1407      6658312 :       sorted_pseudos[n++] = i;
    1408      1538735 :   bitmap_initialize (&insn_conflict_pseudos, &reg_obstack);
    1409      1538735 :   bitmap_initialize (&spill_pseudos_bitmap, &reg_obstack);
    1410      1538735 :   bitmap_initialize (&best_spill_pseudos_bitmap, &reg_obstack);
    1411      1538735 :   update_hard_regno_preference_check = XCNEWVEC (int, max_regno);
    1412      1538735 :   curr_update_hard_regno_preference_check = 0;
    1413      1538735 :   memset (try_hard_reg_pseudos_check, 0, sizeof (try_hard_reg_pseudos_check));
    1414    143102355 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    1415    141563620 :     bitmap_initialize (&try_hard_reg_pseudos[i], &reg_obstack);
    1416      1538735 :   curr_pseudo_check = 0;
    1417      1538735 :   bitmap_initialize (&changed_insns, &reg_obstack);
    1418      1538735 :   bitmap_initialize (&non_reload_pseudos, &reg_obstack);
    1419      1538735 :   bitmap_ior (&non_reload_pseudos, &lra_inheritance_pseudos, &lra_split_regs);
    1420      1538735 :   bitmap_ior_into (&non_reload_pseudos, &lra_subreg_reload_pseudos);
    1421      1538735 :   bitmap_ior_into (&non_reload_pseudos, &lra_optional_reload_pseudos);
    1422      1538735 :   for (iter = 0; iter <= 1; iter++)
    1423              :     {
    1424      1540229 :       qsort (sorted_pseudos, n, sizeof (int), reload_pseudo_compare_func);
    1425      1540229 :       nfails = 0;
    1426      8205964 :       for (i = 0; i < n; i++)
    1427              :         {
    1428      6665735 :           regno = sorted_pseudos[i];
    1429      6665735 :           if (reg_renumber[regno] >= 0)
    1430          751 :             continue;
    1431      6664984 :           if (lra_dump_file != NULL)
    1432          198 :             fprintf (lra_dump_file, "       Assigning to %d "
    1433              :                      "(cl=%s, orig=%d, freq=%d, tfirst=%d, tfreq=%d)...\n",
    1434           99 :                      regno, reg_class_names[regno_allocno_class_array[regno]],
    1435           99 :                      ORIGINAL_REGNO (regno_reg_rtx[regno]),
    1436           99 :                      lra_reg_info[regno].freq, regno_assign_info[regno].first,
    1437           99 :                      regno_assign_info[regno_assign_info[regno].first].freq);
    1438      6664984 :           hard_regno = find_hard_regno_for (regno, &cost, -1, iter == 1);
    1439      6664984 :           reload_p = ! bitmap_bit_p (&non_reload_pseudos, regno);
    1440      6664984 :           if (hard_regno < 0 && reload_p)
    1441        51684 :             hard_regno = spill_for (regno, &all_spilled_pseudos, iter == 1);
    1442      6664984 :           if (hard_regno < 0)
    1443              :             {
    1444       464414 :               if (reload_p)
    1445              :                 {
    1446              :                   /* Put unassigned reload pseudo first in the array.  */
    1447         5214 :                   regno2 = sorted_pseudos[nfails];
    1448         5214 :                   sorted_pseudos[nfails++] = regno;
    1449         5214 :                   sorted_pseudos[i] = regno2;
    1450              :                 }
    1451              :               else
    1452              :                 {
    1453              :                   /* Consider all alternatives on the next constraint
    1454              :                      subpass.  */
    1455       459200 :                   bitmap_set_bit (&all_spilled_pseudos, regno);
    1456              :                 }
    1457              :             }
    1458              :           else
    1459              :             {
    1460              :               /* This register might have been spilled by the previous
    1461              :                  pass.  Indicate that it is no longer spilled.  */
    1462      6200570 :               bitmap_clear_bit (&all_spilled_pseudos, regno);
    1463      6200570 :               assign_hard_regno (hard_regno, regno);
    1464      6200570 :               if (! reload_p || regno_allocno_class_array[regno] == ALL_REGS)
    1465              :                 /* As non-reload pseudo assignment is changed we should
    1466              :                    reconsider insns referring for the pseudo.  Do the same if a
    1467              :                    reload pseudo did not refine its class which can happens
    1468              :                    when the pseudo occurs only in reload insns.  */
    1469      1368975 :                 bitmap_set_bit (&changed_pseudo_bitmap, regno);
    1470              :             }
    1471              :         }
    1472      1540229 :       if (nfails == 0 || iter > 0)
    1473              :         {
    1474      1538735 :           fails_p = nfails != 0;
    1475      1538735 :           break;
    1476              :         }
    1477              :       /* This is a very rare event.  We cannot assign a hard register
    1478              :          to reload pseudo because the hard register was assigned to
    1479              :          another reload pseudo on a previous assignment pass.  For x86
    1480              :          example, on the 1st pass we assigned CX (although another
    1481              :          hard register could be used for this) to reload pseudo in an
    1482              :          insn, on the 2nd pass we need CX (and only this) hard
    1483              :          register for a new reload pseudo in the same insn.  Another
    1484              :          possible situation may occur in assigning to multi-regs
    1485              :          reload pseudos when hard regs pool is too fragmented even
    1486              :          after spilling non-reload pseudos.
    1487              : 
    1488              :          We should do something radical here to succeed.  Here we
    1489              :          spill *all* conflicting pseudos and reassign them.  */
    1490         1494 :       if (lra_dump_file != NULL)
    1491            0 :         fprintf (lra_dump_file, "  2nd iter for reload pseudo assignments:\n");
    1492         1494 :       sparseset_clear (live_range_hard_reg_pseudos);
    1493         4328 :       for (i = 0; i < nfails; i++)
    1494              :         {
    1495         2834 :           if (lra_dump_file != NULL)
    1496            0 :             fprintf (lra_dump_file, "       Reload r%d assignment failure\n",
    1497            0 :                      sorted_pseudos[i]);
    1498         2834 :           find_all_spills_for (sorted_pseudos[i]);
    1499              :         }
    1500        16766 :       EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno)
    1501              :         {
    1502         7636 :           if ((int) conflict_regno >= lra_constraint_new_regno_start)
    1503              :             {
    1504         1927 :               sorted_pseudos[nfails++] = conflict_regno;
    1505         1927 :               former_reload_pseudo_spill_p = true;
    1506              :             }
    1507              :           else
    1508              :             /* It is better to do reloads before spilling as after the
    1509              :                spill-subpass we will reload memory instead of pseudos
    1510              :                and this will make reusing reload pseudos more
    1511              :                complicated.  Going directly to the spill pass in such
    1512              :                case might result in worse code performance or even LRA
    1513              :                cycling if we have few registers.  */
    1514         5709 :             bitmap_set_bit (&all_spilled_pseudos, conflict_regno);
    1515         7636 :           if (lra_dump_file != NULL)
    1516            0 :             fprintf (lra_dump_file, "        Spill %s r%d(hr=%d, freq=%d)\n",
    1517              :                      pseudo_prefix_title (conflict_regno), conflict_regno,
    1518            0 :                      reg_renumber[conflict_regno],
    1519            0 :                      lra_reg_info[conflict_regno].freq);
    1520         7636 :           update_lives (conflict_regno, true);
    1521         7636 :           lra_setup_reg_renumber (conflict_regno, -1, false);
    1522              :         }
    1523         1494 :       if (n < nfails)
    1524              :         n = nfails;
    1525              :     }
    1526      1538735 :   improve_inheritance (&changed_pseudo_bitmap);
    1527      1538735 :   bitmap_clear (&non_reload_pseudos);
    1528      1538735 :   bitmap_clear (&changed_insns);
    1529      1538735 :   if (! lra_simple_p)
    1530              :     {
    1531              :       /* We should not assign to original pseudos of inheritance
    1532              :          pseudos or split pseudos if any its inheritance pseudo did
    1533              :          not get hard register or any its split pseudo was not split
    1534              :          because undo inheritance/split pass will extend live range of
    1535              :          such inheritance or split pseudos.  */
    1536      1538729 :       bitmap_initialize (&do_not_assign_nonreload_pseudos, &reg_obstack);
    1537      3575885 :       EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, u, bi)
    1538      2037156 :         if ((restore_rtx = lra_reg_info[u].restore_rtx) != NULL_RTX
    1539      1173227 :             && REG_P (restore_rtx)
    1540      1151076 :             && reg_renumber[u] < 0
    1541      2468850 :             && bitmap_bit_p (&lra_inheritance_pseudos, u))
    1542       431694 :           bitmap_set_bit (&do_not_assign_nonreload_pseudos, REGNO (restore_rtx));
    1543      2508126 :       EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, u, bi)
    1544       969397 :         if ((restore_rtx = lra_reg_info[u].restore_rtx) != NULL_RTX
    1545       969397 :             && reg_renumber[u] >= 0)
    1546              :           {
    1547          859 :             lra_assert (REG_P (restore_rtx));
    1548          859 :             bitmap_set_bit (&do_not_assign_nonreload_pseudos, REGNO (restore_rtx));
    1549              :           }
    1550    100614211 :       for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
    1551     99075482 :         if (((i < lra_constraint_new_regno_start
    1552     87254500 :               && ! bitmap_bit_p (&do_not_assign_nonreload_pseudos, i))
    1553     12115167 :              || (bitmap_bit_p (&lra_inheritance_pseudos, i)
    1554      2037156 :                  && lra_reg_info[i].restore_rtx != NULL_RTX)
    1555     10941940 :              || (bitmap_bit_p (&lra_split_regs, i)
    1556       969397 :                  && lra_reg_info[i].restore_rtx != NULL_RTX)
    1557     10280843 :              || bitmap_bit_p (&lra_subreg_reload_pseudos, i)
    1558     10280384 :              || bitmap_bit_p (&lra_optional_reload_pseudos, i))
    1559     89909744 :             && reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0
    1560    101436562 :             && regno_allocno_class_array[i] != NO_REGS)
    1561      1661637 :           sorted_pseudos[n++] = i;
    1562      1538729 :       bitmap_clear (&do_not_assign_nonreload_pseudos);
    1563      1538729 :       if (n != 0 && lra_dump_file != NULL)
    1564            2 :         fprintf (lra_dump_file, "  Reassigning non-reload pseudos\n");
    1565      1538729 :       qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func);
    1566      3200366 :       for (i = 0; i < n; i++)
    1567              :         {
    1568      1661637 :           regno = sorted_pseudos[i];
    1569      1661637 :           hard_regno = find_hard_regno_for (regno, &cost, -1, false);
    1570      1661637 :           if (hard_regno >= 0)
    1571              :             {
    1572       125232 :               assign_hard_regno (hard_regno, regno);
    1573              :               /* We change allocation for non-reload pseudo on this
    1574              :                  iteration -- mark the pseudo for invalidation of used
    1575              :                  alternatives of insns containing the pseudo.  */
    1576       125232 :               bitmap_set_bit (&changed_pseudo_bitmap, regno);
    1577              :             }
    1578              :           else
    1579              :             {
    1580      1536405 :               enum reg_class rclass = lra_get_allocno_class (regno);
    1581      1536405 :               enum reg_class spill_class;
    1582              : 
    1583      3072810 :               if (targetm.spill_class == NULL
    1584      1536405 :                   || lra_reg_info[regno].restore_rtx == NULL_RTX
    1585       441918 :                   || ! bitmap_bit_p (&lra_inheritance_pseudos, regno)
    1586      1536405 :                   || (spill_class
    1587       424577 :                       = ((enum reg_class)
    1588       424577 :                          targetm.spill_class
    1589       424577 :                          ((reg_class_t) rclass,
    1590       424577 :                           PSEUDO_REGNO_MODE (regno)))) == NO_REGS)
    1591      1536405 :                 continue;
    1592            0 :               regno_allocno_class_array[regno] = spill_class;
    1593            0 :               hard_regno = find_hard_regno_for (regno, &cost, -1, false);
    1594            0 :               if (hard_regno < 0)
    1595            0 :                 regno_allocno_class_array[regno] = rclass;
    1596              :               else
    1597              :                 {
    1598            0 :                   setup_reg_classes
    1599            0 :                     (regno, spill_class, spill_class, spill_class);
    1600            0 :                   assign_hard_regno (hard_regno, regno);
    1601            0 :                   bitmap_set_bit (&changed_pseudo_bitmap, regno);
    1602              :                 }
    1603              :             }
    1604              :         }
    1605              :     }
    1606      1538735 :   free (update_hard_regno_preference_check);
    1607      1538735 :   bitmap_clear (&best_spill_pseudos_bitmap);
    1608      1538735 :   bitmap_clear (&spill_pseudos_bitmap);
    1609      1538735 :   bitmap_clear (&insn_conflict_pseudos);
    1610      1538735 :   return fails_p;
    1611              : }
    1612              : 
    1613              : /* Entry function to assign hard registers to new reload pseudos
    1614              :    starting with LRA_CONSTRAINT_NEW_REGNO_START (by possible spilling
    1615              :    of old pseudos) and possibly to the old pseudos.  The function adds
    1616              :    what insns to process for the next constraint pass.  Those are all
    1617              :    insns who contains non-reload and non-inheritance pseudos with
    1618              :    changed allocation.
    1619              : 
    1620              :    Return true if we did not spill any non-reload and non-inheritance
    1621              :    pseudos.  Set up FAILS_P if we failed to assign hard registers to
    1622              :    all reload pseudos.  */
    1623              : bool
    1624      1538735 : lra_assign (bool &fails_p)
    1625              : {
    1626      1538735 :   int i;
    1627      1538735 :   unsigned int u;
    1628      1538735 :   bitmap_iterator bi;
    1629      1538735 :   bitmap_head insns_to_process;
    1630      1538735 :   bool no_spills_p;
    1631      1538735 :   int max_regno = max_reg_num ();
    1632              : 
    1633      1538735 :   timevar_push (TV_LRA_ASSIGN);
    1634      1538735 :   lra_assignment_iter++;
    1635      1538735 :   if (lra_dump_file != NULL)
    1636           97 :     fprintf (lra_dump_file, "\n********** Assignment #%d: **********\n\n",
    1637              :              lra_assignment_iter);
    1638      1538735 :   init_lives ();
    1639      1538735 :   sorted_pseudos = XNEWVEC (int, max_regno);
    1640      1538735 :   sorted_reload_pseudos = XNEWVEC (int, max_regno);
    1641      1538735 :   regno_allocno_class_array = XNEWVEC (enum reg_class, max_regno);
    1642      1538735 :   regno_live_length = XNEWVEC (int, max_regno);
    1643    100844480 :   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
    1644              :     {
    1645     99305745 :       int l;
    1646     99305745 :       lra_live_range_t r;
    1647              : 
    1648     99305745 :       regno_allocno_class_array[i] = lra_get_allocno_class (i);
    1649    159082241 :       for (l = 0, r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
    1650     59776496 :         l  += r->finish - r->start + 1;
    1651     99305745 :       regno_live_length[i] = l;
    1652              :     }
    1653      1538735 :   former_reload_pseudo_spill_p = false;
    1654      1538735 :   init_regno_assign_info ();
    1655      1538735 :   bitmap_initialize (&all_spilled_pseudos, &reg_obstack);
    1656      1538735 :   create_live_range_start_chains ();
    1657      1538735 :   setup_live_pseudos_and_spill_after_risky_transforms (&all_spilled_pseudos);
    1658      1538735 :   if (! lra_hard_reg_split_p && ! lra_asm_error_p && flag_checking)
    1659              :     /* Check correctness of allocation but only when there are no hard reg
    1660              :        splits and asm errors as in the case of errors explicit insns involving
    1661              :        hard regs are added or the asm is removed and this can result in
    1662              :        incorrect allocation.  */
    1663    100202653 :     for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
    1664     98665339 :       if (lra_reg_info[i].nrefs != 0
    1665     49499007 :           && reg_renumber[i] >= 0
    1666     98665339 :           && overlaps_hard_reg_set_p (lra_reg_info[i].conflict_hard_regs,
    1667     40600507 :                                       PSEUDO_REGNO_MODE (i), reg_renumber[i]))
    1668            0 :         gcc_unreachable ();
    1669              :   /* Setup insns to process on the next constraint pass.  */
    1670      1538735 :   bitmap_initialize (&changed_pseudo_bitmap, &reg_obstack);
    1671      1538735 :   init_live_reload_and_inheritance_pseudos ();
    1672      1538735 :   fails_p = assign_by_spills ();
    1673      1538735 :   finish_live_reload_and_inheritance_pseudos ();
    1674      1538735 :   bitmap_ior_into (&changed_pseudo_bitmap, &all_spilled_pseudos);
    1675      1538735 :   no_spills_p = true;
    1676      1811240 :   EXECUTE_IF_SET_IN_BITMAP (&all_spilled_pseudos, 0, u, bi)
    1677              :     /* We ignore spilled pseudos created on last inheritance pass
    1678              :        because they will be removed.  */
    1679       300487 :     if (lra_reg_info[u].restore_rtx == NULL_RTX)
    1680              :       {
    1681              :         no_spills_p = false;
    1682              :         break;
    1683              :       }
    1684      1538735 :   finish_live_range_start_chains ();
    1685      1538735 :   bitmap_clear (&all_spilled_pseudos);
    1686      1538735 :   bitmap_initialize (&insns_to_process, &reg_obstack);
    1687      3520677 :   EXECUTE_IF_SET_IN_BITMAP (&changed_pseudo_bitmap, 0, u, bi)
    1688      1981942 :     bitmap_ior_into (&insns_to_process, &lra_reg_info[u].insn_bitmap);
    1689      1538735 :   bitmap_clear (&changed_pseudo_bitmap);
    1690      6307946 :   EXECUTE_IF_SET_IN_BITMAP (&insns_to_process, 0, u, bi)
    1691              :     {
    1692      4769211 :       lra_push_insn_by_uid (u);
    1693              :       /* Invalidate alternatives for insn should be processed.  */
    1694      4769211 :       lra_set_used_insn_alternative_by_uid (u, -1);
    1695              :     }
    1696      1538735 :   bitmap_clear (&insns_to_process);
    1697      1538735 :   finish_regno_assign_info ();
    1698      1538735 :   free (regno_live_length);
    1699      1538735 :   free (regno_allocno_class_array);
    1700      1538735 :   free (sorted_pseudos);
    1701      1538735 :   free (sorted_reload_pseudos);
    1702      1538735 :   finish_lives ();
    1703      1538735 :   timevar_pop (TV_LRA_ASSIGN);
    1704      1538735 :   if (former_reload_pseudo_spill_p)
    1705         1929 :     lra_assignment_iter_after_spill++;
    1706              :   /* This is conditional on flag_checking because valid code can take
    1707              :      more than this maximum number of iteration, but at the same time
    1708              :      the test can uncover errors in machine descriptions.  */
    1709      1538735 :   if (flag_checking
    1710      1538715 :       && (lra_assignment_iter_after_spill
    1711      1538715 :           > LRA_MAX_ASSIGNMENT_ITERATION_NUMBER))
    1712            0 :     internal_error
    1713            0 :       ("maximum number of LRA assignment passes is achieved (%d)",
    1714              :        LRA_MAX_ASSIGNMENT_ITERATION_NUMBER);
    1715              :   /* Reset the assignment correctness flag: */
    1716      1538735 :   check_and_force_assignment_correctness_p = false;
    1717      1538735 :   return no_spills_p;
    1718              : }
    1719              : 
    1720              : /* Find start and finish insns for reload pseudo REGNO.  Return true
    1721              :    if we managed to find the expected insns.  Return false,
    1722              :    otherwise.  */
    1723              : static bool
    1724         2380 : find_reload_regno_insns (int regno, rtx_insn * &start, rtx_insn * &finish)
    1725              : {
    1726         2380 :   unsigned int uid;
    1727         2380 :   bitmap_iterator bi;
    1728         2380 :   int insns_num = 0;
    1729         2380 :   bool clobber_p = false;
    1730         2380 :   rtx_insn *prev_insn, *next_insn;
    1731         2380 :   rtx_insn *start_insn = NULL, *first_insn = NULL, *second_insn = NULL;
    1732              : 
    1733         8150 :   EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
    1734              :     {
    1735         5770 :       if (start_insn == NULL)
    1736         2380 :         start_insn = lra_insn_recog_data[uid]->insn;
    1737         5770 :       if (GET_CODE (PATTERN (lra_insn_recog_data[uid]->insn)) == CLOBBER)
    1738              :         clobber_p = true;
    1739              :       else
    1740         5770 :         insns_num++;
    1741              :     }
    1742              :   /* For reload pseudo we should have at most 3 insns besides clobber referring for
    1743              :      it: input/output reload insns and the original insn.  */
    1744         2380 :   if (insns_num > 3)
    1745              :     return false;
    1746         2380 :   if (clobber_p)
    1747            0 :     insns_num++;
    1748         2380 :   if (insns_num > 1)
    1749              :     {
    1750         2174 :       for (prev_insn = PREV_INSN (start_insn),
    1751         2174 :              next_insn = NEXT_INSN (start_insn);
    1752       115346 :            insns_num != 1 && (prev_insn != NULL
    1753         1197 :                               || (next_insn != NULL && second_insn == NULL)); )
    1754              :         {
    1755              :           if (prev_insn != NULL)
    1756              :             {
    1757       113172 :               if (bitmap_bit_p (&lra_reg_info[regno].insn_bitmap,
    1758       113172 :                                 INSN_UID (prev_insn)))
    1759              :                 {
    1760          682 :                   first_insn = prev_insn;
    1761          682 :                   insns_num--;
    1762              :                 }
    1763       113172 :                 prev_insn = PREV_INSN (prev_insn);
    1764              :             }
    1765       113172 :           if (next_insn != NULL && second_insn == NULL)
    1766              :             {
    1767         3392 :               if (! bitmap_bit_p (&lra_reg_info[regno].insn_bitmap,
    1768         3392 :                                 INSN_UID (next_insn)))
    1769         1881 :                 next_insn = NEXT_INSN (next_insn);
    1770              :               else
    1771              :                 {
    1772         1511 :                   second_insn = next_insn;
    1773         1511 :                   insns_num--;
    1774              :                 }
    1775              :             }
    1776              :         }
    1777         2174 :       if (insns_num > 1)
    1778              :         return false;
    1779              :     }
    1780          977 :   start = first_insn != NULL ? first_insn : start_insn;
    1781         1183 :   finish = second_insn != NULL ? second_insn : start_insn;
    1782         1183 :   return true;
    1783              : }
    1784              : 
    1785              : /* Process reload pseudos which did not get a hard reg, split a hard reg live
    1786              :    range in live range of a reload pseudo, and then return TRUE.  Otherwise,
    1787              :    return FALSE.  When FAIL_P is TRUE and if we did not split a hard reg live
    1788              :    range for failed reload pseudos, report an error and modify related asm
    1789              :    insns.  */
    1790              : bool
    1791         1400 : lra_split_hard_reg_for (bool fail_p)
    1792              : {
    1793         1400 :   int i, regno;
    1794         1400 :   rtx_insn *insn, *first, *last;
    1795         1400 :   unsigned int u;
    1796         1400 :   bitmap_iterator bi;
    1797         1400 :   enum reg_class rclass;
    1798         1400 :   int max_regno = max_reg_num ();
    1799              :   /* We did not assign hard regs to reload pseudos after two
    1800              :      iterations.  Either it's an asm and something is wrong with the
    1801              :      constraints, or we have run out of spill registers; error out in
    1802              :      either case.  */
    1803         1400 :   bool asm_p = false, spill_p = false;
    1804         1400 :   bitmap_head failed_reload_insns, failed_reload_pseudos, over_split_insns;
    1805              : 
    1806         1400 :   if (lra_dump_file != NULL)
    1807            0 :     fprintf (lra_dump_file,
    1808              :              "\n****** Splitting a hard reg after assignment #%d: ******\n\n",
    1809              :              lra_assignment_iter);
    1810         1400 :   bitmap_initialize (&failed_reload_pseudos, &reg_obstack);
    1811         1400 :   bitmap_initialize (&non_reload_pseudos, &reg_obstack);
    1812         1400 :   bitmap_ior (&non_reload_pseudos, &lra_inheritance_pseudos, &lra_split_regs);
    1813         1400 :   bitmap_ior_into (&non_reload_pseudos, &lra_subreg_reload_pseudos);
    1814         1400 :   bitmap_ior_into (&non_reload_pseudos, &lra_optional_reload_pseudos);
    1815         1400 :   bitmap_initialize (&over_split_insns, &reg_obstack);
    1816         1400 :   update_hard_regno_preference_check = XCNEWVEC (int, max_regno);
    1817         1400 :   curr_update_hard_regno_preference_check = 0;
    1818        16147 :   for (i = lra_constraint_new_regno_start; i < max_regno; i++)
    1819         5303 :     if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0
    1820         4474 :         && (rclass = lra_get_allocno_class (i)) != NO_REGS
    1821        19180 :         && ! bitmap_bit_p (&non_reload_pseudos, i))
    1822              :       {
    1823         2380 :         if (! find_reload_regno_insns (i, first, last))
    1824         1197 :           continue;
    1825         1183 :         if (BLOCK_FOR_INSN (first) == BLOCK_FOR_INSN (last))
    1826              :           {
    1827              :             /* Check that we are not trying to split over the same insn
    1828              :                requiring reloads to avoid splitting the same hard reg twice or
    1829              :                more.  If we need several hard regs splitting over the same insn
    1830              :                it can be finished on the next iterations.
    1831              : 
    1832              :                The following loop iteration number is small as we split hard
    1833              :                reg in a very small range.  */
    1834         2186 :             for (insn = first;
    1835         3369 :                  insn != NEXT_INSN (last);
    1836         2186 :                  insn = NEXT_INSN (insn))
    1837         2195 :               if (bitmap_bit_p (&over_split_insns, INSN_UID (insn)))
    1838              :                 break;
    1839         1183 :             if (insn != NEXT_INSN (last)
    1840         1183 :                 || !spill_hard_reg_in_range (i, rclass, first, last))
    1841              :               {
    1842         1024 :                 bitmap_set_bit (&failed_reload_pseudos, i);
    1843              :               }
    1844              :             else
    1845              :               {
    1846          302 :                 for (insn = first;
    1847          461 :                      insn != NEXT_INSN (last);
    1848          302 :                      insn = NEXT_INSN (insn))
    1849          302 :                   bitmap_set_bit (&over_split_insns, INSN_UID (insn));
    1850              :                 spill_p = true;
    1851              :               }
    1852              :           }
    1853              :       }
    1854         1400 :   bitmap_clear (&over_split_insns);
    1855         1400 :   bitmap_clear (&non_reload_pseudos);
    1856         1400 :   if (spill_p)
    1857              :     {
    1858           98 :       lra_dump_insns_if_possible ("changed func after splitting hard regs");
    1859              :     }
    1860              :   else
    1861              :     {
    1862         1302 :       bitmap_initialize (&failed_reload_insns, &reg_obstack);
    1863         2317 :       EXECUTE_IF_SET_IN_BITMAP (&failed_reload_pseudos, 0, u, bi)
    1864              :         {
    1865         1015 :           regno = u;
    1866         1015 :           bitmap_ior_into (&failed_reload_insns,
    1867         1015 :                            &lra_reg_info[regno].insn_bitmap);
    1868         1015 :           if (fail_p)
    1869           47 :             lra_setup_reg_renumber
    1870           94 :               (regno, ira_class_hard_regs[lra_get_allocno_class (regno)][0],
    1871              :                false);
    1872              :         }
    1873         1302 :       if (fail_p)
    1874          182 :         EXECUTE_IF_SET_IN_BITMAP (&failed_reload_insns, 0, u, bi)
    1875              :           {
    1876           81 :             insn = lra_insn_recog_data[u]->insn;
    1877           81 :             if (asm_noperands (PATTERN (insn)) >= 0)
    1878              :               {
    1879           47 :                 asm_p = true;
    1880           47 :                 lra_asm_insn_error (insn);
    1881              :               }
    1882           34 :             else if (!asm_p)
    1883              :               {
    1884            0 :                 error ("unable to find a register to spill");
    1885            0 :                 fatal_insn ("this is the insn:", insn);
    1886              :               }
    1887              :           }
    1888         1302 :       bitmap_clear (&failed_reload_insns);
    1889              :     }
    1890         1400 :   free (update_hard_regno_preference_check);
    1891         1400 :   bitmap_clear (&failed_reload_pseudos);
    1892         1400 :   return spill_p;
    1893              : }
        

Generated by: LCOV version 2.4-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.