LCOV - code coverage report
Current view: top level - gcc - tree-ssa.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 86.3 % 1118 965
Test Date: 2026-08-22 16:33:35 Functions: 97.1 % 35 34
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Miscellaneous SSA utility functions.
       2              :    Copyright (C) 2001-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 "cfghooks.h"
      27              : #include "tree-pass.h"
      28              : #include "ssa.h"
      29              : #include "gimple-pretty-print.h"
      30              : #include "diagnostic-core.h"
      31              : #include "fold-const.h"
      32              : #include "stor-layout.h"
      33              : #include "gimple-iterator.h"
      34              : #include "gimple-fold.h"
      35              : #include "gimplify.h"
      36              : #include "gimple-walk.h"
      37              : #include "tree-ssa-loop-manip.h"
      38              : #include "tree-into-ssa.h"
      39              : #include "tree-ssa.h"
      40              : #include "cfgloop.h"
      41              : #include "cfgexpand.h"
      42              : #include "tree-cfg.h"
      43              : #include "tree-dfa.h"
      44              : #include "stringpool.h"
      45              : #include "attribs.h"
      46              : #include "asan.h"
      47              : 
      48              : /* Pointer map of variable mappings, keyed by edge.  */
      49              : static hash_map<edge, auto_vec<edge_var_map> > *edge_var_maps;
      50              : 
      51              : 
      52              : /* Add a mapping with PHI RESULT and PHI DEF associated with edge E.  */
      53              : 
      54              : void
      55     12258245 : redirect_edge_var_map_add (edge e, tree result, tree def, location_t locus)
      56              : {
      57     12258245 :   edge_var_map new_node;
      58              : 
      59     12258245 :   if (edge_var_maps == NULL)
      60        69894 :     edge_var_maps = new hash_map<edge, auto_vec<edge_var_map> >;
      61              : 
      62     12258245 :   auto_vec<edge_var_map> &slot = edge_var_maps->get_or_insert (e);
      63     12258245 :   new_node.def = def;
      64     12258245 :   new_node.result = result;
      65     12258245 :   new_node.locus = locus;
      66              : 
      67     12258245 :   slot.safe_push (new_node);
      68     12258245 : }
      69              : 
      70              : 
      71              : /* Clear the var mappings in edge E.  */
      72              : 
      73              : void
      74    143754112 : redirect_edge_var_map_clear (edge e)
      75              : {
      76    143754112 :   if (!edge_var_maps)
      77              :     return;
      78              : 
      79    127920300 :   auto_vec<edge_var_map> *head = edge_var_maps->get (e);
      80              : 
      81    127920300 :   if (head)
      82     10779386 :     head->release ();
      83              : }
      84              : 
      85              : 
      86              : /* Duplicate the redirected var mappings in OLDE in NEWE.
      87              : 
      88              :    This assumes a hash_map can have multiple edges mapping to the same
      89              :    var_map (many to one mapping), since we don't remove the previous mappings.
      90              :    */
      91              : 
      92              : void
      93       440597 : redirect_edge_var_map_dup (edge newe, edge olde)
      94              : {
      95       440597 :   if (!edge_var_maps)
      96              :     return;
      97              : 
      98       409852 :   auto_vec<edge_var_map> *new_head = &edge_var_maps->get_or_insert (newe);
      99       409852 :   auto_vec<edge_var_map> *old_head = edge_var_maps->get (olde);
     100       409852 :   if (!old_head)
     101              :     return;
     102              : 
     103         7858 :   new_head->safe_splice (*old_head);
     104              : }
     105              : 
     106              : 
     107              : /* Return the variable mappings for a given edge.  If there is none, return
     108              :    NULL.  */
     109              : 
     110              : vec<edge_var_map> *
     111      8486972 : redirect_edge_var_map_vector (edge e)
     112              : {
     113              :   /* Hey, what kind of idiot would... you'd be surprised.  */
     114      8486972 :   if (!edge_var_maps)
     115              :     return NULL;
     116              : 
     117      8460932 :   auto_vec<edge_var_map> *slot = edge_var_maps->get (e);
     118      8460932 :   if (!slot)
     119              :     return NULL;
     120              : 
     121              :   return slot;
     122              : }
     123              : 
     124              : /* Clear the edge variable mappings.  */
     125              : 
     126              : void
     127    944469514 : redirect_edge_var_map_empty (void)
     128              : {
     129    944469514 :   if (edge_var_maps)
     130    253624219 :     edge_var_maps->empty ();
     131    944469514 : }
     132              : 
     133              : 
     134              : /* Remove the corresponding arguments from the PHI nodes in E's
     135              :    destination block and redirect it to DEST.  Return redirected edge.
     136              :    The list of removed arguments is stored in a vector accessed
     137              :    through edge_var_maps.  */
     138              : 
     139              : edge
     140     64586711 : ssa_redirect_edge (edge e, basic_block dest)
     141              : {
     142     64586711 :   gphi_iterator gsi;
     143     64586711 :   gphi *phi;
     144              : 
     145     64586711 :   redirect_edge_var_map_clear (e);
     146              : 
     147              :   /* Remove the appropriate PHI arguments in E's destination block.
     148              :      If we are redirecting a copied edge the destination has not
     149              :      got PHI argument space reserved nor an interesting argument.  */
     150     64586711 :   if (! (e->dest->flags & BB_DUPLICATED))
     151     75605415 :     for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
     152              :       {
     153     13018534 :         tree def;
     154     13018534 :         location_t locus;
     155              : 
     156     13018534 :         phi = gsi.phi ();
     157     13018534 :         def = gimple_phi_arg_def (phi, e->dest_idx);
     158     13018534 :         locus = gimple_phi_arg_location (phi, e->dest_idx);
     159              : 
     160     13018534 :         if (def == NULL_TREE)
     161      1689670 :           continue;
     162              : 
     163     11328864 :         redirect_edge_var_map_add (e, gimple_phi_result (phi), def, locus);
     164              :       }
     165              : 
     166     64586711 :   e = redirect_edge_succ_nodup (e, dest);
     167              : 
     168     64586711 :   return e;
     169              : }
     170              : 
     171              : 
     172              : /* Add PHI arguments queued in PENDING_STMT list on edge E to edge
     173              :    E->dest.  */
     174              : 
     175              : void
     176      3437249 : flush_pending_stmts (edge e)
     177              : {
     178      3437249 :   gphi *phi;
     179      3437249 :   edge_var_map *vm;
     180      3437249 :   int i;
     181      3437249 :   gphi_iterator gsi;
     182              : 
     183      3437249 :   vec<edge_var_map> *v = redirect_edge_var_map_vector (e);
     184      3437249 :   if (!v)
     185       351964 :     return;
     186              : 
     187      3085285 :   for (gsi = gsi_start_phis (e->dest), i = 0;
     188      8464513 :        !gsi_end_p (gsi) && v->iterate (i, &vm);
     189      5379228 :        gsi_next (&gsi), i++)
     190              :     {
     191      5379228 :       tree def;
     192              : 
     193      5379228 :       phi = gsi.phi ();
     194      5379228 :       def = redirect_edge_var_map_def (vm);
     195      5379228 :       add_phi_arg (phi, def, e, redirect_edge_var_map_location (vm));
     196              :     }
     197              : 
     198      3085285 :   redirect_edge_var_map_clear (e);
     199              : }
     200              : 
     201              : /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
     202              :    GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
     203              :    expression with a different value.
     204              : 
     205              :    This will update any annotations (say debug bind stmts) referring
     206              :    to the original LHS, so that they use the RHS instead.  This is
     207              :    done even if NLHS and LHS are the same, for it is understood that
     208              :    the RHS will be modified afterwards, and NLHS will not be assigned
     209              :    an equivalent value.
     210              : 
     211              :    Adjusting any non-annotation uses of the LHS, if needed, is a
     212              :    responsibility of the caller.
     213              : 
     214              :    The effect of this call should be pretty much the same as that of
     215              :    inserting a copy of STMT before STMT, and then removing the
     216              :    original stmt, at which time gsi_remove() would have update
     217              :    annotations, but using this function saves all the inserting,
     218              :    copying and removing.  */
     219              : 
     220              : void
     221           51 : gimple_replace_ssa_lhs (gimple *stmt, tree nlhs)
     222              : {
     223           51 :   if (MAY_HAVE_DEBUG_BIND_STMTS)
     224              :     {
     225            0 :       tree lhs = gimple_get_lhs (stmt);
     226              : 
     227            0 :       gcc_assert (SSA_NAME_DEF_STMT (lhs) == stmt);
     228              : 
     229            0 :       insert_debug_temp_for_var_def (NULL, lhs);
     230              :     }
     231              : 
     232           51 :   gimple_set_lhs (stmt, nlhs);
     233           51 : }
     234              : 
     235              : 
     236              : /* Given a tree for an expression for which we might want to emit
     237              :    locations or values in debug information (generally a variable, but
     238              :    we might deal with other kinds of trees in the future), return the
     239              :    tree that should be used as the variable of a DEBUG_BIND STMT or
     240              :    VAR_LOCATION INSN or NOTE.  Return NULL if VAR is not to be tracked.  */
     241              : 
     242              : tree
     243    384377790 : target_for_debug_bind (tree var)
     244              : {
     245    384379796 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     246              :     return NULL_TREE;
     247              : 
     248    362608773 :   if (TREE_CODE (var) == SSA_NAME)
     249              :     {
     250     16903643 :       var = SSA_NAME_VAR (var);
     251              :       if (var == NULL_TREE)
     252              :         return NULL_TREE;
     253              :     }
     254              : 
     255    308671809 :   if ((!VAR_P (var) || VAR_DECL_IS_VIRTUAL_OPERAND (var))
     256    371453719 :       && TREE_CODE (var) != PARM_DECL)
     257              :     return NULL_TREE;
     258              : 
     259    306750054 :   if (DECL_HAS_VALUE_EXPR_P (var))
     260         2006 :     return target_for_debug_bind (DECL_VALUE_EXPR (var));
     261              : 
     262    306748048 :   if (DECL_IGNORED_P (var))
     263              :     return NULL_TREE;
     264              : 
     265              :   /* var-tracking only tracks registers.  */
     266    283893241 :   if (!is_gimple_reg_type (TREE_TYPE (var)))
     267      9221358 :     return NULL_TREE;
     268              : 
     269              :   return var;
     270              : }
     271              : 
     272              : /* Called via walk_tree, look for SSA_NAMEs that have already been
     273              :    released.  */
     274              : 
     275              : tree
     276      9947526 : find_released_ssa_name (tree *tp, int *walk_subtrees, void *data_)
     277              : {
     278      9947526 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data_;
     279              : 
     280      9947526 :   if (wi && wi->is_lhs)
     281              :     return NULL_TREE;
     282              : 
     283      9900260 :   if (TREE_CODE (*tp) == SSA_NAME)
     284              :     {
     285      1624167 :       if (SSA_NAME_IN_FREE_LIST (*tp))
     286              :         return *tp;
     287              : 
     288      1604603 :       *walk_subtrees = 0;
     289              :     }
     290      8276093 :   else if (IS_TYPE_OR_DECL_P (*tp))
     291        37117 :     *walk_subtrees = 0;
     292              : 
     293              :   return NULL_TREE;
     294              : }
     295              : 
     296              : /* Insert a DEBUG BIND stmt before the DEF of VAR if VAR is referenced
     297              :    by other DEBUG stmts, and replace uses of the DEF with the
     298              :    newly-created debug temp.  */
     299              : 
     300              : void
     301     93164384 : insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
     302              : {
     303     93164384 :   imm_use_iterator imm_iter;
     304     93164384 :   use_operand_p use_p;
     305     93164384 :   gimple *stmt;
     306     93164384 :   gimple *def_stmt = NULL;
     307     93164384 :   int usecount = 0;
     308     93164384 :   tree value = NULL;
     309              : 
     310     93164384 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     311     89615494 :     return;
     312              : 
     313              :   /* If this name has already been registered for replacement, do nothing
     314              :      as anything that uses this name isn't in SSA form.  */
     315     93164384 :   if (name_registered_for_update_p (var))
     316              :     return;
     317              : 
     318              :   /* Check whether there are debug stmts that reference this variable and,
     319              :      if there are, decide whether we should use a debug temp.  */
     320    103163132 :   FOR_EACH_IMM_USE_FAST (use_p, imm_iter, var)
     321              :     {
     322     11694455 :       stmt = USE_STMT (use_p);
     323              : 
     324     11694455 :       if (!gimple_debug_bind_p (stmt))
     325      7648204 :         continue;
     326              : 
     327      4046251 :       if (usecount++)
     328              :         break;
     329              : 
     330      3548890 :       if (gimple_debug_bind_get_value (stmt) != var)
     331              :         {
     332              :           /* Count this as an additional use, so as to make sure we
     333              :              use a temp unless VAR's definition has a SINGLE_RHS that
     334              :              can be shared.  */
     335       740595 :           usecount++;
     336       740595 :           break;
     337              :         }
     338     92706633 :     }
     339              : 
     340     92706633 :   if (!usecount)
     341              :     return;
     342              : 
     343      3548890 :   if (gsi)
     344      3099012 :     def_stmt = gsi_stmt (*gsi);
     345              :   else
     346       449878 :     def_stmt = SSA_NAME_DEF_STMT (var);
     347              : 
     348              :   /* If we didn't get an insertion point, and the stmt has already
     349              :      been removed, we won't be able to insert the debug bind stmt, so
     350              :      we'll have to drop debug information.  */
     351      3548890 :   if (gimple_code (def_stmt) == GIMPLE_PHI)
     352              :     {
     353       175521 :       value = degenerate_phi_result (as_a <gphi *> (def_stmt));
     354       175521 :       if (value && walk_tree (&value, find_released_ssa_name, NULL, NULL))
     355           33 :         value = NULL;
     356              :       /* error_mark_node is what fixup_noreturn_call changes PHI arguments
     357              :          to.  */
     358       175488 :       else if (value == error_mark_node)
     359            0 :         value = NULL;
     360              :     }
     361      3373369 :   else if (gimple_clobber_p (def_stmt))
     362              :     /* We can end up here when rewriting a decl into SSA and coming
     363              :        along a clobber for the original decl.  Turn that into
     364              :        # DEBUG decl => NULL  */
     365      1300596 :     value = NULL;
     366      2072773 :   else if (is_gimple_assign (def_stmt))
     367              :     {
     368      1989500 :       bool no_value = false;
     369              : 
     370      1989500 :       if (!dom_info_available_p (CDI_DOMINATORS))
     371              :         {
     372        66797 :           struct walk_stmt_info wi;
     373              : 
     374        66797 :           memset (&wi, 0, sizeof (wi));
     375              : 
     376              :           /* When removing blocks without following reverse dominance
     377              :              order, we may sometimes encounter SSA_NAMEs that have
     378              :              already been released, referenced in other SSA_DEFs that
     379              :              we're about to release.  Consider:
     380              : 
     381              :              <bb X>:
     382              :              v_1 = foo;
     383              : 
     384              :              <bb Y>:
     385              :              w_2 = v_1 + bar;
     386              :              # DEBUG w => w_2
     387              : 
     388              :              If we deleted BB X first, propagating the value of w_2
     389              :              won't do us any good.  It's too late to recover their
     390              :              original definition of v_1: when it was deleted, it was
     391              :              only referenced in other DEFs, it couldn't possibly know
     392              :              it should have been retained, and propagating every
     393              :              single DEF just in case it might have to be propagated
     394              :              into a DEBUG STMT would probably be too wasteful.
     395              : 
     396              :              When dominator information is not readily available, we
     397              :              check for and accept some loss of debug information.  But
     398              :              if it is available, there's no excuse for us to remove
     399              :              blocks in the wrong order, so we don't even check for
     400              :              dead SSA NAMEs.  SSA verification shall catch any
     401              :              errors.  */
     402        66770 :           if ((!gsi && !gimple_bb (def_stmt))
     403       133567 :               || walk_gimple_op (def_stmt, find_released_ssa_name, &wi))
     404        19531 :             no_value = true;
     405              :         }
     406              : 
     407        66797 :       if (!no_value)
     408      1969969 :         value = gimple_assign_rhs_to_tree (def_stmt);
     409              :     }
     410              : 
     411      3548890 :   if (value)
     412              :     {
     413              :       /* If there's a single use of VAR, and VAR is the entire debug
     414              :          expression (usecount would have been incremented again
     415              :          otherwise), then we can propagate VALUE into this single use,
     416              :          avoiding the temp.
     417              : 
     418              :          We can also avoid using a temp if VALUE can be shared and
     419              :          propagated into all uses, without generating expressions that
     420              :          wouldn't be valid gimple RHSs.
     421              : 
     422              :          Other cases that would require unsharing or non-gimple RHSs
     423              :          are deferred to a debug temp, although we could avoid temps
     424              :          at the expense of duplication of expressions.  */
     425              : 
     426      1997254 :       if (usecount == 1
     427      1111800 :           || gimple_code (def_stmt) == GIMPLE_PHI
     428      1101716 :           || CONSTANT_CLASS_P (value)
     429      3096333 :           || is_gimple_reg (value))
     430              :         ;
     431              :       else
     432              :         {
     433      1097003 :           gdebug *def_temp;
     434      1097003 :           tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
     435              : 
     436      1097003 :           def_temp = gimple_build_debug_bind (vexpr,
     437              :                                               unshare_expr (value),
     438              :                                               def_stmt);
     439              : 
     440              :           /* FIXME: Is setting the mode really necessary? */
     441      1097003 :           if (DECL_P (value))
     442         2794 :             SET_DECL_MODE (vexpr, DECL_MODE (value));
     443              :           else
     444      1094209 :             SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (value)));
     445              : 
     446      1097003 :           if (gsi)
     447       869724 :             gsi_insert_before (gsi, def_temp, GSI_SAME_STMT);
     448              :           else
     449              :             {
     450       227279 :               gimple_stmt_iterator ngsi = gsi_for_stmt (def_stmt);
     451       227279 :               gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT);
     452              :             }
     453              : 
     454      1097003 :           value = vexpr;
     455              :         }
     456              :     }
     457              : 
     458     10251191 :   FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var)
     459              :     {
     460      6702301 :       if (!gimple_debug_bind_p (stmt))
     461       923147 :         continue;
     462              : 
     463      5779154 :       if (value)
     464              :         {
     465      8113528 :           FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
     466      4056764 :             SET_USE (use_p, unshare_expr (value));
     467              :           /* If we didn't replace uses with a debug decl fold the
     468              :              resulting expression.  Otherwise we end up with invalid IL.  */
     469      4055441 :           if (TREE_CODE (value) != DEBUG_EXPR_DECL)
     470              :             {
     471       929794 :               gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
     472       929794 :               fold_stmt_inplace (&gsi);
     473              :             }
     474              :         }
     475              :       else
     476      1723713 :         gimple_debug_bind_reset_value (stmt);
     477              : 
     478      5779154 :       update_stmt (stmt);
     479      3548890 :     }
     480              : }
     481              : 
     482              : 
     483              : /* Insert a DEBUG BIND stmt before STMT for each DEF referenced by
     484              :    other DEBUG stmts, and replace uses of the DEF with the
     485              :    newly-created debug temp.  */
     486              : 
     487              : void
     488    172354947 : insert_debug_temps_for_defs (gimple_stmt_iterator *gsi)
     489              : {
     490    172354947 :   gimple *stmt;
     491    172354947 :   ssa_op_iter op_iter;
     492    172354947 :   def_operand_p def_p;
     493              : 
     494    172354947 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     495     45659769 :     return;
     496              : 
     497    126695178 :   stmt = gsi_stmt (*gsi);
     498              : 
     499    289768035 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
     500              :     {
     501     36377679 :       tree var = DEF_FROM_PTR (def_p);
     502              : 
     503     36377679 :       if (TREE_CODE (var) != SSA_NAME)
     504       151989 :         continue;
     505              : 
     506     36225690 :       insert_debug_temp_for_var_def (gsi, var);
     507              :     }
     508              : }
     509              : 
     510              : /* Reset all debug stmts that use SSA_NAME(s) defined in STMT.  */
     511              : 
     512              : void
     513         7671 : reset_debug_uses (gimple *stmt)
     514              : {
     515         7671 :   ssa_op_iter op_iter;
     516         7671 :   def_operand_p def_p;
     517         7671 :   imm_use_iterator imm_iter;
     518         7671 :   gimple *use_stmt;
     519              : 
     520         7671 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     521          257 :     return;
     522              : 
     523        19818 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
     524              :     {
     525         4990 :       tree var = DEF_FROM_PTR (def_p);
     526              : 
     527         4990 :       if (TREE_CODE (var) != SSA_NAME)
     528            0 :         continue;
     529              : 
     530        11256 :       FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, var)
     531              :         {
     532         6266 :           if (!gimple_debug_bind_p (use_stmt))
     533         6182 :             continue;
     534              : 
     535           84 :           gimple_debug_bind_reset_value (use_stmt);
     536           84 :           update_stmt (use_stmt);
     537         4990 :         }
     538              :     }
     539              : }
     540              : 
     541              : /* Delete SSA DEFs for SSA versions in the TOREMOVE bitmap, removing
     542              :    dominated stmts before their dominators, so that release_ssa_defs
     543              :    stands a chance of propagating DEFs into debug bind stmts.  */
     544              : 
     545              : void
     546       245064 : release_defs_bitset (bitmap toremove)
     547              : {
     548       245064 :   unsigned j;
     549       245064 :   bitmap_iterator bi;
     550              : 
     551              :   /* Performing a topological sort is probably overkill, this will
     552              :      most likely run in slightly superlinear time, rather than the
     553              :      pathological quadratic worst case.
     554              :      But iterate from max SSA name version to min one because
     555              :      that mimics allocation order during code generation behavior best.
     556              :      Use an array for this which we compact on-the-fly with a NULL
     557              :      marker moving towards the end of the vector.  */
     558       245064 :   auto_vec<tree, 16> names;
     559       245064 :   names.reserve (bitmap_count_bits (toremove) + 1);
     560       245064 :   names.quick_push (NULL_TREE);
     561      2745851 :   EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi)
     562      2500787 :     names.quick_push (ssa_name (j));
     563              : 
     564       245064 :   bitmap_tree_view (toremove);
     565       755157 :   while (!bitmap_empty_p (toremove))
     566              :     {
     567       265029 :       j = names.length () - 1;
     568      3551069 :       for (unsigned i = names.length () - 1; names[i];)
     569              :         {
     570      3286040 :           bool remove_now = true;
     571      3286040 :           tree var = names[i];
     572      3286040 :           gimple *stmt;
     573      3286040 :           imm_use_iterator uit;
     574              : 
     575      3978569 :           FOR_EACH_IMM_USE_STMT (stmt, uit, var)
     576              :             {
     577      1477782 :               ssa_op_iter dit;
     578      1477782 :               def_operand_p def_p;
     579              : 
     580              :               /* We can't propagate PHI nodes into debug stmts.  */
     581      1477782 :               if (gimple_code (stmt) == GIMPLE_PHI
     582      1477782 :                   || is_gimple_debug (stmt))
     583       692529 :                 continue;
     584              : 
     585              :               /* If we find another definition to remove that uses
     586              :                  the one we're looking at, defer the removal of this
     587              :                  one, so that it can be propagated into debug stmts
     588              :                  after the other is.  */
     589       785253 :               FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, dit, SSA_OP_DEF)
     590              :                 {
     591       785253 :                   tree odef = DEF_FROM_PTR (def_p);
     592              : 
     593       785253 :                   if (bitmap_bit_p (toremove, SSA_NAME_VERSION (odef)))
     594              :                     {
     595              :                       remove_now = false;
     596              :                       break;
     597              :                     }
     598              :                 }
     599              : 
     600       785253 :               if (!remove_now)
     601              :                 break;
     602      3286040 :             }
     603              : 
     604      3286040 :           if (remove_now)
     605              :             {
     606      2500787 :               gimple *def = SSA_NAME_DEF_STMT (var);
     607      2500787 :               gimple_stmt_iterator gsi = gsi_for_stmt (def);
     608              : 
     609      2500787 :               if (gimple_code (def) == GIMPLE_PHI)
     610       634745 :                 remove_phi_node (&gsi, true);
     611              :               else
     612              :                 {
     613      1866042 :                   gsi_remove (&gsi, true);
     614      1866042 :                   release_defs (def);
     615              :                 }
     616      2500787 :               bitmap_clear_bit (toremove, SSA_NAME_VERSION (var));
     617              :             }
     618              :           else
     619       785253 :             --i;
     620      3286040 :           if (--j != i)
     621      3096390 :             names[i] = names[j];
     622              :         }
     623              :     }
     624       245064 :   bitmap_list_view (toremove);
     625       245064 : }
     626              : 
     627              : /* Disable warnings about missing quoting in GCC diagnostics for
     628              :    the verification errors.  Their format strings don't follow GCC
     629              :    diagnostic conventions and the calls are ultimately followed by
     630              :    one to internal_error.  */
     631              : #if __GNUC__ >= 10
     632              : #  pragma GCC diagnostic push
     633              : #  pragma GCC diagnostic ignored "-Wformat-diag"
     634              : #endif
     635              : 
     636              : /* Verify virtual SSA form.  */
     637              : 
     638              : bool
     639    228637618 : verify_vssa (basic_block bb_start, tree current_vdef, sbitmap visited)
     640              : {
     641    228637618 :   bool err = false;
     642              : 
     643    228637618 :   struct state_t {
     644              :     basic_block bb;
     645              :     tree        vdef;
     646              :   } state;
     647              : 
     648    228637618 :   auto_vec<state_t, 3> worklist;
     649    228637618 :   state.bb = bb_start;
     650    228637618 :   state.vdef = current_vdef;
     651    228637618 :   worklist.safe_push (state);
     652              : 
     653   2884207602 :   while (!worklist.is_empty ())
     654              :     {
     655   2426932366 :       const auto &state = worklist.pop ();
     656   2426932366 :       const auto &bb = state.bb;
     657   2426932366 :       current_vdef = state.vdef;
     658              : 
     659   2426932366 :       if (!bitmap_set_bit (visited, bb->index))
     660    116813222 :         continue;
     661              : 
     662              :       /* Pick up the single virtual PHI def.  */
     663   2310119144 :       gphi *phi = NULL;
     664   2970991885 :       for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
     665    660872741 :            gsi_next (&si))
     666              :         {
     667    660872741 :           tree res = gimple_phi_result (si.phi ());
     668   1632523458 :           if (virtual_operand_p (res))
     669              :             {
     670    310777976 :               if (phi)
     671              :                 {
     672            0 :                   error ("multiple virtual PHI nodes in BB %d", bb->index);
     673            0 :                   print_gimple_stmt (stderr, phi, 0);
     674            0 :                   print_gimple_stmt (stderr, si.phi (), 0);
     675            0 :                   err = true;
     676              :                 }
     677              :               else
     678              :                 phi = si.phi ();
     679              :             }
     680              :         }
     681   2310119144 :       if (phi)
     682              :         {
     683    310777976 :           current_vdef = gimple_phi_result (phi);
     684    310777976 :           if (TREE_CODE (current_vdef) != SSA_NAME)
     685              :             {
     686            0 :               error ("virtual definition is not an SSA name");
     687            0 :               print_gimple_stmt (stderr, phi, 0);
     688            0 :               err = true;
     689              :             }
     690              :         }
     691              : 
     692              :       /* Verify stmts.  */
     693  17625953698 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
     694  13005715410 :            gsi_next (&gsi))
     695              :         {
     696  13005715410 :           gimple *stmt = gsi_stmt (gsi);
     697  18371034503 :           tree vuse = gimple_vuse (stmt);
     698   5300509438 :           if (vuse)
     699              :             {
     700   3543389011 :               if (vuse != current_vdef)
     701              :                 {
     702            0 :                   error ("stmt with wrong VUSE");
     703            0 :                   print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
     704            0 :                   fprintf (stderr, "expected ");
     705            0 :                   print_generic_expr (stderr, current_vdef);
     706            0 :                   fprintf (stderr, "\n");
     707            0 :                   err = true;
     708              :                 }
     709  16549104421 :               tree vdef = gimple_vdef (stmt);
     710   3543389011 :               if (vdef)
     711              :                 {
     712   2214677552 :                   current_vdef = vdef;
     713   2214677552 :                   if (TREE_CODE (current_vdef) != SSA_NAME)
     714              :                     {
     715            0 :                       error ("virtual definition is not an SSA name");
     716            0 :                       print_gimple_stmt (stderr, phi, 0);
     717            0 :                       err = true;
     718              :                     }
     719              :                 }
     720              :             }
     721              :         }
     722              : 
     723              :       /* Verify destination PHI uses and add successors to worklist.  */
     724   2310119144 :       edge_iterator ei;
     725   2310119144 :       edge e;
     726   5107025051 :       FOR_EACH_EDGE (e, ei, bb->succs)
     727              :         {
     728   2796905907 :           gphi *phi = get_virtual_phi (e->dest);
     729   2796905907 :           if (phi
     730   2796905907 :              && PHI_ARG_DEF_FROM_EDGE (phi, e) != current_vdef)
     731              :             {
     732            0 :               error ("PHI node with wrong VUSE on edge from BB %d",
     733            0 :                      e->src->index);
     734            0 :               print_gimple_stmt (stderr, phi, 0, TDF_VOPS);
     735            0 :               fprintf (stderr, "expected ");
     736            0 :               print_generic_expr (stderr, current_vdef);
     737            0 :               fprintf (stderr, "\n");
     738            0 :               err = true;
     739              :             }
     740              : 
     741              :           /* Add successor BB along with current vdef to worklist.  */
     742   2796905907 :           if (!bitmap_bit_p (visited, e->dest->index))
     743              :             {
     744   2198294748 :               state_t new_state;
     745   2198294748 :               new_state.bb = e->dest;
     746   2198294748 :               new_state.vdef = current_vdef;
     747              : 
     748   2198294748 :               worklist.safe_push (new_state);
     749              :             }
     750              :         }
     751              :     }
     752    228637618 :   return err;
     753    228637618 : }
     754              : 
     755              : /* Return true if SSA_NAME is malformed and mark it visited.
     756              : 
     757              :    IS_VIRTUAL is true if this SSA_NAME was found inside a virtual
     758              :       operand.  */
     759              : 
     760              : static bool
     761  13927970295 : verify_ssa_name (tree ssa_name, bool is_virtual)
     762              : {
     763  13927970295 :   if (TREE_CODE (ssa_name) != SSA_NAME)
     764              :     {
     765            0 :       error ("expected an SSA_NAME object");
     766            0 :       return true;
     767              :     }
     768              : 
     769  13927970295 :   if (SSA_NAME_IN_FREE_LIST (ssa_name))
     770              :     {
     771            0 :       error ("found an SSA_NAME that had been released into the free pool");
     772            0 :       return true;
     773              :     }
     774              : 
     775  13927970295 :   if (SSA_NAME_VAR (ssa_name) != NULL_TREE
     776   8309731508 :       && TREE_TYPE (ssa_name) != TREE_TYPE (SSA_NAME_VAR (ssa_name)))
     777              :     {
     778            0 :       error ("type mismatch between an SSA_NAME and its symbol");
     779            0 :       return true;
     780              :     }
     781              : 
     782  13927970295 :   if (is_virtual && !virtual_operand_p (ssa_name))
     783              :     {
     784            0 :       error ("found a virtual definition for a GIMPLE register");
     785            0 :       return true;
     786              :     }
     787              : 
     788  13927970295 :   if (is_virtual && SSA_NAME_VAR (ssa_name) != gimple_vop (cfun))
     789              :     {
     790            0 :       error ("virtual SSA name for non-VOP decl");
     791            0 :       return true;
     792              :     }
     793              : 
     794  13927970295 :   if (!is_virtual && virtual_operand_p (ssa_name))
     795              :     {
     796            0 :       error ("found a real definition for a non-register");
     797            0 :       return true;
     798              :     }
     799              : 
     800  13927970295 :   if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
     801  13927970295 :       && !gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name)))
     802              :     {
     803            0 :       error ("found a default name with a non-empty defining statement");
     804            0 :       return true;
     805              :     }
     806              : 
     807              :   return false;
     808              : }
     809              : 
     810              : 
     811              : /* Return true if the definition of SSA_NAME at block BB is malformed.
     812              : 
     813              :    STMT is the statement where SSA_NAME is created.
     814              : 
     815              :    DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
     816              :       version numbers.  If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
     817              :       it means that the block in that array slot contains the
     818              :       definition of SSA_NAME.
     819              : 
     820              :    IS_VIRTUAL is true if SSA_NAME is created by a VDEF.  */
     821              : 
     822              : static bool
     823   5923281059 : verify_def (basic_block bb, basic_block *definition_block, tree ssa_name,
     824              :             gimple *stmt, bool is_virtual)
     825              : {
     826   5923281059 :   if (verify_ssa_name (ssa_name, is_virtual))
     827            0 :     goto err;
     828              : 
     829   5923281059 :   if (SSA_NAME_VAR (ssa_name)
     830   3243791931 :       && TREE_CODE (SSA_NAME_VAR (ssa_name)) == RESULT_DECL
     831            0 :       && DECL_BY_REFERENCE (SSA_NAME_VAR (ssa_name)))
     832              :     {
     833            0 :       error ("RESULT_DECL should be read only when DECL_BY_REFERENCE is set");
     834            0 :       goto err;
     835              :     }
     836              : 
     837   5923281059 :   if (definition_block[SSA_NAME_VERSION (ssa_name)])
     838              :     {
     839            0 :       error ("SSA_NAME created in two different blocks %i and %i",
     840            0 :              definition_block[SSA_NAME_VERSION (ssa_name)]->index, bb->index);
     841            0 :       goto err;
     842              :     }
     843              : 
     844   5923281059 :   definition_block[SSA_NAME_VERSION (ssa_name)] = bb;
     845              : 
     846   5923281059 :   if (SSA_NAME_DEF_STMT (ssa_name) != stmt)
     847              :     {
     848            0 :       error ("SSA_NAME_DEF_STMT is wrong");
     849            0 :       fprintf (stderr, "Expected definition statement:\n");
     850            0 :       print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (ssa_name), 4, TDF_VOPS);
     851            0 :       fprintf (stderr, "\nActual definition statement:\n");
     852            0 :       print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
     853            0 :       goto err;
     854              :     }
     855              : 
     856              :   return false;
     857              : 
     858            0 : err:
     859            0 :   fprintf (stderr, "while verifying SSA_NAME ");
     860            0 :   print_generic_expr (stderr, ssa_name);
     861            0 :   fprintf (stderr, " in statement\n");
     862            0 :   print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
     863              : 
     864            0 :   return true;
     865              : }
     866              : 
     867              : 
     868              : /* Return true if the use of SSA_NAME at statement STMT in block BB is
     869              :    malformed.
     870              : 
     871              :    DEF_BB is the block where SSA_NAME was found to be created.
     872              : 
     873              :    IDOM contains immediate dominator information for the flowgraph.
     874              : 
     875              :    CHECK_ABNORMAL is true if the caller wants to check whether this use
     876              :       is flowing through an abnormal edge (only used when checking PHI
     877              :       arguments).
     878              : 
     879              :    If NAMES_DEFINED_IN_BB is not NULL, it contains a bitmap of ssa names
     880              :      that are defined before STMT in basic block BB.  */
     881              : 
     882              : static bool
     883  11361814306 : verify_use (basic_block bb, basic_block def_bb, use_operand_p use_p,
     884              :             gimple *stmt, bool check_abnormal, bitmap names_defined_in_bb)
     885              : {
     886  11361814306 :   bool err = false;
     887  11361814306 :   tree ssa_name = USE_FROM_PTR (use_p);
     888              : 
     889  11361814306 :   if (!TREE_VISITED (ssa_name))
     890   6316457353 :     if (verify_imm_links (stderr, ssa_name))
     891  11361814306 :       err = true;
     892              : 
     893  11361814306 :   TREE_VISITED (ssa_name) = 1;
     894              : 
     895  11361814306 :   if (gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name))
     896  11361814306 :       && SSA_NAME_IS_DEFAULT_DEF (ssa_name))
     897              :     ; /* Default definitions have empty statements.  Nothing to do.  */
     898   9757433840 :   else if (!def_bb)
     899              :     {
     900            0 :       error ("missing definition");
     901            0 :       err = true;
     902              :     }
     903   9757433840 :   else if (bb != def_bb
     904   9757433840 :            && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
     905              :     {
     906            0 :       error ("definition in block %i does not dominate use in block %i",
     907              :              def_bb->index, bb->index);
     908            0 :       err = true;
     909              :     }
     910   9757433840 :   else if (bb == def_bb
     911   9757433840 :            && names_defined_in_bb != NULL
     912  15588357258 :            && !bitmap_bit_p (names_defined_in_bb, SSA_NAME_VERSION (ssa_name)))
     913              :     {
     914            0 :       error ("definition in block %i follows the use", def_bb->index);
     915            0 :       err = true;
     916              :     }
     917              : 
     918  11361814306 :   if (check_abnormal
     919  11369550717 :       && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
     920              :     {
     921            0 :       error ("SSA_NAME_OCCURS_IN_ABNORMAL_PHI should be set");
     922            0 :       err = true;
     923              :     }
     924              : 
     925              :   /* Make sure the use is in an appropriate list by checking the previous
     926              :      element to make sure it's the same.  */
     927  11361814306 :   if (use_p->prev == NULL)
     928              :     {
     929            0 :       error ("no immediate_use list");
     930            0 :       err = true;
     931              :     }
     932              :   else
     933              :     {
     934  11361814306 :       tree listvar;
     935  11361814306 :       if (use_p->prev->use == NULL)
     936   6316457353 :         listvar = use_p->prev->loc.ssa_name;
     937              :       else
     938   5045356953 :         listvar = USE_FROM_PTR (use_p->prev);
     939  11361814306 :       if (listvar != ssa_name)
     940              :         {
     941            0 :           error ("wrong immediate use list");
     942            0 :           err = true;
     943              :         }
     944              :     }
     945              : 
     946  11361814306 :   if (err)
     947              :     {
     948            0 :       fprintf (stderr, "for SSA_NAME: ");
     949            0 :       print_generic_expr (stderr, ssa_name, TDF_VOPS);
     950            0 :       fprintf (stderr, " in statement:\n");
     951            0 :       print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
     952              :     }
     953              : 
     954  11361814306 :   return err;
     955              : }
     956              : 
     957              : 
     958              : /* Return true if any of the arguments for PHI node PHI at block BB is
     959              :    malformed.
     960              : 
     961              :    DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
     962              :       version numbers.  If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
     963              :       it means that the block in that array slot contains the
     964              :       definition of SSA_NAME.  */
     965              : 
     966              : static bool
     967    660884454 : verify_phi_args (gphi *phi, basic_block bb, basic_block *definition_block)
     968              : {
     969    660884454 :   edge e;
     970    660884454 :   bool err = false;
     971    660884454 :   size_t i, phi_num_args = gimple_phi_num_args (phi);
     972              : 
     973   1321768908 :   if (EDGE_COUNT (bb->preds) != phi_num_args)
     974              :     {
     975            0 :       error ("incoming edge count does not match number of PHI arguments");
     976            0 :       err = true;
     977            0 :       goto error;
     978              :     }
     979              : 
     980   2345081721 :   for (i = 0; i < phi_num_args; i++)
     981              :     {
     982   1684197267 :       use_operand_p op_p = gimple_phi_arg_imm_use_ptr (phi, i);
     983   1684197267 :       tree op = USE_FROM_PTR (op_p);
     984              : 
     985   1684197267 :       e = EDGE_PRED (bb, i);
     986              : 
     987   1684197267 :       if (op == NULL_TREE)
     988              :         {
     989            0 :           error ("PHI argument is missing for edge %d->%d",
     990            0 :                  e->src->index,
     991            0 :                  e->dest->index);
     992            0 :           err = true;
     993            0 :           goto error;
     994              :         }
     995              : 
     996   1684197267 :       if (TREE_CODE (op) != SSA_NAME && !is_gimple_min_invariant (op))
     997              :         {
     998            0 :           error ("PHI argument is not SSA_NAME, or invariant");
     999            0 :           err = true;
    1000              :         }
    1001              : 
    1002   1684197267 :       if ((e->flags & EDGE_ABNORMAL) && TREE_CODE (op) != SSA_NAME)
    1003              :         {
    1004            0 :           error ("PHI argument on abnormal edge is not SSA_NAME");
    1005            0 :           err = true;
    1006              :         }
    1007              : 
    1008   1684197267 :       if (TREE_CODE (op) == SSA_NAME)
    1009              :         {
    1010   2908756550 :           err = verify_ssa_name (op, virtual_operand_p (gimple_phi_result (phi)));
    1011   1454378275 :           err |= verify_use (e->src, definition_block[SSA_NAME_VERSION (op)],
    1012   1454378275 :                              op_p, phi, e->flags & EDGE_ABNORMAL, NULL);
    1013              :         }
    1014              : 
    1015   1684197267 :       if (TREE_CODE (op) == ADDR_EXPR)
    1016              :         {
    1017     11906137 :           tree base = TREE_OPERAND (op, 0);
    1018     16177014 :           while (handled_component_p (base))
    1019      4270877 :             base = TREE_OPERAND (base, 0);
    1020     11906137 :           if ((VAR_P (base)
    1021              :                || TREE_CODE (base) == PARM_DECL
    1022              :                || TREE_CODE (base) == RESULT_DECL)
    1023      5571090 :               && !TREE_ADDRESSABLE (base))
    1024              :             {
    1025            0 :               error ("address taken, but ADDRESSABLE bit not set");
    1026            0 :               err = true;
    1027              :             }
    1028              :         }
    1029              : 
    1030   1684197267 :       if (e->dest != bb)
    1031              :         {
    1032            0 :           error ("wrong edge %d->%d for PHI argument",
    1033            0 :                  e->src->index, e->dest->index);
    1034            0 :           err = true;
    1035              :         }
    1036              : 
    1037   1684197267 :       if (err)
    1038              :         {
    1039            0 :           fprintf (stderr, "PHI argument\n");
    1040            0 :           print_generic_stmt (stderr, op, TDF_VOPS);
    1041            0 :           goto error;
    1042              :         }
    1043              :     }
    1044              : 
    1045    660884454 : error:
    1046    660884454 :   if (err)
    1047              :     {
    1048            0 :       fprintf (stderr, "for PHI node\n");
    1049            0 :       print_gimple_stmt (stderr, phi, 0, TDF_VOPS|TDF_MEMSYMS);
    1050              :     }
    1051              : 
    1052              : 
    1053    660884454 :   return err;
    1054              : }
    1055              : 
    1056              : 
    1057              : /* Verify common invariants in the SSA web.
    1058              :    TODO: verify the variable annotations.  */
    1059              : 
    1060              : DEBUG_FUNCTION void
    1061    228743069 : verify_ssa (bool check_modified_stmt, bool check_ssa_operands)
    1062              : {
    1063    228743069 :   basic_block bb;
    1064    457486138 :   basic_block *definition_block = XCNEWVEC (basic_block, num_ssa_names);
    1065    228743069 :   ssa_op_iter iter;
    1066    228743069 :   tree op;
    1067    228743069 :   enum dom_state orig_dom_state = dom_info_state (CDI_DOMINATORS);
    1068    228743069 :   auto_bitmap names_defined_in_bb;
    1069              : 
    1070    228743069 :   gcc_assert (!need_ssa_update_p (cfun));
    1071              : 
    1072    228743069 :   timevar_push (TV_TREE_SSA_VERIFY);
    1073              : 
    1074    228743069 :     {
    1075              :       /* Keep track of SSA names present in the IL.  */
    1076    228743069 :       size_t i;
    1077    228743069 :       tree name;
    1078    228743069 :       hash_map <void *, tree> ssa_info;
    1079              : 
    1080   8916257782 :       FOR_EACH_SSA_NAME (i, name, cfun)
    1081              :         {
    1082   6550310961 :           gimple *stmt;
    1083   6550310961 :           TREE_VISITED (name) = 0;
    1084              : 
    1085  13100621922 :           verify_ssa_name (name, virtual_operand_p (name));
    1086              : 
    1087   6550310961 :           stmt = SSA_NAME_DEF_STMT (name);
    1088   6550310961 :           if (!gimple_nop_p (stmt))
    1089              :             {
    1090   5923281059 :               basic_block bb = gimple_bb (stmt);
    1091   5923281059 :               if (verify_def (bb, definition_block,
    1092              :                               name, stmt, virtual_operand_p (name)))
    1093            0 :                 goto err;
    1094              :             }
    1095              : 
    1096   6550310961 :           void *info = NULL;
    1097   6550310961 :           if (POINTER_TYPE_P (TREE_TYPE (name)))
    1098   1167462898 :             info = SSA_NAME_PTR_INFO (name);
    1099   5382848063 :           else if (INTEGRAL_TYPE_P (TREE_TYPE (name)))
    1100   2260190305 :             info = SSA_NAME_RANGE_INFO (name);
    1101   6550310961 :           if (info)
    1102              :             {
    1103   1368739886 :               bool existed;
    1104   1368739886 :               tree &val = ssa_info.get_or_insert (info, &existed);
    1105   1368739886 :               if (existed)
    1106              :                 {
    1107            0 :                   error ("shared SSA name info");
    1108            0 :                   print_generic_expr (stderr, val);
    1109            0 :                   fprintf (stderr, " and ");
    1110            0 :                   print_generic_expr (stderr, name);
    1111            0 :                   fprintf (stderr, "\n");
    1112            0 :                   goto err;
    1113              :                 }
    1114              :               else
    1115   1368739886 :                 val = name;
    1116              :             }
    1117              :         }
    1118            0 :     }
    1119              : 
    1120    228743069 :   calculate_dominance_info (CDI_DOMINATORS);
    1121              : 
    1122              :   /* Now verify all the uses and make sure they agree with the definitions
    1123              :      found in the previous pass.  */
    1124   2086044793 :   FOR_EACH_BB_FN (bb, cfun)
    1125              :     {
    1126   1857301724 :       edge e;
    1127   1857301724 :       edge_iterator ei;
    1128              : 
    1129              :       /* Make sure that all edges have a clear 'aux' field.  */
    1130   4429878015 :       FOR_EACH_EDGE (e, ei, bb->preds)
    1131              :         {
    1132   2572576291 :           if (e->aux)
    1133              :             {
    1134            0 :               error ("AUX pointer initialized for edge %d->%d", e->src->index,
    1135            0 :                       e->dest->index);
    1136            0 :               goto err;
    1137              :             }
    1138              :         }
    1139              : 
    1140              :       /* Verify the arguments for every PHI node in the block.  */
    1141   2518186178 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1142              :         {
    1143    660884454 :           gphi *phi = gsi.phi ();
    1144    660884454 :           if (verify_phi_args (phi, bb, definition_block))
    1145            0 :             goto err;
    1146              : 
    1147    660884454 :           bitmap_set_bit (names_defined_in_bb,
    1148    660884454 :                           SSA_NAME_VERSION (gimple_phi_result (phi)));
    1149              :         }
    1150              : 
    1151              :       /* Now verify all the uses and vuses in every statement of the block.  */
    1152  16720471358 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    1153  13005867910 :            gsi_next (&gsi))
    1154              :         {
    1155  13005867910 :           gimple *stmt = gsi_stmt (gsi);
    1156  13005867910 :           use_operand_p use_p;
    1157              : 
    1158  25938501790 :           if (check_modified_stmt && gimple_modified_p (stmt))
    1159              :             {
    1160            0 :               error ("stmt (%p) marked modified after optimization pass: ",
    1161              :                      (void *)stmt);
    1162            0 :               print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
    1163            0 :               goto err;
    1164              :             }
    1165              : 
    1166  13005867910 :           if (check_ssa_operands && verify_ssa_operands (cfun, stmt))
    1167              :             {
    1168            0 :               print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
    1169            0 :               goto err;
    1170              :             }
    1171              : 
    1172  13005867910 :           if (gimple_debug_bind_p (stmt)
    1173   6805598290 :               && !gimple_debug_bind_has_value_p (stmt))
    1174   2265182106 :             continue;
    1175              : 
    1176  20648121835 :           FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
    1177              :             {
    1178   9907436031 :               op = USE_FROM_PTR (use_p);
    1179   9907436031 :               if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
    1180              :                               use_p, stmt, false, names_defined_in_bb))
    1181            0 :                 goto err;
    1182              :             }
    1183              : 
    1184  15991294356 :           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS)
    1185              :             {
    1186   5250608552 :               if (SSA_NAME_DEF_STMT (op) != stmt)
    1187              :                 {
    1188            0 :                   error ("SSA_NAME_DEF_STMT is wrong");
    1189            0 :                   fprintf (stderr, "Expected definition statement:\n");
    1190            0 :                   print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
    1191            0 :                   fprintf (stderr, "\nActual definition statement:\n");
    1192            0 :                   print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (op),
    1193              :                                      4, TDF_VOPS);
    1194            0 :                   goto err;
    1195              :                 }
    1196   5250608552 :               bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op));
    1197              :             }
    1198              :         }
    1199              : 
    1200   1857301724 :       bitmap_clear (names_defined_in_bb);
    1201              :     }
    1202              : 
    1203    228743069 :   free (definition_block);
    1204              : 
    1205    228743069 :   if (gimple_vop (cfun)
    1206    228743069 :       && ssa_default_def (cfun, gimple_vop (cfun)))
    1207              :     {
    1208    228637618 :       auto_sbitmap visited (last_basic_block_for_fn (cfun) + 1);
    1209    228637618 :       bitmap_clear (visited);
    1210    228637618 :       if (verify_vssa (ENTRY_BLOCK_PTR_FOR_FN (cfun),
    1211              :                        ssa_default_def (cfun, gimple_vop (cfun)), visited))
    1212            0 :         goto err;
    1213    228637618 :     }
    1214              : 
    1215              :   /* Restore the dominance information to its prior known state, so
    1216              :      that we do not perturb the compiler's subsequent behavior.  */
    1217    228743069 :   if (orig_dom_state == DOM_NONE)
    1218     74552473 :     free_dominance_info (CDI_DOMINATORS);
    1219              :   else
    1220    154190596 :     set_dom_info_availability (CDI_DOMINATORS, orig_dom_state);
    1221              : 
    1222    228743069 :   timevar_pop (TV_TREE_SSA_VERIFY);
    1223    228743069 :   return;
    1224              : 
    1225            0 : err:
    1226            0 :   internal_error ("verify_ssa failed");
    1227    228743069 : }
    1228              : 
    1229              : #if __GNUC__ >= 10
    1230              : #  pragma GCC diagnostic pop
    1231              : #endif
    1232              : 
    1233              : /* Initialize global DFA and SSA structures.
    1234              :    If SIZE is non-zero allocated ssa names array of a given size.  */
    1235              : 
    1236              : void
    1237      3441589 : init_tree_ssa (struct function *fn, int size)
    1238              : {
    1239      3441589 :   fn->gimple_df = ggc_cleared_alloc<gimple_df> ();
    1240      3441589 :   fn->gimple_df->default_defs = hash_table<ssa_name_hasher>::create_ggc (20);
    1241      3441589 :   pt_solution_reset (&fn->gimple_df->escaped);
    1242      3441589 :   pt_solution_reset (&fn->gimple_df->escaped_return);
    1243      3441589 :   init_ssanames (fn, size);
    1244      3441589 : }
    1245              : 
    1246              : /* Deallocate memory associated with SSA data structures for FNDECL.  */
    1247              : 
    1248              : void
    1249      3332764 : delete_tree_ssa (struct function *fn)
    1250              : {
    1251      3332764 :   fini_ssanames (fn);
    1252              : 
    1253              :   /* We no longer maintain the SSA operand cache at this point.  */
    1254      3332764 :   if (ssa_operands_active (fn))
    1255      3308355 :     fini_ssa_operands (fn);
    1256              : 
    1257      3332764 :   fn->gimple_df->default_defs->empty ();
    1258      3332764 :   fn->gimple_df->default_defs = NULL;
    1259      3332764 :   pt_solution_reset (&fn->gimple_df->escaped);
    1260      3332764 :   pt_solution_reset (&fn->gimple_df->escaped_return);
    1261      3332764 :   if (fn->gimple_df->decls_to_pointers != NULL)
    1262        42662 :     delete fn->gimple_df->decls_to_pointers;
    1263      3332764 :   fn->gimple_df->decls_to_pointers = NULL;
    1264      3332764 :   fn->gimple_df = NULL;
    1265              : 
    1266              :   /* We no longer need the edge variable maps.  */
    1267      3332764 :   redirect_edge_var_map_empty ();
    1268      3332764 : }
    1269              : 
    1270              : /* Return true if EXPR is a useless type conversion, otherwise return
    1271              :    false.  */
    1272              : 
    1273              : bool
    1274    999005188 : tree_ssa_useless_type_conversion (tree expr)
    1275              : {
    1276    999005188 :   tree outer_type, inner_type;
    1277              : 
    1278              :   /* If we have an assignment that merely uses a NOP_EXPR to change
    1279              :      the top of the RHS to the type of the LHS and the type conversion
    1280              :      is "safe", then strip away the type conversion so that we can
    1281              :      enter LHS = RHS into the const_and_copies table.  */
    1282    999005188 :   if (!CONVERT_EXPR_P (expr)
    1283    922901093 :       && TREE_CODE (expr) != VIEW_CONVERT_EXPR
    1284    921845098 :       && TREE_CODE (expr) != NON_LVALUE_EXPR)
    1285              :     return false;
    1286              : 
    1287     77724472 :   outer_type = TREE_TYPE (expr);
    1288     77724472 :   inner_type = TREE_TYPE (TREE_OPERAND (expr, 0));
    1289              : 
    1290     77724472 :   if (inner_type == error_mark_node)
    1291              :     return false;
    1292              : 
    1293     77724429 :   return useless_type_conversion_p (outer_type, inner_type);
    1294              : }
    1295              : 
    1296              : /* Strip conversions from EXP according to
    1297              :    tree_ssa_useless_type_conversion and return the resulting
    1298              :    expression.  */
    1299              : 
    1300              : tree
    1301    963665288 : tree_ssa_strip_useless_type_conversions (tree exp)
    1302              : {
    1303    985740500 :   while (tree_ssa_useless_type_conversion (exp))
    1304     22075212 :     exp = TREE_OPERAND (exp, 0);
    1305    963665288 :   return exp;
    1306              : }
    1307              : 
    1308              : /* Return true if T, as SSA_NAME, has an implicit default defined value.  */
    1309              : 
    1310              : bool
    1311    391860828 : ssa_defined_default_def_p (tree t)
    1312              : {
    1313    391860828 :   tree var = SSA_NAME_VAR (t);
    1314              : 
    1315    151499512 :   if (!var)
    1316              :     ;
    1317              :   /* Parameters get their initial value from the function entry.  */
    1318    151499512 :   else if (TREE_CODE (var) == PARM_DECL)
    1319              :     return true;
    1320              :   /* When returning by reference the return address is actually a hidden
    1321              :      parameter.  */
    1322    117689212 :   else if (TREE_CODE (var) == RESULT_DECL && DECL_BY_REFERENCE (var))
    1323              :     return true;
    1324              :   /* Hard register variables get their initial value from the ether.  */
    1325    117471241 :   else if (VAR_P (var) && DECL_HARD_REGISTER (var))
    1326            0 :     return true;
    1327              : 
    1328              :   return false;
    1329              : }
    1330              : 
    1331              : 
    1332              : /* Return true if T, an SSA_NAME, has an undefined value.  PARTIAL is what
    1333              :    should be returned if the value is only partially undefined.  */
    1334              : 
    1335              : bool
    1336    389427336 : ssa_undefined_value_p (tree t, bool partial)
    1337              : {
    1338    389427336 :   gimple *def_stmt;
    1339              : 
    1340    778854672 :   gcc_checking_assert (!virtual_operand_p (t));
    1341              : 
    1342    389427336 :   if (ssa_defined_default_def_p (t))
    1343              :     return false;
    1344              : 
    1345              :   /* The value is undefined iff its definition statement is empty.  */
    1346    357560970 :   def_stmt = SSA_NAME_DEF_STMT (t);
    1347    357560970 :   if (gimple_nop_p (def_stmt))
    1348              :     return true;
    1349              : 
    1350              :   /* The value is undefined if the definition statement is a call
    1351              :      to .DEFERRED_INIT function.  */
    1352    347250319 :   if (gimple_call_internal_p (def_stmt, IFN_DEFERRED_INIT))
    1353              :     return true;
    1354              : 
    1355              :   /* The value is partially undefined if the definition statement is
    1356              :      a REALPART_EXPR or IMAGPART_EXPR and its operand is defined by
    1357              :      the call to .DEFERRED_INIT function.  This is for handling the
    1358              :      following case:
    1359              : 
    1360              :   1 typedef _Complex float C;
    1361              :   2 C foo (int cond)
    1362              :   3 {
    1363              :   4   C f;
    1364              :   5   __imag__ f = 0;
    1365              :   6   if (cond)
    1366              :   7     {
    1367              :   8       __real__ f = 1;
    1368              :   9       return f;
    1369              :  10     }
    1370              :  11   return f;
    1371              :  12 }
    1372              : 
    1373              :     with -ftrivial-auto-var-init, compiler will insert the following
    1374              :     artificial initialization:
    1375              :   f = .DEFERRED_INIT (f, 2);
    1376              :   _1 = REALPART_EXPR <f>;
    1377              : 
    1378              :     we should treat the definition _1 = REALPART_EXPR <f> as undefined.  */
    1379     53365199 :   if (partial && is_gimple_assign (def_stmt)
    1380    388084330 :       && (gimple_assign_rhs_code (def_stmt) == REALPART_EXPR
    1381     40556857 :           || gimple_assign_rhs_code (def_stmt) == IMAGPART_EXPR))
    1382              :     {
    1383       676096 :       tree real_imag_part = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
    1384       676096 :       if (TREE_CODE (real_imag_part) == SSA_NAME
    1385       676096 :          && gimple_call_internal_p (SSA_NAME_DEF_STMT (real_imag_part),
    1386              :                                     IFN_DEFERRED_INIT))
    1387              :         return true;
    1388              :     }
    1389              : 
    1390              :   /* Check if the complex was not only partially defined.  */
    1391     53365054 :   if (partial && is_gimple_assign (def_stmt)
    1392    388084040 :       && gimple_assign_rhs_code (def_stmt) == COMPLEX_EXPR)
    1393              :     {
    1394        18525 :       tree rhs1, rhs2;
    1395              : 
    1396        18525 :       rhs1 = gimple_assign_rhs1 (def_stmt);
    1397        18525 :       rhs2 = gimple_assign_rhs2 (def_stmt);
    1398        18189 :       return (TREE_CODE (rhs1) == SSA_NAME && ssa_undefined_value_p (rhs1))
    1399        36673 :              || (TREE_CODE (rhs2) == SSA_NAME && ssa_undefined_value_p (rhs2));
    1400              :     }
    1401              :   return false;
    1402              : }
    1403              : 
    1404              : 
    1405              : /* Return TRUE iff there are any non-PHI uses of VAR that dominate the
    1406              :    end of BB.  If we return TRUE and BB is a loop header, then VAR we
    1407              :    be assumed to be defined within the loop, even if it is marked as
    1408              :    maybe-undefined.  */
    1409              : 
    1410              : bool
    1411       331277 : ssa_name_any_use_dominates_bb_p (tree var, basic_block bb)
    1412              : {
    1413       331277 :   imm_use_iterator iter;
    1414       331277 :   use_operand_p use_p;
    1415      1076209 :   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
    1416              :     {
    1417       768972 :       if (is_a <gphi *> (USE_STMT (use_p))
    1418       768972 :           || is_gimple_debug (USE_STMT (use_p)))
    1419       698347 :         continue;
    1420        70625 :       basic_block dombb = gimple_bb (USE_STMT (use_p));
    1421        70625 :       if (dominated_by_p (CDI_DOMINATORS, bb, dombb))
    1422        24040 :         return true;
    1423        24040 :     }
    1424              : 
    1425       307237 :   return false;
    1426              : }
    1427              : 
    1428              : /* Mark as maybe_undef any SSA_NAMEs that are unsuitable as ivopts
    1429              :    candidates for potentially involving undefined behavior.  */
    1430              : 
    1431              : void
    1432     12411076 : mark_ssa_maybe_undefs (void)
    1433              : {
    1434     12411076 :   auto_vec<tree> queue;
    1435              : 
    1436              :   /* Scan all SSA_NAMEs, marking the definitely-undefined ones as
    1437              :      maybe-undefined and queuing them for propagation, while clearing
    1438              :      the mark on others.  */
    1439     12411076 :   unsigned int i;
    1440     12411076 :   tree var;
    1441    610772897 :   FOR_EACH_SSA_NAME (i, var, cfun)
    1442              :     {
    1443    403840840 :       if (SSA_NAME_IS_VIRTUAL_OPERAND (var)
    1444    403840840 :           || !ssa_undefined_value_p (var, false))
    1445    395627127 :         ssa_name_set_maybe_undef (var, false);
    1446              :       else
    1447              :         {
    1448      8213713 :           ssa_name_set_maybe_undef (var);
    1449      8213713 :           queue.safe_push (var);
    1450      8213713 :           if (dump_file && (dump_flags & TDF_DETAILS))
    1451          142 :             fprintf (dump_file, "marking _%i as maybe-undef\n",
    1452           71 :                      SSA_NAME_VERSION (var));
    1453              :         }
    1454              :     }
    1455              : 
    1456              :   /* Now propagate maybe-undefined from a DEF to any other PHI that
    1457              :      uses it, as long as there isn't any intervening use of DEF.  */
    1458     22127370 :   while (!queue.is_empty ())
    1459              :     {
    1460      8517712 :       var = queue.pop ();
    1461      8517712 :       imm_use_iterator iter;
    1462      8517712 :       use_operand_p use_p;
    1463     10078439 :       FOR_EACH_IMM_USE_FAST (use_p, iter, var)
    1464              :         {
    1465              :           /* Any uses of VAR that aren't PHI args imply VAR must be
    1466              :              defined, otherwise undefined behavior would have been
    1467              :              definitely invoked.  Only PHI args may hold
    1468              :              maybe-undefined values without invoking undefined
    1469              :              behavior for that reason alone.  */
    1470      1560727 :           if (!is_a <gphi *> (USE_STMT (use_p)))
    1471      1256728 :             continue;
    1472       542033 :           gphi *phi = as_a <gphi *> (USE_STMT (use_p));
    1473              : 
    1474       542033 :           tree def = gimple_phi_result (phi);
    1475       542033 :           if (ssa_name_maybe_undef_p (def))
    1476       219825 :             continue;
    1477              : 
    1478              :           /* Look for any uses of the maybe-unused SSA_NAME that
    1479              :              dominates the block that reaches the incoming block
    1480              :              corresponding to the PHI arg in which it is mentioned.
    1481              :              That means we can assume the SSA_NAME is defined in that
    1482              :              path, so we only mark a PHI result as maybe-undef if we
    1483              :              find an unused reaching SSA_NAME.  */
    1484       322208 :           int idx = phi_arg_index_from_use (use_p);
    1485       322208 :           basic_block bb = gimple_phi_arg_edge (phi, idx)->src;
    1486       322208 :           if (ssa_name_any_use_dominates_bb_p (var, bb))
    1487        18209 :             continue;
    1488              : 
    1489       303999 :           ssa_name_set_maybe_undef (def);
    1490       303999 :           queue.safe_push (def);
    1491       303999 :           if (dump_file && (dump_flags & TDF_DETAILS))
    1492            0 :             fprintf (dump_file, "marking _%i as maybe-undef because of _%i\n",
    1493            0 :                      SSA_NAME_VERSION (def), SSA_NAME_VERSION (var));
    1494      8517712 :         }
    1495              :     }
    1496     12411076 : }
    1497              : 
    1498              : 
    1499              : /* If necessary, rewrite the base of the reference tree *TP from
    1500              :    a MEM_REF to a plain or converted symbol.  */
    1501              : 
    1502              : static void
    1503     24324198 : maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
    1504              : {
    1505     24324198 :   tree sym;
    1506              : 
    1507     27735642 :   while (handled_component_p (*tp))
    1508      3411444 :     tp = &TREE_OPERAND (*tp, 0);
    1509     24324198 :   if (TREE_CODE (*tp) == MEM_REF
    1510      1743850 :       && TREE_CODE (TREE_OPERAND (*tp, 0)) == ADDR_EXPR
    1511       315230 :       && (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
    1512       315230 :       && DECL_P (sym)
    1513       314785 :       && !TREE_ADDRESSABLE (sym)
    1514       181799 :       && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
    1515        57680 :       && is_gimple_reg_type (TREE_TYPE (*tp))
    1516     24381868 :       && ! VOID_TYPE_P (TREE_TYPE (*tp)))
    1517              :     {
    1518        57670 :       if (VECTOR_TYPE_P (TREE_TYPE (sym))
    1519         1438 :           && useless_type_conversion_p (TREE_TYPE (*tp),
    1520         1438 :                                         TREE_TYPE (TREE_TYPE (sym)))
    1521        58050 :           && multiple_p (mem_ref_offset (*tp),
    1522          380 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
    1523              :         {
    1524          758 :           *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
    1525          379 :                         TYPE_SIZE (TREE_TYPE (*tp)),
    1526              :                         int_const_binop (MULT_EXPR,
    1527          758 :                                          bitsize_int (BITS_PER_UNIT),
    1528          379 :                                          TREE_OPERAND (*tp, 1)));
    1529              :         }
    1530        57291 :       else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
    1531         1056 :                && useless_type_conversion_p (TREE_TYPE (*tp),
    1532         1056 :                                              TREE_TYPE (TREE_TYPE (sym)))
    1533        57296 :                && (integer_zerop (TREE_OPERAND (*tp, 1))
    1534            3 :                    || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
    1535            3 :                                           TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
    1536              :         {
    1537            6 :           *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
    1538              :                         ? REALPART_EXPR : IMAGPART_EXPR,
    1539            4 :                         TREE_TYPE (*tp), sym);
    1540              :         }
    1541        57287 :       else if (integer_zerop (TREE_OPERAND (*tp, 1))
    1542        57287 :                && DECL_SIZE (sym) == TYPE_SIZE (TREE_TYPE (*tp)))
    1543              :         {
    1544        56923 :           if (!useless_type_conversion_p (TREE_TYPE (*tp),
    1545        56923 :                                           TREE_TYPE (sym)))
    1546        12419 :             *tp = build1 (VIEW_CONVERT_EXPR,
    1547        12419 :                           TREE_TYPE (*tp), sym);
    1548              :           else
    1549        44504 :             *tp = sym;
    1550              :         }
    1551          364 :       else if (DECL_SIZE (sym)
    1552          364 :                && TREE_CODE (DECL_SIZE (sym)) == INTEGER_CST
    1553          364 :                && (known_subrange_p
    1554          364 :                    (mem_ref_offset (*tp),
    1555          364 :                     wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp))),
    1556          364 :                     0, wi::to_offset (DECL_SIZE_UNIT (sym))))
    1557          364 :                && (! INTEGRAL_TYPE_P (TREE_TYPE (*tp))
    1558          347 :                    || (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp)))
    1559          694 :                        == TYPE_PRECISION (TREE_TYPE (*tp))))
    1560          364 :                && (! INTEGRAL_TYPE_P (TREE_TYPE (sym))
    1561          169 :                    || type_has_mode_precision_p (TREE_TYPE (sym)))
    1562          728 :                && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp))),
    1563          728 :                                   BITS_PER_UNIT) == 0)
    1564              :         {
    1565          728 :           *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
    1566          364 :                         TYPE_SIZE (TREE_TYPE (*tp)),
    1567              :                         wide_int_to_tree (bitsizetype,
    1568          364 :                                           mem_ref_offset (*tp)
    1569          728 :                                           << LOG2_BITS_PER_UNIT));
    1570              :         }
    1571              :     }
    1572     24324198 : }
    1573              : 
    1574              : /* For a tree REF return its base if it is the base of a MEM_REF
    1575              :    that cannot be rewritten into SSA form.  Otherwise return NULL_TREE.  */
    1576              : 
    1577              : static tree
    1578    305683266 : non_rewritable_mem_ref_base (tree ref)
    1579              : {
    1580    305683266 :   tree base;
    1581              : 
    1582              :   /* A plain decl does not need it set.  */
    1583    305683266 :   if (DECL_P (ref))
    1584              :     return NULL_TREE;
    1585              : 
    1586    274956098 :   switch (TREE_CODE (ref))
    1587              :     {
    1588      3008970 :     case REALPART_EXPR:
    1589      3008970 :     case IMAGPART_EXPR:
    1590      3008970 :     case BIT_FIELD_REF:
    1591      3008970 :       if (DECL_P (TREE_OPERAND (ref, 0)))
    1592              :         return NULL_TREE;
    1593              :       break;
    1594      2512995 :     case VIEW_CONVERT_EXPR:
    1595      2512995 :       if (DECL_P (TREE_OPERAND (ref, 0)))
    1596              :         {
    1597      1087591 :           if (TYPE_SIZE (TREE_TYPE (ref))
    1598      1087591 :               != TYPE_SIZE (TREE_TYPE (TREE_OPERAND  (ref, 0))))
    1599          676 :             return TREE_OPERAND (ref, 0);
    1600              :           return NULL_TREE;
    1601              :         }
    1602              :       break;
    1603              :     /* We would need to rewrite ARRAY_REFs or COMPONENT_REFs and even
    1604              :        more so multiple levels of handled components.  */
    1605    273377461 :     default:;
    1606              :     }
    1607              : 
    1608    273377461 :   base = ref;
    1609              : 
    1610              :   /* But watch out for MEM_REFs we cannot lower to a
    1611              :      VIEW_CONVERT_EXPR or a BIT_FIELD_REF.  */
    1612    273377461 :   if (TREE_CODE (base) == MEM_REF
    1613    273377461 :       && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
    1614              :     {
    1615      6514034 :       tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
    1616      6514034 :       if (! DECL_P (decl))
    1617              :         return NULL_TREE;
    1618      6467873 :       if (! is_gimple_reg_type (TREE_TYPE (base))
    1619      6282353 :           || VOID_TYPE_P (TREE_TYPE (base))
    1620     12750226 :           || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base))
    1621              :         return decl;
    1622      6281129 :       if ((VECTOR_TYPE_P (TREE_TYPE (decl))
    1623      6278679 :            || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
    1624         3915 :           && useless_type_conversion_p (TREE_TYPE (base),
    1625         3915 :                                         TREE_TYPE (TREE_TYPE (decl)))
    1626          571 :           && known_ge (mem_ref_offset (base), 0)
    1627          524 :           && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
    1628              :                        mem_ref_offset (base))
    1629      6281647 :           && multiple_p (mem_ref_offset (base),
    1630          518 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base)))))
    1631          516 :         return NULL_TREE;
    1632              :       /* For same sizes and zero offset we can use a VIEW_CONVERT_EXPR.  */
    1633      6280613 :       if (integer_zerop (TREE_OPERAND (base, 1))
    1634      6280613 :           && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (base)))
    1635              :         return NULL_TREE;
    1636              :       /* For integral typed extracts we can use a BIT_FIELD_REF.  */
    1637      5610114 :       if (DECL_SIZE (decl)
    1638      5605669 :           && TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST
    1639      5605669 :           && (known_subrange_p
    1640      5605669 :               (mem_ref_offset (base),
    1641      5605669 :                wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
    1642      5605669 :                0, wi::to_poly_offset (DECL_SIZE_UNIT (decl))))
    1643              :           /* ???  We can't handle bitfield precision extracts without
    1644              :              either using an alternate type for the BIT_FIELD_REF and
    1645              :              then doing a conversion or possibly adjusting the offset
    1646              :              according to endianness.  */
    1647      5603189 :           && (! INTEGRAL_TYPE_P (TREE_TYPE (base))
    1648      2977548 :               || (wi::to_offset (TYPE_SIZE (TREE_TYPE (base)))
    1649      5955096 :                   == TYPE_PRECISION (TREE_TYPE (base))))
    1650              :           /* ???  Likewise for extracts from bitfields, we'd have
    1651              :              to pun the base object to a size precision mode first.  */
    1652      5596227 :           && (! INTEGRAL_TYPE_P (TREE_TYPE (decl))
    1653        41285 :               || type_has_mode_precision_p (TREE_TYPE (decl)))
    1654     11170695 :           && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (base))),
    1655     11121162 :                              BITS_PER_UNIT) == 0)
    1656      5560581 :         return NULL_TREE;
    1657        49533 :       return decl;
    1658              :     }
    1659              : 
    1660              :   /* We cannot rewrite a decl in the base.  */
    1661    266863427 :   base = get_base_address (ref);
    1662    266863427 :   if (DECL_P (base))
    1663              :     return base;
    1664              : 
    1665              :   /* We cannot rewrite TARGET_MEM_REFs.  */
    1666    246531042 :   else if (TREE_CODE (base) == TARGET_MEM_REF
    1667    246531042 :            && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
    1668              :     {
    1669            0 :       tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
    1670            0 :       if (! DECL_P (decl))
    1671              :         return NULL_TREE;
    1672            0 :       return decl;
    1673              :     }
    1674              : 
    1675              :   return NULL_TREE;
    1676              : }
    1677              : 
    1678              : /* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
    1679              :    Otherwise return true.  */
    1680              : 
    1681              : static bool
    1682    107387120 : non_rewritable_lvalue_p (tree lhs)
    1683              : {
    1684              :   /* A plain decl is always rewritable.  */
    1685    107387120 :   if (DECL_P (lhs))
    1686              :     return false;
    1687              : 
    1688              :   /* We can re-write REALPART_EXPR and IMAGPART_EXPR sets in
    1689              :      a reasonably efficient manner... */
    1690     62397188 :   if ((TREE_CODE (lhs) == REALPART_EXPR
    1691     62397188 :        || TREE_CODE (lhs) == IMAGPART_EXPR)
    1692     62397188 :       && DECL_P (TREE_OPERAND (lhs, 0)))
    1693              :     return false;
    1694              : 
    1695              :   /* ???  The following could be relaxed allowing component
    1696              :      references that do not change the access size.  */
    1697     62365008 :   if (TREE_CODE (lhs) == MEM_REF
    1698     62365008 :       && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR)
    1699              :     {
    1700      7466863 :       tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
    1701              : 
    1702              :       /* A decl that is wrapped inside a MEM-REF that covers
    1703              :          it full is also rewritable.  */
    1704      7466863 :       if (integer_zerop (TREE_OPERAND (lhs, 1))
    1705      2188273 :           && DECL_P (decl)
    1706      2188213 :           && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
    1707              :           /* If the dynamic type of the decl has larger precision than
    1708              :              the decl itself we can't use the decls type for SSA rewriting.  */
    1709       576006 :           && ((! INTEGRAL_TYPE_P (TREE_TYPE (decl))
    1710        13980 :                || compare_tree_int (DECL_SIZE (decl),
    1711        13980 :                                     TYPE_PRECISION (TREE_TYPE (decl))) == 0)
    1712          814 :               || (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    1713          793 :                   && (TYPE_PRECISION (TREE_TYPE (decl))
    1714          793 :                       >= TYPE_PRECISION (TREE_TYPE (lhs)))))
    1715              :           /* Make sure we are not re-writing non-float copying into float
    1716              :              copying as that can incur normalization.  */
    1717       575853 :           && (! FLOAT_TYPE_P (TREE_TYPE (decl))
    1718         4833 :               || types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (decl)))
    1719      8038474 :           && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
    1720              :         return false;
    1721              : 
    1722              :       /* A vector-insert using a MEM_REF or ARRAY_REF is rewritable
    1723              :          using a BIT_INSERT_EXPR.  */
    1724      6895738 :       if (DECL_P (decl)
    1725      6895672 :           && VECTOR_TYPE_P (TREE_TYPE (decl))
    1726         1838 :           && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
    1727          284 :           && known_ge (mem_ref_offset (lhs), 0)
    1728          249 :           && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
    1729              :                        mem_ref_offset (lhs))
    1730          249 :           && multiple_p (mem_ref_offset (lhs),
    1731          249 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
    1732     13791410 :           && known_ge (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (decl))),
    1733              :                        wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (lhs)))))
    1734              :         {
    1735          248 :           poly_uint64 lhs_bits, nelts;
    1736          248 :           if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), &lhs_bits)
    1737          250 :               && multiple_p (lhs_bits,
    1738              :                              tree_to_uhwi
    1739          248 :                                (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))),
    1740              :                              &nelts)
    1741          268 :               && valid_vector_subparts_p (nelts))
    1742              :             {
    1743          228 :               if (known_eq (nelts, 1u))
    1744          228 :                 return false;
    1745              :               /* For sub-vector inserts the insert vector mode has to be
    1746              :                  supported.  */
    1747          175 :               tree vtype = build_vector_type (TREE_TYPE (TREE_TYPE (decl)),
    1748          175 :                                               nelts);
    1749          175 :               if (TYPE_MODE (vtype) != BLKmode)
    1750              :                 return false;
    1751              :             }
    1752              :         }
    1753              :     }
    1754              : 
    1755              :   /* A vector-insert using a BIT_FIELD_REF is rewritable using
    1756              :      BIT_INSERT_EXPR.  */
    1757     61793655 :   if (TREE_CODE (lhs) == BIT_FIELD_REF
    1758        19265 :       && DECL_P (TREE_OPERAND (lhs, 0))
    1759        13634 :       && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
    1760        13580 :       && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
    1761         1730 :       && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
    1762         1730 :                           TYPE_SIZE_UNIT
    1763              :                             (TREE_TYPE (TREE_TYPE (TREE_OPERAND (lhs, 0)))), 0)
    1764     61795384 :       && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
    1765         1729 :           % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))) == 0)
    1766         1729 :     return false;
    1767              : 
    1768              :   return true;
    1769              : }
    1770              : 
    1771              : /* When possible, clear TREE_ADDRESSABLE bit, set or clear DECL_NOT_GIMPLE_REG_P
    1772              :    and mark the variable VAR for conversion into SSA.  Return true when updating
    1773              :    stmts is required.  */
    1774              : 
    1775              : static void
    1776    110220042 : maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
    1777              :                     bitmap suitable_for_renaming)
    1778              : {
    1779              :   /* Global Variables, result decls cannot be changed.  */
    1780    110220042 :   if (is_global_var (var)
    1781    108589521 :       || TREE_CODE (var) == RESULT_DECL
    1782    218809563 :       || bitmap_bit_p (addresses_taken, DECL_UID (var)))
    1783              :     return;
    1784              : 
    1785     99270537 :   bool maybe_reg = false;
    1786     99270537 :   if (TREE_ADDRESSABLE (var))
    1787              :     {
    1788      1576296 :       TREE_ADDRESSABLE (var) = 0;
    1789      1576296 :       maybe_reg = true;
    1790      1576296 :       if (dump_file)
    1791              :         {
    1792           71 :           fprintf (dump_file, "No longer having address taken: ");
    1793           71 :           print_generic_expr (dump_file, var);
    1794           71 :           fprintf (dump_file, "\n");
    1795              :         }
    1796              :     }
    1797              : 
    1798              :   /* For register type decls if we do not have any partial defs
    1799              :      we cannot express in SSA form mark them as DECL_NOT_GIMPLE_REG_P
    1800              :      as to avoid SSA rewrite.  For the others go ahead and mark
    1801              :      them for renaming.  */
    1802     99270537 :   if (is_gimple_reg_type (TREE_TYPE (var)))
    1803              :     {
    1804     82724437 :       if (bitmap_bit_p (not_reg_needs, DECL_UID (var)))
    1805              :         {
    1806        33277 :           DECL_NOT_GIMPLE_REG_P (var) = 1;
    1807        33277 :           if (dump_file)
    1808              :             {
    1809            4 :               fprintf (dump_file, "Has partial defs: ");
    1810            4 :               print_generic_expr (dump_file, var);
    1811            4 :               fprintf (dump_file, "\n");
    1812              :             }
    1813              :         }
    1814    165339746 :       else if (BITINT_TYPE_P (TREE_TYPE (var))
    1815        42592 :                && (cfun->curr_properties & PROP_gimple_lbitint) != 0
    1816     82714482 :                && TYPE_PRECISION (TREE_TYPE (var)) > MAX_FIXED_MODE_SIZE)
    1817              :         {
    1818              :           /* Don't rewrite large/huge _BitInt vars after _BitInt lowering
    1819              :              into SSA form.  */
    1820         2660 :           DECL_NOT_GIMPLE_REG_P (var) = 1;
    1821         2660 :           if (dump_file)
    1822              :             {
    1823            0 :               fprintf (dump_file, "_BitInt var after its lowering: ");
    1824            0 :               print_generic_expr (dump_file, var);
    1825            0 :               fprintf (dump_file, "\n");
    1826              :             }
    1827              :         }
    1828     82688500 :       else if (DECL_NOT_GIMPLE_REG_P (var))
    1829              :         {
    1830         8894 :           maybe_reg = true;
    1831         8894 :           DECL_NOT_GIMPLE_REG_P (var) = 0;
    1832              :         }
    1833     82724437 :       if (maybe_reg)
    1834              :         {
    1835       536847 :           if (is_gimple_reg (var))
    1836              :             {
    1837       529420 :               if (dump_file)
    1838              :                 {
    1839           19 :                   fprintf (dump_file, "Now a gimple register: ");
    1840           19 :                   print_generic_expr (dump_file, var);
    1841           19 :                   fprintf (dump_file, "\n");
    1842              :                 }
    1843       529420 :               bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
    1844              :             }
    1845              :           else
    1846         7427 :             DECL_NOT_GIMPLE_REG_P (var) = 1;
    1847              :         }
    1848              :     }
    1849              : }
    1850              : 
    1851              : /* Return true when STMT is ASAN mark where second argument is an address
    1852              :    of a local variable.  */
    1853              : 
    1854              : static bool
    1855     60846098 : is_asan_mark_p (gimple *stmt)
    1856              : {
    1857     60846098 :   if (!gimple_call_internal_p (stmt, IFN_ASAN_MARK))
    1858              :     return false;
    1859              : 
    1860        57787 :   tree addr = get_base_address (gimple_call_arg (stmt, 1));
    1861        57787 :   if (TREE_CODE (addr) == ADDR_EXPR
    1862        57787 :       && VAR_P (TREE_OPERAND (addr, 0)))
    1863              :     {
    1864        57583 :       tree var = TREE_OPERAND (addr, 0);
    1865        57583 :       if (lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE,
    1866        57583 :                             DECL_ATTRIBUTES (var)))
    1867              :         return false;
    1868              : 
    1869        52564 :       unsigned addressable = TREE_ADDRESSABLE (var);
    1870        52564 :       TREE_ADDRESSABLE (var) = 0;
    1871        52564 :       bool r = is_gimple_reg (var);
    1872        52564 :       TREE_ADDRESSABLE (var) = addressable;
    1873        52564 :       return r;
    1874              :     }
    1875              : 
    1876              :   return false;
    1877              : }
    1878              : 
    1879              : /* Compute TREE_ADDRESSABLE and whether we have unhandled partial defs
    1880              :    for local variables.  */
    1881              : 
    1882              : void
    1883     12915550 : execute_update_addresses_taken (void)
    1884              : {
    1885     12915550 :   basic_block bb;
    1886     12915550 :   auto_bitmap addresses_taken;
    1887     12915550 :   auto_bitmap not_reg_needs;
    1888     12915550 :   auto_bitmap suitable_for_renaming;
    1889     12915550 :   bool optimistic_not_addressable = false;
    1890     12915550 :   tree var;
    1891     12915550 :   unsigned i;
    1892              : 
    1893     12915550 :   timevar_push (TV_ADDRESS_TAKEN);
    1894              : 
    1895              :   /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
    1896              :      the function body.  */
    1897    126868157 :   FOR_EACH_BB_FN (bb, cfun)
    1898              :     {
    1899   1120278216 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    1900    892373002 :            gsi_next (&gsi))
    1901              :         {
    1902    892373002 :           gimple *stmt = gsi_stmt (gsi);
    1903    892373002 :           enum gimple_code code = gimple_code (stmt);
    1904    892373002 :           tree decl;
    1905              : 
    1906    892373002 :           if (code == GIMPLE_CALL)
    1907              :             {
    1908     58388971 :               if (optimize_atomic_compare_exchange_p (stmt))
    1909              :                 {
    1910              :                   /* For __atomic_compare_exchange_N if the second argument
    1911              :                      is &var, don't mark var addressable;
    1912              :                      if it becomes non-addressable, we'll rewrite it into
    1913              :                      ATOMIC_COMPARE_EXCHANGE call.  */
    1914         5808 :                   tree arg = gimple_call_arg (stmt, 1);
    1915         5808 :                   gimple_call_set_arg (stmt, 1, null_pointer_node);
    1916         5808 :                   gimple_ior_addresses_taken (addresses_taken, stmt);
    1917         5808 :                   gimple_call_set_arg (stmt, 1, arg);
    1918              :                   /* Remember we have to check again below.  */
    1919         5808 :                   optimistic_not_addressable = true;
    1920              :                 }
    1921     58383163 :               else if (is_asan_mark_p (stmt)
    1922     58383163 :                        || gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
    1923              :                 ;
    1924              :               else
    1925     58363088 :                 gimple_ior_addresses_taken (addresses_taken, stmt);
    1926              :             }
    1927              :           else
    1928              :             /* Note all addresses taken by the stmt.  */
    1929    833984031 :             gimple_ior_addresses_taken (addresses_taken, stmt);
    1930              : 
    1931              :           /* If we have a call or an assignment, see if the lhs contains
    1932              :              a local decl that requires not to be a gimple register.  */
    1933    892373002 :           if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
    1934              :             {
    1935    328618226 :               tree lhs = gimple_get_lhs (stmt);
    1936    328618226 :               if (lhs
    1937    293433919 :                   && TREE_CODE (lhs) != SSA_NAME
    1938    436007394 :                   && ((code == GIMPLE_CALL && ! DECL_P (lhs))
    1939    107276691 :                       || non_rewritable_lvalue_p (lhs)))
    1940              :                 {
    1941     61889947 :                   decl = get_base_address (lhs);
    1942     61889947 :                   if (DECL_P (decl))
    1943     42959092 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1944              :                 }
    1945              :             }
    1946              : 
    1947    892373002 :           if (gimple_assign_single_p (stmt))
    1948              :             {
    1949    182721429 :               tree rhs = gimple_assign_rhs1 (stmt);
    1950    182721429 :               if ((decl = non_rewritable_mem_ref_base (rhs)))
    1951     20359004 :                 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1952              :             }
    1953              : 
    1954    709651573 :           else if (code == GIMPLE_CALL)
    1955              :             {
    1956    173521462 :               for (i = 0; i < gimple_call_num_args (stmt); ++i)
    1957              :                 {
    1958    115132491 :                   tree arg = gimple_call_arg (stmt, i);
    1959    115132491 :                   if ((decl = non_rewritable_mem_ref_base (arg)))
    1960       164907 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1961              :                 }
    1962              :             }
    1963              : 
    1964    651262602 :           else if (code == GIMPLE_ASM)
    1965              :             {
    1966       687485 :               gasm *asm_stmt = as_a <gasm *> (stmt);
    1967      2066458 :               for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
    1968              :                 {
    1969       691488 :                   tree link = gimple_asm_output_op (asm_stmt, i);
    1970       691488 :                   tree lhs = TREE_VALUE (link);
    1971       691488 :                   if (TREE_CODE (lhs) != SSA_NAME)
    1972              :                     {
    1973       184791 :                       decl = get_base_address (lhs);
    1974       184791 :                       if (DECL_P (decl)
    1975       184791 :                           && (non_rewritable_lvalue_p (lhs)
    1976              :                               /* We cannot move required conversions from
    1977              :                                  the lhs to the rhs in asm statements, so
    1978              :                                  require we do not need any.  */
    1979        95973 :                               || !useless_type_conversion_p
    1980        95973 :                                     (TREE_TYPE (lhs), TREE_TYPE (decl))))
    1981        15002 :                         bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1982              :                     }
    1983              :                 }
    1984      1151423 :               for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
    1985              :                 {
    1986       463938 :                   tree link = gimple_asm_input_op (asm_stmt, i);
    1987       463938 :                   if ((decl = non_rewritable_mem_ref_base (TREE_VALUE (link))))
    1988         5577 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1989              :                 }
    1990              :             }
    1991              :         }
    1992              : 
    1993    152300204 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    1994     38347597 :            gsi_next (&gsi))
    1995              :         {
    1996     38347597 :           size_t i;
    1997     38347597 :           gphi *phi = gsi.phi ();
    1998              : 
    1999    176432353 :           for (i = 0; i < gimple_phi_num_args (phi); i++)
    2000              :             {
    2001     99737159 :               tree op = PHI_ARG_DEF (phi, i), var;
    2002     99737159 :               if (TREE_CODE (op) == ADDR_EXPR
    2003       788459 :                   && (var = get_base_address (TREE_OPERAND (op, 0))) != NULL
    2004    100525618 :                   && DECL_P (var))
    2005       598914 :                 bitmap_set_bit (addresses_taken, DECL_UID (var));
    2006              :             }
    2007              :         }
    2008              :     }
    2009              : 
    2010              :   /* We cannot iterate over all referenced vars because that can contain
    2011              :      unused vars from BLOCK trees, which causes code generation differences
    2012              :      for -g vs. -g0.  */
    2013     39939808 :   for (var = DECL_ARGUMENTS (cfun->decl); var; var = DECL_CHAIN (var))
    2014     27024258 :     maybe_optimize_var (var, addresses_taken, not_reg_needs,
    2015              :                         suitable_for_renaming);
    2016              : 
    2017     96111334 :   FOR_EACH_VEC_SAFE_ELT (cfun->local_decls, i, var)
    2018     83195784 :     maybe_optimize_var (var, addresses_taken, not_reg_needs,
    2019              :                         suitable_for_renaming);
    2020              : 
    2021              :   /* Operand caches need to be recomputed for operands referencing the updated
    2022              :      variables and operands need to be rewritten to expose bare symbols.  */
    2023     12915550 :   if (!bitmap_empty_p (suitable_for_renaming)
    2024     12915550 :       || optimistic_not_addressable)
    2025              :     {
    2026      5707156 :       FOR_EACH_BB_FN (bb, cfun)
    2027     48856183 :         for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
    2028              :           {
    2029     37885751 :             gimple *stmt = gsi_stmt (gsi);
    2030              : 
    2031              :             /* Re-write TARGET_MEM_REFs of symbols we want to
    2032              :                rewrite into SSA form.  */
    2033     37885751 :             if (gimple_assign_single_p (stmt))
    2034              :               {
    2035     12479476 :                 tree lhs = gimple_assign_lhs (stmt);
    2036     12479476 :                 tree rhs, *rhsp = gimple_assign_rhs1_ptr (stmt);
    2037     12479476 :                 tree sym;
    2038              : 
    2039              :                 /* Rewrite LHS IMAG/REALPART_EXPR similar to
    2040              :                    gimplify_modify_expr_complex_part.  */
    2041     12479476 :                 if ((TREE_CODE (lhs) == IMAGPART_EXPR
    2042     12479476 :                      || TREE_CODE (lhs) == REALPART_EXPR)
    2043         3631 :                     && DECL_P (TREE_OPERAND (lhs, 0))
    2044     12482066 :                     && bitmap_bit_p (suitable_for_renaming,
    2045         2590 :                                      DECL_UID (TREE_OPERAND (lhs, 0))))
    2046              :                   {
    2047         2512 :                     tree other = make_ssa_name (TREE_TYPE (lhs));
    2048         3777 :                     tree lrhs = build1 (TREE_CODE (lhs) == IMAGPART_EXPR
    2049              :                                         ? REALPART_EXPR : IMAGPART_EXPR,
    2050         2512 :                                         TREE_TYPE (other),
    2051         2512 :                                         TREE_OPERAND (lhs, 0));
    2052         2512 :                     suppress_warning (lrhs);
    2053         2512 :                     gimple *load = gimple_build_assign (other, lrhs);
    2054         2512 :                     location_t loc = gimple_location (stmt);
    2055         2512 :                     gimple_set_location (load, loc);
    2056         5024 :                     gimple_set_vuse (load, gimple_vuse (stmt));
    2057         2512 :                     gsi_insert_before (&gsi, load, GSI_SAME_STMT);
    2058         2512 :                     gimple_assign_set_lhs (stmt, TREE_OPERAND (lhs, 0));
    2059         2512 :                     gimple_assign_set_rhs_with_ops
    2060         3777 :                       (&gsi, COMPLEX_EXPR,
    2061              :                        TREE_CODE (lhs) == IMAGPART_EXPR
    2062         1265 :                        ? other : gimple_assign_rhs1 (stmt),
    2063         2512 :                        TREE_CODE (lhs) == IMAGPART_EXPR
    2064         1247 :                        ? gimple_assign_rhs1 (stmt) : other, NULL_TREE);
    2065         2512 :                     stmt = gsi_stmt (gsi);
    2066         2512 :                     unlink_stmt_vdef (stmt);
    2067         2512 :                     update_stmt (stmt);
    2068         2512 :                     continue;
    2069         2512 :                   }
    2070              : 
    2071              :                 /* Rewrite a vector insert via a BIT_FIELD_REF on the LHS
    2072              :                    into a BIT_INSERT_EXPR.  */
    2073     12476964 :                 if (TREE_CODE (lhs) == BIT_FIELD_REF
    2074          903 :                     && DECL_P (TREE_OPERAND (lhs, 0))
    2075          845 :                     && bitmap_bit_p (suitable_for_renaming,
    2076          845 :                                      DECL_UID (TREE_OPERAND (lhs, 0)))
    2077          702 :                     && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
    2078          702 :                     && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
    2079          702 :                     && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
    2080          702 :                                         TYPE_SIZE_UNIT (TREE_TYPE
    2081              :                                           (TREE_TYPE (TREE_OPERAND (lhs, 0)))),
    2082              :                                         0)
    2083     12477666 :                     && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
    2084          702 :                         % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs))) == 0))
    2085              :                   {
    2086          702 :                     tree var = TREE_OPERAND (lhs, 0);
    2087          702 :                     tree val = gimple_assign_rhs1 (stmt);
    2088          702 :                     if (! types_compatible_p (TREE_TYPE (TREE_TYPE (var)),
    2089          702 :                                               TREE_TYPE (val)))
    2090              :                       {
    2091            0 :                         tree tem = make_ssa_name (TREE_TYPE (TREE_TYPE (var)));
    2092            0 :                         gimple *pun
    2093            0 :                           = gimple_build_assign (tem,
    2094              :                                                  build1 (VIEW_CONVERT_EXPR,
    2095            0 :                                                          TREE_TYPE (tem), val));
    2096            0 :                         gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
    2097            0 :                         val = tem;
    2098              :                       }
    2099          702 :                     tree bitpos = TREE_OPERAND (lhs, 2);
    2100          702 :                     gimple_assign_set_lhs (stmt, var);
    2101          702 :                     gimple_assign_set_rhs_with_ops
    2102          702 :                       (&gsi, BIT_INSERT_EXPR, var, val, bitpos);
    2103          702 :                     stmt = gsi_stmt (gsi);
    2104          702 :                     unlink_stmt_vdef (stmt);
    2105          702 :                     update_stmt (stmt);
    2106          702 :                     continue;
    2107          702 :                   }
    2108              : 
    2109              :                 /* Rewrite a vector insert using a MEM_REF on the LHS
    2110              :                    into a BIT_INSERT_EXPR.  */
    2111     12476262 :                 if (TREE_CODE (lhs) == MEM_REF
    2112       475159 :                     && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
    2113       113261 :                     && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
    2114       113261 :                     && DECL_P (sym)
    2115       113261 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
    2116         8258 :                     && VECTOR_TYPE_P (TREE_TYPE (sym))
    2117          183 :                     && TYPE_MODE (TREE_TYPE (sym)) != BLKmode
    2118              :                     /* If it is a full replacement we can do better below.  */
    2119          177 :                     && maybe_ne (wi::to_poly_offset
    2120          177 :                                    (TYPE_SIZE_UNIT (TREE_TYPE (lhs))),
    2121              :                                  wi::to_poly_offset
    2122          177 :                                    (TYPE_SIZE_UNIT (TREE_TYPE (sym))))
    2123           79 :                     && known_ge (mem_ref_offset (lhs), 0)
    2124           79 :                     && known_gt (wi::to_poly_offset
    2125              :                                    (TYPE_SIZE_UNIT (TREE_TYPE (sym))),
    2126              :                                  mem_ref_offset (lhs))
    2127     12476341 :                     && multiple_p (mem_ref_offset (lhs),
    2128              :                                    wi::to_poly_offset
    2129     12476262 :                                      (TYPE_SIZE_UNIT (TREE_TYPE (lhs)))))
    2130              :                   {
    2131           79 :                     tree val = gimple_assign_rhs1 (stmt);
    2132           79 :                     if (! types_compatible_p (TREE_TYPE (val),
    2133           79 :                                               TREE_TYPE (TREE_TYPE (sym))))
    2134              :                       {
    2135           58 :                         poly_uint64 lhs_bits, nelts;
    2136           58 :                         tree temtype = TREE_TYPE (TREE_TYPE (sym));
    2137           58 :                         if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)),
    2138              :                                              &lhs_bits)
    2139          174 :                             && multiple_p (lhs_bits,
    2140              :                                            tree_to_uhwi
    2141           58 :                                              (TYPE_SIZE (TREE_TYPE
    2142              :                                                            (TREE_TYPE (sym)))),
    2143              :                                            &nelts)
    2144           58 :                             && maybe_ne (nelts, 1u)
    2145          148 :                             && valid_vector_subparts_p (nelts))
    2146           32 :                           temtype = build_vector_type (temtype, nelts);
    2147           58 :                         tree tem = make_ssa_name (temtype);
    2148           58 :                         gimple *pun
    2149           58 :                           = gimple_build_assign (tem,
    2150              :                                                  build1 (VIEW_CONVERT_EXPR,
    2151           58 :                                                          TREE_TYPE (tem), val));
    2152           58 :                         gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
    2153           58 :                         val = tem;
    2154              :                       }
    2155           79 :                     tree bitpos
    2156           79 :                       = wide_int_to_tree (bitsizetype,
    2157           79 :                                           mem_ref_offset (lhs) * BITS_PER_UNIT);
    2158           79 :                     gimple_assign_set_lhs (stmt, sym);
    2159           79 :                     gimple_assign_set_rhs_with_ops
    2160           79 :                       (&gsi, BIT_INSERT_EXPR, sym, val, bitpos);
    2161           79 :                     stmt = gsi_stmt (gsi);
    2162           79 :                     unlink_stmt_vdef (stmt);
    2163           79 :                     update_stmt (stmt);
    2164           79 :                     continue;
    2165           79 :                   }
    2166              : 
    2167              :                 /* We shouldn't have any fancy wrapping of
    2168              :                    component-refs on the LHS, but look through
    2169              :                    VIEW_CONVERT_EXPRs as that is easy.  */
    2170     12476193 :                 while (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
    2171           10 :                   lhs = TREE_OPERAND (lhs, 0);
    2172     12476183 :                 if (TREE_CODE (lhs) == MEM_REF
    2173       475085 :                     && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
    2174       113182 :                     && integer_zerop (TREE_OPERAND (lhs, 1))
    2175        49403 :                     && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
    2176        49403 :                     && DECL_P (sym)
    2177        49403 :                     && !TREE_ADDRESSABLE (sym)
    2178     12506135 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
    2179              :                   lhs = sym;
    2180              :                 else
    2181     12468004 :                   lhs = gimple_assign_lhs (stmt);
    2182              : 
    2183              :                 /* Rewrite the RHS and make sure the resulting assignment
    2184              :                    is validly typed.  */
    2185     12476183 :                 maybe_rewrite_mem_ref_base (rhsp, suitable_for_renaming);
    2186     12476183 :                 rhs = gimple_assign_rhs1 (stmt);
    2187     12476183 :                 if (gimple_assign_lhs (stmt) != lhs
    2188     12484362 :                     && !useless_type_conversion_p (TREE_TYPE (lhs),
    2189         8179 :                                                    TREE_TYPE (rhs)))
    2190              :                   {
    2191         4006 :                     if (gimple_clobber_p (stmt))
    2192              :                       {
    2193           11 :                         rhs = build_constructor (TREE_TYPE (lhs), NULL);
    2194           11 :                         TREE_THIS_VOLATILE (rhs) = 1;
    2195              :                       }
    2196              :                     else
    2197         3995 :                       rhs = fold_build1 (VIEW_CONVERT_EXPR,
    2198              :                                          TREE_TYPE (lhs), rhs);
    2199              :                   }
    2200     12476183 :                 if (gimple_assign_lhs (stmt) != lhs)
    2201         8179 :                   gimple_assign_set_lhs (stmt, lhs);
    2202              : 
    2203     12476183 :                 if (gimple_assign_rhs1 (stmt) != rhs)
    2204              :                   {
    2205         4006 :                     gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    2206         4006 :                     gimple_assign_set_rhs_from_tree (&gsi, rhs);
    2207              :                   }
    2208              :               }
    2209              : 
    2210     25406275 :             else if (gimple_code (stmt) == GIMPLE_CALL)
    2211              :               {
    2212      2468743 :                 unsigned i;
    2213      2468743 :                 if (optimize_atomic_compare_exchange_p (stmt))
    2214              :                   {
    2215         5808 :                     tree expected = gimple_call_arg (stmt, 1);
    2216         5808 :                     tree decl = TREE_OPERAND (expected, 0);
    2217         5808 :                     if (bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
    2218              :                       {
    2219         5733 :                         fold_builtin_atomic_compare_exchange (&gsi);
    2220         5733 :                         continue;
    2221              :                       }
    2222           75 :                     else if (!TREE_ADDRESSABLE (decl))
    2223              :                       /* If there are partial defs of the decl we may
    2224              :                          have cleared the addressable bit but set
    2225              :                          DECL_NOT_GIMPLE_REG_P.  We have to restore
    2226              :                          TREE_ADDRESSABLE here.  */
    2227           27 :                       TREE_ADDRESSABLE (decl) = 1;
    2228              :                   }
    2229      2462935 :                 else if (is_asan_mark_p (stmt))
    2230              :                   {
    2231          392 :                     tree var = TREE_OPERAND (gimple_call_arg (stmt, 1), 0);
    2232          392 :                     if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
    2233              :                       {
    2234          344 :                         unlink_stmt_vdef (stmt);
    2235          344 :                         if (asan_mark_p (stmt, ASAN_MARK_POISON))
    2236              :                           {
    2237          177 :                             gcall *call
    2238          177 :                               = gimple_build_call_internal (IFN_ASAN_POISON, 0);
    2239          177 :                             gimple_call_set_lhs (call, var);
    2240          177 :                             gsi_replace (&gsi, call, true);
    2241              :                           }
    2242              :                         else
    2243              :                           {
    2244              :                             /* In ASAN_MARK (UNPOISON, &b, ...) the variable
    2245              :                                is uninitialized.  Avoid dependencies on
    2246              :                                previous out of scope value.  */
    2247          167 :                             tree clobber = build_clobber (TREE_TYPE (var));
    2248          167 :                             gimple *g = gimple_build_assign (var, clobber);
    2249          167 :                             gsi_replace (&gsi, g, true);
    2250              :                           }
    2251          344 :                         continue;
    2252          344 :                       }
    2253              :                   }
    2254      2462543 :                 else if (gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
    2255            0 :                   for (i = 1; i < gimple_call_num_args (stmt); i++)
    2256              :                     {
    2257            0 :                       tree *argp = gimple_call_arg_ptr (stmt, i);
    2258            0 :                       if (*argp == null_pointer_node)
    2259            0 :                         continue;
    2260            0 :                       gcc_assert (TREE_CODE (*argp) == ADDR_EXPR
    2261              :                                   && VAR_P (TREE_OPERAND (*argp, 0)));
    2262            0 :                       tree var = TREE_OPERAND (*argp, 0);
    2263            0 :                       if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
    2264            0 :                         *argp = null_pointer_node;
    2265              :                     }
    2266      6891341 :                 for (i = 0; i < gimple_call_num_args (stmt); ++i)
    2267              :                   {
    2268      4428675 :                     tree *argp = gimple_call_arg_ptr (stmt, i);
    2269      4428675 :                     maybe_rewrite_mem_ref_base (argp, suitable_for_renaming);
    2270              :                   }
    2271              :               }
    2272              : 
    2273     22937532 :             else if (gimple_code (stmt) == GIMPLE_ASM)
    2274              :               {
    2275        11735 :                 gasm *asm_stmt = as_a <gasm *> (stmt);
    2276        11735 :                 unsigned i;
    2277        62003 :                 for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
    2278              :                   {
    2279        38533 :                     tree link = gimple_asm_output_op (asm_stmt, i);
    2280        38533 :                     maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
    2281              :                                                 suitable_for_renaming);
    2282              :                   }
    2283        27134 :                 for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
    2284              :                   {
    2285        15399 :                     tree link = gimple_asm_input_op (asm_stmt, i);
    2286        15399 :                     maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
    2287              :                                                 suitable_for_renaming);
    2288              :                   }
    2289              :               }
    2290              : 
    2291     22925797 :             else if (gimple_debug_bind_p (stmt)
    2292     17143192 :                      && gimple_debug_bind_has_value_p (stmt))
    2293              :               {
    2294      7365408 :                 tree *valuep = gimple_debug_bind_get_value_ptr (stmt);
    2295      7365408 :                 tree decl;
    2296      7365408 :                 maybe_rewrite_mem_ref_base (valuep, suitable_for_renaming);
    2297      7365408 :                 decl = non_rewritable_mem_ref_base (*valuep);
    2298      7365408 :                 if (decl
    2299      7365408 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
    2300           10 :                   gimple_debug_bind_reset_value (stmt);
    2301              :               }
    2302              : 
    2303     51495028 :             if (gimple_references_memory_p (stmt)
    2304     32916461 :                 || is_gimple_debug (stmt))
    2305     22103112 :               update_stmt (stmt);
    2306              : 
    2307     37876381 :             gsi_next (&gsi);
    2308              :           }
    2309              : 
    2310              :       /* Update SSA form here, we are called as non-pass as well.  */
    2311       221940 :       if (number_of_loops (cfun) > 1
    2312       221940 :           && loops_state_satisfies_p (LOOP_CLOSED_SSA))
    2313          128 :         rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
    2314              :       else
    2315       221812 :         update_ssa (TODO_update_ssa);
    2316              :     }
    2317              : 
    2318     12915550 :   timevar_pop (TV_ADDRESS_TAKEN);
    2319     12915550 : }
    2320              : 
    2321              : namespace {
    2322              : 
    2323              : const pass_data pass_data_update_address_taken =
    2324              : {
    2325              :   GIMPLE_PASS, /* type */
    2326              :   "addressables", /* name */
    2327              :   OPTGROUP_NONE, /* optinfo_flags */
    2328              :   TV_ADDRESS_TAKEN, /* tv_id */
    2329              :   PROP_ssa, /* properties_required */
    2330              :   0, /* properties_provided */
    2331              :   0, /* properties_destroyed */
    2332              :   0, /* todo_flags_start */
    2333              :   TODO_update_address_taken, /* todo_flags_finish */
    2334              : };
    2335              : 
    2336              : class pass_update_address_taken : public gimple_opt_pass
    2337              : {
    2338              : public:
    2339            0 :   pass_update_address_taken (gcc::context *ctxt)
    2340            0 :     : gimple_opt_pass (pass_data_update_address_taken, ctxt)
    2341              :   {}
    2342              : 
    2343              :   /* opt_pass methods: */
    2344              : 
    2345              : }; // class pass_update_address_taken
    2346              : 
    2347              : } // anon namespace
    2348              : 
    2349              : gimple_opt_pass *
    2350            0 : make_pass_update_address_taken (gcc::context *ctxt)
    2351              : {
    2352            0 :   return new pass_update_address_taken (ctxt);
    2353              : }
        

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.