LCOV - code coverage report
Current view: top level - gcc - ipa-inline-transform.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 278 333 83.5 %
Date: 2020-03-28 11:57:23 Functions: 11 13 84.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Callgraph transformations to handle inlining
       2                 :            :    Copyright (C) 2003-2020 Free Software Foundation, Inc.
       3                 :            :    Contributed by Jan Hubicka
       4                 :            : 
       5                 :            : This file is part of GCC.
       6                 :            : 
       7                 :            : GCC is free software; you can redistribute it and/or modify it under
       8                 :            : the terms of the GNU General Public License as published by the Free
       9                 :            : Software Foundation; either version 3, or (at your option) any later
      10                 :            : version.
      11                 :            : 
      12                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :            : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :            : 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                 :            : /* The inline decisions are stored in callgraph in "inline plan" and
      22                 :            :    applied later.
      23                 :            : 
      24                 :            :    To mark given call inline, use inline_call function.
      25                 :            :    The function marks the edge inlinable and, if necessary, produces
      26                 :            :    virtual clone in the callgraph representing the new copy of callee's
      27                 :            :    function body.
      28                 :            : 
      29                 :            :    The inline plan is applied on given function body by inline_transform.  */
      30                 :            : 
      31                 :            : #include "config.h"
      32                 :            : #include "system.h"
      33                 :            : #include "coretypes.h"
      34                 :            : #include "tm.h"
      35                 :            : #include "function.h"
      36                 :            : #include "tree.h"
      37                 :            : #include "alloc-pool.h"
      38                 :            : #include "tree-pass.h"
      39                 :            : #include "cgraph.h"
      40                 :            : #include "tree-cfg.h"
      41                 :            : #include "symbol-summary.h"
      42                 :            : #include "tree-vrp.h"
      43                 :            : #include "ipa-prop.h"
      44                 :            : #include "ipa-fnsummary.h"
      45                 :            : #include "ipa-inline.h"
      46                 :            : #include "tree-inline.h"
      47                 :            : #include "function.h"
      48                 :            : #include "cfg.h"
      49                 :            : #include "basic-block.h"
      50                 :            : #include "ipa-utils.h"
      51                 :            : 
      52                 :            : int ncalls_inlined;
      53                 :            : int nfunctions_inlined;
      54                 :            : 
      55                 :            : /* Scale counts of NODE edges by NUM/DEN.  */
      56                 :            : 
      57                 :            : static void
      58                 :     984734 : update_noncloned_counts (struct cgraph_node *node, 
      59                 :            :                          profile_count num, profile_count den)
      60                 :            : {
      61                 :     984734 :   struct cgraph_edge *e;
      62                 :            : 
      63                 :     984734 :   profile_count::adjust_for_ipa_scaling (&num, &den);
      64                 :            : 
      65                 :    1816670 :   for (e = node->callees; e; e = e->next_callee)
      66                 :            :     {
      67                 :     831940 :       if (!e->inline_failed)
      68                 :      78941 :         update_noncloned_counts (e->callee, num, den);
      69                 :     831940 :       e->count = e->count.apply_scale (num, den);
      70                 :            :     }
      71                 :    1007980 :   for (e = node->indirect_calls; e; e = e->next_callee)
      72                 :      23246 :     e->count = e->count.apply_scale (num, den);
      73                 :     984734 :   node->count = node->count.apply_scale (num, den);
      74                 :     984734 : }
      75                 :            : 
      76                 :            : /* We removed or are going to remove the last call to NODE.
      77                 :            :    Return true if we can and want proactively remove the NODE now.
      78                 :            :    This is important to do, since we want inliner to know when offline
      79                 :            :    copy of function was removed.  */
      80                 :            : 
      81                 :            : static bool
      82                 :    1656730 : can_remove_node_now_p_1 (struct cgraph_node *node, struct cgraph_edge *e)
      83                 :            : {
      84                 :    1656730 :   ipa_ref *ref;
      85                 :            : 
      86                 :    2571310 :   FOR_EACH_ALIAS (node, ref)
      87                 :            :     {
      88                 :     450141 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
      89                 :     273804 :       if ((alias->callers && alias->callers != e)
      90                 :     450141 :           || !can_remove_node_now_p_1 (alias, e))
      91                 :     283543 :         return false;
      92                 :            :     }
      93                 :            :   /* FIXME: When address is taken of DECL_EXTERNAL function we still
      94                 :            :      can remove its offline copy, but we would need to keep unanalyzed node in
      95                 :            :      the callgraph so references can point to it.
      96                 :            : 
      97                 :            :      Also for comdat group we can ignore references inside a group as we
      98                 :            :      want to prove the group as a whole to be dead.  */
      99                 :    1373190 :   return (!node->address_taken
     100                 :    1348370 :           && node->can_remove_if_no_direct_calls_and_refs_p ()
     101                 :            :           /* Inlining might enable more devirtualizing, so we want to remove
     102                 :            :              those only after all devirtualizable virtual calls are processed.
     103                 :            :              Lacking may edges in callgraph we just preserve them post
     104                 :            :              inlining.  */
     105                 :    1306250 :           && (!DECL_VIRTUAL_P (node->decl)
     106                 :       5568 :               || !opt_for_fn (node->decl, flag_devirtualize))
     107                 :            :           /* During early inlining some unanalyzed cgraph nodes might be in the
     108                 :            :              callgraph and they might refer the function in question.  */
     109                 :    2673930 :           && !cgraph_new_nodes.exists ());
     110                 :            : }
     111                 :            : 
     112                 :            : /* We are going to eliminate last direct call to NODE (or alias of it) via edge E.
     113                 :            :    Verify that the NODE can be removed from unit and if it is contained in comdat
     114                 :            :    group that the whole comdat group is removable.  */
     115                 :            : 
     116                 :            : static bool
     117                 :    1376420 : can_remove_node_now_p (struct cgraph_node *node, struct cgraph_edge *e)
     118                 :            : {
     119                 :    1376420 :   struct cgraph_node *next;
     120                 :    1376420 :   if (!can_remove_node_now_p_1 (node, e))
     121                 :            :     return false;
     122                 :            : 
     123                 :            :   /* When we see same comdat group, we need to be sure that all
     124                 :            :      items can be removed.  */
     125                 :    1030200 :   if (!node->same_comdat_group || !node->externally_visible)
     126                 :            :     return true;
     127                 :     502329 :   for (next = dyn_cast<cgraph_node *> (node->same_comdat_group);
     128                 :     501285 :        next != node; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
     129                 :            :     {
     130                 :     168174 :       if (next->alias)
     131                 :      62801 :         continue;
     132                 :     105205 :       if ((next->callers && next->callers != e)
     133                 :     209175 :           || !can_remove_node_now_p_1 (next, e))
     134                 :            :         return false;
     135                 :            :     }
     136                 :            :   return true;
     137                 :            : }
     138                 :            : 
     139                 :            : /* Return true if NODE is a master clone with non-inline clones.  */
     140                 :            : 
     141                 :            : static bool
     142                 :     905829 : master_clone_with_noninline_clones_p (struct cgraph_node *node)
     143                 :            : {
     144                 :          0 :   if (node->clone_of)
     145                 :            :     return false;
     146                 :            : 
     147                 :    1127200 :   for (struct cgraph_node *n = node->clones; n; n = n->next_sibling_clone)
     148                 :     278926 :     if (n->decl != node->decl)
     149                 :            :       return true;
     150                 :            : 
     151                 :            :   return false;
     152                 :            : }
     153                 :            : 
     154                 :            : /* E is expected to be an edge being inlined.  Clone destination node of
     155                 :            :    the edge and redirect it to the new clone.
     156                 :            :    DUPLICATE is used for bookkeeping on whether we are actually creating new
     157                 :            :    clones or re-using node originally representing out-of-line function call.
     158                 :            :    By default the offline copy is removed, when it appears dead after inlining.
     159                 :            :    UPDATE_ORIGINAL prevents this transformation.
     160                 :            :    If OVERALL_SIZE is non-NULL, the size is updated to reflect the
     161                 :            :    transformation.  */
     162                 :            : 
     163                 :            : void
     164                 :    2495790 : clone_inlined_nodes (struct cgraph_edge *e, bool duplicate,
     165                 :            :                      bool update_original, int *overall_size)
     166                 :            : {
     167                 :    2495790 :   struct cgraph_node *inlining_into;
     168                 :    2495790 :   struct cgraph_edge *next;
     169                 :            : 
     170                 :    2495790 :   if (e->caller->inlined_to)
     171                 :            :     inlining_into = e->caller->inlined_to;
     172                 :            :   else
     173                 :    2168550 :     inlining_into = e->caller;
     174                 :            : 
     175                 :    2495790 :   if (duplicate)
     176                 :            :     {
     177                 :            :       /* We may eliminate the need for out-of-line copy to be output.
     178                 :            :          In that case just go ahead and re-use it.  This is not just an
     179                 :            :          memory optimization.  Making offline copy of function disappear
     180                 :            :          from the program will improve future decisions on inlining.  */
     181                 :    2416850 :       if (!e->callee->callers->next_caller
     182                 :            :           /* Recursive inlining never wants the master clone to
     183                 :            :              be overwritten.  */
     184                 :    1254400 :           && update_original
     185                 :    1245240 :           && can_remove_node_now_p (e->callee, e)
     186                 :            :           /* We cannot overwrite a master clone with non-inline clones
     187                 :            :              until after these clones are materialized.  */
     188                 :    4170980 :           && !master_clone_with_noninline_clones_p (e->callee))
     189                 :            :         {
     190                 :            :           /* TODO: When callee is in a comdat group, we could remove all of it,
     191                 :            :              including all inline clones inlined into it.  That would however
     192                 :            :              need small function inlining to register edge removal hook to
     193                 :            :              maintain the priority queue.
     194                 :            : 
     195                 :            :              For now we keep the other functions in the group in program until
     196                 :            :              cgraph_remove_unreachable_functions gets rid of them.  */
     197                 :     905793 :           gcc_assert (!e->callee->inlined_to);
     198                 :     905793 :           e->callee->remove_from_same_comdat_group ();
     199                 :     905793 :           if (e->callee->definition
     200                 :     905793 :               && inline_account_function_p (e->callee))
     201                 :            :             {
     202                 :     791950 :               gcc_assert (!e->callee->alias);
     203                 :     791950 :               if (overall_size)
     204                 :     131152 :                 *overall_size -= ipa_size_summaries->get (e->callee)->size;
     205                 :     791950 :               nfunctions_inlined++;
     206                 :            :             }
     207                 :     905793 :           duplicate = false;
     208                 :     905793 :           e->callee->externally_visible = false;
     209                 :     905793 :           update_noncloned_counts (e->callee, e->count, e->callee->count);
     210                 :            : 
     211                 :     905793 :           dump_callgraph_transformation (e->callee, inlining_into,
     212                 :            :                                          "inlining to");
     213                 :            :         }
     214                 :            :       else
     215                 :            :         {
     216                 :    1511050 :           struct cgraph_node *n;
     217                 :            : 
     218                 :    1511050 :           n = e->callee->create_clone (e->callee->decl,
     219                 :            :                                        e->count,
     220                 :            :                                        update_original, vNULL, true,
     221                 :            :                                        inlining_into,
     222                 :            :                                        NULL);
     223                 :    1511050 :           n->used_as_abstract_origin = e->callee->used_as_abstract_origin;
     224                 :    1511050 :           e->redirect_callee (n);
     225                 :            :         }
     226                 :            :     }
     227                 :            :   else
     228                 :      78941 :     e->callee->remove_from_same_comdat_group ();
     229                 :            : 
     230                 :    2495790 :   e->callee->inlined_to = inlining_into;
     231                 :            : 
     232                 :            :   /* Recursively clone all bodies.  */
     233                 :    4255910 :   for (e = e->callee->callees; e; e = next)
     234                 :            :     {
     235                 :    1760120 :       next = e->next_callee;
     236                 :    1760120 :       if (!e->inline_failed)
     237                 :     211630 :         clone_inlined_nodes (e, duplicate, update_original, overall_size);
     238                 :            :     }
     239                 :    2495790 : }
     240                 :            : 
     241                 :            : /* Check all speculations in N and if any seem useless, resolve them.  When a
     242                 :            :    first edge is resolved, pop all edges from NEW_EDGES and insert them to
     243                 :            :    EDGE_SET.  Then remove each resolved edge from EDGE_SET, if it is there.  */
     244                 :            : 
     245                 :            : static bool
     246                 :    2495040 : check_speculations_1 (cgraph_node *n, vec<cgraph_edge *> *new_edges,
     247                 :            :                       hash_set <cgraph_edge *> *edge_set)
     248                 :            : {
     249                 :    2495040 :   bool speculation_removed = false;
     250                 :    2495040 :   cgraph_edge *next;
     251                 :            : 
     252                 :    4256680 :   for (cgraph_edge *e = n->callees; e; e = next)
     253                 :            :     {
     254                 :    1761640 :       next = e->next_callee;
     255                 :    1761640 :       if (e->speculative && !speculation_useful_p (e, true))
     256                 :            :         {
     257                 :          5 :           while (new_edges && !new_edges->is_empty ())
     258                 :          1 :             edge_set->add (new_edges->pop ());
     259                 :          4 :           edge_set->remove (e);
     260                 :            : 
     261                 :          4 :           cgraph_edge::resolve_speculation (e, NULL);
     262                 :          4 :           speculation_removed = true;
     263                 :            :         }
     264                 :    1761640 :       else if (!e->inline_failed)
     265                 :     211339 :         speculation_removed |= check_speculations_1 (e->callee, new_edges,
     266                 :            :                                                      edge_set);
     267                 :            :     }
     268                 :    2495040 :   return speculation_removed;
     269                 :            : }
     270                 :            : 
     271                 :            : /* Push E to NEW_EDGES.  Called from hash_set traverse method, which
     272                 :            :    unfortunately means this function has to have external linkage, otherwise
     273                 :            :    the code will not compile with gcc 4.8.  */
     274                 :            : 
     275                 :            : bool
     276                 :          0 : push_all_edges_in_set_to_vec (cgraph_edge * const &e,
     277                 :            :                               vec<cgraph_edge *> *new_edges)
     278                 :            : {
     279                 :          0 :   new_edges->safe_push (e);
     280                 :          0 :   return true;
     281                 :            : }
     282                 :            : 
     283                 :            : /* Check all speculations in N and if any seem useless, resolve them and remove
     284                 :            :    them from NEW_EDGES.  */
     285                 :            : 
     286                 :            : static bool
     287                 :    2283700 : check_speculations (cgraph_node *n, vec<cgraph_edge *> *new_edges)
     288                 :            : {
     289                 :    2283700 :   hash_set <cgraph_edge *> edge_set;
     290                 :    2283700 :   bool res = check_speculations_1 (n, new_edges, &edge_set);
     291                 :    2283700 :   if (!edge_set.is_empty ())
     292                 :          0 :     edge_set.traverse <vec<cgraph_edge *> *,
     293                 :          0 :                        push_all_edges_in_set_to_vec> (new_edges);
     294                 :    2283700 :   return res;
     295                 :            : }
     296                 :            : 
     297                 :            : /* Mark all call graph edges coming out of NODE and all nodes that have been
     298                 :            :    inlined to it as in_polymorphic_cdtor.  */
     299                 :            : 
     300                 :            : static void
     301                 :      89247 : mark_all_inlined_calls_cdtor (cgraph_node *node)
     302                 :            : {
     303                 :     170549 :   for (cgraph_edge *cs = node->callees; cs; cs = cs->next_callee)
     304                 :            :     {
     305                 :      81302 :       cs->in_polymorphic_cdtor = true;
     306                 :      81302 :       if (!cs->inline_failed)
     307                 :       8329 :         mark_all_inlined_calls_cdtor (cs->callee);
     308                 :            :     }
     309                 :      92678 :   for (cgraph_edge *cs = node->indirect_calls; cs; cs = cs->next_callee)
     310                 :       3431 :     cs->in_polymorphic_cdtor = true;
     311                 :      89247 : }
     312                 :            : 
     313                 :            : 
     314                 :            : /* Mark edge E as inlined and update callgraph accordingly.  UPDATE_ORIGINAL
     315                 :            :    specify whether profile of original function should be updated.  If any new
     316                 :            :    indirect edges are discovered in the process, add them to NEW_EDGES, unless
     317                 :            :    it is NULL. If UPDATE_OVERALL_SUMMARY is false, do not bother to recompute overall
     318                 :            :    size of caller after inlining. Caller is required to eventually do it via
     319                 :            :    ipa_update_overall_fn_summary.
     320                 :            :    If callee_removed is non-NULL, set it to true if we removed callee node.
     321                 :            : 
     322                 :            :    Return true iff any new callgraph edges were discovered as a
     323                 :            :    result of inlining.  */
     324                 :            : 
     325                 :            : bool
     326                 :    2283700 : inline_call (struct cgraph_edge *e, bool update_original,
     327                 :            :              vec<cgraph_edge *> *new_edges,
     328                 :            :              int *overall_size, bool update_overall_summary,
     329                 :            :              bool *callee_removed)
     330                 :            : {
     331                 :    2283700 :   int old_size = 0, new_size = 0;
     332                 :    2283700 :   struct cgraph_node *to = NULL;
     333                 :    2283700 :   struct cgraph_edge *curr = e;
     334                 :    2283700 :   bool comdat_local = e->callee->comdat_local_p ();
     335                 :    2283700 :   struct cgraph_node *callee = e->callee->ultimate_alias_target ();
     336                 :    2283700 :   bool new_edges_found = false;
     337                 :            : 
     338                 :    2283700 :   int estimated_growth = 0;
     339                 :    2283700 :   if (! update_overall_summary)
     340                 :    1844960 :     estimated_growth = estimate_edge_growth (e);
     341                 :            :   /* This is used only for assert bellow.  */
     342                 :            : #if 0
     343                 :            :   bool predicated = inline_edge_summary (e)->predicate != NULL;
     344                 :            : #endif
     345                 :            : 
     346                 :            :   /* Don't inline inlined edges.  */
     347                 :    2283700 :   gcc_assert (e->inline_failed);
     348                 :            :   /* Don't even think of inlining inline clone.  */
     349                 :    2283700 :   gcc_assert (!callee->inlined_to);
     350                 :            : 
     351                 :    2283700 :   to = e->caller;
     352                 :    2283700 :   if (to->inlined_to)
     353                 :     115607 :     to = to->inlined_to;
     354                 :    2283700 :   if (to->thunk.thunk_p)
     355                 :            :     {
     356                 :        944 :       struct cgraph_node *target = to->callees->callee;
     357                 :        944 :       thunk_expansion = true;
     358                 :        944 :       symtab->call_cgraph_removal_hooks (to);
     359                 :        944 :       if (in_lto_p)
     360                 :         57 :         to->get_untransformed_body ();
     361                 :        944 :       to->expand_thunk (false, true);
     362                 :            :       /* When thunk is instrumented we may have multiple callees.  */
     363                 :        944 :       for (e = to->callees; e && e->callee != target; e = e->next_callee)
     364                 :            :         ;
     365                 :        944 :       symtab->call_cgraph_insertion_hooks (to);
     366                 :        944 :       thunk_expansion = false;
     367                 :        944 :       gcc_assert (e);
     368                 :            :     }
     369                 :            : 
     370                 :            : 
     371                 :    2283700 :   e->inline_failed = CIF_OK;
     372                 :    2283700 :   DECL_POSSIBLY_INLINED (callee->decl) = true;
     373                 :            : 
     374                 :    2283700 :   if (DECL_FUNCTION_PERSONALITY (callee->decl))
     375                 :      57900 :     DECL_FUNCTION_PERSONALITY (to->decl)
     376                 :      28950 :       = DECL_FUNCTION_PERSONALITY (callee->decl);
     377                 :            : 
     378                 :    2283700 :   bool reload_optimization_node = false;
     379                 :    2283700 :   if (!opt_for_fn (callee->decl, flag_strict_aliasing)
     380                 :    2283700 :       && opt_for_fn (to->decl, flag_strict_aliasing))
     381                 :            :     {
     382                 :         11 :       struct gcc_options opts = global_options;
     383                 :            : 
     384                 :         11 :       cl_optimization_restore (&opts, opts_for_fn (to->decl));
     385                 :         11 :       opts.x_flag_strict_aliasing = false;
     386                 :         11 :       if (dump_file)
     387                 :          0 :         fprintf (dump_file, "Dropping flag_strict_aliasing on %s\n",
     388                 :            :                  to->dump_name ());
     389                 :         11 :       DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
     390                 :         11 :          = build_optimization_node (&opts);
     391                 :         11 :       reload_optimization_node = true;
     392                 :            :     }
     393                 :            : 
     394                 :    2283700 :   ipa_fn_summary *caller_info = ipa_fn_summaries->get (to);
     395                 :    2283700 :   ipa_fn_summary *callee_info = ipa_fn_summaries->get (callee);
     396                 :    2283700 :   if (!caller_info->fp_expressions && callee_info->fp_expressions)
     397                 :            :     {
     398                 :       8325 :       caller_info->fp_expressions = true;
     399                 :       8325 :       if (opt_for_fn (callee->decl, flag_rounding_math)
     400                 :       8325 :           != opt_for_fn (to->decl, flag_rounding_math)
     401                 :       8325 :           || opt_for_fn (callee->decl, flag_trapping_math)
     402                 :       8325 :              != opt_for_fn (to->decl, flag_trapping_math)
     403                 :       8325 :           || opt_for_fn (callee->decl, flag_unsafe_math_optimizations)
     404                 :       8325 :              != opt_for_fn (to->decl, flag_unsafe_math_optimizations)
     405                 :       8325 :           || opt_for_fn (callee->decl, flag_finite_math_only)
     406                 :       8325 :              != opt_for_fn (to->decl, flag_finite_math_only)
     407                 :       8325 :           || opt_for_fn (callee->decl, flag_signaling_nans)
     408                 :       8325 :              != opt_for_fn (to->decl, flag_signaling_nans)
     409                 :       8325 :           || opt_for_fn (callee->decl, flag_cx_limited_range)
     410                 :       8325 :              != opt_for_fn (to->decl, flag_cx_limited_range)
     411                 :       8325 :           || opt_for_fn (callee->decl, flag_signed_zeros)
     412                 :       8325 :              != opt_for_fn (to->decl, flag_signed_zeros)
     413                 :       8325 :           || opt_for_fn (callee->decl, flag_associative_math)
     414                 :       8325 :              != opt_for_fn (to->decl, flag_associative_math)
     415                 :       8325 :           || opt_for_fn (callee->decl, flag_reciprocal_math)
     416                 :       8325 :              != opt_for_fn (to->decl, flag_reciprocal_math)
     417                 :       8325 :           || opt_for_fn (callee->decl, flag_fp_int_builtin_inexact)
     418                 :       8325 :              != opt_for_fn (to->decl, flag_fp_int_builtin_inexact)
     419                 :       8325 :           || opt_for_fn (callee->decl, flag_errno_math)
     420                 :       8325 :              != opt_for_fn (to->decl, flag_errno_math))
     421                 :            :         {
     422                 :          0 :           struct gcc_options opts = global_options;
     423                 :            : 
     424                 :          0 :           cl_optimization_restore (&opts, opts_for_fn (to->decl));
     425                 :          0 :           opts.x_flag_rounding_math
     426                 :          0 :             = opt_for_fn (callee->decl, flag_rounding_math);
     427                 :          0 :           opts.x_flag_trapping_math
     428                 :          0 :             = opt_for_fn (callee->decl, flag_trapping_math);
     429                 :          0 :           opts.x_flag_unsafe_math_optimizations
     430                 :          0 :             = opt_for_fn (callee->decl, flag_unsafe_math_optimizations);
     431                 :          0 :           opts.x_flag_finite_math_only
     432                 :          0 :             = opt_for_fn (callee->decl, flag_finite_math_only);
     433                 :          0 :           opts.x_flag_signaling_nans
     434                 :          0 :             = opt_for_fn (callee->decl, flag_signaling_nans);
     435                 :          0 :           opts.x_flag_cx_limited_range
     436                 :          0 :             = opt_for_fn (callee->decl, flag_cx_limited_range);
     437                 :          0 :           opts.x_flag_signed_zeros
     438                 :          0 :             = opt_for_fn (callee->decl, flag_signed_zeros);
     439                 :          0 :           opts.x_flag_associative_math
     440                 :          0 :             = opt_for_fn (callee->decl, flag_associative_math);
     441                 :          0 :           opts.x_flag_reciprocal_math
     442                 :          0 :             = opt_for_fn (callee->decl, flag_reciprocal_math);
     443                 :          0 :           opts.x_flag_fp_int_builtin_inexact
     444                 :          0 :             = opt_for_fn (callee->decl, flag_fp_int_builtin_inexact);
     445                 :          0 :           opts.x_flag_errno_math
     446                 :          0 :             = opt_for_fn (callee->decl, flag_errno_math);
     447                 :          0 :           if (dump_file)
     448                 :          0 :             fprintf (dump_file, "Copying FP flags from %s to %s\n",
     449                 :            :                      callee->dump_name (), to->dump_name ());
     450                 :          0 :           DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
     451                 :          0 :              = build_optimization_node (&opts);
     452                 :          0 :           reload_optimization_node = true;
     453                 :            :         }
     454                 :            :     }
     455                 :            : 
     456                 :            :   /* Reload global optimization flags.  */
     457                 :    2283700 :   if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun)
     458                 :         11 :     set_cfun (cfun, true);
     459                 :            : 
     460                 :            :   /* If aliases are involved, redirect edge to the actual destination and
     461                 :            :      possibly remove the aliases.  */
     462                 :    2283700 :   if (e->callee != callee)
     463                 :            :     {
     464                 :     399461 :       struct cgraph_node *alias = e->callee, *next_alias;
     465                 :     399461 :       e->redirect_callee (callee);
     466                 :     522404 :       while (alias && alias != callee)
     467                 :            :         {
     468                 :     399495 :           if (!alias->callers
     469                 :     530674 :               && can_remove_node_now_p (alias,
     470                 :     131179 :                                         !e->next_caller && !e->prev_caller ? e : NULL))
     471                 :            :             {
     472                 :     122943 :               next_alias = alias->get_alias_target ();
     473                 :     122943 :               alias->remove ();
     474                 :     122943 :               if (callee_removed)
     475                 :        571 :                 *callee_removed = true;
     476                 :            :               alias = next_alias;
     477                 :            :             }
     478                 :            :           else
     479                 :            :             break;
     480                 :            :         }
     481                 :            :     }
     482                 :            : 
     483                 :    2283700 :   clone_inlined_nodes (e, true, update_original, overall_size);
     484                 :            : 
     485                 :    2283700 :   gcc_assert (curr->callee->inlined_to == to);
     486                 :            : 
     487                 :    2283700 :   old_size = ipa_size_summaries->get (to)->size;
     488                 :    2283700 :   ipa_merge_fn_summary_after_inlining (e);
     489                 :    2283700 :   if (e->in_polymorphic_cdtor)
     490                 :      80918 :     mark_all_inlined_calls_cdtor (e->callee);
     491                 :    2283700 :   if (opt_for_fn (e->caller->decl, optimize))
     492                 :    2275840 :     new_edges_found = ipa_propagate_indirect_call_infos (curr, new_edges);
     493                 :    2283700 :   bool removed_p = check_speculations (e->callee, new_edges);
     494                 :    2283700 :   if (update_overall_summary)
     495                 :     438738 :     ipa_update_overall_fn_summary (to, new_edges_found || removed_p);
     496                 :            :   else
     497                 :            :     /* Update self size by the estimate so overall function growth limits
     498                 :            :        work for further inlining into this function.  Before inlining
     499                 :            :        the function we inlined to again we expect the caller to update
     500                 :            :        the overall summary.  */
     501                 :    1844960 :     ipa_size_summaries->get (to)->size += estimated_growth;
     502                 :    2283700 :   new_size = ipa_size_summaries->get (to)->size;
     503                 :            : 
     504                 :    2283700 :   if (callee->calls_comdat_local)
     505                 :          0 :     to->calls_comdat_local = true;
     506                 :    2283700 :   else if (to->calls_comdat_local && comdat_local)
     507                 :       2384 :     to->calls_comdat_local = to->check_calls_comdat_local_p ();
     508                 :            : 
     509                 :            :   /* FIXME: This assert suffers from roundoff errors, disable it for GCC 5
     510                 :            :      and revisit it after conversion to sreals in GCC 6.
     511                 :            :      See PR 65654.  */
     512                 :            : #if 0
     513                 :            :   /* Verify that estimated growth match real growth.  Allow off-by-one
     514                 :            :      error due to ipa_fn_summary::size_scale roudoff errors.  */
     515                 :            :   gcc_assert (!update_overall_summary || !overall_size || new_edges_found
     516                 :            :               || abs (estimated_growth - (new_size - old_size)) <= 1
     517                 :            :               || speculation_removed
     518                 :            :               /* FIXME: a hack.  Edges with false predicate are accounted
     519                 :            :                  wrong, we should remove them from callgraph.  */
     520                 :            :               || predicated);
     521                 :            : #endif
     522                 :            : 
     523                 :            :   /* Account the change of overall unit size; external functions will be
     524                 :            :      removed and are thus not accounted.  */
     525                 :    2283700 :   if (overall_size && inline_account_function_p (to))
     526                 :     431016 :     *overall_size += new_size - old_size;
     527                 :    2283700 :   ncalls_inlined++;
     528                 :            : 
     529                 :            :   /* This must happen after ipa_merge_fn_summary_after_inlining that rely on jump
     530                 :            :      functions of callee to not be updated.  */
     531                 :    2283700 :   return new_edges_found;
     532                 :            : }
     533                 :            : 
     534                 :            : 
     535                 :            : /* Copy function body of NODE and redirect all inline clones to it.
     536                 :            :    This is done before inline plan is applied to NODE when there are
     537                 :            :    still some inline clones if it.
     538                 :            : 
     539                 :            :    This is necessary because inline decisions are not really transitive
     540                 :            :    and the other inline clones may have different bodies.  */
     541                 :            : 
     542                 :            : static struct cgraph_node *
     543                 :      28787 : save_inline_function_body (struct cgraph_node *node)
     544                 :            : {
     545                 :      28787 :   struct cgraph_node *first_clone, *n;
     546                 :            : 
     547                 :      28787 :   if (dump_file)
     548                 :        149 :     fprintf (dump_file, "\nSaving body of %s for later reuse\n",
     549                 :            :              node->dump_name ());
     550                 :            :  
     551                 :      28787 :   gcc_assert (node == cgraph_node::get (node->decl));
     552                 :            : 
     553                 :            :   /* first_clone will be turned into real function.  */
     554                 :      28787 :   first_clone = node->clones;
     555                 :            : 
     556                 :            :   /* Arrange first clone to not be thunk as those do not have bodies.  */
     557                 :      28787 :   if (first_clone->thunk.thunk_p)
     558                 :            :     {
     559                 :          0 :       while (first_clone->thunk.thunk_p)
     560                 :          0 :         first_clone = first_clone->next_sibling_clone;
     561                 :          0 :       first_clone->prev_sibling_clone->next_sibling_clone
     562                 :          0 :         = first_clone->next_sibling_clone;
     563                 :          0 :       if (first_clone->next_sibling_clone)
     564                 :          0 :         first_clone->next_sibling_clone->prev_sibling_clone
     565                 :          0 :            = first_clone->prev_sibling_clone;
     566                 :          0 :       first_clone->next_sibling_clone = node->clones;
     567                 :          0 :       first_clone->prev_sibling_clone = NULL;
     568                 :          0 :       node->clones->prev_sibling_clone = first_clone;
     569                 :          0 :       node->clones = first_clone;
     570                 :            :     }
     571                 :      28787 :   first_clone->decl = copy_node (node->decl);
     572                 :      28787 :   first_clone->decl->decl_with_vis.symtab_node = first_clone;
     573                 :      28787 :   gcc_assert (first_clone == cgraph_node::get (first_clone->decl));
     574                 :            : 
     575                 :            :   /* Now reshape the clone tree, so all other clones descends from
     576                 :            :      first_clone.  */
     577                 :      28787 :   if (first_clone->next_sibling_clone)
     578                 :            :     {
     579                 :      78176 :       for (n = first_clone->next_sibling_clone; n->next_sibling_clone;
     580                 :      64782 :            n = n->next_sibling_clone)
     581                 :      64782 :         n->clone_of = first_clone;
     582                 :      13394 :       n->clone_of = first_clone;
     583                 :      13394 :       n->next_sibling_clone = first_clone->clones;
     584                 :      13394 :       if (first_clone->clones)
     585                 :        201 :         first_clone->clones->prev_sibling_clone = n;
     586                 :      13394 :       first_clone->clones = first_clone->next_sibling_clone;
     587                 :      13394 :       first_clone->next_sibling_clone->prev_sibling_clone = NULL;
     588                 :      13394 :       first_clone->next_sibling_clone = NULL;
     589                 :      13394 :       gcc_assert (!first_clone->prev_sibling_clone);
     590                 :            :     }
     591                 :      28787 :   first_clone->clone_of = NULL;
     592                 :            : 
     593                 :            :   /* Now node in question has no clones.  */
     594                 :      28787 :   node->clones = NULL;
     595                 :            : 
     596                 :            :   /* Inline clones share decl with the function they are cloned
     597                 :            :      from.  Walk the whole clone tree and redirect them all to the
     598                 :            :      new decl.  */
     599                 :      28787 :   if (first_clone->clones)
     600                 :     104020 :     for (n = first_clone->clones; n != first_clone;)
     601                 :            :       {
     602                 :      89606 :         gcc_assert (n->decl == node->decl);
     603                 :      89606 :         n->decl = first_clone->decl;
     604                 :      89606 :         if (n->clones)
     605                 :            :           n = n->clones;
     606                 :      87177 :         else if (n->next_sibling_clone)
     607                 :            :           n = n->next_sibling_clone;
     608                 :            :         else
     609                 :            :           {
     610                 :      33041 :             while (n != first_clone && !n->next_sibling_clone)
     611                 :      16843 :               n = n->clone_of;
     612                 :      16198 :             if (n != first_clone)
     613                 :       1784 :               n = n->next_sibling_clone;
     614                 :            :           }
     615                 :            :       }
     616                 :            : 
     617                 :            :   /* Copy the OLD_VERSION_NODE function tree to the new version.  */
     618                 :      28787 :   tree_function_versioning (node->decl, first_clone->decl,
     619                 :            :                             NULL, NULL, true, NULL, NULL);
     620                 :            : 
     621                 :            :   /* The function will be short lived and removed after we inline all the clones,
     622                 :            :      but make it internal so we won't confuse ourself.  */
     623                 :      28787 :   DECL_EXTERNAL (first_clone->decl) = 0;
     624                 :      28787 :   TREE_PUBLIC (first_clone->decl) = 0;
     625                 :      28787 :   DECL_COMDAT (first_clone->decl) = 0;
     626                 :      28787 :   first_clone->ipa_transforms_to_apply.release ();
     627                 :            : 
     628                 :            :   /* When doing recursive inlining, the clone may become unnecessary.
     629                 :            :      This is possible i.e. in the case when the recursive function is proved to be
     630                 :            :      non-throwing and the recursion happens only in the EH landing pad.
     631                 :            :      We cannot remove the clone until we are done with saving the body.
     632                 :            :      Remove it now.  */
     633                 :      28787 :   if (!first_clone->callers)
     634                 :            :     {
     635                 :          0 :       first_clone->remove_symbol_and_inline_clones ();
     636                 :          0 :       first_clone = NULL;
     637                 :            :     }
     638                 :      28787 :   else if (flag_checking)
     639                 :      28787 :     first_clone->verify ();
     640                 :            : 
     641                 :      28787 :   return first_clone;
     642                 :            : }
     643                 :            : 
     644                 :            : /* Return true when function body of DECL still needs to be kept around
     645                 :            :    for later re-use.  */
     646                 :            : static bool
     647                 :     936940 : preserve_function_body_p (struct cgraph_node *node)
     648                 :            : {
     649                 :     936940 :   gcc_assert (symtab->global_info_ready);
     650                 :     936940 :   gcc_assert (!node->alias && !node->thunk.thunk_p);
     651                 :            : 
     652                 :            :   /* Look if there is any non-thunk clone around.  */
     653                 :     936994 :   for (node = node->clones; node; node = node->next_sibling_clone)
     654                 :      28841 :     if (!node->thunk.thunk_p)
     655                 :            :       return true;
     656                 :            :   return false;
     657                 :            : }
     658                 :            : 
     659                 :            : /* Apply inline plan to function.  */
     660                 :            : 
     661                 :            : unsigned int
     662                 :     936940 : inline_transform (struct cgraph_node *node)
     663                 :            : {
     664                 :     936940 :   unsigned int todo = 0;
     665                 :     936940 :   struct cgraph_edge *e, *next;
     666                 :     936940 :   bool has_inline = false;
     667                 :            :  
     668                 :            :   /* FIXME: Currently the pass manager is adding inline transform more than
     669                 :            :      once to some clones.  This needs revisiting after WPA cleanups.  */
     670                 :     936940 :   if (cfun->after_inlining)
     671                 :            :     return 0;
     672                 :            : 
     673                 :            :   /* We might need the body of this function so that we can expand
     674                 :            :      it inline somewhere else.  */
     675                 :     936940 :   if (preserve_function_body_p (node))
     676                 :      28787 :     save_inline_function_body (node);
     677                 :            : 
     678                 :     936940 :   profile_count num = node->count;
     679                 :     936940 :   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
     680                 :    1618930 :   bool scale = num.initialized_p () && !(num == den);
     681                 :         39 :   if (scale)
     682                 :            :     {
     683                 :         39 :       profile_count::adjust_for_ipa_scaling (&num, &den);
     684                 :         39 :       if (dump_file)
     685                 :            :         {
     686                 :          0 :           fprintf (dump_file, "Applying count scale ");
     687                 :          0 :           num.dump (dump_file);
     688                 :          0 :           fprintf (dump_file, "/");
     689                 :          0 :           den.dump (dump_file);
     690                 :          0 :           fprintf (dump_file, "\n");
     691                 :            :         }
     692                 :            : 
     693                 :         39 :       basic_block bb;
     694                 :         39 :       cfun->cfg->count_max = profile_count::uninitialized ();
     695                 :        287 :       FOR_ALL_BB_FN (bb, cfun)
     696                 :            :         {
     697                 :        248 :           bb->count = bb->count.apply_scale (num, den);
     698                 :        248 :           cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
     699                 :            :         }
     700                 :         39 :       ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
     701                 :            :     }
     702                 :            : 
     703                 :    4771250 :   for (e = node->callees; e; e = next)
     704                 :            :     {
     705                 :    3834310 :       if (!e->inline_failed)
     706                 :     293103 :         has_inline = true;
     707                 :    3834310 :       next = e->next_callee;
     708                 :    3834310 :       cgraph_edge::redirect_call_stmt_to_callee (e);
     709                 :            :     }
     710                 :     936940 :   node->remove_all_references ();
     711                 :            : 
     712                 :     936940 :   timevar_push (TV_INTEGRATION);
     713                 :     936940 :   if (node->callees && (opt_for_fn (node->decl, optimize) || has_inline))
     714                 :            :     {
     715                 :     533179 :       todo = optimize_inline_calls (current_function_decl);
     716                 :            :     }
     717                 :     936940 :   timevar_pop (TV_INTEGRATION);
     718                 :            : 
     719                 :     936940 :   cfun->always_inline_functions_inlined = true;
     720                 :     936940 :   cfun->after_inlining = true;
     721                 :     936940 :   todo |= execute_fixup_cfg ();
     722                 :            : 
     723                 :     936940 :   if (!(todo & TODO_update_ssa_any))
     724                 :            :     /* Redirecting edges might lead to a need for vops to be recomputed.  */
     725                 :     697138 :     todo |= TODO_update_ssa_only_virtuals;
     726                 :            : 
     727                 :            :   return todo;
     728                 :            : }

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.