LCOV - code coverage report
Current view: top level - gcc - tree-ssa-copy.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 81.4 % 215 175
Test Date: 2026-12-05 16:10:02 Functions: 94.1 % 17 16
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Copy propagation and SSA_NAME replacement support routines.
       2              :    Copyright (C) 2004-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify
       7              : it under the terms of the GNU General Public License as published by
       8              : the Free Software Foundation; either version 3, or (at your option)
       9              : any later version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful,
      12              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : GNU General Public License for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "backend.h"
      24              : #include "tree.h"
      25              : #include "gimple.h"
      26              : #include "tree-pass.h"
      27              : #include "ssa.h"
      28              : #include "gimple-pretty-print.h"
      29              : #include "fold-const.h"
      30              : #include "gimple-iterator.h"
      31              : #include "tree-cfg.h"
      32              : #include "tree-ssa-propagate.h"
      33              : #include "cfgloop.h"
      34              : #include "tree-scalar-evolution.h"
      35              : #include "tree-ssa-loop-niter.h"
      36              : #include "gimple-fold.h"
      37              : 
      38              : 
      39              : /* This file implements the copy propagation pass and provides a
      40              :    handful of interfaces for performing const/copy propagation and
      41              :    simple expression replacement which keep variable annotations
      42              :    up-to-date.
      43              : 
      44              :    We require that for any copy operation where the RHS and LHS have
      45              :    a non-null memory tag the memory tag be the same.   It is OK
      46              :    for one or both of the memory tags to be NULL.
      47              : 
      48              :    We also require tracking if a variable is dereferenced in a load or
      49              :    store operation.
      50              : 
      51              :    We enforce these requirements by having all copy propagation and
      52              :    replacements of one SSA_NAME with a different SSA_NAME to use the
      53              :    APIs defined in this file.  */
      54              : 
      55              : /*---------------------------------------------------------------------------
      56              :                                 Copy propagation
      57              : ---------------------------------------------------------------------------*/
      58              : /* Lattice for copy-propagation.  The lattice is initialized to
      59              :    UNDEFINED (value == NULL) for SSA names that can become a copy
      60              :    of something or VARYING (value == self) if not (see get_copy_of_val
      61              :    and stmt_may_generate_copy).  Other values make the name a COPY
      62              :    of that value.
      63              : 
      64              :    When visiting a statement or PHI node the lattice value for an
      65              :    SSA name can transition from UNDEFINED to COPY to VARYING.  */
      66              : 
      67              : struct prop_value_t {
      68              :     /* Copy-of value.  */
      69              :     tree value;
      70              : };
      71              : 
      72      2388083 : class copy_prop : public ssa_propagation_engine
      73              : {
      74              :  public:
      75              :   enum ssa_prop_result visit_stmt (gimple *, edge *, tree *) final override;
      76              :   enum ssa_prop_result visit_phi (gphi *) final override;
      77              : };
      78              : 
      79              : static prop_value_t *copy_of;
      80              : static unsigned n_copy_of;
      81              : 
      82              : 
      83              : /* Return true if this statement may generate a useful copy.  */
      84              : 
      85              : static bool
      86    214340743 : stmt_may_generate_copy (gimple *stmt)
      87              : {
      88    214340743 :   if (gimple_code (stmt) == GIMPLE_PHI)
      89          257 :     return !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (gimple_phi_result (stmt));
      90              : 
      91    214340486 :   gassign *assign = dyn_cast<gassign *> (stmt);
      92     62498022 :   if (!assign)
      93              :     return false;
      94              : 
      95              :   /* If the statement has volatile operands, it won't generate a
      96              :      useful copy.  */
      97     62498022 :   if (gimple_has_volatile_ops (assign))
      98              :     return false;
      99              : 
     100              :   /* Statements with loads and/or stores will never generate a useful copy.  */
     101     57629725 :   if (gimple_vuse (assign))
     102              :     return false;
     103              : 
     104              :   /* If the assignment is from a constant it generates a useful copy.  */
     105     24878219 :   if (gimple_assign_single_p (assign)
     106     24878219 :       && is_gimple_min_invariant (gimple_assign_rhs1 (assign)))
     107              :     return true;
     108              : 
     109              :   /* Otherwise, the only statements that generate useful copies are
     110              :      assignments whose single SSA use doesn't flow through abnormal
     111              :      edges.  */
     112     24463282 :   tree rhs = single_ssa_tree_operand (assign, SSA_OP_USE);
     113     42406795 :   return (rhs && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs));
     114              : }
     115              : 
     116              : 
     117              : /* Return the copy-of value for VAR.  */
     118              : 
     119              : static inline prop_value_t *
     120     55367391 : get_copy_of_val (tree var)
     121              : {
     122     55367391 :   prop_value_t *val = &copy_of[SSA_NAME_VERSION (var)];
     123              : 
     124     55367391 :   if (val->value == NULL_TREE
     125     55367391 :       && !stmt_may_generate_copy (SSA_NAME_DEF_STMT (var)))
     126              :     {
     127              :       /* If the variable will never generate a useful copy relation,
     128              :          make it its own copy.  */
     129      1111345 :       val->value = var;
     130              :     }
     131              : 
     132     55367391 :   return val;
     133              : }
     134              : 
     135              : /* Return the variable VAR is a copy of or VAR if VAR isn't the result
     136              :    of a copy.  */
     137              : 
     138              : static inline tree
     139     61306829 : valueize_val (tree var)
     140              : {
     141     61306829 :   if (TREE_CODE (var) == SSA_NAME)
     142              :     {
     143     43150108 :       tree val = get_copy_of_val (var)->value;
     144     43150108 :       if (val)
     145     43150108 :         return val;
     146              :     }
     147              :   return var;
     148              : }
     149              : 
     150              : /* Set VAL to be the copy of VAR.  If that changed return true.  */
     151              : 
     152              : static inline bool
     153    103363212 : set_copy_of_val (tree var, tree val)
     154              : {
     155    103363212 :   unsigned int ver = SSA_NAME_VERSION (var);
     156    103363212 :   tree old;
     157              : 
     158              :   /* Set FIRST to be the first link in COPY_OF[DEST].  If that
     159              :      changed, return true.  */
     160    103363212 :   old = copy_of[ver].value;
     161    103363212 :   copy_of[ver].value = val;
     162              : 
     163    103363212 :   if (old != val
     164    103363212 :       && (!old || !operand_equal_p (old, val, 0)))
     165    100814481 :     return true;
     166              : 
     167              :   return false;
     168              : }
     169              : 
     170              : 
     171              : /* Dump the copy-of value for variable VAR to FILE.  */
     172              : 
     173              : static void
     174            0 : dump_copy_of (FILE *file, tree var)
     175              : {
     176            0 :   tree val;
     177              : 
     178            0 :   print_generic_expr (file, var, dump_flags);
     179            0 :   if (TREE_CODE (var) != SSA_NAME)
     180              :     return;
     181              : 
     182            0 :   val = copy_of[SSA_NAME_VERSION (var)].value;
     183            0 :   fprintf (file, " copy-of chain: ");
     184            0 :   print_generic_expr (file, var);
     185            0 :   fprintf (file, " ");
     186            0 :   if (!val)
     187            0 :     fprintf (file, "[UNDEFINED]");
     188            0 :   else if (val == var)
     189            0 :     fprintf (file, "[NOT A COPY]");
     190              :   else
     191              :     {
     192            0 :       fprintf (file, "-> ");
     193            0 :       print_generic_expr (file, val);
     194            0 :       fprintf (file, " ");
     195            0 :       fprintf (file, "[COPY]");
     196              :     }
     197              : }
     198              : 
     199              : 
     200              : /* Evaluate the RHS of STMT.  If it produces a valid copy, set the LHS
     201              :    value and store the LHS into *RESULT_P.  */
     202              : 
     203              : static enum ssa_prop_result
     204     24140173 : copy_prop_visit_assignment (gassign *stmt, tree *result_p)
     205              : {
     206     24140173 :   tree lhs = gimple_assign_lhs (stmt);
     207     24140173 :   tree rhs = gimple_fold_stmt_to_constant_1 (stmt, valueize_val);
     208     24140173 :   if (rhs
     209     24140173 :       && (TREE_CODE (rhs) == SSA_NAME
     210      5540405 :           || is_gimple_min_invariant (rhs)))
     211              :     {
     212              :       /* Straight copy between two SSA names or a constant.  Make sure that
     213              :          we can propagate the RHS into uses of LHS.  */
     214      6237983 :       if (!may_propagate_copy (lhs, rhs))
     215     17903070 :         rhs = lhs;
     216              :     }
     217              :   else
     218              :     rhs = lhs;
     219              : 
     220     24140173 :   *result_p = lhs;
     221     24140173 :   if (set_copy_of_val (*result_p, rhs))
     222              :     return SSA_PROP_INTERESTING;
     223      1254650 :   return rhs != lhs ? SSA_PROP_NOT_INTERESTING : SSA_PROP_VARYING;
     224              : }
     225              : 
     226              : 
     227              : /* Visit the GIMPLE_COND STMT.  Return SSA_PROP_INTERESTING
     228              :    if it can determine which edge will be taken.  Otherwise, return
     229              :    SSA_PROP_VARYING.  */
     230              : 
     231              : static enum ssa_prop_result
     232     13092312 : copy_prop_visit_cond_stmt (gimple *stmt, edge *taken_edge_p)
     233              : {
     234     13092312 :   enum ssa_prop_result retval = SSA_PROP_VARYING;
     235     13092312 :   location_t loc = gimple_location (stmt);
     236              : 
     237     13092312 :   tree op0 = valueize_val (gimple_cond_lhs (stmt));
     238     13092312 :   tree op1 = valueize_val (gimple_cond_rhs (stmt));
     239              : 
     240              :   /* See if we can determine the predicate's value.  */
     241     13092312 :   if (dump_file && (dump_flags & TDF_DETAILS))
     242              :     {
     243            0 :       fprintf (dump_file, "Trying to determine truth value of ");
     244            0 :       fprintf (dump_file, "predicate ");
     245            0 :       print_gimple_stmt (dump_file, stmt, 0);
     246              :     }
     247              : 
     248              :   /* Fold COND and see whether we get a useful result.  */
     249     13092312 :   tree folded_cond = fold_binary_loc (loc, gimple_cond_code (stmt),
     250              :                                       boolean_type_node, op0, op1);
     251     13092312 :   if (folded_cond)
     252              :     {
     253      2428775 :       basic_block bb = gimple_bb (stmt);
     254      2428775 :       *taken_edge_p = find_taken_edge (bb, folded_cond);
     255      2428775 :       if (*taken_edge_p)
     256     13092312 :         retval = SSA_PROP_INTERESTING;
     257              :     }
     258              : 
     259     13092312 :   if (dump_file && (dump_flags & TDF_DETAILS) && *taken_edge_p)
     260            0 :     fprintf (dump_file, "\nConditional will always take edge %d->%d\n",
     261            0 :              (*taken_edge_p)->src->index, (*taken_edge_p)->dest->index);
     262              : 
     263     13092312 :   return retval;
     264              : }
     265              : 
     266              : 
     267              : /* Evaluate statement STMT.  If the statement produces a new output
     268              :    value, return SSA_PROP_INTERESTING and store the SSA_NAME holding
     269              :    the new value in *RESULT_P.
     270              : 
     271              :    If STMT is a conditional branch and we can determine its truth
     272              :    value, set *TAKEN_EDGE_P accordingly.
     273              : 
     274              :    If the new value produced by STMT is varying, return
     275              :    SSA_PROP_VARYING.  */
     276              : 
     277              : enum ssa_prop_result
     278     43917162 : copy_prop::visit_stmt (gimple *stmt, edge *taken_edge_p, tree *result_p)
     279              : {
     280     43917162 :   enum ssa_prop_result retval;
     281              : 
     282     43917162 :   if (dump_file && (dump_flags & TDF_DETAILS))
     283              :     {
     284            0 :       fprintf (dump_file, "\nVisiting statement:\n");
     285            0 :       print_gimple_stmt (dump_file, stmt, 0, dump_flags);
     286            0 :       fprintf (dump_file, "\n");
     287              :     }
     288              : 
     289     43917162 :   gassign *assign = dyn_cast<gassign *> (stmt);
     290     24252039 :   if (assign
     291     24252039 :       && TREE_CODE (gimple_assign_lhs (assign)) == SSA_NAME)
     292              :     {
     293              :       /* If the statement is a copy assignment, evaluate its RHS to
     294              :          see if the lattice value of its output has changed.  */
     295     24140173 :       retval = copy_prop_visit_assignment (assign, result_p);
     296              :     }
     297     19776989 :   else if (gimple_code (stmt) == GIMPLE_COND)
     298              :     {
     299              :       /* See if we can determine which edge goes out of a conditional
     300              :          jump.  */
     301     13092312 :       retval = copy_prop_visit_cond_stmt (stmt, taken_edge_p);
     302              :     }
     303              :   else
     304              :     retval = SSA_PROP_VARYING;
     305              : 
     306     37232485 :   if (retval == SSA_PROP_VARYING)
     307              :     {
     308     19827815 :       tree def;
     309     19827815 :       ssa_op_iter i;
     310              : 
     311              :       /* Any other kind of statement is not interesting for constant
     312              :          propagation and, therefore, not worth simulating.  */
     313     19827815 :       if (dump_file && (dump_flags & TDF_DETAILS))
     314            0 :         fprintf (dump_file, "No interesting values produced.\n");
     315              : 
     316              :       /* The assignment is not a copy operation.  Don't visit this
     317              :          statement again and mark all the definitions in the statement
     318              :          to be copies of nothing.  */
     319     24861386 :       FOR_EACH_SSA_TREE_OPERAND (def, stmt, i, SSA_OP_ALL_DEFS)
     320      5033571 :         set_copy_of_val (def, def);
     321              :     }
     322              : 
     323     43917162 :   return retval;
     324              : }
     325              : 
     326              : 
     327              : /* Visit PHI node PHI.  If all the arguments produce the same value,
     328              :    set it to be the value of the LHS of PHI.  */
     329              : 
     330              : enum ssa_prop_result
     331     11601558 : copy_prop::visit_phi (gphi *phi)
     332              : {
     333     11601558 :   enum ssa_prop_result retval;
     334     11601558 :   unsigned i;
     335     11601558 :   prop_value_t phi_val = { NULL_TREE };
     336              : 
     337     11601558 :   tree lhs = gimple_phi_result (phi);
     338              : 
     339     11601558 :   if (dump_file && (dump_flags & TDF_DETAILS))
     340              :     {
     341            0 :       fprintf (dump_file, "\nVisiting PHI node: ");
     342            0 :       print_gimple_stmt (dump_file, phi, 0, dump_flags);
     343              :     }
     344              : 
     345     26986415 :   for (i = 0; i < gimple_phi_num_args (phi); i++)
     346              :     {
     347     22302938 :       prop_value_t *arg_val;
     348     22302938 :       tree arg_value;
     349     22302938 :       tree arg = gimple_phi_arg_def (phi, i);
     350     22302938 :       edge e = gimple_phi_arg_edge (phi, i);
     351              : 
     352              :       /* We don't care about values flowing through non-executable
     353              :          edges.  */
     354     22302938 :       if (!(e->flags & EDGE_EXECUTABLE))
     355      3745122 :         continue;
     356              : 
     357              :       /* Names that flow through abnormal edges cannot be used to
     358              :          derive copies.  */
     359     18557816 :       if (TREE_CODE (arg) == SSA_NAME && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (arg))
     360              :         {
     361              :           phi_val.value = lhs;
     362              :           break;
     363              :         }
     364              : 
     365     18551030 :       if (dump_file && (dump_flags & TDF_DETAILS))
     366              :         {
     367            0 :           fprintf (dump_file, "\tArgument #%d: ", i);
     368            0 :           dump_copy_of (dump_file, arg);
     369            0 :           fprintf (dump_file, "\n");
     370              :         }
     371              : 
     372     18551030 :       if (TREE_CODE (arg) == SSA_NAME)
     373              :         {
     374     12217283 :           arg_val = get_copy_of_val (arg);
     375              : 
     376              :           /* If we didn't visit the definition of arg yet treat it as
     377              :              UNDEFINED.  This also handles PHI arguments that are the
     378              :              same as lhs.  We'll come here again.  */
     379     12217283 :           if (!arg_val->value)
     380            0 :             continue;
     381              : 
     382              :           arg_value = arg_val->value;
     383              :         }
     384              :       else
     385      6333747 :         arg_value = valueize_val (arg);
     386              : 
     387              :       /* In loop-closed SSA form do not copy-propagate SSA-names across
     388              :          loop exit edges.  */
     389     18551030 :       if (loops_state_satisfies_p (LOOP_CLOSED_SSA)
     390      6939125 :           && TREE_CODE (arg_value) == SSA_NAME
     391     22024124 :           && loop_exit_edge_p (e->src->loop_father, e))
     392              :         {
     393              :           phi_val.value = lhs;
     394              :           break;
     395              :         }
     396              : 
     397              :       /* If the LHS didn't have a value yet, make it a copy of the
     398              :          first argument we find.   */
     399     18014523 :       if (phi_val.value == NULL_TREE)
     400              :         {
     401     11082934 :           phi_val.value = arg_value;
     402     11082934 :           continue;
     403              :         }
     404              : 
     405              :       /* If PHI_VAL and ARG don't have a common copy-of chain, then
     406              :          this PHI node cannot be a copy operation.  */
     407      6931589 :       if (phi_val.value != arg_value
     408      6931589 :           && !operand_equal_p (phi_val.value, arg_value, 0))
     409              :         {
     410              :           phi_val.value = lhs;
     411              :           break;
     412              :         }
     413              :     }
     414              : 
     415     11601558 :   if (phi_val.value
     416     11601558 :       && may_propagate_copy (lhs, phi_val.value)
     417     23194359 :       && set_copy_of_val (lhs, phi_val.value))
     418     11517500 :     retval = (phi_val.value != lhs) ? SSA_PROP_INTERESTING : SSA_PROP_VARYING;
     419              :   else
     420              :     retval = SSA_PROP_NOT_INTERESTING;
     421              : 
     422     11601558 :   if (dump_file && (dump_flags & TDF_DETAILS))
     423              :     {
     424            0 :       fprintf (dump_file, "PHI node ");
     425            0 :       dump_copy_of (dump_file, lhs);
     426            0 :       fprintf (dump_file, "\nTelling the propagator to ");
     427            0 :       if (retval == SSA_PROP_INTERESTING)
     428            0 :         fprintf (dump_file, "add SSA edges out of this PHI and continue.");
     429            0 :       else if (retval == SSA_PROP_VARYING)
     430            0 :         fprintf (dump_file, "add SSA edges out of this PHI and never visit again.");
     431              :       else
     432            0 :         fprintf (dump_file, "do nothing with SSA edges and keep iterating.");
     433            0 :       fprintf (dump_file, "\n\n");
     434              :     }
     435              : 
     436     11601558 :   return retval;
     437              : }
     438              : 
     439              : 
     440              : /* Initialize structures used for copy propagation.  */
     441              : 
     442              : static void
     443      2388083 : init_copy_prop (void)
     444              : {
     445      2388083 :   basic_block bb;
     446              : 
     447      2388083 :   n_copy_of = num_ssa_names;
     448      2388083 :   copy_of = XCNEWVEC (prop_value_t, n_copy_of);
     449              : 
     450     31051716 :   FOR_EACH_BB_FN (bb, cfun)
     451              :     {
     452    289372990 :       for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si);
     453    232045724 :            gsi_next (&si))
     454              :         {
     455    232045724 :           gimple *stmt = gsi_stmt (si);
     456    232045724 :           ssa_op_iter iter;
     457    232045724 :           tree def;
     458              : 
     459              :           /* The only statements that we care about are those that may
     460              :              generate useful copies.  We also need to mark conditional
     461              :              jumps so that their outgoing edges are added to the work
     462              :              lists of the propagator.  */
     463    232045724 :           if (stmt_ends_bb_p (stmt))
     464     18816326 :             prop_set_simulate_again (stmt, true);
     465    213229398 :           else if (stmt_may_generate_copy (stmt))
     466     18355825 :             prop_set_simulate_again (stmt, true);
     467              :           else
     468    194873573 :             prop_set_simulate_again (stmt, false);
     469              : 
     470              :           /* Mark all the outputs of this statement as not being
     471              :              the copy of anything.  */
     472    311444504 :           FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS)
     473     79398780 :             if (!prop_simulate_again_p (stmt))
     474     57069358 :               set_copy_of_val (def, def);
     475              :         }
     476              : 
     477     41838664 :       for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
     478     13175031 :            gsi_next (&si))
     479              :         {
     480     13175031 :           gphi *phi = si.phi ();
     481     13175031 :           tree def;
     482              : 
     483     13175031 :           def = gimple_phi_result (phi);
     484     26350062 :           if (virtual_operand_p (def))
     485      5527309 :             prop_set_simulate_again (phi, false);
     486              :           else
     487      7647722 :             prop_set_simulate_again (phi, true);
     488              : 
     489     13175031 :           if (!prop_simulate_again_p (phi))
     490      5527309 :             set_copy_of_val (def, def);
     491              :         }
     492              :     }
     493      2388083 : }
     494              : 
     495      9552332 : class copy_folder : public substitute_and_fold_engine
     496              : {
     497              :  public:
     498              :   tree value_of_expr (tree name, gimple *) final override;
     499              : };
     500              : 
     501              : /* Callback for substitute_and_fold to get at the final copy-of values.  */
     502              : 
     503              : tree
     504    177773470 : copy_folder::value_of_expr (tree name, gimple *)
     505              : {
     506    177773470 :   tree val;
     507    177773470 :   if (SSA_NAME_VERSION (name) >= n_copy_of)
     508              :     return NULL_TREE;
     509    177773470 :   val = copy_of[SSA_NAME_VERSION (name)].value;
     510    177773470 :   if (val && val != name)
     511      3741610 :     return val;
     512              :   return NULL_TREE;
     513              : }
     514              : 
     515              : /* Deallocate memory used in copy propagation and do final
     516              :    substitution.  */
     517              : 
     518              : static bool
     519      2388083 : fini_copy_prop (void)
     520              : {
     521      2388083 :   unsigned i;
     522      2388083 :   tree var;
     523              : 
     524              :   /* Set the final copy-of value for each variable by traversing the
     525              :      copy-of chains.  */
     526    135391151 :   FOR_EACH_SSA_NAME (i, var, cfun)
     527              :     {
     528     99826210 :       if (!copy_of[i].value
     529     93677025 :           || copy_of[i].value == var)
     530     97267797 :         continue;
     531              : 
     532              :       /* Duplicate points-to and range info appropriately.  */
     533      2558413 :       if (copy_of[i].value != var
     534      2558413 :           && TREE_CODE (copy_of[i].value) == SSA_NAME)
     535      2009721 :         maybe_duplicate_ssa_info_at_copy (var, copy_of[i].value);
     536              :     }
     537              : 
     538      2388083 :   class copy_folder copy_folder;
     539      2388083 :   bool changed = copy_folder.substitute_and_fold ();
     540      2388083 :   if (changed)
     541              :     {
     542       138364 :       free_numbers_of_iterations_estimates (cfun);
     543       138364 :       if (scev_initialized_p ())
     544         7523 :         scev_reset ();
     545              :     }
     546              : 
     547      2388083 :   free (copy_of);
     548              : 
     549      2388083 :   return changed;
     550      2388083 : }
     551              : 
     552              : 
     553              : /* Main entry point to the copy propagator.
     554              : 
     555              :    PHIS_ONLY is true if we should only consider PHI nodes as generating
     556              :    copy propagation opportunities.
     557              : 
     558              :    The algorithm propagates the value COPY-OF using ssa_propagate.  For
     559              :    every variable X_i, COPY-OF(X_i) indicates which variable is X_i created
     560              :    from.  The following example shows how the algorithm proceeds at a
     561              :    high level:
     562              : 
     563              :             1   a_24 = x_1
     564              :             2   a_2 = PHI <a_24, x_1>
     565              :             3   a_5 = PHI <a_2>
     566              :             4   x_1 = PHI <x_298, a_5, a_2>
     567              : 
     568              :    The end result should be that a_2, a_5, a_24 and x_1 are a copy of
     569              :    x_298.  Propagation proceeds as follows.
     570              : 
     571              :    Visit #1: a_24 is copy-of x_1.  Value changed.
     572              :    Visit #2: a_2 is copy-of x_1.  Value changed.
     573              :    Visit #3: a_5 is copy-of x_1.  Value changed.
     574              :    Visit #4: x_1 is copy-of x_298.  Value changed.
     575              :    Visit #1: a_24 is copy-of x_298.  Value changed.
     576              :    Visit #2: a_2 is copy-of x_298.  Value changed.
     577              :    Visit #3: a_5 is copy-of x_298.  Value changed.
     578              :    Visit #4: x_1 is copy-of x_298.  Stable state reached.
     579              : 
     580              :    When visiting PHI nodes, we only consider arguments that flow
     581              :    through edges marked executable by the propagation engine.  So,
     582              :    when visiting statement #2 for the first time, we will only look at
     583              :    the first argument (a_24) and optimistically assume that its value
     584              :    is the copy of a_24 (x_1).  */
     585              : 
     586              : static unsigned int
     587      2388083 : execute_copy_prop (void)
     588              : {
     589      2388083 :   init_copy_prop ();
     590      2388083 :   class copy_prop copy_prop;
     591      2388083 :   copy_prop.ssa_propagate ();
     592      2388083 :   if (fini_copy_prop ())
     593       138364 :     return TODO_cleanup_cfg;
     594              :   return 0;
     595      2388083 : }
     596              : 
     597              : namespace {
     598              : 
     599              : const pass_data pass_data_copy_prop =
     600              : {
     601              :   GIMPLE_PASS, /* type */
     602              :   "copyprop", /* name */
     603              :   OPTGROUP_NONE, /* optinfo_flags */
     604              :   TV_TREE_COPY_PROP, /* tv_id */
     605              :   ( PROP_ssa | PROP_cfg ), /* properties_required */
     606              :   0, /* properties_provided */
     607              :   0, /* properties_destroyed */
     608              :   0, /* todo_flags_start */
     609              :   0, /* todo_flags_finish */
     610              : };
     611              : 
     612              : class pass_copy_prop : public gimple_opt_pass
     613              : {
     614              : public:
     615      1211940 :   pass_copy_prop (gcc::context *ctxt)
     616      2423880 :     : gimple_opt_pass (pass_data_copy_prop, ctxt)
     617              :   {}
     618              : 
     619              :   /* opt_pass methods: */
     620       908955 :   opt_pass * clone () final override { return new pass_copy_prop (m_ctxt); }
     621      2388797 :   bool gate (function *) final override { return flag_tree_copy_prop != 0; }
     622      2388083 :   unsigned int execute (function *) final override
     623              :   {
     624      2388083 :     return execute_copy_prop ();
     625              :   }
     626              : 
     627              : }; // class pass_copy_prop
     628              : 
     629              : } // anon namespace
     630              : 
     631              : gimple_opt_pass *
     632       302985 : make_pass_copy_prop (gcc::context *ctxt)
     633              : {
     634       302985 :   return new pass_copy_prop (ctxt);
     635              : }
        

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