LCOV - code coverage report
Current view: top level - gcc - df-scan.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.6 % 1930 1652
Test Date: 2026-02-28 14:20:25 Functions: 92.8 % 97 90
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Scanning of rtl for dataflow analysis.
       2              :    Copyright (C) 1999-2026 Free Software Foundation, Inc.
       3              :    Originally contributed by Michael P. Hayes
       4              :              (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
       5              :    Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
       6              :              and Kenneth Zadeck (zadeck@naturalbridge.com).
       7              : 
       8              : This file is part of GCC.
       9              : 
      10              : GCC is free software; you can redistribute it and/or modify it under
      11              : the terms of the GNU General Public License as published by the Free
      12              : Software Foundation; either version 3, or (at your option) any later
      13              : version.
      14              : 
      15              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      16              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      17              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      18              : for more details.
      19              : 
      20              : You should have received a copy of the GNU General Public License
      21              : along with GCC; see the file COPYING3.  If not see
      22              : <http://www.gnu.org/licenses/>.  */
      23              : 
      24              : #include "config.h"
      25              : #include "system.h"
      26              : #include "coretypes.h"
      27              : #include "backend.h"
      28              : #include "target.h"
      29              : #include "rtl.h"
      30              : #include "tree.h"
      31              : #include "df.h"
      32              : #include "memmodel.h"
      33              : #include "tm_p.h"
      34              : #include "regs.h"
      35              : #include "emit-rtl.h"  /* FIXME: Can go away once crtl is moved to rtl.h.  */
      36              : #include "dumpfile.h"
      37              : #include "calls.h"
      38              : #include "function-abi.h"
      39              : 
      40              : /* The set of hard registers in eliminables[i].from. */
      41              : 
      42              : static HARD_REG_SET elim_reg_set;
      43              : 
      44              : /* Initialize ur_in and ur_out as if all hard registers were partially
      45              :    available.  */
      46              : 
      47   1202357763 : class df_collection_rec
      48              : {
      49              : public:
      50              :   auto_vec<df_ref, 128> def_vec;
      51              :   auto_vec<df_ref, 32> use_vec;
      52              :   auto_vec<df_ref, 32> eq_use_vec;
      53              :   auto_vec<df_mw_hardreg *, 32> mw_vec;
      54              : };
      55              : 
      56              : static void df_ref_record (enum df_ref_class, class df_collection_rec *,
      57              :                            rtx, rtx *,
      58              :                            basic_block, struct df_insn_info *,
      59              :                            enum df_ref_type, int ref_flags);
      60              : static void df_def_record_1 (class df_collection_rec *, rtx *,
      61              :                              basic_block, struct df_insn_info *,
      62              :                              int ref_flags);
      63              : static void df_defs_record (class df_collection_rec *, rtx,
      64              :                             basic_block, struct df_insn_info *,
      65              :                             int ref_flags);
      66              : static void df_uses_record (class df_collection_rec *,
      67              :                             rtx *, enum df_ref_type,
      68              :                             basic_block, struct df_insn_info *,
      69              :                             int ref_flags);
      70              : 
      71              : static void df_install_ref_incremental (df_ref);
      72              : static void df_insn_refs_collect (class df_collection_rec*,
      73              :                                   basic_block, struct df_insn_info *);
      74              : static void df_canonize_collection_rec (class df_collection_rec *);
      75              : 
      76              : static void df_get_regular_block_artificial_uses (bitmap);
      77              : static void df_get_eh_block_artificial_uses (bitmap);
      78              : 
      79              : static void df_record_entry_block_defs (bitmap);
      80              : static void df_record_exit_block_uses (bitmap);
      81              : static void df_get_entry_block_def_set (bitmap);
      82              : static void df_grow_ref_info (struct df_ref_info *, unsigned int);
      83              : static void df_ref_chain_delete_du_chain (df_ref);
      84              : static void df_ref_chain_delete (df_ref);
      85              : 
      86              : static void df_refs_add_to_chains (class df_collection_rec *,
      87              :                                    basic_block, rtx_insn *, unsigned int);
      88              : 
      89              : static bool df_insn_refs_verify (class df_collection_rec *, basic_block,
      90              :                                  rtx_insn *, bool);
      91              : static void df_entry_block_defs_collect (class df_collection_rec *, bitmap);
      92              : static void df_exit_block_uses_collect (class df_collection_rec *, bitmap);
      93              : static void df_install_ref (df_ref, struct df_reg_info *,
      94              :                             struct df_ref_info *, bool);
      95              : 
      96              : static int df_ref_compare (df_ref, df_ref);
      97              : static int df_ref_ptr_compare (const void *, const void *);
      98              : static int df_mw_compare (const df_mw_hardreg *, const df_mw_hardreg *);
      99              : static int df_mw_ptr_compare (const void *, const void *);
     100              : 
     101              : static void df_insn_info_delete (unsigned int);
     102              : 
     103              : /* Indexed by hardware reg number, is true if that register is ever
     104              :    used in the current function.
     105              : 
     106              :    In df-scan.cc, this is set up to record the hard regs used
     107              :    explicitly.  Reload adds in the hard regs used for holding pseudo
     108              :    regs.  Final uses it to generate the code in the function prologue
     109              :    and epilogue to save and restore registers as needed.  */
     110              : 
     111              : static bool regs_ever_live[FIRST_PSEUDO_REGISTER];
     112              : 
     113              : /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
     114              : static const unsigned int copy_defs = 0x1;
     115              : static const unsigned int copy_uses = 0x2;
     116              : static const unsigned int copy_eq_uses = 0x4;
     117              : static const unsigned int copy_mw = 0x8;
     118              : static const unsigned int copy_all = copy_defs | copy_uses | copy_eq_uses
     119              : | copy_mw;
     120              : 
     121              : /*----------------------------------------------------------------------------
     122              :    SCANNING DATAFLOW PROBLEM
     123              : 
     124              :    There are several ways in which scanning looks just like the other
     125              :    dataflow problems.  It shares the all the mechanisms for local info
     126              :    as well as basic block info.  Where it differs is when and how often
     127              :    it gets run.  It also has no need for the iterative solver.
     128              : ----------------------------------------------------------------------------*/
     129              : 
     130              : /* Problem data for the scanning dataflow function.  */
     131              : struct df_scan_problem_data
     132              : {
     133              :   object_allocator<df_base_ref> *ref_base_pool;
     134              :   object_allocator<df_artificial_ref> *ref_artificial_pool;
     135              :   object_allocator<df_regular_ref> *ref_regular_pool;
     136              :   object_allocator<df_insn_info> *insn_pool;
     137              :   object_allocator<df_reg_info> *reg_pool;
     138              :   object_allocator<df_mw_hardreg> *mw_reg_pool;
     139              : 
     140              :   bitmap_obstack reg_bitmaps;
     141              :   bitmap_obstack insn_bitmaps;
     142              : };
     143              : 
     144              : /* Internal function to shut down the scanning problem.  */
     145              : static void
     146      3041716 : df_scan_free_internal (void)
     147              : {
     148      3041716 :   struct df_scan_problem_data *problem_data
     149      3041716 :     = (struct df_scan_problem_data *) df_scan->problem_data;
     150              : 
     151      3041716 :   free (df->def_info.refs);
     152      3041716 :   free (df->def_info.begin);
     153      3041716 :   free (df->def_info.count);
     154      3041716 :   memset (&df->def_info, 0, (sizeof (struct df_ref_info)));
     155              : 
     156      3041716 :   free (df->use_info.refs);
     157      3041716 :   free (df->use_info.begin);
     158      3041716 :   free (df->use_info.count);
     159      3041716 :   memset (&df->use_info, 0, (sizeof (struct df_ref_info)));
     160              : 
     161      3041716 :   free (df->def_regs);
     162      3041716 :   df->def_regs = NULL;
     163      3041716 :   free (df->use_regs);
     164      3041716 :   df->use_regs = NULL;
     165      3041716 :   free (df->eq_use_regs);
     166      3041716 :   df->eq_use_regs = NULL;
     167      3041716 :   df->regs_size = 0;
     168      3041716 :   DF_REG_SIZE (df) = 0;
     169              : 
     170      3041716 :   free (df->insns);
     171      3041716 :   df->insns = NULL;
     172      3041716 :   DF_INSN_SIZE () = 0;
     173              : 
     174      3041716 :   free (df_scan->block_info);
     175      3041716 :   df_scan->block_info = NULL;
     176      3041716 :   df_scan->block_info_size = 0;
     177              : 
     178      3041716 :   bitmap_clear (&df->hardware_regs_used);
     179      3041716 :   bitmap_clear (&df->regular_block_artificial_uses);
     180      3041716 :   bitmap_clear (&df->eh_block_artificial_uses);
     181      3041716 :   BITMAP_FREE (df->entry_block_defs);
     182      3041716 :   BITMAP_FREE (df->exit_block_uses);
     183      3041716 :   bitmap_clear (&df->insns_to_delete);
     184      3041716 :   bitmap_clear (&df->insns_to_rescan);
     185      3041716 :   bitmap_clear (&df->insns_to_notes_rescan);
     186              : 
     187      6083432 :   delete problem_data->ref_base_pool;
     188      6083432 :   delete problem_data->ref_artificial_pool;
     189      6083432 :   delete problem_data->ref_regular_pool;
     190      6083432 :   delete problem_data->insn_pool;
     191      6083432 :   delete problem_data->reg_pool;
     192      6083432 :   delete problem_data->mw_reg_pool;
     193      3041716 :   bitmap_obstack_release (&problem_data->reg_bitmaps);
     194      3041716 :   bitmap_obstack_release (&problem_data->insn_bitmaps);
     195      3041716 :   free (df_scan->problem_data);
     196      3041716 : }
     197              : 
     198              : 
     199              : /* Free basic block info.  */
     200              : 
     201              : static void
     202      6765419 : df_scan_free_bb_info (basic_block bb, void *vbb_info)
     203              : {
     204      6765419 :   struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
     205      6765419 :   unsigned int bb_index = bb->index;
     206      6765419 :   rtx_insn *insn;
     207              : 
     208      6765419 :   FOR_BB_INSNS (bb, insn)
     209            0 :     if (INSN_P (insn))
     210            0 :       df_insn_info_delete (INSN_UID (insn));
     211              : 
     212      6765419 :   if (bb_index < df_scan->block_info_size)
     213      6765419 :     bb_info = df_scan_get_bb_info (bb_index);
     214              : 
     215              :   /* Get rid of any artificial uses or defs.  */
     216      6765419 :   df_ref_chain_delete_du_chain (bb_info->artificial_defs);
     217      6765419 :   df_ref_chain_delete_du_chain (bb_info->artificial_uses);
     218     13530838 :   df_ref_chain_delete (bb_info->artificial_defs);
     219     13530838 :   df_ref_chain_delete (bb_info->artificial_uses);
     220      6765419 :   bb_info->artificial_defs = NULL;
     221      6765419 :   bb_info->artificial_uses = NULL;
     222      6765419 : }
     223              : 
     224              : 
     225              : /* Allocate the problem data for the scanning problem.  This should be
     226              :    called when the problem is created or when the entire function is to
     227              :    be rescanned.  */
     228              : void
     229      3041716 : df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
     230              : {
     231      3041716 :   struct df_scan_problem_data *problem_data;
     232      3041716 :   basic_block bb;
     233              : 
     234              :   /* Given the number of pools, this is really faster than tearing
     235              :      everything apart.  */
     236      3041716 :   if (df_scan->problem_data)
     237      1570351 :     df_scan_free_internal ();
     238              : 
     239      3041716 :   problem_data = XNEW (struct df_scan_problem_data);
     240      3041716 :   df_scan->problem_data = problem_data;
     241      3041716 :   df_scan->computed = true;
     242              : 
     243      6083432 :   problem_data->ref_base_pool = new object_allocator<df_base_ref>
     244      3041716 :     ("df_scan ref base");
     245      6083432 :   problem_data->ref_artificial_pool = new object_allocator<df_artificial_ref>
     246      3041716 :     ("df_scan ref artificial");
     247      6083432 :   problem_data->ref_regular_pool = new object_allocator<df_regular_ref>
     248      3041716 :     ("df_scan ref regular");
     249      6083432 :   problem_data->insn_pool = new object_allocator<df_insn_info>
     250      3041716 :     ("df_scan insn");
     251      6083432 :   problem_data->reg_pool = new object_allocator<df_reg_info>
     252      3041716 :     ("df_scan reg");
     253      6083432 :   problem_data->mw_reg_pool = new object_allocator<df_mw_hardreg>
     254      3041716 :     ("df_scan mw_reg");
     255              : 
     256      3041716 :   bitmap_obstack_initialize (&problem_data->reg_bitmaps);
     257      3041716 :   bitmap_obstack_initialize (&problem_data->insn_bitmaps);
     258              : 
     259      3041716 :   df_grow_reg_info ();
     260              : 
     261      3041716 :   df_grow_insn_info ();
     262      3041716 :   df_grow_bb_info (df_scan);
     263              : 
     264     39756197 :   FOR_ALL_BB_FN (bb, cfun)
     265              :     {
     266     36714481 :       unsigned int bb_index = bb->index;
     267     36714481 :       struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
     268     36714481 :       bb_info->artificial_defs = NULL;
     269     36714481 :       bb_info->artificial_uses = NULL;
     270              :     }
     271              : 
     272      3041716 :   bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps);
     273      3041716 :   bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps);
     274      3041716 :   bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps);
     275      3041716 :   df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
     276      3041716 :   df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
     277      3041716 :   bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps);
     278      3041716 :   bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps);
     279      3041716 :   bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps);
     280      3041716 :   df_scan->optional_p = false;
     281      3041716 : }
     282              : 
     283              : 
     284              : /* Free all of the data associated with the scan problem.  */
     285              : 
     286              : static void
     287      1471365 : df_scan_free (void)
     288              : {
     289      1471365 :   if (df_scan->problem_data)
     290      1471365 :     df_scan_free_internal ();
     291              : 
     292      1471365 :   if (df->blocks_to_analyze)
     293              :     {
     294            0 :       BITMAP_FREE (df->blocks_to_analyze);
     295            0 :       df->blocks_to_analyze = NULL;
     296              :     }
     297              : 
     298      1471365 :   free (df_scan);
     299      1471365 : }
     300              : 
     301              : /* Dump the preamble for DF_SCAN dump. */
     302              : static void
     303         3940 : df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
     304              : {
     305         3940 :   int i;
     306         3940 :   int dcount = 0;
     307         3940 :   int ucount = 0;
     308         3940 :   int ecount = 0;
     309         3940 :   int icount = 0;
     310         3940 :   int ccount = 0;
     311         3940 :   basic_block bb;
     312         3940 :   rtx_insn *insn;
     313              : 
     314         3940 :   fprintf (file, ";;  fully invalidated by EH \t");
     315         3940 :   df_print_regset
     316         3940 :     (file, bitmap_view<HARD_REG_SET> (eh_edge_abi.full_reg_clobbers ()));
     317         3940 :   fprintf (file, ";;  hardware regs used \t");
     318         3940 :   df_print_regset (file, &df->hardware_regs_used);
     319         3940 :   fprintf (file, ";;  regular block artificial uses \t");
     320         3940 :   df_print_regset (file, &df->regular_block_artificial_uses);
     321         3940 :   fprintf (file, ";;  eh block artificial uses \t");
     322         3940 :   df_print_regset (file, &df->eh_block_artificial_uses);
     323         3940 :   fprintf (file, ";;  entry block defs \t");
     324         3940 :   df_print_regset (file, df->entry_block_defs);
     325         3940 :   fprintf (file, ";;  exit block uses \t");
     326         3940 :   df_print_regset (file, df->exit_block_uses);
     327         3940 :   fprintf (file, ";;  regs ever live \t");
     328       370360 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     329       362480 :     if (df_regs_ever_live_p (i))
     330        20159 :       fprintf (file, " %d [%s]", i, reg_names[i]);
     331         3940 :   fprintf (file, "\n;;  ref usage \t");
     332              : 
     333       483601 :   for (i = 0; i < (int)df->regs_inited; i++)
     334       479661 :     if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i))
     335              :       {
     336       211217 :         const char * sep = "";
     337              : 
     338       211217 :         fprintf (file, "r%d={", i);
     339       211217 :         if (DF_REG_DEF_COUNT (i))
     340              :           {
     341       211205 :             fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
     342       211205 :             sep = ",";
     343       211205 :             dcount += DF_REG_DEF_COUNT (i);
     344              :           }
     345       211217 :         if (DF_REG_USE_COUNT (i))
     346              :           {
     347        51545 :             fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
     348        51545 :             sep = ",";
     349        51545 :             ucount += DF_REG_USE_COUNT (i);
     350              :           }
     351       211217 :         if (DF_REG_EQ_USE_COUNT (i))
     352              :           {
     353         2196 :             fprintf (file, "%s%de", sep, DF_REG_EQ_USE_COUNT (i));
     354         2196 :             ecount += DF_REG_EQ_USE_COUNT (i);
     355              :           }
     356       211217 :         fprintf (file, "} ");
     357              :       }
     358              : 
     359        29423 :   FOR_EACH_BB_FN (bb, cfun)
     360       194897 :     FOR_BB_INSNS (bb, insn)
     361       169414 :       if (INSN_P (insn))
     362              :         {
     363       116943 :           if (CALL_P (insn))
     364         6283 :             ccount++;
     365              :           else
     366       110660 :             icount++;
     367              :         }
     368              : 
     369         3940 :   fprintf (file, "\n;;    total ref usage %d{%dd,%du,%de}"
     370              :                  " in %d{%d regular + %d call} insns.\n",
     371         3940 :                  dcount + ucount + ecount, dcount, ucount, ecount,
     372              :                  icount + ccount, icount, ccount);
     373         3940 : }
     374              : 
     375              : /* Dump the bb_info for a given basic block. */
     376              : static void
     377         5480 : df_scan_start_block (basic_block bb, FILE *file)
     378              : {
     379         5480 :   struct df_scan_bb_info *bb_info
     380         5480 :     = df_scan_get_bb_info (bb->index);
     381              : 
     382         5480 :   if (bb_info)
     383              :     {
     384         5480 :       fprintf (file, ";; bb %d artificial_defs: ", bb->index);
     385         5480 :       df_refs_chain_dump (bb_info->artificial_defs, true, file);
     386         5480 :       fprintf (file, "\n;; bb %d artificial_uses: ", bb->index);
     387         5480 :       df_refs_chain_dump (bb_info->artificial_uses, true, file);
     388         5480 :       fprintf (file, "\n");
     389              :     }
     390              : #if 0
     391              :   {
     392              :     rtx_insn *insn;
     393              :     FOR_BB_INSNS (bb, insn)
     394              :       if (INSN_P (insn))
     395              :         df_insn_debug (insn, false, file);
     396              :   }
     397              : #endif
     398         5480 : }
     399              : 
     400              : static const struct df_problem problem_SCAN =
     401              : {
     402              :   DF_SCAN,                    /* Problem id.  */
     403              :   DF_NONE,                    /* Direction.  */
     404              :   df_scan_alloc,              /* Allocate the problem specific data.  */
     405              :   NULL,                       /* Reset global information.  */
     406              :   df_scan_free_bb_info,       /* Free basic block info.  */
     407              :   NULL,                       /* Local compute function.  */
     408              :   NULL,                       /* Init the solution specific data.  */
     409              :   NULL,                       /* Iterative solver.  */
     410              :   NULL,                       /* Confluence operator 0.  */
     411              :   NULL,                       /* Confluence operator n.  */
     412              :   NULL,                       /* Transfer function.  */
     413              :   NULL,                       /* Finalize function.  */
     414              :   df_scan_free,               /* Free all of the problem information.  */
     415              :   NULL,                       /* Remove this problem from the stack of dataflow problems.  */
     416              :   df_scan_start_dump,         /* Debugging.  */
     417              :   df_scan_start_block,        /* Debugging start block.  */
     418              :   NULL,                       /* Debugging end block.  */
     419              :   NULL,                       /* Debugging start insn.  */
     420              :   NULL,                       /* Debugging end insn.  */
     421              :   NULL,                       /* Incremental solution verify start.  */
     422              :   NULL,                       /* Incremental solution verify end.  */
     423              :   NULL,                       /* Dependent problem.  */
     424              :   sizeof (struct df_scan_bb_info),/* Size of entry of block_info array.  */
     425              :   TV_DF_SCAN,                 /* Timing variable.  */
     426              :   false                       /* Reset blocks on dropping out of blocks_to_analyze.  */
     427              : };
     428              : 
     429              : 
     430              : /* Create a new DATAFLOW instance and add it to an existing instance
     431              :    of DF.  The returned structure is what is used to get at the
     432              :    solution.  */
     433              : 
     434              : void
     435      1471365 : df_scan_add_problem (void)
     436              : {
     437      1471365 :   df_add_problem (&problem_SCAN);
     438      1471365 : }
     439              : 
     440              : 
     441              : /*----------------------------------------------------------------------------
     442              :    Storage Allocation Utilities
     443              : ----------------------------------------------------------------------------*/
     444              : 
     445              : 
     446              : /* First, grow the reg_info information.  If the current size is less than
     447              :    the number of pseudos, grow to 25% more than the number of
     448              :    pseudos.
     449              : 
     450              :    Second, assure that all of the slots up to max_reg_num have been
     451              :    filled with reg_info structures.  */
     452              : 
     453              : void
     454   1192584446 : df_grow_reg_info (void)
     455              : {
     456   1192584446 :   unsigned int max_reg = max_reg_num ();
     457   1192584446 :   unsigned int new_size = max_reg;
     458   1192584446 :   struct df_scan_problem_data *problem_data
     459   1192584446 :     = (struct df_scan_problem_data *) df_scan->problem_data;
     460   1192584446 :   unsigned int i;
     461              : 
     462   1192584446 :   if (df->regs_size < new_size)
     463              :     {
     464      3087625 :       new_size += new_size / 4;
     465      3087625 :       df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
     466      3087625 :       df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
     467      3087625 :       df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
     468              :                                     new_size);
     469      3087625 :       df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
     470      3087625 :       df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
     471      3087625 :       df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
     472      3087625 :       df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
     473      3087625 :       df->regs_size = new_size;
     474              :     }
     475              : 
     476   1631243889 :   for (i = df->regs_inited; i < max_reg; i++)
     477              :     {
     478    438659443 :       struct df_reg_info *reg_info;
     479              : 
     480              :       // TODO
     481    438659443 :       reg_info = problem_data->reg_pool->allocate ();
     482    438659443 :       memset (reg_info, 0, sizeof (struct df_reg_info));
     483    438659443 :       df->def_regs[i] = reg_info;
     484    438659443 :       reg_info = problem_data->reg_pool->allocate ();
     485    438659443 :       memset (reg_info, 0, sizeof (struct df_reg_info));
     486    438659443 :       df->use_regs[i] = reg_info;
     487    438659443 :       reg_info = problem_data->reg_pool->allocate ();
     488    438659443 :       memset (reg_info, 0, sizeof (struct df_reg_info));
     489    438659443 :       df->eq_use_regs[i] = reg_info;
     490    438659443 :       df->def_info.begin[i] = 0;
     491    438659443 :       df->def_info.count[i] = 0;
     492    438659443 :       df->use_info.begin[i] = 0;
     493    438659443 :       df->use_info.count[i] = 0;
     494              :     }
     495              : 
     496   1192584446 :   df->regs_inited = max_reg;
     497   1192584446 : }
     498              : 
     499              : 
     500              : /* Grow the ref information.  */
     501              : 
     502              : static void
     503      6010661 : df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
     504              : {
     505      6010661 :   if (ref_info->refs_size < new_size)
     506              :     {
     507      6010661 :       ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
     508      6010661 :       memset (ref_info->refs + ref_info->refs_size, 0,
     509      6010661 :               (new_size - ref_info->refs_size) *sizeof (df_ref));
     510      6010661 :       ref_info->refs_size = new_size;
     511              :     }
     512      6010661 : }
     513              : 
     514              : 
     515              : /* Check and grow the ref information if necessary.  This routine
     516              :    guarantees total_size + BITMAP_ADDEND amount of entries in refs
     517              :    array.  It updates ref_info->refs_size only and does not change
     518              :    ref_info->total_size.  */
     519              : 
     520              : static void
     521      7104332 : df_check_and_grow_ref_info (struct df_ref_info *ref_info,
     522              :                             unsigned bitmap_addend)
     523              : {
     524      7104332 :   if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
     525              :     {
     526      6010661 :       int new_size = ref_info->total_size + bitmap_addend;
     527      6010661 :       new_size += ref_info->total_size / 4;
     528      6010661 :       df_grow_ref_info (ref_info, new_size);
     529              :     }
     530      7104332 : }
     531              : 
     532              : 
     533              : /* Grow the ref information.  If the current size is less than the
     534              :    number of instructions, grow to 25% more than the number of
     535              :    instructions.  */
     536              : 
     537              : void
     538    447521823 : df_grow_insn_info (void)
     539              : {
     540    447521823 :   unsigned int new_size = get_max_uid () + 1;
     541    447521823 :   if (DF_INSN_SIZE () < new_size)
     542              :     {
     543      4313651 :       new_size += new_size / 4;
     544      4313651 :       df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
     545      4313651 :       memset (df->insns + df->insns_size, 0,
     546      4313651 :               (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
     547      4313651 :       DF_INSN_SIZE () = new_size;
     548              :     }
     549    447521823 : }
     550              : 
     551              : 
     552              : 
     553              : 
     554              : /*----------------------------------------------------------------------------
     555              :    PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
     556              : ----------------------------------------------------------------------------*/
     557              : 
     558              : /* Rescan all of the block_to_analyze or all of the blocks in the
     559              :    function if df_set_blocks if blocks_to_analyze is NULL;  */
     560              : 
     561              : void
     562      3041716 : df_scan_blocks (void)
     563              : {
     564      3041716 :   basic_block bb;
     565              : 
     566      3041716 :   df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
     567      3041716 :   df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
     568              : 
     569      3041716 :   df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses);
     570      3041716 :   df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses);
     571              : 
     572      3041716 :   bitmap_ior_into (&df->eh_block_artificial_uses,
     573      3041716 :                    &df->regular_block_artificial_uses);
     574              : 
     575              :   /* ENTRY and EXIT blocks have special defs/uses.  */
     576      3041716 :   df_get_entry_block_def_set (df->entry_block_defs);
     577      3041716 :   df_record_entry_block_defs (df->entry_block_defs);
     578      3041716 :   df_get_exit_block_use_set (df->exit_block_uses);
     579      3041716 :   df_record_exit_block_uses (df->exit_block_uses);
     580      3041716 :   df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK));
     581      3041716 :   df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
     582              : 
     583              :   /* Regular blocks */
     584     33672765 :   FOR_EACH_BB_FN (bb, cfun)
     585              :     {
     586     30631049 :       unsigned int bb_index = bb->index;
     587     30631049 :       df_bb_refs_record (bb_index, true);
     588              :     }
     589      3041716 : }
     590              : 
     591              : /* Create new refs under address LOC within INSN.  This function is
     592              :    only used externally.  REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
     593              :    depending on whether LOC is inside PATTERN (INSN) or a note.  */
     594              : 
     595              : void
     596            0 : df_uses_create (rtx *loc, rtx_insn *insn, int ref_flags)
     597              : {
     598            0 :   gcc_assert (!(ref_flags & ~DF_REF_IN_NOTE));
     599            0 :   df_uses_record (NULL, loc, DF_REF_REG_USE,
     600            0 :                   BLOCK_FOR_INSN (insn),
     601            0 :                   DF_INSN_INFO_GET (insn),
     602              :                   ref_flags);
     603            0 : }
     604              : 
     605              : static void
     606            0 : df_install_ref_incremental (df_ref ref)
     607              : {
     608            0 :   struct df_reg_info **reg_info;
     609            0 :   struct df_ref_info *ref_info;
     610            0 :   df_ref *ref_ptr;
     611            0 :   bool add_to_table;
     612              : 
     613            0 :   rtx_insn *insn = DF_REF_INSN (ref);
     614            0 :   basic_block bb = BLOCK_FOR_INSN (insn);
     615              : 
     616            0 :   if (DF_REF_REG_DEF_P (ref))
     617              :     {
     618            0 :       reg_info = df->def_regs;
     619            0 :       ref_info = &df->def_info;
     620            0 :       ref_ptr = &DF_INSN_DEFS (insn);
     621            0 :       add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
     622              :     }
     623            0 :   else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
     624              :     {
     625            0 :       reg_info = df->eq_use_regs;
     626            0 :       ref_info = &df->use_info;
     627            0 :       ref_ptr = &DF_INSN_EQ_USES (insn);
     628            0 :       switch (ref_info->ref_order)
     629              :         {
     630              :         case DF_REF_ORDER_UNORDERED_WITH_NOTES:
     631              :         case DF_REF_ORDER_BY_REG_WITH_NOTES:
     632              :         case DF_REF_ORDER_BY_INSN_WITH_NOTES:
     633              :           add_to_table = true;
     634              :           break;
     635              :         default:
     636              :           add_to_table = false;
     637              :           break;
     638              :         }
     639              :     }
     640              :   else
     641              :     {
     642            0 :       reg_info = df->use_regs;
     643            0 :       ref_info = &df->use_info;
     644            0 :       ref_ptr = &DF_INSN_USES (insn);
     645            0 :       add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
     646              :     }
     647              : 
     648              :   /* Do not add if ref is not in the right blocks.  */
     649            0 :   if (add_to_table && df->analyze_subset)
     650            0 :     add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
     651              : 
     652            0 :   df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
     653              : 
     654            0 :   if (add_to_table)
     655            0 :     switch (ref_info->ref_order)
     656              :       {
     657            0 :       case DF_REF_ORDER_UNORDERED_WITH_NOTES:
     658            0 :       case DF_REF_ORDER_BY_REG_WITH_NOTES:
     659            0 :       case DF_REF_ORDER_BY_INSN_WITH_NOTES:
     660            0 :         ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
     661            0 :         break;
     662            0 :       default:
     663            0 :         ref_info->ref_order = DF_REF_ORDER_UNORDERED;
     664            0 :         break;
     665              :       }
     666              : 
     667            0 :   while (*ref_ptr && df_ref_compare (*ref_ptr, ref) < 0)
     668            0 :     ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
     669              : 
     670            0 :   DF_REF_NEXT_LOC (ref) = *ref_ptr;
     671            0 :   *ref_ptr = ref;
     672              : 
     673              : #if 0
     674              :   if (dump_file)
     675              :     {
     676              :       fprintf (dump_file, "adding ref ");
     677              :       df_ref_debug (ref, dump_file);
     678              :     }
     679              : #endif
     680              :   /* By adding the ref directly, df_insn_rescan my not find any
     681              :      differences even though the block will have changed.  So we need
     682              :      to mark the block dirty ourselves.  */
     683            0 :   if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
     684            0 :     df_set_bb_dirty (bb);
     685            0 : }
     686              : 
     687              : 
     688              : 
     689              : /*----------------------------------------------------------------------------
     690              :    UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
     691              : ----------------------------------------------------------------------------*/
     692              : 
     693              : static void
     694   7812054904 : df_free_ref (df_ref ref)
     695              : {
     696   7812054904 :   struct df_scan_problem_data *problem_data
     697   7812054904 :     = (struct df_scan_problem_data *) df_scan->problem_data;
     698              : 
     699   7812054904 :   switch (DF_REF_CLASS (ref))
     700              :     {
     701   5874152365 :     case DF_REF_BASE:
     702   5874152365 :       problem_data->ref_base_pool->remove ((df_base_ref *) (ref));
     703   5874152365 :       break;
     704              : 
     705    366329351 :     case DF_REF_ARTIFICIAL:
     706    366329351 :       problem_data->ref_artificial_pool->remove
     707    366329351 :         ((df_artificial_ref *) (ref));
     708    366329351 :       break;
     709              : 
     710   1571573188 :     case DF_REF_REGULAR:
     711   1571573188 :       problem_data->ref_regular_pool->remove
     712   1571573188 :         ((df_regular_ref *) (ref));
     713   1571573188 :       break;
     714              :     }
     715   7812054904 : }
     716              : 
     717              : 
     718              : /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
     719              :    Also delete the def-use or use-def chain if it exists.  */
     720              : 
     721              : static void
     722    305852006 : df_reg_chain_unlink (df_ref ref)
     723              : {
     724    305852006 :   df_ref next = DF_REF_NEXT_REG (ref);
     725    305852006 :   df_ref prev = DF_REF_PREV_REG (ref);
     726    305852006 :   int id = DF_REF_ID (ref);
     727    305852006 :   struct df_reg_info *reg_info;
     728    305852006 :   df_ref *refs = NULL;
     729              : 
     730    305852006 :   if (DF_REF_REG_DEF_P (ref))
     731              :     {
     732    148597072 :       int regno = DF_REF_REGNO (ref);
     733    148597072 :       reg_info = DF_REG_DEF_GET (regno);
     734    148597072 :       refs = df->def_info.refs;
     735              :     }
     736              :   else
     737              :     {
     738    157254934 :       if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
     739              :         {
     740     11340281 :           reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
     741     11340281 :           switch (df->use_info.ref_order)
     742              :             {
     743            0 :             case DF_REF_ORDER_UNORDERED_WITH_NOTES:
     744            0 :             case DF_REF_ORDER_BY_REG_WITH_NOTES:
     745            0 :             case DF_REF_ORDER_BY_INSN_WITH_NOTES:
     746            0 :               refs = df->use_info.refs;
     747            0 :               break;
     748              :             default:
     749              :               break;
     750              :             }
     751              :         }
     752              :       else
     753              :         {
     754    145914653 :           reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
     755    145914653 :           refs = df->use_info.refs;
     756              :         }
     757              :     }
     758              : 
     759    294511725 :   if (refs)
     760              :     {
     761       971547 :       if (df->analyze_subset)
     762              :         {
     763       565275 :           if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
     764       313393 :             refs[id] = NULL;
     765              :         }
     766              :       else
     767       406272 :         refs[id] = NULL;
     768              :     }
     769              : 
     770              :   /* Delete any def-use or use-def chains that start here. It is
     771              :      possible that there is trash in this field.  This happens for
     772              :      insns that have been deleted when rescanning has been deferred
     773              :      and the chain problem has also been deleted.  The chain tear down
     774              :      code skips deleted insns.  */
     775    305852006 :   if (df_chain && DF_REF_CHAIN (ref))
     776            0 :     df_chain_unlink (ref);
     777              : 
     778    305852006 :   reg_info->n_refs--;
     779    305852006 :   if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
     780              :     {
     781     87946731 :       gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
     782     87946731 :       df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
     783              :     }
     784              : 
     785              :   /* Unlink from the reg chain.  If there is no prev, this is the
     786              :      first of the list.  If not, just join the next and prev.  */
     787    305852006 :   if (prev)
     788    207181401 :     DF_REF_NEXT_REG (prev) = next;
     789              :   else
     790              :     {
     791     98670605 :       gcc_assert (reg_info->reg_chain == ref);
     792     98670605 :       reg_info->reg_chain = next;
     793              :     }
     794    305852006 :   if (next)
     795    179927519 :     DF_REF_PREV_REG (next) = prev;
     796              : 
     797    305852006 :   df_free_ref (ref);
     798    305852006 : }
     799              : 
     800              : /* Initialize INSN_INFO to describe INSN.  */
     801              : 
     802              : static void
     803    464724790 : df_insn_info_init_fields (df_insn_info *insn_info, rtx_insn *insn)
     804              : {
     805    464724790 :   memset (insn_info, 0, sizeof (struct df_insn_info));
     806    464724790 :   insn_info->insn = insn;
     807            0 : }
     808              : 
     809              : /* Create the insn record for INSN.  If there was one there, zero it
     810              :    out.  */
     811              : 
     812              : struct df_insn_info *
     813    405774305 : df_insn_create_insn_record (rtx_insn *insn)
     814              : {
     815    405774305 :   struct df_scan_problem_data *problem_data
     816    405774305 :     = (struct df_scan_problem_data *) df_scan->problem_data;
     817    405774305 :   struct df_insn_info *insn_rec;
     818              : 
     819    405774305 :   df_grow_insn_info ();
     820    405774305 :   insn_rec = DF_INSN_INFO_GET (insn);
     821    405774305 :   if (!insn_rec)
     822              :     {
     823    405774305 :       insn_rec = problem_data->insn_pool->allocate ();
     824    405774305 :       DF_INSN_INFO_SET (insn, insn_rec);
     825              :     }
     826    405774305 :   df_insn_info_init_fields (insn_rec, insn);
     827    405774305 :   return insn_rec;
     828              : }
     829              : 
     830              : 
     831              : /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain.  */
     832              : 
     833              : static void
     834     20954038 : df_ref_chain_delete_du_chain (df_ref ref)
     835              : {
     836     80525263 :   for (; ref; ref = DF_REF_NEXT_LOC (ref))
     837              :     /* CHAIN is allocated by DF_CHAIN. So make sure to
     838              :        pass df_scan instance for the problem.  */
     839     59571225 :     if (DF_REF_CHAIN (ref))
     840       483924 :       df_chain_unlink (ref);
     841     20954038 : }
     842              : 
     843              : 
     844              : /* Delete all refs in the ref chain.  */
     845              : 
     846              : static void
     847    487950235 : df_ref_chain_delete (df_ref ref)
     848              : {
     849    487950235 :   df_ref next;
     850    787036822 :   for (; ref; ref = next)
     851              :     {
     852    305852006 :       next = DF_REF_NEXT_LOC (ref);
     853    305852006 :       df_reg_chain_unlink (ref);
     854              :     }
     855            0 : }
     856              : 
     857              : 
     858              : /* Delete the hardreg chain.  */
     859              : 
     860              : static void
     861    150778540 : df_mw_hardreg_chain_delete (struct df_mw_hardreg *hardregs)
     862              : {
     863    150778540 :   struct df_scan_problem_data *problem_data
     864    150778540 :     = (struct df_scan_problem_data *) df_scan->problem_data;
     865    150778540 :   df_mw_hardreg *next;
     866              : 
     867    153430646 :   for (; hardregs; hardregs = next)
     868              :     {
     869      2652106 :       next = DF_MWS_NEXT (hardregs);
     870      2652106 :       problem_data->mw_reg_pool->remove (hardregs);
     871              :     }
     872    150778540 : }
     873              : 
     874              : /* Remove the contents of INSN_INFO (but don't free INSN_INFO itself).  */
     875              : 
     876              : static void
     877    150640288 : df_insn_info_free_fields (df_insn_info *insn_info)
     878              : {
     879              :   /* In general, notes do not have the insn_info fields
     880              :      initialized.  However, combine deletes insns by changing them
     881              :      to notes.  How clever.  So we cannot just check if it is a
     882              :      valid insn before short circuiting this code, we need to see
     883              :      if we actually initialized it.  */
     884    150640288 :   df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
     885              : 
     886    150640288 :   if (df_chain)
     887              :     {
     888       618207 :       df_ref_chain_delete_du_chain (insn_info->defs);
     889       618207 :       df_ref_chain_delete_du_chain (insn_info->uses);
     890       618207 :       df_ref_chain_delete_du_chain (insn_info->eq_uses);
     891              :     }
     892              : 
     893    150640288 :   df_ref_chain_delete (insn_info->defs);
     894    150640288 :   df_ref_chain_delete (insn_info->uses);
     895    150640288 :   df_ref_chain_delete (insn_info->eq_uses);
     896    150640288 : }
     897              : 
     898              : /* Delete all of the refs information from the insn with UID.
     899              :    Internal helper for df_insn_delete, df_insn_rescan, and other
     900              :    df-scan routines that don't have to work in deferred mode
     901              :    and do not have to mark basic blocks for re-processing.  */
     902              : 
     903              : static void
     904    101465508 : df_insn_info_delete (unsigned int uid)
     905              : {
     906    101465508 :   struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
     907              : 
     908    101465508 :   bitmap_clear_bit (&df->insns_to_delete, uid);
     909    101465508 :   bitmap_clear_bit (&df->insns_to_rescan, uid);
     910    101465508 :   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
     911    101465508 :   if (insn_info)
     912              :     {
     913     91689803 :       struct df_scan_problem_data *problem_data
     914     91689803 :         = (struct df_scan_problem_data *) df_scan->problem_data;
     915              : 
     916     91689803 :       df_insn_info_free_fields (insn_info);
     917     91689803 :       problem_data->insn_pool->remove (insn_info);
     918     91689803 :       DF_INSN_UID_SET (uid, NULL);
     919              :     }
     920    101465508 : }
     921              : 
     922              : /* Delete all of the refs information from INSN, either right now
     923              :    or marked for later in deferred mode.  */
     924              : 
     925              : void
     926    107957362 : df_insn_delete (rtx_insn *insn)
     927              : {
     928    107957362 :   unsigned int uid;
     929    107957362 :   basic_block bb;
     930              : 
     931    107957362 :   gcc_checking_assert (INSN_P (insn));
     932              : 
     933    107957362 :   if (!df)
     934              :     return;
     935              : 
     936    101468337 :   uid = INSN_UID (insn);
     937    101468337 :   bb = BLOCK_FOR_INSN (insn);
     938              : 
     939              :   /* ??? bb can be NULL after pass_free_cfg.  At that point, DF should
     940              :      not exist anymore (as mentioned in df-core.cc: "The only requirement
     941              :      [for DF] is that there be a correct control flow graph."  Clearly
     942              :      that isn't the case after pass_free_cfg.  But DF is freed much later
     943              :      because some back-ends want to use DF info even though the CFG is
     944              :      already gone.  It's not clear to me whether that is safe, actually.
     945              :      In any case, we expect BB to be non-NULL at least up to register
     946              :      allocation, so disallow a non-NULL BB up to there.  Not perfect
     947              :      but better than nothing...  */
     948    101468337 :   gcc_checking_assert (bb != NULL || reload_completed);
     949              : 
     950    101468337 :   df_grow_bb_info (df_scan);
     951    101468337 :   df_grow_reg_info ();
     952              : 
     953              :   /* The block must be marked as dirty now, rather than later as in
     954              :      df_insn_rescan and df_notes_rescan because it may not be there at
     955              :      rescanning time and the mark would blow up.
     956              :      DEBUG_INSNs do not make a block's data flow solution dirty (at
     957              :      worst the LUIDs are no longer contiguous).  */
     958    101468337 :   if (bb != NULL && NONDEBUG_INSN_P (insn))
     959     51521218 :     df_set_bb_dirty (bb);
     960              : 
     961              :   /* The client has deferred rescanning.  */
     962    101468337 :   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
     963              :     {
     964      5141381 :       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
     965      5141381 :       if (insn_info)
     966              :         {
     967      5141381 :           bitmap_clear_bit (&df->insns_to_rescan, uid);
     968      5141381 :           bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
     969      5141381 :           bitmap_set_bit (&df->insns_to_delete, uid);
     970              :         }
     971      5141381 :       if (dump_file)
     972          672 :         fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
     973      5141381 :       return;
     974              :     }
     975              : 
     976     96326956 :   if (dump_file)
     977         1053 :     fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
     978              : 
     979     96326956 :   df_insn_info_delete (uid);
     980              : }
     981              : 
     982              : 
     983              : /* Free all of the refs and the mw_hardregs in COLLECTION_REC.  */
     984              : 
     985              : static void
     986   1108521286 : df_free_collection_rec (class df_collection_rec *collection_rec)
     987              : {
     988   1108521286 :   unsigned int ix;
     989   1108521286 :   struct df_scan_problem_data *problem_data
     990   1108521286 :     = (struct df_scan_problem_data *) df_scan->problem_data;
     991   1108521286 :   df_ref ref;
     992   1108521286 :   struct df_mw_hardreg *mw;
     993              : 
     994   7480564734 :   FOR_EACH_VEC_ELT (collection_rec->def_vec, ix, ref)
     995   6372043448 :     df_free_ref (ref);
     996   2220592921 :   FOR_EACH_VEC_ELT (collection_rec->use_vec, ix, ref)
     997   1112071635 :     df_free_ref (ref);
     998   1130227165 :   FOR_EACH_VEC_ELT (collection_rec->eq_use_vec, ix, ref)
     999     21705879 :     df_free_ref (ref);
    1000   1114244815 :   FOR_EACH_VEC_ELT (collection_rec->mw_vec, ix, mw)
    1001      5723529 :     problem_data->mw_reg_pool->remove (mw);
    1002              : 
    1003   1108521286 :   collection_rec->def_vec.release ();
    1004   1108521286 :   collection_rec->use_vec.release ();
    1005   1108521286 :   collection_rec->eq_use_vec.release ();
    1006   1108521286 :   collection_rec->mw_vec.release ();
    1007   1108521286 : }
    1008              : 
    1009              : /* Rescan INSN.  Return TRUE if the rescanning produced any changes.  */
    1010              : 
    1011              : bool
    1012   1053273390 : df_insn_rescan (rtx_insn *insn)
    1013              : {
    1014   1053273390 :   unsigned int uid = INSN_UID (insn);
    1015   1053273390 :   struct df_insn_info *insn_info = NULL;
    1016   1053273390 :   basic_block bb = BLOCK_FOR_INSN (insn);
    1017   1053273390 :   class df_collection_rec collection_rec;
    1018              : 
    1019   1053273390 :   if ((!df) || (!INSN_P (insn)))
    1020              :     return false;
    1021              : 
    1022   1022952518 :   if (!bb)
    1023              :     {
    1024           64 :       if (dump_file)
    1025            0 :         fprintf (dump_file, "no bb for insn with uid = %d.\n", uid);
    1026           64 :       return false;
    1027              :     }
    1028              : 
    1029              :   /* The client has disabled rescanning and plans to do it itself.  */
    1030   1022952454 :   if (df->changeable_flags & DF_NO_INSN_RESCAN)
    1031              :     return false;
    1032              : 
    1033   1009237461 :   df_grow_bb_info (df_scan);
    1034   1009237461 :   df_grow_reg_info ();
    1035              : 
    1036   1009237461 :   insn_info = DF_INSN_UID_SAFE_GET (uid);
    1037              : 
    1038              :   /* The client has deferred rescanning.  */
    1039   1009237461 :   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
    1040              :     {
    1041    574242963 :       if (!insn_info)
    1042              :         {
    1043      3255764 :           insn_info = df_insn_create_insn_record (insn);
    1044      3255764 :           insn_info->defs = 0;
    1045      3255764 :           insn_info->uses = 0;
    1046      3255764 :           insn_info->eq_uses = 0;
    1047      3255764 :           insn_info->mw_hardregs = 0;
    1048              :         }
    1049    574242963 :       if (dump_file)
    1050        10285 :         fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid);
    1051              : 
    1052    574242963 :       bitmap_clear_bit (&df->insns_to_delete, uid);
    1053    574242963 :       bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
    1054    574242963 :       bitmap_set_bit (&df->insns_to_rescan, INSN_UID (insn));
    1055    574242963 :       return false;
    1056              :     }
    1057              : 
    1058    434994498 :   bitmap_clear_bit (&df->insns_to_delete, uid);
    1059    434994498 :   bitmap_clear_bit (&df->insns_to_rescan, uid);
    1060    434994498 :   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
    1061    434994498 :   if (insn_info)
    1062              :     {
    1063    397588904 :       int luid;
    1064    397588904 :       bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false);
    1065              :       /* If there's no change, return false. */
    1066    397588904 :       if (the_same)
    1067              :         {
    1068    338638419 :           df_free_collection_rec (&collection_rec);
    1069    338638419 :           if (dump_file)
    1070         9383 :             fprintf (dump_file, "verify found no changes in insn with uid = %d.\n", uid);
    1071    338638419 :           return false;
    1072              :         }
    1073     58950485 :       if (dump_file)
    1074         5048 :         fprintf (dump_file, "rescanning insn with uid = %d.\n", uid);
    1075              : 
    1076              :       /* There's change - we need to delete the existing info.
    1077              :          Since the insn isn't moved, we can salvage its LUID.  */
    1078     58950485 :       luid = DF_INSN_LUID (insn);
    1079     58950485 :       df_insn_info_free_fields (insn_info);
    1080     58950485 :       df_insn_info_init_fields (insn_info, insn);
    1081     58950485 :       DF_INSN_LUID (insn) = luid;
    1082              :     }
    1083              :   else
    1084              :     {
    1085     37405594 :       struct df_insn_info *insn_info = df_insn_create_insn_record (insn);
    1086     37405594 :       df_insn_refs_collect (&collection_rec, bb, insn_info);
    1087     37405594 :       if (dump_file)
    1088         1205 :         fprintf (dump_file, "scanning new insn with uid = %d.\n", uid);
    1089              :     }
    1090              : 
    1091     96356079 :   df_refs_add_to_chains (&collection_rec, bb, insn, copy_all);
    1092     96356079 :   if (!DEBUG_INSN_P (insn))
    1093     90303800 :     df_set_bb_dirty (bb);
    1094              : 
    1095              :   return true;
    1096   1053273390 : }
    1097              : 
    1098              : /* Same as df_insn_rescan, but don't mark the basic block as
    1099              :    dirty.  */
    1100              : 
    1101              : bool
    1102       138252 : df_insn_rescan_debug_internal (rtx_insn *insn)
    1103              : {
    1104       138252 :   unsigned int uid = INSN_UID (insn);
    1105       138252 :   struct df_insn_info *insn_info;
    1106              : 
    1107       138252 :   gcc_assert (DEBUG_INSN_P (insn)
    1108              :               && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)));
    1109              : 
    1110       138252 :   if (!df)
    1111              :     return false;
    1112              : 
    1113       138252 :   insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
    1114       138252 :   if (!insn_info)
    1115              :     return false;
    1116              : 
    1117       138252 :   if (dump_file)
    1118            0 :     fprintf (dump_file, "deleting debug_insn with uid = %d.\n", uid);
    1119              : 
    1120       138252 :   bitmap_clear_bit (&df->insns_to_delete, uid);
    1121       138252 :   bitmap_clear_bit (&df->insns_to_rescan, uid);
    1122       138252 :   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
    1123              : 
    1124       138252 :   if (insn_info->defs == 0
    1125       138252 :       && insn_info->uses == 0
    1126            0 :       && insn_info->eq_uses == 0
    1127            0 :       && insn_info->mw_hardregs == 0)
    1128              :     return false;
    1129              : 
    1130       138252 :   df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
    1131              : 
    1132       138252 :   if (df_chain)
    1133              :     {
    1134       124203 :       df_ref_chain_delete_du_chain (insn_info->defs);
    1135       124203 :       df_ref_chain_delete_du_chain (insn_info->uses);
    1136       124203 :       df_ref_chain_delete_du_chain (insn_info->eq_uses);
    1137              :     }
    1138              : 
    1139       138252 :   df_ref_chain_delete (insn_info->defs);
    1140       138252 :   df_ref_chain_delete (insn_info->uses);
    1141       138252 :   df_ref_chain_delete (insn_info->eq_uses);
    1142              : 
    1143       138252 :   insn_info->defs = 0;
    1144       138252 :   insn_info->uses = 0;
    1145       138252 :   insn_info->eq_uses = 0;
    1146       138252 :   insn_info->mw_hardregs = 0;
    1147              : 
    1148       138252 :   return true;
    1149              : }
    1150              : 
    1151              : 
    1152              : /* Rescan all of the insns in the function.  Note that the artificial
    1153              :    uses and defs are not touched.  This function will destroy def-use
    1154              :    or use-def chains.  */
    1155              : 
    1156              : void
    1157        34835 : df_insn_rescan_all (void)
    1158              : {
    1159        34835 :   bool no_insn_rescan = false;
    1160        34835 :   bool defer_insn_rescan = false;
    1161        34835 :   basic_block bb;
    1162        34835 :   bitmap_iterator bi;
    1163        34835 :   unsigned int uid;
    1164              : 
    1165        34835 :   if (df->changeable_flags & DF_NO_INSN_RESCAN)
    1166              :     {
    1167            0 :       df_clear_flags (DF_NO_INSN_RESCAN);
    1168            0 :       no_insn_rescan = true;
    1169              :     }
    1170              : 
    1171        34835 :   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
    1172              :     {
    1173            0 :       df_clear_flags (DF_DEFER_INSN_RESCAN);
    1174            0 :       defer_insn_rescan = true;
    1175              :     }
    1176              : 
    1177        34835 :   auto_bitmap tmp (&df_bitmap_obstack);
    1178        34835 :   bitmap_copy (tmp, &df->insns_to_delete);
    1179        34835 :   EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
    1180              :     {
    1181            0 :       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
    1182            0 :       if (insn_info)
    1183            0 :         df_insn_info_delete (uid);
    1184              :     }
    1185              : 
    1186        34835 :   bitmap_clear (&df->insns_to_delete);
    1187        34835 :   bitmap_clear (&df->insns_to_rescan);
    1188        34835 :   bitmap_clear (&df->insns_to_notes_rescan);
    1189              : 
    1190      1259416 :   FOR_EACH_BB_FN (bb, cfun)
    1191              :     {
    1192      1224581 :       rtx_insn *insn;
    1193     13553398 :       FOR_BB_INSNS (bb, insn)
    1194              :         {
    1195     12328817 :           df_insn_rescan (insn);
    1196              :         }
    1197              :     }
    1198              : 
    1199        34835 :   if (no_insn_rescan)
    1200            0 :     df_set_flags (DF_NO_INSN_RESCAN);
    1201        34835 :   if (defer_insn_rescan)
    1202            0 :     df_set_flags (DF_DEFER_INSN_RESCAN);
    1203        34835 : }
    1204              : 
    1205              : 
    1206              : /* Process all of the deferred rescans or deletions.  */
    1207              : 
    1208              : void
    1209     87727683 : df_process_deferred_rescans (void)
    1210              : {
    1211     87727683 :   bool no_insn_rescan = false;
    1212     87727683 :   bool defer_insn_rescan = false;
    1213     87727683 :   bitmap_iterator bi;
    1214     87727683 :   unsigned int uid;
    1215              : 
    1216     87727683 :   if (df->changeable_flags & DF_NO_INSN_RESCAN)
    1217              :     {
    1218            0 :       df_clear_flags (DF_NO_INSN_RESCAN);
    1219            0 :       no_insn_rescan = true;
    1220              :     }
    1221              : 
    1222     87727683 :   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
    1223              :     {
    1224     11814501 :       df_clear_flags (DF_DEFER_INSN_RESCAN);
    1225     11814501 :       defer_insn_rescan = true;
    1226              :     }
    1227              : 
    1228     87727683 :   if (dump_file)
    1229         3401 :     fprintf (dump_file, "starting the processing of deferred insns\n");
    1230              : 
    1231     87727683 :   auto_bitmap tmp (&df_bitmap_obstack);
    1232     87727683 :   bitmap_copy (tmp, &df->insns_to_delete);
    1233     92866235 :   EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
    1234              :     {
    1235      5138552 :       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
    1236      5138552 :       if (insn_info)
    1237      5138552 :         df_insn_info_delete (uid);
    1238              :     }
    1239              : 
    1240     87727683 :   bitmap_copy (tmp, &df->insns_to_rescan);
    1241    377975650 :   EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
    1242              :     {
    1243    290247967 :       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
    1244    290247967 :       if (insn_info)
    1245    290247967 :         df_insn_rescan (insn_info->insn);
    1246              :     }
    1247              : 
    1248     87727683 :   bitmap_copy (tmp, &df->insns_to_notes_rescan);
    1249     87803013 :   EXECUTE_IF_SET_IN_BITMAP (tmp, 0, uid, bi)
    1250              :     {
    1251        75330 :       struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
    1252        75330 :       if (insn_info)
    1253        75330 :         df_notes_rescan (insn_info->insn);
    1254              :     }
    1255              : 
    1256     87727683 :   if (dump_file)
    1257         3401 :     fprintf (dump_file, "ending the processing of deferred insns\n");
    1258              : 
    1259     87727683 :   bitmap_clear (&df->insns_to_delete);
    1260     87727683 :   bitmap_clear (&df->insns_to_rescan);
    1261     87727683 :   bitmap_clear (&df->insns_to_notes_rescan);
    1262              : 
    1263     87727683 :   if (no_insn_rescan)
    1264            0 :     df_set_flags (DF_NO_INSN_RESCAN);
    1265     87727683 :   if (defer_insn_rescan)
    1266     11814501 :     df_set_flags (DF_DEFER_INSN_RESCAN);
    1267              : 
    1268              :   /* If someone changed regs_ever_live during this pass, fix up the
    1269              :      entry and exit blocks.  */
    1270     87727683 :   if (df->redo_entry_and_exit)
    1271              :     {
    1272       878100 :       df_update_entry_exit_and_calls ();
    1273       878100 :       df->redo_entry_and_exit = false;
    1274              :     }
    1275     87727683 : }
    1276              : 
    1277              : 
    1278              : /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
    1279              :    the uses if INCLUDE_USES. Include the eq_uses if
    1280              :    INCLUDE_EQ_USES.  */
    1281              : 
    1282              : static unsigned int
    1283      6009284 : df_count_refs (bool include_defs, bool include_uses,
    1284              :                bool include_eq_uses)
    1285              : {
    1286      6009284 :   unsigned int regno;
    1287      6009284 :   int size = 0;
    1288      6009284 :   unsigned int m = df->regs_inited;
    1289              : 
    1290   1457832861 :   for (regno = 0; regno < m; regno++)
    1291              :     {
    1292   1451823577 :       if (include_defs)
    1293   1451823577 :         size += DF_REG_DEF_COUNT (regno);
    1294   1451823577 :       if (include_uses)
    1295            0 :         size += DF_REG_USE_COUNT (regno);
    1296   1451823577 :       if (include_eq_uses)
    1297            0 :         size += DF_REG_EQ_USE_COUNT (regno);
    1298              :     }
    1299      6009284 :   return size;
    1300              : }
    1301              : 
    1302              : 
    1303              : /* Take build ref table for either the uses or defs from the reg-use
    1304              :    or reg-def chains.  This version processes the refs in reg order
    1305              :    which is likely to be best if processing the whole function.  */
    1306              : 
    1307              : static void
    1308      4705096 : df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info,
    1309              :                                   bool include_defs,
    1310              :                                   bool include_uses,
    1311              :                                   bool include_eq_uses)
    1312              : {
    1313      4705096 :   unsigned int m = df->regs_inited;
    1314      4705096 :   unsigned int regno;
    1315      4705096 :   unsigned int offset = 0;
    1316      4705096 :   unsigned int start;
    1317              : 
    1318      4705096 :   if (df->changeable_flags & DF_NO_HARD_REGS)
    1319              :     {
    1320        22385 :       start = FIRST_PSEUDO_REGISTER;
    1321        22385 :       memset (ref_info->begin, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
    1322        22385 :       memset (ref_info->count, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
    1323              :     }
    1324              :   else
    1325              :     start = 0;
    1326              : 
    1327      4705096 :   ref_info->total_size
    1328      4705096 :     = df_count_refs (include_defs, include_uses, include_eq_uses);
    1329              : 
    1330      4705096 :   df_check_and_grow_ref_info (ref_info, 1);
    1331              : 
    1332    676191083 :   for (regno = start; regno < m; regno++)
    1333              :     {
    1334    671485987 :       int count = 0;
    1335    671485987 :       ref_info->begin[regno] = offset;
    1336    671485987 :       if (include_defs)
    1337              :         {
    1338    671485987 :           df_ref ref = DF_REG_DEF_CHAIN (regno);
    1339   2692014896 :           while (ref)
    1340              :             {
    1341   2020528909 :               ref_info->refs[offset] = ref;
    1342   2020528909 :               DF_REF_ID (ref) = offset++;
    1343   2020528909 :               count++;
    1344   2020528909 :               ref = DF_REF_NEXT_REG (ref);
    1345   2020528909 :               gcc_checking_assert (offset < ref_info->refs_size);
    1346              :             }
    1347              :         }
    1348    671485987 :       if (include_uses)
    1349              :         {
    1350            0 :           df_ref ref = DF_REG_USE_CHAIN (regno);
    1351            0 :           while (ref)
    1352              :             {
    1353            0 :               ref_info->refs[offset] = ref;
    1354            0 :               DF_REF_ID (ref) = offset++;
    1355            0 :               count++;
    1356            0 :               ref = DF_REF_NEXT_REG (ref);
    1357            0 :               gcc_checking_assert (offset < ref_info->refs_size);
    1358              :             }
    1359              :         }
    1360    671485987 :       if (include_eq_uses)
    1361              :         {
    1362            0 :           df_ref ref = DF_REG_EQ_USE_CHAIN (regno);
    1363            0 :           while (ref)
    1364              :             {
    1365            0 :               ref_info->refs[offset] = ref;
    1366            0 :               DF_REF_ID (ref) = offset++;
    1367            0 :               count++;
    1368            0 :               ref = DF_REF_NEXT_REG (ref);
    1369            0 :               gcc_checking_assert (offset < ref_info->refs_size);
    1370              :             }
    1371              :         }
    1372    671485987 :       ref_info->count[regno] = count;
    1373              :     }
    1374              : 
    1375              :   /* The bitmap size is not decremented when refs are deleted.  So
    1376              :      reset it now that we have squished out all of the empty
    1377              :      slots.  */
    1378      4705096 :   ref_info->table_size = offset;
    1379      4705096 : }
    1380              : 
    1381              : 
    1382              : /* Take build ref table for either the uses or defs from the reg-use
    1383              :    or reg-def chains.  This version processes the refs in insn order
    1384              :    which is likely to be best if processing some segment of the
    1385              :    function.  */
    1386              : 
    1387              : static void
    1388      1304188 : df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
    1389              :                                    bool include_defs,
    1390              :                                    bool include_uses,
    1391              :                                    bool include_eq_uses)
    1392              : {
    1393      1304188 :   bitmap_iterator bi;
    1394      1304188 :   unsigned int bb_index;
    1395      1304188 :   unsigned int m = df->regs_inited;
    1396      1304188 :   unsigned int offset = 0;
    1397      1304188 :   unsigned int r;
    1398      1304188 :   unsigned int start
    1399      1304188 :     = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
    1400              : 
    1401      1304188 :   memset (ref_info->begin, 0, sizeof (int) * df->regs_inited);
    1402      1304188 :   memset (ref_info->count, 0, sizeof (int) * df->regs_inited);
    1403              : 
    1404      1304188 :   ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
    1405      1304188 :   df_check_and_grow_ref_info (ref_info, 1);
    1406              : 
    1407      9262062 :   EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
    1408              :     {
    1409      7957874 :       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
    1410      7957874 :       rtx_insn *insn;
    1411      7957874 :       df_ref def, use;
    1412              : 
    1413      7957874 :       if (include_defs)
    1414     15987477 :         FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
    1415              :           {
    1416        71729 :             unsigned int regno = DF_REF_REGNO (def);
    1417        71729 :             ref_info->count[regno]++;
    1418              :           }
    1419      7957874 :       if (include_uses)
    1420            0 :         FOR_EACH_ARTIFICIAL_USE (use, bb_index)
    1421              :           {
    1422            0 :             unsigned int regno = DF_REF_REGNO (use);
    1423            0 :             ref_info->count[regno]++;
    1424              :           }
    1425              : 
    1426     90018949 :       FOR_BB_INSNS (bb, insn)
    1427              :         {
    1428     82061075 :           if (INSN_P (insn))
    1429              :             {
    1430     68692572 :               struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
    1431              : 
    1432     68692572 :               if (include_defs)
    1433    221867268 :                 FOR_EACH_INSN_INFO_DEF (def, insn_info)
    1434              :                   {
    1435    153174696 :                     unsigned int regno = DF_REF_REGNO (def);
    1436    153174696 :                     ref_info->count[regno]++;
    1437              :                   }
    1438     68692572 :               if (include_uses)
    1439            0 :                 FOR_EACH_INSN_INFO_USE (use, insn_info)
    1440              :                   {
    1441            0 :                     unsigned int regno = DF_REF_REGNO (use);
    1442            0 :                     ref_info->count[regno]++;
    1443              :                   }
    1444     68692572 :               if (include_eq_uses)
    1445            0 :                 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
    1446              :                   {
    1447            0 :                     unsigned int regno = DF_REF_REGNO (use);
    1448            0 :                     ref_info->count[regno]++;
    1449              :                   }
    1450              :             }
    1451              :         }
    1452              :     }
    1453              : 
    1454    779582358 :   for (r = start; r < m; r++)
    1455              :     {
    1456    778278170 :       ref_info->begin[r] = offset;
    1457    778278170 :       offset += ref_info->count[r];
    1458    778278170 :       ref_info->count[r] = 0;
    1459              :     }
    1460              : 
    1461      9262062 :   EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
    1462              :     {
    1463      7957874 :       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
    1464      7957874 :       rtx_insn *insn;
    1465      7957874 :       df_ref def, use;
    1466              : 
    1467      7957874 :       if (include_defs)
    1468     15987477 :         FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
    1469              :           {
    1470        71729 :             unsigned int regno = DF_REF_REGNO (def);
    1471        71729 :             if (regno >= start)
    1472              :               {
    1473        71729 :                 unsigned int id
    1474        71729 :                   = ref_info->begin[regno] + ref_info->count[regno]++;
    1475        71729 :                 DF_REF_ID (def) = id;
    1476        71729 :                 ref_info->refs[id] = def;
    1477              :               }
    1478              :           }
    1479      7957874 :       if (include_uses)
    1480            0 :         FOR_EACH_ARTIFICIAL_USE (use, bb_index)
    1481              :           {
    1482            0 :             unsigned int regno = DF_REF_REGNO (def);
    1483            0 :             if (regno >= start)
    1484              :               {
    1485            0 :                 unsigned int id
    1486            0 :                   = ref_info->begin[regno] + ref_info->count[regno]++;
    1487            0 :                 DF_REF_ID (use) = id;
    1488            0 :                 ref_info->refs[id] = use;
    1489              :               }
    1490              :           }
    1491              : 
    1492     90018949 :       FOR_BB_INSNS (bb, insn)
    1493              :         {
    1494     82061075 :           if (INSN_P (insn))
    1495              :             {
    1496     68692572 :               struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
    1497              : 
    1498     68692572 :               if (include_defs)
    1499    221867268 :                 FOR_EACH_INSN_INFO_DEF (def, insn_info)
    1500              :                   {
    1501    153174696 :                     unsigned int regno = DF_REF_REGNO (def);
    1502    153174696 :                     if (regno >= start)
    1503              :                       {
    1504    153174696 :                         unsigned int id
    1505    153174696 :                           = ref_info->begin[regno] + ref_info->count[regno]++;
    1506    153174696 :                         DF_REF_ID (def) = id;
    1507    153174696 :                         ref_info->refs[id] = def;
    1508              :                       }
    1509              :                   }
    1510     68692572 :               if (include_uses)
    1511            0 :                 FOR_EACH_INSN_INFO_USE (use, insn_info)
    1512              :                   {
    1513            0 :                     unsigned int regno = DF_REF_REGNO (use);
    1514            0 :                     if (regno >= start)
    1515              :                       {
    1516            0 :                         unsigned int id
    1517            0 :                           = ref_info->begin[regno] + ref_info->count[regno]++;
    1518            0 :                         DF_REF_ID (use) = id;
    1519            0 :                         ref_info->refs[id] = use;
    1520              :                       }
    1521              :                   }
    1522     68692572 :               if (include_eq_uses)
    1523            0 :                 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
    1524              :                   {
    1525            0 :                     unsigned int regno = DF_REF_REGNO (use);
    1526            0 :                     if (regno >= start)
    1527              :                       {
    1528            0 :                         unsigned int id
    1529            0 :                           = ref_info->begin[regno] + ref_info->count[regno]++;
    1530            0 :                         DF_REF_ID (use) = id;
    1531            0 :                         ref_info->refs[id] = use;
    1532              :                       }
    1533              :                   }
    1534              :             }
    1535              :         }
    1536              :     }
    1537              : 
    1538              :   /* The bitmap size is not decremented when refs are deleted.  So
    1539              :      reset it now that we have squished out all of the empty
    1540              :      slots.  */
    1541              : 
    1542      1304188 :   ref_info->table_size = offset;
    1543      1304188 : }
    1544              : 
    1545              : /* Take build ref table for either the uses or defs from the reg-use
    1546              :    or reg-def chains.  */
    1547              : 
    1548              : static void
    1549      6009284 : df_reorganize_refs_by_reg (struct df_ref_info *ref_info,
    1550              :                            bool include_defs,
    1551              :                            bool include_uses,
    1552              :                            bool include_eq_uses)
    1553              : {
    1554      6009284 :   if (df->analyze_subset)
    1555      1304188 :     df_reorganize_refs_by_reg_by_insn (ref_info, include_defs,
    1556              :                                        include_uses, include_eq_uses);
    1557              :   else
    1558      4705096 :     df_reorganize_refs_by_reg_by_reg (ref_info, include_defs,
    1559              :                                        include_uses, include_eq_uses);
    1560      6009284 : }
    1561              : 
    1562              : 
    1563              : /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET.  */
    1564              : static unsigned int
    1565            0 : df_add_refs_to_table (unsigned int offset,
    1566              :                       struct df_ref_info *ref_info,
    1567              :                       df_ref ref)
    1568              : {
    1569            0 :   for (; ref; ref = DF_REF_NEXT_LOC (ref))
    1570            0 :     if (!(df->changeable_flags & DF_NO_HARD_REGS)
    1571            0 :         || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER))
    1572              :       {
    1573            0 :         ref_info->refs[offset] = ref;
    1574            0 :         DF_REF_ID (ref) = offset++;
    1575              :       }
    1576            0 :   return offset;
    1577              : }
    1578              : 
    1579              : 
    1580              : /* Count the number of refs in all of the insns of BB. Include the
    1581              :    defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
    1582              :    eq_uses if INCLUDE_EQ_USES.  */
    1583              : 
    1584              : static unsigned int
    1585            0 : df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset,
    1586              :                                struct df_ref_info *ref_info,
    1587              :                                bool include_defs, bool include_uses,
    1588              :                                bool include_eq_uses)
    1589              : {
    1590            0 :   rtx_insn *insn;
    1591              : 
    1592            0 :   if (include_defs)
    1593            0 :     offset = df_add_refs_to_table (offset, ref_info,
    1594            0 :                                    df_get_artificial_defs (bb->index));
    1595            0 :   if (include_uses)
    1596            0 :     offset = df_add_refs_to_table (offset, ref_info,
    1597            0 :                                    df_get_artificial_uses (bb->index));
    1598              : 
    1599            0 :   FOR_BB_INSNS (bb, insn)
    1600            0 :     if (INSN_P (insn))
    1601              :       {
    1602            0 :         unsigned int uid = INSN_UID (insn);
    1603            0 :         if (include_defs)
    1604            0 :           offset = df_add_refs_to_table (offset, ref_info,
    1605            0 :                                          DF_INSN_UID_DEFS (uid));
    1606            0 :         if (include_uses)
    1607            0 :           offset = df_add_refs_to_table (offset, ref_info,
    1608            0 :                                          DF_INSN_UID_USES (uid));
    1609            0 :         if (include_eq_uses)
    1610            0 :           offset = df_add_refs_to_table (offset, ref_info,
    1611            0 :                                          DF_INSN_UID_EQ_USES (uid));
    1612              :       }
    1613            0 :   return offset;
    1614              : }
    1615              : 
    1616              : 
    1617              : /* Organize the refs by insn into the table in REF_INFO.  If
    1618              :    blocks_to_analyze is defined, use that set, otherwise the entire
    1619              :    program.  Include the defs if INCLUDE_DEFS. Include the uses if
    1620              :    INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES.  */
    1621              : 
    1622              : static void
    1623            0 : df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
    1624              :                             bool include_defs, bool include_uses,
    1625              :                             bool include_eq_uses)
    1626              : {
    1627            0 :   basic_block bb;
    1628            0 :   unsigned int offset = 0;
    1629              : 
    1630            0 :   ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
    1631            0 :   df_check_and_grow_ref_info (ref_info, 1);
    1632            0 :   if (df->blocks_to_analyze)
    1633              :     {
    1634            0 :       bitmap_iterator bi;
    1635            0 :       unsigned int index;
    1636              : 
    1637            0 :       EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
    1638              :         {
    1639            0 :           offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun,
    1640              :                                                                       index),
    1641              :                                                   offset, ref_info,
    1642              :                                                   include_defs, include_uses,
    1643              :                                                   include_eq_uses);
    1644              :         }
    1645              : 
    1646            0 :       ref_info->table_size = offset;
    1647              :     }
    1648              :   else
    1649              :     {
    1650            0 :       FOR_ALL_BB_FN (bb, cfun)
    1651            0 :         offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info,
    1652              :                                                 include_defs, include_uses,
    1653              :                                                 include_eq_uses);
    1654            0 :       ref_info->table_size = offset;
    1655              :     }
    1656            0 : }
    1657              : 
    1658              : 
    1659              : /* If the use refs in DF are not organized, reorganize them.  */
    1660              : 
    1661              : void
    1662     42160707 : df_maybe_reorganize_use_refs (enum df_ref_order order)
    1663              : {
    1664     42160707 :   if (order == df->use_info.ref_order)
    1665              :     return;
    1666              : 
    1667            0 :   switch (order)
    1668              :     {
    1669            0 :     case DF_REF_ORDER_BY_REG:
    1670            0 :       df_reorganize_refs_by_reg (&df->use_info, false, true, false);
    1671            0 :       break;
    1672              : 
    1673            0 :     case DF_REF_ORDER_BY_REG_WITH_NOTES:
    1674            0 :       df_reorganize_refs_by_reg (&df->use_info, false, true, true);
    1675            0 :       break;
    1676              : 
    1677            0 :     case DF_REF_ORDER_BY_INSN:
    1678            0 :       df_reorganize_refs_by_insn (&df->use_info, false, true, false);
    1679            0 :       break;
    1680              : 
    1681            0 :     case DF_REF_ORDER_BY_INSN_WITH_NOTES:
    1682            0 :       df_reorganize_refs_by_insn (&df->use_info, false, true, true);
    1683            0 :       break;
    1684              : 
    1685            0 :     case DF_REF_ORDER_NO_TABLE:
    1686            0 :       free (df->use_info.refs);
    1687            0 :       df->use_info.refs = NULL;
    1688            0 :       df->use_info.refs_size = 0;
    1689            0 :       break;
    1690              : 
    1691            0 :     case DF_REF_ORDER_UNORDERED:
    1692            0 :     case DF_REF_ORDER_UNORDERED_WITH_NOTES:
    1693            0 :       gcc_unreachable ();
    1694            0 :       break;
    1695              :     }
    1696              : 
    1697            0 :   df->use_info.ref_order = order;
    1698              : }
    1699              : 
    1700              : 
    1701              : /* If the def refs in DF are not organized, reorganize them.  */
    1702              : 
    1703              : void
    1704     48169991 : df_maybe_reorganize_def_refs (enum df_ref_order order)
    1705              : {
    1706     48169991 :   if (order == df->def_info.ref_order)
    1707              :     return;
    1708              : 
    1709     12018568 :   switch (order)
    1710              :     {
    1711      6009284 :     case DF_REF_ORDER_BY_REG:
    1712      6009284 :       df_reorganize_refs_by_reg (&df->def_info, true, false, false);
    1713      6009284 :       break;
    1714              : 
    1715            0 :     case DF_REF_ORDER_BY_INSN:
    1716            0 :       df_reorganize_refs_by_insn (&df->def_info, true, false, false);
    1717            0 :       break;
    1718              : 
    1719      6009284 :     case DF_REF_ORDER_NO_TABLE:
    1720      6009284 :       free (df->def_info.refs);
    1721      6009284 :       df->def_info.refs = NULL;
    1722      6009284 :       df->def_info.refs_size = 0;
    1723      6009284 :       break;
    1724              : 
    1725            0 :     case DF_REF_ORDER_BY_INSN_WITH_NOTES:
    1726            0 :     case DF_REF_ORDER_BY_REG_WITH_NOTES:
    1727            0 :     case DF_REF_ORDER_UNORDERED:
    1728            0 :     case DF_REF_ORDER_UNORDERED_WITH_NOTES:
    1729            0 :       gcc_unreachable ();
    1730     12018568 :       break;
    1731              :     }
    1732              : 
    1733     12018568 :   df->def_info.ref_order = order;
    1734              : }
    1735              : 
    1736              : 
    1737              : /* Change all of the basic block references in INSN to use the insn's
    1738              :    current basic block.  This function is called from routines that move
    1739              :    instructions from one block to another.  */
    1740              : 
    1741              : void
    1742    291598527 : df_insn_change_bb (rtx_insn *insn, basic_block new_bb)
    1743              : {
    1744    291598527 :   basic_block old_bb = BLOCK_FOR_INSN (insn);
    1745    291598527 :   struct df_insn_info *insn_info;
    1746    291598527 :   unsigned int uid = INSN_UID (insn);
    1747              : 
    1748    291598527 :   if (old_bb == new_bb)
    1749              :     return;
    1750              : 
    1751    258832661 :   set_block_for_insn (insn, new_bb);
    1752              : 
    1753    258832661 :   if (!df)
    1754              :     return;
    1755              : 
    1756     31415632 :   if (dump_file)
    1757         5864 :     fprintf (dump_file, "changing bb of uid %d\n", uid);
    1758              : 
    1759     31415632 :   insn_info = DF_INSN_UID_SAFE_GET (uid);
    1760     31236964 :   if (insn_info == NULL)
    1761              :     {
    1762     12003310 :       if (dump_file)
    1763         5541 :         fprintf (dump_file, "  unscanned insn\n");
    1764     12003310 :       df_insn_rescan (insn);
    1765     12003310 :       return;
    1766              :     }
    1767              : 
    1768     19412322 :   if (!INSN_P (insn))
    1769              :     return;
    1770              : 
    1771     17269653 :   if (!DEBUG_INSN_P (insn))
    1772     13613801 :     df_set_bb_dirty (new_bb);
    1773     17269653 :   if (old_bb)
    1774              :     {
    1775     17264782 :       if (dump_file)
    1776          288 :         fprintf (dump_file, "  from %d to %d\n",
    1777              :                  old_bb->index, new_bb->index);
    1778     17264782 :       if (!DEBUG_INSN_P (insn))
    1779     13608974 :         df_set_bb_dirty (old_bb);
    1780              :     }
    1781              :   else
    1782         4871 :     if (dump_file)
    1783            0 :       fprintf (dump_file, "  to %d\n", new_bb->index);
    1784              : }
    1785              : 
    1786              : 
    1787              : /* Helper function for df_ref_change_reg_with_loc.  */
    1788              : 
    1789              : static void
    1790    104735199 : df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df,
    1791              :                               struct df_reg_info *new_df,
    1792              :                               unsigned int new_regno, rtx loc)
    1793              : {
    1794    104735199 :   df_ref the_ref = old_df->reg_chain;
    1795              : 
    1796    195499305 :   while (the_ref)
    1797              :     {
    1798     90764106 :       if ((!DF_REF_IS_ARTIFICIAL (the_ref))
    1799     90764106 :           && DF_REF_LOC (the_ref)
    1800     90764106 :           && (*DF_REF_LOC (the_ref) == loc))
    1801              :         {
    1802     84107157 :           df_ref next_ref = DF_REF_NEXT_REG (the_ref);
    1803     84107157 :           df_ref prev_ref = DF_REF_PREV_REG (the_ref);
    1804     84107157 :           df_ref *ref_ptr;
    1805     84107157 :           struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref);
    1806              : 
    1807     84107157 :           DF_REF_REGNO (the_ref) = new_regno;
    1808     84107157 :           DF_REF_REG (the_ref) = regno_reg_rtx[new_regno];
    1809              : 
    1810              :           /* Pull the_ref out of the old regno chain.  */
    1811     84107157 :           if (prev_ref)
    1812      2598264 :             DF_REF_NEXT_REG (prev_ref) = next_ref;
    1813              :           else
    1814     81508893 :             old_df->reg_chain = next_ref;
    1815     84107157 :           if (next_ref)
    1816     29326772 :             DF_REF_PREV_REG (next_ref) = prev_ref;
    1817     84107157 :           old_df->n_refs--;
    1818              : 
    1819              :           /* Put the ref into the new regno chain.  */
    1820     84107157 :           DF_REF_PREV_REG (the_ref) = NULL;
    1821     84107157 :           DF_REF_NEXT_REG (the_ref) = new_df->reg_chain;
    1822     84107157 :           if (new_df->reg_chain)
    1823     80283525 :             DF_REF_PREV_REG (new_df->reg_chain) = the_ref;
    1824     84107157 :           new_df->reg_chain = the_ref;
    1825     84107157 :           new_df->n_refs++;
    1826     84107157 :           if (DF_REF_BB (the_ref))
    1827     84107157 :             df_set_bb_dirty (DF_REF_BB (the_ref));
    1828              : 
    1829              :           /* Need to sort the record again that the ref was in because
    1830              :              the regno is a sorting key.  First, find the right
    1831              :              record.  */
    1832     84107157 :           if (DF_REF_REG_DEF_P (the_ref))
    1833     31898368 :             ref_ptr = &insn_info->defs;
    1834     52208789 :           else if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE)
    1835      1791193 :             ref_ptr = &insn_info->eq_uses;
    1836              :           else
    1837     50417596 :             ref_ptr = &insn_info->uses;
    1838     84107157 :           if (dump_file)
    1839         2322 :             fprintf (dump_file, "changing reg in insn %d\n",
    1840         2322 :                      DF_REF_INSN_UID (the_ref));
    1841              : 
    1842              :           /* Stop if we find the current reference or where the reference
    1843              :              needs to be.  */
    1844     91315486 :           while (*ref_ptr != the_ref && df_ref_compare (*ref_ptr, the_ref) < 0)
    1845      7208329 :             ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
    1846     84107157 :           if (*ref_ptr != the_ref)
    1847              :             {
    1848              :               /* The reference needs to be promoted up the list.  */
    1849     16186593 :               df_ref next = DF_REF_NEXT_LOC (the_ref);
    1850     16186593 :               DF_REF_NEXT_LOC (the_ref) = *ref_ptr;
    1851     16186593 :               *ref_ptr = the_ref;
    1852     33815076 :               do
    1853     33815076 :                 ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
    1854     33815076 :               while (*ref_ptr != the_ref);
    1855     16186593 :               *ref_ptr = next;
    1856              :             }
    1857     67920564 :           else if (DF_REF_NEXT_LOC (the_ref)
    1858     67920564 :                    && df_ref_compare (the_ref, DF_REF_NEXT_LOC (the_ref)) > 0)
    1859              :             {
    1860              :               /* The reference needs to be demoted down the list.  */
    1861            0 :               *ref_ptr = DF_REF_NEXT_LOC (the_ref);
    1862            0 :               do
    1863            0 :                 ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
    1864            0 :               while (*ref_ptr && df_ref_compare (the_ref, *ref_ptr) > 0);
    1865            0 :               DF_REF_NEXT_LOC (the_ref) = *ref_ptr;
    1866            0 :               *ref_ptr = the_ref;
    1867              :             }
    1868              : 
    1869              :           the_ref = next_ref;
    1870              :         }
    1871              :       else
    1872      6656949 :         the_ref = DF_REF_NEXT_REG (the_ref);
    1873              :     }
    1874    104735199 : }
    1875              : 
    1876              : 
    1877              : /* Change the regno of register LOC to NEW_REGNO and update the df
    1878              :    information accordingly.  Refs that do not match LOC are not changed
    1879              :    which means that artificial refs are not changed since they have no loc.
    1880              :    This call is to support the SET_REGNO macro. */
    1881              : 
    1882              : void
    1883     34911733 : df_ref_change_reg_with_loc (rtx loc, unsigned int new_regno)
    1884              : {
    1885     34911733 :   unsigned int old_regno = REGNO (loc);
    1886     34911733 :   if (old_regno == new_regno)
    1887              :     return;
    1888              : 
    1889     34911733 :   if (df)
    1890              :     {
    1891     34911733 :       df_grow_reg_info ();
    1892              : 
    1893     34911733 :       df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno),
    1894     34911733 :                                     DF_REG_DEF_GET (new_regno),
    1895              :                                     new_regno, loc);
    1896     34911733 :       df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno),
    1897     34911733 :                                     DF_REG_USE_GET (new_regno),
    1898              :                                     new_regno, loc);
    1899     34911733 :       df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno),
    1900     34911733 :                                     DF_REG_EQ_USE_GET (new_regno),
    1901              :                                     new_regno, loc);
    1902              :     }
    1903     34911733 :   set_mode_and_regno (loc, GET_MODE (loc), new_regno);
    1904              : }
    1905              : 
    1906              : 
    1907              : /* Delete the mw_hardregs that point into the eq_notes.  */
    1908              : 
    1909              : static void
    1910     16887807 : df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info)
    1911              : {
    1912     16887807 :   struct df_mw_hardreg **mw_ptr = &insn_info->mw_hardregs;
    1913     16887807 :   struct df_scan_problem_data *problem_data
    1914     16887807 :     = (struct df_scan_problem_data *) df_scan->problem_data;
    1915              : 
    1916     16905976 :   while (*mw_ptr)
    1917              :     {
    1918        18169 :       df_mw_hardreg *mw = *mw_ptr;
    1919        18169 :       if (mw->flags & DF_REF_IN_NOTE)
    1920              :         {
    1921            2 :           *mw_ptr = DF_MWS_NEXT (mw);
    1922            2 :           problem_data->mw_reg_pool->remove (mw);
    1923              :         }
    1924              :       else
    1925        18167 :         mw_ptr = &DF_MWS_NEXT (mw);
    1926              :     }
    1927     16887807 : }
    1928              : 
    1929              : 
    1930              : /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN.  */
    1931              : 
    1932              : void
    1933     44247918 : df_notes_rescan (rtx_insn *insn)
    1934              : {
    1935     44247918 :   struct df_insn_info *insn_info;
    1936     44247918 :   unsigned int uid = INSN_UID (insn);
    1937              : 
    1938     44247918 :   if (!df)
    1939              :     return;
    1940              : 
    1941              :   /* The client has disabled rescanning and plans to do it itself.  */
    1942     40299168 :   if (df->changeable_flags & DF_NO_INSN_RESCAN)
    1943              :     return;
    1944              : 
    1945              :   /* Do nothing if the insn hasn't been emitted yet.  */
    1946     40279893 :   if (!BLOCK_FOR_INSN (insn))
    1947              :     return;
    1948              : 
    1949     40264361 :   df_grow_bb_info (df_scan);
    1950     40264361 :   df_grow_reg_info ();
    1951              : 
    1952     40264361 :   insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
    1953              : 
    1954              :   /* The client has deferred rescanning.  */
    1955     40264361 :   if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
    1956              :     {
    1957     23376554 :       if (!insn_info)
    1958              :         {
    1959            0 :           insn_info = df_insn_create_insn_record (insn);
    1960            0 :           insn_info->defs = 0;
    1961            0 :           insn_info->uses = 0;
    1962            0 :           insn_info->eq_uses = 0;
    1963            0 :           insn_info->mw_hardregs = 0;
    1964              :         }
    1965              : 
    1966     23376554 :       bitmap_clear_bit (&df->insns_to_delete, uid);
    1967              :       /* If the insn is set to be rescanned, it does not need to also
    1968              :          be notes rescanned.  */
    1969     23376554 :       if (!bitmap_bit_p (&df->insns_to_rescan, uid))
    1970      2603854 :         bitmap_set_bit (&df->insns_to_notes_rescan, INSN_UID (insn));
    1971     23376554 :       return;
    1972              :     }
    1973              : 
    1974     16887807 :   bitmap_clear_bit (&df->insns_to_delete, uid);
    1975     16887807 :   bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
    1976              : 
    1977     16887807 :   if (insn_info)
    1978              :     {
    1979     16887807 :       basic_block bb = BLOCK_FOR_INSN (insn);
    1980     16887807 :       rtx note;
    1981     16887807 :       class df_collection_rec collection_rec;
    1982     16887807 :       unsigned int i;
    1983              : 
    1984     16887807 :       df_mw_hardreg_chain_delete_eq_uses (insn_info);
    1985     16887807 :       df_ref_chain_delete (insn_info->eq_uses);
    1986     16887807 :       insn_info->eq_uses = NULL;
    1987              : 
    1988              :       /* Process REG_EQUIV/REG_EQUAL notes */
    1989     38667714 :       for (note = REG_NOTES (insn); note;
    1990     21779907 :            note = XEXP (note, 1))
    1991              :         {
    1992     21779907 :           switch (REG_NOTE_KIND (note))
    1993              :             {
    1994     12127484 :             case REG_EQUIV:
    1995     12127484 :             case REG_EQUAL:
    1996     12127484 :               df_uses_record (&collection_rec,
    1997              :                               &XEXP (note, 0), DF_REF_REG_USE,
    1998              :                               bb, insn_info, DF_REF_IN_NOTE);
    1999     21779907 :             default:
    2000     21779907 :               break;
    2001              :             }
    2002              :         }
    2003              : 
    2004              :       /* Find some place to put any new mw_hardregs.  */
    2005     16887807 :       df_canonize_collection_rec (&collection_rec);
    2006     16887807 :       struct df_mw_hardreg **mw_ptr = &insn_info->mw_hardregs, *mw;
    2007     16887807 :       FOR_EACH_VEC_ELT (collection_rec.mw_vec, i, mw)
    2008              :         {
    2009            0 :           while (*mw_ptr && df_mw_compare (*mw_ptr, mw) < 0)
    2010            0 :             mw_ptr = &DF_MWS_NEXT (*mw_ptr);
    2011            0 :           DF_MWS_NEXT (mw) = *mw_ptr;
    2012            0 :           *mw_ptr = mw;
    2013            0 :           mw_ptr = &DF_MWS_NEXT (mw);
    2014              :         }
    2015     16887807 :       df_refs_add_to_chains (&collection_rec, bb, insn, copy_eq_uses);
    2016     16887807 :     }
    2017              :   else
    2018            0 :     df_insn_rescan (insn);
    2019              : 
    2020              : }
    2021              : 
    2022              : 
    2023              : /*----------------------------------------------------------------------------
    2024              :    Hard core instruction scanning code.  No external interfaces here,
    2025              :    just a lot of routines that look inside insns.
    2026              : ----------------------------------------------------------------------------*/
    2027              : 
    2028              : 
    2029              : /* Return true if the contents of two df_ref's are identical.
    2030              :    It ignores DF_REF_MARKER.  */
    2031              : 
    2032              : static bool
    2033   8201652978 : df_ref_equal_p (df_ref ref1, df_ref ref2)
    2034              : {
    2035   8201652978 :   if (!ref2)
    2036              :     return false;
    2037              : 
    2038   8201652978 :   if (ref1 == ref2)
    2039              :     return true;
    2040              : 
    2041   8201652978 :   if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)
    2042   8110600990 :       || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)
    2043   7602385450 :       || DF_REF_REG (ref1) != DF_REF_REG (ref2)
    2044   7601860545 :       || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)
    2045   7596696647 :       || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))
    2046   7596696647 :           != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)))
    2047   7594280479 :       || DF_REF_BB (ref1) != DF_REF_BB (ref2)
    2048  15795933457 :       || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2))
    2049              :     return false;
    2050              : 
    2051   7594280479 :   switch (DF_REF_CLASS (ref1))
    2052              :     {
    2053              :     case DF_REF_ARTIFICIAL:
    2054              :     case DF_REF_BASE:
    2055              :       return true;
    2056              : 
    2057   1426530272 :     case DF_REF_REGULAR:
    2058   1426530272 :       return DF_REF_LOC (ref1) == DF_REF_LOC (ref2);
    2059              : 
    2060            0 :     default:
    2061            0 :       gcc_unreachable ();
    2062              :     }
    2063              : }
    2064              : 
    2065              : 
    2066              : /* Compare REF1 and REF2 for sorting.  This is only called from places
    2067              :    where all of the refs are of the same type, in the same insn, and
    2068              :    have the same bb.  So these fields are not checked.  */
    2069              : 
    2070              : static int
    2071  11342875499 : df_ref_compare (df_ref ref1, df_ref ref2)
    2072              : {
    2073  11342875499 :   if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
    2074    760073377 :     return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
    2075              : 
    2076  10582802122 :   if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
    2077  10516649045 :     return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
    2078              : 
    2079     66153077 :   if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
    2080     14300741 :     return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
    2081              : 
    2082     51852336 :   if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
    2083       523524 :     return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
    2084              : 
    2085              :   /* Cannot look at the LOC field on artificial refs.  */
    2086     51328812 :   if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
    2087     51328812 :       && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
    2088     39278699 :     return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
    2089              : 
    2090     12050113 :   if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
    2091              :     {
    2092              :       /* If two refs are identical except that one of them has is from
    2093              :          a mw and one is not, we need to have the one with the mw
    2094              :          first.  */
    2095      9380814 :       if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) ==
    2096      9380814 :           DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG))
    2097      9380814 :         return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2);
    2098            0 :       else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG))
    2099              :         return -1;
    2100              :       else
    2101            0 :         return 1;
    2102              :     }
    2103              : 
    2104      2669299 :   return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
    2105              : }
    2106              : 
    2107              : /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2.  */
    2108              : 
    2109              : static int
    2110   3696833888 : df_ref_ptr_compare (const void *r1, const void *r2)
    2111              : {
    2112   3696833888 :   return df_ref_compare (*(const df_ref *) r1, *(const df_ref *) r2);
    2113              : }
    2114              : 
    2115              : /* Sort and compress a set of refs.  */
    2116              : 
    2117              : static void
    2118   4689888837 : df_sort_and_compress_refs (vec<df_ref, va_heap> *ref_vec)
    2119              : {
    2120   4689888837 :   unsigned int count;
    2121   4689888837 :   unsigned int i;
    2122   4689888837 :   unsigned int dist = 0;
    2123              : 
    2124   4689888837 :   count = ref_vec->length ();
    2125              : 
    2126              :   /* If there are 1 or 0 elements, there is nothing to do.  */
    2127   4689888113 :   if (count < 2)
    2128              :     return;
    2129    567210183 :   else if (count == 2)
    2130              :     {
    2131    347181869 :       df_ref r0 = (*ref_vec)[0];
    2132    347181869 :       df_ref r1 = (*ref_vec)[1];
    2133    347181869 :       if (df_ref_compare (r0, r1) > 0)
    2134    158931661 :         std::swap ((*ref_vec)[0], (*ref_vec)[1]);
    2135              :     }
    2136              :   else
    2137              :     {
    2138   7433041601 :       for (i = 0; i < count - 1; i++)
    2139              :         {
    2140   7267799153 :           df_ref r0 = (*ref_vec)[i];
    2141   7267799153 :           df_ref r1 = (*ref_vec)[i + 1];
    2142   7267799153 :           if (df_ref_compare (r0, r1) >= 0)
    2143              :             break;
    2144              :         }
    2145              :       /* If the array is already strictly ordered,
    2146              :          which is the most common case for large COUNT case
    2147              :          (which happens for CALL INSNs),
    2148              :          no need to sort and filter out duplicate.
    2149              :          Simply return the count.
    2150              :          Make sure DF_GET_ADD_REFS adds refs in the increasing order
    2151              :          of DF_REF_COMPARE.  */
    2152    220028314 :       if (i == count - 1)
    2153              :         return;
    2154     54785866 :       ref_vec->qsort (df_ref_ptr_compare);
    2155              :     }
    2156              : 
    2157   1388343596 :   for (i=0; i<count-dist; i++)
    2158              :     {
    2159              :       /* Find the next ref that is not equal to the current ref.  */
    2160    986757797 :       while (i + dist + 1 < count
    2161   1571547859 :              && df_ref_equal_p ((*ref_vec)[i],
    2162    584790062 :                                 (*ref_vec)[i + dist + 1]))
    2163              :         {
    2164       381936 :           df_free_ref ((*ref_vec)[i + dist + 1]);
    2165       381936 :           dist++;
    2166              :         }
    2167              :       /* Copy it down to the next position.  */
    2168    986375861 :       if (dist && i + dist + 1 < count)
    2169        94972 :         (*ref_vec)[i + 1] = (*ref_vec)[i + dist + 1];
    2170              :     }
    2171              : 
    2172    401967735 :   count -= dist;
    2173    401967735 :   ref_vec->truncate (count);
    2174              : }
    2175              : 
    2176              : 
    2177              : /* Return true if the contents of two df_ref's are identical.
    2178              :    It ignores DF_REF_MARKER.  */
    2179              : 
    2180              : static bool
    2181      6535224 : df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2)
    2182              : {
    2183      6535224 :   if (!mw2)
    2184              :     return false;
    2185      6535224 :   return (mw1 == mw2) ||
    2186      6535224 :     (mw1->mw_reg == mw2->mw_reg
    2187      6001079 :      && mw1->type == mw2->type
    2188      5751252 :      && mw1->flags == mw2->flags
    2189      5747960 :      && mw1->start_regno == mw2->start_regno
    2190      5747960 :      && mw1->end_regno == mw2->end_regno);
    2191              : }
    2192              : 
    2193              : 
    2194              : /* Compare MW1 and MW2 for sorting.  */
    2195              : 
    2196              : static int
    2197      1751821 : df_mw_compare (const df_mw_hardreg *mw1, const df_mw_hardreg *mw2)
    2198              : {
    2199      1751821 :   if (mw1->type != mw2->type)
    2200      1150712 :     return mw1->type - mw2->type;
    2201              : 
    2202       601109 :   if (mw1->flags != mw2->flags)
    2203        30288 :     return mw1->flags - mw2->flags;
    2204              : 
    2205       570821 :   if (mw1->start_regno != mw2->start_regno)
    2206       449524 :     return mw1->start_regno - mw2->start_regno;
    2207              : 
    2208       121297 :   if (mw1->end_regno != mw2->end_regno)
    2209            0 :     return mw1->end_regno - mw2->end_regno;
    2210              : 
    2211       121297 :   return mw1->mw_order - mw2->mw_order;
    2212              : }
    2213              : 
    2214              : /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2.  */
    2215              : 
    2216              : static int
    2217      1119379 : df_mw_ptr_compare (const void *m1, const void *m2)
    2218              : {
    2219      1119379 :   return df_mw_compare (*(const df_mw_hardreg *const *) m1,
    2220      1119379 :                         *(const df_mw_hardreg *const *) m2);
    2221              : }
    2222              : 
    2223              : /* Sort and compress a set of refs.  */
    2224              : 
    2225              : static void
    2226   1563296279 : df_sort_and_compress_mws (vec<df_mw_hardreg *, va_heap> *mw_vec)
    2227              : {
    2228   1563296279 :   unsigned int count;
    2229   1563296279 :   struct df_scan_problem_data *problem_data
    2230   1563296279 :     = (struct df_scan_problem_data *) df_scan->problem_data;
    2231   1563296279 :   unsigned int i;
    2232   1563296279 :   unsigned int dist = 0;
    2233              : 
    2234   1563296279 :   count = mw_vec->length ();
    2235   1563296279 :   if (count < 2)
    2236              :     return;
    2237       708617 :   else if (count == 2)
    2238              :     {
    2239       632442 :       struct df_mw_hardreg *m0 = (*mw_vec)[0];
    2240       632442 :       struct df_mw_hardreg *m1 = (*mw_vec)[1];
    2241       632442 :       if (df_mw_compare (m0, m1) > 0)
    2242              :         {
    2243       135948 :           struct df_mw_hardreg *tmp = (*mw_vec)[0];
    2244       135948 :           (*mw_vec)[0] = (*mw_vec)[1];
    2245       135948 :           (*mw_vec)[1] = tmp;
    2246              :         }
    2247              :     }
    2248              :   else
    2249        76175 :     mw_vec->qsort (df_mw_ptr_compare);
    2250              : 
    2251      2202459 :   for (i=0; i<count-dist; i++)
    2252              :     {
    2253              :       /* Find the next ref that is not equal to the current ref.  */
    2254      1518273 :       while (i + dist + 1 < count
    2255      1518273 :              && df_mw_equal_p ((*mw_vec)[i], (*mw_vec)[i + dist + 1]))
    2256              :         {
    2257        24431 :           problem_data->mw_reg_pool->remove ((*mw_vec)[i + dist + 1]);
    2258        24431 :           dist++;
    2259              :         }
    2260              :       /* Copy it down to the next position.  */
    2261      1493842 :       if (dist && i + dist + 1 < count)
    2262         4468 :         (*mw_vec)[i + 1] = (*mw_vec)[i + dist + 1];
    2263              :     }
    2264              : 
    2265       708617 :   count -= dist;
    2266       708617 :   mw_vec->truncate (count);
    2267              : }
    2268              : 
    2269              : 
    2270              : /* Sort and remove duplicates from the COLLECTION_REC.  */
    2271              : 
    2272              : static void
    2273   1563296279 : df_canonize_collection_rec (class df_collection_rec *collection_rec)
    2274              : {
    2275   1563296279 :   df_sort_and_compress_refs (&collection_rec->def_vec);
    2276   1563296279 :   df_sort_and_compress_refs (&collection_rec->use_vec);
    2277   1563296279 :   df_sort_and_compress_refs (&collection_rec->eq_use_vec);
    2278   1563296279 :   df_sort_and_compress_mws (&collection_rec->mw_vec);
    2279   1563296279 : }
    2280              : 
    2281              : 
    2282              : /* Add the new df_ref to appropriate reg_info/ref_info chains.  */
    2283              : 
    2284              : static void
    2285   1876711938 : df_install_ref (df_ref this_ref,
    2286              :                 struct df_reg_info *reg_info,
    2287              :                 struct df_ref_info *ref_info,
    2288              :                 bool add_to_table)
    2289              : {
    2290   1876711938 :   unsigned int regno = DF_REF_REGNO (this_ref);
    2291              :   /* Add the ref to the reg_{def,use,eq_use} chain.  */
    2292   1876711938 :   df_ref head = reg_info->reg_chain;
    2293              : 
    2294   1876711938 :   reg_info->reg_chain = this_ref;
    2295   1876711938 :   reg_info->n_refs++;
    2296              : 
    2297   1876711938 :   if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE))
    2298              :     {
    2299    355340110 :       gcc_assert (regno < FIRST_PSEUDO_REGISTER);
    2300    355340110 :       df->hard_regs_live_count[regno]++;
    2301              :     }
    2302              : 
    2303   1876711938 :   gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL
    2304              :                        && DF_REF_PREV_REG (this_ref) == NULL);
    2305              : 
    2306   1876711938 :   DF_REF_NEXT_REG (this_ref) = head;
    2307              : 
    2308              :   /* We cannot actually link to the head of the chain.  */
    2309   1876711938 :   DF_REF_PREV_REG (this_ref) = NULL;
    2310              : 
    2311   1876711938 :   if (head)
    2312   1525205118 :     DF_REF_PREV_REG (head) = this_ref;
    2313              : 
    2314   1876711938 :   if (add_to_table)
    2315              :     {
    2316      1095048 :       gcc_assert (ref_info->ref_order != DF_REF_ORDER_NO_TABLE);
    2317      1095048 :       df_check_and_grow_ref_info (ref_info, 1);
    2318      1095048 :       DF_REF_ID (this_ref) = ref_info->table_size;
    2319              :       /* Add the ref to the big array of defs.  */
    2320      1095048 :       ref_info->refs[ref_info->table_size] = this_ref;
    2321      1095048 :       ref_info->table_size++;
    2322              :     }
    2323              :   else
    2324   1875616890 :     DF_REF_ID (this_ref) = -1;
    2325              : 
    2326   1876711938 :   ref_info->total_size++;
    2327   1876711938 : }
    2328              : 
    2329              : 
    2330              : /* This function takes one of the groups of refs (defs, uses or
    2331              :    eq_uses) and installs the entire group into the insn.  It also adds
    2332              :    each of these refs into the appropriate chains.  */
    2333              : 
    2334              : static df_ref
    2335   1282021802 : df_install_refs (basic_block bb,
    2336              :                  const vec<df_ref, va_heap> *old_vec,
    2337              :                  struct df_reg_info **reg_info,
    2338              :                  struct df_ref_info *ref_info,
    2339              :                  bool is_notes)
    2340              : {
    2341   1282021802 :   unsigned int count = old_vec->length ();
    2342   1282021802 :   if (count)
    2343              :     {
    2344    515382946 :       bool add_to_table;
    2345    515382946 :       df_ref this_ref;
    2346    515382946 :       unsigned int ix;
    2347              : 
    2348    515382946 :       switch (ref_info->ref_order)
    2349              :         {
    2350            0 :         case DF_REF_ORDER_UNORDERED_WITH_NOTES:
    2351            0 :         case DF_REF_ORDER_BY_REG_WITH_NOTES:
    2352            0 :         case DF_REF_ORDER_BY_INSN_WITH_NOTES:
    2353            0 :           ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
    2354            0 :           add_to_table = true;
    2355            0 :           break;
    2356      1881951 :         case DF_REF_ORDER_UNORDERED:
    2357      1881951 :         case DF_REF_ORDER_BY_REG:
    2358      1881951 :         case DF_REF_ORDER_BY_INSN:
    2359      1881951 :           ref_info->ref_order = DF_REF_ORDER_UNORDERED;
    2360      1881951 :           add_to_table = !is_notes;
    2361      1881951 :           break;
    2362              :         default:
    2363              :           add_to_table = false;
    2364              :           break;
    2365              :         }
    2366              : 
    2367              :       /* Do not add if ref is not in the right blocks.  */
    2368      1881951 :       if (add_to_table && df->analyze_subset)
    2369      1323204 :         add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
    2370              : 
    2371   2392094884 :       FOR_EACH_VEC_ELT (*old_vec, ix, this_ref)
    2372              :         {
    2373   1876711938 :           DF_REF_NEXT_LOC (this_ref) = (ix + 1 < old_vec->length ()
    2374   1876711938 :                                         ? (*old_vec)[ix + 1]
    2375              :                                         : NULL);
    2376   1876711938 :           df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)],
    2377              :                           ref_info, add_to_table);
    2378              :         }
    2379    515382946 :       return (*old_vec)[0];
    2380              :     }
    2381              :   else
    2382              :     return 0;
    2383              : }
    2384              : 
    2385              : 
    2386              : /* This function takes the mws installs the entire group into the
    2387              :    insn.  */
    2388              : 
    2389              : static struct df_mw_hardreg *
    2390    389359623 : df_install_mws (const vec<df_mw_hardreg *, va_heap> *old_vec)
    2391              : {
    2392    389359623 :   unsigned int count = old_vec->length ();
    2393    389359623 :   if (count)
    2394              :     {
    2395      3210016 :       for (unsigned int i = 0; i < count - 1; i++)
    2396       292949 :         DF_MWS_NEXT ((*old_vec)[i]) = (*old_vec)[i + 1];
    2397      2917067 :       DF_MWS_NEXT ((*old_vec)[count - 1]) = 0;
    2398      2917067 :       return (*old_vec)[0];
    2399              :     }
    2400              :   else
    2401              :     return 0;
    2402              : }
    2403              : 
    2404              : 
    2405              : /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
    2406              :    chains and update other necessary information.  */
    2407              : 
    2408              : static void
    2409    454774993 : df_refs_add_to_chains (class df_collection_rec *collection_rec,
    2410              :                        basic_block bb, rtx_insn *insn, unsigned int flags)
    2411              : {
    2412    454774993 :   if (insn)
    2413              :     {
    2414    406247430 :       struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn);
    2415              :       /* If there is a vector in the collection rec, add it to the
    2416              :          insn.  A null rec is a signal that the caller will handle the
    2417              :          chain specially.  */
    2418    406247430 :       if (flags & copy_defs)
    2419              :         {
    2420    389359623 :           gcc_checking_assert (!insn_rec->defs);
    2421    389359623 :           insn_rec->defs
    2422    389359623 :             = df_install_refs (bb, &collection_rec->def_vec,
    2423              :                                df->def_regs,
    2424              :                                &df->def_info, false);
    2425              :         }
    2426    406247430 :       if (flags & copy_uses)
    2427              :         {
    2428    389359623 :           gcc_checking_assert (!insn_rec->uses);
    2429    389359623 :           insn_rec->uses
    2430    389359623 :             = df_install_refs (bb, &collection_rec->use_vec,
    2431              :                                df->use_regs,
    2432    389359623 :                                &df->use_info, false);
    2433              :         }
    2434    406247430 :       if (flags & copy_eq_uses)
    2435              :         {
    2436    406247430 :           gcc_checking_assert (!insn_rec->eq_uses);
    2437    406247430 :           insn_rec->eq_uses
    2438    406247430 :             = df_install_refs (bb, &collection_rec->eq_use_vec,
    2439              :                                df->eq_use_regs,
    2440    406247430 :                                &df->use_info, true);
    2441              :         }
    2442    406247430 :       if (flags & copy_mw)
    2443              :         {
    2444    389359623 :           gcc_checking_assert (!insn_rec->mw_hardregs);
    2445    389359623 :           insn_rec->mw_hardregs
    2446    389359623 :             = df_install_mws (&collection_rec->mw_vec);
    2447              :         }
    2448              :     }
    2449              :   else
    2450              :     {
    2451     48527563 :       struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
    2452              : 
    2453     48527563 :       gcc_checking_assert (!bb_info->artificial_defs);
    2454     48527563 :       bb_info->artificial_defs
    2455     48527563 :         = df_install_refs (bb, &collection_rec->def_vec,
    2456              :                            df->def_regs,
    2457              :                            &df->def_info, false);
    2458     48527563 :       gcc_checking_assert (!bb_info->artificial_uses);
    2459     48527563 :       bb_info->artificial_uses
    2460     48527563 :         = df_install_refs (bb, &collection_rec->use_vec,
    2461              :                            df->use_regs,
    2462     48527563 :                            &df->use_info, false);
    2463              :     }
    2464    454774993 : }
    2465              : 
    2466              : 
    2467              : /* Allocate a ref and initialize its fields.  */
    2468              : 
    2469              : static df_ref
    2470   9382914836 : df_ref_create_structure (enum df_ref_class cl,
    2471              :                          class df_collection_rec *collection_rec,
    2472              :                          rtx reg, rtx *loc,
    2473              :                          basic_block bb, struct df_insn_info *info,
    2474              :                          enum df_ref_type ref_type,
    2475              :                          int ref_flags)
    2476              : {
    2477   9382914836 :   const unsigned int regno
    2478   9382914836 :     = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
    2479   9382914836 :   struct df_scan_problem_data *problem_data
    2480   9382914836 :     = (struct df_scan_problem_data *) df_scan->problem_data;
    2481   9382914836 :   df_ref this_ref;
    2482              : 
    2483   9382914836 :   switch (cl)
    2484              :     {
    2485   6930833843 :     case DF_REF_BASE:
    2486   6930833843 :       this_ref = (df_ref) (problem_data->ref_base_pool->allocate ());
    2487   6930833843 :       gcc_checking_assert (loc == NULL);
    2488              :       break;
    2489              : 
    2490    512309640 :     case DF_REF_ARTIFICIAL:
    2491    512309640 :       this_ref = (df_ref) (problem_data->ref_artificial_pool->allocate ());
    2492    512309640 :       this_ref->artificial_ref.bb = bb;
    2493    512309640 :       gcc_checking_assert (loc == NULL);
    2494              :       break;
    2495              : 
    2496   1939771353 :     case DF_REF_REGULAR:
    2497   1939771353 :       this_ref = (df_ref) (problem_data->ref_regular_pool->allocate ());
    2498   1939771353 :       this_ref->regular_ref.loc = loc;
    2499   1939771353 :       gcc_checking_assert (loc);
    2500              :       break;
    2501              : 
    2502            0 :     default:
    2503            0 :       gcc_unreachable ();
    2504              :     }
    2505              : 
    2506   9382914836 :   DF_REF_CLASS (this_ref) = cl;
    2507   9382914836 :   DF_REF_ID (this_ref) = -1;
    2508   9382914836 :   DF_REF_REG (this_ref) = reg;
    2509   9382914836 :   DF_REF_REGNO (this_ref) = regno;
    2510   9382914836 :   DF_REF_TYPE (this_ref) = ref_type;
    2511   9382914836 :   DF_REF_INSN_INFO (this_ref) = info;
    2512   9382914836 :   DF_REF_CHAIN (this_ref) = NULL;
    2513   9382914836 :   DF_REF_FLAGS (this_ref) = ref_flags;
    2514   9382914836 :   DF_REF_NEXT_REG (this_ref) = NULL;
    2515   9382914836 :   DF_REF_PREV_REG (this_ref) = NULL;
    2516   9382914836 :   DF_REF_ORDER (this_ref) = df->ref_order++;
    2517              : 
    2518              :   /* We need to clear the DF_HARD_REG_LIVE bit because fwprop, and in the
    2519              :      future possibly other optimizations, sometimes create new refs using
    2520              :      live refs as the model.  */
    2521   9382914836 :   DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE);
    2522              : 
    2523              :   /* Now see if this ref really needs to have the bit set.  */
    2524   9382914836 :   if (regno < FIRST_PSEUDO_REGISTER
    2525   9382914836 :       && cl != DF_REF_ARTIFICIAL
    2526   8250031892 :       && !DEBUG_INSN_P (info->insn))
    2527              :     {
    2528   8183194009 :       if (ref_type == DF_REF_REG_DEF)
    2529              :         {
    2530   7344527861 :           if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER))
    2531    522543721 :             DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
    2532              :         }
    2533    838666148 :       else if (!(TEST_HARD_REG_BIT (elim_reg_set, regno)
    2534     86756197 :                  && (regno == FRAME_POINTER_REGNUM
    2535     86756197 :                      || regno == ARG_POINTER_REGNUM)))
    2536    751909951 :         DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
    2537              :     }
    2538              : 
    2539   9382914836 :   if (collection_rec)
    2540              :     {
    2541   9382914836 :       if (DF_REF_REG_DEF_P (this_ref))
    2542   7758610799 :         collection_rec->def_vec.safe_push (this_ref);
    2543   1624304037 :       else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE)
    2544     41373428 :         collection_rec->eq_use_vec.safe_push (this_ref);
    2545              :       else
    2546   1582930609 :         collection_rec->use_vec.safe_push (this_ref);
    2547              :     }
    2548              :   else
    2549            0 :     df_install_ref_incremental (this_ref);
    2550              : 
    2551   9382914836 :   return this_ref;
    2552              : }
    2553              : 
    2554              : 
    2555              : /* Create new references of type DF_REF_TYPE for each part of register REG
    2556              :    at address LOC within INSN of BB.  */
    2557              : 
    2558              : 
    2559              : static void
    2560   9373956860 : df_ref_record (enum df_ref_class cl,
    2561              :                class df_collection_rec *collection_rec,
    2562              :                rtx reg, rtx *loc,
    2563              :                basic_block bb, struct df_insn_info *insn_info,
    2564              :                enum df_ref_type ref_type,
    2565              :                int ref_flags)
    2566              : {
    2567   9373956860 :   unsigned int regno;
    2568              : 
    2569   9373956860 :   gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
    2570              : 
    2571   9373956860 :   regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
    2572   9373956860 :   if (regno < FIRST_PSEUDO_REGISTER)
    2573              :     {
    2574   8753383556 :       struct df_mw_hardreg *hardreg = NULL;
    2575   8753383556 :       struct df_scan_problem_data *problem_data
    2576   8753383556 :         = (struct df_scan_problem_data *) df_scan->problem_data;
    2577   8753383556 :       unsigned int i;
    2578   8753383556 :       unsigned int endregno;
    2579   8753383556 :       df_ref ref;
    2580              : 
    2581   8753383556 :       if (GET_CODE (reg) == SUBREG)
    2582              :         {
    2583       345194 :           int off = subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
    2584       172597 :                                          SUBREG_BYTE (reg), GET_MODE (reg));
    2585       172597 :           unsigned int nregno = regno + off;
    2586       172597 :           endregno = nregno + subreg_nregs (reg);
    2587       172597 :           if (off < 0 && regno < (unsigned) -off)
    2588              :             /* Deal with paradoxical SUBREGs on big endian where
    2589              :                in debug insns the hard reg number might be smaller
    2590              :                than -off, such as (subreg:DI (reg:SI 0 [+4 ]) 0));
    2591              :                RA decisions shouldn't be affected by debug insns
    2592              :                and so RA can decide to put pseudo into a hard reg
    2593              :                with small REGNO, even when it is referenced in
    2594              :                a paradoxical SUBREG in a debug insn.  */
    2595              :             regno = 0;
    2596              :           else
    2597       172597 :             regno = nregno;
    2598              :         }
    2599              :       else
    2600   8753210959 :         endregno = END_REGNO (reg);
    2601              : 
    2602              :       /*  If this is a multiword hardreg, we create some extra
    2603              :           datastructures that will enable us to easily build REG_DEAD
    2604              :           and REG_UNUSED notes.  */
    2605   8753383556 :       if (collection_rec
    2606   8753383556 :           && (endregno != regno + 1) && insn_info)
    2607              :         {
    2608              :           /* Sets to a subreg of a multiword register are partial.
    2609              :              Sets to a non-subreg of a multiword register are not.  */
    2610      8957976 :           if (GET_CODE (reg) == SUBREG)
    2611            0 :             ref_flags |= DF_REF_PARTIAL;
    2612      8957976 :           ref_flags |= DF_REF_MW_HARDREG;
    2613              : 
    2614      8957976 :           gcc_assert (regno < endregno);
    2615              : 
    2616      8957976 :           hardreg = problem_data->mw_reg_pool->allocate ();
    2617      8957976 :           hardreg->type = ref_type;
    2618      8957976 :           hardreg->flags = ref_flags;
    2619      8957976 :           hardreg->mw_reg = reg;
    2620      8957976 :           hardreg->start_regno = regno;
    2621      8957976 :           hardreg->end_regno = endregno - 1;
    2622      8957976 :           hardreg->mw_order = df->ref_order++;
    2623      8957976 :           collection_rec->mw_vec.safe_push (hardreg);
    2624              :         }
    2625              : 
    2626  17515725088 :       for (i = regno; i < endregno; i++)
    2627              :         {
    2628   8762341532 :           ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc,
    2629              :                                          bb, insn_info, ref_type, ref_flags);
    2630              : 
    2631   8762341532 :           gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i);
    2632              :         }
    2633              :     }
    2634              :   else
    2635              :     {
    2636    620573304 :       df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info,
    2637              :                                ref_type, ref_flags);
    2638              :     }
    2639   9373956860 : }
    2640              : 
    2641              : 
    2642              : /* Process all the registers defined in the rtx pointed by LOC.
    2643              :    Autoincrement/decrement definitions will be picked up by df_uses_record.
    2644              :    Any change here has to be matched in df_find_hard_reg_defs_1.  */
    2645              : 
    2646              : static void
    2647    954656583 : df_def_record_1 (class df_collection_rec *collection_rec,
    2648              :                  rtx *loc, basic_block bb, struct df_insn_info *insn_info,
    2649              :                  int flags)
    2650              : {
    2651    954656583 :   rtx dst = *loc;
    2652              : 
    2653              :   /* It is legal to have a set destination be a parallel. */
    2654    954656583 :   if (GET_CODE (dst) == PARALLEL)
    2655              :     {
    2656       159119 :       int i;
    2657       426550 :       for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
    2658              :         {
    2659       267431 :           rtx temp = XVECEXP (dst, 0, i);
    2660       267431 :           gcc_assert (GET_CODE (temp) == EXPR_LIST);
    2661       267431 :           df_def_record_1 (collection_rec, &XEXP (temp, 0),
    2662              :                            bb, insn_info, flags);
    2663              :         }
    2664              :       return;
    2665              :     }
    2666              : 
    2667    954497464 :   if (GET_CODE (dst) == STRICT_LOW_PART)
    2668              :     {
    2669       125967 :       flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;
    2670              : 
    2671       125967 :       loc = &XEXP (dst, 0);
    2672       125967 :       dst = *loc;
    2673              :     }
    2674              : 
    2675    954497464 :   if (GET_CODE (dst) == ZERO_EXTRACT)
    2676              :     {
    2677        70275 :       flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;
    2678              : 
    2679        70275 :       loc = &XEXP (dst, 0);
    2680        70275 :       dst = *loc;
    2681              :     }
    2682              : 
    2683              :   /* At this point if we do not have a reg or a subreg, just return.  */
    2684    954497464 :   if (REG_P (dst))
    2685              :     {
    2686    707028172 :       df_ref_record (DF_REF_REGULAR, collection_rec,
    2687              :                      dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
    2688              : 
    2689              :       /* We want to keep sp alive everywhere - by making all
    2690              :          writes to sp also use of sp. */
    2691    707028172 :       if (REGNO (dst) == STACK_POINTER_REGNUM)
    2692     24855129 :         df_ref_record (DF_REF_BASE, collection_rec,
    2693              :                        dst, NULL, bb, insn_info, DF_REF_REG_USE, flags);
    2694              :     }
    2695    247469292 :   else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
    2696              :     {
    2697      3144971 :       if (read_modify_subreg_p (dst))
    2698      1793134 :         flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;
    2699              : 
    2700      3144971 :       flags |= DF_REF_SUBREG;
    2701              : 
    2702      3144971 :       df_ref_record (DF_REF_REGULAR, collection_rec,
    2703              :                      dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
    2704              :     }
    2705              : }
    2706              : 
    2707              : 
    2708              : /* Process all the registers defined in the pattern rtx, X.  Any change
    2709              :    here has to be matched in df_find_hard_reg_defs.  */
    2710              : 
    2711              : static void
    2712   1660209530 : df_defs_record (class df_collection_rec *collection_rec,
    2713              :                 rtx x, basic_block bb, struct df_insn_info *insn_info,
    2714              :                 int flags)
    2715              : {
    2716   1660209530 :   RTX_CODE code = GET_CODE (x);
    2717   1660209530 :   int i;
    2718              : 
    2719   1660209530 :   switch (code)
    2720              :     {
    2721    830571463 :     case SET:
    2722    830571463 :       df_def_record_1 (collection_rec, &SET_DEST (x), bb, insn_info, flags);
    2723    830571463 :       break;
    2724              : 
    2725    123817689 :     case CLOBBER:
    2726    123817689 :       flags |= DF_REF_MUST_CLOBBER;
    2727    123817689 :       df_def_record_1 (collection_rec, &XEXP (x, 0), bb, insn_info, flags);
    2728    123817689 :       break;
    2729              : 
    2730            0 :     case COND_EXEC:
    2731            0 :       df_defs_record (collection_rec, COND_EXEC_CODE (x),
    2732              :                       bb, insn_info, DF_REF_CONDITIONAL);
    2733            0 :       break;
    2734              : 
    2735              :     case PARALLEL:
    2736    351126718 :       for (i = 0; i < XVECLEN (x, 0); i++)
    2737    236969423 :         df_defs_record (collection_rec, XVECEXP (x, 0, i),
    2738              :                         bb, insn_info, flags);
    2739              :       break;
    2740              :     default:
    2741              :       /* No DEFs to record in other cases */
    2742              :       break;
    2743              :     }
    2744   1660209530 : }
    2745              : 
    2746              : /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
    2747              :    destination of a set or clobber.  This has to match the logic in
    2748              :    df_defs_record_1.  */
    2749              : 
    2750              : static void
    2751     37119656 : df_find_hard_reg_defs_1 (rtx dst, HARD_REG_SET *defs)
    2752              : {
    2753              :   /* It is legal to have a set destination be a parallel. */
    2754     37119656 :   if (GET_CODE (dst) == PARALLEL)
    2755              :     {
    2756       159119 :       int i;
    2757       426550 :       for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
    2758              :         {
    2759       267431 :           rtx temp = XVECEXP (dst, 0, i);
    2760       267431 :           gcc_assert (GET_CODE (temp) == EXPR_LIST);
    2761       267431 :           df_find_hard_reg_defs_1 (XEXP (temp, 0), defs);
    2762              :         }
    2763              :       return;
    2764              :     }
    2765              : 
    2766     36960537 :   if (GET_CODE (dst) == STRICT_LOW_PART)
    2767            0 :       dst = XEXP (dst, 0);
    2768              : 
    2769     36960537 :   if (GET_CODE (dst) == ZERO_EXTRACT)
    2770            0 :       dst = XEXP (dst, 0);
    2771              : 
    2772              :   /* At this point if we do not have a reg or a subreg, just return.  */
    2773     36960537 :   if (REG_P (dst) && HARD_REGISTER_P (dst))
    2774     36960537 :     SET_HARD_REG_BIT (*defs, REGNO (dst));
    2775            0 :   else if (GET_CODE (dst) == SUBREG
    2776            0 :            && REG_P (SUBREG_REG (dst)) && HARD_REGISTER_P (dst))
    2777            0 :     SET_HARD_REG_BIT (*defs, REGNO (SUBREG_REG (dst)));
    2778              : }
    2779              : 
    2780              : /* Set bits in *DEFS for hard registers defined in the pattern X.  This
    2781              :    has to match the logic in df_defs_record.  */
    2782              : 
    2783              : static void
    2784     88979254 : df_find_hard_reg_defs (rtx x, HARD_REG_SET *defs)
    2785              : {
    2786     88979254 :   RTX_CODE code = GET_CODE (x);
    2787     88979254 :   int i;
    2788              : 
    2789     88979254 :   switch (code)
    2790              :     {
    2791     36814010 :     case SET:
    2792     36814010 :       df_find_hard_reg_defs_1 (SET_DEST (x), defs);
    2793     36814010 :       break;
    2794              : 
    2795        38215 :     case CLOBBER:
    2796        38215 :       df_find_hard_reg_defs_1 (XEXP (x, 0), defs);
    2797        38215 :       break;
    2798              : 
    2799            0 :     case COND_EXEC:
    2800            0 :       df_find_hard_reg_defs (COND_EXEC_CODE (x), defs);
    2801            0 :       break;
    2802              : 
    2803              :     case PARALLEL:
    2804      7235092 :       for (i = 0; i < XVECLEN (x, 0); i++)
    2805      4836133 :         df_find_hard_reg_defs (XVECEXP (x, 0, i), defs);
    2806              :       break;
    2807              :     default:
    2808              :       /* No DEFs to record in other cases */
    2809              :       break;
    2810              :     }
    2811     88979254 : }
    2812              : 
    2813              : 
    2814              : /* Process all the registers used in the rtx at address LOC.  */
    2815              : 
    2816              : static void
    2817   3627595717 : df_uses_record (class df_collection_rec *collection_rec,
    2818              :                 rtx *loc, enum df_ref_type ref_type,
    2819              :                 basic_block bb, struct df_insn_info *insn_info,
    2820              :                 int flags)
    2821              : {
    2822   5335680044 :   RTX_CODE code;
    2823   5335680044 :   rtx x;
    2824              : 
    2825   5335680044 :  retry:
    2826   5335680044 :   x = *loc;
    2827   5335680044 :   if (!x)
    2828              :     return;
    2829   5335680044 :   code = GET_CODE (x);
    2830   5335680044 :   switch (code)
    2831              :     {
    2832              :     case LABEL_REF:
    2833              :     case SYMBOL_REF:
    2834              :     case CONST:
    2835              :     CASE_CONST_ANY:
    2836              :     case PC:
    2837              :     case ADDR_VEC:
    2838              :     case ADDR_DIFF_VEC:
    2839              :       return;
    2840              : 
    2841    309240790 :     case CLOBBER:
    2842              :       /* If we are clobbering a MEM, mark any registers inside the address
    2843              :          as being used.  */
    2844    309240790 :       if (MEM_P (XEXP (x, 0)))
    2845      3885591 :         df_uses_record (collection_rec,
    2846              :                         &XEXP (XEXP (x, 0), 0),
    2847              :                         DF_REF_REG_MEM_STORE,
    2848              :                         bb, insn_info,
    2849              :                         flags);
    2850              : 
    2851              :       /* If we're clobbering a REG then we have a def so ignore.  */
    2852              :       return;
    2853              : 
    2854    284421225 :     case MEM:
    2855    284421225 :       df_uses_record (collection_rec,
    2856              :                       &XEXP (x, 0), DF_REF_REG_MEM_LOAD,
    2857              :                       bb, insn_info, flags & DF_REF_IN_NOTE);
    2858    284421225 :       return;
    2859              : 
    2860     14393356 :     case SUBREG:
    2861              :       /* While we're here, optimize this case.  */
    2862     14393356 :       flags |= DF_REF_PARTIAL;
    2863              :       /* In case the SUBREG is not of a REG, do not optimize.  */
    2864     14393356 :       if (!REG_P (SUBREG_REG (x)))
    2865              :         {
    2866       829735 :           loc = &SUBREG_REG (x);
    2867       829735 :           df_uses_record (collection_rec, loc, ref_type, bb, insn_info, flags);
    2868       829735 :           return;
    2869              :         }
    2870              :       /* Fall through */
    2871              : 
    2872   1195703063 :     case REG:
    2873   1195703063 :       df_ref_record (DF_REF_REGULAR, collection_rec,
    2874              :                      x, loc, bb, insn_info,
    2875              :                      ref_type, flags);
    2876   1195703063 :       return;
    2877              : 
    2878       403426 :     case SIGN_EXTRACT:
    2879       403426 :     case ZERO_EXTRACT:
    2880       403426 :       {
    2881       403426 :         df_uses_record (collection_rec,
    2882              :                         &XEXP (x, 1), ref_type, bb, insn_info, flags);
    2883       403426 :         df_uses_record (collection_rec,
    2884              :                         &XEXP (x, 2), ref_type, bb, insn_info, flags);
    2885              : 
    2886              :         /* If the parameters to the zero or sign extract are
    2887              :            constants, strip them off and recurse, otherwise there is
    2888              :            no information that we can gain from this operation.  */
    2889       403426 :         if (code == ZERO_EXTRACT)
    2890       370952 :           flags |= DF_REF_ZERO_EXTRACT;
    2891              :         else
    2892        32474 :           flags |= DF_REF_SIGN_EXTRACT;
    2893              : 
    2894       403426 :         df_uses_record (collection_rec,
    2895              :                         &XEXP (x, 0), ref_type, bb, insn_info, flags);
    2896       403426 :         return;
    2897              :       }
    2898    830571463 :       break;
    2899              : 
    2900    830571463 :     case SET:
    2901    830571463 :       {
    2902    830571463 :         rtx dst = SET_DEST (x);
    2903    830571463 :         gcc_assert (!(flags & DF_REF_IN_NOTE));
    2904    830571463 :         df_uses_record (collection_rec,
    2905              :                         &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags);
    2906              : 
    2907    830571463 :         switch (GET_CODE (dst))
    2908              :           {
    2909      3102017 :             case SUBREG:
    2910      3102017 :               if (read_modify_subreg_p (dst))
    2911              :                 {
    2912      1781405 :                   df_uses_record (collection_rec, &SUBREG_REG (dst),
    2913              :                                   DF_REF_REG_USE, bb, insn_info,
    2914              :                                   flags | DF_REF_READ_WRITE | DF_REF_SUBREG);
    2915      1781405 :                   break;
    2916              :                 }
    2917              :               /* Fall through.  */
    2918              :             case REG:
    2919              :             case PARALLEL:
    2920              :             case SCRATCH:
    2921              :             case PC:
    2922              :                 break;
    2923    136206151 :             case MEM:
    2924    136206151 :               df_uses_record (collection_rec, &XEXP (dst, 0),
    2925              :                               DF_REF_REG_MEM_STORE, bb, insn_info, flags);
    2926    136206151 :               break;
    2927       125967 :             case STRICT_LOW_PART:
    2928       125967 :               {
    2929       125967 :                 rtx *temp = &XEXP (dst, 0);
    2930              :                 /* A strict_low_part uses the whole REG and not just the
    2931              :                  SUBREG.  */
    2932       125967 :                 dst = XEXP (dst, 0);
    2933        38884 :                 df_uses_record (collection_rec,
    2934       125967 :                                 (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
    2935              :                                 DF_REF_REG_USE, bb, insn_info,
    2936              :                                 DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART);
    2937              :               }
    2938       125967 :               break;
    2939        70275 :             case ZERO_EXTRACT:
    2940        70275 :               {
    2941        70275 :                 df_uses_record (collection_rec, &XEXP (dst, 1),
    2942              :                                 DF_REF_REG_USE, bb, insn_info, flags);
    2943        70275 :                 df_uses_record (collection_rec, &XEXP (dst, 2),
    2944              :                                 DF_REF_REG_USE, bb, insn_info, flags);
    2945        70275 :                 if (GET_CODE (XEXP (dst,0)) == MEM)
    2946         6414 :                   df_uses_record (collection_rec, &XEXP (dst, 0),
    2947              :                                   DF_REF_REG_USE, bb, insn_info,
    2948              :                                   flags);
    2949              :                 else
    2950        63861 :                   df_uses_record (collection_rec, &XEXP (dst, 0),
    2951              :                                   DF_REF_REG_USE, bb, insn_info,
    2952              :                                   DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT);
    2953              :               }
    2954              :               break;
    2955              : 
    2956            0 :             default:
    2957            0 :               gcc_unreachable ();
    2958              :           }
    2959              :         return;
    2960              :       }
    2961              : 
    2962              :     case RETURN:
    2963              :     case SIMPLE_RETURN:
    2964              :       break;
    2965              : 
    2966      6609011 :     case ASM_OPERANDS:
    2967      6609011 :     case UNSPEC_VOLATILE:
    2968      6609011 :     case TRAP_IF:
    2969      6609011 :     case ASM_INPUT:
    2970      6609011 :       {
    2971              :         /* Traditional and volatile asm instructions must be
    2972              :            considered to use and clobber all hard registers, all
    2973              :            pseudo-registers and all of memory.  So must TRAP_IF and
    2974              :            UNSPEC_VOLATILE operations.
    2975              : 
    2976              :            Consider for instance a volatile asm that changes the fpu
    2977              :            rounding mode.  An insn should not be moved across this
    2978              :            even if it only uses pseudo-regs because it might give an
    2979              :            incorrectly rounded result.
    2980              : 
    2981              :            However, flow.c's liveness computation did *not* do this,
    2982              :            giving the reasoning as " ?!? Unfortunately, marking all
    2983              :            hard registers as live causes massive problems for the
    2984              :            register allocator and marking all pseudos as live creates
    2985              :            mountains of uninitialized variable warnings."
    2986              : 
    2987              :            In order to maintain the status quo with regard to liveness
    2988              :            and uses, we do what flow.c did and just mark any regs we
    2989              :            can find in ASM_OPERANDS as used.  In global asm insns are
    2990              :            scanned and regs_asm_clobbered is filled out.
    2991              : 
    2992              :            For all ASM_OPERANDS, we must traverse the vector of input
    2993              :            operands.  We cannot just fall through here since then we
    2994              :            would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
    2995              :            which do not indicate traditional asms unlike their normal
    2996              :            usage.  */
    2997      6609011 :         if (code == ASM_OPERANDS)
    2998              :           {
    2999              :             int j;
    3000              : 
    3001      2532535 :             for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
    3002      1227707 :               df_uses_record (collection_rec, &ASM_OPERANDS_INPUT (x, j),
    3003              :                               DF_REF_REG_USE, bb, insn_info, flags);
    3004              :             return;
    3005              :           }
    3006              :         break;
    3007              :       }
    3008              : 
    3009    433343459 :     case VAR_LOCATION:
    3010    433343459 :       df_uses_record (collection_rec,
    3011              :                       &PAT_VAR_LOCATION_LOC (x),
    3012              :                       DF_REF_REG_USE, bb, insn_info, flags);
    3013    433343459 :       return;
    3014              : 
    3015     24937171 :     case PRE_DEC:
    3016     24937171 :     case POST_DEC:
    3017     24937171 :     case PRE_INC:
    3018     24937171 :     case POST_INC:
    3019     24937171 :     case PRE_MODIFY:
    3020     24937171 :     case POST_MODIFY:
    3021     24937171 :       gcc_assert (!DEBUG_INSN_P (insn_info->insn));
    3022              :       /* Catch the def of the register being modified.  */
    3023     24937171 :       df_ref_record (DF_REF_REGULAR, collection_rec, XEXP (x, 0), &XEXP (x, 0),
    3024              :                      bb, insn_info,
    3025              :                      DF_REF_REG_DEF,
    3026              :                      flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY);
    3027              : 
    3028              :       /* ... Fall through to handle uses ...  */
    3029              : 
    3030              :     default:
    3031              :       break;
    3032              :     }
    3033              : 
    3034              :   /* Recursively scan the operands of this expression.  */
    3035   1173422777 :   {
    3036   1173422777 :     const char *fmt = GET_RTX_FORMAT (code);
    3037   1173422777 :     int i;
    3038              : 
    3039   2292611779 :     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    3040              :       {
    3041   1966206095 :         if (fmt[i] == 'e')
    3042              :           {
    3043              :             /* Tail recursive case: save a function call level.  */
    3044   1731007568 :             if (i == 0)
    3045              :               {
    3046    847017093 :                 loc = &XEXP (x, 0);
    3047    847017093 :                 goto retry;
    3048              :               }
    3049    883990475 :             df_uses_record (collection_rec, &XEXP (x, i), ref_type,
    3050              :                             bb, insn_info, flags);
    3051              :           }
    3052    235198527 :         else if (fmt[i] == 'E')
    3053              :           {
    3054              :             int j;
    3055    400438080 :             for (j = 0; j < XVECLEN (x, i); j++)
    3056    269080995 :               df_uses_record (collection_rec,
    3057              :                               &XVECEXP (x, i, j), ref_type,
    3058              :                               bb, insn_info, flags);
    3059              :           }
    3060              :       }
    3061              :   }
    3062              : 
    3063              :   return;
    3064              : }
    3065              : 
    3066              : 
    3067              : /* For all DF_REF_CONDITIONAL defs, add a corresponding uses.  */
    3068              : 
    3069              : static void
    3070            0 : df_get_conditional_uses (class df_collection_rec *collection_rec)
    3071              : {
    3072            0 :   unsigned int ix;
    3073            0 :   df_ref ref;
    3074              : 
    3075            0 :   FOR_EACH_VEC_ELT (collection_rec->def_vec, ix, ref)
    3076              :     {
    3077            0 :       if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL))
    3078              :         {
    3079            0 :           df_ref use;
    3080              : 
    3081            0 :           use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref),
    3082            0 :                                          DF_REF_LOC (ref), DF_REF_BB (ref),
    3083              :                                          DF_REF_INSN_INFO (ref), DF_REF_REG_USE,
    3084              :                                          DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL);
    3085            0 :           DF_REF_REGNO (use) = DF_REF_REGNO (ref);
    3086              :         }
    3087              :     }
    3088            0 : }
    3089              : 
    3090              : 
    3091              : /* Get call's extra defs and uses (track caller-saved registers). */
    3092              : 
    3093              : static void
    3094     84143121 : df_get_call_refs (class df_collection_rec *collection_rec,
    3095              :                   basic_block bb,
    3096              :                   struct df_insn_info *insn_info,
    3097              :                   int flags)
    3098              : {
    3099     84143121 :   rtx note;
    3100     84143121 :   bool is_sibling_call;
    3101     84143121 :   unsigned int i;
    3102     84143121 :   HARD_REG_SET defs_generated;
    3103              : 
    3104     84143121 :   CLEAR_HARD_REG_SET (defs_generated);
    3105     84143121 :   df_find_hard_reg_defs (PATTERN (insn_info->insn), &defs_generated);
    3106     84143121 :   is_sibling_call = SIBLING_CALL_P (insn_info->insn);
    3107     84143121 :   function_abi callee_abi = insn_callee_abi (insn_info->insn);
    3108              : 
    3109   7825310253 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3110              :     {
    3111   7741167132 :       if (i == STACK_POINTER_REGNUM
    3112   7741167132 :           && !FAKE_CALL_P (insn_info->insn))
    3113              :         /* The stack ptr is used (honorarily) by a CALL insn.  */
    3114     83977971 :         df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
    3115              :                        NULL, bb, insn_info, DF_REF_REG_USE,
    3116              :                        DF_REF_CALL_STACK_USAGE | flags);
    3117   7657189161 :       else if (global_regs[i])
    3118              :         {
    3119              :           /* Calls to const functions cannot access any global registers and
    3120              :              calls to pure functions cannot set them.  All other calls may
    3121              :              reference any of the global registers, so they are recorded as
    3122              :              used. */
    3123         1296 :           if (!RTL_CONST_CALL_P (insn_info->insn))
    3124              :             {
    3125         1296 :               df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
    3126              :                              NULL, bb, insn_info, DF_REF_REG_USE, flags);
    3127         1296 :               if (!RTL_PURE_CALL_P (insn_info->insn))
    3128         1161 :                 df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
    3129              :                                NULL, bb, insn_info, DF_REF_REG_DEF, flags);
    3130              :             }
    3131              :         }
    3132   7657187865 :       else if (callee_abi.clobbers_full_reg_p (i)
    3133              :                /* no clobbers for regs that are the result of the call */
    3134   6856750298 :                && !TEST_HARD_REG_BIT (defs_generated, i)
    3135  14479172005 :                && (!is_sibling_call
    3136    150784600 :                    || !bitmap_bit_p (df->exit_block_uses, i)
    3137        11463 :                    || refers_to_regno_p (i, crtl->return_rtx)))
    3138   6821984140 :           df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
    3139              :                          NULL, bb, insn_info, DF_REF_REG_DEF,
    3140              :                          DF_REF_MAY_CLOBBER | flags);
    3141              :     }
    3142              : 
    3143              :   /* Record the registers used to pass arguments, and explicitly
    3144              :      noted as clobbered.  */
    3145    262557470 :   for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note;
    3146    178414349 :        note = XEXP (note, 1))
    3147              :     {
    3148    178414349 :       if (GET_CODE (XEXP (note, 0)) == USE)
    3149    167593851 :         df_uses_record (collection_rec, &XEXP (XEXP (note, 0), 0),
    3150              :                         DF_REF_REG_USE, bb, insn_info, flags);
    3151     10820498 :       else if (GET_CODE (XEXP (note, 0)) == CLOBBER)
    3152              :         {
    3153      9029068 :           if (REG_P (XEXP (XEXP (note, 0), 0)))
    3154              :             {
    3155      9029068 :               unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
    3156      9029068 :               if (!TEST_HARD_REG_BIT (defs_generated, regno))
    3157      9028201 :                 df_defs_record (collection_rec, XEXP (note, 0), bb,
    3158              :                                 insn_info, flags);
    3159              :             }
    3160              :           else
    3161            0 :             df_uses_record (collection_rec, &XEXP (note, 0),
    3162              :                             DF_REF_REG_USE, bb, insn_info, flags);
    3163              :         }
    3164              :     }
    3165              : 
    3166     84143121 :   return;
    3167              : }
    3168              : 
    3169              : /* Collect all refs in the INSN. This function is free of any
    3170              :    side-effect - it will create and return a lists of df_ref's in the
    3171              :    COLLECTION_REC without putting those refs into existing ref chains
    3172              :    and reg chains. */
    3173              : 
    3174              : static void
    3175   1414211906 : df_insn_refs_collect (class df_collection_rec *collection_rec,
    3176              :                       basic_block bb, struct df_insn_info *insn_info)
    3177              : {
    3178   1414211906 :   rtx note;
    3179   1414211906 :   bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC);
    3180              : 
    3181              :   /* Clear out the collection record.  */
    3182   1414211906 :   collection_rec->def_vec.truncate (0);
    3183   1414211906 :   collection_rec->use_vec.truncate (0);
    3184   1414211906 :   collection_rec->eq_use_vec.truncate (0);
    3185   1414211906 :   collection_rec->mw_vec.truncate (0);
    3186              : 
    3187              :   /* Process REG_EQUIV/REG_EQUAL notes.  */
    3188   2049168674 :   for (note = REG_NOTES (insn_info->insn); note;
    3189    634956768 :        note = XEXP (note, 1))
    3190              :     {
    3191    634956768 :       switch (REG_NOTE_KIND (note))
    3192              :         {
    3193     47844434 :         case REG_EQUIV:
    3194     47844434 :         case REG_EQUAL:
    3195     47844434 :           df_uses_record (collection_rec,
    3196              :                           &XEXP (note, 0), DF_REF_REG_USE,
    3197              :                           bb, insn_info, DF_REF_IN_NOTE);
    3198     47844434 :           break;
    3199         7073 :         case REG_NON_LOCAL_GOTO:
    3200              :           /* The frame ptr is used by a non-local goto.  */
    3201         7073 :           df_ref_record (DF_REF_BASE, collection_rec,
    3202         7073 :                          regno_reg_rtx[FRAME_POINTER_REGNUM],
    3203              :                          NULL, bb, insn_info,
    3204              :                          DF_REF_REG_USE, 0);
    3205         7073 :           if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
    3206         7073 :             df_ref_record (DF_REF_BASE, collection_rec,
    3207         7073 :                            regno_reg_rtx[HARD_FRAME_POINTER_REGNUM],
    3208              :                            NULL, bb, insn_info,
    3209              :                            DF_REF_REG_USE, 0);
    3210         7073 :           break;
    3211              :         default:
    3212              :           break;
    3213              :         }
    3214              :     }
    3215              : 
    3216   1414211906 :   int flags = (is_cond_exec) ? DF_REF_CONDITIONAL : 0;
    3217              :   /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
    3218              :      uses from CALL_INSN_FUNCTION_USAGE. */
    3219   1414211906 :   if (CALL_P (insn_info->insn))
    3220     84143121 :     df_get_call_refs (collection_rec, bb, insn_info, flags);
    3221              : 
    3222              :   /* Record other defs.  These should be mostly for DF_REF_REGULAR, so
    3223              :      that a qsort on the defs is unnecessary in most cases.  */
    3224   1414211906 :   df_defs_record (collection_rec,
    3225   1414211906 :                   PATTERN (insn_info->insn), bb, insn_info, 0);
    3226              : 
    3227              :   /* Record the register uses.  */
    3228   1414211906 :   df_uses_record (collection_rec,
    3229   1414211906 :                   &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0);
    3230              : 
    3231              :   /* DF_REF_CONDITIONAL needs corresponding USES. */
    3232   1414211906 :   if (is_cond_exec)
    3233            0 :     df_get_conditional_uses (collection_rec);
    3234              : 
    3235   1414211906 :   df_canonize_collection_rec (collection_rec);
    3236   1414211906 : }
    3237              : 
    3238              : /* Recompute the luids for the insns in BB.  */
    3239              : 
    3240              : void
    3241     22918213 : df_recompute_luids (basic_block bb)
    3242              : {
    3243     22918213 :   rtx_insn *insn;
    3244     22918213 :   int luid = 0;
    3245              : 
    3246     22918213 :   df_grow_insn_info ();
    3247              : 
    3248              :   /* Scan the block an insn at a time from beginning to end.  */
    3249    281830006 :   FOR_BB_INSNS (bb, insn)
    3250              :     {
    3251    258911793 :       struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
    3252              :       /* Inserting labels does not always trigger the incremental
    3253              :          rescanning.  */
    3254    258911793 :       if (!insn_info)
    3255              :         {
    3256      2183797 :           gcc_assert (!INSN_P (insn));
    3257      2183797 :           insn_info = df_insn_create_insn_record (insn);
    3258              :         }
    3259              : 
    3260    258911793 :       DF_INSN_INFO_LUID (insn_info) = luid;
    3261    258911793 :       if (INSN_P (insn))
    3262    214139749 :         luid++;
    3263              :     }
    3264     22918213 : }
    3265              : 
    3266              : 
    3267              : /* Collect all artificial refs at the block level for BB and add them
    3268              :    to COLLECTION_REC.  */
    3269              : 
    3270              : static void
    3271    120917164 : df_bb_refs_collect (class df_collection_rec *collection_rec, basic_block bb)
    3272              : {
    3273    120917164 :   collection_rec->def_vec.truncate (0);
    3274    120917164 :   collection_rec->use_vec.truncate (0);
    3275    120917164 :   collection_rec->eq_use_vec.truncate (0);
    3276    120917164 :   collection_rec->mw_vec.truncate (0);
    3277              : 
    3278    120917164 :   if (bb->index == ENTRY_BLOCK)
    3279              :     {
    3280      6379161 :       df_entry_block_defs_collect (collection_rec, df->entry_block_defs);
    3281      6379161 :       return;
    3282              :     }
    3283    114538003 :   else if (bb->index == EXIT_BLOCK)
    3284              :     {
    3285      6379161 :       df_exit_block_uses_collect (collection_rec, df->exit_block_uses);
    3286      6379161 :       return;
    3287              :     }
    3288              : 
    3289    108158842 :   if (bb_has_eh_pred (bb))
    3290              :     {
    3291              :       unsigned int i;
    3292              :       /* Mark the registers that will contain data for the handler.  */
    3293      3319958 :       for (i = 0; ; ++i)
    3294              :         {
    3295      4979937 :           unsigned regno = EH_RETURN_DATA_REGNO (i);
    3296      3319958 :           if (regno == INVALID_REGNUM)
    3297              :             break;
    3298      3319958 :           df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
    3299              :                          bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
    3300      3319958 :         }
    3301              :     }
    3302              : 
    3303              :   /* Add the hard_frame_pointer if this block is the target of a
    3304              :      non-local goto.  */
    3305    108158842 :   if (bb->flags & BB_NON_LOCAL_GOTO_TARGET)
    3306         8799 :     df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL,
    3307              :                    bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
    3308              : 
    3309              :   /* Add the artificial uses.  */
    3310    108158842 :   if (bb->index >= NUM_FIXED_BLOCKS)
    3311              :     {
    3312    108158842 :       bitmap_iterator bi;
    3313    108158842 :       unsigned int regno;
    3314    108158842 :       bitmap au = bb_has_eh_pred (bb)
    3315    108158842 :         ? &df->eh_block_artificial_uses
    3316    108158842 :         : &df->regular_block_artificial_uses;
    3317              : 
    3318    392536423 :       EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi)
    3319              :         {
    3320    284377581 :           df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
    3321              :                          bb, NULL, DF_REF_REG_USE, 0);
    3322              :         }
    3323              :     }
    3324              : 
    3325    108158842 :   df_canonize_collection_rec (collection_rec);
    3326              : }
    3327              : 
    3328              : 
    3329              : /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS.  */
    3330              : 
    3331              : void
    3332     43687952 : df_bb_refs_record (int bb_index, bool scan_insns)
    3333              : {
    3334     43687952 :   basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
    3335     43687952 :   rtx_insn *insn;
    3336     43687952 :   int luid = 0;
    3337              : 
    3338     43687952 :   if (!df)
    3339      6439791 :     return;
    3340              : 
    3341     37248161 :   df_collection_rec collection_rec;
    3342     37248161 :   df_grow_bb_info (df_scan);
    3343     37248161 :   if (scan_insns)
    3344              :     /* Scan the block an insn at a time from beginning to end.  */
    3345    378359196 :     FOR_BB_INSNS (bb, insn)
    3346              :       {
    3347    347728147 :         struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
    3348    347728147 :         gcc_assert (!insn_info);
    3349              : 
    3350    347728147 :         insn_info = df_insn_create_insn_record (insn);
    3351    347728147 :         if (INSN_P (insn))
    3352              :           {
    3353              :             /* Record refs within INSN.  */
    3354    293003544 :             DF_INSN_INFO_LUID (insn_info) = luid++;
    3355    293003544 :             df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn));
    3356    293003544 :             df_refs_add_to_chains (&collection_rec, bb, insn, copy_all);
    3357              :           }
    3358    347728147 :         DF_INSN_INFO_LUID (insn_info) = luid;
    3359              :       }
    3360              : 
    3361              :   /* Other block level artificial refs */
    3362     37248161 :   df_bb_refs_collect (&collection_rec, bb);
    3363     37248161 :   df_refs_add_to_chains (&collection_rec, bb, NULL, copy_all);
    3364              : 
    3365              :   /* Now that the block has been processed, set the block as dirty so
    3366              :      LR and LIVE will get it processed.  */
    3367     37248161 :   df_set_bb_dirty (bb);
    3368     37248161 : }
    3369              : 
    3370              : 
    3371              : /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
    3372              :    block. */
    3373              : 
    3374              : static void
    3375      9420877 : df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses)
    3376              : {
    3377              : #ifdef EH_USES
    3378              :   unsigned int i;
    3379              : #endif
    3380              : 
    3381      9420877 :   bitmap_clear (regular_block_artificial_uses);
    3382              : 
    3383      9420877 :   if (reload_completed)
    3384              :     {
    3385      5122634 :       if (frame_pointer_needed)
    3386      1155884 :         bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
    3387              :     }
    3388              :   else
    3389              :     /* Before reload, there are a few registers that must be forced
    3390              :        live everywhere -- which might not already be the case for
    3391              :        blocks within infinite loops.  */
    3392              :     {
    3393      4298243 :       unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
    3394              : 
    3395              :       /* Any reference to any pseudo before reload is a potential
    3396              :          reference of the frame pointer.  */
    3397      4298243 :       bitmap_set_bit (regular_block_artificial_uses, FRAME_POINTER_REGNUM);
    3398              : 
    3399      4298243 :       if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
    3400      4298243 :         bitmap_set_bit (regular_block_artificial_uses,
    3401              :                         HARD_FRAME_POINTER_REGNUM);
    3402              : 
    3403              :       /* Pseudos with argument area equivalences may require
    3404              :          reloading via the argument pointer.  */
    3405      4298243 :       if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
    3406      4298243 :           && fixed_regs[ARG_POINTER_REGNUM])
    3407      4298243 :         bitmap_set_bit (regular_block_artificial_uses, ARG_POINTER_REGNUM);
    3408              : 
    3409              :       /* Any constant, or pseudo with constant equivalences, may
    3410              :          require reloading from memory using the pic register.  */
    3411      4298243 :       if (picreg != INVALID_REGNUM
    3412            0 :           && fixed_regs[picreg])
    3413            0 :         bitmap_set_bit (regular_block_artificial_uses, picreg);
    3414              :     }
    3415              :   /* The all-important stack pointer must always be live.  */
    3416      9420877 :   bitmap_set_bit (regular_block_artificial_uses, STACK_POINTER_REGNUM);
    3417              : 
    3418              : #ifdef EH_USES
    3419              :   /* EH_USES registers are used:
    3420              :      1) at all insns that might throw (calls or with -fnon-call-exceptions
    3421              :         trapping insns)
    3422              :      2) in all EH edges
    3423              :      3) to support backtraces and/or debugging, anywhere between their
    3424              :         initialization and where they the saved registers are restored
    3425              :         from them, including the cases where we don't reach the epilogue
    3426              :         (noreturn call or infinite loop).  */
    3427              :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3428              :     if (EH_USES (i))
    3429              :       bitmap_set_bit (regular_block_artificial_uses, i);
    3430              : #endif
    3431      9420877 : }
    3432              : 
    3433              : 
    3434              : /* Get the artificial use set for an eh block. */
    3435              : 
    3436              : static void
    3437      9420877 : df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses)
    3438              : {
    3439      9420877 :   bitmap_clear (eh_block_artificial_uses);
    3440              : 
    3441              :   /* The following code (down through the arg_pointer setting APPEARS
    3442              :      to be necessary because there is nothing that actually
    3443              :      describes what the exception handling code may actually need
    3444              :      to keep alive.  */
    3445      9420877 :   if (reload_completed)
    3446              :     {
    3447      5122634 :       if (frame_pointer_needed)
    3448              :         {
    3449      1155884 :           bitmap_set_bit (eh_block_artificial_uses, FRAME_POINTER_REGNUM);
    3450      1155884 :           if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
    3451      1155884 :             bitmap_set_bit (eh_block_artificial_uses,
    3452              :                             HARD_FRAME_POINTER_REGNUM);
    3453              :         }
    3454      5122634 :       if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
    3455      5122634 :           && fixed_regs[ARG_POINTER_REGNUM])
    3456      5122634 :         bitmap_set_bit (eh_block_artificial_uses, ARG_POINTER_REGNUM);
    3457              :     }
    3458      9420877 : }
    3459              : 
    3460              : 
    3461              : 
    3462              : /*----------------------------------------------------------------------------
    3463              :    Specialized hard register scanning functions.
    3464              : ----------------------------------------------------------------------------*/
    3465              : 
    3466              : 
    3467              : /* Mark a register in SET.  Hard registers in large modes get all
    3468              :    of their component registers set as well.  */
    3469              : 
    3470              : static void
    3471      9746523 : df_mark_reg (rtx reg, void *vset)
    3472              : {
    3473      9746168 :   bitmap_set_range ((bitmap) vset, REGNO (reg), REG_NREGS (reg));
    3474          355 : }
    3475              : 
    3476              : 
    3477              : /* Set the bit for regs that are considered being defined at the entry. */
    3478              : 
    3479              : static void
    3480     16516080 : df_get_entry_block_def_set (bitmap entry_block_defs)
    3481              : {
    3482     16516080 :   rtx r;
    3483     16516080 :   int i;
    3484              : 
    3485     16516080 :   bitmap_clear (entry_block_defs);
    3486              : 
    3487              :   /* For separate shrink-wrapping we use LIVE to analyze which basic blocks
    3488              :      need a prologue for some component to be executed before that block,
    3489              :      and we do not care about any other registers.  Hence, we do not want
    3490              :      any register for any component defined in the entry block, and we can
    3491              :      just leave all registers undefined.  */
    3492     16516080 :   if (df_scan->local_flags & DF_SCAN_EMPTY_ENTRY_EXIT)
    3493              :     return;
    3494              : 
    3495   1467567714 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3496              :     {
    3497   1451787416 :       if (global_regs[i])
    3498         1742 :         bitmap_set_bit (entry_block_defs, i);
    3499   1451787416 :       if (FUNCTION_ARG_REGNO_P (i))
    3500    224918681 :         bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
    3501              :     }
    3502              : 
    3503              :   /* The always important stack pointer.  */
    3504     15780298 :   bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM);
    3505              : 
    3506              :   /* Once the prologue has been generated, all of these registers
    3507              :      should just show up in the first regular block.  */
    3508     15780298 :   if (targetm.have_prologue () && epilogue_completed)
    3509              :     {
    3510              :       /* Defs for the callee saved registers are inserted so that the
    3511              :          pushes have some defining location.  */
    3512    265150533 :       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3513    262299452 :         if (!crtl->abi->clobbers_full_reg_p (i)
    3514     26005154 :             && !fixed_regs[i]
    3515    279730537 :             && df_regs_ever_live_p (i))
    3516      3796726 :           bitmap_set_bit (entry_block_defs, i);
    3517              :     }
    3518              : 
    3519     15780298 :   r = targetm.calls.struct_value_rtx (current_function_decl, true);
    3520     15780298 :   if (r && REG_P (r))
    3521            0 :     bitmap_set_bit (entry_block_defs, REGNO (r));
    3522              : 
    3523              :   /* If the function has an incoming STATIC_CHAIN, it has to show up
    3524              :      in the entry def set.  */
    3525     15780298 :   r = rtx_for_static_chain (current_function_decl, true);
    3526     15780298 :   if (r && REG_P (r))
    3527       212238 :     bitmap_set_bit (entry_block_defs, REGNO (r));
    3528              : 
    3529     15780298 :   if ((!reload_completed) || frame_pointer_needed)
    3530              :     {
    3531              :       /* Any reference to any pseudo before reload is a potential
    3532              :          reference of the frame pointer.  */
    3533      9206746 :       bitmap_set_bit (entry_block_defs, FRAME_POINTER_REGNUM);
    3534              : 
    3535              :       /* If they are different, also mark the hard frame pointer as live.  */
    3536      9206746 :       if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
    3537              :           && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
    3538      9206746 :         bitmap_set_bit (entry_block_defs, HARD_FRAME_POINTER_REGNUM);
    3539              :     }
    3540              : 
    3541              :   /* These registers are live everywhere.  */
    3542     15780298 :   if (!reload_completed)
    3543              :     {
    3544              :       /* Pseudos with argument area equivalences may require
    3545              :          reloading via the argument pointer.  */
    3546      7195445 :       if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
    3547      7195445 :           && fixed_regs[ARG_POINTER_REGNUM])
    3548      7195445 :         bitmap_set_bit (entry_block_defs, ARG_POINTER_REGNUM);
    3549              : 
    3550              :       /* Any constant, or pseudo with constant equivalences, may
    3551              :          require reloading from memory using the pic register.  */
    3552      7195445 :       unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
    3553            0 :       if (picreg != INVALID_REGNUM
    3554            0 :           && fixed_regs[picreg])
    3555            0 :         bitmap_set_bit (entry_block_defs, picreg);
    3556              :     }
    3557              : 
    3558              : #ifdef INCOMING_RETURN_ADDR_RTX
    3559     17222076 :   if (REG_P (INCOMING_RETURN_ADDR_RTX))
    3560            0 :     bitmap_set_bit (entry_block_defs, REGNO (INCOMING_RETURN_ADDR_RTX));
    3561              : #endif
    3562              : 
    3563     15780298 :   targetm.extra_live_on_entry (entry_block_defs);
    3564              : }
    3565              : 
    3566              : 
    3567              : /* Return the (conservative) set of hard registers that are defined on
    3568              :    entry to the function.
    3569              :    It uses df->entry_block_defs to determine which register
    3570              :    reference to include.  */
    3571              : 
    3572              : static void
    3573     12181503 : df_entry_block_defs_collect (class df_collection_rec *collection_rec,
    3574              :                              bitmap entry_block_defs)
    3575              : {
    3576     12181503 :   unsigned int i;
    3577     12181503 :   bitmap_iterator bi;
    3578              : 
    3579    205405767 :   EXECUTE_IF_SET_IN_BITMAP (entry_block_defs, 0, i, bi)
    3580              :     {
    3581    193224264 :       df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
    3582    193224264 :                      ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_DEF, 0);
    3583              :     }
    3584              : 
    3585     12181503 :   df_canonize_collection_rec (collection_rec);
    3586     12181503 : }
    3587              : 
    3588              : 
    3589              : /* Record the (conservative) set of hard registers that are defined on
    3590              :    entry to the function.  */
    3591              : 
    3592              : static void
    3593      5802342 : df_record_entry_block_defs (bitmap entry_block_defs)
    3594              : {
    3595      5802342 :   class df_collection_rec collection_rec;
    3596      5802342 :   df_entry_block_defs_collect (&collection_rec, entry_block_defs);
    3597              : 
    3598              :   /* Process bb_refs chain */
    3599      5802342 :   df_refs_add_to_chains (&collection_rec,
    3600      5802342 :                          BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK),
    3601              :                          NULL,
    3602              :                          copy_defs);
    3603      5802342 : }
    3604              : 
    3605              : 
    3606              : /* Update the defs in the entry block.  */
    3607              : 
    3608              : void
    3609      7095203 : df_update_entry_block_defs (void)
    3610              : {
    3611      7095203 :   bool changed = false;
    3612              : 
    3613      7095203 :   auto_bitmap refs (&df_bitmap_obstack);
    3614      7095203 :   df_get_entry_block_def_set (refs);
    3615      7095203 :   gcc_assert (df->entry_block_defs);
    3616      7095203 :   if (!bitmap_equal_p (df->entry_block_defs, refs))
    3617              :     {
    3618      2760626 :       struct df_scan_bb_info *bb_info = df_scan_get_bb_info (ENTRY_BLOCK);
    3619      2760626 :       df_ref_chain_delete_du_chain (bb_info->artificial_defs);
    3620      2760626 :       df_ref_chain_delete (bb_info->artificial_defs);
    3621      2760626 :       bb_info->artificial_defs = NULL;
    3622      2760626 :       changed = true;
    3623              :     }
    3624              : 
    3625      2760626 :   if (changed)
    3626              :     {
    3627      2760626 :       df_record_entry_block_defs (refs);
    3628      2760626 :       bitmap_copy (df->entry_block_defs, refs);
    3629      2760626 :       df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK));
    3630              :     }
    3631      7095203 : }
    3632              : 
    3633              : 
    3634              : /* Return true if REGNO is used by the epilogue.  */
    3635              : bool
    3636   1656573810 : df_epilogue_uses_p (unsigned int regno)
    3637              : {
    3638   1656573810 :   return (EPILOGUE_USES (regno)
    3639   1656573810 :           || TEST_HARD_REG_BIT (crtl->must_be_zero_on_return, regno));
    3640              : }
    3641              : 
    3642              : /* Set the bit for regs that are considered being used at the exit. */
    3643              : 
    3644              : void
    3645     18742041 : df_get_exit_block_use_set (bitmap exit_block_uses)
    3646              : {
    3647     18742041 :   unsigned int i;
    3648     18742041 :   unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
    3649              : 
    3650     18742041 :   bitmap_clear (exit_block_uses);
    3651              : 
    3652              :   /* For separate shrink-wrapping we use LIVE to analyze which basic blocks
    3653              :      need an epilogue for some component to be executed after that block,
    3654              :      and we do not care about any other registers.  Hence, we do not want
    3655              :      any register for any component seen as used in the exit block, and we
    3656              :      can just say no registers at all are used.  */
    3657     18742041 :   if (df_scan->local_flags & DF_SCAN_EMPTY_ENTRY_EXIT)
    3658              :     return;
    3659              : 
    3660              :   /* Stack pointer is always live at the exit.  */
    3661     18006259 :   bitmap_set_bit (exit_block_uses, STACK_POINTER_REGNUM);
    3662              : 
    3663              :   /* Mark the frame pointer if needed at the end of the function.
    3664              :      If we end up eliminating it, it will be removed from the live
    3665              :      list of each basic block by reload.  */
    3666              : 
    3667     18006259 :   if ((!reload_completed) || frame_pointer_needed)
    3668              :     {
    3669     11432577 :       bitmap_set_bit (exit_block_uses, FRAME_POINTER_REGNUM);
    3670              : 
    3671              :       /* If they are different, also mark the hard frame pointer as live.  */
    3672     11432577 :       if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
    3673              :           && !LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
    3674     11432577 :         bitmap_set_bit (exit_block_uses, HARD_FRAME_POINTER_REGNUM);
    3675              :     }
    3676              : 
    3677              :   /* Many architectures have a GP register even without flag_pic.
    3678              :      Assume the pic register is not in use, or will be handled by
    3679              :      other means, if it is not fixed.  */
    3680     18006259 :   if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
    3681              :       && picreg != INVALID_REGNUM
    3682            0 :       && fixed_regs[picreg])
    3683            0 :     bitmap_set_bit (exit_block_uses, picreg);
    3684              : 
    3685              :   /* Mark all global registers, and all registers used by the
    3686              :      epilogue as being live at the end of the function since they
    3687              :      may be referenced by our caller.  */
    3688   1674582087 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3689   1656575828 :     if (global_regs[i] || df_epilogue_uses_p (i))
    3690         7953 :       bitmap_set_bit (exit_block_uses, i);
    3691              : 
    3692     18006259 :   if (targetm.have_epilogue () && epilogue_completed)
    3693              :     {
    3694              :       /* Mark all call-saved registers that we actually used.  */
    3695    265162623 :       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3696    262311412 :         if (df_regs_ever_live_p (i)
    3697              :             && !LOCAL_REGNO (i)
    3698    262311412 :             && !crtl->abi->clobbers_full_reg_p (i))
    3699      5933241 :           bitmap_set_bit (exit_block_uses, i);
    3700              :     }
    3701              : 
    3702              :   /* Mark the registers that will contain data for the handler.  */
    3703     18006259 :   if (reload_completed && crtl->calls_eh_return)
    3704          172 :     IOR_REG_SET_HRS (exit_block_uses, eh_return_data_regs);
    3705              : 
    3706              : #ifdef EH_RETURN_STACKADJ_RTX
    3707     36012518 :   if ((!targetm.have_epilogue () || ! epilogue_completed)
    3708     33161307 :       && crtl->calls_eh_return)
    3709              :     {
    3710          459 :       rtx tmp = EH_RETURN_STACKADJ_RTX;
    3711          355 :       if (tmp && REG_P (tmp))
    3712          355 :         df_mark_reg (tmp, exit_block_uses);
    3713              :     }
    3714              : #endif
    3715              : 
    3716              : #ifdef EH_RETURN_TAKEN_RTX
    3717              :   if ((!targetm.have_epilogue () || ! epilogue_completed)
    3718              :       && crtl->calls_eh_return)
    3719              :     {
    3720              :       rtx tmp = EH_RETURN_TAKEN_RTX;
    3721              :       if (tmp && REG_P (tmp))
    3722              :         df_mark_reg (tmp, exit_block_uses);
    3723              :     }
    3724              : #endif
    3725              : 
    3726     18006259 :   if ((!targetm.have_epilogue () || ! epilogue_completed)
    3727              :       && crtl->calls_eh_return)
    3728              :     {
    3729     18006259 :       rtx tmp = EH_RETURN_HANDLER_RTX;
    3730     18006259 :       if (tmp && REG_P (tmp))
    3731              :         df_mark_reg (tmp, exit_block_uses);
    3732              :     }
    3733              : 
    3734              :   /* Mark function return value.  */
    3735     18006259 :   diddle_return_value (df_mark_reg, (void*) exit_block_uses);
    3736              : }
    3737              : 
    3738              : 
    3739              : /* Return the refs of hard registers that are used in the exit block.
    3740              :    It uses df->exit_block_uses to determine register to include.  */
    3741              : 
    3742              : static void
    3743     11856221 : df_exit_block_uses_collect (class df_collection_rec *collection_rec, bitmap exit_block_uses)
    3744              : {
    3745     11856221 :   unsigned int i;
    3746     11856221 :   bitmap_iterator bi;
    3747              : 
    3748     43235259 :   EXECUTE_IF_SET_IN_BITMAP (exit_block_uses, 0, i, bi)
    3749     31379038 :     df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
    3750     31379038 :                    EXIT_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_USE, 0);
    3751              : 
    3752              :   /* It is deliberate that this is not put in the exit block uses but
    3753              :      I do not know why.  */
    3754     11856221 :   if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
    3755     11856221 :       && reload_completed
    3756      7557978 :       && !bitmap_bit_p (exit_block_uses, ARG_POINTER_REGNUM)
    3757      7557978 :       && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun))
    3758     11856221 :       && fixed_regs[ARG_POINTER_REGNUM])
    3759            0 :     df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[ARG_POINTER_REGNUM], NULL,
    3760              :                    EXIT_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_USE, 0);
    3761              : 
    3762     11856221 :   df_canonize_collection_rec (collection_rec);
    3763     11856221 : }
    3764              : 
    3765              : 
    3766              : /* Record the set of hard registers that are used in the exit block.
    3767              :    It uses df->exit_block_uses to determine which bit to include.  */
    3768              : 
    3769              : static void
    3770      5477060 : df_record_exit_block_uses (bitmap exit_block_uses)
    3771              : {
    3772      5477060 :   class df_collection_rec collection_rec;
    3773      5477060 :   df_exit_block_uses_collect (&collection_rec, exit_block_uses);
    3774              : 
    3775              :   /* Process bb_refs chain */
    3776      5477060 :   df_refs_add_to_chains (&collection_rec,
    3777      5477060 :                          BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK),
    3778              :                          NULL,
    3779              :                          copy_uses);
    3780      5477060 : }
    3781              : 
    3782              : 
    3783              : /* Update the uses in the exit block.  */
    3784              : 
    3785              : void
    3786      8357183 : df_update_exit_block_uses (void)
    3787              : {
    3788      8357183 :   bool changed = false;
    3789              : 
    3790      8357183 :   auto_bitmap refs (&df_bitmap_obstack);
    3791      8357183 :   df_get_exit_block_use_set (refs);
    3792      8357183 :   gcc_assert (df->exit_block_uses);
    3793      8357183 :   if (!bitmap_equal_p (df->exit_block_uses, refs))
    3794              :     {
    3795      2435344 :       struct df_scan_bb_info *bb_info = df_scan_get_bb_info (EXIT_BLOCK);
    3796      2435344 :       df_ref_chain_delete_du_chain (bb_info->artificial_uses);
    3797      2435344 :       df_ref_chain_delete (bb_info->artificial_uses);
    3798      2435344 :       bb_info->artificial_uses = NULL;
    3799      2435344 :       changed = true;
    3800              :     }
    3801              : 
    3802      2435344 :   if (changed)
    3803              :     {
    3804      2435344 :       df_record_exit_block_uses (refs);
    3805      2435344 :       bitmap_copy (df->exit_block_uses, refs);
    3806      2435344 :       df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
    3807              :     }
    3808      8357183 : }
    3809              : 
    3810              : static bool initialized = false;
    3811              : 
    3812              : 
    3813              : /* Initialize some platform specific structures.  */
    3814              : 
    3815              : void
    3816      1471365 : df_hard_reg_init (void)
    3817              : {
    3818      1471365 :   int i;
    3819      1471365 :   static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
    3820              : 
    3821      1471365 :   if (initialized)
    3822              :     return;
    3823              : 
    3824              :   /* Record which registers will be eliminated.  We use this in
    3825              :      mark_used_regs.  */
    3826      1039925 :   CLEAR_HARD_REG_SET (elim_reg_set);
    3827              : 
    3828      1039925 :   for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
    3829       831940 :     SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
    3830              : 
    3831       207985 :   initialized = true;
    3832              : }
    3833              : 
    3834              : /* Recompute the parts of scanning that are based on regs_ever_live
    3835              :    because something changed in that array.  */
    3836              : 
    3837              : void
    3838      6676214 : df_update_entry_exit_and_calls (void)
    3839              : {
    3840      6676214 :   basic_block bb;
    3841              : 
    3842      6676214 :   df_update_entry_block_defs ();
    3843      6676214 :   df_update_exit_block_uses ();
    3844              : 
    3845              :   /* The call insns need to be rescanned because there may be changes
    3846              :      in the set of registers clobbered across the call.  */
    3847     79475273 :   FOR_EACH_BB_FN (bb, cfun)
    3848              :     {
    3849     72799059 :       rtx_insn *insn;
    3850    912992711 :       FOR_BB_INSNS (bb, insn)
    3851              :         {
    3852    840193652 :           if (INSN_P (insn) && CALL_P (insn))
    3853     29643218 :             df_insn_rescan (insn);
    3854              :         }
    3855              :     }
    3856      6676214 : }
    3857              : 
    3858              : 
    3859              : /* Return true if hard REG is actually used in the some instruction.
    3860              :    There are a fair number of conditions that affect the setting of
    3861              :    this array.  See the comment in df.h for df->hard_regs_live_count
    3862              :    for the conditions that this array is set. */
    3863              : 
    3864              : bool
    3865   4134124042 : df_hard_reg_used_p (unsigned int reg)
    3866              : {
    3867   4134124042 :   return df->hard_regs_live_count[reg] != 0;
    3868              : }
    3869              : 
    3870              : 
    3871              : /* A count of the number of times REG is actually used in the some
    3872              :    instruction.  There are a fair number of conditions that affect the
    3873              :    setting of this array.  See the comment in df.h for
    3874              :    df->hard_regs_live_count for the conditions that this array is
    3875              :    set. */
    3876              : 
    3877              : 
    3878              : unsigned int
    3879            0 : df_hard_reg_used_count (unsigned int reg)
    3880              : {
    3881            0 :   return df->hard_regs_live_count[reg];
    3882              : }
    3883              : 
    3884              : 
    3885              : /* Get the value of regs_ever_live[REGNO].  */
    3886              : 
    3887              : bool
    3888    733840925 : df_regs_ever_live_p (unsigned int regno)
    3889              : {
    3890    733840925 :   return regs_ever_live[regno];
    3891              : }
    3892              : 
    3893              : /* Set regs_ever_live[REGNO] to VALUE.  If this cause regs_ever_live
    3894              :    to change, schedule that change for the next update.  */
    3895              : 
    3896              : void
    3897    103215138 : df_set_regs_ever_live (unsigned int regno, bool value)
    3898              : {
    3899    103215138 :   if (regs_ever_live[regno] == value)
    3900              :     return;
    3901              : 
    3902      3578599 :   regs_ever_live[regno] = value;
    3903      3578599 :   if (df)
    3904      3578599 :     df->redo_entry_and_exit = true;
    3905              : }
    3906              : 
    3907              : 
    3908              : /* Compute "regs_ever_live" information from the underlying df
    3909              :    information.  Set the vector to all false if RESET.  */
    3910              : 
    3911              : void
    3912     47738146 : df_compute_regs_ever_live (bool reset)
    3913              : {
    3914     47738146 :   unsigned int i;
    3915     47738146 :   bool changed = df->redo_entry_and_exit;
    3916              : 
    3917     47738146 :   if (reset)
    3918      2549691 :     memset (regs_ever_live, 0, sizeof (regs_ever_live));
    3919              : 
    3920   4439647578 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3921   4391909432 :     if ((!regs_ever_live[i]) && df_hard_reg_used_p (i))
    3922              :       {
    3923     12485495 :         regs_ever_live[i] = true;
    3924     12485495 :         changed = true;
    3925              :       }
    3926     47738146 :   if (changed)
    3927      3274178 :     df_update_entry_exit_and_calls ();
    3928     47738146 :   df->redo_entry_and_exit = false;
    3929     47738146 : }
    3930              : 
    3931              : 
    3932              : /*----------------------------------------------------------------------------
    3933              :   Dataflow ref information verification functions.
    3934              : 
    3935              :   df_reg_chain_mark (refs, regno, is_def, is_eq_use)
    3936              :   df_reg_chain_verify_unmarked (refs)
    3937              :   df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
    3938              :   df_mws_verify (mw*, mw*, bool)
    3939              :   df_insn_refs_verify (collection_rec, bb, insn, bool)
    3940              :   df_bb_refs_verify (bb, refs, bool)
    3941              :   df_bb_verify (bb)
    3942              :   df_exit_block_bitmap_verify (bool)
    3943              :   df_entry_block_bitmap_verify (bool)
    3944              :   df_scan_verify ()
    3945              : ----------------------------------------------------------------------------*/
    3946              : 
    3947              : 
    3948              : /* Mark all refs in the reg chain.  Verify that all of the registers
    3949              : are in the correct chain.  */
    3950              : 
    3951              : static unsigned int
    3952   2778155184 : df_reg_chain_mark (df_ref refs, unsigned int regno,
    3953              :                    bool is_def, bool is_eq_use)
    3954              : {
    3955   2778155184 :   unsigned int count = 0;
    3956   2778155184 :   df_ref ref;
    3957   6340761601 :   for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
    3958              :     {
    3959   3562606417 :       gcc_assert (!DF_REF_IS_REG_MARKED (ref));
    3960              : 
    3961              :       /* If there are no def-use or use-def chains, make sure that all
    3962              :          of the chains are clear.  */
    3963   3562606417 :       if (!df_chain)
    3964   3259735385 :         gcc_assert (!DF_REF_CHAIN (ref));
    3965              : 
    3966              :       /* Check to make sure the ref is in the correct chain.  */
    3967   3562606417 :       gcc_assert (DF_REF_REGNO (ref) == regno);
    3968   3562606417 :       if (is_def)
    3969   2794549688 :         gcc_assert (DF_REF_REG_DEF_P (ref));
    3970              :       else
    3971    768056729 :         gcc_assert (!DF_REF_REG_DEF_P (ref));
    3972              : 
    3973   3562606417 :       if (is_eq_use)
    3974     17406510 :         gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE));
    3975              :       else
    3976   3545199907 :         gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) == 0);
    3977              : 
    3978   3562606417 :       if (DF_REF_NEXT_REG (ref))
    3979   2971222282 :         gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref)) == ref);
    3980   3562606417 :       count++;
    3981   3562606417 :       DF_REF_REG_MARK (ref);
    3982              :     }
    3983   2778155184 :   return count;
    3984              : }
    3985              : 
    3986              : 
    3987              : /* Verify that all of the registers in the chain are unmarked.  */
    3988              : 
    3989              : static void
    3990   2778155184 : df_reg_chain_verify_unmarked (df_ref refs)
    3991              : {
    3992   2778155184 :   df_ref ref;
    3993   6340761601 :   for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
    3994   3562606417 :     gcc_assert (!DF_REF_IS_REG_MARKED (ref));
    3995   2778155184 : }
    3996              : 
    3997              : 
    3998              : /* Verify that NEW_REC and OLD_REC have exactly the same members. */
    3999              : 
    4000              : static bool
    4001   3355278876 : df_refs_verify (const vec<df_ref, va_heap> *new_rec, df_ref old_rec,
    4002              :                 bool abort_if_fail)
    4003              : {
    4004   3355278876 :   unsigned int ix;
    4005   3355278876 :   df_ref new_ref;
    4006              : 
    4007  10921143081 :   FOR_EACH_VEC_ELT (*new_rec, ix, new_ref)
    4008              :     {
    4009   7621092987 :       if (old_rec == NULL || !df_ref_equal_p (new_ref, old_rec))
    4010              :         {
    4011     55228782 :           if (abort_if_fail)
    4012            0 :             gcc_assert (0);
    4013              :           else
    4014              :             return false;
    4015              :         }
    4016              : 
    4017              :       /* Abort if fail is called from the function level verifier.  If
    4018              :          that is the context, mark this reg as being seem.  */
    4019   7565864205 :       if (abort_if_fail)
    4020              :         {
    4021   3562606417 :           gcc_assert (DF_REF_IS_REG_MARKED (old_rec));
    4022   3562606417 :           DF_REF_REG_UNMARK (old_rec);
    4023              :         }
    4024              : 
    4025   7565864205 :       old_rec = DF_REF_NEXT_LOC (old_rec);
    4026              :     }
    4027              : 
    4028   3300050094 :   if (abort_if_fail)
    4029   2225979598 :     gcc_assert (old_rec == NULL);
    4030              :   else
    4031   1074070496 :     return old_rec == NULL;
    4032              :   return false;
    4033              : }
    4034              : 
    4035              : 
    4036              : /* Verify that NEW_REC and OLD_REC have exactly the same members. */
    4037              : 
    4038              : static bool
    4039   1024854322 : df_mws_verify (const vec<df_mw_hardreg *, va_heap> *new_rec,
    4040              :                struct df_mw_hardreg *old_rec,
    4041              :                bool abort_if_fail)
    4042              : {
    4043   1024854322 :   unsigned int ix;
    4044   1024854322 :   struct df_mw_hardreg *new_reg;
    4045              : 
    4046   1030577851 :   FOR_EACH_VEC_ELT (*new_rec, ix, new_reg)
    4047              :     {
    4048      5725568 :       if (old_rec == NULL || !df_mw_equal_p (new_reg, old_rec))
    4049              :         {
    4050         2039 :           if (abort_if_fail)
    4051            0 :             gcc_assert (0);
    4052              :           else
    4053              :             return false;
    4054              :         }
    4055      5723529 :       old_rec = DF_MWS_NEXT (old_rec);
    4056              :     }
    4057              : 
    4058   1024852283 :   if (abort_if_fail)
    4059    686213864 :     gcc_assert (old_rec == NULL);
    4060              :   else
    4061    338638419 :     return old_rec == NULL;
    4062              :   return false;
    4063              : }
    4064              : 
    4065              : 
    4066              : /* Return true if the existing insn refs information is complete and
    4067              :    correct. Otherwise (i.e. if there's any missing or extra refs),
    4068              :    return the correct df_ref chain in REFS_RETURN.
    4069              : 
    4070              :    If ABORT_IF_FAIL, leave the refs that are verified (already in the
    4071              :    ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
    4072              :    verification mode instead of the whole function, so unmark
    4073              :    everything.
    4074              : 
    4075              :    If ABORT_IF_FAIL is set, this function never returns false.  */
    4076              : 
    4077              : static bool
    4078   1083802768 : df_insn_refs_verify (class df_collection_rec *collection_rec,
    4079              :                      basic_block bb,
    4080              :                      rtx_insn *insn,
    4081              :                      bool abort_if_fail)
    4082              : {
    4083   1083802768 :   bool ret1, ret2, ret3;
    4084   1083802768 :   unsigned int uid = INSN_UID (insn);
    4085   1083802768 :   struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
    4086              : 
    4087   1083802768 :   df_insn_refs_collect (collection_rec, bb, insn_info);
    4088              : 
    4089              :   /* Unfortunately we cannot opt out early if one of these is not
    4090              :      right and abort_if_fail is set because the marks will not get cleared.  */
    4091   1083802768 :   ret1 = df_refs_verify (&collection_rec->def_vec, DF_INSN_UID_DEFS (uid),
    4092              :                          abort_if_fail);
    4093   1083802768 :   if (!ret1 && !abort_if_fail)
    4094              :     return false;
    4095   1076948348 :   ret2 = df_refs_verify (&collection_rec->use_vec, DF_INSN_UID_USES (uid),
    4096              :                          abort_if_fail);
    4097   1076948348 :   if (!ret2 && !abort_if_fail)
    4098              :     return false;
    4099   1027189754 :   ret3 = df_refs_verify (&collection_rec->eq_use_vec, DF_INSN_UID_EQ_USES (uid),
    4100              :                          abort_if_fail);
    4101   1027189754 :   if (!ret3 && !abort_if_fail)
    4102              :     return false;
    4103   1024854322 :   if (! df_mws_verify (&collection_rec->mw_vec, DF_INSN_UID_MWS (uid),
    4104              :                        abort_if_fail))
    4105              :     return false;
    4106    338638419 :   return (ret1 && ret2 && ret3);
    4107              : }
    4108              : 
    4109              : 
    4110              : /* Return true if all refs in the basic block are correct and complete.
    4111              :    Due to df_ref_chain_verify, it will cause all refs
    4112              :    that are verified to have DF_REF_MARK bit set.  */
    4113              : 
    4114              : static bool
    4115     83669003 : df_bb_verify (basic_block bb)
    4116              : {
    4117     83669003 :   rtx_insn *insn;
    4118     83669003 :   struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
    4119     83669003 :   class df_collection_rec collection_rec;
    4120              : 
    4121     83669003 :   gcc_assert (bb_info);
    4122              : 
    4123              :   /* Scan the block, one insn at a time, from beginning to end.  */
    4124    905255260 :   FOR_BB_INSNS_REVERSE (bb, insn)
    4125              :     {
    4126    821586257 :       if (!INSN_P (insn))
    4127    135372393 :         continue;
    4128    686213864 :       df_insn_refs_verify (&collection_rec, bb, insn, true);
    4129    686213864 :       df_free_collection_rec (&collection_rec);
    4130              :     }
    4131              : 
    4132              :   /* Do the artificial defs and uses.  */
    4133     83669003 :   df_bb_refs_collect (&collection_rec, bb);
    4134    167338006 :   df_refs_verify (&collection_rec.def_vec, df_get_artificial_defs (bb->index), true);
    4135     83669003 :   df_refs_verify (&collection_rec.use_vec, df_get_artificial_uses (bb->index), true);
    4136     83669003 :   df_free_collection_rec (&collection_rec);
    4137              : 
    4138    167338006 :   return true;
    4139     83669003 : }
    4140              : 
    4141              : 
    4142              : /* Returns true if the entry block has correct and complete df_ref set.
    4143              :    If not it either aborts if ABORT_IF_FAIL is true or returns false.  */
    4144              : 
    4145              : static bool
    4146      6379161 : df_entry_block_bitmap_verify (bool abort_if_fail)
    4147              : {
    4148      6379161 :   bool is_eq;
    4149              : 
    4150      6379161 :   auto_bitmap entry_block_defs (&df_bitmap_obstack);
    4151      6379161 :   df_get_entry_block_def_set (entry_block_defs);
    4152              : 
    4153      6379161 :   is_eq = bitmap_equal_p (entry_block_defs, df->entry_block_defs);
    4154              : 
    4155      6379161 :   if (!is_eq && abort_if_fail)
    4156              :     {
    4157            0 :       fprintf (stderr, "entry_block_defs = ");
    4158            0 :       df_print_regset (stderr, entry_block_defs);
    4159            0 :       fprintf (stderr, "df->entry_block_defs = ");
    4160            0 :       df_print_regset (stderr, df->entry_block_defs);
    4161            0 :       gcc_assert (0);
    4162              :     }
    4163              : 
    4164      6379161 :   return is_eq;
    4165      6379161 : }
    4166              : 
    4167              : 
    4168              : /* Returns true if the exit block has correct and complete df_ref set.
    4169              :    If not it either aborts if ABORT_IF_FAIL is true or returns false. */
    4170              : 
    4171              : static bool
    4172      6379161 : df_exit_block_bitmap_verify (bool abort_if_fail)
    4173              : {
    4174      6379161 :   bool is_eq;
    4175              : 
    4176      6379161 :   auto_bitmap exit_block_uses (&df_bitmap_obstack);
    4177      6379161 :   df_get_exit_block_use_set (exit_block_uses);
    4178              : 
    4179      6379161 :   is_eq = bitmap_equal_p (exit_block_uses, df->exit_block_uses);
    4180              : 
    4181      6379161 :   if (!is_eq && abort_if_fail)
    4182              :     {
    4183            0 :       fprintf (stderr, "exit_block_uses = ");
    4184            0 :       df_print_regset (stderr, exit_block_uses);
    4185            0 :       fprintf (stderr, "df->exit_block_uses = ");
    4186            0 :       df_print_regset (stderr, df->exit_block_uses);
    4187            0 :       gcc_assert (0);
    4188              :     }
    4189              : 
    4190      6379161 :   return is_eq;
    4191      6379161 : }
    4192              : 
    4193              : 
    4194              : /* Return true if df_ref information for all insns in all blocks are
    4195              :    correct and complete.  */
    4196              : 
    4197              : void
    4198      6379161 : df_scan_verify (void)
    4199              : {
    4200      6379161 :   unsigned int i;
    4201      6379161 :   basic_block bb;
    4202              : 
    4203      6379161 :   if (!df)
    4204            0 :     return;
    4205              : 
    4206              :   /* Verification is a 4 step process. */
    4207              : 
    4208              :   /* (1) All of the refs are marked by going through the reg chains.  */
    4209    932430889 :   for (i = 0; i < DF_REG_SIZE (df); i++)
    4210              :     {
    4211    926051728 :       gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false)
    4212              :                   == DF_REG_DEF_COUNT (i));
    4213    926051728 :       gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i), i, false, false)
    4214              :                   == DF_REG_USE_COUNT (i));
    4215    926051728 :       gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i), i, false, true)
    4216              :                   == DF_REG_EQ_USE_COUNT (i));
    4217              :     }
    4218              : 
    4219              :   /* (2) There are various bitmaps whose value may change over the
    4220              :      course of the compilation.  This step recomputes them to make
    4221              :      sure that they have not slipped out of date.  */
    4222      6379161 :   auto_bitmap regular_block_artificial_uses (&df_bitmap_obstack);
    4223      6379161 :   auto_bitmap eh_block_artificial_uses (&df_bitmap_obstack);
    4224              : 
    4225      6379161 :   df_get_regular_block_artificial_uses (regular_block_artificial_uses);
    4226      6379161 :   df_get_eh_block_artificial_uses (eh_block_artificial_uses);
    4227              : 
    4228      6379161 :   bitmap_ior_into (eh_block_artificial_uses,
    4229      6379161 :                    regular_block_artificial_uses);
    4230              : 
    4231              :   /* Check artificial_uses bitmaps didn't change. */
    4232      6379161 :   gcc_assert (bitmap_equal_p (regular_block_artificial_uses,
    4233              :                               &df->regular_block_artificial_uses));
    4234      6379161 :   gcc_assert (bitmap_equal_p (eh_block_artificial_uses,
    4235              :                               &df->eh_block_artificial_uses));
    4236              : 
    4237              :   /* Verify entry block and exit block. These only verify the bitmaps,
    4238              :      the refs are verified in df_bb_verify.  */
    4239      6379161 :   df_entry_block_bitmap_verify (true);
    4240      6379161 :   df_exit_block_bitmap_verify (true);
    4241              : 
    4242              :   /* (3) All of the insns in all of the blocks are traversed and the
    4243              :      marks are cleared both in the artificial refs attached to the
    4244              :      blocks and the real refs inside the insns.  It is a failure to
    4245              :      clear a mark that has not been set as this means that the ref in
    4246              :      the block or insn was not in the reg chain.  */
    4247              : 
    4248     90048164 :   FOR_ALL_BB_FN (bb, cfun)
    4249     83669003 :     df_bb_verify (bb);
    4250              : 
    4251              :   /* (4) See if all reg chains are traversed a second time.  This time
    4252              :      a check is made that the marks are clear. A set mark would be a
    4253              :      from a reg that is not in any insn or basic block.  */
    4254              : 
    4255    932430889 :   for (i = 0; i < DF_REG_SIZE (df); i++)
    4256              :     {
    4257    926051728 :       df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i));
    4258    926051728 :       df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i));
    4259    926051728 :       df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i));
    4260              :     }
    4261      6379161 : }
        

Generated by: LCOV version 2.4-beta

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