LCOV - code coverage report
Current view: top level - gcc - tree-ssanames.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 81.6 % 485 396
Test Date: 2026-11-14 16:39:50 Functions: 93.2 % 44 41
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Generic routines for manipulating SSA_NAME expressions
       2              :    Copyright (C) 2003-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify
       7              : it under the terms of the GNU General Public License as published by
       8              : the Free Software Foundation; either version 3, or (at your option)
       9              : any later version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful,
      12              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : GNU General Public License for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "backend.h"
      24              : #include "tree.h"
      25              : #include "gimple.h"
      26              : #include "tree-pass.h"
      27              : #include "ssa.h"
      28              : #include "gimple-pretty-print.h"
      29              : #include "gimple-iterator.h"
      30              : #include "stor-layout.h"
      31              : #include "tree-into-ssa.h"
      32              : #include "tree-ssa.h"
      33              : #include "cfgloop.h"
      34              : #include "tree-scalar-evolution.h"
      35              : #include "value-query.h"
      36              : #include "value-range-storage.h"
      37              : 
      38              : /* Rewriting a function into SSA form can create a huge number of SSA_NAMEs,
      39              :    many of which may be thrown away shortly after their creation if jumps
      40              :    were threaded through PHI nodes.
      41              : 
      42              :    While our garbage collection mechanisms will handle this situation, it
      43              :    is extremely wasteful to create nodes and throw them away, especially
      44              :    when the nodes can be reused.
      45              : 
      46              :    For PR 8361, we can significantly reduce the number of nodes allocated
      47              :    and thus the total amount of memory allocated by managing SSA_NAMEs a
      48              :    little.  This additionally helps reduce the amount of work done by the
      49              :    garbage collector.  Similar results have been seen on a wider variety
      50              :    of tests (such as the compiler itself).
      51              : 
      52              :    Right now we maintain our free list on a per-function basis.  It may
      53              :    or may not make sense to maintain the free list for the duration of
      54              :    a compilation unit.
      55              : 
      56              :    External code should rely solely upon HIGHEST_SSA_VERSION and the
      57              :    externally defined functions.  External code should not know about
      58              :    the details of the free list management.
      59              : 
      60              :    External code should also not assume the version number on nodes is
      61              :    monotonically increasing.  We reuse the version number when we
      62              :    reuse an SSA_NAME expression.  This helps keep arrays and bitmaps
      63              :    more compact.  */
      64              : 
      65              : 
      66              : /* Version numbers with special meanings.  We start allocating new version
      67              :    numbers after the special ones.  */
      68              : #define UNUSED_NAME_VERSION 0
      69              : 
      70              : unsigned int ssa_name_nodes_reused;
      71              : unsigned int ssa_name_nodes_created;
      72              : 
      73              : #define FREE_SSANAMES(fun) (fun)->gimple_df->free_ssanames
      74              : #define FREE_SSANAMES_QUEUE(fun) (fun)->gimple_df->free_ssanames_queue
      75              : 
      76              : /* Return TRUE if R fits in the global range of NAME.  */
      77              : 
      78              : inline bool
      79      6808369 : range_info_fits_p (tree name, const vrange &r)
      80              : {
      81      6808369 :   gcc_checking_assert (SSA_NAME_RANGE_INFO (name));
      82      6808369 :   vrange_storage *mem = SSA_NAME_RANGE_INFO (name);
      83      6808369 :   return mem->fits_p (r);
      84              : }
      85              : 
      86              : /* Allocate a new global range for NAME and set it to R.  Return the
      87              :    allocation slot.  */
      88              : 
      89              : inline vrange_storage *
      90     28650516 : range_info_alloc (tree name, const vrange &r)
      91              : {
      92     28650516 :   vrange_storage *mem = ggc_alloc_vrange_storage (r);
      93     28650516 :   SSA_NAME_RANGE_INFO (name) = mem;
      94     28650516 :   return mem;
      95              : }
      96              : 
      97              : /* Free storage allocated for the global range for NAME.  */
      98              : 
      99              : inline void
     100      1229095 : range_info_free (tree name)
     101              : {
     102      1229095 :   vrange_storage *mem = SSA_NAME_RANGE_INFO (name);
     103      1229095 :   ggc_free (mem);
     104      1229095 : }
     105              : 
     106              : /* Attach PT to NAME, creating range storage if necessary.  */
     107              : 
     108              : static void
     109     19040484 : set_pt_solution (tree name, pt_solution *pt)
     110              : {
     111     19040484 :   gcc_checking_assert (POINTER_TYPE_P (TREE_TYPE (name)));
     112     19040484 :   if (!SSA_NAME_RANGE_INFO (name))
     113     11776167 :     SSA_NAME_RANGE_INFO (name) = ggc_alloc_vrange_storage (TREE_TYPE (name));
     114     19040484 :   ssa_name_prange_info (name)->pt = pt;
     115     19040484 : }
     116              : 
     117              : /* Return NAME's solution, creating an unknown solution if necessary.  */
     118              : 
     119              : static pt_solution *
     120     24165875 : get_pt_solution (tree name)
     121              : {
     122     24165875 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
     123     24165875 :   prange_storage *s = ssa_name_prange_info (name);
     124     24165875 :   if (s && s->pt)
     125              :     return s->pt;
     126     15171830 :   pt_solution *pt = ggc_cleared_alloc<pt_solution> ();
     127     15171830 :   pt_solution_reset (pt);
     128     15171830 :   set_pt_solution (name, pt);
     129     15171830 :   return pt;
     130              : }
     131              : 
     132              : /* Make PT the points-to solution for NAME.  */
     133              : 
     134              : void
     135     24165875 : set_ssa_name_pt_solution (tree name, const pt_solution &pt)
     136              : {
     137     24165875 :   *get_pt_solution (name) = pt;
     138     24165875 : }
     139              : 
     140              : /* Return the global range for NAME in R.  */
     141              : 
     142              : inline void
     143    334403993 : range_info_get_range (const_tree name, vrange &r)
     144              : {
     145    334403993 :   SSA_NAME_RANGE_INFO (name)->get_vrange (r, TREE_TYPE (name));
     146    334403993 : }
     147              : 
     148              : /* Set the global range for NAME from R.  Return TRUE if successful,
     149              :    or FALSE if we can't set a range of NAME's type.  */
     150              : 
     151              : inline bool
     152     34229790 : range_info_set_range (tree name, const vrange &r)
     153              : {
     154     34229790 :   if (!SSA_NAME_RANGE_INFO (name) || !range_info_fits_p (name, r))
     155              :     {
     156              :       // Preserve SSA-owned points-to information when the
     157              :       // variable-sized range storage must grow.
     158     28650516 :       pt_solution *pt = NULL;
     159     28650516 :       if (prange_storage *old = ssa_name_prange_info (name))
     160       628665 :         pt = old->pt;
     161     28650516 :       if (SSA_NAME_RANGE_INFO (name))
     162      1229095 :         range_info_free (name);
     163              : 
     164     28650516 :       vrange_storage *mem = range_info_alloc (name, r);
     165     28650516 :       if (mem && pt)
     166              :         {
     167       518422 :           prange_storage *s = mem->dyn_prange ();
     168       518422 :           s->pt = pt;
     169              :         }
     170              :       return mem != NULL;
     171              :     }
     172              :   else
     173              :     {
     174      5579274 :       SSA_NAME_RANGE_INFO (name)->set_vrange (r);
     175      5579274 :       return true;
     176              :     }
     177              : }
     178              : 
     179              : /* Initialize management of SSA_NAMEs to default SIZE.  If SIZE is
     180              :    zero use default.  */
     181              : 
     182              : void
     183      3424286 : init_ssanames (struct function *fn, int size)
     184              : {
     185      3424286 :   if (!size)
     186      3338463 :     vec_alloc (SSANAMES (fn), 50);
     187              :   else
     188        85823 :     vec_safe_reserve (SSANAMES (fn), size, true);
     189              : 
     190              :   /* Version 0 is special, so reserve the first slot in the table.  Though
     191              :      currently unused, we may use version 0 in alias analysis as part of
     192              :      the heuristics used to group aliases when the alias sets are too
     193              :      large.
     194              : 
     195              :      We use vec::quick_push here because we know that SSA_NAMES has at
     196              :      least 50 elements reserved in it.  */
     197      3424286 :   SSANAMES (fn)->quick_push (NULL_TREE);
     198      3424286 :   FREE_SSANAMES (fn) = NULL;
     199      3424286 :   FREE_SSANAMES_QUEUE (fn) = NULL;
     200              : 
     201      3424286 :   fn->gimple_df->ssa_renaming_needed = 0;
     202      3424286 :   fn->gimple_df->rename_vops = 0;
     203      3424286 : }
     204              : 
     205              : /* Finalize management of SSA_NAMEs.  */
     206              : 
     207              : void
     208      3313395 : fini_ssanames (struct function *fn)
     209              : {
     210      3313395 :   unsigned i;
     211      3313395 :   tree name;
     212              :   /* Some SSA names leak into global tree data structures so we can't simply
     213              :      ggc_free them.  But make sure to clear references to stmts since we now
     214              :      ggc_free the CFG itself.  */
     215     98909109 :   FOR_EACH_VEC_SAFE_ELT (SSANAMES (fn), i, name)
     216     95595714 :     if (name)
     217     68555590 :       SSA_NAME_DEF_STMT (name) = NULL;
     218      3313395 :   vec_free (SSANAMES (fn));
     219      3313395 :   vec_free (FREE_SSANAMES (fn));
     220      3313395 :   vec_free (FREE_SSANAMES_QUEUE (fn));
     221      3313395 : }
     222              : 
     223              : /* Dump some simple statistics regarding the re-use of SSA_NAME nodes.  */
     224              : 
     225              : void
     226            0 : ssanames_print_statistics (void)
     227              : {
     228            0 :   fprintf (stderr, "%-32s" PRsa (11) "\n", "SSA_NAME nodes allocated:",
     229            0 :            SIZE_AMOUNT (ssa_name_nodes_created));
     230            0 :   fprintf (stderr, "%-32s" PRsa (11) "\n", "SSA_NAME nodes reused:",
     231            0 :            SIZE_AMOUNT (ssa_name_nodes_reused));
     232            0 : }
     233              : 
     234              : /* Verify the state of the SSA_NAME lists.
     235              : 
     236              :    There must be no duplicates on the free list.
     237              :    Every name on the free list must be marked as on the free list.
     238              :    Any name on the free list must not appear in the IL.
     239              :    No names can be leaked.  */
     240              : 
     241              : DEBUG_FUNCTION void
     242            0 : verify_ssaname_freelists (struct function *fun)
     243              : {
     244            0 :   if (!gimple_in_ssa_p (fun))
     245            0 :     return;
     246              : 
     247            0 :   auto_bitmap names_in_il;
     248              : 
     249              :   /* Walk the entire IL noting every SSA_NAME we see.  */
     250            0 :   basic_block bb;
     251            0 :   FOR_EACH_BB_FN (bb, fun)
     252              :     {
     253            0 :       tree t;
     254              :       /* First note the result and arguments of PHI nodes.  */
     255            0 :       for (gphi_iterator gsi = gsi_start_phis (bb);
     256            0 :            !gsi_end_p (gsi);
     257            0 :            gsi_next (&gsi))
     258              :         {
     259            0 :           gphi *phi = gsi.phi ();
     260            0 :           t = gimple_phi_result (phi);
     261            0 :           bitmap_set_bit (names_in_il, SSA_NAME_VERSION (t));
     262              : 
     263            0 :           for (unsigned int i = 0; i < gimple_phi_num_args (phi); i++)
     264              :             {
     265            0 :               t = gimple_phi_arg_def (phi, i);
     266            0 :               if (TREE_CODE (t) == SSA_NAME)
     267            0 :                 bitmap_set_bit (names_in_il, SSA_NAME_VERSION (t));
     268              :             }
     269              :         }
     270              : 
     271              :       /* Then note the operands of each statement.  */
     272            0 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
     273            0 :            !gsi_end_p (gsi);
     274            0 :            gsi_next (&gsi))
     275              :         {
     276            0 :           ssa_op_iter iter;
     277            0 :           gimple *stmt = gsi_stmt (gsi);
     278            0 :           FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, SSA_OP_ALL_OPERANDS)
     279            0 :             bitmap_set_bit (names_in_il, SSA_NAME_VERSION (t));
     280              :         }
     281              :     }
     282              : 
     283              :   /* Now walk the free list noting what we find there and verifying
     284              :      there are no duplicates.  */
     285            0 :   auto_bitmap names_in_freelists;
     286            0 :   if (FREE_SSANAMES (fun))
     287              :     {
     288            0 :       for (unsigned int i = 0; i < FREE_SSANAMES (fun)->length (); i++)
     289              :         {
     290            0 :           tree t = (*FREE_SSANAMES (fun))[i];
     291              : 
     292              :           /* Verify that the name is marked as being in the free list.  */
     293            0 :           gcc_assert (SSA_NAME_IN_FREE_LIST (t));
     294              : 
     295              :           /* Verify the name has not already appeared in the free list and
     296              :              note it in the list of names found in the free list.  */
     297            0 :           gcc_assert (!bitmap_bit_p (names_in_freelists, SSA_NAME_VERSION (t)));
     298            0 :           bitmap_set_bit (names_in_freelists, SSA_NAME_VERSION (t));
     299              :         }
     300              :     }
     301              : 
     302              :   /* Similarly for the names in the pending free list.  */
     303            0 :   if (FREE_SSANAMES_QUEUE (fun))
     304              :     {
     305            0 :       for (unsigned int i = 0; i < FREE_SSANAMES_QUEUE (fun)->length (); i++)
     306              :         {
     307            0 :           tree t = (*FREE_SSANAMES_QUEUE (fun))[i];
     308              : 
     309              :           /* Verify that the name is marked as being in the free list.  */
     310            0 :           gcc_assert (SSA_NAME_IN_FREE_LIST (t));
     311              : 
     312              :           /* Verify the name has not already appeared in the free list and
     313              :              note it in the list of names found in the free list.  */
     314            0 :           gcc_assert (!bitmap_bit_p (names_in_freelists, SSA_NAME_VERSION (t)));
     315            0 :           bitmap_set_bit (names_in_freelists, SSA_NAME_VERSION (t));
     316              :         }
     317              :     }
     318              : 
     319              :   /* If any name appears in both the IL and the freelists, then
     320              :      something horrible has happened.  */
     321            0 :   bool intersect_p = bitmap_intersect_p (names_in_il, names_in_freelists);
     322            0 :   gcc_assert (!intersect_p);
     323              : 
     324              :   /* Names can be queued up for release if there is an ssa update
     325              :      pending.  Pretend we saw them in the IL.  */
     326            0 :   if (names_to_release)
     327            0 :     bitmap_ior_into (names_in_il, names_to_release);
     328              : 
     329              :   /* Function splitting can "lose" SSA_NAMEs in an effort to ensure that
     330              :      debug/non-debug compilations have the same SSA_NAMEs.  So for each
     331              :      lost SSA_NAME, see if it's likely one from that wart.  These will always
     332              :      be marked as default definitions.  So we loosely assume that anything
     333              :      marked as a default definition isn't leaked by pretending they are
     334              :      in the IL.  */
     335            0 :   for (unsigned int i = UNUSED_NAME_VERSION + 1; i < num_ssa_names; i++)
     336            0 :     if (ssa_name (i) && SSA_NAME_IS_DEFAULT_DEF (ssa_name (i)))
     337            0 :       bitmap_set_bit (names_in_il, i);
     338              : 
     339            0 :   unsigned int i;
     340            0 :   bitmap_iterator bi;
     341            0 :   auto_bitmap all_names;
     342            0 :   bitmap_set_range (all_names, UNUSED_NAME_VERSION + 1, num_ssa_names - 1);
     343            0 :   bitmap_ior_into (names_in_il, names_in_freelists);
     344              : 
     345              :   /* Any name not mentioned in the IL and not in the feelists
     346              :      has been leaked.  */
     347            0 :   EXECUTE_IF_AND_COMPL_IN_BITMAP(all_names, names_in_il,
     348              :                                  UNUSED_NAME_VERSION + 1, i, bi)
     349            0 :     gcc_assert (!ssa_name (i));
     350            0 : }
     351              : 
     352              : /* Move all SSA_NAMEs from FREE_SSA_NAMES_QUEUE to FREE_SSA_NAMES.
     353              : 
     354              :    We do not, but should have a mode to verify the state of the SSA_NAMEs
     355              :    lists.  In particular at this point every name must be in the IL,
     356              :    on the free list or in the queue.  Anything else is an error.  */
     357              : 
     358              : void
     359    650083815 : flush_ssaname_freelist (void)
     360              : {
     361              :   /* If there were any SSA names released reset the SCEV cache.  */
     362    650083815 :   if (! vec_safe_is_empty (FREE_SSANAMES_QUEUE (cfun)))
     363     11009980 :     scev_reset_htab ();
     364    650083815 :   vec_safe_splice (FREE_SSANAMES (cfun), FREE_SSANAMES_QUEUE (cfun));
     365    650083815 :   vec_safe_truncate (FREE_SSANAMES_QUEUE (cfun), 0);
     366    650083815 : }
     367              : 
     368              : /* Initialize SSA_NAME_IMM_USE_NODE of a SSA NAME.  */
     369              : 
     370              : void
     371    157322583 : init_ssa_name_imm_use (tree name)
     372              : {
     373    157322583 :   use_operand_p imm;
     374    157322583 :   imm = &(SSA_NAME_IMM_USE_NODE (name));
     375    157322583 :   imm->use = NULL;
     376    157322583 :   imm->prev = imm;
     377    157322583 :   imm->next = imm;
     378    157322583 :   imm->loc.ssa_name = name;
     379    157322583 : }
     380              : 
     381              : /* Return an SSA_NAME node for variable VAR defined in statement STMT
     382              :    in function FN.  STMT may be an empty statement for artificial
     383              :    references (e.g., default definitions created when a variable is
     384              :    used without a preceding definition).  If VERISON is not zero then
     385              :    allocate the SSA name with that version.  */
     386              : 
     387              : tree
     388    155639477 : make_ssa_name_fn (struct function *fn, tree var, gimple *stmt,
     389              :                   unsigned int version)
     390              : {
     391    155639477 :   tree t;
     392    155639477 :   gcc_assert (VAR_P (var)
     393              :               || TREE_CODE (var) == PARM_DECL
     394              :               || TREE_CODE (var) == RESULT_DECL
     395              :               || (TYPE_P (var) && is_gimple_reg_type (var)));
     396              : 
     397              :   /* Get the specified SSA name version.  */
     398    155639477 :   if (version != 0)
     399              :     {
     400         8518 :       t = make_node (SSA_NAME);
     401         8518 :       SSA_NAME_VERSION (t) = version;
     402         8518 :       if (version >= SSANAMES (fn)->length ())
     403         2311 :         vec_safe_grow_cleared (SSANAMES (fn), version + 1, true);
     404         8518 :       gcc_assert ((*SSANAMES (fn))[version] == NULL);
     405         8518 :       (*SSANAMES (fn))[version] = t;
     406         8518 :       ssa_name_nodes_created++;
     407              :     }
     408              :   /* If our free list has an element, then use it.  */
     409    155630959 :   else if (!vec_safe_is_empty (FREE_SSANAMES (fn)))
     410              :     {
     411     32412762 :       t = FREE_SSANAMES (fn)->pop ();
     412     32412762 :       ssa_name_nodes_reused++;
     413              : 
     414              :       /* The node was cleared out when we put it on the free list, so
     415              :          there is no need to do so again here.  */
     416     32412762 :       gcc_assert ((*SSANAMES (fn))[SSA_NAME_VERSION (t)] == NULL);
     417     32412762 :       (*SSANAMES (fn))[SSA_NAME_VERSION (t)] = t;
     418              :     }
     419              :   else
     420              :     {
     421    123218197 :       t = make_node (SSA_NAME);
     422    123218197 :       SSA_NAME_VERSION (t) = SSANAMES (fn)->length ();
     423    123218197 :       vec_safe_push (SSANAMES (fn), t);
     424    123218197 :       ssa_name_nodes_created++;
     425              :     }
     426              : 
     427    155639477 :   if (TYPE_P (var))
     428              :     {
     429     59565109 :       TREE_TYPE (t) = TYPE_MAIN_VARIANT (var);
     430     59565109 :       SET_SSA_NAME_VAR_OR_IDENTIFIER (t, NULL_TREE);
     431              :     }
     432              :   else
     433              :     {
     434     96074368 :       TREE_TYPE (t) = TREE_TYPE (var);
     435    141062752 :       SET_SSA_NAME_VAR_OR_IDENTIFIER (t, var);
     436              :     }
     437    155639477 :   SSA_NAME_DEF_STMT (t) = stmt;
     438    155639477 :   SSA_NAME_RANGE_INFO (t) = NULL;
     439              : 
     440    155639477 :   SSA_NAME_IN_FREE_LIST (t) = 0;
     441    155639477 :   SSA_NAME_IS_DEFAULT_DEF (t) = 0;
     442    155639477 :   init_ssa_name_imm_use (t);
     443              : #if defined ENABLE_GIMPLE_CHECKING
     444    155639477 :   t->ssa_name.active_iterated_stmt = NULL;
     445    155639477 :   t->ssa_name.fast_iteration_depth = 0;
     446              : #endif
     447              : 
     448    155639477 :   return t;
     449              : }
     450              : 
     451              : /* Update the range information for NAME, intersecting into an existing
     452              :    range if applicable.  Return TRUE if the range was updated.  */
     453              : 
     454              : bool
     455     49288957 : set_range_info (tree name, const vrange &r)
     456              : {
     457     49288957 :   if (r.undefined_p () || r.varying_p ())
     458              :     return false;
     459              : 
     460              :   // Pick up the current range, or VARYING if none.
     461     49101031 :   tree type = TREE_TYPE (name);
     462     49101031 :   value_range tmp (type);
     463     49101031 :   if (SSA_NAME_RANGE_INFO (name))
     464     39676114 :     range_info_get_range (name, tmp);
     465              :   else
     466      9424917 :     tmp.set_varying (type);
     467              : 
     468              :   // If the result doesn't change, or is undefined, return false.
     469     49101031 :   if (!tmp.intersect (r) || tmp.undefined_p ())
     470              :     return false;
     471              : 
     472     15948076 :   if (!range_info_set_range (name, tmp))
     473              :     return false;
     474              : 
     475     15948076 :   if (dump_file)
     476              :     {
     477         5015 :       value_range tmp (type);
     478         5015 :       fprintf (dump_file, "Global Exported: ");
     479         5015 :       print_generic_expr (dump_file, name, TDF_SLIM);
     480         5015 :       fprintf (dump_file, " = ");
     481         5015 :       gimple_range_global (tmp, name);
     482         5015 :       tmp.dump (dump_file);
     483         5015 :       fputc ('\n', dump_file);
     484         5015 :     }
     485              :   // Update the active query, if needed.
     486     15948076 :   get_range_query (cfun)->update_range_info (name, r);
     487     15948076 :   return true;
     488     49101031 : }
     489              : 
     490              : /* query nonnull attribute for pointer NAME.  */
     491              : 
     492              : bool
     493     36795832 : ptr_nonnull_p (tree name)
     494              : {
     495     36795832 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
     496     36795832 :   prange_storage *ps = ssa_name_prange_info (name);
     497     36795832 :   return ps ? ps->nonnull_p (TREE_TYPE (name)) : false;
     498              : }
     499              : 
     500              : /* Set nonnull attribute to pointer NAME.  */
     501              : 
     502              : void
     503      4704060 : set_ptr_nonnull (tree name)
     504              : {
     505      4704060 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
     506      4704060 :   prange_storage *ps = ssa_name_prange_info (name);
     507      4704060 :   if (ps)
     508              :     {
     509      4704060 :       ps->set_nonnull (TREE_TYPE (name));
     510      4704060 :       return;
     511              :     }
     512            0 :   prange pr;
     513            0 :   pr.set_nonzero (TREE_TYPE (name));
     514            0 :   range_info_set_range (name, pr);
     515            0 : }
     516              : 
     517              : /* Update the non-zero bits bitmask of NAME.  */
     518              : 
     519              : void
     520            1 : set_nonzero_bits (tree name, const wide_int &mask)
     521              : {
     522            1 :   if (POINTER_TYPE_P (TREE_TYPE (name)))
     523              :     {
     524            0 :       prange p (TREE_TYPE (name));
     525            0 :       p.set_nonzero_bits (mask);
     526            0 :       set_range_info (name, p);
     527            0 :       return;
     528            0 :     }
     529              : 
     530            1 :   int_range<2> r (TREE_TYPE (name));
     531            1 :   r.set_nonzero_bits (mask);
     532            1 :   set_range_info (name, r);
     533            1 : }
     534              : 
     535              : /* Update the known bits of NAME.
     536              : 
     537              :    Zero bits in MASK cover constant values.  Set bits in MASK cover
     538              :    unknown values.  VALUE are the known bits.  */
     539              : 
     540              : void
     541     15349167 : set_bitmask (tree name, const wide_int &value, const wide_int &mask)
     542              : {
     543     15349167 :   if (POINTER_TYPE_P (TREE_TYPE (name)))
     544              :     {
     545      1444317 :       prange p (TREE_TYPE (name));
     546      1444317 :       p.update_bitmask (irange_bitmask (value, mask));
     547      1444317 :       set_range_info (name, p);
     548      1444317 :       return;
     549      1444317 :     }
     550              : 
     551     13904850 :   int_range_max r (TREE_TYPE (name));
     552     13904850 :   r.update_bitmask (irange_bitmask (value, mask));
     553     13904850 :   set_range_info (name, r);
     554     13904850 : }
     555              : 
     556              : /* Return a wide_int with potentially non-zero bits in SSA_NAME
     557              :    NAME, the constant for INTEGER_CST, or -1 if unknown.  */
     558              : 
     559              : static wide_int
     560    934355979 : get_nonzero_bits_1 (const_tree name)
     561              : {
     562    934355979 :   if (TREE_CODE (name) == INTEGER_CST)
     563    169382042 :     return wi::to_wide (name);
     564              : 
     565    764973937 :   if (POLY_INT_CST_P (name))
     566              :     return -known_alignment (wi::to_poly_wide (name));
     567              : 
     568              :   /* Use element_precision instead of TYPE_PRECISION so complex and
     569              :      vector types get a non-zero precision.  */
     570    764973937 :   unsigned int precision = element_precision (TREE_TYPE (name));
     571              : 
     572    764973937 :   if (VECTOR_TYPE_P (TREE_TYPE (name)))
     573              :     {
     574        40554 :       tree elem = uniform_vector_p (name);
     575        40554 :       if (elem)
     576         1974 :         return get_nonzero_bits_1 (elem);
     577              :     }
     578              : 
     579    764971963 :   if (TREE_CODE (name) != SSA_NAME || !SSA_NAME_RANGE_INFO (name))
     580    489409849 :     return wi::shwi (-1, precision);
     581              : 
     582              :   // Alignment information is encoded in the bitmask, so pointers simply
     583              :   // need to extract the bitmask like integers do.
     584    275562114 :   if (POINTER_TYPE_P (TREE_TYPE (name)))
     585              :     {
     586     45676814 :       prange_storage *s = ssa_name_prange_info (name);
     587     45676814 :       gcc_checking_assert (s);
     588     45676814 :       return s->get_bitmask (TREE_TYPE (name)).get_nonzero_bits ();
     589              :     }
     590              : 
     591    229885300 :   if (!irange::supports_p (TREE_TYPE (name)))
     592       711170 :     return wi::shwi (-1, precision);
     593              : 
     594    229174130 :   int_range_max tmp;
     595    229174130 :   range_info_get_range (name, tmp);
     596    229174130 :   return tmp.get_nonzero_bits ();
     597    229174130 : }
     598              : 
     599              : /* Return a wide_int with potentially non-zero bits in SSA_NAME
     600              :    NAME, the constant for INTEGER_CST, or -1 if unknown.
     601              :    In addition to what get_nonzero_bits_1 handles, this handles one
     602              :    level of BIT_AND_EXPR, either as a def_stmt or tree directly.  */
     603              : 
     604              : wide_int
     605    878415709 : get_nonzero_bits (const_tree name)
     606              : {
     607    878415709 :   if (TREE_CODE (name) == BIT_AND_EXPR)
     608      3682828 :     return (get_nonzero_bits_1 (TREE_OPERAND (name, 0))
     609      5524242 :             & get_nonzero_bits_1 (TREE_OPERAND (name, 1)));
     610    876574295 :   if (TREE_CODE (name) == SSA_NAME)
     611              :     {
     612    723842577 :       gimple *g = SSA_NAME_DEF_STMT (name);
     613    723842577 :       if (g
     614    723842475 :           && is_gimple_assign (g)
     615   1255423611 :           && gimple_assign_rhs_code (g) == BIT_AND_EXPR)
     616     54096882 :         return (get_nonzero_bits_1 (name)
     617    108193764 :                 & get_nonzero_bits_1 (gimple_assign_rhs1 (g))
     618     81145323 :                 & get_nonzero_bits_1 (gimple_assign_rhs2 (g)));
     619              :     }
     620    849525854 :   return get_nonzero_bits_1 (name);
     621              : }
     622              : 
     623              : /* Return a wide_int with known non-zero bits in SSA_NAME
     624              :    NAME (bits whose values aren't known are also clear), the constant
     625              :    for INTEGER_CST, or 0 if unknown.  */
     626              : 
     627              : static wide_int
     628    390377912 : get_known_nonzero_bits_1 (const_tree name)
     629              : {
     630    390377912 :   if (TREE_CODE (name) == INTEGER_CST)
     631    182207964 :     return wi::to_wide (name);
     632              : 
     633              :   /* Use element_precision instead of TYPE_PRECISION so complex and
     634              :      vector types get a non-zero precision.  */
     635    208169948 :   unsigned int precision = element_precision (TREE_TYPE (name));
     636    208169948 :   if (TREE_CODE (name) != SSA_NAME)
     637        14980 :     return wi::shwi (0, precision);
     638              : 
     639    208154968 :   if (!SSA_NAME_RANGE_INFO (name))
     640    160833430 :     return wi::shwi (0, precision);
     641              : 
     642              :   // Known pointer bits, including alignment, are encoded in the bitmask
     643     47321538 :   if (POINTER_TYPE_P (TREE_TYPE (name)))
     644              :     {
     645            0 :       prange_storage *s = ssa_name_prange_info (name);
     646            0 :       gcc_checking_assert (s);
     647            0 :       if (s->undefined_p ())
     648            0 :         return wi::shwi (0, precision);
     649            0 :       irange_bitmask bm = s->get_bitmask (TREE_TYPE (name));
     650            0 :       return wi::bit_and_not (bm.value (), bm.mask ());
     651            0 :     }
     652              : 
     653     47321538 :   if (!irange::supports_p (TREE_TYPE (name)))
     654            0 :     return wi::shwi (0, precision);
     655              : 
     656     47321538 :   int_range_max tmp;
     657     47321538 :   range_info_get_range (name, tmp);
     658     47321538 :   if (tmp.undefined_p ())
     659            0 :     return wi::shwi (0, precision);
     660     47321538 :   irange_bitmask bm = tmp.get_bitmask ();
     661     47321576 :   return wi::bit_and_not (bm.value (), bm.mask ());
     662     47321538 : }
     663              : 
     664              : /* Return a wide_int with known non-zero bits in SSA_NAME
     665              :    NAME, the constant for INTEGER_CST, or 0 if unknown.
     666              :    In addition to what get_known_nonzero_bits_1 handles, this handles one
     667              :    level of BIT_IOR_EXPR, either as a def_stmt or tree directly.  */
     668              : 
     669              : wide_int
     670    382300774 : get_known_nonzero_bits (const_tree name)
     671              : {
     672    382300774 :   if (TREE_CODE (name) == BIT_IOR_EXPR)
     673       540904 :     return (get_known_nonzero_bits_1 (TREE_OPERAND (name, 0))
     674       811356 :             | get_known_nonzero_bits_1 (TREE_OPERAND (name, 1)));
     675    382030322 :   if (TREE_CODE (name) == SSA_NAME)
     676              :     {
     677    199849255 :       gimple *g = SSA_NAME_DEF_STMT (name);
     678    199849255 :       if (g
     679    199849255 :           && is_gimple_assign (g)
     680    333310608 :           && gimple_assign_rhs_code (g) == BIT_IOR_EXPR)
     681      7806686 :         return (get_known_nonzero_bits_1 (name)
     682     15613372 :                 | get_known_nonzero_bits_1 (gimple_assign_rhs1 (g))
     683     11710029 :                 | get_known_nonzero_bits_1 (gimple_assign_rhs2 (g)));
     684              :     }
     685    378126979 :   return get_known_nonzero_bits_1 (name);
     686              : }
     687              : 
     688              : /* Return TRUE is OP, an SSA_NAME has a range of values [0..1] at the
     689              :    STMT, false otherwise.
     690              : 
     691              :    This can be because it is a boolean type, any unsigned integral
     692              :    type with a single bit of precision, or has known range of [0..1]
     693              :    via range analysis.  */
     694              : 
     695              : bool
     696     20274325 : ssa_name_has_boolean_range (tree op, gimple *stmt)
     697              : {
     698     20274325 :   gcc_assert (TREE_CODE (op) == SSA_NAME);
     699              : 
     700              :   /* An integral type with a single bit of precision.  */
     701     40158717 :   if (INTEGRAL_TYPE_P (TREE_TYPE (op))
     702     15655025 :       && TYPE_UNSIGNED (TREE_TYPE (op))
     703     29415717 :       && TYPE_PRECISION (TREE_TYPE (op)) == 1)
     704              :     return true;
     705              : 
     706              :   /* An integral type with more precision, but the object
     707              :      only takes on values [0..1] as determined by range
     708              :      analysis.  */
     709     34599964 :   if (INTEGRAL_TYPE_P (TREE_TYPE (op))
     710     29980664 :       && (TYPE_PRECISION (TREE_TYPE (op)) > 1))
     711              :     {
     712     12874145 :       int_range<2> r;
     713     25748290 :       if (get_range_query (cfun)->range_of_expr (r, op, stmt)
     714     12874145 :           && r == range_true_and_false (TREE_TYPE (op)))
     715              :         return true;
     716              : 
     717     12501771 :       if (wi::eq_p (get_nonzero_bits (op), 1))
     718              :         return true;
     719     12874145 :     }
     720              : 
     721              :   return false;
     722              : }
     723              : 
     724              : /* We no longer need the SSA_NAME expression VAR, release it so that
     725              :    it may be reused.
     726              : 
     727              :    Note it is assumed that no calls to make_ssa_name will be made
     728              :    until all uses of the ssa name are released and that the only
     729              :    use of the SSA_NAME expression is to check its SSA_NAME_VAR.  All
     730              :    other fields must be assumed clobbered.  */
     731              : 
     732              : void
     733     87202915 : release_ssa_name_fn (struct function *fn, tree var)
     734              : {
     735     87202915 :   if (!var)
     736              :     return;
     737              : 
     738              :   /* Never release the default definition for a symbol.  It's a
     739              :      special SSA name that should always exist once it's created.  */
     740     87202915 :   if (SSA_NAME_IS_DEFAULT_DEF (var))
     741              :     return;
     742              : 
     743              :   /* If VAR has been registered for SSA updating, don't remove it.
     744              :      After update_ssa has run, the name will be released.  */
     745     87202887 :   if (name_registered_for_update_p (var))
     746              :     {
     747       851642 :       release_ssa_name_after_update_ssa (var);
     748       851642 :       return;
     749              :     }
     750              : 
     751              :   /* release_ssa_name can be called multiple times on a single SSA_NAME.
     752              :      However, it should only end up on our free list one time.   We
     753              :      keep a status bit in the SSA_NAME node itself to indicate it has
     754              :      been put on the free list.
     755              : 
     756              :      Note that once on the freelist you cannot reference the SSA_NAME's
     757              :      defining statement.  */
     758     86351245 :   if (! SSA_NAME_IN_FREE_LIST (var))
     759              :     {
     760     86351245 :       int saved_ssa_name_version = SSA_NAME_VERSION (var);
     761     86351245 :       use_operand_p imm = &(SSA_NAME_IMM_USE_NODE (var));
     762              : 
     763     86351245 :       if (MAY_HAVE_DEBUG_BIND_STMTS)
     764     56732511 :         insert_debug_temp_for_var_def (NULL, var);
     765              : 
     766     86351245 :       if (flag_checking)
     767     86350664 :         verify_imm_links (stderr, var);
     768     97437159 :       while (imm->next != imm)
     769     11085914 :         delink_imm_use (imm->next);
     770              : 
     771     86351245 :       (*SSANAMES (fn))[SSA_NAME_VERSION (var)] = NULL_TREE;
     772     86351245 :       memset (var, 0, tree_size (var));
     773              : 
     774     86351245 :       imm->prev = imm;
     775     86351245 :       imm->next = imm;
     776     86351245 :       imm->loc.ssa_name = var;
     777              : 
     778              :       /* First put back the right tree node so that the tree checking
     779              :          macros do not complain.  */
     780     86351245 :       TREE_SET_CODE (var, SSA_NAME);
     781              : 
     782              :       /* Restore the version number.  */
     783     86351245 :       SSA_NAME_VERSION (var) = saved_ssa_name_version;
     784              : 
     785              :       /* Note this SSA_NAME is now in the first list.  */
     786     86351245 :       SSA_NAME_IN_FREE_LIST (var) = 1;
     787              : 
     788              :       /* Put in a non-NULL TREE_TYPE so dumping code will not ICE
     789              :          if it happens to come along a released SSA name and tries
     790              :          to inspect its type.  */
     791     86351245 :       TREE_TYPE (var) = error_mark_node;
     792              : 
     793              :       /* And finally queue it so that it will be put on the free list.  */
     794     86351245 :       vec_safe_push (FREE_SSANAMES_QUEUE (fn), var);
     795              :     }
     796              : }
     797              : 
     798              : /* Return the bitmask expressing byte alignment ALIGN with byte offset
     799              :    MISALIGN for a pointer of type TYPE.  */
     800              : 
     801              : static irange_bitmask
     802       360807 : alignment_to_bitmask (tree type, unsigned int align, unsigned int misalign)
     803              : {
     804              :   /* ptr & (ALIGN - 1) == MISALIGN says the low log2(ALIGN) bits of the pointer
     805              :      are known and hold MISALIGN, so the unknown-bit mask is ~(ALIGN - 1) and
     806              :      the known value is MISALIGN.
     807              :      An ALIGN of 1 carries no information and yields an unknown bitmask.  */
     808       360807 :   unsigned int prec = TYPE_PRECISION (type);
     809       360807 :   wide_int value = wi::uhwi (misalign, prec);
     810       360807 :   wide_int low_bits = wi::uhwi (align - 1, prec);
     811       360807 :   return irange_bitmask (value, ~low_bits);
     812       360807 : }
     813              : 
     814              : /* if BM contains usable alignment info, return the byte alignment and offset
     815              :    in ALIGNP and MISALIGNP.  Otherwise return FALSE.  */
     816              : 
     817              : static bool
     818     51685641 : bitmask_to_alignment (const irange_bitmask &bm, unsigned int *alignp,
     819              :                       unsigned int *misalignp)
     820              : {
     821     51685641 :   if (bm.unknown_p ())
     822              :     return false;
     823              : 
     824      6647243 :   wide_int mask = bm.mask ();
     825      6647243 :   unsigned int bit;
     826              : 
     827              :   /* A fully known pointer supports any representable alignment, with
     828              :      the corresponding offset.  Otherwise stop at the first unknown bit.  */
     829     13294486 :   bit = mask == 0 ? bm.value ().get_precision () : wi::ctz (mask);
     830      6647243 :   if (bit == 0)
     831              :     return false;
     832              : 
     833              :   /* A more strongly calculated alignment should simply be max alignment.  */
     834      6550621 :   if (bit > HOST_BITS_PER_INT - 1)
     835              :     bit = HOST_BITS_PER_INT - 1;
     836              : 
     837      6550621 :   *alignp = 1u << bit;
     838      6550621 :   *misalignp = wi::extract_uhwi (bm.value (), 0, bit);
     839      6550621 :   return true;
     840      6647243 : }
     841              : 
     842              : /* Extract useful alignment information from NAME's global range.  Return
     843              :    false if no alignment beyond byte alignment is known.  */
     844              : 
     845              : bool
     846     58634972 : get_ssa_name_alignment (const_tree name, unsigned int *alignp,
     847              :                         unsigned int *misalignp)
     848              : {
     849    117259665 :   if (!POINTER_TYPE_P (TREE_TYPE (name)) || !SSA_NAME_RANGE_INFO (name))
     850              :     return false;
     851              : 
     852     51685641 :   prange_storage *s = ssa_name_prange_info (name);
     853     51685641 :   if (!s)
     854              :     return false;
     855              : 
     856     51685641 :   return bitmask_to_alignment (s->get_bitmask (TREE_TYPE (name)),
     857              :                                alignp, misalignp);
     858              : }
     859              : 
     860              : /* Clear NAME's known bits independently of the legacy alignment fields.  */
     861              : 
     862              : void
     863            0 : mark_ssa_name_alignment_unknown (tree name)
     864              : {
     865            0 :   if (!SSA_NAME_RANGE_INFO (name))
     866            0 :     return;
     867              : 
     868            0 :   prange r (TREE_TYPE (name));
     869            0 :   range_info_get_range (name, r);
     870            0 :   if (r.undefined_p ())
     871            0 :     return;
     872              : 
     873              :   /* Withdraw the known bits or the alignment survives in the bitmask.  */
     874            0 :   irange_bitmask unknown (TYPE_PRECISION (TREE_TYPE (name)));
     875            0 :   r.update_bitmask (unknown);
     876            0 :   range_info_set_range (name, r);
     877            0 : }
     878              : 
     879              : /* Refine NAME's bitmask with ALIGN and MISALIGN.  Preserve the existing
     880              :    information if the requested alignment conflicts with known bits.  */
     881              : 
     882              : void
     883       360807 : set_ssa_name_alignment (tree name, unsigned int align, unsigned int misalign)
     884              : {
     885       360807 :   gcc_checking_assert (align != 0);
     886       360807 :   gcc_assert ((align & (align - 1)) == 0);
     887       360807 :   gcc_assert ((misalign & ~(align - 1)) == 0);
     888       360807 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
     889              : 
     890       360807 :   tree type = TREE_TYPE (name);
     891       360807 :   irange_bitmask bm = alignment_to_bitmask (type, align, misalign);
     892       360807 :   if (bm.unknown_p ())
     893              :     return;
     894              : 
     895       334713 :   prange r (type);
     896       334713 :   if (SSA_NAME_RANGE_INFO (name))
     897       285210 :     range_info_get_range (name, r);
     898       334713 :   if (r.undefined_p ())
     899              :     return;
     900              : 
     901       334713 :   irange_bitmask cur = r.get_bitmask ();
     902       334713 :   if (!cur.intersect (bm))
     903            0 :     return;
     904              : 
     905       334713 :   r.update_bitmask (cur);
     906       334713 :   if (!r.undefined_p ())
     907       334713 :     range_info_set_range (name, r);
     908       360807 : }
     909              : 
     910              : 
     911              : /* Creates a new SSA name using the template NAME tobe defined by
     912              :    statement STMT in function FN.  */
     913              : 
     914              : tree
     915     20119397 : copy_ssa_name_fn (struct function *fn, tree name, gimple *stmt)
     916              : {
     917     20119397 :   tree new_name;
     918              : 
     919     20119397 :   if (SSA_NAME_VAR (name))
     920     12801713 :     new_name = make_ssa_name_fn (fn, SSA_NAME_VAR (name), stmt);
     921              :   else
     922              :     {
     923      7317684 :       new_name = make_ssa_name_fn (fn, TREE_TYPE (name), stmt);
     924     14635368 :       SET_SSA_NAME_VAR_OR_IDENTIFIER (new_name, SSA_NAME_IDENTIFIER (name));
     925              :     }
     926              : 
     927     20119397 :   return new_name;
     928              : }
     929              : 
     930              : /* Give DEST its own copy of the points-to information of
     931              :    the SSA name SRC.  SRC may be NULL_TREE or carry no information, in
     932              :    which case DEST is left alone.  */
     933              : 
     934              : void
     935      3157981 : duplicate_ssa_name_pt_solution (tree dest, const pt_solution* pt)
     936              : {
     937      3157981 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (dest)));
     938      5615429 :   gcc_assert (!ssa_name_pt_solution (dest));
     939              : 
     940      3157981 :   if (!pt)
     941              :     return;
     942      3117010 :   pt_solution *copy = ggc_alloc<pt_solution> ();
     943      3117010 :   *copy = *pt;
     944      3117010 :   set_pt_solution (dest, copy);
     945              : }
     946              : 
     947              : /* Give DEST its own copy of the points-to information of
     948              :    the SSA name SRC.  SRC may be NULL_TREE or carry no information, in
     949              :    which case DEST is left alone.  */
     950              : 
     951              : void
     952      7533962 : duplicate_ssa_name_pt_solution (tree dest, tree src)
     953              : {
     954      7533962 :   if (!src)
     955              :      return;
     956              : 
     957     10462000 :   if (const pt_solution *pt = ssa_name_pt_solution (src))
     958      2746161 :     duplicate_ssa_name_pt_solution (dest, pt);
     959              : }
     960              : 
     961              : /* Copy any global range information from SRC to NAME.  If REMOVE_LOCAL_ADDR
     962              :    is true, then any specified address that a prange may refer to is checked
     963              :    to see if it's local to the function and removed if so.
     964              :    The default is FALSE, which is the previous default behaviour and copies
     965              :    the entire range as is.  */
     966              : 
     967              : void
     968     17947001 : duplicate_ssa_name_range_info (tree name, tree src, bool remove_local_addr)
     969              : {
     970     17947001 :   gcc_checking_assert (!SSA_NAME_RANGE_INFO (name));
     971              : 
     972     17947001 :   if (!SSA_NAME_RANGE_INFO (src))
     973            0 :     return;
     974              : 
     975     17947001 :   value_range src_range (TREE_TYPE (src));
     976     17947001 :   range_info_get_range (src, src_range);
     977              : 
     978              :   /* Remove any local addresses from the range if present.  */
     979     17947001 :   if (remove_local_addr && is_a <prange> (src_range))
     980      6499806 :     as_a <prange> (src_range).clear_function_local_addr ();
     981     17947001 :   range_info_set_range (name, src_range);
     982     17947001 : }
     983              : 
     984              : /* For a SSA copy DEST = SRC duplicate SSA info present on DEST to SRC
     985              :    to preserve it in case DEST is eliminated to SRC.  */
     986              : 
     987              : void
     988     55548503 : maybe_duplicate_ssa_info_at_copy (tree dest, tree src)
     989              : {
     990              :   /* While points-to info is flow-insensitive we have to avoid copying
     991              :      info from not executed regions invoking UB to dominating defs.  */
     992     55548503 :   if (gimple_bb (SSA_NAME_DEF_STMT (src))
     993     55548503 :       != gimple_bb (SSA_NAME_DEF_STMT (dest)))
     994              :     return;
     995              : 
     996     43048814 :   if (SSA_NAME_RANGE_INFO (dest) && !SSA_NAME_RANGE_INFO (src))
     997              :     {
     998       622033 :       duplicate_ssa_name_range_info (src, dest);
     999       622033 :       duplicate_ssa_name_pt_solution (src, dest);
    1000              :     }
    1001              : }
    1002              : 
    1003              : 
    1004              : /* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
    1005              :    in function FN.  */
    1006              : 
    1007              : tree
    1008     18413447 : duplicate_ssa_name_fn (struct function *fn, tree name, gimple *stmt)
    1009              : {
    1010     18413447 :   tree new_name = copy_ssa_name_fn (fn, name, stmt);
    1011              : 
    1012     18413447 :   if (SSA_NAME_RANGE_INFO (name))
    1013              :     {
    1014      6623161 :       duplicate_ssa_name_range_info (new_name, name);
    1015      6623161 :       duplicate_ssa_name_pt_solution (new_name, name);
    1016              :     }
    1017              : 
    1018     18413447 :   return new_name;
    1019              : }
    1020              : 
    1021              : 
    1022              : /* Reset all flow sensitive data on NAME such as range-info, nonzero
    1023              :    bits and alignment.  */
    1024              : 
    1025              : void
    1026      7939940 : reset_flow_sensitive_info (tree name)
    1027              : {
    1028              :   /* Aliasing info is not flow sensitive, so preserve it if present.  */
    1029      7939940 :   prange_storage *s = ssa_name_prange_info (name);
    1030      7939940 :   pt_solution *pt = s ? s->pt : NULL;
    1031              : 
    1032      7939940 :   SSA_NAME_RANGE_INFO (name) = NULL;
    1033      7939940 :   if (pt)
    1034       751644 :     set_pt_solution (name, pt);
    1035              : 
    1036              :   // Clear range info in the current range query.
    1037     15879880 :   get_range_query (cfun)->reset_range_info (name);
    1038      7939940 : }
    1039              : 
    1040              : /* Clear all flow sensitive data from all statements and PHI definitions
    1041              :    in BB.  */
    1042              : 
    1043              : void
    1044      1420188 : reset_flow_sensitive_info_in_bb (basic_block bb)
    1045              : {
    1046      4146429 :   for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    1047      1306053 :        gsi_next (&gsi))
    1048              :     {
    1049      1306053 :       gimple *stmt = gsi_stmt (gsi);
    1050      1306053 :       ssa_op_iter i;
    1051      1306053 :       tree op;
    1052      1571597 :       FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF)
    1053       265544 :         reset_flow_sensitive_info (op);
    1054              :     }
    1055              : 
    1056      1432311 :   for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    1057        12123 :        gsi_next (&gsi))
    1058              :     {
    1059        12123 :       tree phi_def = gimple_phi_result (gsi.phi ());
    1060        12123 :       reset_flow_sensitive_info (phi_def);
    1061              :     }
    1062      1420188 : }
    1063              : 
    1064              : /* Release all the SSA_NAMEs created by STMT.  */
    1065              : 
    1066              : void
    1067     78874071 : release_defs (gimple *stmt)
    1068              : {
    1069     78874071 :   tree def;
    1070     78874071 :   ssa_op_iter iter;
    1071              : 
    1072    132611021 :   FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS)
    1073     53736950 :     if (TREE_CODE (def) == SSA_NAME)
    1074     53185064 :       release_ssa_name (def);
    1075     78874071 : }
    1076              : 
    1077              : 
    1078              : /* Replace the symbol associated with SSA_NAME with SYM.  */
    1079              : 
    1080              : void
    1081        12816 : replace_ssa_name_symbol (tree ssa_name, tree sym)
    1082              : {
    1083        12816 :   SET_SSA_NAME_VAR_OR_IDENTIFIER (ssa_name, sym);
    1084        12816 :   TREE_TYPE (ssa_name) = TREE_TYPE (sym);
    1085        12816 : }
    1086              : 
    1087              : /* Release the vector of free SSA_NAMEs and compact the vector of SSA_NAMEs
    1088              :    that are live.  */
    1089              : 
    1090              : static void
    1091      2986306 : release_free_names_and_compact_live_names (function *fun)
    1092              : {
    1093      2986306 :   unsigned i, j;
    1094      2986306 :   int n = vec_safe_length (FREE_SSANAMES (fun));
    1095              : 
    1096              :   /* Now release the freelist.  */
    1097      2986306 :   vec_free (FREE_SSANAMES (fun));
    1098              : 
    1099              :   /* And compact the SSA number space.  We make sure to not change the
    1100              :      relative order of SSA versions.  */
    1101     85983528 :   for (i = 1, j = 1; i < fun->gimple_df->ssa_names->length (); ++i)
    1102              :     {
    1103     82997222 :       tree name = ssa_name (i);
    1104     82997222 :       if (name)
    1105              :         {
    1106     52576492 :           if (i != j)
    1107              :             {
    1108     32851490 :               SSA_NAME_VERSION (name) = j;
    1109     32851490 :               (*fun->gimple_df->ssa_names)[j] = name;
    1110              :             }
    1111     52576492 :           j++;
    1112              :         }
    1113              :     }
    1114      2986306 :   fun->gimple_df->ssa_names->truncate (j);
    1115              : 
    1116      2986306 :   statistics_counter_event (fun, "SSA names released", n);
    1117      2986306 :   statistics_counter_event (fun, "SSA name holes removed", i - j);
    1118      2986306 :   if (dump_file)
    1119          350 :     fprintf (dump_file, "Released %i names, %.2f%%, removed %i holes\n",
    1120          350 :              n, n * 100.0 / num_ssa_names, i - j);
    1121      2986306 : }
    1122              : 
    1123              : /* Return SSA names that are unused to GGC memory and compact the SSA
    1124              :    version namespace.  This is used to keep footprint of compiler during
    1125              :    interprocedural optimization.  */
    1126              : 
    1127              : namespace {
    1128              : 
    1129              : const pass_data pass_data_release_ssa_names =
    1130              : {
    1131              :   GIMPLE_PASS, /* type */
    1132              :   "release_ssa", /* name */
    1133              :   OPTGROUP_NONE, /* optinfo_flags */
    1134              :   TV_TREE_SSA_OTHER, /* tv_id */
    1135              :   PROP_ssa, /* properties_required */
    1136              :   0, /* properties_provided */
    1137              :   0, /* properties_destroyed */
    1138              :   TODO_remove_unused_locals, /* todo_flags_start */
    1139              :   0, /* todo_flags_finish */
    1140              : };
    1141              : 
    1142              : class pass_release_ssa_names : public gimple_opt_pass
    1143              : {
    1144              : public:
    1145       297180 :   pass_release_ssa_names (gcc::context *ctxt)
    1146       594360 :     : gimple_opt_pass (pass_data_release_ssa_names, ctxt)
    1147              :   {}
    1148              : 
    1149              :   /* opt_pass methods: */
    1150              :   unsigned int execute (function *) final override;
    1151              : 
    1152              : }; // class pass_release_ssa_names
    1153              : 
    1154              : unsigned int
    1155      2986306 : pass_release_ssa_names::execute (function *fun)
    1156              : {
    1157      2986306 :   release_free_names_and_compact_live_names (fun);
    1158      2986306 :   return 0;
    1159              : }
    1160              : 
    1161              : } // anon namespace
    1162              : 
    1163              : gimple_opt_pass *
    1164       297180 : make_pass_release_ssa_names (gcc::context *ctxt)
    1165              : {
    1166       297180 :   return new pass_release_ssa_names (ctxt);
    1167              : }
        

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