LCOV - code coverage report
Current view: top level - gcc - tree-inline.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.4 % 3297 2916
Test Date: 2026-12-05 16:10:02 Functions: 96.6 % 88 85
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Tree inlining.
       2              :    Copyright (C) 2001-2026 Free Software Foundation, Inc.
       3              :    Contributed by Alexandre Oliva <aoliva@redhat.com>
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify
       8              : it under the terms of the GNU General Public License as published by
       9              : the Free Software Foundation; either version 3, or (at your option)
      10              : any later version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful,
      13              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15              : GNU General Public License for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "backend.h"
      25              : #include "target.h"
      26              : #include "rtl.h"
      27              : #include "tree.h"
      28              : #include "gimple.h"
      29              : #include "cfghooks.h"
      30              : #include "tree-pass.h"
      31              : #include "ssa.h"
      32              : #include "cgraph.h"
      33              : #include "tree-pretty-print.h"
      34              : #include "diagnostic-core.h"
      35              : #include "gimple-predict.h"
      36              : #include "fold-const.h"
      37              : #include "stor-layout.h"
      38              : #include "calls.h"
      39              : #include "tree-inline.h"
      40              : #include "langhooks.h"
      41              : #include "cfganal.h"
      42              : #include "tree-iterator.h"
      43              : #include "intl.h"
      44              : #include "gimple-iterator.h"
      45              : #include "gimple-fold.h"
      46              : #include "tree-eh.h"
      47              : #include "gimplify.h"
      48              : #include "gimplify-me.h"
      49              : #include "gimple-walk.h"
      50              : #include "tree-cfg.h"
      51              : #include "tree-into-ssa.h"
      52              : #include "tree-dfa.h"
      53              : #include "tree-ssa.h"
      54              : #include "except.h"
      55              : #include "debug.h"
      56              : #include "value-prof.h"
      57              : #include "cfgloop.h"
      58              : #include "builtins.h"
      59              : #include "stringpool.h"
      60              : #include "attribs.h"
      61              : #include "sreal.h"
      62              : #include "tree-cfgcleanup.h"
      63              : #include "tree-ssa-live.h"
      64              : #include "alloc-pool.h"
      65              : #include "symbol-summary.h"
      66              : #include "symtab-thunks.h"
      67              : #include "symtab-clones.h"
      68              : #include "asan.h"
      69              : 
      70              : /* I'm not real happy about this, but we need to handle gimple and
      71              :    non-gimple trees.  */
      72              : 
      73              : /* Inlining, Cloning, Versioning, Parallelization
      74              : 
      75              :    Inlining: a function body is duplicated, but the PARM_DECLs are
      76              :    remapped into VAR_DECLs, and non-void RETURN_EXPRs become
      77              :    MODIFY_EXPRs that store to a dedicated returned-value variable.
      78              :    The duplicated eh_region info of the copy will later be appended
      79              :    to the info for the caller; the eh_region info in copied throwing
      80              :    statements and RESX statements are adjusted accordingly.
      81              : 
      82              :    Cloning: (only in C++) We have one body for a con/de/structor, and
      83              :    multiple function decls, each with a unique parameter list.
      84              :    Duplicate the body, using the given splay tree; some parameters
      85              :    will become constants (like 0 or 1).
      86              : 
      87              :    Versioning: a function body is duplicated and the result is a new
      88              :    function rather than into blocks of an existing function as with
      89              :    inlining.  Some parameters will become constants.
      90              : 
      91              :    Parallelization: a region of a function is duplicated resulting in
      92              :    a new function.  Variables may be replaced with complex expressions
      93              :    to enable shared variable semantics.
      94              : 
      95              :    All of these will simultaneously lookup any callgraph edges.  If
      96              :    we're going to inline the duplicated function body, and the given
      97              :    function has some cloned callgraph nodes (one for each place this
      98              :    function will be inlined) those callgraph edges will be duplicated.
      99              :    If we're cloning the body, those callgraph edges will be
     100              :    updated to point into the new body.  (Note that the original
     101              :    callgraph node and edge list will not be altered.)
     102              : 
     103              :    See the CALL_EXPR handling case in copy_tree_body_r ().  */
     104              : 
     105              : /* To Do:
     106              : 
     107              :    o In order to make inlining-on-trees work, we pessimized
     108              :      function-local static constants.  In particular, they are now
     109              :      always output, even when not addressed.  Fix this by treating
     110              :      function-local static constants just like global static
     111              :      constants; the back-end already knows not to output them if they
     112              :      are not needed.
     113              : 
     114              :    o Provide heuristics to clamp inlining of recursive template
     115              :      calls?  */
     116              : 
     117              : 
     118              : /* Weights that estimate_num_insns uses to estimate the size of the
     119              :    produced code.  */
     120              : 
     121              : eni_weights eni_size_weights;
     122              : 
     123              : /* Weights that estimate_num_insns uses to estimate the time necessary
     124              :    to execute the produced code.  */
     125              : 
     126              : eni_weights eni_time_weights;
     127              : 
     128              : /* Prototypes.  */
     129              : 
     130              : static tree declare_return_variable (copy_body_data *, tree, tree,
     131              :                                      basic_block);
     132              : static void remap_block (tree *, copy_body_data *);
     133              : static void copy_bind_expr (tree *, int *, copy_body_data *);
     134              : static void declare_inline_vars (tree, tree);
     135              : static void remap_save_expr (tree *, hash_map<tree, tree> *, int *);
     136              : static void prepend_lexical_block (tree current_block, tree new_block);
     137              : static tree copy_result_decl_to_var (tree, copy_body_data *);
     138              : static tree copy_decl_maybe_to_var (tree, copy_body_data *);
     139              : static gimple_seq remap_gimple_stmt (gimple *, copy_body_data *);
     140              : static void insert_init_stmt (copy_body_data *, basic_block, gimple *);
     141              : 
     142              : /* Insert a tree->tree mapping for ID.  Despite the name suggests
     143              :    that the trees should be variables, it is used for more than that.  */
     144              : 
     145              : void
     146    697299885 : insert_decl_map (copy_body_data *id, tree key, tree value)
     147              : {
     148    697299885 :   id->decl_map->put (key, value);
     149              : 
     150              :   /* Always insert an identity map as well.  If we see this same new
     151              :      node again, we won't want to duplicate it a second time.  */
     152    697299885 :   if (key != value && value)
     153    212976228 :     id->decl_map->put (value, value);
     154    697299885 : }
     155              : 
     156              : /* If nonzero, we're remapping the contents of inlined debug
     157              :    statements.  If negative, an error has occurred, such as a
     158              :    reference to a variable that isn't available in the inlined
     159              :    context.  */
     160              : static int processing_debug_stmt = 0;
     161              : 
     162              : /* Construct new SSA name for old NAME. ID is the inline context.  */
     163              : 
     164              : static tree
     165     71744297 : remap_ssa_name (tree name, copy_body_data *id)
     166              : {
     167     71744297 :   tree new_tree, var;
     168     71744297 :   tree *n;
     169              : 
     170     71744297 :   gcc_assert (TREE_CODE (name) == SSA_NAME);
     171              : 
     172     71744297 :   n = id->decl_map->get (name);
     173     71744297 :   if (n)
     174              :     {
     175              :       /* When we perform edge redirection as part of CFG copy, IPA-SRA can
     176              :          remove an unused LHS from a call statement.  Such LHS can however
     177              :          still appear in debug statements, but their value is lost in this
     178              :          function and we do not want to map them.  */
     179     52654038 :       if (id->killed_new_ssa_names
     180     52654038 :           && id->killed_new_ssa_names->contains (*n))
     181              :         {
     182          386 :           gcc_assert (processing_debug_stmt);
     183          386 :           processing_debug_stmt = -1;
     184          386 :           return name;
     185              :         }
     186              : 
     187     52653652 :       return unshare_expr (*n);
     188              :     }
     189              : 
     190     19090259 :   if (processing_debug_stmt)
     191              :     {
     192        98962 :       if (SSA_NAME_IS_DEFAULT_DEF (name)
     193        98919 :           && TREE_CODE (SSA_NAME_VAR (name)) == PARM_DECL
     194        98871 :           && id->entry_bb == NULL
     195       197832 :           && single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
     196              :         {
     197        98870 :           gimple *def_temp;
     198        98870 :           gimple_stmt_iterator gsi;
     199        98870 :           tree val = SSA_NAME_VAR (name);
     200              : 
     201        98870 :           n = id->decl_map->get (val);
     202        98870 :           if (n != NULL)
     203        98870 :             val = *n;
     204        98870 :           if (TREE_CODE (val) != PARM_DECL
     205        98870 :               && !(VAR_P (val) && DECL_ABSTRACT_ORIGIN (val)))
     206              :             {
     207            0 :               processing_debug_stmt = -1;
     208            0 :               return name;
     209              :             }
     210        98870 :           n = id->decl_map->get (val);
     211        98870 :           if (n && TREE_CODE (*n) == DEBUG_EXPR_DECL)
     212              :             return *n;
     213        34522 :           tree vexpr = build_debug_expr_decl (TREE_TYPE (name));
     214              :           /* FIXME: Is setting the mode really necessary? */
     215        34522 :           SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (name)));
     216        34522 :           def_temp = gimple_build_debug_source_bind (vexpr, val, NULL);
     217        34522 :           gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
     218        34522 :           gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT);
     219        34522 :           insert_decl_map (id, val, vexpr);
     220        34522 :           return vexpr;
     221              :         }
     222              : 
     223           92 :       processing_debug_stmt = -1;
     224           92 :       return name;
     225              :     }
     226              : 
     227              :   /* Remap anonymous SSA names or SSA names of anonymous decls.  */
     228     18991297 :   var = SSA_NAME_VAR (name);
     229      3770978 :   if (!var
     230      3770978 :       || (!SSA_NAME_IS_DEFAULT_DEF (name)
     231      3365393 :           && VAR_P (var)
     232      3155921 :           && !VAR_DECL_IS_VIRTUAL_OPERAND (var)
     233      3155921 :           && DECL_ARTIFICIAL (var)
     234       581068 :           && DECL_IGNORED_P (var)
     235       161759 :           && !DECL_NAME (var)))
     236              :     {
     237     15225763 :       const pt_solution *pt;
     238     15225763 :       new_tree = make_ssa_name (remap_type (TREE_TYPE (name), id));
     239     15225763 :       if (!var && SSA_NAME_IDENTIFIER (name))
     240      1995362 :         SET_SSA_NAME_VAR_OR_IDENTIFIER (new_tree, SSA_NAME_IDENTIFIER (name));
     241     15225763 :       insert_decl_map (id, name, new_tree);
     242     30451526 :       SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
     243     15225763 :         = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
     244              :       /* Range info can be transferred, if local addresses are removed.  */
     245     15225763 :       if (SSA_NAME_RANGE_INFO (name))
     246      8740765 :         duplicate_ssa_name_range_info (new_tree, name, true);
     247              :       /* At least IPA points-to info can be directly transferred.  */
     248     15225763 :       if (id->src_cfun->gimple_df
     249     15225763 :           && id->src_cfun->gimple_df->ipa_pta
     250        15379 :           && POINTER_TYPE_P (TREE_TYPE (name))
     251         4849 :           && (pt = ssa_name_pt_solution (name))
     252     15228185 :           && !pt->anything)
     253         2401 :         set_ssa_name_pt_solution (new_tree, *pt);
     254              :       return new_tree;
     255              :     }
     256              : 
     257              :   /* Do not set DEF_STMT yet as statement is not copied yet. We do that
     258              :      in copy_bb.  */
     259      3765534 :   new_tree = remap_decl (var, id);
     260              : 
     261              :   /* We might've substituted constant or another SSA_NAME for
     262              :      the variable.
     263              : 
     264              :      Replace the SSA name representing RESULT_DECL by variable during
     265              :      inlining:  this saves us from need to introduce PHI node in a case
     266              :      return value is just partly initialized.  */
     267       389024 :   if ((VAR_P (new_tree) || TREE_CODE (new_tree) == PARM_DECL)
     268      4154558 :       && (!SSA_NAME_VAR (name)
     269      3765534 :           || TREE_CODE (SSA_NAME_VAR (name)) != RESULT_DECL
     270            0 :           || !id->transform_return_to_modify))
     271              :     {
     272      3765534 :       const pt_solution *pt;
     273      3765534 :       new_tree = make_ssa_name (new_tree);
     274      3765534 :       insert_decl_map (id, name, new_tree);
     275      7531068 :       SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_tree)
     276      3765534 :         = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name);
     277              : 
     278      3765534 :       tree zero = NULL_TREE;
     279      3765534 :       if (SSA_NAME_IS_DEFAULT_DEF (name))
     280              :         {
     281              :           /* By inlining function having uninitialized variable, we might
     282              :              extend the lifetime (variable might get reused).  This cause
     283              :              ICE in the case we end up extending lifetime of SSA name across
     284              :              abnormal edge, but also increase register pressure.
     285              : 
     286              :              We simply initialize all uninitialized vars by 0 except
     287              :              for case we are inlining to very first BB.  We can avoid
     288              :              this for all BBs that are not inside strongly connected
     289              :              regions of the CFG, but this is expensive to test.  */
     290       405585 :           if (id->entry_bb
     291        45119 :               && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name)
     292            0 :               && (!SSA_NAME_VAR (name)
     293            0 :                   || TREE_CODE (SSA_NAME_VAR (name)) != PARM_DECL)
     294       405585 :               && (id->entry_bb != EDGE_SUCC (ENTRY_BLOCK_PTR_FOR_FN (cfun),
     295            0 :                                              0)->dest
     296            0 :                   || EDGE_COUNT (id->entry_bb->preds) != 1))
     297              :             {
     298            0 :               gimple_stmt_iterator gsi = gsi_last_bb (id->entry_bb);
     299            0 :               gimple *init_stmt;
     300            0 :               zero = build_zero_cst (TREE_TYPE (new_tree));
     301              : 
     302            0 :               init_stmt = gimple_build_assign (new_tree, zero);
     303            0 :               gsi_insert_after (&gsi, init_stmt, GSI_NEW_STMT);
     304            0 :               SSA_NAME_IS_DEFAULT_DEF (new_tree) = 0;
     305              :             }
     306              :           else
     307              :             {
     308       405585 :               SSA_NAME_DEF_STMT (new_tree) = gimple_build_nop ();
     309       405585 :               set_ssa_default_def (cfun, SSA_NAME_VAR (new_tree), new_tree);
     310              :             }
     311              :         }
     312              :       /* Range info can be transferred if local addresses are removed
     313              :          and no uninitialized name was processed and set to zero.  */
     314      3765534 :       if (!zero && SSA_NAME_RANGE_INFO (name))
     315      1930178 :         duplicate_ssa_name_range_info (new_tree, name, true);
     316              :       /* At least IPA points-to info can be directly transferred.  */
     317      3765534 :       if (id->src_cfun->gimple_df
     318      3765534 :           && id->src_cfun->gimple_df->ipa_pta
     319         2700 :           && POINTER_TYPE_P (TREE_TYPE (name))
     320          612 :           && (pt = ssa_name_pt_solution (name))
     321      3765837 :           && !pt->anything)
     322          303 :         set_ssa_name_pt_solution (new_tree, *pt);
     323              :     }
     324              :   else
     325            0 :     insert_decl_map (id, name, new_tree);
     326              :   return new_tree;
     327              : }
     328              : 
     329              : /* Remap DECL during the copying of the BLOCK tree for the function.  */
     330              : 
     331              : tree
     332    355011707 : remap_decl (tree decl, copy_body_data *id)
     333              : {
     334    355011707 :   tree *n;
     335              : 
     336              :   /* We only remap local variables in the current function.  */
     337              : 
     338              :   /* See if we have remapped this declaration.  */
     339              : 
     340    355011707 :   n = id->decl_map->get (decl);
     341              : 
     342    355011707 :   if (!n && processing_debug_stmt)
     343              :     {
     344       676134 :       processing_debug_stmt = -1;
     345       676134 :       return decl;
     346              :     }
     347              : 
     348              :   /* When remapping a type within copy_gimple_seq_and_replace_locals, all
     349              :      necessary DECLs have already been remapped and we do not want to duplicate
     350              :      a decl coming from outside of the sequence we are copying.  */
     351    130813583 :   if (!n
     352    130813583 :       && id->prevent_decl_creation_for_types
     353            0 :       && id->remapping_type_depth > 0
     354            0 :       && (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL))
     355              :     return decl;
     356              : 
     357              :   /* If we didn't already have an equivalent for this declaration, create one
     358              :      now.  */
     359    354335573 :   if (!n)
     360              :     {
     361              :       /* Make a copy of the variable or label.  */
     362    130813583 :       tree t = id->copy_decl (decl, id);
     363              : 
     364              :       /* Remember it, so that if we encounter this local entity again
     365              :          we can reuse this copy.  Do this early because remap_type may
     366              :          need this decl for TYPE_STUB_DECL.  */
     367    130813583 :       insert_decl_map (id, decl, t);
     368              : 
     369    130813583 :       if (!DECL_P (t) || t == decl)
     370              :         return t;
     371              : 
     372              :       /* Remap types, if necessary.  */
     373    128443895 :       TREE_TYPE (t) = remap_type (TREE_TYPE (t), id);
     374    128443895 :       if (TREE_CODE (t) == TYPE_DECL)
     375              :         {
     376      1605411 :           DECL_ORIGINAL_TYPE (t) = remap_type (DECL_ORIGINAL_TYPE (t), id);
     377              : 
     378              :           /* Preserve the invariant that DECL_ORIGINAL_TYPE != TREE_TYPE,
     379              :              which is enforced in gen_typedef_die when DECL_ABSTRACT_ORIGIN
     380              :              is not set on the TYPE_DECL, for example in LTO mode.  */
     381      1605411 :           if (DECL_ORIGINAL_TYPE (t) == TREE_TYPE (t))
     382              :             {
     383           10 :               tree x = build_variant_type_copy (TREE_TYPE (t));
     384           10 :               TYPE_STUB_DECL (x) = TYPE_STUB_DECL (TREE_TYPE (t));
     385           10 :               TYPE_NAME (x) = TYPE_NAME (TREE_TYPE (t));
     386           10 :               DECL_ORIGINAL_TYPE (t) = x;
     387              :             }
     388              :         }
     389              : 
     390              :       /* Remap sizes as necessary.  */
     391    128443895 :       walk_tree (&DECL_SIZE (t), copy_tree_body_r, id, NULL);
     392    128443895 :       walk_tree (&DECL_SIZE_UNIT (t), copy_tree_body_r, id, NULL);
     393              : 
     394              :       /* If fields, do likewise for offset and qualifier.  */
     395    128443895 :       if (TREE_CODE (t) == FIELD_DECL)
     396              :         {
     397          773 :           walk_tree (&DECL_FIELD_OFFSET (t), copy_tree_body_r, id, NULL);
     398          773 :           if (TREE_CODE (DECL_CONTEXT (t)) == QUAL_UNION_TYPE)
     399            0 :             walk_tree (&DECL_QUALIFIER (t), copy_tree_body_r, id, NULL);
     400              :         }
     401              : 
     402              :       return t;
     403              :     }
     404              : 
     405    223521990 :   if (id->do_not_unshare)
     406    141489473 :     return *n;
     407              :   else
     408     82032517 :     return unshare_expr (*n);
     409              : }
     410              : 
     411              : static tree
     412       109086 : remap_type_1 (tree type, copy_body_data *id)
     413              : {
     414       109086 :   tree new_tree, t;
     415              : 
     416              :   /* We do need a copy.  build and register it now.  If this is a pointer or
     417              :      reference type, remap the designated type and make a new pointer or
     418              :      reference type.  */
     419       109086 :   if (TREE_CODE (type) == POINTER_TYPE)
     420              :     {
     421        29245 :       new_tree = build_pointer_type_for_mode (remap_type (TREE_TYPE (type), id),
     422        29245 :                                          TYPE_MODE (type),
     423        29245 :                                          TYPE_REF_CAN_ALIAS_ALL (type));
     424        29245 :       if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
     425        15987 :         new_tree = build_type_attribute_qual_variant (new_tree,
     426        15987 :                                                       TYPE_ATTRIBUTES (type),
     427        15987 :                                                       TYPE_QUALS (type));
     428        29245 :       insert_decl_map (id, type, new_tree);
     429        29245 :       return new_tree;
     430              :     }
     431        79841 :   else if (TREE_CODE (type) == REFERENCE_TYPE)
     432              :     {
     433         8774 :       new_tree = build_reference_type_for_mode (remap_type (TREE_TYPE (type), id),
     434         8774 :                                             TYPE_MODE (type),
     435         8774 :                                             TYPE_REF_CAN_ALIAS_ALL (type));
     436         8774 :       if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type))
     437         5991 :         new_tree = build_type_attribute_qual_variant (new_tree,
     438         5991 :                                                       TYPE_ATTRIBUTES (type),
     439         5991 :                                                       TYPE_QUALS (type));
     440         8774 :       insert_decl_map (id, type, new_tree);
     441         8774 :       return new_tree;
     442              :     }
     443              :   else
     444        71067 :     new_tree = copy_node (type);
     445              : 
     446        71067 :   insert_decl_map (id, type, new_tree);
     447              : 
     448              :   /* This is a new type, not a copy of an old type.  Need to reassociate
     449              :      variants.  We can handle everything except the main variant lazily.  */
     450        71067 :   t = TYPE_MAIN_VARIANT (type);
     451        71067 :   if (type != t)
     452              :     {
     453           79 :       t = remap_type (t, id);
     454           79 :       TYPE_MAIN_VARIANT (new_tree) = t;
     455           79 :       TYPE_NEXT_VARIANT (new_tree) = TYPE_NEXT_VARIANT (t);
     456           79 :       TYPE_NEXT_VARIANT (t) = new_tree;
     457              :     }
     458              :   else
     459              :     {
     460        70988 :       TYPE_MAIN_VARIANT (new_tree) = new_tree;
     461        70988 :       TYPE_NEXT_VARIANT (new_tree) = NULL;
     462              :     }
     463              : 
     464        71067 :   if (TYPE_STUB_DECL (type))
     465          182 :     TYPE_STUB_DECL (new_tree) = remap_decl (TYPE_STUB_DECL (type), id);
     466              : 
     467              :   /* Lazily create pointer and reference types.  */
     468        71067 :   TYPE_POINTER_TO (new_tree) = NULL;
     469        71067 :   TYPE_REFERENCE_TO (new_tree) = NULL;
     470              : 
     471              :   /* Copy all types that may contain references to local variables; be sure to
     472              :      preserve sharing in between type and its main variant when possible.  */
     473        71067 :   switch (TREE_CODE (new_tree))
     474              :     {
     475        34169 :     case INTEGER_TYPE:
     476        34169 :     case REAL_TYPE:
     477        34169 :     case FIXED_POINT_TYPE:
     478        34169 :     case ENUMERAL_TYPE:
     479        34169 :     case BOOLEAN_TYPE:
     480        34169 :       if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
     481              :         {
     482            0 :           gcc_checking_assert (TYPE_MIN_VALUE (type) == TYPE_MIN_VALUE (TYPE_MAIN_VARIANT (type)));
     483            0 :           gcc_checking_assert (TYPE_MAX_VALUE (type) == TYPE_MAX_VALUE (TYPE_MAIN_VARIANT (type)));
     484              : 
     485            0 :           TYPE_MIN_VALUE (new_tree) = TYPE_MIN_VALUE (TYPE_MAIN_VARIANT (new_tree));
     486            0 :           TYPE_MAX_VALUE (new_tree) = TYPE_MAX_VALUE (TYPE_MAIN_VARIANT (new_tree));
     487              :         }
     488              :       else
     489              :         {
     490        34169 :           t = TYPE_MIN_VALUE (new_tree);
     491        34169 :           if (t && TREE_CODE (t) != INTEGER_CST)
     492            0 :             walk_tree (&TYPE_MIN_VALUE (new_tree), copy_tree_body_r, id, NULL);
     493              : 
     494        34169 :           t = TYPE_MAX_VALUE (new_tree);
     495        34169 :           if (t && TREE_CODE (t) != INTEGER_CST)
     496        34169 :             walk_tree (&TYPE_MAX_VALUE (new_tree), copy_tree_body_r, id, NULL);
     497              :         }
     498              :       return new_tree;
     499              : 
     500           16 :     case FUNCTION_TYPE:
     501           16 :       if (TYPE_MAIN_VARIANT (new_tree) != new_tree
     502           16 :           && TREE_TYPE (type) == TREE_TYPE (TYPE_MAIN_VARIANT (type)))
     503            0 :         TREE_TYPE (new_tree) = TREE_TYPE (TYPE_MAIN_VARIANT (new_tree));
     504              :       else
     505           16 :         TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id);
     506           16 :       if (TYPE_MAIN_VARIANT (new_tree) != new_tree
     507           16 :           && TYPE_ARG_TYPES (type) == TYPE_ARG_TYPES (TYPE_MAIN_VARIANT (type)))
     508            0 :         TYPE_ARG_TYPES (new_tree) = TYPE_ARG_TYPES (TYPE_MAIN_VARIANT (new_tree));
     509              :       else
     510           16 :         walk_tree (&TYPE_ARG_TYPES (new_tree), copy_tree_body_r, id, NULL);
     511              :       return new_tree;
     512              : 
     513        36651 :     case ARRAY_TYPE:
     514        36651 :       if (TYPE_MAIN_VARIANT (new_tree) != new_tree
     515        36651 :           && TREE_TYPE (type) == TREE_TYPE (TYPE_MAIN_VARIANT (type)))
     516           29 :         TREE_TYPE (new_tree) = TREE_TYPE (TYPE_MAIN_VARIANT (new_tree));
     517              :       else
     518        36622 :         TREE_TYPE (new_tree) = remap_type (TREE_TYPE (new_tree), id);
     519              : 
     520        36651 :       if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
     521              :         {
     522           62 :           gcc_checking_assert (TYPE_DOMAIN (type)
     523              :                                == TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)));
     524           62 :           TYPE_DOMAIN (new_tree) = TYPE_DOMAIN (TYPE_MAIN_VARIANT (new_tree));
     525              :         }
     526              :       else
     527              :         {
     528        36589 :           TYPE_DOMAIN (new_tree) = remap_type (TYPE_DOMAIN (new_tree), id);
     529              :           /* For array bounds where we have decided not to copy over the bounds
     530              :              variable which isn't used in OpenMP/OpenACC region, change them to
     531              :              an uninitialized VAR_DECL temporary.  */
     532        36589 :           if (id->adjust_array_error_bounds
     533         3752 :               && TYPE_DOMAIN (new_tree)
     534         3752 :               && TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node
     535        39486 :               && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
     536              :             {
     537         2897 :               tree v = create_tmp_var (TREE_TYPE (TYPE_DOMAIN (new_tree)));
     538         2897 :               DECL_ATTRIBUTES (v)
     539         2897 :                 = tree_cons (get_identifier ("omp dummy var"), NULL_TREE,
     540         2897 :                              DECL_ATTRIBUTES (v));
     541         2897 :               TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) = v;
     542              :             }
     543              :         }
     544              :       break;
     545              : 
     546          231 :     case RECORD_TYPE:
     547          231 :     case UNION_TYPE:
     548          231 :     case QUAL_UNION_TYPE:
     549          231 :       if (TYPE_MAIN_VARIANT (type) != type
     550          231 :           && TYPE_FIELDS (type) == TYPE_FIELDS (TYPE_MAIN_VARIANT (type)))
     551           17 :         TYPE_FIELDS (new_tree) = TYPE_FIELDS (TYPE_MAIN_VARIANT (new_tree));
     552              :       else
     553              :         {
     554          214 :           tree f, nf = NULL;
     555              : 
     556          987 :           for (f = TYPE_FIELDS (new_tree); f ; f = DECL_CHAIN (f))
     557              :             {
     558          773 :               t = remap_decl (f, id);
     559          773 :               DECL_CONTEXT (t) = new_tree;
     560          773 :               DECL_CHAIN (t) = nf;
     561          773 :               nf = t;
     562              :             }
     563          214 :           TYPE_FIELDS (new_tree) = nreverse (nf);
     564              :         }
     565              :       break;
     566              : 
     567            0 :     case OFFSET_TYPE:
     568            0 :     default:
     569              :       /* Shouldn't have been thought variable sized.  */
     570            0 :       gcc_unreachable ();
     571              :     }
     572              : 
     573              :   /* All variants of type share the same size, so use the already remapped data.  */
     574        36882 :   if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
     575              :     {
     576           79 :       tree s = TYPE_SIZE (type);
     577           79 :       tree mvs = TYPE_SIZE (TYPE_MAIN_VARIANT (type));
     578           79 :       tree su = TYPE_SIZE_UNIT (type);
     579           79 :       tree mvsu = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type));
     580           79 :       gcc_checking_assert ((TREE_CODE (s) == PLACEHOLDER_EXPR
     581              :                             && (TREE_CODE (mvs) == PLACEHOLDER_EXPR))
     582              :                            || s == mvs);
     583           79 :       gcc_checking_assert ((TREE_CODE (su) == PLACEHOLDER_EXPR
     584              :                             && (TREE_CODE (mvsu) == PLACEHOLDER_EXPR))
     585              :                            || su == mvsu);
     586           79 :       TYPE_SIZE (new_tree) = TYPE_SIZE (TYPE_MAIN_VARIANT (new_tree));
     587           79 :       TYPE_SIZE_UNIT (new_tree) = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (new_tree));
     588              :     }
     589              :   else
     590              :     {
     591        36803 :       walk_tree (&TYPE_SIZE (new_tree), copy_tree_body_r, id, NULL);
     592        36803 :       walk_tree (&TYPE_SIZE_UNIT (new_tree), copy_tree_body_r, id, NULL);
     593              :     }
     594              : 
     595              :   return new_tree;
     596              : }
     597              : 
     598              : /* Helper function for remap_type_2, called through walk_tree.  */
     599              : 
     600              : static tree
     601        31461 : remap_type_3 (tree *tp, int *walk_subtrees, void *data)
     602              : {
     603        31461 :   copy_body_data *id = (copy_body_data *) data;
     604              : 
     605        31461 :   if (TYPE_P (*tp))
     606            0 :     *walk_subtrees = 0;
     607              : 
     608        31461 :   else if (DECL_P (*tp) && remap_decl (*tp, id) != *tp)
     609            9 :     return *tp;
     610              : 
     611              :   return NULL_TREE;
     612              : }
     613              : 
     614              : /* Return true if TYPE needs to be remapped because remap_decl on any
     615              :    needed embedded decl returns something other than that decl.  */
     616              : 
     617              : static bool
     618        52177 : remap_type_2 (tree type, copy_body_data *id)
     619              : {
     620        62947 :   tree t;
     621              : 
     622              : #define RETURN_TRUE_IF_VAR(T) \
     623              :   do                                                            \
     624              :     {                                                           \
     625              :       tree _t = (T);                                            \
     626              :       if (_t)                                                   \
     627              :         {                                                       \
     628              :           if (DECL_P (_t) && remap_decl (_t, id) != _t)         \
     629              :             return true;                                        \
     630              :           if (!TYPE_SIZES_GIMPLIFIED (type)                     \
     631              :               && walk_tree (&_t, remap_type_3, id, NULL))   \
     632              :             return true;                                        \
     633              :         }                                                       \
     634              :     }                                                           \
     635              :   while (0)
     636              : 
     637        62947 :   switch (TREE_CODE (type))
     638              :     {
     639        10770 :     case POINTER_TYPE:
     640        10770 :     case REFERENCE_TYPE:
     641        10770 :     case FUNCTION_TYPE:
     642        10770 :     case METHOD_TYPE:
     643        10770 :       return remap_type_2 (TREE_TYPE (type), id);
     644              : 
     645        35065 :     case INTEGER_TYPE:
     646        35065 :     case REAL_TYPE:
     647        35065 :     case FIXED_POINT_TYPE:
     648        35065 :     case ENUMERAL_TYPE:
     649        35065 :     case BOOLEAN_TYPE:
     650        35065 :       RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
     651        35065 :       RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
     652        23174 :       return false;
     653              : 
     654        16628 :     case ARRAY_TYPE:
     655        16628 :       if (remap_type_2 (TREE_TYPE (type), id)
     656        32602 :           || (TYPE_DOMAIN (type) && remap_type_2 (TYPE_DOMAIN (type), id)))
     657              :         return true;
     658              :       break;
     659              : 
     660          357 :     case RECORD_TYPE:
     661          357 :     case UNION_TYPE:
     662          357 :     case QUAL_UNION_TYPE:
     663         3561 :       for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
     664         3204 :         if (TREE_CODE (t) == FIELD_DECL)
     665              :           {
     666         1242 :             RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
     667         1242 :             RETURN_TRUE_IF_VAR (DECL_SIZE (t));
     668         1242 :             RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
     669         1242 :             if (TREE_CODE (type) == QUAL_UNION_TYPE)
     670            0 :               RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
     671              :           }
     672              :       break;
     673              : 
     674              :     default:
     675              :       return false;
     676              :     }
     677              : 
     678         7875 :   RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
     679         7866 :   RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
     680         7121 :   return false;
     681              : #undef RETURN_TRUE_IF_VAR
     682              : }
     683              : 
     684              : tree
     685   1413495404 : remap_type (tree type, copy_body_data *id)
     686              : {
     687   1413495404 :   tree *node;
     688   1413495404 :   tree tmp;
     689              : 
     690   1413495404 :   if (type == NULL)
     691              :     return type;
     692              : 
     693              :   /* See if we have remapped this type.  */
     694   1413142427 :   node = id->decl_map->get (type);
     695   1413142427 :   if (node)
     696    931631251 :     return *node;
     697              : 
     698              :   /* The type only needs remapping if it's variably modified.  */
     699    481511176 :   if (! variably_modified_type_p (type, id->src_fn)
     700              :       /* Don't remap if copy_decl method doesn't always return a new
     701              :          decl and for all embedded decls returns the passed in decl.  */
     702    481511176 :       || (id->dont_remap_vla_if_no_change && !remap_type_2 (type, id)))
     703              :     {
     704    481402153 :       insert_decl_map (id, type, type);
     705    481402153 :       return type;
     706              :     }
     707              : 
     708       109023 :   id->remapping_type_depth++;
     709       109023 :   tmp = remap_type_1 (type, id);
     710       109023 :   id->remapping_type_depth--;
     711              : 
     712       109023 :   return tmp;
     713              : }
     714              : 
     715              : /* Decide if DECL can be put into BLOCK_NONLOCAL_VARs.  */
     716              : 
     717              : static bool
     718     50789679 : can_be_nonlocal (tree decl, copy_body_data *id)
     719              : {
     720              :   /* We cannot duplicate function decls.  */
     721     50789679 :   if (TREE_CODE (decl) == FUNCTION_DECL)
     722              :     return true;
     723              : 
     724              :   /* Local static vars must be non-local or we get multiple declaration
     725              :      problems.  */
     726     50769746 :   if (VAR_P (decl) && !auto_var_in_fn_p (decl, id->src_fn))
     727       235297 :     return true;
     728              : 
     729              :   return false;
     730              : }
     731              : 
     732              : static tree
     733     52489296 : remap_decls (tree decls, vec<tree, va_gc> **nonlocalized_list,
     734              :              copy_body_data *id)
     735              : {
     736     52489296 :   tree old_var;
     737     52489296 :   tree new_decls = NULL_TREE;
     738              : 
     739              :   /* Remap its variables.  */
     740     98797704 :   for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
     741              :     {
     742     46308408 :       tree new_var;
     743              : 
     744     46308408 :       if (can_be_nonlocal (old_var, id))
     745              :         {
     746              :           /* We need to add this variable to the local decls as otherwise
     747              :              nothing else will do so.  */
     748       165265 :           if (VAR_P (old_var) && ! DECL_EXTERNAL (old_var) && cfun)
     749       145056 :             add_local_decl (cfun, old_var);
     750       101872 :           if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE)
     751       136334 :               && !DECL_IGNORED_P (old_var)
     752       301336 :               && nonlocalized_list)
     753        84914 :             vec_safe_push (*nonlocalized_list, old_var);
     754       165265 :           continue;
     755              :         }
     756              : 
     757              :       /* Remap the variable.  */
     758     46143143 :       new_var = remap_decl (old_var, id);
     759              : 
     760              :       /* If we didn't remap this variable, we can't mess with its
     761              :          TREE_CHAIN.  If we remapped this variable to the return slot, it's
     762              :          already declared somewhere else, so don't declare it here.  */
     763              : 
     764     46143143 :       if (new_var == old_var || new_var == id->retvar)
     765              :         ;
     766     41862489 :       else if (!new_var)
     767              :         {
     768            0 :           if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE)
     769            0 :               && !DECL_IGNORED_P (old_var)
     770            0 :               && nonlocalized_list)
     771            0 :             vec_safe_push (*nonlocalized_list, old_var);
     772              :         }
     773              :       else
     774              :         {
     775     41862489 :           gcc_assert (DECL_P (new_var));
     776     41862489 :           DECL_CHAIN (new_var) = new_decls;
     777     41862489 :           new_decls = new_var;
     778              : 
     779              :           /* Also copy value-expressions.  */
     780     41862489 :           if (VAR_P (new_var) && DECL_HAS_VALUE_EXPR_P (new_var))
     781              :             {
     782      1626018 :               tree tem = DECL_VALUE_EXPR (new_var);
     783      1626018 :               bool old_regimplify = id->regimplify;
     784      1626018 :               id->remapping_type_depth++;
     785      1626018 :               walk_tree (&tem, copy_tree_body_r, id, NULL);
     786      1626018 :               id->remapping_type_depth--;
     787      1626018 :               id->regimplify = old_regimplify;
     788      1626018 :               SET_DECL_VALUE_EXPR (new_var, tem);
     789              :             }
     790              :         }
     791              :     }
     792              : 
     793     52489296 :   return nreverse (new_decls);
     794              : }
     795              : 
     796              : /* Copy the BLOCK to contain remapped versions of the variables
     797              :    therein.  And hook the new block into the block-tree.  */
     798              : 
     799              : static void
     800     47152316 : remap_block (tree *block, copy_body_data *id)
     801              : {
     802     47152316 :   tree old_block;
     803     47152316 :   tree new_block;
     804              : 
     805              :   /* Make the new block.  */
     806     47152316 :   old_block = *block;
     807     47152316 :   new_block = make_node (BLOCK);
     808     47152316 :   TREE_USED (new_block) = TREE_USED (old_block);
     809     47152316 :   BLOCK_ABSTRACT_ORIGIN (new_block) = BLOCK_ORIGIN (old_block);
     810     47152316 :   copy_debug_abstract_origin (new_block, old_block);
     811     47152316 :   BLOCK_SOURCE_LOCATION (new_block) = BLOCK_SOURCE_LOCATION (old_block);
     812     47152316 :   BLOCK_NONLOCALIZED_VARS (new_block)
     813     47234494 :     = vec_safe_copy (BLOCK_NONLOCALIZED_VARS (old_block));
     814     47152316 :   *block = new_block;
     815              : 
     816              :   /* Remap its variables.  */
     817     94304632 :   BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block),
     818     47152316 :                                         &BLOCK_NONLOCALIZED_VARS (new_block),
     819              :                                         id);
     820              : 
     821              :   /* Remember the remapped block.  */
     822     47152316 :   insert_decl_map (id, old_block, new_block);
     823     47152316 : }
     824              : 
     825              : /* Copy the whole block tree and root it in id->block.  */
     826              : 
     827              : static tree
     828     26589316 : remap_blocks (tree block, copy_body_data *id)
     829              : {
     830     26589316 :   tree t;
     831     26589316 :   tree new_tree = block;
     832              : 
     833     26589316 :   if (!block)
     834              :     return NULL;
     835              : 
     836     26589316 :   remap_block (&new_tree, id);
     837     26589316 :   gcc_assert (new_tree != block);
     838     48316217 :   for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
     839     21726901 :     prepend_lexical_block (new_tree, remap_blocks (t, id));
     840              :   /* Blocks are in arbitrary order, but make things slightly prettier and do
     841              :      not swap order when producing a copy.  */
     842     26589316 :   BLOCK_SUBBLOCKS (new_tree) = blocks_nreverse (BLOCK_SUBBLOCKS (new_tree));
     843     26589316 :   return new_tree;
     844              : }
     845              : 
     846              : /* Remap the block tree rooted at BLOCK to nothing.  */
     847              : 
     848              : static void
     849        75117 : remap_blocks_to_null (tree block, copy_body_data *id)
     850              : {
     851        75117 :   tree t;
     852        75117 :   insert_decl_map (id, block, NULL_TREE);
     853       123278 :   for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
     854        48161 :     remap_blocks_to_null (t, id);
     855        75117 : }
     856              : 
     857              : /* Remap the location info pointed to by LOCUS.  */
     858              : 
     859              : static location_t
     860     26684396 : remap_location (location_t locus, copy_body_data *id)
     861              : {
     862     26684396 :   if (LOCATION_BLOCK (locus))
     863              :     {
     864     10789016 :       tree *n = id->decl_map->get (LOCATION_BLOCK (locus));
     865     10789016 :       gcc_assert (n);
     866     10789016 :       if (*n)
     867     10755988 :         return set_block (locus, *n);
     868              :     }
     869              : 
     870     15928408 :   locus = LOCATION_LOCUS (locus);
     871              : 
     872     15928408 :   if (locus != UNKNOWN_LOCATION && id->block)
     873           15 :     return set_block (locus, id->block);
     874              : 
     875              :   return locus;
     876              : }
     877              : 
     878              : static void
     879     37736376 : copy_statement_list (tree *tp)
     880              : {
     881     37736376 :   tree_stmt_iterator oi, ni;
     882     37736376 :   tree new_tree;
     883              : 
     884     37736376 :   new_tree = alloc_stmt_list ();
     885     37736376 :   ni = tsi_start (new_tree);
     886     37736376 :   oi = tsi_start (*tp);
     887     37736376 :   TREE_TYPE (new_tree) = TREE_TYPE (*tp);
     888     37736376 :   *tp = new_tree;
     889              : 
     890    123966612 :   for (; !tsi_end_p (oi); tsi_next (&oi))
     891              :     {
     892     86230236 :       tree stmt = tsi_stmt (oi);
     893     86230236 :       if (TREE_CODE (stmt) == STATEMENT_LIST)
     894              :         /* This copy is not redundant; tsi_link_after will smash this
     895              :            STATEMENT_LIST into the end of the one we're building, and we
     896              :            don't want to do that with the original.  */
     897        77627 :         copy_statement_list (&stmt);
     898     86230236 :       tsi_link_after (&ni, stmt, TSI_CONTINUE_LINKING);
     899              :     }
     900     37736376 : }
     901              : 
     902              : static void
     903     20563281 : copy_bind_expr (tree *tp, int *walk_subtrees, copy_body_data *id)
     904              : {
     905     20563281 :   tree block = BIND_EXPR_BLOCK (*tp);
     906              :   /* Copy (and replace) the statement.  */
     907     20563281 :   copy_tree_r (tp, walk_subtrees, NULL);
     908     20563281 :   if (block)
     909              :     {
     910     20562703 :       remap_block (&block, id);
     911     20562703 :       BIND_EXPR_BLOCK (*tp) = block;
     912              :     }
     913              : 
     914     20563281 :   if (BIND_EXPR_VARS (*tp))
     915              :     /* This will remap a lot of the same decls again, but this should be
     916              :        harmless.  */
     917      5336812 :     BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), NULL, id);
     918     20563281 : }
     919              : 
     920              : 
     921              : /* Create a new gimple_seq by remapping all the statements in BODY
     922              :    using the inlining information in ID.  */
     923              : 
     924              : static gimple_seq
     925           67 : remap_gimple_seq (gimple_seq body, copy_body_data *id)
     926              : {
     927           67 :   gimple_stmt_iterator si;
     928           67 :   gimple_seq new_body = NULL;
     929              : 
     930           67 :   for (si = gsi_start (body); !gsi_end_p (si); gsi_next (&si))
     931              :     {
     932            0 :       gimple_seq new_stmts = remap_gimple_stmt (gsi_stmt (si), id);
     933            0 :       gimple_seq_add_seq (&new_body, new_stmts);
     934              :     }
     935              : 
     936           67 :   return new_body;
     937              : }
     938              : 
     939              : 
     940              : /* Copy a GIMPLE_BIND statement STMT, remapping all the symbols in its
     941              :    block using the mapping information in ID.  */
     942              : 
     943              : static gimple *
     944            0 : copy_gimple_bind (gbind *stmt, copy_body_data *id)
     945              : {
     946            0 :   gimple *new_bind;
     947            0 :   tree new_block, new_vars;
     948            0 :   gimple_seq body, new_body;
     949              : 
     950              :   /* Copy the statement.  Note that we purposely don't use copy_stmt
     951              :      here because we need to remap statements as we copy.  */
     952            0 :   body = gimple_bind_body (stmt);
     953            0 :   new_body = remap_gimple_seq (body, id);
     954              : 
     955            0 :   new_block = gimple_bind_block (stmt);
     956            0 :   if (new_block)
     957            0 :     remap_block (&new_block, id);
     958              : 
     959              :   /* This will remap a lot of the same decls again, but this should be
     960              :      harmless.  */
     961            0 :   new_vars = gimple_bind_vars (stmt);
     962            0 :   if (new_vars)
     963            0 :     new_vars = remap_decls (new_vars, NULL, id);
     964              : 
     965            0 :   new_bind = gimple_build_bind (new_vars, new_body, new_block);
     966              : 
     967            0 :   return new_bind;
     968              : }
     969              : 
     970              : /* Return true if DECL is a parameter or a SSA_NAME for a parameter.  */
     971              : 
     972              : static bool
     973        32848 : is_parm (tree decl)
     974              : {
     975        32848 :   if (TREE_CODE (decl) == SSA_NAME)
     976              :     {
     977        30937 :       decl = SSA_NAME_VAR (decl);
     978              :       if (!decl)
     979              :         return false;
     980              :     }
     981              : 
     982        20190 :   return (TREE_CODE (decl) == PARM_DECL);
     983              : }
     984              : 
     985              : /* Copy the TREE_THIS_NOTRAP flag from OLD to T if it is appropriate to do so.
     986              :    T and OLD must be both either INDIRECT_REF or MEM_REF.  */
     987              : 
     988              : static void
     989     21659447 : maybe_copy_this_notrap (copy_body_data *id, tree t, tree old)
     990              : {
     991     21659447 :   gcc_assert (TREE_CODE (t) == TREE_CODE (old));
     992              : 
     993              :   /* We cannot blindly propagate the TREE_THIS_NOTRAP flag if we have remapped
     994              :      a parameter as the property might be valid only for the parameter itself,
     995              :      typically when it is passed by reference.  But we propagate the flag when
     996              :      this is the dereference of an entire object done in a type that has self-
     997              :      referential size, to avoid the static size check in tree_could_trap_p.  */
     998     21659447 :   if (TREE_THIS_NOTRAP (old)
     999     21659447 :       && (!is_parm (TREE_OPERAND (old, 0))
    1000        14095 :           || (!id->transform_parameter && is_parm (TREE_OPERAND (t, 0)))
    1001        10159 :           || ((TREE_CODE (t) == INDIRECT_REF
    1002        10159 :                || integer_zerop (TREE_OPERAND (t, 1)))
    1003        10159 :               && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
    1004         9472 :               && DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0))
    1005         9472 :               && type_contains_placeholder_p (TREE_TYPE (t)))))
    1006        18753 :     TREE_THIS_NOTRAP (t) = 1;
    1007     21659447 : }
    1008              : 
    1009              : /* Remap the dependence CLIQUE from the source to the destination function
    1010              :    as specified in ID.  */
    1011              : 
    1012              : static unsigned short
    1013      2853831 : remap_dependence_clique (copy_body_data *id, unsigned short clique)
    1014              : {
    1015      2853831 :   if (clique == 0 || processing_debug_stmt)
    1016              :     return 0;
    1017      2819517 :   if (!id->dependence_map)
    1018       736569 :     id->dependence_map = new hash_map<dependence_hash, unsigned short>;
    1019      2819517 :   bool existed;
    1020      2819517 :   unsigned short &newc = id->dependence_map->get_or_insert (clique, &existed);
    1021      2819517 :   if (!existed)
    1022              :     {
    1023              :       /* Clique 1 is reserved for local ones set by PTA.  */
    1024      1103509 :       if (cfun->last_clique == 0)
    1025       340991 :         cfun->last_clique = 1;
    1026      2207018 :       newc = get_new_clique (cfun);
    1027              :     }
    1028      2819517 :   return newc;
    1029              : }
    1030              : 
    1031              : /* Remap the GIMPLE operand pointed to by *TP.  DATA is really a
    1032              :    'struct walk_stmt_info *'.  DATA->INFO is a 'copy_body_data *'.
    1033              :    WALK_SUBTREES is used to indicate walk_gimple_op whether to keep
    1034              :    recursing into the children nodes of *TP.  */
    1035              : 
    1036              : static tree
    1037    212366589 : remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data)
    1038              : {
    1039    212366589 :   struct walk_stmt_info *wi_p = (struct walk_stmt_info *) data;
    1040    212366589 :   copy_body_data *id = (copy_body_data *) wi_p->info;
    1041    212366589 :   tree fn = id->src_fn;
    1042              : 
    1043              :   /* For recursive invocations this is no longer the LHS itself.  */
    1044    212366589 :   bool is_lhs = wi_p->is_lhs;
    1045    212366589 :   wi_p->is_lhs = false;
    1046              : 
    1047    212366589 :   if (TREE_CODE (*tp) == SSA_NAME)
    1048              :     {
    1049     67620190 :       *tp = remap_ssa_name (*tp, id);
    1050     67620190 :       *walk_subtrees = 0;
    1051     67620190 :       if (is_lhs)
    1052     16858351 :         SSA_NAME_DEF_STMT (*tp) = wi_p->stmt;
    1053              :       return NULL;
    1054              :     }
    1055    144746399 :   else if (auto_var_in_fn_p (*tp, fn))
    1056              :     {
    1057              :       /* Local variables and labels need to be replaced by equivalent
    1058              :          variables.  We don't want to copy static variables; there's
    1059              :          only one of those, no matter how many times we inline the
    1060              :          containing function.  Similarly for globals from an outer
    1061              :          function.  */
    1062     47237924 :       tree new_decl;
    1063              : 
    1064              :       /* Remap the declaration.  */
    1065     47237924 :       new_decl = remap_decl (*tp, id);
    1066     47237924 :       gcc_assert (new_decl);
    1067              :       /* Replace this variable with the copy.  */
    1068     47237924 :       STRIP_TYPE_NOPS (new_decl);
    1069              :       /* ???  The C++ frontend uses void * pointer zero to initialize
    1070              :          any other type.  This confuses the middle-end type verification.
    1071              :          As cloned bodies do not go through gimplification again the fixup
    1072              :          there doesn't trigger.  */
    1073     47237924 :       if (TREE_CODE (new_decl) == INTEGER_CST
    1074     47237924 :           && !useless_type_conversion_p (TREE_TYPE (*tp), TREE_TYPE (new_decl)))
    1075            0 :         new_decl = fold_convert (TREE_TYPE (*tp), new_decl);
    1076     47237924 :       *tp = new_decl;
    1077     47237924 :       *walk_subtrees = 0;
    1078              :     }
    1079     97508475 :   else if (TREE_CODE (*tp) == STATEMENT_LIST)
    1080            0 :     gcc_unreachable ();
    1081     97508475 :   else if (TREE_CODE (*tp) == SAVE_EXPR)
    1082            0 :     gcc_unreachable ();
    1083     97508475 :   else if (TREE_CODE (*tp) == LABEL_DECL
    1084     97508475 :            && (!DECL_CONTEXT (*tp)
    1085          463 :                || decl_function_context (*tp) == id->src_fn))
    1086              :     /* These may need to be remapped for EH handling.  */
    1087            0 :     *tp = remap_decl (*tp, id);
    1088     97508475 :   else if (TREE_CODE (*tp) == FIELD_DECL)
    1089              :     {
    1090              :       /* If the enclosing record type is variably_modified_type_p, the field
    1091              :          has already been remapped.  Otherwise, it need not be.  */
    1092     16904196 :       tree *n = id->decl_map->get (*tp);
    1093     16904196 :       if (n)
    1094           83 :         *tp = *n;
    1095     16904196 :       *walk_subtrees = 0;
    1096              :     }
    1097     80604279 :   else if (TYPE_P (*tp))
    1098              :     /* Types may need remapping as well.  */
    1099            0 :     *tp = remap_type (*tp, id);
    1100     80604279 :   else if (CONSTANT_CLASS_P (*tp))
    1101              :     {
    1102              :       /* If this is a constant, we have to copy the node iff the type
    1103              :          will be remapped.  copy_tree_r will not copy a constant.  */
    1104     14031443 :       tree new_type = remap_type (TREE_TYPE (*tp), id);
    1105              : 
    1106     14031443 :       if (new_type == TREE_TYPE (*tp))
    1107     14028205 :         *walk_subtrees = 0;
    1108              : 
    1109         3238 :       else if (TREE_CODE (*tp) == INTEGER_CST)
    1110         3238 :         *tp = wide_int_to_tree (new_type, wi::to_wide (*tp));
    1111              :       else
    1112              :         {
    1113            0 :           *tp = copy_node (*tp);
    1114            0 :           TREE_TYPE (*tp) = new_type;
    1115              :         }
    1116              :     }
    1117              :   else
    1118              :     {
    1119              :       /* Otherwise, just copy the node.  Note that copy_tree_r already
    1120              :          knows not to copy VAR_DECLs, etc., so this is safe.  */
    1121              : 
    1122     66572836 :       if (TREE_CODE (*tp) == MEM_REF && !id->do_not_fold)
    1123              :         {
    1124              :           /* We need to re-canonicalize MEM_REFs from inline substitutions
    1125              :              that can happen when a pointer argument is an ADDR_EXPR.
    1126              :              Recurse here manually to allow that.  */
    1127     14280383 :           tree ptr = TREE_OPERAND (*tp, 0);
    1128     14280383 :           tree type = remap_type (TREE_TYPE (*tp), id);
    1129     14280383 :           tree old = *tp;
    1130     14280383 :           walk_tree (&ptr, remap_gimple_op_r, data, NULL);
    1131     14280383 :           *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
    1132     14280383 :           TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
    1133     14280383 :           TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
    1134     14280383 :           copy_warning (*tp, old);
    1135     14280383 :           if (MR_DEPENDENCE_CLIQUE (old) != 0)
    1136              :             {
    1137      2765223 :               MR_DEPENDENCE_CLIQUE (*tp)
    1138      2765223 :                 = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
    1139      2765223 :               MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old);
    1140              :             }
    1141     14280383 :           maybe_copy_this_notrap (id, *tp, old);
    1142     14280383 :           REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
    1143     14280383 :           *walk_subtrees = 0;
    1144     14280383 :           return NULL;
    1145              :         }
    1146              : 
    1147              :       /* Here is the "usual case".  Copy this tree node, and then
    1148              :          tweak some special cases.  */
    1149     52292453 :       copy_tree_r (tp, walk_subtrees, NULL);
    1150              : 
    1151     52292453 :       if (TREE_CODE (*tp) != OMP_CLAUSE)
    1152     52292453 :         TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
    1153              : 
    1154     52292453 :       if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3))
    1155              :         {
    1156              :           /* The copied TARGET_EXPR has never been expanded, even if the
    1157              :              original node was expanded already.  */
    1158            0 :           TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3);
    1159            0 :           TREE_OPERAND (*tp, 3) = NULL_TREE;
    1160              :         }
    1161     52292453 :       else if (TREE_CODE (*tp) == ADDR_EXPR)
    1162              :         {
    1163              :           /* Variable substitution need not be simple.  In particular,
    1164              :              the MEM_REF substitution above.  Make sure that
    1165              :              TREE_CONSTANT and friends are up-to-date.  */
    1166     16096498 :           int invariant = is_gimple_min_invariant (*tp);
    1167     16096498 :           walk_tree (&TREE_OPERAND (*tp, 0), remap_gimple_op_r, data, NULL);
    1168     16096498 :           recompute_tree_invariant_for_addr_expr (*tp);
    1169              : 
    1170              :           /* If this used to be invariant, but is not any longer,
    1171              :              then regimplification is probably needed.  */
    1172     16096498 :           if (invariant && !is_gimple_min_invariant (*tp))
    1173         4628 :             id->regimplify = true;
    1174              : 
    1175     16096498 :           *walk_subtrees = 0;
    1176              :         }
    1177     36195955 :       else if (TREE_CODE (*tp) == OMP_NEXT_VARIANT)
    1178              :         {
    1179              :           /* Neither operand is interesting, and walking the selector
    1180              :              causes problems because it's not an expression.  */
    1181          288 :           gcc_assert (TREE_CODE (TREE_OPERAND (*tp, 0)) == INTEGER_CST);
    1182          288 :           *walk_subtrees = 0;
    1183              :         }
    1184              :     }
    1185              : 
    1186              :   /* Update the TREE_BLOCK for the cloned expr.  */
    1187    130466016 :   if (EXPR_P (*tp))
    1188              :     {
    1189     34529055 :       tree new_block = id->remapping_type_depth == 0 ? id->block : NULL;
    1190     34529055 :       tree old_block = TREE_BLOCK (*tp);
    1191     34529055 :       if (old_block)
    1192              :         {
    1193     19878307 :           tree *n;
    1194     19878307 :           n = id->decl_map->get (TREE_BLOCK (*tp));
    1195     19878307 :           if (n)
    1196     19873479 :             new_block = *n;
    1197              :         }
    1198     34529055 :       TREE_SET_BLOCK (*tp, new_block);
    1199              :     }
    1200              : 
    1201              :   /* Keep iterating.  */
    1202              :   return NULL_TREE;
    1203              : }
    1204              : 
    1205              : 
    1206              : /* Called from copy_body_id via walk_tree.  DATA is really a
    1207              :    `copy_body_data *'.  */
    1208              : 
    1209              : tree
    1210   1431849160 : copy_tree_body_r (tree *tp, int *walk_subtrees, void *data)
    1211              : {
    1212   1431849160 :   copy_body_data *id = (copy_body_data *) data;
    1213   1431849160 :   tree fn = id->src_fn;
    1214   1431849160 :   tree new_block;
    1215              : 
    1216              :   /* Begin by recognizing trees that we'll completely rewrite for the
    1217              :      inlining context.  Our output for these trees is completely
    1218              :      different from out input (e.g. RETURN_EXPR is deleted, and morphs
    1219              :      into an edge).  Further down, we'll handle trees that get
    1220              :      duplicated and/or tweaked.  */
    1221              : 
    1222              :   /* When requested, RETURN_EXPRs should be transformed to just the
    1223              :      contained MODIFY_EXPR.  The branch semantics of the return will
    1224              :      be handled elsewhere by manipulating the CFG rather than a statement.  */
    1225   1431849160 :   if (TREE_CODE (*tp) == RETURN_EXPR && id->transform_return_to_modify)
    1226              :     {
    1227            0 :       tree assignment = TREE_OPERAND (*tp, 0);
    1228              : 
    1229              :       /* If we're returning something, just turn that into an
    1230              :          assignment into the equivalent of the original RESULT_DECL.
    1231              :          If the "assignment" is just the result decl, the result
    1232              :          decl has already been set (e.g. a recent "foo (&result_decl,
    1233              :          ...)"); just toss the entire RETURN_EXPR.  */
    1234            0 :       if (assignment && TREE_CODE (assignment) == MODIFY_EXPR)
    1235              :         {
    1236              :           /* Replace the RETURN_EXPR with (a copy of) the
    1237              :              MODIFY_EXPR hanging underneath.  */
    1238            0 :           *tp = copy_node (assignment);
    1239              :         }
    1240              :       else /* Else the RETURN_EXPR returns no value.  */
    1241              :         {
    1242            0 :           *tp = NULL;
    1243            0 :           return (tree) (void *)1;
    1244              :         }
    1245            0 :     }
    1246   1431849160 :   else if (TREE_CODE (*tp) == SSA_NAME)
    1247              :     {
    1248      4076604 :       *tp = remap_ssa_name (*tp, id);
    1249      4076604 :       *walk_subtrees = 0;
    1250      4076604 :       return NULL;
    1251              :     }
    1252              : 
    1253              :   /* Local variables and labels need to be replaced by equivalent
    1254              :      variables.  We don't want to copy static variables; there's only
    1255              :      one of those, no matter how many times we inline the containing
    1256              :      function.  Similarly for globals from an outer function.  */
    1257   1427772556 :   else if (auto_var_in_fn_p (*tp, fn))
    1258              :     {
    1259    175804750 :       tree new_decl;
    1260              : 
    1261              :       /* Remap the declaration.  */
    1262    175804750 :       new_decl = remap_decl (*tp, id);
    1263    175804750 :       gcc_assert (new_decl);
    1264              :       /* Replace this variable with the copy.  */
    1265    175804750 :       STRIP_TYPE_NOPS (new_decl);
    1266    175804750 :       *tp = new_decl;
    1267    175804750 :       *walk_subtrees = 0;
    1268              :     }
    1269   1251967806 :   else if (TREE_CODE (*tp) == STATEMENT_LIST)
    1270     37658548 :     copy_statement_list (tp);
    1271   1214309258 :   else if (TREE_CODE (*tp) == SAVE_EXPR
    1272   1213619395 :            || TREE_CODE (*tp) == TARGET_EXPR)
    1273     15696273 :     remap_save_expr (tp, id->decl_map, walk_subtrees);
    1274   1198612985 :   else if (TREE_CODE (*tp) == LABEL_DECL
    1275   1198612985 :            && (! DECL_CONTEXT (*tp)
    1276            7 :                || decl_function_context (*tp) == id->src_fn))
    1277              :     /* These may need to be remapped for EH handling.  */
    1278            0 :     *tp = remap_decl (*tp, id);
    1279   1198612985 :   else if (TREE_CODE (*tp) == BIND_EXPR)
    1280     20563281 :     copy_bind_expr (tp, walk_subtrees, id);
    1281              :   /* Types may need remapping as well.  */
    1282   1178049704 :   else if (TYPE_P (*tp))
    1283       223984 :     *tp = remap_type (*tp, id);
    1284              : 
    1285              :   /* If this is a constant, we have to copy the node iff the type will be
    1286              :      remapped.  copy_tree_r will not copy a constant.  */
    1287   1177825720 :   else if (CONSTANT_CLASS_P (*tp))
    1288              :     {
    1289    361440197 :       tree new_type = remap_type (TREE_TYPE (*tp), id);
    1290              : 
    1291    361440197 :       if (new_type == TREE_TYPE (*tp))
    1292    361439062 :         *walk_subtrees = 0;
    1293              : 
    1294         1135 :       else if (TREE_CODE (*tp) == INTEGER_CST)
    1295         1135 :         *tp = wide_int_to_tree (new_type, wi::to_wide (*tp));
    1296              :       else
    1297              :         {
    1298            0 :           *tp = copy_node (*tp);
    1299            0 :           TREE_TYPE (*tp) = new_type;
    1300              :         }
    1301              :     }
    1302              : 
    1303              :   /* Otherwise, just copy the node.  Note that copy_tree_r already
    1304              :      knows not to copy VAR_DECLs, etc., so this is safe.  */
    1305              :   else
    1306              :     {
    1307              :       /* Here we handle trees that are not completely rewritten.
    1308              :          First we detect some inlining-induced bogosities for
    1309              :          discarding.  */
    1310    816385523 :       if (TREE_CODE (*tp) == MODIFY_EXPR
    1311     10960352 :           && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
    1312    816385544 :           && (auto_var_in_fn_p (TREE_OPERAND (*tp, 0), fn)))
    1313              :         {
    1314              :           /* Some assignments VAR = VAR; don't generate any rtl code
    1315              :              and thus don't count as variable modification.  Avoid
    1316              :              keeping bogosities like 0 = 0.  */
    1317            0 :           tree decl = TREE_OPERAND (*tp, 0), value;
    1318            0 :           tree *n;
    1319              : 
    1320            0 :           n = id->decl_map->get (decl);
    1321            0 :           if (n)
    1322              :             {
    1323            0 :               value = *n;
    1324            0 :               STRIP_TYPE_NOPS (value);
    1325            0 :               if (TREE_CONSTANT (value) || TREE_READONLY (value))
    1326              :                 {
    1327            0 :                   *tp = build_empty_stmt (EXPR_LOCATION (*tp));
    1328            0 :                   return copy_tree_body_r (tp, walk_subtrees, data);
    1329              :                 }
    1330              :             }
    1331              :         }
    1332    816385523 :       else if (INDIRECT_REF_P (*tp))
    1333              :         {
    1334              :           /* Get rid of *& from inline substitutions that can happen when a
    1335              :              pointer argument is an ADDR_EXPR.  */
    1336     44343804 :           tree decl = TREE_OPERAND (*tp, 0);
    1337     44343804 :           tree *n = id->decl_map->get (decl);
    1338     44343804 :           if (n)
    1339              :             {
    1340              :               /* If we happen to get an ADDR_EXPR in n->value, strip
    1341              :                  it manually here as we'll eventually get ADDR_EXPRs
    1342              :                  which lie about their types pointed to.  In this case
    1343              :                  build_fold_indirect_ref wouldn't strip the INDIRECT_REF,
    1344              :                  but we absolutely rely on that.  As fold_indirect_ref
    1345              :                  does other useful transformations, try that first, though.  */
    1346      7306781 :               tree type = TREE_TYPE (*tp);
    1347      7306781 :               tree ptr = id->do_not_unshare ? *n : unshare_expr (*n);
    1348      7306781 :               tree old = *tp;
    1349      7306781 :               *tp = id->do_not_fold ? NULL : gimple_fold_indirect_ref (ptr);
    1350      7306781 :               if (! *tp)
    1351              :                 {
    1352      7306646 :                   type = remap_type (type, id);
    1353      7306646 :                   if (TREE_CODE (ptr) == ADDR_EXPR && !id->do_not_fold)
    1354              :                     {
    1355            0 :                       *tp
    1356            0 :                         = fold_indirect_ref_1 (EXPR_LOCATION (ptr), type, ptr);
    1357              :                       /* ???  We should either assert here or build
    1358              :                          a VIEW_CONVERT_EXPR instead of blindly leaking
    1359              :                          incompatible types to our IL.  */
    1360            0 :                       if (! *tp)
    1361            0 :                         *tp = TREE_OPERAND (ptr, 0);
    1362              :                     }
    1363              :                   else
    1364              :                     {
    1365      7306646 :                       *tp = build1 (INDIRECT_REF, type, ptr);
    1366      7306646 :                       TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
    1367      7306646 :                       TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
    1368      7306646 :                       TREE_READONLY (*tp) = TREE_READONLY (old);
    1369      7306646 :                       maybe_copy_this_notrap (id, *tp, old);
    1370              :                     }
    1371              :                 }
    1372      7306781 :               *walk_subtrees = 0;
    1373      7306781 :               return NULL;
    1374              :             }
    1375              :         }
    1376    772041719 :       else if (TREE_CODE (*tp) == MEM_REF && !id->do_not_fold)
    1377              :         {
    1378              :           /* We need to re-canonicalize MEM_REFs from inline substitutions
    1379              :              that can happen when a pointer argument is an ADDR_EXPR.
    1380              :              Recurse here manually to allow that.  */
    1381        72418 :           tree ptr = TREE_OPERAND (*tp, 0);
    1382        72418 :           tree type = remap_type (TREE_TYPE (*tp), id);
    1383        72418 :           tree old = *tp;
    1384        72418 :           walk_tree (&ptr, copy_tree_body_r, data, NULL);
    1385        72418 :           *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1));
    1386        72418 :           TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
    1387        72418 :           TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old);
    1388        72418 :           copy_warning (*tp, old);
    1389        72418 :           if (MR_DEPENDENCE_CLIQUE (old) != 0)
    1390              :             {
    1391         5886 :               MR_DEPENDENCE_CLIQUE (*tp)
    1392         5886 :                 = remap_dependence_clique (id, MR_DEPENDENCE_CLIQUE (old));
    1393         5886 :               MR_DEPENDENCE_BASE (*tp) = MR_DEPENDENCE_BASE (old);
    1394              :             }
    1395        72418 :           maybe_copy_this_notrap (id, *tp, old);
    1396        72418 :           REF_REVERSE_STORAGE_ORDER (*tp) = REF_REVERSE_STORAGE_ORDER (old);
    1397        72418 :           *walk_subtrees = 0;
    1398        72418 :           return NULL;
    1399              :         }
    1400              : 
    1401              :       /* Here is the "usual case".  Copy this tree node, and then
    1402              :          tweak some special cases.  */
    1403    809006324 :       copy_tree_r (tp, walk_subtrees, NULL);
    1404              : 
    1405              :       /* If EXPR has block defined, map it to newly constructed block.
    1406              :          When inlining we want EXPRs without block appear in the block
    1407              :          of function call if we are not remapping a type.  */
    1408    809006324 :       if (EXPR_P (*tp))
    1409              :         {
    1410    705797570 :           new_block = id->remapping_type_depth == 0 ? id->block : NULL;
    1411    705797570 :           if (TREE_BLOCK (*tp))
    1412              :             {
    1413        14027 :               tree *n;
    1414        14027 :               n = id->decl_map->get (TREE_BLOCK (*tp));
    1415        14027 :               if (n)
    1416        14027 :                 new_block = *n;
    1417              :             }
    1418    705797570 :           TREE_SET_BLOCK (*tp, new_block);
    1419              :         }
    1420              : 
    1421    809006324 :       if (TREE_CODE (*tp) != OMP_CLAUSE)
    1422    809006233 :         TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
    1423              : 
    1424              :       /* The copied TARGET_EXPR has never been expanded, even if the
    1425              :          original node was expanded already.  */
    1426    809006324 :       if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3))
    1427              :         {
    1428            0 :           TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3);
    1429            0 :           TREE_OPERAND (*tp, 3) = NULL_TREE;
    1430              :         }
    1431              : 
    1432              :       /* Variable substitution need not be simple.  In particular, the
    1433              :          INDIRECT_REF substitution above.  Make sure that TREE_CONSTANT
    1434              :          and friends are up-to-date.  */
    1435    809006324 :       else if (TREE_CODE (*tp) == ADDR_EXPR)
    1436              :         {
    1437     80049677 :           int invariant = is_gimple_min_invariant (*tp);
    1438     80049677 :           walk_tree (&TREE_OPERAND (*tp, 0), copy_tree_body_r, id, NULL);
    1439              : 
    1440              :           /* Handle the case where we substituted an INDIRECT_REF
    1441              :              into the operand of the ADDR_EXPR.  */
    1442     80049677 :           if (INDIRECT_REF_P (TREE_OPERAND (*tp, 0))
    1443     80049677 :               && !id->do_not_fold)
    1444              :             {
    1445          195 :               tree t = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0);
    1446          195 :               if (TREE_TYPE (t) != TREE_TYPE (*tp))
    1447          195 :                 t = fold_convert (remap_type (TREE_TYPE (*tp), id), t);
    1448          195 :               *tp = t;
    1449              :             }
    1450              :           else
    1451     80049482 :             recompute_tree_invariant_for_addr_expr (*tp);
    1452              : 
    1453              :           /* If this used to be invariant, but is not any longer,
    1454              :              then regimplification is probably needed.  */
    1455     80049677 :           if (invariant && !is_gimple_min_invariant (*tp))
    1456           19 :             id->regimplify = true;
    1457              : 
    1458     80049677 :           *walk_subtrees = 0;
    1459              :         }
    1460    728956647 :       else if (TREE_CODE (*tp) == OMP_CLAUSE
    1461    728956647 :                && (OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_AFFINITY
    1462           76 :                    || OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_DEPEND))
    1463              :         {
    1464           30 :           tree t = OMP_CLAUSE_DECL (*tp);
    1465           30 :           if (t && OMP_ITERATOR_DECL_P (t))
    1466              :             {
    1467           18 :               *walk_subtrees = 0;
    1468           18 :               OMP_CLAUSE_DECL (*tp) = copy_node (t);
    1469           18 :               t = OMP_CLAUSE_DECL (*tp);
    1470           18 :               TREE_PURPOSE (t) = copy_node (TREE_PURPOSE (t));
    1471          108 :               for (int i = 0; i <= 4; i++)
    1472           90 :                 walk_tree (&TREE_VEC_ELT (TREE_PURPOSE (t), i),
    1473              :                            copy_tree_body_r, id, NULL);
    1474           18 :               if (OMP_ITERATOR_BLOCK (TREE_PURPOSE (t)))
    1475           18 :                 remap_block (&OMP_ITERATOR_BLOCK (TREE_PURPOSE (t)), id);
    1476           18 :               walk_tree (&TREE_VALUE (t), copy_tree_body_r, id, NULL);
    1477              :             }
    1478              :         }
    1479              :     }
    1480              : 
    1481              :   /* Keep iterating.  */
    1482              :   return NULL_TREE;
    1483              : }
    1484              : 
    1485              : /* Helper for remap_gimple_stmt.  Given an EH region number for the
    1486              :    source function, map that to the duplicate EH region number in
    1487              :    the destination function.  */
    1488              : 
    1489              : static int
    1490       101560 : remap_eh_region_nr (int old_nr, copy_body_data *id)
    1491              : {
    1492       101560 :   eh_region old_r, new_r;
    1493              : 
    1494       101560 :   old_r = get_eh_region_from_number_fn (id->src_cfun, old_nr);
    1495       101560 :   new_r = static_cast<eh_region> (*id->eh_map->get (old_r));
    1496              : 
    1497       101560 :   return new_r->index;
    1498              : }
    1499              : 
    1500              : /* Similar, but operate on INTEGER_CSTs.  */
    1501              : 
    1502              : static tree
    1503         9713 : remap_eh_region_tree_nr (tree old_t_nr, copy_body_data *id)
    1504              : {
    1505         9713 :   int old_nr, new_nr;
    1506              : 
    1507         9713 :   old_nr = tree_to_shwi (old_t_nr);
    1508         9713 :   new_nr = remap_eh_region_nr (old_nr, id);
    1509              : 
    1510         9713 :   return build_int_cst (integer_type_node, new_nr);
    1511              : }
    1512              : 
    1513              : /* Helper for copy_bb.  Remap statement STMT using the inlining
    1514              :    information in ID.  Return the new statement copy.  */
    1515              : 
    1516              : static gimple_seq
    1517     98439599 : remap_gimple_stmt (gimple *stmt, copy_body_data *id)
    1518              : {
    1519     98439599 :   gimple *copy = NULL;
    1520     98439599 :   struct walk_stmt_info wi;
    1521     98439599 :   bool skip_first = false;
    1522     98439599 :   gimple_seq stmts = NULL;
    1523              : 
    1524     98439599 :   if (is_gimple_debug (stmt)
    1525     98439599 :       && (gimple_debug_nonbind_marker_p (stmt)
    1526     13980605 :           ? !DECL_STRUCT_FUNCTION (id->dst_fn)->debug_nonbind_markers
    1527     47849876 :           : !opt_for_fn (id->dst_fn, flag_var_tracking_assignments)))
    1528              :     return NULL;
    1529              : 
    1530     98407375 :   if (!is_gimple_debug (stmt)
    1531     36609118 :       && id->param_body_adjs
    1532    102145066 :       && id->param_body_adjs->m_dead_stmts.contains (stmt))
    1533              :     {
    1534         6781 :       tree *dval = id->param_body_adjs->m_dead_stmt_debug_equiv.get (stmt);
    1535         6781 :       if (!dval)
    1536              :         return NULL;
    1537              : 
    1538         3316 :       gcc_assert (is_gimple_assign (stmt));
    1539         3316 :       tree lhs = gimple_assign_lhs (stmt);
    1540         3316 :       tree *dvar = id->param_body_adjs->m_dead_ssa_debug_equiv.get (lhs);
    1541         3316 :       gdebug *bind = gimple_build_debug_bind (*dvar, *dval, stmt);
    1542         3316 :       if (id->reset_location)
    1543            0 :         gimple_set_location (bind, input_location);
    1544         3316 :       id->debug_stmts.safe_push (bind);
    1545         3316 :       gimple_seq_add_stmt_without_update (&stmts, bind);
    1546         3316 :       return stmts;
    1547              :     }
    1548              : 
    1549              :   /* Begin by recognizing trees that we'll completely rewrite for the
    1550              :      inlining context.  Our output for these trees is completely
    1551              :      different from our input (e.g. RETURN_EXPR is deleted and morphs
    1552              :      into an edge).  Further down, we'll handle trees that get
    1553              :      duplicated and/or tweaked.  */
    1554              : 
    1555              :   /* When requested, GIMPLE_RETURN should be transformed to just the
    1556              :      contained GIMPLE_ASSIGN.  The branch semantics of the return will
    1557              :      be handled elsewhere by manipulating the CFG rather than the
    1558              :      statement.  */
    1559     98400594 :   if (gimple_code (stmt) == GIMPLE_RETURN && id->transform_return_to_modify)
    1560              :     {
    1561      4598020 :       tree retval = gimple_return_retval (as_a <greturn *> (stmt));
    1562              : 
    1563              :       /* If we're returning something, just turn that into an
    1564              :          assignment to the equivalent of the original RESULT_DECL.
    1565              :          If RETVAL is just the result decl, the result decl has
    1566              :          already been set (e.g. a recent "foo (&result_decl, ...)");
    1567              :          just toss the entire GIMPLE_RETURN.  Likewise for when the
    1568              :          call doesn't want the return value.  */
    1569      4598020 :       if (retval
    1570      4598020 :           && (TREE_CODE (retval) != RESULT_DECL
    1571      2407257 :               && (!id->call_stmt
    1572      2407257 :                   || gimple_call_lhs (id->call_stmt) != NULL_TREE)
    1573      2272928 :               && (TREE_CODE (retval) != SSA_NAME
    1574      1790992 :                   || ! SSA_NAME_VAR (retval)
    1575       425553 :                   || TREE_CODE (SSA_NAME_VAR (retval)) != RESULT_DECL)))
    1576              :         {
    1577      4379780 :           copy = gimple_build_assign (id->do_not_unshare
    1578      2189890 :                                       ? id->retvar : unshare_expr (id->retvar),
    1579              :                                       retval);
    1580              :           /* id->retvar is already substituted.  Skip it on later remapping.  */
    1581      2189890 :           skip_first = true;
    1582              :         }
    1583              :       else
    1584              :         return NULL;
    1585              :     }
    1586     93802574 :   else if (gimple_has_substatements (stmt))
    1587              :     {
    1588           67 :       gimple_seq s1, s2;
    1589              : 
    1590              :       /* When cloning bodies from the C++ front end, we will be handed bodies
    1591              :          in High GIMPLE form.  Handle here all the High GIMPLE statements that
    1592              :          have embedded statements.  */
    1593           67 :       switch (gimple_code (stmt))
    1594              :         {
    1595            0 :         case GIMPLE_BIND:
    1596            0 :           copy = copy_gimple_bind (as_a <gbind *> (stmt), id);
    1597            0 :           break;
    1598              : 
    1599            0 :         case GIMPLE_CATCH:
    1600            0 :           {
    1601            0 :             gcatch *catch_stmt = as_a <gcatch *> (stmt);
    1602            0 :             s1 = remap_gimple_seq (gimple_catch_handler (catch_stmt), id);
    1603            0 :             copy = gimple_build_catch (gimple_catch_types (catch_stmt), s1);
    1604              :           }
    1605            0 :           break;
    1606              : 
    1607            0 :         case GIMPLE_EH_FILTER:
    1608            0 :           s1 = remap_gimple_seq (gimple_eh_filter_failure (stmt), id);
    1609            0 :           copy = gimple_build_eh_filter (gimple_eh_filter_types (stmt), s1);
    1610            0 :           break;
    1611              : 
    1612            0 :         case GIMPLE_TRY:
    1613            0 :           s1 = remap_gimple_seq (gimple_try_eval (stmt), id);
    1614            0 :           s2 = remap_gimple_seq (gimple_try_cleanup (stmt), id);
    1615            0 :           copy = gimple_build_try (s1, s2, gimple_try_kind (stmt));
    1616            0 :           break;
    1617              : 
    1618            0 :         case GIMPLE_WITH_CLEANUP_EXPR:
    1619            0 :           s1 = remap_gimple_seq (gimple_wce_cleanup (stmt), id);
    1620            0 :           copy = gimple_build_wce (s1);
    1621            0 :           break;
    1622              : 
    1623            0 :         case GIMPLE_OMP_PARALLEL:
    1624            0 :           {
    1625            0 :             gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt);
    1626            0 :             s1 = remap_gimple_seq (gimple_omp_body (omp_par_stmt), id);
    1627            0 :             copy = gimple_build_omp_parallel
    1628            0 :                      (s1,
    1629              :                       gimple_omp_parallel_clauses (omp_par_stmt),
    1630              :                       gimple_omp_parallel_child_fn (omp_par_stmt),
    1631              :                       gimple_omp_parallel_data_arg (omp_par_stmt));
    1632              :           }
    1633            0 :           break;
    1634              : 
    1635            0 :         case GIMPLE_OMP_TASK:
    1636            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1637            0 :           copy = gimple_build_omp_task
    1638            0 :                    (s1,
    1639              :                     gimple_omp_task_clauses (stmt),
    1640              :                     gimple_omp_task_child_fn (stmt),
    1641              :                     gimple_omp_task_data_arg (stmt),
    1642              :                     gimple_omp_task_copy_fn (stmt),
    1643              :                     gimple_omp_task_arg_size (stmt),
    1644              :                     gimple_omp_task_arg_align (stmt));
    1645            0 :           break;
    1646              : 
    1647            0 :         case GIMPLE_OMP_FOR:
    1648            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1649            0 :           s2 = remap_gimple_seq (gimple_omp_for_pre_body (stmt), id);
    1650            0 :           copy = gimple_build_omp_for (s1, gimple_omp_for_kind (stmt),
    1651              :                                        gimple_omp_for_clauses (stmt),
    1652              :                                        gimple_omp_for_collapse (stmt), s2);
    1653            0 :           {
    1654            0 :             size_t i;
    1655            0 :             for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
    1656              :               {
    1657            0 :                 gimple_omp_for_set_index (copy, i,
    1658              :                                           gimple_omp_for_index (stmt, i));
    1659            0 :                 gimple_omp_for_set_initial (copy, i,
    1660              :                                             gimple_omp_for_initial (stmt, i));
    1661            0 :                 gimple_omp_for_set_final (copy, i,
    1662              :                                           gimple_omp_for_final (stmt, i));
    1663            0 :                 gimple_omp_for_set_incr (copy, i,
    1664              :                                          gimple_omp_for_incr (stmt, i));
    1665            0 :                 gimple_omp_for_set_cond (copy, i,
    1666              :                                          gimple_omp_for_cond (stmt, i));
    1667              :               }
    1668              :           }
    1669              :           break;
    1670              : 
    1671            0 :         case GIMPLE_OMP_MASTER:
    1672            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1673            0 :           copy = gimple_build_omp_master (s1);
    1674            0 :           break;
    1675              : 
    1676            0 :         case GIMPLE_OMP_MASKED:
    1677            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1678            0 :           copy = gimple_build_omp_masked
    1679            0 :                    (s1, gimple_omp_masked_clauses (stmt));
    1680            0 :           break;
    1681              : 
    1682            0 :         case GIMPLE_OMP_SCOPE:
    1683            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1684            0 :           copy = gimple_build_omp_scope
    1685            0 :                    (s1, gimple_omp_scope_clauses (stmt));
    1686            0 :           break;
    1687              : 
    1688            0 :         case GIMPLE_OMP_DISPATCH:
    1689            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1690            0 :           copy = gimple_build_omp_dispatch (s1,
    1691              :                                             gimple_omp_dispatch_clauses (stmt));
    1692            0 :           break;
    1693              : 
    1694            0 :         case GIMPLE_OMP_TASKGROUP:
    1695            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1696            0 :           copy = gimple_build_omp_taskgroup
    1697            0 :                    (s1, gimple_omp_taskgroup_clauses (stmt));
    1698            0 :           break;
    1699              : 
    1700            0 :         case GIMPLE_OMP_ORDERED:
    1701            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1702            0 :           copy = gimple_build_omp_ordered
    1703            0 :                    (s1,
    1704            0 :                     gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt)));
    1705            0 :           break;
    1706              : 
    1707            0 :         case GIMPLE_OMP_SCAN:
    1708            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1709            0 :           copy = gimple_build_omp_scan
    1710            0 :                    (s1, gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt)));
    1711            0 :           break;
    1712              : 
    1713            0 :         case GIMPLE_OMP_SECTION:
    1714            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1715            0 :           copy = gimple_build_omp_section (s1);
    1716            0 :           break;
    1717              : 
    1718            0 :         case GIMPLE_OMP_SECTIONS:
    1719            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1720            0 :           copy = gimple_build_omp_sections
    1721            0 :                    (s1, gimple_omp_sections_clauses (stmt));
    1722            0 :           break;
    1723              : 
    1724            0 :         case GIMPLE_OMP_STRUCTURED_BLOCK:
    1725            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1726            0 :           copy = gimple_build_omp_structured_block (s1);
    1727            0 :           break;
    1728              : 
    1729            0 :         case GIMPLE_OMP_SINGLE:
    1730            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1731            0 :           copy = gimple_build_omp_single
    1732            0 :                    (s1, gimple_omp_single_clauses (stmt));
    1733            0 :           break;
    1734              : 
    1735            0 :         case GIMPLE_OMP_TARGET:
    1736            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1737            0 :           copy = gimple_build_omp_target
    1738            0 :                    (s1, gimple_omp_target_kind (stmt),
    1739              :                     gimple_omp_target_clauses (stmt));
    1740            0 :           break;
    1741              : 
    1742            0 :         case GIMPLE_OMP_TEAMS:
    1743            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1744            0 :           copy = gimple_build_omp_teams
    1745            0 :                    (s1, gimple_omp_teams_clauses (stmt));
    1746            0 :           break;
    1747              : 
    1748            0 :         case GIMPLE_OMP_CRITICAL:
    1749            0 :           s1 = remap_gimple_seq (gimple_omp_body (stmt), id);
    1750            0 :           copy = gimple_build_omp_critical (s1,
    1751              :                                             gimple_omp_critical_name
    1752            0 :                                               (as_a <gomp_critical *> (stmt)),
    1753              :                                             gimple_omp_critical_clauses
    1754            0 :                                               (as_a <gomp_critical *> (stmt)));
    1755            0 :           break;
    1756              : 
    1757            0 :         case GIMPLE_ASSUME:
    1758            0 :           s1 = remap_gimple_seq (gimple_assume_body (stmt), id);
    1759            0 :           copy = gimple_build_assume (gimple_assume_guard (stmt), s1);
    1760            0 :           break;
    1761              : 
    1762           67 :         case GIMPLE_TRANSACTION:
    1763           67 :           {
    1764           67 :             gtransaction *old_trans_stmt = as_a <gtransaction *> (stmt);
    1765           67 :             gtransaction *new_trans_stmt;
    1766           67 :             s1 = remap_gimple_seq (gimple_transaction_body (old_trans_stmt),
    1767              :                                    id);
    1768           67 :             copy = new_trans_stmt = gimple_build_transaction (s1);
    1769           67 :             gimple_transaction_set_subcode (new_trans_stmt,
    1770              :               gimple_transaction_subcode (old_trans_stmt));
    1771           67 :             gimple_transaction_set_label_norm (new_trans_stmt,
    1772              :               gimple_transaction_label_norm (old_trans_stmt));
    1773           67 :             gimple_transaction_set_label_uninst (new_trans_stmt,
    1774              :               gimple_transaction_label_uninst (old_trans_stmt));
    1775           67 :             gimple_transaction_set_label_over (new_trans_stmt,
    1776              :               gimple_transaction_label_over (old_trans_stmt));
    1777              :           }
    1778           67 :           break;
    1779              : 
    1780            0 :         default:
    1781            0 :           gcc_unreachable ();
    1782              :         }
    1783              :     }
    1784              :   else
    1785              :     {
    1786     93802507 :       if (gimple_assign_single_p (stmt)
    1787     14020274 :           && gimple_assign_lhs (stmt) == gimple_assign_rhs1 (stmt)
    1788     93802507 :           && auto_var_in_fn_p (gimple_assign_lhs (stmt), id->src_fn))
    1789              :         {
    1790              :           /* Here we handle statements that are not completely rewritten.
    1791              :              First we detect some inlining-induced bogosities for
    1792              :              discarding.  */
    1793              : 
    1794              :           /* Some assignments VAR = VAR; don't generate any rtl code
    1795              :              and thus don't count as variable modification.  Avoid
    1796              :              keeping bogosities like 0 = 0.  */
    1797            0 :           tree decl = gimple_assign_lhs (stmt), value;
    1798            0 :           tree *n;
    1799              : 
    1800            0 :           n = id->decl_map->get (decl);
    1801            0 :           if (n)
    1802              :             {
    1803            0 :               value = *n;
    1804            0 :               STRIP_TYPE_NOPS (value);
    1805            0 :               if (TREE_CONSTANT (value) || TREE_READONLY (value))
    1806            0 :                 return NULL;
    1807              :             }
    1808              :         }
    1809              : 
    1810              :       /* For *ptr_N ={v} {CLOBBER}, if ptr_N is SSA_NAME defined
    1811              :          in a block that we aren't copying during tree_function_versioning,
    1812              :          just drop the clobber stmt.  */
    1813     93802507 :       if (id->blocks_to_copy && gimple_clobber_p (stmt))
    1814              :         {
    1815        17698 :           tree lhs = gimple_assign_lhs (stmt);
    1816        17698 :           if (TREE_CODE (lhs) == MEM_REF
    1817        17698 :               && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
    1818              :             {
    1819         1130 :               gimple *def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (lhs, 0));
    1820         1130 :               if (gimple_bb (def_stmt)
    1821         1470 :                   && !bitmap_bit_p (id->blocks_to_copy,
    1822          340 :                                     gimple_bb (def_stmt)->index))
    1823              :                 return NULL;
    1824              :             }
    1825              :         }
    1826              : 
    1827              :       /* We do not allow CLOBBERs of handled components.  In case
    1828              :          returned value is stored via such handled component, remove
    1829              :          the clobber so stmt verifier is happy.  */
    1830     93802504 :       if (gimple_clobber_p (stmt)
    1831     93802504 :           && TREE_CODE (gimple_assign_lhs (stmt)) == RESULT_DECL)
    1832              :         {
    1833            0 :           tree remapped = remap_decl (gimple_assign_lhs (stmt), id);
    1834            0 :           if (!DECL_P (remapped)
    1835            0 :               && TREE_CODE (remapped) != MEM_REF)
    1836              :             return NULL;
    1837              :         }
    1838              : 
    1839     93802504 :       if (gimple_debug_bind_p (stmt))
    1840              :         {
    1841     47291141 :           tree var = gimple_debug_bind_get_var (stmt);
    1842     47291141 :           tree value = gimple_debug_bind_get_value (stmt);
    1843     47291141 :           if (id->param_body_adjs
    1844     47291141 :               && id->param_body_adjs->m_dead_stmts.contains (stmt))
    1845              :             {
    1846        16464 :               value = unshare_expr_without_location (value);
    1847        16464 :               id->param_body_adjs->remap_with_debug_expressions (&value);
    1848              :             }
    1849              : 
    1850     47291141 :           gdebug *copy = gimple_build_debug_bind (var, value, stmt);
    1851     47291141 :           if (id->reset_location)
    1852            4 :             gimple_set_location (copy, input_location);
    1853     47291141 :           id->debug_stmts.safe_push (copy);
    1854     47291141 :           gimple_seq_add_stmt_without_update (&stmts, copy);
    1855     47291141 :           return stmts;
    1856              :         }
    1857     46511363 :       if (gimple_debug_source_bind_p (stmt))
    1858              :         {
    1859       558735 :           gdebug *copy = gimple_build_debug_source_bind
    1860       558735 :                            (gimple_debug_source_bind_get_var (stmt),
    1861              :                             gimple_debug_source_bind_get_value (stmt),
    1862       558735 :                             stmt);
    1863       558735 :           if (id->reset_location)
    1864            0 :             gimple_set_location (copy, input_location);
    1865       558735 :           id->debug_stmts.safe_push (copy);
    1866       558735 :           gimple_seq_add_stmt_without_update (&stmts, copy);
    1867       558735 :           return stmts;
    1868              :         }
    1869     45952628 :       if (gimple_debug_nonbind_marker_p (stmt))
    1870              :         {
    1871              :           /* If the inlined function has too many debug markers,
    1872              :              don't copy them.  */
    1873     13948381 :           if (id->src_cfun->debug_marker_count
    1874     13948381 :               > param_max_debug_marker_count
    1875     13948381 :               || id->reset_location)
    1876            0 :             return stmts;
    1877              : 
    1878     13948381 :           gdebug *copy = as_a <gdebug *> (gimple_copy (stmt));
    1879     13948381 :           id->debug_stmts.safe_push (copy);
    1880     13948381 :           gimple_seq_add_stmt_without_update (&stmts, copy);
    1881     13948381 :           return stmts;
    1882              :         }
    1883              : 
    1884              :       /* Create a new deep copy of the statement.  */
    1885     32004247 :       copy = gimple_copy (stmt);
    1886              : 
    1887              :       /* Clear flags that need revisiting.  */
    1888     32004247 :       if (gcall *call_stmt = dyn_cast <gcall *> (copy))
    1889              :         {
    1890      5194102 :           if (gimple_call_tail_p (call_stmt))
    1891          148 :             gimple_call_set_tail (call_stmt, false);
    1892      5194102 :           if (gimple_call_from_thunk_p (call_stmt))
    1893          187 :             gimple_call_set_from_thunk (call_stmt, false);
    1894              :           /* Silently clear musttail flag when inlining a function
    1895              :              with must tail call from a non-musttail call.  The inlining
    1896              :              removes one frame so acts like musttail's intent, and we
    1897              :              can be inlining a function with musttail calls in the middle
    1898              :              of caller where musttail will always error.  */
    1899      5194102 :           if (gimple_call_must_tail_p (call_stmt)
    1900           49 :               && id->call_stmt
    1901      5194143 :               && !gimple_call_must_tail_p (id->call_stmt))
    1902           14 :             gimple_call_set_must_tail (call_stmt, false);
    1903      5194102 :           if (gimple_call_internal_p (call_stmt))
    1904        61163 :             switch (gimple_call_internal_fn (call_stmt))
    1905              :               {
    1906          177 :               case IFN_GOMP_SIMD_LANE:
    1907          177 :               case IFN_GOMP_SIMD_VF:
    1908          177 :               case IFN_GOMP_SIMD_LAST_LANE:
    1909          177 :               case IFN_GOMP_SIMD_ORDERED_START:
    1910          177 :               case IFN_GOMP_SIMD_ORDERED_END:
    1911          177 :                 DECL_STRUCT_FUNCTION (id->dst_fn)->has_simduid_loops = true;
    1912          177 :                 break;
    1913              :               default:
    1914              :                 break;
    1915              :               }
    1916              :         }
    1917              : 
    1918              :       /* Remap the region numbers for __builtin_eh_{pointer,filter},
    1919              :          RESX and EH_DISPATCH.  */
    1920     32004247 :       if (id->eh_map)
    1921     32004247 :         switch (gimple_code (copy))
    1922              :           {
    1923      5194102 :           case GIMPLE_CALL:
    1924      5194102 :             {
    1925      5194102 :               tree r, fndecl = gimple_call_fndecl (copy);
    1926      5194102 :               if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
    1927      1437110 :                 switch (DECL_FUNCTION_CODE (fndecl))
    1928              :                   {
    1929            0 :                   case BUILT_IN_EH_COPY_VALUES:
    1930            0 :                     r = gimple_call_arg (copy, 1);
    1931            0 :                     r = remap_eh_region_tree_nr (r, id);
    1932            0 :                     gimple_call_set_arg (copy, 1, r);
    1933              :                     /* FALLTHRU */
    1934              : 
    1935         9713 :                   case BUILT_IN_EH_POINTER:
    1936         9713 :                   case BUILT_IN_EH_FILTER:
    1937         9713 :                     r = gimple_call_arg (copy, 0);
    1938         9713 :                     r = remap_eh_region_tree_nr (r, id);
    1939         9713 :                     gimple_call_set_arg (copy, 0, r);
    1940         9713 :                     break;
    1941              : 
    1942              :                   default:
    1943              :                     break;
    1944              :                   }
    1945              : 
    1946              :               /* Reset alias info if we didn't apply measures to
    1947              :                  keep it valid over inlining by setting DECL_PT_UID.  */
    1948      5194102 :               if (!id->src_cfun->gimple_df
    1949      5194102 :                   || !id->src_cfun->gimple_df->ipa_pta)
    1950      5186810 :                 gimple_call_reset_alias_info (as_a <gcall *> (copy));
    1951              :             }
    1952              :             break;
    1953              : 
    1954        81037 :           case GIMPLE_RESX:
    1955        81037 :             {
    1956        81037 :               gresx *resx_stmt = as_a <gresx *> (copy);
    1957        81037 :               int r = gimple_resx_region (resx_stmt);
    1958        81037 :               r = remap_eh_region_nr (r, id);
    1959        81037 :               gimple_resx_set_region (resx_stmt, r);
    1960              :             }
    1961        81037 :             break;
    1962              : 
    1963        10810 :           case GIMPLE_EH_DISPATCH:
    1964        10810 :             {
    1965        10810 :               geh_dispatch *eh_dispatch = as_a <geh_dispatch *> (copy);
    1966        10810 :               int r = gimple_eh_dispatch_region (eh_dispatch);
    1967        10810 :               r = remap_eh_region_nr (r, id);
    1968        10810 :               gimple_eh_dispatch_set_region (eh_dispatch, r);
    1969              :             }
    1970        10810 :             break;
    1971              : 
    1972              :           default:
    1973              :             break;
    1974              :           }
    1975              :     }
    1976              : 
    1977              :   /* If STMT has a block defined, map it to the newly constructed block.  */
    1978     34194204 :   if (tree block = gimple_block (copy))
    1979              :     {
    1980     30896701 :       tree *n;
    1981     30896701 :       n = id->decl_map->get (block);
    1982     30896701 :       gcc_assert (n);
    1983     30896701 :       gimple_set_block (copy, *n);
    1984              :     }
    1985     34194204 :   if (id->param_body_adjs)
    1986              :     {
    1987      3730910 :       gimple_seq extra_stmts = NULL;
    1988      3730910 :       id->param_body_adjs->modify_gimple_stmt (&copy, &extra_stmts, stmt);
    1989      3730910 :       if (!gimple_seq_empty_p (extra_stmts))
    1990              :         {
    1991           58 :           memset (&wi, 0, sizeof (wi));
    1992           58 :           wi.info = id;
    1993           58 :           for (gimple_stmt_iterator egsi = gsi_start (extra_stmts);
    1994          172 :                !gsi_end_p (egsi);
    1995          114 :                gsi_next (&egsi))
    1996          114 :             walk_gimple_op (gsi_stmt (egsi), remap_gimple_op_r, &wi);
    1997           58 :           gimple_seq_add_seq_without_update (&stmts, extra_stmts);
    1998              :         }
    1999              :     }
    2000              : 
    2001     34194204 :   if (id->reset_location)
    2002          696 :     gimple_set_location (copy, input_location);
    2003              : 
    2004              :   /* Debug statements ought to be rebuilt and not copied.  */
    2005     34194204 :   gcc_checking_assert (!is_gimple_debug (copy));
    2006              : 
    2007              :   /* Remap all the operands in COPY.  */
    2008     34194204 :   memset (&wi, 0, sizeof (wi));
    2009     34194204 :   wi.info = id;
    2010     34194204 :   if (skip_first)
    2011      2189890 :     walk_tree (gimple_op_ptr (copy, 1), remap_gimple_op_r, &wi, NULL);
    2012              :   else
    2013     32004314 :     walk_gimple_op (copy, remap_gimple_op_r, &wi);
    2014              : 
    2015              :   /* Clear the copied virtual operands.  We are not remapping them here
    2016              :      but are going to recreate them from scratch.  */
    2017     34194204 :   if (gimple_has_mem_ops (copy))
    2018              :     {
    2019     29337779 :       gimple_set_vdef (copy, NULL_TREE);
    2020     29337779 :       gimple_set_vuse (copy, NULL_TREE);
    2021              :     }
    2022              : 
    2023     34194204 :   if (cfun->can_throw_non_call_exceptions)
    2024              :     {
    2025              :       /* When inlining a function which does not have non-call exceptions
    2026              :          enabled into a function that has (which only happens with
    2027              :          always-inline) we have to fixup stmts that cannot throw.  */
    2028      1723558 :       if (gcond *cond = dyn_cast <gcond *> (copy))
    2029       209303 :         if (gimple_could_trap_p (cond))
    2030              :           {
    2031            1 :             gassign *cmp
    2032            1 :               = gimple_build_assign (make_ssa_name (boolean_type_node),
    2033              :                                      gimple_cond_code (cond),
    2034              :                                      gimple_cond_lhs (cond),
    2035              :                                      gimple_cond_rhs (cond));
    2036            1 :             gimple_seq_add_stmt_without_update (&stmts, cmp);
    2037            1 :             gimple_cond_set_code (cond, NE_EXPR);
    2038            1 :             gimple_cond_set_lhs (cond, gimple_assign_lhs (cmp));
    2039            1 :             gimple_cond_set_rhs (cond, boolean_false_node);
    2040              :           }
    2041              :     }
    2042              : 
    2043     34194204 :   gimple_seq_add_stmt_without_update (&stmts, copy);
    2044     34194204 :   return stmts;
    2045              : }
    2046              : 
    2047              : 
    2048              : /* Copy basic block, scale profile accordingly.  Edges will be taken care of
    2049              :    later  */
    2050              : 
    2051              : static basic_block
    2052     14814238 : copy_bb (copy_body_data *id, basic_block bb,
    2053              :          profile_count num, profile_count den)
    2054              : {
    2055     14814238 :   gimple_stmt_iterator gsi, copy_gsi, seq_gsi;
    2056     14814238 :   basic_block copy_basic_block;
    2057     14814238 :   tree decl;
    2058     14814238 :   basic_block prev;
    2059              : 
    2060     14814238 :   profile_count::adjust_for_ipa_scaling (&num, &den);
    2061              : 
    2062              :   /* Search for previous copied basic block.  */
    2063     14814238 :   prev = bb->prev_bb;
    2064     14976207 :   while (!prev->aux)
    2065       161969 :     prev = prev->prev_bb;
    2066              : 
    2067              :   /* create_basic_block() will append every new block to
    2068              :      basic_block_info automatically.  */
    2069     14814238 :   copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux);
    2070     14814238 :   copy_basic_block->count = bb->count.apply_scale (num, den);
    2071              : 
    2072     14814238 :   copy_gsi = gsi_start_bb (copy_basic_block);
    2073              : 
    2074     14814238 :   unsigned min_cond_uid = 0;
    2075     14814238 :   if (id->src_cfun->cond_uids)
    2076              :     {
    2077           63 :       if (!cfun->cond_uids)
    2078            7 :         cfun->cond_uids = new hash_map <gcond*, unsigned> ();
    2079              : 
    2080          193 :       for (auto itr : *id->src_cfun->cond_uids)
    2081           67 :         if (itr.second >= min_cond_uid)
    2082           67 :           min_cond_uid = itr.second + 1;
    2083              :     }
    2084              : 
    2085    128068075 :   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    2086              :     {
    2087     98439599 :       gimple_seq stmts;
    2088     98439599 :       gimple *stmt = gsi_stmt (gsi);
    2089     98439599 :       gimple *orig_stmt = stmt;
    2090     98439599 :       gimple_stmt_iterator stmts_gsi;
    2091     98439599 :       bool stmt_added = false;
    2092              : 
    2093     98439599 :       id->regimplify = false;
    2094     98439599 :       stmts = remap_gimple_stmt (stmt, id);
    2095              : 
    2096     98439599 :       if (gimple_seq_empty_p (stmts))
    2097      2444005 :         continue;
    2098              : 
    2099     95995777 :       seq_gsi = copy_gsi;
    2100              : 
    2101     95995777 :       for (stmts_gsi = gsi_start (stmts);
    2102    191991669 :            !gsi_end_p (stmts_gsi); )
    2103              :         {
    2104     95995892 :           stmt = gsi_stmt (stmts_gsi);
    2105              : 
    2106              :           /* Advance iterator now before stmt is moved to seq_gsi.  */
    2107     95995892 :           gsi_next (&stmts_gsi);
    2108              : 
    2109     95995892 :           if (gimple_nop_p (stmt))
    2110          183 :               continue;
    2111              : 
    2112              :           /* If -fcondition-coverage is used, register the inlined conditions
    2113              :              in the cond->expression mapping of the caller.  The expression tag
    2114              :              is shifted conditions from the two bodies are not mixed.  */
    2115     95995709 :           if (id->src_cfun->cond_uids && is_a <gcond*> (stmt))
    2116              :             {
    2117           19 :               gcond *orig_cond = as_a <gcond*> (orig_stmt);
    2118           19 :               gcond *cond = as_a <gcond*> (stmt);
    2119           19 :               unsigned *v = id->src_cfun->cond_uids->get (orig_cond);
    2120           19 :               if (v)
    2121           19 :                 cfun->cond_uids->put (cond, *v + min_cond_uid);
    2122              :             }
    2123              : 
    2124     95995709 :           gimple_duplicate_stmt_histograms (cfun, stmt, id->src_cfun,
    2125              :                                             orig_stmt);
    2126              : 
    2127     95995709 :           gsi_insert_after (&seq_gsi, stmt, GSI_NEW_STMT);
    2128              : 
    2129     95995709 :           if (id->regimplify)
    2130         4554 :             gimple_regimplify_operands (stmt, &seq_gsi);
    2131              : 
    2132     95995892 :           stmt_added = true;
    2133              :         }
    2134              : 
    2135     95995777 :       if (!stmt_added)
    2136          183 :         continue;
    2137              : 
    2138              :       /* If copy_basic_block has been empty at the start of this iteration,
    2139              :          call gsi_start_bb again to get at the newly added statements.  */
    2140     95995594 :       if (gsi_end_p (copy_gsi))
    2141     26190460 :         copy_gsi = gsi_start_bb (copy_basic_block);
    2142              :       else
    2143     82900364 :         gsi_next (&copy_gsi);
    2144              : 
    2145              :       /* Process the new statement.  The call to gimple_regimplify_operands
    2146              :          possibly turned the statement into multiple statements, we
    2147              :          need to process all of them.  */
    2148     95995713 :       do
    2149              :         {
    2150     95995713 :           tree fn;
    2151     95995713 :           gcall *call_stmt;
    2152              : 
    2153     95995713 :           stmt = gsi_stmt (copy_gsi);
    2154     95995713 :           call_stmt = dyn_cast <gcall *> (stmt);
    2155      5194102 :           if (call_stmt
    2156      5194102 :               && gimple_call_va_arg_pack_p (call_stmt)
    2157          324 :               && id->call_stmt
    2158          322 :               && ! gimple_call_va_arg_pack_p (id->call_stmt))
    2159              :             {
    2160              :               /* __builtin_va_arg_pack () should be replaced by
    2161              :                  all arguments corresponding to ... in the caller.  */
    2162          308 :               tree p;
    2163          308 :               gcall *new_call;
    2164          308 :               vec<tree> argarray;
    2165          308 :               size_t nargs_caller = gimple_call_num_args (id->call_stmt);
    2166          308 :               size_t nargs = nargs_caller;
    2167              : 
    2168          792 :               for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
    2169              :                 {
    2170              :                   /* Avoid crashing on invalid IL that doesn't have a
    2171              :                      varargs function or that passes not enough arguments.  */
    2172          500 :                   if (nargs == 0)
    2173              :                     break;
    2174          484 :                   nargs--;
    2175              :                 }
    2176              : 
    2177              :               /* Create the new array of arguments.  */
    2178          308 :               size_t nargs_callee = gimple_call_num_args (call_stmt);
    2179          308 :               size_t n = nargs + nargs_callee;
    2180          308 :               argarray.create (n);
    2181          308 :               argarray.safe_grow_cleared (n, true);
    2182              : 
    2183              :               /* Copy all the arguments before '...'  */
    2184          308 :               if (nargs_callee)
    2185          612 :                 memcpy (argarray.address (),
    2186          306 :                         gimple_call_arg_ptr (call_stmt, 0),
    2187              :                         nargs_callee * sizeof (tree));
    2188              : 
    2189              :               /* Append the arguments passed in '...'  */
    2190          308 :               if (nargs)
    2191          174 :                 memcpy (argarray.address () + nargs_callee,
    2192          174 :                         gimple_call_arg_ptr (id->call_stmt, 0)
    2193          174 :                         + (nargs_caller - nargs), nargs * sizeof (tree));
    2194              : 
    2195          308 :               new_call = gimple_build_call_vec (gimple_call_fn (call_stmt),
    2196              :                                                 argarray);
    2197              : 
    2198          308 :               argarray.release ();
    2199              : 
    2200              :               /* Copy all GIMPLE_CALL flags, location and block, except
    2201              :                  GF_CALL_VA_ARG_PACK.  */
    2202          308 :               gimple_call_copy_flags (new_call, call_stmt);
    2203          308 :               gimple_call_set_va_arg_pack (new_call, false);
    2204          616 :               gimple_call_set_fntype (new_call, gimple_call_fntype (call_stmt));
    2205              :               /* location includes block.  */
    2206          308 :               gimple_set_location (new_call, gimple_location (stmt));
    2207          308 :               gimple_call_set_lhs (new_call, gimple_call_lhs (call_stmt));
    2208              : 
    2209          308 :               gsi_replace (&copy_gsi, new_call, false);
    2210          308 :               stmt = new_call;
    2211              :             }
    2212     95995405 :           else if (call_stmt
    2213      5193794 :                    && id->call_stmt
    2214      4220963 :                    && (decl = gimple_call_fndecl (stmt))
    2215    100081939 :                    && fndecl_built_in_p (decl, BUILT_IN_VA_ARG_PACK_LEN))
    2216              :             {
    2217              :               /* __builtin_va_arg_pack_len () should be replaced by
    2218              :                  the number of anonymous arguments.  */
    2219          147 :               size_t nargs = gimple_call_num_args (id->call_stmt);
    2220          147 :               tree count, p;
    2221          147 :               gimple *new_stmt;
    2222              : 
    2223          423 :               for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
    2224          276 :                 nargs--;
    2225              : 
    2226          147 :               if (!gimple_call_lhs (stmt))
    2227              :                 {
    2228              :                   /* Drop unused calls.  */
    2229            1 :                   gsi_remove (&copy_gsi, false);
    2230            1 :                   continue;
    2231              :                 }
    2232          146 :               else if (!gimple_call_va_arg_pack_p (id->call_stmt))
    2233              :                 {
    2234          124 :                   count = build_int_cst (integer_type_node, nargs);
    2235          124 :                   new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count);
    2236          124 :                   gsi_replace (&copy_gsi, new_stmt, false);
    2237          124 :                   stmt = new_stmt;
    2238              :                 }
    2239           22 :               else if (nargs != 0)
    2240              :                 {
    2241            7 :                   tree newlhs = make_ssa_name (integer_type_node);
    2242            7 :                   count = build_int_cst (integer_type_node, nargs);
    2243            7 :                   new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
    2244              :                                                   PLUS_EXPR, newlhs, count);
    2245            7 :                   gimple_call_set_lhs (stmt, newlhs);
    2246            7 :                   gsi_insert_after (&copy_gsi, new_stmt, GSI_NEW_STMT);
    2247              :                 }
    2248              :             }
    2249     95995258 :           else if (call_stmt
    2250      5193647 :                    && id->call_stmt
    2251    100216074 :                    && gimple_call_internal_p (stmt))
    2252        46755 :             switch (gimple_call_internal_fn (stmt))
    2253              :               {
    2254          154 :               case IFN_TSAN_FUNC_EXIT:
    2255              :                 /* Drop .TSAN_FUNC_EXIT () internal calls during inlining.  */
    2256          154 :                 gsi_remove (&copy_gsi, false);
    2257          154 :                 continue;
    2258         1396 :               case IFN_ASAN_MARK:
    2259              :                 /* Drop .ASAN_MARK internal calls during inlining into
    2260              :                    no_sanitize functions.  */
    2261         1396 :                 if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn)
    2262         1396 :                     && !sanitize_flags_p (SANITIZE_HWADDRESS, id->dst_fn))
    2263              :                   {
    2264           14 :                     gsi_remove (&copy_gsi, false);
    2265           14 :                     continue;
    2266              :                   }
    2267              :                 break;
    2268              :               default:
    2269              :                 break;
    2270              :               }
    2271              : 
    2272              :           /* Statements produced by inlining can be unfolded, especially
    2273              :              when we constant propagated some operands.  We can't fold
    2274              :              them right now for two reasons:
    2275              :              1) folding require SSA_NAME_DEF_STMTs to be correct
    2276              :              2) we can't change function calls to builtins.
    2277              :              So we just mark statement for later folding.  We mark
    2278              :              all new statements, instead just statements that has changed
    2279              :              by some nontrivial substitution so even statements made
    2280              :              foldable indirectly are updated.  If this turns out to be
    2281              :              expensive, copy_body can be told to watch for nontrivial
    2282              :              changes.  */
    2283     95995544 :           if (id->statements_to_fold)
    2284     95995544 :             id->statements_to_fold->add (stmt);
    2285              : 
    2286              :           /* We're duplicating a CALL_EXPR.  Find any corresponding
    2287              :              callgraph edges and update or duplicate them.  */
    2288     95995544 :           if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
    2289              :             {
    2290      5193809 :               struct cgraph_edge *edge;
    2291              : 
    2292      5193809 :               switch (id->transform_call_graph_edges)
    2293              :                 {
    2294      4220978 :                 case CB_CGE_DUPLICATE:
    2295      4220978 :                   edge = id->src_node->get_edge (orig_stmt);
    2296      4220978 :                   if (edge)
    2297              :                     {
    2298      4174394 :                       struct cgraph_edge *old_edge = edge;
    2299              : 
    2300              :                       /* A speculative call is consist of multiple
    2301              :                          edges - indirect edge and one or more direct edges
    2302              :                          Duplicate the whole thing and distribute frequencies
    2303              :                          accordingly.  */
    2304      4174394 :                       if (edge->speculative)
    2305              :                         {
    2306        20223 :                           int n = 0;
    2307        20223 :                           profile_count direct_cnt
    2308        20223 :                                  = profile_count::zero ();
    2309              : 
    2310              :                           /* First figure out the distribution of counts
    2311              :                              so we can re-scale BB profile accordingly.  */
    2312        47334 :                           for (cgraph_edge *e = old_edge; e;
    2313        27111 :                                e = e->next_speculative_call_target ())
    2314        27111 :                             direct_cnt = direct_cnt + e->count;
    2315              : 
    2316        20223 :                           cgraph_edge *indirect
    2317        20223 :                                  = old_edge->speculative_call_indirect_edge ();
    2318        20223 :                           profile_count indir_cnt = indirect->count;
    2319              : 
    2320              :                           /* Next iterate all direct edges, clone it and its
    2321              :                              corresponding reference and update profile.  */
    2322        20223 :                           for (cgraph_edge *e = old_edge;
    2323        47334 :                                e;
    2324        27111 :                                e = e->next_speculative_call_target ())
    2325              :                             {
    2326        27111 :                               profile_count cnt = e->count;
    2327              : 
    2328        27111 :                               id->dst_node->clone_reference
    2329        27111 :                                  (e->speculative_call_target_ref (), stmt);
    2330        27111 :                               edge = e->clone (id->dst_node, call_stmt,
    2331              :                                                gimple_uid (stmt), num, den,
    2332              :                                                true);
    2333        27111 :                               profile_probability prob
    2334        27111 :                                  = cnt.probability_in (direct_cnt
    2335              :                                                        + indir_cnt);
    2336        27111 :                               edge->count
    2337              :                                  = copy_basic_block->count.apply_probability
    2338        27111 :                                          (prob);
    2339        27111 :                               n++;
    2340              :                             }
    2341        20223 :                           gcc_checking_assert
    2342              :                                  (indirect->num_speculative_call_targets_p ()
    2343              :                                   == n);
    2344              : 
    2345              :                           /* Duplicate the indirect edge after all direct edges
    2346              :                              cloned.  */
    2347        20223 :                           indirect = indirect->clone (id->dst_node, call_stmt,
    2348              :                                                       gimple_uid (stmt),
    2349              :                                                       num, den,
    2350              :                                                       true);
    2351              : 
    2352        20223 :                           profile_probability prob
    2353        20223 :                              = indir_cnt.probability_in (direct_cnt
    2354              :                                                          + indir_cnt);
    2355        20223 :                           indirect->count
    2356        20223 :                              = copy_basic_block->count.apply_probability (prob);
    2357              :                         }
    2358              :                       /* If edge is a callback-carrying edge, copy all its
    2359              :                          attached edges as well.  */
    2360      4154171 :                       else if (edge->has_callback)
    2361              :                         {
    2362         2434 :                           edge
    2363         2434 :                             = edge->clone (id->dst_node, call_stmt,
    2364              :                                            gimple_uid (stmt), num, den, true);
    2365         2434 :                           cgraph_edge *e;
    2366         2896 :                           for (e = old_edge->first_callback_edge (); e;
    2367          462 :                                e = e->next_callback_edge ())
    2368          462 :                             edge = e->clone (id->dst_node, call_stmt,
    2369              :                                              gimple_uid (stmt), num, den, true);
    2370              :                         }
    2371              :                       else
    2372              :                         {
    2373      4151737 :                           edge = edge->clone (id->dst_node, call_stmt,
    2374              :                                               gimple_uid (stmt),
    2375              :                                               num, den,
    2376              :                                               true);
    2377      4151737 :                           edge->count = copy_basic_block->count;
    2378              :                         }
    2379              :                     }
    2380              :                   break;
    2381              : 
    2382       776033 :                 case CB_CGE_MOVE_CLONES:
    2383       776033 :                   id->dst_node->set_call_stmt_including_clones (orig_stmt,
    2384              :                                                                 call_stmt);
    2385       776033 :                   edge = id->dst_node->get_edge (stmt);
    2386       776033 :                   break;
    2387              : 
    2388       196798 :                 case CB_CGE_MOVE:
    2389       196798 :                   edge = id->dst_node->get_edge (orig_stmt);
    2390       196798 :                   if (edge)
    2391       196420 :                     edge = cgraph_edge::set_call_stmt (edge, call_stmt);
    2392              :                   break;
    2393              : 
    2394            0 :                 default:
    2395            0 :                   gcc_unreachable ();
    2396              :                 }
    2397              : 
    2398              :               /* Constant propagation on argument done during inlining
    2399              :                  may create new direct call.  Produce an edge for it.  */
    2400      4151737 :               if ((!edge
    2401      5034172 :                    || (edge->indirect_inlining_edge
    2402         4028 :                        && id->transform_call_graph_edges == CB_CGE_MOVE_CLONES))
    2403       160129 :                   && id->dst_node->definition
    2404      1055473 :                   && (fn = gimple_call_fndecl (stmt)) != NULL)
    2405              :                 {
    2406            0 :                   struct cgraph_node *dest = cgraph_node::get_create (fn);
    2407              : 
    2408              :                   /* We have missing edge in the callgraph.  This can happen
    2409              :                      when previous inlining turned an indirect call into a
    2410              :                      direct call by constant propagating arguments or we are
    2411              :                      producing dead clone (for further cloning).  In all
    2412              :                      other cases we hit a bug (incorrect node sharing is the
    2413              :                      most common reason for missing edges).  */
    2414            0 :                   gcc_assert (!dest->definition
    2415              :                               || dest->address_taken
    2416              :                               || !id->src_node->definition
    2417              :                               || !id->dst_node->definition);
    2418            0 :                   if (id->transform_call_graph_edges == CB_CGE_MOVE_CLONES)
    2419            0 :                     id->dst_node->create_edge_including_clones
    2420            0 :                       (dest, orig_stmt, call_stmt, bb->count,
    2421              :                        CIF_ORIGINALLY_INDIRECT_CALL);
    2422              :                   else
    2423            0 :                     id->dst_node->create_edge (dest, call_stmt,
    2424              :                                         bb->count)->inline_failed
    2425            0 :                       = CIF_ORIGINALLY_INDIRECT_CALL;
    2426            0 :                   if (dump_file)
    2427              :                     {
    2428            0 :                       fprintf (dump_file, "Created new direct edge to %s\n",
    2429              :                                dest->dump_name ());
    2430              :                     }
    2431              :                 }
    2432              : 
    2433      5193809 :               notice_special_calls (as_a <gcall *> (stmt));
    2434              :             }
    2435              : 
    2436     95995544 :           maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt,
    2437              :                                       id->eh_map, id->eh_lp_nr);
    2438              : 
    2439     95995544 :           gsi_next (&copy_gsi);
    2440              :         }
    2441     95995713 :       while (!gsi_end_p (copy_gsi));
    2442              : 
    2443    191991188 :       copy_gsi = gsi_last_bb (copy_basic_block);
    2444              :     }
    2445              : 
    2446     14814238 :   return copy_basic_block;
    2447              : }
    2448              : 
    2449              : /* Inserting Single Entry Multiple Exit region in SSA form into code in SSA
    2450              :    form is quite easy, since dominator relationship for old basic blocks does
    2451              :    not change.
    2452              : 
    2453              :    There is however exception where inlining might change dominator relation
    2454              :    across EH edges from basic block within inlined functions destinating
    2455              :    to landing pads in function we inline into.
    2456              : 
    2457              :    The function fills in PHI_RESULTs of such PHI nodes if they refer
    2458              :    to gimple regs.  Otherwise, the function mark PHI_RESULT of such
    2459              :    PHI nodes for renaming.  For non-gimple regs, renaming is safe: the
    2460              :    EH edges are abnormal and SSA_NAME_OCCURS_IN_ABNORMAL_PHI must be
    2461              :    set, and this means that there will be no overlapping live ranges
    2462              :    for the underlying symbol.
    2463              : 
    2464              :    This might change in future if we allow redirecting of EH edges and
    2465              :    we might want to change way build CFG pre-inlining to include
    2466              :    all the possible edges then.  */
    2467              : static void
    2468       782313 : update_ssa_across_abnormal_edges (basic_block bb, basic_block ret_bb,
    2469              :                                   bool can_throw, bool nonlocal_goto)
    2470              : {
    2471       782313 :   edge e;
    2472       782313 :   edge_iterator ei;
    2473              : 
    2474      2158170 :   FOR_EACH_EDGE (e, ei, bb->succs)
    2475      1375857 :     if (!e->dest->aux
    2476       752001 :         || ((basic_block)e->dest->aux)->index == ENTRY_BLOCK)
    2477              :       {
    2478       623856 :         gphi *phi;
    2479       623856 :         gphi_iterator si;
    2480              : 
    2481       623856 :         if (!nonlocal_goto)
    2482       623418 :           gcc_assert (e->flags & EDGE_EH);
    2483              : 
    2484       623856 :         if (!can_throw)
    2485          229 :           gcc_assert (!(e->flags & EDGE_EH));
    2486              : 
    2487      1039315 :         for (si = gsi_start_phis (e->dest); !gsi_end_p (si); gsi_next (&si))
    2488              :           {
    2489       415459 :             edge re;
    2490              : 
    2491       415459 :             phi = si.phi ();
    2492              : 
    2493              :             /* For abnormal goto/call edges the receiver can be the
    2494              :                ENTRY_BLOCK.  Do not assert this cannot happen.  */
    2495              : 
    2496       415459 :             gcc_assert ((e->flags & EDGE_EH)
    2497              :                         || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)));
    2498              : 
    2499       415459 :             re = find_edge (ret_bb, e->dest);
    2500       415459 :             gcc_checking_assert (re);
    2501       415459 :             gcc_assert ((re->flags & (EDGE_EH | EDGE_ABNORMAL))
    2502              :                         == (e->flags & (EDGE_EH | EDGE_ABNORMAL)));
    2503              : 
    2504       415459 :             SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e),
    2505              :                      USE_FROM_PTR (PHI_ARG_DEF_PTR_FROM_EDGE (phi, re)));
    2506              :           }
    2507              :       }
    2508       782313 : }
    2509              : 
    2510              : /* Insert clobbers for automatic variables of inlined ID->src_fn
    2511              :    function at the start of basic block ID->eh_landing_pad_dest.  */
    2512              : 
    2513              : static void
    2514       452471 : add_clobbers_to_eh_landing_pad (copy_body_data *id)
    2515              : {
    2516       452471 :   tree var;
    2517       452471 :   basic_block bb = id->eh_landing_pad_dest;
    2518       452471 :   live_vars_map *vars = NULL;
    2519       452471 :   unsigned int cnt = 0;
    2520       452471 :   unsigned int i;
    2521      1562613 :   FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
    2522       700530 :     if (VAR_P (var)
    2523       700530 :         && !DECL_HARD_REGISTER (var)
    2524       700530 :         && !TREE_THIS_VOLATILE (var)
    2525       700510 :         && !DECL_HAS_VALUE_EXPR_P (var)
    2526       691534 :         && !is_gimple_reg (var)
    2527       298692 :         && auto_var_in_fn_p (var, id->src_fn)
    2528       996884 :         && !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var)))
    2529              :       {
    2530       296354 :         tree *t = id->decl_map->get (var);
    2531       296354 :         if (!t)
    2532            0 :           continue;
    2533       296354 :         tree new_var = *t;
    2534       296354 :         if (VAR_P (new_var)
    2535       296354 :             && !DECL_HARD_REGISTER (new_var)
    2536       296354 :             && !TREE_THIS_VOLATILE (new_var)
    2537       296354 :             && !DECL_HAS_VALUE_EXPR_P (new_var)
    2538       296354 :             && !is_gimple_reg (new_var)
    2539       592708 :             && auto_var_in_fn_p (new_var, id->dst_fn))
    2540              :           {
    2541       296354 :             if (vars == NULL)
    2542       185472 :               vars = new live_vars_map;
    2543       296354 :             vars->put (DECL_UID (var), cnt++);
    2544              :           }
    2545              :       }
    2546       452471 :   if (vars == NULL)
    2547       266999 :     return;
    2548              : 
    2549       185472 :   vec<bitmap_head> live = compute_live_vars (id->src_cfun, vars);
    2550      1074152 :   FOR_EACH_VEC_SAFE_ELT (id->src_cfun->local_decls, i, var)
    2551       517736 :     if (VAR_P (var))
    2552              :       {
    2553       517736 :         edge e;
    2554       517736 :         edge_iterator ei;
    2555       517736 :         bool needed = false;
    2556       517736 :         unsigned int *v = vars->get (DECL_UID (var));
    2557       517736 :         if (v == NULL)
    2558       221382 :           continue;
    2559      5304631 :         FOR_EACH_EDGE (e, ei, bb->preds)
    2560      5172484 :           if ((e->flags & EDGE_EH) != 0
    2561      5172444 :               && e->src->index >= id->add_clobbers_to_eh_landing_pads)
    2562              :             {
    2563       487028 :               basic_block src_bb = (basic_block) e->src->aux;
    2564              : 
    2565       487028 :               if (bitmap_bit_p (&live[src_bb->index], *v))
    2566              :                 {
    2567              :                   needed = true;
    2568              :                   break;
    2569              :                 }
    2570              :             }
    2571       296354 :         if (needed)
    2572              :           {
    2573       164207 :             tree new_var = *id->decl_map->get (var);
    2574       164207 :             gimple_stmt_iterator gsi = gsi_after_labels (bb);
    2575       164207 :             tree clobber = build_clobber (TREE_TYPE (new_var));
    2576       164207 :             gimple *clobber_stmt = gimple_build_assign (new_var, clobber);
    2577       164207 :             gsi_insert_before (&gsi, clobber_stmt, GSI_NEW_STMT);
    2578              :           }
    2579              :       }
    2580       185472 :   destroy_live_vars (live);
    2581       185472 :   delete vars;
    2582              : }
    2583              : 
    2584              : /* Copy edges from BB into its copy constructed earlier, scale profile
    2585              :    accordingly.  Edges will be taken care of later.  Assume aux
    2586              :    pointers to point to the copies of each BB.  Return true if any
    2587              :    debug stmts are left after a statement that must end the basic block.  */
    2588              : 
    2589              : static bool
    2590     24488358 : copy_edges_for_bb (basic_block bb, profile_count num, profile_count den,
    2591              :                    basic_block ret_bb, basic_block abnormal_goto_dest,
    2592              :                    copy_body_data *id)
    2593              : {
    2594     24488358 :   basic_block new_bb = (basic_block) bb->aux;
    2595     24488358 :   edge_iterator ei;
    2596     24488358 :   edge old_edge;
    2597     24488358 :   gimple_stmt_iterator si;
    2598     24488358 :   bool need_debug_cleanup = false;
    2599              : 
    2600              :   /* Use the indices from the original blocks to create edges for the
    2601              :      new ones.  */
    2602     47420803 :   FOR_EACH_EDGE (old_edge, ei, bb->succs)
    2603     22932445 :     if (!(old_edge->flags & EDGE_EH))
    2604              :       {
    2605     22773678 :         edge new_edge;
    2606     22773678 :         int flags = old_edge->flags;
    2607     22773678 :         location_t locus = old_edge->goto_locus;
    2608              : 
    2609              :         /* Return edges do get a FALLTHRU flag when they get inlined.  */
    2610     22773678 :         if (old_edge->dest->index == EXIT_BLOCK
    2611      4835627 :             && !(flags & (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE|EDGE_FAKE))
    2612      4835627 :             && old_edge->dest->aux != EXIT_BLOCK_PTR_FOR_FN (cfun))
    2613      4598020 :           flags |= EDGE_FALLTHRU;
    2614              : 
    2615     22773678 :         new_edge
    2616     22773678 :           = make_edge (new_bb, (basic_block) old_edge->dest->aux, flags);
    2617     22773678 :         new_edge->probability = old_edge->probability;
    2618     22773678 :         if (!id->reset_location)
    2619     22773290 :           new_edge->goto_locus = remap_location (locus, id);
    2620              :       }
    2621              : 
    2622     24488358 :   if (bb->index == ENTRY_BLOCK || bb->index == EXIT_BLOCK)
    2623              :     return false;
    2624              : 
    2625              :   /* When doing function splitting, we must decrease count of the return block
    2626              :      which was previously reachable by block we did not copy.  */
    2627     14814238 :   if (single_succ_p (bb) && single_succ_edge (bb)->dest->index == EXIT_BLOCK)
    2628     11501994 :     FOR_EACH_EDGE (old_edge, ei, bb->preds)
    2629      6666367 :       if (old_edge->src->index != ENTRY_BLOCK
    2630      3827530 :           && !old_edge->src->aux)
    2631        47055 :         new_bb->count -= old_edge->count ().apply_scale (num, den);
    2632              : 
    2633              :   /* Walk stmts from end to start so that splitting will adjust the BB
    2634              :      pointer for each stmt at most once, even when we split the block
    2635              :      multiple times.  */
    2636     14814238 :   bool seen_nondebug = false;
    2637    125624027 :   for (si = gsi_last_bb (new_bb); !gsi_end_p (si);)
    2638              :     {
    2639     95995551 :       bool can_throw, nonlocal_goto;
    2640     95995551 :       gimple *copy_stmt = gsi_stmt (si);
    2641              : 
    2642              :       /* Do this before the possible split_block.  */
    2643     95995551 :       gsi_prev (&si);
    2644              : 
    2645              :       /* If this tree could throw an exception, there are two
    2646              :          cases where we need to add abnormal edge(s): the
    2647              :          tree wasn't in a region and there is a "current
    2648              :          region" in the caller; or the original tree had
    2649              :          EH edges.  In both cases split the block after the tree,
    2650              :          and add abnormal edge(s) as needed; we need both
    2651              :          those from the callee and the caller.
    2652              :          We check whether the copy can throw, because the const
    2653              :          propagation can change an INDIRECT_REF which throws
    2654              :          into a COMPONENT_REF which doesn't.  If the copy
    2655              :          can throw, the original could also throw.  */
    2656     95995551 :       can_throw = stmt_can_throw_internal (cfun, copy_stmt);
    2657     95995551 :       nonlocal_goto
    2658     95995551 :         = (stmt_can_make_abnormal_goto (copy_stmt)
    2659     95995551 :            && !computed_goto_p (copy_stmt));
    2660              : 
    2661     95995055 :       if (can_throw || nonlocal_goto)
    2662              :         {
    2663              :           /* If there's only debug insns after copy_stmt don't split
    2664              :              the block but instead mark the block for cleanup.  */
    2665       782451 :           if (!seen_nondebug)
    2666              :             need_debug_cleanup = true;
    2667              :           else
    2668              :             {
    2669              :               /* Note that bb's predecessor edges aren't necessarily
    2670              :                  right at this point; split_block doesn't care.  */
    2671       290441 :               edge e = split_block (new_bb, copy_stmt);
    2672       290441 :               e->dest->aux = new_bb->aux;
    2673       290441 :               seen_nondebug = false;
    2674              :             }
    2675              :         }
    2676              : 
    2677     95995551 :       if (!is_gimple_debug (copy_stmt))
    2678     34193978 :         seen_nondebug = true;
    2679              : 
    2680     95995551 :       bool update_probs = false;
    2681              : 
    2682     95995551 :       if (gimple_code (copy_stmt) == GIMPLE_EH_DISPATCH)
    2683              :         {
    2684        10810 :           make_eh_dispatch_edges (as_a <geh_dispatch *> (copy_stmt));
    2685        10810 :           update_probs = true;
    2686              :         }
    2687     95984741 :       else if (can_throw)
    2688              :         {
    2689       782084 :           make_eh_edge (copy_stmt);
    2690       782084 :           update_probs = true;
    2691              :         }
    2692              : 
    2693              :       /* EH edges may not match old edges.  Copy as much as possible.  */
    2694       792894 :       if (update_probs)
    2695              :         {
    2696       792894 :           edge e;
    2697       792894 :           edge_iterator ei;
    2698       792894 :           basic_block copy_stmt_bb = gimple_bb (copy_stmt);
    2699              : 
    2700      1596586 :           FOR_EACH_EDGE (old_edge, ei, bb->succs)
    2701       803692 :             if ((old_edge->flags & EDGE_EH)
    2702       167720 :                 && (e = find_edge (copy_stmt_bb,
    2703       167720 :                                    (basic_block) old_edge->dest->aux))
    2704       962258 :                 && (e->flags & EDGE_EH))
    2705       158566 :               e->probability = old_edge->probability;
    2706              : 
    2707      2180692 :           FOR_EACH_EDGE (e, ei, copy_stmt_bb->succs)
    2708      1387798 :             if (e->flags & EDGE_EH)
    2709              :               {
    2710       782084 :                 if (!e->probability.initialized_p ())
    2711       623904 :                   e->probability = profile_probability::never ();
    2712       782084 :                 if (e->dest->index < id->add_clobbers_to_eh_landing_pads)
    2713              :                   {
    2714       622483 :                     if (id->eh_landing_pad_dest == NULL)
    2715       452471 :                       id->eh_landing_pad_dest = e->dest;
    2716              :                     else
    2717       170012 :                       gcc_assert (id->eh_landing_pad_dest == e->dest);
    2718              :                   }
    2719              :               }
    2720              :         }
    2721              : 
    2722              : 
    2723              :       /* If the call we inline cannot make abnormal goto do not add
    2724              :          additional abnormal edges but only retain those already present
    2725              :          in the original function body.  */
    2726     95995551 :       if (abnormal_goto_dest == NULL)
    2727              :         nonlocal_goto = false;
    2728         1101 :       if (nonlocal_goto)
    2729              :         {
    2730          338 :           basic_block copy_stmt_bb = gimple_bb (copy_stmt);
    2731              : 
    2732          338 :           if (get_abnormal_succ_dispatcher (copy_stmt_bb))
    2733              :             nonlocal_goto = false;
    2734              :           /* ABNORMAL_DISPATCHER (1) is for longjmp/setjmp or nonlocal gotos
    2735              :              in OpenMP regions which aren't allowed to be left abnormally.
    2736              :              So, no need to add abnormal edge in that case.  */
    2737          338 :           else if (is_gimple_call (copy_stmt)
    2738          338 :                    && gimple_call_internal_p (copy_stmt)
    2739            0 :                    && (gimple_call_internal_fn (copy_stmt)
    2740              :                        == IFN_ABNORMAL_DISPATCHER)
    2741          338 :                    && gimple_call_arg (copy_stmt, 0) == boolean_true_node)
    2742              :             nonlocal_goto = false;
    2743              :           else
    2744              :             {
    2745          338 :               make_single_succ_edge (copy_stmt_bb, abnormal_goto_dest,
    2746              :                                      EDGE_ABNORMAL);
    2747          338 :               gimple_call_set_ctrl_altering (copy_stmt, true);
    2748          338 :               if (is_a <gcall *> (copy_stmt)
    2749          338 :                   && (gimple_call_flags (copy_stmt) & ECF_NORETURN))
    2750           78 :                 fixup_noreturn_call (copy_stmt);
    2751              :             }
    2752              :         }
    2753              : 
    2754     95995551 :       if ((can_throw || nonlocal_goto)
    2755     96777864 :           && gimple_in_ssa_p (cfun))
    2756       782313 :         update_ssa_across_abnormal_edges (gimple_bb (copy_stmt), ret_bb,
    2757              :                                           can_throw, nonlocal_goto);
    2758              :     }
    2759              :   return need_debug_cleanup;
    2760              : }
    2761              : 
    2762              : /* Copy the PHIs.  All blocks and edges are copied, some blocks
    2763              :    was possibly split and new outgoing EH edges inserted.
    2764              :    BB points to the block of original function and AUX pointers links
    2765              :    the original and newly copied blocks.  */
    2766              : 
    2767              : static void
    2768     24488358 : copy_phis_for_bb (basic_block bb, copy_body_data *id)
    2769              : {
    2770     24488358 :   basic_block const new_bb = (basic_block) bb->aux;
    2771     24488358 :   edge_iterator ei;
    2772     24488358 :   gphi *phi;
    2773     24488358 :   gphi_iterator si;
    2774     24488358 :   edge new_edge;
    2775     24488358 :   bool inserted = false;
    2776              : 
    2777     27565839 :   for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
    2778              :     {
    2779      3077481 :       tree res, new_res;
    2780      3077481 :       gphi *new_phi;
    2781              : 
    2782      3077481 :       phi = si.phi ();
    2783      3077481 :       res = PHI_RESULT (phi);
    2784      3077481 :       new_res = res;
    2785      3077481 :       if (!virtual_operand_p (res)
    2786      3077481 :           && (!id->param_body_adjs
    2787      3077481 :               || !id->param_body_adjs->m_dead_stmts.contains (phi)))
    2788              :         {
    2789      1715088 :           walk_tree (&new_res, copy_tree_body_r, id, NULL);
    2790      1715088 :           if (EDGE_COUNT (new_bb->preds) == 0)
    2791              :             {
    2792              :               /* Technically we'd want a SSA_DEFAULT_DEF here... */
    2793            0 :               SSA_NAME_DEF_STMT (new_res) = gimple_build_nop ();
    2794              :             }
    2795              :           else
    2796              :             {
    2797      1715088 :               new_phi = create_phi_node (new_res, new_bb);
    2798      5626194 :               FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
    2799              :                 {
    2800      3911106 :                   edge old_edge = find_edge ((basic_block) new_edge->src->aux,
    2801      3911106 :                                              bb);
    2802      3911106 :                   tree arg;
    2803      3911106 :                   tree new_arg;
    2804      3911106 :                   edge_iterator ei2;
    2805      3911106 :                   location_t locus;
    2806              : 
    2807              :                   /* When doing partial cloning, we allow PHIs on the entry
    2808              :                      block as long as all the arguments are the same.
    2809              :                      Find any input edge to see argument to copy.  */
    2810      3911106 :                   if (!old_edge)
    2811         2053 :                     FOR_EACH_EDGE (old_edge, ei2, bb->preds)
    2812         2053 :                       if (!old_edge->src->aux)
    2813              :                         break;
    2814              : 
    2815      3911106 :                   arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge);
    2816      3911106 :                   new_arg = arg;
    2817      3911106 :                   walk_tree (&new_arg, copy_tree_body_r, id, NULL);
    2818      3911106 :                   gcc_assert (new_arg);
    2819              :                   /* With return slot optimization we can end up with
    2820              :                      non-gimple (foo *)&this->m, fix that here.  */
    2821      3911106 :                   if (TREE_CODE (new_arg) != SSA_NAME
    2822      1591037 :                       && TREE_CODE (new_arg) != FUNCTION_DECL
    2823      5502143 :                       && !is_gimple_val (new_arg))
    2824              :                     {
    2825           12 :                       gimple_seq stmts = NULL;
    2826           12 :                       new_arg = force_gimple_operand (new_arg, &stmts, true,
    2827              :                                                       NULL);
    2828           12 :                       gsi_insert_seq_on_edge (new_edge, stmts);
    2829           12 :                       inserted = true;
    2830              :                     }
    2831      3911106 :                   locus = gimple_phi_arg_location_from_edge (phi, old_edge);
    2832      3911106 :                   if (id->reset_location)
    2833            0 :                     locus = input_location;
    2834              :                   else
    2835      3911106 :                     locus = remap_location (locus, id);
    2836      3911106 :                   add_phi_arg (new_phi, new_arg, new_edge, locus);
    2837              :                 }
    2838              :             }
    2839              :         }
    2840              :     }
    2841              : 
    2842              :   /* Commit the delayed edge insertions.  */
    2843     24488358 :   if (inserted)
    2844           36 :     FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
    2845           24 :       gsi_commit_one_edge_insert (new_edge, NULL);
    2846     24488358 : }
    2847              : 
    2848              : 
    2849              : /* Wrapper for remap_decl so it can be used as a callback.  */
    2850              : 
    2851              : static tree
    2852       103896 : remap_decl_1 (tree decl, void *data)
    2853              : {
    2854       103896 :   return remap_decl (decl, (copy_body_data *) data);
    2855              : }
    2856              : 
    2857              : /* Build struct function and associated datastructures for the new clone
    2858              :    NEW_FNDECL to be build.  CALLEE_FNDECL is the original.  Function changes
    2859              :    the cfun to the function of new_fndecl (and current_function_decl too).  */
    2860              : 
    2861              : static void
    2862       253052 : initialize_cfun (tree new_fndecl, tree callee_fndecl, profile_count count)
    2863              : {
    2864       253052 :   struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
    2865              : 
    2866              :   /* Register specific tree functions.  */
    2867       253052 :   gimple_register_cfg_hooks ();
    2868              : 
    2869              :   /* Get clean struct function.  */
    2870       253052 :   push_struct_function (new_fndecl, true);
    2871       253052 :   targetm.target_option.relayout_function (new_fndecl);
    2872              : 
    2873              :   /* We will rebuild these, so just sanity check that they are empty.  */
    2874       253052 :   gcc_assert (VALUE_HISTOGRAMS (cfun) == NULL);
    2875       253052 :   gcc_assert (cfun->local_decls == NULL);
    2876       253052 :   gcc_assert (cfun->cfg == NULL);
    2877       253052 :   gcc_assert (cfun->decl == new_fndecl);
    2878              : 
    2879              :   /* Copy items we preserve during cloning.  */
    2880       253052 :   cfun->static_chain_decl = src_cfun->static_chain_decl;
    2881       253052 :   cfun->nonlocal_goto_save_area = src_cfun->nonlocal_goto_save_area;
    2882       253052 :   cfun->function_end_locus = src_cfun->function_end_locus;
    2883       253052 :   cfun->curr_properties = src_cfun->curr_properties;
    2884       253052 :   cfun->va_list_gpr_size = src_cfun->va_list_gpr_size;
    2885       253052 :   cfun->va_list_fpr_size = src_cfun->va_list_fpr_size;
    2886       253052 :   cfun->has_nonlocal_label = src_cfun->has_nonlocal_label;
    2887       253052 :   cfun->calls_eh_return = src_cfun->calls_eh_return;
    2888       253052 :   cfun->stdarg = src_cfun->stdarg;
    2889       253052 :   cfun->after_inlining = src_cfun->after_inlining;
    2890       253052 :   cfun->can_throw_non_call_exceptions
    2891       253052 :     = src_cfun->can_throw_non_call_exceptions;
    2892       253052 :   cfun->can_delete_dead_exceptions = src_cfun->can_delete_dead_exceptions;
    2893       253052 :   cfun->returns_struct = src_cfun->returns_struct;
    2894       253052 :   cfun->returns_pcc_struct = src_cfun->returns_pcc_struct;
    2895       253052 :   cfun->assume_function = src_cfun->assume_function;
    2896              : 
    2897       253052 :   init_empty_tree_cfg ();
    2898              : 
    2899       253052 :   profile_status_for_fn (cfun) = profile_status_for_fn (src_cfun);
    2900       253052 :   cfun->cfg->full_profile = src_cfun->cfg->full_profile;
    2901              : 
    2902       253052 :   profile_count num = count;
    2903       253052 :   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
    2904       253052 :   profile_count::adjust_for_ipa_scaling (&num, &den);
    2905              : 
    2906       253052 :   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count =
    2907       253052 :     ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (num, den);
    2908       253052 :   EXIT_BLOCK_PTR_FOR_FN (cfun)->count =
    2909       253052 :     EXIT_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (num, den);
    2910       253052 :   if (src_cfun->eh)
    2911       253052 :     init_eh_for_function ();
    2912              : 
    2913       253052 :   if (src_cfun->gimple_df)
    2914              :     {
    2915       253052 :       init_tree_ssa (cfun);
    2916       253052 :       cfun->gimple_df->in_ssa_p = src_cfun->gimple_df->in_ssa_p;
    2917       253052 :       if (cfun->gimple_df->in_ssa_p)
    2918       253052 :         init_ssa_operands (cfun);
    2919              :     }
    2920       253052 : }
    2921              : 
    2922              : /* Helper function for copy_cfg_body.  Move debug stmts from the end
    2923              :    of NEW_BB to the beginning of successor basic blocks when needed.  If the
    2924              :    successor has multiple predecessors, reset them, otherwise keep
    2925              :    their value.  */
    2926              : 
    2927              : static void
    2928      1638492 : maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb)
    2929              : {
    2930      1638492 :   edge e;
    2931      1638492 :   edge_iterator ei;
    2932      1638492 :   gimple_stmt_iterator si = gsi_last_nondebug_bb (new_bb);
    2933              : 
    2934      1638492 :   if (gsi_end_p (si)
    2935      1724970 :       || gsi_one_before_end_p (si)
    2936      1839369 :       || !(stmt_can_throw_internal (cfun, gsi_stmt (si))
    2937        86479 :            || stmt_can_make_abnormal_goto (gsi_stmt (si))))
    2938      1610572 :     return;
    2939              : 
    2940        83762 :   FOR_EACH_EDGE (e, ei, new_bb->succs)
    2941              :     {
    2942        55842 :       gimple_stmt_iterator ssi = gsi_last_bb (new_bb);
    2943        55842 :       gimple_stmt_iterator dsi = gsi_after_labels (e->dest);
    2944       176199 :       while (is_gimple_debug (gsi_stmt (ssi)))
    2945              :         {
    2946       120357 :           gimple *stmt = gsi_stmt (ssi);
    2947       120357 :           gdebug *new_stmt;
    2948       120357 :           tree var;
    2949       120357 :           tree value;
    2950              : 
    2951              :           /* For the last edge move the debug stmts instead of copying
    2952              :              them.  */
    2953       120357 :           if (ei_one_before_end_p (ei))
    2954              :             {
    2955        60177 :               si = ssi;
    2956        60177 :               gsi_prev (&ssi);
    2957        60177 :               if (!single_pred_p (e->dest) && gimple_debug_bind_p (stmt))
    2958              :                 {
    2959        58656 :                   gimple_debug_bind_reset_value (stmt);
    2960       116670 :                   gimple_set_location (stmt, UNKNOWN_LOCATION);
    2961              :                 }
    2962        60177 :               gsi_remove (&si, false);
    2963        60177 :               gsi_insert_before (&dsi, stmt, GSI_NEW_STMT);
    2964        60177 :               continue;
    2965              :             }
    2966              : 
    2967        60180 :           if (gimple_debug_bind_p (stmt))
    2968              :             {
    2969        58659 :               var = gimple_debug_bind_get_var (stmt);
    2970        58659 :               if (single_pred_p (e->dest))
    2971              :                 {
    2972        48944 :                   value = gimple_debug_bind_get_value (stmt);
    2973        48944 :                   value = unshare_expr (value);
    2974        48944 :                   new_stmt = gimple_build_debug_bind (var, value, stmt);
    2975              :                 }
    2976              :               else
    2977         9715 :                 new_stmt = gimple_build_debug_bind (var, NULL_TREE, NULL);
    2978              :             }
    2979         1521 :           else if (gimple_debug_source_bind_p (stmt))
    2980              :             {
    2981            0 :               var = gimple_debug_source_bind_get_var (stmt);
    2982            0 :               value = gimple_debug_source_bind_get_value (stmt);
    2983            0 :               new_stmt = gimple_build_debug_source_bind (var, value, stmt);
    2984              :             }
    2985         1521 :           else if (gimple_debug_nonbind_marker_p (stmt))
    2986         1521 :             new_stmt = as_a <gdebug *> (gimple_copy (stmt));
    2987              :           else
    2988            0 :             gcc_unreachable ();
    2989        60180 :           gsi_insert_before (&dsi, new_stmt, GSI_NEW_STMT);
    2990        60180 :           id->debug_stmts.safe_push (new_stmt);
    2991        60180 :           gsi_prev (&ssi);
    2992              :         }
    2993              :     }
    2994              : }
    2995              : 
    2996              : /* Make a copy of the sub-loops of SRC_PARENT and place them
    2997              :    as siblings of DEST_PARENT.  */
    2998              : 
    2999              : static void
    3000      5512825 : copy_loops (copy_body_data *id,
    3001              :             class loop *dest_parent, class loop *src_parent)
    3002              : {
    3003      5512825 :   class loop *src_loop = src_parent->inner;
    3004      6140426 :   while (src_loop)
    3005              :     {
    3006       627601 :       if (!id->blocks_to_copy
    3007       627601 :           || bitmap_bit_p (id->blocks_to_copy, src_loop->header->index))
    3008              :         {
    3009       623454 :           class loop *dest_loop = alloc_loop ();
    3010              : 
    3011              :           /* Assign the new loop its header and latch and associate
    3012              :              those with the new loop.  */
    3013       623454 :           dest_loop->header = (basic_block)src_loop->header->aux;
    3014       623454 :           dest_loop->header->loop_father = dest_loop;
    3015       623454 :           if (src_loop->latch != NULL)
    3016              :             {
    3017       623438 :               dest_loop->latch = (basic_block)src_loop->latch->aux;
    3018       623438 :               dest_loop->latch->loop_father = dest_loop;
    3019              :             }
    3020              : 
    3021              :           /* Copy loop meta-data.  */
    3022       623454 :           copy_loop_info (src_loop, dest_loop);
    3023       623454 :           if (dest_loop->unroll)
    3024         2177 :             cfun->has_unroll = true;
    3025       623454 :           if (dest_loop->force_vectorize)
    3026          175 :             cfun->has_force_vectorize_loops = true;
    3027       623454 :           if (id->src_cfun->last_clique != 0)
    3028        82722 :             dest_loop->owned_clique
    3029        82722 :               = remap_dependence_clique (id,
    3030        82722 :                                          src_loop->owned_clique
    3031              :                                          ? src_loop->owned_clique : 1);
    3032              : 
    3033              :           /* Finally place it into the loop array and the loop tree.  */
    3034       623454 :           place_new_loop (cfun, dest_loop);
    3035       623454 :           flow_loop_tree_node_add (dest_parent, dest_loop);
    3036              : 
    3037       623454 :           if (src_loop->simduid)
    3038              :             {
    3039           75 :               dest_loop->simduid = remap_decl (src_loop->simduid, id);
    3040           75 :               cfun->has_simduid_loops = true;
    3041              :             }
    3042              : 
    3043              :           /* Recurse.  */
    3044       623454 :           copy_loops (id, dest_loop, src_loop);
    3045              :         }
    3046       627601 :       src_loop = src_loop->next;
    3047              :     }
    3048      5512825 : }
    3049              : 
    3050              : /* Call redirect_call_stmt_to_callee on all calls in BB.  */
    3051              : 
    3052              : void
    3053     13242159 : redirect_all_calls (copy_body_data * id, basic_block bb)
    3054              : {
    3055     13242159 :   gimple_stmt_iterator si;
    3056     13242159 :   gimple *last = last_nondebug_stmt (bb);
    3057    108973373 :   for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
    3058              :     {
    3059     82489055 :       gimple *stmt = gsi_stmt (si);
    3060     82489055 :       if (is_gimple_call (stmt))
    3061              :         {
    3062      4275200 :           struct cgraph_edge *edge = id->dst_node->get_edge (stmt);
    3063      4275200 :           if (edge)
    3064              :             {
    3065      4228616 :               if (!id->killed_new_ssa_names)
    3066      2253231 :                 id->killed_new_ssa_names = new hash_set<tree> (16);
    3067      4228616 :               cgraph_edge::redirect_call_stmt_to_callee (
    3068              :                 edge, id->killed_new_ssa_names);
    3069      4228616 :               if (edge->has_callback)
    3070              :                 {
    3071              :                   /* When redirecting a carrying edge, we need to redirect its
    3072              :                      attached edges as well.  */
    3073         2434 :                   cgraph_edge *cbe;
    3074         2896 :                   for (cbe = edge->first_callback_edge (); cbe;
    3075          462 :                        cbe = cbe->next_callback_edge ())
    3076          462 :                     cgraph_edge::redirect_call_stmt_to_callee (
    3077              :                       cbe, id->killed_new_ssa_names);
    3078              :                 }
    3079              : 
    3080      4228616 :               if (stmt == last && id->call_stmt && maybe_clean_eh_stmt (stmt))
    3081        59632 :                 gimple_purge_dead_eh_edges (bb);
    3082              :             }
    3083              :         }
    3084              :     }
    3085     13242159 : }
    3086              : 
    3087              : /* Make a copy of the body of FN so that it can be inserted inline in
    3088              :    another function.  Walks FN via CFG, returns new fndecl.  */
    3089              : 
    3090              : static tree
    3091      4889371 : copy_cfg_body (copy_body_data * id,
    3092              :                basic_block entry_block_map, basic_block exit_block_map,
    3093              :                basic_block new_entry)
    3094              : {
    3095      4889371 :   tree callee_fndecl = id->src_fn;
    3096              :   /* Original cfun for the callee, doesn't change.  */
    3097      4889371 :   struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
    3098      4889371 :   struct function *cfun_to_copy;
    3099      4889371 :   basic_block bb;
    3100      4889371 :   tree new_fndecl = NULL;
    3101      4889371 :   bool need_debug_cleanup = false;
    3102      4889371 :   int last;
    3103      4889371 :   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
    3104      4889371 :   profile_count num = entry_block_map->count;
    3105              : 
    3106      4889371 :   cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
    3107              : 
    3108              :   /* Register specific tree functions.  */
    3109      4889371 :   gimple_register_cfg_hooks ();
    3110              : 
    3111              :   /* If we are offlining region of the function, make sure to connect
    3112              :      new entry to ENTRY_BLOCK_PTR_FOR_FN (cfun).  Since new entry can be
    3113              :      part of loop, we must compute frequency and probability of
    3114              :      ENTRY_BLOCK_PTR_FOR_FN (cfun) based on the frequencies and
    3115              :      probabilities of edges incoming from nonduplicated region.  */
    3116      4889371 :   if (new_entry)
    3117              :     {
    3118        52311 :       edge e;
    3119        52311 :       edge_iterator ei;
    3120        52311 :       ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();
    3121              : 
    3122       112694 :       FOR_EACH_EDGE (e, ei, new_entry->preds)
    3123        60383 :         if (!e->src->aux)
    3124        60383 :           ENTRY_BLOCK_PTR_FOR_FN (cfun)->count += e->count ();
    3125              :       /* Do not scale - the profile of offlined region should
    3126              :          remain unchanged.  */
    3127        52311 :       num = den = profile_count::one ();
    3128              :     }
    3129              : 
    3130      4889371 :   profile_count::adjust_for_ipa_scaling (&num, &den);
    3131              : 
    3132              :   /* Must have a CFG here at this point.  */
    3133      4889371 :   gcc_assert (ENTRY_BLOCK_PTR_FOR_FN
    3134              :               (DECL_STRUCT_FUNCTION (callee_fndecl)));
    3135              : 
    3136              : 
    3137      4889371 :   ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = entry_block_map;
    3138      4889371 :   EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = exit_block_map;
    3139      4889371 :   entry_block_map->aux = ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy);
    3140      4889371 :   exit_block_map->aux = EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy);
    3141              : 
    3142              :   /* Duplicate any exception-handling regions.  */
    3143      4889371 :   if (cfun->eh)
    3144      4889371 :     id->eh_map = duplicate_eh_regions (cfun_to_copy, NULL, id->eh_lp_nr,
    3145              :                                        remap_decl_1, id);
    3146              : 
    3147              :   /* Use aux pointers to map the original blocks to copy.  */
    3148     19886084 :   FOR_EACH_BB_FN (bb, cfun_to_copy)
    3149     14996713 :     if (!id->blocks_to_copy || bitmap_bit_p (id->blocks_to_copy, bb->index))
    3150              :       {
    3151     14814238 :         basic_block new_bb = copy_bb (id, bb, num, den);
    3152     14814238 :         bb->aux = new_bb;
    3153     14814238 :         new_bb->aux = bb;
    3154     14814238 :         new_bb->loop_father = entry_block_map->loop_father;
    3155              :       }
    3156              : 
    3157      4889371 :   last = last_basic_block_for_fn (cfun);
    3158              : 
    3159              :   /* Now that we've duplicated the blocks, duplicate their edges.  */
    3160      4889371 :   basic_block abnormal_goto_dest = NULL;
    3161      4889371 :   if (id->call_stmt
    3162      4889371 :       && stmt_can_make_abnormal_goto (id->call_stmt))
    3163              :     {
    3164          327 :       gimple_stmt_iterator gsi = gsi_for_stmt (id->call_stmt);
    3165              : 
    3166          327 :       bb = gimple_bb (id->call_stmt);
    3167          327 :       gsi_next (&gsi);
    3168          327 :       if (gsi_end_p (gsi))
    3169          327 :         abnormal_goto_dest = get_abnormal_succ_dispatcher (bb);
    3170              :     }
    3171     29664826 :   FOR_ALL_BB_FN (bb, cfun_to_copy)
    3172     24775455 :     if (!id->blocks_to_copy
    3173     24775455 :         || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
    3174     24488358 :       need_debug_cleanup |= copy_edges_for_bb (bb, num, den, exit_block_map,
    3175              :                                                abnormal_goto_dest, id);
    3176              : 
    3177      4889371 :   if (id->eh_landing_pad_dest)
    3178              :     {
    3179       452471 :       add_clobbers_to_eh_landing_pad (id);
    3180       452471 :       id->eh_landing_pad_dest = NULL;
    3181              :     }
    3182              : 
    3183      4889371 :   if (new_entry)
    3184              :     {
    3185        52311 :       edge e = make_edge (entry_block_map, (basic_block)new_entry->aux,
    3186              :                           EDGE_FALLTHRU);
    3187        52311 :       e->probability = profile_probability::always ();
    3188              :     }
    3189              : 
    3190              :   /* Duplicate the loop tree, if available and wanted.  */
    3191      4889371 :   if (loops_for_fn (src_cfun) != NULL
    3192      4889371 :       && current_loops != NULL)
    3193              :     {
    3194      4889371 :       copy_loops (id, entry_block_map->loop_father,
    3195              :                   get_loop (src_cfun, 0));
    3196              :       /* Defer to cfgcleanup to update loop-father fields of basic-blocks.  */
    3197      4889371 :       loops_state_set (LOOPS_NEED_FIXUP);
    3198              :     }
    3199              : 
    3200              :   /* If the loop tree in the source function needed fixup, mark the
    3201              :      destination loop tree for fixup, too.  */
    3202      4889371 :   if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
    3203            0 :     loops_state_set (LOOPS_NEED_FIXUP);
    3204              : 
    3205      4889371 :   if (gimple_in_ssa_p (cfun))
    3206     29664826 :     FOR_ALL_BB_FN (bb, cfun_to_copy)
    3207     24775455 :       if (!id->blocks_to_copy
    3208     24775455 :           || (bb->index > 0 && bitmap_bit_p (id->blocks_to_copy, bb->index)))
    3209     24488358 :         copy_phis_for_bb (bb, id);
    3210              : 
    3211     29664826 :   FOR_ALL_BB_FN (bb, cfun_to_copy)
    3212     24775455 :     if (bb->aux)
    3213              :       {
    3214     24592980 :         if (need_debug_cleanup
    3215      2154463 :             && bb->index != ENTRY_BLOCK
    3216      1836192 :             && bb->index != EXIT_BLOCK)
    3217      1517921 :           maybe_move_debug_stmts_to_successors (id, (basic_block) bb->aux);
    3218              :         /* Update call edge destinations.  This cannot be done before loop
    3219              :            info is updated, because we may split basic blocks.  */
    3220     24592980 :         if (id->transform_call_graph_edges == CB_CGE_DUPLICATE
    3221     22143023 :             && bb->index != ENTRY_BLOCK
    3222     17506704 :             && bb->index != EXIT_BLOCK)
    3223     12870385 :           redirect_all_calls (id, (basic_block)bb->aux);
    3224     24592980 :         ((basic_block)bb->aux)->aux = NULL;
    3225     24592980 :         bb->aux = NULL;
    3226              :       }
    3227              : 
    3228              :   /* Zero out AUX fields of newly created block during EH edge
    3229              :      insertion. */
    3230      5261145 :   for (; last < last_basic_block_for_fn (cfun); last++)
    3231              :     {
    3232       371774 :       if (need_debug_cleanup)
    3233       120571 :         maybe_move_debug_stmts_to_successors (id,
    3234       120571 :                                               BASIC_BLOCK_FOR_FN (cfun, last));
    3235       371774 :       BASIC_BLOCK_FOR_FN (cfun, last)->aux = NULL;
    3236              :       /* Update call edge destinations.  This cannot be done before loop
    3237              :          info is updated, because we may split basic blocks.  */
    3238       371774 :       if (id->transform_call_graph_edges == CB_CGE_DUPLICATE)
    3239       371774 :         redirect_all_calls (id, BASIC_BLOCK_FOR_FN (cfun, last));
    3240              :     }
    3241      4889371 :   entry_block_map->aux = NULL;
    3242      4889371 :   exit_block_map->aux = NULL;
    3243              : 
    3244      4889371 :   if (id->eh_map)
    3245              :     {
    3246      4889371 :       delete id->eh_map;
    3247      4889371 :       id->eh_map = NULL;
    3248              :     }
    3249      4889371 :   if (id->dependence_map)
    3250              :     {
    3251       736569 :       delete id->dependence_map;
    3252       736569 :       id->dependence_map = NULL;
    3253              :     }
    3254              : 
    3255      4889371 :   return new_fndecl;
    3256              : }
    3257              : 
    3258              : /* Copy the debug STMT using ID.  We deal with these statements in a
    3259              :    special way: if any variable in their VALUE expression wasn't
    3260              :    remapped yet, we won't remap it, because that would get decl uids
    3261              :    out of sync, causing codegen differences between -g and -g0.  If
    3262              :    this arises, we drop the VALUE expression altogether.  */
    3263              : 
    3264              : static void
    3265     61861753 : copy_debug_stmt (gdebug *stmt, copy_body_data *id)
    3266              : {
    3267     61861753 :   tree t, *n;
    3268     61861753 :   struct walk_stmt_info wi;
    3269              : 
    3270     61861753 :   if (tree block = gimple_block (stmt))
    3271              :     {
    3272     40483399 :       n = id->decl_map->get (block);
    3273     40483399 :       gimple_set_block (stmt, n ? *n : id->block);
    3274              :     }
    3275              : 
    3276     61861753 :   if (gimple_debug_nonbind_marker_p (stmt))
    3277              :     {
    3278     13949902 :       if (id->call_stmt && !gimple_block (stmt))
    3279              :         {
    3280        37406 :           gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    3281        37406 :           gsi_remove (&gsi, true);
    3282              :         }
    3283     13949902 :       return;
    3284              :     }
    3285              : 
    3286              :   /* Remap all the operands in COPY.  */
    3287     47911851 :   memset (&wi, 0, sizeof (wi));
    3288     47911851 :   wi.info = id;
    3289              : 
    3290     47911851 :   processing_debug_stmt = 1;
    3291              : 
    3292     47911851 :   if (gimple_debug_source_bind_p (stmt))
    3293       558735 :     t = gimple_debug_source_bind_get_var (stmt);
    3294     47353116 :   else if (gimple_debug_bind_p (stmt))
    3295     47353116 :     t = gimple_debug_bind_get_var (stmt);
    3296              :   else
    3297            0 :     gcc_unreachable ();
    3298              : 
    3299     47911851 :   if (TREE_CODE (t) == PARM_DECL
    3300       311358 :       && id->debug_map
    3301     47913711 :       && (n = id->debug_map->get (t)))
    3302              :     {
    3303            0 :       gcc_assert (VAR_P (*n));
    3304            0 :       t = *n;
    3305              :     }
    3306     47911851 :   else if (VAR_P (t) && !is_global_var (t) && !id->decl_map->get (t))
    3307              :     /* T is a non-localized variable.  */;
    3308              :   else
    3309     41395677 :     walk_tree (&t, remap_gimple_op_r, &wi, NULL);
    3310              : 
    3311     47911851 :   if (gimple_debug_bind_p (stmt))
    3312              :     {
    3313     47353116 :       gimple_debug_bind_set_var (stmt, t);
    3314              : 
    3315     47353116 :       if (gimple_debug_bind_has_value_p (stmt))
    3316     26930991 :         walk_tree (gimple_debug_bind_get_value_ptr (stmt),
    3317              :                    remap_gimple_op_r, &wi, NULL);
    3318              : 
    3319              :       /* Punt if any decl couldn't be remapped.  */
    3320     47353116 :       if (processing_debug_stmt < 0)
    3321       676566 :         gimple_debug_bind_reset_value (stmt);
    3322              :     }
    3323       558735 :   else if (gimple_debug_source_bind_p (stmt))
    3324              :     {
    3325       558735 :       gimple_debug_source_bind_set_var (stmt, t);
    3326              :       /* When inlining and source bind refers to one of the optimized
    3327              :          away parameters, change the source bind into normal debug bind
    3328              :          referring to the corresponding DEBUG_EXPR_DECL that should have
    3329              :          been bound before the call stmt.  */
    3330       558735 :       t = gimple_debug_source_bind_get_value (stmt);
    3331       558735 :       if (t != NULL_TREE
    3332       558735 :           && TREE_CODE (t) == PARM_DECL
    3333       424933 :           && id->call_stmt)
    3334              :         {
    3335       419814 :           vec<tree, va_gc> **debug_args = decl_debug_args_lookup (id->src_fn);
    3336       419814 :           unsigned int i;
    3337       419814 :           if (debug_args != NULL)
    3338              :             {
    3339       530250 :               for (i = 0; i < vec_safe_length (*debug_args); i += 2)
    3340       530249 :                 if ((**debug_args)[i] == DECL_ORIGIN (t)
    3341       530249 :                     && TREE_CODE ((**debug_args)[i + 1]) == DEBUG_EXPR_DECL)
    3342              :                   {
    3343       414144 :                     t = (**debug_args)[i + 1];
    3344       414144 :                     stmt->subcode = GIMPLE_DEBUG_BIND;
    3345       414144 :                     gimple_debug_bind_set_value (stmt, t);
    3346       414144 :                     break;
    3347              :                   }
    3348              :             }
    3349              :         }
    3350       558735 :       if (gimple_debug_source_bind_p (stmt))
    3351       144591 :         walk_tree (gimple_debug_source_bind_get_value_ptr (stmt),
    3352              :                    remap_gimple_op_r, &wi, NULL);
    3353              :     }
    3354              : 
    3355     47911851 :   processing_debug_stmt = 0;
    3356              : 
    3357     47911851 :   update_stmt (stmt);
    3358              : }
    3359              : 
    3360              : /* Process deferred debug stmts.  In order to give values better odds
    3361              :    of being successfully remapped, we delay the processing of debug
    3362              :    stmts until all other stmts that might require remapping are
    3363              :    processed.  */
    3364              : 
    3365              : static void
    3366      4889371 : copy_debug_stmts (copy_body_data *id)
    3367              : {
    3368      4889371 :   if (!id->debug_stmts.exists ())
    3369              :     return;
    3370              : 
    3371     64948794 :   for (gdebug *stmt : id->debug_stmts)
    3372              :     /* But avoid re-processing debug stmts that have been elided.  */
    3373     61861753 :     if (gimple_bb (stmt))
    3374     61861753 :       copy_debug_stmt (stmt, id);
    3375              : 
    3376      3087041 :   id->debug_stmts.release ();
    3377              : }
    3378              : 
    3379              : /* Make a copy of the body of SRC_FN so that it can be inserted inline in
    3380              :    another function.  */
    3381              : 
    3382              : static tree
    3383     31004672 : copy_tree_body (copy_body_data *id)
    3384              : {
    3385     31004672 :   tree fndecl = id->src_fn;
    3386     31004672 :   tree body = DECL_SAVED_TREE (fndecl);
    3387              : 
    3388     31004672 :   walk_tree (&body, copy_tree_body_r, id, NULL);
    3389              : 
    3390     31004672 :   return body;
    3391              : }
    3392              : 
    3393              : /* Make a copy of the body of FN so that it can be inserted inline in
    3394              :    another function.  */
    3395              : 
    3396              : static tree
    3397      4889371 : copy_body (copy_body_data *id,
    3398              :            basic_block entry_block_map, basic_block exit_block_map,
    3399              :            basic_block new_entry)
    3400              : {
    3401      4889371 :   tree fndecl = id->src_fn;
    3402      4889371 :   tree body;
    3403              : 
    3404              :   /* If this body has a CFG, walk CFG and copy.  */
    3405      4889371 :   gcc_assert (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (fndecl)));
    3406      4889371 :   body = copy_cfg_body (id, entry_block_map, exit_block_map,
    3407              :                         new_entry);
    3408      4889371 :   copy_debug_stmts (id);
    3409      4889371 :   if (id->killed_new_ssa_names)
    3410              :     {
    3411      2253231 :       ipa_release_ssas_in_hash (id->killed_new_ssa_names);
    3412      4506462 :       delete id->killed_new_ssa_names;
    3413      2253231 :       id->killed_new_ssa_names = NULL;
    3414              :     }
    3415              : 
    3416      4889371 :   return body;
    3417              : }
    3418              : 
    3419              : /* Return true if VALUE is an ADDR_EXPR of an automatic variable
    3420              :    defined in function FN, or of a data member thereof.  */
    3421              : 
    3422              : static bool
    3423       168173 : self_inlining_addr_expr (tree value, tree fn)
    3424              : {
    3425       168173 :   tree var;
    3426              : 
    3427       168173 :   if (TREE_CODE (value) != ADDR_EXPR)
    3428              :     return false;
    3429              : 
    3430       160632 :   var = get_base_address (TREE_OPERAND (value, 0));
    3431              : 
    3432       160632 :   return var && auto_var_in_fn_p (var, fn);
    3433              : }
    3434              : 
    3435              : /* Append to BB a debug annotation that binds VAR to VALUE, inheriting
    3436              :    lexical block and line number information from base_stmt, if given,
    3437              :    or from the last stmt of the block otherwise.  */
    3438              : 
    3439              : static gimple *
    3440      7958642 : insert_init_debug_bind (copy_body_data *id,
    3441              :                         basic_block bb, tree var, tree value,
    3442              :                         gimple *base_stmt)
    3443              : {
    3444      7958642 :   gimple *note;
    3445      7958642 :   gimple_stmt_iterator gsi;
    3446      7958642 :   tree tracked_var;
    3447              : 
    3448      7958642 :   if (!gimple_in_ssa_p (id->src_cfun))
    3449              :     return NULL;
    3450              : 
    3451      7958642 :   if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
    3452              :     return NULL;
    3453              : 
    3454      7023583 :   tracked_var = target_for_debug_bind (var);
    3455      7023583 :   if (!tracked_var)
    3456              :     return NULL;
    3457              : 
    3458      6356630 :   if (bb)
    3459              :     {
    3460      6349047 :       gsi = gsi_last_bb (bb);
    3461      6349047 :       if (!base_stmt && !gsi_end_p (gsi))
    3462              :         base_stmt = gsi_stmt (gsi);
    3463              :     }
    3464              : 
    3465      6356630 :   note = gimple_build_debug_bind (tracked_var,
    3466      6356630 :                                   value == error_mark_node
    3467      6356630 :                                   ? NULL_TREE : unshare_expr (value),
    3468              :                                   base_stmt);
    3469              : 
    3470      6356630 :   if (bb)
    3471              :     {
    3472      6349047 :       if (!gsi_end_p (gsi))
    3473      5509647 :         gsi_insert_after (&gsi, note, GSI_SAME_STMT);
    3474              :       else
    3475       839400 :         gsi_insert_before (&gsi, note, GSI_SAME_STMT);
    3476              :     }
    3477              : 
    3478              :   return note;
    3479              : }
    3480              : 
    3481              : static void
    3482       484634 : insert_init_stmt (copy_body_data *id, basic_block bb, gimple *init_stmt)
    3483              : {
    3484              :   /* If VAR represents a zero-sized variable, it's possible that the
    3485              :      assignment statement may result in no gimple statements.  */
    3486       484634 :   if (init_stmt)
    3487              :     {
    3488       484634 :       gimple_stmt_iterator si = gsi_last_bb (bb);
    3489              : 
    3490              :       /* We can end up with init statements that store to a non-register
    3491              :          from a rhs with a conversion.  Handle that here by forcing the
    3492              :          rhs into a temporary.  gimple_regimplify_operands is not
    3493              :          prepared to do this for us.  */
    3494       484634 :       if (!is_gimple_debug (init_stmt)
    3495       477051 :           && !is_gimple_reg (gimple_assign_lhs (init_stmt))
    3496       368374 :           && is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (init_stmt)))
    3497       510910 :           && gimple_assign_rhs_class (init_stmt) == GIMPLE_UNARY_RHS)
    3498              :         {
    3499            2 :           tree rhs = build1 (gimple_assign_rhs_code (init_stmt),
    3500            1 :                              TREE_TYPE (gimple_assign_lhs (init_stmt)),
    3501              :                              gimple_assign_rhs1 (init_stmt));
    3502            1 :           rhs = force_gimple_operand_gsi (&si, rhs, true, NULL_TREE, false,
    3503              :                                           GSI_NEW_STMT);
    3504            1 :           gimple_assign_set_rhs_code (init_stmt, TREE_CODE (rhs));
    3505            1 :           gimple_assign_set_rhs1 (init_stmt, rhs);
    3506              :         }
    3507       484634 :       gsi_insert_after (&si, init_stmt, GSI_NEW_STMT);
    3508       484634 :       if (!is_gimple_debug (init_stmt))
    3509              :         {
    3510       477051 :           gimple_regimplify_operands (init_stmt, &si);
    3511              : 
    3512       477051 :           tree def = gimple_assign_lhs (init_stmt);
    3513       477051 :           insert_init_debug_bind (id, bb, def, def, init_stmt);
    3514              :         }
    3515              :     }
    3516       484634 : }
    3517              : 
    3518              : /* Deal with mismatched formal/actual parameters, in a rather brute-force way
    3519              :    if need be (which should only be necessary for invalid programs).  Attempt
    3520              :    to convert VAL to TYPE and return the result if it is possible, just return
    3521              :    a zero constant of the given type if it fails.  */
    3522              : 
    3523              : tree
    3524          968 : force_value_to_type (tree type, tree value)
    3525              : {
    3526              :   /* If we can match up types by promotion/demotion do so.  */
    3527          968 :   if (fold_convertible_p (type, value))
    3528          541 :     return fold_convert (type, value);
    3529              : 
    3530              :   /* ???  For valid programs we should not end up here.
    3531              :      Still if we end up with truly mismatched types here, fall back
    3532              :      to using a VIEW_CONVERT_EXPR or a literal zero to not leak invalid
    3533              :      GIMPLE to the following passes.  */
    3534          427 :   if (TREE_CODE (value) == WITH_SIZE_EXPR)
    3535            0 :     return error_mark_node;
    3536          427 :   else if (!is_gimple_reg_type (TREE_TYPE (value))
    3537          427 :            || TYPE_SIZE (type) == TYPE_SIZE (TREE_TYPE (value)))
    3538          136 :     return fold_build1 (VIEW_CONVERT_EXPR, type, value);
    3539              :   else
    3540          291 :     return build_zero_cst (type);
    3541              : }
    3542              : 
    3543              : /* Initialize parameter P with VALUE.  If needed, produce init statement
    3544              :    at the end of BB.  When BB is NULL, we return init statement to be
    3545              :    output later.  */
    3546              : static gimple *
    3547      7948442 : setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
    3548              :                      basic_block bb, tree *vars)
    3549              : {
    3550      7948442 :   gimple *init_stmt = NULL;
    3551      7948442 :   tree var;
    3552      7948442 :   tree def = (gimple_in_ssa_p (cfun)
    3553      7948442 :               ? ssa_default_def (id->src_cfun, p) : NULL);
    3554              : 
    3555              :   /* Make an equivalent VAR_DECL.  Note that we must NOT remap the type
    3556              :      here since the type of this decl must be visible to the calling
    3557              :      function.  */
    3558      7948442 :   var = copy_decl_to_var (p, id);
    3559              : 
    3560              :   /* Declare this new variable.  */
    3561      7948442 :   DECL_CHAIN (var) = *vars;
    3562      7948442 :   *vars = var;
    3563              : 
    3564              :   /* Make gimplifier happy about this variable.  */
    3565      7948442 :   DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
    3566              : 
    3567              :   /* If the parameter is never assigned to, has no SSA_NAMEs created,
    3568              :      we would not need to create a new variable here at all, if it
    3569              :      weren't for debug info.  Still, we can just use the argument
    3570              :      value.  */
    3571      7948442 :   if (TREE_READONLY (p)
    3572      4207314 :       && !TREE_ADDRESSABLE (p)
    3573      4206323 :       && value
    3574      4206315 :       && !TREE_SIDE_EFFECTS (value)
    3575     12154751 :       && !def)
    3576              :     {
    3577              :       /* We may produce non-gimple trees by adding NOPs or introduce invalid
    3578              :          sharing when the value is not constant or DECL.  And we need to make
    3579              :          sure that it cannot be modified from another path in the callee.  */
    3580       380559 :       if (((is_gimple_min_invariant (value)
    3581              :             /* When the parameter is used in a context that forces it to
    3582              :                not be a GIMPLE register avoid substituting something that
    3583              :                is not a decl there.  */
    3584       167723 :             && ! DECL_NOT_GIMPLE_REG_P (p))
    3585       212847 :            || (DECL_P (value) && TREE_READONLY (value))
    3586       212763 :            || (auto_var_in_fn_p (value, id->dst_fn)
    3587          385 :                && !TREE_ADDRESSABLE (value)))
    3588       168178 :           && useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value))
    3589              :           /* We have to be very careful about ADDR_EXPR.  Make sure
    3590              :              the base variable isn't a local variable of the inlined
    3591              :              function, e.g., when doing recursive inlining, direct or
    3592              :              mutually-recursive or whatever, which is why we don't
    3593              :              just test whether fn == current_function_decl.  */
    3594       548732 :           && ! self_inlining_addr_expr (value, fn))
    3595              :         {
    3596       168173 :           insert_decl_map (id, p, value);
    3597       168173 :           if (!id->debug_map)
    3598       162438 :             id->debug_map = new hash_map<tree, tree>;
    3599       168173 :           id->debug_map->put (p, var);
    3600       168173 :           return insert_init_debug_bind (id, bb, var, value, NULL);
    3601              :         }
    3602              :     }
    3603              : 
    3604              :   /* Register the VAR_DECL as the equivalent for the PARM_DECL;
    3605              :      that way, when the PARM_DECL is encountered, it will be
    3606              :      automatically replaced by the VAR_DECL.  */
    3607      7780269 :   insert_decl_map (id, p, var);
    3608              : 
    3609              :   /* Even if P was TREE_READONLY, the new VAR should not be.  In the original
    3610              :      code, we would have constructed a temporary, and then the function body
    3611              :      would have never changed the value of P.  However, now, we will be
    3612              :      constructing VAR directly.  Therefore, it must not be TREE_READONLY.  */
    3613      7780269 :   TREE_READONLY (var) = 0;
    3614              : 
    3615      7780269 :   tree rhs = value;
    3616      7780269 :   if (value
    3617      7779334 :       && value != error_mark_node
    3618     15559603 :       && !useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value)))
    3619          957 :     rhs = force_value_to_type (TREE_TYPE (p), value);
    3620              : 
    3621              :   /* If there is no setup required and we are in SSA, take the easy route
    3622              :      replacing all SSA names representing the function parameter by the
    3623              :      SSA name passed to function.
    3624              : 
    3625              :      We need to construct map for the variable anyway as it might be used
    3626              :      in different SSA names when parameter is set in function.
    3627              : 
    3628              :      Do replacement at -O0 for const arguments replaced by constant.
    3629              :      This is important for builtin_constant_p and other construct requiring
    3630              :      constant argument to be visible in inlined function body.  */
    3631     15560538 :   if (gimple_in_ssa_p (cfun) && rhs && def && is_gimple_reg (p)
    3632      6981638 :       && (optimize
    3633        26333 :           || (TREE_READONLY (p)
    3634        12598 :               && is_gimple_min_invariant (rhs)))
    3635      6958955 :       && (TREE_CODE (rhs) == SSA_NAME
    3636      2610877 :           || is_gimple_min_invariant (rhs))
    3637      6958681 :       && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
    3638              :     {
    3639      6958681 :       insert_decl_map (id, def, rhs);
    3640      6958681 :       return insert_init_debug_bind (id, bb, var, rhs, NULL);
    3641              :     }
    3642              : 
    3643              :   /* If the value of argument is never used, don't care about initializing
    3644              :      it.  */
    3645      1617012 :   if (optimize && gimple_in_ssa_p (cfun) && !def && is_gimple_reg (p))
    3646              :     {
    3647              :       /* When there's a gross type mismatch between the passed value
    3648              :          and the declared argument type drop it on the floor and do
    3649              :          not bother to insert a debug bind.  */
    3650       354751 :       if (value && !is_gimple_reg_type (TREE_TYPE (value)))
    3651              :         return NULL;
    3652       354737 :       return insert_init_debug_bind (id, bb, var, rhs, NULL);
    3653              :     }
    3654              : 
    3655              :   /* Initialize this VAR_DECL from the equivalent argument.  Convert
    3656              :      the argument to the proper type in case it was promoted.  */
    3657       466837 :   if (value)
    3658              :     {
    3659       466748 :       if (rhs == error_mark_node)
    3660              :         {
    3661            0 :           insert_decl_map (id, p, var);
    3662            0 :           return insert_init_debug_bind (id, bb, var, rhs, NULL);
    3663              :         }
    3664              : 
    3665       466748 :       STRIP_USELESS_TYPE_CONVERSION (rhs);
    3666              : 
    3667              :       /* If we are in SSA form properly remap the default definition.  */
    3668       933496 :       if (gimple_in_ssa_p (cfun) && is_gimple_reg (p))
    3669              :         {
    3670        25583 :           if (def)
    3671              :             {
    3672        22957 :               def = remap_ssa_name (def, id);
    3673        22957 :               init_stmt = gimple_build_assign (def, rhs);
    3674        22957 :               SSA_NAME_IS_DEFAULT_DEF (def) = 0;
    3675        22957 :               set_ssa_default_def (cfun, var, NULL);
    3676              :             }
    3677              :         }
    3678       441165 :       else if (!is_empty_type (TREE_TYPE (var)))
    3679       368374 :         init_stmt = gimple_build_assign (var, rhs);
    3680              : 
    3681       466748 :       if (bb && init_stmt)
    3682       391035 :         insert_init_stmt (id, bb, init_stmt);
    3683              :     }
    3684              :   return init_stmt;
    3685              : }
    3686              : 
    3687              : /* Generate code to initialize the parameters of the function at the
    3688              :    top of the stack in ID from the GIMPLE_CALL STMT.  */
    3689              : 
    3690              : static void
    3691      4636319 : initialize_inlined_parameters (copy_body_data *id, gimple *stmt,
    3692              :                                tree fn, basic_block bb)
    3693              : {
    3694      4636319 :   tree parms;
    3695      4636319 :   size_t i;
    3696      4636319 :   tree p;
    3697      4636319 :   tree vars = NULL_TREE;
    3698      4636319 :   tree static_chain = gimple_call_chain (stmt);
    3699              : 
    3700              :   /* Figure out what the parameters are.  */
    3701      4636319 :   parms = DECL_ARGUMENTS (fn);
    3702              : 
    3703              :   /* Loop through the parameter declarations, replacing each with an
    3704              :      equivalent VAR_DECL, appropriately initialized.  */
    3705     12556176 :   for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
    3706              :     {
    3707      7919857 :       tree val;
    3708      7919857 :       val = i < gimple_call_num_args (stmt) ? gimple_call_arg (stmt, i) : NULL;
    3709      7919857 :       setup_one_parameter (id, p, val, fn, bb, &vars);
    3710              :     }
    3711              :   /* After remapping parameters remap their types.  This has to be done
    3712              :      in a second loop over all parameters to appropriately remap
    3713              :      variable sized arrays when the size is specified in a
    3714              :      parameter following the array.  */
    3715     12556176 :   for (p = parms, i = 0; p; p = DECL_CHAIN (p), i++)
    3716              :     {
    3717      7919857 :       tree *varp = id->decl_map->get (p);
    3718      7919857 :       if (varp && VAR_P (*varp))
    3719              :         {
    3720     15507480 :           tree def = (gimple_in_ssa_p (cfun) && is_gimple_reg (p)
    3721      7312455 :                       ? ssa_default_def (id->src_cfun, p) : NULL);
    3722      7753740 :           tree var = *varp;
    3723      7753740 :           TREE_TYPE (var) = remap_type (TREE_TYPE (var), id);
    3724              :           /* Also remap the default definition if it was remapped
    3725              :              to the default definition of the parameter replacement
    3726              :              by the parameter setup.  */
    3727      7753740 :           if (def)
    3728              :             {
    3729      6956724 :               tree *defp = id->decl_map->get (def);
    3730      6956724 :               if (defp
    3731      6956636 :                   && TREE_CODE (*defp) == SSA_NAME
    3732     13648679 :                   && SSA_NAME_VAR (*defp) == var)
    3733        22957 :                 TREE_TYPE (*defp) = TREE_TYPE (var);
    3734              :             }
    3735              :           /* When not optimizing and the parameter is unused, assign to
    3736              :              a dummy SSA name.  Do this after remapping the type above.  */
    3737       797016 :           else if (!optimize
    3738         3481 :                    && is_gimple_reg (p)
    3739       799642 :                    && i < gimple_call_num_args (stmt))
    3740              :             {
    3741         2626 :               tree val = gimple_call_arg (stmt, i);
    3742         2626 :               if (val != error_mark_node)
    3743              :                 {
    3744         2626 :                   if (!useless_type_conversion_p (TREE_TYPE (p),
    3745         2626 :                                                   TREE_TYPE (val)))
    3746            0 :                     val = force_value_to_type (TREE_TYPE (p), val);
    3747         2626 :                   def = make_ssa_name (var);
    3748         2626 :                   gimple *init_stmt = gimple_build_assign (def, val);
    3749         2626 :                   insert_init_stmt (id, bb, init_stmt);
    3750              :                 }
    3751              :             }
    3752              :         }
    3753              :     }
    3754              : 
    3755              :   /* Initialize the static chain.  */
    3756      4636319 :   p = DECL_STRUCT_FUNCTION (fn)->static_chain_decl;
    3757      4636319 :   gcc_assert (fn != current_function_decl);
    3758      4636319 :   if (p)
    3759              :     {
    3760              :       /* Calling a function that requires a static chain directly
    3761              :          without setting up the static chain has undefined behavior
    3762              :          at run-time.  */
    3763         2414 :       if (!static_chain)
    3764            0 :         static_chain = null_pointer_node;
    3765         2414 :       setup_one_parameter (id, p, static_chain, fn, bb, &vars);
    3766              :     }
    3767              : 
    3768              :   /* Reverse so the variables appear in the correct order in DWARF
    3769              :      debug info.  */
    3770      4636319 :   vars = nreverse (vars);
    3771              : 
    3772      4636319 :   declare_inline_vars (id->block, vars);
    3773      4636319 : }
    3774              : 
    3775              : 
    3776              : /* Declare a return variable to replace the RESULT_DECL for the
    3777              :    function we are calling.  An appropriate DECL_STMT is returned.
    3778              :    The USE_STMT is filled to contain a use of the declaration to
    3779              :    indicate the return value of the function.
    3780              : 
    3781              :    RETURN_SLOT, if non-null is place where to store the result.  It
    3782              :    is set only for CALL_EXPR_RETURN_SLOT_OPT.  MODIFY_DEST, if non-null,
    3783              :    was the LHS of the MODIFY_EXPR to which this call is the RHS.
    3784              : 
    3785              :    The return value is a (possibly null) value that holds the result
    3786              :    as seen by the caller.  */
    3787              : 
    3788              : static tree
    3789      4636319 : declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest,
    3790              :                          basic_block entry_bb)
    3791              : {
    3792      4636319 :   tree callee = id->src_fn;
    3793      4636319 :   tree result = DECL_RESULT (callee);
    3794      4636319 :   tree callee_type = TREE_TYPE (result);
    3795      4636319 :   tree caller_type;
    3796      4636319 :   tree var, use;
    3797              : 
    3798              :   /* Handle type-mismatches in the function declaration return type
    3799              :      vs. the call expression.  */
    3800      4636319 :   if (modify_dest)
    3801      2172904 :     caller_type = TREE_TYPE (modify_dest);
    3802      2463415 :   else if (return_slot)
    3803       143554 :     caller_type = TREE_TYPE (return_slot);
    3804              :   else /* No LHS on the call.  */
    3805      2319861 :     caller_type = TREE_TYPE (TREE_TYPE (callee));
    3806              : 
    3807              :   /* We don't need to do anything for functions that don't return anything.  */
    3808      4636319 :   if (VOID_TYPE_P (callee_type))
    3809              :     return NULL_TREE;
    3810              : 
    3811              :   /* If there was a return slot, then the return value is the
    3812              :      dereferenced address of that object.  */
    3813      2486005 :   if (return_slot)
    3814              :     {
    3815              :       /* The front end shouldn't have used both return_slot and
    3816              :          a modify expression.  */
    3817       143554 :       gcc_assert (!modify_dest);
    3818       143554 :       if (DECL_BY_REFERENCE (result))
    3819              :         {
    3820        83094 :           tree return_slot_addr = build_fold_addr_expr (return_slot);
    3821        83094 :           STRIP_USELESS_TYPE_CONVERSION (return_slot_addr);
    3822              : 
    3823              :           /* We are going to construct *&return_slot and we can't do that
    3824              :              for variables believed to be not addressable.
    3825              : 
    3826              :              FIXME: This check possibly can match, because values returned
    3827              :              via return slot optimization are not believed to have address
    3828              :              taken by alias analysis.  */
    3829        83094 :           gcc_assert (TREE_CODE (return_slot) != SSA_NAME);
    3830        83094 :           var = return_slot_addr;
    3831        83094 :           mark_addressable (return_slot);
    3832              :         }
    3833              :       else
    3834              :         {
    3835        60460 :           var = return_slot;
    3836        60460 :           gcc_assert (TREE_CODE (var) != SSA_NAME);
    3837        60460 :           if (TREE_ADDRESSABLE (result))
    3838        23299 :             mark_addressable (var);
    3839              :         }
    3840       143554 :       if (DECL_NOT_GIMPLE_REG_P (result)
    3841       143554 :           && DECL_P (var))
    3842            0 :         DECL_NOT_GIMPLE_REG_P (var) = 1;
    3843              : 
    3844       143554 :       if (!useless_type_conversion_p (callee_type, caller_type))
    3845        83095 :         var = build1 (VIEW_CONVERT_EXPR, callee_type, var);
    3846              : 
    3847       143554 :       use = NULL;
    3848       143554 :       goto done;
    3849              :     }
    3850              : 
    3851              :   /* All types requiring non-trivial constructors should have been handled.  */
    3852      2342451 :   gcc_assert (!TREE_ADDRESSABLE (callee_type));
    3853              : 
    3854              :   /* Attempt to avoid creating a new temporary variable.  */
    3855      2342451 :   if (modify_dest
    3856      2172883 :       && TREE_CODE (modify_dest) != SSA_NAME)
    3857              :     {
    3858       385928 :       bool use_it = false;
    3859              : 
    3860              :       /* We can't use MODIFY_DEST if there's type promotion involved.  */
    3861       385928 :       if (!useless_type_conversion_p (callee_type, caller_type))
    3862              :         use_it = false;
    3863              : 
    3864              :       /* ??? If we're assigning to a variable sized type, then we must
    3865              :          reuse the destination variable, because we've no good way to
    3866              :          create variable sized temporaries at this point.  */
    3867       385926 :       else if (!poly_int_tree_p (TYPE_SIZE_UNIT (caller_type)))
    3868              :         use_it = true;
    3869              : 
    3870              :       /* If the callee cannot possibly modify MODIFY_DEST, then we can
    3871              :          reuse it as the result of the call directly.  Don't do this if
    3872              :          it would promote MODIFY_DEST to addressable.  */
    3873       385926 :       else if (TREE_ADDRESSABLE (result))
    3874              :         use_it = false;
    3875              :       else
    3876              :         {
    3877       384597 :           tree base_m = get_base_address (modify_dest);
    3878              : 
    3879              :           /* If the base isn't a decl, then it's a pointer, and we don't
    3880              :              know where that's going to go.  */
    3881       384597 :           if (!DECL_P (base_m))
    3882              :             use_it = false;
    3883       380580 :           else if (is_global_var (base_m))
    3884              :             use_it = false;
    3885       380104 :           else if (DECL_NOT_GIMPLE_REG_P (result)
    3886       380104 :                    && !DECL_NOT_GIMPLE_REG_P (base_m))
    3887              :             use_it = false;
    3888       380104 :           else if (!TREE_ADDRESSABLE (base_m))
    3889              :             use_it = true;
    3890              :         }
    3891              : 
    3892              :       if (use_it)
    3893              :         {
    3894       278761 :           var = modify_dest;
    3895       278761 :           use = NULL;
    3896       278761 :           goto done;
    3897              :         }
    3898              :     }
    3899              : 
    3900      2063690 :   gcc_assert (poly_int_tree_p (TYPE_SIZE_UNIT (callee_type)));
    3901              : 
    3902      2063690 :   var = copy_result_decl_to_var (result, id);
    3903      2063690 :   DECL_SEEN_IN_BIND_EXPR_P (var) = 1;
    3904              : 
    3905              :   /* Do not have the rest of GCC warn about this variable as it should
    3906              :      not be visible to the user.  */
    3907      2063690 :   suppress_warning (var /* OPT_Wuninitialized? */);
    3908              : 
    3909      2063690 :   declare_inline_vars (id->block, var);
    3910              : 
    3911              :   /* Build the use expr.  If the return type of the function was
    3912              :      promoted, convert it back to the expected type.  */
    3913      2063690 :   use = var;
    3914      2063690 :   if (!useless_type_conversion_p (caller_type, TREE_TYPE (var)))
    3915              :     {
    3916              :       /* If we can match up types by promotion/demotion do so.  */
    3917            7 :       if (fold_convertible_p (caller_type, var))
    3918            0 :         use = fold_convert (caller_type, var);
    3919              :       else
    3920              :         {
    3921              :           /* ???  For valid programs we should not end up here.
    3922              :              Still if we end up with truly mismatched types here, fall back
    3923              :              to using a MEM_REF to not leak invalid GIMPLE to the following
    3924              :              passes.  */
    3925              :           /* Prevent var from being written into SSA form.  */
    3926            7 :           if (is_gimple_reg_type (TREE_TYPE (var)))
    3927            7 :             DECL_NOT_GIMPLE_REG_P (var) = true;
    3928            7 :           use = fold_build2 (MEM_REF, caller_type,
    3929              :                              build_fold_addr_expr (var),
    3930              :                              build_int_cst (ptr_type_node, 0));
    3931              :         }
    3932              :     }
    3933              : 
    3934      2063690 :   STRIP_USELESS_TYPE_CONVERSION (use);
    3935              : 
    3936      2063690 :   if (DECL_BY_REFERENCE (result))
    3937              :     {
    3938            0 :       TREE_ADDRESSABLE (var) = 1;
    3939            0 :       var = build_fold_addr_expr (var);
    3940              :     }
    3941              : 
    3942      2063690 :  done:
    3943              :   /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
    3944              :      way, when the RESULT_DECL is encountered, it will be
    3945              :      automatically replaced by the VAR_DECL.
    3946              : 
    3947              :      When returning by reference, ensure that RESULT_DECL remaps to
    3948              :      gimple_val.  */
    3949      2486005 :   if (DECL_BY_REFERENCE (result)
    3950      2486005 :       && !is_gimple_val (var))
    3951              :     {
    3952        83094 :       tree temp = create_tmp_var (TREE_TYPE (result), "retvalptr");
    3953        83094 :       insert_decl_map (id, result, temp);
    3954              :       /* When RESULT_DECL is in SSA form, we need to remap and initialize
    3955              :          it's default_def SSA_NAME.  */
    3956        83094 :       if (gimple_in_ssa_p (id->src_cfun)
    3957        83094 :           && is_gimple_reg (result))
    3958        83094 :         if (tree default_def = ssa_default_def (id->src_cfun, result))
    3959              :           {
    3960        83057 :             temp = make_ssa_name (temp);
    3961        83057 :             insert_decl_map (id, default_def, temp);
    3962              :           }
    3963        83094 :       insert_init_stmt (id, entry_bb, gimple_build_assign (temp, var));
    3964              :     }
    3965              :   else
    3966      2402911 :     insert_decl_map (id, result, var);
    3967              : 
    3968              :   /* Remember this so we can ignore it in remap_decls.  */
    3969      2486005 :   id->retvar = var;
    3970      2486005 :   return use;
    3971              : }
    3972              : 
    3973              : /* Determine if the function can be copied.  If so return NULL.  If
    3974              :    not return a string describing the reason for failure.  */
    3975              : 
    3976              : const char *
    3977     18573280 : copy_forbidden (struct function *fun)
    3978              : {
    3979     18573280 :   const char *reason = fun->cannot_be_copied_reason;
    3980              : 
    3981              :   /* Only examine the function once.  */
    3982     18573280 :   if (fun->cannot_be_copied_set)
    3983              :     return reason;
    3984              : 
    3985              :   /* We cannot copy a function that receives a non-local goto
    3986              :      because we cannot remap the destination label used in the
    3987              :      function that is performing the non-local goto.  */
    3988              :   /* ??? Actually, this should be possible, if we work at it.
    3989              :      No doubt there's just a handful of places that simply
    3990              :      assume it doesn't happen and don't substitute properly.  */
    3991     11079992 :   if (fun->has_nonlocal_label)
    3992              :     {
    3993          783 :       reason = G_("function %q+F can never be copied "
    3994              :                   "because it receives a non-local goto");
    3995          783 :       goto fail;
    3996              :     }
    3997              : 
    3998     11079209 :   if (fun->has_forced_label_in_static)
    3999              :     {
    4000          230 :       reason = G_("function %q+F can never be copied because it saves "
    4001              :                   "address of local label in a static variable");
    4002          230 :       goto fail;
    4003              :     }
    4004              : 
    4005     11078979 :  fail:
    4006     11079992 :   fun->cannot_be_copied_reason = reason;
    4007     11079992 :   fun->cannot_be_copied_set = true;
    4008     11079992 :   return reason;
    4009              : }
    4010              : 
    4011              : 
    4012              : static const char *inline_forbidden_reason;
    4013              : 
    4014              : /* A callback for walk_gimple_seq to handle statements.  Returns non-null
    4015              :    iff a function cannot be inlined.  Also sets the reason why. */
    4016              : 
    4017              : static tree
    4018    178300348 : inline_forbidden_p_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
    4019              :                          struct walk_stmt_info *wip)
    4020              : {
    4021    178300348 :   tree fn = (tree) wip->info;
    4022    178300348 :   tree t;
    4023    178300348 :   gimple *stmt = gsi_stmt (*gsi);
    4024              : 
    4025    178300348 :   switch (gimple_code (stmt))
    4026              :     {
    4027     19469881 :     case GIMPLE_CALL:
    4028              :       /* Refuse to inline alloca call unless user explicitly forced so as
    4029              :          this may change program's memory overhead drastically when the
    4030              :          function using alloca is called in loop.  In GCC present in
    4031              :          SPEC2000 inlining into schedule_block cause it to require 2GB of
    4032              :          RAM instead of 256MB.  Don't do so for alloca calls emitted for
    4033              :          VLA objects as those can't cause unbounded growth (they're always
    4034              :          wrapped inside stack_save/stack_restore regions.  */
    4035     19469881 :       if (gimple_maybe_alloca_call_p (stmt)
    4036         9563 :           && !gimple_call_alloca_for_var_p (as_a <gcall *> (stmt))
    4037     19474654 :           && !lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)))
    4038              :         {
    4039         4645 :           inline_forbidden_reason
    4040         4645 :             = G_("function %q+F can never be inlined because it uses "
    4041              :                  "alloca (override using the always_inline attribute)");
    4042         4645 :           *handled_ops_p = true;
    4043         4645 :           return fn;
    4044              :         }
    4045              : 
    4046     19465236 :       t = gimple_call_fndecl (stmt);
    4047     19465236 :       if (t == NULL_TREE)
    4048              :         break;
    4049              : 
    4050              :       /* We cannot inline functions that call setjmp.  */
    4051     18731529 :       if (setjmp_call_p (t))
    4052              :         {
    4053         1052 :           inline_forbidden_reason
    4054         1052 :             = G_("function %q+F can never be inlined because it uses setjmp");
    4055         1052 :           *handled_ops_p = true;
    4056         1052 :           return t;
    4057              :         }
    4058              : 
    4059     18730477 :       if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
    4060      3869394 :         switch (DECL_FUNCTION_CODE (t))
    4061              :           {
    4062              :             /* We cannot inline functions that take a variable number of
    4063              :                arguments.  */
    4064         2815 :           case BUILT_IN_VA_START:
    4065         2815 :           case BUILT_IN_NEXT_ARG:
    4066         2815 :           case BUILT_IN_VA_END:
    4067         2815 :             inline_forbidden_reason
    4068         2815 :               = G_("function %q+F can never be inlined because it "
    4069              :                    "uses variable argument lists");
    4070         2815 :             *handled_ops_p = true;
    4071         2815 :             return t;
    4072              : 
    4073          226 :           case BUILT_IN_LONGJMP:
    4074              :             /* We can't inline functions that call __builtin_longjmp at
    4075              :                all.  The non-local goto machinery really requires the
    4076              :                destination be in a different function.  If we allow the
    4077              :                function calling __builtin_longjmp to be inlined into the
    4078              :                function calling __builtin_setjmp, Things will Go Awry.  */
    4079          226 :             inline_forbidden_reason
    4080          226 :               = G_("function %q+F can never be inlined because "
    4081              :                    "it uses setjmp-longjmp exception handling");
    4082          226 :             *handled_ops_p = true;
    4083          226 :             return t;
    4084              : 
    4085          276 :           case BUILT_IN_NONLOCAL_GOTO:
    4086              :             /* Similarly.  */
    4087          276 :             inline_forbidden_reason
    4088          276 :               = G_("function %q+F can never be inlined because "
    4089              :                    "it uses non-local goto");
    4090          276 :             *handled_ops_p = true;
    4091          276 :             return t;
    4092              : 
    4093          384 :           case BUILT_IN_RETURN:
    4094          384 :           case BUILT_IN_APPLY_ARGS:
    4095              :             /* If a __builtin_apply_args caller would be inlined,
    4096              :                it would be saving arguments of the function it has
    4097              :                been inlined into.  Similarly __builtin_return would
    4098              :                return from the function the inline has been inlined into.  */
    4099          384 :             inline_forbidden_reason
    4100          384 :               = G_("function %q+F can never be inlined because "
    4101              :                    "it uses %<__builtin_return%> or %<__builtin_apply_args%>");
    4102          384 :             *handled_ops_p = true;
    4103          384 :             return t;
    4104              : 
    4105              :           default:
    4106              :             break;
    4107              :           }
    4108              :       break;
    4109              : 
    4110          333 :     case GIMPLE_GOTO:
    4111          333 :       t = gimple_goto_dest (stmt);
    4112              : 
    4113              :       /* We will not inline a function which uses computed goto.  The
    4114              :          addresses of its local labels, which may be tucked into
    4115              :          global storage, are of course not constant across
    4116              :          instantiations, which causes unexpected behavior.  */
    4117          333 :       if (TREE_CODE (t) != LABEL_DECL)
    4118              :         {
    4119          333 :           inline_forbidden_reason
    4120          333 :             = G_("function %q+F can never be inlined "
    4121              :                  "because it contains a computed goto");
    4122          333 :           *handled_ops_p = true;
    4123          333 :           return t;
    4124              :         }
    4125              :       break;
    4126              : 
    4127              :     default:
    4128              :       break;
    4129              :     }
    4130              : 
    4131    178290617 :   *handled_ops_p = false;
    4132    178290617 :   return NULL_TREE;
    4133              : }
    4134              : 
    4135              : /* Return true if FNDECL is a function that cannot be inlined into
    4136              :    another one.  */
    4137              : 
    4138              : static bool
    4139      5961389 : inline_forbidden_p (tree fndecl)
    4140              : {
    4141      5961389 :   struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
    4142      5961389 :   struct walk_stmt_info wi;
    4143      5961389 :   basic_block bb;
    4144      5961389 :   bool forbidden_p = false;
    4145              : 
    4146              :   /* First check for shared reasons not to copy the code.  */
    4147      5961389 :   inline_forbidden_reason = copy_forbidden (fun);
    4148      5961389 :   if (inline_forbidden_reason != NULL)
    4149              :     return true;
    4150              : 
    4151              :   /* Next, walk the statements of the function looking for
    4152              :      constructs we can't handle, or are non-optimal for inlining.  */
    4153      5960683 :   hash_set<tree> visited_nodes;
    4154      5960683 :   memset (&wi, 0, sizeof (wi));
    4155      5960683 :   wi.info = (void *) fndecl;
    4156      5960683 :   wi.pset = &visited_nodes;
    4157              : 
    4158              :   /* We cannot inline a function with a variable-sized parameter because we
    4159              :      cannot materialize a temporary of such a type in the caller if need be.
    4160              :      Note that the return case is not symmetrical because we can guarantee
    4161              :      that a temporary is not needed by means of CALL_EXPR_RETURN_SLOT_OPT.  */
    4162     18923915 :   for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
    4163     12963234 :     if (!poly_int_tree_p (DECL_SIZE (parm)))
    4164              :       {
    4165            2 :         inline_forbidden_reason
    4166            2 :           = G_("function %q+F can never be inlined because "
    4167              :                "it has a VLA argument");
    4168            2 :         return true;
    4169              :       }
    4170              : 
    4171     38727064 :   FOR_EACH_BB_FN (bb, fun)
    4172              :     {
    4173     32776114 :       gimple *ret;
    4174     32776114 :       gimple_seq seq = bb_seq (bb);
    4175     32776114 :       ret = walk_gimple_seq (seq, inline_forbidden_p_stmt, NULL, &wi);
    4176     32776114 :       forbidden_p = (ret != NULL);
    4177     32776114 :       if (forbidden_p)
    4178              :         break;
    4179              :     }
    4180              : 
    4181              :   return forbidden_p;
    4182      5960683 : }
    4183              : 
    4184              : /* Return false if the function FNDECL cannot be inlined on account of its
    4185              :    attributes, true otherwise.  */
    4186              : static bool
    4187      5961389 : function_attribute_inlinable_p (const_tree fndecl)
    4188              : {
    4189     11897776 :   for (auto scoped_attributes : targetm.attribute_table)
    4190              :     {
    4191      5961389 :       const_tree a;
    4192              : 
    4193      7849627 :       for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
    4194              :         {
    4195      1913240 :           const_tree name = get_attribute_name (a);
    4196              : 
    4197     54860603 :           for (const attribute_spec &attribute : scoped_attributes->attributes)
    4198     52972365 :             if (is_attribute_p (attribute.name, name))
    4199        25002 :               return targetm.function_attribute_inlinable_p (fndecl);
    4200              :         }
    4201              :     }
    4202              : 
    4203              :   return true;
    4204              : }
    4205              : 
    4206              : /* Returns nonzero if FN is a function that does not have any
    4207              :    fundamental inline blocking properties.  */
    4208              : 
    4209              : bool
    4210      6598072 : tree_inlinable_function_p (tree fn)
    4211              : {
    4212      6598072 :   bool inlinable = true;
    4213      6598072 :   bool do_warning;
    4214      6598072 :   tree always_inline;
    4215              : 
    4216              :   /* Do not inline a target_clones function before its versions have been
    4217              :      expanded.  This restriction is temporary: unlike the other reasons below,
    4218              :      it must not be cached in DECL_UNINLINABLE and inherited by the clones.  */
    4219      6598072 :   if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn)))
    4220              :     return false;
    4221              : 
    4222              :   /* If we've already decided this function shouldn't be inlined,
    4223              :      there's no need to check again.  */
    4224      6597984 :   if (DECL_UNINLINABLE (fn))
    4225              :     return false;
    4226              : 
    4227              :   /* We only warn for functions declared `inline' by the user.  */
    4228      5980746 :   do_warning = (opt_for_fn (fn, warn_inline)
    4229          637 :                 && DECL_DECLARED_INLINE_P (fn)
    4230          508 :                 && !DECL_NO_INLINE_WARNING_P (fn)
    4231      5981124 :                 && !DECL_IN_SYSTEM_HEADER (fn));
    4232              : 
    4233      5980746 :   always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn));
    4234              : 
    4235      5980746 :   if (flag_no_inline
    4236        95647 :       && always_inline == NULL)
    4237              :     {
    4238        19357 :       if (do_warning)
    4239            0 :         warning (OPT_Winline, "function %q+F can never be inlined because it "
    4240              :                  "is suppressed using %<-fno-inline%>", fn);
    4241              :       inlinable = false;
    4242              :     }
    4243              : 
    4244      5961389 :   else if (!function_attribute_inlinable_p (fn))
    4245              :     {
    4246            0 :       if (do_warning)
    4247            0 :         warning (OPT_Winline, "function %q+F can never be inlined because it "
    4248              :                  "uses attributes conflicting with inlining", fn);
    4249              :       inlinable = false;
    4250              :     }
    4251              : 
    4252      5961389 :   else if (inline_forbidden_p (fn))
    4253              :     {
    4254              :       /* See if we should warn about uninlinable functions.  Previously,
    4255              :          some of these warnings would be issued while trying to expand
    4256              :          the function inline, but that would cause multiple warnings
    4257              :          about functions that would for example call alloca.  But since
    4258              :          this a property of the function, just one warning is enough.
    4259              :          As a bonus we can now give more details about the reason why a
    4260              :          function is not inlinable.  */
    4261        10439 :       if (always_inline)
    4262            2 :         error (inline_forbidden_reason, fn);
    4263        10437 :       else if (do_warning)
    4264            2 :         warning (OPT_Winline, inline_forbidden_reason, fn);
    4265              : 
    4266              :       inlinable = false;
    4267              :     }
    4268              : 
    4269              :   /* Squirrel away the result so that we don't have to check again.  */
    4270      5980746 :   DECL_UNINLINABLE (fn) = !inlinable;
    4271              : 
    4272      5980746 :   return inlinable;
    4273              : }
    4274              : 
    4275              : /* Estimate the cost of a memory move of type TYPE.  Use machine dependent
    4276              :    word size and take possible memcpy call into account and return
    4277              :    cost based on whether optimizing for size or speed according to SPEED_P.  */
    4278              : 
    4279              : int
    4280    338972606 : estimate_move_cost (tree type, bool ARG_UNUSED (speed_p))
    4281              : {
    4282    338972606 :   HOST_WIDE_INT size;
    4283              : 
    4284    338972606 :   gcc_assert (!VOID_TYPE_P (type));
    4285              : 
    4286    338972606 :   if (VECTOR_TYPE_P (type))
    4287              :     {
    4288      4386434 :       scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (type));
    4289      4386434 :       machine_mode simd = targetm.vectorize.preferred_simd_mode (inner);
    4290      4386434 :       int orig_mode_size
    4291      8772868 :         = estimated_poly_value (GET_MODE_SIZE (TYPE_MODE (type)));
    4292      8772868 :       int simd_mode_size = estimated_poly_value (GET_MODE_SIZE (simd));
    4293      4386434 :       return ((orig_mode_size + simd_mode_size - 1)
    4294      4386434 :               / simd_mode_size);
    4295              :     }
    4296              : 
    4297    334586172 :   size = int_size_in_bytes (type);
    4298              : 
    4299    334588637 :   if (size < 0 || size > MOVE_MAX_PIECES * MOVE_RATIO (speed_p))
    4300              :     /* Cost of a memcpy call, 3 arguments and the call.  */
    4301              :     return 4;
    4302              :   else
    4303    333620490 :     return ((size + MOVE_MAX_PIECES - 1) / MOVE_MAX_PIECES);
    4304              : }
    4305              : 
    4306              : /* Returns cost of operation CODE, according to WEIGHTS  */
    4307              : 
    4308              : static int
    4309    407507179 : estimate_operator_cost (enum tree_code code, eni_weights *weights,
    4310              :                         tree op1 ATTRIBUTE_UNUSED, tree op2)
    4311              : {
    4312    407507179 :   switch (code)
    4313              :     {
    4314              :     /* These are "free" conversions, or their presumed cost
    4315              :        is folded into other operations.  */
    4316              :     case RANGE_EXPR:
    4317              :     CASE_CONVERT:
    4318              :     case COMPLEX_EXPR:
    4319              :     case PAREN_EXPR:
    4320              :     case VIEW_CONVERT_EXPR:
    4321              :       return 0;
    4322              : 
    4323              :     /* Assign cost of 1 to usual operations.
    4324              :        ??? We may consider mapping RTL costs to this.  */
    4325              :     case COND_EXPR:
    4326              :     case VEC_COND_EXPR:
    4327              :     case VEC_PERM_EXPR:
    4328              : 
    4329              :     case PLUS_EXPR:
    4330              :     case POINTER_PLUS_EXPR:
    4331              :     case POINTER_DIFF_EXPR:
    4332              :     case MINUS_EXPR:
    4333              :     case MULT_EXPR:
    4334              :     case MULT_HIGHPART_EXPR:
    4335              : 
    4336              :     case ADDR_SPACE_CONVERT_EXPR:
    4337              :     case FIXED_CONVERT_EXPR:
    4338              :     case FIX_TRUNC_EXPR:
    4339              : 
    4340              :     case NEGATE_EXPR:
    4341              :     case FLOAT_EXPR:
    4342              :     case MIN_EXPR:
    4343              :     case MAX_EXPR:
    4344              :     case ABS_EXPR:
    4345              :     case ABSU_EXPR:
    4346              : 
    4347              :     case LSHIFT_EXPR:
    4348              :     case RSHIFT_EXPR:
    4349              :     case LROTATE_EXPR:
    4350              :     case RROTATE_EXPR:
    4351              : 
    4352              :     case BIT_IOR_EXPR:
    4353              :     case BIT_XOR_EXPR:
    4354              :     case BIT_AND_EXPR:
    4355              :     case BIT_NOT_EXPR:
    4356              : 
    4357              :     case TRUTH_ANDIF_EXPR:
    4358              :     case TRUTH_ORIF_EXPR:
    4359              :     case TRUTH_AND_EXPR:
    4360              :     case TRUTH_OR_EXPR:
    4361              :     case TRUTH_XOR_EXPR:
    4362              :     case TRUTH_NOT_EXPR:
    4363              : 
    4364              :     case LT_EXPR:
    4365              :     case LE_EXPR:
    4366              :     case GT_EXPR:
    4367              :     case GE_EXPR:
    4368              :     case EQ_EXPR:
    4369              :     case NE_EXPR:
    4370              :     case ORDERED_EXPR:
    4371              :     case UNORDERED_EXPR:
    4372              : 
    4373              :     case UNLT_EXPR:
    4374              :     case UNLE_EXPR:
    4375              :     case UNGT_EXPR:
    4376              :     case UNGE_EXPR:
    4377              :     case UNEQ_EXPR:
    4378              :     case LTGT_EXPR:
    4379              : 
    4380              :     case CONJ_EXPR:
    4381              : 
    4382              :     case PREDECREMENT_EXPR:
    4383              :     case PREINCREMENT_EXPR:
    4384              :     case POSTDECREMENT_EXPR:
    4385              :     case POSTINCREMENT_EXPR:
    4386              : 
    4387              :     case REALIGN_LOAD_EXPR:
    4388              : 
    4389              :     case WIDEN_SUM_EXPR:
    4390              :     case WIDEN_MULT_EXPR:
    4391              :     case DOT_PROD_EXPR:
    4392              :     case SAD_EXPR:
    4393              :     case WIDEN_MULT_PLUS_EXPR:
    4394              :     case WIDEN_MULT_MINUS_EXPR:
    4395              :     case WIDEN_LSHIFT_EXPR:
    4396              : 
    4397              :     case VEC_WIDEN_MULT_HI_EXPR:
    4398              :     case VEC_WIDEN_MULT_LO_EXPR:
    4399              :     case VEC_WIDEN_MULT_EVEN_EXPR:
    4400              :     case VEC_WIDEN_MULT_ODD_EXPR:
    4401              :     case VEC_UNPACK_HI_EXPR:
    4402              :     case VEC_UNPACK_LO_EXPR:
    4403              :     case VEC_UNPACK_FLOAT_HI_EXPR:
    4404              :     case VEC_UNPACK_FLOAT_LO_EXPR:
    4405              :     case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
    4406              :     case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
    4407              :     case VEC_PACK_TRUNC_EXPR:
    4408              :     case VEC_PACK_SAT_EXPR:
    4409              :     case VEC_PACK_FIX_TRUNC_EXPR:
    4410              :     case VEC_PACK_FLOAT_EXPR:
    4411              :     case VEC_WIDEN_LSHIFT_HI_EXPR:
    4412              :     case VEC_WIDEN_LSHIFT_LO_EXPR:
    4413              :     case VEC_DUPLICATE_EXPR:
    4414              :     case VEC_SERIES_EXPR:
    4415              : 
    4416              :       return 1;
    4417              : 
    4418              :     /* Few special cases of expensive operations.  This is useful
    4419              :        to avoid inlining on functions having too many of these.  */
    4420      2753917 :     case TRUNC_DIV_EXPR:
    4421      2753917 :     case CEIL_DIV_EXPR:
    4422      2753917 :     case FLOOR_DIV_EXPR:
    4423      2753917 :     case ROUND_DIV_EXPR:
    4424      2753917 :     case EXACT_DIV_EXPR:
    4425      2753917 :     case TRUNC_MOD_EXPR:
    4426      2753917 :     case CEIL_MOD_EXPR:
    4427      2753917 :     case FLOOR_MOD_EXPR:
    4428      2753917 :     case ROUND_MOD_EXPR:
    4429      2753917 :     case RDIV_EXPR:
    4430      2753917 :       if (TREE_CODE (op2) != INTEGER_CST)
    4431      1399344 :         return weights->div_mod_cost;
    4432              :       return 1;
    4433              : 
    4434              :     /* Bit-field insertion needs several shift and mask operations.  */
    4435              :     case BIT_INSERT_EXPR:
    4436              :       return 3;
    4437              : 
    4438    184104323 :     default:
    4439              :       /* We expect a copy assignment with no operator.  */
    4440    184104323 :       gcc_assert (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS);
    4441              :       return 0;
    4442              :     }
    4443              : }
    4444              : 
    4445              : 
    4446              : /* Estimate number of instructions that will be created by expanding
    4447              :    the statements in the statement sequence STMTS.
    4448              :    WEIGHTS contains weights attributed to various constructs.  */
    4449              : 
    4450              : int
    4451       232162 : estimate_num_insns_seq (gimple_seq stmts, eni_weights *weights)
    4452              : {
    4453       232162 :   int cost;
    4454       232162 :   gimple_stmt_iterator gsi;
    4455              : 
    4456       232162 :   cost = 0;
    4457       616605 :   for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
    4458       384443 :     cost += estimate_num_insns (gsi_stmt (gsi), weights);
    4459              : 
    4460       232162 :   return cost;
    4461              : }
    4462              : 
    4463              : 
    4464              : /* Estimate number of instructions that will be created by expanding STMT.
    4465              :    WEIGHTS contains weights attributed to various constructs.  */
    4466              : 
    4467              : int
    4468    579118791 : estimate_num_insns (gimple *stmt, eni_weights *weights)
    4469              : {
    4470    579118791 :   unsigned cost, i;
    4471    579118791 :   enum gimple_code code = gimple_code (stmt);
    4472    579118791 :   tree lhs;
    4473    579118791 :   tree rhs;
    4474              : 
    4475    579118791 :   switch (code)
    4476              :     {
    4477    331392476 :     case GIMPLE_ASSIGN:
    4478              :       /* Try to estimate the cost of assignments.  We have three cases to
    4479              :          deal with:
    4480              :          1) Simple assignments to registers;
    4481              :          2) Stores to things that must live in memory.  This includes
    4482              :             "normal" stores to scalars, but also assignments of large
    4483              :             structures, or constructors of big arrays;
    4484              : 
    4485              :          Let us look at the first two cases, assuming we have "a = b + C":
    4486              :          <GIMPLE_ASSIGN <var_decl "a">
    4487              :                 <plus_expr <var_decl "b"> <constant C>>
    4488              :          If "a" is a GIMPLE register, the assignment to it is free on almost
    4489              :          any target, because "a" usually ends up in a real register.  Hence
    4490              :          the only cost of this expression comes from the PLUS_EXPR, and we
    4491              :          can ignore the GIMPLE_ASSIGN.
    4492              :          If "a" is not a GIMPLE register, the assignment to "a" will most
    4493              :          likely be a real store, so the cost of the GIMPLE_ASSIGN is the cost
    4494              :          of moving something into "a", which we compute using the function
    4495              :          estimate_move_cost.  */
    4496    331392476 :       if (gimple_clobber_p (stmt))
    4497              :         return 0;       /* ={v} {CLOBBER} stmt expands to nothing.  */
    4498              : 
    4499    314657064 :       lhs = gimple_assign_lhs (stmt);
    4500    314657064 :       rhs = gimple_assign_rhs1 (stmt);
    4501              : 
    4502    314657064 :       cost = 0;
    4503              : 
    4504              :       /* Account for the cost of moving to / from memory.  */
    4505    314657064 :       if (gimple_store_p (stmt))
    4506     77471387 :         cost += estimate_move_cost (TREE_TYPE (lhs), weights->time_based);
    4507    314657064 :       if (gimple_assign_load_p (stmt))
    4508     86083109 :         cost += estimate_move_cost (TREE_TYPE (rhs), weights->time_based);
    4509              : 
    4510    408033398 :       cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights,
    4511              :                                       gimple_assign_rhs1 (stmt),
    4512    314657064 :                                       get_gimple_rhs_class (gimple_assign_rhs_code (stmt))
    4513              :                                       == GIMPLE_BINARY_RHS
    4514     93376334 :                                       ? gimple_assign_rhs2 (stmt) : NULL);
    4515    314657064 :       break;
    4516              : 
    4517     92850115 :     case GIMPLE_COND:
    4518     92850115 :       cost = 1 + estimate_operator_cost (gimple_cond_code (stmt), weights,
    4519              :                                          gimple_op (stmt, 0),
    4520              :                                          gimple_op (stmt, 1));
    4521     92850115 :       break;
    4522              : 
    4523       855901 :     case GIMPLE_SWITCH:
    4524       855901 :       {
    4525       855901 :         gswitch *switch_stmt = as_a <gswitch *> (stmt);
    4526              :         /* Take into account cost of the switch + guess 2 conditional jumps for
    4527              :            each case label.
    4528              : 
    4529              :            TODO: once the switch expansion logic is sufficiently separated, we can
    4530              :            do better job on estimating cost of the switch.  */
    4531       855901 :         if (weights->time_based)
    4532       128087 :           cost = floor_log2 (gimple_switch_num_labels (switch_stmt)) * 2;
    4533              :         else
    4534       727814 :           cost = gimple_switch_num_labels (switch_stmt) * 2;
    4535              :       }
    4536              :       break;
    4537              : 
    4538     74151184 :     case GIMPLE_CALL:
    4539     74151184 :       {
    4540     74151184 :         tree decl;
    4541              : 
    4542     74151184 :         if (gimple_call_internal_p (stmt))
    4543              :           return 0;
    4544     71237306 :         else if ((decl = gimple_call_fndecl (stmt))
    4545     71237306 :                  && fndecl_built_in_p (decl))
    4546              :           {
    4547              :             /* Do not special case builtins where we see the body.
    4548              :                This just confuse inliner.  */
    4549     18267437 :             struct cgraph_node *node;
    4550     18267437 :             if ((node = cgraph_node::get (decl))
    4551     18267437 :                 && node->definition)
    4552              :               ;
    4553              :             /* For builtins that are likely expanded to nothing or
    4554              :                inlined do not account operand costs.  */
    4555     18237389 :             else if (is_simple_builtin (decl))
    4556              :               return 0;
    4557     15362973 :             else if (is_inexpensive_builtin (decl))
    4558      1942073 :               return weights->target_builtin_call_cost;
    4559     13420900 :             else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
    4560              :               {
    4561              :                 /* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so
    4562              :                    specialize the cheap expansion we do here.
    4563              :                    ???  This asks for a more general solution.  */
    4564     13171881 :                 switch (DECL_FUNCTION_CODE (decl))
    4565              :                   {
    4566         9821 :                     case BUILT_IN_POW:
    4567         9821 :                     case BUILT_IN_POWF:
    4568         9821 :                     case BUILT_IN_POWL:
    4569         9821 :                       if (TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST
    4570        13860 :                           && (real_equal
    4571         4039 :                               (&TREE_REAL_CST (gimple_call_arg (stmt, 1)),
    4572              :                                &dconst2)))
    4573          543 :                         return estimate_operator_cost
    4574          543 :                             (MULT_EXPR, weights, gimple_call_arg (stmt, 0),
    4575          543 :                              gimple_call_arg (stmt, 0));
    4576              :                       break;
    4577              : 
    4578              :                     default:
    4579              :                       break;
    4580              :                   }
    4581              :               }
    4582              :           }
    4583              : 
    4584     66420274 :         cost = decl ? weights->call_cost : weights->indirect_call_cost;
    4585     66420274 :         if (gimple_call_lhs (stmt))
    4586     25965409 :           cost += estimate_move_cost (TREE_TYPE (gimple_call_lhs (stmt)),
    4587              :                                       weights->time_based);
    4588    201187755 :         for (i = 0; i < gimple_call_num_args (stmt); i++)
    4589              :           {
    4590    134767481 :             tree arg = gimple_call_arg (stmt, i);
    4591    134767481 :             cost += estimate_move_cost (TREE_TYPE (arg),
    4592              :                                         weights->time_based);
    4593              :           }
    4594              :         break;
    4595              :       }
    4596              : 
    4597     18398875 :     case GIMPLE_RETURN:
    4598     18398875 :       return weights->return_cost;
    4599              : 
    4600              :     case GIMPLE_GOTO:
    4601              :     case GIMPLE_LABEL:
    4602              :     case GIMPLE_NOP:
    4603              :     case GIMPLE_PHI:
    4604              :     case GIMPLE_PREDICT:
    4605              :     case GIMPLE_DEBUG:
    4606              :       return 0;
    4607              : 
    4608       666323 :     case GIMPLE_ASM:
    4609       666323 :       {
    4610       666323 :         int count = asm_str_count (gimple_asm_string (as_a <gasm *> (stmt)));
    4611              :         /* 1000 means infinity. This avoids overflows later
    4612              :            with very long asm statements.  */
    4613       666323 :         if (count > 1000)
    4614              :           count = 1000;
    4615              :         /* If this asm is asm inline, count anything as minimum size.  */
    4616       666323 :         if (gimple_asm_inline_p (as_a <gasm *> (stmt)))
    4617          709 :           count = MIN (1, count);
    4618       666323 :         return MAX (1, count);
    4619              :       }
    4620              : 
    4621              :     case GIMPLE_RESX:
    4622              :       /* This is either going to be an external function call with one
    4623              :          argument, or two register copy statements plus a goto.  */
    4624              :       return 2;
    4625              : 
    4626        18734 :     case GIMPLE_EH_DISPATCH:
    4627              :       /* ??? This is going to turn into a switch statement.  Ideally
    4628              :          we'd have a look at the eh region and estimate the number of
    4629              :          edges involved.  */
    4630        18734 :       return 10;
    4631              : 
    4632            0 :     case GIMPLE_BIND:
    4633            0 :       return estimate_num_insns_seq (
    4634            0 :                gimple_bind_body (as_a <gbind *> (stmt)),
    4635            0 :                weights);
    4636              : 
    4637            0 :     case GIMPLE_EH_FILTER:
    4638            0 :       return estimate_num_insns_seq (gimple_eh_filter_failure (stmt), weights);
    4639              : 
    4640         8292 :     case GIMPLE_CATCH:
    4641         8292 :       return estimate_num_insns_seq (gimple_catch_handler (
    4642         8292 :                                        as_a <gcatch *> (stmt)),
    4643         8292 :                                      weights);
    4644              : 
    4645         8297 :     case GIMPLE_TRY:
    4646         8297 :       return (estimate_num_insns_seq (gimple_try_eval (stmt), weights)
    4647         8297 :               + estimate_num_insns_seq (gimple_try_cleanup (stmt), weights));
    4648              : 
    4649              :     /* OMP directives are generally very expensive.  */
    4650              : 
    4651              :     case GIMPLE_OMP_RETURN:
    4652              :     case GIMPLE_OMP_SECTIONS_SWITCH:
    4653              :     case GIMPLE_OMP_ATOMIC_STORE:
    4654              :     case GIMPLE_OMP_CONTINUE:
    4655              :       /* ...except these, which are cheap.  */
    4656              :       return 0;
    4657              : 
    4658            0 :     case GIMPLE_OMP_ATOMIC_LOAD:
    4659            0 :       return weights->omp_cost;
    4660              : 
    4661            0 :     case GIMPLE_OMP_FOR:
    4662            0 :       return (weights->omp_cost
    4663            0 :               + estimate_num_insns_seq (gimple_omp_body (stmt), weights)
    4664            0 :               + estimate_num_insns_seq (gimple_omp_for_pre_body (stmt), weights));
    4665              : 
    4666            0 :     case GIMPLE_OMP_PARALLEL:
    4667            0 :     case GIMPLE_OMP_TASK:
    4668            0 :     case GIMPLE_OMP_CRITICAL:
    4669            0 :     case GIMPLE_OMP_MASTER:
    4670            0 :     case GIMPLE_OMP_MASKED:
    4671            0 :     case GIMPLE_OMP_SCOPE:
    4672            0 :     case GIMPLE_OMP_DISPATCH:
    4673            0 :     case GIMPLE_OMP_TASKGROUP:
    4674            0 :     case GIMPLE_OMP_ORDERED:
    4675            0 :     case GIMPLE_OMP_SCAN:
    4676            0 :     case GIMPLE_OMP_SECTION:
    4677            0 :     case GIMPLE_OMP_SECTIONS:
    4678            0 :     case GIMPLE_OMP_STRUCTURED_BLOCK:
    4679            0 :     case GIMPLE_OMP_SINGLE:
    4680            0 :     case GIMPLE_OMP_TARGET:
    4681            0 :     case GIMPLE_OMP_TEAMS:
    4682            0 :       return (weights->omp_cost
    4683            0 :               + estimate_num_insns_seq (gimple_omp_body (stmt), weights));
    4684              : 
    4685           75 :     case GIMPLE_TRANSACTION:
    4686           75 :       return (weights->tm_cost
    4687           75 :               + estimate_num_insns_seq (gimple_transaction_body (
    4688           75 :                                           as_a <gtransaction *> (stmt)),
    4689           75 :                                         weights));
    4690              : 
    4691            0 :     default:
    4692            0 :       gcc_unreachable ();
    4693              :     }
    4694              : 
    4695    474783354 :   return cost;
    4696              : }
    4697              : 
    4698              : /* Estimate number of instructions that will be created by expanding
    4699              :    function FNDECL.  WEIGHTS contains weights attributed to various
    4700              :    constructs.  */
    4701              : 
    4702              : int
    4703            0 : estimate_num_insns_fn (tree fndecl, eni_weights *weights)
    4704              : {
    4705            0 :   struct function *my_function = DECL_STRUCT_FUNCTION (fndecl);
    4706            0 :   gimple_stmt_iterator bsi;
    4707            0 :   basic_block bb;
    4708            0 :   int n = 0;
    4709              : 
    4710            0 :   gcc_assert (my_function && my_function->cfg);
    4711            0 :   FOR_EACH_BB_FN (bb, my_function)
    4712              :     {
    4713            0 :       for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
    4714            0 :         n += estimate_num_insns (gsi_stmt (bsi), weights);
    4715              :     }
    4716              : 
    4717            0 :   return n;
    4718              : }
    4719              : 
    4720              : 
    4721              : /* Initializes weights used by estimate_num_insns.  */
    4722              : 
    4723              : void
    4724       295425 : init_inline_once (void)
    4725              : {
    4726       295425 :   eni_size_weights.call_cost = 1;
    4727       295425 :   eni_size_weights.indirect_call_cost = 3;
    4728       295425 :   eni_size_weights.target_builtin_call_cost = 1;
    4729       295425 :   eni_size_weights.div_mod_cost = 1;
    4730       295425 :   eni_size_weights.omp_cost = 40;
    4731       295425 :   eni_size_weights.tm_cost = 10;
    4732       295425 :   eni_size_weights.time_based = false;
    4733       295425 :   eni_size_weights.return_cost = 1;
    4734              : 
    4735              :   /* Estimating time for call is difficult, since we have no idea what the
    4736              :      called function does.  In the current uses of eni_time_weights,
    4737              :      underestimating the cost does less harm than overestimating it, so
    4738              :      we choose a rather small value here.  */
    4739       295425 :   eni_time_weights.call_cost = 10;
    4740       295425 :   eni_time_weights.indirect_call_cost = 15;
    4741       295425 :   eni_time_weights.target_builtin_call_cost = 1;
    4742       295425 :   eni_time_weights.div_mod_cost = 10;
    4743       295425 :   eni_time_weights.omp_cost = 40;
    4744       295425 :   eni_time_weights.tm_cost = 40;
    4745       295425 :   eni_time_weights.time_based = true;
    4746       295425 :   eni_time_weights.return_cost = 2;
    4747       295425 : }
    4748              : 
    4749              : 
    4750              : /* Install new lexical TREE_BLOCK underneath 'current_block'.  */
    4751              : 
    4752              : static void
    4753     30945627 : prepend_lexical_block (tree current_block, tree new_block)
    4754              : {
    4755     30945627 :   BLOCK_CHAIN (new_block) = BLOCK_SUBBLOCKS (current_block);
    4756     30945627 :   BLOCK_SUBBLOCKS (current_block) = new_block;
    4757     30945627 :   BLOCK_SUPERCONTEXT (new_block) = current_block;
    4758     30945627 : }
    4759              : 
    4760              : /* Add local variables from CALLEE to CALLER.  */
    4761              : 
    4762              : static inline void
    4763      4788386 : add_local_variables (struct function *callee, struct function *caller,
    4764              :                      copy_body_data *id)
    4765              : {
    4766      4788386 :   tree var;
    4767      4788386 :   unsigned ix;
    4768              : 
    4769     13289790 :   FOR_EACH_LOCAL_DECL (callee, ix, var)
    4770      4480911 :     if (!can_be_nonlocal (var, id))
    4771              :       {
    4772      4390946 :         tree new_var = remap_decl (var, id);
    4773              : 
    4774              :         /* Remap debug-expressions.  */
    4775      4390946 :         if (VAR_P (new_var)
    4776      4390946 :             && DECL_HAS_DEBUG_EXPR_P (var)
    4777      4710704 :             && new_var != var)
    4778              :           {
    4779       319758 :             tree tem = DECL_DEBUG_EXPR (var);
    4780       319758 :             bool old_regimplify = id->regimplify;
    4781       319758 :             id->remapping_type_depth++;
    4782       319758 :             walk_tree (&tem, copy_tree_body_r, id, NULL);
    4783       319758 :             id->remapping_type_depth--;
    4784       319758 :             id->regimplify = old_regimplify;
    4785       319758 :             SET_DECL_DEBUG_EXPR (new_var, tem);
    4786       319758 :             DECL_HAS_DEBUG_EXPR_P (new_var) = 1;
    4787              :           }
    4788      4390946 :         add_local_decl (caller, new_var);
    4789              :       }
    4790      4788386 : }
    4791              : 
    4792              : /* Add to BINDINGS a debug stmt resetting SRCVAR if inlining might
    4793              :    have brought in or introduced any debug stmts for SRCVAR.  */
    4794              : 
    4795              : static inline void
    4796      9916876 : reset_debug_binding (copy_body_data *id, tree srcvar, gimple_seq *bindings)
    4797              : {
    4798      9916876 :   tree *remappedvarp = id->decl_map->get (srcvar);
    4799              : 
    4800      9916876 :   if (!remappedvarp)
    4801              :     return;
    4802              : 
    4803      9860846 :   if (!VAR_P (*remappedvarp))
    4804              :     return;
    4805              : 
    4806      9710912 :   if (*remappedvarp == id->retvar)
    4807              :     return;
    4808              : 
    4809      9710912 :   tree tvar = target_for_debug_bind (*remappedvarp);
    4810      9710912 :   if (!tvar)
    4811              :     return;
    4812              : 
    4813     15603302 :   gdebug *stmt = gimple_build_debug_bind (tvar, NULL_TREE,
    4814      7801651 :                                           id->call_stmt);
    4815      7801651 :   gimple_seq_add_stmt (bindings, stmt);
    4816              : }
    4817              : 
    4818              : /* For each inlined variable for which we may have debug bind stmts,
    4819              :    add before GSI a final debug stmt resetting it, marking the end of
    4820              :    its life, so that var-tracking knows it doesn't have to compute
    4821              :    further locations for it.  */
    4822              : 
    4823              : static inline void
    4824      4636319 : reset_debug_bindings (copy_body_data *id, gimple_stmt_iterator gsi)
    4825              : {
    4826      4636319 :   tree var;
    4827      4636319 :   unsigned ix;
    4828      4636319 :   gimple_seq bindings = NULL;
    4829              : 
    4830      4636319 :   if (!gimple_in_ssa_p (id->src_cfun))
    4831       563582 :     return;
    4832              : 
    4833      4636319 :   if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
    4834              :     return;
    4835              : 
    4836      4072737 :   for (var = DECL_ARGUMENTS (id->src_fn);
    4837     11078797 :        var; var = DECL_CHAIN (var))
    4838      7006060 :     reset_debug_binding (id, var, &bindings);
    4839              : 
    4840     10403472 :   FOR_EACH_LOCAL_DECL (id->src_cfun, ix, var)
    4841      2910816 :     reset_debug_binding (id, var, &bindings);
    4842              : 
    4843      4072737 :   gsi_insert_seq_before_without_update (&gsi, bindings, GSI_SAME_STMT);
    4844              : }
    4845              : 
    4846              : /* If STMT is a GIMPLE_CALL, replace it with its inline expansion.  */
    4847              : 
    4848              : static bool
    4849     15966912 : expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
    4850              :                     bitmap to_purge)
    4851              : {
    4852     15966912 :   tree use_retvar;
    4853     15966912 :   tree fn;
    4854     15966912 :   hash_map<tree, tree> *dst;
    4855     15966912 :   hash_map<tree, tree> *st = NULL;
    4856     15966912 :   tree return_slot;
    4857     15966912 :   tree modify_dest;
    4858     15966912 :   struct cgraph_edge *cg_edge;
    4859     15966912 :   cgraph_inline_failed_t reason;
    4860     15966912 :   basic_block return_block;
    4861     15966912 :   edge e;
    4862     15966912 :   gimple_stmt_iterator gsi, stmt_gsi;
    4863     15966912 :   bool successfully_inlined = false;
    4864     15966912 :   bool purge_dead_abnormal_edges;
    4865     15966912 :   gcall *call_stmt;
    4866     15966912 :   unsigned int prop_mask, src_properties;
    4867     15966912 :   struct function *dst_cfun;
    4868     15966912 :   tree simduid;
    4869     15966912 :   use_operand_p use;
    4870     15966912 :   gimple *simtenter_stmt = NULL;
    4871     15966912 :   vec<tree> *simtvars_save;
    4872     15966912 :   tree save_stack = NULL_TREE;
    4873              : 
    4874              :   /* The gimplifier uses input_location in too many places, such as
    4875              :      internal_get_tmp_var ().  */
    4876     15966912 :   location_t saved_location = input_location;
    4877     15966912 :   input_location = gimple_location (stmt);
    4878              : 
    4879              :   /* From here on, we're only interested in CALL_EXPRs.  */
    4880     15966912 :   call_stmt = dyn_cast <gcall *> (stmt);
    4881     15966912 :   if (!call_stmt)
    4882            0 :     goto egress;
    4883              : 
    4884     15966912 :   cg_edge = id->dst_node->get_edge (stmt);
    4885              :   /* Edge should exist and speculations should be resolved at this
    4886              :      stage.  */
    4887     15966912 :   gcc_checking_assert (cg_edge && !cg_edge->speculative);
    4888              :   /* First, see if we can figure out what function is being called.
    4889              :      If we cannot, then there is no hope of inlining the function.  */
    4890     15966912 :   if (cg_edge->indirect_unknown_callee)
    4891       242243 :     goto egress;
    4892     15724669 :   fn = cg_edge->callee->decl;
    4893     15724669 :   gcc_checking_assert (fn);
    4894              : 
    4895              :   /* If FN is a declaration of a function in a nested scope that was
    4896              :      globally declared inline, we don't set its DECL_INITIAL.
    4897              :      However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the
    4898              :      C++ front-end uses it for cdtors to refer to their internal
    4899              :      declarations, that are not real functions.  Fortunately those
    4900              :      don't have trees to be saved, so we can tell by checking their
    4901              :      gimple_body.  */
    4902     15724669 :   if (!DECL_INITIAL (fn)
    4903      6981981 :       && DECL_ABSTRACT_ORIGIN (fn)
    4904     15859738 :       && gimple_has_body_p (DECL_ABSTRACT_ORIGIN (fn)))
    4905          289 :     fn = DECL_ABSTRACT_ORIGIN (fn);
    4906              : 
    4907              :   /* Don't try to inline functions that are not well-suited to inlining.  */
    4908     15724669 :   if (cg_edge->inline_failed)
    4909              :     {
    4910     11088152 :       reason = cg_edge->inline_failed;
    4911              :       /* If this call was originally indirect, we do not want to emit any
    4912              :          inlining related warnings or sorry messages because there are no
    4913              :          guarantees regarding those.  */
    4914     11088152 :       if (cg_edge->indirect_inlining_edge)
    4915         1965 :         goto egress;
    4916              : 
    4917     11086187 :       if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn))
    4918              :           /* For extern inline functions that get redefined we always
    4919              :              silently ignored always_inline flag. Better behavior would
    4920              :              be to be able to keep both bodies and use extern inline body
    4921              :              for inlining, but we can't do that because frontends overwrite
    4922              :              the body.  */
    4923           63 :           && !cg_edge->callee->redefined_extern_inline
    4924              :           /* During early inline pass, report only when optimization is
    4925              :              not turned on.  */
    4926           63 :           && (symtab->global_info_ready
    4927           61 :               || !optimize
    4928           51 :               || cgraph_inline_failed_type (reason) == CIF_FINAL_ERROR)
    4929              :           /* PR 20090218-1_0.c. Body can be provided by another module. */
    4930     11086221 :           && (reason != CIF_BODY_NOT_AVAILABLE || !flag_generate_lto))
    4931              :         {
    4932           27 :           error ("inlining failed in call to %<always_inline%> %q+F: %s", fn,
    4933              :                  cgraph_inline_failed_string (reason));
    4934           27 :           if (gimple_location (stmt) != UNKNOWN_LOCATION)
    4935           27 :             inform (gimple_location (stmt), "called from here");
    4936            0 :           else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
    4937            0 :             inform (DECL_SOURCE_LOCATION (cfun->decl),
    4938              :                    "called from this function");
    4939              :         }
    4940     11086160 :       else if (opt_for_fn (fn, warn_inline)
    4941          339 :                && DECL_DECLARED_INLINE_P (fn)
    4942          110 :                && !DECL_NO_INLINE_WARNING_P (fn)
    4943           77 :                && !DECL_IN_SYSTEM_HEADER (fn)
    4944           60 :                && reason != CIF_UNSPECIFIED
    4945           60 :                && !lookup_attribute ("noinline", DECL_ATTRIBUTES (fn))
    4946              :                /* Do not warn about not inlined recursive calls.  */
    4947           60 :                && !cg_edge->recursive_p ()
    4948              :                /* Avoid warnings during early inline pass. */
    4949     11086220 :                && symtab->global_info_ready)
    4950              :         {
    4951            8 :           auto_diagnostic_group d;
    4952            8 :           if (warning (OPT_Winline, "inlining failed in call to %q+F: %s",
    4953              :                        fn, _(cgraph_inline_failed_string (reason))))
    4954              :             {
    4955            8 :               if (gimple_location (stmt) != UNKNOWN_LOCATION)
    4956            8 :                 inform (gimple_location (stmt), "called from here");
    4957            0 :               else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION)
    4958            0 :                 inform (DECL_SOURCE_LOCATION (cfun->decl),
    4959              :                        "called from this function");
    4960              :             }
    4961            8 :         }
    4962     11086187 :       goto egress;
    4963              :     }
    4964      4636517 :   id->src_node = cg_edge->callee;
    4965              : 
    4966              :   /* If callee is thunk, all we need is to adjust the THIS pointer
    4967              :      and redirect to function being thunked.  */
    4968      4636517 :   if (id->src_node->thunk)
    4969              :     {
    4970          198 :       cgraph_edge *edge;
    4971          198 :       tree virtual_offset = NULL;
    4972          198 :       profile_count count = cg_edge->count;
    4973          198 :       tree op;
    4974          198 :       gimple_stmt_iterator iter = gsi_for_stmt (stmt);
    4975          198 :       thunk_info *info = thunk_info::get (id->src_node);
    4976              : 
    4977          198 :       cgraph_edge::remove (cg_edge);
    4978          396 :       edge = id->src_node->callees->clone (id->dst_node, call_stmt,
    4979              :                                            gimple_uid (stmt),
    4980              :                                            profile_count::one (),
    4981              :                                            profile_count::one (),
    4982              :                                            true);
    4983          198 :       edge->count = count;
    4984          198 :       if (info->virtual_offset_p)
    4985            7 :         virtual_offset = size_int (info->virtual_value);
    4986          198 :       op = create_tmp_reg_fn (cfun, TREE_TYPE (gimple_call_arg (stmt, 0)),
    4987              :                               NULL);
    4988          198 :       gsi_insert_before (&iter, gimple_build_assign (op,
    4989              :                                                     gimple_call_arg (stmt, 0)),
    4990              :                          GSI_NEW_STMT);
    4991          198 :       gcc_assert (info->this_adjusting);
    4992          198 :       op = thunk_adjust (&iter, op, 1, info->fixed_offset,
    4993              :                          virtual_offset, info->indirect_offset);
    4994              : 
    4995          198 :       gimple_call_set_arg (stmt, 0, op);
    4996          198 :       gimple_call_set_fndecl (stmt, edge->callee->decl);
    4997          198 :       update_stmt (stmt);
    4998          198 :       id->src_node->remove ();
    4999          198 :       successfully_inlined = expand_call_inline (bb, stmt, id, to_purge);
    5000          198 :       maybe_remove_unused_call_args (cfun, stmt);
    5001              :       /* This used to return true even though we do fail to inline in
    5002              :          some cases.  See PR98525.  */
    5003          198 :       goto egress;
    5004              :     }
    5005      4636319 :   fn = cg_edge->callee->decl;
    5006      4636319 :   cg_edge->callee->get_untransformed_body ();
    5007              : 
    5008      4636319 :   if (flag_checking && cg_edge->callee->decl != id->dst_node->decl)
    5009      4636310 :     cg_edge->callee->verify ();
    5010              : 
    5011              :   /* We will be inlining this callee.  */
    5012      4636319 :   id->eh_lp_nr = lookup_stmt_eh_lp (stmt);
    5013              : 
    5014              :   /* Update the callers EH personality.  */
    5015      4636319 :   if (DECL_FUNCTION_PERSONALITY (fn))
    5016       299258 :     DECL_FUNCTION_PERSONALITY (cg_edge->caller->decl)
    5017       149629 :       = DECL_FUNCTION_PERSONALITY (fn);
    5018              : 
    5019              :   /* Split the block before the GIMPLE_CALL.  */
    5020      4636319 :   stmt_gsi = gsi_for_stmt (stmt);
    5021      4636319 :   gsi_prev (&stmt_gsi);
    5022      4636319 :   e = split_block (bb, gsi_end_p (stmt_gsi) ? NULL : gsi_stmt (stmt_gsi));
    5023      4636319 :   bb = e->src;
    5024      4636319 :   return_block = e->dest;
    5025      4636319 :   remove_edge (e);
    5026              : 
    5027              :   /* If the GIMPLE_CALL was in the last statement of BB, it may have
    5028              :      been the source of abnormal edges.  In this case, schedule
    5029              :      the removal of dead abnormal edges.  */
    5030      4636319 :   gsi = gsi_start_bb (return_block);
    5031      4636319 :   gsi_next (&gsi);
    5032      4636319 :   purge_dead_abnormal_edges = gsi_end_p (gsi);
    5033              : 
    5034      4636319 :   stmt_gsi = gsi_start_bb (return_block);
    5035              : 
    5036              :   /* Build a block containing code to initialize the arguments, the
    5037              :      actual inline expansion of the body, and a label for the return
    5038              :      statements within the function to jump to.  The type of the
    5039              :      statement expression is the return type of the function call.
    5040              :      ???  If the call does not have an associated block then we will
    5041              :      remap all callee blocks to NULL, effectively dropping most of
    5042              :      its debug information.  This should only happen for calls to
    5043              :      artificial decls inserted by the compiler itself.  We need to
    5044              :      either link the inlined blocks into the caller block tree or
    5045              :      not refer to them in any way to not break GC for locations.  */
    5046      4636319 :   if (tree block = gimple_block (stmt))
    5047              :     {
    5048              :       /* We do want to assign a not UNKNOWN_LOCATION BLOCK_SOURCE_LOCATION
    5049              :          to make inlined_function_outer_scope_p return true on this BLOCK.  */
    5050      4609363 :       location_t loc = LOCATION_LOCUS (gimple_location (stmt));
    5051      4609363 :       if (loc == UNKNOWN_LOCATION)
    5052       260059 :         loc = LOCATION_LOCUS (DECL_SOURCE_LOCATION (fn));
    5053       260059 :       if (loc == UNKNOWN_LOCATION)
    5054              :         loc = BUILTINS_LOCATION;
    5055      4609363 :       if (has_discriminator (gimple_location (stmt)))
    5056      1611611 :         loc = location_with_discriminator
    5057      1611611 :                 (loc, get_discriminator_from_loc (gimple_location (stmt)));
    5058      4609363 :       id->block = make_node (BLOCK);
    5059      7930687 :       BLOCK_ABSTRACT_ORIGIN (id->block) = DECL_ORIGIN (fn);
    5060      4609363 :       copy_debug_abstract_origin (id->block, fn);
    5061      4609363 :       BLOCK_SOURCE_LOCATION (id->block) = loc;
    5062      4609363 :       prepend_lexical_block (block, id->block);
    5063              :     }
    5064              : 
    5065              :   /* Local declarations will be replaced by their equivalents in this map.  */
    5066      4636319 :   st = id->decl_map;
    5067      4636319 :   id->decl_map = new hash_map<tree, tree>;
    5068      4636319 :   dst = id->debug_map;
    5069      4636319 :   id->debug_map = NULL;
    5070      4636319 :   if (flag_stack_reuse != SR_NONE)
    5071      4629244 :     id->add_clobbers_to_eh_landing_pads = last_basic_block_for_fn (cfun);
    5072              : 
    5073              :   /* Record the function we are about to inline.  */
    5074      4636319 :   id->src_fn = fn;
    5075      4636319 :   id->src_cfun = DECL_STRUCT_FUNCTION (fn);
    5076      4636319 :   id->reset_location = DECL_IGNORED_P (fn);
    5077      4636319 :   id->call_stmt = call_stmt;
    5078      4636319 :   cfun->cfg->full_profile &= id->src_cfun->cfg->full_profile;
    5079              : 
    5080              :   /* When inlining into an OpenMP SIMD-on-SIMT loop, arrange for new automatic
    5081              :      variables to be added to IFN_GOMP_SIMT_ENTER argument list.  */
    5082      4636319 :   dst_cfun = DECL_STRUCT_FUNCTION (id->dst_fn);
    5083      4636319 :   simtvars_save = id->dst_simt_vars;
    5084      4636319 :   if (!(dst_cfun->curr_properties & PROP_gimple_lomp_dev)
    5085        21519 :       && (simduid = bb->loop_father->simduid) != NULL_TREE
    5086            0 :       && (simduid = ssa_default_def (dst_cfun, simduid)) != NULL_TREE
    5087            0 :       && single_imm_use (simduid, &use, &simtenter_stmt)
    5088            0 :       && is_gimple_call (simtenter_stmt)
    5089      4636319 :       && gimple_call_internal_p (simtenter_stmt, IFN_GOMP_SIMT_ENTER))
    5090            0 :     vec_alloc (id->dst_simt_vars, 0);
    5091              :   else
    5092      4636319 :     id->dst_simt_vars = NULL;
    5093              : 
    5094      4636319 :   if (profile_status_for_fn (id->src_cfun) == PROFILE_ABSENT)
    5095        31349 :     profile_status_for_fn (dst_cfun) = PROFILE_ABSENT;
    5096              : 
    5097              :   /* If the src function contains an IFN_VA_ARG, then so will the dst
    5098              :      function after inlining.  Likewise for IFN_GOMP_USE_SIMT.  */
    5099      4636319 :   prop_mask = PROP_gimple_lva | PROP_gimple_lomp_dev;
    5100      4636319 :   src_properties = id->src_cfun->curr_properties & prop_mask;
    5101      4636319 :   if (src_properties != prop_mask)
    5102         1063 :     dst_cfun->curr_properties &= src_properties | ~prop_mask;
    5103      4636319 :   dst_cfun->calls_eh_return |= id->src_cfun->calls_eh_return;
    5104      4636319 :   id->dst_node->has_omp_variant_constructs
    5105      4636319 :     |= id->src_node->has_omp_variant_constructs;
    5106              : 
    5107      4636319 :   gcc_assert (!id->src_cfun->after_inlining);
    5108              : 
    5109      4636319 :   id->entry_bb = bb;
    5110      4636319 :   if (lookup_attribute ("cold", DECL_ATTRIBUTES (fn)))
    5111              :     {
    5112         1463 :       gimple_stmt_iterator si = gsi_last_bb (bb);
    5113         1463 :       gsi_insert_after (&si, gimple_build_predict (PRED_COLD_FUNCTION,
    5114              :                                                    NOT_TAKEN),
    5115              :                         GSI_NEW_STMT);
    5116              :     }
    5117      4636319 :   initialize_inlined_parameters (id, stmt, fn, bb);
    5118      4072755 :   if (debug_nonbind_markers_p && debug_inline_points && id->block
    5119      8696991 :       && inlined_function_outer_scope_p (id->block))
    5120              :     {
    5121      4060672 :       gimple_stmt_iterator si = gsi_last_bb (bb);
    5122      4060672 :       gsi_insert_after (&si, gimple_build_debug_inline_entry
    5123      4060672 :                         (id->block, DECL_SOURCE_LOCATION (id->src_fn)),
    5124              :                         GSI_NEW_STMT);
    5125              :     }
    5126              : 
    5127              :   /* If function to be inlined calls alloca, wrap the inlined function
    5128              :      in between save_stack = __builtin_stack_save (); and
    5129              :      __builtin_stack_restore (save_stack); calls.  */
    5130      4636319 :   if (id->src_cfun->calls_alloca && !gimple_call_noreturn_p (stmt))
    5131              :     /* Don't do this for VLA allocations though, just for user alloca
    5132              :        calls.  */
    5133         4871 :     for (struct cgraph_edge *e = id->src_node->callees; e; e = e->next_callee)
    5134         4452 :       if (gimple_maybe_alloca_call_p (e->call_stmt)
    5135         4452 :           && !gimple_call_alloca_for_var_p (e->call_stmt))
    5136              :         {
    5137           88 :           tree fn = builtin_decl_implicit (BUILT_IN_STACK_SAVE);
    5138           88 :           gcall *call = gimple_build_call (fn, 0);
    5139           88 :           save_stack = make_ssa_name (ptr_type_node);
    5140           88 :           gimple_call_set_lhs (call, save_stack);
    5141           88 :           gimple_stmt_iterator si = gsi_last_bb (bb);
    5142           88 :           gsi_insert_after (&si, call, GSI_NEW_STMT);
    5143           88 :           struct cgraph_node *dest = cgraph_node::get_create (fn);
    5144           88 :           id->dst_node->create_edge (dest, call, bb->count)->inline_failed
    5145           88 :             = CIF_BODY_NOT_AVAILABLE;
    5146           88 :           break;
    5147              :         }
    5148              : 
    5149      4636319 :   if (DECL_INITIAL (fn))
    5150              :     {
    5151      4636319 :       if (gimple_block (stmt))
    5152              :         {
    5153      4609363 :           tree *var;
    5154              : 
    5155      4609363 :           prepend_lexical_block (id->block,
    5156      4609363 :                                  remap_blocks (DECL_INITIAL (fn), id));
    5157      4609363 :           gcc_checking_assert (BLOCK_SUBBLOCKS (id->block)
    5158              :                                && (BLOCK_CHAIN (BLOCK_SUBBLOCKS (id->block))
    5159              :                                    == NULL_TREE));
    5160              :           /* Move vars for PARM_DECLs from DECL_INITIAL block to id->block,
    5161              :              otherwise for DWARF DW_TAG_formal_parameter will not be children of
    5162              :              DW_TAG_inlined_subroutine, but of a DW_TAG_lexical_block
    5163              :              under it.  The parameters can be then evaluated in the debugger,
    5164              :              but don't show in backtraces.  */
    5165      6780063 :           for (var = &BLOCK_VARS (BLOCK_SUBBLOCKS (id->block)); *var; )
    5166      2170700 :             if (TREE_CODE (DECL_ORIGIN (*var)) == PARM_DECL)
    5167              :               {
    5168       584887 :                 tree v = *var;
    5169       584887 :                 *var = TREE_CHAIN (v);
    5170       584887 :                 TREE_CHAIN (v) = BLOCK_VARS (id->block);
    5171       584887 :                 BLOCK_VARS (id->block) = v;
    5172              :               }
    5173              :             else
    5174      1585813 :               var = &TREE_CHAIN (*var);
    5175              :         }
    5176              :       else
    5177        26956 :         remap_blocks_to_null (DECL_INITIAL (fn), id);
    5178              :     }
    5179              : 
    5180              :   /* Return statements in the function body will be replaced by jumps
    5181              :      to the RET_LABEL.  */
    5182      4636319 :   gcc_assert (DECL_INITIAL (fn));
    5183      4636319 :   gcc_assert (TREE_CODE (DECL_INITIAL (fn)) == BLOCK);
    5184              : 
    5185              :   /* Find the LHS to which the result of this call is assigned.  */
    5186      4636319 :   return_slot = NULL;
    5187      4636319 :   if (gimple_call_lhs (stmt))
    5188              :     {
    5189      2336702 :       modify_dest = gimple_call_lhs (stmt);
    5190              : 
    5191              :       /* The function which we are inlining might not return a value,
    5192              :          in which case we should issue a warning that the function
    5193              :          does not return a value.  In that case the optimizers will
    5194              :          see that the variable to which the value is assigned was not
    5195              :          initialized.  We do not want to issue a warning about that
    5196              :          uninitialized variable.  */
    5197      2336702 :       if (DECL_P (modify_dest))
    5198       502599 :         suppress_warning (modify_dest, OPT_Wuninitialized);
    5199              : 
    5200              :       /* If we have a return slot, we can assign it the result directly,
    5201              :          except in the case where it is a global variable that is only
    5202              :          written to because, the callee being permitted to read or take
    5203              :          the address of its DECL_RESULT, this could invalidate the flag
    5204              :          on the global variable; instead we preventively remove the store,
    5205              :          which would have happened later if the call was not inlined.  */
    5206      2336702 :       if (gimple_call_return_slot_opt_p (call_stmt))
    5207              :         {
    5208       143554 :           tree base = get_base_address (modify_dest);
    5209              : 
    5210       143554 :           if (VAR_P (base)
    5211       118863 :               && (TREE_STATIC (base) || DECL_EXTERNAL (base))
    5212       143626 :               && varpool_node::get (base)->writeonly)
    5213              :             return_slot = NULL;
    5214              :           else
    5215              :             return_slot = modify_dest;
    5216              : 
    5217              :           modify_dest = NULL;
    5218              :         }
    5219              :     }
    5220              :   else
    5221              :     modify_dest = NULL;
    5222              : 
    5223              :   /* If we are inlining a call to the C++ operator new, we don't want
    5224              :      to use type based alias analysis on the return value.  Otherwise
    5225              :      we may get confused if the compiler sees that the inlined new
    5226              :      function returns a pointer which was just deleted.  See bug
    5227              :      33407.  */
    5228      4636319 :   if (DECL_IS_OPERATOR_NEW_P (fn))
    5229              :     {
    5230        20253 :       return_slot = NULL;
    5231        20253 :       modify_dest = NULL;
    5232              :     }
    5233              : 
    5234              :   /* Declare the return variable for the function.  */
    5235      4636319 :   use_retvar = declare_return_variable (id, return_slot, modify_dest, bb);
    5236              : 
    5237              :   /* Add local vars in this inlined callee to caller.  */
    5238      4636319 :   add_local_variables (id->src_cfun, cfun, id);
    5239              : 
    5240      4636319 :   if (dump_enabled_p ())
    5241              :     {
    5242          774 :       char buf[128];
    5243          774 :       snprintf (buf, sizeof(buf), "%4.2f",
    5244          774 :                 cg_edge->sreal_frequency ().to_double ());
    5245          774 :       dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS,
    5246          774 :                        call_stmt,
    5247              :                        "Inlining %C to %C with frequency %s\n",
    5248              :                        id->src_node, id->dst_node, buf);
    5249          774 :       if (dump_file && (dump_flags & TDF_DETAILS))
    5250              :         {
    5251          281 :           id->src_node->dump (dump_file);
    5252          281 :           id->dst_node->dump (dump_file);
    5253              :         }
    5254              :     }
    5255              : 
    5256              :   /* This is it.  Duplicate the callee body.  Assume callee is
    5257              :      pre-gimplified.  Note that we must not alter the caller
    5258              :      function in any way before this point, as this CALL_EXPR may be
    5259              :      a self-referential call; if we're calling ourselves, we need to
    5260              :      duplicate our body before altering anything.  */
    5261      4636319 :   copy_body (id, bb, return_block, NULL);
    5262              : 
    5263      4636319 :   reset_debug_bindings (id, stmt_gsi);
    5264              : 
    5265      4636319 :   if (flag_stack_reuse != SR_NONE)
    5266     12538716 :     for (tree p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
    5267      7909472 :       if (!TREE_THIS_VOLATILE (p))
    5268              :         {
    5269              :           /* The value associated with P is a local temporary only if
    5270              :              there is no value associated with P in the debug map.  */
    5271      7909199 :           tree *varp = id->decl_map->get (p);
    5272      7909199 :           if (varp
    5273      7909199 :               && VAR_P (*varp)
    5274      7743236 :               && !is_gimple_reg (*varp)
    5275      8349976 :               && !(id->debug_map && id->debug_map->get (p)))
    5276              :             {
    5277       440362 :               tree clobber = build_clobber (TREE_TYPE (*varp),
    5278              :                                             CLOBBER_STORAGE_END);
    5279       440362 :               gimple *clobber_stmt;
    5280       440362 :               clobber_stmt = gimple_build_assign (*varp, clobber);
    5281       440362 :               gimple_set_location (clobber_stmt, gimple_location (stmt));
    5282       440362 :               gsi_insert_before (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
    5283              :             }
    5284              :         }
    5285              : 
    5286      4636319 :   if (save_stack)
    5287              :     {
    5288           88 :       tree fn = builtin_decl_implicit (BUILT_IN_STACK_RESTORE);
    5289           88 :       gcall *call = gimple_build_call (fn, 1, save_stack);
    5290           88 :       gsi_insert_before (&stmt_gsi, call, GSI_SAME_STMT);
    5291           88 :       struct cgraph_node *dest = cgraph_node::get_create (fn);
    5292           88 :       id->dst_node->create_edge (dest, call,
    5293              :                                  return_block->count)->inline_failed
    5294           88 :         = CIF_BODY_NOT_AVAILABLE;
    5295              :     }
    5296              : 
    5297              :   /* Reset the escaped solution.  */
    5298      4636319 :   if (cfun->gimple_df)
    5299              :     {
    5300      4636319 :       pt_solution_reset (&cfun->gimple_df->escaped);
    5301      4636319 :       pt_solution_reset (&cfun->gimple_df->escaped_return);
    5302              :     }
    5303              : 
    5304              :   /* Add new automatic variables to IFN_GOMP_SIMT_ENTER arguments.  */
    5305      4636319 :   if (id->dst_simt_vars && id->dst_simt_vars->length () > 0)
    5306              :     {
    5307            0 :       size_t nargs = gimple_call_num_args (simtenter_stmt);
    5308            0 :       vec<tree> *vars = id->dst_simt_vars;
    5309            0 :       auto_vec<tree> newargs (nargs + vars->length ());
    5310            0 :       for (size_t i = 0; i < nargs; i++)
    5311            0 :         newargs.quick_push (gimple_call_arg (simtenter_stmt, i));
    5312            0 :       for (tree *pvar = vars->begin (); pvar != vars->end (); pvar++)
    5313              :         {
    5314            0 :           tree ptrtype = build_pointer_type (TREE_TYPE (*pvar));
    5315            0 :           newargs.quick_push (build1 (ADDR_EXPR, ptrtype, *pvar));
    5316              :         }
    5317            0 :       gcall *g = gimple_build_call_internal_vec (IFN_GOMP_SIMT_ENTER, newargs);
    5318            0 :       gimple_call_set_lhs (g, gimple_call_lhs (simtenter_stmt));
    5319            0 :       gimple_stmt_iterator gsi = gsi_for_stmt (simtenter_stmt);
    5320            0 :       gsi_replace (&gsi, g, false);
    5321            0 :     }
    5322      4636319 :   vec_free (id->dst_simt_vars);
    5323      4636319 :   id->dst_simt_vars = simtvars_save;
    5324              : 
    5325              :   /* Clean up.  */
    5326      4636319 :   if (id->debug_map)
    5327              :     {
    5328       161112 :       delete id->debug_map;
    5329       161112 :       id->debug_map = dst;
    5330              :     }
    5331      9272638 :   delete id->decl_map;
    5332      4636319 :   id->decl_map = st;
    5333              : 
    5334              :   /* Unlink the calls virtual operands before replacing it.  */
    5335      4636319 :   unlink_stmt_vdef (stmt);
    5336      4636319 :   if (gimple_vdef (stmt)
    5337      4636319 :       && TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
    5338      2160076 :     release_ssa_name (gimple_vdef (stmt));
    5339              : 
    5340              :   /* If the inlined function returns a result that we care about,
    5341              :      substitute the GIMPLE_CALL with an assignment of the return
    5342              :      variable to the LHS of the call.  That is, if STMT was
    5343              :      'a = foo (...)', substitute the call with 'a = USE_RETVAR'.  */
    5344      4636319 :   if (use_retvar && gimple_call_lhs (stmt))
    5345              :     {
    5346      1914366 :       gimple *old_stmt = stmt;
    5347      1914366 :       tree lhs = gimple_call_lhs (stmt);
    5348      1914366 :       if (!is_gimple_reg (lhs)
    5349       107167 :           && !is_gimple_reg (use_retvar)
    5350      2021491 :           && is_gimple_reg_type (TREE_TYPE (lhs)))
    5351              :         {
    5352              :           /* If both lhs and use_retvar aren't gimple regs, yet have
    5353              :              gimple reg type, copy through a temporary SSA_NAME.  */
    5354            0 :           gassign *g = gimple_build_assign (make_ssa_name (TREE_TYPE (lhs)),
    5355              :                                             use_retvar);
    5356            0 :           gimple_set_location (g, gimple_location (old_stmt));
    5357            0 :           gsi_insert_before (&stmt_gsi, g, GSI_SAME_STMT);
    5358            0 :           use_retvar = gimple_assign_lhs (g);
    5359              :         }
    5360      1914366 :       stmt = gimple_build_assign (lhs, use_retvar);
    5361      1914366 :       gimple_set_location (stmt, gimple_location (old_stmt));
    5362      1914366 :       gsi_replace (&stmt_gsi, stmt, false);
    5363      1914366 :       maybe_clean_or_replace_eh_stmt (old_stmt, stmt);
    5364              :       /* Append a clobber for id->retvar if easily possible.  */
    5365      1914366 :       if (flag_stack_reuse != SR_NONE
    5366      1912214 :           && id->retvar
    5367      1912214 :           && VAR_P (id->retvar)
    5368      1912214 :           && id->retvar != return_slot
    5369      1912214 :           && id->retvar != modify_dest
    5370      1912214 :           && !TREE_THIS_VOLATILE (id->retvar)
    5371      1912184 :           && !is_gimple_reg (id->retvar)
    5372      2022544 :           && !stmt_ends_bb_p (stmt))
    5373              :         {
    5374       108175 :           tree clobber = build_clobber (TREE_TYPE (id->retvar),
    5375              :                                         CLOBBER_STORAGE_END);
    5376       108175 :           gimple *clobber_stmt;
    5377       108175 :           clobber_stmt = gimple_build_assign (id->retvar, clobber);
    5378       108175 :           gimple_set_location (clobber_stmt, gimple_location (old_stmt));
    5379       108175 :           gsi_insert_after (&stmt_gsi, clobber_stmt, GSI_SAME_STMT);
    5380              :         }
    5381              :     }
    5382              :   else
    5383              :     {
    5384              :       /* Handle the case of inlining a function with no return
    5385              :          statement, which causes the return value to become undefined.  */
    5386      2721953 :       if (gimple_call_lhs (stmt)
    5387      2721953 :           && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
    5388              :         {
    5389           21 :           tree name = gimple_call_lhs (stmt);
    5390           21 :           tree var = SSA_NAME_VAR (name);
    5391            6 :           tree def = var ? ssa_default_def (cfun, var) : NULL;
    5392              : 
    5393            6 :           if (def)
    5394              :             {
    5395              :               /* If the variable is used undefined, make this name
    5396              :                  undefined via a move.  */
    5397            0 :               stmt = gimple_build_assign (gimple_call_lhs (stmt), def);
    5398            0 :               gsi_replace (&stmt_gsi, stmt, true);
    5399              :             }
    5400              :           else
    5401              :             {
    5402           21 :               if (!var)
    5403              :                 {
    5404           15 :                   var = create_tmp_reg_fn (cfun, TREE_TYPE (name), NULL);
    5405           30 :                   SET_SSA_NAME_VAR_OR_IDENTIFIER (name, var);
    5406              :                 }
    5407              :               /* Otherwise make this variable undefined.  */
    5408           21 :               gsi_remove (&stmt_gsi, true);
    5409           21 :               set_ssa_default_def (cfun, var, name);
    5410           21 :               SSA_NAME_DEF_STMT (name) = gimple_build_nop ();
    5411              :             }
    5412              :         }
    5413              :       /* Replace with a clobber for id->retvar.  */
    5414      2721932 :       else if (flag_stack_reuse != SR_NONE
    5415      2717009 :                && id->retvar
    5416       570945 :                && VAR_P (id->retvar)
    5417       479388 :                && id->retvar != return_slot
    5418       426504 :                && id->retvar != modify_dest
    5419       149105 :                && !TREE_THIS_VOLATILE (id->retvar)
    5420      2871037 :                && !is_gimple_reg (id->retvar))
    5421              :         {
    5422        15205 :           tree clobber = build_clobber (TREE_TYPE (id->retvar));
    5423        15205 :           gimple *clobber_stmt;
    5424        15205 :           clobber_stmt = gimple_build_assign (id->retvar, clobber);
    5425        15205 :           gimple_set_location (clobber_stmt, gimple_location (stmt));
    5426        15205 :           gsi_replace (&stmt_gsi, clobber_stmt, false);
    5427        15205 :           maybe_clean_or_replace_eh_stmt (stmt, clobber_stmt);
    5428              :         }
    5429              :       else
    5430      2706727 :         gsi_remove (&stmt_gsi, true);
    5431              :     }
    5432              : 
    5433      4636319 :   if (purge_dead_abnormal_edges)
    5434      1129614 :     bitmap_set_bit (to_purge, return_block->index);
    5435              : 
    5436              :   /* If the value of the new expression is ignored, that's OK.  We
    5437              :      don't warn about this for CALL_EXPRs, so we shouldn't warn about
    5438              :      the equivalent inlined version either.  */
    5439      4636319 :   if (auto assign = dyn_cast<gassign *> (stmt))
    5440              :     {
    5441      1914366 :       gcc_assert (gimple_assign_single_p (assign)
    5442              :                   || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (assign)));
    5443      1914366 :       TREE_USED (gimple_assign_rhs1 (assign)) = 1;
    5444              :     }
    5445              : 
    5446      4636319 :   id->add_clobbers_to_eh_landing_pads = 0;
    5447              : 
    5448              :   /* Output the inlining info for this abstract function, since it has been
    5449              :      inlined.  If we don't do this now, we can lose the information about the
    5450              :      variables in the function when the blocks get blown away as soon as we
    5451              :      remove the cgraph node.  */
    5452      4636319 :   if (gimple_block (stmt))
    5453      4609363 :     (*debug_hooks->outlining_inline_function) (fn);
    5454              : 
    5455              :   /* Update callgraph if needed.  */
    5456      4636319 :   cg_edge->callee->remove ();
    5457              : 
    5458      4636319 :   id->block = NULL_TREE;
    5459      4636319 :   id->retvar = NULL_TREE;
    5460      4636319 :   successfully_inlined = true;
    5461              : 
    5462     15966912 :  egress:
    5463     15966912 :   input_location = saved_location;
    5464     15966912 :   return successfully_inlined;
    5465              : }
    5466              : 
    5467              : /* Expand call statements reachable from STMT_P.
    5468              :    We can only have CALL_EXPRs as the "toplevel" tree code or nested
    5469              :    in a MODIFY_EXPR.  */
    5470              : 
    5471              : static bool
    5472     32941651 : gimple_expand_calls_inline (basic_block bb, copy_body_data *id,
    5473              :                             bitmap to_purge)
    5474              : {
    5475     32941651 :   gimple_stmt_iterator gsi;
    5476     32941651 :   bool inlined = false;
    5477              : 
    5478    244581163 :   for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
    5479              :     {
    5480    178697861 :       gimple *stmt = gsi_stmt (gsi);
    5481    178697861 :       gsi_prev (&gsi);
    5482              : 
    5483    178697861 :       if (is_gimple_call (stmt)
    5484    178697861 :           && !gimple_call_internal_p (stmt))
    5485     15966714 :         inlined |= expand_call_inline (bb, stmt, id, to_purge);
    5486              :     }
    5487              : 
    5488     32941651 :   return inlined;
    5489              : }
    5490              : 
    5491              : 
    5492              : /* Walk all basic blocks created after FIRST and try to fold every statement
    5493              :    in the STATEMENTS pointer set.  */
    5494              : 
    5495              : static void
    5496      1668146 : fold_marked_statements (int first, hash_set<gimple *> *statements)
    5497              : {
    5498      1668146 :   auto_bitmap to_purge;
    5499      1668146 :   auto_bitmap to_purge_abnormal;
    5500              : 
    5501      1668146 :   auto_vec<edge, 20> stack (n_basic_blocks_for_fn (cfun) + 2);
    5502      1668146 :   auto_sbitmap visited (last_basic_block_for_fn (cfun));
    5503      1668146 :   bitmap_clear (visited);
    5504              : 
    5505      1668146 :   stack.quick_push (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
    5506     40714370 :   while (!stack.is_empty ())
    5507              :     {
    5508              :       /* Look at the edge on the top of the stack.  */
    5509     39046224 :       edge e = stack.pop ();
    5510     39046224 :       basic_block dest = e->dest;
    5511              : 
    5512     48098331 :       if (dest == EXIT_BLOCK_PTR_FOR_FN (cfun)
    5513     37403483 :           || bitmap_bit_p (visited, dest->index))
    5514      9052107 :         continue;
    5515              : 
    5516     29994117 :       bitmap_set_bit (visited, dest->index);
    5517              : 
    5518     29994117 :       if (dest->index >= first)
    5519     38920270 :         for (gimple_stmt_iterator gsi = gsi_start_bb (dest);
    5520    136694224 :              !gsi_end_p (gsi); gsi_next (&gsi))
    5521              :           {
    5522    117234089 :             if (!statements->contains (gsi_stmt (gsi)))
    5523     23970855 :               continue;
    5524              : 
    5525     93263234 :             gimple *old_stmt = gsi_stmt (gsi);
    5526     93263234 :             bool can_make_abnormal_goto = false;
    5527     93263234 :             tree old_decl = NULL_TREE;
    5528              : 
    5529     93263234 :             if (is_gimple_call (old_stmt))
    5530              :               {
    5531      4150980 :                 old_decl = gimple_call_fndecl (old_stmt);
    5532      4150980 :                 if (stmt_can_make_abnormal_goto (old_stmt))
    5533              :                   can_make_abnormal_goto = true;
    5534              :               }
    5535              : 
    5536      4150980 :             if (old_decl && fndecl_built_in_p (old_decl))
    5537              :               {
    5538              :                 /* Folding builtins can create multiple instructions,
    5539              :                    we need to look at all of them.  */
    5540      1571178 :                 gimple_stmt_iterator i2 = gsi;
    5541      1571178 :                 gsi_prev (&i2);
    5542      1571178 :                 if (fold_stmt (&gsi))
    5543              :                   {
    5544        93166 :                     gimple *new_stmt;
    5545              :                     /* If a builtin at the end of a bb folded into nothing,
    5546              :                        the following loop won't work.  */
    5547        93166 :                     if (gsi_end_p (gsi))
    5548              :                       {
    5549            0 :                         cgraph_update_edges_for_call_stmt (old_stmt,
    5550              :                                                            old_decl, NULL);
    5551            0 :                         if (can_make_abnormal_goto)
    5552            0 :                           bitmap_set_bit (to_purge_abnormal, dest->index);
    5553     19460135 :                         break;
    5554              :                       }
    5555        93166 :                     if (gsi_end_p (i2))
    5556       125370 :                       i2 = gsi_start_bb (dest);
    5557              :                     else
    5558        30481 :                       gsi_next (&i2);
    5559        94094 :                     while (1)
    5560              :                       {
    5561          464 :                         new_stmt = gsi_stmt (i2);
    5562        93630 :                         update_stmt (new_stmt);
    5563        93630 :                         cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
    5564              :                                                            new_stmt);
    5565              : 
    5566        93630 :                         if (new_stmt == gsi_stmt (gsi))
    5567              :                           {
    5568              :                             /* It is okay to check only for the very last
    5569              :                                of these statements.  If it is a throwing
    5570              :                                statement nothing will change.  If it isn't
    5571              :                                this can remove EH edges.  If that weren't
    5572              :                                correct then because some intermediate stmts
    5573              :                                throw, but not the last one.  That would mean
    5574              :                                we'd have to split the block, which we can't
    5575              :                                here and we'd loose anyway.  And as builtins
    5576              :                                probably never throw, this all
    5577              :                                is mood anyway.  */
    5578        93166 :                             if (maybe_clean_or_replace_eh_stmt (old_stmt,
    5579              :                                                                 new_stmt))
    5580            7 :                               bitmap_set_bit (to_purge, dest->index);
    5581        93166 :                             if (can_make_abnormal_goto
    5582        93166 :                                 && !stmt_can_make_abnormal_goto (new_stmt))
    5583            0 :                               bitmap_set_bit (to_purge_abnormal, dest->index);
    5584              :                             break;
    5585              :                           }
    5586          464 :                         gsi_next (&i2);
    5587              :                       }
    5588              :                   }
    5589              :               }
    5590     91692056 :             else if (fold_stmt (&gsi))
    5591              :               {
    5592              :                 /* Re-read the statement from GSI as fold_stmt() may
    5593              :                    have changed it.  */
    5594      3009025 :                 gimple *new_stmt = gsi_stmt (gsi);
    5595      3009025 :                 update_stmt (new_stmt);
    5596              : 
    5597      3009025 :                 if (is_gimple_call (old_stmt)
    5598      3009025 :                     || is_gimple_call (new_stmt))
    5599         4867 :                   cgraph_update_edges_for_call_stmt (old_stmt, old_decl,
    5600              :                                                      new_stmt);
    5601              : 
    5602      3009025 :                 if (maybe_clean_or_replace_eh_stmt (old_stmt, new_stmt))
    5603          154 :                   bitmap_set_bit (to_purge, dest->index);
    5604      3009025 :                 if (can_make_abnormal_goto
    5605      3009025 :                     && !stmt_can_make_abnormal_goto (new_stmt))
    5606            7 :                   bitmap_set_bit (to_purge_abnormal, dest->index);
    5607              :               }
    5608              :           }
    5609              : 
    5610     58322021 :       if (EDGE_COUNT (dest->succs) > 0)
    5611              :         {
    5612              :           /* Avoid warnings emitted from folding statements that
    5613              :              became unreachable because of inlined function parameter
    5614              :              propagation.  */
    5615     28327904 :           e = find_taken_edge (dest, NULL_TREE);
    5616     28327904 :           if (e)
    5617     19470488 :             stack.quick_push (e);
    5618              :           else
    5619              :             {
    5620      8857416 :               edge_iterator ei;
    5621     26765006 :               FOR_EACH_EDGE (e, ei, dest->succs)
    5622     17907590 :                 stack.safe_push (e);
    5623              :             }
    5624              :         }
    5625              :     }
    5626              : 
    5627      1668146 :   gimple_purge_all_dead_eh_edges (to_purge);
    5628      1668146 :   gimple_purge_all_dead_abnormal_call_edges (to_purge_abnormal);
    5629      1668146 : }
    5630              : 
    5631              : /* Expand calls to inline functions in the body of FN.  */
    5632              : 
    5633              : unsigned int
    5634      2044009 : optimize_inline_calls (tree fn)
    5635              : {
    5636      2044009 :   copy_body_data id;
    5637      2044009 :   basic_block bb;
    5638      2044009 :   int last = n_basic_blocks_for_fn (cfun);
    5639      2044009 :   bool inlined_p = false;
    5640              : 
    5641              :   /* Clear out ID.  */
    5642      2044009 :   memset (&id, 0, sizeof (id));
    5643              : 
    5644      2044009 :   id.src_node = id.dst_node = cgraph_node::get (fn);
    5645      2044009 :   gcc_assert (id.dst_node->definition);
    5646      2044009 :   id.dst_fn = fn;
    5647              :   /* Or any functions that aren't finished yet.  */
    5648      2044009 :   if (current_function_decl)
    5649      2044009 :     id.dst_fn = current_function_decl;
    5650              : 
    5651      2044009 :   id.copy_decl = copy_decl_maybe_to_var;
    5652      2044009 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    5653      2044009 :   id.transform_new_cfg = false;
    5654      2044009 :   id.transform_return_to_modify = true;
    5655      2044009 :   id.transform_parameter = true;
    5656      2044009 :   id.statements_to_fold = new hash_set<gimple *>;
    5657              : 
    5658      2044009 :   push_gimplify_context ();
    5659              : 
    5660              :   /* We make no attempts to keep dominance info up-to-date.  */
    5661      2044009 :   free_dominance_info (CDI_DOMINATORS);
    5662      2044009 :   free_dominance_info (CDI_POST_DOMINATORS);
    5663              : 
    5664              :   /* Register specific gimple functions.  */
    5665      2044009 :   gimple_register_cfg_hooks ();
    5666              : 
    5667              :   /* Reach the trees by walking over the CFG, and note the
    5668              :      enclosing basic-blocks in the call edges.  */
    5669              :   /* We walk the blocks going forward, because inlined function bodies
    5670              :      will split id->current_basic_block, and the new blocks will
    5671              :      follow it; we'll trudge through them, processing their CALL_EXPRs
    5672              :      along the way.  */
    5673      2044009 :   auto_bitmap to_purge;
    5674     34985660 :   FOR_EACH_BB_FN (bb, cfun)
    5675     32941651 :     inlined_p |= gimple_expand_calls_inline (bb, &id, to_purge);
    5676              : 
    5677      2044009 :   pop_gimplify_context (NULL);
    5678              : 
    5679      2044009 :   if (flag_checking)
    5680              :     {
    5681      2043991 :       struct cgraph_edge *e;
    5682              : 
    5683      2043991 :       id.dst_node->verify ();
    5684              : 
    5685              :       /* Double check that we inlined everything we are supposed to inline.  */
    5686     12420804 :       for (e = id.dst_node->callees; e; e = e->next_callee)
    5687     10376813 :         gcc_assert (e->inline_failed);
    5688              :     }
    5689              : 
    5690              :   /* If we didn't inline into the function there is nothing to do.  */
    5691      2044009 :   if (!inlined_p)
    5692              :     {
    5693      1257830 :       delete id.statements_to_fold;
    5694              :       return 0;
    5695              :     }
    5696              : 
    5697              :   /* Fold queued statements.  */
    5698      1415094 :   update_max_bb_count ();
    5699      1415094 :   fold_marked_statements (last, id.statements_to_fold);
    5700      2830188 :   delete id.statements_to_fold;
    5701              : 
    5702              :   /* Finally purge EH and abnormal edges from the call stmts we inlined.
    5703              :      We need to do this after fold_marked_statements since that may walk
    5704              :      the SSA use-def chain.  */
    5705      1415094 :   unsigned i;
    5706      1415094 :   bitmap_iterator bi;
    5707      2544708 :   EXECUTE_IF_SET_IN_BITMAP (to_purge, 0, i, bi)
    5708              :     {
    5709      1129614 :       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
    5710      1129614 :       if (bb)
    5711              :         {
    5712      1129614 :           gimple_purge_dead_eh_edges (bb);
    5713      1129614 :           gimple_purge_dead_abnormal_call_edges (bb);
    5714              :         }
    5715              :     }
    5716              : 
    5717      1415094 :   gcc_assert (!id.debug_stmts.exists ());
    5718              : 
    5719              :   /* Renumber the lexical scoping (non-code) blocks consecutively.  */
    5720      1415094 :   number_blocks (fn);
    5721              : 
    5722      1415094 :   delete_unreachable_blocks_update_callgraph (id.dst_node, false);
    5723      1415094 :   id.dst_node->calls_comdat_local = id.dst_node->check_calls_comdat_local_p ();
    5724              : 
    5725      1415094 :   if (flag_checking)
    5726      1415085 :     id.dst_node->verify ();
    5727              : 
    5728              :   /* It would be nice to check SSA/CFG/statement consistency here, but it is
    5729              :      not possible yet - the IPA passes might make various functions to not
    5730              :      throw and they don't care to proactively update local EH info.  This is
    5731              :      done later in fixup_cfg pass that also execute the verification.  */
    5732      1415094 :   return (TODO_update_ssa
    5733              :           | TODO_cleanup_cfg
    5734      1415094 :           | (gimple_in_ssa_p (cfun) ? TODO_remove_unused_locals : 0)
    5735      2830188 :           | (gimple_in_ssa_p (cfun) ? TODO_update_address_taken : 0));
    5736      2044009 : }
    5737              : 
    5738              : /* Passed to walk_tree.  Copies the node pointed to, if appropriate.  */
    5739              : 
    5740              : tree
    5741   1987802066 : copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
    5742              : {
    5743   1987802066 :   enum tree_code code = TREE_CODE (*tp);
    5744   1987802066 :   enum tree_code_class cl = TREE_CODE_CLASS (code);
    5745              : 
    5746              :   /* We make copies of most nodes.  */
    5747   1987802066 :   if (IS_EXPR_CODE_CLASS (cl)
    5748              :       || code == TREE_LIST
    5749    304462281 :       || code == TREE_VEC
    5750    299474821 :       || code == TYPE_DECL
    5751    299474821 :       || code == OMP_CLAUSE)
    5752              :     {
    5753              :       /* Because the chain gets clobbered when we make a copy, we save it
    5754              :          here.  */
    5755   1688351730 :       tree chain = NULL_TREE, new_tree;
    5756              : 
    5757   1688351730 :       if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
    5758      5011945 :         chain = TREE_CHAIN (*tp);
    5759              : 
    5760              :       /* Copy the node.  */
    5761   1688351730 :       new_tree = copy_node (*tp);
    5762              : 
    5763   1688351730 :       *tp = new_tree;
    5764              : 
    5765              :       /* Now, restore the chain, if appropriate.  That will cause
    5766              :          walk_tree to walk into the chain as well.  */
    5767   1688351730 :       if (code == PARM_DECL
    5768   1688351730 :           || code == TREE_LIST
    5769   1686125485 :           || code == OMP_CLAUSE)
    5770      2250702 :         TREE_CHAIN (*tp) = chain;
    5771              : 
    5772              :       /* For now, we don't update BLOCKs when we make copies.  So, we
    5773              :          have to nullify all BIND_EXPRs.  */
    5774   1688351730 :       if (TREE_CODE (*tp) == BIND_EXPR)
    5775     20563282 :         BIND_EXPR_BLOCK (*tp) = NULL_TREE;
    5776              :     }
    5777    299450336 :   else if (code == CONSTRUCTOR)
    5778              :     {
    5779              :       /* CONSTRUCTOR nodes need special handling because
    5780              :          we need to duplicate the vector of elements.  */
    5781     18297644 :       tree new_tree;
    5782              : 
    5783     18297644 :       new_tree = copy_node (*tp);
    5784     26664056 :       CONSTRUCTOR_ELTS (new_tree) = vec_safe_copy (CONSTRUCTOR_ELTS (*tp));
    5785     18297644 :       *tp = new_tree;
    5786              :     }
    5787    281152692 :   else if (code == STATEMENT_LIST)
    5788              :     /* We used to just abort on STATEMENT_LIST, but we can run into them
    5789              :        with statement-expressions (c++/40975).  */
    5790          201 :     copy_statement_list (tp);
    5791    281152491 :   else if (TREE_CODE_CLASS (code) == tcc_type)
    5792          278 :     *walk_subtrees = 0;
    5793    281152213 :   else if (TREE_CODE_CLASS (code) == tcc_declaration)
    5794    121294401 :     *walk_subtrees = 0;
    5795    159857812 :   else if (TREE_CODE_CLASS (code) == tcc_constant)
    5796            0 :     *walk_subtrees = 0;
    5797   1987802066 :   return NULL_TREE;
    5798              : }
    5799              : 
    5800              : /* The SAVE_EXPR pointed to by TP is being copied.  If ST contains
    5801              :    information indicating to what new SAVE_EXPR this one should be mapped,
    5802              :    use that one.  Otherwise, create a new node and enter it in ST.  FN is
    5803              :    the function into which the copy will be placed.  */
    5804              : 
    5805              : static void
    5806     15696273 : remap_save_expr (tree *tp, hash_map<tree, tree> *st, int *walk_subtrees)
    5807              : {
    5808     15696273 :   tree *n;
    5809     15696273 :   tree t;
    5810              : 
    5811              :   /* See if we already encountered this SAVE_EXPR.  */
    5812     15696273 :   n = st->get (*tp);
    5813              : 
    5814              :   /* If we didn't already remap this SAVE_EXPR, do so now.  */
    5815     15696273 :   if (!n)
    5816              :     {
    5817     15238624 :       t = copy_node (*tp);
    5818              : 
    5819              :       /* Remember this SAVE_EXPR.  */
    5820     15238624 :       st->put (*tp, t);
    5821              :       /* Make sure we don't remap an already-remapped SAVE_EXPR.  */
    5822     15238624 :       st->put (t, t);
    5823              :     }
    5824              :   else
    5825              :     {
    5826              :       /* We've already walked into this SAVE_EXPR; don't do it again.  */
    5827       457649 :       *walk_subtrees = 0;
    5828       457649 :       t = *n;
    5829              :     }
    5830              : 
    5831              :   /* Replace this SAVE_EXPR with the copy.  */
    5832     15696273 :   *tp = t;
    5833     15696273 : }
    5834              : 
    5835              : /* Called via walk_gimple_seq.  If *GSIP points to a GIMPLE_LABEL for a local
    5836              :    label, copies the declaration and enters it in the splay_tree in DATA (which
    5837              :    is really a 'copy_body_data *'.  */
    5838              : 
    5839              : static tree
    5840      1636245 : mark_local_labels_stmt (gimple_stmt_iterator *gsip,
    5841              :                         bool *handled_ops_p ATTRIBUTE_UNUSED,
    5842              :                         struct walk_stmt_info *wi)
    5843              : {
    5844      1636245 :   copy_body_data *id = (copy_body_data *) wi->info;
    5845      1636245 :   glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsip));
    5846              : 
    5847        53836 :   if (stmt)
    5848              :     {
    5849        53836 :       tree decl = gimple_label_label (stmt);
    5850              : 
    5851              :       /* Copy the decl and remember the copy.  */
    5852        53836 :       insert_decl_map (id, decl, id->copy_decl (decl, id));
    5853              :     }
    5854              : 
    5855      1636245 :   return NULL_TREE;
    5856              : }
    5857              : 
    5858              : static gimple_seq duplicate_remap_omp_clause_seq (gimple_seq seq,
    5859              :                                                   struct walk_stmt_info *wi);
    5860              : 
    5861              : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
    5862              :    Using the splay_tree pointed to by ST (which is really a `splay_tree'),
    5863              :    remaps all local declarations to appropriate replacements in gimple
    5864              :    operands. */
    5865              : 
    5866              : static tree
    5867      3574907 : replace_locals_op (tree *tp, int *walk_subtrees, void *data)
    5868              : {
    5869      3574907 :   struct walk_stmt_info *wi = (struct walk_stmt_info*) data;
    5870      3574907 :   copy_body_data *id = (copy_body_data *) wi->info;
    5871      3574907 :   hash_map<tree, tree> *st = id->decl_map;
    5872      3574907 :   tree *n;
    5873      3574907 :   tree expr = *tp;
    5874              : 
    5875              :   /* For recursive invocations this is no longer the LHS itself.  */
    5876      3574907 :   bool is_lhs = wi->is_lhs;
    5877      3574907 :   wi->is_lhs = false;
    5878              : 
    5879      3574907 :   if (TREE_CODE (expr) == SSA_NAME)
    5880              :     {
    5881        24546 :       *tp = remap_ssa_name (*tp, id);
    5882        24546 :       *walk_subtrees = 0;
    5883        24546 :       if (is_lhs)
    5884        12273 :         SSA_NAME_DEF_STMT (*tp) = gsi_stmt (wi->gsi);
    5885              :     }
    5886              :   /* Only a local declaration (variable or label).  */
    5887      3550361 :   else if ((VAR_P (expr) && !TREE_STATIC (expr))
    5888      2069038 :            || TREE_CODE (expr) == LABEL_DECL)
    5889              :     {
    5890              :       /* Lookup the declaration.  */
    5891      1591051 :       n = st->get (expr);
    5892              : 
    5893              :       /* If it's there, remap it.  */
    5894      1591051 :       if (n)
    5895       108386 :         *tp = *n;
    5896      1591051 :       *walk_subtrees = 0;
    5897              :     }
    5898      1959310 :   else if (TREE_CODE (expr) == STATEMENT_LIST
    5899      1959310 :            || TREE_CODE (expr) == BIND_EXPR
    5900      1959310 :            || TREE_CODE (expr) == SAVE_EXPR)
    5901            0 :     gcc_unreachable ();
    5902      1959310 :   else if (TREE_CODE (expr) == TARGET_EXPR)
    5903              :     {
    5904              :       /* Don't mess with a TARGET_EXPR that hasn't been expanded.
    5905              :          It's OK for this to happen if it was part of a subtree that
    5906              :          isn't immediately expanded, such as operand 2 of another
    5907              :          TARGET_EXPR.  */
    5908            0 :       if (!TREE_OPERAND (expr, 1))
    5909              :         {
    5910            0 :           TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
    5911            0 :           TREE_OPERAND (expr, 3) = NULL_TREE;
    5912              :         }
    5913              :     }
    5914      1959310 :   else if (TREE_CODE (expr) == OMP_CLAUSE)
    5915              :     {
    5916              :       /* Before the omplower pass completes, some OMP clauses can contain
    5917              :          sequences that are neither copied by gimple_seq_copy nor walked by
    5918              :          walk_gimple_seq.  To make copy_gimple_seq_and_replace_locals work even
    5919              :          in those situations, we have to copy and process them explicitly.  */
    5920              : 
    5921          604 :       if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LASTPRIVATE)
    5922              :         {
    5923           14 :           gimple_seq seq = OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr);
    5924           14 :           seq = duplicate_remap_omp_clause_seq (seq, wi);
    5925           14 :           OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (expr) = seq;
    5926              :         }
    5927          590 :       else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_LINEAR)
    5928              :         {
    5929           85 :           gimple_seq seq = OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr);
    5930           85 :           seq = duplicate_remap_omp_clause_seq (seq, wi);
    5931           85 :           OMP_CLAUSE_LINEAR_GIMPLE_SEQ (expr) = seq;
    5932              :         }
    5933          505 :       else if (OMP_CLAUSE_CODE (expr) == OMP_CLAUSE_REDUCTION)
    5934              :         {
    5935          109 :           gimple_seq seq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr);
    5936          109 :           seq = duplicate_remap_omp_clause_seq (seq, wi);
    5937          109 :           OMP_CLAUSE_REDUCTION_GIMPLE_INIT (expr) = seq;
    5938          109 :           seq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr);
    5939          109 :           seq = duplicate_remap_omp_clause_seq (seq, wi);
    5940          109 :           OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (expr) = seq;
    5941              :         }
    5942              :     }
    5943              : 
    5944              :   /* Keep iterating.  */
    5945      3574907 :   return NULL_TREE;
    5946              : }
    5947              : 
    5948              : 
    5949              : /* Called via walk_gimple_seq by copy_gimple_seq_and_replace_local.
    5950              :    Using the splay_tree pointed to by ST (which is really a `splay_tree'),
    5951              :    remaps all local declarations to appropriate replacements in gimple
    5952              :    statements. */
    5953              : 
    5954              : static tree
    5955      1636245 : replace_locals_stmt (gimple_stmt_iterator *gsip,
    5956              :                      bool *handled_ops_p ATTRIBUTE_UNUSED,
    5957              :                      struct walk_stmt_info *wi)
    5958              : {
    5959      1636245 :   copy_body_data *id = (copy_body_data *) wi->info;
    5960      1636245 :   gimple *gs = gsi_stmt (*gsip);
    5961              : 
    5962      1636245 :   if (gbind *stmt = dyn_cast <gbind *> (gs))
    5963              :     {
    5964          359 :       tree block = gimple_bind_block (stmt);
    5965              : 
    5966          359 :       if (block)
    5967              :         {
    5968          279 :           remap_block (&block, id);
    5969          279 :           gimple_bind_set_block (stmt, block);
    5970              :         }
    5971              : 
    5972              :       /* This will remap a lot of the same decls again, but this should be
    5973              :          harmless.  */
    5974          359 :       if (gimple_bind_vars (stmt))
    5975              :         {
    5976              :           tree old_var, decls = gimple_bind_vars (stmt);
    5977              : 
    5978          528 :           for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
    5979          360 :             if (!can_be_nonlocal (old_var, id)
    5980          360 :                 && ! variably_modified_type_p (TREE_TYPE (old_var), id->src_fn))
    5981          360 :               remap_decl (old_var, id);
    5982              : 
    5983          168 :           gcc_checking_assert (!id->prevent_decl_creation_for_types);
    5984          168 :           id->prevent_decl_creation_for_types = true;
    5985          168 :           gimple_bind_set_vars (stmt, remap_decls (decls, NULL, id));
    5986          168 :           id->prevent_decl_creation_for_types = false;
    5987              :         }
    5988              :     }
    5989              : 
    5990              :   /* Keep iterating.  */
    5991      1636245 :   return NULL_TREE;
    5992              : }
    5993              : 
    5994              : /* Create a copy of SEQ and remap all decls in it.  */
    5995              : 
    5996              : static gimple_seq
    5997          317 : duplicate_remap_omp_clause_seq (gimple_seq seq, struct walk_stmt_info *wi)
    5998              : {
    5999          317 :   if (!seq)
    6000              :     return NULL;
    6001              : 
    6002              :   /* If there are any labels in OMP sequences, they can be only referred to in
    6003              :      the sequence itself and therefore we can do both here.  */
    6004           60 :   walk_gimple_seq (seq, mark_local_labels_stmt, NULL, wi);
    6005           60 :   gimple_seq copy = gimple_seq_copy (seq);
    6006           60 :   walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, wi);
    6007           60 :   return copy;
    6008              : }
    6009              : 
    6010              : /* Copies everything in SEQ and replaces variables and labels local to
    6011              :    current_function_decl.  */
    6012              : 
    6013              : gimple_seq
    6014      1103426 : copy_gimple_seq_and_replace_locals (gimple_seq seq)
    6015              : {
    6016      1103426 :   copy_body_data id;
    6017      1103426 :   struct walk_stmt_info wi;
    6018      1103426 :   gimple_seq copy;
    6019              : 
    6020              :   /* There's nothing to do for NULL_TREE.  */
    6021      1103426 :   if (seq == NULL)
    6022              :     return seq;
    6023              : 
    6024              :   /* Set up ID.  */
    6025      1103410 :   memset (&id, 0, sizeof (id));
    6026      1103410 :   id.src_fn = current_function_decl;
    6027      1103410 :   id.dst_fn = current_function_decl;
    6028      1103410 :   id.src_cfun = cfun;
    6029      1103410 :   id.decl_map = new hash_map<tree, tree>;
    6030      1103410 :   id.debug_map = NULL;
    6031              : 
    6032      1103410 :   id.copy_decl = copy_decl_no_change;
    6033      1103410 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    6034      1103410 :   id.transform_new_cfg = false;
    6035      1103410 :   id.transform_return_to_modify = false;
    6036      1103410 :   id.transform_parameter = false;
    6037              : 
    6038              :   /* Walk the tree once to find local labels.  */
    6039      1103410 :   memset (&wi, 0, sizeof (wi));
    6040      1103410 :   hash_set<tree> visited;
    6041      1103410 :   wi.info = &id;
    6042      1103410 :   wi.pset = &visited;
    6043      1103410 :   walk_gimple_seq (seq, mark_local_labels_stmt, NULL, &wi);
    6044              : 
    6045      1103410 :   copy = gimple_seq_copy (seq);
    6046              : 
    6047              :   /* Walk the copy, remapping decls.  */
    6048      1103410 :   memset (&wi, 0, sizeof (wi));
    6049      1103410 :   wi.info = &id;
    6050      1103410 :   walk_gimple_seq (copy, replace_locals_stmt, replace_locals_op, &wi);
    6051              : 
    6052              :   /* Clean up.  */
    6053      2206820 :   delete id.decl_map;
    6054      1103410 :   if (id.debug_map)
    6055            0 :     delete id.debug_map;
    6056      1103410 :   if (id.dependence_map)
    6057              :     {
    6058            0 :       delete id.dependence_map;
    6059            0 :       id.dependence_map = NULL;
    6060              :     }
    6061              : 
    6062      1103410 :   return copy;
    6063      1103410 : }
    6064              : 
    6065              : 
    6066              : /* Declare the variables created by the inliner.  Add all the variables in
    6067              :    VARS to BIND_EXPR.  */
    6068              : 
    6069              : static void
    6070      6998253 : declare_inline_vars (tree block, tree vars)
    6071              : {
    6072      6998253 :   tree t;
    6073     17220862 :   for (t = vars; t; t = DECL_CHAIN (t))
    6074              :     {
    6075     10222609 :       DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
    6076     10222609 :       gcc_assert (!TREE_STATIC (t) && !TREE_ASM_WRITTEN (t));
    6077     10222609 :       add_local_decl (cfun, t);
    6078              :     }
    6079              : 
    6080      6998253 :   if (block)
    6081      6914872 :     BLOCK_VARS (block) = chainon (BLOCK_VARS (block), vars);
    6082      6998253 : }
    6083              : 
    6084              : /* Copy NODE (which must be a DECL).  The DECL originally was in the FROM_FN,
    6085              :    but now it will be in the TO_FN.  PARM_TO_VAR means enable PARM_DECL to
    6086              :    VAR_DECL translation.  */
    6087              : 
    6088              : tree
    6089    138473650 : copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy)
    6090              : {
    6091              :   /* Don't generate debug information for the copy if we wouldn't have
    6092              :      generated it for the copy either.  */
    6093    138473650 :   DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (decl);
    6094    138473650 :   DECL_IGNORED_P (copy) = DECL_IGNORED_P (decl);
    6095              : 
    6096              :   /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
    6097              :      declaration inspired this copy.  */
    6098    171628683 :   DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
    6099              : 
    6100              :   /* The new variable/label has no RTL, yet.  */
    6101    138473650 :   if (HAS_RTL_P (copy)
    6102    138473650 :       && !TREE_STATIC (copy) && !DECL_EXTERNAL (copy))
    6103    138468318 :     SET_DECL_RTL (copy, 0);
    6104              :   /* For vector typed decls make sure to update DECL_MODE according
    6105              :      to the new function context.  */
    6106    138473650 :   if (VECTOR_TYPE_P (TREE_TYPE (copy)))
    6107       337242 :     SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy)));
    6108              : 
    6109              :   /* These args would always appear unused, if not for this.  */
    6110    138473650 :   TREE_USED (copy) = 1;
    6111              : 
    6112              :   /* Set the context for the new declaration.  */
    6113    138473650 :   if (!DECL_CONTEXT (decl))
    6114              :     /* Globals stay global.  */
    6115              :     ;
    6116    138473499 :   else if (DECL_CONTEXT (decl) != id->src_fn)
    6117              :     /* Things that weren't in the scope of the function we're inlining
    6118              :        from aren't in the scope we're inlining to, either.  */
    6119              :     ;
    6120    138470795 :   else if (TREE_STATIC (decl))
    6121              :     /* Function-scoped static variables should stay in the original
    6122              :        function.  */
    6123              :     ;
    6124              :   else
    6125              :     {
    6126              :       /* Ordinary automatic local variables are now in the scope of the
    6127              :          new function.  */
    6128    138467437 :       DECL_CONTEXT (copy) = id->dst_fn;
    6129    138467437 :       if (VAR_P (copy) && id->dst_simt_vars && !is_gimple_reg (copy))
    6130              :         {
    6131            0 :           if (!lookup_attribute ("omp simt private", DECL_ATTRIBUTES (copy)))
    6132            0 :             DECL_ATTRIBUTES (copy)
    6133            0 :               = tree_cons (get_identifier ("omp simt private"), NULL,
    6134            0 :                            DECL_ATTRIBUTES (copy));
    6135            0 :           id->dst_simt_vars->safe_push (copy);
    6136              :         }
    6137              :     }
    6138              : 
    6139    138473650 :   return copy;
    6140              : }
    6141              : 
    6142              : /* Create a new VAR_DECL that is identical in all respect to DECL except that
    6143              :    DECL can be either a VAR_DECL, a PARM_DECL or RESULT_DECL.  The original
    6144              :    DECL must come from ID->src_fn and the copy will be part of ID->dst_fn.  */
    6145              : 
    6146              : tree
    6147      8127973 : copy_decl_to_var (tree decl, copy_body_data *id)
    6148              : {
    6149      8127973 :   tree copy, type;
    6150              : 
    6151      8127973 :   gcc_assert (TREE_CODE (decl) == PARM_DECL
    6152              :               || TREE_CODE (decl) == RESULT_DECL);
    6153              : 
    6154      8127973 :   type = TREE_TYPE (decl);
    6155              : 
    6156      8127973 :   copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
    6157      8127973 :                      VAR_DECL, DECL_NAME (decl), type);
    6158      8127973 :   if (DECL_PT_UID_SET_P (decl))
    6159          272 :     SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
    6160      8127973 :   TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
    6161      8127973 :   TREE_READONLY (copy) = TREE_READONLY (decl);
    6162      8127973 :   TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
    6163      8127973 :   DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (decl);
    6164      8127973 :   DECL_BY_REFERENCE (copy) = DECL_BY_REFERENCE (decl);
    6165              : 
    6166      8127973 :   return copy_decl_for_dup_finish (id, decl, copy);
    6167              : }
    6168              : 
    6169              : /* Like copy_decl_to_var, but create a return slot object instead of a
    6170              :    pointer variable for return by invisible reference.  */
    6171              : 
    6172              : static tree
    6173      2108882 : copy_result_decl_to_var (tree decl, copy_body_data *id)
    6174              : {
    6175      2108882 :   tree copy, type;
    6176              : 
    6177      2108882 :   gcc_assert (TREE_CODE (decl) == PARM_DECL
    6178              :               || TREE_CODE (decl) == RESULT_DECL);
    6179              : 
    6180      2108882 :   type = TREE_TYPE (decl);
    6181      2108882 :   if (DECL_BY_REFERENCE (decl))
    6182          141 :     type = TREE_TYPE (type);
    6183              : 
    6184      2108882 :   copy = build_decl (DECL_SOURCE_LOCATION (id->dst_fn),
    6185      2108882 :                      VAR_DECL, DECL_NAME (decl), type);
    6186      2108882 :   if (DECL_PT_UID_SET_P (decl))
    6187            0 :     SET_DECL_PT_UID (copy, DECL_PT_UID (decl));
    6188      2108882 :   TREE_READONLY (copy) = TREE_READONLY (decl);
    6189      2108882 :   TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
    6190      2108882 :   if (!DECL_BY_REFERENCE (decl))
    6191              :     {
    6192      2108741 :       TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
    6193      2108741 :       DECL_NOT_GIMPLE_REG_P (copy)
    6194      4217482 :         = (DECL_NOT_GIMPLE_REG_P (decl)
    6195              :            /* RESULT_DECLs are treated special by needs_to_live_in_memory,
    6196              :               mirror that to the created VAR_DECL.  */
    6197      2108741 :            || (TREE_CODE (decl) == RESULT_DECL
    6198      2108574 :                && aggregate_value_p (decl, id->src_fn)));
    6199              :     }
    6200              : 
    6201      2108882 :   return copy_decl_for_dup_finish (id, decl, copy);
    6202              : }
    6203              : 
    6204              : tree
    6205    128236447 : copy_decl_no_change (tree decl, copy_body_data *id)
    6206              : {
    6207    128236447 :   tree copy;
    6208              : 
    6209    128236447 :   copy = copy_node (decl);
    6210              : 
    6211              :   /* The COPY is not abstract; it will be generated in DST_FN.  */
    6212    128236447 :   DECL_ABSTRACT_P (copy) = false;
    6213    128236447 :   lang_hooks.dup_lang_specific_decl (copy);
    6214              : 
    6215              :   /* TREE_ADDRESSABLE isn't used to indicate that a label's address has
    6216              :      been taken; it's for internal bookkeeping in expand_goto_internal.  */
    6217    128236447 :   if (TREE_CODE (copy) == LABEL_DECL)
    6218              :     {
    6219      1702681 :       TREE_ADDRESSABLE (copy) = 0;
    6220      1702681 :       LABEL_DECL_UID (copy) = -1;
    6221              :     }
    6222              : 
    6223    128236447 :   return copy_decl_for_dup_finish (id, decl, copy);
    6224              : }
    6225              : 
    6226              : static tree
    6227     24479021 : copy_decl_maybe_to_var (tree decl, copy_body_data *id)
    6228              : {
    6229     24479021 :   if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
    6230        14246 :     return copy_decl_to_var (decl, id);
    6231              :   else
    6232     24464775 :     return copy_decl_no_change (decl, id);
    6233              : }
    6234              : 
    6235              : /* Return a copy of the function's argument tree without any modifications.  */
    6236              : 
    6237              : static tree
    6238        80598 : copy_arguments_nochange (tree orig_parm, copy_body_data * id)
    6239              : {
    6240        80598 :   tree arg, *parg;
    6241        80598 :   tree new_parm = NULL;
    6242              : 
    6243        80598 :   parg = &new_parm;
    6244       243700 :   for (arg = orig_parm; arg; arg = DECL_CHAIN (arg))
    6245              :     {
    6246       163102 :       tree new_tree = remap_decl (arg, id);
    6247       163102 :       if (TREE_CODE (new_tree) != PARM_DECL)
    6248         4193 :         new_tree = id->copy_decl (arg, id);
    6249       163102 :       lang_hooks.dup_lang_specific_decl (new_tree);
    6250       163102 :       *parg = new_tree;
    6251       163102 :       parg = &DECL_CHAIN (new_tree);
    6252              :     }
    6253        80598 :   return new_parm;
    6254              : }
    6255              : 
    6256              : /* Return a copy of the function's static chain.  */
    6257              : static tree
    6258         1033 : copy_static_chain (tree static_chain, copy_body_data * id)
    6259              : {
    6260         1033 :   tree *chain_copy, *pvar;
    6261              : 
    6262         1033 :   chain_copy = &static_chain;
    6263         2066 :   for (pvar = chain_copy; *pvar; pvar = &DECL_CHAIN (*pvar))
    6264              :     {
    6265         1033 :       tree new_tree = remap_decl (*pvar, id);
    6266         1033 :       lang_hooks.dup_lang_specific_decl (new_tree);
    6267         1033 :       DECL_CHAIN (new_tree) = DECL_CHAIN (*pvar);
    6268         1033 :       *pvar = new_tree;
    6269              :     }
    6270         1033 :   return static_chain;
    6271              : }
    6272              : 
    6273              : /* Return true if the function is allowed to be versioned.
    6274              :    This is a guard for the versioning functionality.  */
    6275              : 
    6276              : bool
    6277     12896389 : tree_versionable_function_p (tree fndecl)
    6278              : {
    6279     12896389 :   return (!lookup_attribute ("noclone", DECL_ATTRIBUTES (fndecl))
    6280     25508278 :           && copy_forbidden (DECL_STRUCT_FUNCTION (fndecl)) == NULL);
    6281              : }
    6282              : 
    6283              : /* Update clone info after duplication.  */
    6284              : 
    6285              : static void
    6286       253052 : update_clone_info (copy_body_data * id)
    6287              : {
    6288       253052 :   struct cgraph_node *this_node = id->dst_node;
    6289       253052 :   if (!this_node->clones)
    6290              :     return;
    6291       642777 :   for (cgraph_node *node = this_node->clones; node != this_node;)
    6292              :     {
    6293              :       /* First update replace maps to match the new body.  */
    6294       557753 :       clone_info *info = clone_info::get (node);
    6295       557753 :       if (info && info->tree_map)
    6296              :         {
    6297              :           unsigned int i;
    6298            0 :           for (i = 0; i < vec_safe_length (info->tree_map); i++)
    6299              :             {
    6300            0 :               struct ipa_replace_map *replace_info;
    6301            0 :               replace_info = (*info->tree_map)[i];
    6302            0 :               walk_tree (&replace_info->new_tree, copy_tree_body_r, id, NULL);
    6303              :             }
    6304              :         }
    6305              : 
    6306       557753 :       if (node->clones)
    6307              :         node = node->clones;
    6308       532328 :       else if (node->next_sibling_clone)
    6309              :         node = node->next_sibling_clone;
    6310              :       else
    6311              :         {
    6312       208467 :           while (node != id->dst_node && !node->next_sibling_clone)
    6313       110449 :             node = node->clone_of;
    6314        98018 :           if (node != id->dst_node)
    6315        12994 :             node = node->next_sibling_clone;
    6316              :         }
    6317              :     }
    6318              : }
    6319              : 
    6320              : /* Create a copy of a function's tree.
    6321              :    OLD_DECL and NEW_DECL are FUNCTION_DECL tree nodes
    6322              :    of the original function and the new copied function
    6323              :    respectively.  In case we want to replace a DECL
    6324              :    tree with another tree while duplicating the function's
    6325              :    body, TREE_MAP represents the mapping between these
    6326              :    trees. If UPDATE_CLONES is set, the call_stmt fields
    6327              :    of edges of clones of the function will be updated.
    6328              : 
    6329              :    If non-NULL PARAM_ADJUSTMENTS determines how function prototype (i.e. the
    6330              :    function parameters and return value) should be modified).
    6331              :    If non-NULL BLOCKS_TO_COPY determine what basic blocks to copy.
    6332              :    If non_NULL NEW_ENTRY determine new entry BB of the clone.
    6333              : */
    6334              : void
    6335       253052 : tree_function_versioning (tree old_decl, tree new_decl,
    6336              :                           vec<ipa_replace_map *, va_gc> *tree_map,
    6337              :                           ipa_param_adjustments *param_adjustments,
    6338              :                           bool update_clones, bitmap blocks_to_copy,
    6339              :                           basic_block new_entry)
    6340              : {
    6341       253052 :   struct cgraph_node *old_version_node;
    6342       253052 :   struct cgraph_node *new_version_node;
    6343       253052 :   copy_body_data id;
    6344       253052 :   tree p;
    6345       253052 :   unsigned i;
    6346       253052 :   struct ipa_replace_map *replace_info;
    6347       253052 :   basic_block old_entry_block, bb;
    6348       253052 :   auto_vec<gimple *, 10> init_stmts;
    6349       253052 :   tree vars = NULL_TREE;
    6350              : 
    6351              :   /* We can get called recursively from expand_call_inline via clone
    6352              :      materialization.  While expand_call_inline maintains input_location
    6353              :      we cannot tolerate it to leak into the materialized clone.  */
    6354       253052 :   location_t saved_location = input_location;
    6355       253052 :   input_location = UNKNOWN_LOCATION;
    6356              : 
    6357       253052 :   gcc_assert (TREE_CODE (old_decl) == FUNCTION_DECL
    6358              :               && TREE_CODE (new_decl) == FUNCTION_DECL);
    6359       253052 :   DECL_POSSIBLY_INLINED (old_decl) = 1;
    6360              : 
    6361       253052 :   old_version_node = cgraph_node::get (old_decl);
    6362       253052 :   gcc_checking_assert (old_version_node);
    6363       253052 :   new_version_node = cgraph_node::get (new_decl);
    6364       253052 :   gcc_checking_assert (new_version_node);
    6365              : 
    6366              :   /* Copy over debug args.  */
    6367       253052 :   if (DECL_HAS_DEBUG_ARGS_P (old_decl))
    6368              :     {
    6369         4015 :       vec<tree, va_gc> **new_debug_args, **old_debug_args;
    6370         4015 :       gcc_checking_assert (decl_debug_args_lookup (new_decl) == NULL);
    6371         4015 :       DECL_HAS_DEBUG_ARGS_P (new_decl) = 0;
    6372         4015 :       old_debug_args = decl_debug_args_lookup (old_decl);
    6373         4015 :       if (old_debug_args)
    6374              :         {
    6375         4015 :           new_debug_args = decl_debug_args_insert (new_decl);
    6376         8030 :           *new_debug_args = vec_safe_copy (*old_debug_args);
    6377              :         }
    6378              :     }
    6379              : 
    6380              :   /* Output the inlining info for this abstract function, since it has been
    6381              :      inlined.  If we don't do this now, we can lose the information about the
    6382              :      variables in the function when the blocks get blown away as soon as we
    6383              :      remove the cgraph node.  */
    6384       253052 :   (*debug_hooks->outlining_inline_function) (old_decl);
    6385              : 
    6386       253052 :   DECL_ARTIFICIAL (new_decl) = 1;
    6387       457318 :   DECL_ABSTRACT_ORIGIN (new_decl) = DECL_ORIGIN (old_decl);
    6388       253052 :   copy_debug_abstract_origin (new_decl, old_decl);
    6389       457318 :   if (DECL_ORIGIN (old_decl) == old_decl)
    6390       224364 :     old_version_node->used_as_abstract_origin = true;
    6391       253052 :   DECL_FUNCTION_PERSONALITY (new_decl) = DECL_FUNCTION_PERSONALITY (old_decl);
    6392              : 
    6393              :   /* Prepare the data structures for the tree copy.  */
    6394       253052 :   memset (&id, 0, sizeof (id));
    6395              : 
    6396              :   /* Generate a new name for the new version. */
    6397       253052 :   id.statements_to_fold = new hash_set<gimple *>;
    6398              : 
    6399       253052 :   id.decl_map = new hash_map<tree, tree>;
    6400       253052 :   id.debug_map = NULL;
    6401       253052 :   id.src_fn = old_decl;
    6402       253052 :   id.dst_fn = new_decl;
    6403       253052 :   id.src_node = old_version_node;
    6404       253052 :   id.dst_node = new_version_node;
    6405       253052 :   id.src_cfun = DECL_STRUCT_FUNCTION (old_decl);
    6406       253052 :   id.blocks_to_copy = blocks_to_copy;
    6407              : 
    6408       253052 :   id.copy_decl = copy_decl_no_change;
    6409       253052 :   id.transform_call_graph_edges
    6410       253052 :     = update_clones ? CB_CGE_MOVE_CLONES : CB_CGE_MOVE;
    6411       253052 :   id.transform_new_cfg = true;
    6412       253052 :   id.transform_return_to_modify = false;
    6413       253052 :   id.transform_parameter = false;
    6414              : 
    6415       253052 :   old_entry_block = ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (old_decl));
    6416       253052 :   DECL_RESULT (new_decl) = DECL_RESULT (old_decl);
    6417       253052 :   DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl);
    6418       253052 :   initialize_cfun (new_decl, old_decl,
    6419       253052 :                    new_entry ? new_entry->count : old_entry_block->count);
    6420       253052 :   new_version_node->has_omp_variant_constructs
    6421       253052 :     = old_version_node->has_omp_variant_constructs;
    6422       253052 :   if (DECL_STRUCT_FUNCTION (new_decl)->gimple_df)
    6423       253052 :     DECL_STRUCT_FUNCTION (new_decl)->gimple_df->ipa_pta
    6424       253052 :       = id.src_cfun->gimple_df->ipa_pta;
    6425              : 
    6426              :   /* Copy the function's static chain.  */
    6427       253052 :   p = DECL_STRUCT_FUNCTION (old_decl)->static_chain_decl;
    6428       253052 :   if (p)
    6429         2066 :     DECL_STRUCT_FUNCTION (new_decl)->static_chain_decl
    6430         1033 :       = copy_static_chain (p, &id);
    6431              : 
    6432       253052 :   auto_vec<int, 16> new_param_indices;
    6433       253052 :   clone_info *info = clone_info::get (old_version_node);
    6434       260077 :   ipa_param_adjustments *old_param_adjustments
    6435       253052 :     = info ? info->param_adjustments : NULL;
    6436         7025 :   if (old_param_adjustments)
    6437         6936 :     old_param_adjustments->get_updated_indices (&new_param_indices);
    6438              : 
    6439              :   /* If there's a tree_map, prepare for substitution.  */
    6440       253052 :   if (tree_map)
    6441        41275 :     for (i = 0; i < tree_map->length (); i++)
    6442              :       {
    6443        26171 :         gimple *init;
    6444        26171 :         replace_info = (*tree_map)[i];
    6445              : 
    6446        26171 :         int p = replace_info->parm_num;
    6447        26171 :         if (old_param_adjustments)
    6448            0 :           p = new_param_indices[p];
    6449              : 
    6450        26171 :         tree parm;
    6451        75689 :         for (parm = DECL_ARGUMENTS (old_decl); p;
    6452        49518 :              parm = DECL_CHAIN (parm))
    6453        49518 :           p--;
    6454        26171 :         gcc_assert (parm);
    6455        26171 :         init = setup_one_parameter (&id, parm, replace_info->new_tree,
    6456              :                                     id.src_fn, NULL, &vars);
    6457        26171 :         if (init)
    6458         7879 :           init_stmts.safe_push (init);
    6459              :       }
    6460              : 
    6461       253052 :   ipa_param_body_adjustments *param_body_adjs = NULL;
    6462       253052 :   if (param_adjustments)
    6463              :     {
    6464       332752 :       param_body_adjs = new ipa_param_body_adjustments (param_adjustments,
    6465              :                                                         new_decl, old_decl,
    6466       166376 :                                                         &id, &vars, tree_map);
    6467       166376 :       id.param_body_adjs = param_body_adjs;
    6468       166376 :       DECL_ARGUMENTS (new_decl) = param_body_adjs->get_new_param_chain ();
    6469              :     }
    6470        86676 :   else if (DECL_ARGUMENTS (old_decl) != NULL_TREE)
    6471       161196 :     DECL_ARGUMENTS (new_decl)
    6472        80598 :       = copy_arguments_nochange (DECL_ARGUMENTS (old_decl), &id);
    6473              : 
    6474       253052 :   DECL_INITIAL (new_decl) = remap_blocks (DECL_INITIAL (id.src_fn), &id);
    6475       253052 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (new_decl)) = new_decl;
    6476              : 
    6477       253052 :   declare_inline_vars (DECL_INITIAL (new_decl), vars);
    6478              : 
    6479       253052 :   if (!vec_safe_is_empty (DECL_STRUCT_FUNCTION (old_decl)->local_decls))
    6480              :     /* Add local vars.  */
    6481       152067 :     add_local_variables (DECL_STRUCT_FUNCTION (old_decl), cfun, &id);
    6482              : 
    6483       253052 :   if (DECL_RESULT (old_decl) == NULL_TREE)
    6484              :     ;
    6485       166376 :   else if (param_adjustments && param_adjustments->m_skip_return
    6486       305600 :            && !VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
    6487              :     {
    6488        45192 :       tree resdecl_repl = copy_result_decl_to_var (DECL_RESULT (old_decl),
    6489              :                                                    &id);
    6490        45192 :       declare_inline_vars (NULL, resdecl_repl);
    6491        45192 :       if (DECL_BY_REFERENCE (DECL_RESULT (old_decl)))
    6492          141 :         resdecl_repl = build_fold_addr_expr (resdecl_repl);
    6493        45192 :       insert_decl_map (&id, DECL_RESULT (old_decl), resdecl_repl);
    6494              : 
    6495        90384 :       DECL_RESULT (new_decl)
    6496        45192 :         = build_decl (DECL_SOURCE_LOCATION (DECL_RESULT (old_decl)),
    6497              :                       RESULT_DECL, NULL_TREE, void_type_node);
    6498        45192 :       DECL_CONTEXT (DECL_RESULT (new_decl)) = new_decl;
    6499        45192 :       DECL_IS_MALLOC (new_decl) = false;
    6500        45192 :       cfun->returns_struct = 0;
    6501        45192 :       cfun->returns_pcc_struct = 0;
    6502              :     }
    6503              :   else
    6504              :     {
    6505       207860 :       tree old_name;
    6506       207860 :       DECL_RESULT (new_decl) = remap_decl (DECL_RESULT (old_decl), &id);
    6507       207860 :       lang_hooks.dup_lang_specific_decl (DECL_RESULT (new_decl));
    6508       415720 :       if (gimple_in_ssa_p (id.src_cfun)
    6509       207860 :           && DECL_BY_REFERENCE (DECL_RESULT (old_decl))
    6510         4878 :           && (old_name = ssa_default_def (id.src_cfun, DECL_RESULT (old_decl))))
    6511              :         {
    6512         4859 :           tree new_name = make_ssa_name (DECL_RESULT (new_decl));
    6513         4859 :           insert_decl_map (&id, old_name, new_name);
    6514         4859 :           SSA_NAME_DEF_STMT (new_name) = gimple_build_nop ();
    6515         4859 :           set_ssa_default_def (cfun, DECL_RESULT (new_decl), new_name);
    6516              :         }
    6517              :     }
    6518              : 
    6519              :   /* Set up the destination functions loop tree.  */
    6520       253052 :   if (loops_for_fn (DECL_STRUCT_FUNCTION (old_decl)) != NULL)
    6521              :     {
    6522       253052 :       cfun->curr_properties &= ~PROP_loops;
    6523       253052 :       loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
    6524       253052 :       cfun->curr_properties |= PROP_loops;
    6525              :     }
    6526              : 
    6527              :   /* Copy the Function's body.  */
    6528       253052 :   copy_body (&id, ENTRY_BLOCK_PTR_FOR_FN (cfun), EXIT_BLOCK_PTR_FOR_FN (cfun),
    6529              :              new_entry);
    6530              : 
    6531              :   /* Renumber the lexical scoping (non-code) blocks consecutively.  */
    6532       253052 :   number_blocks (new_decl);
    6533              : 
    6534              :   /* We want to create the BB unconditionally, so that the addition of
    6535              :      debug stmts doesn't affect BB count, which may in the end cause
    6536              :      codegen differences.  */
    6537       253052 :   bb = split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
    6538       513983 :   while (init_stmts.length ())
    6539         7879 :     insert_init_stmt (&id, bb, init_stmts.pop ());
    6540       253052 :   if (param_body_adjs)
    6541       166376 :     param_body_adjs->append_init_stmts (bb);
    6542       253052 :   update_clone_info (&id);
    6543              : 
    6544              :   /* Remap the nonlocal_goto_save_area, if any.  */
    6545       253052 :   if (cfun->nonlocal_goto_save_area)
    6546              :     {
    6547            0 :       struct walk_stmt_info wi;
    6548              : 
    6549            0 :       memset (&wi, 0, sizeof (wi));
    6550            0 :       wi.info = &id;
    6551            0 :       walk_tree (&cfun->nonlocal_goto_save_area, remap_gimple_op_r, &wi, NULL);
    6552              :     }
    6553              : 
    6554              :   /* Clean up.  */
    6555       506104 :   delete id.decl_map;
    6556       253052 :   if (id.debug_map)
    6557         1326 :     delete id.debug_map;
    6558       253052 :   free_dominance_info (CDI_DOMINATORS);
    6559       253052 :   free_dominance_info (CDI_POST_DOMINATORS);
    6560              : 
    6561       253052 :   update_max_bb_count ();
    6562       253052 :   fold_marked_statements (0, id.statements_to_fold);
    6563       506104 :   delete id.statements_to_fold;
    6564       253052 :   delete_unreachable_blocks_update_callgraph (id.dst_node, update_clones);
    6565       253052 :   if (id.dst_node->definition)
    6566       248442 :     cgraph_edge::rebuild_references ();
    6567       253052 :   if (loops_state_satisfies_p (LOOPS_NEED_FIXUP))
    6568              :     {
    6569       253052 :       calculate_dominance_info (CDI_DOMINATORS);
    6570       253052 :       fix_loop_structure (NULL);
    6571              :     }
    6572       253052 :   update_ssa (TODO_update_ssa);
    6573              : 
    6574              :   /* After partial cloning we need to rescale frequencies, so they are
    6575              :      within proper range in the cloned function.  */
    6576       253052 :   if (new_entry)
    6577              :     {
    6578        52311 :       struct cgraph_edge *e;
    6579        52311 :       rebuild_frequencies ();
    6580              : 
    6581        52311 :       new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    6582       236638 :       for (e = new_version_node->callees; e; e = e->next_callee)
    6583              :         {
    6584       184327 :           basic_block bb = gimple_bb (e->call_stmt);
    6585       184327 :           e->count = bb->count;
    6586              :         }
    6587        57307 :       for (e = new_version_node->indirect_calls; e; e = e->next_callee)
    6588              :         {
    6589         4996 :           basic_block bb = gimple_bb (e->call_stmt);
    6590         4996 :           e->count = bb->count;
    6591              :         }
    6592              :     }
    6593              : 
    6594       253052 :   if (param_body_adjs && MAY_HAVE_DEBUG_BIND_STMTS)
    6595              :     {
    6596       142062 :       vec<tree, va_gc> **debug_args = NULL;
    6597       142062 :       unsigned int len = 0;
    6598       142062 :       unsigned reset_len = param_body_adjs->m_reset_debug_decls.length ();
    6599              : 
    6600       253291 :       for (i = 0; i < reset_len; i++)
    6601              :         {
    6602       111229 :           tree parm = param_body_adjs->m_reset_debug_decls[i];
    6603       111229 :           gcc_assert (is_gimple_reg (parm));
    6604       111229 :           tree ddecl;
    6605              : 
    6606       111229 :           if (debug_args == NULL)
    6607              :             {
    6608        84642 :               debug_args = decl_debug_args_insert (new_decl);
    6609        84642 :               len = vec_safe_length (*debug_args);
    6610              :             }
    6611       111229 :           ddecl = build_debug_expr_decl (TREE_TYPE (parm));
    6612              :           /* FIXME: Is setting the mode really necessary? */
    6613       111229 :           SET_DECL_MODE (ddecl, DECL_MODE (parm));
    6614       111229 :           vec_safe_push (*debug_args, DECL_ORIGIN (parm));
    6615       111229 :           vec_safe_push (*debug_args, ddecl);
    6616              :         }
    6617       142062 :       if (debug_args != NULL)
    6618              :         {
    6619              :           /* On the callee side, add
    6620              :              DEBUG D#Y s=> parm
    6621              :              DEBUG var => D#Y
    6622              :              stmts to the first bb where var is a VAR_DECL created for the
    6623              :              optimized away parameter in DECL_INITIAL block.  This hints
    6624              :              in the debug info that var (whole DECL_ORIGIN is the parm
    6625              :              PARM_DECL) is optimized away, but could be looked up at the
    6626              :              call site as value of D#X there.  */
    6627        84642 :           gimple_stmt_iterator cgsi
    6628        84642 :             = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
    6629        84642 :           gimple *def_temp;
    6630        84642 :           tree var = vars;
    6631       169284 :           i = vec_safe_length (*debug_args);
    6632       111229 :           do
    6633              :             {
    6634       111229 :               tree vexpr = NULL_TREE;
    6635       111229 :               i -= 2;
    6636       111229 :               while (var != NULL_TREE
    6637       147120 :                      && DECL_ABSTRACT_ORIGIN (var) != (**debug_args)[i])
    6638        35891 :                 var = TREE_CHAIN (var);
    6639       111229 :               if (var == NULL_TREE)
    6640              :                 break;
    6641       111229 :               tree parm = (**debug_args)[i];
    6642       111229 :               if (tree parm_ddef = ssa_default_def (id.src_cfun, parm))
    6643       148172 :                 if (tree *d
    6644        74086 :                     = param_body_adjs->m_dead_ssa_debug_equiv.get (parm_ddef))
    6645        30451 :                   vexpr = *d;
    6646       111229 :               if (!vexpr)
    6647              :                 {
    6648        80778 :                   vexpr = build_debug_expr_decl (TREE_TYPE (parm));
    6649              :                   /* FIXME: Is setting the mode really necessary? */
    6650        80778 :                   SET_DECL_MODE (vexpr, DECL_MODE (parm));
    6651              :                 }
    6652       111229 :               def_temp = gimple_build_debug_bind (var, vexpr, NULL);
    6653       111229 :               gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
    6654       111229 :               def_temp = gimple_build_debug_source_bind (vexpr, parm, NULL);
    6655       111229 :               gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
    6656              :             }
    6657       111229 :           while (i > len);
    6658              :         }
    6659              :     }
    6660       166376 :   delete param_body_adjs;
    6661       253052 :   free_dominance_info (CDI_DOMINATORS);
    6662       253052 :   free_dominance_info (CDI_POST_DOMINATORS);
    6663              : 
    6664       253052 :   gcc_assert (!id.debug_stmts.exists ());
    6665       253052 :   pop_cfun ();
    6666       253052 :   input_location = saved_location;
    6667       253052 :   return;
    6668       253052 : }
    6669              : 
    6670              : /* EXP is CALL_EXPR present in a GENERIC expression tree.  Try to integrate
    6671              :    the callee and return the inlined body on success.  */
    6672              : 
    6673              : tree
    6674            0 : maybe_inline_call_in_expr (tree exp)
    6675              : {
    6676            0 :   tree fn = get_callee_fndecl (exp);
    6677              : 
    6678              :   /* We can only try to inline "const" functions.  */
    6679            0 :   if (fn && TREE_READONLY (fn) && DECL_SAVED_TREE (fn))
    6680              :     {
    6681            0 :       call_expr_arg_iterator iter;
    6682            0 :       copy_body_data id;
    6683            0 :       tree param, arg, t;
    6684            0 :       hash_map<tree, tree> decl_map;
    6685              : 
    6686              :       /* Remap the parameters.  */
    6687            0 :       for (param = DECL_ARGUMENTS (fn), arg = first_call_expr_arg (exp, &iter);
    6688            0 :            param;
    6689            0 :            param = DECL_CHAIN (param), arg = next_call_expr_arg (&iter))
    6690            0 :         decl_map.put (param, arg);
    6691              : 
    6692            0 :       memset (&id, 0, sizeof (id));
    6693            0 :       id.src_fn = fn;
    6694            0 :       id.dst_fn = current_function_decl;
    6695            0 :       id.src_cfun = DECL_STRUCT_FUNCTION (fn);
    6696            0 :       id.decl_map = &decl_map;
    6697              : 
    6698            0 :       id.copy_decl = copy_decl_no_change;
    6699            0 :       id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    6700            0 :       id.transform_new_cfg = false;
    6701            0 :       id.transform_return_to_modify = true;
    6702            0 :       id.transform_parameter = true;
    6703              : 
    6704              :       /* Make sure not to unshare trees behind the front-end's back
    6705              :          since front-end specific mechanisms may rely on sharing.  */
    6706            0 :       id.regimplify = false;
    6707            0 :       id.do_not_unshare = true;
    6708              : 
    6709              :       /* We're not inside any EH region.  */
    6710            0 :       id.eh_lp_nr = 0;
    6711              : 
    6712            0 :       t = copy_tree_body (&id);
    6713              : 
    6714              :       /* We can only return something suitable for use in a GENERIC
    6715              :          expression tree.  */
    6716            0 :       if (TREE_CODE (t) == MODIFY_EXPR)
    6717            0 :         return TREE_OPERAND (t, 1);
    6718            0 :     }
    6719              : 
    6720              :    return NULL_TREE;
    6721              : }
    6722              : 
    6723              : /* Duplicate a type, fields and all.  */
    6724              : 
    6725              : tree
    6726           63 : build_duplicate_type (tree type)
    6727              : {
    6728           63 :   struct copy_body_data id;
    6729              : 
    6730           63 :   memset (&id, 0, sizeof (id));
    6731           63 :   id.src_fn = current_function_decl;
    6732           63 :   id.dst_fn = current_function_decl;
    6733           63 :   id.src_cfun = cfun;
    6734           63 :   id.decl_map = new hash_map<tree, tree>;
    6735           63 :   id.debug_map = NULL;
    6736           63 :   id.copy_decl = copy_decl_no_change;
    6737              : 
    6738           63 :   type = remap_type_1 (type, &id);
    6739              : 
    6740          126 :   delete id.decl_map;
    6741           63 :   if (id.debug_map)
    6742            0 :     delete id.debug_map;
    6743              : 
    6744           63 :   TYPE_CANONICAL (type) = type;
    6745              : 
    6746           63 :   return type;
    6747              : }
    6748              : 
    6749              : /* Unshare the entire DECL_SAVED_TREE of FN and return the remapped
    6750              :    parameters and RESULT_DECL in PARMS and RESULT.  Used by C++ constexpr
    6751              :    evaluation.  */
    6752              : 
    6753              : tree
    6754     31004672 : copy_fn (tree fn, tree& parms, tree& result)
    6755              : {
    6756     31004672 :   copy_body_data id;
    6757     31004672 :   tree param;
    6758     31004672 :   hash_map<tree, tree> decl_map;
    6759              : 
    6760     31004672 :   tree *p = &parms;
    6761     31004672 :   *p = NULL_TREE;
    6762              : 
    6763     31004672 :   memset (&id, 0, sizeof (id));
    6764     31004672 :   id.src_fn = fn;
    6765     31004672 :   id.dst_fn = current_function_decl;
    6766     31004672 :   id.src_cfun = DECL_STRUCT_FUNCTION (fn);
    6767     31004672 :   id.decl_map = &decl_map;
    6768              : 
    6769    130361921 :   id.copy_decl = [] (tree decl, copy_body_data *id)
    6770              :     {
    6771     99357249 :       if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
    6772              :         /* Don't make copies of local types or injected enumerators,
    6773              :            the C++ constexpr evaluator doesn't need them and they
    6774              :            confuse modules streaming.  */
    6775              :         return decl;
    6776     97216922 :       return copy_decl_no_change (decl, id);
    6777              :     };
    6778     31004672 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    6779     31004672 :   id.transform_new_cfg = false;
    6780     31004672 :   id.transform_return_to_modify = false;
    6781     31004672 :   id.transform_parameter = true;
    6782              : 
    6783              :   /* Make sure not to unshare trees behind the front-end's back
    6784              :      since front-end specific mechanisms may rely on sharing.  */
    6785     31004672 :   id.regimplify = false;
    6786     31004672 :   id.do_not_unshare = true;
    6787     31004672 :   id.do_not_fold = true;
    6788              : 
    6789              :   /* We're not inside any EH region.  */
    6790     31004672 :   id.eh_lp_nr = 0;
    6791              : 
    6792              :   /* Remap the parameters and result and return them to the caller.  */
    6793     31004672 :   for (param = DECL_ARGUMENTS (fn);
    6794     74686342 :        param;
    6795     43681670 :        param = DECL_CHAIN (param))
    6796              :     {
    6797     43681670 :       *p = remap_decl (param, &id);
    6798     43681670 :       p = &DECL_CHAIN (*p);
    6799              :     }
    6800              : 
    6801     31004672 :   if (DECL_RESULT (fn))
    6802     31004672 :     result = remap_decl (DECL_RESULT (fn), &id);
    6803              :   else
    6804              :     result = NULL_TREE;
    6805              : 
    6806     31004672 :   return copy_tree_body (&id);
    6807     31004672 : }
        

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.