LCOV - code coverage report
Current view: top level - gcc - cgraph.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 82.2 % 2349 1930
Test Date: 2026-09-19 16:22:48 Functions: 92.7 % 137 127
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Callgraph handling code.
       2              :    Copyright (C) 2003-2026 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              : /*  This file contains basic routines manipulating call graph
      22              : 
      23              :     The call-graph is a data structure designed for inter-procedural
      24              :     optimization.  It represents a multi-graph where nodes are functions
      25              :     (symbols within symbol table) and edges are call sites. */
      26              : 
      27              : #include "config.h"
      28              : #include "system.h"
      29              : #include "coretypes.h"
      30              : #include "backend.h"
      31              : #include "target.h"
      32              : #include "rtl.h"
      33              : #include "tree.h"
      34              : #include "gimple.h"
      35              : #include "predict.h"
      36              : #include "alloc-pool.h"
      37              : #include "gimple-ssa.h"
      38              : #include "cgraph.h"
      39              : #include "lto-streamer.h"
      40              : #include "fold-const.h"
      41              : #include "varasm.h"
      42              : #include "calls.h"
      43              : #include "print-tree.h"
      44              : #include "langhooks.h"
      45              : #include "intl.h"
      46              : #include "tree-eh.h"
      47              : #include "gimple-iterator.h"
      48              : #include "tree-cfg.h"
      49              : #include "tree-ssa.h"
      50              : #include "value-prof.h"
      51              : #include "ipa-utils.h"
      52              : #include "symbol-summary.h"
      53              : #include "tree-vrp.h"
      54              : #include "sreal.h"
      55              : #include "ipa-cp.h"
      56              : #include "ipa-prop.h"
      57              : #include "ipa-fnsummary.h"
      58              : #include "cfgloop.h"
      59              : #include "gimple-pretty-print.h"
      60              : #include "tree-dfa.h"
      61              : #include "profile.h"
      62              : #include "context.h"
      63              : #include "gimplify.h"
      64              : #include "stringpool.h"
      65              : #include "attribs.h"
      66              : #include "selftest.h"
      67              : #include "tree-into-ssa.h"
      68              : #include "ipa-inline.h"
      69              : #include "tree-nested.h"
      70              : #include "symtab-thunks.h"
      71              : #include "symtab-clones.h"
      72              : #include "attr-callback.h"
      73              : #include "callback-info.h"
      74              : 
      75              : /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this.  */
      76              : #include "tree-pass.h"
      77              : 
      78              : /* Symbol table global context.  */
      79              : symbol_table *symtab;
      80              : 
      81              : /* List of hooks triggered on cgraph_edge events.  */
      82              : struct cgraph_edge_hook_list {
      83              :   cgraph_edge_hook hook;
      84              :   void *data;
      85              :   struct cgraph_edge_hook_list *next;
      86              : };
      87              : 
      88              : /* List of hooks triggered on cgraph_node events.  */
      89              : struct cgraph_node_hook_list {
      90              :   cgraph_node_hook hook;
      91              :   void *data;
      92              :   struct cgraph_node_hook_list *next;
      93              : };
      94              : 
      95              : /* List of hooks triggered on events involving two cgraph_edges.  */
      96              : struct cgraph_2edge_hook_list {
      97              :   cgraph_2edge_hook hook;
      98              :   void *data;
      99              :   struct cgraph_2edge_hook_list *next;
     100              : };
     101              : 
     102              : /* List of hooks triggered on events involving two cgraph_nodes.  */
     103              : struct cgraph_2node_hook_list {
     104              :   cgraph_2node_hook hook;
     105              :   void *data;
     106              :   struct cgraph_2node_hook_list *next;
     107              : };
     108              : 
     109              : /* Hash descriptor for cgraph_function_version_info.  */
     110              : 
     111              : struct function_version_hasher : ggc_ptr_hash<cgraph_function_version_info>
     112              : {
     113              :   static hashval_t hash (cgraph_function_version_info *);
     114              :   static bool equal (cgraph_function_version_info *,
     115              :                      cgraph_function_version_info *);
     116              : };
     117              : 
     118              : /* Map a cgraph_node to cgraph_function_version_info using this htab.
     119              :    The cgraph_function_version_info has a THIS_NODE field that is the
     120              :    corresponding cgraph_node..  */
     121              : 
     122              : static GTY(()) hash_table<function_version_hasher> *cgraph_fnver_htab = NULL;
     123              : 
     124              : /* Hash function for cgraph_fnver_htab.  */
     125              : hashval_t
     126       315210 : function_version_hasher::hash (cgraph_function_version_info *ptr)
     127              : {
     128       315210 :   int uid = ptr->this_node->get_uid ();
     129       315210 :   return (hashval_t)(uid);
     130              : }
     131              : 
     132              : /* eq function for cgraph_fnver_htab.  */
     133              : bool
     134       286340 : function_version_hasher::equal (cgraph_function_version_info *n1,
     135              :                                 cgraph_function_version_info *n2)
     136              : {
     137       286340 :   return n1->this_node->get_uid () == n2->this_node->get_uid ();
     138              : }
     139              : 
     140              : /* Mark as GC root all allocated nodes.  */
     141              : static GTY(()) struct cgraph_function_version_info *
     142              :   version_info_node = NULL;
     143              : 
     144              : /* Return true if NODE's address can be compared.  */
     145              : 
     146              : bool
     147      5064820 : symtab_node::address_can_be_compared_p ()
     148              : {
     149              :   /* Address of virtual tables and functions is never compared.  */
     150      5064820 :   if (DECL_VIRTUAL_P (decl))
     151              :     return false;
     152              :   /* Address of C++ cdtors is never compared.  */
     153      4967377 :   if (is_a <cgraph_node *> (this)
     154       540418 :       && (DECL_CXX_CONSTRUCTOR_P (decl)
     155       537930 :           || DECL_CXX_DESTRUCTOR_P (decl)))
     156              :     return false;
     157              :   /* Constant pool symbols addresses are never compared.
     158              :      flag_merge_constants permits us to assume the same on readonly vars.  */
     159      4963421 :   if (is_a <varpool_node *> (this)
     160      4426959 :       && (DECL_IN_CONSTANT_POOL (decl)
     161      4426956 :           || ((flag_merge_constants >= 2 || DECL_MERGEABLE (decl))
     162         2550 :               && TREE_READONLY (decl) && !TREE_THIS_VOLATILE (decl))))
     163         2546 :     return false;
     164              :   return true;
     165              : }
     166              : 
     167              : /* Get the cgraph_function_version_info node corresponding to node.  */
     168              : cgraph_function_version_info *
     169    141819832 : cgraph_node::function_version (void)
     170              : {
     171    141819832 :   cgraph_function_version_info key;
     172    141819832 :   key.this_node = this;
     173              : 
     174    141819832 :   if (cgraph_fnver_htab == NULL)
     175              :     return NULL;
     176              : 
     177        50509 :   return cgraph_fnver_htab->find (&key);
     178              : }
     179              : 
     180              : /* If profile is IPA, turn it into local one.  */
     181              : void
     182            0 : cgraph_node::make_profile_local ()
     183              : {
     184            0 :   if (!count.ipa ().initialized_p ())
     185              :     return;
     186            0 :   if (!(count == profile_count::zero ()))
     187            0 :     count = count.guessed_local ();
     188            0 :   for (cgraph_edge *e = callees; e; e = e->next_callee)
     189              :     {
     190            0 :       if (!e->inline_failed)
     191            0 :         e->callee->make_profile_local ();
     192            0 :       if (!(e->count == profile_count::zero ()))
     193            0 :         e->count = e->count.guessed_local ();
     194              :     }
     195            0 :   for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
     196            0 :     if (!(e->count == profile_count::zero ()))
     197            0 :       e->count = e->count.guessed_local ();
     198              : }
     199              : 
     200              : /* Turn profile to global0.  Walk into inlined functions.
     201              :    QUALITY must be GUESSED_GLOBAL0, GUESSED_GLOBAL0_ADJUSTED
     202              :    or GUESSED_GLOBAL0_AFDO  */
     203              : void
     204            5 : cgraph_node::make_profile_global0 (profile_quality quality)
     205              : {
     206            5 :   if (count == profile_count::zero ())
     207              :     ;
     208            5 :   else if (quality == GUESSED_GLOBAL0)
     209              :     {
     210            4 :       if (count.quality () == GUESSED_GLOBAL0)
     211              :         return;
     212            4 :       count = count.global0 ();
     213              :     }
     214            1 :   else if (quality == GUESSED_GLOBAL0_ADJUSTED)
     215              :     {
     216            1 :       if (count.quality () == GUESSED_GLOBAL0
     217            1 :           || count.quality () == GUESSED_GLOBAL0_ADJUSTED)
     218              :         return;
     219            1 :       count = count.global0adjusted ();
     220              :     }
     221            0 :   else if (quality == GUESSED_GLOBAL0_AFDO)
     222              :     {
     223            0 :       if (count.quality () == GUESSED_GLOBAL0
     224            0 :           || count.quality () == GUESSED_GLOBAL0_ADJUSTED
     225            0 :           || count.quality () == GUESSED_GLOBAL0_AFDO)
     226              :         return;
     227            0 :       count = count.global0afdo ();
     228              :     }
     229              :   else
     230            0 :     gcc_unreachable ();
     231            8 :   for (cgraph_edge *e = callees; e; e = e->next_callee)
     232              :     {
     233            3 :       if (!e->inline_failed)
     234            0 :         e->callee->make_profile_global0 (quality);
     235            3 :       if (e->count == profile_count::zero ())
     236              :         ;
     237            3 :       else if (quality == GUESSED_GLOBAL0)
     238            1 :         e->count = e->count.global0 ();
     239            2 :       else if (quality == GUESSED_GLOBAL0_ADJUSTED)
     240            2 :         e->count = e->count.global0adjusted ();
     241            0 :       else if (quality == GUESSED_GLOBAL0_AFDO)
     242            0 :         e->count = e->count.global0afdo ();
     243              :       else
     244            0 :         gcc_unreachable ();
     245              :     }
     246            6 :   for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
     247            1 :     if (e->count == profile_count::zero ())
     248              :       ;
     249            1 :     else if (quality == GUESSED_GLOBAL0)
     250            0 :       e->count = e->count.global0 ();
     251            1 :     else if (quality == GUESSED_GLOBAL0_ADJUSTED)
     252            1 :       e->count = e->count.global0adjusted ();
     253            0 :     else if (quality == GUESSED_GLOBAL0_AFDO)
     254            0 :       e->count = e->count.global0afdo ();
     255              :     else
     256            0 :       gcc_unreachable ();
     257              : }
     258              : 
     259              : /* Scale profile by NUM/DEN.  Walk into inlined functions.  */
     260              : 
     261              : void
     262      1705728 : cgraph_node::apply_scale (profile_count num, profile_count den)
     263              : {
     264      1838926 :   if (num == den && !(num == profile_count::zero ()))
     265       131269 :     return;
     266              : 
     267      2974932 :   for (cgraph_edge *e = callees; e; e = e->next_callee)
     268              :     {
     269      1400473 :       if (!e->inline_failed)
     270       187206 :         e->callee->apply_scale (num, den);
     271      1400473 :       e->count = e->count.apply_scale (num, den);
     272              :     }
     273      1601491 :   for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
     274        27032 :     e->count = e->count.apply_scale (num, den);
     275      1574459 :   count = count.apply_scale (num, den);
     276              : }
     277              : 
     278              : /* Scale profile to given IPA_COUNT.
     279              :    IPA_COUNT should pass ipa_p () with a single exception.
     280              :    It can be also GUESSED_LOCAL in case we want to
     281              :    drop any IPA info about the profile.  */
     282              : 
     283              : void
     284           24 : cgraph_node::scale_profile_to (profile_count ipa_count)
     285              : {
     286              :   /* If we do not know the adjustment, it is better to keep profile
     287              :      as it is.  */
     288           24 :   if (!ipa_count.initialized_p ()
     289           24 :       || ipa_count == count)
     290            9 :     return;
     291              :   /* ipa-cp converts value to guessed-local in case it believes
     292              :      that we lost track of IPA profile.  */
     293           20 :   if (ipa_count.quality () == GUESSED_LOCAL)
     294              :     {
     295            0 :       make_profile_local ();
     296            0 :       return;
     297              :     }
     298           20 :   if (ipa_count == profile_count::zero ())
     299              :     {
     300            4 :       make_profile_global0 (GUESSED_GLOBAL0);
     301            4 :       return;
     302              :     }
     303           16 :   if (ipa_count == profile_count::adjusted_zero ())
     304              :     {
     305            1 :       make_profile_global0 (GUESSED_GLOBAL0_ADJUSTED);
     306            1 :       return;
     307              :     }
     308           30 :   gcc_assert (ipa_count.ipa () == ipa_count
     309              :               && !inlined_to);
     310           15 :   profile_count num = count.combine_with_ipa_count (ipa_count);
     311           15 :   profile_count den = count;
     312           15 :   profile_count::adjust_for_ipa_scaling (&num, &den);
     313           15 :   apply_scale (num, den);
     314              : }
     315              : 
     316              : /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
     317              :    corresponding to cgraph_node NODE.  */
     318              : cgraph_function_version_info *
     319         1562 : cgraph_node::insert_new_function_version (void)
     320              : {
     321         1562 :   version_info_node = NULL;
     322         1562 :   version_info_node = ggc_cleared_alloc<cgraph_function_version_info> ();
     323         1562 :   version_info_node->this_node = this;
     324         1562 :   version_info_node->assembler_name = DECL_ASSEMBLER_NAME (this->decl);
     325              : 
     326         1562 :   if (cgraph_fnver_htab == NULL)
     327          203 :     cgraph_fnver_htab = hash_table<function_version_hasher>::create_ggc (2);
     328              : 
     329         1562 :   *cgraph_fnver_htab->find_slot (version_info_node, INSERT)
     330         1562 :     = version_info_node;
     331         1562 :   return version_info_node;
     332              : }
     333              : 
     334              : /* Remove the cgraph_function_version_info node given by DECL_V.  */
     335              : void
     336    109628212 : cgraph_node::delete_function_version (cgraph_function_version_info *decl_v)
     337              : {
     338    109628212 :   if (decl_v == NULL)
     339              :     return;
     340              : 
     341          266 :   if (version_info_node == decl_v)
     342          205 :     version_info_node = NULL;
     343              : 
     344          266 :   if (decl_v->prev != NULL)
     345          159 :     decl_v->prev->next = decl_v->next;
     346              : 
     347          266 :   if (decl_v->next != NULL)
     348          227 :     decl_v->next->prev = decl_v->prev;
     349              : 
     350          266 :   if (cgraph_fnver_htab != NULL)
     351          266 :     cgraph_fnver_htab->remove_elt (decl_v);
     352              : }
     353              : 
     354              : /* Remove the cgraph_function_version_info and cgraph_node for DECL.  This
     355              :    DECL is a duplicate declaration.  */
     356              : void
     357          258 : cgraph_node::delete_function_version_by_decl (tree decl)
     358              : {
     359          258 :   cgraph_node *decl_node = cgraph_node::get (decl);
     360              : 
     361          258 :   if (decl_node == NULL)
     362              :     return;
     363              : 
     364          204 :   delete_function_version (decl_node->function_version ());
     365              : 
     366          204 :   decl_node->remove ();
     367              : }
     368              : 
     369              : /* Add decl to the structure of semantically identical function versions.
     370              :    The node is inserted at the point maintaining the priority ordering on the
     371              :    versions.  */
     372              : void
     373         8982 : cgraph_node::add_function_version (cgraph_function_version_info *fn_v,
     374              :                                    tree decl)
     375              : {
     376         8982 :   cgraph_node *decl_node = cgraph_node::get_create (decl);
     377         8982 :   cgraph_function_version_info *decl_v = NULL;
     378              : 
     379         8982 :   gcc_assert (decl_node != NULL);
     380              : 
     381         8982 :   decl_v = decl_node->function_version ();
     382              : 
     383              :   /* If the nodes are already linked, skip.  */
     384         8982 :   if (decl_v != NULL && (decl_v->next || decl_v->prev))
     385              :     return;
     386              : 
     387          183 :   if (decl_v == NULL)
     388          183 :     decl_v = decl_node->insert_new_function_version ();
     389              : 
     390          183 :   gcc_assert (decl_v);
     391         1080 :   gcc_assert (fn_v);
     392              : 
     393              :   /* Go to start of the FMV structure.  */
     394         5583 :   while (fn_v->prev)
     395              :     fn_v = fn_v->prev;
     396              : 
     397         1080 :   cgraph_function_version_info *insert_point_before = NULL;
     398         1080 :   cgraph_function_version_info *insert_point_after = fn_v;
     399              : 
     400              :   /* Find the insertion point for the new version to maintain ordering.
     401              :      The default node must always go at the beginning.  */
     402         1080 :   if (!is_function_default_version (decl))
     403              :     while (insert_point_after
     404        10175 :            && (targetm.compare_version_priority
     405         4888 :                  (decl, insert_point_after->this_node->decl) > 0
     406          703 :                || is_function_default_version
     407          703 :                     (insert_point_after->this_node->decl)
     408          582 :                || lookup_attribute
     409          582 :                     ("target_clones",
     410          582 :                      DECL_ATTRIBUTES (insert_point_after->this_node->decl))))
     411              :       {
     412         4306 :         insert_point_before = insert_point_after;
     413         4306 :         insert_point_after = insert_point_after->next;
     414              :       }
     415              : 
     416         1080 :   decl_v->prev = insert_point_before;
     417         1080 :   decl_v->next= insert_point_after;
     418              : 
     419         1080 :   if (insert_point_before)
     420          945 :     insert_point_before->next = decl_v;
     421         1080 :   if (insert_point_after)
     422          681 :     insert_point_after->prev = decl_v;
     423              : }
     424              : 
     425              : /* Initialize callgraph dump file.  */
     426              : 
     427              : void
     428       307756 : symbol_table::initialize (void)
     429              : {
     430       307756 :   if (!dump_file)
     431       307754 :     dump_file = dump_begin (TDI_cgraph, NULL);
     432              : 
     433       307756 :   if (!ipa_clones_dump_file)
     434       307756 :     ipa_clones_dump_file = dump_begin (TDI_clones, NULL);
     435       307756 : }
     436              : 
     437              : /* Allocate new callgraph node and insert it into basic data structures.  */
     438              : 
     439              : cgraph_node *
     440    113457912 : symbol_table::create_empty (void)
     441              : {
     442    113457912 :   cgraph_count++;
     443    113457912 :   return new (ggc_alloc<cgraph_node> ()) cgraph_node ();
     444              : }
     445              : 
     446              : /* Register HOOK to be called with DATA on each removed edge.  */
     447              : cgraph_edge_hook_list *
     448      2207190 : symbol_table::add_edge_removal_hook (cgraph_edge_hook hook, void *data)
     449              : {
     450      2207190 :   cgraph_edge_hook_list *entry;
     451      4414380 :   cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
     452              : 
     453      2207190 :   entry = (cgraph_edge_hook_list *) xmalloc (sizeof (*entry));
     454      2207190 :   entry->hook = hook;
     455      2207190 :   entry->data = data;
     456      2207190 :   entry->next = NULL;
     457      8740851 :   while (*ptr)
     458      6533661 :     ptr = &(*ptr)->next;
     459      2207190 :   *ptr = entry;
     460      2207190 :   return entry;
     461              : }
     462              : 
     463              : /* Remove ENTRY from the list of hooks called on removing edges.  */
     464              : void
     465      2206774 : symbol_table::remove_edge_removal_hook (cgraph_edge_hook_list *entry)
     466              : {
     467      2206774 :   cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
     468              : 
     469      6810254 :   while (*ptr != entry)
     470      4603480 :     ptr = &(*ptr)->next;
     471      2206774 :   *ptr = entry->next;
     472      2206774 :   free (entry);
     473      2206774 : }
     474              : 
     475              : /* Call all edge removal hooks.  */
     476              : void
     477     46562799 : symbol_table::call_edge_removal_hooks (cgraph_edge *e)
     478              : {
     479     46562799 :   cgraph_edge_hook_list *entry = m_first_edge_removal_hook;
     480     90744645 :   while (entry)
     481              :   {
     482     44181846 :     entry->hook (e, entry->data);
     483     44181846 :     entry = entry->next;
     484              :   }
     485     46562799 : }
     486              : 
     487              : /* Register HOOK to be called with DATA on each removed node.  */
     488              : cgraph_node_hook_list *
     489      8292829 : symbol_table::add_cgraph_removal_hook (cgraph_node_hook hook, void *data)
     490              : {
     491      8292829 :   cgraph_node_hook_list *entry;
     492     16585658 :   cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
     493              : 
     494      8292829 :   entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
     495      8292829 :   entry->hook = hook;
     496      8292829 :   entry->data = data;
     497      8292829 :   entry->next = NULL;
     498     43353535 :   while (*ptr)
     499     35060706 :     ptr = &(*ptr)->next;
     500      8292829 :   *ptr = entry;
     501      8292829 :   return entry;
     502              : }
     503              : 
     504              : /* Remove ENTRY from the list of hooks called on removing nodes.  */
     505              : void
     506      8180377 : symbol_table::remove_cgraph_removal_hook (cgraph_node_hook_list *entry)
     507              : {
     508      8180377 :   cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
     509              : 
     510     38716911 :   while (*ptr != entry)
     511     30536534 :     ptr = &(*ptr)->next;
     512      8180377 :   *ptr = entry->next;
     513      8180377 :   free (entry);
     514      8180377 : }
     515              : 
     516              : /* Call all node removal hooks.  */
     517              : void
     518    109661298 : symbol_table::call_cgraph_removal_hooks (cgraph_node *node)
     519              : {
     520    109661298 :   cgraph_node_hook_list *entry = m_first_cgraph_removal_hook;
     521    154327559 :   while (entry)
     522              :   {
     523     44666261 :     entry->hook (node, entry->data);
     524     44666261 :     entry = entry->next;
     525              :   }
     526    109661298 : }
     527              : 
     528              : /* Call all node removal hooks.  */
     529              : void
     530       124216 : symbol_table::call_cgraph_insertion_hooks (cgraph_node *node)
     531              : {
     532       124216 :   cgraph_node_hook_list *entry = m_first_cgraph_insertion_hook;
     533       374001 :   while (entry)
     534              :   {
     535       249785 :     entry->hook (node, entry->data);
     536       249785 :     entry = entry->next;
     537              :   }
     538       124216 : }
     539              : 
     540              : 
     541              : /* Register HOOK to be called with DATA on each inserted node.  */
     542              : cgraph_node_hook_list *
     543      8787638 : symbol_table::add_cgraph_insertion_hook (cgraph_node_hook hook, void *data)
     544              : {
     545      8787638 :   cgraph_node_hook_list *entry;
     546     17575276 :   cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
     547              : 
     548      8787638 :   entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
     549      8787638 :   entry->hook = hook;
     550      8787638 :   entry->data = data;
     551      8787638 :   entry->next = NULL;
     552     26044496 :   while (*ptr)
     553     17256858 :     ptr = &(*ptr)->next;
     554      8787638 :   *ptr = entry;
     555      8787638 :   return entry;
     556              : }
     557              : 
     558              : /* Remove ENTRY from the list of hooks called on inserted nodes.  */
     559              : void
     560      8637055 : symbol_table::remove_cgraph_insertion_hook (cgraph_node_hook_list *entry)
     561              : {
     562      8637055 :   cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
     563              : 
     564     23858156 :   while (*ptr != entry)
     565     15221101 :     ptr = &(*ptr)->next;
     566      8637055 :   *ptr = entry->next;
     567      8637055 :   free (entry);
     568      8637055 : }
     569              : 
     570              : /* Register HOOK to be called with DATA on each duplicated edge.  */
     571              : cgraph_2edge_hook_list *
     572      1969910 : symbol_table::add_edge_duplication_hook (cgraph_2edge_hook hook, void *data)
     573              : {
     574      1969910 :   cgraph_2edge_hook_list *entry;
     575      3939820 :   cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
     576              : 
     577      1969910 :   entry = (cgraph_2edge_hook_list *) xmalloc (sizeof (*entry));
     578      1969910 :   entry->hook = hook;
     579      1969910 :   entry->data = data;
     580      1969910 :   entry->next = NULL;
     581      7255989 :   while (*ptr)
     582      5286079 :     ptr = &(*ptr)->next;
     583      1969910 :   *ptr = entry;
     584      1969910 :   return entry;
     585              : }
     586              : 
     587              : /* Remove ENTRY from the list of hooks called on duplicating edges.  */
     588              : void
     589      1969494 : symbol_table::remove_edge_duplication_hook (cgraph_2edge_hook_list *entry)
     590              : {
     591      1969494 :   cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
     592              : 
     593      5325392 :   while (*ptr != entry)
     594      3355898 :     ptr = &(*ptr)->next;
     595      1969494 :   *ptr = entry->next;
     596      1969494 :   free (entry);
     597      1969494 : }
     598              : 
     599              : /* Call all edge duplication hooks.  */
     600              : void
     601      7966958 : symbol_table::call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2)
     602              : {
     603      7966958 :   cgraph_2edge_hook_list *entry = m_first_edge_duplicated_hook;
     604     29983698 :   while (entry)
     605              :   {
     606     22016740 :     entry->hook (cs1, cs2, entry->data);
     607     22016740 :     entry = entry->next;
     608              :   }
     609      7966958 : }
     610              : 
     611              : /* Register HOOK to be called with DATA on each duplicated node.  */
     612              : cgraph_2node_hook_list *
     613      8147932 : symbol_table::add_cgraph_duplication_hook (cgraph_2node_hook hook, void *data)
     614              : {
     615      8147932 :   cgraph_2node_hook_list *entry;
     616     16295864 :   cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
     617              : 
     618      8147932 :   entry = (cgraph_2node_hook_list *) xmalloc (sizeof (*entry));
     619      8147932 :   entry->hook = hook;
     620      8147932 :   entry->data = data;
     621      8147932 :   entry->next = NULL;
     622     40329102 :   while (*ptr)
     623     32181170 :     ptr = &(*ptr)->next;
     624      8147932 :   *ptr = entry;
     625      8147932 :   return entry;
     626              : }
     627              : 
     628              : /* Remove ENTRY from the list of hooks called on duplicating nodes.  */
     629              : void
     630      8049040 : symbol_table::remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry)
     631              : {
     632      8049040 :   cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
     633              : 
     634     36664163 :   while (*ptr != entry)
     635     28615123 :     ptr = &(*ptr)->next;
     636      8049040 :   *ptr = entry->next;
     637      8049040 :   free (entry);
     638      8049040 : }
     639              : 
     640              : /* Call all node duplication hooks.  */
     641              : void
     642      3340697 : symbol_table::call_cgraph_duplication_hooks (cgraph_node *node,
     643              :                                              cgraph_node *node2)
     644              : {
     645      3340697 :   cgraph_2node_hook_list *entry = m_first_cgraph_duplicated_hook;
     646     23759875 :   while (entry)
     647              :   {
     648     20419178 :     entry->hook (node, node2, entry->data);
     649     20419178 :     entry = entry->next;
     650              :   }
     651      3340697 : }
     652              : 
     653              : /* Return cgraph node assigned to DECL.  Create new one when needed.  */
     654              : 
     655              : cgraph_node *
     656    109919483 : cgraph_node::create (tree decl)
     657              : {
     658    109919483 :   cgraph_node *node = symtab->create_empty ();
     659    109919483 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
     660              : 
     661    109919483 :   node->decl = decl;
     662    109919483 :   node->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
     663              : 
     664    109859303 :   if ((flag_openacc || flag_openmp)
     665    110188901 :       && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
     666              :     {
     667         8544 :       node->offloadable = 1;
     668         8544 :       if (ENABLE_OFFLOADING)
     669              :         g->have_offload = true;
     670              :     }
     671              : 
     672    109919483 :   if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
     673          119 :     node->ifunc_resolver = true;
     674              : 
     675    109919483 :   node->register_symbol ();
     676    109919483 :   maybe_record_nested_function (node);
     677              : 
     678    109919483 :   return node;
     679              : }
     680              : 
     681              : /* Try to find a call graph node for declaration DECL and if it does not exist
     682              :    or if it corresponds to an inline clone, create a new one.  */
     683              : 
     684              : cgraph_node *
     685    612593176 : cgraph_node::get_create (tree decl)
     686              : {
     687    612593176 :   cgraph_node *first_clone = cgraph_node::get (decl);
     688              : 
     689    612593176 :   if (first_clone && !first_clone->inlined_to)
     690              :     return first_clone;
     691              : 
     692    109849314 :   cgraph_node *node = cgraph_node::create (decl);
     693    109849314 :   if (first_clone)
     694              :     {
     695            8 :       first_clone->clone_of = node;
     696            8 :       node->clones = first_clone;
     697            8 :       node->order = first_clone->order;
     698            8 :       symtab->symtab_prevail_in_asm_name_hash (node);
     699            8 :       node->decl->decl_with_vis.symtab_node = node;
     700            8 :       if (dump_file && symtab->state != PARSING)
     701            2 :         fprintf (dump_file, "Introduced new external node "
     702              :                  "(%s) and turned into root of the clone tree.\n",
     703              :                  node->dump_name ());
     704              :     }
     705    109849306 :   else if (dump_file && symtab->state != PARSING)
     706         1401 :     fprintf (dump_file, "Introduced new external node "
     707              :              "(%s).\n", node->dump_name ());
     708              :   return node;
     709              : }
     710              : 
     711              : /* Mark ALIAS as an alias to DECL.  DECL_NODE is cgraph node representing
     712              :    the function body is associated with
     713              :    (not necessarily cgraph_node (DECL)).  */
     714              : 
     715              : cgraph_node *
     716      8247075 : cgraph_node::create_alias (tree alias, tree target)
     717              : {
     718      8247075 :   cgraph_node *alias_node;
     719              : 
     720      8247075 :   gcc_assert (TREE_CODE (target) == FUNCTION_DECL
     721              :               || TREE_CODE (target) == IDENTIFIER_NODE);
     722      8247075 :   gcc_assert (TREE_CODE (alias) == FUNCTION_DECL);
     723      8247075 :   alias_node = cgraph_node::get_create (alias);
     724      8247075 :   gcc_assert (!alias_node->definition);
     725      8247075 :   alias_node->alias_target = target;
     726      8247075 :   alias_node->definition = true;
     727      8247075 :   alias_node->alias = true;
     728      8247075 :   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
     729           47 :     alias_node->transparent_alias = alias_node->weakref = true;
     730      8247075 :   if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias)))
     731          321 :     alias_node->ifunc_resolver = true;
     732      8247075 :   return alias_node;
     733              : }
     734              : 
     735              : /* Attempt to mark ALIAS as an alias to DECL.  Return alias node if successful
     736              :    and NULL otherwise.
     737              :    Same body aliases are output whenever the body of DECL is output,
     738              :    and cgraph_node::get (ALIAS) transparently returns
     739              :    cgraph_node::get (DECL).  */
     740              : 
     741              : cgraph_node *
     742      8227368 : cgraph_node::create_same_body_alias (tree alias, tree decl)
     743              : {
     744      8227368 :   cgraph_node *n;
     745              : 
     746              :   /* If aliases aren't supported by the assembler, fail.  */
     747      8227368 :   if (!TARGET_SUPPORTS_ALIASES)
     748              :     return NULL;
     749              : 
     750              :   /* Langhooks can create same body aliases of symbols not defined.
     751              :      Those are useless. Drop them on the floor.  */
     752      8227368 :   if (symtab->global_info_ready)
     753              :     return NULL;
     754              : 
     755      8227368 :   n = cgraph_node::create_alias (alias, decl);
     756      8227368 :   n->cpp_implicit_alias = true;
     757      8227368 :   if (symtab->cpp_implicit_aliases_done)
     758      3787148 :     n->resolve_alias (cgraph_node::get (decl));
     759              :   return n;
     760              : }
     761              : 
     762              : /* Add thunk alias into callgraph.  The alias declaration is ALIAS and it
     763              :    aliases DECL with an adjustments made into the first parameter.
     764              :    See comments in struct cgraph_thunk_info for detail on the parameters.  */
     765              : 
     766              : cgraph_node *
     767         4582 : cgraph_node::create_thunk (tree alias, tree, bool this_adjusting,
     768              :                            HOST_WIDE_INT fixed_offset,
     769              :                            HOST_WIDE_INT virtual_value,
     770              :                            HOST_WIDE_INT indirect_offset,
     771              :                            tree virtual_offset,
     772              :                            tree real_alias)
     773              : {
     774         4582 :   cgraph_node *node;
     775              : 
     776         4582 :   node = cgraph_node::get (alias);
     777         4582 :   if (node)
     778         3856 :     node->reset ();
     779              :   else
     780          726 :     node = cgraph_node::create (alias);
     781              : 
     782              :   /* Make sure that if VIRTUAL_OFFSET is in sync with VIRTUAL_VALUE.  */
     783         4582 :   gcc_checking_assert (virtual_offset
     784              :                        ? virtual_value == wi::to_wide (virtual_offset)
     785              :                        : virtual_value == 0);
     786              : 
     787         4582 :   node->thunk = true;
     788         4582 :   node->definition = true;
     789              : 
     790         4582 :   thunk_info *i;
     791         4582 :   thunk_info local_info;
     792         4582 :   if (symtab->state < CONSTRUCTION)
     793              :     i = &local_info;
     794              :   else
     795            0 :     i = thunk_info::get_create (node);
     796         4582 :   i->fixed_offset = fixed_offset;
     797         4582 :   i->virtual_value = virtual_value;
     798         4582 :   i->indirect_offset = indirect_offset;
     799         4582 :   i->alias = real_alias;
     800         4582 :   i->this_adjusting = this_adjusting;
     801         4582 :   i->virtual_offset_p = virtual_offset != NULL;
     802         4582 :   if (symtab->state < CONSTRUCTION)
     803         4582 :     i->register_early (node);
     804              : 
     805         4582 :   return node;
     806              : }
     807              : 
     808              : /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
     809              :    Return NULL if there's no such node.  */
     810              : 
     811              : cgraph_node *
     812            0 : cgraph_node::get_for_asmname (tree asmname)
     813              : {
     814              :   /* We do not want to look at inline clones.  */
     815            0 :   for (symtab_node *node = symtab_node::get_for_asmname (asmname);
     816            0 :        node;
     817            0 :        node = node->next_sharing_asm_name)
     818              :     {
     819            0 :       cgraph_node *cn = dyn_cast <cgraph_node *> (node);
     820            0 :       if (cn && !cn->inlined_to)
     821              :         return cn;
     822              :     }
     823              :   return NULL;
     824              : }
     825              : 
     826              : /* Returns a hash value for X (which really is a cgraph_edge).  */
     827              : 
     828              : hashval_t
     829    237965929 : cgraph_edge_hasher::hash (cgraph_edge *e)
     830              : {
     831              :   /* This is a really poor hash function, but it is what htab_hash_pointer
     832              :      uses.  */
     833    237965929 :   return (hashval_t) ((intptr_t)e->call_stmt >> 3);
     834              : }
     835              : 
     836              : /* Returns a hash value for X (which really is a cgraph_edge).  */
     837              : 
     838              : hashval_t
     839     47242063 : cgraph_edge_hasher::hash (gimple *call_stmt)
     840              : {
     841              :   /* This is a really poor hash function, but it is what htab_hash_pointer
     842              :      uses.  */
     843     47242063 :   return (hashval_t) ((intptr_t)call_stmt >> 3);
     844              : }
     845              : 
     846              : /* Return nonzero if the call_stmt of cgraph_edge X is stmt *Y.  */
     847              : 
     848              : inline bool
     849    291195999 : cgraph_edge_hasher::equal (cgraph_edge *x, gimple *y)
     850              : {
     851    291195999 :   return x->call_stmt == y;
     852              : }
     853              : 
     854              : /* Add call graph edge E to call site hash of its caller.  */
     855              : 
     856              : static inline void
     857         5649 : cgraph_update_edge_in_call_site_hash (cgraph_edge *e)
     858              : {
     859         5649 :   gimple *call = e->call_stmt;
     860         5649 :   *e->caller->call_site_hash->find_slot_with_hash
     861         5649 :       (call, cgraph_edge_hasher::hash (call), INSERT) = e;
     862         5649 : }
     863              : 
     864              : /* Add call graph edge E to call site hash of its caller.  */
     865              : 
     866              : static inline void
     867      8907943 : cgraph_add_edge_to_call_site_hash (cgraph_edge *e)
     868              : {
     869              :   /* There are two speculative edges for every statement (one direct,
     870              :      one indirect); always hash the direct one.  */
     871      8907943 :   if (e->speculative && e->indirect_unknown_callee)
     872              :     return;
     873              :   /* We always want to hash the carrying edge of a callback, not the edges
     874              :      pointing to the callbacks themselves, as their call statement doesn't
     875              :      exist.  */
     876      8907925 :   if (e->callback)
     877              :     return;
     878      8907915 :   cgraph_edge **slot = e->caller->call_site_hash->find_slot_with_hash
     879      8907915 :       (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt), INSERT);
     880      8907915 :   if (*slot)
     881              :     {
     882         5723 :       cgraph_edge *edge = (cgraph_edge *) *slot;
     883         5723 :       gcc_assert (edge->speculative || edge->has_callback);
     884         5723 :       if (edge->has_callback)
     885              :         /* If the slot is already occupied, then the hashed edge is the
     886              :            callback-carrying edge, which is desired behavior.  In some cases,
     887              :            the callback flag of E is not set yet and so the early exit above is
     888              :            not taken.  */
     889              :         return;
     890         5631 :       if (e->callee && (!e->prev_callee
     891            4 :                         || !e->prev_callee->speculative
     892            4 :                         || e->prev_callee->call_stmt != e->call_stmt))
     893         1033 :         *slot = e;
     894              :       return;
     895              :     }
     896      8902192 :   gcc_assert (!*slot || e->speculative);
     897      8902192 :   *slot = e;
     898              : }
     899              : 
     900              : /* Return the callgraph edge representing the GIMPLE_CALL statement
     901              :    CALL_STMT.  */
     902              : 
     903              : cgraph_edge *
     904    216863241 : cgraph_node::get_edge (gimple *call_stmt)
     905              : {
     906    216863241 :   cgraph_edge *e, *e2;
     907    216863241 :   int n = 0;
     908              : 
     909    216863241 :   if (call_site_hash)
     910     37008417 :     return call_site_hash->find_with_hash
     911     37008417 :         (call_stmt, cgraph_edge_hasher::hash (call_stmt));
     912              : 
     913              :   /* This loop may turn out to be performance problem.  In such case adding
     914              :      hashtables into call nodes with very many edges is probably best
     915              :      solution.  It is not good idea to add pointer into CALL_EXPR itself
     916              :      because we want to make possible having multiple cgraph nodes representing
     917              :      different clones of the same body before the body is actually cloned.  */
     918   1743414417 :   for (e = callees; e; e = e->next_callee)
     919              :     {
     920   1694136488 :       if (e->call_stmt == call_stmt)
     921              :         break;
     922   1563559593 :       n++;
     923              :     }
     924              : 
     925    179854824 :   if (!e)
     926     63097083 :     for (e = indirect_calls; e; e = e->next_callee)
     927              :       {
     928     16666544 :         if (e->call_stmt == call_stmt)
     929              :           break;
     930     13819154 :         n++;
     931              :       }
     932              : 
     933              :   /* We want to work with the callback-carrying edge whenever possible.  When it
     934              :      comes to callback edges, a call statement might have multiple callback
     935              :      edges attached to it.  These can be easily obtained from the carrying edge
     936              :      instead.  */
     937    179854824 :   if (e && e->callback)
     938        54458 :     e = e->get_callback_carrying_edge ();
     939              : 
     940    179854824 :   if (n > 100)
     941              :     {
     942        32056 :       call_site_hash = hash_table<cgraph_edge_hasher>::create_ggc (120);
     943      3287079 :       for (e2 = callees; e2; e2 = e2->next_callee)
     944      3255023 :         cgraph_add_edge_to_call_site_hash (e2);
     945       118989 :       for (e2 = indirect_calls; e2; e2 = e2->next_callee)
     946        86933 :         cgraph_add_edge_to_call_site_hash (e2);
     947              :     }
     948              : 
     949              :   return e;
     950              : }
     951              : 
     952              : /* Change field call_stmt of edge E to NEW_STMT.  If UPDATE_DERIVED_EDGES and E
     953              :    is any component of speculative edge, then update all components.
     954              :    speculations can be resolved in the process and edge can be removed and
     955              :    deallocated.  if update_derived_edges and e is a part of a callback pair,
     956              :    update all associated edges and return their carrying edge.  return the edge
     957              :    that now represents the call.  */
     958              : 
     959              : cgraph_edge *
     960      3149681 : cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
     961              :                             bool update_derived_edges)
     962              : {
     963      3150411 :   tree decl;
     964              : 
     965      3150411 :   cgraph_node *new_direct_callee = NULL;
     966      3121460 :   if ((e->indirect_unknown_callee || e->speculative)
     967      3194642 :       && (decl = gimple_call_fndecl (new_stmt)))
     968              :     {
     969              :       /* Constant propagation and especially inlining can turn an indirect call
     970              :          into a direct one.  */
     971            0 :       new_direct_callee = cgraph_node::get (decl);
     972            0 :       gcc_checking_assert (new_direct_callee);
     973              :     }
     974              : 
     975              :   /* Speculative edges has three component, update all of them
     976              :      when asked to.  */
     977      3150411 :   if (update_derived_edges && e->speculative
     978              :       /* If we are about to resolve the speculation by calling make_direct
     979              :          below, do not bother going over all the speculative edges now.  */
     980         6651 :       && !new_direct_callee)
     981              :     {
     982         6651 :       cgraph_edge *direct, *indirect, *next;
     983         6651 :       ipa_ref *ref;
     984         6651 :       bool e_indirect = e->indirect_unknown_callee;
     985         6651 :       int n = 0;
     986              : 
     987         6651 :       direct = e->first_speculative_call_target ();
     988         6651 :       indirect = e->speculative_call_indirect_edge ();
     989              : 
     990         6651 :       gcall *old_stmt = direct->call_stmt;
     991        15280 :       for (cgraph_edge *d = direct; d; d = next)
     992              :         {
     993         8629 :           next = d->next_speculative_call_target ();
     994         8629 :           cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
     995         8629 :           gcc_assert (d2 == d);
     996         8629 :           n++;
     997              :         }
     998         6651 :       gcc_checking_assert (indirect->num_speculative_call_targets_p () == n);
     999        20302 :       for (unsigned int i = 0; e->caller->iterate_reference (i, ref); i++)
    1000        13651 :         if (ref->speculative && ref->stmt == old_stmt)
    1001              :           {
    1002         8629 :             ref->stmt = new_stmt;
    1003         8629 :             n--;
    1004              :           }
    1005              : 
    1006         6651 :       indirect = set_call_stmt (indirect, new_stmt, false);
    1007         6651 :       return e_indirect ? indirect : direct;
    1008              :     }
    1009              : 
    1010      3143760 :   if (new_direct_callee)
    1011            0 :     e = make_direct (e, new_direct_callee);
    1012              : 
    1013              :   /* When updating a callback or a callback-carrying edge, update every edge
    1014              :      involved.  */
    1015      3143760 :   if (update_derived_edges && (e->callback || e->has_callback))
    1016              :     {
    1017          730 :       cgraph_edge *current, *next, *carrying;
    1018          730 :       carrying = e->has_callback ? e : e->get_callback_carrying_edge ();
    1019              : 
    1020          730 :       current = e->first_callback_edge ();
    1021          730 :       if (current)
    1022              :         {
    1023           95 :           for (cgraph_edge *d = current; d; d = next)
    1024              :             {
    1025           48 :               next = d->next_callback_edge ();
    1026           48 :               cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
    1027           48 :               gcc_assert (d2 == d);
    1028              :             }
    1029              :         }
    1030          730 :       carrying = set_call_stmt (carrying, new_stmt, false);
    1031          730 :       return carrying;
    1032              :     }
    1033              : 
    1034              :   /* Only direct speculative edges go to call_site_hash.  */
    1035      3143030 :   if (e->caller->call_site_hash
    1036       629693 :       && (!e->speculative || !e->indirect_unknown_callee)
    1037              :       /* It is possible that edge was previously speculative.  In this case
    1038              :          we have different value in call stmt hash which needs preserving.  */
    1039      3772723 :       && e->caller->get_edge (e->call_stmt) == e)
    1040       624044 :     e->caller->call_site_hash->remove_elt_with_hash
    1041       624044 :       (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt));
    1042              : 
    1043      3143030 :   e->call_stmt = new_stmt;
    1044              : 
    1045      3143030 :   function *fun = DECL_STRUCT_FUNCTION (e->caller->decl);
    1046      3143030 :   e->can_throw_external = stmt_can_throw_external (fun, new_stmt);
    1047              :   /* Update call stite hash.  For speculative calls we only record the first
    1048              :      direct edge.  */
    1049      3143030 :   if (e->caller->call_site_hash
    1050       629693 :       && (!e->speculative
    1051            0 :           || (e->callee
    1052            0 :               && (!e->prev_callee || !e->prev_callee->speculative
    1053            0 :                   || e->prev_callee->call_stmt != e->call_stmt))
    1054            0 :           || (e->speculative && !e->callee)))
    1055       629693 :     cgraph_add_edge_to_call_site_hash (e);
    1056              :   return e;
    1057              : }
    1058              : 
    1059              : /* Allocate a cgraph_edge structure and fill it with data according to the
    1060              :    parameters of which only CALLEE can be NULL (when creating an indirect call
    1061              :    edge).  CLONING_P should be set if properties that are copied from an
    1062              :    original edge should not be calculated.  */
    1063              : 
    1064              : cgraph_edge *
    1065     47002772 : symbol_table::create_edge (cgraph_node *caller, cgraph_node *callee,
    1066              :                            gcall *call_stmt, profile_count count,
    1067              :                            bool indir_unknown_callee, bool cloning_p)
    1068              : {
    1069     47002772 :   cgraph_edge *edge;
    1070              : 
    1071              :   /* LTO does not actually have access to the call_stmt since these
    1072              :      have not been loaded yet.  */
    1073     47002772 :   if (call_stmt)
    1074              :     {
    1075              :       /* This is a rather expensive check possibly triggering
    1076              :          construction of call stmt hashtable.  */
    1077     46140723 :       cgraph_edge *e;
    1078     46140723 :       gcc_checking_assert (!(e = caller->get_edge (call_stmt))
    1079              :                            || e->speculative || e->has_callback || e->callback);
    1080              : 
    1081     46140723 :       gcc_assert (is_gimple_call (call_stmt));
    1082              :     }
    1083              : 
    1084     47002772 :   edge = ggc_alloc<cgraph_edge> ();
    1085     47002772 :   edge->m_summary_id = -1;
    1086     47002772 :   edges_count++;
    1087              : 
    1088     47002772 :   ++edges_max_uid;
    1089     47002772 :   gcc_assert (edges_max_uid != 0);
    1090     47002772 :   edge->m_uid = edges_max_uid;
    1091     47002772 :   edge->aux = NULL;
    1092     47002772 :   edge->caller = caller;
    1093     47002772 :   edge->callee = callee;
    1094     47002772 :   edge->prev_caller = NULL;
    1095     47002772 :   edge->next_caller = NULL;
    1096     47002772 :   edge->prev_callee = NULL;
    1097     47002772 :   edge->next_callee = NULL;
    1098     47002772 :   edge->lto_stmt_uid = 0;
    1099     47002772 :   edge->speculative_id = 0;
    1100              : 
    1101     47002772 :   edge->count = count;
    1102     47002772 :   edge->call_stmt = call_stmt;
    1103     47002772 :   edge->indirect_info = NULL;
    1104     47002772 :   edge->indirect_inlining_edge = 0;
    1105     47002772 :   edge->speculative = false;
    1106     47002772 :   edge->has_callback = false;
    1107     47002772 :   edge->callback = false;
    1108     47002772 :   edge->indirect_unknown_callee = indir_unknown_callee;
    1109     47002772 :   if (call_stmt && caller->call_site_hash)
    1110      4936294 :     cgraph_add_edge_to_call_site_hash (edge);
    1111              : 
    1112     47002772 :   if (cloning_p)
    1113              :     return edge;
    1114              : 
    1115     39064002 :   edge->can_throw_external
    1116     39064002 :     = call_stmt ? stmt_can_throw_external (DECL_STRUCT_FUNCTION (caller->decl),
    1117              :                                            call_stmt) : false;
    1118     39064002 :   edge->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
    1119     39064002 :   edge->call_stmt_cannot_inline_p = false;
    1120              : 
    1121     39064002 :   if (opt_for_fn (edge->caller->decl, flag_devirtualize)
    1122     39064002 :       && call_stmt && DECL_STRUCT_FUNCTION (caller->decl))
    1123     30751077 :     edge->in_polymorphic_cdtor
    1124     30751077 :       = decl_maybe_in_construction_p (NULL, NULL, call_stmt,
    1125              :                                       caller->decl);
    1126              :   else
    1127      8312925 :     edge->in_polymorphic_cdtor = caller->thunk;
    1128              : 
    1129     38391413 :   if (callee && symtab->state != LTO_STREAMING
    1130     76855437 :       && edge->callee->comdat_local_p ())
    1131         7092 :     edge->caller->calls_comdat_local = true;
    1132              : 
    1133              :   return edge;
    1134              : }
    1135              : 
    1136              : /* Create edge from a given function to CALLEE in the cgraph.  CLONING_P should
    1137              :    be set if properties that are copied from an original edge should not be
    1138              :    calculated.  */
    1139              : 
    1140              : cgraph_edge *
    1141     46157058 : cgraph_node::create_edge (cgraph_node *callee,
    1142              :                           gcall *call_stmt, profile_count count, bool cloning_p)
    1143              : {
    1144     46157058 :   cgraph_edge *edge = symtab->create_edge (this, callee, call_stmt, count,
    1145              :                                            false, cloning_p);
    1146              : 
    1147     46157058 :   if (!cloning_p)
    1148     38391413 :     initialize_inline_failed (edge);
    1149              : 
    1150     46157058 :   edge->next_caller = callee->callers;
    1151     46157058 :   if (callee->callers)
    1152     36001795 :     callee->callers->prev_caller = edge;
    1153     46157058 :   edge->next_callee = callees;
    1154     46157058 :   if (callees)
    1155     35671059 :     callees->prev_callee = edge;
    1156     46157058 :   callees = edge;
    1157     46157058 :   callee->callers = edge;
    1158              : 
    1159     46157058 :   return edge;
    1160              : }
    1161              : 
    1162              : /* Create an indirect edge to a (yet-)undetermined callee.  CALL_STMT is the
    1163              :    corresponding statement, if available, ECF_FLAGS and COUNT are corresponding
    1164              :    gimple call flags and profiling count respectively.  CLONING_P should be set
    1165              :    if properties that are copied from an original edge should not be
    1166              :    calculated.  */
    1167              : 
    1168              : cgraph_edge *
    1169       845714 : cgraph_node::create_indirect_edge (gcall *call_stmt, int ecf_flags,
    1170              :                                    profile_count count, bool cloning_p)
    1171              : {
    1172       845714 :   cgraph_edge *edge = symtab->create_edge (this, NULL, call_stmt, count, true,
    1173              :                                            cloning_p);
    1174              : 
    1175       845714 :   if (!cloning_p)
    1176              :     {
    1177       672589 :       initialize_inline_failed (edge);
    1178              : 
    1179       672589 :       tree target = NULL_TREE;
    1180       672589 :       if (call_stmt)
    1181       672589 :         target = gimple_call_fn (call_stmt);
    1182       672589 :       if (target && virtual_method_call_p (target))
    1183              :         {
    1184        95016 :           ipa_polymorphic_call_context context (decl, target, call_stmt);
    1185        95016 :           HOST_WIDE_INT token = tree_to_shwi (OBJ_TYPE_REF_TOKEN (target));
    1186        95016 :           tree type = obj_type_ref_class (target);
    1187        95016 :           edge->indirect_info
    1188        95016 :             = (new (ggc_alloc<cgraph_polymorphic_indirect_info> ())
    1189              :                cgraph_polymorphic_indirect_info (ecf_flags, context, token,
    1190        95016 :                                                  type));
    1191              :         }
    1192       577573 :       else if (target && TREE_CODE (target) == SSA_NAME)
    1193       570548 :         edge->indirect_info
    1194       570548 :           = (new (ggc_alloc<cgraph_simple_indirect_info> ())
    1195       570548 :              cgraph_simple_indirect_info (ecf_flags));
    1196              :       else
    1197         7025 :         edge->indirect_info
    1198         7025 :           = (new (ggc_alloc<cgraph_indirect_call_info> ())
    1199         7025 :              cgraph_indirect_call_info(CIIK_UNSPECIFIED, ecf_flags));
    1200              :     }
    1201              : 
    1202       845714 :   edge->next_callee = indirect_calls;
    1203       845714 :   if (indirect_calls)
    1204       408393 :     indirect_calls->prev_callee = edge;
    1205       845714 :   indirect_calls = edge;
    1206              : 
    1207       845714 :   return edge;
    1208              : }
    1209              : 
    1210              : /* Remove the edge from the list of the callees of the caller.  */
    1211              : 
    1212              : void
    1213      4853007 : cgraph_edge::remove_caller (void)
    1214              : {
    1215      4853007 :   if (prev_callee)
    1216      3991578 :     prev_callee->next_callee = next_callee;
    1217      4853007 :   if (next_callee)
    1218      3332005 :     next_callee->prev_callee = prev_callee;
    1219      4853007 :   if (!prev_callee)
    1220              :     {
    1221       861429 :       if (indirect_unknown_callee)
    1222         1248 :         caller->indirect_calls = next_callee;
    1223              :       else
    1224       860181 :         caller->callees = next_callee;
    1225              :     }
    1226      4853007 :   if (caller->call_site_hash
    1227      4853007 :       && this == caller->get_edge (call_stmt))
    1228       696038 :     caller->call_site_hash->remove_elt_with_hash
    1229       696038 :         (call_stmt, cgraph_edge_hasher::hash (call_stmt));
    1230      4853007 : }
    1231              : 
    1232              : /* Put the edge onto the free list.  */
    1233              : 
    1234              : void
    1235     46562799 : symbol_table::free_edge (cgraph_edge *e)
    1236              : {
    1237     46562799 :   edges_count--;
    1238     46562799 :   if (e->m_summary_id != -1)
    1239     21982204 :     edge_released_summary_ids.safe_push (e->m_summary_id);
    1240              : 
    1241     46562799 :   if (e->indirect_info)
    1242       838103 :     ggc_free (e->indirect_info);
    1243     46562799 :   ggc_free (e);
    1244     46562799 : }
    1245              : 
    1246              : /* Remove the edge in the cgraph.  */
    1247              : 
    1248              : void
    1249       118917 : cgraph_edge::remove (cgraph_edge *edge)
    1250              : {
    1251              :   /* Call all edge removal hooks.  */
    1252       118917 :   symtab->call_edge_removal_hooks (edge);
    1253              : 
    1254       118917 :   if (!edge->indirect_unknown_callee)
    1255              :     /* Remove from callers list of the callee.  */
    1256       116278 :     edge->remove_callee ();
    1257              : 
    1258              :   /* Remove from callees list of the callers.  */
    1259       118917 :   edge->remove_caller ();
    1260              : 
    1261              :   /* Put the edge onto the free list.  */
    1262       118917 :   symtab->free_edge (edge);
    1263       118917 : }
    1264              : 
    1265              : /* Returns the next speculative_id based on currently in use
    1266              :    for the given statement for the edge.
    1267              :    Returns 0 if no speculative edges exist for this statement. */
    1268              : 
    1269              : int
    1270        17124 : cgraph_edge::get_next_speculative_id ()
    1271              : {
    1272        17124 :   int max_id = -1;
    1273              : 
    1274              :   /* If this edge is not yet speculative, there are no existing speculative
    1275              :      edges for this call site, so return 0.  */
    1276        17124 :   if (!speculative)
    1277              :     return 0;
    1278              : 
    1279              :   /* Iterate only through speculative edges for this specific call site.  */
    1280            0 :   for (cgraph_edge *e = first_speculative_call_target ();
    1281            0 :        e;
    1282            0 :        e = e->next_speculative_call_target ())
    1283              :     {
    1284            0 :       if (e->speculative_id > max_id)
    1285              :         max_id = e->speculative_id;
    1286              :     }
    1287              : 
    1288            0 :   return max_id + 1;
    1289              : }
    1290              : 
    1291              : 
    1292              : /* Turn edge into speculative call calling N2. Update
    1293              :    the profile so the direct call is taken COUNT times
    1294              :    with FREQUENCY.
    1295              : 
    1296              :    At clone materialization time, the indirect call E will
    1297              :    be expanded as:
    1298              : 
    1299              :    if (call_dest == N2)
    1300              :      n2 ();
    1301              :    else
    1302              :      call call_dest
    1303              : 
    1304              :    At this time the function just creates the direct call,
    1305              :    the reference representing the if conditional and attaches
    1306              :    them all to the original indirect call statement.
    1307              : 
    1308              :    speculative_id is used to link direct calls with their corresponding
    1309              :    IPA_REF_ADDR references when representing speculative calls.
    1310              : 
    1311              :    Return direct edge created.  */
    1312              : 
    1313              : cgraph_edge *
    1314        15450 : cgraph_edge::make_speculative (cgraph_node *n2, profile_count direct_count,
    1315              :                                unsigned int speculative_id)
    1316              : {
    1317        15450 :   cgraph_node *n = caller;
    1318        15450 :   ipa_ref *ref = NULL;
    1319        15450 :   cgraph_edge *e2;
    1320              : 
    1321        15450 :   if (dump_file)
    1322           29 :     fprintf (dump_file, "Indirect call -> speculative call %s => %s\n",
    1323              :              n->dump_name (), n2->dump_name ());
    1324        15450 :   speculative = true;
    1325        15450 :   e2 = n->create_edge (n2, call_stmt, direct_count);
    1326        15450 :   initialize_inline_failed (e2);
    1327        15450 :   e2->speculative = true;
    1328        15450 :   if (TREE_NOTHROW (n2->decl))
    1329              :     e2->can_throw_external = false;
    1330              :   else
    1331         5268 :     e2->can_throw_external = can_throw_external;
    1332        15450 :   e2->lto_stmt_uid = lto_stmt_uid;
    1333        15450 :   e2->speculative_id = speculative_id;
    1334        15450 :   e2->in_polymorphic_cdtor = in_polymorphic_cdtor;
    1335        15450 :   indirect_info->num_speculative_call_targets++;
    1336        15450 :   count -= e2->count;
    1337        15450 :   symtab->call_edge_duplication_hooks (this, e2);
    1338        15450 :   ref = n->create_reference (n2, IPA_REF_ADDR, call_stmt);
    1339        15450 :   ref->lto_stmt_uid = lto_stmt_uid;
    1340        15450 :   ref->speculative_id = speculative_id;
    1341        15450 :   ref->speculative = speculative;
    1342        15450 :   n2->mark_address_taken ();
    1343        15450 :   return e2;
    1344              : }
    1345              : 
    1346              : /* Create a callback edge calling N2.  Callback edges
    1347              :    never get turned into actual calls, they are just used
    1348              :    as clues and allow for optimizing functions which do not
    1349              :    have any callsites during compile time, e.g. functions
    1350              :    passed to standard library functions.
    1351              : 
    1352              :    The edge will be attached to the same call statement as
    1353              :    the callback-carrying edge, which is the instance this method
    1354              :    is called on.
    1355              : 
    1356              :    FN_IDX is the index of the callback function in dispatching function's
    1357              :    argument list.  ATTR is the attribute used to derive the edge.
    1358              : 
    1359              :    Return the resulting callback edge.  */
    1360              : 
    1361              : cgraph_edge *
    1362        15129 : cgraph_edge::make_callback (cgraph_node *n2, unsigned fn_idx, tree attr)
    1363              : {
    1364        15129 :   cgraph_node *n = caller;
    1365        15129 :   cgraph_edge *e2;
    1366              : 
    1367        15129 :   has_callback = true;
    1368        15129 :   e2 = n->create_edge (n2, call_stmt, count);
    1369        15129 :   if (dump_file)
    1370            5 :     fprintf (
    1371              :       dump_file,
    1372              :       "Created callback edge %s -> %s belonging to carrying edge %s -> %s\n",
    1373            5 :       e2->caller->dump_name (), e2->callee->dump_name (), caller->dump_name (),
    1374            5 :       callee->dump_name ());
    1375        15129 :   e2->inline_failed = CIF_CALLBACK_EDGE;
    1376        15129 :   e2->callback = true;
    1377        15129 :   if (TREE_NOTHROW (n2->decl))
    1378              :     e2->can_throw_external = false;
    1379              :   else
    1380          251 :     e2->can_throw_external = can_throw_external;
    1381        15129 :   e2->lto_stmt_uid = lto_stmt_uid;
    1382        15129 :   callback_info *ci = callback_info_sum->get_create (e2);
    1383        15129 :   ci->init (fn_idx, attr);
    1384        15129 :   symtab->call_edge_duplication_hooks (this, e2);
    1385        15129 :   n2->mark_address_taken ();
    1386        15129 :   return e2;
    1387              : }
    1388              : 
    1389              : /* Returns the callback_carrying edge of a callback edge on which
    1390              :    it is called on or NULL when no such edge can be found.
    1391              : 
    1392              :    An edge is taken to be the callback-carrying if it has it's has_callback
    1393              :    flag set and the edges share their call statements.  */
    1394              : 
    1395              : cgraph_edge *
    1396        80918 : cgraph_edge::get_callback_carrying_edge ()
    1397              : {
    1398        80918 :   gcc_checking_assert (callback);
    1399        80918 :   cgraph_edge *e;
    1400       630883 :   for (e = caller->callees; e; e = e->next_callee)
    1401              :     {
    1402       630711 :       if (e->has_callback && e->call_stmt == call_stmt
    1403        80746 :           && e->lto_stmt_uid == lto_stmt_uid)
    1404              :         break;
    1405              :     }
    1406        80918 :   return e;
    1407              : }
    1408              : 
    1409              : /* Returns the first callback edge in the list of callees of the caller node.
    1410              :    Note that the edges might be in arbitrary order.  Must be called on a
    1411              :    callback or callback-carrying edge.  */
    1412              : 
    1413              : cgraph_edge *
    1414        48187 : cgraph_edge::first_callback_edge ()
    1415              : {
    1416        48187 :   gcc_checking_assert (has_callback || callback);
    1417        48187 :   cgraph_edge *e = NULL;
    1418       223816 :   for (e = caller->callees; e; e = e->next_callee)
    1419              :     {
    1420       206787 :       if (e->callback && e->call_stmt == call_stmt
    1421        31158 :           && e->lto_stmt_uid == lto_stmt_uid)
    1422              :         break;
    1423              :     }
    1424        48187 :   return e;
    1425              : }
    1426              : 
    1427              : /* Given a callback edge, returns the next callback edge belonging to the same
    1428              :    carrying edge.  Must be called on a callback edge, not the callback-carrying
    1429              :    edge.  */
    1430              : 
    1431              : cgraph_edge *
    1432        31166 : cgraph_edge::next_callback_edge ()
    1433              : {
    1434        31166 :   gcc_checking_assert (callback);
    1435        31166 :   cgraph_edge *e = NULL;
    1436       307795 :   for (e = next_callee; e; e = e->next_callee)
    1437              :     {
    1438       276637 :       if (e->callback && e->call_stmt == call_stmt
    1439            8 :           && e->lto_stmt_uid == lto_stmt_uid)
    1440              :         break;
    1441              :     }
    1442        31166 :   return e;
    1443              : }
    1444              : 
    1445              : /* When called on a callback-carrying edge, removes all of its attached callback
    1446              :    edges and sets has_callback to FALSE.  */
    1447              : 
    1448              : void
    1449            2 : cgraph_edge::purge_callback_edges ()
    1450              : {
    1451            2 :   gcc_checking_assert (has_callback);
    1452            2 :   cgraph_edge *e, *next;
    1453            4 :   for (e = first_callback_edge (); e; e = next)
    1454              :     {
    1455            2 :       next = e->next_callback_edge ();
    1456            2 :       cgraph_edge::remove (e);
    1457              :     }
    1458            2 :   has_callback = false;
    1459            2 : }
    1460              : 
    1461              : /* Speculative call consists of an indirect edge and one or more
    1462              :    direct edge+ref pairs.
    1463              : 
    1464              :    Given an edge which is part of speculative call, return the first
    1465              :    direct call edge in the speculative call sequence.  */
    1466              : 
    1467              : cgraph_edge *
    1468        51603 : cgraph_edge::first_speculative_call_target ()
    1469              : {
    1470        51603 :   cgraph_edge *e = this;
    1471              : 
    1472        51603 :   gcc_checking_assert (e->speculative);
    1473        51603 :   if (e->callee)
    1474              :     {
    1475        14193 :       while (e->prev_callee && e->prev_callee->speculative
    1476         1135 :              && e->prev_callee->call_stmt == e->call_stmt
    1477        42067 :              && e->prev_callee->lto_stmt_uid == e->lto_stmt_uid)
    1478              :         e = e->prev_callee;
    1479              :       return e;
    1480              :     }
    1481              :   /* Call stmt site hash always points to the first target of the
    1482              :      speculative call sequence.  */
    1483         9536 :   if (e->call_stmt)
    1484         9495 :     return e->caller->get_edge (e->call_stmt);
    1485           57 :   for (cgraph_edge *e2 = e->caller->callees; true; e2 = e2->next_callee)
    1486           57 :     if (e2->speculative
    1487           47 :         && e->call_stmt == e2->call_stmt
    1488           47 :         && e->lto_stmt_uid == e2->lto_stmt_uid)
    1489              :       return e2;
    1490              : }
    1491              : 
    1492              : /* We always maintain first direct edge in the call site hash, if one
    1493              :    exists.  E is going to be removed.  See if it is first one and update
    1494              :    hash accordingly.  INDIRECT is the indirect edge of speculative call.
    1495              :    We assume that INDIRECT->num_speculative_call_targets_p () is already
    1496              :    updated for removal of E.  */
    1497              : static void
    1498        41187 : update_call_stmt_hash_for_removing_direct_edge (cgraph_edge *e,
    1499              :                                                 cgraph_edge *indirect)
    1500              : {
    1501        41187 :   if (e->caller->call_site_hash)
    1502              :     {
    1503         5649 :       if (e->caller->get_edge (e->call_stmt) != e)
    1504              :         ;
    1505         5649 :       else if (!indirect->num_speculative_call_targets_p ())
    1506         4841 :         cgraph_update_edge_in_call_site_hash (indirect);
    1507              :       else
    1508              :         {
    1509          808 :           gcc_checking_assert (e->next_callee && e->next_callee->speculative
    1510              :                                && e->next_callee->call_stmt == e->call_stmt);
    1511          808 :           cgraph_update_edge_in_call_site_hash (e->next_callee);
    1512              :         }
    1513              :     }
    1514        41187 : }
    1515              : 
    1516              : /* Speculative call EDGE turned out to be direct call to CALLEE_DECL.  Remove
    1517              :    the speculative call sequence and return edge representing the call, the
    1518              :    original EDGE can be removed and deallocated.  Return the edge that now
    1519              :    represents the call.
    1520              : 
    1521              :    For "speculative" indirect call that contains multiple "speculative"
    1522              :    targets (i.e. edge->indirect_info->num_speculative_call_targets > 1),
    1523              :    decrease the count and only remove current direct edge.
    1524              : 
    1525              :    If no speculative direct call left to the speculative indirect call, remove
    1526              :    the speculative of both the indirect call and corresponding direct edge.
    1527              : 
    1528              :    It is up to caller to iteratively resolve each "speculative" direct call and
    1529              :    redirect the call as appropriate.  */
    1530              : 
    1531              : cgraph_edge *
    1532         5771 : cgraph_edge::resolve_speculation (cgraph_edge *edge, tree callee_decl)
    1533              : {
    1534         5771 :   cgraph_edge *e2;
    1535         5771 :   ipa_ref *ref;
    1536              : 
    1537         5771 :   gcc_assert (edge->speculative && (!callee_decl || edge->callee));
    1538         5771 :   if (!edge->callee)
    1539            0 :     e2 = edge->first_speculative_call_target ();
    1540              :   else
    1541              :     e2 = edge;
    1542         5771 :   ref = e2->speculative_call_target_ref ();
    1543         5771 :   edge = edge->speculative_call_indirect_edge ();
    1544         5771 :   symtab_node *callee;
    1545         5771 :   if (!callee_decl
    1546         1167 :       || !(callee = symtab_node::get (callee_decl))
    1547         6938 :       || !ref->referred->semantically_equivalent_p (callee))
    1548              :     {
    1549         4915 :       if (dump_file)
    1550              :         {
    1551           78 :           if (callee_decl)
    1552              :             {
    1553            0 :               fprintf (dump_file, "Speculative indirect call %s => %s has "
    1554              :                        "turned out to have contradicting known target ",
    1555            0 :                        edge->caller->dump_name (),
    1556            0 :                        e2->callee->dump_name ());
    1557            0 :               print_generic_expr (dump_file, callee_decl);
    1558            0 :               fprintf (dump_file, "\n");
    1559              :             }
    1560              :           else
    1561              :             {
    1562           78 :               fprintf (dump_file, "Removing speculative call %s => %s\n",
    1563           78 :                        edge->caller->dump_name (),
    1564           78 :                        e2->callee->dump_name ());
    1565              :             }
    1566              :         }
    1567              :     }
    1568              :   else
    1569              :     {
    1570          856 :       cgraph_edge *tmp = edge;
    1571          856 :       if (dump_file)
    1572           99 :         fprintf (dump_file, "Speculative call turned into direct call.\n");
    1573              :       edge = e2;
    1574              :       e2 = tmp;
    1575              :       /* FIXME:  If EDGE is inlined, we should scale up the frequencies
    1576              :          and counts in the functions inlined through it.  */
    1577              :     }
    1578         5771 :   edge->count += e2->count;
    1579         5771 :   if (edge->num_speculative_call_targets_p ())
    1580              :     {
    1581              :       /* The indirect edge has multiple speculative targets, don't remove
    1582              :          speculative until all related direct edges are resolved.  */
    1583         4915 :       edge->indirect_info->num_speculative_call_targets--;
    1584         4915 :       if (!edge->indirect_info->num_speculative_call_targets)
    1585         1005 :         edge->speculative = false;
    1586              :     }
    1587              :   else
    1588          856 :     edge->speculative = false;
    1589         5771 :   e2->speculative = false;
    1590         5771 :   update_call_stmt_hash_for_removing_direct_edge (e2, edge);
    1591         5771 :   ref->remove_reference ();
    1592         5771 :   if (e2->indirect_unknown_callee || e2->inline_failed)
    1593         5272 :     remove (e2);
    1594              :   else
    1595          499 :     e2->callee->remove_symbol_and_inline_clones ();
    1596         5771 :   return edge;
    1597              : }
    1598              : 
    1599              : /* Return edge corresponding to speculative call to a given target.
    1600              :    NULL if speculative call does not have one.  */
    1601              : 
    1602              : cgraph_edge *
    1603            0 : cgraph_edge::speculative_call_for_target (cgraph_node *target)
    1604              : {
    1605            0 :   for (cgraph_edge *direct = first_speculative_call_target ();
    1606            0 :        direct;
    1607            0 :        direct = direct->next_speculative_call_target ())
    1608            0 :     if (direct->speculative_call_target_ref ()
    1609            0 :         ->referred->semantically_equivalent_p (target))
    1610              :       return direct;
    1611              :   return NULL;
    1612              : }
    1613              : 
    1614              : /* Make an indirect or speculative EDGE with an unknown callee an ordinary edge
    1615              :    leading to CALLEE.  Speculations can be resolved in the process and EDGE can
    1616              :    be removed and deallocated.  Return the edge that now represents the
    1617              :    call.  */
    1618              : 
    1619              : cgraph_edge *
    1620         4903 : cgraph_edge::make_direct (cgraph_edge *edge, cgraph_node *callee)
    1621              : {
    1622         4903 :   gcc_assert (edge->indirect_unknown_callee || edge->speculative);
    1623              : 
    1624              :   /* If we are redirecting speculative call, make it non-speculative.  */
    1625         4903 :   if (edge->speculative)
    1626              :     {
    1627          995 :       cgraph_edge *found = NULL;
    1628          995 :       cgraph_edge *direct, *next;
    1629              : 
    1630          995 :       edge = edge->speculative_call_indirect_edge ();
    1631              : 
    1632              :       /* Look all speculative targets and remove all but one corresponding
    1633              :          to callee (if it exists).  */
    1634          995 :       for (direct = edge->first_speculative_call_target ();
    1635         2396 :            direct;
    1636         1401 :            direct = next)
    1637              :         {
    1638         1401 :           next = direct->next_speculative_call_target ();
    1639              : 
    1640              :           /* Compare ref not direct->callee.  Direct edge is possibly
    1641              :              inlined or redirected.  */
    1642         1401 :           if (!direct->speculative_call_target_ref ()
    1643         1401 :                ->referred->semantically_equivalent_p (callee)
    1644         1401 :               || found)
    1645          545 :             edge = direct->resolve_speculation (direct, NULL);
    1646              :           else
    1647              :             found = direct;
    1648              :         }
    1649              : 
    1650              :       /* On successful speculation just remove the indirect edge and
    1651              :          return the pre existing direct edge.
    1652              :          It is important to not remove it and redirect because the direct
    1653              :          edge may be inlined or redirected.  */
    1654          995 :       if (found)
    1655              :         {
    1656          856 :           cgraph_edge *e2 = resolve_speculation (found, callee->decl);
    1657          856 :           gcc_checking_assert (!found->speculative && e2 == found);
    1658              :           return found;
    1659              :         }
    1660          139 :       gcc_checking_assert (!edge->speculative);
    1661              :     }
    1662              : 
    1663         4047 :   edge->indirect_unknown_callee = 0;
    1664         4047 :   ggc_free (edge->indirect_info);
    1665         4047 :   edge->indirect_info = NULL;
    1666              : 
    1667              :   /* Get the edge out of the indirect edge list. */
    1668         4047 :   if (edge->prev_callee)
    1669          109 :     edge->prev_callee->next_callee = edge->next_callee;
    1670         4047 :   if (edge->next_callee)
    1671          552 :     edge->next_callee->prev_callee = edge->prev_callee;
    1672         4047 :   if (!edge->prev_callee)
    1673         3938 :     edge->caller->indirect_calls = edge->next_callee;
    1674              : 
    1675              :   /* Put it into the normal callee list */
    1676         4047 :   edge->prev_callee = NULL;
    1677         4047 :   edge->next_callee = edge->caller->callees;
    1678         4047 :   if (edge->caller->callees)
    1679         2634 :     edge->caller->callees->prev_callee = edge;
    1680         4047 :   edge->caller->callees = edge;
    1681              : 
    1682              :   /* Insert to callers list of the new callee.  */
    1683         4047 :   edge->set_callee (callee);
    1684              : 
    1685              :   /* We need to re-determine the inlining status of the edge.  */
    1686         4047 :   initialize_inline_failed (edge);
    1687         4047 :   return edge;
    1688              : }
    1689              : 
    1690              : /* Redirect callee of the edge to N.  The function does not update underlying
    1691              :    call expression.  */
    1692              : 
    1693              : void
    1694      4765772 : cgraph_edge::redirect_callee (cgraph_node *n)
    1695              : {
    1696      4765772 :   bool loc = callee->comdat_local_p ();
    1697      4765772 :   cgraph_node *old_callee = callee;
    1698              : 
    1699              :   /* Remove from callers list of the current callee.  */
    1700      4765772 :   remove_callee ();
    1701              : 
    1702              :   /* Insert to callers list of the new callee.  */
    1703      4765772 :   set_callee (n);
    1704              : 
    1705      4765772 :   if (callback)
    1706              :     {
    1707              :       /* When redirecting a callback callee, redirect its ref as well.  */
    1708          220 :       ipa_ref *old_ref = caller->find_reference (old_callee, call_stmt,
    1709          220 :                                                  lto_stmt_uid, IPA_REF_ADDR);
    1710          220 :       gcc_checking_assert (old_ref);
    1711          220 :       old_ref->remove_reference ();
    1712          220 :       ipa_ref *new_ref = caller->create_reference (n, IPA_REF_ADDR, call_stmt);
    1713          220 :       new_ref->lto_stmt_uid = lto_stmt_uid;
    1714              :       /* If the last reference to OLD_CALLEE has been redirected, unset
    1715              :          address_taken.  old_ref is only used as a placeholder when looking for
    1716              :          a different reference.  */
    1717          220 :       if (!old_callee->iterate_referring (0, old_ref))
    1718          185 :         old_callee->address_taken = 0;
    1719          220 :       n->mark_address_taken ();
    1720          220 :       callback_info *ci = callback_info_sum->get (this);
    1721          220 :       ci->redirected = true;
    1722              :     }
    1723              : 
    1724      4765772 :   if (!inline_failed)
    1725              :     return;
    1726       809574 :   if (!loc && n->comdat_local_p ())
    1727              :     {
    1728           56 :       cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
    1729           56 :       to->calls_comdat_local = true;
    1730              :     }
    1731       809518 :   else if (loc && !n->comdat_local_p ())
    1732              :     {
    1733           92 :       cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
    1734           92 :       gcc_checking_assert (to->calls_comdat_local);
    1735           92 :       to->calls_comdat_local = to->check_calls_comdat_local_p ();
    1736              :     }
    1737              : }
    1738              : 
    1739              : /* If necessary, change the function declaration in the call statement
    1740              :    associated with E so that it corresponds to the edge callee.  Speculations
    1741              :    can be resolved in the process and EDGE can be removed and deallocated.
    1742              : 
    1743              :    The edge could be one of speculative direct call generated from speculative
    1744              :    indirect call.  In this circumstance, decrease the speculative targets
    1745              :    count (i.e. num_speculative_call_targets) and redirect call stmt to the
    1746              :    corresponding i-th target.  If no speculative direct call left to the
    1747              :    speculative indirect call, remove "speculative" of the indirect call and
    1748              :    also redirect stmt to it's final direct target.
    1749              : 
    1750              :    When called from within tree-inline, KILLED_SSAs has to contain the pointer
    1751              :    to killed_new_ssa_names within the copy_body_data structure and SSAs
    1752              :    discovered to be useless (if LHS is removed) will be added to it, otherwise
    1753              :    it needs to be NULL.
    1754              : 
    1755              :    It is up to caller to iteratively transform each "speculative"
    1756              :    direct call as appropriate.  */
    1757              : 
    1758              : gimple *
    1759     10355066 : cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
    1760              :                                            hash_set <tree> *killed_ssas)
    1761              : {
    1762     10355066 :   tree decl = gimple_call_fndecl (e->call_stmt);
    1763     10355066 :   gcall *new_stmt;
    1764              : 
    1765     10355066 :   if (e->speculative)
    1766              :     {
    1767              :       /* If there already is an direct call (i.e. as a result of inliner's
    1768              :          substitution), forget about speculating.  */
    1769        35416 :       if (decl)
    1770            0 :         e = make_direct (e->speculative_call_indirect_edge (),
    1771              :                          cgraph_node::get (decl));
    1772              :       else
    1773              :         {
    1774              :           /* Be sure we redirect all speculative targets before poking
    1775              :              about indirect edge.  */
    1776        35416 :           gcc_checking_assert (e->callee);
    1777        35416 :           cgraph_edge *indirect = e->speculative_call_indirect_edge ();
    1778        35416 :           gcall *new_stmt;
    1779        35416 :           ipa_ref *ref;
    1780              : 
    1781              :           /* Expand speculation into GIMPLE code.  */
    1782        35416 :           if (dump_file)
    1783              :             {
    1784          150 :               fprintf (dump_file,
    1785              :                        "Expanding speculative call of %s -> %s count: ",
    1786           75 :                        e->caller->dump_name (),
    1787              :                        e->callee->dump_name ());
    1788           75 :               e->count.dump (dump_file);
    1789           75 :               fprintf (dump_file, "\n");
    1790              :             }
    1791        35416 :           push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
    1792              : 
    1793        35416 :           profile_count all = indirect->count;
    1794        35416 :           for (cgraph_edge *e2 = e->first_speculative_call_target ();
    1795        80225 :                e2;
    1796        44809 :                e2 = e2->next_speculative_call_target ())
    1797        44809 :             all = all + e2->count;
    1798        35416 :           profile_probability prob = e->count.probability_in (all);
    1799        35416 :           if (!prob.initialized_p ())
    1800          160 :             prob = profile_probability::even ();
    1801        35416 :           ref = e->speculative_call_target_ref ();
    1802        70832 :           new_stmt = gimple_ic (e->call_stmt,
    1803              :                                 dyn_cast<cgraph_node *> (ref->referred),
    1804              :                                 prob);
    1805        35416 :           e->speculative = false;
    1806        35416 :           if (indirect->num_speculative_call_targets_p ())
    1807              :             {
    1808              :               /* The indirect edge has multiple speculative targets, don't
    1809              :                  remove speculative until all related direct edges are
    1810              :                  redirected.  */
    1811        35416 :               indirect->indirect_info->num_speculative_call_targets--;
    1812        35416 :               if (!indirect->indirect_info->num_speculative_call_targets)
    1813        27664 :                 indirect->speculative = false;
    1814              :             }
    1815              :           else
    1816            0 :             indirect->speculative = false;
    1817              :           /* Indirect edges are not both in the call site hash.
    1818              :              get it updated.  */
    1819        35416 :           update_call_stmt_hash_for_removing_direct_edge (e, indirect);
    1820        35416 :           cgraph_edge::set_call_stmt (e, new_stmt, false);
    1821        35416 :           e->count = gimple_bb (e->call_stmt)->count;
    1822              : 
    1823              :           /* Once we are done with expanding the sequence, update also indirect
    1824              :              call probability.  Until then the basic block accounts for the
    1825              :              sum of indirect edge and all non-expanded speculations.  */
    1826        35416 :           if (!indirect->speculative)
    1827        27664 :             indirect->count = gimple_bb (indirect->call_stmt)->count;
    1828        35416 :           ref->speculative = false;
    1829        35416 :           ref->stmt = NULL;
    1830        35416 :           pop_cfun ();
    1831              :           /* Continue redirecting E to proper target.  */
    1832              :         }
    1833              :     }
    1834              : 
    1835              : 
    1836     10355066 :   if (e->indirect_unknown_callee
    1837     10269705 :       || decl == e->callee->decl)
    1838      9141357 :     return e->call_stmt;
    1839              : 
    1840              :   /* When redirecting a callback edge, all we need to do is replace
    1841              :      the original address with the address of the function we are
    1842              :      redirecting to.  */
    1843      1213709 :   if (e->callback)
    1844              :     {
    1845         3223 :       cgraph_edge *carrying = e->get_callback_carrying_edge ();
    1846         3223 :       if (!callback_is_special_cased (carrying->callee->decl, e->call_stmt)
    1847         5693 :           && !lookup_attribute ("callback_only",
    1848         2470 :                                 DECL_ATTRIBUTES (carrying->callee->decl)))
    1849              :         /* Callback attribute is removed if the dispatching function changes
    1850              :            signature, as the indices wouldn't be correct anymore.  These edges
    1851              :            will get cleaned up later, ignore their redirection for now.  */
    1852            0 :         return e->call_stmt;
    1853         3223 :       callback_info *ci = callback_info_sum->get (e);
    1854         3223 :       tree previous_arg = gimple_call_arg (e->call_stmt, ci->fn_idx);
    1855         3223 :       location_t loc = EXPR_LOCATION (previous_arg);
    1856         3223 :       tree new_addr = build_fold_addr_expr_loc (loc, e->callee->decl);
    1857         3223 :       gimple_call_set_arg (e->call_stmt, ci->fn_idx, new_addr);
    1858         3223 :       return e->call_stmt;
    1859              :     }
    1860              : 
    1861      1210486 :   if (decl && ipa_saved_clone_sources)
    1862              :     {
    1863       984303 :       tree *p = ipa_saved_clone_sources->get (e->callee);
    1864       984303 :       if (p && decl == *p)
    1865              :         {
    1866        34774 :           gimple_call_set_fndecl (e->call_stmt, e->callee->decl);
    1867        34774 :           return e->call_stmt;
    1868              :         }
    1869              :     }
    1870      1175712 :   if (flag_checking && decl)
    1871              :     {
    1872      1136630 :       if (cgraph_node *node = cgraph_node::get (decl))
    1873              :         {
    1874       994462 :           clone_info *info = clone_info::get (node);
    1875       994462 :           gcc_assert (!info || !info->param_adjustments);
    1876              :         }
    1877              :     }
    1878              : 
    1879      1175712 :   clone_info *callee_info = clone_info::get (e->callee);
    1880      1175712 :   if (symtab->dump_file)
    1881              :     {
    1882            0 :       fprintf (symtab->dump_file, "updating call of %s -> %s: ",
    1883            0 :                e->caller->dump_name (), e->callee->dump_name ());
    1884            0 :       print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
    1885            0 :       if (callee_info && callee_info->param_adjustments)
    1886            0 :         callee_info->param_adjustments->dump (symtab->dump_file);
    1887              :     }
    1888              : 
    1889       651935 :   if (ipa_param_adjustments *padjs
    1890      1175712 :          = callee_info ? callee_info->param_adjustments : NULL)
    1891              :     {
    1892              :       /* We need to defer cleaning EH info on the new statement to
    1893              :          fixup-cfg.  We may not have dominator information at this point
    1894              :          and thus would end up with unreachable blocks and have no way
    1895              :          to communicate that we need to run CFG cleanup then.  */
    1896       644967 :       int lp_nr = lookup_stmt_eh_lp (e->call_stmt);
    1897       644967 :       if (lp_nr != 0)
    1898       159186 :         remove_stmt_from_eh_lp (e->call_stmt);
    1899              : 
    1900       644967 :       tree old_fntype = gimple_call_fntype (e->call_stmt);
    1901       644967 :       new_stmt = padjs->modify_call (e, false, killed_ssas);
    1902       644967 :       cgraph_node *origin = e->callee;
    1903       946780 :       while (origin->clone_of)
    1904              :         origin = origin->clone_of;
    1905              : 
    1906       644967 :       if ((origin->former_clone_of
    1907       503310 :            && old_fntype == TREE_TYPE (origin->former_clone_of))
    1908       649038 :           || old_fntype == TREE_TYPE (origin->decl))
    1909       499241 :         gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
    1910              :       else
    1911              :         {
    1912       145726 :           tree new_fntype = padjs->build_new_function_type (old_fntype, true);
    1913       145726 :           gimple_call_set_fntype (new_stmt, new_fntype);
    1914              :         }
    1915              : 
    1916       644967 :       if (lp_nr != 0)
    1917       159186 :         add_stmt_to_eh_lp (new_stmt, lp_nr);
    1918              :     }
    1919              :   else
    1920              :     {
    1921       530745 :       if (flag_checking
    1922       530745 :           && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
    1923              :                                                   BUILT_IN_UNREACHABLE_TRAP))
    1924       319247 :         ipa_verify_edge_has_no_modifications (e);
    1925       530745 :       new_stmt = e->call_stmt;
    1926       530745 :       gimple_call_set_fndecl (new_stmt, e->callee->decl);
    1927       530745 :       update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
    1928              :     }
    1929              : 
    1930              :   /* If changing the call to __cxa_pure_virtual or similar noreturn function,
    1931              :      adjust gimple_call_fntype too.  */
    1932      1175712 :   if (gimple_call_noreturn_p (new_stmt)
    1933       214389 :       && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (e->callee->decl)))
    1934       214316 :       && TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl))
    1935      1390022 :       && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl)))
    1936       214310 :           == void_type_node))
    1937       213614 :     gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
    1938              : 
    1939              :   /* If the call becomes noreturn, remove the LHS if possible.  */
    1940      1175712 :   tree lhs = gimple_call_lhs (new_stmt);
    1941      1175712 :   if (lhs
    1942       348861 :       && gimple_call_noreturn_p (new_stmt)
    1943      1208968 :       && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (new_stmt)))
    1944           58 :           || should_remove_lhs_p (lhs)))
    1945              :     {
    1946        33217 :       gimple_call_set_lhs (new_stmt, NULL_TREE);
    1947              :       /* We need to fix up the SSA name to avoid checking errors.  */
    1948        33217 :       if (TREE_CODE (lhs) == SSA_NAME)
    1949              :         {
    1950        28088 :           tree var = create_tmp_reg_fn (DECL_STRUCT_FUNCTION (e->caller->decl),
    1951        28088 :                                         TREE_TYPE (lhs), NULL);
    1952        28088 :           SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var);
    1953        28088 :           SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
    1954        28088 :           set_ssa_default_def (DECL_STRUCT_FUNCTION (e->caller->decl),
    1955              :                                var, lhs);
    1956              :         }
    1957        33217 :       update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
    1958              :     }
    1959              : 
    1960              :   /* If new callee has no static chain, remove it.  */
    1961      1175712 :   if (gimple_call_chain (new_stmt) && !DECL_STATIC_CHAIN (e->callee->decl))
    1962              :     {
    1963           56 :       gimple_call_set_chain (new_stmt, NULL);
    1964           56 :       update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
    1965              :     }
    1966              : 
    1967      1175712 :   maybe_remove_unused_call_args (DECL_STRUCT_FUNCTION (e->caller->decl),
    1968              :                                  new_stmt);
    1969              : 
    1970              :   /* Update callback edges if setting the carrying edge's statement, or else
    1971              :      their pairing would fall apart.  */
    1972      1175712 :   e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt, e->has_callback);
    1973              : 
    1974      1175712 :   if (symtab->dump_file)
    1975              :     {
    1976            0 :       fprintf (symtab->dump_file, "  updated to:");
    1977            0 :       print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
    1978              :     }
    1979              :   return new_stmt;
    1980              : }
    1981              : 
    1982              : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
    1983              :    OLD_STMT changed into NEW_STMT.  OLD_CALL is gimple_call_fndecl
    1984              :    of OLD_STMT if it was previously call statement.
    1985              :    If NEW_STMT is NULL, the call has been dropped without any
    1986              :    replacement.  */
    1987              : 
    1988              : static void
    1989       123696 : cgraph_update_edges_for_call_stmt_node (cgraph_node *node,
    1990              :                                         gimple *old_stmt, tree old_call,
    1991              :                                         gimple *new_stmt)
    1992              : {
    1993       123696 :   tree new_call = (new_stmt && is_gimple_call (new_stmt))
    1994       130089 :                   ? gimple_call_fndecl (new_stmt) : 0;
    1995              : 
    1996              :   /* We are seeing indirect calls, then there is nothing to update.  */
    1997       123696 :   if (!new_call && !old_call)
    1998              :     return;
    1999              :   /* See if we turned indirect call into direct call or folded call to one builtin
    2000              :      into different builtin.  */
    2001       121965 :   if (old_call != new_call)
    2002              :     {
    2003       120379 :       cgraph_edge *e = node->get_edge (old_stmt);
    2004       120379 :       cgraph_edge *ne = NULL;
    2005       120379 :       profile_count count;
    2006              : 
    2007       120379 :       if (e)
    2008              :         {
    2009              :           /* If call was devirtualized during cloning, mark edge
    2010              :              as resolved.  */
    2011        99078 :           if (e->speculative)
    2012              :             {
    2013            0 :               if (new_stmt && is_gimple_call (new_stmt))
    2014              :                 {
    2015            0 :                   tree decl = gimple_call_fndecl (new_stmt);
    2016            0 :                   if (decl)
    2017            0 :                     e = cgraph_edge::make_direct
    2018            0 :                             (e, cgraph_node::get_create (decl));
    2019              :                 }
    2020              :               else
    2021            0 :                 gcc_unreachable ();
    2022              :             }
    2023              :           /* Keep calls marked as dead dead.  */
    2024        99078 :           if (new_stmt && is_gimple_call (new_stmt) && e->callee
    2025       100634 :               && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
    2026              :                                     BUILT_IN_UNREACHABLE_TRAP))
    2027              :             {
    2028            3 :               cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
    2029              :                                           as_a <gcall *> (new_stmt));
    2030           28 :               return;
    2031              :             }
    2032              :           /* See if the edge is already there and has the correct callee.  It
    2033              :              might be so because of indirect inlining has already updated
    2034              :              it.  We also might've cloned and redirected the edge.  */
    2035        99075 :           if (new_call && e->callee)
    2036              :             {
    2037              :               cgraph_node *callee = e->callee;
    2038         3107 :               while (callee)
    2039              :                 {
    2040         1576 :                   if (callee->decl == new_call
    2041         1576 :                       || callee->former_clone_of == new_call)
    2042              :                     {
    2043           22 :                       cgraph_edge::set_call_stmt (e, as_a <gcall *> (new_stmt));
    2044           22 :                       return;
    2045              :                     }
    2046         1554 :                   callee = callee->clone_of;
    2047              :                 }
    2048              :             }
    2049              : 
    2050              :           /* Otherwise remove edge and create new one; we can't simply redirect
    2051              :              since function has changed, so inline plan and other information
    2052              :              attached to edge is invalid.  */
    2053        99053 :           count = e->count;
    2054        99053 :           if (e->indirect_unknown_callee || e->inline_failed)
    2055        99053 :             cgraph_edge::remove (e);
    2056              :           else
    2057            0 :             e->callee->remove_symbol_and_inline_clones ();
    2058              :         }
    2059        21301 :       else if (new_call)
    2060              :         {
    2061              :           /* We are seeing new direct call; compute profile info based on BB.  */
    2062            4 :           basic_block bb = gimple_bb (new_stmt);
    2063            4 :           count = bb->count;
    2064              :         }
    2065              : 
    2066        99057 :       if (new_call)
    2067              :         {
    2068         3300 :           ne = node->create_edge (cgraph_node::get_create (new_call),
    2069              :                                   as_a <gcall *> (new_stmt), count);
    2070         3300 :           gcc_assert (ne->inline_failed);
    2071              :         }
    2072              :     }
    2073              :   /* We only updated the call stmt; update pointer in cgraph edge..  */
    2074         1586 :   else if (old_stmt != new_stmt)
    2075            0 :     cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
    2076              :                                 as_a <gcall *> (new_stmt));
    2077              : }
    2078              : 
    2079              : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
    2080              :    OLD_STMT changed into NEW_STMT.  OLD_DECL is gimple_call_fndecl
    2081              :    of OLD_STMT before it was updated (updating can happen inplace).  */
    2082              : 
    2083              : void
    2084       102046 : cgraph_update_edges_for_call_stmt (gimple *old_stmt, tree old_decl,
    2085              :                                    gimple *new_stmt)
    2086              : {
    2087       102046 :   cgraph_node *orig = cgraph_node::get (cfun->decl);
    2088       102046 :   cgraph_node *node;
    2089              : 
    2090       102046 :   gcc_checking_assert (orig);
    2091       102046 :   gcc_assert (!orig->thunk);
    2092       102046 :   cgraph_update_edges_for_call_stmt_node (orig, old_stmt, old_decl, new_stmt);
    2093       102046 :   if (orig->clones)
    2094        42655 :     for (node = orig->clones; node != orig;)
    2095              :       {
    2096              :         /* Do not attempt to adjust bodies of yet unexpanded thunks.  */
    2097        21652 :         if (!node->thunk)
    2098        21650 :           cgraph_update_edges_for_call_stmt_node (node, old_stmt, old_decl,
    2099              :                                                   new_stmt);
    2100        21652 :         if (node->clones)
    2101              :           node = node->clones;
    2102        21639 :         else if (node->next_sibling_clone)
    2103              :           node = node->next_sibling_clone;
    2104              :         else
    2105              :           {
    2106        42019 :             while (node != orig && !node->next_sibling_clone)
    2107        21016 :               node = node->clone_of;
    2108        21003 :             if (node != orig)
    2109            0 :               node = node->next_sibling_clone;
    2110              :           }
    2111              :       }
    2112       102046 : }
    2113              : 
    2114              : 
    2115              : /* Remove all callees from the node.  */
    2116              : 
    2117              : void
    2118    242372927 : cgraph_node::remove_callees (void)
    2119              : {
    2120    242372927 :   cgraph_edge *e, *f;
    2121              : 
    2122    242372927 :   calls_comdat_local = false;
    2123              : 
    2124              :   /* It is sufficient to remove the edges from the lists of callers of
    2125              :      the callees.  The callee list of the node can be zapped with one
    2126              :      assignment.  */
    2127    283247255 :   for (e = callees; e; e = f)
    2128              :     {
    2129     40874328 :       f = e->next_callee;
    2130     40874328 :       symtab->call_edge_removal_hooks (e);
    2131     40874328 :       if (!e->indirect_unknown_callee)
    2132     40874328 :         e->remove_callee ();
    2133     40874328 :       symtab->free_edge (e);
    2134              :     }
    2135    243208391 :   for (e = indirect_calls; e; e = f)
    2136              :     {
    2137       835464 :       f = e->next_callee;
    2138       835464 :       symtab->call_edge_removal_hooks (e);
    2139       835464 :       if (!e->indirect_unknown_callee)
    2140            0 :         e->remove_callee ();
    2141       835464 :       symtab->free_edge (e);
    2142              :     }
    2143    242372927 :   indirect_calls = NULL;
    2144    242372927 :   callees = NULL;
    2145    242372927 :   if (call_site_hash)
    2146              :     {
    2147        31981 :       call_site_hash->empty ();
    2148        31981 :       call_site_hash = NULL;
    2149              :     }
    2150    242372927 : }
    2151              : 
    2152              : /* Remove all callers from the node.  */
    2153              : 
    2154              : void
    2155    109628008 : cgraph_node::remove_callers (void)
    2156              : {
    2157    109628008 :   cgraph_edge *e, *f;
    2158              : 
    2159              :   /* It is sufficient to remove the edges from the lists of callees of
    2160              :      the callers.  The caller list of the node can be zapped with one
    2161              :      assignment.  */
    2162    114362098 :   for (e = callers; e; e = f)
    2163              :     {
    2164      4734090 :       f = e->next_caller;
    2165              :       /* When removing a callback-carrying edge, remove all its attached edges
    2166              :          as well.  */
    2167      4734090 :       if (e->has_callback)
    2168              :         {
    2169            2 :           cgraph_edge *cbe, *next_cbe = NULL;
    2170            2 :           for (cbe = e->first_callback_edge (); cbe; cbe = next_cbe)
    2171              :             {
    2172            0 :               next_cbe = cbe->next_callback_edge ();
    2173            0 :               cgraph_edge::remove (cbe);
    2174              :             }
    2175              :         }
    2176      4734090 :       symtab->call_edge_removal_hooks (e);
    2177      4734090 :       e->remove_caller ();
    2178      4734090 :       symtab->free_edge (e);
    2179              :     }
    2180    109628008 :   callers = NULL;
    2181    109628008 : }
    2182              : 
    2183              : /* Helper function for cgraph_release_function_body and free_lang_data.
    2184              :    It releases body from function DECL without having to inspect its
    2185              :    possibly non-existent symtab node.  */
    2186              : 
    2187              : void
    2188    119772072 : release_function_body (tree decl)
    2189              : {
    2190    119772072 :   function *fn = DECL_STRUCT_FUNCTION (decl);
    2191    119772072 :   if (fn)
    2192              :     {
    2193    108006576 :       if (fn->cfg
    2194    108006576 :           && loops_for_fn (fn))
    2195              :         {
    2196      1810004 :           fn->curr_properties &= ~PROP_loops;
    2197      1810004 :           loop_optimizer_finalize (fn);
    2198              :         }
    2199    108006576 :       if (fn->gimple_df)
    2200              :         {
    2201      1818808 :           delete_tree_ssa (fn);
    2202      1818808 :           fn->eh = NULL;
    2203              :         }
    2204    108006576 :       if (fn->cfg)
    2205              :         {
    2206      1810005 :           gcc_assert (!dom_info_available_p (fn, CDI_DOMINATORS));
    2207      1810005 :           gcc_assert (!dom_info_available_p (fn, CDI_POST_DOMINATORS));
    2208      1810005 :           delete_tree_cfg_annotations (fn);
    2209      1810005 :           free_cfg (fn);
    2210      1810005 :           fn->cfg = NULL;
    2211              :         }
    2212    108006576 :       if (fn->value_histograms)
    2213           13 :         free_histograms (fn);
    2214    108006576 :       gimple_set_body (decl, NULL);
    2215              :       /* Struct function hangs a lot of data that would leak if we didn't
    2216              :          removed all pointers to it.   */
    2217    108006576 :       ggc_free (fn);
    2218    108006576 :       DECL_STRUCT_FUNCTION (decl) = NULL;
    2219              :     }
    2220    119772072 :   DECL_SAVED_TREE (decl) = NULL;
    2221    119772072 : }
    2222              : 
    2223              : /* Release memory used to represent body of function.
    2224              :    Use this only for functions that are released before being translated to
    2225              :    target code (i.e. RTL).  Functions that are compiled to RTL and beyond
    2226              :    are free'd in final.cc via free_after_compilation().
    2227              :    KEEP_ARGUMENTS are useful only if you want to rebuild body as thunk.  */
    2228              : 
    2229              : void
    2230    119760150 : cgraph_node::release_body (bool keep_arguments)
    2231              : {
    2232    119760150 :   ipa_transforms_to_apply.release ();
    2233    119760150 :   if (!used_as_abstract_origin && symtab->state != PARSING)
    2234              :     {
    2235    119155471 :       DECL_RESULT (decl) = NULL;
    2236              : 
    2237    119155471 :       if (!keep_arguments)
    2238    119124181 :         DECL_ARGUMENTS (decl) = NULL;
    2239              :     }
    2240              :   /* If the node is abstract and needed, then do not clear
    2241              :      DECL_INITIAL of its associated function declaration because it's
    2242              :      needed to emit debug info later.  */
    2243    119760150 :   if (!used_as_abstract_origin && DECL_INITIAL (decl))
    2244    107471746 :     DECL_INITIAL (decl) = error_mark_node;
    2245    119760150 :   release_function_body (decl);
    2246    119760150 :   lto_free_function_in_decl_state_for_node (this);
    2247    119760150 :   if (flag_checking && clones)
    2248              :     {
    2249              :       /* It is invalid to release body before materializing clones except
    2250              :          for thunks that don't really need a body.  Verify also that we do
    2251              :          not leak pointers to the call statements.  */
    2252           53 :       for (cgraph_node *node = clones; node;
    2253           31 :            node = node->next_sibling_clone)
    2254           31 :         gcc_assert (node->thunk && !node->callees->call_stmt);
    2255              :     }
    2256    119760150 :   remove_callees ();
    2257    119760150 :   remove_all_references ();
    2258    119760150 : }
    2259              : 
    2260              : /* Remove function from symbol table.  */
    2261              : 
    2262              : void
    2263    109628008 : cgraph_node::remove (void)
    2264              : {
    2265    109628008 :   bool clone_info_set = false;
    2266    109628008 :   clone_info *info, saved_info;
    2267    109628008 :   if (symtab->ipa_clones_dump_file && symtab->cloned_nodes.contains (this))
    2268           13 :     fprintf (symtab->ipa_clones_dump_file,
    2269              :              "Callgraph removal;%s;%d;%s;%d;%d\n", asm_name (), get_uid (),
    2270           13 :              DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
    2271           26 :              DECL_SOURCE_COLUMN (decl));
    2272              : 
    2273    109628008 :   if ((info = clone_info::get (this)) != NULL)
    2274              :     {
    2275       459938 :       saved_info = *info;
    2276       459938 :       clone_info_set = true;
    2277              :     }
    2278    109628008 :   symtab->call_cgraph_removal_hooks (this);
    2279    109628008 :   remove_callers ();
    2280    109628008 :   remove_callees ();
    2281    109628008 :   ipa_transforms_to_apply.release ();
    2282    109628008 :   delete_function_version (function_version ());
    2283              : 
    2284              :   /* Incremental inlining access removed nodes stored in the postorder list.
    2285              :      */
    2286    109628008 :   force_output = false;
    2287    109628008 :   forced_by_abi = false;
    2288              : 
    2289    218796078 :   unregister (clone_info_set ? &saved_info : NULL);
    2290    109628008 :   if (prev_sibling_clone)
    2291       821886 :     prev_sibling_clone->next_sibling_clone = next_sibling_clone;
    2292    108806122 :   else if (clone_of)
    2293              :     {
    2294      1890920 :       clone_of->clones = next_sibling_clone;
    2295      1890920 :       if (!clones)
    2296              :         {
    2297      1887840 :           bool need_body = false;
    2298      1887840 :           for (cgraph_node *n = clone_of; n; n = n->clone_of)
    2299      1882054 :             if (n->analyzed || n->clones)
    2300              :               {
    2301              :                 need_body = true;
    2302              :                 break;
    2303              :               }
    2304      1882051 :           if (!need_body)
    2305         5786 :             clone_of->release_body ();
    2306              :         }
    2307              :     }
    2308    109628008 :   if (next_sibling_clone)
    2309      1062206 :     next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
    2310    109628008 :   if (clones)
    2311              :     {
    2312        40294 :       cgraph_node *n, *next;
    2313              : 
    2314        40294 :       if (clone_of)
    2315              :         {
    2316       183540 :           for (n = clones; n->next_sibling_clone; n = n->next_sibling_clone)
    2317       143246 :             n->clone_of = clone_of;
    2318        40294 :           n->clone_of = clone_of;
    2319        40294 :           n->next_sibling_clone = clone_of->clones;
    2320        40294 :           if (clone_of->clones)
    2321        35001 :             clone_of->clones->prev_sibling_clone = n;
    2322        40294 :           clone_of->clones = clones;
    2323              :         }
    2324              :       else
    2325              :         {
    2326              :           /* We are removing node with clones.  This makes clones inconsistent,
    2327              :              but assume they will be removed subsequently and just keep clone
    2328              :              tree intact.  This can happen in unreachable function removal since
    2329              :              we remove unreachable functions in random order, not by bottom-up
    2330              :              walk of clone trees.  */
    2331            0 :           for (n = clones; n; n = next)
    2332              :             {
    2333            0 :                next = n->next_sibling_clone;
    2334            0 :                n->next_sibling_clone = NULL;
    2335            0 :                n->prev_sibling_clone = NULL;
    2336            0 :                n->clone_of = NULL;
    2337              :             }
    2338              :         }
    2339              :     }
    2340              : 
    2341              :   /* While all the clones are removed after being proceeded, the function
    2342              :      itself is kept in the cgraph even after it is compiled.  Check whether
    2343              :      we are done with this body and reclaim it proactively if this is the case.
    2344              :      */
    2345    109628008 :   if (symtab->state != LTO_STREAMING)
    2346              :     {
    2347    109625871 :       cgraph_node *n = cgraph_node::get (decl);
    2348    109625871 :       if (!n
    2349    109625871 :           || (!n->clones && !n->clone_of && !n->inlined_to
    2350      1166719 :               && ((symtab->global_info_ready || in_lto_p)
    2351        10586 :                   && (TREE_ASM_WRITTEN (n->decl)
    2352        10554 :                       || DECL_EXTERNAL (n->decl)
    2353         5525 :                       || !n->analyzed
    2354         5330 :                       || (!flag_wpa && n->in_other_partition)))))
    2355    106489002 :         release_body ();
    2356              :     }
    2357              :   else
    2358         2137 :     lto_free_function_in_decl_state_for_node (this);
    2359              : 
    2360    109628008 :   decl = NULL;
    2361    109628008 :   if (call_site_hash)
    2362              :     {
    2363            0 :       call_site_hash->empty ();
    2364            0 :       call_site_hash = NULL;
    2365              :     }
    2366              : 
    2367    109628008 :   symtab->release_symbol (this);
    2368    109628008 : }
    2369              : 
    2370              : /* Likewise indicate that a node is having address taken.  */
    2371              : 
    2372              : void
    2373      4853860 : cgraph_node::mark_address_taken (void)
    2374              : {
    2375              :   /* Indirect inlining can figure out that all uses of the address are
    2376              :      inlined.  */
    2377      4853860 :   if (inlined_to)
    2378              :     {
    2379            0 :       gcc_assert (cfun->after_inlining);
    2380            0 :       gcc_assert (callers->indirect_inlining_edge);
    2381              :       return;
    2382              :     }
    2383              :   /* FIXME: address_taken flag is used both as a shortcut for testing whether
    2384              :      IPA_REF_ADDR reference exists (and thus it should be set on node
    2385              :      representing alias we take address of) and as a test whether address
    2386              :      of the object was taken (and thus it should be set on node alias is
    2387              :      referring to).  We should remove the first use and the remove the
    2388              :      following set.  */
    2389      4853860 :   address_taken = 1;
    2390      4853860 :   cgraph_node *node = ultimate_alias_target ();
    2391      4853860 :   node->address_taken = 1;
    2392              : }
    2393              : 
    2394              : /* Return local info node for the compiled function.  */
    2395              : 
    2396              : cgraph_node *
    2397     12951318 : cgraph_node::local_info_node (tree decl)
    2398              : {
    2399     12951318 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    2400     12951318 :   cgraph_node *node = get (decl);
    2401     12951318 :   if (!node)
    2402              :     return NULL;
    2403     12951318 :   return node->ultimate_alias_target ();
    2404              : }
    2405              : 
    2406              : /* Return RTL info for the compiled function.  */
    2407              : 
    2408              : cgraph_rtl_info *
    2409     61878731 : cgraph_node::rtl_info (const_tree decl)
    2410              : {
    2411     61878731 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    2412     61878731 :   cgraph_node *node = get (decl);
    2413     61878731 :   if (!node)
    2414              :     return NULL;
    2415     61726986 :   enum availability avail;
    2416     61726986 :   node = node->ultimate_alias_target (&avail);
    2417     61726986 :   if (decl != current_function_decl
    2418     58638369 :       && (avail < AVAIL_AVAILABLE
    2419     53203693 :           || (node->decl != current_function_decl
    2420     53128588 :               && !TREE_ASM_WRITTEN (node->decl))))
    2421              :     return NULL;
    2422              :   /* Allocate if it doesn't exist.  */
    2423     52722625 :   if (node->rtl == NULL)
    2424              :     {
    2425      1379303 :       node->rtl = ggc_cleared_alloc<cgraph_rtl_info> ();
    2426      1379303 :       SET_HARD_REG_SET (node->rtl->function_used_regs);
    2427              :     }
    2428     52722625 :   return node->rtl;
    2429              : }
    2430              : 
    2431              : /* Return a string describing the failure REASON.  */
    2432              : 
    2433              : const char*
    2434         9832 : cgraph_inline_failed_string (cgraph_inline_failed_t reason)
    2435              : {
    2436              : #undef DEFCIFCODE
    2437              : #define DEFCIFCODE(code, type, string)  string,
    2438              : 
    2439         9832 :   static const char *cif_string_table[CIF_N_REASONS] = {
    2440              : #include "cif-code.def"
    2441              :   };
    2442              : 
    2443              :   /* Signedness of an enum type is implementation defined, so cast it
    2444              :      to unsigned before testing. */
    2445         9832 :   gcc_assert ((unsigned) reason < CIF_N_REASONS);
    2446         9832 :   return cif_string_table[reason];
    2447              : }
    2448              : 
    2449              : /* Return a type describing the failure REASON.  */
    2450              : 
    2451              : cgraph_inline_failed_type_t
    2452     75555739 : cgraph_inline_failed_type (cgraph_inline_failed_t reason)
    2453              : {
    2454              : #undef DEFCIFCODE
    2455              : #define DEFCIFCODE(code, type, string)  type,
    2456              : 
    2457     75555739 :   static cgraph_inline_failed_type_t cif_type_table[CIF_N_REASONS] = {
    2458              : #include "cif-code.def"
    2459              :   };
    2460              : 
    2461              :   /* Signedness of an enum type is implementation defined, so cast it
    2462              :      to unsigned before testing. */
    2463     75555739 :   gcc_assert ((unsigned) reason < CIF_N_REASONS);
    2464     75555739 :   return cif_type_table[reason];
    2465              : }
    2466              : 
    2467              : /* Names used to print out the availability enum.  */
    2468              : const char * const cgraph_availability_names[] =
    2469              :   {"unset", "not_available", "overwritable", "available", "local"};
    2470              : 
    2471              : /* Output flags of edge to a file F.  */
    2472              : 
    2473              : void
    2474        22303 : cgraph_edge::dump_edge_flags (FILE *f)
    2475              : {
    2476        22303 :   if (speculative)
    2477          220 :     fprintf (f, "(speculative) ");
    2478        22303 :   if (callback)
    2479            8 :     fprintf (f, "(callback) ");
    2480        22303 :   if (has_callback)
    2481           12 :     fprintf (f, "(has_callback) ");
    2482        22303 :   if (!inline_failed)
    2483         1789 :     fprintf (f, "(inlined) ");
    2484        22303 :   if (call_stmt_cannot_inline_p)
    2485            0 :     fprintf (f, "(call_stmt_cannot_inline_p) ");
    2486        22303 :   if (indirect_inlining_edge)
    2487          325 :     fprintf (f, "(indirect_inlining) ");
    2488        22303 :   if (count.initialized_p ())
    2489              :     {
    2490        21762 :       fprintf (f, "(");
    2491        21762 :       count.dump (f);
    2492        21762 :       fprintf (f, ",");
    2493        21762 :       fprintf (f, "%.2f per call) ", sreal_frequency ().to_double ());
    2494              :     }
    2495        22303 :   if (can_throw_external)
    2496         2312 :     fprintf (f, "(can throw external) ");
    2497        22303 : }
    2498              : 
    2499              : /* Dump edge to stderr.  */
    2500              : 
    2501              : void
    2502            0 : cgraph_edge::debug (void)
    2503              : {
    2504            0 :   fprintf (stderr, "%s -> %s ", caller->dump_asm_name (),
    2505            0 :            callee == NULL ? "(null)" : callee->dump_asm_name ());
    2506            0 :   dump_edge_flags (stderr);
    2507            0 :   fprintf (stderr, "\n\n");
    2508            0 :   caller->debug ();
    2509            0 :   if (callee != NULL)
    2510            0 :     callee->debug ();
    2511            0 : }
    2512              : 
    2513              : /* Dump call graph node to file F.  */
    2514              : 
    2515              : void
    2516         5961 : cgraph_node::dump (FILE *f)
    2517              : {
    2518         5961 :   cgraph_edge *edge;
    2519              : 
    2520         5961 :   dump_base (f);
    2521              : 
    2522         5961 :   if (inlined_to)
    2523          776 :     fprintf (f, "  Function %s is inline copy in %s\n",
    2524              :              dump_name (),
    2525              :              inlined_to->dump_name ());
    2526         5961 :   if (clone_of)
    2527          755 :     fprintf (f, "  Clone of %s\n", clone_of->dump_asm_name ());
    2528         5961 :   if (symtab->function_flags_ready)
    2529        10818 :     fprintf (f, "  Availability: %s\n",
    2530         5409 :              cgraph_availability_names [get_availability ()]);
    2531              : 
    2532         5961 :   if (profile_id)
    2533          193 :     fprintf (f, "  Profile id: %i\n",
    2534              :              profile_id);
    2535         5961 :   if (unit_id)
    2536          157 :     fprintf (f, "  Unit id: %i\n",
    2537              :              unit_id);
    2538         5961 :   cgraph_function_version_info *vi = function_version ();
    2539         5961 :   if (vi != NULL)
    2540              :     {
    2541            0 :       fprintf (f, "  Version info: ");
    2542            0 :       if (vi->prev != NULL)
    2543              :         {
    2544            0 :           fprintf (f, "prev: ");
    2545            0 :           fprintf (f, "%s ", vi->prev->this_node->dump_asm_name ());
    2546              :         }
    2547            0 :       if (vi->next != NULL)
    2548              :         {
    2549            0 :           fprintf (f, "next: ");
    2550            0 :           fprintf (f, "%s ", vi->next->this_node->dump_asm_name ());
    2551              :         }
    2552            0 :       if (vi->dispatcher_resolver != NULL_TREE)
    2553            0 :         fprintf (f, "dispatcher: %s",
    2554            0 :                  lang_hooks.decl_printable_name (vi->dispatcher_resolver, 2));
    2555              : 
    2556            0 :       fprintf (f, "\n");
    2557              :     }
    2558         5961 :   fprintf (f, "  Function flags:");
    2559         5961 :   if (count.initialized_p ())
    2560              :     {
    2561         3711 :       fprintf (f, " count:");
    2562         3711 :       count.dump (f);
    2563              :     }
    2564         5961 :   if (tp_first_run > 0)
    2565           89 :     fprintf (f, " first_run:%" PRId64, (int64_t) tp_first_run);
    2566         5961 :   if (cgraph_node *origin = nested_function_origin (this))
    2567            0 :     fprintf (f, " nested in:%s", origin->dump_asm_name ());
    2568         5961 :   if (gimple_has_body_p (decl))
    2569         3952 :     fprintf (f, " body");
    2570         5961 :   if (process)
    2571            0 :     fprintf (f, " process");
    2572         5961 :   if (local)
    2573         1128 :     fprintf (f, " local");
    2574         5961 :   if (redefined_extern_inline)
    2575            0 :     fprintf (f, " redefined_extern_inline");
    2576         5961 :   if (only_called_at_startup)
    2577          417 :     fprintf (f, " only_called_at_startup");
    2578         5961 :   if (only_called_at_exit)
    2579            7 :     fprintf (f, " only_called_at_exit");
    2580         5961 :   if (tm_clone)
    2581            0 :     fprintf (f, " tm_clone");
    2582         5961 :   if (calls_comdat_local)
    2583            9 :     fprintf (f, " calls_comdat_local");
    2584         5961 :   if (icf_merged)
    2585           26 :     fprintf (f, " icf_merged");
    2586         5961 :   if (merged_comdat)
    2587            0 :     fprintf (f, " merged_comdat");
    2588         5961 :   if (merged_extern_inline)
    2589            0 :     fprintf (f, " merged_extern_inline");
    2590         5961 :   if (split_part)
    2591           23 :     fprintf (f, " split_part");
    2592         5961 :   if (indirect_call_target)
    2593          213 :     fprintf (f, " indirect_call_target");
    2594         5961 :   if (nonfreeing_fn)
    2595          343 :     fprintf (f, " nonfreeing_fn");
    2596         5961 :   if (DECL_STATIC_CONSTRUCTOR (decl))
    2597           48 :     fprintf (f," static_constructor (priority:%i)", get_init_priority ());
    2598         5961 :   if (DECL_STATIC_DESTRUCTOR (decl))
    2599            7 :     fprintf (f," static_destructor (priority:%i)", get_fini_priority ());
    2600         5961 :   if (frequency == NODE_FREQUENCY_HOT)
    2601           80 :     fprintf (f, " hot");
    2602         5961 :   if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
    2603           40 :     fprintf (f, " unlikely_executed");
    2604         5961 :   if (frequency == NODE_FREQUENCY_EXECUTED_ONCE)
    2605          724 :     fprintf (f, " executed_once");
    2606         5961 :   if (opt_for_fn (decl, optimize_size))
    2607          200 :     fprintf (f, " optimize_size");
    2608         5961 :   if (parallelized_function)
    2609            4 :     fprintf (f, " parallelized_function");
    2610         5961 :   if (DECL_IS_MALLOC (decl))
    2611           74 :     fprintf (f, " decl_is_malloc");
    2612         5961 :   if (DECL_IS_OPERATOR_NEW_P (decl))
    2613           35 :     fprintf (f, " %soperator_new",
    2614           35 :              DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
    2615         5961 :   if (DECL_IS_OPERATOR_DELETE_P (decl))
    2616           26 :     fprintf (f, " %soperator_delete",
    2617           26 :              DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
    2618              : 
    2619         5961 :   if (DECL_STATIC_CHAIN (decl))
    2620            6 :     fprintf (f, " static_chain");
    2621              : 
    2622         5961 :   fprintf (f, "\n");
    2623              : 
    2624         5961 :   if (thunk)
    2625              :     {
    2626           49 :       fprintf (f, "  Thunk");
    2627           49 :       thunk_info::get (this)->dump (f);
    2628              :     }
    2629         5912 :   else if (former_thunk_p ())
    2630              :     {
    2631           21 :       fprintf (f, "  Former thunk ");
    2632           21 :       thunk_info::get (this)->dump (f);
    2633              :     }
    2634         5891 :   else gcc_checking_assert (!thunk_info::get (this));
    2635              : 
    2636         5961 :   fprintf (f, "  Called by: ");
    2637              : 
    2638         5961 :   profile_count sum = profile_count::zero ();
    2639        13875 :   for (edge = callers; edge; edge = edge->next_caller)
    2640              :     {
    2641         7914 :       fprintf (f, "%s ", edge->caller->dump_asm_name ());
    2642         7914 :       edge->dump_edge_flags (f);
    2643         7914 :       if (edge->count.initialized_p ())
    2644         7670 :         sum += edge->count.ipa ();
    2645              :     }
    2646              : 
    2647         5961 :   fprintf (f, "\n  Calls: ");
    2648        20350 :   for (edge = callees; edge; edge = edge->next_callee)
    2649              :     {
    2650        14389 :       fprintf (f, "%s ", edge->callee->dump_asm_name ());
    2651        14389 :       edge->dump_edge_flags (f);
    2652              :     }
    2653         5961 :   fprintf (f, "\n");
    2654              : 
    2655         5961 :   if (!body_removed && count.ipa ().initialized_p ())
    2656              :     {
    2657          129 :       bool ok = true;
    2658          129 :       bool min = false;
    2659              :       ipa_ref *ref;
    2660              : 
    2661          129 :       FOR_EACH_ALIAS (this, ref)
    2662            0 :         if (dyn_cast <cgraph_node *> (ref->referring)->count.initialized_p ())
    2663            0 :           sum += dyn_cast <cgraph_node *> (ref->referring)->count.ipa ();
    2664              : 
    2665          129 :       if (inlined_to
    2666          129 :           || (symtab->state < EXPANSION
    2667          129 :               && ultimate_alias_target () == this && only_called_directly_p ()))
    2668            3 :         ok = !count.ipa ().differs_from_p (sum);
    2669          126 :       else if (count.ipa () > profile_count::from_gcov_type (100)
    2670          126 :                && count.ipa () < sum.apply_scale (99, 100))
    2671            0 :         ok = false, min = true;
    2672          129 :       if (!ok)
    2673              :         {
    2674            0 :           fprintf (f, "   Invalid sum of caller counts ");
    2675            0 :           sum.dump (f);
    2676            0 :           if (min)
    2677            0 :             fprintf (f, ", should be at most ");
    2678              :           else
    2679            0 :             fprintf (f, ", should be ");
    2680            0 :           count.ipa ().dump (f);
    2681            0 :           fprintf (f, "\n");
    2682              :         }
    2683              :     }
    2684              : 
    2685         6730 :   for (edge = indirect_calls; edge; edge = edge->next_callee)
    2686              :     {
    2687          769 :       fprintf (f, "   ");
    2688          769 :       edge->indirect_info->dump (f);
    2689              :     }
    2690         5961 : }
    2691              : 
    2692              : /* Dump call graph node to file F in graphviz format.  */
    2693              : 
    2694              : void
    2695            0 : cgraph_node::dump_graphviz (FILE *f)
    2696              : {
    2697            0 :   cgraph_edge *edge;
    2698              : 
    2699            0 :   for (edge = callees; edge; edge = edge->next_callee)
    2700              :     {
    2701            0 :       cgraph_node *callee = edge->callee;
    2702              : 
    2703            0 :       fprintf (f, "\t\"%s\" -> \"%s\"\n", dump_name (), callee->dump_name ());
    2704              :     }
    2705            0 : }
    2706              : 
    2707              : 
    2708              : /* Dump call graph node NODE to stderr.  */
    2709              : 
    2710              : DEBUG_FUNCTION void
    2711            0 : cgraph_node::debug (void)
    2712              : {
    2713            0 :   dump (stderr);
    2714            0 : }
    2715              : 
    2716              : /* Dump the callgraph to file F.  */
    2717              : 
    2718              : void
    2719           77 : cgraph_node::dump_cgraph (FILE *f)
    2720              : {
    2721           77 :   cgraph_node *node;
    2722              : 
    2723           77 :   fprintf (f, "callgraph:\n\n");
    2724          362 :   FOR_EACH_FUNCTION (node)
    2725          285 :     node->dump (f);
    2726           77 : }
    2727              : 
    2728              : /* Dump human readable information about the indirect call to F.  If NEWLINE
    2729              :    is true, it will be terminated by a newline.  */
    2730              : 
    2731              : void
    2732          916 : cgraph_indirect_call_info::dump (FILE *f, bool newline) const
    2733              : {
    2734          916 :   if (const cgraph_polymorphic_indirect_info *pii
    2735          916 :       = dyn_cast <const cgraph_polymorphic_indirect_info *> (this))
    2736              :     {
    2737          512 :       fprintf (f, "    indirect polymorphic callsite, %s, "
    2738              :                "calling param %i, offset " HOST_WIDE_INT_PRINT_DEC
    2739              :                "otr_token " HOST_WIDE_INT_PRINT_DEC ", otr_type ",
    2740          512 :                pii->vptr_changed ? "vptr_changed" : "vptr not changed",
    2741          512 :                pii->param_index, pii->offset, pii->otr_token);
    2742          512 :       print_generic_expr (f, pii->otr_type);
    2743          512 :       fprintf (f, ", context ");
    2744          512 :       pii->context.dump (f, false);
    2745              :     }
    2746          404 :   else if (const cgraph_simple_indirect_info *sii
    2747          404 :            = dyn_cast <const cgraph_simple_indirect_info *> (this))
    2748              :     {
    2749          404 :       if (sii->agg_contents)
    2750           49 :         fprintf (f, "    indirect %s callsite, calling param %i, "
    2751              :                  "offset " HOST_WIDE_INT_PRINT_DEC ", %s",
    2752           49 :                  sii->member_ptr ? "member ptr" : "aggregate",
    2753           49 :                  sii->param_index, sii->offset,
    2754           49 :                  sii->by_ref ? "by reference" : "by_value");
    2755          355 :       else if (sii->param_index >= 0)
    2756            8 :         fprintf (f, "    indirect simple callsite, calling param %i",
    2757              :                  sii->param_index);
    2758              :       else
    2759          347 :         fprintf (f, "    indirect simple callsite, not calling a known "
    2760              :                  "parameter");
    2761              :     }
    2762              :   else
    2763            0 :     fprintf (f, "    indirect callsite");
    2764              : 
    2765          916 :   fprintf (f, ", flags %i, num speculative call targets: %i", ecf_flags,
    2766          916 :            num_speculative_call_targets);
    2767          916 :   if (newline)
    2768          769 :     fprintf (f, "\n");
    2769          916 : }
    2770              : 
    2771              : /* Dump human readable information about the indirect call to stderr.  */
    2772              : 
    2773              : void
    2774            0 : cgraph_indirect_call_info::debug () const
    2775              : {
    2776            0 :   dump (stderr);
    2777            0 : }
    2778              : 
    2779              : /* Return true when the DECL can possibly be inlined.  */
    2780              : 
    2781              : bool
    2782    102266340 : cgraph_function_possibly_inlined_p (tree decl)
    2783              : {
    2784    102266340 :   if (!symtab->global_info_ready)
    2785     94180294 :     return !DECL_UNINLINABLE (decl);
    2786      8086046 :   return DECL_POSSIBLY_INLINED (decl);
    2787              : }
    2788              : 
    2789              : /* Return function availability.  See cgraph.h for description of individual
    2790              :    return values.  */
    2791              : enum availability
    2792    840196170 : cgraph_node::get_availability (symtab_node *ref)
    2793              : {
    2794    840196170 :   if (ref)
    2795              :     {
    2796    589778848 :       cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
    2797    589778848 :       if (cref)
    2798    589778848 :         ref = cref->inlined_to;
    2799              :     }
    2800    840196170 :   enum availability avail;
    2801    840196170 :   if (!analyzed && !in_other_partition)
    2802    499370378 :     avail = AVAIL_NOT_AVAILABLE;
    2803    340825792 :   else if (local)
    2804    100490388 :     avail = AVAIL_LOCAL;
    2805    240335404 :   else if (inlined_to)
    2806      2172892 :     avail = AVAIL_AVAILABLE;
    2807    238162512 :   else if (transparent_alias)
    2808          134 :     ultimate_alias_target (&avail, ref);
    2809    238162378 :   else if (ifunc_resolver
    2810    238162378 :            || lookup_attribute ("noipa", DECL_ATTRIBUTES (decl)))
    2811      3970020 :     avail = AVAIL_INTERPOSABLE;
    2812    234192358 :   else if (!externally_visible)
    2813     30851246 :     avail = AVAIL_AVAILABLE;
    2814              :   /* If this is a reference from symbol itself and there are no aliases, we
    2815              :      may be sure that the symbol was not interposed by something else because
    2816              :      the symbol itself would be unreachable otherwise.
    2817              : 
    2818              :      Also comdat groups are always resolved in groups.  */
    2819        20278 :   else if ((this == ref && !has_aliases_p ())
    2820    203341831 :            || (ref && get_comdat_group ()
    2821      1155449 :                && get_comdat_group () == ref->get_comdat_group ()))
    2822        23021 :     avail = AVAIL_AVAILABLE;
    2823              :   /* Inline functions are safe to be analyzed even if their symbol can
    2824              :      be overwritten at runtime.  It is not meaningful to enforce any sane
    2825              :      behavior on replacing inline function by different body.  */
    2826    203318091 :   else if (DECL_DECLARED_INLINE_P (decl))
    2827     75944704 :     avail = AVAIL_AVAILABLE;
    2828              : 
    2829              :   /* If the function can be overwritten, return OVERWRITABLE.  Take
    2830              :      care at least of two notable extensions - the COMDAT functions
    2831              :      used to share template instantiations in C++ (this is symmetric
    2832              :      to code cp_cannot_inline_tree_fn and probably shall be shared and
    2833              :      the inlinability hooks completely eliminated).  */
    2834              : 
    2835    127373387 :   else if (decl_replaceable_p (decl, semantic_interposition)
    2836    127373387 :            && !DECL_EXTERNAL (decl))
    2837      9338544 :     avail = AVAIL_INTERPOSABLE;
    2838    118034843 :   else avail = AVAIL_AVAILABLE;
    2839              : 
    2840    840196170 :   return avail;
    2841              : }
    2842              : 
    2843              : /* Worker for cgraph_node_can_be_local_p.  */
    2844              : static bool
    2845       792456 : cgraph_node_cannot_be_local_p_1 (cgraph_node *node, void *)
    2846              : {
    2847       792456 :   return !(!node->force_output
    2848       771204 :            && !node->ref_by_asm
    2849       771200 :            && !node->ifunc_resolver
    2850              :            /* Limitation of gas requires us to output targets of symver aliases
    2851              :               as global symbols.  This is binutils PR 25295.  */
    2852       771160 :            && !node->symver
    2853       771160 :            && ((DECL_COMDAT (node->decl)
    2854       315015 :                 && !node->forced_by_abi
    2855       296921 :                 && !node->used_from_object_file_p ()
    2856       296921 :                 && !node->same_comdat_group)
    2857       517100 :                || !node->externally_visible)
    2858       406877 :            && !DECL_STATIC_CONSTRUCTOR (node->decl)
    2859       405020 :            && !DECL_STATIC_DESTRUCTOR (node->decl));
    2860              : }
    2861              : 
    2862              : /* Return true if cgraph_node can be made local for API change.
    2863              :    Extern inline functions and C++ COMDAT functions can be made local
    2864              :    at the expense of possible code size growth if function is used in multiple
    2865              :    compilation units.  */
    2866              : bool
    2867      1069007 : cgraph_node::can_be_local_p (void)
    2868              : {
    2869      1069007 :   return (!address_taken
    2870      1069007 :           && !call_for_symbol_thunks_and_aliases (cgraph_node_cannot_be_local_p_1,
    2871      1069007 :                                                 NULL, true));
    2872              : }
    2873              : 
    2874              : /* Call callback on cgraph_node, thunks and aliases associated to cgraph_node.
    2875              :    When INCLUDE_OVERWRITABLE is false, overwritable symbols are
    2876              :    skipped.  When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
    2877              :    skipped.  */
    2878              : bool
    2879    165827467 : cgraph_node::call_for_symbol_thunks_and_aliases (bool (*callback)
    2880              :                                                    (cgraph_node *, void *),
    2881              :                                                  void *data,
    2882              :                                                  bool include_overwritable,
    2883              :                                                  bool exclude_virtual_thunks)
    2884              : {
    2885    165827467 :   cgraph_edge *e;
    2886    165827467 :   ipa_ref *ref;
    2887    165827467 :   enum availability avail = AVAIL_AVAILABLE;
    2888              : 
    2889    165827467 :   if (include_overwritable
    2890    165827467 :       || (avail = get_availability ()) > AVAIL_INTERPOSABLE)
    2891              :     {
    2892    165816385 :       if (callback (this, data))
    2893              :         return true;
    2894              :     }
    2895    176699147 :   FOR_EACH_ALIAS (this, ref)
    2896              :     {
    2897     16320051 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    2898     16320051 :       if (include_overwritable
    2899     16320051 :           || alias->get_availability () > AVAIL_INTERPOSABLE)
    2900     16319949 :         if (alias->call_for_symbol_thunks_and_aliases (callback, data,
    2901              :                                                      include_overwritable,
    2902              :                                                      exclude_virtual_thunks))
    2903              :           return true;
    2904              :     }
    2905    160379096 :   if (avail <= AVAIL_INTERPOSABLE)
    2906              :     return false;
    2907    166737269 :   for (e = callers; e; e = e->next_caller)
    2908      6369255 :     if (e->caller->thunk
    2909         2540 :         && (include_overwritable
    2910          195 :             || e->caller->get_availability () > AVAIL_INTERPOSABLE)
    2911      6371795 :         && !(exclude_virtual_thunks
    2912           22 :              && thunk_info::get (e->caller)->virtual_offset_p))
    2913         2528 :       if (e->caller->call_for_symbol_thunks_and_aliases (callback, data,
    2914              :                                                        include_overwritable,
    2915              :                                                        exclude_virtual_thunks))
    2916              :         return true;
    2917              : 
    2918              :   return false;
    2919              : }
    2920              : 
    2921              : /* Worker to bring NODE local.  */
    2922              : 
    2923              : bool
    2924            0 : cgraph_node::make_local (cgraph_node *node, void *)
    2925              : {
    2926            0 :   gcc_checking_assert (node->can_be_local_p ());
    2927            0 :   if (DECL_COMDAT (node->decl) || DECL_EXTERNAL (node->decl))
    2928              :     {
    2929            0 :       node->make_decl_local ();
    2930            0 :       node->set_section (NULL);
    2931            0 :       node->set_comdat_group (NULL);
    2932            0 :       node->externally_visible = false;
    2933            0 :       node->forced_by_abi = false;
    2934            0 :       node->local = true;
    2935            0 :       node->unique_name = ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
    2936            0 :                            || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
    2937            0 :                            && !flag_incremental_link);
    2938            0 :       node->resolution = LDPR_PREVAILING_DEF_IRONLY;
    2939            0 :       gcc_assert (node->get_availability () == AVAIL_LOCAL);
    2940              :     }
    2941            0 :   return false;
    2942              : }
    2943              : 
    2944              : /* Bring cgraph node local.  */
    2945              : 
    2946              : void
    2947            0 : cgraph_node::make_local (void)
    2948              : {
    2949            0 :   call_for_symbol_thunks_and_aliases (cgraph_node::make_local, NULL, true);
    2950            0 : }
    2951              : 
    2952              : /* Worker to set nothrow flag.  */
    2953              : 
    2954              : static void
    2955       993017 : set_nothrow_flag_1 (cgraph_node *node, bool nothrow, bool non_call,
    2956              :                     bool *changed)
    2957              : {
    2958       993017 :   cgraph_edge *e;
    2959              : 
    2960       993017 :   if (nothrow && !TREE_NOTHROW (node->decl))
    2961              :     {
    2962              :       /* With non-call exceptions we can't say for sure if other function body
    2963              :          was not possibly optimized to still throw.  */
    2964       992992 :       if (!non_call || node->binds_to_current_def_p ())
    2965              :         {
    2966       988074 :           TREE_NOTHROW (node->decl) = true;
    2967       988074 :           *changed = true;
    2968      2416601 :           for (e = node->callers; e; e = e->next_caller)
    2969      1428527 :             e->can_throw_external = false;
    2970              :         }
    2971              :     }
    2972            0 :   else if (!nothrow && TREE_NOTHROW (node->decl))
    2973              :     {
    2974            0 :       TREE_NOTHROW (node->decl) = false;
    2975            0 :       *changed = true;
    2976              :     }
    2977       993017 :   ipa_ref *ref;
    2978      1049372 :   FOR_EACH_ALIAS (node, ref)
    2979              :     {
    2980        56355 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    2981        56355 :       if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
    2982        55930 :         set_nothrow_flag_1 (alias, nothrow, non_call, changed);
    2983              :     }
    2984      2458443 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    2985      1465426 :     if (e->caller->thunk
    2986      1465426 :         && (!nothrow || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    2987          138 :       set_nothrow_flag_1 (e->caller, nothrow, non_call, changed);
    2988       993017 : }
    2989              : 
    2990              : /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
    2991              :    if any to NOTHROW.  */
    2992              : 
    2993              : bool
    2994       944268 : cgraph_node::set_nothrow_flag (bool nothrow)
    2995              : {
    2996       944268 :   bool changed = false;
    2997       944268 :   bool non_call = opt_for_fn (decl, flag_non_call_exceptions);
    2998              : 
    2999       944268 :   if (!nothrow || get_availability () > AVAIL_INTERPOSABLE)
    3000       936842 :     set_nothrow_flag_1 (this, nothrow, non_call, &changed);
    3001              :   else
    3002              :     {
    3003              :       ipa_ref *ref;
    3004              : 
    3005        14989 :       FOR_EACH_ALIAS (this, ref)
    3006              :         {
    3007         7563 :           cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    3008         7563 :           if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
    3009          107 :             set_nothrow_flag_1 (alias, nothrow, non_call, &changed);
    3010              :         }
    3011              :     }
    3012       944268 :   return changed;
    3013              : }
    3014              : 
    3015              : /* Worker to set malloc flag.  */
    3016              : static void
    3017        31296 : set_malloc_flag_1 (cgraph_node *node, bool malloc_p, bool *changed)
    3018              : {
    3019        31296 :   if (malloc_p && !DECL_IS_MALLOC (node->decl))
    3020              :     {
    3021        30907 :       DECL_IS_MALLOC (node->decl) = true;
    3022        30907 :       *changed = true;
    3023              :     }
    3024              : 
    3025        31296 :   ipa_ref *ref;
    3026        31297 :   FOR_EACH_ALIAS (node, ref)
    3027              :     {
    3028            1 :       cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    3029            1 :       if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    3030            1 :         set_malloc_flag_1 (alias, malloc_p, changed);
    3031              :     }
    3032              : 
    3033        64637 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    3034        33341 :     if (e->caller->thunk
    3035        33341 :         && (!malloc_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    3036            0 :       set_malloc_flag_1 (e->caller, malloc_p, changed);
    3037        31296 : }
    3038              : 
    3039              : /* Set DECL_IS_MALLOC on NODE's decl and on NODE's aliases if any.  */
    3040              : 
    3041              : bool
    3042        31295 : cgraph_node::set_malloc_flag (bool malloc_p)
    3043              : {
    3044        31295 :   bool changed = false;
    3045              : 
    3046        31295 :   if (!malloc_p || get_availability () > AVAIL_INTERPOSABLE)
    3047        31295 :     set_malloc_flag_1 (this, malloc_p, &changed);
    3048              :   else
    3049              :     {
    3050              :       ipa_ref *ref;
    3051              : 
    3052            0 :       FOR_EACH_ALIAS (this, ref)
    3053              :         {
    3054            0 :           cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    3055            0 :           if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    3056            0 :             set_malloc_flag_1 (alias, malloc_p, &changed);
    3057              :         }
    3058              :     }
    3059        31295 :   return changed;
    3060              : }
    3061              : 
    3062              : /* Worker to set malloc flag.  */
    3063              : static void
    3064       255534 : add_detected_attribute_1 (cgraph_node *node, const char *attr, bool *changed)
    3065              : {
    3066       255534 :   if (!lookup_attribute (attr, DECL_ATTRIBUTES (node->decl)))
    3067              :     {
    3068       229440 :       DECL_ATTRIBUTES (node->decl) = tree_cons (get_identifier (attr),
    3069       229440 :                                          NULL_TREE, DECL_ATTRIBUTES (node->decl));
    3070       229440 :       *changed = true;
    3071              :     }
    3072              : 
    3073       255534 :   ipa_ref *ref;
    3074       256096 :   FOR_EACH_ALIAS (node, ref)
    3075              :     {
    3076          562 :       cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    3077          562 :       if (alias->get_availability () > AVAIL_INTERPOSABLE)
    3078          134 :         add_detected_attribute_1 (alias, attr, changed);
    3079              :     }
    3080              : 
    3081       805962 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    3082       550428 :     if (e->caller->thunk
    3083       550428 :         && (e->caller->get_availability () > AVAIL_INTERPOSABLE))
    3084           17 :       add_detected_attribute_1 (e->caller, attr, changed);
    3085       255534 : }
    3086              : 
    3087              : /* Add attribute ATTR to function and its aliases.  */
    3088              : 
    3089              : bool
    3090       259297 : cgraph_node::add_detected_attribute (const char *attr)
    3091              : {
    3092       259297 :   bool changed = false;
    3093              : 
    3094       259297 :   if (get_availability () > AVAIL_INTERPOSABLE)
    3095       255383 :     add_detected_attribute_1 (this, attr, &changed);
    3096              :   else
    3097              :     {
    3098              :       ipa_ref *ref;
    3099              : 
    3100         3938 :       FOR_EACH_ALIAS (this, ref)
    3101              :         {
    3102           24 :           cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    3103           24 :           if (alias->get_availability () > AVAIL_INTERPOSABLE)
    3104            0 :             add_detected_attribute_1 (alias, attr, &changed);
    3105              :         }
    3106              :     }
    3107       259297 :   return changed;
    3108              : }
    3109              : 
    3110              : /* Worker to set noreturng flag.  */
    3111              : static void
    3112        27545 : set_noreturn_flag_1 (cgraph_node *node, bool noreturn_p, bool *changed)
    3113              : {
    3114        27545 :   if (noreturn_p && !TREE_THIS_VOLATILE (node->decl))
    3115              :     {
    3116        27545 :       TREE_THIS_VOLATILE (node->decl) = true;
    3117        27545 :       *changed = true;
    3118              :     }
    3119              : 
    3120        27545 :   ipa_ref *ref;
    3121        28190 :   FOR_EACH_ALIAS (node, ref)
    3122              :     {
    3123          645 :       cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    3124          645 :       if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    3125          645 :         set_noreturn_flag_1 (alias, noreturn_p, changed);
    3126              :     }
    3127              : 
    3128        44137 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    3129        16592 :     if (e->caller->thunk
    3130        16592 :         && (!noreturn_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    3131           20 :       set_noreturn_flag_1 (e->caller, noreturn_p, changed);
    3132        27545 : }
    3133              : 
    3134              : /* Set TREE_THIS_VOLATILE on NODE's decl and on NODE's aliases if any.  */
    3135              : 
    3136              : bool
    3137        26888 : cgraph_node::set_noreturn_flag (bool noreturn_p)
    3138              : {
    3139        26888 :   bool changed = false;
    3140              : 
    3141        26888 :   if (!noreturn_p || get_availability () > AVAIL_INTERPOSABLE)
    3142        26871 :     set_noreturn_flag_1 (this, noreturn_p, &changed);
    3143              :   else
    3144              :     {
    3145              :       ipa_ref *ref;
    3146              : 
    3147           34 :       FOR_EACH_ALIAS (this, ref)
    3148              :         {
    3149           17 :           cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    3150           17 :           if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    3151            9 :             set_noreturn_flag_1 (alias, noreturn_p, &changed);
    3152              :         }
    3153              :     }
    3154        26888 :   return changed;
    3155              : }
    3156              : 
    3157              : /* Worker to set_const_flag.  */
    3158              : 
    3159              : static void
    3160      1018852 : set_const_flag_1 (cgraph_node *node, bool set_const, bool looping,
    3161              :                   bool *changed)
    3162              : {
    3163              :   /* Static constructors and destructors without a side effect can be
    3164              :      optimized out.  */
    3165      1018852 :   if (set_const && !looping)
    3166              :     {
    3167      1012304 :       if (DECL_STATIC_CONSTRUCTOR (node->decl))
    3168              :         {
    3169          293 :           DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
    3170          293 :           *changed = true;
    3171              :         }
    3172      1012304 :       if (DECL_STATIC_DESTRUCTOR (node->decl))
    3173              :         {
    3174            1 :           DECL_STATIC_DESTRUCTOR (node->decl) = 0;
    3175            1 :           *changed = true;
    3176              :         }
    3177              :     }
    3178      1018852 :   if (!set_const)
    3179              :     {
    3180         2691 :       if (TREE_READONLY (node->decl))
    3181              :         {
    3182          158 :           TREE_READONLY (node->decl) = 0;
    3183          158 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    3184          158 :           *changed = true;
    3185              :         }
    3186              :     }
    3187              :   else
    3188              :     {
    3189              :       /* Consider function:
    3190              : 
    3191              :          bool a(int *p)
    3192              :          {
    3193              :            return *p==*p;
    3194              :          }
    3195              : 
    3196              :          During early optimization we will turn this into:
    3197              : 
    3198              :          bool a(int *p)
    3199              :          {
    3200              :            return true;
    3201              :          }
    3202              : 
    3203              :          Now if this function will be detected as CONST however when interposed
    3204              :          it may end up being just pure.  We always must assume the worst
    3205              :          scenario here.  */
    3206      1016161 :       if (TREE_READONLY (node->decl))
    3207              :         {
    3208          783 :           if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
    3209              :             {
    3210          438 :               DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    3211          438 :               *changed = true;
    3212              :             }
    3213              :         }
    3214      1015378 :       else if (node->binds_to_current_def_p ())
    3215              :         {
    3216       176338 :           TREE_READONLY (node->decl) = true;
    3217       176338 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
    3218       176338 :           DECL_PURE_P (node->decl) = false;
    3219       176338 :           *changed = true;
    3220              :         }
    3221              :       else
    3222              :         {
    3223       839040 :           if (dump_file && (dump_flags & TDF_DETAILS))
    3224            0 :             fprintf (dump_file, "Dropping state to PURE because function does "
    3225              :                      "not bind to current def.\n");
    3226       839040 :           if (!DECL_PURE_P (node->decl))
    3227              :             {
    3228       399477 :               DECL_PURE_P (node->decl) = true;
    3229       399477 :               DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
    3230       399477 :               *changed = true;
    3231              :             }
    3232       439563 :           else if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
    3233              :             {
    3234          140 :               DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    3235          140 :               *changed = true;
    3236              :             }
    3237              :         }
    3238              :     }
    3239              : 
    3240      1018852 :   ipa_ref *ref;
    3241      1129020 :   FOR_EACH_ALIAS (node, ref)
    3242              :     {
    3243       110168 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    3244       110168 :       if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
    3245       110105 :         set_const_flag_1 (alias, set_const, looping, changed);
    3246              :     }
    3247      1018948 :   for (struct cgraph_node *n = node->simd_clones; n != NULL;
    3248           96 :        n = n->simdclone->next_clone)
    3249           96 :     set_const_flag_1 (n, set_const, looping, changed);
    3250      2764210 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    3251      1745358 :     if (e->caller->thunk
    3252      1745358 :         && (!set_const || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    3253              :       {
    3254              :         /* Virtual thunks access virtual offset in the vtable, so they can
    3255              :            only be pure, never const.  */
    3256          369 :         if (set_const
    3257          369 :             && (thunk_info::get (e->caller)->virtual_offset_p
    3258          238 :                 || !node->binds_to_current_def_p (e->caller)))
    3259          131 :           *changed |= e->caller->set_pure_flag (true, looping);
    3260              :         else
    3261          238 :           set_const_flag_1 (e->caller, set_const, looping, changed);
    3262              :       }
    3263      1018852 : }
    3264              : 
    3265              : /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
    3266              :    If SET_CONST if false, clear the flag.
    3267              : 
    3268              :    When setting the flag be careful about possible interposition and
    3269              :    do not set the flag for functions that can be interposed and set pure
    3270              :    flag for functions that can bind to other definition.
    3271              : 
    3272              :    Return true if any change was done. */
    3273              : 
    3274              : bool
    3275       935239 : cgraph_node::set_const_flag (bool set_const, bool looping)
    3276              : {
    3277       935239 :   bool changed = false;
    3278       935239 :   if (!set_const || get_availability () > AVAIL_INTERPOSABLE)
    3279       908181 :     set_const_flag_1 (this, set_const, looping, &changed);
    3280              :   else
    3281              :     {
    3282              :       ipa_ref *ref;
    3283              : 
    3284        27974 :       FOR_EACH_ALIAS (this, ref)
    3285              :         {
    3286          916 :           cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    3287          916 :           if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
    3288          232 :             set_const_flag_1 (alias, set_const, looping, &changed);
    3289              :         }
    3290              :     }
    3291       935239 :   return changed;
    3292              : }
    3293              : 
    3294              : /* Info used by set_pure_flag_1.  */
    3295              : 
    3296              : struct set_pure_flag_info
    3297              : {
    3298              :   bool pure;
    3299              :   bool looping;
    3300              :   bool changed;
    3301              : };
    3302              : 
    3303              : /* Worker to set_pure_flag.  */
    3304              : 
    3305              : static bool
    3306       376650 : set_pure_flag_1 (cgraph_node *node, void *data)
    3307              : {
    3308       376650 :   struct set_pure_flag_info *info = (struct set_pure_flag_info *)data;
    3309              :   /* Static constructors and destructors without a side effect can be
    3310              :      optimized out.  */
    3311       376650 :   if (info->pure && !info->looping)
    3312              :     {
    3313       308972 :       if (DECL_STATIC_CONSTRUCTOR (node->decl))
    3314              :         {
    3315            0 :           DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
    3316            0 :           info->changed = true;
    3317              :         }
    3318       308972 :       if (DECL_STATIC_DESTRUCTOR (node->decl))
    3319              :         {
    3320            0 :           DECL_STATIC_DESTRUCTOR (node->decl) = 0;
    3321            0 :           info->changed = true;
    3322              :         }
    3323              :     }
    3324       376650 :   if (info->pure)
    3325              :     {
    3326       373959 :       if (!DECL_PURE_P (node->decl) && !TREE_READONLY (node->decl))
    3327              :         {
    3328       373429 :           DECL_PURE_P (node->decl) = true;
    3329       373429 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = info->looping;
    3330       373429 :           info->changed = true;
    3331              :         }
    3332          530 :       else if (DECL_LOOPING_CONST_OR_PURE_P (node->decl)
    3333          530 :                && !info->looping)
    3334              :         {
    3335          253 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    3336          253 :           info->changed = true;
    3337              :         }
    3338              :     }
    3339              :   else
    3340              :     {
    3341         2691 :       if (DECL_PURE_P (node->decl))
    3342              :         {
    3343           75 :           DECL_PURE_P (node->decl) = false;
    3344           75 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    3345           75 :           info->changed = true;
    3346              :         }
    3347              :     }
    3348       376650 :   return false;
    3349              : }
    3350              : 
    3351              : /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
    3352              :    if any to PURE.
    3353              : 
    3354              :    When setting the flag, be careful about possible interposition.
    3355              :    Return true if any change was done. */
    3356              : 
    3357              : bool
    3358       386711 : cgraph_node::set_pure_flag (bool pure, bool looping)
    3359              : {
    3360       386711 :   struct set_pure_flag_info info = {pure, looping, false};
    3361       386711 :   call_for_symbol_thunks_and_aliases (set_pure_flag_1, &info, !pure, true);
    3362       386711 :   for (struct cgraph_node *n = simd_clones; n != NULL;
    3363            0 :        n = n->simdclone->next_clone)
    3364            0 :     set_pure_flag_1 (n, &info);
    3365       386711 :   return info.changed;
    3366              : }
    3367              : 
    3368              : /* Return true when cgraph_node cannot return or throw and thus
    3369              :    it is safe to ignore its side effects for IPA analysis.  */
    3370              : 
    3371              : bool
    3372     15073311 : cgraph_node::cannot_return_p (void)
    3373              : {
    3374     15073311 :   int flags = flags_from_decl_or_type (decl);
    3375     15073311 :   if (!opt_for_fn (decl, flag_exceptions))
    3376      4784950 :     return (flags & ECF_NORETURN) != 0;
    3377              :   else
    3378     10288361 :     return ((flags & (ECF_NORETURN | ECF_NOTHROW))
    3379     10288361 :              == (ECF_NORETURN | ECF_NOTHROW));
    3380              : }
    3381              : 
    3382              : /* Return true when call of edge cannot lead to return from caller
    3383              :    and thus it is safe to ignore its side effects for IPA analysis
    3384              :    when computing side effects of the caller.
    3385              :    FIXME: We could actually mark all edges that have no reaching
    3386              :    patch to the exit block or throw to get better results.  */
    3387              : bool
    3388      3206435 : cgraph_edge::cannot_lead_to_return_p (void)
    3389              : {
    3390      3206435 :   if (caller->cannot_return_p ())
    3391              :     return true;
    3392      3116876 :   if (indirect_unknown_callee)
    3393              :     {
    3394        86974 :       int flags = indirect_info->ecf_flags;
    3395        86974 :       if (!opt_for_fn (caller->decl, flag_exceptions))
    3396        20098 :         return (flags & ECF_NORETURN) != 0;
    3397              :       else
    3398        66876 :         return ((flags & (ECF_NORETURN | ECF_NOTHROW))
    3399        66876 :                  == (ECF_NORETURN | ECF_NOTHROW));
    3400              :     }
    3401              :   else
    3402      3029902 :     return callee->cannot_return_p ();
    3403              : }
    3404              : 
    3405              : /* Return true if the edge after scaling it profile by SCALE
    3406              :    may be considered hot.  */
    3407              : 
    3408              : bool
    3409      5709850 : cgraph_edge::maybe_hot_p (sreal scale)
    3410              : {
    3411              :   /* Never consider calls in functions optimized for size hot.  */
    3412      5709850 :   if (opt_for_fn (caller->decl, optimize_size))
    3413              :     return false;
    3414              : 
    3415              :   /* If reliable IPA count is available, just use it.  */
    3416      5645340 :   profile_count c = count.ipa ();
    3417      5645340 :   if (c.reliable_p ()
    3418      5645340 :       || (c.quality () == AFDO && c.nonzero_p ()))
    3419       779263 :     return maybe_hot_count_p (NULL, c * scale);
    3420              : 
    3421              :   /* In auto-FDO, count 0 may lead to hot code in case the
    3422              :      call is simply not called often enough to receive some samples.  */
    3423      4866077 :   if ((c.quality () == AFDO
    3424      4866077 :        || count.quality () == GUESSED_GLOBAL0_ADJUSTED)
    3425      4866077 :       && callee && callee->count.quality () == AFDO)
    3426            0 :     return maybe_hot_count_p (NULL, c.force_nonzero () * scale);
    3427              : 
    3428              :   /* See if we can determine hotness using caller frequency.  */
    3429      4866077 :   if (caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
    3430      4862530 :       || (callee
    3431      4453380 :           && callee->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED))
    3432              :     return false;
    3433      4860278 :   if (caller->frequency > NODE_FREQUENCY_UNLIKELY_EXECUTED
    3434      4860278 :       && (callee
    3435      4451128 :           && callee->frequency <= NODE_FREQUENCY_EXECUTED_ONCE))
    3436              :     return false;
    3437              :   /* ??? This may make sense for hot functions determined by
    3438              :      user attribute, but if function is hot by profile, it may
    3439              :      contains non-hot calls.  In most practical cases this case
    3440              :      is handled by the reliable ipa count above, but i.e. after
    3441              :      inlining function with no profile to function with profile
    3442              :      we get here.. */
    3443      4803825 :   if (caller->frequency == NODE_FREQUENCY_HOT)
    3444              :     return true;
    3445              : 
    3446              :   /* Use IPA count and if it s not available apply local heuristics.  */
    3447      4803823 :   if (c.initialized_p ())
    3448              :     {
    3449              :       /* A special case; AFDO zero means that function may quite possibly
    3450              :          be executed few times per execution.  If scale is large, we still
    3451              :          want to consider the call hot.  */
    3452            0 :       if (c.quality () == AFDO)
    3453            0 :         c = c.force_nonzero ();
    3454            0 :       return maybe_hot_count_p (NULL, c * scale);
    3455              :     }
    3456      4803823 :   if (!count.initialized_p ())
    3457              :     return true;
    3458      3520332 :   cgraph_node *where = caller->inlined_to ? caller->inlined_to : caller;
    3459      3520332 :   if (!where->count.initialized_p ())
    3460              :     return true;
    3461      3520332 :   c = count * scale;
    3462      3520332 :   if (caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE)
    3463              :     {
    3464        76866 :       if (c * 2 < where->count * 3)
    3465        19901 :         return false;
    3466              :     }
    3467      3443466 :   else if (c * param_hot_bb_frequency_fraction < where->count)
    3468       393053 :     return false;
    3469              :   return true;
    3470              : }
    3471              : 
    3472              : /* Return true if the edge may be considered hot.  */
    3473              : 
    3474              : bool
    3475      2250598 : cgraph_edge::maybe_hot_p ()
    3476              : {
    3477      2250598 :   return maybe_hot_p (1);
    3478              : }
    3479              : 
    3480              : /* Worker for cgraph_can_remove_if_no_direct_calls_p.  */
    3481              : 
    3482              : static bool
    3483       694395 : nonremovable_p (cgraph_node *node, void *)
    3484              : {
    3485       694395 :   return !node->can_remove_if_no_direct_calls_and_refs_p ();
    3486              : }
    3487              : 
    3488              : /* Return true if whole comdat group can be removed if there are no direct
    3489              :    calls to THIS.  */
    3490              : 
    3491              : bool
    3492       953104 : cgraph_node::can_remove_if_no_direct_calls_p (bool will_inline)
    3493              : {
    3494       953104 :   struct ipa_ref *ref;
    3495              : 
    3496              :   /* For local symbols or non-comdat group it is the same as
    3497              :      can_remove_if_no_direct_calls_p.  */
    3498       953104 :   if (!externally_visible || !same_comdat_group)
    3499              :     {
    3500       700280 :       if (DECL_EXTERNAL (decl))
    3501              :         return true;
    3502       700280 :       if (address_taken)
    3503              :         return false;
    3504       667398 :       return !call_for_symbol_and_aliases (nonremovable_p, NULL, true);
    3505              :     }
    3506              : 
    3507       252824 :   if (will_inline && address_taken)
    3508              :     return false;
    3509              : 
    3510              :   /* Otherwise check if we can remove the symbol itself and then verify
    3511              :      that only uses of the comdat groups are direct call to THIS
    3512              :      or its aliases.   */
    3513       252824 :   if (!can_remove_if_no_direct_calls_and_refs_p ())
    3514              :     return false;
    3515              : 
    3516              :   /* Check that all refs come from within the comdat group.  */
    3517       487842 :   for (int i = 0; iterate_referring (i, ref); i++)
    3518       247721 :     if (ref->referring->get_comdat_group () != get_comdat_group ())
    3519              :       return false;
    3520              : 
    3521       240121 :   struct cgraph_node *target = ultimate_alias_target ();
    3522       480242 :   for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
    3523       723301 :        next != this; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    3524              :     {
    3525       253735 :       if (!externally_visible)
    3526            0 :         continue;
    3527       253735 :       if (!next->alias
    3528       253735 :           && !next->can_remove_if_no_direct_calls_and_refs_p ())
    3529              :         return false;
    3530              : 
    3531              :       /* If we see different symbol than THIS, be sure to check calls.  */
    3532       253735 :       if (next->ultimate_alias_target () != target)
    3533        22177 :         for (cgraph_edge *e = next->callers; e; e = e->next_caller)
    3534         4802 :           if (e->caller->get_comdat_group () != get_comdat_group ()
    3535         4802 :               || will_inline)
    3536              :             return false;
    3537              : 
    3538              :       /* If function is not being inlined, we care only about
    3539              :          references outside of the comdat group.  */
    3540       251840 :       if (!will_inline)
    3541       253043 :         for (int i = 0; next->iterate_referring (i, ref); i++)
    3542        11453 :           if (ref->referring->get_comdat_group () != get_comdat_group ())
    3543              :             return false;
    3544              :     }
    3545              :   return true;
    3546              : }
    3547              : 
    3548              : /* Return true when function cgraph_node can be expected to be removed
    3549              :    from program when direct calls in this compilation unit are removed.
    3550              : 
    3551              :    As a special case COMDAT functions are
    3552              :    cgraph_can_remove_if_no_direct_calls_p while the are not
    3553              :    cgraph_only_called_directly_p (it is possible they are called from other
    3554              :    unit)
    3555              : 
    3556              :    This function behaves as cgraph_only_called_directly_p because eliminating
    3557              :    all uses of COMDAT function does not make it necessarily disappear from
    3558              :    the program unless we are compiling whole program or we do LTO.  In this
    3559              :    case we know we win since dynamic linking will not really discard the
    3560              :    linkonce section.  */
    3561              : 
    3562              : bool
    3563      3199485 : cgraph_node::will_be_removed_from_program_if_no_direct_calls_p
    3564              :          (bool will_inline)
    3565              : {
    3566      3199485 :   gcc_assert (!inlined_to);
    3567      3199485 :   if (DECL_EXTERNAL (decl))
    3568              :     return true;
    3569              : 
    3570      3199485 :   if (!in_lto_p && !flag_whole_program)
    3571              :     {
    3572              :       /* If the symbol is in comdat group, we need to verify that whole comdat
    3573              :          group becomes unreachable.  Technically we could skip references from
    3574              :          within the group, too.  */
    3575      2983736 :       if (!only_called_directly_p ())
    3576              :         return false;
    3577       758360 :       if (same_comdat_group && externally_visible)
    3578              :         {
    3579            0 :           struct cgraph_node *target = ultimate_alias_target ();
    3580              : 
    3581            0 :           if (will_inline && address_taken)
    3582              :             return true;
    3583            0 :           for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
    3584            0 :                next != this;
    3585            0 :                next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    3586              :             {
    3587            0 :               if (!externally_visible)
    3588            0 :                 continue;
    3589            0 :               if (!next->alias
    3590            0 :                   && !next->only_called_directly_p ())
    3591              :                 return false;
    3592              : 
    3593              :               /* If we see different symbol than THIS,
    3594              :                  be sure to check calls.  */
    3595            0 :               if (next->ultimate_alias_target () != target)
    3596            0 :                 for (cgraph_edge *e = next->callers; e; e = e->next_caller)
    3597            0 :                   if (e->caller->get_comdat_group () != get_comdat_group ()
    3598            0 :                       || will_inline)
    3599              :                     return false;
    3600              :             }
    3601              :         }
    3602              :       return true;
    3603              :     }
    3604              :   else
    3605       215749 :     return can_remove_if_no_direct_calls_p (will_inline);
    3606              : }
    3607              : 
    3608              : 
    3609              : /* Worker for cgraph_only_called_directly_p.  */
    3610              : 
    3611              : static bool
    3612     16501163 : cgraph_not_only_called_directly_p_1 (cgraph_node *node, void *)
    3613              : {
    3614     16501163 :   return !node->only_called_directly_or_aliased_p ();
    3615              : }
    3616              : 
    3617              : /* Return true when function cgraph_node and all its aliases are only called
    3618              :    directly.
    3619              :    i.e. it is not externally visible, address was not taken and
    3620              :    it is not used in any other non-standard way.  */
    3621              : 
    3622              : bool
    3623     16348380 : cgraph_node::only_called_directly_p (void)
    3624              : {
    3625     16348380 :   gcc_assert (ultimate_alias_target () == this);
    3626     16348380 :   return !call_for_symbol_and_aliases (cgraph_not_only_called_directly_p_1,
    3627     16348380 :                                        NULL, true);
    3628              : }
    3629              : 
    3630              : /* Returns TRUE iff THIS is a descendant of N in the clone tree.  */
    3631              : 
    3632              : bool
    3633           29 : cgraph_node::is_clone_of (cgraph_node *n) const
    3634              : {
    3635           29 :   for (cgraph_node *walker = clone_of; walker; walker = walker->clone_of)
    3636            0 :     if (walker == n)
    3637              :       return true;
    3638              :   return false;
    3639              : }
    3640              : 
    3641              : /* Collect all callers of NODE.  Worker for collect_callers_of_node.  */
    3642              : 
    3643              : static bool
    3644       143589 : collect_callers_of_node_1 (cgraph_node *node, void *data)
    3645              : {
    3646       143589 :   vec<cgraph_edge *> *redirect_callers = (vec<cgraph_edge *> *)data;
    3647       143589 :   cgraph_edge *cs;
    3648       143589 :   enum availability avail;
    3649       143589 :   node->ultimate_alias_target (&avail);
    3650              : 
    3651       143589 :   if (avail > AVAIL_INTERPOSABLE)
    3652       487554 :     for (cs = node->callers; cs != NULL; cs = cs->next_caller)
    3653       343965 :       if (!cs->indirect_inlining_edge
    3654       343965 :           && !cs->caller->thunk)
    3655       343965 :         redirect_callers->safe_push (cs);
    3656       143589 :   return false;
    3657              : }
    3658              : 
    3659              : /* Collect all callers of cgraph_node and its aliases that are known to lead to
    3660              :    cgraph_node (i.e. are not overwritable).  */
    3661              : 
    3662              : auto_vec<cgraph_edge *>
    3663       142328 : cgraph_node::collect_callers (void)
    3664              : {
    3665       142328 :   auto_vec<cgraph_edge *> redirect_callers;
    3666       142328 :   call_for_symbol_thunks_and_aliases (collect_callers_of_node_1,
    3667              :                                     &redirect_callers, false);
    3668       142328 :   return redirect_callers;
    3669              : }
    3670              : 
    3671              : 
    3672              : /* Return TRUE if NODE2 a clone of NODE or is equivalent to it.  Return
    3673              :    optimistically true if this cannot be determined.  */
    3674              : 
    3675              : static bool
    3676        27311 : clone_of_p (cgraph_node *node, cgraph_node *node2)
    3677              : {
    3678        27311 :   node = node->ultimate_alias_target ();
    3679        27311 :   node2 = node2->ultimate_alias_target ();
    3680              : 
    3681        27311 :   if (node2->clone_of == node
    3682         2283 :       || node2->former_clone_of == node->decl)
    3683              :     return true;
    3684              : 
    3685         2283 :   if (!node->thunk && !node->former_thunk_p ())
    3686              :     {
    3687              :       while (node2
    3688         6848 :              && node->decl != node2->decl
    3689        11414 :              && node->decl != node2->former_clone_of)
    3690         4565 :         node2 = node2->clone_of;
    3691         2283 :       return node2 != NULL;
    3692              :     }
    3693              : 
    3694              :   /* There are no virtual clones of thunks so check former_clone_of or if we
    3695              :      might have skipped thunks because this adjustments are no longer
    3696              :      necessary.  */
    3697            0 :   while (node->thunk || node->former_thunk_p ())
    3698              :     {
    3699            0 :       if (!thunk_info::get (node)->this_adjusting)
    3700              :         return false;
    3701              :       /* In case of instrumented expanded thunks, which can have multiple calls
    3702              :          in them, we do not know how to continue and just have to be
    3703              :          optimistic.  The same applies if all calls have already been inlined
    3704              :          into the thunk.  */
    3705            0 :       if (!node->callees || node->callees->next_callee)
    3706              :         return true;
    3707            0 :       node = node->callees->callee->ultimate_alias_target ();
    3708              : 
    3709            0 :       clone_info *info = clone_info::get (node2);
    3710            0 :       if (!info || !info->param_adjustments
    3711            0 :           || info->param_adjustments->first_param_intact_p ())
    3712              :         return false;
    3713            0 :       if (node2->former_clone_of == node->decl
    3714            0 :           || node2->former_clone_of == node->former_clone_of)
    3715              :         return true;
    3716              : 
    3717              :       cgraph_node *n2 = node2;
    3718            0 :       while (n2 && node->decl != n2->decl)
    3719            0 :         n2 = n2->clone_of;
    3720            0 :       if (n2)
    3721              :         return true;
    3722              :     }
    3723              : 
    3724              :   return false;
    3725              : }
    3726              : 
    3727              : /* Verify edge count and frequency.  */
    3728              : 
    3729              : bool
    3730    203578763 : cgraph_edge::verify_count ()
    3731              : {
    3732    203578763 :   bool error_found = false;
    3733    203578763 :   if (!count.verify ())
    3734              :     {
    3735            0 :       error ("caller edge count invalid");
    3736            0 :       error_found = true;
    3737              :     }
    3738    203578763 :   return error_found;
    3739              : }
    3740              : 
    3741              : /* Switch to THIS_CFUN if needed and print STMT to stderr.  */
    3742              : static void
    3743            0 : cgraph_debug_gimple_stmt (function *this_cfun, gimple *stmt)
    3744              : {
    3745            0 :   bool fndecl_was_null = false;
    3746              :   /* debug_gimple_stmt needs correct cfun */
    3747            0 :   if (cfun != this_cfun)
    3748            0 :     set_cfun (this_cfun);
    3749              :   /* ...and an actual current_function_decl */
    3750            0 :   if (!current_function_decl)
    3751              :     {
    3752            0 :       current_function_decl = this_cfun->decl;
    3753            0 :       fndecl_was_null = true;
    3754              :     }
    3755            0 :   debug_gimple_stmt (stmt);
    3756            0 :   if (fndecl_was_null)
    3757            0 :     current_function_decl = NULL;
    3758            0 : }
    3759              : 
    3760              : /* Verify that call graph edge corresponds to DECL from the associated
    3761              :    statement.  Return true if the verification should fail.  */
    3762              : 
    3763              : bool
    3764    100164365 : cgraph_edge::verify_corresponds_to_fndecl (tree decl)
    3765              : {
    3766    100164365 :   cgraph_node *node;
    3767              : 
    3768    100164365 :   if (!decl || callee->inlined_to)
    3769              :     return false;
    3770     96254548 :   if (symtab->state == LTO_STREAMING)
    3771              :     return false;
    3772     96254548 :   node = cgraph_node::get (decl);
    3773              : 
    3774              :   /* We do not know if a node from a different partition is an alias or what it
    3775              :      aliases and therefore cannot do the former_clone_of check reliably.  When
    3776              :      body_removed is set, we have lost all information about what was alias or
    3777              :      thunk of and also cannot proceed.  */
    3778     96254548 :   if (!node
    3779     96180024 :       || node->body_removed
    3780     95268321 :       || node->in_other_partition
    3781     95268321 :       || callee->icf_merged
    3782     95166638 :       || callee->in_other_partition)
    3783              :     return false;
    3784              : 
    3785     95166638 :   node = node->ultimate_alias_target ();
    3786              : 
    3787              :   /* Optimizers can redirect unreachable calls or calls triggering undefined
    3788              :      behavior to __builtin_unreachable or __builtin_unreachable trap.  */
    3789              : 
    3790     95166638 :   if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
    3791              :                                        BUILT_IN_UNREACHABLE_TRAP))
    3792              :     return false;
    3793              : 
    3794     92145138 :   if (callee->former_clone_of != node->decl
    3795     92143602 :       && (node != callee->ultimate_alias_target ())
    3796     92172449 :       && !clone_of_p (node, callee))
    3797              :     return true;
    3798              :   else
    3799     92145138 :     return false;
    3800              : }
    3801              : 
    3802              : /* Disable warnings about missing quoting in GCC diagnostics for
    3803              :    the verification errors.  Their format strings don't follow GCC
    3804              :    diagnostic conventions and the calls are ultimately followed by
    3805              :    one to internal_error.  */
    3806              : #if __GNUC__ >= 10
    3807              : #  pragma GCC diagnostic push
    3808              : #  pragma GCC diagnostic ignored "-Wformat-diag"
    3809              : #endif
    3810              : 
    3811              : /* Verify consistency of speculative call in NODE corresponding to STMT
    3812              :    and LTO_STMT_UID.  If INDIRECT is set, assume that it is the indirect
    3813              :    edge of call sequence. Return true if error is found.
    3814              : 
    3815              :    This function is called to every component of indirect call (direct edges,
    3816              :    indirect edge and refs).  To save duplicated work, do full testing only
    3817              :    in that case.  */
    3818              : static bool
    3819       453485 : verify_speculative_call (struct cgraph_node *node, gimple *stmt,
    3820              :                          unsigned int lto_stmt_uid,
    3821              :                          struct cgraph_edge *indirect)
    3822              : {
    3823       453485 :   if (indirect == NULL)
    3824              :     {
    3825       534780 :       for (indirect = node->indirect_calls; indirect;
    3826       202928 :            indirect = indirect->next_callee)
    3827       534780 :         if (indirect->call_stmt == stmt
    3828       332018 :             && indirect->lto_stmt_uid == lto_stmt_uid)
    3829              :           break;
    3830       331852 :       if (!indirect)
    3831              :         {
    3832            0 :           error ("missing indirect call in speculative call sequence");
    3833            0 :           return true;
    3834              :         }
    3835       331852 :       if (!indirect->speculative)
    3836              :         {
    3837            0 :           error ("indirect call in speculative call sequence has no "
    3838              :                  "speculative flag");
    3839            0 :           return true;
    3840              :         }
    3841              :       return false;
    3842              :     }
    3843              : 
    3844              :   /* Maximal number of targets.  We probably will never want to have more than
    3845              :      this.  */
    3846              :   const unsigned int num = 256;
    3847              :   cgraph_edge *direct_calls[num];
    3848              :   ipa_ref *refs[num];
    3849              : 
    3850     31259681 :   for (unsigned int i = 0; i < num; i++)
    3851              :     {
    3852     31138048 :       direct_calls[i] = NULL;
    3853     31138048 :       refs[i] = NULL;
    3854              :     }
    3855              : 
    3856       121633 :   cgraph_edge *first_call = NULL;
    3857       121633 :   cgraph_edge *prev_call = NULL;
    3858              : 
    3859      1204970 :   for (cgraph_edge *direct = node->callees; direct;
    3860      1083337 :        direct = direct->next_callee)
    3861      1083337 :     if (direct->call_stmt == stmt && direct->lto_stmt_uid == lto_stmt_uid)
    3862              :       {
    3863       165926 :         if (!first_call)
    3864       121633 :           first_call = direct;
    3865       165926 :         if (prev_call && direct != prev_call->next_callee)
    3866              :           {
    3867            0 :             error ("speculative edges are not adjacent");
    3868            0 :             return true;
    3869              :           }
    3870       165926 :         prev_call = direct;
    3871       165926 :         if (!direct->speculative)
    3872              :           {
    3873            0 :             error ("direct call to %s in speculative call sequence has no "
    3874            0 :                    "speculative flag", direct->callee->dump_name ());
    3875            0 :             return true;
    3876              :           }
    3877       165926 :         if (direct->speculative_id >= num)
    3878              :           {
    3879            0 :             error ("direct call to %s in speculative call sequence has "
    3880              :                    "speculative_id %i out of range",
    3881            0 :                    direct->callee->dump_name (), direct->speculative_id);
    3882            0 :             return true;
    3883              :           }
    3884       165926 :         if (direct_calls[direct->speculative_id])
    3885              :           {
    3886            0 :             error ("duplicate direct call to %s in speculative call sequence "
    3887              :                    "with speculative_id %i",
    3888            0 :                    direct->callee->dump_name (), direct->speculative_id);
    3889            0 :             return true;
    3890              :           }
    3891       165926 :         direct_calls[direct->speculative_id] = direct;
    3892              :       }
    3893              : 
    3894       121633 :   if (first_call->call_stmt
    3895       121633 :       && first_call != node->get_edge (first_call->call_stmt))
    3896              :     {
    3897            0 :       error ("call stmt hash does not point to first direct edge of "
    3898              :              "speculative call sequence");
    3899            0 :       return true;
    3900              :     }
    3901              : 
    3902              :   ipa_ref *ref;
    3903      1507738 :   for (int i = 0; node->iterate_reference (i, ref); i++)
    3904      1386105 :     if (ref->speculative
    3905       279434 :         && ref->stmt == stmt && ref->lto_stmt_uid == lto_stmt_uid)
    3906              :       {
    3907       165926 :         if (ref->speculative_id >= num)
    3908              :           {
    3909            0 :             error ("direct call to %s in speculative call sequence has "
    3910              :                    "speculative_id %i out of range",
    3911            0 :                    ref->referred->dump_name (), ref->speculative_id);
    3912            0 :             return true;
    3913              :           }
    3914       165926 :         if (refs[ref->speculative_id])
    3915              :           {
    3916            0 :             error ("duplicate reference %s in speculative call sequence "
    3917              :                    "with speculative_id %i",
    3918            0 :                    ref->referred->dump_name (), ref->speculative_id);
    3919            0 :             return true;
    3920              :           }
    3921       165926 :         refs[ref->speculative_id] = ref;
    3922              :       }
    3923              : 
    3924              :   int num_targets = 0;
    3925     31259681 :   for (unsigned int i = 0 ; i < num ; i++)
    3926              :     {
    3927     31138048 :       if (refs[i] && !direct_calls[i])
    3928              :         {
    3929            0 :           error ("missing direct call for speculation %i", i);
    3930            0 :           return true;
    3931              :         }
    3932     31138048 :       if (!refs[i] && direct_calls[i])
    3933              :         {
    3934            0 :           error ("missing ref for speculation %i", i);
    3935            0 :           return true;
    3936              :         }
    3937     31138048 :       if (refs[i] != NULL)
    3938       165926 :         num_targets++;
    3939              :     }
    3940              : 
    3941       121633 :   if (num_targets != indirect->num_speculative_call_targets_p ())
    3942              :     {
    3943            0 :       error ("number of speculative targets %i mismatched with "
    3944              :              "num_speculative_call_targets %i",
    3945              :              num_targets,
    3946              :              indirect->num_speculative_call_targets_p ());
    3947            0 :       return true;
    3948              :     }
    3949              :   return false;
    3950              : }
    3951              : 
    3952              : /* Verify cgraph nodes of given cgraph node.  */
    3953              : DEBUG_FUNCTION void
    3954     53649813 : cgraph_node::verify_node (void)
    3955              : {
    3956     53649813 :   cgraph_edge *e;
    3957     53649813 :   function *this_cfun = DECL_STRUCT_FUNCTION (decl);
    3958     53649813 :   basic_block this_block;
    3959     53649813 :   gimple_stmt_iterator gsi;
    3960     53649813 :   bool error_found = false;
    3961     53649813 :   int i;
    3962     53649813 :   ipa_ref *ref = NULL;
    3963              : 
    3964     53649813 :   if (seen_error ())
    3965     53649813 :     return;
    3966              : 
    3967     53649813 :   timevar_push (TV_CGRAPH_VERIFY);
    3968     53649813 :   error_found |= verify_base ();
    3969    163095547 :   for (e = callees; e; e = e->next_callee)
    3970    109445734 :     if (e->aux)
    3971              :       {
    3972            0 :         error ("aux field set for edge %s->%s",
    3973            0 :                identifier_to_locale (e->caller->name ()),
    3974            0 :                identifier_to_locale (e->callee->name ()));
    3975            0 :         error_found = true;
    3976              :       }
    3977     53649813 :   if (!count.verify ())
    3978              :     {
    3979            0 :       error ("cgraph count invalid");
    3980            0 :       error_found = true;
    3981              :     }
    3982     53649813 :   if (inlined_to && same_comdat_group)
    3983              :     {
    3984            0 :       error ("inline clone in same comdat group list");
    3985            0 :       error_found = true;
    3986              :     }
    3987     53649813 :   if (inlined_to && !count.compatible_p (inlined_to->count))
    3988              :     {
    3989            0 :       error ("inline clone count is not compatible");
    3990            0 :       count.debug ();
    3991            0 :       inlined_to->count.debug ();
    3992            0 :       error_found = true;
    3993              :     }
    3994     53649813 :   if (tp_first_run < 0)
    3995              :     {
    3996            0 :       error ("tp_first_run must be non-negative");
    3997            0 :       error_found = true;
    3998              :     }
    3999     53649813 :   if (!definition && !in_other_partition && local)
    4000              :     {
    4001            0 :       error ("local symbols must be defined");
    4002            0 :       error_found = true;
    4003              :     }
    4004     53649813 :   if (inlined_to && externally_visible)
    4005              :     {
    4006            0 :       error ("externally visible inline clone");
    4007            0 :       error_found = true;
    4008              :     }
    4009     53649813 :   if (inlined_to && address_taken)
    4010              :     {
    4011            0 :       error ("inline clone with address taken");
    4012            0 :       error_found = true;
    4013              :     }
    4014     53649813 :   if (inlined_to && force_output)
    4015              :     {
    4016            0 :       error ("inline clone is forced to output");
    4017            0 :       error_found = true;
    4018              :     }
    4019     53649813 :   if (inlined_to && ref_by_asm)
    4020              :     {
    4021            0 :       error ("inline clone is referenced by assembly");
    4022            0 :       error_found = true;
    4023              :     }
    4024     53649813 :   if (symtab->state != LTO_STREAMING)
    4025              :     {
    4026     53538036 :       if (calls_comdat_local && !same_comdat_group)
    4027              :         {
    4028            0 :           error ("calls_comdat_local is set outside of a comdat group");
    4029            0 :           error_found = true;
    4030              :         }
    4031     53538036 :       if (!inlined_to && calls_comdat_local != check_calls_comdat_local_p ())
    4032              :         {
    4033            0 :           error ("invalid calls_comdat_local flag");
    4034            0 :           error_found = true;
    4035              :         }
    4036              :     }
    4037     53649813 :   if (DECL_IS_MALLOC (decl)
    4038     53649813 :       && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
    4039              :     {
    4040            0 :       error ("malloc attribute should be used for a function that "
    4041              :              "returns a pointer");
    4042            0 :       error_found = true;
    4043              :     }
    4044     53649813 :   if (definition
    4045     36354138 :       && externally_visible
    4046              :       /* For aliases in lto1 free_lang_data doesn't guarantee preservation
    4047              :          of opt_for_fn (decl, flag_semantic_interposition).  See PR105399.  */
    4048     19523574 :       && (!alias || !in_lto_p)
    4049     53649813 :       && semantic_interposition
    4050     19520651 :          != opt_for_fn (decl, flag_semantic_interposition))
    4051              :     {
    4052            0 :       error ("semantic interposition mismatch");
    4053            0 :       error_found = true;
    4054              :     }
    4055     56000954 :   for (e = indirect_calls; e; e = e->next_callee)
    4056              :     {
    4057      2351141 :       if (e->aux)
    4058              :         {
    4059            0 :           error ("aux field set for indirect edge from %s",
    4060            0 :                  identifier_to_locale (e->caller->name ()));
    4061            0 :           error_found = true;
    4062              :         }
    4063      2351141 :       if (!e->count.compatible_p (count))
    4064              :         {
    4065            0 :           error ("edge count is not compatible with function count");
    4066            0 :           e->count.debug ();
    4067            0 :           count.debug ();
    4068            0 :           error_found = true;
    4069              :         }
    4070      2351141 :       if (inlined_to && !e->count.compatible_p (inlined_to->count))
    4071              :         {
    4072            0 :           error ("edge count is not compatible with inlined to function count");
    4073            0 :           e->count.debug ();
    4074            0 :           count.debug ();
    4075            0 :           error_found = true;
    4076              :         }
    4077      2351141 :       if (!e->indirect_unknown_callee
    4078      2351141 :           || !e->indirect_info)
    4079              :         {
    4080            0 :           error ("An indirect edge from %s is not marked as indirect or has "
    4081              :                  "associated indirect_info, the corresponding statement is: ",
    4082            0 :                  identifier_to_locale (e->caller->name ()));
    4083            0 :           cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    4084            0 :           error_found = true;
    4085              :         }
    4086      2351141 :       if (e->call_stmt && e->lto_stmt_uid)
    4087              :         {
    4088            0 :           error ("edge has both call_stmt and lto_stmt_uid set");
    4089            0 :           error_found = true;
    4090              :         }
    4091              :     }
    4092     53649813 :   bool check_comdat = comdat_local_p ();
    4093    145431701 :   for (e = callers; e; e = e->next_caller)
    4094              :     {
    4095     91781888 :       if (e->verify_count ())
    4096            0 :         error_found = true;
    4097     91781888 :       if (check_comdat
    4098     91781888 :           && !in_same_comdat_group_p (e->caller))
    4099              :         {
    4100            0 :           error ("comdat-local function called by %s outside its comdat",
    4101              :                  identifier_to_locale (e->caller->name ()));
    4102            0 :           error_found = true;
    4103              :         }
    4104     91781888 :       if (!e->inline_failed)
    4105              :         {
    4106      8665068 :           if (inlined_to
    4107      8665068 :               != (e->caller->inlined_to
    4108      8665068 :                   ? e->caller->inlined_to : e->caller))
    4109              :             {
    4110            0 :               error ("inlined_to pointer is wrong");
    4111            0 :               error_found = true;
    4112              :             }
    4113      8665068 :           if (callers->next_caller)
    4114              :             {
    4115            0 :               error ("multiple inline callers");
    4116            0 :               error_found = true;
    4117              :             }
    4118              :         }
    4119              :       else
    4120     83116820 :         if (inlined_to)
    4121              :           {
    4122            0 :             error ("inlined_to pointer set for noninline callers");
    4123            0 :             error_found = true;
    4124              :           }
    4125              :     }
    4126    163095547 :   for (e = callees; e; e = e->next_callee)
    4127              :     {
    4128    109445734 :       if (e->verify_count ())
    4129            0 :         error_found = true;
    4130    109445734 :       if (!e->count.compatible_p (count))
    4131              :         {
    4132            0 :           error ("edge count is not compatible with function count");
    4133            0 :           e->count.debug ();
    4134            0 :           count.debug ();
    4135            0 :           error_found = true;
    4136              :         }
    4137    109445734 :       if (gimple_has_body_p (e->caller->decl)
    4138    102687706 :           && !e->caller->inlined_to
    4139     93353743 :           && !e->speculative
    4140     93298919 :           && !e->callback
    4141     93276982 :           && !e->has_callback
    4142              :           /* Optimized out calls are redirected to __builtin_unreachable.  */
    4143     93188508 :           && (e->count.nonzero_p ()
    4144     53908510 :               || ! e->callee->decl
    4145     53908510 :               || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
    4146              :                                      BUILT_IN_UNREACHABLE_TRAP))
    4147              :           && count
    4148     91343473 :               == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
    4149    200781413 :           && (!e->count.ipa_p ()
    4150     41249824 :               && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
    4151              :         {
    4152            0 :           error ("caller edge count does not match BB count");
    4153            0 :           fprintf (stderr, "edge count: ");
    4154            0 :           e->count.dump (stderr);
    4155            0 :           fprintf (stderr, "\n bb count: ");
    4156            0 :           gimple_bb (e->call_stmt)->count.dump (stderr);
    4157            0 :           fprintf (stderr, "\n");
    4158            0 :           error_found = true;
    4159              :         }
    4160    109445734 :       if (e->call_stmt && e->lto_stmt_uid)
    4161              :         {
    4162            0 :           error ("edge has both call_stmt and lto_stmt_uid set");
    4163            0 :           error_found = true;
    4164              :         }
    4165    109445734 :       if (e->speculative
    4166    109445734 :           && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
    4167              :                                       NULL))
    4168              :         error_found = true;
    4169              :     }
    4170     56000954 :   for (e = indirect_calls; e; e = e->next_callee)
    4171              :     {
    4172      2351141 :       if (e->verify_count ())
    4173            0 :         error_found = true;
    4174      2351141 :       if (gimple_has_body_p (e->caller->decl)
    4175      2304746 :           && !e->caller->inlined_to
    4176      2067276 :           && !e->speculative
    4177      2027162 :           && e->count.ipa_p ()
    4178              :           && count
    4179       761087 :               == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
    4180      3112224 :           && (!e->count.ipa_p ()
    4181            0 :               && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
    4182              :         {
    4183            0 :           error ("indirect call count does not match BB count");
    4184            0 :           fprintf (stderr, "edge count: ");
    4185            0 :           e->count.dump (stderr);
    4186            0 :           fprintf (stderr, "\n bb count: ");
    4187            0 :           gimple_bb (e->call_stmt)->count.dump (stderr);
    4188            0 :           fprintf (stderr, "\n");
    4189            0 :           error_found = true;
    4190              :         }
    4191      2351141 :       if (e->speculative
    4192      2351141 :           && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
    4193              :                                       e))
    4194              :         error_found = true;
    4195              :     }
    4196    120574335 :   for (i = 0; iterate_reference (i, ref); i++)
    4197              :     {
    4198     66924522 :       if (ref->stmt && ref->lto_stmt_uid)
    4199              :         {
    4200            0 :           error ("reference has both stmt and lto_stmt_uid set");
    4201            0 :           error_found = true;
    4202              :         }
    4203     66924522 :       if (ref->speculative
    4204     66924522 :           && verify_speculative_call (this, ref->stmt,
    4205              :                                       ref->lto_stmt_uid, NULL))
    4206              :         error_found = true;
    4207              :     }
    4208              : 
    4209     53649813 :   if (!callers && inlined_to)
    4210              :     {
    4211            0 :       error ("inlined_to pointer is set but no predecessors found");
    4212            0 :       error_found = true;
    4213              :     }
    4214     53649813 :   if (inlined_to == this)
    4215              :     {
    4216            0 :       error ("inlined_to pointer refers to itself");
    4217            0 :       error_found = true;
    4218              :     }
    4219              : 
    4220     53649813 :   if (clone_of)
    4221              :     {
    4222      6348116 :       cgraph_node *first_clone = clone_of->clones;
    4223      6348116 :       if (first_clone != this)
    4224              :         {
    4225      3226976 :           if (prev_sibling_clone->clone_of != clone_of)
    4226              :             {
    4227            0 :               error ("cgraph_node has wrong clone_of");
    4228            0 :               error_found = true;
    4229              :             }
    4230              :         }
    4231              :     }
    4232     53649813 :   if (clones)
    4233              :     {
    4234              :       cgraph_node *n;
    4235      8696300 :       for (n = clones; n; n = n->next_sibling_clone)
    4236      6960359 :         if (n->clone_of != this)
    4237              :           break;
    4238      1735941 :       if (n)
    4239              :         {
    4240            0 :           error ("cgraph_node has wrong clone list");
    4241            0 :           error_found = true;
    4242              :         }
    4243              :     }
    4244     53649813 :   if ((prev_sibling_clone || next_sibling_clone) && !clone_of)
    4245              :     {
    4246            0 :        error ("cgraph_node is in clone list but it is not clone");
    4247            0 :        error_found = true;
    4248              :     }
    4249     53649813 :   if (!prev_sibling_clone && clone_of && clone_of->clones != this)
    4250              :     {
    4251            0 :       error ("cgraph_node has wrong prev_clone pointer");
    4252            0 :       error_found = true;
    4253              :     }
    4254     53649813 :   if (prev_sibling_clone && prev_sibling_clone->next_sibling_clone != this)
    4255              :     {
    4256            0 :       error ("double linked list of clones corrupted");
    4257            0 :       error_found = true;
    4258              :     }
    4259              : 
    4260     53649813 :   if (analyzed && alias)
    4261              :     {
    4262      1464487 :       bool ref_found = false;
    4263      1464487 :       int i;
    4264      1464487 :       ipa_ref *ref = NULL;
    4265              : 
    4266      1464487 :       if (callees)
    4267              :         {
    4268            0 :           error ("Alias has call edges");
    4269            0 :           error_found = true;
    4270              :         }
    4271      2928974 :       for (i = 0; iterate_reference (i, ref); i++)
    4272      1464487 :         if (ref->use != IPA_REF_ALIAS)
    4273              :           {
    4274            0 :             error ("Alias has non-alias reference");
    4275            0 :             error_found = true;
    4276              :           }
    4277      1464487 :         else if (ref_found)
    4278              :           {
    4279            0 :             error ("Alias has more than one alias reference");
    4280            0 :             error_found = true;
    4281              :           }
    4282              :         else
    4283              :           ref_found = true;
    4284      1464487 :       if (!ref_found)
    4285              :         {
    4286            0 :           error ("Analyzed alias has no reference");
    4287            0 :           error_found = true;
    4288              :         }
    4289              :     }
    4290              : 
    4291     53649813 :   if (analyzed && thunk)
    4292              :     {
    4293        22996 :       if (!callees)
    4294              :         {
    4295            0 :           error ("No edge out of thunk node");
    4296            0 :           error_found = true;
    4297              :         }
    4298        22996 :       else if (callees->next_callee)
    4299              :         {
    4300            0 :           error ("More than one edge out of thunk node");
    4301            0 :           error_found = true;
    4302              :         }
    4303        22996 :       if (gimple_has_body_p (decl) && !inlined_to)
    4304              :         {
    4305            0 :           error ("Thunk is not supposed to have body");
    4306            0 :           error_found = true;
    4307              :         }
    4308              :     }
    4309     36329048 :   else if (analyzed && gimple_has_body_p (decl)
    4310     31306732 :            && !TREE_ASM_WRITTEN (decl)
    4311     31306732 :            && (!DECL_EXTERNAL (decl) || inlined_to)
    4312     83838732 :            && !flag_wpa)
    4313              :     {
    4314     30185479 :       if ((this_cfun->curr_properties & PROP_assumptions_done) != 0)
    4315              :         ;
    4316     30185369 :       else if (this_cfun->cfg)
    4317              :         {
    4318     30185369 :           hash_set<gimple *> stmts;
    4319              : 
    4320              :           /* Reach the trees by walking over the CFG, and note the
    4321              :              enclosing basic-blocks in the call edges.  */
    4322    250068975 :           FOR_EACH_BB_FN (this_block, this_cfun)
    4323              :             {
    4324    219883606 :               for (gsi = gsi_start_phis (this_block);
    4325    264925816 :                    !gsi_end_p (gsi); gsi_next (&gsi))
    4326     45042210 :                 stmts.add (gsi_stmt (gsi));
    4327    439767212 :               for (gsi = gsi_start_bb (this_block);
    4328   1354406146 :                    !gsi_end_p (gsi);
    4329   1134522540 :                    gsi_next (&gsi))
    4330              :                 {
    4331   1134522540 :                   gimple *stmt = gsi_stmt (gsi);
    4332   1134522540 :                   stmts.add (stmt);
    4333   1134522540 :                   if (is_gimple_call (stmt))
    4334              :                     {
    4335    107114213 :                       cgraph_edge *e = get_edge (stmt);
    4336    107114213 :                       tree decl = gimple_call_fndecl (stmt);
    4337    107114213 :                       if (e)
    4338              :                         {
    4339    102333358 :                           if (e->aux)
    4340              :                             {
    4341            0 :                               error ("shared call_stmt:");
    4342            0 :                               cgraph_debug_gimple_stmt (this_cfun, stmt);
    4343            0 :                               error_found = true;
    4344              :                             }
    4345    102333358 :                           if (!e->indirect_unknown_callee)
    4346              :                             {
    4347              :                               /* Callback edges violate this assertion
    4348              :                                  because their call statement doesn't exist,
    4349              :                                  their associated statement belongs to the
    4350              :                                  callback-dispatching function.  */
    4351    100164365 :                               if (!e->callback
    4352    100164365 :                                   && e->verify_corresponds_to_fndecl (decl))
    4353              :                                 {
    4354            0 :                                   error ("edge points to wrong declaration:");
    4355            0 :                                   debug_tree (e->callee->decl);
    4356            0 :                                   fprintf (stderr," Instead of:");
    4357            0 :                                   debug_tree (decl);
    4358            0 :                                   error_found = true;
    4359              :                                 }
    4360              :                             }
    4361      2168993 :                           else if (decl)
    4362              :                             {
    4363            0 :                               error ("an indirect edge with unknown callee "
    4364              :                                      "corresponding to a call_stmt with "
    4365              :                                      "a known declaration:");
    4366            0 :                               error_found = true;
    4367            0 :                               cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    4368              :                             }
    4369    102333358 :                           e->aux = (void *)1;
    4370              :                         }
    4371      4780855 :                       else if (decl)
    4372              :                         {
    4373            0 :                           error ("missing callgraph edge for call stmt:");
    4374            0 :                           cgraph_debug_gimple_stmt (this_cfun, stmt);
    4375            0 :                           error_found = true;
    4376              :                         }
    4377              :                     }
    4378              :                 }
    4379              :               }
    4380    101345754 :             for (i = 0; iterate_reference (i, ref); i++)
    4381     62090859 :               if (ref->stmt && !stmts.contains (ref->stmt))
    4382              :                 {
    4383            0 :                   error ("reference to dead statement");
    4384            0 :                   cgraph_debug_gimple_stmt (this_cfun, ref->stmt);
    4385            0 :                   error_found = true;
    4386              :                 }
    4387     30185369 :         }
    4388              :       else
    4389              :         /* No CFG available?!  */
    4390            0 :         gcc_unreachable ();
    4391              : 
    4392    130413764 :       for (e = callees; e; e = e->next_callee)
    4393              :         {
    4394    100228285 :           if (e->callback && e->has_callback)
    4395              :             {
    4396            0 :               error ("edge has both callback and has_callback set");
    4397            0 :               error_found = true;
    4398              :             }
    4399              : 
    4400    100228285 :           if (e->callback)
    4401              :             {
    4402        23237 :               if (!e->get_callback_carrying_edge ())
    4403              :                 {
    4404            0 :                   error ("callback edge %s->%s has no callback-carrying",
    4405            0 :                          identifier_to_locale (e->caller->name ()),
    4406            0 :                          identifier_to_locale (e->callee->name ()));
    4407            0 :                   error_found = true;
    4408              :                 }
    4409              :             }
    4410              : 
    4411    100228285 :           if (e->has_callback
    4412        95603 :               && !callback_is_special_cased (e->callee->decl, e->call_stmt)
    4413    100313126 :               && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
    4414              :             {
    4415        84829 :               int ncallbacks = 0;
    4416        84829 :               int nfound_edges = 0;
    4417        84829 :               for (tree cb
    4418        84829 :                    = lookup_attribute ("callback_only",
    4419        84829 :                                        DECL_ATTRIBUTES (e->callee->decl));
    4420       169667 :                    cb; cb = lookup_attribute ("callback_only", TREE_CHAIN (cb)),
    4421              :                        ncallbacks++)
    4422              :                 ;
    4423       744629 :               for (cgraph_edge *cbe = callees; cbe; cbe = cbe->next_callee)
    4424              :                 {
    4425       659800 :                   if (cbe->callback && cbe->call_stmt == e->call_stmt
    4426        19911 :                       && cbe->lto_stmt_uid == e->lto_stmt_uid)
    4427              :                     {
    4428        19911 :                       nfound_edges++;
    4429              :                     }
    4430              :                 }
    4431        84829 :               if (ncallbacks < nfound_edges)
    4432              :                 {
    4433            0 :                   error ("callback edge %s->%s callback edge count mismatch, "
    4434              :                          "expected at most %d, found %d",
    4435            0 :                          identifier_to_locale (e->caller->name ()),
    4436            0 :                          identifier_to_locale (e->callee->name ()), ncallbacks,
    4437              :                          nfound_edges);
    4438              :                 }
    4439              :             }
    4440              : 
    4441    100228285 :           if (e->has_callback
    4442    100228285 :               && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
    4443           12 :             for (cgraph_edge *cbe = e->first_callback_edge (); cbe;
    4444            0 :                  cbe = cbe->next_callback_edge ())
    4445            0 :               if (!fndecl_built_in_p (cbe->callee->decl, BUILT_IN_UNREACHABLE))
    4446            0 :                 error ("callback-carrying edge is pointing towards "
    4447              :                        "__builtin_unreachable, but its callback edge %s -> %s "
    4448              :                        "is not",
    4449            0 :                        cbe->caller->name (), cbe->callee->name ());
    4450              : 
    4451    100228285 :           if (!e->aux && !e->speculative && !e->callback && !e->has_callback)
    4452              :             {
    4453            0 :               error ("edge %s->%s has no corresponding call_stmt",
    4454            0 :                      identifier_to_locale (e->caller->name ()),
    4455            0 :                      identifier_to_locale (e->callee->name ()));
    4456            0 :               cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    4457            0 :               error_found = true;
    4458              :             }
    4459    100228285 :           e->aux = 0;
    4460              :         }
    4461     32467539 :       for (e = indirect_calls; e; e = e->next_callee)
    4462              :         {
    4463      2282060 :           if (!e->aux && !e->speculative)
    4464              :             {
    4465            0 :               error ("an indirect edge from %s has no corresponding call_stmt",
    4466            0 :                      identifier_to_locale (e->caller->name ()));
    4467            0 :               cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    4468            0 :               error_found = true;
    4469              :             }
    4470      2282060 :           e->aux = 0;
    4471              :         }
    4472              :     }
    4473              : 
    4474     53649813 :   if (nested_function_info *info = nested_function_info::get (this))
    4475              :     {
    4476            0 :       if (info->nested != NULL)
    4477              :         {
    4478            0 :           for (cgraph_node *n = info->nested; n != NULL;
    4479            0 :                n = next_nested_function (n))
    4480              :             {
    4481            0 :               nested_function_info *ninfo = nested_function_info::get (n);
    4482            0 :               if (ninfo->origin == NULL)
    4483              :                 {
    4484            0 :                   error ("missing origin for a node in a nested list");
    4485            0 :                   error_found = true;
    4486              :                 }
    4487            0 :               else if (ninfo->origin != this)
    4488              :                 {
    4489            0 :                   error ("origin points to a different parent");
    4490            0 :                   error_found = true;
    4491            0 :                   break;
    4492              :                 }
    4493              :             }
    4494              :         }
    4495            0 :       if (info->next_nested != NULL && info->origin == NULL)
    4496              :         {
    4497            0 :           error ("missing origin for a node in a nested list");
    4498            0 :           error_found = true;
    4499              :         }
    4500              :     }
    4501              : 
    4502     53649813 :   if (error_found)
    4503              :     {
    4504            0 :       dump (stderr);
    4505            0 :       internal_error ("verify_cgraph_node failed");
    4506              :     }
    4507     53649813 :   timevar_pop (TV_CGRAPH_VERIFY);
    4508              : }
    4509              : 
    4510              : /* Verify whole cgraph structure.  */
    4511              : DEBUG_FUNCTION void
    4512          808 : cgraph_node::verify_cgraph_nodes (void)
    4513              : {
    4514          808 :   cgraph_node *node;
    4515              : 
    4516          808 :   if (seen_error ())
    4517              :     return;
    4518              : 
    4519         5110 :   FOR_EACH_FUNCTION (node)
    4520         4326 :     node->verify ();
    4521              : }
    4522              : 
    4523              : #if __GNUC__ >= 10
    4524              : #  pragma GCC diagnostic pop
    4525              : #endif
    4526              : 
    4527              : /* Walk the alias chain to return the function cgraph_node is alias of.
    4528              :    Walk through thunks, too.
    4529              :    When AVAILABILITY is non-NULL, get minimal availability in the chain.
    4530              :    When REF is non-NULL, assume that reference happens in symbol REF
    4531              :    when determining the availability.  */
    4532              : 
    4533              : cgraph_node *
    4534    137847103 : cgraph_node::function_symbol (enum availability *availability,
    4535              :                               struct symtab_node *ref)
    4536              : {
    4537    137847103 :   cgraph_node *node = ultimate_alias_target (availability, ref);
    4538              : 
    4539    275699832 :   while (node->thunk)
    4540              :     {
    4541         5626 :       enum availability a;
    4542              : 
    4543         5626 :       ref = node;
    4544         5626 :       node = node->callees->callee;
    4545         9803 :       node = node->ultimate_alias_target (availability ? &a : NULL, ref);
    4546         5626 :       if (availability && a < *availability)
    4547           38 :         *availability = a;
    4548              :     }
    4549    137847103 :   return node;
    4550              : }
    4551              : 
    4552              : /* Walk the alias chain to return the function cgraph_node is alias of.
    4553              :    Walk through non virtual thunks, too.  Thus we return either a function
    4554              :    or a virtual thunk node.
    4555              :    When AVAILABILITY is non-NULL, get minimal availability in the chain.
    4556              :    When REF is non-NULL, assume that reference happens in symbol REF
    4557              :    when determining the availability.  */
    4558              : 
    4559              : cgraph_node *
    4560     35023646 : cgraph_node::function_or_virtual_thunk_symbol
    4561              :                                 (enum availability *availability,
    4562              :                                  struct symtab_node *ref)
    4563              : {
    4564     35023646 :   cgraph_node *node = ultimate_alias_target (availability, ref);
    4565              : 
    4566     70048346 :   while (node->thunk && !thunk_info::get (node)->virtual_offset_p)
    4567              :     {
    4568         1054 :       enum availability a;
    4569              : 
    4570         1054 :       ref = node;
    4571         1054 :       node = node->callees->callee;
    4572         1054 :       node = node->ultimate_alias_target (availability ? &a : NULL, ref);
    4573         1054 :       if (availability && a < *availability)
    4574          305 :         *availability = a;
    4575              :     }
    4576     35023646 :   return node;
    4577              : }
    4578              : 
    4579              : /* When doing LTO, read cgraph_node's body from disk if it is not already
    4580              :    present.  Also perform any necessary clone materializations.  */
    4581              : 
    4582              : bool
    4583      6530561 : cgraph_node::get_untransformed_body ()
    4584              : {
    4585      6530561 :   lto_file_decl_data *file_data;
    4586      6530561 :   const char *data, *name;
    4587      6530561 :   size_t len;
    4588      6530561 :   tree decl = this->decl;
    4589              : 
    4590              :   /* See if there is clone to be materialized.
    4591              :      (inline clones does not need materialization, but we can be seeing
    4592              :       an inline clone of real clone).  */
    4593      6530561 :   cgraph_node *p = this;
    4594      9434095 :   for (cgraph_node *c = clone_of; c; c = c->clone_of)
    4595              :     {
    4596      2903534 :       if (c->decl != decl)
    4597       145195 :         p->materialize_clone ();
    4598      2903534 :       p = c;
    4599              :     }
    4600              : 
    4601              :   /* Check if body is already there.  Either we have gimple body or
    4602              :      the function is thunk and in that case we set DECL_ARGUMENTS.  */
    4603      6530561 :   if (DECL_ARGUMENTS (decl) || gimple_has_body_p (decl))
    4604              :     return false;
    4605              : 
    4606       169332 :   gcc_assert (in_lto_p && !DECL_RESULT (decl));
    4607              : 
    4608        84666 :   timevar_push (TV_IPA_LTO_GIMPLE_IN);
    4609              : 
    4610        84666 :   file_data = lto_file_data;
    4611        84666 :   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
    4612              : 
    4613              :   /* We may have renamed the declaration, e.g., a static function.  */
    4614        84666 :   name = lto_get_decl_name_mapping (file_data, name);
    4615        84666 :   struct lto_in_decl_state *decl_state
    4616        84666 :          = lto_get_function_in_decl_state (file_data, decl);
    4617              : 
    4618        84666 :   cgraph_node *origin = this;
    4619       169547 :   while (origin->clone_of)
    4620              :     origin = origin->clone_of;
    4621              : 
    4622        84666 :   int stream_order = origin->order - file_data->order_base;
    4623        84666 :   data = lto_get_section_data (file_data, LTO_section_function_body,
    4624              :                                name, stream_order, &len,
    4625              :                                decl_state->compressed);
    4626        84666 :   if (!data)
    4627            0 :     fatal_error (input_location, "%s: section %s.%d is missing",
    4628              :                  file_data->file_name, name, stream_order);
    4629              : 
    4630        84666 :   gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
    4631              : 
    4632        84666 :   if (!quiet_flag)
    4633            0 :     fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
    4634        84666 :   lto_input_function_body (file_data, this, data);
    4635        84666 :   lto_stats.num_function_bodies++;
    4636        84666 :   lto_free_section_data (file_data, LTO_section_function_body, name,
    4637              :                          data, len, decl_state->compressed);
    4638        84666 :   lto_free_function_in_decl_state_for_node (this);
    4639              :   /* Keep lto file data so ipa-inline-analysis knows about cross module
    4640              :      inlining.  */
    4641              : 
    4642        84666 :   timevar_pop (TV_IPA_LTO_GIMPLE_IN);
    4643              : 
    4644        84666 :   return true;
    4645              : }
    4646              : 
    4647              : /* Prepare function body.  When doing LTO, read cgraph_node's body from disk
    4648              :    if it is not already present.  When some IPA transformations are scheduled,
    4649              :    apply them.  */
    4650              : 
    4651              : bool
    4652        29042 : cgraph_node::get_body (void)
    4653              : {
    4654        29042 :   bool updated;
    4655              : 
    4656        29042 :   updated = get_untransformed_body ();
    4657              : 
    4658              :   /* Getting transformed body makes no sense for inline clones;
    4659              :      we should never use this on real clones because they are materialized
    4660              :      early.
    4661              :      TODO: Materializing clones here will likely lead to smaller LTRANS
    4662              :      footprint. */
    4663        29042 :   gcc_assert (!inlined_to && !clone_of);
    4664        29042 :   if (ipa_transforms_to_apply.exists ())
    4665              :     {
    4666        12445 :       opt_pass *saved_current_pass = current_pass;
    4667        12445 :       FILE *saved_dump_file = dump_file;
    4668        12445 :       const char *saved_dump_file_name = dump_file_name;
    4669        12445 :       dump_flags_t saved_dump_flags = dump_flags;
    4670        12445 :       dump_file_name = NULL;
    4671        12445 :       set_dump_file (NULL);
    4672              : 
    4673        12445 :       push_cfun (DECL_STRUCT_FUNCTION (decl));
    4674              : 
    4675        12445 :       update_ssa (TODO_update_ssa_only_virtuals);
    4676        12445 :       execute_all_ipa_transforms (true);
    4677        12445 :       cgraph_edge::rebuild_edges ();
    4678        12445 :       free_dominance_info (CDI_DOMINATORS);
    4679        12445 :       free_dominance_info (CDI_POST_DOMINATORS);
    4680        12445 :       pop_cfun ();
    4681        12445 :       updated = true;
    4682              : 
    4683        12445 :       current_pass = saved_current_pass;
    4684        12445 :       set_dump_file (saved_dump_file);
    4685        12445 :       dump_file_name = saved_dump_file_name;
    4686        12445 :       dump_flags = saved_dump_flags;
    4687              :     }
    4688        29042 :   return updated;
    4689              : }
    4690              : 
    4691              : /* Return the DECL_STRUCT_FUNCTION of the function.  */
    4692              : 
    4693              : struct function *
    4694       111078 : cgraph_node::get_fun () const
    4695              : {
    4696       111078 :   const cgraph_node *node = this;
    4697       111078 :   struct function *fun = DECL_STRUCT_FUNCTION (node->decl);
    4698              : 
    4699       111078 :   while (!fun && node->clone_of)
    4700              :     {
    4701            0 :       node = node->clone_of;
    4702            0 :       fun = DECL_STRUCT_FUNCTION (node->decl);
    4703              :     }
    4704              : 
    4705       111078 :   return fun;
    4706              : }
    4707              : 
    4708              : /* Reset all state within cgraph.cc so that we can rerun the compiler
    4709              :    within the same process.  For use by toplev::finalize.  */
    4710              : 
    4711              : void
    4712       264541 : cgraph_cc_finalize (void)
    4713              : {
    4714       264541 :   nested_function_info::release ();
    4715       264541 :   thunk_info::release ();
    4716       264541 :   clone_info::release ();
    4717       264541 :   callback_info_sum_t::free_info_sum ();
    4718       264541 :   symtab = NULL;
    4719              : 
    4720       264541 :   cgraph_fnver_htab = NULL;
    4721       264541 :   version_info_node = NULL;
    4722       264541 : }
    4723              : 
    4724              : /* A worker for call_for_symbol_and_aliases.  */
    4725              : 
    4726              : bool
    4727       762642 : cgraph_node::call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
    4728              :                                                               void *),
    4729              :                                             void *data,
    4730              :                                             bool include_overwritable)
    4731              : {
    4732       762642 :   ipa_ref *ref;
    4733      1540269 :   FOR_EACH_ALIAS (this, ref)
    4734              :     {
    4735       887866 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    4736       887866 :       if (include_overwritable
    4737       887866 :           || alias->get_availability () > AVAIL_INTERPOSABLE)
    4738       887866 :         if (alias->call_for_symbol_and_aliases (callback, data,
    4739              :                                                 include_overwritable))
    4740              :           return true;
    4741              :     }
    4742              :   return false;
    4743              : }
    4744              : 
    4745              : /* Return true if NODE has thunk.  */
    4746              : 
    4747              : bool
    4748        36484 : cgraph_node::has_thunk_p (cgraph_node *node, void *)
    4749              : {
    4750        70797 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    4751        34313 :     if (e->caller->thunk)
    4752              :       return true;
    4753              :   return false;
    4754              : }
    4755              : 
    4756              : /* Expected frequency of executions within the function.  */
    4757              : 
    4758              : sreal
    4759    225636478 : cgraph_edge::sreal_frequency ()
    4760              : {
    4761    225636478 :   return count.to_sreal_scale (caller->inlined_to
    4762    225636478 :                                ? caller->inlined_to->count
    4763    225636478 :                                : caller->count);
    4764              : }
    4765              : 
    4766              : /* Expected frequency of executions within the function.
    4767              :    If edge is speculative, sum all its indirect targets.  */
    4768              : 
    4769              : sreal
    4770         4223 : cgraph_edge::combined_sreal_frequency ()
    4771              : {
    4772         4223 :   if (!speculative)
    4773         3908 :     return sreal_frequency ();
    4774          315 :   cgraph_edge *e = this;
    4775          315 :   if (e->callee)
    4776            0 :     e = e->speculative_call_indirect_edge ();
    4777          315 :   sreal sum = e->sreal_frequency ();
    4778          315 :   for (e = e->first_speculative_call_target ();
    4779          716 :        e;
    4780          401 :        e = e->next_speculative_call_target ())
    4781          401 :     sum += e->sreal_frequency ();
    4782          315 :   return sum;
    4783              : }
    4784              : 
    4785              : 
    4786              : /* During LTO stream in this can be used to check whether call can possibly
    4787              :    be internal to the current translation unit.  */
    4788              : 
    4789              : bool
    4790       481883 : cgraph_edge::possibly_call_in_translation_unit_p (void)
    4791              : {
    4792       481883 :   gcc_checking_assert (in_lto_p && caller->prevailing_p ());
    4793              : 
    4794              :   /* While incremental linking we may end up getting function body later.  */
    4795       481883 :   if (flag_incremental_link == INCREMENTAL_LINK_LTO)
    4796              :     return true;
    4797              : 
    4798              :   /* We may be smarter here and avoid streaming in indirect calls we can't
    4799              :      track, but that would require arranging streaming the indirect call
    4800              :      summary first.  */
    4801       481616 :   if (!callee)
    4802              :     return true;
    4803              : 
    4804              :   /* If callee is local to the original translation unit, it will be
    4805              :      defined.  */
    4806       478841 :   if (!TREE_PUBLIC (callee->decl) && !DECL_EXTERNAL (callee->decl))
    4807              :     return true;
    4808              : 
    4809              :   /* Otherwise we need to lookup prevailing symbol (symbol table is not merged,
    4810              :      yet) and see if it is a definition.  In fact we may also resolve aliases,
    4811              :      but that is probably not too important.  */
    4812       482529 :   symtab_node *node = callee;
    4813       482529 :   for (int n = 10; node->previous_sharing_asm_name && n ; n--)
    4814        10175 :     node = node->previous_sharing_asm_name;
    4815       472354 :   if (node->previous_sharing_asm_name)
    4816          234 :     node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (callee->decl));
    4817       472354 :   gcc_assert (TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl));
    4818       472354 :   return node->get_availability () >= AVAIL_INTERPOSABLE;
    4819              : }
    4820              : 
    4821              : /* Return num_speculative_targets of this edge.  */
    4822              : 
    4823              : int
    4824       197313 : cgraph_edge::num_speculative_call_targets_p (void)
    4825              : {
    4826       197313 :   return indirect_info ? indirect_info->num_speculative_call_targets : 0;
    4827              : }
    4828              : 
    4829              : /* Check if function calls comdat local.  This is used to recompute
    4830              :    calls_comdat_local flag after function transformations.  */
    4831              : bool
    4832     50236508 : cgraph_node::check_calls_comdat_local_p ()
    4833              : {
    4834    162380498 :   for (cgraph_edge *e = callees; e; e = e->next_callee)
    4835    116074218 :     if (e->inline_failed
    4836    121245763 :         ? e->callee->comdat_local_p ()
    4837      3874743 :         : e->callee->check_calls_comdat_local_p ())
    4838              :       return true;
    4839              :   return false;
    4840              : }
    4841              : 
    4842              : /* Return true if this node represents a former, i.e. an expanded, thunk.  */
    4843              : 
    4844              : bool
    4845      5174503 : cgraph_node::former_thunk_p (void)
    4846              : {
    4847      5174503 :   if (thunk)
    4848              :     return false;
    4849      5174503 :   thunk_info *i = thunk_info::get (this);
    4850      5174503 :   if (!i)
    4851              :     return false;
    4852           25 :   gcc_checking_assert (i->fixed_offset || i->virtual_offset_p
    4853              :                        || i->indirect_offset);
    4854              :   return true;
    4855              : }
    4856              : 
    4857              : /* A stashed copy of "symtab" for use by selftest::symbol_table_test.
    4858              :    This needs to be a global so that it can be a GC root, and thus
    4859              :    prevent the stashed copy from being garbage-collected if the GC runs
    4860              :    during a symbol_table_test.  */
    4861              : 
    4862              : symbol_table *saved_symtab;
    4863              : 
    4864              : #if CHECKING_P
    4865              : 
    4866              : namespace selftest {
    4867              : 
    4868              : /* class selftest::symbol_table_test.  */
    4869              : 
    4870              : /* Constructor.  Store the old value of symtab, and create a new one.  */
    4871              : 
    4872           64 : symbol_table_test::symbol_table_test ()
    4873              : {
    4874           64 :   gcc_assert (saved_symtab == NULL);
    4875           64 :   saved_symtab = symtab;
    4876           64 :   symtab = new (ggc_alloc<symbol_table> ()) symbol_table ();
    4877           64 : }
    4878              : 
    4879              : /* Destructor.  Restore the old value of symtab.  */
    4880              : 
    4881           64 : symbol_table_test::~symbol_table_test ()
    4882              : {
    4883           64 :   gcc_assert (saved_symtab != NULL);
    4884           64 :   symtab = saved_symtab;
    4885           64 :   saved_symtab = NULL;
    4886           64 : }
    4887              : 
    4888              : /* Verify that symbol_table_test works.  */
    4889              : 
    4890              : static void
    4891            4 : test_symbol_table_test ()
    4892              : {
    4893              :   /* Simulate running two selftests involving symbol tables.  */
    4894           12 :   for (int i = 0; i < 2; i++)
    4895              :     {
    4896            8 :       symbol_table_test stt;
    4897            8 :       tree test_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
    4898              :                                    get_identifier ("test_decl"),
    4899              :                                    build_function_type_list (void_type_node,
    4900              :                                                              NULL_TREE));
    4901            8 :       cgraph_node *node = cgraph_node::get_create (test_decl);
    4902            8 :       gcc_assert (node);
    4903              : 
    4904              :       /* Verify that the node has order 0 on both iterations,
    4905              :          and thus that nodes have predictable dump names in selftests.  */
    4906            8 :       ASSERT_EQ (node->order, 0);
    4907            8 :       ASSERT_STREQ (node->dump_name (), "test_decl/1");
    4908            8 :     }
    4909            4 : }
    4910              : 
    4911              : /* Run all of the selftests within this file.  */
    4912              : 
    4913              : void
    4914            4 : cgraph_cc_tests ()
    4915              : {
    4916            4 :   test_symbol_table_test ();
    4917            4 : }
    4918              : 
    4919              : } // namespace selftest
    4920              : 
    4921              : #endif /* CHECKING_P */
    4922              : 
    4923              : #include "gt-cgraph.h"
        

Generated by: LCOV version 2.4-beta

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