LCOV - code coverage report
Current view: top level - gcc - lra-lives.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.0 % 703 675
Test Date: 2024-04-20 14:03:02 Functions: 85.0 % 40 34
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Build live ranges for pseudos.
       2                 :             :    Copyright (C) 2010-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.    */
      20                 :             : 
      21                 :             : 
      22                 :             : /* This file contains code to build pseudo live-ranges (analogous
      23                 :             :    structures used in IRA, so read comments about the live-ranges
      24                 :             :    there) and other info necessary for other passes to assign
      25                 :             :    hard-registers to pseudos, coalesce the spilled pseudos, and assign
      26                 :             :    stack memory slots to spilled pseudos.  */
      27                 :             : 
      28                 :             : #include "config.h"
      29                 :             : #include "system.h"
      30                 :             : #include "coretypes.h"
      31                 :             : #include "backend.h"
      32                 :             : #include "rtl.h"
      33                 :             : #include "tree.h"
      34                 :             : #include "predict.h"
      35                 :             : #include "df.h"
      36                 :             : #include "memmodel.h"
      37                 :             : #include "tm_p.h"
      38                 :             : #include "insn-config.h"
      39                 :             : #include "regs.h"
      40                 :             : #include "ira.h"
      41                 :             : #include "recog.h"
      42                 :             : #include "cfganal.h"
      43                 :             : #include "sparseset.h"
      44                 :             : #include "lra-int.h"
      45                 :             : #include "target.h"
      46                 :             : #include "function-abi.h"
      47                 :             : 
      48                 :             : /* Program points are enumerated by numbers from range
      49                 :             :    0..LRA_LIVE_MAX_POINT-1.  There are approximately two times more
      50                 :             :    program points than insns.  Program points are places in the
      51                 :             :    program where liveness info can be changed.  In most general case
      52                 :             :    (there are more complicated cases too) some program points
      53                 :             :    correspond to places where input operand dies and other ones
      54                 :             :    correspond to places where output operands are born.  */
      55                 :             : int lra_live_max_point;
      56                 :             : 
      57                 :             : /* Accumulated execution frequency of all references for each hard
      58                 :             :    register.  */
      59                 :             : int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
      60                 :             : 
      61                 :             : /* A global flag whose true value says to build live ranges for all
      62                 :             :    pseudos, otherwise the live ranges only for pseudos got memory is
      63                 :             :    build.  True value means also building copies and setting up hard
      64                 :             :    register preferences.  The complete info is necessary only for the
      65                 :             :    assignment pass.  The complete info is not needed for the
      66                 :             :    coalescing and spill passes.  */
      67                 :             : static bool complete_info_p;
      68                 :             : 
      69                 :             : /* Pseudos live at current point in the RTL scan.  */
      70                 :             : static sparseset pseudos_live;
      71                 :             : 
      72                 :             : /* Pseudos probably living through calls and setjumps.  As setjump is
      73                 :             :    a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
      74                 :             :    then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
      75                 :             :    too.  These data are necessary for cases when only one subreg of a
      76                 :             :    multi-reg pseudo is set up after a call.  So we decide it is
      77                 :             :    probably live when traversing bb backward.  We are sure about
      78                 :             :    living when we see its usage or definition of the pseudo.  */
      79                 :             : static sparseset pseudos_live_through_calls;
      80                 :             : static sparseset pseudos_live_through_setjumps;
      81                 :             : 
      82                 :             : /* Set of hard regs (except eliminable ones) currently live.  */
      83                 :             : static HARD_REG_SET hard_regs_live;
      84                 :             : 
      85                 :             : /* Set of pseudos and hard registers start living/dying in the current
      86                 :             :    insn.  These sets are used to update REG_DEAD and REG_UNUSED notes
      87                 :             :    in the insn.  */
      88                 :             : static sparseset start_living, start_dying;
      89                 :             : 
      90                 :             : /* Set of pseudos and hard regs dead and unused in the current
      91                 :             :    insn.  */
      92                 :             : static sparseset unused_set, dead_set;
      93                 :             : 
      94                 :             : /* Bitmap used for holding intermediate bitmap operation results.  */
      95                 :             : static bitmap_head temp_bitmap;
      96                 :             : 
      97                 :             : /* Pool for pseudo live ranges.  */
      98                 :             : static object_allocator<lra_live_range> lra_live_range_pool ("live ranges");
      99                 :             : 
     100                 :             : /* Free live range list LR.  */
     101                 :             : static void
     102                 :   296729487 : free_live_range_list (lra_live_range_t lr)
     103                 :             : {
     104                 :   296729487 :   lra_live_range_t next;
     105                 :             : 
     106                 :   387222653 :   while (lr != NULL)
     107                 :             :     {
     108                 :    90493166 :       next = lr->next;
     109                 :    90493166 :       lra_live_range_pool.remove (lr);
     110                 :    90493166 :       lr = next;
     111                 :             :     }
     112                 :   296729487 : }
     113                 :             : 
     114                 :             : /* Create and return pseudo live range with given attributes.  */
     115                 :             : static lra_live_range_t
     116                 :    99899795 : create_live_range (int regno, int start, int finish, lra_live_range_t next)
     117                 :             : {
     118                 :           0 :   lra_live_range_t p = lra_live_range_pool.allocate ();
     119                 :    99899795 :   p->regno = regno;
     120                 :    99899795 :   p->start = start;
     121                 :    99899795 :   p->finish = finish;
     122                 :    99899795 :   p->next = next;
     123                 :    99899795 :   return p;
     124                 :             : }
     125                 :             : 
     126                 :             : /* Copy live range R and return the result.  */
     127                 :             : static lra_live_range_t
     128                 :     1702344 : copy_live_range (lra_live_range_t r)
     129                 :             : {
     130                 :     1702344 :   return new (lra_live_range_pool) lra_live_range (*r);
     131                 :             : }
     132                 :             : 
     133                 :             : /* Copy live range list given by its head R and return the result.  */
     134                 :             : lra_live_range_t
     135                 :     1067169 : lra_copy_live_range_list (lra_live_range_t r)
     136                 :             : {
     137                 :     1067169 :   lra_live_range_t p, first, *chain;
     138                 :             : 
     139                 :     1067169 :   first = NULL;
     140                 :     2769513 :   for (chain = &first; r != NULL; r = r->next)
     141                 :             :     {
     142                 :     1702344 :       p = copy_live_range (r);
     143                 :     1702344 :       *chain = p;
     144                 :     1702344 :       chain = &p->next;
     145                 :             :     }
     146                 :     1067169 :   return first;
     147                 :             : }
     148                 :             : 
     149                 :             : /* Merge *non-intersected* ranges R1 and R2 and returns the result.
     150                 :             :    The function maintains the order of ranges and tries to minimize
     151                 :             :    size of the result range list.  Ranges R1 and R2 may not be used
     152                 :             :    after the call.  */
     153                 :             : lra_live_range_t
     154                 :     1067169 : lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
     155                 :             : {
     156                 :     1067169 :   lra_live_range_t first, last;
     157                 :             : 
     158                 :     1067169 :   if (r1 == NULL)
     159                 :             :     return r2;
     160                 :      442233 :   if (r2 == NULL)
     161                 :             :     return r1;
     162                 :     4713935 :   for (first = last = NULL; r1 != NULL && r2 != NULL;)
     163                 :             :     {
     164                 :     4271702 :       if (r1->start < r2->start)
     165                 :      271616 :         std::swap (r1, r2);
     166                 :             : 
     167                 :     4271702 :       if (r1->start == r2->finish + 1)
     168                 :             :         {
     169                 :             :           /* Joint ranges: merge r1 and r2 into r1.  */
     170                 :       48311 :           r1->start = r2->start;
     171                 :       48311 :           lra_live_range_t temp = r2;
     172                 :       48311 :           r2 = r2->next;
     173                 :       48311 :           lra_live_range_pool.remove (temp);
     174                 :             :         }
     175                 :             :       else
     176                 :             :         {
     177                 :     4223391 :           gcc_assert (r2->finish + 1 < r1->start);
     178                 :             :           /* Add r1 to the result.  */
     179                 :     4223391 :           if (first == NULL)
     180                 :             :             first = last = r1;
     181                 :             :           else
     182                 :             :             {
     183                 :     3786830 :               last->next = r1;
     184                 :     3786830 :               last = r1;
     185                 :             :             }
     186                 :     4223391 :           r1 = r1->next;
     187                 :             :         }
     188                 :             :     }
     189                 :      442233 :   if (r1 != NULL)
     190                 :             :     {
     191                 :       21637 :       if (first == NULL)
     192                 :             :         first = r1;
     193                 :             :       else
     194                 :       15965 :         last->next = r1;
     195                 :             :     }
     196                 :             :   else
     197                 :             :     {
     198                 :      420596 :       lra_assert (r2 != NULL);
     199                 :      420596 :       if (first == NULL)
     200                 :             :         first = r2;
     201                 :             :       else
     202                 :      420596 :         last->next = r2;
     203                 :             :     }
     204                 :             :   return first;
     205                 :             : }
     206                 :             : 
     207                 :             : /* Return TRUE if live ranges R1 and R2 intersect.  */
     208                 :             : bool
     209                 :    25277222 : lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
     210                 :             : {
     211                 :             :   /* Remember the live ranges are always kept ordered.  */
     212                 :    37571630 :   while (r1 != NULL && r2 != NULL)
     213                 :             :     {
     214                 :    37127248 :       if (r1->start > r2->finish)
     215                 :    11281606 :         r1 = r1->next;
     216                 :    25845642 :       else if (r2->start > r1->finish)
     217                 :     1012802 :         r2 = r2->next;
     218                 :             :       else
     219                 :             :         return true;
     220                 :             :     }
     221                 :             :   return false;
     222                 :             : }
     223                 :             : 
     224                 :             : enum point_type {
     225                 :             :   DEF_POINT,
     226                 :             :   USE_POINT
     227                 :             : };
     228                 :             : 
     229                 :             : /* Return TRUE if set A contains a pseudo register, otherwise, return FALSE.  */
     230                 :             : static bool
     231                 :   711537028 : sparseset_contains_pseudos_p (sparseset a)
     232                 :             : {
     233                 :   711537028 :   int regno;
     234                 :   838366859 :   EXECUTE_IF_SET_IN_SPARSESET (a, regno)
     235                 :   307709113 :     if (!HARD_REGISTER_NUM_P (regno))
     236                 :             :       return true;
     237                 :             :   return false;
     238                 :             : }
     239                 :             : 
     240                 :             : /* Mark pseudo REGNO as living or dying at program point POINT, depending on
     241                 :             :    whether TYPE is a definition or a use.  If this is the first reference to
     242                 :             :    REGNO that we've encountered, then create a new live range for it.  */
     243                 :             : 
     244                 :             : static void
     245                 :  1186594741 : update_pseudo_point (int regno, int point, enum point_type type)
     246                 :             : {
     247                 :  1186594741 :   lra_live_range_t p;
     248                 :             : 
     249                 :             :   /* Don't compute points for hard registers.  */
     250                 :  1186594741 :   if (HARD_REGISTER_NUM_P (regno))
     251                 :             :     return;
     252                 :             : 
     253                 :  1101789796 :   if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
     254                 :             :     {
     255                 :  1068366517 :       if (type == DEF_POINT)
     256                 :             :         {
     257                 :   463403971 :           if (sparseset_bit_p (pseudos_live, regno))
     258                 :             :             {
     259                 :   463403971 :               p = lra_reg_info[regno].live_ranges;
     260                 :   463403971 :               lra_assert (p != NULL);
     261                 :   463403971 :               p->finish = point;
     262                 :             :             }
     263                 :             :         }
     264                 :             :       else /* USE_POINT */
     265                 :             :         {
     266                 :   604962546 :           if (!sparseset_bit_p (pseudos_live, regno)
     267                 :   604962546 :               && ((p = lra_reg_info[regno].live_ranges) == NULL
     268                 :   382710383 :                   || (p->finish != point && p->finish + 1 != point)))
     269                 :    99899795 :             lra_reg_info[regno].live_ranges
     270                 :    99899795 :               = create_live_range (regno, point, -1, p);
     271                 :             :         }
     272                 :             :     }
     273                 :             : }
     274                 :             : 
     275                 :             : /* The corresponding bitmaps of BB currently being processed.  */
     276                 :             : static bitmap bb_killed_pseudos, bb_gen_pseudos;
     277                 :             : 
     278                 :             : /* Record hard register REGNO as now being live.  It updates
     279                 :             :    living hard regs and START_LIVING.  */
     280                 :             : static void
     281                 :   211291855 : make_hard_regno_live (int regno)
     282                 :             : {
     283                 :   211291855 :   lra_assert (HARD_REGISTER_NUM_P (regno));
     284                 :   211291855 :   if (TEST_HARD_REG_BIT (hard_regs_live, regno)
     285                 :   211291855 :       || TEST_HARD_REG_BIT (eliminable_regset, regno))
     286                 :             :     return;
     287                 :   119369176 :   SET_HARD_REG_BIT (hard_regs_live, regno);
     288                 :   119369176 :   sparseset_set_bit (start_living, regno);
     289                 :   119369176 :   if (fixed_regs[regno] || TEST_HARD_REG_BIT (hard_regs_spilled_into, regno))
     290                 :    69545187 :     bitmap_set_bit (bb_gen_pseudos, regno);
     291                 :             : }
     292                 :             : 
     293                 :             : /* Process the definition of hard register REGNO.  This updates
     294                 :             :    hard_regs_live, START_DYING and conflict hard regs for living
     295                 :             :    pseudos.  */
     296                 :             : static void
     297                 :   117784928 : make_hard_regno_dead (int regno)
     298                 :             : {
     299                 :   117784928 :   if (TEST_HARD_REG_BIT (eliminable_regset, regno))
     300                 :             :     return;
     301                 :             : 
     302                 :   117784022 :   lra_assert (HARD_REGISTER_NUM_P (regno));
     303                 :   117784022 :   unsigned int i;
     304                 :  1327417751 :   EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
     305                 :  1209633729 :     SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
     306                 :             : 
     307                 :   117784022 :   if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
     308                 :             :     return;
     309                 :   117783308 :   CLEAR_HARD_REG_BIT (hard_regs_live, regno);
     310                 :   117783308 :   sparseset_set_bit (start_dying, regno);
     311                 :   117783308 :   if (fixed_regs[regno] || TEST_HARD_REG_BIT (hard_regs_spilled_into, regno))
     312                 :             :     {
     313                 :    69545232 :       bitmap_clear_bit (bb_gen_pseudos, regno);
     314                 :    69545232 :       bitmap_set_bit (bb_killed_pseudos, regno);
     315                 :             :     }
     316                 :             : }
     317                 :             : 
     318                 :             : /* Mark pseudo REGNO as now being live and update START_LIVING.  */
     319                 :             : static void
     320                 :   618350942 : mark_pseudo_live (int regno)
     321                 :             : {
     322                 :   618350942 :   lra_assert (!HARD_REGISTER_NUM_P (regno));
     323                 :   618350942 :   if (sparseset_bit_p (pseudos_live, regno))
     324                 :             :     return;
     325                 :             : 
     326                 :   474089013 :   sparseset_set_bit (pseudos_live, regno);
     327                 :   474089013 :   sparseset_set_bit (start_living, regno);
     328                 :             : }
     329                 :             : 
     330                 :             : /* Mark pseudo REGNO as now being dead and update START_DYING.  */
     331                 :             : static void
     332                 :   474089013 : mark_pseudo_dead (int regno)
     333                 :             : {
     334                 :   474089013 :   lra_assert (!HARD_REGISTER_NUM_P (regno));
     335                 :   474089013 :   lra_reg_info[regno].conflict_hard_regs |= hard_regs_live;
     336                 :   474089013 :   if (!sparseset_bit_p (pseudos_live, regno))
     337                 :             :     return;
     338                 :             : 
     339                 :   474089013 :   sparseset_clear_bit (pseudos_live, regno);
     340                 :   474089013 :   sparseset_set_bit (start_dying, regno);
     341                 :             : }
     342                 :             : 
     343                 :             : /* Mark register REGNO (pseudo or hard register) in MODE as being live
     344                 :             :    and update BB_GEN_PSEUDOS.  */
     345                 :             : static void
     346                 :   334352414 : mark_regno_live (int regno, machine_mode mode)
     347                 :             : {
     348                 :   334352414 :   int last;
     349                 :             : 
     350                 :   334352414 :   if (HARD_REGISTER_NUM_P (regno))
     351                 :             :     {
     352                 :   190790414 :       for (last = end_hard_regno (mode, regno); regno < last; regno++)
     353                 :    95685390 :         make_hard_regno_live (regno);
     354                 :             :     }
     355                 :             :   else
     356                 :             :     {
     357                 :   239247390 :       mark_pseudo_live (regno);
     358                 :   239247390 :       bitmap_set_bit (bb_gen_pseudos, regno);
     359                 :             :     }
     360                 :   334352414 : }
     361                 :             : 
     362                 :             : 
     363                 :             : /* Mark register REGNO (pseudo or hard register) in MODE as being dead
     364                 :             :    and update BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS.  */
     365                 :             : static void
     366                 :   137436455 : mark_regno_dead (int regno, machine_mode mode)
     367                 :             : {
     368                 :   137436455 :   int last;
     369                 :             : 
     370                 :   137436455 :   if (HARD_REGISTER_NUM_P (regno))
     371                 :             :     {
     372                 :    71284339 :       for (last = end_hard_regno (mode, regno); regno < last; regno++)
     373                 :    35855738 :         make_hard_regno_dead (regno);
     374                 :             :     }
     375                 :             :   else
     376                 :             :     {
     377                 :   102007854 :       mark_pseudo_dead (regno);
     378                 :   102007854 :       bitmap_clear_bit (bb_gen_pseudos, regno);
     379                 :   102007854 :       bitmap_set_bit (bb_killed_pseudos, regno);
     380                 :             :     }
     381                 :   137436455 : }
     382                 :             : 
     383                 :             : 
     384                 :             : 
     385                 :             : /* This page contains code for making global live analysis of pseudos.
     386                 :             :    The code works only when pseudo live info is changed on a BB
     387                 :             :    border.  That might be a consequence of some global transformations
     388                 :             :    in LRA, e.g. PIC pseudo reuse or rematerialization.  */
     389                 :             : 
     390                 :             : /* Structure describing local BB data used for pseudo
     391                 :             :    live-analysis.  */
     392                 :             : class bb_data_pseudos
     393                 :             : {
     394                 :             : public:
     395                 :             :   /* Basic block about which the below data are.  */
     396                 :             :   basic_block bb;
     397                 :             :   bitmap_head killed_pseudos; /* pseudos killed in the BB.  */
     398                 :             :   bitmap_head gen_pseudos; /* pseudos generated in the BB.  */
     399                 :             : };
     400                 :             : 
     401                 :             : /* Array for all BB data.  Indexed by the corresponding BB index.  */
     402                 :             : typedef class bb_data_pseudos *bb_data_t;
     403                 :             : 
     404                 :             : /* All basic block data are referred through the following array.  */
     405                 :             : static bb_data_t bb_data;
     406                 :             : 
     407                 :             : /* Two small functions for access to the bb data.  */
     408                 :             : static inline bb_data_t
     409                 :    66822625 : get_bb_data (basic_block bb)
     410                 :             : {
     411                 :    66822625 :   return &bb_data[(bb)->index];
     412                 :             : }
     413                 :             : 
     414                 :             : static inline bb_data_t
     415                 :     6205700 : get_bb_data_by_index (int index)
     416                 :             : {
     417                 :     6205700 :   return &bb_data[index];
     418                 :             : }
     419                 :             : 
     420                 :             : /* Bitmap with all hard regs.  */
     421                 :             : static bitmap_head all_hard_regs_bitmap;
     422                 :             : 
     423                 :             : /* The transfer function used by the DF equation solver to propagate
     424                 :             :    live info through block with BB_INDEX according to the following
     425                 :             :    equation:
     426                 :             : 
     427                 :             :      bb.livein = (bb.liveout - bb.kill) OR bb.gen
     428                 :             : */
     429                 :             : static bool
     430                 :     6205700 : live_trans_fun (int bb_index)
     431                 :             : {
     432                 :     6205700 :   basic_block bb = get_bb_data_by_index (bb_index)->bb;
     433                 :     6205700 :   bitmap bb_liveout = df_get_live_out (bb);
     434                 :     6205700 :   bitmap bb_livein = df_get_live_in (bb);
     435                 :     6205700 :   bb_data_t bb_info = get_bb_data (bb);
     436                 :             : 
     437                 :     6205700 :   bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
     438                 :     6205700 :   return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
     439                 :     6205700 :                                &temp_bitmap, &bb_info->killed_pseudos);
     440                 :             : }
     441                 :             : 
     442                 :             : /* The confluence function used by the DF equation solver to set up
     443                 :             :    live info for a block BB without predecessor.  */
     444                 :             : static void
     445                 :      229920 : live_con_fun_0 (basic_block bb)
     446                 :             : {
     447                 :      229920 :   bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
     448                 :      229920 : }
     449                 :             : 
     450                 :             : /* The confluence function used by the DF equation solver to propagate
     451                 :             :    live info from successor to predecessor on edge E according to the
     452                 :             :    following equation:
     453                 :             : 
     454                 :             :       bb.liveout = 0 for entry block | OR (livein of successors)
     455                 :             :  */
     456                 :             : static bool
     457                 :     9101607 : live_con_fun_n (edge e)
     458                 :             : {
     459                 :     9101607 :   basic_block bb = e->src;
     460                 :     9101607 :   basic_block dest = e->dest;
     461                 :     9101607 :   bitmap bb_liveout = df_get_live_out (bb);
     462                 :     9101607 :   bitmap dest_livein = df_get_live_in (dest);
     463                 :             : 
     464                 :     9101607 :   return bitmap_ior_and_compl_into (bb_liveout,
     465                 :     9101607 :                                     dest_livein, &all_hard_regs_bitmap);
     466                 :             : }
     467                 :             : 
     468                 :             : /* Indexes of all function blocks.  */
     469                 :             : static bitmap_head all_blocks;
     470                 :             : 
     471                 :             : /* Allocate and initialize data needed for global pseudo live
     472                 :             :    analysis.  */
     473                 :             : static void
     474                 :     1426764 : initiate_live_solver (void)
     475                 :             : {
     476                 :     1426764 :   bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
     477                 :     1426764 :   bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
     478                 :     1426764 :   bb_data = XNEWVEC (class bb_data_pseudos, last_basic_block_for_fn (cfun));
     479                 :     1426764 :   bitmap_initialize (&all_blocks, &reg_obstack);
     480                 :             : 
     481                 :     1426764 :   basic_block bb;
     482                 :    17575460 :   FOR_ALL_BB_FN (bb, cfun)
     483                 :             :     {
     484                 :    16148696 :       bb_data_t bb_info = get_bb_data (bb);
     485                 :    16148696 :       bb_info->bb = bb;
     486                 :    16148696 :       bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
     487                 :    16148696 :       bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
     488                 :    16148696 :       bitmap_set_bit (&all_blocks, bb->index);
     489                 :             :     }
     490                 :     1426764 : }
     491                 :             : 
     492                 :             : /* Free all data needed for global pseudo live analysis.  */
     493                 :             : static void
     494                 :     1426764 : finish_live_solver (void)
     495                 :             : {
     496                 :     1426764 :   basic_block bb;
     497                 :             : 
     498                 :     1426764 :   bitmap_clear (&all_blocks);
     499                 :    17575460 :   FOR_ALL_BB_FN (bb, cfun)
     500                 :             :     {
     501                 :    16148696 :       bb_data_t bb_info = get_bb_data (bb);
     502                 :    16148696 :       bitmap_clear (&bb_info->killed_pseudos);
     503                 :    16148696 :       bitmap_clear (&bb_info->gen_pseudos);
     504                 :             :     }
     505                 :     1426764 :   free (bb_data);
     506                 :     1426764 :   bitmap_clear (&all_hard_regs_bitmap);
     507                 :     1426764 : }
     508                 :             : 
     509                 :             : 
     510                 :             : 
     511                 :             : /* Insn currently scanned.  */
     512                 :             : static rtx_insn *curr_insn;
     513                 :             : /* The insn data.  */
     514                 :             : static lra_insn_recog_data_t curr_id;
     515                 :             : /* The insn static data.  */
     516                 :             : static struct lra_static_insn_data *curr_static_id;
     517                 :             : 
     518                 :             : /* Vec containing execution frequencies of program points.  */
     519                 :             : static vec<int> point_freq_vec;
     520                 :             : 
     521                 :             : /* The start of the above vector elements.  */
     522                 :             : int *lra_point_freq;
     523                 :             : 
     524                 :             : /* Increment the current program point POINT to the next point which has
     525                 :             :    execution frequency FREQ.  */
     526                 :             : static void
     527                 :   203468565 : next_program_point (int &point, int freq)
     528                 :             : {
     529                 :   203468565 :   point_freq_vec.safe_push (freq);
     530                 :   203468565 :   lra_point_freq = point_freq_vec.address ();
     531                 :   203468565 :   point++;
     532                 :   203468565 : }
     533                 :             : 
     534                 :             : /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT.  */
     535                 :             : void
     536                 :    11908751 : lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
     537                 :             :                                               int hard_regno, int profit)
     538                 :             : {
     539                 :    11908751 :   lra_assert (regno >= lra_constraint_new_regno_start);
     540                 :    11908751 :   if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
     541                 :     2053510 :     lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
     542                 :     9855241 :   else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
     543                 :       87220 :     lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
     544                 :     9768021 :   else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
     545                 :             :     {
     546                 :     7462098 :       lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
     547                 :     7462098 :       lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
     548                 :             :     }
     549                 :     2305923 :   else if (lra_reg_info[regno].preferred_hard_regno2 < 0
     550                 :       63220 :            || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
     551                 :             :     {
     552                 :     2265088 :       lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
     553                 :     2265088 :       lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
     554                 :             :     }
     555                 :             :   else
     556                 :             :     return;
     557                 :             :   /* Keep the 1st hard regno as more profitable.  */
     558                 :    11867916 :   if (lra_reg_info[regno].preferred_hard_regno1 >= 0
     559                 :    11867916 :       && lra_reg_info[regno].preferred_hard_regno2 >= 0
     560                 :     2435315 :       && (lra_reg_info[regno].preferred_hard_regno_profit2
     561                 :     2435315 :           > lra_reg_info[regno].preferred_hard_regno_profit1))
     562                 :             :     {
     563                 :       90404 :       std::swap (lra_reg_info[regno].preferred_hard_regno1,
     564                 :       90404 :                  lra_reg_info[regno].preferred_hard_regno2);
     565                 :       90404 :       std::swap (lra_reg_info[regno].preferred_hard_regno_profit1,
     566                 :       90404 :                  lra_reg_info[regno].preferred_hard_regno_profit2);
     567                 :             :     }
     568                 :    11867916 :   if (lra_dump_file != NULL)
     569                 :             :     {
     570                 :         250 :       if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
     571                 :         250 :         fprintf (lra_dump_file,
     572                 :             :                  " Hard reg %d is preferable by r%d with profit %d\n",
     573                 :             :                  hard_regno, regno,
     574                 :             :                  lra_reg_info[regno].preferred_hard_regno_profit1);
     575                 :         250 :       if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
     576                 :          98 :         fprintf (lra_dump_file,
     577                 :             :                  " Hard reg %d is preferable by r%d with profit %d\n",
     578                 :             :                  hard_regno, regno,
     579                 :             :                  lra_reg_info[regno].preferred_hard_regno_profit2);
     580                 :             :     }
     581                 :             : }
     582                 :             : 
     583                 :             : /* Check whether REGNO lives through calls and setjmps and clear
     584                 :             :    the corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
     585                 :             :    PSEUDOS_LIVE_THROUGH_SETJUMPS.  All calls in the region described
     586                 :             :    by PSEUDOS_LIVE_THROUGH_CALLS have the given ABI.  */
     587                 :             : 
     588                 :             : static inline void
     589                 :   425247118 : check_pseudos_live_through_calls (int regno, const function_abi &abi)
     590                 :             : {
     591                 :   425247118 :   if (! sparseset_bit_p (pseudos_live_through_calls, regno))
     592                 :             :     return;
     593                 :             : 
     594                 :    95092961 :   machine_mode mode = PSEUDO_REGNO_MODE (regno);
     595                 :             : 
     596                 :    95092961 :   sparseset_clear_bit (pseudos_live_through_calls, regno);
     597                 :    95092961 :   lra_reg_info[regno].conflict_hard_regs |= abi.mode_clobbers (mode);
     598                 :    95092961 :   if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
     599                 :             :     return;
     600                 :        7097 :   sparseset_clear_bit (pseudos_live_through_setjumps, regno);
     601                 :             :   /* Don't allocate pseudos that cross setjmps or any call, if this
     602                 :             :      function receives a nonlocal goto.  */
     603                 :        7097 :   SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
     604                 :             : }
     605                 :             : 
     606                 :             : /* Return true if insn REG is an early clobber operand in alternative
     607                 :             :    NALT.  Negative NALT means that we don't know the current insn
     608                 :             :    alternative.  So assume the worst.  */
     609                 :             : static inline bool
     610                 :   350011982 : reg_early_clobber_p (const struct lra_insn_reg *reg, int n_alt)
     611                 :             : {
     612                 :   350011982 :   return (n_alt == LRA_UNKNOWN_ALT
     613                 :   350011982 :           ? reg->early_clobber_alts != 0
     614                 :             :           : (n_alt != LRA_NON_CLOBBERED_ALT
     615                 :   336453016 :              && TEST_BIT (reg->early_clobber_alts, n_alt)));
     616                 :             : }
     617                 :             : 
     618                 :             : /* Clear pseudo REGNO in SET or all hard registers of REGNO in MODE in SET.  */
     619                 :             : static void
     620                 :   141031813 : clear_sparseset_regnos (sparseset set, int regno, enum machine_mode mode)
     621                 :             : {
     622                 :   141031813 :   if (regno >= FIRST_PSEUDO_REGISTER)
     623                 :             :     {
     624                 :    78673808 :       sparseset_clear_bit (dead_set, regno);
     625                 :    78673808 :       return;
     626                 :             :     }
     627                 :   124964263 :   for (int last = end_hard_regno (mode, regno); regno < last; regno++)
     628                 :    62606258 :     sparseset_clear_bit (set, regno);
     629                 :             : }
     630                 :             : 
     631                 :             : /* Return true if pseudo REGNO is in SET or all hard registers of REGNO in MODE
     632                 :             :    are in SET.  */
     633                 :             : static bool
     634                 :   144311244 : regnos_in_sparseset_p (sparseset set, int regno, enum machine_mode mode)
     635                 :             : {
     636                 :   144311244 :   if (regno >= FIRST_PSEUDO_REGISTER)
     637                 :    81740104 :     return sparseset_bit_p (dead_set, regno);
     638                 :   125177398 :   for (int last = end_hard_regno (mode, regno); regno < last; regno++)
     639                 :    62819393 :     if (!sparseset_bit_p (set, regno))
     640                 :             :       return false;
     641                 :             :   return true;
     642                 :             : }
     643                 :             : 
     644                 :             : /* Process insns of the basic block BB to update pseudo live ranges,
     645                 :             :    pseudo hard register conflicts, and insn notes.  We do it on
     646                 :             :    backward scan of BB insns.  CURR_POINT is the program point where
     647                 :             :    BB ends.  The function updates this counter and returns in
     648                 :             :    CURR_POINT the program point where BB starts.  The function also
     649                 :             :    does local live info updates and can delete the dead insns if
     650                 :             :    DEAD_INSN_P.  It returns true if pseudo live info was
     651                 :             :    changed at the BB start.  */
     652                 :             : static bool
     653                 :    28319505 : process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
     654                 :             : {
     655                 :    28319505 :   int i, regno, freq;
     656                 :    28319505 :   unsigned int j;
     657                 :    28319505 :   bitmap_iterator bi;
     658                 :    28319505 :   bitmap reg_live_out;
     659                 :    28319505 :   unsigned int px;
     660                 :    28319505 :   rtx_insn *next;
     661                 :    28319505 :   rtx link, *link_loc;
     662                 :    28319505 :   bool need_curr_point_incr;
     663                 :             :   /* Only has a meaningful value once we've seen a call.  */
     664                 :    28319505 :   function_abi last_call_abi = default_function_abi;
     665                 :             : 
     666                 :    28319505 :   reg_live_out = df_get_live_out (bb);
     667                 :    28319505 :   sparseset_clear (pseudos_live);
     668                 :    28319505 :   sparseset_clear (pseudos_live_through_calls);
     669                 :    28319505 :   sparseset_clear (pseudos_live_through_setjumps);
     670                 :    56639010 :   REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
     671                 :    28319505 :   hard_regs_live &= ~eliminable_regset;
     672                 :   407423057 :   EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
     673                 :             :     {
     674                 :   379103552 :       update_pseudo_point (j, curr_point, USE_POINT);
     675                 :   379103552 :       mark_pseudo_live (j);
     676                 :             :     }
     677                 :             : 
     678                 :    28319505 :   bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
     679                 :    28319505 :   bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
     680                 :    28319505 :   bitmap_clear (bb_gen_pseudos);
     681                 :    28319505 :   bitmap_clear (bb_killed_pseudos);
     682                 :    28319505 :   freq = REG_FREQ_FROM_BB (bb);
     683                 :             : 
     684                 :    28319505 :   if (lra_dump_file != NULL)
     685                 :         566 :     fprintf (lra_dump_file, "  BB %d\n", bb->index);
     686                 :             : 
     687                 :             :   /* Scan the code of this basic block, noting which pseudos and hard
     688                 :             :      regs are born or die.
     689                 :             : 
     690                 :             :      Note that this loop treats uninitialized values as live until the
     691                 :             :      beginning of the block.  For example, if an instruction uses
     692                 :             :      (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
     693                 :             :      FOO will remain live until the beginning of the block.  Likewise
     694                 :             :      if FOO is not set at all.  This is unnecessarily pessimistic, but
     695                 :             :      it probably doesn't matter much in practice.  */
     696                 :   768406094 :   FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
     697                 :             :     {
     698                 :   355883542 :       bool call_p;
     699                 :   355883542 :       int n_alt, dst_regno, src_regno;
     700                 :   355883542 :       rtx set;
     701                 :   355883542 :       struct lra_insn_reg *reg;
     702                 :             : 
     703                 :   355883542 :       if (!NONDEBUG_INSN_P (curr_insn))
     704                 :   157857080 :         continue;
     705                 :             : 
     706                 :   198026462 :       curr_id = lra_get_insn_recog_data (curr_insn);
     707                 :   198026462 :       curr_static_id = curr_id->insn_static_data;
     708                 :   198026462 :       n_alt = curr_id->used_insn_alternative;
     709                 :   198026462 :       if (lra_dump_file != NULL)
     710                 :        2809 :         fprintf (lra_dump_file, "   Insn %u: point = %d, n_alt = %d\n",
     711                 :        2809 :                  INSN_UID (curr_insn), curr_point, n_alt);
     712                 :             : 
     713                 :   198026462 :       set = single_set (curr_insn);
     714                 :             : 
     715                 :   198026462 :       if (dead_insn_p && set != NULL_RTX
     716                 :   156966347 :           && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set))
     717                 :    81818015 :           && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
     718                 :    81582326 :           && ! may_trap_p (PATTERN (curr_insn))
     719                 :             :           /* Don't do premature remove of pic offset pseudo as we can
     720                 :             :              start to use it after some reload generation.  */
     721                 :   271331752 :           && (pic_offset_table_rtx == NULL_RTX
     722                 :     7807123 :               || pic_offset_table_rtx != SET_DEST (set)))
     723                 :             :         {
     724                 :    73244165 :           bool remove_p = true;
     725                 :             : 
     726                 :    73657427 :           for (reg = curr_id->regs; reg != NULL; reg = reg->next)
     727                 :    73605858 :             if (reg->type != OP_IN
     728                 :    73605858 :                 && (reg->regno < FIRST_PSEUDO_REGISTER
     729                 :    73244258 :                     ? TEST_HARD_REG_BIT (hard_regs_live, reg->regno)
     730                 :    73244256 :                     : sparseset_bit_p (pseudos_live, reg->regno)))
     731                 :             :               {
     732                 :             :                 remove_p = false;
     733                 :             :                 break;
     734                 :             :               }
     735                 :    74260353 :           for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
     736                 :    14403422 :             if (reg->type != OP_IN)
     737                 :             :               {
     738                 :             :                 remove_p = false;
     739                 :             :                 break;
     740                 :             :               }
     741                 :             : 
     742                 :    73244165 :           if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
     743                 :             :             {
     744                 :       44795 :               dst_regno = REGNO (SET_DEST (set));
     745                 :       44795 :               if (lra_dump_file != NULL)
     746                 :           0 :                 fprintf (lra_dump_file, "   Deleting dead insn %u\n",
     747                 :           0 :                          INSN_UID (curr_insn));
     748                 :       44795 :               lra_set_insn_deleted (curr_insn);
     749                 :       44795 :               if (lra_reg_info[dst_regno].nrefs == 0)
     750                 :             :                 {
     751                 :             :                   /* There might be some debug insns with the pseudo.  */
     752                 :        4882 :                   unsigned int uid;
     753                 :        4882 :                   rtx_insn *insn;
     754                 :             : 
     755                 :        4882 :                   bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
     756                 :        5020 :                   EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
     757                 :             :                     {
     758                 :         138 :                       insn = lra_insn_recog_data[uid]->insn;
     759                 :         138 :                       lra_substitute_pseudo_within_insn (insn, dst_regno,
     760                 :             :                                                          SET_SRC (set), true);
     761                 :         138 :                       lra_update_insn_regno_info (insn);
     762                 :             :                     }
     763                 :             :                 }
     764                 :       44795 :               continue;
     765                 :       44795 :             }
     766                 :             :         }
     767                 :             : 
     768                 :             :       /* Update max ref width and hard reg usage.  */
     769                 :   514080574 :       for (reg = curr_id->regs; reg != NULL; reg = reg->next)
     770                 :             :         {
     771                 :   316098907 :           int regno = reg->regno;
     772                 :             : 
     773                 :   316098907 :           lra_update_biggest_mode (regno, reg->biggest_mode);
     774                 :   316098907 :           if (HARD_REGISTER_NUM_P (regno))
     775                 :    84625788 :             lra_hard_reg_usage[regno] += freq;
     776                 :             :         }
     777                 :             : 
     778                 :   197981667 :       call_p = CALL_P (curr_insn);
     779                 :             : 
     780                 :             :       /* If we have a simple register copy and the source reg is live after
     781                 :             :          this instruction, then remove the source reg from the live set so
     782                 :             :          that it will not conflict with the destination reg.  */
     783                 :   197981667 :       rtx ignore_reg = non_conflicting_reg_copy_p (curr_insn);
     784                 :   197981667 :       if (ignore_reg != NULL_RTX)
     785                 :             :         {
     786                 :    54423088 :           int ignore_regno = REGNO (ignore_reg);
     787                 :    54423088 :           if (HARD_REGISTER_NUM_P (ignore_regno)
     788                 :    54423088 :               && TEST_HARD_REG_BIT (hard_regs_live, ignore_regno))
     789                 :      169110 :             CLEAR_HARD_REG_BIT (hard_regs_live, ignore_regno);
     790                 :    54253978 :           else if (!HARD_REGISTER_NUM_P (ignore_regno)
     791                 :    54253978 :                    && sparseset_bit_p (pseudos_live, ignore_regno))
     792                 :    11203907 :             sparseset_clear_bit (pseudos_live, ignore_regno);
     793                 :             :           else
     794                 :             :             /* We don't need any special handling of the source reg if
     795                 :             :                it is dead after this instruction.  */
     796                 :             :             ignore_reg = NULL_RTX;
     797                 :             :         }
     798                 :             : 
     799                 :   188828028 :       src_regno = (set != NULL_RTX && REG_P (SET_SRC (set))
     800                 :   271288129 :                    ? REGNO (SET_SRC (set)) : -1);
     801                 :   188828028 :       dst_regno = (set != NULL_RTX && REG_P (SET_DEST (set))
     802                 :   141178410 :                    ? REGNO (SET_DEST (set)) : -1);
     803                 :   197981667 :       if (complete_info_p
     804                 :   195153789 :           && src_regno >= 0 && dst_regno >= 0
     805                 :             :           /* Check that source regno does not conflict with
     806                 :             :              destination regno to exclude most impossible
     807                 :             :              preferences.  */
     808                 :   251463469 :           && (((!HARD_REGISTER_NUM_P (src_regno)
     809                 :    47279709 :                 && (! sparseset_bit_p (pseudos_live, src_regno)
     810                 :        9456 :                     || (!HARD_REGISTER_NUM_P (dst_regno)
     811                 :    53481803 :                         && lra_reg_val_equal_p (src_regno,
     812                 :             :                                                 lra_reg_info[dst_regno].val,
     813                 :           1 :                                                 lra_reg_info[dst_regno].offset))))
     814                 :             :                || (HARD_REGISTER_NUM_P (src_regno)
     815                 :     6202093 :                    && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
     816                 :             :               /* It might be 'inheritance pseudo <- reload pseudo'.  */
     817                 :        9468 :               || (src_regno >= lra_constraint_new_regno_start
     818                 :         257 :                   && dst_regno >= lra_constraint_new_regno_start
     819                 :             :                   /* Remember to skip special cases where src/dest regnos are
     820                 :             :                      the same, e.g. insn SET pattern has matching constraints
     821                 :             :                      like =r,0.  */
     822                 :           0 :                   && src_regno != dst_regno)))
     823                 :             :         {
     824                 :    53472334 :           int hard_regno = -1, regno = -1;
     825                 :             : 
     826                 :    53472334 :           if (dst_regno >= lra_constraint_new_regno_start
     827                 :    13076079 :               && src_regno >= lra_constraint_new_regno_start)
     828                 :             :             {
     829                 :             :               /* It might be still an original (non-reload) insn with
     830                 :             :                  one unused output and a constraint requiring to use
     831                 :             :                  the same reg for input/output operands. In this case
     832                 :             :                  dst_regno and src_regno have the same value, we don't
     833                 :             :                  need a misleading copy for this case.  */
     834                 :     4757230 :               if (dst_regno != src_regno)
     835                 :     4757230 :                 lra_create_copy (dst_regno, src_regno, freq);
     836                 :             :             }
     837                 :    48715104 :           else if (dst_regno >= lra_constraint_new_regno_start)
     838                 :             :             {
     839                 :     8318849 :               if (!HARD_REGISTER_NUM_P (hard_regno = src_regno))
     840                 :     8311686 :                 hard_regno = reg_renumber[src_regno];
     841                 :             :               regno = dst_regno;
     842                 :             :             }
     843                 :    40396255 :           else if (src_regno >= lra_constraint_new_regno_start)
     844                 :             :             {
     845                 :     8327146 :               if (!HARD_REGISTER_NUM_P (hard_regno = dst_regno))
     846                 :     7584203 :                 hard_regno = reg_renumber[dst_regno];
     847                 :             :               regno = src_regno;
     848                 :             :             }
     849                 :    53472334 :           if (regno >= 0 && hard_regno >= 0)
     850                 :     9413115 :             lra_setup_reload_pseudo_preferenced_hard_reg
     851                 :     9413115 :               (regno, hard_regno, freq);
     852                 :             :         }
     853                 :             : 
     854                 :   197981667 :       sparseset_clear (start_living);
     855                 :             : 
     856                 :             :       /* Mark each defined value as live.  We need to do this for
     857                 :             :          unused values because they still conflict with quantities
     858                 :             :          that are live at the time of the definition.  */
     859                 :   514080574 :       for (reg = curr_id->regs; reg != NULL; reg = reg->next)
     860                 :   316098907 :         if (reg->type != OP_IN)
     861                 :             :           {
     862                 :   138529570 :             update_pseudo_point (reg->regno, curr_point, USE_POINT);
     863                 :   138529570 :             mark_regno_live (reg->regno, reg->biggest_mode);
     864                 :             :             /* ??? Should be a no-op for unused registers.  */
     865                 :   138529570 :             check_pseudos_live_through_calls (reg->regno, last_call_abi);
     866                 :             :           }
     867                 :             : 
     868                 :   248084774 :       for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
     869                 :    50103107 :         if (reg->type != OP_IN)
     870                 :    36476421 :           make_hard_regno_live (reg->regno);
     871                 :             : 
     872                 :   197981667 :       if (curr_id->arg_hard_regs != NULL)
     873                 :    28989359 :         for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
     874                 :    20491913 :           if (!HARD_REGISTER_NUM_P (regno))
     875                 :             :             /* It is a clobber.  */
     876                 :      947823 :             make_hard_regno_live (regno - FIRST_PSEUDO_REGISTER);
     877                 :             : 
     878                 :   197981667 :       sparseset_copy (unused_set, start_living);
     879                 :             : 
     880                 :   197981667 :       sparseset_clear (start_dying);
     881                 :             : 
     882                 :             :       /* See which defined values die here.  */
     883                 :   514080574 :       for (reg = curr_id->regs; reg != NULL; reg = reg->next)
     884                 :   316098907 :         if (reg->type != OP_IN
     885                 :   591748812 :             && ! reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
     886                 :             :           {
     887                 :   137120335 :             if (reg->type == OP_OUT)
     888                 :   119099534 :               update_pseudo_point (reg->regno, curr_point, DEF_POINT);
     889                 :   137120335 :             mark_regno_dead (reg->regno, reg->biggest_mode);
     890                 :             :           }
     891                 :             : 
     892                 :   248084774 :       for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
     893                 :    50103107 :         if (reg->type != OP_IN
     894                 :   100811098 :             && ! reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
     895                 :    14231570 :           make_hard_regno_dead (reg->regno);
     896                 :             : 
     897                 :   197981667 :       if (curr_id->arg_hard_regs != NULL)
     898                 :    28989359 :         for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
     899                 :    20491913 :           if (!HARD_REGISTER_NUM_P (regno))
     900                 :             :             /* It is a clobber.  */
     901                 :      947823 :             make_hard_regno_dead (regno - FIRST_PSEUDO_REGISTER);
     902                 :             : 
     903                 :   197981667 :       if (call_p)
     904                 :             :         {
     905                 :    11087795 :           function_abi call_abi = insn_callee_abi (curr_insn);
     906                 :             : 
     907                 :    11087795 :           if (last_call_abi != call_abi)
     908                 :     7949582 :             EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
     909                 :     5885498 :               check_pseudos_live_through_calls (j, last_call_abi);
     910                 :             : 
     911                 :    11087795 :           last_call_abi = call_abi;
     912                 :             : 
     913                 :    11087795 :           sparseset_ior (pseudos_live_through_calls,
     914                 :             :                          pseudos_live_through_calls, pseudos_live);
     915                 :    11087795 :           if (cfun->has_nonlocal_label
     916                 :    11087795 :               || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
     917                 :    11083535 :                   && (find_reg_note (curr_insn, REG_SETJMP, NULL_RTX)
     918                 :             :                       != NULL_RTX)))
     919                 :        6591 :             sparseset_ior (pseudos_live_through_setjumps,
     920                 :             :                            pseudos_live_through_setjumps, pseudos_live);
     921                 :             :         }
     922                 :             : 
     923                 :             :       /* Increment the current program point if we must.  */
     924                 :   197981667 :       if (sparseset_contains_pseudos_p (unused_set)
     925                 :   197981667 :           || sparseset_contains_pseudos_p (start_dying))
     926                 :   101355452 :         next_program_point (curr_point, freq);
     927                 :             : 
     928                 :             :       /* If we removed the source reg from a simple register copy from the
     929                 :             :          live set above, then add it back now so we don't accidentally add
     930                 :             :          it to the start_living set below.  */
     931                 :   197981667 :       if (ignore_reg != NULL_RTX)
     932                 :             :         {
     933                 :    11373017 :           int ignore_regno = REGNO (ignore_reg);
     934                 :    11373017 :           if (HARD_REGISTER_NUM_P (ignore_regno))
     935                 :      169110 :             SET_HARD_REG_BIT (hard_regs_live, ignore_regno);
     936                 :             :           else
     937                 :    11203907 :             sparseset_set_bit (pseudos_live, ignore_regno);
     938                 :             :         }
     939                 :             : 
     940                 :   197981667 :       sparseset_clear (start_living);
     941                 :             : 
     942                 :             :       /* Mark each used value as live.  */
     943                 :   514080574 :       for (reg = curr_id->regs; reg != NULL; reg = reg->next)
     944                 :   316098907 :         if (reg->type != OP_OUT)
     945                 :             :           {
     946                 :   195718313 :             if (reg->type == OP_IN)
     947                 :   177569337 :               update_pseudo_point (reg->regno, curr_point, USE_POINT);
     948                 :   195718313 :             mark_regno_live (reg->regno, reg->biggest_mode);
     949                 :   195718313 :             check_pseudos_live_through_calls (reg->regno, last_call_abi);
     950                 :             :           }
     951                 :             : 
     952                 :   248084774 :       for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
     953                 :    50103107 :         if (reg->type != OP_OUT)
     954                 :    14104407 :           make_hard_regno_live (reg->regno);
     955                 :             : 
     956                 :   197981667 :       if (curr_id->arg_hard_regs != NULL)
     957                 :             :         /* Make argument hard registers live.  */
     958                 :    28989359 :         for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
     959                 :    20491913 :           if (HARD_REGISTER_NUM_P (regno))
     960                 :    19544090 :             make_hard_regno_live (regno);
     961                 :             : 
     962                 :   197981667 :       sparseset_and_compl (dead_set, start_living, start_dying);
     963                 :             : 
     964                 :   197981667 :       sparseset_clear (start_dying);
     965                 :             : 
     966                 :             :       /* Mark early clobber outputs dead.  */
     967                 :   514080574 :       for (reg = curr_id->regs; reg != NULL; reg = reg->next)
     968                 :   316098907 :         if (reg->type != OP_IN
     969                 :   454944597 :             && reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
     970                 :             :           {
     971                 :      316120 :             if (reg->type == OP_OUT)
     972                 :      211589 :               update_pseudo_point (reg->regno, curr_point, DEF_POINT);
     973                 :      316120 :             mark_regno_dead (reg->regno, reg->biggest_mode);
     974                 :             : 
     975                 :             :             /* We're done processing inputs, so make sure early clobber
     976                 :             :                operands that are both inputs and outputs are still live.  */
     977                 :      316120 :             if (reg->type == OP_INOUT)
     978                 :      104531 :               mark_regno_live (reg->regno, reg->biggest_mode);
     979                 :             :           }
     980                 :             : 
     981                 :   248084774 :       for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
     982                 :    50103107 :         if (reg->type != OP_IN
     983                 :   108824379 :             && reg_early_clobber_p (reg, n_alt) && ! reg->subreg_p)
     984                 :             :           {
     985                 :    22244851 :             struct lra_insn_reg *reg2;
     986                 :             : 
     987                 :             :             /* We can have early clobbered non-operand hard reg and
     988                 :             :                the same hard reg as an insn input.  Don't make hard
     989                 :             :                reg dead before the insns.  */
     990                 :    45024409 :             for (reg2 = curr_static_id->hard_regs; reg2 != NULL; reg2 = reg2->next)
     991                 :    22808336 :               if (reg2->type != OP_OUT && reg2->regno == reg->regno)
     992                 :             :                 break;
     993                 :    22244851 :             if (reg2 == NULL)
     994                 :    22216073 :               make_hard_regno_dead (reg->regno);
     995                 :             :           }
     996                 :             : 
     997                 :             :       /* Increment the current program point if we must.  */
     998                 :   197981667 :       if (sparseset_contains_pseudos_p (dead_set)
     999                 :   197981667 :           || sparseset_contains_pseudos_p (start_dying))
    1000                 :    79523830 :         next_program_point (curr_point, freq);
    1001                 :             : 
    1002                 :             :       /* Update notes.  */
    1003                 :   400260975 :       for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
    1004                 :             :         {
    1005                 :   202279308 :           if (REG_NOTE_KIND (link) != REG_DEAD
    1006                 :    83238157 :               && REG_NOTE_KIND (link) != REG_UNUSED)
    1007                 :             :             ;
    1008                 :   144311244 :           else if (REG_P (XEXP (link, 0)))
    1009                 :             :             {
    1010                 :   144311244 :               rtx note_reg = XEXP (link, 0);
    1011                 :   144311244 :               int note_regno = REGNO (note_reg);
    1012                 :             : 
    1013                 :   147590675 :               if ((REG_NOTE_KIND (link) == REG_DEAD
    1014                 :   119041151 :                    && ! regnos_in_sparseset_p (dead_set, note_regno,
    1015                 :   119041151 :                                                GET_MODE (note_reg)))
    1016                 :   261347427 :                   || (REG_NOTE_KIND (link) == REG_UNUSED
    1017                 :    25270093 :                       && ! regnos_in_sparseset_p (unused_set, note_regno,
    1018                 :    25270093 :                                                   GET_MODE (note_reg))))
    1019                 :             :                 {
    1020                 :     3279431 :                   *link_loc = XEXP (link, 1);
    1021                 :     3279431 :                   continue;
    1022                 :             :                 }
    1023                 :   141031813 :               if (REG_NOTE_KIND (link) == REG_DEAD)
    1024                 :   117036183 :                 clear_sparseset_regnos (dead_set, note_regno,
    1025                 :   117036183 :                                         GET_MODE (note_reg));
    1026                 :    23995630 :               else if (REG_NOTE_KIND (link) == REG_UNUSED)
    1027                 :    23995630 :                 clear_sparseset_regnos (unused_set, note_regno,
    1028                 :    23995630 :                                         GET_MODE (note_reg));
    1029                 :             :             }
    1030                 :   198999877 :           link_loc = &XEXP (link, 1);
    1031                 :             :         }
    1032                 :   205118664 :       EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
    1033                 :     7136997 :         add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
    1034                 :   397954187 :       EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
    1035                 :     1990853 :         add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
    1036                 :             :     }
    1037                 :             : 
    1038                 :    28319505 :   if (bb_has_eh_pred (bb))
    1039                 :             :     /* Any pseudos that are currently live conflict with the eh_return
    1040                 :             :        data registers.  For liveness purposes, these registers are set
    1041                 :             :        by artificial definitions at the start of the BB, so are not
    1042                 :             :        actually live on entry.  */
    1043                 :      521374 :     for (j = 0; ; ++j)
    1044                 :             :       {
    1045                 :     1564122 :         unsigned int regno = EH_RETURN_DATA_REGNO (j);
    1046                 :             : 
    1047                 :     1042748 :         if (regno == INVALID_REGNUM)
    1048                 :             :           break;
    1049                 :             : 
    1050                 :     1042748 :         make_hard_regno_live (regno);
    1051                 :     1042748 :         make_hard_regno_dead (regno);
    1052                 :     1042748 :       }
    1053                 :             : 
    1054                 :             :   /* Pseudos can't go in stack regs at the start of a basic block that
    1055                 :             :      is reached by an abnormal edge.  Likewise for registers that are at
    1056                 :             :      least partly call clobbered, because caller-save, fixup_abnormal_edges
    1057                 :             :      and possibly the table driven EH machinery are not quite ready to
    1058                 :             :      handle such pseudos live across such edges.  */
    1059                 :    28319505 :   if (bb_has_abnormal_pred (bb))
    1060                 :             :     {
    1061                 :             :       HARD_REG_SET clobbers;
    1062                 :             : 
    1063                 :      524730 :       CLEAR_HARD_REG_SET (clobbers);
    1064                 :             : #ifdef STACK_REGS
    1065                 :     2118528 :       EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
    1066                 :     1593798 :         lra_reg_info[px].no_stack_p = true;
    1067                 :     4722570 :       for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
    1068                 :     4197840 :         SET_HARD_REG_BIT (clobbers, px);
    1069                 :             : #endif
    1070                 :             :       /* No need to record conflicts for call clobbered regs if we
    1071                 :             :          have nonlocal labels around, as we don't ever try to
    1072                 :             :          allocate such regs in this case.  */
    1073                 :      524730 :       if (!cfun->has_nonlocal_label
    1074                 :      524730 :           && has_abnormal_call_or_eh_pred_edge_p (bb))
    1075                 :    48486852 :         for (px = 0; HARD_REGISTER_NUM_P (px); px++)
    1076                 :    47965488 :           if (eh_edge_abi.clobbers_at_least_part_of_reg_p (px)
    1077                 :             : #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
    1078                 :             :               /* We should create a conflict of PIC pseudo with PIC
    1079                 :             :                  hard reg as PIC hard reg can have a wrong value after
    1080                 :             :                  jump described by the abnormal edge.  In this case we
    1081                 :             :                  cannot allocate PIC hard reg to PIC pseudo as PIC
    1082                 :             :                  pseudo will also have a wrong value.  */
    1083                 :    48545571 :               || (px == REAL_PIC_OFFSET_TABLE_REGNUM
    1084                 :      521364 :                   && pic_offset_table_rtx != NULL_RTX
    1085                 :       25098 :                   && !HARD_REGISTER_P (pic_offset_table_rtx))
    1086                 :             : #endif
    1087                 :             :               )
    1088                 :    43464048 :             SET_HARD_REG_BIT (clobbers, px);
    1089                 :             : 
    1090                 :      524730 :       clobbers &= ~hard_regs_live;
    1091                 :    48799890 :       for (px = 0; HARD_REGISTER_NUM_P (px); px++)
    1092                 :    48275160 :         if (TEST_HARD_REG_BIT (clobbers, px))
    1093                 :             :           {
    1094                 :    43490976 :             make_hard_regno_live (px);
    1095                 :    43490976 :             make_hard_regno_dead (px);
    1096                 :             :           }
    1097                 :             :     }
    1098                 :             : 
    1099                 :    28319505 :   bool live_change_p = false;
    1100                 :             :   /* Check if bb border live info was changed.  */
    1101                 :    28319505 :   unsigned int live_pseudos_num = 0;
    1102                 :   400027626 :   EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
    1103                 :             :                             FIRST_PSEUDO_REGISTER, j, bi)
    1104                 :             :     {
    1105                 :   371826909 :       live_pseudos_num++;
    1106                 :   371826909 :       if (! sparseset_bit_p (pseudos_live, j))
    1107                 :             :         {
    1108                 :      118788 :           live_change_p = true;
    1109                 :      118788 :           if (lra_dump_file != NULL)
    1110                 :          14 :             fprintf (lra_dump_file,
    1111                 :             :                      "  r%d is removed as live at bb%d start\n", j, bb->index);
    1112                 :             :           break;
    1113                 :             :         }
    1114                 :             :     }
    1115                 :    28319505 :   if (! live_change_p
    1116                 :    28319505 :       && sparseset_cardinality (pseudos_live) != live_pseudos_num)
    1117                 :             :     {
    1118                 :      110361 :       live_change_p = true;
    1119                 :      110361 :       if (lra_dump_file != NULL)
    1120                 :          28 :         EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
    1121                 :           7 :           if (! bitmap_bit_p (df_get_live_in (bb), j))
    1122                 :           7 :             fprintf (lra_dump_file,
    1123                 :             :                      "  r%d is added to live at bb%d start\n", j, bb->index);
    1124                 :             :     }
    1125                 :             :   /* See if we'll need an increment at the end of this basic block.
    1126                 :             :      An increment is needed if the PSEUDOS_LIVE set is not empty,
    1127                 :             :      to make sure the finish points are set up correctly.  */
    1128                 :    28319505 :   need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
    1129                 :             : 
    1130                 :   772481823 :   EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
    1131                 :             :     {
    1132                 :   372081159 :       update_pseudo_point (i, curr_point, DEF_POINT);
    1133                 :   372081159 :       mark_pseudo_dead (i);
    1134                 :             :     }
    1135                 :             : 
    1136                 :   119556599 :   EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
    1137                 :             :     {
    1138                 :   109972920 :       if (sparseset_cardinality (pseudos_live_through_calls) == 0)
    1139                 :             :         break;
    1140                 :    91237094 :       if (sparseset_bit_p (pseudos_live_through_calls, j))
    1141                 :    85113737 :         check_pseudos_live_through_calls (j, last_call_abi);
    1142                 :             :     }
    1143                 :             : 
    1144                 :  2633713965 :   for (i = 0; HARD_REGISTER_NUM_P (i); ++i)
    1145                 :             :     {
    1146                 :  2605394460 :       if (!TEST_HARD_REG_BIT (hard_regs_live, i))
    1147                 :  2565804767 :         continue;
    1148                 :             : 
    1149                 :    39589693 :       if (!TEST_HARD_REG_BIT (hard_regs_spilled_into, i))
    1150                 :    39589693 :         continue;
    1151                 :             : 
    1152                 :           0 :       if (bitmap_bit_p (df_get_live_in (bb), i))
    1153                 :           0 :         continue;
    1154                 :             : 
    1155                 :           0 :       live_change_p = true;
    1156                 :           0 :       if (lra_dump_file)
    1157                 :           0 :         fprintf (lra_dump_file,
    1158                 :             :                  "  hard reg r%d is added to live at bb%d start\n", i,
    1159                 :             :                  bb->index);
    1160                 :           0 :       bitmap_set_bit (df_get_live_in (bb), i);
    1161                 :             :     }
    1162                 :             : 
    1163                 :    28319505 :   if (need_curr_point_incr)
    1164                 :    22589283 :     next_program_point (curr_point, freq);
    1165                 :             : 
    1166                 :    28319505 :   return live_change_p;
    1167                 :             : }
    1168                 :             : 
    1169                 :             : /* Compress pseudo live ranges by removing program points where
    1170                 :             :    nothing happens.  Complexity of many algorithms in LRA is linear
    1171                 :             :    function of program points number.  To speed up the code we try to
    1172                 :             :    minimize the number of the program points here.  */
    1173                 :             : static void
    1174                 :     1469496 : remove_some_program_points_and_update_live_ranges (void)
    1175                 :             : {
    1176                 :     1469496 :   unsigned i;
    1177                 :     1469496 :   int n, max_regno;
    1178                 :     1469496 :   int *map;
    1179                 :     1469496 :   lra_live_range_t r, prev_r, next_r;
    1180                 :     1469496 :   sbitmap_iterator sbi;
    1181                 :     1469496 :   bool born_p, dead_p, prev_born_p, prev_dead_p;
    1182                 :             : 
    1183                 :     1469496 :   auto_sbitmap born (lra_live_max_point);
    1184                 :     1469496 :   auto_sbitmap dead (lra_live_max_point);
    1185                 :     1469496 :   bitmap_clear (born);
    1186                 :     1469496 :   bitmap_clear (dead);
    1187                 :     1469496 :   max_regno = max_reg_num ();
    1188                 :   153534035 :   for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
    1189                 :             :     {
    1190                 :   251964334 :       for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
    1191                 :             :         {
    1192                 :    99899795 :           lra_assert (r->start <= r->finish);
    1193                 :    99899795 :           bitmap_set_bit (born, r->start);
    1194                 :    99899795 :           bitmap_set_bit (dead, r->finish);
    1195                 :             :         }
    1196                 :             :     }
    1197                 :     1469496 :   auto_sbitmap born_or_dead (lra_live_max_point);
    1198                 :     1469496 :   bitmap_ior (born_or_dead, born, dead);
    1199                 :     1469496 :   map = XCNEWVEC (int, lra_live_max_point);
    1200                 :     1469496 :   n = -1;
    1201                 :     1469496 :   prev_born_p = prev_dead_p = false;
    1202                 :   177201803 :   EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
    1203                 :             :     {
    1204                 :   174262811 :       born_p = bitmap_bit_p (born, i);
    1205                 :   174262811 :       dead_p = bitmap_bit_p (dead, i);
    1206                 :   174262811 :       if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
    1207                 :   160985023 :           || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
    1208                 :             :         {
    1209                 :    37726479 :           map[i] = n;
    1210                 :    37726479 :           lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
    1211                 :             :         }
    1212                 :             :       else
    1213                 :             :         {
    1214                 :   136536332 :           map[i] = ++n;
    1215                 :   136536332 :           lra_point_freq[n] = lra_point_freq[i];
    1216                 :             :         }
    1217                 :   174262811 :       prev_born_p = born_p;
    1218                 :   174262811 :       prev_dead_p = dead_p;
    1219                 :             :     }
    1220                 :     1469496 :   n++;
    1221                 :     1469496 :   if (lra_dump_file != NULL)
    1222                 :         100 :     fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
    1223                 :             :              lra_live_max_point, n,
    1224                 :         100 :              lra_live_max_point ? 100 * n / lra_live_max_point : 100);
    1225                 :     1469496 :   if (n < lra_live_max_point)
    1226                 :             :     {
    1227                 :     1237227 :       lra_live_max_point = n;
    1228                 :   150245925 :       for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
    1229                 :             :         {
    1230                 :   149008698 :           for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
    1231                 :   248105531 :                r != NULL;
    1232                 :             :                r = next_r)
    1233                 :             :             {
    1234                 :    99096833 :               next_r = r->next;
    1235                 :    99096833 :               r->start = map[r->start];
    1236                 :    99096833 :               r->finish = map[r->finish];
    1237                 :    99096833 :               if (prev_r == NULL || prev_r->start > r->finish + 1)
    1238                 :             :                 {
    1239                 :    97200667 :                   prev_r = r;
    1240                 :    97200667 :                   continue;
    1241                 :             :                 }
    1242                 :     1896166 :               prev_r->start = r->start;
    1243                 :     1896166 :               prev_r->next = next_r;
    1244                 :     1896166 :               lra_live_range_pool.remove (r);
    1245                 :             :             }
    1246                 :             :         }
    1247                 :             :     }
    1248                 :     1469496 :   free (map);
    1249                 :     1469496 : }
    1250                 :             : 
    1251                 :             : /* Print live ranges R to file F.  */
    1252                 :             : void
    1253                 :        2672 : lra_print_live_range_list (FILE *f, lra_live_range_t r)
    1254                 :             : {
    1255                 :        5894 :   for (; r != NULL; r = r->next)
    1256                 :        3222 :     fprintf (f, " [%d..%d]", r->start, r->finish);
    1257                 :        2672 :   fprintf (f, "\n");
    1258                 :        2672 : }
    1259                 :             : 
    1260                 :             : DEBUG_FUNCTION void
    1261                 :           0 : debug (lra_live_range &ref)
    1262                 :             : {
    1263                 :           0 :   lra_print_live_range_list (stderr, &ref);
    1264                 :           0 : }
    1265                 :             : 
    1266                 :             : DEBUG_FUNCTION void
    1267                 :           0 : debug (lra_live_range *ptr)
    1268                 :             : {
    1269                 :           0 :   if (ptr)
    1270                 :           0 :     debug (*ptr);
    1271                 :             :   else
    1272                 :           0 :     fprintf (stderr, "<nil>\n");
    1273                 :           0 : }
    1274                 :             : 
    1275                 :             : /* Print live ranges R to stderr.  */
    1276                 :             : void
    1277                 :           0 : lra_debug_live_range_list (lra_live_range_t r)
    1278                 :             : {
    1279                 :           0 :   lra_print_live_range_list (stderr, r);
    1280                 :           0 : }
    1281                 :             : 
    1282                 :             : /* Print live ranges of pseudo REGNO to file F.  */
    1283                 :             : static void
    1284                 :        6078 : print_pseudo_live_ranges (FILE *f, int regno)
    1285                 :             : {
    1286                 :        6078 :   if (lra_reg_info[regno].live_ranges == NULL)
    1287                 :             :     return;
    1288                 :        2672 :   fprintf (f, " r%d:", regno);
    1289                 :        2672 :   lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
    1290                 :             : }
    1291                 :             : 
    1292                 :             : /* Print live ranges of pseudo REGNO to stderr.  */
    1293                 :             : void
    1294                 :           0 : lra_debug_pseudo_live_ranges (int regno)
    1295                 :             : {
    1296                 :           0 :   print_pseudo_live_ranges (stderr, regno);
    1297                 :           0 : }
    1298                 :             : 
    1299                 :             : /* Print live ranges of all pseudos to file F.  */
    1300                 :             : static void
    1301                 :         200 : print_live_ranges (FILE *f)
    1302                 :             : {
    1303                 :         200 :   int i, max_regno;
    1304                 :             : 
    1305                 :         200 :   max_regno = max_reg_num ();
    1306                 :        6478 :   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
    1307                 :        6078 :     print_pseudo_live_ranges (f, i);
    1308                 :         200 : }
    1309                 :             : 
    1310                 :             : /* Print live ranges of all pseudos to stderr.  */
    1311                 :             : void
    1312                 :           0 : lra_debug_live_ranges (void)
    1313                 :             : {
    1314                 :           0 :   print_live_ranges (stderr);
    1315                 :           0 : }
    1316                 :             : 
    1317                 :             : /* Compress pseudo live ranges.  */
    1318                 :             : static void
    1319                 :     1469496 : compress_live_ranges (void)
    1320                 :             : {
    1321                 :     1469496 :   remove_some_program_points_and_update_live_ranges ();
    1322                 :     1469496 :   if (lra_dump_file != NULL)
    1323                 :             :     {
    1324                 :         100 :       fprintf (lra_dump_file, "Ranges after the compression:\n");
    1325                 :         100 :       print_live_ranges (lra_dump_file);
    1326                 :             :     }
    1327                 :     1469496 : }
    1328                 :             : 
    1329                 :             : 
    1330                 :             : 
    1331                 :             : /* The number of the current live range pass.  */
    1332                 :             : int lra_live_range_iter;
    1333                 :             : 
    1334                 :             : /* The function creates live ranges only for memory pseudos (or for
    1335                 :             :    all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos.  It
    1336                 :             :    also does dead insn elimination if DEAD_INSN_P and global live
    1337                 :             :    analysis only for pseudos and only if the pseudo live info was
    1338                 :             :    changed on a BB border.  Return TRUE if the live info was
    1339                 :             :    changed.  */
    1340                 :             : static bool
    1341                 :     1662573 : lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
    1342                 :             : {
    1343                 :     1662573 :   basic_block bb;
    1344                 :     1662573 :   int i, hard_regno, max_regno = max_reg_num ();
    1345                 :     1662573 :   int curr_point;
    1346                 :     1662573 :   bool bb_live_change_p, have_referenced_pseudos = false;
    1347                 :             : 
    1348                 :     1662573 :   timevar_push (TV_LRA_CREATE_LIVE_RANGES);
    1349                 :             : 
    1350                 :     1662573 :   complete_info_p = all_p;
    1351                 :     1662573 :   if (lra_dump_file != NULL)
    1352                 :         114 :     fprintf (lra_dump_file,
    1353                 :             :              "\n********** Pseudo live ranges #%d: **********\n\n",
    1354                 :             :              ++lra_live_range_iter);
    1355                 :     1662573 :   memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
    1356                 :   308843793 :   for (i = 0; i < max_regno; i++)
    1357                 :             :     {
    1358                 :   307181220 :       lra_reg_info[i].live_ranges = NULL;
    1359                 :   307181220 :       CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
    1360                 :   307181220 :       lra_reg_info[i].preferred_hard_regno1 = -1;
    1361                 :   307181220 :       lra_reg_info[i].preferred_hard_regno2 = -1;
    1362                 :   307181220 :       lra_reg_info[i].preferred_hard_regno_profit1 = 0;
    1363                 :   307181220 :       lra_reg_info[i].preferred_hard_regno_profit2 = 0;
    1364                 :             : #ifdef STACK_REGS
    1365                 :   307181220 :       lra_reg_info[i].no_stack_p = false;
    1366                 :             : #endif
    1367                 :             :       /* The biggest mode is already set but its value might be to
    1368                 :             :          conservative because of recent transformation.  Here in this
    1369                 :             :          file we recalculate it again as it costs practically
    1370                 :             :          nothing.  */
    1371                 :   307181220 :       if (!HARD_REGISTER_NUM_P (i) && regno_reg_rtx[i] != NULL_RTX)
    1372                 :   153425178 :         lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
    1373                 :             :       else
    1374                 :   153756042 :         lra_reg_info[i].biggest_mode = VOIDmode;
    1375                 :   307181220 :       if (!HARD_REGISTER_NUM_P (i)
    1376                 :   154224504 :           && lra_reg_info[i].nrefs != 0)
    1377                 :             :         {
    1378                 :    81969375 :           if ((hard_regno = reg_renumber[i]) >= 0)
    1379                 :    69486127 :             lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
    1380                 :             :           have_referenced_pseudos = true;
    1381                 :             :         }
    1382                 :             :     }
    1383                 :     1662573 :   lra_free_copies ();
    1384                 :             : 
    1385                 :             :   /* Under some circumstances, we can have functions without pseudo
    1386                 :             :      registers.  For such functions, lra_live_max_point will be 0,
    1387                 :             :      see e.g. PR55604, and there's nothing more to do for us here.  */
    1388                 :     1662573 :   if (! have_referenced_pseudos)
    1389                 :             :     {
    1390                 :      193077 :       timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
    1391                 :      193077 :       return false;
    1392                 :             :     }
    1393                 :             : 
    1394                 :     1469496 :   pseudos_live = sparseset_alloc (max_regno);
    1395                 :     1469496 :   pseudos_live_through_calls = sparseset_alloc (max_regno);
    1396                 :     1469496 :   pseudos_live_through_setjumps = sparseset_alloc (max_regno);
    1397                 :     1469496 :   start_living = sparseset_alloc (max_regno);
    1398                 :     1469496 :   start_dying = sparseset_alloc (max_regno);
    1399                 :     1469496 :   dead_set = sparseset_alloc (max_regno);
    1400                 :     1469496 :   unused_set = sparseset_alloc (max_regno);
    1401                 :     1469496 :   curr_point = 0;
    1402                 :     1469496 :   unsigned new_length = get_max_uid () * 2;
    1403                 :     1469496 :   point_freq_vec.truncate (0);
    1404                 :     1469496 :   point_freq_vec.reserve_exact (new_length);
    1405                 :     1469496 :   lra_point_freq = point_freq_vec.address ();
    1406                 :     1469496 :   int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
    1407                 :     1469496 :   int n = inverted_rev_post_order_compute (cfun, rpo);
    1408                 :     1469496 :   lra_assert (n == n_basic_blocks_for_fn (cfun));
    1409                 :             :   bb_live_change_p = false;
    1410                 :    32727993 :   for (i = 0; i < n; ++i)
    1411                 :             :     {
    1412                 :    31258497 :       bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
    1413                 :    31258497 :       if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
    1414                 :    29789001 :           == ENTRY_BLOCK_PTR_FOR_FN (cfun))
    1415                 :     2938992 :         continue;
    1416                 :    28319505 :       if (process_bb_lives (bb, curr_point, dead_insn_p))
    1417                 :    31258497 :         bb_live_change_p = true;
    1418                 :             :     }
    1419                 :     1469496 :   free (rpo);
    1420                 :     1469496 :   if (bb_live_change_p)
    1421                 :             :     {
    1422                 :             :       /* We need to clear pseudo live info as some pseudos can
    1423                 :             :          disappear, e.g. pseudos with used equivalences.  */
    1424                 :     4826540 :       FOR_EACH_BB_FN (bb, cfun)
    1425                 :             :         {
    1426                 :     4756357 :           bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
    1427                 :     4756357 :                               max_regno - FIRST_PSEUDO_REGISTER);
    1428                 :     4756357 :           bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
    1429                 :             :                               max_regno - FIRST_PSEUDO_REGISTER);
    1430                 :             :         }
    1431                 :             :       /* As we did not change CFG since LRA start we can use
    1432                 :             :          DF-infrastructure solver to solve live data flow problem.  */
    1433                 :     6527019 :       for (int i = 0; HARD_REGISTER_NUM_P (i); ++i)
    1434                 :             :         {
    1435                 :     6456836 :           if (TEST_HARD_REG_BIT (hard_regs_spilled_into, i))
    1436                 :           0 :             bitmap_clear_bit (&all_hard_regs_bitmap, i);
    1437                 :             :         }
    1438                 :       70183 :       df_simple_dataflow
    1439                 :       70183 :         (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
    1440                 :             :          live_trans_fun, &all_blocks,
    1441                 :             :          df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
    1442                 :       70183 :       if (lra_dump_file != NULL)
    1443                 :             :         {
    1444                 :           7 :           fprintf (lra_dump_file,
    1445                 :             :                    "Global pseudo live data have been updated:\n");
    1446                 :           7 :           basic_block bb;
    1447                 :          35 :           FOR_EACH_BB_FN (bb, cfun)
    1448                 :             :             {
    1449                 :          28 :               bb_data_t bb_info = get_bb_data (bb);
    1450                 :          28 :               bitmap bb_livein = df_get_live_in (bb);
    1451                 :          28 :               bitmap bb_liveout = df_get_live_out (bb);
    1452                 :             : 
    1453                 :          28 :               fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
    1454                 :          28 :               lra_dump_bitmap_with_title ("  gen:",
    1455                 :             :                                           &bb_info->gen_pseudos, bb->index);
    1456                 :          28 :               lra_dump_bitmap_with_title ("  killed:",
    1457                 :             :                                           &bb_info->killed_pseudos, bb->index);
    1458                 :          28 :               lra_dump_bitmap_with_title ("  livein:", bb_livein, bb->index);
    1459                 :          28 :               lra_dump_bitmap_with_title ("  liveout:", bb_liveout, bb->index);
    1460                 :             :             }
    1461                 :             :         }
    1462                 :             :     }
    1463                 :     1469496 :   lra_live_max_point = curr_point;
    1464                 :     1469496 :   if (lra_dump_file != NULL)
    1465                 :         100 :     print_live_ranges (lra_dump_file);
    1466                 :             :   /* Clean up.  */
    1467                 :     1469496 :   sparseset_free (unused_set);
    1468                 :     1469496 :   sparseset_free (dead_set);
    1469                 :     1469496 :   sparseset_free (start_dying);
    1470                 :     1469496 :   sparseset_free (start_living);
    1471                 :     1469496 :   sparseset_free (pseudos_live_through_calls);
    1472                 :     1469496 :   sparseset_free (pseudos_live_through_setjumps);
    1473                 :     1469496 :   sparseset_free (pseudos_live);
    1474                 :     1469496 :   compress_live_ranges ();
    1475                 :     1469496 :   timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
    1476                 :     1469496 :   return bb_live_change_p;
    1477                 :             : }
    1478                 :             : 
    1479                 :             : /* The main entry function creates live-ranges and other live info
    1480                 :             :    necessary for the assignment sub-pass.  It uses
    1481                 :             :    lra_creates_live_ranges_1 -- so read comments for the
    1482                 :             :    function.  */
    1483                 :             : void
    1484                 :     1592390 : lra_create_live_ranges (bool all_p, bool dead_insn_p)
    1485                 :             : {
    1486                 :     1592390 :   if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
    1487                 :             :     return;
    1488                 :       70183 :   if (lra_dump_file != NULL)
    1489                 :           7 :     fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
    1490                 :             :   /* Live info was changed on a bb border.  It means that some info,
    1491                 :             :      e.g. about conflict regs, calls crossed, and live ranges may be
    1492                 :             :      wrong.  We need this info for allocation.  So recalculate it
    1493                 :             :      again but without removing dead insns which can change live info
    1494                 :             :      again.  Repetitive live range calculations are expensive therefore
    1495                 :             :      we stop here as we already have correct info although some
    1496                 :             :      improvement in rare cases could be possible on this sub-pass if
    1497                 :             :      we do dead insn elimination again (still the improvement may
    1498                 :             :      happen later).  */
    1499                 :       70183 :   lra_clear_live_ranges ();
    1500                 :       70183 :   bool res = lra_create_live_ranges_1 (all_p, false);
    1501                 :       70183 :   lra_assert (! res);
    1502                 :             : }
    1503                 :             : 
    1504                 :             : /* Finish all live ranges.  */
    1505                 :             : void
    1506                 :     1649238 : lra_clear_live_ranges (void)
    1507                 :             : {
    1508                 :     1649238 :   int i;
    1509                 :             : 
    1510                 :   298378725 :   for (i = 0; i < max_reg_num (); i++)
    1511                 :   296729487 :     free_live_range_list (lra_reg_info[i].live_ranges);
    1512                 :     1649238 :   point_freq_vec.release ();
    1513                 :     1649238 : }
    1514                 :             : 
    1515                 :             : /* Initialize live ranges data once per function.  */
    1516                 :             : void
    1517                 :     1426764 : lra_live_ranges_init (void)
    1518                 :             : {
    1519                 :     1426764 :   bitmap_initialize (&temp_bitmap, &reg_obstack);
    1520                 :     1426764 :   initiate_live_solver ();
    1521                 :     1426764 : }
    1522                 :             : 
    1523                 :             : /* Finish live ranges data once per function.  */
    1524                 :             : void
    1525                 :     1426764 : lra_live_ranges_finish (void)
    1526                 :             : {
    1527                 :     1426764 :   finish_live_solver ();
    1528                 :     1426764 :   bitmap_clear (&temp_bitmap);
    1529                 :     1426764 :   lra_live_range_pool.release ();
    1530                 :     1426764 : }
        

Generated by: LCOV version 2.1-beta

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