LCOV - code coverage report
Current view: top level - gcc - ira-build.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 72.2 % 1952 1410
Test Date: 2026-07-11 15:47:05 Functions: 78.8 % 118 93
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Building internal representation for IRA.
       2              :    Copyright (C) 2006-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              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "backend.h"
      25              : #include "target.h"
      26              : #include "rtl.h"
      27              : #include "predict.h"
      28              : #include "df.h"
      29              : #include "insn-config.h"
      30              : #include "regs.h"
      31              : #include "memmodel.h"
      32              : #include "ira.h"
      33              : #include "ira-int.h"
      34              : #include "sparseset.h"
      35              : #include "cfgloop.h"
      36              : 
      37              : static ira_copy_t find_allocno_copy (ira_allocno_t, ira_allocno_t, rtx_insn *,
      38              :                                      ira_loop_tree_node_t);
      39              : 
      40              : /* The root of the loop tree corresponding to the all function.  */
      41              : ira_loop_tree_node_t ira_loop_tree_root;
      42              : 
      43              : /* Height of the loop tree.  */
      44              : int ira_loop_tree_height;
      45              : 
      46              : /* All nodes representing basic blocks are referred through the
      47              :    following array.  We cannot use basic block member `aux' for this
      48              :    because it is used for insertion of insns on edges.  */
      49              : ira_loop_tree_node_t ira_bb_nodes;
      50              : 
      51              : /* All nodes representing loops are referred through the following
      52              :    array.  */
      53              : ira_loop_tree_node_t ira_loop_nodes;
      54              : 
      55              : /* And size of the ira_loop_nodes array.  */
      56              : unsigned int ira_loop_nodes_count;
      57              : 
      58              : /* Map regno -> allocnos with given regno (see comments for
      59              :    allocno member `next_regno_allocno').  */
      60              : ira_allocno_t *ira_regno_allocno_map;
      61              : 
      62              : /* Array of references to all allocnos.  The order number of the
      63              :    allocno corresponds to the index in the array.  Removed allocnos
      64              :    have NULL element value.  */
      65              : ira_allocno_t *ira_allocnos;
      66              : 
      67              : /* Sizes of the previous array.  */
      68              : int ira_allocnos_num;
      69              : 
      70              : /* Count of conflict record structures we've created, used when creating
      71              :    a new conflict id.  */
      72              : int ira_objects_num;
      73              : 
      74              : /* Map a conflict id to its conflict record.  */
      75              : ira_object_t *ira_object_id_map;
      76              : 
      77              : /* Array of references to all allocno preferences.  The order number
      78              :    of the preference corresponds to the index in the array.  */
      79              : ira_pref_t *ira_prefs;
      80              : 
      81              : /* Size of the previous array.  */
      82              : int ira_prefs_num;
      83              : 
      84              : /* Array of references to all copies.  The order number of the copy
      85              :    corresponds to the index in the array.  Removed copies have NULL
      86              :    element value.  */
      87              : ira_copy_t *ira_copies;
      88              : 
      89              : /* Size of the previous array.  */
      90              : int ira_copies_num;
      91              : 
      92              : 
      93              : 
      94              : /* LAST_BASIC_BLOCK before generating additional insns because of live
      95              :    range splitting.  Emitting insns on a critical edge creates a new
      96              :    basic block.  */
      97              : static int last_basic_block_before_change;
      98              : 
      99              : /* Initialize some members in loop tree node NODE.  Use LOOP_NUM for
     100              :    the member loop_num.  */
     101              : static void
     102      2114563 : init_loop_tree_node (struct ira_loop_tree_node *node, int loop_num)
     103              : {
     104      2114563 :   int max_regno = max_reg_num ();
     105              : 
     106      2114563 :   node->regno_allocno_map
     107      2114563 :     = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t) * max_regno);
     108      2114563 :   memset (node->regno_allocno_map, 0, sizeof (ira_allocno_t) * max_regno);
     109      2114563 :   memset (node->reg_pressure, 0, sizeof (node->reg_pressure));
     110      2114563 :   node->all_allocnos = ira_allocate_bitmap ();
     111      2114563 :   node->modified_regnos = ira_allocate_bitmap ();
     112      2114563 :   node->border_allocnos = ira_allocate_bitmap ();
     113      2114563 :   node->local_copies = ira_allocate_bitmap ();
     114      2114563 :   node->loop_num = loop_num;
     115      2114563 :   node->children = NULL;
     116      2114563 :   node->subloops = NULL;
     117      2114563 : }
     118              : 
     119              : 
     120              : /* The following function allocates the loop tree nodes.  If
     121              :    CURRENT_LOOPS is NULL, the nodes corresponding to the loops (except
     122              :    the root which corresponds the all function) will be not allocated
     123              :    but nodes will still be allocated for basic blocks.  */
     124              : static void
     125      1504950 : create_loop_tree_nodes (void)
     126              : {
     127      1504950 :   unsigned int i, j;
     128      1504950 :   bool skip_p;
     129      1504950 :   edge_iterator ei;
     130      1504950 :   edge e;
     131      1504950 :   loop_p loop;
     132              : 
     133      1504950 :   ira_bb_nodes
     134      1504950 :     = ((struct ira_loop_tree_node *)
     135      1504950 :        ira_allocate (sizeof (struct ira_loop_tree_node)
     136      1504950 :                      * last_basic_block_for_fn (cfun)));
     137      1504950 :   last_basic_block_before_change = last_basic_block_for_fn (cfun);
     138     19147586 :   for (i = 0; i < (unsigned int) last_basic_block_for_fn (cfun); i++)
     139              :     {
     140     17642636 :       ira_bb_nodes[i].regno_allocno_map = NULL;
     141     17642636 :       memset (ira_bb_nodes[i].reg_pressure, 0,
     142              :               sizeof (ira_bb_nodes[i].reg_pressure));
     143     17642636 :       ira_bb_nodes[i].all_allocnos = NULL;
     144     17642636 :       ira_bb_nodes[i].modified_regnos = NULL;
     145     17642636 :       ira_bb_nodes[i].border_allocnos = NULL;
     146     17642636 :       ira_bb_nodes[i].local_copies = NULL;
     147              :     }
     148      1504950 :   if (current_loops == NULL)
     149              :     {
     150       494155 :       ira_loop_nodes_count = 1;
     151       988310 :       ira_loop_nodes = ((struct ira_loop_tree_node *)
     152       494155 :                         ira_allocate (sizeof (struct ira_loop_tree_node)));
     153       494155 :       init_loop_tree_node (ira_loop_nodes, 0);
     154       494155 :       return;
     155              :     }
     156      1010795 :   ira_loop_nodes_count = number_of_loops (cfun);
     157      2021590 :   ira_loop_nodes = ((struct ira_loop_tree_node *)
     158      1010795 :                     ira_allocate (sizeof (struct ira_loop_tree_node)
     159      1010795 :                                   * ira_loop_nodes_count));
     160      3657227 :   FOR_EACH_VEC_SAFE_ELT (get_loops (cfun), i, loop)
     161              :     {
     162      1635637 :       if (loop_outer (loop) != NULL)
     163              :         {
     164       624842 :           ira_loop_nodes[i].regno_allocno_map = NULL;
     165       624842 :           skip_p = false;
     166      1948717 :           FOR_EACH_EDGE (e, ei, loop->header->preds)
     167      1323875 :             if (e->src != loop->latch
     168      1323875 :                 && (e->flags & EDGE_ABNORMAL) && EDGE_CRITICAL_P (e))
     169              :               {
     170              :                 skip_p = true;
     171              :                 break;
     172              :               }
     173       624842 :           if (skip_p)
     174        15229 :             continue;
     175       624842 :           auto_vec<edge> edges = get_loop_exit_edges (loop);
     176      2319603 :           FOR_EACH_VEC_ELT (edges, j, e)
     177      1085148 :             if ((e->flags & EDGE_ABNORMAL) && EDGE_CRITICAL_P (e))
     178              :               {
     179              :                 skip_p = true;
     180              :                 break;
     181              :               }
     182       624842 :           if (skip_p)
     183        15229 :             continue;
     184       624842 :         }
     185      1620408 :       init_loop_tree_node (&ira_loop_nodes[i], loop->num);
     186              :     }
     187              : }
     188              : 
     189              : /* The function returns TRUE if there are more one allocation
     190              :    region.  */
     191              : static bool
     192      1504950 : more_one_region_p (void)
     193              : {
     194      1504950 :   unsigned int i;
     195      1504950 :   loop_p loop;
     196              : 
     197      1504950 :   if (current_loops != NULL)
     198      2467564 :     FOR_EACH_VEC_SAFE_ELT (get_loops (cfun), i, loop)
     199      1492280 :       if (ira_loop_nodes[i].regno_allocno_map != NULL
     200      1046306 :           && ira_loop_tree_root != &ira_loop_nodes[i])
     201              :         return true;
     202              :   return false;
     203              : }
     204              : 
     205              : /* Free the loop tree node of a loop.  */
     206              : static void
     207      2573486 : finish_loop_tree_node (ira_loop_tree_node_t loop)
     208              : {
     209      2573486 :   if (loop->regno_allocno_map != NULL)
     210              :     {
     211      2114563 :       ira_assert (loop->bb == NULL);
     212      2114563 :       ira_free_bitmap (loop->local_copies);
     213      2114563 :       ira_free_bitmap (loop->border_allocnos);
     214      2114563 :       ira_free_bitmap (loop->modified_regnos);
     215      2114563 :       ira_free_bitmap (loop->all_allocnos);
     216      2114563 :       ira_free (loop->regno_allocno_map);
     217      2114563 :       loop->regno_allocno_map = NULL;
     218              :     }
     219      2573486 : }
     220              : 
     221              : /* Free the loop tree nodes.  */
     222              : static void
     223      1504950 : finish_loop_tree_nodes (void)
     224              : {
     225      1504950 :   unsigned int i;
     226              : 
     227      3634742 :   for (i = 0; i < ira_loop_nodes_count; i++)
     228      2129792 :     finish_loop_tree_node (&ira_loop_nodes[i]);
     229      1504950 :   ira_free (ira_loop_nodes);
     230     20652536 :   for (i = 0; i < (unsigned int) last_basic_block_before_change; i++)
     231              :     {
     232     17642636 :       if (ira_bb_nodes[i].local_copies != NULL)
     233            0 :         ira_free_bitmap (ira_bb_nodes[i].local_copies);
     234     17642636 :       if (ira_bb_nodes[i].border_allocnos != NULL)
     235            0 :         ira_free_bitmap (ira_bb_nodes[i].border_allocnos);
     236     17642636 :       if (ira_bb_nodes[i].modified_regnos != NULL)
     237            0 :         ira_free_bitmap (ira_bb_nodes[i].modified_regnos);
     238     17642636 :       if (ira_bb_nodes[i].all_allocnos != NULL)
     239            0 :         ira_free_bitmap (ira_bb_nodes[i].all_allocnos);
     240     17642636 :       if (ira_bb_nodes[i].regno_allocno_map != NULL)
     241            0 :         ira_free (ira_bb_nodes[i].regno_allocno_map);
     242              :     }
     243      1504950 :   ira_free (ira_bb_nodes);
     244      1504950 : }
     245              : 
     246              : 
     247              : 
     248              : /* The following recursive function adds LOOP to the loop tree
     249              :    hierarchy.  LOOP is added only once.  If LOOP is NULL we adding
     250              :    loop designating the whole function when CFG loops are not
     251              :    built.  */
     252              : static void
     253     17755931 : add_loop_to_tree (class loop *loop)
     254              : {
     255     17755931 :   int loop_num;
     256     17755931 :   class loop *parent;
     257     17755931 :   ira_loop_tree_node_t loop_node, parent_node;
     258              : 
     259              :   /* We cannot use loop node access macros here because of potential
     260              :      checking and because the nodes are not initialized enough
     261              :      yet.  */
     262     17755931 :   if (loop != NULL && loop_outer (loop) != NULL)
     263      3126471 :     add_loop_to_tree (loop_outer (loop));
     264     17755931 :   loop_num = loop != NULL ? loop->num : 0;
     265     17755931 :   if (ira_loop_nodes[loop_num].regno_allocno_map != NULL
     266     17746968 :       && ira_loop_nodes[loop_num].children == NULL)
     267              :     {
     268              :       /* We have not added loop node to the tree yet.  */
     269      2114563 :       loop_node = &ira_loop_nodes[loop_num];
     270      2114563 :       loop_node->loop = loop;
     271      2114563 :       loop_node->bb = NULL;
     272      2114563 :       if (loop == NULL)
     273              :         parent = NULL;
     274              :       else
     275              :         {
     276      1620408 :           for (parent = loop_outer (loop);
     277      1623103 :                parent != NULL;
     278         2695 :                parent = loop_outer (parent))
     279       612308 :             if (ira_loop_nodes[parent->num].regno_allocno_map != NULL)
     280              :               break;
     281              :         }
     282      1620408 :       if (parent == NULL)
     283              :         {
     284      1504950 :           loop_node->next = NULL;
     285      1504950 :           loop_node->subloop_next = NULL;
     286      1504950 :           loop_node->parent = NULL;
     287              :         }
     288              :       else
     289              :         {
     290       609613 :           parent_node = &ira_loop_nodes[parent->num];
     291       609613 :           loop_node->next = parent_node->children;
     292       609613 :           parent_node->children = loop_node;
     293       609613 :           loop_node->subloop_next = parent_node->subloops;
     294       609613 :           parent_node->subloops = loop_node;
     295       609613 :           loop_node->parent = parent_node;
     296              :         }
     297              :     }
     298     17755931 : }
     299              : 
     300              : /* The following recursive function sets up levels of nodes of the
     301              :    tree given its root LOOP_NODE.  The enumeration starts with LEVEL.
     302              :    The function returns maximal value of level in the tree + 1.  */
     303              : static int
     304      2114563 : setup_loop_tree_level (ira_loop_tree_node_t loop_node, int level)
     305              : {
     306      2114563 :   int height, max_height;
     307      2114563 :   ira_loop_tree_node_t subloop_node;
     308              : 
     309      2114563 :   ira_assert (loop_node->bb == NULL);
     310      2114563 :   loop_node->level = level;
     311      2114563 :   max_height = level + 1;
     312      2114563 :   for (subloop_node = loop_node->subloops;
     313      2724176 :        subloop_node != NULL;
     314       609613 :        subloop_node = subloop_node->subloop_next)
     315              :     {
     316       609613 :       ira_assert (subloop_node->bb == NULL);
     317       609613 :       height = setup_loop_tree_level (subloop_node, level + 1);
     318       609613 :       if (height > max_height)
     319              :         max_height = height;
     320              :     }
     321      2114563 :   return max_height;
     322              : }
     323              : 
     324              : /* Create the loop tree.  The algorithm is designed to provide correct
     325              :    order of loops (they are ordered by their last loop BB) and basic
     326              :    blocks in the chain formed by member next.  */
     327              : static void
     328      1504950 : form_loop_tree (void)
     329              : {
     330      1504950 :   basic_block bb;
     331      1504950 :   class loop *parent;
     332      1504950 :   ira_loop_tree_node_t bb_node, loop_node;
     333              : 
     334              :   /* We cannot use loop/bb node access macros because of potential
     335              :      checking and because the nodes are not initialized enough
     336              :      yet.  */
     337     16134410 :   FOR_EACH_BB_FN (bb, cfun)
     338              :     {
     339     14629460 :       bb_node = &ira_bb_nodes[bb->index];
     340     14629460 :       bb_node->bb = bb;
     341     14629460 :       bb_node->loop = NULL;
     342     14629460 :       bb_node->subloops = NULL;
     343     14629460 :       bb_node->children = NULL;
     344     14629460 :       bb_node->subloop_next = NULL;
     345     14629460 :       bb_node->next = NULL;
     346     14629460 :       if (current_loops == NULL)
     347              :         parent = NULL;
     348              :       else
     349              :         {
     350     10819684 :           for (parent = bb->loop_father;
     351     11155990 :                parent != NULL;
     352       336306 :                parent = loop_outer (parent))
     353     11155990 :             if (ira_loop_nodes[parent->num].regno_allocno_map != NULL)
     354              :               break;
     355              :         }
     356     14629460 :       add_loop_to_tree (parent);
     357     14629460 :       loop_node = &ira_loop_nodes[parent == NULL ? 0 : parent->num];
     358     14629460 :       bb_node->next = loop_node->children;
     359     14629460 :       bb_node->parent = loop_node;
     360     14629460 :       loop_node->children = bb_node;
     361              :     }
     362      1504950 :   ira_loop_tree_root = IRA_LOOP_NODE_BY_INDEX (0);
     363      1504950 :   ira_loop_tree_height = setup_loop_tree_level (ira_loop_tree_root, 0);
     364      1504950 :   ira_assert (ira_loop_tree_root->regno_allocno_map != NULL);
     365      1504950 : }
     366              : 
     367              : 
     368              : 
     369              : /* Rebuild IRA_REGNO_ALLOCNO_MAP and REGNO_ALLOCNO_MAPs of the loop
     370              :    tree nodes.  */
     371              : static void
     372            0 : rebuild_regno_allocno_maps (void)
     373              : {
     374            0 :   unsigned int l;
     375            0 :   int max_regno, regno;
     376            0 :   ira_allocno_t a;
     377            0 :   ira_loop_tree_node_t loop_tree_node;
     378            0 :   loop_p loop;
     379            0 :   ira_allocno_iterator ai;
     380              : 
     381            0 :   ira_assert (current_loops != NULL);
     382            0 :   max_regno = max_reg_num ();
     383            0 :   FOR_EACH_VEC_SAFE_ELT (get_loops (cfun), l, loop)
     384            0 :     if (ira_loop_nodes[l].regno_allocno_map != NULL)
     385              :       {
     386            0 :         ira_free (ira_loop_nodes[l].regno_allocno_map);
     387            0 :         ira_loop_nodes[l].regno_allocno_map
     388            0 :           = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t)
     389            0 :                                             * max_regno);
     390            0 :         memset (ira_loop_nodes[l].regno_allocno_map, 0,
     391              :                 sizeof (ira_allocno_t) * max_regno);
     392              :       }
     393            0 :   ira_free (ira_regno_allocno_map);
     394            0 :   ira_regno_allocno_map
     395            0 :     = (ira_allocno_t *) ira_allocate (max_regno * sizeof (ira_allocno_t));
     396            0 :   memset (ira_regno_allocno_map, 0, max_regno * sizeof (ira_allocno_t));
     397            0 :   FOR_EACH_ALLOCNO (a, ai)
     398              :     {
     399            0 :       if (ALLOCNO_CAP_MEMBER (a) != NULL)
     400              :         /* Caps are not in the regno allocno maps.  */
     401            0 :         continue;
     402            0 :       regno = ALLOCNO_REGNO (a);
     403            0 :       loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a);
     404            0 :       ALLOCNO_NEXT_REGNO_ALLOCNO (a) = ira_regno_allocno_map[regno];
     405            0 :       ira_regno_allocno_map[regno] = a;
     406            0 :       if (loop_tree_node->regno_allocno_map[regno] == NULL)
     407              :         /* Remember that we can create temporary allocnos to break
     408              :            cycles in register shuffle.  */
     409            0 :         loop_tree_node->regno_allocno_map[regno] = a;
     410              :     }
     411            0 : }
     412              : 
     413              : 
     414              : /* Pools for allocnos, allocno live ranges and objects.  */
     415              : static object_allocator<live_range> live_range_pool ("live ranges");
     416              : static object_allocator<ira_allocno> allocno_pool ("allocnos");
     417              : static object_allocator<ira_object> object_pool ("objects");
     418              : 
     419              : /* Vec containing references to all created allocnos.  It is a
     420              :    container of array allocnos.  */
     421              : static vec<ira_allocno_t> allocno_vec;
     422              : 
     423              : /* Vec containing references to all created ira_objects.  It is a
     424              :    container of ira_object_id_map.  */
     425              : static vec<ira_object_t> ira_object_id_map_vec;
     426              : 
     427              : /* Initialize data concerning allocnos.  */
     428              : static void
     429      1504950 : initiate_allocnos (void)
     430              : {
     431      1504950 :   allocno_vec.create (max_reg_num () * 2);
     432      1504950 :   ira_allocnos = NULL;
     433      1504950 :   ira_allocnos_num = 0;
     434      1504950 :   ira_objects_num = 0;
     435      1504950 :   ira_object_id_map_vec.create (max_reg_num () * 2);
     436      1504950 :   ira_object_id_map = NULL;
     437      1504950 :   ira_regno_allocno_map
     438      1504950 :     = (ira_allocno_t *) ira_allocate (max_reg_num ()
     439              :                                       * sizeof (ira_allocno_t));
     440      1504950 :   memset (ira_regno_allocno_map, 0, max_reg_num () * sizeof (ira_allocno_t));
     441      1504950 : }
     442              : 
     443              : /* Create and return an object corresponding to a new allocno A.  */
     444              : static ira_object_t
     445     40675273 : ira_create_object (ira_allocno_t a, int subword)
     446              : {
     447     40675273 :   enum reg_class aclass = ALLOCNO_CLASS (a);
     448     40675273 :   ira_object_t obj = object_pool.allocate ();
     449              : 
     450     40675273 :   OBJECT_ALLOCNO (obj) = a;
     451     40675273 :   OBJECT_SUBWORD (obj) = subword;
     452     40675273 :   OBJECT_CONFLICT_ID (obj) = ira_objects_num;
     453     40675273 :   OBJECT_CONFLICT_VEC_P (obj) = false;
     454     40675273 :   OBJECT_CONFLICT_ARRAY (obj) = NULL;
     455     40675273 :   OBJECT_NUM_CONFLICTS (obj) = 0;
     456     40675273 :   OBJECT_CONFLICT_HARD_REGS (obj) = ira_no_alloc_regs;
     457     40675273 :   OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) = ira_no_alloc_regs;
     458     40675273 :   OBJECT_CONFLICT_HARD_REGS (obj) |= ~reg_class_contents[aclass];
     459     40675273 :   OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= ~reg_class_contents[aclass];
     460     40675273 :   OBJECT_MIN (obj) = INT_MAX;
     461     40675273 :   OBJECT_MAX (obj) = -1;
     462     40675273 :   OBJECT_LIVE_RANGES (obj) = NULL;
     463              : 
     464     40675273 :   ira_object_id_map_vec.safe_push (obj);
     465     40675273 :   ira_object_id_map
     466     40675273 :     = ira_object_id_map_vec.address ();
     467     40675273 :   ira_objects_num = ira_object_id_map_vec.length ();
     468              : 
     469     40675273 :   return obj;
     470              : }
     471              : 
     472              : /* Create and return the allocno corresponding to REGNO in
     473              :    LOOP_TREE_NODE.  Add the allocno to the list of allocnos with the
     474              :    same regno if CAP_P is FALSE.  */
     475              : ira_allocno_t
     476     39347590 : ira_create_allocno (int regno, bool cap_p,
     477              :                     ira_loop_tree_node_t loop_tree_node)
     478              : {
     479     39347590 :   ira_allocno_t a;
     480              : 
     481     39347590 :   a = allocno_pool.allocate ();
     482     39347590 :   ALLOCNO_REGNO (a) = regno;
     483     39347590 :   ALLOCNO_LOOP_TREE_NODE (a) = loop_tree_node;
     484     39347590 :   if (! cap_p)
     485              :     {
     486     35705103 :       ALLOCNO_NEXT_REGNO_ALLOCNO (a) = ira_regno_allocno_map[regno];
     487     35705103 :       ira_regno_allocno_map[regno] = a;
     488     35705103 :       if (loop_tree_node->regno_allocno_map[regno] == NULL)
     489              :         /* Remember that we can create temporary allocnos to break
     490              :            cycles in register shuffle on region borders (see
     491              :            ira-emit.cc).  */
     492     35700631 :         loop_tree_node->regno_allocno_map[regno] = a;
     493              :     }
     494     39347590 :   ALLOCNO_CAP (a) = NULL;
     495     39347590 :   ALLOCNO_CAP_MEMBER (a) = NULL;
     496     39347590 :   ALLOCNO_NUM (a) = ira_allocnos_num;
     497     39347590 :   bitmap_set_bit (loop_tree_node->all_allocnos, ALLOCNO_NUM (a));
     498     39347590 :   ALLOCNO_NREFS (a) = 0;
     499     39347590 :   ALLOCNO_FREQ (a) = 0;
     500     39347590 :   ALLOCNO_MIGHT_CONFLICT_WITH_PARENT_P (a) = false;
     501     39347590 :   ALLOCNO_SET_REGISTER_FILTERS (a, 0);
     502     39347590 :   ALLOCNO_DEPENDENT_FILTERS (a) = NULL;
     503     39347590 :   ALLOCNO_HARD_REGNO (a) = -1;
     504     39347590 :   ALLOCNO_CALL_FREQ (a) = 0;
     505     39347590 :   ALLOCNO_CALLS_CROSSED_NUM (a) = 0;
     506     39347590 :   ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a) = 0;
     507     39347590 :   ALLOCNO_CROSSED_CALLS_ABIS (a) = 0;
     508     39347590 :   CLEAR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a));
     509              : #ifdef STACK_REGS
     510     39347590 :   ALLOCNO_NO_STACK_REG_P (a) = false;
     511     39347590 :   ALLOCNO_TOTAL_NO_STACK_REG_P (a) = false;
     512              : #endif
     513     39347590 :   ALLOCNO_DONT_REASSIGN_P (a) = false;
     514     39347590 :   ALLOCNO_BAD_SPILL_P (a) = false;
     515     39347590 :   ALLOCNO_ASSIGNED_P (a) = false;
     516     39347590 :   ALLOCNO_MODE (a) = (regno < 0 ? VOIDmode : PSEUDO_REGNO_MODE (regno));
     517     39347590 :   ALLOCNO_WMODE (a) = ALLOCNO_MODE (a);
     518     39347590 :   ALLOCNO_PREFS (a) = NULL;
     519     39347590 :   ALLOCNO_COPIES (a) = NULL;
     520     39347590 :   ALLOCNO_HARD_REG_COSTS (a) = NULL;
     521     39347590 :   ALLOCNO_CONFLICT_HARD_REG_COSTS (a) = NULL;
     522     39347590 :   ALLOCNO_UPDATED_HARD_REG_COSTS (a) = NULL;
     523     39347590 :   ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) = NULL;
     524     39347590 :   ALLOCNO_CLASS (a) = NO_REGS;
     525     39347590 :   ALLOCNO_UPDATED_CLASS_COST (a) = 0;
     526     39347590 :   ALLOCNO_CLASS_COST (a) = 0;
     527     39347590 :   ALLOCNO_MEMORY_COST (a) = 0;
     528     39347590 :   ALLOCNO_UPDATED_MEMORY_COST (a) = 0;
     529     39347590 :   ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) = 0;
     530     39347590 :   ALLOCNO_NUM_OBJECTS (a) = 0;
     531              : 
     532     39347590 :   ALLOCNO_ADD_DATA (a) = NULL;
     533     39347590 :   allocno_vec.safe_push (a);
     534     39347590 :   ira_allocnos = allocno_vec.address ();
     535     39347590 :   ira_allocnos_num = allocno_vec.length ();
     536              : 
     537     39347590 :   return a;
     538              : }
     539              : 
     540              : /* Set up register class for A and update its conflict hard
     541              :    registers.  */
     542              : void
     543     39347590 : ira_set_allocno_class (ira_allocno_t a, enum reg_class aclass)
     544              : {
     545     39347590 :   ira_allocno_object_iterator oi;
     546     39347590 :   ira_object_t obj;
     547              : 
     548     39347590 :   ALLOCNO_CLASS (a) = aclass;
     549     39347590 :   FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
     550              :     {
     551            0 :       OBJECT_CONFLICT_HARD_REGS (obj) |= ~reg_class_contents[aclass];
     552            0 :       OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= ~reg_class_contents[aclass];
     553              :     }
     554     39347590 : }
     555              : 
     556              : /* Determine the number of objects we should associate with allocno A
     557              :    and allocate them.  */
     558              : void
     559     39347590 : ira_create_allocno_objects (ira_allocno_t a)
     560              : {
     561     39347590 :   machine_mode mode = ALLOCNO_MODE (a);
     562     39347590 :   enum reg_class aclass = ALLOCNO_CLASS (a);
     563     39347590 :   int n = ira_reg_class_max_nregs[aclass][mode];
     564     39347590 :   int i;
     565              : 
     566     40937787 :   if (n != 2 || maybe_ne (GET_MODE_SIZE (mode), n * UNITS_PER_WORD))
     567              :     n = 1;
     568              : 
     569     39347590 :   ALLOCNO_NUM_OBJECTS (a) = n;
     570     80022863 :   for (i = 0; i < n; i++)
     571     40675273 :     ALLOCNO_OBJECT (a, i) = ira_create_object (a, i);
     572     39347590 : }
     573              : 
     574              : /* For each allocno, set ALLOCNO_NUM_OBJECTS and create the
     575              :    ALLOCNO_OBJECT structures.  This must be called after the allocno
     576              :    classes are known.  */
     577              : static void
     578      1504950 : create_allocno_objects (void)
     579              : {
     580      1504950 :   ira_allocno_t a;
     581      1504950 :   ira_allocno_iterator ai;
     582              : 
     583     37205581 :   FOR_EACH_ALLOCNO (a, ai)
     584     35700631 :     ira_create_allocno_objects (a);
     585      1504950 : }
     586              : 
     587              : /* Merge hard register conflict information for all objects associated with
     588              :    allocno TO into the corresponding objects associated with FROM.
     589              :    If TOTAL_ONLY is true, we only merge OBJECT_TOTAL_CONFLICT_HARD_REGS.  */
     590              : static void
     591      6509074 : merge_hard_reg_conflicts (ira_allocno_t from, ira_allocno_t to,
     592              :                           bool total_only)
     593              : {
     594      6509074 :   int i;
     595      6509074 :   gcc_assert (ALLOCNO_NUM_OBJECTS (to) == ALLOCNO_NUM_OBJECTS (from));
     596     13134006 :   for (i = 0; i < ALLOCNO_NUM_OBJECTS (to); i++)
     597              :     {
     598      6624932 :       ira_object_t from_obj = ALLOCNO_OBJECT (from, i);
     599      6624932 :       ira_object_t to_obj = ALLOCNO_OBJECT (to, i);
     600              : 
     601      6624932 :       if (!total_only)
     602              :         OBJECT_CONFLICT_HARD_REGS (to_obj)
     603      6624932 :           |= OBJECT_CONFLICT_HARD_REGS (from_obj);
     604      6624932 :       OBJECT_TOTAL_CONFLICT_HARD_REGS (to_obj)
     605     13249864 :         |= OBJECT_TOTAL_CONFLICT_HARD_REGS (from_obj);
     606              :     }
     607              : #ifdef STACK_REGS
     608      6509074 :   if (!total_only && ALLOCNO_NO_STACK_REG_P (from))
     609        21742 :     ALLOCNO_NO_STACK_REG_P (to) = true;
     610      6509074 :   if (ALLOCNO_TOTAL_NO_STACK_REG_P (from))
     611        23729 :     ALLOCNO_TOTAL_NO_STACK_REG_P (to) = true;
     612              : #endif
     613      6509074 : }
     614              : 
     615              : /* Update hard register conflict information for all objects associated with
     616              :    A to include the regs in SET.  */
     617              : void
     618      4474336 : ior_hard_reg_conflicts (ira_allocno_t a, const_hard_reg_set set)
     619              : {
     620      4474336 :   ira_allocno_object_iterator i;
     621      4474336 :   ira_object_t obj;
     622              : 
     623      4474336 :   FOR_EACH_ALLOCNO_OBJECT (a, obj, i)
     624              :     {
     625     13695300 :       OBJECT_CONFLICT_HARD_REGS (obj) |= set;
     626      9039436 :       OBJECT_TOTAL_CONFLICT_HARD_REGS (obj) |= set;
     627              :     }
     628      4474336 : }
     629              : 
     630              : /* Return TRUE if a conflict vector with NUM elements is more
     631              :    profitable than a conflict bit vector for OBJ.  */
     632              : bool
     633     25787619 : ira_conflict_vector_profitable_p (ira_object_t obj, int num)
     634              : {
     635     25787619 :   int nbytes;
     636     25787619 :   int max = OBJECT_MAX (obj);
     637     25787619 :   int min = OBJECT_MIN (obj);
     638              : 
     639     25787619 :   if (max < min)
     640              :     /* We prefer a bit vector in such case because it does not result
     641              :        in allocation.  */
     642              :     return false;
     643              : 
     644     24877718 :   nbytes = (max - min) / 8 + 1;
     645     24877718 :   STATIC_ASSERT (sizeof (ira_object_t) <= 8);
     646              :   /* Don't use sizeof (ira_object_t), use constant 8.  Size of ira_object_t (a
     647              :      pointer) is different on 32-bit and 64-bit targets.  Usage sizeof
     648              :      (ira_object_t) can result in different code generation by GCC built as 32-
     649              :      and 64-bit program.  In any case the profitability is just an estimation
     650              :      and border cases are rare.  */
     651     24877718 :   return (2 * 8 /* sizeof (ira_object_t) */ * (num + 1) < 3 * nbytes);
     652              : }
     653              : 
     654              : /* Allocates and initialize the conflict vector of OBJ for NUM
     655              :    conflicting objects.  */
     656              : void
     657      5021152 : ira_allocate_conflict_vec (ira_object_t obj, int num)
     658              : {
     659      5021152 :   int size;
     660      5021152 :   ira_object_t *vec;
     661              : 
     662      5021152 :   ira_assert (OBJECT_CONFLICT_ARRAY (obj) == NULL);
     663      5021152 :   num++; /* for NULL end marker  */
     664      5021152 :   size = sizeof (ira_object_t) * num;
     665      5021152 :   OBJECT_CONFLICT_ARRAY (obj) = ira_allocate (size);
     666      5021152 :   vec = (ira_object_t *) OBJECT_CONFLICT_ARRAY (obj);
     667      5021152 :   vec[0] = NULL;
     668      5021152 :   OBJECT_NUM_CONFLICTS (obj) = 0;
     669      5021152 :   OBJECT_CONFLICT_ARRAY_SIZE (obj) = size;
     670      5021152 :   OBJECT_CONFLICT_VEC_P (obj) = true;
     671      5021152 : }
     672              : 
     673              : /* Allocate and initialize the conflict bit vector of OBJ.  */
     674              : static void
     675         3257 : allocate_conflict_bit_vec (ira_object_t obj)
     676              : {
     677         3257 :   unsigned int size;
     678              : 
     679         3257 :   ira_assert (OBJECT_CONFLICT_ARRAY (obj) == NULL);
     680         3257 :   size = ((OBJECT_MAX (obj) - OBJECT_MIN (obj) + IRA_INT_BITS)
     681         3257 :           / IRA_INT_BITS * sizeof (IRA_INT_TYPE));
     682         3257 :   OBJECT_CONFLICT_ARRAY (obj) = ira_allocate (size);
     683         3257 :   memset (OBJECT_CONFLICT_ARRAY (obj), 0, size);
     684         3257 :   OBJECT_CONFLICT_ARRAY_SIZE (obj) = size;
     685         3257 :   OBJECT_CONFLICT_VEC_P (obj) = false;
     686         3257 : }
     687              : 
     688              : /* Allocate and initialize the conflict vector or conflict bit vector
     689              :    of OBJ for NUM conflicting allocnos whatever is more profitable.  */
     690              : void
     691         4472 : ira_allocate_object_conflicts (ira_object_t obj, int num)
     692              : {
     693         4472 :   if (ira_conflict_vector_profitable_p (obj, num))
     694         1215 :     ira_allocate_conflict_vec (obj, num);
     695              :   else
     696         3257 :     allocate_conflict_bit_vec (obj);
     697         4472 : }
     698              : 
     699              : /* Add OBJ2 to the conflicts of OBJ1.  */
     700              : static void
     701            0 : add_to_conflicts (ira_object_t obj1, ira_object_t obj2)
     702              : {
     703            0 :   int num;
     704            0 :   unsigned int size;
     705              : 
     706            0 :   if (OBJECT_CONFLICT_VEC_P (obj1))
     707              :     {
     708            0 :       ira_object_t *vec = OBJECT_CONFLICT_VEC (obj1);
     709            0 :       int curr_num = OBJECT_NUM_CONFLICTS (obj1);
     710            0 :       num = curr_num + 2;
     711            0 :       if (OBJECT_CONFLICT_ARRAY_SIZE (obj1) < num * sizeof (ira_object_t))
     712              :         {
     713            0 :           ira_object_t *newvec;
     714            0 :           size = (3 * num / 2 + 1) * sizeof (ira_object_t);
     715            0 :           newvec = (ira_object_t *) ira_allocate (size);
     716            0 :           memcpy (newvec, vec, curr_num * sizeof (ira_object_t));
     717            0 :           ira_free (vec);
     718            0 :           vec = newvec;
     719            0 :           OBJECT_CONFLICT_ARRAY (obj1) = vec;
     720            0 :           OBJECT_CONFLICT_ARRAY_SIZE (obj1) = size;
     721              :         }
     722            0 :       vec[num - 2] = obj2;
     723            0 :       vec[num - 1] = NULL;
     724            0 :       OBJECT_NUM_CONFLICTS (obj1)++;
     725              :     }
     726              :   else
     727              :     {
     728            0 :       int nw, added_head_nw, id;
     729            0 :       IRA_INT_TYPE *vec = OBJECT_CONFLICT_BITVEC (obj1);
     730              : 
     731            0 :       id = OBJECT_CONFLICT_ID (obj2);
     732            0 :       if (OBJECT_MIN (obj1) > id)
     733              :         {
     734              :           /* Expand head of the bit vector.  */
     735            0 :           added_head_nw = (OBJECT_MIN (obj1) - id - 1) / IRA_INT_BITS + 1;
     736            0 :           nw = (OBJECT_MAX (obj1) - OBJECT_MIN (obj1)) / IRA_INT_BITS + 1;
     737            0 :           size = (nw + added_head_nw) * sizeof (IRA_INT_TYPE);
     738            0 :           if (OBJECT_CONFLICT_ARRAY_SIZE (obj1) >= size)
     739              :             {
     740            0 :               memmove ((char *) vec + added_head_nw * sizeof (IRA_INT_TYPE),
     741            0 :                        vec, nw * sizeof (IRA_INT_TYPE));
     742            0 :               memset (vec, 0, added_head_nw * sizeof (IRA_INT_TYPE));
     743              :             }
     744              :           else
     745              :             {
     746            0 :               size
     747            0 :                 = (3 * (nw + added_head_nw) / 2 + 1) * sizeof (IRA_INT_TYPE);
     748            0 :               vec = (IRA_INT_TYPE *) ira_allocate (size);
     749            0 :               memcpy ((char *) vec + added_head_nw * sizeof (IRA_INT_TYPE),
     750            0 :                       OBJECT_CONFLICT_ARRAY (obj1), nw * sizeof (IRA_INT_TYPE));
     751            0 :               memset (vec, 0, added_head_nw * sizeof (IRA_INT_TYPE));
     752            0 :               memset ((char *) vec
     753              :                       + (nw + added_head_nw) * sizeof (IRA_INT_TYPE),
     754            0 :                       0, size - (nw + added_head_nw) * sizeof (IRA_INT_TYPE));
     755            0 :               ira_free (OBJECT_CONFLICT_ARRAY (obj1));
     756            0 :               OBJECT_CONFLICT_ARRAY (obj1) = vec;
     757            0 :               OBJECT_CONFLICT_ARRAY_SIZE (obj1) = size;
     758              :             }
     759            0 :           OBJECT_MIN (obj1) -= added_head_nw * IRA_INT_BITS;
     760              :         }
     761            0 :       else if (OBJECT_MAX (obj1) < id)
     762              :         {
     763            0 :           nw = (id - OBJECT_MIN (obj1)) / IRA_INT_BITS + 1;
     764            0 :           size = nw * sizeof (IRA_INT_TYPE);
     765            0 :           if (OBJECT_CONFLICT_ARRAY_SIZE (obj1) < size)
     766              :             {
     767              :               /* Expand tail of the bit vector.  */
     768            0 :               size = (3 * nw / 2 + 1) * sizeof (IRA_INT_TYPE);
     769            0 :               vec = (IRA_INT_TYPE *) ira_allocate (size);
     770            0 :               memcpy (vec, OBJECT_CONFLICT_ARRAY (obj1), OBJECT_CONFLICT_ARRAY_SIZE (obj1));
     771            0 :               memset ((char *) vec + OBJECT_CONFLICT_ARRAY_SIZE (obj1),
     772            0 :                       0, size - OBJECT_CONFLICT_ARRAY_SIZE (obj1));
     773            0 :               ira_free (OBJECT_CONFLICT_ARRAY (obj1));
     774            0 :               OBJECT_CONFLICT_ARRAY (obj1) = vec;
     775            0 :               OBJECT_CONFLICT_ARRAY_SIZE (obj1) = size;
     776              :             }
     777            0 :           OBJECT_MAX (obj1) = id;
     778              :         }
     779            0 :       SET_MINMAX_SET_BIT (vec, id, OBJECT_MIN (obj1), OBJECT_MAX (obj1));
     780              :     }
     781            0 : }
     782              : 
     783              : /* Add OBJ1 to the conflicts of OBJ2 and vice versa.  */
     784              : static void
     785            0 : ira_add_conflict (ira_object_t obj1, ira_object_t obj2)
     786              : {
     787            0 :   add_to_conflicts (obj1, obj2);
     788            0 :   add_to_conflicts (obj2, obj1);
     789            0 : }
     790              : 
     791              : /* Clear all conflicts of OBJ.  */
     792              : static void
     793            0 : clear_conflicts (ira_object_t obj)
     794              : {
     795            0 :   if (OBJECT_CONFLICT_VEC_P (obj))
     796              :     {
     797            0 :       OBJECT_NUM_CONFLICTS (obj) = 0;
     798            0 :       OBJECT_CONFLICT_VEC (obj)[0] = NULL;
     799              :     }
     800            0 :   else if (OBJECT_CONFLICT_ARRAY_SIZE (obj) != 0)
     801              :     {
     802            0 :       int nw;
     803              : 
     804            0 :       nw = (OBJECT_MAX (obj) - OBJECT_MIN (obj)) / IRA_INT_BITS + 1;
     805            0 :       memset (OBJECT_CONFLICT_BITVEC (obj), 0, nw * sizeof (IRA_INT_TYPE));
     806              :     }
     807            0 : }
     808              : 
     809              : /* The array used to find duplications in conflict vectors of
     810              :    allocnos.  */
     811              : static int *conflict_check;
     812              : 
     813              : /* The value used to mark allocation presence in conflict vector of
     814              :    the current allocno.  */
     815              : static int curr_conflict_check_tick;
     816              : 
     817              : /* Remove duplications in conflict vector of OBJ.  */
     818              : static void
     819            0 : compress_conflict_vec (ira_object_t obj)
     820              : {
     821            0 :   ira_object_t *vec, conflict_obj;
     822            0 :   int i, j;
     823              : 
     824            0 :   ira_assert (OBJECT_CONFLICT_VEC_P (obj));
     825            0 :   vec = OBJECT_CONFLICT_VEC (obj);
     826            0 :   curr_conflict_check_tick++;
     827            0 :   for (i = j = 0; (conflict_obj = vec[i]) != NULL; i++)
     828              :     {
     829            0 :       int id = OBJECT_CONFLICT_ID (conflict_obj);
     830            0 :       if (conflict_check[id] != curr_conflict_check_tick)
     831              :         {
     832            0 :           conflict_check[id] = curr_conflict_check_tick;
     833            0 :           vec[j++] = conflict_obj;
     834              :         }
     835              :     }
     836            0 :   OBJECT_NUM_CONFLICTS (obj) = j;
     837            0 :   vec[j] = NULL;
     838            0 : }
     839              : 
     840              : /* Remove duplications in conflict vectors of all allocnos.  */
     841              : static void
     842            0 : compress_conflict_vecs (void)
     843              : {
     844            0 :   ira_object_t obj;
     845            0 :   ira_object_iterator oi;
     846              : 
     847            0 :   conflict_check = (int *) ira_allocate (sizeof (int) * ira_objects_num);
     848            0 :   memset (conflict_check, 0, sizeof (int) * ira_objects_num);
     849            0 :   curr_conflict_check_tick = 0;
     850            0 :   FOR_EACH_OBJECT (obj, oi)
     851              :     {
     852            0 :       if (OBJECT_CONFLICT_VEC_P (obj))
     853            0 :         compress_conflict_vec (obj);
     854              :     }
     855            0 :   ira_free (conflict_check);
     856            0 : }
     857              : 
     858              : /* This recursive function outputs allocno A and if it is a cap the
     859              :    function outputs its members.  */
     860              : void
     861          959 : ira_print_expanded_allocno (ira_allocno_t a)
     862              : {
     863          959 :   basic_block bb;
     864              : 
     865          959 :   fprintf (ira_dump_file, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
     866          959 :   if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
     867            0 :     fprintf (ira_dump_file, ",b%d", bb->index);
     868              :   else
     869          959 :     fprintf (ira_dump_file, ",l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num);
     870          959 :   if (ALLOCNO_CAP_MEMBER (a) != NULL)
     871              :     {
     872            0 :       fprintf (ira_dump_file, ":");
     873            0 :       ira_print_expanded_allocno (ALLOCNO_CAP_MEMBER (a));
     874              :     }
     875          959 :   fprintf (ira_dump_file, ")");
     876          959 : }
     877              : 
     878              : /* Copy SRC's dependent-filter list to DST's.  */
     879              : 
     880              : static void
     881      9169732 : copy_dependent_filters (ira_allocno_t dst, ira_allocno_t src)
     882              : {
     883      9169732 :   for (auto *filter = ALLOCNO_DEPENDENT_FILTERS (src);
     884      9169732 :        filter;
     885            0 :        filter = filter->next)
     886            0 :     ira_add_dependent_filter (dst, filter->id, filter->mode,
     887              :                               filter->ref_allocno, filter->ref_hard_regno,
     888            0 :                               filter->ref_mode);
     889      9169732 : }
     890              : 
     891              : /* Create and return the cap representing allocno A in the
     892              :    parent loop.  */
     893              : static ira_allocno_t
     894      3642487 : create_cap_allocno (ira_allocno_t a)
     895              : {
     896      3642487 :   ira_allocno_t cap;
     897      3642487 :   ira_loop_tree_node_t parent;
     898      3642487 :   enum reg_class aclass;
     899              : 
     900      3642487 :   parent = ALLOCNO_LOOP_TREE_NODE (a)->parent;
     901      3642487 :   cap = ira_create_allocno (ALLOCNO_REGNO (a), true, parent);
     902      3642487 :   ALLOCNO_MODE (cap) = ALLOCNO_MODE (a);
     903      3642487 :   ALLOCNO_WMODE (cap) = ALLOCNO_WMODE (a);
     904      3642487 :   aclass = ALLOCNO_CLASS (a);
     905      3642487 :   ira_set_allocno_class (cap, aclass);
     906      3642487 :   ira_create_allocno_objects (cap);
     907      3642487 :   ALLOCNO_CAP_MEMBER (cap) = a;
     908      3642487 :   ALLOCNO_CAP (a) = cap;
     909      3642487 :   ALLOCNO_CLASS_COST (cap) = ALLOCNO_CLASS_COST (a);
     910      3642487 :   ALLOCNO_MEMORY_COST (cap) = ALLOCNO_MEMORY_COST (a);
     911      3642487 :   ira_allocate_and_copy_costs
     912      3642487 :     (&ALLOCNO_HARD_REG_COSTS (cap), aclass, ALLOCNO_HARD_REG_COSTS (a));
     913      3642487 :   ira_allocate_and_copy_costs
     914      3642487 :     (&ALLOCNO_CONFLICT_HARD_REG_COSTS (cap), aclass,
     915              :      ALLOCNO_CONFLICT_HARD_REG_COSTS (a));
     916      3642487 :   ALLOCNO_BAD_SPILL_P (cap) = ALLOCNO_BAD_SPILL_P (a);
     917      3642487 :   ALLOCNO_NREFS (cap) = ALLOCNO_NREFS (a);
     918      3642487 :   ALLOCNO_FREQ (cap) = ALLOCNO_FREQ (a);
     919      3642487 :   ALLOCNO_CALL_FREQ (cap) = ALLOCNO_CALL_FREQ (a);
     920      3642487 :   ALLOCNO_SET_REGISTER_FILTERS (cap, ALLOCNO_REGISTER_FILTERS (a));
     921      3642487 :   ALLOCNO_DEPENDENT_FILTERS (cap) = NULL;
     922      3642487 :   copy_dependent_filters (cap, a);
     923              : 
     924      3642487 :   merge_hard_reg_conflicts (a, cap, false);
     925              : 
     926      3642487 :   ALLOCNO_CALLS_CROSSED_NUM (cap) = ALLOCNO_CALLS_CROSSED_NUM (a);
     927      3642487 :   ALLOCNO_CHEAP_CALLS_CROSSED_NUM (cap) = ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a);
     928      3642487 :   ALLOCNO_CROSSED_CALLS_ABIS (cap) = ALLOCNO_CROSSED_CALLS_ABIS (a);
     929      3642487 :   ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (cap)
     930      3642487 :     = ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a);
     931      3642487 :   if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
     932              :     {
     933            0 :       fprintf (ira_dump_file, "    Creating cap ");
     934            0 :       ira_print_expanded_allocno (cap);
     935            0 :       fprintf (ira_dump_file, "\n");
     936              :     }
     937      3642487 :   return cap;
     938              : }
     939              : 
     940              : /* Create and return a live range for OBJECT with given attributes.  */
     941              : live_range_t
     942     63405945 : ira_create_live_range (ira_object_t obj, int start, int finish,
     943              :                        live_range_t next)
     944              : {
     945     63405945 :   live_range_t p;
     946              : 
     947     63405945 :   p = live_range_pool.allocate ();
     948     63405945 :   p->object = obj;
     949     63405945 :   p->start = start;
     950     63405945 :   p->finish = finish;
     951     63405945 :   p->next = next;
     952     63405945 :   return p;
     953              : }
     954              : 
     955              : /* Create a new live range for OBJECT and queue it at the head of its
     956              :    live range list.  */
     957              : void
     958     63405945 : ira_add_live_range_to_object (ira_object_t object, int start, int finish)
     959              : {
     960     63405945 :   live_range_t p;
     961     63405945 :   p = ira_create_live_range (object, start, finish,
     962              :                              OBJECT_LIVE_RANGES (object));
     963     63405945 :   OBJECT_LIVE_RANGES (object) = p;
     964     63405945 : }
     965              : 
     966              : /* Copy allocno live range R and return the result.  */
     967              : static live_range_t
     968            0 : copy_live_range (live_range_t r)
     969              : {
     970            0 :   live_range_t p;
     971              : 
     972            0 :   p = live_range_pool.allocate ();
     973            0 :   *p = *r;
     974            0 :   return p;
     975              : }
     976              : 
     977              : /* Copy allocno live range list given by its head R and return the
     978              :    result.  */
     979              : live_range_t
     980            0 : ira_copy_live_range_list (live_range_t r)
     981              : {
     982            0 :   live_range_t p, first, last;
     983              : 
     984            0 :   if (r == NULL)
     985              :     return NULL;
     986            0 :   for (first = last = NULL; r != NULL; r = r->next)
     987              :     {
     988            0 :       p = copy_live_range (r);
     989            0 :       if (first == NULL)
     990              :         first = p;
     991              :       else
     992            0 :         last->next = p;
     993            0 :       last = p;
     994              :     }
     995              :   return first;
     996              : }
     997              : 
     998              : /* Merge ranges R1 and R2 and returns the result.  The function
     999              :    maintains the order of ranges and tries to minimize number of the
    1000              :    result ranges.  */
    1001              : live_range_t
    1002      2416278 : ira_merge_live_ranges (live_range_t r1, live_range_t r2)
    1003              : {
    1004      2416278 :   live_range_t first, last;
    1005              : 
    1006      2416278 :   if (r1 == NULL)
    1007              :     return r2;
    1008      2416275 :   if (r2 == NULL)
    1009              :     return r1;
    1010     18399232 :   for (first = last = NULL; r1 != NULL && r2 != NULL;)
    1011              :     {
    1012     15984754 :       if (r1->start < r2->start)
    1013     11820032 :         std::swap (r1, r2);
    1014     15984754 :       if (r1->start <= r2->finish + 1)
    1015              :         {
    1016              :           /* Intersected ranges: merge r1 and r2 into r1.  */
    1017       981365 :           r1->start = r2->start;
    1018       981365 :           if (r1->finish < r2->finish)
    1019            0 :             r1->finish = r2->finish;
    1020       981365 :           live_range_t temp = r2;
    1021       981365 :           r2 = r2->next;
    1022       981365 :           ira_finish_live_range (temp);
    1023       981365 :           if (r2 == NULL)
    1024              :             {
    1025              :               /* To try to merge with subsequent ranges in r1.  */
    1026       933320 :               r2 = r1->next;
    1027       933320 :               r1->next = NULL;
    1028              :             }
    1029              :         }
    1030              :       else
    1031              :         {
    1032              :           /* Add r1 to the result.  */
    1033     15003389 :           if (first == NULL)
    1034              :             first = last = r1;
    1035              :           else
    1036              :             {
    1037     12934652 :               last->next = r1;
    1038     12934652 :               last = r1;
    1039              :             }
    1040     15003389 :           r1 = r1->next;
    1041     15003389 :           if (r1 == NULL)
    1042              :             {
    1043              :               /* To try to merge with subsequent ranges in r2.  */
    1044     13186327 :               r1 = r2->next;
    1045     13186327 :               r2->next = NULL;
    1046              :             }
    1047              :         }
    1048              :     }
    1049      2414478 :   if (r1 != NULL)
    1050              :     {
    1051       352990 :       if (first == NULL)
    1052              :         first = r1;
    1053              :       else
    1054         7249 :         last->next = r1;
    1055       352990 :       ira_assert (r1->next == NULL);
    1056              :     }
    1057      2061488 :   else if (r2 != NULL)
    1058              :     {
    1059      2061488 :       if (first == NULL)
    1060              :         first = r2;
    1061              :       else
    1062      2061488 :         last->next = r2;
    1063      2061488 :       ira_assert (r2->next == NULL);
    1064              :     }
    1065              :   else
    1066              :     {
    1067            0 :       ira_assert (last->next == NULL);
    1068              :     }
    1069              :   return first;
    1070              : }
    1071              : 
    1072              : /* Return TRUE if live ranges R1 and R2 intersect.  */
    1073              : bool
    1074     20219132 : ira_live_ranges_intersect_p (live_range_t r1, live_range_t r2)
    1075              : {
    1076              :   /* Remember the live ranges are always kept ordered.  */
    1077     46689261 :   while (r1 != NULL && r2 != NULL)
    1078              :     {
    1079     27711266 :       if (r1->start > r2->finish)
    1080     19390831 :         r1 = r1->next;
    1081      8320435 :       else if (r2->start > r1->finish)
    1082      7079298 :         r2 = r2->next;
    1083              :       else
    1084              :         return true;
    1085              :     }
    1086              :   return false;
    1087              : }
    1088              : 
    1089              : /* Free allocno live range R.  */
    1090              : void
    1091     63405945 : ira_finish_live_range (live_range_t r)
    1092              : {
    1093     63405945 :   live_range_pool.remove (r);
    1094     63405945 : }
    1095              : 
    1096              : /* Free list of allocno live ranges starting with R.  */
    1097              : void
    1098     40675273 : ira_finish_live_range_list (live_range_t r)
    1099              : {
    1100     40675273 :   live_range_t next_r;
    1101              : 
    1102     90444530 :   for (; r != NULL; r = next_r)
    1103              :     {
    1104     49769257 :       next_r = r->next;
    1105     49769257 :       ira_finish_live_range (r);
    1106              :     }
    1107     40675273 : }
    1108              : 
    1109              : /* Free updated register costs of allocno A.  */
    1110              : void
    1111     58873846 : ira_free_allocno_updated_costs (ira_allocno_t a)
    1112              : {
    1113     58873846 :   enum reg_class aclass;
    1114              : 
    1115     58873846 :   aclass = ALLOCNO_CLASS (a);
    1116     58873846 :   if (ALLOCNO_UPDATED_HARD_REG_COSTS (a) != NULL)
    1117     13423214 :     ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a), aclass);
    1118     58873846 :   ALLOCNO_UPDATED_HARD_REG_COSTS (a) = NULL;
    1119     58873846 :   if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) != NULL)
    1120      7489592 :     ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a),
    1121              :                           aclass);
    1122     58873846 :   ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) = NULL;
    1123     58873846 : }
    1124              : 
    1125              : /* Free and nullify all cost vectors allocated earlier for allocno
    1126              :    A.  */
    1127              : static void
    1128     39347590 : ira_free_allocno_costs (ira_allocno_t a)
    1129              : {
    1130     39347590 :   enum reg_class aclass = ALLOCNO_CLASS (a);
    1131     39347590 :   ira_object_t obj;
    1132     39347590 :   ira_allocno_object_iterator oi;
    1133              : 
    1134     80022863 :   FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
    1135              :     {
    1136     40675273 :       ira_finish_live_range_list (OBJECT_LIVE_RANGES (obj));
    1137     40675273 :       ira_object_id_map[OBJECT_CONFLICT_ID (obj)] = NULL;
    1138     40675273 :       if (OBJECT_CONFLICT_ARRAY (obj) != NULL)
    1139     24877718 :         ira_free (OBJECT_CONFLICT_ARRAY (obj));
    1140     40675273 :       object_pool.remove (obj);
    1141              :     }
    1142              : 
    1143     39347590 :   ira_allocnos[ALLOCNO_NUM (a)] = NULL;
    1144     39347590 :   if (ALLOCNO_HARD_REG_COSTS (a) != NULL)
    1145     10327375 :     ira_free_cost_vector (ALLOCNO_HARD_REG_COSTS (a), aclass);
    1146     39347590 :   if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a) != NULL)
    1147      1226500 :     ira_free_cost_vector (ALLOCNO_CONFLICT_HARD_REG_COSTS (a), aclass);
    1148     39347590 :   if (ALLOCNO_UPDATED_HARD_REG_COSTS (a) != NULL)
    1149            0 :     ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a), aclass);
    1150     39347590 :   if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) != NULL)
    1151            0 :     ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a),
    1152              :                           aclass);
    1153     39347590 :   ALLOCNO_HARD_REG_COSTS (a) = NULL;
    1154     39347590 :   ALLOCNO_CONFLICT_HARD_REG_COSTS (a) = NULL;
    1155     39347590 :   ALLOCNO_UPDATED_HARD_REG_COSTS (a) = NULL;
    1156     39347590 :   ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) = NULL;
    1157     39347590 : }
    1158              : 
    1159              : /* Free the memory allocated for allocno A.  */
    1160              : static void
    1161     39347590 : finish_allocno (ira_allocno_t a)
    1162              : {
    1163     39347590 :   auto *filter = ALLOCNO_DEPENDENT_FILTERS (a);
    1164     39347590 :   while (filter)
    1165              :     {
    1166            0 :       auto *next = filter->next;
    1167            0 :       ira_free (filter);
    1168            0 :       filter = next;
    1169              :     }
    1170     39347590 :   ira_free_allocno_costs (a);
    1171     39347590 :   allocno_pool.remove (a);
    1172     39347590 : }
    1173              : 
    1174              : /* Free the memory allocated for all allocnos.  */
    1175              : static void
    1176      1504950 : finish_allocnos (void)
    1177              : {
    1178      1504950 :   ira_allocno_t a;
    1179      1504950 :   ira_allocno_iterator ai;
    1180              : 
    1181     38442707 :   FOR_EACH_ALLOCNO (a, ai)
    1182     36937757 :     finish_allocno (a);
    1183      1504950 :   ira_free (ira_regno_allocno_map);
    1184      1504950 :   ira_object_id_map_vec.release ();
    1185      1504950 :   allocno_vec.release ();
    1186      1504950 :   allocno_pool.release ();
    1187      1504950 :   object_pool.release ();
    1188      1504950 :   live_range_pool.release ();
    1189      1504950 : }
    1190              : 
    1191              : 
    1192              : 
    1193              : /* Pools for allocno preferences.  */
    1194              : static object_allocator <ira_allocno_pref> pref_pool ("prefs");
    1195              : 
    1196              : /* Vec containing references to all created preferences.  It is a
    1197              :    container of array ira_prefs.  */
    1198              : static vec<ira_pref_t> pref_vec;
    1199              : 
    1200              : /* The function initializes data concerning allocno prefs.  */
    1201              : static void
    1202      1504950 : initiate_prefs (void)
    1203              : {
    1204      1504950 :   pref_vec.create (get_max_uid ());
    1205      1504950 :   ira_prefs = NULL;
    1206      1504950 :   ira_prefs_num = 0;
    1207      1504950 : }
    1208              : 
    1209              : /* Return pref for A and HARD_REGNO if any.  */
    1210              : static ira_pref_t
    1211      7780593 : find_allocno_pref (ira_allocno_t a, int hard_regno)
    1212              : {
    1213      7780593 :   ira_pref_t pref;
    1214              : 
    1215      7836710 :   for (pref = ALLOCNO_PREFS (a); pref != NULL; pref = pref->next_pref)
    1216       524656 :     if (pref->allocno == a && pref->hard_regno == hard_regno)
    1217              :       return pref;
    1218              :   return NULL;
    1219              : }
    1220              : 
    1221              : /* Create and return pref with given attributes A, HARD_REGNO, and FREQ.  */
    1222              : ira_pref_t
    1223      7312054 : ira_create_pref (ira_allocno_t a, int hard_regno, int freq)
    1224              : {
    1225      7312054 :   ira_pref_t pref;
    1226              : 
    1227      7312054 :   pref = pref_pool.allocate ();
    1228      7312054 :   pref->num = ira_prefs_num;
    1229      7312054 :   pref->allocno = a;
    1230      7312054 :   pref->hard_regno = hard_regno;
    1231      7312054 :   pref->freq = freq;
    1232      7312054 :   pref_vec.safe_push (pref);
    1233      7312054 :   ira_prefs = pref_vec.address ();
    1234      7312054 :   ira_prefs_num = pref_vec.length ();
    1235      7312054 :   return pref;
    1236              : }
    1237              : 
    1238              : /* Attach a pref PREF to the corresponding allocno.  */
    1239              : static void
    1240      7312054 : add_allocno_pref_to_list (ira_pref_t pref)
    1241              : {
    1242      7312054 :   ira_allocno_t a = pref->allocno;
    1243              : 
    1244      7312054 :   pref->next_pref = ALLOCNO_PREFS (a);
    1245      7312054 :   ALLOCNO_PREFS (a) = pref;
    1246      7312054 : }
    1247              : 
    1248              : /* Create (or update frequency if the pref already exists) the pref of
    1249              :    allocnos A preferring HARD_REGNO with frequency FREQ.  */
    1250              : void
    1251      7829850 : ira_add_allocno_pref (ira_allocno_t a, int hard_regno, int freq)
    1252              : {
    1253      7829850 :   ira_pref_t pref;
    1254              : 
    1255      7829850 :   if (freq <= 0)
    1256              :     return;
    1257     15561186 :   if ((pref = find_allocno_pref (a, hard_regno)) != NULL)
    1258              :     {
    1259       468539 :       pref->freq += freq;
    1260       468539 :       return;
    1261              :     }
    1262      7312054 :   pref = ira_create_pref (a, hard_regno, freq);
    1263      7312054 :   ira_assert (a != NULL);
    1264      7312054 :   add_allocno_pref_to_list (pref);
    1265              : }
    1266              : 
    1267              : /* Print info about PREF into file F.  */
    1268              : static void
    1269          191 : print_pref (FILE *f, ira_pref_t pref)
    1270              : {
    1271          191 :   fprintf (f, "  pref%d:a%d(r%d)<-hr%d@%d\n", pref->num,
    1272          191 :            ALLOCNO_NUM (pref->allocno), ALLOCNO_REGNO (pref->allocno),
    1273              :            pref->hard_regno, pref->freq);
    1274          191 : }
    1275              : 
    1276              : /* Print info about PREF into stderr.  */
    1277              : void
    1278            0 : ira_debug_pref (ira_pref_t pref)
    1279              : {
    1280            0 :   print_pref (stderr, pref);
    1281            0 : }
    1282              : 
    1283              : /* Print info about all prefs into file F.  */
    1284              : static void
    1285           95 : print_prefs (FILE *f)
    1286              : {
    1287           95 :   ira_pref_t pref;
    1288           95 :   ira_pref_iterator pi;
    1289              : 
    1290          286 :   FOR_EACH_PREF (pref, pi)
    1291          191 :     print_pref (f, pref);
    1292           95 : }
    1293              : 
    1294              : /* Print info about all prefs into stderr.  */
    1295              : void
    1296            0 : ira_debug_prefs (void)
    1297              : {
    1298            0 :   print_prefs (stderr);
    1299            0 : }
    1300              : 
    1301              : /* Print info about prefs involving allocno A into file F.  */
    1302              : static void
    1303            0 : print_allocno_prefs (FILE *f, ira_allocno_t a)
    1304              : {
    1305            0 :   ira_pref_t pref;
    1306              : 
    1307            0 :   fprintf (f, " a%d(r%d):", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
    1308            0 :   for (pref = ALLOCNO_PREFS (a); pref != NULL; pref = pref->next_pref)
    1309            0 :     fprintf (f, " pref%d:hr%d@%d", pref->num, pref->hard_regno, pref->freq);
    1310            0 :   fprintf (f, "\n");
    1311            0 : }
    1312              : 
    1313              : /* Print info about prefs involving allocno A into stderr.  */
    1314              : void
    1315            0 : ira_debug_allocno_prefs (ira_allocno_t a)
    1316              : {
    1317            0 :   print_allocno_prefs (stderr, a);
    1318            0 : }
    1319              : 
    1320              : /* The function frees memory allocated for PREF.  */
    1321              : static void
    1322      7312054 : finish_pref (ira_pref_t pref)
    1323              : {
    1324      7312054 :   ira_prefs[pref->num] = NULL;
    1325      7312054 :   pref_pool.remove (pref);
    1326      7312054 : }
    1327              : 
    1328              : /* Remove PREF from the list of allocno prefs and free memory for
    1329              :    it.  */
    1330              : void
    1331       863940 : ira_remove_pref (ira_pref_t pref)
    1332              : {
    1333       863940 :   ira_pref_t cpref, prev;
    1334              : 
    1335       863940 :   if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
    1336           14 :     fprintf (ira_dump_file, " Removing pref%d:hr%d@%d\n",
    1337              :              pref->num, pref->hard_regno, pref->freq);
    1338       863940 :   for (prev = NULL, cpref = ALLOCNO_PREFS (pref->allocno);
    1339       869935 :        cpref != NULL;
    1340         5995 :        prev = cpref, cpref = cpref->next_pref)
    1341       869935 :     if (cpref == pref)
    1342              :       break;
    1343       863940 :   ira_assert (cpref != NULL);
    1344       863940 :   if (prev == NULL)
    1345       857947 :     ALLOCNO_PREFS (pref->allocno) = pref->next_pref;
    1346              :   else
    1347         5993 :     prev->next_pref = pref->next_pref;
    1348       863940 :   finish_pref (pref);
    1349       863940 : }
    1350              : 
    1351              : /* Remove all prefs of allocno A.  */
    1352              : void
    1353      2409833 : ira_remove_allocno_prefs (ira_allocno_t a)
    1354              : {
    1355      2409833 :   ira_pref_t pref, next_pref;
    1356              : 
    1357      2453680 :   for (pref = ALLOCNO_PREFS (a); pref != NULL; pref = next_pref)
    1358              :     {
    1359        43847 :       next_pref = pref->next_pref;
    1360        43847 :       finish_pref (pref);
    1361              :     }
    1362      2409833 :   ALLOCNO_PREFS (a) = NULL;
    1363      2409833 : }
    1364              : 
    1365              : /* Free memory allocated for all prefs.  */
    1366              : static void
    1367      1504950 : finish_prefs (void)
    1368              : {
    1369      1504950 :   ira_pref_t pref;
    1370      1504950 :   ira_pref_iterator pi;
    1371              : 
    1372      7909217 :   FOR_EACH_PREF (pref, pi)
    1373      6404267 :     finish_pref (pref);
    1374      1504950 :   pref_vec.release ();
    1375      1504950 :   pref_pool.release ();
    1376      1504950 : }
    1377              : 
    1378              : 
    1379              : 
    1380              : /* Pools for copies.  */
    1381              : static object_allocator<ira_allocno_copy> copy_pool ("copies");
    1382              : 
    1383              : /* Vec containing references to all created copies.  It is a
    1384              :    container of array ira_copies.  */
    1385              : static vec<ira_copy_t> copy_vec;
    1386              : 
    1387              : /* The function initializes data concerning allocno copies.  */
    1388              : static void
    1389      1504950 : initiate_copies (void)
    1390              : {
    1391      1504950 :   copy_vec.create (get_max_uid ());
    1392      1504950 :   ira_copies = NULL;
    1393      1504950 :   ira_copies_num = 0;
    1394      1504950 : }
    1395              : 
    1396              : /* Return copy connecting A1 and A2 and originated from INSN of
    1397              :    LOOP_TREE_NODE if any.  */
    1398              : static ira_copy_t
    1399      9584395 : find_allocno_copy (ira_allocno_t a1, ira_allocno_t a2, rtx_insn *insn,
    1400              :                    ira_loop_tree_node_t loop_tree_node)
    1401              : {
    1402      9584395 :   ira_copy_t cp, next_cp;
    1403      9584395 :   ira_allocno_t another_a;
    1404              : 
    1405     18641862 :   for (cp = ALLOCNO_COPIES (a1); cp != NULL; cp = next_cp)
    1406              :     {
    1407      9112938 :       if (cp->first == a1)
    1408              :         {
    1409      6891003 :           next_cp = cp->next_first_allocno_copy;
    1410      6891003 :           another_a = cp->second;
    1411              :         }
    1412      2221935 :       else if (cp->second == a1)
    1413              :         {
    1414      2221935 :           next_cp = cp->next_second_allocno_copy;
    1415      2221935 :           another_a = cp->first;
    1416              :         }
    1417              :       else
    1418            0 :         gcc_unreachable ();
    1419      9112938 :       if (another_a == a2 && cp->insn == insn
    1420        55528 :           && cp->loop_tree_node == loop_tree_node)
    1421              :         return cp;
    1422              :     }
    1423              :   return NULL;
    1424              : }
    1425              : 
    1426              : /* Create and return copy with given attributes LOOP_TREE_NODE, FIRST,
    1427              :    SECOND, FREQ, CONSTRAINT_P, and INSN.  */
    1428              : ira_copy_t
    1429      9528924 : ira_create_copy (ira_allocno_t first, ira_allocno_t second, int freq,
    1430              :                  bool constraint_p, rtx_insn *insn,
    1431              :                  ira_loop_tree_node_t loop_tree_node)
    1432              : {
    1433      9528924 :   ira_copy_t cp;
    1434              : 
    1435      9528924 :   cp = copy_pool.allocate ();
    1436      9528924 :   cp->num = ira_copies_num;
    1437      9528924 :   cp->first = first;
    1438      9528924 :   cp->second = second;
    1439      9528924 :   cp->freq = freq;
    1440      9528924 :   cp->constraint_p = constraint_p;
    1441      9528924 :   cp->insn = insn;
    1442      9528924 :   cp->loop_tree_node = loop_tree_node;
    1443      9528924 :   copy_vec.safe_push (cp);
    1444      9528924 :   ira_copies = copy_vec.address ();
    1445      9528924 :   ira_copies_num = copy_vec.length ();
    1446      9528924 :   return cp;
    1447              : }
    1448              : 
    1449              : /* Attach a copy CP to allocnos involved into the copy.  */
    1450              : static void
    1451      9528924 : add_allocno_copy_to_list (ira_copy_t cp)
    1452              : {
    1453      9528924 :   ira_allocno_t first = cp->first, second = cp->second;
    1454              : 
    1455      9528924 :   cp->prev_first_allocno_copy = NULL;
    1456      9528924 :   cp->prev_second_allocno_copy = NULL;
    1457      9528924 :   cp->next_first_allocno_copy = ALLOCNO_COPIES (first);
    1458      9528924 :   if (cp->next_first_allocno_copy != NULL)
    1459              :     {
    1460      3885523 :       if (cp->next_first_allocno_copy->first == first)
    1461      2647884 :         cp->next_first_allocno_copy->prev_first_allocno_copy = cp;
    1462              :       else
    1463      1237639 :         cp->next_first_allocno_copy->prev_second_allocno_copy = cp;
    1464              :     }
    1465      9528924 :   cp->next_second_allocno_copy = ALLOCNO_COPIES (second);
    1466      9528924 :   if (cp->next_second_allocno_copy != NULL)
    1467              :     {
    1468      3039154 :       if (cp->next_second_allocno_copy->second == second)
    1469       507036 :         cp->next_second_allocno_copy->prev_second_allocno_copy = cp;
    1470              :       else
    1471      2532118 :         cp->next_second_allocno_copy->prev_first_allocno_copy = cp;
    1472              :     }
    1473      9528924 :   ALLOCNO_COPIES (first) = cp;
    1474      9528924 :   ALLOCNO_COPIES (second) = cp;
    1475      9528924 : }
    1476              : 
    1477              : /* Make a copy CP a canonical copy where number of the
    1478              :    first allocno is less than the second one.  */
    1479              : static void
    1480      9528924 : swap_allocno_copy_ends_if_necessary (ira_copy_t cp)
    1481              : {
    1482      9528924 :   if (ALLOCNO_NUM (cp->first) <= ALLOCNO_NUM (cp->second))
    1483              :     return;
    1484              : 
    1485      6175239 :   std::swap (cp->first, cp->second);
    1486      6175239 :   std::swap (cp->prev_first_allocno_copy, cp->prev_second_allocno_copy);
    1487      6175239 :   std::swap (cp->next_first_allocno_copy, cp->next_second_allocno_copy);
    1488              : }
    1489              : 
    1490              : /* Create (or update frequency if the copy already exists) and return
    1491              :    the copy of allocnos FIRST and SECOND with frequency FREQ
    1492              :    corresponding to move insn INSN (if any) and originated from
    1493              :    LOOP_TREE_NODE.  */
    1494              : ira_copy_t
    1495      9584395 : ira_add_allocno_copy (ira_allocno_t first, ira_allocno_t second, int freq,
    1496              :                       bool constraint_p, rtx_insn *insn,
    1497              :                       ira_loop_tree_node_t loop_tree_node)
    1498              : {
    1499      9584395 :   ira_copy_t cp;
    1500              : 
    1501      9584395 :   if ((cp = find_allocno_copy (first, second, insn, loop_tree_node)) != NULL)
    1502              :     {
    1503        55471 :       cp->freq += freq;
    1504        55471 :       return cp;
    1505              :     }
    1506      9528924 :   cp = ira_create_copy (first, second, freq, constraint_p, insn,
    1507              :                         loop_tree_node);
    1508      9528924 :   ira_assert (first != NULL && second != NULL);
    1509      9528924 :   add_allocno_copy_to_list (cp);
    1510      9528924 :   swap_allocno_copy_ends_if_necessary (cp);
    1511      9528924 :   return cp;
    1512              : }
    1513              : 
    1514              : /* Print info about copy CP into file F.  */
    1515              : static void
    1516          160 : print_copy (FILE *f, ira_copy_t cp)
    1517              : {
    1518          320 :   fprintf (f, "  cp%d:a%d(r%d)<->a%d(r%d)@%d:%s\n", cp->num,
    1519          160 :            ALLOCNO_NUM (cp->first), ALLOCNO_REGNO (cp->first),
    1520          160 :            ALLOCNO_NUM (cp->second), ALLOCNO_REGNO (cp->second), cp->freq,
    1521          160 :            cp->insn != NULL
    1522          120 :            ? "move" : cp->constraint_p ? "constraint" : "shuffle");
    1523          160 : }
    1524              : 
    1525              : DEBUG_FUNCTION void
    1526            0 : debug (ira_allocno_copy &ref)
    1527              : {
    1528            0 :   print_copy (stderr, &ref);
    1529            0 : }
    1530              : 
    1531              : DEBUG_FUNCTION void
    1532            0 : debug (ira_allocno_copy *ptr)
    1533              : {
    1534            0 :   if (ptr)
    1535            0 :     debug (*ptr);
    1536              :   else
    1537            0 :     fprintf (stderr, "<nil>\n");
    1538            0 : }
    1539              : 
    1540              : /* Print info about copy CP into stderr.  */
    1541              : void
    1542            0 : ira_debug_copy (ira_copy_t cp)
    1543              : {
    1544            0 :   print_copy (stderr, cp);
    1545            0 : }
    1546              : 
    1547              : /* Print info about all copies into file F.  */
    1548              : static void
    1549           95 : print_copies (FILE *f)
    1550              : {
    1551           95 :   ira_copy_t cp;
    1552           95 :   ira_copy_iterator ci;
    1553              : 
    1554          255 :   FOR_EACH_COPY (cp, ci)
    1555          160 :     print_copy (f, cp);
    1556           95 : }
    1557              : 
    1558              : /* Print info about all copies into stderr.  */
    1559              : void
    1560            0 : ira_debug_copies (void)
    1561              : {
    1562            0 :   print_copies (stderr);
    1563            0 : }
    1564              : 
    1565              : /* Print info about copies involving allocno A into file F.  */
    1566              : static void
    1567            0 : print_allocno_copies (FILE *f, ira_allocno_t a)
    1568              : {
    1569            0 :   ira_allocno_t another_a;
    1570            0 :   ira_copy_t cp, next_cp;
    1571              : 
    1572            0 :   fprintf (f, " a%d(r%d):", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
    1573            0 :   for (cp = ALLOCNO_COPIES (a); cp != NULL; cp = next_cp)
    1574              :     {
    1575            0 :       if (cp->first == a)
    1576              :         {
    1577            0 :           next_cp = cp->next_first_allocno_copy;
    1578            0 :           another_a = cp->second;
    1579              :         }
    1580            0 :       else if (cp->second == a)
    1581              :         {
    1582            0 :           next_cp = cp->next_second_allocno_copy;
    1583            0 :           another_a = cp->first;
    1584              :         }
    1585              :       else
    1586            0 :         gcc_unreachable ();
    1587            0 :       fprintf (f, " cp%d:a%d(r%d)@%d", cp->num,
    1588              :                ALLOCNO_NUM (another_a), ALLOCNO_REGNO (another_a), cp->freq);
    1589              :     }
    1590            0 :   fprintf (f, "\n");
    1591            0 : }
    1592              : 
    1593              : DEBUG_FUNCTION void
    1594            0 : debug (ira_allocno &ref)
    1595              : {
    1596            0 :   print_allocno_copies (stderr, &ref);
    1597            0 : }
    1598              : 
    1599              : DEBUG_FUNCTION void
    1600            0 : debug (ira_allocno *ptr)
    1601              : {
    1602            0 :   if (ptr)
    1603            0 :     debug (*ptr);
    1604              :   else
    1605            0 :     fprintf (stderr, "<nil>\n");
    1606            0 : }
    1607              : 
    1608              : 
    1609              : /* Print info about copies involving allocno A into stderr.  */
    1610              : void
    1611            0 : ira_debug_allocno_copies (ira_allocno_t a)
    1612              : {
    1613            0 :   print_allocno_copies (stderr, a);
    1614            0 : }
    1615              : 
    1616              : /* The function frees memory allocated for copy CP.  */
    1617              : static void
    1618      9528924 : finish_copy (ira_copy_t cp)
    1619              : {
    1620            0 :   copy_pool.remove (cp);
    1621      9528924 : }
    1622              : 
    1623              : 
    1624              : /* Free memory allocated for all copies.  */
    1625              : static void
    1626      1504950 : finish_copies (void)
    1627              : {
    1628      1504950 :   ira_copy_t cp;
    1629      1504950 :   ira_copy_iterator ci;
    1630              : 
    1631     11033874 :   FOR_EACH_COPY (cp, ci)
    1632      9528924 :     finish_copy (cp);
    1633      1504950 :   copy_vec.release ();
    1634      1504950 :   copy_pool.release ();
    1635      1504950 : }
    1636              : 
    1637              : 
    1638              : 
    1639              : /* Pools for cost vectors.  It is defined only for allocno classes.  */
    1640              : static pool_allocator *cost_vector_pool[N_REG_CLASSES];
    1641              : 
    1642              : /* The function initiates work with hard register cost vectors.  It
    1643              :    creates allocation pool for each allocno class.  */
    1644              : static void
    1645      1504950 : initiate_cost_vectors (void)
    1646              : {
    1647      1504950 :   int i;
    1648      1504950 :   enum reg_class aclass;
    1649              : 
    1650     39108419 :   for (i = 0; i < ira_allocno_classes_num; i++)
    1651              :     {
    1652     37603469 :       aclass = ira_allocno_classes[i];
    1653     37603469 :       cost_vector_pool[aclass] = new pool_allocator
    1654     37603469 :         ("cost vectors", sizeof (int) * (ira_class_hard_regs_num[aclass]));
    1655              :     }
    1656      1504950 : }
    1657              : 
    1658              : /* Allocate and return a cost vector VEC for ACLASS.  */
    1659              : int *
    1660     32466681 : ira_allocate_cost_vector (reg_class_t aclass)
    1661              : {
    1662     32466681 :   return (int*) cost_vector_pool[(int) aclass]->allocate ();
    1663              : }
    1664              : 
    1665              : /* Free a cost vector VEC for ACLASS.  */
    1666              : void
    1667     32466681 : ira_free_cost_vector (int *vec, reg_class_t aclass)
    1668              : {
    1669     32466681 :   ira_assert (vec != NULL);
    1670     32466681 :   cost_vector_pool[(int) aclass]->remove (vec);
    1671     32466681 : }
    1672              : 
    1673              : /* Finish work with hard register cost vectors.  Release allocation
    1674              :    pool for each allocno class.  */
    1675              : static void
    1676      1504950 : finish_cost_vectors (void)
    1677              : {
    1678      1504950 :   int i;
    1679      1504950 :   enum reg_class aclass;
    1680              : 
    1681     39108419 :   for (i = 0; i < ira_allocno_classes_num; i++)
    1682              :     {
    1683     37603469 :       aclass = ira_allocno_classes[i];
    1684     75206938 :       delete cost_vector_pool[aclass];
    1685              :     }
    1686      1504950 : }
    1687              : 
    1688              : 
    1689              : 
    1690              : /* Compute a post-ordering of the reverse control flow of the loop body
    1691              :    designated by the children nodes of LOOP_NODE, whose body nodes in
    1692              :    pre-order are input as LOOP_PREORDER.  Return a VEC with a post-order
    1693              :    of the reverse loop body.
    1694              : 
    1695              :    For the post-order of the reverse CFG, we visit the basic blocks in
    1696              :    LOOP_PREORDER array in the reverse order of where they appear.
    1697              :    This is important: We do not just want to compute a post-order of
    1698              :    the reverse CFG, we want to make a best-guess for a visiting order that
    1699              :    minimizes the number of chain elements per allocno live range.  If the
    1700              :    blocks would be visited in a different order, we would still compute a
    1701              :    correct post-ordering but it would be less likely that two nodes
    1702              :    connected by an edge in the CFG are neighbors in the topsort.  */
    1703              : 
    1704              : static vec<ira_loop_tree_node_t>
    1705      2114563 : ira_loop_tree_body_rev_postorder (ira_loop_tree_node_t loop_node ATTRIBUTE_UNUSED,
    1706              :                                   const vec<ira_loop_tree_node_t> &loop_preorder)
    1707              : {
    1708      2114563 :   vec<ira_loop_tree_node_t> topsort_nodes = vNULL;
    1709      2114563 :   unsigned int n_loop_preorder;
    1710              : 
    1711      2114563 :   n_loop_preorder = loop_preorder.length ();
    1712      2114563 :   if (n_loop_preorder != 0)
    1713              :     {
    1714      2114563 :       ira_loop_tree_node_t subloop_node;
    1715      2114563 :       unsigned int i;
    1716      2114563 :       auto_vec<ira_loop_tree_node_t> dfs_stack;
    1717              : 
    1718              :       /* This is a bit of strange abuse of the BB_VISITED flag:  We use
    1719              :          the flag to mark blocks we still have to visit to add them to
    1720              :          our post-order.  Define an alias to avoid confusion.  */
    1721              : #define BB_TO_VISIT BB_VISITED
    1722              : 
    1723     16744023 :       FOR_EACH_VEC_ELT (loop_preorder, i, subloop_node)
    1724              :         {
    1725     14629460 :           gcc_checking_assert (! (subloop_node->bb->flags & BB_TO_VISIT));
    1726     14629460 :           subloop_node->bb->flags |= BB_TO_VISIT;
    1727              :         }
    1728              : 
    1729      2114563 :       topsort_nodes.create (n_loop_preorder);
    1730      2114563 :       dfs_stack.create (n_loop_preorder);
    1731              : 
    1732     20973149 :       FOR_EACH_VEC_ELT_REVERSE (loop_preorder, i, subloop_node)
    1733              :         {
    1734     14629460 :           if (! (subloop_node->bb->flags & BB_TO_VISIT))
    1735      4024483 :             continue;
    1736              : 
    1737     10604977 :           subloop_node->bb->flags &= ~BB_TO_VISIT;
    1738     10604977 :           dfs_stack.quick_push (subloop_node);
    1739     31974064 :           while (! dfs_stack.is_empty ())
    1740              :             {
    1741     17344604 :               edge e;
    1742     17344604 :               edge_iterator ei;
    1743              : 
    1744     17344604 :               ira_loop_tree_node_t n = dfs_stack.last ();
    1745     43223420 :               FOR_EACH_EDGE (e, ei, n->bb->preds)
    1746              :                 {
    1747     25878816 :                   ira_loop_tree_node_t pred_node;
    1748     25878816 :                   basic_block pred_bb = e->src;
    1749              : 
    1750     25878816 :                   if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
    1751      1504950 :                     continue;
    1752              : 
    1753     24373866 :                   pred_node = IRA_BB_NODE_BY_INDEX (pred_bb->index);
    1754     24373866 :                   if (pred_node != n
    1755     24082748 :                       && (pred_node->bb->flags & BB_TO_VISIT))
    1756              :                     {
    1757      4024483 :                       pred_node->bb->flags &= ~BB_TO_VISIT;
    1758      4024483 :                       dfs_stack.quick_push (pred_node);
    1759              :                     }
    1760              :                 }
    1761     17344604 :               if (n == dfs_stack.last ())
    1762              :                 {
    1763     14629460 :                   dfs_stack.pop ();
    1764     14629460 :                   topsort_nodes.quick_push (n);
    1765              :                 }
    1766              :             }
    1767              :         }
    1768              : 
    1769              : #undef BB_TO_VISIT
    1770      2114563 :     }
    1771              : 
    1772      4229126 :   gcc_assert (topsort_nodes.length () == n_loop_preorder);
    1773      2114563 :   return topsort_nodes;
    1774              : }
    1775              : 
    1776              : /* The current loop tree node and its regno allocno map.  */
    1777              : ira_loop_tree_node_t ira_curr_loop_tree_node;
    1778              : ira_allocno_t *ira_curr_regno_allocno_map;
    1779              : 
    1780              : /* This recursive function traverses loop tree with root LOOP_NODE
    1781              :    calling non-null functions PREORDER_FUNC and POSTORDER_FUNC
    1782              :    correspondingly in preorder and postorder.  The function sets up
    1783              :    IRA_CURR_LOOP_TREE_NODE and IRA_CURR_REGNO_ALLOCNO_MAP.  If BB_P,
    1784              :    basic block nodes of LOOP_NODE is also processed (before its
    1785              :    subloop nodes).
    1786              : 
    1787              :    If BB_P is set and POSTORDER_FUNC is given, the basic blocks in
    1788              :    the loop are passed in the *reverse* post-order of the *reverse*
    1789              :    CFG.  This is only used by ira_create_allocno_live_ranges, which
    1790              :    wants to visit basic blocks in this order to minimize the number
    1791              :    of elements per live range chain.
    1792              :    Note that the loop tree nodes are still visited in the normal,
    1793              :    forward post-order of  the loop tree.  */
    1794              : 
    1795              : void
    1796     13865710 : ira_traverse_loop_tree (bool bb_p, ira_loop_tree_node_t loop_node,
    1797              :                         void (*preorder_func) (ira_loop_tree_node_t),
    1798              :                         void (*postorder_func) (ira_loop_tree_node_t))
    1799              : {
    1800     13865710 :   ira_loop_tree_node_t subloop_node;
    1801              : 
    1802     13865710 :   ira_assert (loop_node->bb == NULL);
    1803     13865710 :   ira_curr_loop_tree_node = loop_node;
    1804     13865710 :   ira_curr_regno_allocno_map = ira_curr_loop_tree_node->regno_allocno_map;
    1805              : 
    1806     13865710 :   if (preorder_func != NULL)
    1807     10084620 :     (*preorder_func) (loop_node);
    1808              : 
    1809     13865710 :   if (bb_p)
    1810              :     {
    1811     10976205 :       auto_vec<ira_loop_tree_node_t> loop_preorder;
    1812     10976205 :       unsigned int i;
    1813              : 
    1814              :       /* Add all nodes to the set of nodes to visit.  The IRA loop tree
    1815              :          is set up such that nodes in the loop body appear in a pre-order
    1816              :          of their place in the CFG.  */
    1817     10976205 :       for (subloop_node = loop_node->children;
    1818     93733304 :            subloop_node != NULL;
    1819     82757099 :            subloop_node = subloop_node->next)
    1820     82757099 :         if (subloop_node->bb != NULL)
    1821     79421769 :           loop_preorder.safe_push (subloop_node);
    1822              : 
    1823     10976205 :       if (preorder_func != NULL)
    1824     73653951 :         FOR_EACH_VEC_ELT (loop_preorder, i, subloop_node)
    1825     64792309 :           (*preorder_func) (subloop_node);
    1826              : 
    1827     10976205 :       if (postorder_func != NULL)
    1828              :         {
    1829      2114563 :           vec<ira_loop_tree_node_t> loop_rev_postorder =
    1830      2114563 :             ira_loop_tree_body_rev_postorder (loop_node, loop_preorder);
    1831     18858586 :           FOR_EACH_VEC_ELT_REVERSE (loop_rev_postorder, i, subloop_node)
    1832     14629460 :             (*postorder_func) (subloop_node);
    1833      2114563 :           loop_rev_postorder.release ();
    1834              :         }
    1835     10976205 :     }
    1836              : 
    1837     13865710 :   for (subloop_node = loop_node->subloops;
    1838     17976427 :        subloop_node != NULL;
    1839      4110717 :        subloop_node = subloop_node->subloop_next)
    1840              :     {
    1841      4110717 :       ira_assert (subloop_node->bb == NULL);
    1842      4110717 :       ira_traverse_loop_tree (bb_p, subloop_node,
    1843              :                               preorder_func, postorder_func);
    1844              :     }
    1845              : 
    1846     13865710 :   ira_curr_loop_tree_node = loop_node;
    1847     13865710 :   ira_curr_regno_allocno_map = ira_curr_loop_tree_node->regno_allocno_map;
    1848              : 
    1849     13865710 :   if (postorder_func != NULL)
    1850      3781090 :     (*postorder_func) (loop_node);
    1851     13865710 : }
    1852              : 
    1853              : 
    1854              : 
    1855              : /* The basic block currently being processed.  */
    1856              : static basic_block curr_bb;
    1857              : 
    1858              : /* This recursive function creates allocnos corresponding to
    1859              :    pseudo-registers containing in X.  True OUTPUT_P means that X is
    1860              :    an lvalue.  OUTER corresponds to the parent expression of X.  */
    1861              : static void
    1862    461474492 : create_insn_allocnos (rtx x, rtx outer, bool output_p)
    1863              : {
    1864    461474492 :   int i, j;
    1865    461474492 :   const char *fmt;
    1866    461474492 :   enum rtx_code code = GET_CODE (x);
    1867              : 
    1868    461474492 :   if (code == REG)
    1869              :     {
    1870    151904131 :       int regno;
    1871              : 
    1872    151904131 :       if ((regno = REGNO (x)) >= FIRST_PSEUDO_REGISTER)
    1873              :         {
    1874     85412278 :           ira_allocno_t a;
    1875              : 
    1876     85412278 :           if ((a = ira_curr_regno_allocno_map[regno]) == NULL)
    1877     29526039 :             a = ira_create_allocno (regno, false, ira_curr_loop_tree_node);
    1878              : 
    1879              :           /* This used to only trigger at allocno creation which seems
    1880              :              wrong.  We care about the WMODE property across all the uses.  */
    1881     85412278 :           if (outer != NULL && GET_CODE (outer) == SUBREG)
    1882              :             {
    1883      3041015 :               machine_mode wmode = GET_MODE (outer);
    1884      3041015 :               if (partial_subreg_p (ALLOCNO_WMODE (a), wmode))
    1885       535030 :                 ALLOCNO_WMODE (a) = wmode;
    1886              :             }
    1887              : 
    1888     85412278 :           ALLOCNO_NREFS (a)++;
    1889     85412278 :           ALLOCNO_FREQ (a) += REG_FREQ_FROM_BB (curr_bb);
    1890     85412278 :           if (output_p)
    1891     34526950 :             bitmap_set_bit (ira_curr_loop_tree_node->modified_regnos, regno);
    1892              :         }
    1893    151904131 :       return;
    1894              :     }
    1895              :   else if (code == SET)
    1896              :     {
    1897     80174956 :       create_insn_allocnos (SET_DEST (x), NULL, true);
    1898     80174956 :       create_insn_allocnos (SET_SRC (x), NULL, false);
    1899     80174956 :       return;
    1900              :     }
    1901              :   else if (code == CLOBBER)
    1902              :     {
    1903     11056551 :       create_insn_allocnos (XEXP (x, 0), NULL, true);
    1904     11056551 :       return;
    1905              :     }
    1906              :   else if (code == MEM)
    1907              :     {
    1908     34572075 :       create_insn_allocnos (XEXP (x, 0), NULL, false);
    1909     34572075 :       return;
    1910              :     }
    1911              :   else if (code == PRE_DEC || code == POST_DEC || code == PRE_INC ||
    1912              :            code == POST_INC || code == POST_MODIFY || code == PRE_MODIFY)
    1913              :     {
    1914      1850880 :       create_insn_allocnos (XEXP (x, 0), NULL, true);
    1915      1850880 :       create_insn_allocnos (XEXP (x, 0), NULL, false);
    1916      1850880 :       return;
    1917              :     }
    1918              : 
    1919    181915899 :   fmt = GET_RTX_FORMAT (code);
    1920    439071508 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1921              :     {
    1922    257155609 :       if (fmt[i] == 'e')
    1923    139572019 :         create_insn_allocnos (XEXP (x, i), x, output_p);
    1924    117583590 :       else if (fmt[i] == 'E')
    1925     41173961 :         for (j = 0; j < XVECLEN (x, i); j++)
    1926     27569516 :           create_insn_allocnos (XVECEXP (x, i, j), x, output_p);
    1927              :     }
    1928              : }
    1929              : 
    1930              : /* Create allocnos corresponding to pseudo-registers living in the
    1931              :    basic block represented by the corresponding loop tree node
    1932              :    BB_NODE.  */
    1933              : static void
    1934     14629460 : create_bb_allocnos (ira_loop_tree_node_t bb_node)
    1935              : {
    1936     14629460 :   basic_block bb;
    1937     14629460 :   rtx_insn *insn;
    1938     14629460 :   unsigned int i;
    1939     14629460 :   bitmap_iterator bi;
    1940              : 
    1941     14629460 :   curr_bb = bb = bb_node->bb;
    1942     14629460 :   ira_assert (bb != NULL);
    1943    178048395 :   FOR_BB_INSNS_REVERSE (bb, insn)
    1944    163418935 :     if (NONDEBUG_INSN_P (insn))
    1945     84652659 :       create_insn_allocnos (PATTERN (insn), NULL, false);
    1946              :   /* It might be a allocno living through from one subloop to
    1947              :      another.  */
    1948    153530660 :   EXECUTE_IF_SET_IN_REG_SET (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, i, bi)
    1949    138901200 :     if (ira_curr_regno_allocno_map[i] == NULL)
    1950       648702 :       ira_create_allocno (i, false, ira_curr_loop_tree_node);
    1951     14629460 : }
    1952              : 
    1953              : /* Create allocnos corresponding to pseudo-registers living on edge E
    1954              :    (a loop entry or exit).  Also mark the allocnos as living on the
    1955              :    loop border. */
    1956              : static void
    1957      1743700 : create_loop_allocnos (edge e)
    1958              : {
    1959      1743700 :   unsigned int i;
    1960      1743700 :   bitmap live_in_regs, border_allocnos;
    1961      1743700 :   bitmap_iterator bi;
    1962      1743700 :   ira_loop_tree_node_t parent;
    1963              : 
    1964      1743700 :   live_in_regs = df_get_live_in (e->dest);
    1965      1743700 :   border_allocnos = ira_curr_loop_tree_node->border_allocnos;
    1966     18966109 :   EXECUTE_IF_SET_IN_REG_SET (df_get_live_out (e->src),
    1967              :                              FIRST_PSEUDO_REGISTER, i, bi)
    1968     17222409 :     if (bitmap_bit_p (live_in_regs, i))
    1969              :       {
    1970     11510038 :         if (ira_curr_regno_allocno_map[i] == NULL)
    1971              :           {
    1972              :             /* The order of creations is important for right
    1973              :                ira_regno_allocno_map.  */
    1974      5525396 :             if ((parent = ira_curr_loop_tree_node->parent) != NULL
    1975      5525396 :                 && parent->regno_allocno_map[i] == NULL)
    1976          494 :               ira_create_allocno (i, false, parent);
    1977      5525396 :             ira_create_allocno (i, false, ira_curr_loop_tree_node);
    1978              :           }
    1979     11510038 :         bitmap_set_bit (border_allocnos,
    1980     11510038 :                         ALLOCNO_NUM (ira_curr_regno_allocno_map[i]));
    1981              :       }
    1982      1743700 : }
    1983              : 
    1984              : /* Create allocnos corresponding to pseudo-registers living in loop
    1985              :    represented by the corresponding loop tree node LOOP_NODE.  This
    1986              :    function is called by ira_traverse_loop_tree.  */
    1987              : static void
    1988     16744023 : create_loop_tree_node_allocnos (ira_loop_tree_node_t loop_node)
    1989              : {
    1990     16744023 :   if (loop_node->bb != NULL)
    1991     14629460 :     create_bb_allocnos (loop_node);
    1992      2114563 :   else if (loop_node != ira_loop_tree_root)
    1993              :     {
    1994       609613 :       int i;
    1995       609613 :       edge_iterator ei;
    1996       609613 :       edge e;
    1997              : 
    1998       609613 :       ira_assert (current_loops != NULL);
    1999      1901145 :       FOR_EACH_EDGE (e, ei, loop_node->loop->header->preds)
    2000      1291532 :         if (e->src != loop_node->loop->latch)
    2001       697606 :           create_loop_allocnos (e);
    2002              : 
    2003       609613 :       auto_vec<edge> edges = get_loop_exit_edges (loop_node->loop);
    2004      2867811 :       FOR_EACH_VEC_ELT (edges, i, e)
    2005      1046094 :         create_loop_allocnos (e);
    2006       609613 :     }
    2007     16744023 : }
    2008              : 
    2009              : /* Propagate information about allocnos modified inside the loop given
    2010              :    by its LOOP_TREE_NODE to its parent.  */
    2011              : static void
    2012      1666527 : propagate_modified_regnos (ira_loop_tree_node_t loop_tree_node)
    2013              : {
    2014      1666527 :   if (loop_tree_node == ira_loop_tree_root)
    2015              :     return;
    2016       609468 :   ira_assert (loop_tree_node->bb == NULL);
    2017       609468 :   bitmap_ior_into (loop_tree_node->parent->modified_regnos,
    2018       609468 :                    loop_tree_node->modified_regnos);
    2019              : }
    2020              : 
    2021              : /* Propagate ALLOCNO_HARD_REG_COSTS from A to PARENT_A.  Use SPILL_COST
    2022              :    as the cost of spilling a register throughout A (which we have to do
    2023              :    for PARENT_A allocations that conflict with A).  */
    2024              : static void
    2025      3117412 : ira_propagate_hard_reg_costs (ira_allocno_t parent_a, ira_allocno_t a,
    2026              :                               int spill_cost)
    2027              : {
    2028      3117412 :   HARD_REG_SET conflicts = ira_total_conflict_hard_regs (a);
    2029      3117412 :   if (ira_caller_save_loop_spill_p (parent_a, a, spill_cost))
    2030       857592 :     conflicts |= ira_need_caller_save_regs (a);
    2031      3117412 :   conflicts &= ~ira_total_conflict_hard_regs (parent_a);
    2032              : 
    2033      3117412 :   auto costs = ALLOCNO_HARD_REG_COSTS (a);
    2034      6234824 :   if (!hard_reg_set_empty_p (conflicts))
    2035       538412 :     ALLOCNO_MIGHT_CONFLICT_WITH_PARENT_P (a) = true;
    2036      2579000 :   else if (!costs)
    2037      2417223 :     return;
    2038              : 
    2039       700189 :   auto aclass = ALLOCNO_CLASS (a);
    2040       700189 :   ira_allocate_and_set_costs (&ALLOCNO_HARD_REG_COSTS (parent_a),
    2041              :                               aclass, ALLOCNO_CLASS_COST (parent_a));
    2042       700189 :   auto parent_costs = ALLOCNO_HARD_REG_COSTS (parent_a);
    2043      9888597 :   for (int i = 0; i < ira_class_hard_regs_num[aclass]; ++i)
    2044      9188408 :     if (TEST_HARD_REG_BIT (conflicts, ira_class_hard_regs[aclass][i]))
    2045      2451547 :       parent_costs[i] += spill_cost;
    2046      6736861 :     else if (costs)
    2047              :       /* The cost to A of allocating this register to PARENT_A can't
    2048              :          be more than the cost of spilling the register throughout A.  */
    2049      2966828 :       parent_costs[i] += MIN (costs[i], spill_cost);
    2050              : }
    2051              : 
    2052              : /* Propagate new info about allocno A (see comments about accumulated
    2053              :    info in allocno definition) to the corresponding allocno on upper
    2054              :    loop tree level.  So allocnos on upper levels accumulate
    2055              :    information about the corresponding allocnos in nested regions.
    2056              :    The new info means allocno info finally calculated in this
    2057              :    file.  */
    2058              : static void
    2059        35511 : propagate_allocno_info (void)
    2060              : {
    2061        35511 :   int i;
    2062        35511 :   ira_allocno_t a, parent_a;
    2063        35511 :   ira_loop_tree_node_t parent;
    2064        35511 :   enum reg_class aclass;
    2065              : 
    2066        35511 :   if (flag_ira_region != IRA_REGION_ALL
    2067        35511 :       && flag_ira_region != IRA_REGION_MIXED)
    2068              :     return;
    2069     10903968 :   for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2070     10868457 :     for (a = ira_regno_allocno_map[i];
    2071     18774304 :          a != NULL;
    2072      7905847 :          a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    2073      7905847 :       if ((parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) != NULL
    2074      5027214 :           && (parent_a = parent->regno_allocno_map[i]) != NULL
    2075              :           /* There are no caps yet at this point.  So use
    2076              :              border_allocnos to find allocnos for the propagation.  */
    2077     11025055 :           && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE (a)->border_allocnos,
    2078              :                            ALLOCNO_NUM (a)))
    2079              :         {
    2080              :           /* Calculate the cost of storing to memory on entry to A's loop,
    2081              :              referencing as memory within A's loop, and restoring from
    2082              :              memory on exit from A's loop.  */
    2083      3117412 :           ira_loop_border_costs border_costs (a);
    2084      3117412 :           int spill_cost = INT_MAX;
    2085      3117412 :           if (ira_subloop_allocnos_can_differ_p (parent_a))
    2086      2660658 :             spill_cost = (border_costs.spill_inside_loop_cost ()
    2087      2660658 :                           + ALLOCNO_MEMORY_COST (a));
    2088              : 
    2089      3117412 :           if (! ALLOCNO_BAD_SPILL_P (a))
    2090      2931250 :             ALLOCNO_BAD_SPILL_P (parent_a) = false;
    2091      3117412 :           ALLOCNO_NREFS (parent_a) += ALLOCNO_NREFS (a);
    2092      3117412 :           ALLOCNO_FREQ (parent_a) += ALLOCNO_FREQ (a);
    2093      3117412 :           ALLOCNO_SET_REGISTER_FILTERS (parent_a,
    2094              :                                         ALLOCNO_REGISTER_FILTERS (parent_a)
    2095              :                                         | ALLOCNO_REGISTER_FILTERS (a));
    2096      3117412 :           copy_dependent_filters (parent_a, a);
    2097              : 
    2098              :           /* If A's allocation can differ from PARENT_A's, we can if necessary
    2099              :              spill PARENT_A on entry to A's loop and restore it afterwards.
    2100              :              Doing that has cost SPILL_COST.  */
    2101      3117412 :           if (!ira_subloop_allocnos_can_differ_p (parent_a))
    2102       456754 :             merge_hard_reg_conflicts (a, parent_a, true);
    2103              : 
    2104      3117412 :           if (!ira_caller_save_loop_spill_p (parent_a, a, spill_cost))
    2105              :             {
    2106      2688616 :               ALLOCNO_CALL_FREQ (parent_a) += ALLOCNO_CALL_FREQ (a);
    2107      2688616 :               ALLOCNO_CALLS_CROSSED_NUM (parent_a)
    2108      2688616 :                 += ALLOCNO_CALLS_CROSSED_NUM (a);
    2109      2688616 :               ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a)
    2110      2688616 :                 += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a);
    2111      2688616 :               ALLOCNO_CROSSED_CALLS_ABIS (parent_a)
    2112      2688616 :                 |= ALLOCNO_CROSSED_CALLS_ABIS (a);
    2113      2688616 :               ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (parent_a)
    2114      2688616 :                 |= ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a);
    2115              :             }
    2116      3117412 :           ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a)
    2117      3117412 :             += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a);
    2118      3117412 :           aclass = ALLOCNO_CLASS (a);
    2119      3117412 :           ira_assert (aclass == ALLOCNO_CLASS (parent_a));
    2120      3117412 :           ira_propagate_hard_reg_costs (parent_a, a, spill_cost);
    2121      3117412 :           ira_allocate_and_accumulate_costs
    2122      3117412 :             (&ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a),
    2123              :              aclass,
    2124              :              ALLOCNO_CONFLICT_HARD_REG_COSTS (a));
    2125              :           /* The cost to A of allocating a register to PARENT_A can't be
    2126              :              more than the cost of spilling the register throughout A.  */
    2127      3117412 :           ALLOCNO_CLASS_COST (parent_a)
    2128      3117412 :             += MIN (ALLOCNO_CLASS_COST (a), spill_cost);
    2129      3117412 :           ALLOCNO_MEMORY_COST (parent_a) += ALLOCNO_MEMORY_COST (a);
    2130              :         }
    2131              : }
    2132              : 
    2133              : /* Create allocnos corresponding to pseudo-registers in the current
    2134              :    function.  Traverse the loop tree for this.  */
    2135              : static void
    2136      1504950 : create_allocnos (void)
    2137              : {
    2138              :   /* We need to process BB first to correctly link allocnos by member
    2139              :      next_regno_allocno.  */
    2140      1504950 :   ira_traverse_loop_tree (true, ira_loop_tree_root,
    2141              :                           create_loop_tree_node_allocnos, NULL);
    2142      1504950 :   if (optimize)
    2143      1057059 :     ira_traverse_loop_tree (false, ira_loop_tree_root, NULL,
    2144              :                             propagate_modified_regnos);
    2145      1504950 : }
    2146              : 
    2147              : 
    2148              : 
    2149              : /* The page contains function to remove some regions from a separate
    2150              :    register allocation.  We remove regions whose separate allocation
    2151              :    will hardly improve the result.  As a result we speed up regional
    2152              :    register allocation.  */
    2153              : 
    2154              : /* The function changes the object in range list given by R to OBJ.  */
    2155              : static void
    2156            0 : change_object_in_range_list (live_range_t r, ira_object_t obj)
    2157              : {
    2158      5029528 :   for (; r != NULL; r = r->next)
    2159      2613250 :     r->object = obj;
    2160            0 : }
    2161              : 
    2162              : /* Move all live ranges associated with allocno FROM to allocno TO.  */
    2163              : static void
    2164      2409833 : move_allocno_live_ranges (ira_allocno_t from, ira_allocno_t to)
    2165              : {
    2166      2409833 :   int i;
    2167      2409833 :   int n = ALLOCNO_NUM_OBJECTS (from);
    2168              : 
    2169      2409833 :   gcc_assert (n == ALLOCNO_NUM_OBJECTS (to));
    2170              : 
    2171      4826111 :   for (i = 0; i < n; i++)
    2172              :     {
    2173      2416278 :       ira_object_t from_obj = ALLOCNO_OBJECT (from, i);
    2174      2416278 :       ira_object_t to_obj = ALLOCNO_OBJECT (to, i);
    2175      2416278 :       live_range_t lr = OBJECT_LIVE_RANGES (from_obj);
    2176              : 
    2177      2416278 :       if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL)
    2178              :         {
    2179          138 :           fprintf (ira_dump_file,
    2180              :                    "      Moving ranges of a%dr%d to a%dr%d: ",
    2181              :                    ALLOCNO_NUM (from), ALLOCNO_REGNO (from),
    2182              :                    ALLOCNO_NUM (to), ALLOCNO_REGNO (to));
    2183          138 :           ira_print_live_range_list (ira_dump_file, lr);
    2184              :         }
    2185      2416278 :       change_object_in_range_list (lr, to_obj);
    2186      2416278 :       OBJECT_LIVE_RANGES (to_obj)
    2187      2416278 :         = ira_merge_live_ranges (lr, OBJECT_LIVE_RANGES (to_obj));
    2188      2416278 :       OBJECT_LIVE_RANGES (from_obj) = NULL;
    2189              :     }
    2190      2409833 : }
    2191              : 
    2192              : static void
    2193            0 : copy_allocno_live_ranges (ira_allocno_t from, ira_allocno_t to)
    2194              : {
    2195            0 :   int i;
    2196            0 :   int n = ALLOCNO_NUM_OBJECTS (from);
    2197              : 
    2198            0 :   gcc_assert (n == ALLOCNO_NUM_OBJECTS (to));
    2199              : 
    2200            0 :   for (i = 0; i < n; i++)
    2201              :     {
    2202            0 :       ira_object_t from_obj = ALLOCNO_OBJECT (from, i);
    2203            0 :       ira_object_t to_obj = ALLOCNO_OBJECT (to, i);
    2204            0 :       live_range_t lr = OBJECT_LIVE_RANGES (from_obj);
    2205              : 
    2206            0 :       if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL)
    2207              :         {
    2208            0 :           fprintf (ira_dump_file, "      Copying ranges of a%dr%d to a%dr%d: ",
    2209              :                    ALLOCNO_NUM (from), ALLOCNO_REGNO (from),
    2210              :                    ALLOCNO_NUM (to), ALLOCNO_REGNO (to));
    2211            0 :           ira_print_live_range_list (ira_dump_file, lr);
    2212              :         }
    2213            0 :       lr = ira_copy_live_range_list (lr);
    2214            0 :       change_object_in_range_list (lr, to_obj);
    2215            0 :       OBJECT_LIVE_RANGES (to_obj)
    2216            0 :         = ira_merge_live_ranges (lr, OBJECT_LIVE_RANGES (to_obj));
    2217              :     }
    2218            0 : }
    2219              : 
    2220              : /* Return TRUE if NODE represents a loop with low register
    2221              :    pressure.  */
    2222              : static bool
    2223      1047983 : low_pressure_loop_node_p (ira_loop_tree_node_t node)
    2224              : {
    2225      1047983 :   int i;
    2226      1047983 :   enum reg_class pclass;
    2227              : 
    2228      1047983 :   if (node->bb != NULL)
    2229              :     return false;
    2230              : 
    2231      4578141 :   for (i = 0; i < ira_pressure_classes_num; i++)
    2232              :     {
    2233      3701401 :       pclass = ira_pressure_classes[i];
    2234      3701401 :       if (node->reg_pressure[pclass] > ira_class_hard_regs_num[pclass]
    2235       171243 :           && ira_class_hard_regs_num[pclass] > 1)
    2236              :         return false;
    2237              :     }
    2238              :   return true;
    2239              : }
    2240              : 
    2241              : #ifdef STACK_REGS
    2242              : /* Return TRUE if LOOP has a complex enter or exit edge.  We don't
    2243              :    form a region from such loop if the target use stack register
    2244              :    because reg-stack.cc cannot deal with such edges.  */
    2245              : static bool
    2246       171243 : loop_with_complex_edge_p (class loop *loop)
    2247              : {
    2248       171243 :   int i;
    2249       171243 :   edge_iterator ei;
    2250       171243 :   edge e;
    2251       171243 :   bool res;
    2252              : 
    2253       549308 :   FOR_EACH_EDGE (e, ei, loop->header->preds)
    2254       378065 :     if (e->flags & EDGE_EH)
    2255              :       return true;
    2256       171243 :   auto_vec<edge> edges = get_loop_exit_edges (loop);
    2257       171243 :   res = false;
    2258       678463 :   FOR_EACH_VEC_ELT (edges, i, e)
    2259       337309 :     if (e->flags & EDGE_COMPLEX)
    2260              :       {
    2261              :         res = true;
    2262              :         break;
    2263              :       }
    2264       171243 :   return res;
    2265       171243 : }
    2266              : #endif
    2267              : 
    2268              : /* Sort loops for marking them for removal.  We put already marked
    2269              :    loops first, then less frequent loops next, and then outer loops
    2270              :    next.  */
    2271              : static int
    2272      7890051 : loop_compare_func (const void *v1p, const void *v2p)
    2273              : {
    2274      7890051 :   int diff;
    2275      7890051 :   ira_loop_tree_node_t l1 = *(const ira_loop_tree_node_t *) v1p;
    2276      7890051 :   ira_loop_tree_node_t l2 = *(const ira_loop_tree_node_t *) v2p;
    2277              : 
    2278      7890051 :   ira_assert (l1->parent != NULL && l2->parent != NULL);
    2279      7890051 :   if (l1->to_remove_p && ! l2->to_remove_p)
    2280              :     return -1;
    2281      7814683 :   if (! l1->to_remove_p && l2->to_remove_p)
    2282              :     return 1;
    2283     15494878 :   if ((diff = l1->loop->header->count.to_frequency (cfun)
    2284      7747439 :               - l2->loop->header->count.to_frequency (cfun)) != 0)
    2285              :     return diff;
    2286      9464952 :   if ((diff = (int) loop_depth (l1->loop) - (int) loop_depth (l2->loop)) != 0)
    2287              :     return diff;
    2288              :   /* Make sorting stable.  */
    2289      2873631 :   return l1->loop_num - l2->loop_num;
    2290              : }
    2291              : 
    2292              : /* Mark loops which should be removed from regional allocation.  We
    2293              :    remove a loop with low register pressure inside another loop with
    2294              :    register pressure.  In this case a separate allocation of the loop
    2295              :    hardly helps (for irregular register file architecture it could
    2296              :    help by choosing a better hard register in the loop but we prefer
    2297              :    faster allocation even in this case).  We also remove cheap loops
    2298              :    if there are more than param_ira_max_loops_num of them.  Loop with EH
    2299              :    exit or enter edges are removed too because the allocation might
    2300              :    require put pseudo moves on the EH edges (we could still do this
    2301              :    for pseudos with caller saved hard registers in some cases but it
    2302              :    is impossible to say here or during top-down allocation pass what
    2303              :    hard register the pseudos get finally).  */
    2304              : static void
    2305      1010795 : mark_loops_for_removal (void)
    2306              : {
    2307      1010795 :   int i, n;
    2308      1010795 :   ira_loop_tree_node_t *sorted_loops;
    2309      1010795 :   loop_p loop;
    2310              : 
    2311      1010795 :   ira_assert (current_loops != NULL);
    2312      1010795 :   sorted_loops
    2313      1010795 :     = (ira_loop_tree_node_t *) ira_allocate (sizeof (ira_loop_tree_node_t)
    2314      1010795 :                                              * number_of_loops (cfun));
    2315      4668022 :   for (n = i = 0; vec_safe_iterate (get_loops (cfun), i, &loop); i++)
    2316      1635637 :     if (ira_loop_nodes[i].regno_allocno_map != NULL)
    2317              :       {
    2318      1620408 :         if (ira_loop_nodes[i].parent == NULL)
    2319              :           {
    2320              :             /* Don't remove the root.  */
    2321      1010795 :             ira_loop_nodes[i].to_remove_p = false;
    2322      1010795 :             continue;
    2323              :           }
    2324       609613 :         sorted_loops[n++] = &ira_loop_nodes[i];
    2325      1219226 :         ira_loop_nodes[i].to_remove_p
    2326       609613 :           = ((low_pressure_loop_node_p (ira_loop_nodes[i].parent)
    2327       438370 :               && low_pressure_loop_node_p (&ira_loop_nodes[i]))
    2328              : #ifdef STACK_REGS
    2329       609613 :              || loop_with_complex_edge_p (ira_loop_nodes[i].loop)
    2330              : #endif
    2331              :              );
    2332              :       }
    2333      1010795 :   qsort (sorted_loops, n, sizeof (ira_loop_tree_node_t), loop_compare_func);
    2334      2047947 :   for (i = 0; i < n - param_ira_max_loops_num; i++)
    2335              :     {
    2336        26357 :       sorted_loops[i]->to_remove_p = true;
    2337        26357 :       if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
    2338            0 :         fprintf
    2339            0 :           (ira_dump_file,
    2340              :            "  Mark loop %d (header %d, freq %d, depth %d) for removal (%s)\n",
    2341            0 :            sorted_loops[i]->loop_num, sorted_loops[i]->loop->header->index,
    2342            0 :            sorted_loops[i]->loop->header->count.to_frequency (cfun),
    2343            0 :            loop_depth (sorted_loops[i]->loop),
    2344            0 :            low_pressure_loop_node_p (sorted_loops[i]->parent)
    2345            0 :            && low_pressure_loop_node_p (sorted_loops[i])
    2346              :            ? "low pressure" : "cheap loop");
    2347              :     }
    2348      1010795 :   ira_free (sorted_loops);
    2349      1010795 : }
    2350              : 
    2351              : /* Mark all loops but root for removing.  */
    2352              : static void
    2353            0 : mark_all_loops_for_removal (void)
    2354              : {
    2355            0 :   int i;
    2356            0 :   loop_p loop;
    2357              : 
    2358            0 :   ira_assert (current_loops != NULL);
    2359            0 :   FOR_EACH_VEC_SAFE_ELT (get_loops (cfun), i, loop)
    2360            0 :     if (ira_loop_nodes[i].regno_allocno_map != NULL)
    2361              :       {
    2362            0 :         if (ira_loop_nodes[i].parent == NULL)
    2363              :           {
    2364              :             /* Don't remove the root.  */
    2365            0 :             ira_loop_nodes[i].to_remove_p = false;
    2366            0 :             continue;
    2367              :           }
    2368            0 :         ira_loop_nodes[i].to_remove_p = true;
    2369            0 :         if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
    2370            0 :           fprintf
    2371            0 :             (ira_dump_file,
    2372              :              "  Mark loop %d (header %d, freq %d, depth %d) for removal\n",
    2373              :              ira_loop_nodes[i].loop_num,
    2374            0 :              ira_loop_nodes[i].loop->header->index,
    2375            0 :              ira_loop_nodes[i].loop->header->count.to_frequency (cfun),
    2376            0 :              loop_depth (ira_loop_nodes[i].loop));
    2377              :       }
    2378            0 : }
    2379              : 
    2380              : /* Definition of vector of loop tree nodes.  */
    2381              : 
    2382              : /* Vec containing references to all removed loop tree nodes.  */
    2383              : static vec<ira_loop_tree_node_t> removed_loop_vec;
    2384              : 
    2385              : /* Vec containing references to all children of loop tree nodes.  */
    2386              : static vec<ira_loop_tree_node_t> children_vec;
    2387              : 
    2388              : /* Remove subregions of NODE if their separate allocation will not
    2389              :    improve the result.  */
    2390              : static void
    2391      1620408 : remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_node_t node)
    2392              : {
    2393      1620408 :   unsigned int start;
    2394      1620408 :   bool remove_p;
    2395      1620408 :   ira_loop_tree_node_t subnode;
    2396              : 
    2397      1620408 :   remove_p = node->to_remove_p;
    2398      1620408 :   if (! remove_p)
    2399      1176714 :     children_vec.safe_push (node);
    2400      1620408 :   start = children_vec.length ();
    2401     13049705 :   for (subnode = node->children; subnode != NULL; subnode = subnode->next)
    2402     11429297 :     if (subnode->bb == NULL)
    2403       609613 :       remove_uneccesary_loop_nodes_from_loop_tree (subnode);
    2404              :     else
    2405     10819684 :       children_vec.safe_push (subnode);
    2406      1620408 :   node->children = node->subloops = NULL;
    2407      1620408 :   if (remove_p)
    2408              :     {
    2409       443694 :       removed_loop_vec.safe_push (node);
    2410       443694 :       return;
    2411              :     }
    2412     12162317 :   while (children_vec.length () > start)
    2413              :     {
    2414     10985603 :       subnode = children_vec.pop ();
    2415     10985603 :       subnode->parent = node;
    2416     10985603 :       subnode->next = node->children;
    2417     10985603 :       node->children = subnode;
    2418     10985603 :       if (subnode->bb == NULL)
    2419              :         {
    2420       165919 :           subnode->subloop_next = node->subloops;
    2421       165919 :           node->subloops = subnode;
    2422              :         }
    2423              :     }
    2424              : }
    2425              : 
    2426              : /* Return TRUE if NODE is inside PARENT.  */
    2427              : static bool
    2428        87782 : loop_is_inside_p (ira_loop_tree_node_t node, ira_loop_tree_node_t parent)
    2429              : {
    2430       124221 :   for (node = node->parent; node != NULL; node = node->parent)
    2431        79806 :     if (node == parent)
    2432              :       return true;
    2433              :   return false;
    2434              : }
    2435              : 
    2436              : /* Sort allocnos according to their order in regno allocno list.  */
    2437              : static int
    2438        54385 : regno_allocno_order_compare_func (const void *v1p, const void *v2p)
    2439              : {
    2440        54385 :   ira_allocno_t a1 = *(const ira_allocno_t *) v1p;
    2441        54385 :   ira_allocno_t a2 = *(const ira_allocno_t *) v2p;
    2442        54385 :   ira_loop_tree_node_t n1 = ALLOCNO_LOOP_TREE_NODE (a1);
    2443        54385 :   ira_loop_tree_node_t n2 = ALLOCNO_LOOP_TREE_NODE (a2);
    2444              : 
    2445       108770 :   if (loop_is_inside_p (n1, n2))
    2446              :     return -1;
    2447        66794 :   else if (loop_is_inside_p (n2, n1))
    2448              :     return 1;
    2449              :   /* If allocnos are equally good, sort by allocno numbers, so that
    2450              :      the results of qsort leave nothing to chance.  We put allocnos
    2451              :      with higher number first in the list because it is the original
    2452              :      order for allocnos from loops on the same levels.  */
    2453        11018 :   return ALLOCNO_NUM (a2) - ALLOCNO_NUM (a1);
    2454              : }
    2455              : 
    2456              : /* This array is used to sort allocnos to restore allocno order in
    2457              :    the regno allocno list.  */
    2458              : static ira_allocno_t *regno_allocnos;
    2459              : 
    2460              : /* Restore allocno order for REGNO in the regno allocno list.  */
    2461              : static void
    2462      1603698 : ira_rebuild_regno_allocno_list (int regno)
    2463              : {
    2464      1603698 :   int i, n;
    2465      1603698 :   ira_allocno_t a;
    2466              : 
    2467      1603698 :   for (n = 0, a = ira_regno_allocno_map[regno];
    2468      3217925 :        a != NULL;
    2469      1614227 :        a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    2470      1614227 :     regno_allocnos[n++] = a;
    2471      1603698 :   ira_assert (n > 0);
    2472      1603698 :   qsort (regno_allocnos, n, sizeof (ira_allocno_t),
    2473              :          regno_allocno_order_compare_func);
    2474      3217925 :   for (i = 1; i < n; i++)
    2475        10529 :     ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos[i - 1]) = regno_allocnos[i];
    2476      1603698 :   ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos[n - 1]) = NULL;
    2477      1603698 :   ira_regno_allocno_map[regno] = regno_allocnos[0];
    2478      1603698 :   if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
    2479           67 :     fprintf (ira_dump_file, " Rebuilding regno allocno list for %d\n", regno);
    2480      1603698 : }
    2481              : 
    2482              : /* Propagate info from allocno FROM_A to allocno A.  */
    2483              : static void
    2484      2409833 : propagate_some_info_from_allocno (ira_allocno_t a, ira_allocno_t from_a)
    2485              : {
    2486      2409833 :   enum reg_class aclass;
    2487              : 
    2488      2409833 :   merge_hard_reg_conflicts (from_a, a, false);
    2489      2409833 :   ALLOCNO_NREFS (a) += ALLOCNO_NREFS (from_a);
    2490      2409833 :   ALLOCNO_FREQ (a) += ALLOCNO_FREQ (from_a);
    2491      2409833 :   ALLOCNO_CALL_FREQ (a) += ALLOCNO_CALL_FREQ (from_a);
    2492      2409833 :   ALLOCNO_CALLS_CROSSED_NUM (a) += ALLOCNO_CALLS_CROSSED_NUM (from_a);
    2493      2409833 :   ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a)
    2494      2409833 :     += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (from_a);
    2495      2409833 :   ALLOCNO_CROSSED_CALLS_ABIS (a) |= ALLOCNO_CROSSED_CALLS_ABIS (from_a);
    2496      2409833 :   ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a)
    2497      2409833 :     |= ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (from_a);
    2498      2409833 :   ALLOCNO_SET_REGISTER_FILTERS (a,
    2499              :                                 ALLOCNO_REGISTER_FILTERS (from_a)
    2500              :                                 | ALLOCNO_REGISTER_FILTERS (a));
    2501      2409833 :   copy_dependent_filters (a, from_a);
    2502              : 
    2503      2409833 :   ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a)
    2504      2409833 :     += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (from_a);
    2505      2409833 :   if (! ALLOCNO_BAD_SPILL_P (from_a))
    2506      1477811 :     ALLOCNO_BAD_SPILL_P (a) = false;
    2507      2409833 :   aclass = ALLOCNO_CLASS (from_a);
    2508      2409833 :   ira_assert (aclass == ALLOCNO_CLASS (a));
    2509      2409833 :   ira_allocate_and_accumulate_costs (&ALLOCNO_HARD_REG_COSTS (a), aclass,
    2510              :                                      ALLOCNO_HARD_REG_COSTS (from_a));
    2511      2409833 :   ira_allocate_and_accumulate_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a),
    2512              :                                      aclass,
    2513              :                                      ALLOCNO_CONFLICT_HARD_REG_COSTS (from_a));
    2514      2409833 :   ALLOCNO_CLASS_COST (a) += ALLOCNO_CLASS_COST (from_a);
    2515      2409833 :   ALLOCNO_MEMORY_COST (a) += ALLOCNO_MEMORY_COST (from_a);
    2516      2409833 : }
    2517              : 
    2518              : /* Remove allocnos from loops removed from the allocation
    2519              :    consideration.  */
    2520              : static void
    2521      1010795 : remove_unnecessary_allocnos (void)
    2522              : {
    2523      1010795 :   int regno;
    2524      1010795 :   bool merged_p, rebuild_p;
    2525      1010795 :   ira_allocno_t a, prev_a, next_a, parent_a;
    2526      1010795 :   ira_loop_tree_node_t a_node, parent;
    2527              : 
    2528      1010795 :   merged_p = false;
    2529      1010795 :   regno_allocnos = NULL;
    2530     50943022 :   for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--)
    2531              :     {
    2532     49932227 :       rebuild_p = false;
    2533     49932227 :       for (prev_a = NULL, a = ira_regno_allocno_map[regno];
    2534     73464627 :            a != NULL;
    2535              :            a = next_a)
    2536              :         {
    2537     23532400 :           next_a = ALLOCNO_NEXT_REGNO_ALLOCNO (a);
    2538     23532400 :           a_node = ALLOCNO_LOOP_TREE_NODE (a);
    2539     23532400 :           if (! a_node->to_remove_p)
    2540              :             prev_a = a;
    2541              :           else
    2542              :             {
    2543      4013531 :               for (parent = a_node->parent;
    2544      4296590 :                    (parent_a = parent->regno_allocno_map[regno]) == NULL
    2545      4296590 :                      && parent->to_remove_p;
    2546       283059 :                    parent = parent->parent)
    2547              :                 ;
    2548      4013531 :               if (parent_a == NULL)
    2549              :                 {
    2550              :                   /* There are no allocnos with the same regno in
    2551              :                      upper region -- just move the allocno to the
    2552              :                      upper region.  */
    2553      1603698 :                   prev_a = a;
    2554      1603698 :                   ALLOCNO_LOOP_TREE_NODE (a) = parent;
    2555      1603698 :                   parent->regno_allocno_map[regno] = a;
    2556      1603698 :                   bitmap_set_bit (parent->all_allocnos, ALLOCNO_NUM (a));
    2557      1603698 :                   rebuild_p = true;
    2558              :                 }
    2559              :               else
    2560              :                 {
    2561              :                   /* Remove the allocno and update info of allocno in
    2562              :                      the upper region.  */
    2563      2409833 :                   if (prev_a == NULL)
    2564      2268009 :                     ira_regno_allocno_map[regno] = next_a;
    2565              :                   else
    2566       141824 :                     ALLOCNO_NEXT_REGNO_ALLOCNO (prev_a) = next_a;
    2567      2409833 :                   move_allocno_live_ranges (a, parent_a);
    2568      2409833 :                   merged_p = true;
    2569      2409833 :                   propagate_some_info_from_allocno (parent_a, a);
    2570              :                   /* Remove it from the corresponding regno allocno
    2571              :                      map to avoid info propagation of subsequent
    2572              :                      allocno into this already removed allocno.  */
    2573      2409833 :                   a_node->regno_allocno_map[regno] = NULL;
    2574      2409833 :                   ira_remove_allocno_prefs (a);
    2575      2409833 :                   finish_allocno (a);
    2576              :                 }
    2577              :             }
    2578              :         }
    2579     49932227 :       if (rebuild_p)
    2580              :         /* We need to restore the order in regno allocno list.  */
    2581              :         {
    2582      1603698 :           if (regno_allocnos == NULL)
    2583       132206 :             regno_allocnos
    2584       132206 :               = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t)
    2585       132206 :                                                 * ira_allocnos_num);
    2586      1603698 :           ira_rebuild_regno_allocno_list (regno);
    2587              :         }
    2588              :     }
    2589      1010795 :   if (merged_p)
    2590       160564 :     ira_rebuild_start_finish_chains ();
    2591      1010795 :   if (regno_allocnos != NULL)
    2592       132206 :     ira_free (regno_allocnos);
    2593      1010795 : }
    2594              : 
    2595              : /* Remove allocnos from all loops but the root.  */
    2596              : static void
    2597            0 : remove_low_level_allocnos (void)
    2598              : {
    2599            0 :   int regno;
    2600            0 :   bool merged_p, propagate_p;
    2601            0 :   ira_allocno_t a, top_a;
    2602            0 :   ira_loop_tree_node_t a_node, parent;
    2603            0 :   ira_allocno_iterator ai;
    2604              : 
    2605            0 :   merged_p = false;
    2606            0 :   FOR_EACH_ALLOCNO (a, ai)
    2607              :     {
    2608            0 :       a_node = ALLOCNO_LOOP_TREE_NODE (a);
    2609            0 :       if (a_node == ira_loop_tree_root || ALLOCNO_CAP_MEMBER (a) != NULL)
    2610            0 :         continue;
    2611            0 :       regno = ALLOCNO_REGNO (a);
    2612            0 :       if ((top_a = ira_loop_tree_root->regno_allocno_map[regno]) == NULL)
    2613              :         {
    2614            0 :           ALLOCNO_LOOP_TREE_NODE (a) = ira_loop_tree_root;
    2615            0 :           ira_loop_tree_root->regno_allocno_map[regno] = a;
    2616            0 :           continue;
    2617              :         }
    2618            0 :       propagate_p = a_node->parent->regno_allocno_map[regno] == NULL;
    2619              :       /* Remove the allocno and update info of allocno in the upper
    2620              :          region.  */
    2621            0 :       move_allocno_live_ranges (a, top_a);
    2622            0 :       merged_p = true;
    2623            0 :       if (propagate_p)
    2624            0 :         propagate_some_info_from_allocno (top_a, a);
    2625              :     }
    2626            0 :   FOR_EACH_ALLOCNO (a, ai)
    2627              :     {
    2628            0 :       a_node = ALLOCNO_LOOP_TREE_NODE (a);
    2629            0 :       if (a_node == ira_loop_tree_root)
    2630            0 :         continue;
    2631            0 :       parent = a_node->parent;
    2632            0 :       regno = ALLOCNO_REGNO (a);
    2633            0 :       if (ALLOCNO_CAP_MEMBER (a) != NULL)
    2634            0 :         ira_assert (ALLOCNO_CAP (a) != NULL);
    2635            0 :       else if (ALLOCNO_CAP (a) == NULL)
    2636            0 :         ira_assert (parent->regno_allocno_map[regno] != NULL);
    2637              :     }
    2638            0 :   FOR_EACH_ALLOCNO (a, ai)
    2639              :     {
    2640            0 :       regno = ALLOCNO_REGNO (a);
    2641            0 :       if (ira_loop_tree_root->regno_allocno_map[regno] == a)
    2642              :         {
    2643            0 :           ira_object_t obj;
    2644            0 :           ira_allocno_object_iterator oi;
    2645              : 
    2646            0 :           ira_regno_allocno_map[regno] = a;
    2647            0 :           ALLOCNO_NEXT_REGNO_ALLOCNO (a) = NULL;
    2648            0 :           ALLOCNO_CAP_MEMBER (a) = NULL;
    2649            0 :           FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
    2650            0 :             OBJECT_CONFLICT_HARD_REGS (obj)
    2651            0 :               = OBJECT_TOTAL_CONFLICT_HARD_REGS (obj);
    2652              : #ifdef STACK_REGS
    2653            0 :           if (ALLOCNO_TOTAL_NO_STACK_REG_P (a))
    2654            0 :             ALLOCNO_NO_STACK_REG_P (a) = true;
    2655              : #endif
    2656              :         }
    2657              :       else
    2658              :         {
    2659            0 :           ira_remove_allocno_prefs (a);
    2660            0 :           finish_allocno (a);
    2661              :         }
    2662              :     }
    2663            0 :   if (merged_p)
    2664            0 :     ira_rebuild_start_finish_chains ();
    2665            0 : }
    2666              : 
    2667              : /* Remove loops from consideration.  We remove all loops except for
    2668              :    root if ALL_P or loops for which a separate allocation will not
    2669              :    improve the result.  We have to do this after allocno creation and
    2670              :    their costs and allocno class evaluation because only after that
    2671              :    the register pressure can be known and is calculated.  */
    2672              : static void
    2673      1504950 : remove_unnecessary_regions (bool all_p)
    2674              : {
    2675      1504950 :   if (current_loops == NULL)
    2676              :     return;
    2677      1010795 :   if (all_p)
    2678            0 :     mark_all_loops_for_removal ();
    2679              :   else
    2680      1010795 :     mark_loops_for_removal ();
    2681      2021590 :   children_vec.create (last_basic_block_for_fn (cfun)
    2682      2021590 :                        + number_of_loops (cfun));
    2683      2021590 :   removed_loop_vec.create (last_basic_block_for_fn (cfun)
    2684      2021590 :                            + number_of_loops (cfun));
    2685      1010795 :   remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_root);
    2686      1010795 :   children_vec.release ();
    2687      1010795 :   if (all_p)
    2688            0 :     remove_low_level_allocnos ();
    2689              :   else
    2690      1010795 :     remove_unnecessary_allocnos ();
    2691      1454489 :   while (removed_loop_vec.length () > 0)
    2692       443694 :     finish_loop_tree_node (removed_loop_vec.pop ());
    2693      1010795 :   removed_loop_vec.release ();
    2694              : }
    2695              : 
    2696              : 
    2697              : 
    2698              : /* At this point true value of allocno attribute bad_spill_p means
    2699              :    that there is an insn where allocno occurs and where the allocno
    2700              :    cannot be used as memory.  The function updates the attribute, now
    2701              :    it can be true only for allocnos which cannot be used as memory in
    2702              :    an insn and in whose live ranges there is other allocno deaths.
    2703              :    Spilling allocnos with true value will not improve the code because
    2704              :    it will not make other allocnos colorable and additional reloads
    2705              :    for the corresponding pseudo will be generated in reload pass for
    2706              :    each insn it occurs.
    2707              : 
    2708              :    This is a trick mentioned in one classic article of Chaitin etc
    2709              :    which is frequently omitted in other implementations of RA based on
    2710              :    graph coloring.  */
    2711              : static void
    2712      1504950 : update_bad_spill_attribute (void)
    2713              : {
    2714      1504950 :   int i;
    2715      1504950 :   ira_allocno_t a;
    2716      1504950 :   ira_allocno_iterator ai;
    2717      1504950 :   ira_allocno_object_iterator aoi;
    2718      1504950 :   ira_object_t obj;
    2719      1504950 :   live_range_t r;
    2720      1504950 :   enum reg_class aclass;
    2721     51168300 :   bitmap_head dead_points[N_REG_CLASSES];
    2722              : 
    2723     39108419 :   for (i = 0; i < ira_allocno_classes_num; i++)
    2724              :     {
    2725     37603469 :       aclass = ira_allocno_classes[i];
    2726     37603469 :       bitmap_initialize (&dead_points[aclass], &reg_obstack);
    2727              :     }
    2728     36300698 :   FOR_EACH_ALLOCNO (a, ai)
    2729              :     {
    2730     33290798 :       aclass = ALLOCNO_CLASS (a);
    2731     33290798 :       if (aclass == NO_REGS)
    2732       571827 :         continue;
    2733    101511787 :       FOR_EACH_ALLOCNO_OBJECT (a, obj, aoi)
    2734     74489816 :         for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
    2735     40492748 :           bitmap_set_bit (&dead_points[aclass], r->finish);
    2736              :     }
    2737     36300698 :   FOR_EACH_ALLOCNO (a, ai)
    2738              :     {
    2739     33290798 :       aclass = ALLOCNO_CLASS (a);
    2740     33290798 :       if (aclass == NO_REGS)
    2741       571827 :         continue;
    2742     32718971 :       if (! ALLOCNO_BAD_SPILL_P (a))
    2743     18250423 :         continue;
    2744     59571169 :       FOR_EACH_ALLOCNO_OBJECT (a, obj, aoi)
    2745              :         {
    2746     25697740 :           for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
    2747              :             {
    2748     23989769 :               for (i = r->start + 1; i < r->finish; i++)
    2749     12864513 :                 if (bitmap_bit_p (&dead_points[aclass], i))
    2750              :                   break;
    2751     15390867 :               if (i < r->finish)
    2752              :                 break;
    2753              :             }
    2754     14572484 :           if (r != NULL)
    2755              :             {
    2756      4265611 :               ALLOCNO_BAD_SPILL_P (a) = false;
    2757      4265611 :               break;
    2758              :             }
    2759              :         }
    2760              :     }
    2761     39108419 :   for (i = 0; i < ira_allocno_classes_num; i++)
    2762              :     {
    2763     37603469 :       aclass = ira_allocno_classes[i];
    2764     37603469 :       bitmap_clear (&dead_points[aclass]);
    2765              :     }
    2766      1504950 : }
    2767              : 
    2768              : 
    2769              : 
    2770              : /* Set up minimal and maximal live range points for allocnos.  */
    2771              : static void
    2772      1504950 : setup_min_max_allocno_live_range_point (void)
    2773              : {
    2774      1504950 :   int i;
    2775      1504950 :   ira_allocno_t a, parent_a, cap;
    2776      1504950 :   ira_allocno_iterator ai;
    2777              : #ifdef ENABLE_IRA_CHECKING
    2778      1504950 :   ira_object_iterator oi;
    2779      1504950 :   ira_object_t obj;
    2780              : #endif
    2781      1504950 :   live_range_t r;
    2782      1504950 :   ira_loop_tree_node_t parent;
    2783              : 
    2784     38438235 :   FOR_EACH_ALLOCNO (a, ai)
    2785              :     {
    2786     36933285 :       int n = ALLOCNO_NUM_OBJECTS (a);
    2787              : 
    2788     75187808 :       for (i = 0; i < n; i++)
    2789              :         {
    2790     38254523 :           ira_object_t obj = ALLOCNO_OBJECT (a, i);
    2791     38254523 :           r = OBJECT_LIVE_RANGES (obj);
    2792     38254523 :           if (r == NULL)
    2793      3692246 :             continue;
    2794     34562277 :           OBJECT_MAX (obj) = r->finish;
    2795     41234654 :           for (; r->next != NULL; r = r->next)
    2796              :             ;
    2797     34562277 :           OBJECT_MIN (obj) = r->start;
    2798              :         }
    2799              :     }
    2800     68416107 :   for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2801     66911157 :     for (a = ira_regno_allocno_map[i];
    2802    100201955 :          a != NULL;
    2803     33290798 :          a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    2804              :       {
    2805     33290798 :         int j;
    2806     33290798 :         int n = ALLOCNO_NUM_OBJECTS (a);
    2807              : 
    2808     67859693 :         for (j = 0; j < n; j++)
    2809              :           {
    2810     34568895 :             ira_object_t obj = ALLOCNO_OBJECT (a, j);
    2811     34568895 :             ira_object_t parent_obj;
    2812              : 
    2813     34568895 :             if (OBJECT_MAX (obj) < 0)
    2814              :               {
    2815              :                 /* The object is not used and hence does not live.  */
    2816            0 :                 ira_assert (OBJECT_LIVE_RANGES (obj) == NULL);
    2817            0 :                 OBJECT_MAX (obj) = 0;
    2818            0 :                 OBJECT_MIN (obj) = 1;
    2819            0 :                 continue;
    2820              :               }
    2821     34568895 :             ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL);
    2822              :             /* Accumulation of range info.  */
    2823     34568895 :             if (ALLOCNO_CAP (a) != NULL)
    2824              :               {
    2825      5622451 :                 for (cap = ALLOCNO_CAP (a); cap != NULL; cap = ALLOCNO_CAP (cap))
    2826              :                   {
    2827      3685628 :                     ira_object_t cap_obj = ALLOCNO_OBJECT (cap, j);
    2828      3685628 :                     if (OBJECT_MAX (cap_obj) < OBJECT_MAX (obj))
    2829      3685628 :                       OBJECT_MAX (cap_obj) = OBJECT_MAX (obj);
    2830      3685628 :                     if (OBJECT_MIN (cap_obj) > OBJECT_MIN (obj))
    2831      3685628 :                       OBJECT_MIN (cap_obj) = OBJECT_MIN (obj);
    2832              :                   }
    2833      1936823 :                 continue;
    2834      1936823 :               }
    2835     32632072 :             if ((parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) == NULL)
    2836     29448388 :               continue;
    2837      3183684 :             parent_a = parent->regno_allocno_map[i];
    2838      3183684 :             parent_obj = ALLOCNO_OBJECT (parent_a, j);
    2839      3183684 :             if (OBJECT_MAX (parent_obj) < OBJECT_MAX (obj))
    2840      1919602 :               OBJECT_MAX (parent_obj) = OBJECT_MAX (obj);
    2841      3183684 :             if (OBJECT_MIN (parent_obj) > OBJECT_MIN (obj))
    2842         6911 :               OBJECT_MIN (parent_obj) = OBJECT_MIN (obj);
    2843              :           }
    2844              :       }
    2845              : #ifdef ENABLE_IRA_CHECKING
    2846     39759473 :   FOR_EACH_OBJECT (obj, oi)
    2847              :     {
    2848     38254523 :       if ((OBJECT_MIN (obj) >= 0 && OBJECT_MIN (obj) <= ira_max_point)
    2849     38254523 :           && (OBJECT_MAX (obj) >= 0 && OBJECT_MAX (obj) <= ira_max_point))
    2850     38254523 :         continue;
    2851            0 :       gcc_unreachable ();
    2852              :     }
    2853              : #endif
    2854      1504950 : }
    2855              : 
    2856              : /* Sort allocnos according to their live ranges.  Allocnos with
    2857              :    smaller allocno class are put first unless we use priority
    2858              :    coloring.  Allocnos with the same class are ordered according
    2859              :    their start (min).  Allocnos with the same start are ordered
    2860              :    according their finish (max).  */
    2861              : static int
    2862   1329979418 : object_range_compare_func (const void *v1p, const void *v2p)
    2863              : {
    2864   1329979418 :   int diff;
    2865   1329979418 :   ira_object_t obj1 = *(const ira_object_t *) v1p;
    2866   1329979418 :   ira_object_t obj2 = *(const ira_object_t *) v2p;
    2867   1329979418 :   ira_allocno_t a1 = OBJECT_ALLOCNO (obj1);
    2868   1329979418 :   ira_allocno_t a2 = OBJECT_ALLOCNO (obj2);
    2869              : 
    2870   1329979418 :   if ((diff = OBJECT_MIN (obj1) - OBJECT_MIN (obj2)) != 0)
    2871              :     return diff;
    2872    206273408 :   if ((diff = OBJECT_MAX (obj1) - OBJECT_MAX (obj2)) != 0)
    2873              :      return diff;
    2874    164120473 :   return ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2);
    2875              : }
    2876              : 
    2877              : /* Sort ira_object_id_map and set up conflict id of allocnos.  */
    2878              : static void
    2879      1504950 : sort_conflict_id_map (void)
    2880              : {
    2881      1504950 :   int i, num;
    2882      1504950 :   ira_allocno_t a;
    2883      1504950 :   ira_allocno_iterator ai;
    2884              : 
    2885      1504950 :   num = 0;
    2886     39943185 :   FOR_EACH_ALLOCNO (a, ai)
    2887              :     {
    2888              :       ira_allocno_object_iterator oi;
    2889              :       ira_object_t obj;
    2890              : 
    2891    113626043 :       FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
    2892     38254523 :         ira_object_id_map[num++] = obj;
    2893              :     }
    2894      1504950 :   if (num > 1)
    2895      1212036 :     qsort (ira_object_id_map, num, sizeof (ira_object_t),
    2896              :            object_range_compare_func);
    2897     39759473 :   for (i = 0; i < num; i++)
    2898              :     {
    2899     38254523 :       ira_object_t obj = ira_object_id_map[i];
    2900              : 
    2901     38254523 :       gcc_assert (obj != NULL);
    2902     38254523 :       OBJECT_CONFLICT_ID (obj) = i;
    2903              :     }
    2904      3921228 :   for (i = num; i < ira_objects_num; i++)
    2905      2416278 :     ira_object_id_map[i] = NULL;
    2906      1504950 : }
    2907              : 
    2908              : /* Set up minimal and maximal conflict ids of allocnos with which
    2909              :    given allocno can conflict.  */
    2910              : static void
    2911      1504950 : setup_min_max_conflict_allocno_ids (void)
    2912              : {
    2913      1504950 :   int aclass;
    2914      1504950 :   int i, j, min, max, start, finish, first_not_finished, filled_area_start;
    2915      1504950 :   int *live_range_min, *last_lived;
    2916      1504950 :   int word0_min, word0_max;
    2917      1504950 :   ira_allocno_t a;
    2918      1504950 :   ira_allocno_iterator ai;
    2919              : 
    2920      1504950 :   live_range_min = (int *) ira_allocate (sizeof (int) * ira_objects_num);
    2921      1504950 :   aclass = -1;
    2922      1504950 :   first_not_finished = -1;
    2923     42175751 :   for (i = 0; i < ira_objects_num; i++)
    2924              :     {
    2925     40670801 :       ira_object_t obj = ira_object_id_map[i];
    2926              : 
    2927     40670801 :       if (obj == NULL)
    2928      2416278 :         continue;
    2929              : 
    2930     38254523 :       a = OBJECT_ALLOCNO (obj);
    2931              : 
    2932     38254523 :       if (aclass < 0)
    2933              :         {
    2934      1297641 :           aclass = ALLOCNO_CLASS (a);
    2935      1297641 :           min = i;
    2936      1297641 :           first_not_finished = i;
    2937              :         }
    2938              :       else
    2939              :         {
    2940     36956882 :           start = OBJECT_MIN (obj);
    2941              :           /* If we skip an allocno, the allocno with smaller ids will
    2942              :              be also skipped because of the secondary sorting the
    2943              :              range finishes (see function
    2944              :              object_range_compare_func).  */
    2945     36956882 :           while (first_not_finished < i
    2946     51919335 :                  && start > OBJECT_MAX (ira_object_id_map
    2947              :                                         [first_not_finished]))
    2948     14962453 :             first_not_finished++;
    2949              :           min = first_not_finished;
    2950              :         }
    2951     38254523 :       if (min == i)
    2952              :         /* We could increase min further in this case but it is good
    2953              :            enough.  */
    2954      7508878 :         min++;
    2955     38254523 :       live_range_min[i] = OBJECT_MIN (obj);
    2956     38254523 :       OBJECT_MIN (obj) = min;
    2957              :     }
    2958      1504950 :   last_lived = (int *) ira_allocate (sizeof (int) * ira_max_point);
    2959      1504950 :   aclass = -1;
    2960      1504950 :   filled_area_start = -1;
    2961     42175751 :   for (i = ira_objects_num - 1; i >= 0; i--)
    2962              :     {
    2963     40670801 :       ira_object_t obj = ira_object_id_map[i];
    2964              : 
    2965     40670801 :       if (obj == NULL)
    2966      2416278 :         continue;
    2967              : 
    2968     38254523 :       a = OBJECT_ALLOCNO (obj);
    2969     38254523 :       if (aclass < 0)
    2970              :         {
    2971      1297641 :           aclass = ALLOCNO_CLASS (a);
    2972     49586906 :           for (j = 0; j < ira_max_point; j++)
    2973     48289265 :             last_lived[j] = -1;
    2974              :           filled_area_start = ira_max_point;
    2975              :         }
    2976     38254523 :       min = live_range_min[i];
    2977     38254523 :       finish = OBJECT_MAX (obj);
    2978     38254523 :       max = last_lived[finish];
    2979     38254523 :       if (max < 0)
    2980              :         /* We could decrease max further in this case but it is good
    2981              :            enough.  */
    2982     16147706 :         max = OBJECT_CONFLICT_ID (obj) - 1;
    2983     38254523 :       OBJECT_MAX (obj) = max;
    2984              :       /* In filling, we can go further A range finish to recognize
    2985              :          intersection quickly because if the finish of subsequently
    2986              :          processed allocno (it has smaller conflict id) range is
    2987              :          further A range finish than they are definitely intersected
    2988              :          (the reason for this is the allocnos with bigger conflict id
    2989              :          have their range starts not smaller than allocnos with
    2990              :          smaller ids.  */
    2991     86543788 :       for (j = min; j < filled_area_start; j++)
    2992     48289265 :         last_lived[j] = i;
    2993              :       filled_area_start = min;
    2994              :     }
    2995      1504950 :   ira_free (last_lived);
    2996      1504950 :   ira_free (live_range_min);
    2997              : 
    2998              :   /* For allocnos with more than one object, we may later record extra conflicts in
    2999              :      subobject 0 that we cannot really know about here.
    3000              :      For now, simply widen the min/max range of these subobjects.  */
    3001              : 
    3002      1504950 :   word0_min = INT_MAX;
    3003      1504950 :   word0_max = INT_MIN;
    3004              : 
    3005     38438235 :   FOR_EACH_ALLOCNO (a, ai)
    3006              :     {
    3007     36933285 :       int n = ALLOCNO_NUM_OBJECTS (a);
    3008     36933285 :       ira_object_t obj0;
    3009              : 
    3010     36933285 :       if (n < 2)
    3011     35612047 :         continue;
    3012      1321238 :       obj0 = ALLOCNO_OBJECT (a, 0);
    3013      1321238 :       if (OBJECT_CONFLICT_ID (obj0) < word0_min)
    3014              :         word0_min = OBJECT_CONFLICT_ID (obj0);
    3015      1321238 :       if (OBJECT_CONFLICT_ID (obj0) > word0_max)
    3016              :         word0_max = OBJECT_CONFLICT_ID (obj0);
    3017              :     }
    3018     38438235 :   FOR_EACH_ALLOCNO (a, ai)
    3019              :     {
    3020     36933285 :       int n = ALLOCNO_NUM_OBJECTS (a);
    3021     36933285 :       ira_object_t obj0;
    3022              : 
    3023     36933285 :       if (n < 2)
    3024     35612047 :         continue;
    3025      1321238 :       obj0 = ALLOCNO_OBJECT (a, 0);
    3026      1321238 :       if (OBJECT_MIN (obj0) > word0_min)
    3027       824477 :         OBJECT_MIN (obj0) = word0_min;
    3028      1321238 :       if (OBJECT_MAX (obj0) < word0_max)
    3029      1046024 :         OBJECT_MAX (obj0) = word0_max;
    3030              :     }
    3031      1504950 : }
    3032              : 
    3033              : 
    3034              : 
    3035              : static void
    3036        35511 : create_caps (void)
    3037              : {
    3038        35511 :   ira_allocno_t a;
    3039        35511 :   ira_allocno_iterator ai;
    3040        35511 :   ira_loop_tree_node_t loop_tree_node;
    3041              : 
    3042     11583845 :   FOR_EACH_ALLOCNO (a, ai)
    3043              :     {
    3044     11548334 :       if (ALLOCNO_LOOP_TREE_NODE (a) == ira_loop_tree_root)
    3045      4788435 :         continue;
    3046      6759899 :       if (ALLOCNO_CAP_MEMBER (a) != NULL)
    3047      1732685 :         create_cap_allocno (a);
    3048      5027214 :       else if (ALLOCNO_CAP (a) == NULL)
    3049              :         {
    3050      5027214 :           loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a);
    3051      5027214 :           if (!bitmap_bit_p (loop_tree_node->border_allocnos, ALLOCNO_NUM (a)))
    3052      1909802 :             create_cap_allocno (a);
    3053              :         }
    3054              :     }
    3055        35511 : }
    3056              : 
    3057              : 
    3058              : 
    3059              : /* The page contains code transforming more one region internal
    3060              :    representation (IR) to one region IR which is necessary for reload.
    3061              :    This transformation is called IR flattening.  We might just rebuild
    3062              :    the IR for one region but we don't do it because it takes a lot of
    3063              :    time.  */
    3064              : 
    3065              : /* Map: regno -> allocnos which will finally represent the regno for
    3066              :    IR with one region.  */
    3067              : static ira_allocno_t *regno_top_level_allocno_map;
    3068              : 
    3069              : /* Find the allocno that corresponds to A at a level one higher up in the
    3070              :    loop tree.  Returns NULL if A is a cap, or if it has no parent.  */
    3071              : ira_allocno_t
    3072    251817797 : ira_parent_allocno (ira_allocno_t a)
    3073              : {
    3074    251817797 :   ira_loop_tree_node_t parent;
    3075              : 
    3076    251817797 :   if (ALLOCNO_CAP (a) != NULL)
    3077              :     return NULL;
    3078              : 
    3079    251817797 :   parent = ALLOCNO_LOOP_TREE_NODE (a)->parent;
    3080    251817797 :   if (parent == NULL)
    3081              :     return NULL;
    3082              : 
    3083    232538879 :   return parent->regno_allocno_map[ALLOCNO_REGNO (a)];
    3084              : }
    3085              : 
    3086              : /* Find the allocno that corresponds to A at a level one higher up in the
    3087              :    loop tree.  If ALLOCNO_CAP is set for A, return that.  */
    3088              : ira_allocno_t
    3089    363045954 : ira_parent_or_cap_allocno (ira_allocno_t a)
    3090              : {
    3091    363045954 :   if (ALLOCNO_CAP (a) != NULL)
    3092              :     return ALLOCNO_CAP (a);
    3093              : 
    3094    197535348 :   return ira_parent_allocno (a);
    3095              : }
    3096              : 
    3097              : /* Process all allocnos originated from pseudo REGNO and copy live
    3098              :    ranges, hard reg conflicts, and allocno stack reg attributes from
    3099              :    low level allocnos to final allocnos which are destinations of
    3100              :    removed stores at a loop exit.  Return true if we copied live
    3101              :    ranges.  */
    3102              : static bool
    3103            0 : copy_info_to_removed_store_destinations (int regno)
    3104              : {
    3105            0 :   ira_allocno_t a;
    3106            0 :   ira_allocno_t parent_a = NULL;
    3107            0 :   ira_loop_tree_node_t parent;
    3108            0 :   bool merged_p;
    3109              : 
    3110            0 :   merged_p = false;
    3111            0 :   for (a = ira_regno_allocno_map[regno];
    3112            0 :        a != NULL;
    3113            0 :        a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    3114              :     {
    3115            0 :       if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))])
    3116              :         /* This allocno will be removed.  */
    3117            0 :         continue;
    3118              : 
    3119              :       /* Caps will be removed.  */
    3120            0 :       ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL);
    3121            0 :       for (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent;
    3122            0 :            parent != NULL;
    3123            0 :            parent = parent->parent)
    3124            0 :         if ((parent_a = parent->regno_allocno_map[regno]) == NULL
    3125            0 :             || (parent_a
    3126            0 :                 == regno_top_level_allocno_map[REGNO
    3127            0 :                                                (allocno_emit_reg (parent_a))]
    3128            0 :                 && ALLOCNO_EMIT_DATA (parent_a)->mem_optimized_dest_p))
    3129              :           break;
    3130            0 :       if (parent == NULL || parent_a == NULL)
    3131            0 :         continue;
    3132              : 
    3133            0 :       copy_allocno_live_ranges (a, parent_a);
    3134            0 :       merge_hard_reg_conflicts (a, parent_a, true);
    3135              : 
    3136            0 :       ALLOCNO_CALL_FREQ (parent_a) += ALLOCNO_CALL_FREQ (a);
    3137            0 :       ALLOCNO_CALLS_CROSSED_NUM (parent_a)
    3138            0 :         += ALLOCNO_CALLS_CROSSED_NUM (a);
    3139            0 :       ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a)
    3140            0 :         += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a);
    3141            0 :       ALLOCNO_CROSSED_CALLS_ABIS (parent_a)
    3142            0 :         |= ALLOCNO_CROSSED_CALLS_ABIS (a);
    3143            0 :       ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (parent_a)
    3144            0 :         |= ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a);
    3145            0 :       ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a)
    3146            0 :         += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a);
    3147            0 :       merged_p = true;
    3148              :     }
    3149            0 :   return merged_p;
    3150              : }
    3151              : 
    3152              : /* Flatten the IR.  In other words, this function transforms IR as if
    3153              :    it were built with one region (without loops).  We could make it
    3154              :    much simpler by rebuilding IR with one region, but unfortunately it
    3155              :    takes a lot of time.  MAX_REGNO_BEFORE_EMIT and
    3156              :    IRA_MAX_POINT_BEFORE_EMIT are correspondingly MAX_REG_NUM () and
    3157              :    IRA_MAX_POINT before emitting insns on the loop borders.  */
    3158              : void
    3159            0 : ira_flattening (int max_regno_before_emit, int ira_max_point_before_emit)
    3160              : {
    3161            0 :   int i, j;
    3162            0 :   bool keep_p;
    3163            0 :   int hard_regs_num;
    3164            0 :   bool new_pseudos_p, merged_p, mem_dest_p;
    3165            0 :   unsigned int n;
    3166            0 :   enum reg_class aclass;
    3167            0 :   ira_allocno_t a, parent_a, first, second, node_first, node_second;
    3168            0 :   ira_copy_t cp;
    3169            0 :   ira_loop_tree_node_t node;
    3170            0 :   live_range_t r;
    3171            0 :   ira_allocno_iterator ai;
    3172            0 :   ira_copy_iterator ci;
    3173              : 
    3174            0 :   regno_top_level_allocno_map
    3175            0 :     = (ira_allocno_t *) ira_allocate (max_reg_num ()
    3176              :                                       * sizeof (ira_allocno_t));
    3177            0 :   memset (regno_top_level_allocno_map, 0,
    3178            0 :           max_reg_num () * sizeof (ira_allocno_t));
    3179            0 :   new_pseudos_p = merged_p = false;
    3180            0 :   FOR_EACH_ALLOCNO (a, ai)
    3181              :     {
    3182            0 :       ira_allocno_object_iterator oi;
    3183            0 :       ira_object_t obj;
    3184              : 
    3185            0 :       if (ALLOCNO_CAP_MEMBER (a) != NULL)
    3186              :         /* Caps are not in the regno allocno maps and they are never
    3187              :            will be transformed into allocnos existing after IR
    3188              :            flattening.  */
    3189            0 :         continue;
    3190            0 :       FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
    3191            0 :         OBJECT_TOTAL_CONFLICT_HARD_REGS (obj)
    3192            0 :           = OBJECT_CONFLICT_HARD_REGS (obj);
    3193              : #ifdef STACK_REGS
    3194            0 :       ALLOCNO_TOTAL_NO_STACK_REG_P (a) = ALLOCNO_NO_STACK_REG_P (a);
    3195              : #endif
    3196              :     }
    3197              :   /* Fix final allocno attributes.  */
    3198            0 :   for (i = max_regno_before_emit - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    3199              :     {
    3200            0 :       mem_dest_p = false;
    3201            0 :       for (a = ira_regno_allocno_map[i];
    3202            0 :            a != NULL;
    3203            0 :            a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    3204              :         {
    3205            0 :           ira_emit_data_t parent_data, data = ALLOCNO_EMIT_DATA (a);
    3206              : 
    3207            0 :           ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL);
    3208            0 :           if (data->somewhere_renamed_p)
    3209            0 :             new_pseudos_p = true;
    3210            0 :           parent_a = ira_parent_allocno (a);
    3211            0 :           if (parent_a == NULL)
    3212              :             {
    3213            0 :               ALLOCNO_COPIES (a) = NULL;
    3214            0 :               regno_top_level_allocno_map[REGNO (data->reg)] = a;
    3215            0 :               continue;
    3216              :             }
    3217            0 :           ira_assert (ALLOCNO_CAP_MEMBER (parent_a) == NULL);
    3218              : 
    3219            0 :           if (data->mem_optimized_dest != NULL)
    3220            0 :             mem_dest_p = true;
    3221            0 :           parent_data = ALLOCNO_EMIT_DATA (parent_a);
    3222            0 :           if (REGNO (data->reg) == REGNO (parent_data->reg))
    3223              :             {
    3224            0 :               merge_hard_reg_conflicts (a, parent_a, true);
    3225            0 :               move_allocno_live_ranges (a, parent_a);
    3226            0 :               merged_p = true;
    3227            0 :               parent_data->mem_optimized_dest_p
    3228            0 :                 = (parent_data->mem_optimized_dest_p
    3229            0 :                    || data->mem_optimized_dest_p);
    3230            0 :               continue;
    3231              :             }
    3232            0 :           new_pseudos_p = true;
    3233            0 :           for (;;)
    3234              :             {
    3235            0 :               ALLOCNO_NREFS (parent_a) -= ALLOCNO_NREFS (a);
    3236            0 :               ALLOCNO_FREQ (parent_a) -= ALLOCNO_FREQ (a);
    3237            0 :               ALLOCNO_CALL_FREQ (parent_a) -= ALLOCNO_CALL_FREQ (a);
    3238            0 :               ALLOCNO_CALLS_CROSSED_NUM (parent_a)
    3239            0 :                 -= ALLOCNO_CALLS_CROSSED_NUM (a);
    3240            0 :               ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a)
    3241            0 :                 -= ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a);
    3242              :               /* Assume that ALLOCNO_CROSSED_CALLS_ABIS and
    3243              :                  ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS stay the same.
    3244              :                  We'd need to rebuild the IR to do better.  */
    3245            0 :               ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a)
    3246            0 :                 -= ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a);
    3247            0 :               ira_assert (ALLOCNO_CALLS_CROSSED_NUM (parent_a) >= 0
    3248              :                           && ALLOCNO_NREFS (parent_a) >= 0
    3249              :                           && ALLOCNO_FREQ (parent_a) >= 0);
    3250            0 :               aclass = ALLOCNO_CLASS (parent_a);
    3251            0 :               hard_regs_num = ira_class_hard_regs_num[aclass];
    3252            0 :               if (ALLOCNO_HARD_REG_COSTS (a) != NULL
    3253            0 :                   && ALLOCNO_HARD_REG_COSTS (parent_a) != NULL)
    3254            0 :                 for (j = 0; j < hard_regs_num; j++)
    3255            0 :                   ALLOCNO_HARD_REG_COSTS (parent_a)[j]
    3256            0 :                     -= ALLOCNO_HARD_REG_COSTS (a)[j];
    3257            0 :               if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a) != NULL
    3258            0 :                   && ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a) != NULL)
    3259            0 :                 for (j = 0; j < hard_regs_num; j++)
    3260            0 :                   ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a)[j]
    3261            0 :                     -= ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[j];
    3262            0 :               ALLOCNO_CLASS_COST (parent_a)
    3263            0 :                 -= ALLOCNO_CLASS_COST (a);
    3264            0 :               ALLOCNO_MEMORY_COST (parent_a) -= ALLOCNO_MEMORY_COST (a);
    3265            0 :               parent_a = ira_parent_allocno (parent_a);
    3266            0 :               if (parent_a == NULL)
    3267              :                 break;
    3268              :             }
    3269            0 :           ALLOCNO_COPIES (a) = NULL;
    3270            0 :           regno_top_level_allocno_map[REGNO (data->reg)] = a;
    3271              :         }
    3272            0 :       if (mem_dest_p && copy_info_to_removed_store_destinations (i))
    3273              :         merged_p = true;
    3274              :     }
    3275            0 :   ira_assert (new_pseudos_p || ira_max_point_before_emit == ira_max_point);
    3276            0 :   if (merged_p || ira_max_point_before_emit != ira_max_point)
    3277            0 :     ira_rebuild_start_finish_chains ();
    3278            0 :   if (new_pseudos_p)
    3279              :     {
    3280            0 :       sparseset objects_live;
    3281              : 
    3282              :       /* Rebuild conflicts.  */
    3283            0 :       FOR_EACH_ALLOCNO (a, ai)
    3284              :         {
    3285            0 :           ira_allocno_object_iterator oi;
    3286            0 :           ira_object_t obj;
    3287              : 
    3288            0 :           if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))]
    3289            0 :               || ALLOCNO_CAP_MEMBER (a) != NULL)
    3290            0 :             continue;
    3291            0 :           FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
    3292              :             {
    3293            0 :               for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
    3294            0 :                 ira_assert (r->object == obj);
    3295            0 :               clear_conflicts (obj);
    3296              :             }
    3297              :         }
    3298            0 :       objects_live = sparseset_alloc (ira_objects_num);
    3299            0 :       for (i = 0; i < ira_max_point; i++)
    3300              :         {
    3301            0 :           for (r = ira_start_point_ranges[i]; r != NULL; r = r->start_next)
    3302              :             {
    3303            0 :               ira_object_t obj = r->object;
    3304              : 
    3305            0 :               a = OBJECT_ALLOCNO (obj);
    3306            0 :               if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))]
    3307            0 :                   || ALLOCNO_CAP_MEMBER (a) != NULL)
    3308            0 :                 continue;
    3309              : 
    3310            0 :               aclass = ALLOCNO_CLASS (a);
    3311            0 :               EXECUTE_IF_SET_IN_SPARSESET (objects_live, n)
    3312              :                 {
    3313            0 :                   ira_object_t live_obj = ira_object_id_map[n];
    3314            0 :                   ira_allocno_t live_a = OBJECT_ALLOCNO (live_obj);
    3315            0 :                   enum reg_class live_aclass = ALLOCNO_CLASS (live_a);
    3316              : 
    3317            0 :                   if (ira_reg_classes_intersect_p[aclass][live_aclass]
    3318              :                       /* Don't set up conflict for the allocno with itself.  */
    3319            0 :                       && live_a != a)
    3320            0 :                     ira_add_conflict (obj, live_obj);
    3321              :                 }
    3322            0 :               sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
    3323              :             }
    3324              : 
    3325            0 :           for (r = ira_finish_point_ranges[i]; r != NULL; r = r->finish_next)
    3326            0 :             sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (r->object));
    3327              :         }
    3328            0 :       sparseset_free (objects_live);
    3329            0 :       compress_conflict_vecs ();
    3330              :     }
    3331              :   /* Mark some copies for removing and change allocnos in the rest
    3332              :      copies.  */
    3333            0 :   FOR_EACH_COPY (cp, ci)
    3334              :     {
    3335            0 :       if (ALLOCNO_CAP_MEMBER (cp->first) != NULL
    3336            0 :           || ALLOCNO_CAP_MEMBER (cp->second) != NULL)
    3337              :         {
    3338            0 :           if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL)
    3339            0 :             fprintf
    3340            0 :               (ira_dump_file, "      Remove cp%d:%c%dr%d-%c%dr%d\n",
    3341              :                cp->num, ALLOCNO_CAP_MEMBER (cp->first) != NULL ? 'c' : 'a',
    3342              :                ALLOCNO_NUM (cp->first),
    3343            0 :                REGNO (allocno_emit_reg (cp->first)),
    3344            0 :                ALLOCNO_CAP_MEMBER (cp->second) != NULL ? 'c' : 'a',
    3345              :                ALLOCNO_NUM (cp->second),
    3346            0 :                REGNO (allocno_emit_reg (cp->second)));
    3347            0 :           cp->loop_tree_node = NULL;
    3348            0 :           continue;
    3349              :         }
    3350            0 :       first
    3351            0 :         = regno_top_level_allocno_map[REGNO (allocno_emit_reg (cp->first))];
    3352            0 :       second
    3353            0 :         = regno_top_level_allocno_map[REGNO (allocno_emit_reg (cp->second))];
    3354            0 :       node = cp->loop_tree_node;
    3355            0 :       if (node == NULL)
    3356              :         keep_p = true; /* It copy generated in ira-emit.cc.  */
    3357              :       else
    3358              :         {
    3359              :           /* Check that the copy was not propagated from level on
    3360              :              which we will have different pseudos.  */
    3361            0 :           node_first = node->regno_allocno_map[ALLOCNO_REGNO (cp->first)];
    3362            0 :           node_second = node->regno_allocno_map[ALLOCNO_REGNO (cp->second)];
    3363            0 :           keep_p = ((REGNO (allocno_emit_reg (first))
    3364            0 :                      == REGNO (allocno_emit_reg (node_first)))
    3365            0 :                      && (REGNO (allocno_emit_reg (second))
    3366            0 :                          == REGNO (allocno_emit_reg (node_second))));
    3367              :         }
    3368            0 :       if (keep_p)
    3369              :         {
    3370            0 :           cp->loop_tree_node = ira_loop_tree_root;
    3371            0 :           cp->first = first;
    3372            0 :           cp->second = second;
    3373              :         }
    3374              :       else
    3375              :         {
    3376            0 :           cp->loop_tree_node = NULL;
    3377            0 :           if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL)
    3378            0 :             fprintf (ira_dump_file, "      Remove cp%d:a%dr%d-a%dr%d\n",
    3379              :                      cp->num, ALLOCNO_NUM (cp->first),
    3380            0 :                      REGNO (allocno_emit_reg (cp->first)),
    3381              :                      ALLOCNO_NUM (cp->second),
    3382            0 :                      REGNO (allocno_emit_reg (cp->second)));
    3383              :         }
    3384              :     }
    3385              :   /* Remove unnecessary allocnos on lower levels of the loop tree.  */
    3386            0 :   FOR_EACH_ALLOCNO (a, ai)
    3387              :     {
    3388            0 :       if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))]
    3389            0 :           || ALLOCNO_CAP_MEMBER (a) != NULL)
    3390              :         {
    3391            0 :           if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL)
    3392            0 :             fprintf (ira_dump_file, "      Remove a%dr%d\n",
    3393            0 :                      ALLOCNO_NUM (a), REGNO (allocno_emit_reg (a)));
    3394            0 :           ira_remove_allocno_prefs (a);
    3395            0 :           finish_allocno (a);
    3396            0 :           continue;
    3397              :         }
    3398            0 :       ALLOCNO_LOOP_TREE_NODE (a) = ira_loop_tree_root;
    3399            0 :       ALLOCNO_REGNO (a) = REGNO (allocno_emit_reg (a));
    3400            0 :       ALLOCNO_CAP (a) = NULL;
    3401              :       /* Restore updated costs for assignments from reload.  */
    3402            0 :       ALLOCNO_UPDATED_MEMORY_COST (a) = ALLOCNO_MEMORY_COST (a);
    3403            0 :       ALLOCNO_UPDATED_CLASS_COST (a) = ALLOCNO_CLASS_COST (a);
    3404            0 :       if (! ALLOCNO_ASSIGNED_P (a))
    3405            0 :         ira_free_allocno_updated_costs (a);
    3406            0 :       ira_assert (ALLOCNO_UPDATED_HARD_REG_COSTS (a) == NULL);
    3407            0 :       ira_assert (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) == NULL);
    3408              :     }
    3409              :   /* Remove unnecessary copies.  */
    3410            0 :   FOR_EACH_COPY (cp, ci)
    3411              :     {
    3412            0 :       if (cp->loop_tree_node == NULL)
    3413              :         {
    3414            0 :           ira_copies[cp->num] = NULL;
    3415            0 :           finish_copy (cp);
    3416            0 :           continue;
    3417              :         }
    3418            0 :       ira_assert
    3419              :         (ALLOCNO_LOOP_TREE_NODE (cp->first) == ira_loop_tree_root
    3420              :          && ALLOCNO_LOOP_TREE_NODE (cp->second) == ira_loop_tree_root);
    3421            0 :       add_allocno_copy_to_list (cp);
    3422            0 :       swap_allocno_copy_ends_if_necessary (cp);
    3423              :     }
    3424            0 :   rebuild_regno_allocno_maps ();
    3425            0 :   if (ira_max_point != ira_max_point_before_emit)
    3426            0 :     ira_compress_allocno_live_ranges ();
    3427            0 :   ira_free (regno_top_level_allocno_map);
    3428            0 : }
    3429              : 
    3430              : 
    3431              : 
    3432              : #ifdef ENABLE_IRA_CHECKING
    3433              : /* Check creation of all allocnos.  Allocnos on lower levels should
    3434              :    have allocnos or caps on all upper levels.  */
    3435              : static void
    3436      1504950 : check_allocno_creation (void)
    3437              : {
    3438      1504950 :   ira_allocno_t a;
    3439      1504950 :   ira_allocno_iterator ai;
    3440      1504950 :   ira_loop_tree_node_t loop_tree_node;
    3441              : 
    3442     38438235 :   FOR_EACH_ALLOCNO (a, ai)
    3443              :     {
    3444     36933285 :       loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a);
    3445     36933285 :       ira_assert (bitmap_bit_p (loop_tree_node->all_allocnos,
    3446              :                                 ALLOCNO_NUM (a)));
    3447     36933285 :       if (loop_tree_node == ira_loop_tree_root)
    3448     30173386 :         continue;
    3449      6759899 :       if (ALLOCNO_CAP_MEMBER (a) != NULL)
    3450      1732685 :         ira_assert (ALLOCNO_CAP (a) != NULL);
    3451      5027214 :       else if (ALLOCNO_CAP (a) == NULL)
    3452      3117412 :         ira_assert (loop_tree_node->parent
    3453              :                     ->regno_allocno_map[ALLOCNO_REGNO (a)] != NULL
    3454              :                     && bitmap_bit_p (loop_tree_node->border_allocnos,
    3455              :                                      ALLOCNO_NUM (a)));
    3456              :     }
    3457      1504950 : }
    3458              : #endif
    3459              : 
    3460              : /* Identify allocnos which prefer a register class with a single hard register.
    3461              :    Adjust ALLOCNO_CONFLICT_HARD_REG_COSTS so that conflicting allocnos are
    3462              :    less likely to use the preferred singleton register.  */
    3463              : static void
    3464      1504950 : update_conflict_hard_reg_costs (void)
    3465              : {
    3466      1504950 :   ira_allocno_t a;
    3467      1504950 :   ira_allocno_iterator ai;
    3468      1504950 :   int i, index, min;
    3469              : 
    3470     38438235 :   FOR_EACH_ALLOCNO (a, ai)
    3471              :     {
    3472     36933285 :       reg_class_t aclass = ALLOCNO_CLASS (a);
    3473     36933285 :       reg_class_t pref = reg_preferred_class (ALLOCNO_REGNO (a));
    3474     36933285 :       int singleton = ira_class_singleton[pref][ALLOCNO_MODE (a)];
    3475     36933285 :       if (singleton < 0)
    3476     28906258 :         continue;
    3477      8027027 :       index = ira_class_hard_reg_index[(int) aclass][singleton];
    3478      8027027 :       if (index < 0)
    3479            0 :         continue;
    3480      8027027 :       if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a) == NULL
    3481       793809 :           || ALLOCNO_HARD_REG_COSTS (a) == NULL)
    3482      7356457 :         continue;
    3483       670570 :       min = INT_MAX;
    3484     10290901 :       for (i = ira_class_hard_regs_num[(int) aclass] - 1; i >= 0; i--)
    3485      9620331 :         if (ALLOCNO_HARD_REG_COSTS (a)[i] > ALLOCNO_CLASS_COST (a)
    3486      8349791 :             && min > ALLOCNO_HARD_REG_COSTS (a)[i])
    3487      9620331 :           min = ALLOCNO_HARD_REG_COSTS (a)[i];
    3488       670570 :       if (min == INT_MAX)
    3489         8880 :         continue;
    3490       661690 :       ira_allocate_and_set_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a),
    3491              :                                   aclass, 0);
    3492       661690 :       ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[index]
    3493       661690 :         -= min - ALLOCNO_CLASS_COST (a);
    3494              :     }
    3495      1504950 : }
    3496              : 
    3497              : /* Create a internal representation (IR) for IRA (allocnos, copies,
    3498              :    loop tree nodes).  The function returns TRUE if we generate loop
    3499              :    structure (besides nodes representing all function and the basic
    3500              :    blocks) for regional allocation.  A true return means that we
    3501              :    really need to flatten IR before the reload.  */
    3502              : bool
    3503      1504950 : ira_build (void)
    3504              : {
    3505      1504950 :   bool loops_p;
    3506              : 
    3507      1504950 :   df_analyze ();
    3508      1504950 :   initiate_cost_vectors ();
    3509      1504950 :   initiate_allocnos ();
    3510      1504950 :   initiate_prefs ();
    3511      1504950 :   initiate_copies ();
    3512      1504950 :   create_loop_tree_nodes ();
    3513      1504950 :   form_loop_tree ();
    3514      1504950 :   create_allocnos ();
    3515      1504950 :   ira_costs ();
    3516      1504950 :   create_allocno_objects ();
    3517      1504950 :   ira_create_allocno_live_ranges ();
    3518      1504950 :   remove_unnecessary_regions (false);
    3519      1504950 :   ira_compress_allocno_live_ranges ();
    3520      1504950 :   update_bad_spill_attribute ();
    3521      1504950 :   loops_p = more_one_region_p ();
    3522      1504950 :   if (loops_p)
    3523              :     {
    3524        35511 :       propagate_allocno_info ();
    3525        35511 :       create_caps ();
    3526              :     }
    3527      1504950 :   ira_tune_allocno_costs ();
    3528              : #ifdef ENABLE_IRA_CHECKING
    3529      1504950 :   check_allocno_creation ();
    3530              : #endif
    3531      1504950 :   setup_min_max_allocno_live_range_point ();
    3532      1504950 :   sort_conflict_id_map ();
    3533      1504950 :   setup_min_max_conflict_allocno_ids ();
    3534      1504950 :   ira_build_conflicts ();
    3535      1504950 :   update_conflict_hard_reg_costs ();
    3536      1504950 :   if (! ira_conflicts_p)
    3537              :     {
    3538       447891 :       ira_allocno_t a;
    3539       447891 :       ira_allocno_iterator ai;
    3540              : 
    3541              :       /* Remove all regions but root one.  */
    3542       447891 :       if (loops_p)
    3543              :         {
    3544            0 :           remove_unnecessary_regions (true);
    3545            0 :           loops_p = false;
    3546              :         }
    3547              :       /* We don't save hard registers around calls for fast allocation
    3548              :          -- add caller clobbered registers as conflicting ones to
    3549              :          allocno crossing calls.  */
    3550     12525634 :       FOR_EACH_ALLOCNO (a, ai)
    3551     11629852 :         if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
    3552       199950 :           ior_hard_reg_conflicts (a, ira_need_caller_save_regs (a));
    3553              :     }
    3554      1504950 :   if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
    3555           95 :     print_copies (ira_dump_file);
    3556      1504950 :   if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
    3557           95 :     print_prefs (ira_dump_file);
    3558      1504950 :   if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
    3559              :     {
    3560           95 :       int n, nr, nr_big;
    3561           95 :       ira_allocno_t a;
    3562           95 :       live_range_t r;
    3563           95 :       ira_allocno_iterator ai;
    3564              : 
    3565           95 :       n = 0;
    3566           95 :       nr = 0;
    3567           95 :       nr_big = 0;
    3568          690 :       FOR_EACH_ALLOCNO (a, ai)
    3569              :         {
    3570          595 :           int j, nobj = ALLOCNO_NUM_OBJECTS (a);
    3571              : 
    3572          595 :           if (nobj > 1)
    3573            0 :             nr_big++;
    3574         1190 :           for (j = 0; j < nobj; j++)
    3575              :             {
    3576          595 :               ira_object_t obj = ALLOCNO_OBJECT (a, j);
    3577          595 :               n += OBJECT_NUM_CONFLICTS (obj);
    3578         1343 :               for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next)
    3579          748 :                 nr++;
    3580              :             }
    3581              :         }
    3582          190 :       fprintf (ira_dump_file, "  regions=%d, blocks=%d, points=%d\n",
    3583          130 :                current_loops == NULL ? 1 : number_of_loops (cfun),
    3584           95 :                n_basic_blocks_for_fn (cfun), ira_max_point);
    3585           95 :       fprintf (ira_dump_file,
    3586              :                "    allocnos=%d (big %d), copies=%d, conflicts=%d, ranges=%d\n",
    3587              :                ira_allocnos_num, nr_big, ira_copies_num, n, nr);
    3588              :     }
    3589      1504950 :   return loops_p;
    3590              : }
    3591              : 
    3592              : /* Release the data created by function ira_build.  */
    3593              : void
    3594      1504950 : ira_destroy (void)
    3595              : {
    3596      1504950 :   finish_loop_tree_nodes ();
    3597      1504950 :   finish_prefs ();
    3598      1504950 :   finish_copies ();
    3599      1504950 :   finish_allocnos ();
    3600      1504950 :   finish_cost_vectors ();
    3601      1504950 :   ira_finish_allocno_live_ranges ();
    3602      1504950 : }
        

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.