LCOV - code coverage report
Current view: top level - gcc - tree-inline.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.4 % 3258 2881
Test Date: 2024-11-30 13:30:02 Functions: 94.4 % 89 84
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

Generated by: LCOV version 2.1-beta

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