LCOV - code coverage report
Current view: top level - gcc - tree-ssa-operands.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.2 % 602 513
Test Date: 2026-08-22 16:33:35 Functions: 88.9 % 36 32
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* SSA operands management for trees.
       2              :    Copyright (C) 2003-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify
       7              : it under the terms of the GNU General Public License as published by
       8              : the Free Software Foundation; either version 3, or (at your option)
       9              : any later version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful,
      12              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : GNU General Public License for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "backend.h"
      24              : #include "tree.h"
      25              : #include "gimple.h"
      26              : #include "timevar.h"
      27              : #include "ssa.h"
      28              : #include "gimple-pretty-print.h"
      29              : #include "diagnostic-core.h"
      30              : #include "stmt.h"
      31              : #include "print-tree.h"
      32              : #include "dumpfile.h"
      33              : 
      34              : 
      35              : /* This file contains the code required to manage the operands cache of the
      36              :    SSA optimizer.  For every stmt, we maintain an operand cache in the stmt
      37              :    annotation.  This cache contains operands that will be of interest to
      38              :    optimizers and other passes wishing to manipulate the IL.
      39              : 
      40              :    The operand type are broken up into REAL and VIRTUAL operands.  The real
      41              :    operands are represented as pointers into the stmt's operand tree.  Thus
      42              :    any manipulation of the real operands will be reflected in the actual tree.
      43              :    Virtual operands are represented solely in the cache, although the base
      44              :    variable for the SSA_NAME may, or may not occur in the stmt's tree.
      45              :    Manipulation of the virtual operands will not be reflected in the stmt tree.
      46              : 
      47              :    The routines in this file are concerned with creating this operand cache
      48              :    from a stmt tree.
      49              : 
      50              :    The operand tree is the parsed by the various get_* routines which look
      51              :    through the stmt tree for the occurrence of operands which may be of
      52              :    interest, and calls are made to the append_* routines whenever one is
      53              :    found.  There are 4 of these routines, each representing one of the
      54              :    4 types of operands. Defs, Uses, Virtual Uses, and Virtual May Defs.
      55              : 
      56              :    The append_* routines check for duplication, and simply keep a list of
      57              :    unique objects for each operand type in the build_* extendable vectors.
      58              : 
      59              :    Once the stmt tree is completely parsed, the finalize_ssa_operands()
      60              :    routine is called, which proceeds to perform the finalization routine
      61              :    on each of the 4 operand vectors which have been built up.
      62              : 
      63              :    If the stmt had a previous operand cache, the finalization routines
      64              :    attempt to match up the new operands with the old ones.  If it's a perfect
      65              :    match, the old vector is simply reused.  If it isn't a perfect match, then
      66              :    a new vector is created and the new operands are placed there.  For
      67              :    virtual operands, if the previous cache had SSA_NAME version of a
      68              :    variable, and that same variable occurs in the same operands cache, then
      69              :    the new cache vector will also get the same SSA_NAME.
      70              : 
      71              :    i.e., if a stmt had a VUSE of 'a_5', and 'a' occurs in the new
      72              :    operand vector for VUSE, then the new vector will also be modified
      73              :    such that it contains 'a_5' rather than 'a'.  */
      74              : 
      75              : 
      76              : /* Flags to describe operand properties in helpers.  */
      77              : 
      78              : /* By default, operands are loaded.  */
      79              : #define opf_use         0
      80              : 
      81              : /* Operand is the target of an assignment expression or a
      82              :    call-clobbered variable.  */
      83              : #define opf_def         (1 << 0)
      84              : 
      85              : /* No virtual operands should be created in the expression.  This is used
      86              :    when traversing ADDR_EXPR nodes which have different semantics than
      87              :    other expressions.  Inside an ADDR_EXPR node, the only operands that we
      88              :    need to consider are indices into arrays.  For instance, &a.b[i] should
      89              :    generate a USE of 'i' but it should not generate a VUSE for 'a' nor a
      90              :    VUSE for 'b'.  */
      91              : #define opf_no_vops     (1 << 1)
      92              : 
      93              : /* Operand is in a place where address-taken does not imply addressable.  */
      94              : #define opf_non_addressable (1 << 3)
      95              : 
      96              : /* Operand is in a place where opf_non_addressable does not apply.  */
      97              : #define opf_not_non_addressable (1 << 4)
      98              : 
      99              : /* Operand is having its address taken.  */
     100              : #define opf_address_taken (1 << 5)
     101              : 
     102              : /* Class containing temporary per-stmt state.  */
     103              : 
     104  24415807360 : class operands_scanner
     105              : {
     106              :   public:
     107  12207903680 :     operands_scanner (struct function *fun, gimple *statement)
     108  12207903680 :       {
     109  12207903680 :         build_vuse = NULL_TREE;
     110  12207903680 :         build_vdef = NULL_TREE;
     111  12207903680 :         fn = fun;
     112  12207903680 :         stmt = statement;
     113              :       }
     114              : 
     115              :     /* Create an operands cache for STMT.  */
     116              :     void build_ssa_operands ();
     117              : 
     118              :     /* Verifies SSA statement operands.  */
     119              :     DEBUG_FUNCTION bool verify_ssa_operands ();
     120              : 
     121              :   private:
     122              :     /* Disable copy and assign of this class, as it may have problems with
     123              :        build_uses vec.  */
     124              :     DISABLE_COPY_AND_ASSIGN (operands_scanner);
     125              : 
     126              :     /* Array for building all the use operands.  */
     127              :     auto_vec<tree *, 16> build_uses;
     128              : 
     129              :     /* The built VDEF operand.  */
     130              :     tree build_vdef;
     131              : 
     132              :     /* The built VUSE operand.  */
     133              :     tree build_vuse;
     134              : 
     135              :     /* Function which STMT belongs to.  */
     136              :     struct function *fn;
     137              : 
     138              :     /* Statement to work on.  */
     139              :     gimple *stmt;
     140              : 
     141              :     /* Takes elements from build_uses and turns them into use operands of STMT.  */
     142              :     void finalize_ssa_uses ();
     143              : 
     144              :     /* Clear the in_list bits and empty the build array for VDEFs and
     145              :        VUSEs.  */
     146              :     void cleanup_build_arrays ();
     147              : 
     148              :     /* Finalize all the build vectors, fill the new ones into INFO.  */
     149              :     void finalize_ssa_stmt_operands ();
     150              : 
     151              :     /* Start the process of building up operands vectors in INFO.  */
     152              :     void start_ssa_stmt_operands ();
     153              : 
     154              :     /* Add USE_P to the list of pointers to operands.  */
     155              :     void append_use (tree *use_p);
     156              : 
     157              :     /* Add VAR to the set of variables that require a VDEF operator.  */
     158              :     void append_vdef (tree var);
     159              : 
     160              :     /* Add VAR to the set of variables that require a VUSE operator.  */
     161              :     void append_vuse (tree var);
     162              : 
     163              :     /* Add virtual operands for STMT.  FLAGS is as in get_expr_operands.  */
     164              :     void add_virtual_operand (int flags);
     165              : 
     166              : 
     167              :     /* Add *VAR_P to the appropriate operand array for statement STMT.
     168              :        FLAGS is as in get_expr_operands.  If *VAR_P is a GIMPLE register,
     169              :        it will be added to the statement's real operands, otherwise it is
     170              :        added to virtual operands.  */
     171              :     void add_stmt_operand (tree *var_p, int flags);
     172              : 
     173              :     /* A subroutine of get_expr_operands to handle MEM_REF.
     174              : 
     175              :        STMT is the statement being processed, EXPR is the MEM_REF
     176              :           that got us here.
     177              : 
     178              :        FLAGS is as in get_expr_operands.  */
     179              :     void get_mem_ref_operands (tree expr, int flags);
     180              : 
     181              :     /* A subroutine of get_expr_operands to handle TARGET_MEM_REF.  */
     182              :     void get_tmr_operands (tree expr, int flags);
     183              : 
     184              : 
     185              :     /* If STMT is a call that may clobber globals and other symbols that
     186              :        escape, add them to the VDEF/VUSE lists for it.  */
     187              :     void maybe_add_call_vops (gcall *stmt);
     188              : 
     189              :     /* Scan operands in the ASM_EXPR stmt referred to in INFO.  */
     190              :     void get_asm_stmt_operands (gasm *stmt);
     191              : 
     192              : 
     193              :     /* Recursively scan the expression pointed to by EXPR_P in statement
     194              :        STMT.  FLAGS is one of the OPF_* constants modifying how to
     195              :        interpret the operands found.  */
     196              :     void get_expr_operands (tree *expr_p, int flags);
     197              : 
     198              :     /* Parse STMT looking for operands.  When finished, the various
     199              :        build_* operand vectors will have potential operands in them.  */
     200              :     void parse_ssa_operands ();
     201              : 
     202              : 
     203              :     /* Takes elements from build_defs and turns them into def operands of STMT.
     204              :        TODO -- Make build_defs vec of tree *.  */
     205              :     void finalize_ssa_defs ();
     206              : };
     207              : 
     208              : /* Accessor to tree-ssa-operands.cc caches.  */
     209              : static inline struct ssa_operands *
     210    849743702 : gimple_ssa_operands (const struct function *fun)
     211              : {
     212    849743702 :   return &fun->gimple_df->ssa_operands;
     213              : }
     214              : 
     215              : 
     216              : /*  Return true if the SSA operands cache is active.  */
     217              : 
     218              : bool
     219    892302422 : ssa_operands_active (struct function *fun)
     220              : {
     221    892302422 :   if (fun == NULL)
     222              :     return false;
     223              : 
     224    892302422 :   return fun->gimple_df && gimple_ssa_operands (fun)->ops_active;
     225              : }
     226              : 
     227              : 
     228              : /* Create the VOP variable, an artificial global variable to act as a
     229              :    representative of all of the virtual operands FUD chain.  */
     230              : 
     231              : static void
     232      3364591 : create_vop_var (struct function *fn)
     233              : {
     234      3364591 :   tree global_var;
     235              : 
     236      3364591 :   gcc_assert (fn->gimple_df->vop == NULL_TREE);
     237              : 
     238      3364591 :   global_var = build_decl (BUILTINS_LOCATION, VAR_DECL,
     239              :                            get_identifier (".MEM"),
     240              :                            void_type_node);
     241      3364591 :   DECL_ARTIFICIAL (global_var) = 1;
     242      3364591 :   DECL_IGNORED_P (global_var) = 1;
     243      3364591 :   TREE_READONLY (global_var) = 0;
     244      3364591 :   DECL_EXTERNAL (global_var) = 1;
     245      3364591 :   TREE_STATIC (global_var) = 1;
     246      3364591 :   TREE_USED (global_var) = 1;
     247      3364591 :   DECL_CONTEXT (global_var) = NULL_TREE;
     248      3364591 :   TREE_THIS_VOLATILE (global_var) = 0;
     249      3364591 :   TREE_ADDRESSABLE (global_var) = 0;
     250      3364591 :   VAR_DECL_IS_VIRTUAL_OPERAND (global_var) = 1;
     251              : 
     252      3364591 :   fn->gimple_df->vop = global_var;
     253      3364591 : }
     254              : 
     255              : /* These are the sizes of the operand memory buffer in bytes which gets
     256              :    allocated each time more operands space is required.  The final value is
     257              :    the amount that is allocated every time after that.
     258              :    In 1k we can fit 25 use operands (or 63 def operands) on a host with
     259              :    8 byte pointers, that would be 10 statements each with 1 def and 2
     260              :    uses.  */
     261              : 
     262              : #define OP_SIZE_INIT    0
     263              : #define OP_SIZE_1       (1024 - sizeof (void *))
     264              : #define OP_SIZE_2       (1024 * 4 - sizeof (void *))
     265              : #define OP_SIZE_3       (1024 * 16 - sizeof (void *))
     266              : 
     267              : /* Initialize the operand cache routines.  */
     268              : 
     269              : void
     270      3364591 : init_ssa_operands (struct function *fn)
     271              : {
     272      3364591 :   gcc_assert (gimple_ssa_operands (fn)->operand_memory == NULL);
     273      3364591 :   gimple_ssa_operands (fn)->operand_memory_index
     274      3364591 :      = gimple_ssa_operands (fn)->ssa_operand_mem_size;
     275      3364591 :   gimple_ssa_operands (fn)->ops_active = true;
     276      3364591 :   gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_INIT;
     277      3364591 :   create_vop_var (fn);
     278      3364591 : }
     279              : 
     280              : 
     281              : /* Dispose of anything required by the operand routines.  */
     282              : 
     283              : void
     284      3308355 : fini_ssa_operands (struct function *fn)
     285              : {
     286      3308355 :   struct ssa_operand_memory_d *ptr;
     287              : 
     288      3308355 :   gimple_ssa_operands (fn)->free_uses = NULL;
     289              : 
     290      8052134 :   while ((ptr = gimple_ssa_operands (fn)->operand_memory) != NULL)
     291              :     {
     292      4743779 :       gimple_ssa_operands (fn)->operand_memory
     293      4743779 :         = gimple_ssa_operands (fn)->operand_memory->next;
     294      4743779 :       ggc_free (ptr);
     295              :     }
     296              : 
     297      3308355 :   gimple_ssa_operands (fn)->ops_active = false;
     298              : 
     299      3308355 :   fn->gimple_df->vop = NULL_TREE;
     300      3308355 : }
     301              : 
     302              : 
     303              : /* Return memory for an operand of size SIZE.  */
     304              : 
     305              : static inline void *
     306    188360317 : ssa_operand_alloc (struct function *fn, unsigned size)
     307              : {
     308    188360317 :   char *ptr;
     309              : 
     310    188360317 :   gcc_assert (size == sizeof (struct use_optype_d));
     311              : 
     312    188360317 :   if (gimple_ssa_operands (fn)->operand_memory_index + size
     313    188360317 :       >= gimple_ssa_operands (fn)->ssa_operand_mem_size)
     314              :     {
     315      4808539 :       struct ssa_operand_memory_d *ptr;
     316              : 
     317      4808539 :       switch (gimple_ssa_operands (fn)->ssa_operand_mem_size)
     318              :         {
     319      3362695 :         case OP_SIZE_INIT:
     320      3362695 :           gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_1;
     321      3362695 :           break;
     322      1047143 :         case OP_SIZE_1:
     323      1047143 :           gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_2;
     324      1047143 :           break;
     325       398701 :         case OP_SIZE_2:
     326       398701 :         case OP_SIZE_3:
     327       398701 :           gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_3;
     328       398701 :           break;
     329            0 :         default:
     330            0 :           gcc_unreachable ();
     331              :         }
     332              : 
     333              : 
     334      4808539 :       ptr = (ssa_operand_memory_d *) ggc_internal_alloc
     335      4808539 :         (sizeof (void *) + gimple_ssa_operands (fn)->ssa_operand_mem_size);
     336              : 
     337      4808539 :       ptr->next = gimple_ssa_operands (fn)->operand_memory;
     338      4808539 :       gimple_ssa_operands (fn)->operand_memory = ptr;
     339      4808539 :       gimple_ssa_operands (fn)->operand_memory_index = 0;
     340              :     }
     341              : 
     342    188360317 :   ptr = &(gimple_ssa_operands (fn)->operand_memory
     343    188360317 :           ->mem[gimple_ssa_operands (fn)->operand_memory_index]);
     344    188360317 :   gimple_ssa_operands (fn)->operand_memory_index += size;
     345    188360317 :   return ptr;
     346              : }
     347              : 
     348              : 
     349              : /* Allocate a USE operand.  */
     350              : 
     351              : static inline struct use_optype_d *
     352    342210405 : alloc_use (struct function *fn)
     353              : {
     354    342210405 :   struct use_optype_d *ret;
     355    342210405 :   if (gimple_ssa_operands (fn)->free_uses)
     356              :     {
     357    153850088 :       ret = gimple_ssa_operands (fn)->free_uses;
     358    153850088 :       gimple_ssa_operands (fn)->free_uses
     359    153850088 :         = gimple_ssa_operands (fn)->free_uses->next;
     360              :     }
     361              :   else
     362    188360317 :     ret = (struct use_optype_d *)
     363    188360317 :           ssa_operand_alloc (fn, sizeof (struct use_optype_d));
     364    342210405 :   return ret;
     365              : }
     366              : 
     367              : 
     368              : /* Adds OP to the list of uses of statement STMT after LAST.  */
     369              : 
     370              : static inline use_optype_p
     371    342210405 : add_use_op (struct function *fn, gimple *stmt, tree *op, use_optype_p last)
     372              : {
     373    342210405 :   use_optype_p new_use;
     374              : 
     375    342210405 :   new_use = alloc_use (fn);
     376    342210405 :   USE_OP_PTR (new_use)->use = op;
     377    342210405 :   link_imm_use_stmt (USE_OP_PTR (new_use), *op, stmt);
     378    342210405 :   last->next = new_use;
     379    342210405 :   new_use->next = NULL;
     380    342210405 :   return new_use;
     381              : }
     382              : 
     383              : 
     384              : 
     385              : /* Takes elements from build_defs and turns them into def operands of STMT.
     386              :    TODO -- Make build_defs vec of tree *.  */
     387              : 
     388              : inline void
     389    417358123 : operands_scanner::finalize_ssa_defs ()
     390              : {
     391              :   /* Pre-pend the vdef we may have built.  */
     392    417358123 :   if (build_vdef != NULL_TREE)
     393              :     {
     394     62326587 :       tree oldvdef = gimple_vdef (stmt);
     395     62326587 :       if (oldvdef
     396     24930956 :           && TREE_CODE (oldvdef) == SSA_NAME)
     397     62326587 :         oldvdef = SSA_NAME_VAR (oldvdef);
     398     62326587 :       if (oldvdef != build_vdef)
     399     37395631 :         gimple_set_vdef (stmt, build_vdef);
     400              :     }
     401              : 
     402              :   /* Clear and unlink a no longer necessary VDEF.  */
     403    417358123 :   if (build_vdef == NULL_TREE
     404    538623115 :       && gimple_vdef (stmt) != NULL_TREE)
     405              :     {
     406      4258687 :       if (TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
     407              :         {
     408      4051567 :           unlink_stmt_vdef (stmt);
     409      8103134 :           release_ssa_name_fn (fn, gimple_vdef (stmt));
     410              :         }
     411      4258687 :       gimple_set_vdef (stmt, NULL_TREE);
     412              :     }
     413              : 
     414              :   /* If we have a non-SSA_NAME VDEF, mark it for renaming.  */
     415    417358123 :   if (gimple_vdef (stmt)
     416    183591579 :       && TREE_CODE (gimple_vdef (stmt)) != SSA_NAME)
     417              :     {
     418     40871368 :       fn->gimple_df->rename_vops = 1;
     419     40871368 :       fn->gimple_df->ssa_renaming_needed = 1;
     420              :     }
     421    417358123 : }
     422              : 
     423              : 
     424              : /* Takes elements from build_uses and turns them into use operands of STMT.  */
     425              : 
     426              : inline void
     427    417358123 : operands_scanner::finalize_ssa_uses ()
     428              : {
     429    417358123 :   unsigned new_i;
     430    417358123 :   struct use_optype_d new_list;
     431    417358123 :   use_optype_p old_ops, ptr, last;
     432              : 
     433              :   /* Pre-pend the VUSE we may have built.  */
     434    417358123 :   if (build_vuse != NULL_TREE)
     435              :     {
     436    102141310 :       tree oldvuse = gimple_vuse (stmt);
     437    102141310 :       if (oldvuse
     438     42666686 :           && TREE_CODE (oldvuse) == SSA_NAME)
     439    102141310 :         oldvuse = SSA_NAME_VAR (oldvuse);
     440    102141310 :       if (oldvuse != (build_vuse != NULL_TREE
     441              :                       ? build_vuse : build_vdef))
     442     59474624 :         gimple_set_vuse (stmt, NULL_TREE);
     443    204282620 :       build_uses.safe_insert (0, gimple_vuse_ptr (stmt));
     444              :     }
     445              : 
     446    417358123 :   new_list.next = NULL;
     447    417358123 :   last = &new_list;
     448              : 
     449    417358123 :   old_ops = gimple_use_ops (stmt);
     450              : 
     451              :   /* Clear a no longer necessary VUSE.  */
     452    417358123 :   if (build_vuse == NULL_TREE
     453    498808392 :       && gimple_vuse (stmt) != NULL_TREE)
     454      6671157 :     gimple_set_vuse (stmt, NULL_TREE);
     455              : 
     456              :   /* If there is anything in the old list, free it.  */
     457    417358123 :   if (old_ops)
     458              :     {
     459    160323705 :       for (ptr = old_ops; ptr->next; ptr = ptr->next)
     460     49050495 :         delink_imm_use (USE_OP_PTR (ptr));
     461    111273210 :       delink_imm_use (USE_OP_PTR (ptr));
     462    111273210 :       ptr->next = gimple_ssa_operands (fn)->free_uses;
     463    111273210 :       gimple_ssa_operands (fn)->free_uses = old_ops;
     464              :     }
     465              : 
     466              :   /* If we added a VUSE, make sure to set the operand if it is not already
     467              :      present and mark it for renaming.  */
     468    417358123 :   if (build_vuse != NULL_TREE
     469    519499433 :       && gimple_vuse (stmt) == NULL_TREE)
     470              :     {
     471     59474624 :       gimple_set_vuse (stmt, gimple_vop (fn));
     472     59474624 :       fn->gimple_df->rename_vops = 1;
     473     59474624 :       fn->gimple_df->ssa_renaming_needed = 1;
     474              :     }
     475              : 
     476              :   /* Now create nodes for all the new nodes.  */
     477    759568528 :   for (new_i = 0; new_i < build_uses.length (); new_i++)
     478              :     {
     479    342210405 :       tree *op = build_uses[new_i];
     480    342210405 :       last = add_use_op (fn, stmt, op, last);
     481              :     }
     482              : 
     483              :   /* Now set the stmt's operands.  */
     484    417358123 :   gimple_set_use_ops (stmt, new_list.next);
     485    417358123 : }
     486              : 
     487              : 
     488              : /* Clear the in_list bits and empty the build array for VDEFs and
     489              :    VUSEs.  */
     490              : 
     491              : inline void
     492  12207903680 : operands_scanner::cleanup_build_arrays ()
     493              : {
     494  12207903680 :   build_vdef = NULL_TREE;
     495  12207903680 :   build_vuse = NULL_TREE;
     496  12207903680 :   build_uses.truncate (0);
     497              : }
     498              : 
     499              : 
     500              : /* Finalize all the build vectors, fill the new ones into INFO.  */
     501              : 
     502              : inline void
     503    417358123 : operands_scanner::finalize_ssa_stmt_operands ()
     504              : {
     505    417358123 :   finalize_ssa_defs ();
     506    417358123 :   finalize_ssa_uses ();
     507    417358123 :   cleanup_build_arrays ();
     508    417358123 : }
     509              : 
     510              : 
     511              : /* Start the process of building up operands vectors in INFO.  */
     512              : 
     513              : inline void
     514  12207903680 : operands_scanner::start_ssa_stmt_operands ()
     515              : {
     516  12207903680 :   gcc_assert (build_uses.length () == 0);
     517  12207903680 :   gcc_assert (build_vuse == NULL_TREE);
     518  12207903680 :   gcc_assert (build_vdef == NULL_TREE);
     519  12207903680 : }
     520              : 
     521              : 
     522              : /* Add USE_P to the list of pointers to operands.  */
     523              : 
     524              : inline void
     525   5883196144 : operands_scanner::append_use (tree *use_p)
     526              : {
     527   5883196144 :   build_uses.safe_push (use_p);
     528              : }
     529              : 
     530              : 
     531              : /* Add VAR to the set of variables that require a VDEF operator.  */
     532              : 
     533              : inline void
     534   2018854009 : operands_scanner::append_vdef (tree var)
     535              : {
     536   2018854009 :   gcc_assert ((build_vdef == NULL_TREE
     537              :                || build_vdef == var)
     538              :               && (build_vuse == NULL_TREE
     539              :                   || build_vuse == var));
     540              : 
     541   2018854009 :   build_vdef = var;
     542   2018854009 :   build_vuse = var;
     543   2018854009 : }
     544              : 
     545              : 
     546              : /* Add VAR to the set of variables that require a VUSE operator.  */
     547              : 
     548              : inline void
     549   1403592601 : operands_scanner::append_vuse (tree var)
     550              : {
     551   1403592601 :   gcc_assert (build_vuse == NULL_TREE
     552              :               || build_vuse == var);
     553              : 
     554   1403592601 :   build_vuse = var;
     555   1403592601 : }
     556              : 
     557              : /* Add virtual operands for STMT.  FLAGS is as in get_expr_operands.  */
     558              : 
     559              : void
     560   3634676947 : operands_scanner::add_virtual_operand (int flags)
     561              : {
     562              :   /* Add virtual operands to the stmt, unless the caller has specifically
     563              :      requested not to do that (used when adding operands inside an
     564              :      ADDR_EXPR expression).  */
     565   3634676947 :   if (flags & opf_no_vops)
     566              :     return;
     567              : 
     568   3225579093 :   gcc_assert (!is_gimple_debug (stmt));
     569              : 
     570   3225579093 :   if (flags & opf_def)
     571   2018854009 :     append_vdef (gimple_vop (fn));
     572              :   else
     573   1206725084 :     append_vuse (gimple_vop (fn));
     574              : }
     575              : 
     576              : 
     577              : /* Add *VAR_P to the appropriate operand array for statement STMT.
     578              :    FLAGS is as in get_expr_operands.  If *VAR_P is a GIMPLE register,
     579              :    it will be added to the statement's real operands, otherwise it is
     580              :    added to virtual operands.  */
     581              : 
     582              : void
     583  10064107721 : operands_scanner::add_stmt_operand (tree *var_p, int flags)
     584              : {
     585  10064107721 :   tree var = *var_p;
     586              : 
     587  10064107721 :   gcc_assert (SSA_VAR_P (*var_p)
     588              :               || TREE_CODE (*var_p) == STRING_CST
     589              :               || TREE_CODE (*var_p) == CONST_DECL);
     590              : 
     591  10064107721 :   if (is_gimple_reg (var))
     592              :     {
     593              :       /* The variable is a GIMPLE register.  Add it to real operands.  */
     594   8654911790 :       if (flags & opf_def)
     595              :         ;
     596              :       else
     597   5883196144 :         append_use (var_p);
     598   8654911790 :       if (DECL_P (*var_p))
     599     69517286 :         fn->gimple_df->ssa_renaming_needed = 1;
     600              :     }
     601              :   else
     602              :     {
     603              :       /* Mark statements with volatile operands.  */
     604   1409195931 :       if (!(flags & opf_no_vops)
     605   1392555858 :           && TREE_THIS_VOLATILE (var))
     606     61199936 :         gimple_set_has_volatile_ops (stmt, true);
     607              : 
     608              :       /* The variable is a memory access.  Add virtual operands.  */
     609   1409195931 :       add_virtual_operand (flags);
     610              :     }
     611  10064107721 : }
     612              : 
     613              : /* Mark the base address of REF as having its address taken.
     614              :    REF may be a single variable whose address has been taken or any
     615              :    other valid GIMPLE memory reference (structure reference, array,
     616              :    etc).  */
     617              : 
     618              : static void
     619   1585404250 : mark_address_taken (tree ref)
     620              : {
     621   1585404250 :   tree var;
     622              : 
     623              :   /* Note that it is *NOT OKAY* to use the target of a COMPONENT_REF
     624              :      as the only thing we take the address of.  If VAR is a structure,
     625              :      taking the address of a field means that the whole structure may
     626              :      be referenced using pointer arithmetic.  See PR 21407 and the
     627              :      ensuing mailing list discussion.  */
     628   1585404250 :   var = get_base_address (ref);
     629   1585404250 :   if (VAR_P (var)
     630              :       || TREE_CODE (var) == RESULT_DECL
     631              :       || TREE_CODE (var) == PARM_DECL)
     632    495290434 :     TREE_ADDRESSABLE (var) = 1;
     633   1585404250 : }
     634              : 
     635              : 
     636              : /* A subroutine of get_expr_operands to handle MEM_REF.
     637              : 
     638              :    STMT is the statement being processed, EXPR is the MEM_REF
     639              :       that got us here.
     640              : 
     641              :    FLAGS is as in get_expr_operands.  */
     642              : 
     643              : void
     644   1424721962 : operands_scanner::get_mem_ref_operands (tree expr, int flags)
     645              : {
     646   1424721962 :   tree *pptr = &TREE_OPERAND (expr, 0);
     647              : 
     648   1424721962 :   if (!(flags & opf_no_vops)
     649   1032375865 :       && TREE_THIS_VOLATILE (expr))
     650      1196872 :     gimple_set_has_volatile_ops (stmt, true);
     651              : 
     652              :   /* Add the VOP.  */
     653   1424721962 :   add_virtual_operand (flags);
     654              : 
     655              :   /* If requested, add a USE operand for the base pointer.  */
     656   1424721962 :   get_expr_operands (pptr,
     657              :                      opf_non_addressable | opf_use
     658   1424721962 :                      | (flags & (opf_no_vops|opf_not_non_addressable)));
     659   1424721962 : }
     660              : 
     661              : 
     662              : /* A subroutine of get_expr_operands to handle TARGET_MEM_REF.  */
     663              : 
     664              : void
     665     30782371 : operands_scanner::get_tmr_operands(tree expr, int flags)
     666              : {
     667     30782371 :   if (!(flags & opf_no_vops)
     668     30670687 :       && TREE_THIS_VOLATILE (expr))
     669            0 :     gimple_set_has_volatile_ops (stmt, true);
     670              : 
     671              :   /* First record the real operands.  */
     672     30782371 :   get_expr_operands (&TMR_BASE (expr),
     673              :                      opf_non_addressable | opf_use
     674     30782371 :                      | (flags & (opf_no_vops|opf_not_non_addressable)));
     675     30782371 :   get_expr_operands (&TMR_INDEX (expr), opf_use | (flags & opf_no_vops));
     676     30782371 :   get_expr_operands (&TMR_INDEX2 (expr), opf_use | (flags & opf_no_vops));
     677              : 
     678     30782371 :   add_virtual_operand (flags);
     679     30782371 : }
     680              : 
     681              : 
     682              : /* If STMT is a call that may clobber globals and other symbols that
     683              :    escape, add them to the VDEF/VUSE lists for it.  */
     684              : 
     685              : void
     686    839262887 : operands_scanner::maybe_add_call_vops (gcall *stmt)
     687              : {
     688    839262887 :   int call_flags = gimple_call_flags (stmt);
     689              : 
     690              :   /* If aliases have been computed already, add VDEF or VUSE
     691              :      operands for all the symbols that have been found to be
     692              :      call-clobbered.  */
     693    839262887 :   if (!(call_flags & ECF_NOVOPS))
     694              :     {
     695              :       /* A 'pure' or a 'const' function never call-clobbers anything.  */
     696    838615401 :       if (!(call_flags & (ECF_PURE | ECF_CONST)))
     697    701142634 :         add_virtual_operand (opf_def);
     698    137472767 :       else if (!(call_flags & ECF_CONST))
     699     64520662 :         add_virtual_operand (opf_use);
     700              :     }
     701    839262887 : }
     702              : 
     703              : 
     704              : /* Scan operands in the ASM_EXPR stmt referred to in INFO.  */
     705              : 
     706              : void
     707     10366108 : operands_scanner::get_asm_stmt_operands (gasm *stmt)
     708              : {
     709     10366108 :   size_t i, noutputs;
     710     10366108 :   const char **oconstraints;
     711     10366108 :   const char *constraint;
     712     10366108 :   bool allows_mem, allows_reg, is_inout;
     713              : 
     714     10366108 :   noutputs = gimple_asm_noutputs (stmt);
     715     10366108 :   oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
     716              : 
     717              :   /* Gather all output operands.  */
     718     20560617 :   for (i = 0; i < gimple_asm_noutputs (stmt); i++)
     719              :     {
     720     10194509 :       tree link = gimple_asm_output_op (stmt, i);
     721     10194509 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
     722     10194509 :       oconstraints[i] = constraint;
     723     10194509 :       parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
     724              :                                &allows_reg, &is_inout, nullptr);
     725              : 
     726              :       /* This should have been split in gimplify_asm_expr.  */
     727     10194509 :       gcc_assert (!allows_reg || !is_inout);
     728              : 
     729              :       /* Memory operands are addressable.  Note that STMT needs the
     730              :          address of this operand.  */
     731     10194509 :       if (!allows_reg && allows_mem)
     732       870074 :         mark_address_taken (TREE_VALUE (link));
     733              : 
     734     10194509 :       get_expr_operands (&TREE_VALUE (link), opf_def | opf_not_non_addressable);
     735              :     }
     736              : 
     737              :   /* Gather all input operands.  */
     738     17283261 :   for (i = 0; i < gimple_asm_ninputs (stmt); i++)
     739              :     {
     740      6917153 :       tree link = gimple_asm_input_op (stmt, i);
     741      6917153 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
     742      6917153 :       parse_input_constraint (&constraint, 0, 0, noutputs, 0, oconstraints,
     743              :                               &allows_mem, &allows_reg, nullptr);
     744              : 
     745              :       /* Memory operands are addressable.  Note that STMT needs the
     746              :          address of this operand.  */
     747      6917153 :       if (!allows_reg && allows_mem)
     748       924811 :         mark_address_taken (TREE_VALUE (link));
     749              : 
     750      6917153 :       get_expr_operands (&TREE_VALUE (link), opf_not_non_addressable);
     751              :     }
     752              : 
     753              :   /* Clobber all memory and addressable symbols for asm ("" : : : "memory");  */
     754     10366108 :   if (gimple_asm_clobbers_memory_p (stmt))
     755      4290461 :     add_virtual_operand (opf_def);
     756     10366108 : }
     757              : 
     758              : 
     759              : /* Recursively scan the expression pointed to by EXPR_P in statement
     760              :    STMT.  FLAGS is one of the OPF_* constants modifying how to
     761              :    interpret the operands found.  */
     762              : 
     763              : void
     764  23438168283 : operands_scanner::get_expr_operands (tree *expr_p, int flags)
     765              : {
     766  28898889270 :   enum tree_code code;
     767  28898889270 :   enum tree_code_class codeclass;
     768  28898889270 :   tree expr = *expr_p;
     769  28898889270 :   int uflags = opf_use;
     770              : 
     771  28898889270 :   if (expr == NULL)
     772              :     return;
     773              : 
     774  23016214361 :   if (is_gimple_debug (stmt))
     775   4696475814 :     uflags |= (flags & opf_no_vops);
     776              : 
     777  23016214361 :   code = TREE_CODE (expr);
     778  23016214361 :   codeclass = TREE_CODE_CLASS (code);
     779              : 
     780  23016214361 :   switch (code)
     781              :     {
     782   2813598188 :     case ADDR_EXPR:
     783              :       /* Taking the address of a variable does not represent a
     784              :          reference to it, but the fact that the statement takes its
     785              :          address will be of interest to some passes (e.g. alias
     786              :          resolution).  */
     787   2813598188 :       if ((!(flags & opf_non_addressable)
     788    448002247 :            || (flags & opf_not_non_addressable))
     789   2922924107 :           && !is_gimple_debug (stmt))
     790   1583609365 :         mark_address_taken (TREE_OPERAND (expr, 0));
     791              : 
     792              :       /* Otherwise, there may be variables referenced inside but there
     793              :          should be no VUSEs created, since the referenced objects are
     794              :          not really accessed.  The only operands that we should find
     795              :          here are ARRAY_REF indices which will always be real operands
     796              :          (GIMPLE does not allow non-registers as array indices).  */
     797   2813598188 :       flags |= opf_no_vops;
     798   2813598188 :       get_expr_operands (&TREE_OPERAND (expr, 0),
     799              :                          flags | opf_not_non_addressable | opf_address_taken);
     800   2813598188 :       return;
     801              : 
     802  11692182831 :     case SSA_NAME:
     803  11692182831 :     case VAR_DECL:
     804  11692182831 :     case PARM_DECL:
     805  11692182831 :     case RESULT_DECL:
     806  11692182831 :     case STRING_CST:
     807  11692182831 :     case CONST_DECL:
     808  11692182831 :       if (!(flags & opf_address_taken))
     809  10064107721 :         add_stmt_operand (expr_p, flags);
     810              :       return;
     811              : 
     812              :     case OMP_NEXT_VARIANT:
     813              :     case OMP_TARGET_DEVICE_MATCHES:
     814              :       return;
     815              : 
     816    660233199 :     case DEBUG_EXPR_DECL:
     817    660233199 :       gcc_assert (gimple_debug_bind_p (stmt));
     818              :       return;
     819              : 
     820   1424721962 :     case MEM_REF:
     821   1424721962 :       get_mem_ref_operands (expr, flags);
     822   1424721962 :       return;
     823              : 
     824     30782371 :     case TARGET_MEM_REF:
     825     30782371 :       get_tmr_operands (expr, flags);
     826     30782371 :       return;
     827              : 
     828   2541383002 :     case ARRAY_REF:
     829   2541383002 :     case ARRAY_RANGE_REF:
     830   2541383002 :     case COMPONENT_REF:
     831   2541383002 :     case REALPART_EXPR:
     832   2541383002 :     case IMAGPART_EXPR:
     833   2541383002 :       {
     834   2541383002 :         if (!(flags & opf_no_vops)
     835   1821423911 :             && TREE_THIS_VOLATILE (expr))
     836      5444188 :           gimple_set_has_volatile_ops (stmt, true);
     837              : 
     838   2541383002 :         get_expr_operands (&TREE_OPERAND (expr, 0), flags);
     839              : 
     840   2541383002 :         if (code == COMPONENT_REF)
     841   2128179279 :           get_expr_operands (&TREE_OPERAND (expr, 2), uflags);
     842    413203723 :         else if (code == ARRAY_REF || code == ARRAY_RANGE_REF)
     843              :           {
     844    381315023 :             get_expr_operands (&TREE_OPERAND (expr, 1), uflags);
     845    381315023 :             get_expr_operands (&TREE_OPERAND (expr, 2), uflags);
     846    381315023 :             get_expr_operands (&TREE_OPERAND (expr, 3), uflags);
     847              :           }
     848              : 
     849              :         return;
     850              :       }
     851              : 
     852        15835 :     case WITH_SIZE_EXPR:
     853              :       /* WITH_SIZE_EXPR is a pass-through reference to its first argument,
     854              :          and an rvalue reference to its second argument.  */
     855        15835 :       get_expr_operands (&TREE_OPERAND (expr, 1), uflags);
     856        15835 :       get_expr_operands (&TREE_OPERAND (expr, 0), flags);
     857        15835 :       return;
     858              : 
     859      1626532 :     case COND_EXPR:
     860      1626532 :     case VEC_COND_EXPR:
     861      1626532 :     case VEC_PERM_EXPR:
     862      1626532 :       get_expr_operands (&TREE_OPERAND (expr, 0), uflags);
     863      1626532 :       get_expr_operands (&TREE_OPERAND (expr, 1), uflags);
     864      1626532 :       get_expr_operands (&TREE_OPERAND (expr, 2), uflags);
     865      1626532 :       return;
     866              : 
     867    263882210 :     case CONSTRUCTOR:
     868    263882210 :       {
     869              :         /* General aggregate CONSTRUCTORs have been decomposed, but they
     870              :            are still in use as the COMPLEX_EXPR equivalent for vectors.  */
     871    263882210 :         constructor_elt *ce;
     872    263882210 :         unsigned HOST_WIDE_INT idx;
     873              : 
     874              :         /* A volatile constructor is actually TREE_CLOBBER_P, transfer
     875              :            the volatility to the statement, don't use TREE_CLOBBER_P for
     876              :            mirroring the other uses of THIS_VOLATILE in this file.  */
     877    263882210 :         if (!(flags & opf_no_vops)
     878    263871189 :             && TREE_THIS_VOLATILE (expr))
     879    236741207 :           gimple_set_has_volatile_ops (stmt, true);
     880              : 
     881    285276170 :         for (idx = 0;
     882    285276170 :              vec_safe_iterate (CONSTRUCTOR_ELTS (expr), idx, &ce);
     883              :              idx++)
     884     21393960 :           get_expr_operands (&ce->value, uflags);
     885              : 
     886              :         return;
     887              :       }
     888              : 
     889     15848123 :     case BIT_FIELD_REF:
     890     15848123 :       if (!(flags & opf_no_vops)
     891     14662197 :           && TREE_THIS_VOLATILE (expr))
     892          849 :         gimple_set_has_volatile_ops (stmt, true);
     893              :       /* FALLTHRU */
     894              : 
     895     77744180 :     case VIEW_CONVERT_EXPR:
     896     77744180 :     do_unary:
     897     77744180 :       get_expr_operands (&TREE_OPERAND (expr, 0), flags);
     898     77744180 :       return;
     899              : 
     900     58241950 :     case BIT_INSERT_EXPR:
     901     58241950 :     case COMPOUND_EXPR:
     902     58241950 :     case OBJ_TYPE_REF:
     903     58241950 :     do_binary:
     904     58241950 :       {
     905     58241950 :         get_expr_operands (&TREE_OPERAND (expr, 0), flags);
     906     58241950 :         get_expr_operands (&TREE_OPERAND (expr, 1), flags);
     907     58241950 :         return;
     908              :       }
     909              : 
     910            0 :     case DOT_PROD_EXPR:
     911            0 :     case SAD_EXPR:
     912            0 :     case REALIGN_LOAD_EXPR:
     913            0 :     case WIDEN_MULT_PLUS_EXPR:
     914            0 :     case WIDEN_MULT_MINUS_EXPR:
     915            0 :       {
     916            0 :         get_expr_operands (&TREE_OPERAND (expr, 0), flags);
     917            0 :         get_expr_operands (&TREE_OPERAND (expr, 1), flags);
     918            0 :         get_expr_operands (&TREE_OPERAND (expr, 2), flags);
     919            0 :         return;
     920              :       }
     921              : 
     922              :     case FUNCTION_DECL:
     923              :     case LABEL_DECL:
     924              :     case CASE_LABEL_EXPR:
     925              :       /* Expressions that make no memory references.  */
     926              :       return;
     927              : 
     928   2583421945 :     default:
     929   2583421945 :       if (codeclass == tcc_unary)
     930     21345007 :         goto do_unary;
     931   2562076938 :       if (codeclass == tcc_binary || codeclass == tcc_comparison)
     932     48963825 :         goto do_binary;
     933   2513113113 :       if (codeclass == tcc_constant || codeclass == tcc_type)
     934              :         return;
     935              :     }
     936              : 
     937              :   /* If we get here, something has gone wrong.  */
     938            0 :   if (flag_checking)
     939              :     {
     940            0 :       fprintf (stderr, "unhandled expression in get_expr_operands():\n");
     941            0 :       debug_tree (expr);
     942            0 :       fputs ("\n", stderr);
     943            0 :       gcc_unreachable ();
     944              :     }
     945              : }
     946              : 
     947              : 
     948              : /* Parse STMT looking for operands.  When finished, the various
     949              :    build_* operand vectors will have potential operands in them.  */
     950              : 
     951              : void
     952  12207903680 : operands_scanner::parse_ssa_operands ()
     953              : {
     954  12207903680 :   enum gimple_code code = gimple_code (stmt);
     955  12207903680 :   size_t i, n, start = 0;
     956              : 
     957  12207903680 :   switch (code)
     958              :     {
     959     10366108 :     case GIMPLE_ASM:
     960     10366108 :       get_asm_stmt_operands (as_a <gasm *> (stmt));
     961     10366108 :       break;
     962              : 
     963        22926 :     case GIMPLE_TRANSACTION:
     964              :       /* The start of a transaction is a memory barrier.  */
     965        22926 :       add_virtual_operand (opf_def | opf_use);
     966        22926 :       break;
     967              : 
     968   6595691861 :     case GIMPLE_DEBUG:
     969   6595691861 :       if (gimple_debug_bind_p (stmt)
     970   6595691861 :           && gimple_debug_bind_has_value_p (stmt))
     971   2856169553 :         get_expr_operands (gimple_debug_bind_get_value_ptr (stmt),
     972              :                            opf_use | opf_no_vops);
     973              :       break;
     974              : 
     975    196867517 :     case GIMPLE_RETURN:
     976    196867517 :       append_vuse (gimple_vop (fn));
     977    196867517 :       goto do_default;
     978              : 
     979              :     /* Switch index is the only operand that matters.  */
     980      3487675 :     case GIMPLE_SWITCH:
     981      3487675 :       get_expr_operands (gimple_switch_index_ptr (as_a <gswitch*> (stmt)),
     982              :                          opf_use);
     983      3487675 :       break;
     984              : 
     985    839262887 :     case GIMPLE_CALL:
     986              :       /* Add call-clobbered operands, if needed.  */
     987    839262887 :       maybe_add_call_vops (as_a <gcall *> (stmt));
     988              :       /* FALLTHRU */
     989              : 
     990   4584516995 :     case GIMPLE_ASSIGN:
     991   4584516995 :       get_expr_operands (gimple_op_ptr (stmt, 0), opf_def);
     992   4584516995 :       start = 1;
     993              :       /* FALLTHRU */
     994              : 
     995   5598335110 :     default:
     996   5598335110 :     do_default:
     997   5598335110 :       n = gimple_num_ops (stmt);
     998  16671230576 :       for (i = start; i < n; i++)
     999  11072895466 :         get_expr_operands (gimple_op_ptr (stmt, i), opf_use);
    1000              :       break;
    1001              :     }
    1002  12207903680 : }
    1003              : 
    1004              : 
    1005              : /* Create an operands cache for STMT.  */
    1006              : 
    1007              : void
    1008    417358123 : operands_scanner::build_ssa_operands ()
    1009              : {
    1010              :   /* Initially assume that the statement has no volatile operands.  */
    1011    417358123 :   gimple_set_has_volatile_ops (stmt, false);
    1012              : 
    1013    417358123 :   start_ssa_stmt_operands ();
    1014    417358123 :   parse_ssa_operands ();
    1015    417358123 :   finalize_ssa_stmt_operands ();
    1016    417358123 : }
    1017              : 
    1018              : /* Verifies SSA statement operands.  */
    1019              : 
    1020              : DEBUG_FUNCTION bool
    1021  11790545557 : operands_scanner::verify_ssa_operands ()
    1022              : {
    1023  11790545557 :   use_operand_p use_p;
    1024  11790545557 :   def_operand_p def_p;
    1025  11790545557 :   ssa_op_iter iter;
    1026  11790545557 :   unsigned i;
    1027  11790545557 :   tree def;
    1028  11790545557 :   bool volatile_p = gimple_has_volatile_ops (stmt);
    1029              : 
    1030              :   /* build_ssa_operands w/o finalizing them.  */
    1031  11790545557 :   gimple_set_has_volatile_ops (stmt, false);
    1032  11790545557 :   start_ssa_stmt_operands ();
    1033  11790545557 :   parse_ssa_operands ();
    1034              : 
    1035              :   /* Now verify the built operands are the same as present in STMT.  */
    1036  11790545557 :   def = gimple_vdef (stmt);
    1037   4608181967 :   if (def
    1038   1910358988 :       && TREE_CODE (def) == SSA_NAME)
    1039  11790545557 :     def = SSA_NAME_VAR (def);
    1040  11790545557 :   if (build_vdef != def)
    1041              :     {
    1042            0 :       error ("virtual definition of statement not up to date");
    1043            0 :       return true;
    1044              :     }
    1045  11790545557 :   if (gimple_vdef (stmt)
    1046              :       && ((def_p = gimple_vdef_op (stmt)) == NULL_DEF_OPERAND_P
    1047              :           || DEF_FROM_PTR (def_p) != gimple_vdef (stmt)))
    1048              :     {
    1049              :       error ("virtual def operand missing for statement");
    1050              :       return true;
    1051              :     }
    1052              : 
    1053  11790545557 :   tree use = gimple_vuse (stmt);
    1054   4608181967 :   if (use
    1055   3063312606 :       && TREE_CODE (use) == SSA_NAME)
    1056  11790545557 :     use = SSA_NAME_VAR (use);
    1057  11790545557 :   if (build_vuse != use)
    1058              :     {
    1059            0 :       error ("virtual use of statement not up to date");
    1060            0 :       return true;
    1061              :     }
    1062  11790545557 :   if (gimple_vuse (stmt)
    1063   4608181967 :       && ((use_p = gimple_vuse_op (stmt)) == NULL_USE_OPERAND_P
    1064   3063312606 :           || USE_FROM_PTR (use_p) != gimple_vuse (stmt)))
    1065              :     {
    1066            0 :       error ("virtual use operand missing for statement");
    1067            0 :       return true;
    1068              :     }
    1069              : 
    1070  17433672606 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
    1071              :     {
    1072              :       tree *op;
    1073   7365166483 :       FOR_EACH_VEC_ELT (build_uses, i, op)
    1074              :         {
    1075   7365166483 :           if (use_p->use == op)
    1076              :             {
    1077   5643127049 :               build_uses[i] = NULL;
    1078   5643127049 :               break;
    1079              :             }
    1080              :         }
    1081  11286254098 :       if (i == build_uses.length ())
    1082              :         {
    1083            0 :           error ("excess use operand for statement");
    1084            0 :           debug_generic_expr (USE_FROM_PTR (use_p));
    1085            0 :           return true;
    1086              :         }
    1087              :     }
    1088              : 
    1089              :   tree *op;
    1090  17433672606 :   FOR_EACH_VEC_ELT (build_uses, i, op)
    1091   5643127049 :     if (op != NULL)
    1092              :       {
    1093            0 :         error ("use operand missing for statement");
    1094            0 :         debug_generic_expr (*op);
    1095            0 :         return true;
    1096              :       }
    1097              : 
    1098  16453812915 :   if (gimple_has_volatile_ops (stmt) != volatile_p)
    1099              :     {
    1100            0 :       error ("statement volatile flag not up to date");
    1101            0 :       return true;
    1102              :     }
    1103              : 
    1104  11790545557 :   cleanup_build_arrays ();
    1105  11790545557 :   return false;
    1106              : }
    1107              : 
    1108              : /* Interface for external use.  */
    1109              : 
    1110              : DEBUG_FUNCTION bool
    1111  11790545557 : verify_ssa_operands (struct function *fn, gimple *stmt)
    1112              : {
    1113  11790545557 :   return operands_scanner (fn, stmt).verify_ssa_operands ();
    1114              : }
    1115              : 
    1116              : 
    1117              : /* Releases the operands of STMT back to their freelists, and clears
    1118              :    the stmt operand lists.  */
    1119              : 
    1120              : void
    1121      2092715 : free_stmt_operands (struct function *fn, gimple *stmt)
    1122              : {
    1123      2092715 :   use_optype_p uses = gimple_use_ops (stmt), last_use;
    1124              : 
    1125      2081470 :   if (uses)
    1126              :     {
    1127         8786 :       for (last_use = uses; last_use->next; last_use = last_use->next)
    1128         2952 :         delink_imm_use (USE_OP_PTR (last_use));
    1129         5834 :       delink_imm_use (USE_OP_PTR (last_use));
    1130         5834 :       last_use->next = gimple_ssa_operands (fn)->free_uses;
    1131         5834 :       gimple_ssa_operands (fn)->free_uses = uses;
    1132         5834 :       gimple_set_use_ops (stmt, NULL);
    1133              :     }
    1134              : 
    1135      2092715 :   if (gimple_has_mem_ops (stmt))
    1136              :     {
    1137      1888336 :       gimple_set_vuse (stmt, NULL_TREE);
    1138      1888336 :       gimple_set_vdef (stmt, NULL_TREE);
    1139              :     }
    1140      2092715 : }
    1141              : 
    1142              : 
    1143              : /* Get the operands of statement STMT.  */
    1144              : 
    1145              : void
    1146    419581975 : update_stmt_operands (struct function *fn, gimple *stmt)
    1147              : {
    1148              :   /* If update_stmt_operands is called before SSA is initialized, do
    1149              :      nothing.  */
    1150    419581975 :   if (!ssa_operands_active (fn))
    1151              :     return;
    1152              : 
    1153    417358123 :   timevar_push (TV_TREE_OPS);
    1154              : 
    1155    834716246 :   gcc_assert (gimple_modified_p (stmt));
    1156    417358123 :   operands_scanner (fn, stmt).build_ssa_operands ();
    1157    417358123 :   gimple_set_modified (stmt, false);
    1158              : 
    1159    417358123 :   timevar_pop (TV_TREE_OPS);
    1160              : }
    1161              : 
    1162              : 
    1163              : /* Swap operands EXP0 and EXP1 in statement STMT.  No attempt is done
    1164              :    to test the validity of the swap operation.  */
    1165              : 
    1166              : void
    1167       443932 : swap_ssa_operands (gimple *stmt, tree *exp0, tree *exp1)
    1168              : {
    1169       443932 :   tree op0, op1;
    1170       443932 :   op0 = *exp0;
    1171       443932 :   op1 = *exp1;
    1172              : 
    1173       443932 :   if (op0 != op1)
    1174              :     {
    1175              :       /* Attempt to preserve the relative positions of these two operands in
    1176              :          their * respective immediate use lists by adjusting their use pointer
    1177              :          to point to the new operand position.  */
    1178       443932 :       use_optype_p use0, use1, ptr;
    1179       443932 :       use0 = use1 = NULL;
    1180              : 
    1181              :       /* Find the 2 operands in the cache, if they are there.  */
    1182       887981 :       for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next)
    1183       443932 :         if (USE_OP_PTR (ptr)->use == exp0)
    1184              :           {
    1185              :             use0 = ptr;
    1186              :             break;
    1187              :           }
    1188              : 
    1189      1331679 :       for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next)
    1190       874668 :         if (USE_OP_PTR (ptr)->use == exp1)
    1191              :           {
    1192              :             use1 = ptr;
    1193              :             break;
    1194              :           }
    1195              : 
    1196              :       /* And adjust their location to point to the new position of the
    1197              :          operand.  */
    1198       443932 :       if (use0)
    1199       443815 :         USE_OP_PTR (use0)->use = exp1;
    1200       443932 :       if (use1)
    1201       430853 :         USE_OP_PTR (use1)->use = exp0;
    1202              : 
    1203              :       /* Now swap the data.  */
    1204       443932 :       *exp0 = op1;
    1205       443932 :       *exp1 = op0;
    1206              :     }
    1207       443932 : }
    1208              : 
    1209              : 
    1210              : /* Scan the immediate_use list for VAR making sure its linked properly.
    1211              :    Return TRUE if there is a problem and emit an error message to F.  */
    1212              : 
    1213              : DEBUG_FUNCTION bool
    1214   6402557242 : verify_imm_links (FILE *f, tree var)
    1215              : {
    1216   6402557242 :   use_operand_p ptr, prev, list;
    1217   6402557242 :   unsigned int count;
    1218              : 
    1219   6402557242 :   gcc_assert (TREE_CODE (var) == SSA_NAME);
    1220              : 
    1221   6402557242 :   list = &(SSA_NAME_IMM_USE_NODE (var));
    1222   6402557242 :   gcc_assert (list->use == NULL);
    1223              : 
    1224   6402557242 :   if (list->prev == NULL)
    1225              :     {
    1226            0 :       gcc_assert (list->next == NULL);
    1227              :       return false;
    1228              :     }
    1229              : 
    1230   6402557242 :   prev = list;
    1231   6402557242 :   count = 0;
    1232  17775399477 :   for (ptr = list->next; ptr != list; )
    1233              :     {
    1234  11372842235 :       if (prev != ptr->prev)
    1235              :         {
    1236            0 :           fprintf (f, "prev != ptr->prev\n");
    1237            0 :           goto error;
    1238              :         }
    1239              : 
    1240  11372842235 :       if (ptr->use == NULL)
    1241              :         {
    1242            0 :           fprintf (f, "ptr->use == NULL\n");
    1243            0 :           goto error; /* 2 roots, or SAFE guard node.  */
    1244              :         }
    1245  11372842235 :       else if (*(ptr->use) != var)
    1246              :         {
    1247            0 :           fprintf (f, "*(ptr->use) != var\n");
    1248            0 :           goto error;
    1249              :         }
    1250              : 
    1251  11372842235 :       prev = ptr;
    1252  11372842235 :       ptr = ptr->next;
    1253              : 
    1254  11372842235 :       count++;
    1255  11372842235 :       if (count == 0)
    1256              :         {
    1257            0 :           fprintf (f, "number of immediate uses doesn't fit unsigned int\n");
    1258            0 :           goto error;
    1259              :         }
    1260              :     }
    1261              : 
    1262              :   /* Verify list in the other direction.  */
    1263              :   prev = list;
    1264  17775399477 :   for (ptr = list->prev; ptr != list; )
    1265              :     {
    1266  11372842235 :       if (prev != ptr->next)
    1267              :         {
    1268            0 :           fprintf (f, "prev != ptr->next\n");
    1269            0 :           goto error;
    1270              :         }
    1271  11372842235 :       prev = ptr;
    1272  11372842235 :       ptr = ptr->prev;
    1273  11372842235 :       if (count == 0)
    1274              :         {
    1275            0 :           fprintf (f, "count-- < 0\n");
    1276            0 :           goto error;
    1277              :         }
    1278  11372842235 :       count--;
    1279              :     }
    1280              : 
    1281   6402557242 :   if (count != 0)
    1282              :     {
    1283            0 :       fprintf (f, "count != 0\n");
    1284            0 :       goto error;
    1285              :     }
    1286              : 
    1287              :   return false;
    1288              : 
    1289            0 :  error:
    1290            0 :   if (ptr->loc.stmt && gimple_modified_p (ptr->loc.stmt))
    1291              :     {
    1292            0 :       fprintf (f, " STMT MODIFIED. - <%p> ", (void *)ptr->loc.stmt);
    1293            0 :       print_gimple_stmt (f, ptr->loc.stmt, 0, TDF_SLIM);
    1294              :     }
    1295            0 :   fprintf (f, " IMM ERROR : (use_p : tree - %p:%p)", (void *)ptr,
    1296            0 :            (void *)ptr->use);
    1297            0 :   print_generic_expr (f, USE_FROM_PTR (ptr), TDF_SLIM);
    1298            0 :   fprintf (f, "\n");
    1299            0 :   return true;
    1300              : }
    1301              : 
    1302              : 
    1303              : /* Dump all the immediate uses to FILE.  */
    1304              : 
    1305              : void
    1306            0 : dump_immediate_uses_for (FILE *file, tree var)
    1307              : {
    1308            0 :   imm_use_iterator iter;
    1309            0 :   use_operand_p use_p;
    1310              : 
    1311            0 :   gcc_assert (var && TREE_CODE (var) == SSA_NAME);
    1312              : 
    1313            0 :   print_generic_expr (file, var, TDF_SLIM);
    1314            0 :   fprintf (file, " : -->");
    1315            0 :   if (has_zero_uses (var))
    1316            0 :     fprintf (file, " no uses.\n");
    1317              :   else
    1318            0 :     if (has_single_use (var))
    1319            0 :       fprintf (file, " single use.\n");
    1320              :     else
    1321            0 :       fprintf (file, "%d uses.\n", num_imm_uses (var));
    1322              : 
    1323            0 :   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
    1324              :     {
    1325            0 :       if (use_p->loc.stmt == NULL && use_p->use == NULL)
    1326            0 :         fprintf (file, "***end of stmt iterator marker***\n");
    1327              :       else
    1328            0 :         if (!is_gimple_reg (USE_FROM_PTR (use_p)))
    1329            0 :           print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_VOPS|TDF_MEMSYMS);
    1330              :         else
    1331            0 :           print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_SLIM);
    1332            0 :     }
    1333            0 :   fprintf (file, "\n");
    1334            0 : }
    1335              : 
    1336              : 
    1337              : /* Dump all the immediate uses to FILE.  */
    1338              : 
    1339              : void
    1340            0 : dump_immediate_uses (FILE *file)
    1341              : {
    1342            0 :   tree var;
    1343            0 :   unsigned int x;
    1344              : 
    1345            0 :   fprintf (file, "Immediate_uses: \n\n");
    1346            0 :   FOR_EACH_SSA_NAME (x, var, cfun)
    1347              :     {
    1348            0 :       dump_immediate_uses_for (file, var);
    1349              :     }
    1350            0 : }
    1351              : 
    1352              : 
    1353              : /* Dump def-use edges on stderr.  */
    1354              : 
    1355              : DEBUG_FUNCTION void
    1356            0 : debug_immediate_uses (void)
    1357              : {
    1358            0 :   dump_immediate_uses (stderr);
    1359            0 : }
    1360              : 
    1361              : 
    1362              : /* Dump def-use edges on stderr.  */
    1363              : 
    1364              : DEBUG_FUNCTION void
    1365            0 : debug_immediate_uses_for (tree var)
    1366              : {
    1367            0 :   dump_immediate_uses_for (stderr, var);
    1368            0 : }
    1369              : 
    1370              : 
    1371              : /* Unlink STMTs virtual definition from the IL by propagating its use.  */
    1372              : 
    1373              : void
    1374     59361148 : unlink_stmt_vdef (gimple *stmt)
    1375              : {
    1376     59361148 :   use_operand_p use_p;
    1377     59361148 :   imm_use_iterator iter;
    1378     59361148 :   gimple *use_stmt;
    1379     59361148 :   tree vdef = gimple_vdef (stmt);
    1380     59361148 :   tree vuse = gimple_vuse (stmt);
    1381              : 
    1382     59361148 :   if (!vdef
    1383     16015872 :       || TREE_CODE (vdef) != SSA_NAME)
    1384     44215133 :     return;
    1385              : 
    1386     37637974 :   FOR_EACH_IMM_USE_STMT (use_stmt, iter, vdef)
    1387              :     {
    1388     47198310 :       FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
    1389     23599155 :         SET_USE (use_p, vuse);
    1390     15146015 :     }
    1391              : 
    1392     15146015 :   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (vdef))
    1393          949 :     SSA_NAME_OCCURS_IN_ABNORMAL_PHI (vuse) = 1;
    1394              : }
    1395              : 
    1396              : /* Return true if the var whose chain of uses starts at PTR has a
    1397              :    single nondebug use.  Set USE_P and STMT to that single nondebug
    1398              :    use, if so, or to NULL otherwise.  */
    1399              : bool
    1400     50876691 : single_imm_use_1 (const ssa_use_operand_t *head,
    1401              :                   use_operand_p *use_p, gimple **stmt)
    1402              : {
    1403     50876691 :   ssa_use_operand_t *ptr, *single_use = 0;
    1404              : 
    1405    112289750 :   for (ptr = head->next; ptr != head; ptr = ptr->next)
    1406    106903463 :     if (USE_STMT(ptr) && !is_gimple_debug (USE_STMT (ptr)))
    1407              :       {
    1408     96360678 :         if (single_use)
    1409              :           {
    1410              :             single_use = NULL;
    1411              :             break;
    1412              :           }
    1413              :         single_use = ptr;
    1414              :       }
    1415              : 
    1416     50876691 :   if (use_p)
    1417     50876691 :     *use_p = single_use;
    1418              : 
    1419     50876691 :   if (stmt)
    1420     50876691 :     *stmt = single_use ? single_use->loc.stmt : NULL;
    1421              : 
    1422     50876691 :   return single_use;
    1423              : }
    1424              : 
    1425              : /* Gather all stmts SSAVAR is used on, eliminating duplicates.  */
    1426              : 
    1427              : auto_vec<gimple *, 2>
    1428      3330990 : gather_imm_use_stmts (tree ssavar)
    1429              : {
    1430      3330990 :   auto_vec<gimple *, 2> stmts;
    1431      3330990 :   imm_use_iterator iter;
    1432      3330990 :   use_operand_p use_p;
    1433     11020820 :   FOR_EACH_IMM_USE_FAST (use_p, iter, ssavar)
    1434              :     {
    1435      7689830 :       gimple *use_stmt = USE_STMT (use_p);
    1436      7689830 :       if (use_stmt->ilf)
    1437        49786 :         continue;
    1438      7640044 :       use_stmt->ilf = 1;
    1439      7640044 :       stmts.safe_push (use_stmt);
    1440      3330990 :     }
    1441     17633014 :   for (gimple *use_stmt : stmts)
    1442      7640044 :     use_stmt->ilf = 0;
    1443      3330990 :   return stmts;
    1444              : }
        

Generated by: LCOV version 2.4-beta

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