LCOV - code coverage report
Current view: top level - gcc - tree-ssa-live.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 89.7 % 789 708
Test Date: 2024-09-28 13:20:55 Functions: 86.0 % 43 37
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Liveness for SSA trees.
       2                 :             :    Copyright (C) 2003-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Andrew MacLeod <amacleod@redhat.com>
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify
       8                 :             : it under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful,
      13                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             : GNU General Public License for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : #include "config.h"
      22                 :             : #define INCLUDE_MEMORY
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "backend.h"
      26                 :             : #include "rtl.h"
      27                 :             : #include "tree.h"
      28                 :             : #include "gimple.h"
      29                 :             : #include "timevar.h"
      30                 :             : #include "ssa.h"
      31                 :             : #include "cgraph.h"
      32                 :             : #include "gimple-pretty-print.h"
      33                 :             : #include "diagnostic-core.h"
      34                 :             : #include "gimple-iterator.h"
      35                 :             : #include "tree-dfa.h"
      36                 :             : #include "dumpfile.h"
      37                 :             : #include "tree-ssa-live.h"
      38                 :             : #include "debug.h"
      39                 :             : #include "tree-ssa.h"
      40                 :             : #include "ipa-utils.h"
      41                 :             : #include "cfgloop.h"
      42                 :             : #include "stringpool.h"
      43                 :             : #include "attribs.h"
      44                 :             : #include "optinfo.h"
      45                 :             : #include "gimple-walk.h"
      46                 :             : #include "cfganal.h"
      47                 :             : #include "tree-cfg.h"
      48                 :             : 
      49                 :             : static void verify_live_on_entry (tree_live_info_p);
      50                 :             : 
      51                 :             : 
      52                 :             : /* VARMAP maintains a mapping from SSA version number to real variables.
      53                 :             : 
      54                 :             :    All SSA_NAMES are divided into partitions.  Initially each ssa_name is the
      55                 :             :    only member of it's own partition.  Coalescing will attempt to group any
      56                 :             :    ssa_names which occur in a copy or in a PHI node into the same partition.
      57                 :             : 
      58                 :             :    At the end of out-of-ssa, each partition becomes a "real" variable and is
      59                 :             :    rewritten as a compiler variable.
      60                 :             : 
      61                 :             :    The var_map data structure is used to manage these partitions.  It allows
      62                 :             :    partitions to be combined, and determines which partition belongs to what
      63                 :             :    ssa_name or variable, and vice versa.  */
      64                 :             : 
      65                 :             : 
      66                 :             : /* Remove the base table in MAP.  */
      67                 :             : 
      68                 :             : static void
      69                 :     4282386 : var_map_base_fini (var_map map)
      70                 :             : {
      71                 :             :   /* Free the basevar info if it is present.  */
      72                 :     4282386 :   if (map->partition_to_base_index != NULL)
      73                 :             :     {
      74                 :     1427462 :       free (map->partition_to_base_index);
      75                 :     1427462 :       map->partition_to_base_index = NULL;
      76                 :     1427462 :       map->num_basevars = 0;
      77                 :             :     }
      78                 :     4282386 : }
      79                 :             : /* Create a variable partition map of SIZE for region, initialize and return
      80                 :             :    it.  Region is a loop if LOOP is non-NULL, otherwise is the current
      81                 :             :    function.  If BITINT is non-NULL, only SSA_NAMEs from that bitmap
      82                 :             :    will be coalesced.  */
      83                 :             : 
      84                 :             : var_map
      85                 :     1427462 : init_var_map (int size, class loop *loop, bitmap bitint)
      86                 :             : {
      87                 :     1427462 :   var_map map;
      88                 :             : 
      89                 :     1427462 :   map = (var_map) xmalloc (sizeof (struct _var_map));
      90                 :     1427462 :   map->var_partition = partition_new (size);
      91                 :             : 
      92                 :     1427462 :   map->partition_to_view = NULL;
      93                 :     1427462 :   map->view_to_partition = NULL;
      94                 :     1427462 :   map->num_partitions = size;
      95                 :     1427462 :   map->partition_size = size;
      96                 :     1427462 :   map->num_basevars = 0;
      97                 :     1427462 :   map->partition_to_base_index = NULL;
      98                 :     1427462 :   map->vec_bbs = vNULL;
      99                 :     1427462 :   if (loop)
     100                 :             :     {
     101                 :           0 :       map->bmp_bbs = BITMAP_ALLOC (NULL);
     102                 :           0 :       map->outofssa_p = false;
     103                 :           0 :       basic_block *bbs = get_loop_body_in_dom_order (loop);
     104                 :           0 :       for (unsigned i = 0; i < loop->num_nodes; ++i)
     105                 :             :         {
     106                 :           0 :           bitmap_set_bit (map->bmp_bbs, bbs[i]->index);
     107                 :           0 :           map->vec_bbs.safe_push (bbs[i]);
     108                 :             :         }
     109                 :           0 :       free (bbs);
     110                 :             :     }
     111                 :             :   else
     112                 :             :     {
     113                 :     1427462 :       map->bmp_bbs = NULL;
     114                 :     1427462 :       map->outofssa_p = bitint == NULL;
     115                 :     1427462 :       map->bitint = bitint;
     116                 :     1427462 :       basic_block bb;
     117                 :     2854924 :       map->vec_bbs.reserve_exact (n_basic_blocks_for_fn (cfun)
     118                 :     1427462 :                                   - NUM_FIXED_BLOCKS);
     119                 :    13042676 :       FOR_EACH_BB_FN (bb, cfun)
     120                 :    11615214 :         map->vec_bbs.quick_push (bb);
     121                 :             :     }
     122                 :     1427462 :   return map;
     123                 :             : }
     124                 :             : 
     125                 :             : 
     126                 :             : /* Free memory associated with MAP.  */
     127                 :             : 
     128                 :             : void
     129                 :     1427462 : delete_var_map (var_map map)
     130                 :             : {
     131                 :     1427462 :   var_map_base_fini (map);
     132                 :     1427462 :   partition_delete (map->var_partition);
     133                 :     1427462 :   free (map->partition_to_view);
     134                 :     1427462 :   free (map->view_to_partition);
     135                 :     1427462 :   if (map->bmp_bbs)
     136                 :           0 :     BITMAP_FREE (map->bmp_bbs);
     137                 :     1427462 :   map->vec_bbs.release ();
     138                 :     1427462 :   free (map);
     139                 :     1427462 : }
     140                 :             : 
     141                 :             : 
     142                 :             : /* This function will combine the partitions in MAP for VAR1 and VAR2.  It
     143                 :             :    Returns the partition which represents the new partition.  If the two
     144                 :             :    partitions cannot be combined, NO_PARTITION is returned.  */
     145                 :             : 
     146                 :             : int
     147                 :     4848362 : var_union (var_map map, tree var1, tree var2)
     148                 :             : {
     149                 :     4848362 :   int p1, p2, p3;
     150                 :             : 
     151                 :     4848362 :   gcc_assert (TREE_CODE (var1) == SSA_NAME);
     152                 :     4848362 :   gcc_assert (TREE_CODE (var2) == SSA_NAME);
     153                 :             : 
     154                 :             :   /* This is independent of partition_to_view. If partition_to_view is
     155                 :             :      on, then whichever one of these partitions is absorbed will never have a
     156                 :             :      dereference into the partition_to_view array any more.  */
     157                 :             : 
     158                 :     4848362 :   p1 = partition_find (map->var_partition, SSA_NAME_VERSION (var1));
     159                 :     4848362 :   p2 = partition_find (map->var_partition, SSA_NAME_VERSION (var2));
     160                 :             : 
     161                 :     4848362 :   gcc_assert (p1 != NO_PARTITION);
     162                 :     4848362 :   gcc_assert (p2 != NO_PARTITION);
     163                 :             : 
     164                 :     4848362 :   if (p1 == p2)
     165                 :             :     p3 = p1;
     166                 :             :   else
     167                 :     4848362 :     p3 = partition_union (map->var_partition, p1, p2);
     168                 :             : 
     169                 :     4848362 :   if (map->partition_to_view)
     170                 :     4848362 :     p3 = map->partition_to_view[p3];
     171                 :             : 
     172                 :     4848362 :   return p3;
     173                 :             : }
     174                 :             : 
     175                 :             : 
     176                 :             : /* Compress the partition numbers in MAP such that they fall in the range
     177                 :             :    0..(num_partitions-1) instead of wherever they turned out during
     178                 :             :    the partitioning exercise.  This removes any references to unused
     179                 :             :    partitions, thereby allowing bitmaps and other vectors to be much
     180                 :             :    denser.
     181                 :             : 
     182                 :             :    This is implemented such that compaction doesn't affect partitioning.
     183                 :             :    Ie., once partitions are created and possibly merged, running one
     184                 :             :    or more different kind of compaction will not affect the partitions
     185                 :             :    themselves.  Their index might change, but all the same variables will
     186                 :             :    still be members of the same partition group.  This allows work on reduced
     187                 :             :    sets, and no loss of information when a larger set is later desired.
     188                 :             : 
     189                 :             :    In particular, coalescing can work on partitions which have 2 or more
     190                 :             :    definitions, and then 'recompact' later to include all the single
     191                 :             :    definitions for assignment to program variables.  */
     192                 :             : 
     193                 :             : 
     194                 :             : /* Set MAP back to the initial state of having no partition view.  Return a
     195                 :             :    bitmap which has a bit set for each partition number which is in use in the
     196                 :             :    varmap.  */
     197                 :             : 
     198                 :             : static bitmap
     199                 :     2854924 : partition_view_init (var_map map)
     200                 :             : {
     201                 :     2854924 :   bitmap used;
     202                 :     2854924 :   int tmp;
     203                 :     2854924 :   unsigned int x;
     204                 :             : 
     205                 :     2854924 :   used = BITMAP_ALLOC (NULL);
     206                 :             : 
     207                 :             :   /* Already in a view? Abandon the old one.  */
     208                 :     2854924 :   if (map->partition_to_view)
     209                 :             :     {
     210                 :     1427462 :       free (map->partition_to_view);
     211                 :     1427462 :       map->partition_to_view = NULL;
     212                 :             :     }
     213                 :     2854924 :   if (map->view_to_partition)
     214                 :             :     {
     215                 :     1427462 :       free (map->view_to_partition);
     216                 :     1427462 :       map->view_to_partition = NULL;
     217                 :             :     }
     218                 :             : 
     219                 :             :   /* Find out which partitions are actually referenced.  */
     220                 :   135982130 :   for (x = 0; x < map->partition_size; x++)
     221                 :             :     {
     222                 :   133127206 :       tmp = partition_find (map->var_partition, x);
     223                 :   315551054 :       if (ssa_name (tmp) != NULL_TREE && !virtual_operand_p (ssa_name (tmp))
     224                 :   192052504 :           && (!has_zero_uses (ssa_name (tmp))
     225                 :     3942523 :               || !SSA_NAME_IS_DEFAULT_DEF (ssa_name (tmp))
     226                 :     3420007 :               || (SSA_NAME_VAR (ssa_name (tmp))
     227                 :     3420007 :                   && !VAR_P (SSA_NAME_VAR (ssa_name (tmp))))))
     228                 :    58447516 :         bitmap_set_bit (used, tmp);
     229                 :             :     }
     230                 :             : 
     231                 :     2854924 :   map->num_partitions = map->partition_size;
     232                 :     2854924 :   return used;
     233                 :             : }
     234                 :             : 
     235                 :             : 
     236                 :             : /* This routine will finalize the view data for MAP based on the partitions
     237                 :             :    set in SELECTED.  This is either the same bitmap returned from
     238                 :             :    partition_view_init, or a trimmed down version if some of those partitions
     239                 :             :    were not desired in this view.  SELECTED is freed before returning.  */
     240                 :             : 
     241                 :             : static void
     242                 :     2854924 : partition_view_fini (var_map map, bitmap selected)
     243                 :             : {
     244                 :     2854924 :   bitmap_iterator bi;
     245                 :     2854924 :   unsigned count, i, x, limit;
     246                 :             : 
     247                 :     2854924 :   gcc_assert (selected);
     248                 :             : 
     249                 :     2854924 :   count = bitmap_count_bits (selected);
     250                 :     2854924 :   limit = map->partition_size;
     251                 :             : 
     252                 :             :   /* If its a one-to-one ratio, we don't need any view compaction.  */
     253                 :     2854924 :   if (count < limit)
     254                 :             :     {
     255                 :     2854924 :       map->partition_to_view = (int *)xmalloc (limit * sizeof (int));
     256                 :     2854924 :       memset (map->partition_to_view, 0xff, (limit * sizeof (int)));
     257                 :     2854924 :       map->view_to_partition = (int *)xmalloc (count * sizeof (int));
     258                 :             : 
     259                 :     2854924 :       i = 0;
     260                 :             :       /* Give each selected partition an index.  */
     261                 :    37616775 :       EXECUTE_IF_SET_IN_BITMAP (selected, 0, x, bi)
     262                 :             :         {
     263                 :    34761851 :           map->partition_to_view[x] = i;
     264                 :    34761851 :           map->view_to_partition[i] = x;
     265                 :    34761851 :           i++;
     266                 :             :         }
     267                 :     2854924 :       gcc_assert (i == count);
     268                 :     2854924 :       map->num_partitions = i;
     269                 :             :     }
     270                 :             : 
     271                 :     2854924 :   BITMAP_FREE (selected);
     272                 :     2854924 : }
     273                 :             : 
     274                 :             : 
     275                 :             : /* Create a partition view which includes all the used partitions in MAP.  */
     276                 :             : 
     277                 :             : void
     278                 :     1427462 : partition_view_normal (var_map map)
     279                 :             : {
     280                 :     1427462 :   bitmap used;
     281                 :             : 
     282                 :     1427462 :   used = partition_view_init (map);
     283                 :     1427462 :   partition_view_fini (map, used);
     284                 :             : 
     285                 :     1427462 :   var_map_base_fini (map);
     286                 :     1427462 : }
     287                 :             : 
     288                 :             : 
     289                 :             : /* Create a partition view in MAP which includes just partitions which occur in
     290                 :             :    the bitmap ONLY. If WANT_BASES is true, create the base variable map
     291                 :             :    as well.  */
     292                 :             : 
     293                 :             : void
     294                 :     1427462 : partition_view_bitmap (var_map map, bitmap only)
     295                 :             : {
     296                 :     1427462 :   bitmap used;
     297                 :     1427462 :   bitmap new_partitions = BITMAP_ALLOC (NULL);
     298                 :     1427462 :   unsigned x, p;
     299                 :     1427462 :   bitmap_iterator bi;
     300                 :             : 
     301                 :     1427462 :   used = partition_view_init (map);
     302                 :    11813917 :   EXECUTE_IF_SET_IN_BITMAP (only, 0, x, bi)
     303                 :             :     {
     304                 :    10386455 :       p = partition_find (map->var_partition, x);
     305                 :    10386455 :       gcc_assert (bitmap_bit_p (used, p));
     306                 :    10386455 :       bitmap_set_bit (new_partitions, p);
     307                 :             :     }
     308                 :     1427462 :   partition_view_fini (map, new_partitions);
     309                 :             : 
     310                 :     1427462 :   var_map_base_fini (map);
     311                 :     1427462 : }
     312                 :             : 
     313                 :             : 
     314                 :             : static bitmap usedvars;
     315                 :             : 
     316                 :             : /* Mark VAR as used, so that it'll be preserved during rtl expansion.
     317                 :             :    Returns true if VAR wasn't marked before.  */
     318                 :             : 
     319                 :             : static inline bool
     320                 :   118427426 : set_is_used (tree var)
     321                 :             : {
     322                 :   118427426 :   return bitmap_set_bit (usedvars, DECL_UID (var));
     323                 :             : }
     324                 :             : 
     325                 :             : /* Return true if VAR is marked as used.  */
     326                 :             : 
     327                 :             : static inline bool
     328                 :   128386438 : is_used_p (tree var)
     329                 :             : {
     330                 :   128386438 :   return bitmap_bit_p (usedvars, DECL_UID (var));
     331                 :             : }
     332                 :             : 
     333                 :             : static inline void mark_all_vars_used (tree *);
     334                 :             : 
     335                 :             : /* Helper function for mark_all_vars_used, called via walk_tree.  */
     336                 :             : 
     337                 :             : static tree
     338                 :   707482030 : mark_all_vars_used_1 (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
     339                 :             : {
     340                 :   707482030 :   tree t = *tp;
     341                 :   707482030 :   enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
     342                 :   707482030 :   tree b;
     343                 :             : 
     344                 :   707482030 :   if (TREE_CODE (t) == SSA_NAME)
     345                 :             :     {
     346                 :   268588609 :       *walk_subtrees = 0;
     347                 :   268588609 :       t = SSA_NAME_VAR (t);
     348                 :             :       if (!t)
     349                 :             :         return NULL;
     350                 :             :     }
     351                 :             : 
     352                 :   523329521 :   if (IS_EXPR_CODE_CLASS (c)
     353                 :   523329521 :       && (b = TREE_BLOCK (t)) != NULL)
     354                 :    48877056 :     TREE_USED (b) = true;
     355                 :             : 
     356                 :             :   /* Ignore TMR_OFFSET and TMR_STEP for TARGET_MEM_REFS, as those
     357                 :             :      fields do not contain vars.  */
     358                 :   523329521 :   if (TREE_CODE (t) == TARGET_MEM_REF)
     359                 :             :     {
     360                 :      741730 :       mark_all_vars_used (&TMR_BASE (t));
     361                 :      741730 :       mark_all_vars_used (&TMR_INDEX (t));
     362                 :      741730 :       mark_all_vars_used (&TMR_INDEX2 (t));
     363                 :      741730 :       *walk_subtrees = 0;
     364                 :      741730 :       return NULL;
     365                 :             :     }
     366                 :             : 
     367                 :             :   /* Only need to mark VAR_DECLS; parameters and return results are not
     368                 :             :      eliminated as unused.  */
     369                 :   522587791 :   if (VAR_P (t))
     370                 :             :     {
     371                 :             :       /* When a global var becomes used for the first time also walk its
     372                 :             :          initializer (non global ones don't have any).  */
     373                 :   146135663 :       if (set_is_used (t) && is_global_var (t)
     374                 :   123178584 :           && DECL_CONTEXT (t) == current_function_decl)
     375                 :      685601 :         mark_all_vars_used (&DECL_INITIAL (t));
     376                 :             :     }
     377                 :             :   /* remove_unused_scope_block_p requires information about labels
     378                 :             :      which are not DECL_IGNORED_P to tell if they might be used in the IL.  */
     379                 :   404160365 :   else if (TREE_CODE (t) == LABEL_DECL)
     380                 :             :     /* Although the TREE_USED values that the frontend uses would be
     381                 :             :        acceptable (albeit slightly over-conservative) for our purposes,
     382                 :             :        init_vars_expansion clears TREE_USED for LABEL_DECLs too, so we
     383                 :             :        must re-compute it here.  */
     384                 :     3797763 :     TREE_USED (t) = 1;
     385                 :             : 
     386                 :   522587791 :   if (IS_TYPE_OR_DECL_P (t))
     387                 :   238034744 :     *walk_subtrees = 0;
     388                 :             : 
     389                 :             :   return NULL;
     390                 :             : }
     391                 :             : 
     392                 :             : /* Mark the scope block SCOPE and its subblocks unused when they can be
     393                 :             :    possibly eliminated if dead.  */
     394                 :             : 
     395                 :             : static void
     396                 :    76880674 : mark_scope_block_unused (tree scope)
     397                 :             : {
     398                 :    76880674 :   tree t;
     399                 :    76880674 :   TREE_USED (scope) = false;
     400                 :    76880674 :   if (!(*debug_hooks->ignore_block) (scope))
     401                 :      203896 :     TREE_USED (scope) = true;
     402                 :   146232985 :   for (t = BLOCK_SUBBLOCKS (scope); t ; t = BLOCK_CHAIN (t))
     403                 :    69352311 :     mark_scope_block_unused (t);
     404                 :    76880674 : }
     405                 :             : 
     406                 :             : /* Look if the block is dead (by possibly eliminating its dead subblocks)
     407                 :             :    and return true if so.
     408                 :             :    Block is declared dead if:
     409                 :             :      1) No statements are associated with it.
     410                 :             :      2) Declares no live variables
     411                 :             :      3) All subblocks are dead
     412                 :             :         or there is precisely one subblocks and the block
     413                 :             :         has same abstract origin as outer block and declares
     414                 :             :         no variables, so it is pure wrapper.
     415                 :             :    When we are not outputting full debug info, we also eliminate dead variables
     416                 :             :    out of scope blocks to let them to be recycled by GGC and to save copying work
     417                 :             :    done by the inliner.  */
     418                 :             : 
     419                 :             : static bool
     420                 :    76880674 : remove_unused_scope_block_p (tree scope, bool in_ctor_dtor_block)
     421                 :             : {
     422                 :    76880674 :   tree *t, *next;
     423                 :    76880674 :   bool unused = !TREE_USED (scope);
     424                 :    76880674 :   int nsubblocks = 0;
     425                 :             : 
     426                 :             :   /* For ipa-polymorphic-call.cc purposes, preserve blocks:
     427                 :             :      1) with BLOCK_ABSTRACT_ORIGIN of a ctor/dtor or their clones  */
     428                 :    76880674 :   if (inlined_polymorphic_ctor_dtor_block_p (scope, true))
     429                 :             :     {
     430                 :             :       in_ctor_dtor_block = true;
     431                 :             :       unused = false;
     432                 :             :     }
     433                 :             :   /* 2) inside such blocks, the outermost block with block_ultimate_origin
     434                 :             :      being a FUNCTION_DECL.  */
     435                 :    65460326 :   else if (in_ctor_dtor_block)
     436                 :             :     {
     437                 :    10467723 :       tree fn = block_ultimate_origin (scope);
     438                 :    10467723 :       if (fn && TREE_CODE (fn) == FUNCTION_DECL)
     439                 :             :         {
     440                 :    76880674 :           in_ctor_dtor_block = false;
     441                 :    76880674 :           unused = false;
     442                 :             :         }
     443                 :             :     }
     444                 :             : 
     445                 :   149183741 :   for (t = &BLOCK_VARS (scope); *t; t = next)
     446                 :             :     {
     447                 :    72303067 :       next = &DECL_CHAIN (*t);
     448                 :             : 
     449                 :             :       /* Debug info of nested function refers to the block of the
     450                 :             :          function.  We might stil call it even if all statements
     451                 :             :          of function it was nested into was elliminated.
     452                 :             : 
     453                 :             :          TODO: We can actually look into cgraph to see if function
     454                 :             :          will be output to file.  */
     455                 :    72303067 :       if (TREE_CODE (*t) == FUNCTION_DECL)
     456                 :             :         unused = false;
     457                 :             : 
     458                 :             :       /* If a decl has a value expr, we need to instantiate it
     459                 :             :          regardless of debug info generation, to avoid codegen
     460                 :             :          differences in memory overlap tests.  update_equiv_regs() may
     461                 :             :          indirectly call validate_equiv_mem() to test whether a
     462                 :             :          SET_DEST overlaps with others, and if the value expr changes
     463                 :             :          by virtual register instantiation, we may get end up with
     464                 :             :          different results.  */
     465                 :    72086941 :       else if (VAR_P (*t) && DECL_HAS_VALUE_EXPR_P (*t))
     466                 :             :         unused = false;
     467                 :             : 
     468                 :             :       /* Remove everything we don't generate debug info for.  */
     469                 :    71271544 :       else if (DECL_IGNORED_P (*t))
     470                 :             :         {
     471                 :     3542872 :           *t = DECL_CHAIN (*t);
     472                 :     3542872 :           next = t;
     473                 :             :         }
     474                 :             : 
     475                 :             :       /* When we are outputting debug info, we usually want to output
     476                 :             :          info about optimized-out variables in the scope blocks.
     477                 :             :          Exception are the scope blocks not containing any instructions
     478                 :             :          at all so user can't get into the scopes at first place.  */
     479                 :    67728672 :       else if (is_used_p (*t))
     480                 :             :         unused = false;
     481                 :    58359266 :       else if (TREE_CODE (*t) == LABEL_DECL && TREE_USED (*t))
     482                 :             :         /* For labels that are still used in the IL, the decision to
     483                 :             :            preserve them must not depend DEBUG_INFO_LEVEL, otherwise we
     484                 :             :            risk having different ordering in debug vs.  non-debug builds
     485                 :             :            during inlining or versioning.
     486                 :             :            A label appearing here (we have already checked DECL_IGNORED_P)
     487                 :             :            should not be used in the IL unless it has been explicitly used
     488                 :             :            before, so we use TREE_USED as an approximation.  */
     489                 :             :         /* In principle, we should do the same here as for the debug case
     490                 :             :            below, however, when debugging, there might be additional nested
     491                 :             :            levels that keep an upper level with a label live, so we have to
     492                 :             :            force this block to be considered used, too.  */
     493                 :             :         unused = false;
     494                 :             : 
     495                 :             :       /* When we are not doing full debug info, we however can keep around
     496                 :             :          only the used variables for cfgexpand's memory packing saving quite
     497                 :             :          a lot of memory.
     498                 :             : 
     499                 :             :          For sake of -g3, we keep around those vars but we don't count this as
     500                 :             :          use of block, so innermost block with no used vars and no instructions
     501                 :             :          can be considered dead.  We only want to keep around blocks user can
     502                 :             :          breakpoint into and ask about value of optimized out variables.
     503                 :             : 
     504                 :             :          Similarly we need to keep around types at least until all
     505                 :             :          variables of all nested blocks are gone.  We track no
     506                 :             :          information on whether given type is used or not, so we have
     507                 :             :          to keep them even when not emitting debug information,
     508                 :             :          otherwise we may end up remapping variables and their (local)
     509                 :             :          types in different orders depending on whether debug
     510                 :             :          information is being generated.  */
     511                 :             : 
     512                 :    57957947 :       else if (TREE_CODE (*t) == TYPE_DECL
     513                 :    55632881 :                || debug_info_level == DINFO_LEVEL_NORMAL
     514                 :     2127449 :                || debug_info_level == DINFO_LEVEL_VERBOSE)
     515                 :             :         ;
     516                 :             :       else
     517                 :             :         {
     518                 :     2123501 :           *t = DECL_CHAIN (*t);
     519                 :     2123501 :           next = t;
     520                 :             :         }
     521                 :             :     }
     522                 :             : 
     523                 :   146232985 :   for (t = &BLOCK_SUBBLOCKS (scope); *t ;)
     524                 :    69352311 :     if (remove_unused_scope_block_p (*t, in_ctor_dtor_block))
     525                 :             :       {
     526                 :     7405323 :         if (BLOCK_SUBBLOCKS (*t))
     527                 :             :           {
     528                 :     2347109 :             tree next = BLOCK_CHAIN (*t);
     529                 :     2347109 :             tree supercontext = BLOCK_SUPERCONTEXT (*t);
     530                 :             : 
     531                 :     2347109 :             *t = BLOCK_SUBBLOCKS (*t);
     532                 :     2848230 :             while (BLOCK_CHAIN (*t))
     533                 :             :               {
     534                 :      501121 :                 BLOCK_SUPERCONTEXT (*t) = supercontext;
     535                 :      501121 :                 t = &BLOCK_CHAIN (*t);
     536                 :             :               }
     537                 :     2347109 :             BLOCK_CHAIN (*t) = next;
     538                 :     2347109 :             BLOCK_SUPERCONTEXT (*t) = supercontext;
     539                 :     2347109 :             t = &BLOCK_CHAIN (*t);
     540                 :     2347109 :             nsubblocks ++;
     541                 :             :           }
     542                 :             :         else
     543                 :     5058214 :           *t = BLOCK_CHAIN (*t);
     544                 :             :       }
     545                 :             :     else
     546                 :             :       {
     547                 :    61946988 :         t = &BLOCK_CHAIN (*t);
     548                 :    61946988 :         nsubblocks ++;
     549                 :             :       }
     550                 :             : 
     551                 :             : 
     552                 :    76880674 :    if (!unused)
     553                 :             :      ;
     554                 :             :    /* Outer scope is always used.  */
     555                 :    17277121 :    else if (!BLOCK_SUPERCONTEXT (scope)
     556                 :    17277121 :             || TREE_CODE (BLOCK_SUPERCONTEXT (scope)) == FUNCTION_DECL)
     557                 :             :      unused = false;
     558                 :             :    /* Innermost blocks with no live variables nor statements can be always
     559                 :             :       eliminated.  */
     560                 :    16638355 :    else if (!nsubblocks)
     561                 :             :      ;
     562                 :             :    /* When not generating debug info we can eliminate info on unused
     563                 :             :       variables.  */
     564                 :    11580141 :    else if (!flag_auto_profile
     565                 :    11580141 :             && debug_info_level == DINFO_LEVEL_NONE
     566                 :    12637155 :             && !optinfo_wants_inlining_info_p ())
     567                 :             :      {
     568                 :             :        /* Even for -g0 don't prune outer scopes from inlined functions,
     569                 :             :           otherwise late diagnostics from such functions will not be
     570                 :             :           emitted or suppressed properly.  */
     571                 :     1056966 :        if (inlined_function_outer_scope_p (scope))
     572                 :             :          {
     573                 :      849538 :            gcc_assert (TREE_CODE (BLOCK_ORIGIN (scope)) == FUNCTION_DECL);
     574                 :             :            unused = false;
     575                 :             :          }
     576                 :             :      }
     577                 :    10523175 :    else if (BLOCK_VARS (scope) || BLOCK_NUM_NONLOCALIZED_VARS (scope))
     578                 :             :      unused = false;
     579                 :             :    /* See if this block is important for representation of inlined
     580                 :             :       function.  Inlined functions are always represented by block
     581                 :             :       with block_ultimate_origin being set to FUNCTION_DECL and
     582                 :             :       DECL_SOURCE_LOCATION set, unless they expand to nothing...  */
     583                 :     2233514 :    else if (inlined_function_outer_scope_p (scope))
     584                 :             :      unused = false;
     585                 :             :    else
     586                 :             :    /* Verfify that only blocks with source location set
     587                 :             :       are entry points to the inlined functions.  */
     588                 :     2139681 :      gcc_assert (LOCATION_LOCUS (BLOCK_SOURCE_LOCATION (scope))
     589                 :             :                  == UNKNOWN_LOCATION);
     590                 :             : 
     591                 :    76880674 :    TREE_USED (scope) = !unused;
     592                 :    76880674 :    return unused;
     593                 :             : }
     594                 :             : 
     595                 :             : /* Mark all VAR_DECLS under *EXPR_P as used, so that they won't be
     596                 :             :    eliminated during the tree->rtl conversion process.  */
     597                 :             : 
     598                 :             : static inline void
     599                 :   527825446 : mark_all_vars_used (tree *expr_p)
     600                 :             : {
     601                 :   527825446 :   walk_tree (expr_p, mark_all_vars_used_1, NULL, NULL);
     602                 :   527825446 : }
     603                 :             : 
     604                 :             : /* Helper function for clear_unused_block_pointer, called via walk_tree.  */
     605                 :             : 
     606                 :             : static tree
     607                 :   269349676 : clear_unused_block_pointer_1 (tree *tp, int *, void *)
     608                 :             : {
     609                 :    42282167 :   if (EXPR_P (*tp) && TREE_BLOCK (*tp)
     610                 :   299039955 :       && !TREE_USED (TREE_BLOCK (*tp)))
     611                 :      840913 :     TREE_SET_BLOCK (*tp, NULL);
     612                 :   269349676 :   return NULL_TREE;
     613                 :             : }
     614                 :             : 
     615                 :             : /* Set all block pointer in debug or clobber stmt to NULL if the block
     616                 :             :    is unused, so that they will not be streamed out.  */
     617                 :             : 
     618                 :             : static void
     619                 :     7528363 : clear_unused_block_pointer (void)
     620                 :             : {
     621                 :     7528363 :   basic_block bb;
     622                 :     7528363 :   gimple_stmt_iterator gsi;
     623                 :             : 
     624                 :    59393936 :   FOR_EACH_BB_FN (bb, cfun)
     625                 :   452028052 :     for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     626                 :             :       {
     627                 :   349499370 :         unsigned i;
     628                 :   349499370 :         tree b;
     629                 :   349499370 :         gimple *stmt;
     630                 :             : 
     631                 :   348297439 :       next:
     632                 :   349499370 :         stmt = gsi_stmt (gsi);
     633                 :   349499370 :         if (!is_gimple_debug (stmt) && !gimple_clobber_p (stmt))
     634                 :   176692820 :           continue;
     635                 :   172806550 :         b = gimple_block (stmt);
     636                 :   172806550 :         if (b && !TREE_USED (b))
     637                 :             :           {
     638                 :             :             /* Elide debug marker stmts that have an associated BLOCK from an
     639                 :             :                inline instance removed with also the outermost scope BLOCK of
     640                 :             :                said inline instance removed.  If the outermost scope BLOCK of
     641                 :             :                said inline instance is preserved use that in place of the
     642                 :             :                removed BLOCK.  That keeps the marker associated to the correct
     643                 :             :                inline instance (or no inline instance in case it was not from
     644                 :             :                an inline instance).  */
     645                 :     5264082 :             if (gimple_debug_nonbind_marker_p (stmt)
     646                 :     6618017 :                 && BLOCK_ABSTRACT_ORIGIN (b))
     647                 :             :               {
     648                 :     1699146 :                 while (TREE_CODE (b) == BLOCK
     649                 :     1699146 :                        && !inlined_function_outer_scope_p (b))
     650                 :      360629 :                   b = BLOCK_SUPERCONTEXT (b);
     651                 :     1338517 :                 if (TREE_CODE (b) == BLOCK)
     652                 :             :                   {
     653                 :     1334288 :                     if (TREE_USED (b))
     654                 :             :                       {
     655                 :      131824 :                         gimple_set_block (stmt, b);
     656                 :      131824 :                         continue;
     657                 :             :                       }
     658                 :     1202464 :                     gsi_remove (&gsi, true);
     659                 :     1202464 :                     if (gsi_end_p (gsi))
     660                 :             :                       break;
     661                 :     1201931 :                     goto next;
     662                 :             :                   }
     663                 :             :               }
     664                 :     3929794 :             gimple_set_block (stmt, NULL);
     665                 :             :           }
     666                 :   427926344 :         for (i = 0; i < gimple_num_ops (stmt); i++)
     667                 :   256454082 :           walk_tree (gimple_op_ptr (stmt, i), clear_unused_block_pointer_1,
     668                 :             :                      NULL, NULL);
     669                 :             :       }
     670                 :     7528363 : }
     671                 :             : 
     672                 :             : /* Dump scope blocks starting at SCOPE to FILE.  INDENT is the
     673                 :             :    indentation level and FLAGS is as in print_generic_expr.  */
     674                 :             : 
     675                 :             : static void
     676                 :        4236 : dump_scope_block (FILE *file, int indent, tree scope, dump_flags_t flags)
     677                 :             : {
     678                 :        4236 :   tree var, t;
     679                 :        4236 :   unsigned int i;
     680                 :             : 
     681                 :        4236 :   fprintf (file, "\n%*s{ Scope block #%i%s",indent, "" , BLOCK_NUMBER (scope),
     682                 :        4236 :            TREE_USED (scope) ? "" : " (unused)");
     683                 :        4236 :   if (LOCATION_LOCUS (BLOCK_SOURCE_LOCATION (scope)) != UNKNOWN_LOCATION)
     684                 :             :     {
     685                 :         920 :       expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (scope));
     686                 :         920 :       fprintf (file, " %s:%i", s.file, s.line);
     687                 :             :     }
     688                 :        4236 :   if (BLOCK_ABSTRACT_ORIGIN (scope))
     689                 :             :     {
     690                 :        1980 :       tree origin = block_ultimate_origin (scope);
     691                 :        1980 :       if (origin)
     692                 :             :         {
     693                 :        1980 :           fprintf (file, " Originating from :");
     694                 :        1980 :           if (DECL_P (origin))
     695                 :         920 :             print_generic_decl (file, origin, flags);
     696                 :             :           else
     697                 :        1060 :             fprintf (file, "#%i", BLOCK_NUMBER (origin));
     698                 :             :         }
     699                 :             :     }
     700                 :        4236 :   if (BLOCK_FRAGMENT_ORIGIN (scope))
     701                 :           0 :     fprintf (file, " Fragment of : #%i",
     702                 :           0 :              BLOCK_NUMBER (BLOCK_FRAGMENT_ORIGIN (scope)));
     703                 :        4236 :   else if (BLOCK_FRAGMENT_CHAIN (scope))
     704                 :             :     {
     705                 :           0 :       fprintf (file, " Fragment chain :");
     706                 :           0 :       for (t = BLOCK_FRAGMENT_CHAIN (scope); t ;
     707                 :           0 :            t = BLOCK_FRAGMENT_CHAIN (t))
     708                 :           0 :         fprintf (file, " #%i", BLOCK_NUMBER (t));
     709                 :             :     }
     710                 :        4236 :   fprintf (file, " \n");
     711                 :        8040 :   for (var = BLOCK_VARS (scope); var; var = DECL_CHAIN (var))
     712                 :             :     {
     713                 :        3804 :       fprintf (file, "%*s", indent, "");
     714                 :        3804 :       print_generic_decl (file, var, flags);
     715                 :        3804 :       fprintf (file, "\n");
     716                 :             :     }
     717                 :        4236 :   for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (scope); i++)
     718                 :             :     {
     719                 :           0 :       fprintf (file, "%*s",indent, "");
     720                 :           0 :       print_generic_decl (file, BLOCK_NONLOCALIZED_VAR (scope, i),
     721                 :             :                           flags);
     722                 :           0 :       fprintf (file, " (nonlocalized)\n");
     723                 :             :     }
     724                 :        6613 :   for (t = BLOCK_SUBBLOCKS (scope); t ; t = BLOCK_CHAIN (t))
     725                 :        2377 :     dump_scope_block (file, indent + 2, t, flags);
     726                 :        4236 :   fprintf (file, "\n%*s}\n",indent, "");
     727                 :        4236 : }
     728                 :             : 
     729                 :             : /* Dump the tree of lexical scopes starting at SCOPE to stderr.  FLAGS
     730                 :             :    is as in print_generic_expr.  */
     731                 :             : 
     732                 :             : DEBUG_FUNCTION void
     733                 :           0 : debug_scope_block (tree scope, dump_flags_t flags)
     734                 :             : {
     735                 :           0 :   dump_scope_block (stderr, 0, scope, flags);
     736                 :           0 : }
     737                 :             : 
     738                 :             : 
     739                 :             : /* Dump the tree of lexical scopes of current_function_decl to FILE.
     740                 :             :    FLAGS is as in print_generic_expr.  */
     741                 :             : 
     742                 :             : void
     743                 :        1859 : dump_scope_blocks (FILE *file, dump_flags_t flags)
     744                 :             : {
     745                 :        1859 :   dump_scope_block (file, 0, DECL_INITIAL (current_function_decl), flags);
     746                 :        1859 : }
     747                 :             : 
     748                 :             : 
     749                 :             : /* Dump the tree of lexical scopes of current_function_decl to stderr.
     750                 :             :    FLAGS is as in print_generic_expr.  */
     751                 :             : 
     752                 :             : DEBUG_FUNCTION void
     753                 :           0 : debug_scope_blocks (dump_flags_t flags)
     754                 :             : {
     755                 :           0 :   dump_scope_blocks (stderr, flags);
     756                 :           0 : }
     757                 :             : 
     758                 :             : /* Remove local variables that are not referenced in the IL.  */
     759                 :             : 
     760                 :             : void
     761                 :     8831018 : remove_unused_locals (void)
     762                 :             : {
     763                 :     8831018 :   basic_block bb;
     764                 :     8831018 :   tree var;
     765                 :     8831018 :   unsigned srcidx, dstidx, num;
     766                 :     8831018 :   bool have_local_clobbers = false;
     767                 :             : 
     768                 :             :   /* Removing declarations from lexical blocks when not optimizing is
     769                 :             :      not only a waste of time, it actually causes differences in stack
     770                 :             :      layout.  */
     771                 :     8831018 :   if (!optimize)
     772                 :     1302655 :     return;
     773                 :             : 
     774                 :     7528363 :   timevar_push (TV_REMOVE_UNUSED);
     775                 :             : 
     776                 :     7528363 :   mark_scope_block_unused (DECL_INITIAL (current_function_decl));
     777                 :             : 
     778                 :     7528363 :   usedvars = BITMAP_ALLOC (NULL);
     779                 :     7528363 :   auto_bitmap useddebug;
     780                 :             : 
     781                 :             :   /* Walk the CFG marking all referenced symbols.  */
     782                 :    59393936 :   FOR_EACH_BB_FN (bb, cfun)
     783                 :             :     {
     784                 :    51865573 :       gimple_stmt_iterator gsi;
     785                 :    51865573 :       size_t i;
     786                 :    51865573 :       edge_iterator ei;
     787                 :    51865573 :       edge e;
     788                 :             : 
     789                 :             :       /* Walk the statements.  */
     790                 :   457200736 :       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     791                 :             :         {
     792                 :   353469590 :           gimple *stmt = gsi_stmt (gsi);
     793                 :   353469590 :           tree b = gimple_block (stmt);
     794                 :             : 
     795                 :             :           /* If we wanted to mark the block referenced by the inline
     796                 :             :              entry point marker as used, this would be a good spot to
     797                 :             :              do it.  If the block is not otherwise used, the stmt will
     798                 :             :              be cleaned up in clean_unused_block_pointer.  */
     799                 :   353469590 :           if (is_gimple_debug (stmt))
     800                 :             :             {
     801                 :   166772069 :               if (gimple_debug_bind_p (stmt))
     802                 :             :                 {
     803                 :   121877585 :                   tree var = gimple_debug_bind_get_var  (stmt);
     804                 :   121877585 :                   if (VAR_P (var))
     805                 :             :                     {
     806                 :   115103251 :                       if (!gimple_debug_bind_get_value (stmt))
     807                 :             :                         /* Run the 2nd phase.  */
     808                 :             :                         have_local_clobbers = true;
     809                 :             :                       else
     810                 :    61785936 :                         bitmap_set_bit (useddebug, DECL_UID (var));
     811                 :             :                     }
     812                 :             :                 }
     813                 :   166772069 :               continue;
     814                 :   166772069 :             }
     815                 :             : 
     816                 :   186697521 :           if (gimple_clobber_p (stmt))
     817                 :             :             {
     818                 :    10004690 :               have_local_clobbers = true;
     819                 :    10004690 :               continue;
     820                 :             :             }
     821                 :             : 
     822                 :   176692831 :           if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
     823                 :             :             {
     824                 :         822 :               have_local_clobbers = true;
     825                 :         822 :               continue;
     826                 :             :             }
     827                 :             : 
     828                 :   176692009 :           if (b)
     829                 :   162555956 :             TREE_USED (b) = true;
     830                 :             : 
     831                 :   671650006 :           for (i = 0; i < gimple_num_ops (stmt); i++)
     832                 :   494957997 :             mark_all_vars_used (gimple_op_ptr (gsi_stmt (gsi), i));
     833                 :             :         }
     834                 :             : 
     835                 :    51865573 :       for (gphi_iterator gpi = gsi_start_phis (bb);
     836                 :    69105133 :            !gsi_end_p (gpi);
     837                 :    17239560 :            gsi_next (&gpi))
     838                 :             :         {
     839                 :    17239560 :           use_operand_p arg_p;
     840                 :    17239560 :           ssa_op_iter i;
     841                 :    17239560 :           tree def;
     842                 :    17239560 :           gphi *phi = gpi.phi ();
     843                 :             : 
     844                 :    34479120 :           if (virtual_operand_p (gimple_phi_result (phi)))
     845                 :     8398594 :             continue;
     846                 :             : 
     847                 :     8840966 :           def = gimple_phi_result (phi);
     848                 :     8840966 :           mark_all_vars_used (&def);
     849                 :             : 
     850                 :    29956658 :           FOR_EACH_PHI_ARG (arg_p, phi, i, SSA_OP_ALL_USES)
     851                 :             :             {
     852                 :    21115692 :               tree arg = USE_FROM_PTR (arg_p);
     853                 :    21115692 :               int index = PHI_ARG_INDEX_FROM_USE (arg_p);
     854                 :    21115692 :               tree block =
     855                 :    21115692 :                 LOCATION_BLOCK (gimple_phi_arg_location (phi, index));
     856                 :    13147354 :               if (block != NULL)
     857                 :    13146142 :                 TREE_USED (block) = true;
     858                 :    21115692 :               mark_all_vars_used (&arg);
     859                 :             :             }
     860                 :             :         }
     861                 :             : 
     862                 :   124266922 :       FOR_EACH_EDGE (e, ei, bb->succs)
     863                 :    72401349 :         if (LOCATION_BLOCK (e->goto_locus) != NULL)
     864                 :    49738064 :           TREE_USED (LOCATION_BLOCK (e->goto_locus)) = true;
     865                 :             :     }
     866                 :             : 
     867                 :             :   /* We do a two-pass approach about the out-of-scope clobbers.  We want
     868                 :             :      to remove them if they are the only references to a local variable,
     869                 :             :      but we want to retain them when there's any other.  So the first pass
     870                 :             :      ignores them, and the second pass (if there were any) tries to remove
     871                 :             :      them.  We do the same for .DEFERRED_INIT.  */
     872                 :     7528363 :   if (have_local_clobbers)
     873                 :    39802384 :     FOR_EACH_BB_FN (bb, cfun)
     874                 :             :       {
     875                 :    36469913 :         gimple_stmt_iterator gsi;
     876                 :             : 
     877                 :   370413982 :         for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
     878                 :             :           {
     879                 :   297474156 :             gimple *stmt = gsi_stmt (gsi);
     880                 :   297474156 :             tree b = gimple_block (stmt);
     881                 :             : 
     882                 :   297474156 :             if (gimple_clobber_p (stmt))
     883                 :             :               {
     884                 :    10004690 :                 tree lhs = gimple_assign_lhs (stmt);
     885                 :    10004690 :                 tree base = get_base_address (lhs);
     886                 :             :                 /* Remove clobbers referencing unused vars, or clobbers
     887                 :             :                    with MEM_REF lhs referencing uninitialized pointers.  */
     888                 :     8442783 :                 if ((VAR_P (base) && !is_used_p (base))
     889                 :    17854199 :                     || (TREE_CODE (lhs) == MEM_REF
     890                 :     2597144 :                         && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME
     891                 :     1547431 :                         && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (lhs, 0))
     892                 :      924055 :                         && (TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (lhs, 0)))
     893                 :             :                             != PARM_DECL)))
     894                 :             :                   {
     895                 :      618495 :                     unlink_stmt_vdef (stmt);
     896                 :      618495 :                     gsi_remove (&gsi, true);
     897                 :      618495 :                     release_defs (stmt);
     898                 :      618495 :                     continue;
     899                 :             :                   }
     900                 :     9386195 :                 if (b)
     901                 :     8966519 :                   TREE_USED (b) = true;
     902                 :             :               }
     903                 :   287469466 :             else if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
     904                 :             :               {
     905                 :         822 :                 tree lhs = gimple_call_lhs (stmt);
     906                 :         822 :                 tree base = get_base_address (lhs);
     907                 :         822 :                 if (DECL_P (base) && !is_used_p (base))
     908                 :             :                   {
     909                 :          11 :                     unlink_stmt_vdef (stmt);
     910                 :          11 :                     gsi_remove (&gsi, true);
     911                 :          11 :                     release_defs (stmt);
     912                 :          11 :                     continue;
     913                 :             :                   }
     914                 :         811 :                 if (b)
     915                 :         811 :                   TREE_USED (b) = true;
     916                 :             :               }
     917                 :   287468644 :             else if (gimple_debug_bind_p (stmt))
     918                 :             :               {
     919                 :   119864825 :                 tree var = gimple_debug_bind_get_var (stmt);
     920                 :   123216539 :                 if (VAR_P (var)
     921                 :   113253398 :                     && !bitmap_bit_p (useddebug, DECL_UID (var))
     922                 :   123307274 :                     && !is_used_p (var))
     923                 :             :                   {
     924                 :     3351714 :                     if (dump_file && (dump_flags & TDF_DETAILS))
     925                 :           0 :                       fprintf (dump_file, "Dead debug bind reset to %u\n",
     926                 :           0 :                                DECL_UID (var));
     927                 :     3351714 :                     gsi_remove (&gsi, true);
     928                 :     3351714 :                     continue;
     929                 :             :                   }
     930                 :             :               }
     931                 :   293503936 :             gsi_next (&gsi);
     932                 :             :           }
     933                 :             :       }
     934                 :             : 
     935                 :     7528363 :   if (cfun->has_simduid_loops)
     936                 :             :     {
     937                 :       93584 :       for (auto loop : loops_list (cfun, 0))
     938                 :       34631 :         if (loop->simduid && !is_used_p (loop->simduid))
     939                 :       19930 :           loop->simduid = NULL_TREE;
     940                 :             :     }
     941                 :             : 
     942                 :     7528363 :   cfun->has_local_explicit_reg_vars = false;
     943                 :             : 
     944                 :             :   /* Remove unmarked local and global vars from local_decls.  */
     945                 :     7528363 :   num = vec_safe_length (cfun->local_decls);
     946                 :    56292098 :   for (srcidx = 0, dstidx = 0; srcidx < num; srcidx++)
     947                 :             :     {
     948                 :    48763735 :       var = (*cfun->local_decls)[srcidx];
     949                 :    48763735 :       if (VAR_P (var))
     950                 :             :         {
     951                 :    48763735 :           if (!is_used_p (var))
     952                 :             :             {
     953                 :    25078896 :               tree def;
     954                 :    25078896 :               if (cfun->nonlocal_goto_save_area
     955                 :    25078896 :                   && TREE_OPERAND (cfun->nonlocal_goto_save_area, 0) == var)
     956                 :          10 :                 cfun->nonlocal_goto_save_area = NULL;
     957                 :             :               /* Release any default def associated with var.  */
     958                 :    25078896 :               if ((def = ssa_default_def (cfun, var)) != NULL_TREE)
     959                 :             :                 {
     960                 :     1085392 :                   set_ssa_default_def (cfun, var, NULL_TREE);
     961                 :     1085392 :                   release_ssa_name (def);
     962                 :             :                 }
     963                 :    25078896 :               continue;
     964                 :    25078896 :             }
     965                 :             :         }
     966                 :    23684839 :       if (VAR_P (var) && DECL_HARD_REGISTER (var) && !is_global_var (var))
     967                 :        4503 :         cfun->has_local_explicit_reg_vars = true;
     968                 :             : 
     969                 :    23684839 :       if (srcidx != dstidx)
     970                 :    12807065 :         (*cfun->local_decls)[dstidx] = var;
     971                 :    23684839 :       dstidx++;
     972                 :             :     }
     973                 :     7528363 :   if (dstidx != num)
     974                 :             :     {
     975                 :     3722108 :       statistics_counter_event (cfun, "unused VAR_DECLs removed", num - dstidx);
     976                 :     3722108 :       cfun->local_decls->truncate (dstidx);
     977                 :             :     }
     978                 :             : 
     979                 :     7528363 :   remove_unused_scope_block_p (DECL_INITIAL (current_function_decl),
     980                 :     7528363 :                                polymorphic_ctor_dtor_p (current_function_decl,
     981                 :             :                                                         true) != NULL_TREE);
     982                 :     7528363 :   clear_unused_block_pointer ();
     983                 :             : 
     984                 :     7528363 :   BITMAP_FREE (usedvars);
     985                 :             : 
     986                 :     7528363 :   if (dump_file && (dump_flags & TDF_DETAILS))
     987                 :             :     {
     988                 :        1857 :       fprintf (dump_file, "Scope blocks after cleanups:\n");
     989                 :        1857 :       dump_scope_blocks (dump_file, dump_flags);
     990                 :             :     }
     991                 :             : 
     992                 :     7528363 :   timevar_pop (TV_REMOVE_UNUSED);
     993                 :     7528363 : }
     994                 :             : 
     995                 :             : /* Allocate and return a new live range information object base on MAP.  */
     996                 :             : 
     997                 :             : static tree_live_info_p
     998                 :     1247749 : new_tree_live_info (var_map map)
     999                 :             : {
    1000                 :     1247749 :   tree_live_info_p live;
    1001                 :     1247749 :   basic_block bb;
    1002                 :             : 
    1003                 :     1247749 :   live = XNEW (struct tree_live_info_d);
    1004                 :     1247749 :   live->map = map;
    1005                 :     1247749 :   live->num_blocks = last_basic_block_for_fn (cfun);
    1006                 :             : 
    1007                 :     1247749 :   bitmap_obstack_initialize (&live->livein_obstack);
    1008                 :     1247749 :   bitmap_obstack_initialize (&live->liveout_obstack);
    1009                 :             : 
    1010                 :     1247749 :   live->livein = XCNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
    1011                 :     1247749 :   live->liveout = XCNEWVEC (bitmap_head, last_basic_block_for_fn (cfun));
    1012                 :    12086896 :   for (unsigned i = 0; map->vec_bbs.iterate (i, &bb); ++i)
    1013                 :             :     {
    1014                 :    10839147 :       bitmap_initialize (&live->livein[bb->index], &live->livein_obstack);
    1015                 :    10839147 :       bitmap_initialize (&live->liveout[bb->index], &live->liveout_obstack);
    1016                 :             :     }
    1017                 :             : 
    1018                 :     1247749 :   live->work_stack = XNEWVEC (int, last_basic_block_for_fn (cfun));
    1019                 :     1247749 :   live->stack_top = live->work_stack;
    1020                 :             : 
    1021                 :     1247749 :   return live;
    1022                 :             : }
    1023                 :             : 
    1024                 :             : 
    1025                 :             : /* Free storage for live range info object LIVE.  */
    1026                 :             : 
    1027                 :             : void
    1028                 :     1247749 : delete_tree_live_info (tree_live_info_p live)
    1029                 :             : {
    1030                 :     1247749 :   if (live->livein)
    1031                 :             :     {
    1032                 :           0 :       bitmap_obstack_release (&live->livein_obstack);
    1033                 :           0 :       free (live->livein);
    1034                 :             :     }
    1035                 :     1247749 :   if (live->liveout)
    1036                 :             :     {
    1037                 :     1247749 :       bitmap_obstack_release (&live->liveout_obstack);
    1038                 :     1247749 :       free (live->liveout);
    1039                 :             :     }
    1040                 :     1247749 :   free (live->work_stack);
    1041                 :     1247749 :   free (live);
    1042                 :     1247749 : }
    1043                 :             : 
    1044                 :             : 
    1045                 :             : /* Visit basic block BB and propagate any required live on entry bits from
    1046                 :             :    LIVE into the predecessors.  VISITED is the bitmap of visited blocks.
    1047                 :             :    TMP is a temporary work bitmap which is passed in to avoid reallocating
    1048                 :             :    it each time.  */
    1049                 :             : 
    1050                 :             : static void
    1051                 :    12364888 : loe_visit_block (tree_live_info_p live, basic_block bb, sbitmap visited)
    1052                 :             : {
    1053                 :    12364888 :   edge e;
    1054                 :    12364888 :   bool change;
    1055                 :    12364888 :   edge_iterator ei;
    1056                 :    12364888 :   basic_block pred_bb;
    1057                 :    12364888 :   bitmap loe;
    1058                 :             : 
    1059                 :    12364888 :   gcc_checking_assert (!bitmap_bit_p (visited, bb->index));
    1060                 :    12364888 :   bitmap_set_bit (visited, bb->index);
    1061                 :             : 
    1062                 :    12364888 :   loe = live_on_entry (live, bb);
    1063                 :             : 
    1064                 :    30276969 :   FOR_EACH_EDGE (e, ei, bb->preds)
    1065                 :             :     {
    1066                 :    17912081 :       pred_bb = e->src;
    1067                 :    17912081 :       if (!region_contains_p (live->map, pred_bb))
    1068                 :     1264136 :         continue;
    1069                 :             :       /* Variables live-on-entry from BB that aren't defined in the
    1070                 :             :          predecessor block.  This should be the live on entry vars to pred.
    1071                 :             :          Note that liveout is the DEFs in a block while live on entry is
    1072                 :             :          being calculated.
    1073                 :             :          Add these bits to live-on-entry for the pred. if there are any
    1074                 :             :          changes, and pred_bb has been visited already, add it to the
    1075                 :             :          revisit stack.  */
    1076                 :    16647945 :       change = bitmap_ior_and_compl_into (live_on_entry (live, pred_bb),
    1077                 :    16647945 :                                           loe, &live->liveout[pred_bb->index]);
    1078                 :    16647945 :       if (change
    1079                 :    16647945 :           && bitmap_bit_p (visited, pred_bb->index))
    1080                 :             :         {
    1081                 :     1525741 :           bitmap_clear_bit (visited, pred_bb->index);
    1082                 :     1525741 :           *(live->stack_top)++ = pred_bb->index;
    1083                 :             :         }
    1084                 :             :     }
    1085                 :    12364888 : }
    1086                 :             : 
    1087                 :             : 
    1088                 :             : /* Using LIVE, fill in all the live-on-entry blocks between the defs and uses
    1089                 :             :    of all the variables.  */
    1090                 :             : 
    1091                 :             : static void
    1092                 :     1247749 : live_worklist (tree_live_info_p live)
    1093                 :             : {
    1094                 :     1247749 :   unsigned b;
    1095                 :     1247749 :   basic_block bb;
    1096                 :     1247749 :   auto_sbitmap visited (last_basic_block_for_fn (cfun) + 1);
    1097                 :             : 
    1098                 :     1247749 :   bitmap_clear (visited);
    1099                 :             : 
    1100                 :             :   /* Visit region's blocks in reverse order and propagate live on entry values
    1101                 :             :      into the predecessors blocks.  */
    1102                 :    13334645 :   for (unsigned i = live->map->vec_bbs.length () - 1;
    1103                 :    12086896 :        live->map->vec_bbs.iterate (i, &bb); --i)
    1104                 :    10839147 :     loe_visit_block (live, bb, visited);
    1105                 :             : 
    1106                 :             :   /* Process any blocks which require further iteration.  */
    1107                 :     2773490 :   while (live->stack_top != live->work_stack)
    1108                 :             :     {
    1109                 :     1525741 :       b = *--(live->stack_top);
    1110                 :     1525741 :       loe_visit_block (live, BASIC_BLOCK_FOR_FN (cfun, b), visited);
    1111                 :             :     }
    1112                 :     1247749 : }
    1113                 :             : 
    1114                 :             : 
    1115                 :             : /* Calculate the initial live on entry vector for SSA_NAME using immediate_use
    1116                 :             :    links.  Set the live on entry fields in LIVE.  Def's are marked temporarily
    1117                 :             :    in the liveout vector.  */
    1118                 :             : 
    1119                 :             : static void
    1120                 :    10386455 : set_var_live_on_entry (tree ssa_name, tree_live_info_p live)
    1121                 :             : {
    1122                 :    10386455 :   int p;
    1123                 :    10386455 :   gimple *stmt;
    1124                 :    10386455 :   use_operand_p use;
    1125                 :    10386455 :   basic_block def_bb = NULL;
    1126                 :    10386455 :   imm_use_iterator imm_iter;
    1127                 :             : 
    1128                 :    10386455 :   p = var_to_partition (live->map, ssa_name);
    1129                 :    10386455 :   if (p == NO_PARTITION)
    1130                 :      693840 :     return;
    1131                 :             : 
    1132                 :    10386455 :   stmt = SSA_NAME_DEF_STMT (ssa_name);
    1133                 :    10386455 :   if (stmt)
    1134                 :             :     {
    1135                 :    10386455 :       def_bb = gimple_bb (stmt);
    1136                 :             :       /* Mark defs in liveout bitmap temporarily.  */
    1137                 :    10386455 :       if (def_bb && region_contains_p (live->map, def_bb))
    1138                 :     6802802 :         bitmap_set_bit (&live->liveout[def_bb->index], p);
    1139                 :             :     }
    1140                 :             :   else
    1141                 :           0 :     def_bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
    1142                 :             : 
    1143                 :             :   /* An undefined local variable does not need to be very alive.  */
    1144                 :    10386455 :   if (ssa_undefined_value_p (ssa_name, false))
    1145                 :             :     return;
    1146                 :             : 
    1147                 :             :   /* Visit each use of SSA_NAME and if it isn't in the same block as the def,
    1148                 :             :      add it to the list of live on entry blocks.  */
    1149                 :    31371115 :   FOR_EACH_IMM_USE_FAST (use, imm_iter, ssa_name)
    1150                 :             :     {
    1151                 :    21678500 :       gimple *use_stmt = USE_STMT (use);
    1152                 :    21678500 :       basic_block add_block = NULL;
    1153                 :             : 
    1154                 :    21678500 :       if (gimple_code (use_stmt) == GIMPLE_PHI)
    1155                 :             :         {
    1156                 :             :           /* Uses in PHI's are considered to be live at exit of the SRC block
    1157                 :             :              as this is where a copy would be inserted.  Check to see if it is
    1158                 :             :              defined in that block, or whether its live on entry.  */
    1159                 :     5500517 :           int index = PHI_ARG_INDEX_FROM_USE (use);
    1160                 :     5500517 :           edge e = gimple_phi_arg_edge (as_a <gphi *> (use_stmt), index);
    1161                 :     5500517 :           if (e->src != def_bb && region_contains_p (live->map, e->src))
    1162                 :     1918678 :             add_block = e->src;
    1163                 :             :         }
    1164                 :    16177983 :       else if (is_gimple_debug (use_stmt))
    1165                 :     3835121 :         continue;
    1166                 :             :       else
    1167                 :             :         {
    1168                 :             :           /* If its not defined in this block, its live on entry.  */
    1169                 :    12342862 :           basic_block use_bb = gimple_bb (use_stmt);
    1170                 :    12342862 :           if (use_bb != def_bb && region_contains_p (live->map, use_bb))
    1171                 :             :             add_block = use_bb;
    1172                 :             :         }
    1173                 :             : 
    1174                 :             :       /* If there was a live on entry use, set the bit.  */
    1175                 :    10020141 :       if (add_block)
    1176                 :    10020141 :         bitmap_set_bit (&live->livein[add_block->index], p);
    1177                 :             :     }
    1178                 :             : }
    1179                 :             : 
    1180                 :             : 
    1181                 :             : /* Calculate the live on exit vectors based on the entry info in LIVEINFO.  */
    1182                 :             : 
    1183                 :             : static void
    1184                 :     1247749 : calculate_live_on_exit (tree_live_info_p liveinfo)
    1185                 :             : {
    1186                 :     1247749 :   basic_block bb;
    1187                 :     1247749 :   edge e;
    1188                 :     1247749 :   edge_iterator ei;
    1189                 :             : 
    1190                 :             :   /* live on entry calculations used liveout vectors for defs, clear them.  */
    1191                 :    12086896 :   for (unsigned i = 0; liveinfo->map->vec_bbs.iterate (i, &bb); ++i)
    1192                 :    10839147 :     bitmap_clear (&liveinfo->liveout[bb->index]);
    1193                 :             : 
    1194                 :             :   /* Set all the live-on-exit bits for uses in PHIs.  */
    1195                 :    12086896 :   FOR_EACH_BB_FN (bb, cfun)
    1196                 :             :     {
    1197                 :    10839147 :       gphi_iterator gsi;
    1198                 :    10839147 :       size_t i;
    1199                 :             : 
    1200                 :             :       /* Mark the PHI arguments which are live on exit to the pred block.  */
    1201                 :    13473764 :       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1202                 :             :         {
    1203                 :     2634617 :           gphi *phi = gsi.phi ();
    1204                 :     5269234 :           if (virtual_operand_p (gimple_phi_result (phi)))
    1205                 :        5649 :             continue;
    1206                 :     9405054 :           for (i = 0; i < gimple_phi_num_args (phi); i++)
    1207                 :             :             {
    1208                 :     6776086 :               tree t = PHI_ARG_DEF (phi, i);
    1209                 :     6776086 :               int p;
    1210                 :             : 
    1211                 :     6776086 :               if (TREE_CODE (t) != SSA_NAME)
    1212                 :     1247582 :                 continue;
    1213                 :             : 
    1214                 :     5528504 :               p = var_to_partition (liveinfo->map, t);
    1215                 :     5528504 :               if (p == NO_PARTITION)
    1216                 :        1386 :                 continue;
    1217                 :     5527118 :               e = gimple_phi_arg_edge (phi, i);
    1218                 :     5527118 :               if (region_contains_p (liveinfo->map, e->src))
    1219                 :     5526900 :                 bitmap_set_bit (&liveinfo->liveout[e->src->index], p);
    1220                 :             :             }
    1221                 :             :         }
    1222                 :             : 
    1223                 :    10839147 :       if (!region_contains_p (liveinfo->map, bb))
    1224                 :           0 :         continue;
    1225                 :             : 
    1226                 :             :       /* Add each successors live on entry to this bock live on exit.  */
    1227                 :    26504700 :       FOR_EACH_EDGE (e, ei, bb->succs)
    1228                 :    15665553 :         if (region_contains_p (liveinfo->map, e->dest))
    1229                 :    14440338 :           bitmap_ior_into (&liveinfo->liveout[bb->index],
    1230                 :    14440338 :                            live_on_entry (liveinfo, e->dest));
    1231                 :             :     }
    1232                 :     1247749 : }
    1233                 :             : 
    1234                 :             : 
    1235                 :             : /* Given partition map MAP, calculate all the live on entry bitmaps for
    1236                 :             :    each partition.  Return a new live info object.  */
    1237                 :             : 
    1238                 :             : tree_live_info_p
    1239                 :     1247749 : calculate_live_ranges (var_map map, bool want_livein)
    1240                 :             : {
    1241                 :     1247749 :   tree var;
    1242                 :     1247749 :   unsigned i;
    1243                 :     1247749 :   tree_live_info_p live;
    1244                 :             : 
    1245                 :     1247749 :   live = new_tree_live_info (map);
    1246                 :    12881953 :   for (i = 0; i < num_var_partitions (map); i++)
    1247                 :             :     {
    1248                 :    10386455 :       var = partition_to_var (map, i);
    1249                 :    10386455 :       if (var != NULL_TREE)
    1250                 :    10386455 :         set_var_live_on_entry (var, live);
    1251                 :             :     }
    1252                 :             : 
    1253                 :     1247749 :   live_worklist (live);
    1254                 :             : 
    1255                 :     1247749 :   if (flag_checking)
    1256                 :     1247732 :     verify_live_on_entry (live);
    1257                 :             : 
    1258                 :     1247749 :   calculate_live_on_exit (live);
    1259                 :             : 
    1260                 :     1247749 :   if (!want_livein)
    1261                 :             :     {
    1262                 :     1247749 :       bitmap_obstack_release (&live->livein_obstack);
    1263                 :     1247749 :       free (live->livein);
    1264                 :     1247749 :       live->livein = NULL;
    1265                 :             :     }
    1266                 :             : 
    1267                 :     1247749 :   return live;
    1268                 :             : }
    1269                 :             : 
    1270                 :             : /* Data structure for compute_live_vars* functions.  */
    1271                 :             : 
    1272                 :             : struct compute_live_vars_data {
    1273                 :             :   /* Vector of bitmaps for live vars indices at the end of basic blocks,
    1274                 :             :      indexed by bb->index.  ACTIVE[ENTRY_BLOCK] must be empty bitmap,
    1275                 :             :      ACTIVE[EXIT_BLOCK] is used for STOP_AFTER.  */
    1276                 :             :   vec<bitmap_head> active;
    1277                 :             :   /* Work bitmap of currently live variables.  */
    1278                 :             :   bitmap work;
    1279                 :             :   /* Set of interesting variables.  Variables with uids not in this
    1280                 :             :      hash_map are not tracked.  */
    1281                 :             :   live_vars_map *vars;
    1282                 :             : };
    1283                 :             : 
    1284                 :             : /* Callback for walk_stmt_load_store_addr_ops.  If OP is a VAR_DECL with
    1285                 :             :    uid set in DATA->vars, enter its corresponding index into bitmap
    1286                 :             :    DATA->work.  */
    1287                 :             : 
    1288                 :             : static bool
    1289                 :    23633996 : compute_live_vars_visit (gimple *, tree op, tree, void *pdata)
    1290                 :             : {
    1291                 :    23633996 :   compute_live_vars_data *data = (compute_live_vars_data *) pdata;
    1292                 :    23633996 :   op = get_base_address (op);
    1293                 :    23633996 :   if (op && VAR_P (op))
    1294                 :    15662558 :     if (unsigned int *v = data->vars->get (DECL_UID (op)))
    1295                 :    12398511 :       bitmap_set_bit (data->work, *v);
    1296                 :    23633996 :   return false;
    1297                 :             : }
    1298                 :             : 
    1299                 :             : /* Helper routine for compute_live_vars, calculating the sets of live
    1300                 :             :    variables at the end of BB, leaving the result in DATA->work.
    1301                 :             :    If STOP_AFTER is non-NULL, stop processing after that stmt.  */
    1302                 :             : 
    1303                 :             : static void
    1304                 :    11460270 : compute_live_vars_1 (basic_block bb, compute_live_vars_data *data,
    1305                 :             :                      gimple *stop_after)
    1306                 :             : {
    1307                 :    11460270 :   edge e;
    1308                 :    11460270 :   edge_iterator ei;
    1309                 :    11460270 :   gimple_stmt_iterator gsi;
    1310                 :    11460270 :   walk_stmt_load_store_addr_fn visit = compute_live_vars_visit;
    1311                 :             : 
    1312                 :    11460270 :   bitmap_clear (data->work);
    1313                 :    27864485 :   FOR_EACH_EDGE (e, ei, bb->preds)
    1314                 :    16404215 :     bitmap_ior_into (data->work, &data->active[e->src->index]);
    1315                 :             : 
    1316                 :    16554326 :   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1317                 :     5094056 :     walk_stmt_load_store_addr_ops (gsi_stmt (gsi), data, NULL, NULL, visit);
    1318                 :   144215359 :   for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1319                 :             :     {
    1320                 :   132984029 :       gimple *stmt = gsi_stmt (gsi);
    1321                 :             : 
    1322                 :   132984029 :       if (gimple_clobber_p (stmt))
    1323                 :             :         {
    1324                 :     4264527 :           tree lhs = gimple_assign_lhs (stmt);
    1325                 :     4264527 :           if (VAR_P (lhs))
    1326                 :     3051842 :             if (unsigned int *v = data->vars->get (DECL_UID (lhs)))
    1327                 :     2557904 :               bitmap_clear_bit (data->work, *v);
    1328                 :             :         }
    1329                 :   128719502 :       else if (!is_gimple_debug (stmt))
    1330                 :    36620344 :         walk_stmt_load_store_addr_ops (stmt, data, visit, visit, visit);
    1331                 :   132984029 :       if (stmt == stop_after)
    1332                 :             :         break;
    1333                 :             :     }
    1334                 :    11460270 : }
    1335                 :             : 
    1336                 :             : /* For function FN and live_vars_map (hash map from DECL_UIDs to a dense set of
    1337                 :             :    indexes of automatic variables VARS, compute which of those variables are
    1338                 :             :    (might be) live at the end of each basic block.  */
    1339                 :             : 
    1340                 :             : vec<bitmap_head>
    1341                 :      305790 : compute_live_vars (struct function *fn, live_vars_map *vars)
    1342                 :             : {
    1343                 :      305790 :   vec<bitmap_head> active;
    1344                 :             : 
    1345                 :             :   /* We approximate the live range of a stack variable by taking the first
    1346                 :             :      mention of its name as starting point(s), and by the end-of-scope
    1347                 :             :      death clobber added by gimplify as ending point(s) of the range.
    1348                 :             :      This overapproximates in the case we for instance moved an address-taken
    1349                 :             :      operation upward, without also moving a dereference to it upwards.
    1350                 :             :      But it's conservatively correct as a variable never can hold values
    1351                 :             :      before its name is mentioned at least once.
    1352                 :             : 
    1353                 :             :      We then do a mostly classical bitmap liveness algorithm.  */
    1354                 :             : 
    1355                 :      305790 :   active.create (last_basic_block_for_fn (fn));
    1356                 :      305790 :   active.quick_grow_cleared (last_basic_block_for_fn (fn));
    1357                 :     6462011 :   for (int i = 0; i < last_basic_block_for_fn (fn); i++)
    1358                 :     6156221 :     bitmap_initialize (&active[i], &bitmap_default_obstack);
    1359                 :             : 
    1360                 :      305790 :   bitmap work = BITMAP_ALLOC (NULL);
    1361                 :             : 
    1362                 :      305790 :   int *rpo = XNEWVEC (int, last_basic_block_for_fn (fn));
    1363                 :      305790 :   int n_bbs = pre_and_rev_post_order_compute_fn (fn, NULL, rpo, false);
    1364                 :             : 
    1365                 :      305790 :   bool changed = true;
    1366                 :      305790 :   compute_live_vars_data data = { active, work, vars };
    1367                 :      852860 :   while (changed)
    1368                 :             :     {
    1369                 :             :       int i;
    1370                 :             :       changed = false;
    1371                 :    11778400 :       for (i = 0; i < n_bbs; i++)
    1372                 :             :         {
    1373                 :    11231330 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    1374                 :    11231330 :           compute_live_vars_1 (bb, &data, NULL);
    1375                 :    11231330 :           if (bitmap_ior_into (&active[bb->index], work))
    1376                 :     4196728 :             changed = true;
    1377                 :             :         }
    1378                 :             :     }
    1379                 :             : 
    1380                 :      305790 :   free (rpo);
    1381                 :      305790 :   BITMAP_FREE (work);
    1382                 :             : 
    1383                 :      305790 :   return active;
    1384                 :             : }
    1385                 :             : 
    1386                 :             : /* For ACTIVE computed by compute_live_vars, compute a bitmap of variables
    1387                 :             :    live after the STOP_AFTER statement and return that bitmap.  */
    1388                 :             : 
    1389                 :             : bitmap
    1390                 :      228940 : live_vars_at_stmt (vec<bitmap_head> &active, live_vars_map *vars,
    1391                 :             :                    gimple *stop_after)
    1392                 :             : {
    1393                 :      228940 :   bitmap work = BITMAP_ALLOC (NULL);
    1394                 :      228940 :   compute_live_vars_data data = { active, work, vars };
    1395                 :      228940 :   basic_block bb = gimple_bb (stop_after);
    1396                 :      228940 :   compute_live_vars_1 (bb, &data, stop_after);
    1397                 :      228940 :   return work;
    1398                 :             : }
    1399                 :             : 
    1400                 :             : /* Destroy what compute_live_vars has returned when it is no longer needed.  */
    1401                 :             : 
    1402                 :             : void
    1403                 :      305790 : destroy_live_vars (vec<bitmap_head> &active)
    1404                 :             : {
    1405                 :      305790 :   unsigned len = active.length ();
    1406                 :     6462011 :   for (unsigned i = 0; i < len; i++)
    1407                 :     6156221 :     bitmap_clear (&active[i]);
    1408                 :             : 
    1409                 :      305790 :   active.release ();
    1410                 :      305790 : }
    1411                 :             : 
    1412                 :             : /* Output partition map MAP to file F.  */
    1413                 :             : 
    1414                 :             : void
    1415                 :         172 : dump_var_map (FILE *f, var_map map)
    1416                 :             : {
    1417                 :         172 :   int t;
    1418                 :         172 :   unsigned x, y;
    1419                 :         172 :   int p;
    1420                 :             : 
    1421                 :         172 :   fprintf (f, "\nPartition map \n\n");
    1422                 :             : 
    1423                 :        1029 :   for (x = 0; x < map->num_partitions; x++)
    1424                 :             :     {
    1425                 :         685 :       if (map->view_to_partition != NULL)
    1426                 :         305 :         p = map->view_to_partition[x];
    1427                 :             :       else
    1428                 :         380 :         p = x;
    1429                 :             : 
    1430                 :         685 :       if (ssa_name (p) == NULL_TREE
    1431                 :        1265 :           || virtual_operand_p (ssa_name (p)))
    1432                 :         219 :         continue;
    1433                 :             : 
    1434                 :             :       t = 0;
    1435                 :       16948 :       for (y = 1; y < num_ssa_names; y++)
    1436                 :             :         {
    1437                 :        8008 :           p = partition_find (map->var_partition, y);
    1438                 :        8008 :           if (map->partition_to_view)
    1439                 :        5071 :             p = map->partition_to_view[p];
    1440                 :        8008 :           if (p == (int)x)
    1441                 :             :             {
    1442                 :         498 :               if (t++ == 0)
    1443                 :             :                 {
    1444                 :         466 :                   fprintf (f, "Partition %d (", x);
    1445                 :         466 :                   print_generic_expr (f, partition_to_var (map, p), TDF_SLIM);
    1446                 :         466 :                   fprintf (f, " - ");
    1447                 :             :                 }
    1448                 :         498 :               fprintf (f, "%d ", y);
    1449                 :             :             }
    1450                 :             :         }
    1451                 :         466 :       if (t != 0)
    1452                 :         466 :         fprintf (f, ")\n");
    1453                 :             :     }
    1454                 :         172 :   fprintf (f, "\n");
    1455                 :         172 : }
    1456                 :             : 
    1457                 :             : 
    1458                 :             : /* Generic dump for the above.  */
    1459                 :             : 
    1460                 :             : DEBUG_FUNCTION void
    1461                 :           0 : debug (_var_map &ref)
    1462                 :             : {
    1463                 :           0 :   dump_var_map (stderr, &ref);
    1464                 :           0 : }
    1465                 :             : 
    1466                 :             : DEBUG_FUNCTION void
    1467                 :           0 : debug (_var_map *ptr)
    1468                 :             : {
    1469                 :           0 :   if (ptr)
    1470                 :           0 :     debug (*ptr);
    1471                 :             :   else
    1472                 :           0 :     fprintf (stderr, "<nil>\n");
    1473                 :           0 : }
    1474                 :             : 
    1475                 :             : 
    1476                 :             : /* Output live range info LIVE to file F, controlled by FLAG.  */
    1477                 :             : 
    1478                 :             : void
    1479                 :          32 : dump_live_info (FILE *f, tree_live_info_p live, int flag)
    1480                 :             : {
    1481                 :          32 :   basic_block bb;
    1482                 :          32 :   unsigned i;
    1483                 :          32 :   var_map map = live->map;
    1484                 :          32 :   bitmap_iterator bi;
    1485                 :             : 
    1486                 :          32 :   if ((flag & LIVEDUMP_ENTRY) && live->livein)
    1487                 :             :     {
    1488                 :           0 :       FOR_EACH_BB_FN (bb, cfun)
    1489                 :             :         {
    1490                 :           0 :           fprintf (f, "\nLive on entry to BB%d : ", bb->index);
    1491                 :           0 :           EXECUTE_IF_SET_IN_BITMAP (&live->livein[bb->index], 0, i, bi)
    1492                 :             :             {
    1493                 :           0 :               print_generic_expr (f, partition_to_var (map, i), TDF_SLIM);
    1494                 :           0 :               fprintf (f, "  ");
    1495                 :             :             }
    1496                 :           0 :           fprintf (f, "\n");
    1497                 :             :         }
    1498                 :             :     }
    1499                 :             : 
    1500                 :          32 :   if ((flag & LIVEDUMP_EXIT) && live->liveout)
    1501                 :             :     {
    1502                 :           0 :       FOR_EACH_BB_FN (bb, cfun)
    1503                 :             :         {
    1504                 :           0 :           fprintf (f, "\nLive on exit from BB%d : ", bb->index);
    1505                 :           0 :           EXECUTE_IF_SET_IN_BITMAP (&live->liveout[bb->index], 0, i, bi)
    1506                 :             :             {
    1507                 :           0 :               print_generic_expr (f, partition_to_var (map, i), TDF_SLIM);
    1508                 :           0 :               fprintf (f, "  ");
    1509                 :             :             }
    1510                 :           0 :           fprintf (f, "\n");
    1511                 :             :         }
    1512                 :             :     }
    1513                 :          32 : }
    1514                 :             : 
    1515                 :             : 
    1516                 :             : /* Generic dump for the above.  */
    1517                 :             : 
    1518                 :             : DEBUG_FUNCTION void
    1519                 :           0 : debug (tree_live_info_d &ref)
    1520                 :             : {
    1521                 :           0 :   dump_live_info (stderr, &ref, 0);
    1522                 :           0 : }
    1523                 :             : 
    1524                 :             : DEBUG_FUNCTION void
    1525                 :           0 : debug (tree_live_info_d *ptr)
    1526                 :             : {
    1527                 :           0 :   if (ptr)
    1528                 :           0 :     debug (*ptr);
    1529                 :             :   else
    1530                 :           0 :     fprintf (stderr, "<nil>\n");
    1531                 :           0 : }
    1532                 :             : 
    1533                 :             : 
    1534                 :             : /* Verify that the info in LIVE matches the current cfg.  */
    1535                 :             : 
    1536                 :             : static void
    1537                 :     1247732 : verify_live_on_entry (tree_live_info_p live)
    1538                 :             : {
    1539                 :     1247732 :   unsigned i;
    1540                 :     1247732 :   tree var;
    1541                 :     1247732 :   gimple *stmt;
    1542                 :     1247732 :   basic_block bb;
    1543                 :     1247732 :   edge e;
    1544                 :     1247732 :   int num;
    1545                 :     1247732 :   edge_iterator ei;
    1546                 :     1247732 :   var_map map = live->map;
    1547                 :             : 
    1548                 :             :    /* Check for live on entry partitions and report those with a DEF in
    1549                 :             :       the program. This will typically mean an optimization has done
    1550                 :             :       something wrong.  */
    1551                 :     1247732 :   bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
    1552                 :     1247732 :   num = 0;
    1553                 :     2495464 :   FOR_EACH_EDGE (e, ei, bb->succs)
    1554                 :             :     {
    1555                 :     1247732 :       int entry_block = e->dest->index;
    1556                 :     1247732 :       if (!region_contains_p (live->map, e->dest))
    1557                 :           0 :         continue;
    1558                 :    11634131 :       for (i = 0; i < (unsigned)num_var_partitions (map); i++)
    1559                 :             :         {
    1560                 :    10386399 :           basic_block tmp;
    1561                 :    10386399 :           tree d = NULL_TREE;
    1562                 :    10386399 :           bitmap loe;
    1563                 :    10386399 :           var = partition_to_var (map, i);
    1564                 :    10386399 :           stmt = SSA_NAME_DEF_STMT (var);
    1565                 :    10386399 :           tmp = gimple_bb (stmt);
    1566                 :    10386399 :           if (SSA_NAME_VAR (var))
    1567                 :     7368348 :             d = ssa_default_def (cfun, SSA_NAME_VAR (var));
    1568                 :             : 
    1569                 :    10386399 :           loe = live_on_entry (live, e->dest);
    1570                 :    10386399 :           if (loe && bitmap_bit_p (loe, i))
    1571                 :             :             {
    1572                 :     1918624 :               if (!gimple_nop_p (stmt))
    1573                 :             :                 {
    1574                 :           0 :                   num++;
    1575                 :           0 :                   print_generic_expr (stderr, var, TDF_SLIM);
    1576                 :           0 :                   fprintf (stderr, " is defined ");
    1577                 :           0 :                   if (tmp)
    1578                 :           0 :                     fprintf (stderr, " in BB%d, ", tmp->index);
    1579                 :           0 :                   fprintf (stderr, "by:\n");
    1580                 :           0 :                   print_gimple_stmt (stderr, stmt, 0, TDF_SLIM);
    1581                 :           0 :                   fprintf (stderr, "\nIt is also live-on-entry to entry BB %d",
    1582                 :             :                            entry_block);
    1583                 :           0 :                   fprintf (stderr, " So it appears to have multiple defs.\n");
    1584                 :             :                 }
    1585                 :             :               else
    1586                 :             :                 {
    1587                 :     1918624 :                   if (d != var)
    1588                 :             :                     {
    1589                 :           0 :                       num++;
    1590                 :           0 :                       print_generic_expr (stderr, var, TDF_SLIM);
    1591                 :           0 :                       fprintf (stderr, " is live-on-entry to BB%d ",
    1592                 :             :                                entry_block);
    1593                 :           0 :                       if (d)
    1594                 :             :                         {
    1595                 :           0 :                           fprintf (stderr, " but is not the default def of ");
    1596                 :           0 :                           print_generic_expr (stderr, d, TDF_SLIM);
    1597                 :           0 :                           fprintf (stderr, "\n");
    1598                 :             :                         }
    1599                 :             :                       else
    1600                 :           0 :                         fprintf (stderr, " and there is no default def.\n");
    1601                 :             :                     }
    1602                 :             :                 }
    1603                 :             :             }
    1604                 :             :           else
    1605                 :     8467775 :             if (d == var)
    1606                 :             :               {
    1607                 :             :                 /* An undefined local variable does not need to be very
    1608                 :             :                    alive.  */
    1609                 :     1665002 :                 if (ssa_undefined_value_p (var, false))
    1610                 :     1665002 :                   continue;
    1611                 :             : 
    1612                 :             :                 /* The only way this var shouldn't be marked live on entry is
    1613                 :             :                    if it occurs in a PHI argument of the block.  */
    1614                 :      971208 :                 size_t z;
    1615                 :      971208 :                 bool ok = false;
    1616                 :      971208 :                 gphi_iterator gsi;
    1617                 :      971208 :                 for (gsi = gsi_start_phis (e->dest);
    1618                 :      971412 :                      !gsi_end_p (gsi) && !ok;
    1619                 :         204 :                      gsi_next (&gsi))
    1620                 :             :                   {
    1621                 :         204 :                     gphi *phi = gsi.phi ();
    1622                 :         408 :                     if (virtual_operand_p (gimple_phi_result (phi)))
    1623                 :           0 :                       continue;
    1624                 :         331 :                     for (z = 0; z < gimple_phi_num_args (phi); z++)
    1625                 :         269 :                       if (var == gimple_phi_arg_def (phi, z))
    1626                 :             :                         {
    1627                 :             :                           ok = true;
    1628                 :             :                           break;
    1629                 :             :                         }
    1630                 :             :                   }
    1631                 :      971208 :                 if (ok)
    1632                 :         142 :                   continue;
    1633                 :             :                 /* Expand adds unused default defs for PARM_DECLs and
    1634                 :             :                    RESULT_DECLs.  They're ok.  */
    1635                 :      971066 :                 if (has_zero_uses (var)
    1636                 :      971066 :                     && SSA_NAME_VAR (var)
    1637                 :     1942132 :                     && !VAR_P (SSA_NAME_VAR (var)))
    1638                 :      971066 :                   continue;
    1639                 :           0 :                 num++;
    1640                 :           0 :                 print_generic_expr (stderr, var, TDF_SLIM);
    1641                 :           0 :                 fprintf (stderr, " is not marked live-on-entry to entry BB%d ",
    1642                 :             :                          entry_block);
    1643                 :           0 :                 fprintf (stderr, "but it is a default def so it should be.\n");
    1644                 :             :               }
    1645                 :             :         }
    1646                 :             :     }
    1647                 :     1247732 :   gcc_assert (num <= 0);
    1648                 :     1247732 : }
    1649                 :             : 
    1650                 :             : 
    1651                 :             : /* Virtual operand liveness analysis data init.  */
    1652                 :             : 
    1653                 :             : void
    1654                 :      183052 : virtual_operand_live::init ()
    1655                 :             : {
    1656                 :      183052 :   liveout = XCNEWVEC (tree, last_basic_block_for_fn (cfun) + 1);
    1657                 :      183052 :   liveout[ENTRY_BLOCK] = ssa_default_def (cfun, gimple_vop (cfun));
    1658                 :      183052 : }
    1659                 :             : 
    1660                 :             : /* Compute live-in of BB from cached live-out.  */
    1661                 :             : 
    1662                 :             : tree
    1663                 :     1657191 : virtual_operand_live::get_live_in (basic_block bb)
    1664                 :             : {
    1665                 :             :   /* A virtual PHI is a convenient cache for live-in.  */
    1666                 :     1657191 :   gphi *phi = get_virtual_phi (bb);
    1667                 :     1657191 :   if (phi)
    1668                 :      518897 :     return gimple_phi_result (phi);
    1669                 :             : 
    1670                 :     1138294 :   if (!liveout)
    1671                 :      183052 :     init ();
    1672                 :             : 
    1673                 :             :   /* Since we don't have a virtual PHI and we don't know whether there's
    1674                 :             :      a downstream virtual use (and thus PHIs are inserted where necessary)
    1675                 :             :      we now have to check each incoming edge live-out.  */
    1676                 :     1138294 :   edge_iterator ei;
    1677                 :     1138294 :   edge e;
    1678                 :     1138294 :   tree livein = NULL_TREE;
    1679                 :     1138294 :   bool first = true;
    1680                 :     2472298 :   FOR_EACH_EDGE (e, ei, bb->preds)
    1681                 :     1334016 :     if (e->flags & EDGE_DFS_BACK)
    1682                 :             :       /* We can ignore backedges since if there's a def there it would
    1683                 :             :          have forced a PHI in the source because it also acts as use
    1684                 :             :          downstream.  */
    1685                 :       59021 :       continue;
    1686                 :     1274995 :     else if (first)
    1687                 :             :       {
    1688                 :     1138294 :         livein = get_live_out (e->src);
    1689                 :     1138294 :         first = false;
    1690                 :             :       }
    1691                 :      136701 :     else if (get_live_out (e->src) != livein)
    1692                 :             :       /* When there's no virtual use downstream this indicates a point
    1693                 :             :          where we'd insert a PHI merging the different live virtual
    1694                 :             :          operands.  */
    1695                 :             :       return NULL_TREE;
    1696                 :             : 
    1697                 :             :   return livein;
    1698                 :             : }
    1699                 :             : 
    1700                 :             : /* Compute live-out of BB.  */
    1701                 :             : 
    1702                 :             : tree
    1703                 :     1274995 : virtual_operand_live::get_live_out (basic_block bb)
    1704                 :             : {
    1705                 :     1274995 :   if (!liveout)
    1706                 :           0 :     init ();
    1707                 :             : 
    1708                 :     1274995 :   if (liveout[bb->index])
    1709                 :             :     return liveout[bb->index];
    1710                 :             : 
    1711                 :      738966 :   tree lo = NULL_TREE;
    1712                 :     3313542 :   for (auto gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi))
    1713                 :             :     {
    1714                 :     2347708 :       gimple *stmt = gsi_stmt (gsi);
    1715                 :     3180132 :       if (gimple_vdef (stmt))
    1716                 :             :         {
    1717                 :             :           lo = gimple_vdef (stmt);
    1718                 :             :           break;
    1719                 :             :         }
    1720                 :     2886274 :       if (gimple_vuse (stmt))
    1721                 :             :         {
    1722                 :             :           lo = gimple_vuse (stmt);
    1723                 :             :           break;
    1724                 :             :         }
    1725                 :             :     }
    1726                 :      738966 :   if (!lo)
    1727                 :      226868 :     lo = get_live_in (bb);
    1728                 :      738966 :   liveout[bb->index] = lo;
    1729                 :      738966 :   return lo;
    1730                 :             : }
        

Generated by: LCOV version 2.1-beta

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