LCOV - code coverage report
Current view: top level - gcc - cgraph.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 82.8 % 2070 1714
Test Date: 2024-04-13 14:00:49 Functions: 93.5 % 123 115
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Callgraph handling code.
       2                 :             :    Copyright (C) 2003-2024 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                 :             : 
      73                 :             : /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this.  */
      74                 :             : #include "tree-pass.h"
      75                 :             : 
      76                 :             : /* Queue of cgraph nodes scheduled to be lowered.  */
      77                 :             : symtab_node *x_cgraph_nodes_queue;
      78                 :             : #define cgraph_nodes_queue ((cgraph_node *)x_cgraph_nodes_queue)
      79                 :             : 
      80                 :             : /* Symbol table global context.  */
      81                 :             : symbol_table *symtab;
      82                 :             : 
      83                 :             : /* List of hooks triggered on cgraph_edge events.  */
      84                 :             : struct cgraph_edge_hook_list {
      85                 :             :   cgraph_edge_hook hook;
      86                 :             :   void *data;
      87                 :             :   struct cgraph_edge_hook_list *next;
      88                 :             : };
      89                 :             : 
      90                 :             : /* List of hooks triggered on cgraph_node events.  */
      91                 :             : struct cgraph_node_hook_list {
      92                 :             :   cgraph_node_hook hook;
      93                 :             :   void *data;
      94                 :             :   struct cgraph_node_hook_list *next;
      95                 :             : };
      96                 :             : 
      97                 :             : /* List of hooks triggered on events involving two cgraph_edges.  */
      98                 :             : struct cgraph_2edge_hook_list {
      99                 :             :   cgraph_2edge_hook hook;
     100                 :             :   void *data;
     101                 :             :   struct cgraph_2edge_hook_list *next;
     102                 :             : };
     103                 :             : 
     104                 :             : /* List of hooks triggered on events involving two cgraph_nodes.  */
     105                 :             : struct cgraph_2node_hook_list {
     106                 :             :   cgraph_2node_hook hook;
     107                 :             :   void *data;
     108                 :             :   struct cgraph_2node_hook_list *next;
     109                 :             : };
     110                 :             : 
     111                 :             : /* Hash descriptor for cgraph_function_version_info.  */
     112                 :             : 
     113                 :             : struct function_version_hasher : ggc_ptr_hash<cgraph_function_version_info>
     114                 :             : {
     115                 :             :   static hashval_t hash (cgraph_function_version_info *);
     116                 :             :   static bool equal (cgraph_function_version_info *,
     117                 :             :                      cgraph_function_version_info *);
     118                 :             : };
     119                 :             : 
     120                 :             : /* Map a cgraph_node to cgraph_function_version_info using this htab.
     121                 :             :    The cgraph_function_version_info has a THIS_NODE field that is the
     122                 :             :    corresponding cgraph_node..  */
     123                 :             : 
     124                 :             : static GTY(()) hash_table<function_version_hasher> *cgraph_fnver_htab = NULL;
     125                 :             : 
     126                 :             : /* Hash function for cgraph_fnver_htab.  */
     127                 :             : hashval_t
     128                 :      109291 : function_version_hasher::hash (cgraph_function_version_info *ptr)
     129                 :             : {
     130                 :      109291 :   int uid = ptr->this_node->get_uid ();
     131                 :      109291 :   return (hashval_t)(uid);
     132                 :             : }
     133                 :             : 
     134                 :             : /* eq function for cgraph_fnver_htab.  */
     135                 :             : bool
     136                 :       89586 : function_version_hasher::equal (cgraph_function_version_info *n1,
     137                 :             :                                 cgraph_function_version_info *n2)
     138                 :             : {
     139                 :       89586 :   return n1->this_node->get_uid () == n2->this_node->get_uid ();
     140                 :             : }
     141                 :             : 
     142                 :             : /* Mark as GC root all allocated nodes.  */
     143                 :             : static GTY(()) struct cgraph_function_version_info *
     144                 :             :   version_info_node = NULL;
     145                 :             : 
     146                 :             : /* Return true if NODE's address can be compared.  */
     147                 :             : 
     148                 :             : bool
     149                 :     4956003 : symtab_node::address_can_be_compared_p ()
     150                 :             : {
     151                 :             :   /* Address of virtual tables and functions is never compared.  */
     152                 :     4956003 :   if (DECL_VIRTUAL_P (decl))
     153                 :             :     return false;
     154                 :             :   /* Address of C++ cdtors is never compared.  */
     155                 :     4873767 :   if (is_a <cgraph_node *> (this)
     156                 :      524552 :       && (DECL_CXX_CONSTRUCTOR_P (decl)
     157                 :      520297 :           || DECL_CXX_DESTRUCTOR_P (decl)))
     158                 :             :     return false;
     159                 :             :   /* Constant pool symbols addresses are never compared.
     160                 :             :      flag_merge_constants permits us to assume the same on readonly vars.  */
     161                 :     4867833 :   if (is_a <varpool_node *> (this)
     162                 :     4349215 :       && (DECL_IN_CONSTANT_POOL (decl)
     163                 :     4349212 :           || ((flag_merge_constants >= 2 || DECL_MERGEABLE (decl))
     164                 :        1513 :               && TREE_READONLY (decl) && !TREE_THIS_VOLATILE (decl))))
     165                 :        1509 :     return false;
     166                 :             :   return true;
     167                 :             : }
     168                 :             : 
     169                 :             : /* Get the cgraph_function_version_info node corresponding to node.  */
     170                 :             : cgraph_function_version_info *
     171                 :    87489435 : cgraph_node::function_version (void)
     172                 :             : {
     173                 :    87489435 :   cgraph_function_version_info key;
     174                 :    87489435 :   key.this_node = this;
     175                 :             : 
     176                 :    87489435 :   if (cgraph_fnver_htab == NULL)
     177                 :             :     return NULL;
     178                 :             : 
     179                 :       25324 :   return cgraph_fnver_htab->find (&key);
     180                 :             : }
     181                 :             : 
     182                 :             : /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
     183                 :             :    corresponding to cgraph_node NODE.  */
     184                 :             : cgraph_function_version_info *
     185                 :        1573 : cgraph_node::insert_new_function_version (void)
     186                 :             : {
     187                 :        1573 :   version_info_node = NULL;
     188                 :        1573 :   version_info_node = ggc_cleared_alloc<cgraph_function_version_info> ();
     189                 :        1573 :   version_info_node->this_node = this;
     190                 :             : 
     191                 :        1573 :   if (cgraph_fnver_htab == NULL)
     192                 :         198 :     cgraph_fnver_htab = hash_table<function_version_hasher>::create_ggc (2);
     193                 :             : 
     194                 :        1573 :   *cgraph_fnver_htab->find_slot (version_info_node, INSERT)
     195                 :        1573 :     = version_info_node;
     196                 :        1573 :   return version_info_node;
     197                 :             : }
     198                 :             : 
     199                 :             : /* Remove the cgraph_function_version_info node given by DECL_V.  */
     200                 :             : static void
     201                 :    84068379 : delete_function_version (cgraph_function_version_info *decl_v)
     202                 :             : {
     203                 :    84068379 :   if (decl_v == NULL)
     204                 :             :     return;
     205                 :             : 
     206                 :         281 :   if (version_info_node == decl_v)
     207                 :         225 :     version_info_node = NULL;
     208                 :             : 
     209                 :         281 :   if (decl_v->prev != NULL)
     210                 :         244 :     decl_v->prev->next = decl_v->next;
     211                 :             : 
     212                 :         281 :   if (decl_v->next != NULL)
     213                 :          17 :     decl_v->next->prev = decl_v->prev;
     214                 :             : 
     215                 :         281 :   if (cgraph_fnver_htab != NULL)
     216                 :         281 :     cgraph_fnver_htab->remove_elt (decl_v);
     217                 :             : }
     218                 :             : 
     219                 :             : /* Remove the cgraph_function_version_info and cgraph_node for DECL.  This
     220                 :             :    DECL is a duplicate declaration.  */
     221                 :             : void
     222                 :         284 : cgraph_node::delete_function_version_by_decl (tree decl)
     223                 :             : {
     224                 :         284 :   cgraph_node *decl_node = cgraph_node::get (decl);
     225                 :             : 
     226                 :         284 :   if (decl_node == NULL)
     227                 :             :     return;
     228                 :             : 
     229                 :         224 :   delete_function_version (decl_node->function_version ());
     230                 :             : 
     231                 :         224 :   decl_node->remove ();
     232                 :             : }
     233                 :             : 
     234                 :             : /* Record that DECL1 and DECL2 are semantically identical function
     235                 :             :    versions.  */
     236                 :             : void
     237                 :        1028 : cgraph_node::record_function_versions (tree decl1, tree decl2)
     238                 :             : {
     239                 :        1028 :   cgraph_node *decl1_node = cgraph_node::get_create (decl1);
     240                 :        1028 :   cgraph_node *decl2_node = cgraph_node::get_create (decl2);
     241                 :        1028 :   cgraph_function_version_info *decl1_v = NULL;
     242                 :        1028 :   cgraph_function_version_info *decl2_v = NULL;
     243                 :        1028 :   cgraph_function_version_info *before;
     244                 :        1028 :   cgraph_function_version_info *after;
     245                 :             : 
     246                 :        1028 :   gcc_assert (decl1_node != NULL && decl2_node != NULL);
     247                 :        1028 :   decl1_v = decl1_node->function_version ();
     248                 :        1028 :   decl2_v = decl2_node->function_version ();
     249                 :             : 
     250                 :        1028 :   if (decl1_v != NULL && decl2_v != NULL)
     251                 :             :     return;
     252                 :             : 
     253                 :        1028 :   if (decl1_v == NULL)
     254                 :         176 :     decl1_v = decl1_node->insert_new_function_version ();
     255                 :             : 
     256                 :        1028 :   if (decl2_v == NULL)
     257                 :        1028 :     decl2_v = decl2_node->insert_new_function_version ();
     258                 :             : 
     259                 :             :   /* Chain decl2_v and decl1_v.  All semantically identical versions
     260                 :             :      will be chained together.  */
     261                 :             : 
     262                 :        1028 :   before = decl1_v;
     263                 :        1028 :   after = decl2_v;
     264                 :             : 
     265                 :        1028 :   while (before->next != NULL)
     266                 :             :     before = before->next;
     267                 :             : 
     268                 :        1028 :   while (after->prev != NULL)
     269                 :             :     after= after->prev;
     270                 :             : 
     271                 :        1028 :   before->next = after;
     272                 :        1028 :   after->prev = before;
     273                 :             : }
     274                 :             : 
     275                 :             : /* Initialize callgraph dump file.  */
     276                 :             : 
     277                 :             : void
     278                 :      296229 : symbol_table::initialize (void)
     279                 :             : {
     280                 :      296229 :   if (!dump_file)
     281                 :      296227 :     dump_file = dump_begin (TDI_cgraph, NULL);
     282                 :             : 
     283                 :      296229 :   if (!ipa_clones_dump_file)
     284                 :      296229 :     ipa_clones_dump_file = dump_begin (TDI_clones, NULL);
     285                 :      296229 : }
     286                 :             : 
     287                 :             : /* Allocate new callgraph node and insert it into basic data structures.  */
     288                 :             : 
     289                 :             : cgraph_node *
     290                 :    87606128 : symbol_table::create_empty (void)
     291                 :             : {
     292                 :    87606128 :   cgraph_count++;
     293                 :    87606128 :   return new (ggc_alloc<cgraph_node> ()) cgraph_node (cgraph_max_uid++);
     294                 :             : }
     295                 :             : 
     296                 :             : /* Register HOOK to be called with DATA on each removed edge.  */
     297                 :             : cgraph_edge_hook_list *
     298                 :     1833645 : symbol_table::add_edge_removal_hook (cgraph_edge_hook hook, void *data)
     299                 :             : {
     300                 :     1833645 :   cgraph_edge_hook_list *entry;
     301                 :     1833645 :   cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
     302                 :             : 
     303                 :     1833645 :   entry = (cgraph_edge_hook_list *) xmalloc (sizeof (*entry));
     304                 :     1833645 :   entry->hook = hook;
     305                 :     1833645 :   entry->data = data;
     306                 :     1833645 :   entry->next = NULL;
     307                 :     6314436 :   while (*ptr)
     308                 :     4480791 :     ptr = &(*ptr)->next;
     309                 :     1833645 :   *ptr = entry;
     310                 :     1833645 :   return entry;
     311                 :             : }
     312                 :             : 
     313                 :             : /* Remove ENTRY from the list of hooks called on removing edges.  */
     314                 :             : void
     315                 :     1833629 : symbol_table::remove_edge_removal_hook (cgraph_edge_hook_list *entry)
     316                 :             : {
     317                 :     1833629 :   cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
     318                 :             : 
     319                 :     4982946 :   while (*ptr != entry)
     320                 :     3149317 :     ptr = &(*ptr)->next;
     321                 :     1833629 :   *ptr = entry->next;
     322                 :     1833629 :   free (entry);
     323                 :     1833629 : }
     324                 :             : 
     325                 :             : /* Call all edge removal hooks.  */
     326                 :             : void
     327                 :    38757135 : symbol_table::call_edge_removal_hooks (cgraph_edge *e)
     328                 :             : {
     329                 :    38757135 :   cgraph_edge_hook_list *entry = m_first_edge_removal_hook;
     330                 :    62451686 :   while (entry)
     331                 :             :   {
     332                 :    23694551 :     entry->hook (e, entry->data);
     333                 :    23694551 :     entry = entry->next;
     334                 :             :   }
     335                 :    38757135 : }
     336                 :             : 
     337                 :             : /* Register HOOK to be called with DATA on each removed node.  */
     338                 :             : cgraph_node_hook_list *
     339                 :     7316047 : symbol_table::add_cgraph_removal_hook (cgraph_node_hook hook, void *data)
     340                 :             : {
     341                 :     7316047 :   cgraph_node_hook_list *entry;
     342                 :     7316047 :   cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
     343                 :             : 
     344                 :     7316047 :   entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
     345                 :     7316047 :   entry->hook = hook;
     346                 :     7316047 :   entry->data = data;
     347                 :     7316047 :   entry->next = NULL;
     348                 :    37596044 :   while (*ptr)
     349                 :    30279997 :     ptr = &(*ptr)->next;
     350                 :     7316047 :   *ptr = entry;
     351                 :     7316047 :   return entry;
     352                 :             : }
     353                 :             : 
     354                 :             : /* Remove ENTRY from the list of hooks called on removing nodes.  */
     355                 :             : void
     356                 :     7218772 : symbol_table::remove_cgraph_removal_hook (cgraph_node_hook_list *entry)
     357                 :             : {
     358                 :     7218772 :   cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
     359                 :             : 
     360                 :    33293656 :   while (*ptr != entry)
     361                 :    26074884 :     ptr = &(*ptr)->next;
     362                 :     7218772 :   *ptr = entry->next;
     363                 :     7218772 :   free (entry);
     364                 :     7218772 : }
     365                 :             : 
     366                 :             : /* Call all node removal hooks.  */
     367                 :             : void
     368                 :    84099290 : symbol_table::call_cgraph_removal_hooks (cgraph_node *node)
     369                 :             : {
     370                 :    84099290 :   cgraph_node_hook_list *entry = m_first_cgraph_removal_hook;
     371                 :   117189839 :   while (entry)
     372                 :             :   {
     373                 :    33090549 :     entry->hook (node, entry->data);
     374                 :    33090549 :     entry = entry->next;
     375                 :             :   }
     376                 :    84099290 : }
     377                 :             : 
     378                 :             : /* Call all node removal hooks.  */
     379                 :             : void
     380                 :      109826 : symbol_table::call_cgraph_insertion_hooks (cgraph_node *node)
     381                 :             : {
     382                 :      109826 :   cgraph_node_hook_list *entry = m_first_cgraph_insertion_hook;
     383                 :      325402 :   while (entry)
     384                 :             :   {
     385                 :      215576 :     entry->hook (node, entry->data);
     386                 :      215576 :     entry = entry->next;
     387                 :             :   }
     388                 :      109826 : }
     389                 :             : 
     390                 :             : 
     391                 :             : /* Register HOOK to be called with DATA on each inserted node.  */
     392                 :             : cgraph_node_hook_list *
     393                 :     7787800 : symbol_table::add_cgraph_insertion_hook (cgraph_node_hook hook, void *data)
     394                 :             : {
     395                 :     7787800 :   cgraph_node_hook_list *entry;
     396                 :     7787800 :   cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
     397                 :             : 
     398                 :     7787800 :   entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
     399                 :     7787800 :   entry->hook = hook;
     400                 :     7787800 :   entry->data = data;
     401                 :     7787800 :   entry->next = NULL;
     402                 :    22984244 :   while (*ptr)
     403                 :    15196444 :     ptr = &(*ptr)->next;
     404                 :     7787800 :   *ptr = entry;
     405                 :     7787800 :   return entry;
     406                 :             : }
     407                 :             : 
     408                 :             : /* Remove ENTRY from the list of hooks called on inserted nodes.  */
     409                 :             : void
     410                 :     7647859 : symbol_table::remove_cgraph_insertion_hook (cgraph_node_hook_list *entry)
     411                 :             : {
     412                 :     7647859 :   cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
     413                 :             : 
     414                 :    20962182 :   while (*ptr != entry)
     415                 :    13314323 :     ptr = &(*ptr)->next;
     416                 :     7647859 :   *ptr = entry->next;
     417                 :     7647859 :   free (entry);
     418                 :     7647859 : }
     419                 :             : 
     420                 :             : /* Register HOOK to be called with DATA on each duplicated edge.  */
     421                 :             : cgraph_2edge_hook_list *
     422                 :     1609027 : symbol_table::add_edge_duplication_hook (cgraph_2edge_hook hook, void *data)
     423                 :             : {
     424                 :     1609027 :   cgraph_2edge_hook_list *entry;
     425                 :     1609027 :   cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
     426                 :             : 
     427                 :     1609027 :   entry = (cgraph_2edge_hook_list *) xmalloc (sizeof (*entry));
     428                 :     1609027 :   entry->hook = hook;
     429                 :     1609027 :   entry->data = data;
     430                 :     1609027 :   entry->next = NULL;
     431                 :     5138198 :   while (*ptr)
     432                 :     3529171 :     ptr = &(*ptr)->next;
     433                 :     1609027 :   *ptr = entry;
     434                 :     1609027 :   return entry;
     435                 :             : }
     436                 :             : 
     437                 :             : /* Remove ENTRY from the list of hooks called on duplicating edges.  */
     438                 :             : void
     439                 :     1609011 : symbol_table::remove_edge_duplication_hook (cgraph_2edge_hook_list *entry)
     440                 :             : {
     441                 :     1609011 :   cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
     442                 :             : 
     443                 :     3806708 :   while (*ptr != entry)
     444                 :     2197697 :     ptr = &(*ptr)->next;
     445                 :     1609011 :   *ptr = entry->next;
     446                 :     1609011 :   free (entry);
     447                 :     1609011 : }
     448                 :             : 
     449                 :             : /* Call all edge duplication hooks.  */
     450                 :             : void
     451                 :     5198472 : symbol_table::call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2)
     452                 :             : {
     453                 :     5198472 :   cgraph_2edge_hook_list *entry = m_first_edge_duplicated_hook;
     454                 :    15335493 :   while (entry)
     455                 :             :   {
     456                 :    10137021 :     entry->hook (cs1, cs2, entry->data);
     457                 :    10137021 :     entry = entry->next;
     458                 :             :   }
     459                 :     5198472 : }
     460                 :             : 
     461                 :             : /* Register HOOK to be called with DATA on each duplicated node.  */
     462                 :             : cgraph_2node_hook_list *
     463                 :     7181236 : symbol_table::add_cgraph_duplication_hook (cgraph_2node_hook hook, void *data)
     464                 :             : {
     465                 :     7181236 :   cgraph_2node_hook_list *entry;
     466                 :     7181236 :   cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
     467                 :             : 
     468                 :     7181236 :   entry = (cgraph_2node_hook_list *) xmalloc (sizeof (*entry));
     469                 :     7181236 :   entry->hook = hook;
     470                 :     7181236 :   entry->data = data;
     471                 :     7181236 :   entry->next = NULL;
     472                 :    34934803 :   while (*ptr)
     473                 :    27753567 :     ptr = &(*ptr)->next;
     474                 :     7181236 :   *ptr = entry;
     475                 :     7181236 :   return entry;
     476                 :             : }
     477                 :             : 
     478                 :             : /* Remove ENTRY from the list of hooks called on duplicating nodes.  */
     479                 :             : void
     480                 :     7096419 : symbol_table::remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry)
     481                 :             : {
     482                 :     7096419 :   cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
     483                 :             : 
     484                 :    31532254 :   while (*ptr != entry)
     485                 :    24435835 :     ptr = &(*ptr)->next;
     486                 :     7096419 :   *ptr = entry->next;
     487                 :     7096419 :   free (entry);
     488                 :     7096419 : }
     489                 :             : 
     490                 :             : /* Call all node duplication hooks.  */
     491                 :             : void
     492                 :     2385014 : symbol_table::call_cgraph_duplication_hooks (cgraph_node *node,
     493                 :             :                                              cgraph_node *node2)
     494                 :             : {
     495                 :     2385014 :   cgraph_2node_hook_list *entry = m_first_cgraph_duplicated_hook;
     496                 :    16843893 :   while (entry)
     497                 :             :   {
     498                 :    14458879 :     entry->hook (node, node2, entry->data);
     499                 :    14458879 :     entry = entry->next;
     500                 :             :   }
     501                 :     2385014 : }
     502                 :             : 
     503                 :             : /* Return cgraph node assigned to DECL.  Create new one when needed.  */
     504                 :             : 
     505                 :             : cgraph_node *
     506                 :    85033258 : cgraph_node::create (tree decl)
     507                 :             : {
     508                 :    85033258 :   cgraph_node *node = symtab->create_empty ();
     509                 :    85033258 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
     510                 :             : 
     511                 :    85033258 :   node->decl = decl;
     512                 :    85033258 :   node->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
     513                 :             : 
     514                 :    84982851 :   if ((flag_openacc || flag_openmp)
     515                 :    85185280 :       && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
     516                 :             :     {
     517                 :        7542 :       node->offloadable = 1;
     518                 :        7542 :       if (ENABLE_OFFLOADING)
     519                 :             :         g->have_offload = true;
     520                 :             :     }
     521                 :             : 
     522                 :    85033258 :   if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
     523                 :         127 :     node->ifunc_resolver = true;
     524                 :             : 
     525                 :    85033258 :   node->register_symbol ();
     526                 :    85033258 :   maybe_record_nested_function (node);
     527                 :             : 
     528                 :    85033258 :   return node;
     529                 :             : }
     530                 :             : 
     531                 :             : /* Try to find a call graph node for declaration DECL and if it does not exist
     532                 :             :    or if it corresponds to an inline clone, create a new one.  */
     533                 :             : 
     534                 :             : cgraph_node *
     535                 :   446074323 : cgraph_node::get_create (tree decl)
     536                 :             : {
     537                 :   446074323 :   cgraph_node *first_clone = cgraph_node::get (decl);
     538                 :             : 
     539                 :   446074323 :   if (first_clone && !first_clone->inlined_to)
     540                 :             :     return first_clone;
     541                 :             : 
     542                 :    84974030 :   cgraph_node *node = cgraph_node::create (decl);
     543                 :    84974030 :   if (first_clone)
     544                 :             :     {
     545                 :           7 :       first_clone->clone_of = node;
     546                 :           7 :       node->clones = first_clone;
     547                 :           7 :       node->order = first_clone->order;
     548                 :           7 :       symtab->symtab_prevail_in_asm_name_hash (node);
     549                 :           7 :       node->decl->decl_with_vis.symtab_node = node;
     550                 :           7 :       if (dump_file && symtab->state != PARSING)
     551                 :           2 :         fprintf (dump_file, "Introduced new external node "
     552                 :             :                  "(%s) and turned into root of the clone tree.\n",
     553                 :             :                  node->dump_name ());
     554                 :             :     }
     555                 :    84974023 :   else if (dump_file && symtab->state != PARSING)
     556                 :        1226 :     fprintf (dump_file, "Introduced new external node "
     557                 :             :              "(%s).\n", node->dump_name ());
     558                 :             :   return node;
     559                 :             : }
     560                 :             : 
     561                 :             : /* Mark ALIAS as an alias to DECL.  DECL_NODE is cgraph node representing
     562                 :             :    the function body is associated with
     563                 :             :    (not necessarily cgraph_node (DECL)).  */
     564                 :             : 
     565                 :             : cgraph_node *
     566                 :     6221766 : cgraph_node::create_alias (tree alias, tree target)
     567                 :             : {
     568                 :     6221766 :   cgraph_node *alias_node;
     569                 :             : 
     570                 :     6221766 :   gcc_assert (TREE_CODE (target) == FUNCTION_DECL
     571                 :             :               || TREE_CODE (target) == IDENTIFIER_NODE);
     572                 :     6221766 :   gcc_assert (TREE_CODE (alias) == FUNCTION_DECL);
     573                 :     6221766 :   alias_node = cgraph_node::get_create (alias);
     574                 :     6221766 :   gcc_assert (!alias_node->definition);
     575                 :     6221766 :   alias_node->alias_target = target;
     576                 :     6221766 :   alias_node->definition = true;
     577                 :     6221766 :   alias_node->alias = true;
     578                 :     6221766 :   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
     579                 :         175 :     alias_node->transparent_alias = alias_node->weakref = true;
     580                 :     6221766 :   if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias)))
     581                 :         305 :     alias_node->ifunc_resolver = true;
     582                 :     6221766 :   return alias_node;
     583                 :             : }
     584                 :             : 
     585                 :             : /* Attempt to mark ALIAS as an alias to DECL.  Return alias node if successful
     586                 :             :    and NULL otherwise.
     587                 :             :    Same body aliases are output whenever the body of DECL is output,
     588                 :             :    and cgraph_node::get (ALIAS) transparently returns
     589                 :             :    cgraph_node::get (DECL).  */
     590                 :             : 
     591                 :             : cgraph_node *
     592                 :     6202333 : cgraph_node::create_same_body_alias (tree alias, tree decl)
     593                 :             : {
     594                 :     6202333 :   cgraph_node *n;
     595                 :             : 
     596                 :             :   /* If aliases aren't supported by the assembler, fail.  */
     597                 :     6202333 :   if (!TARGET_SUPPORTS_ALIASES)
     598                 :             :     return NULL;
     599                 :             : 
     600                 :             :   /* Langhooks can create same body aliases of symbols not defined.
     601                 :             :      Those are useless. Drop them on the floor.  */
     602                 :     6202333 :   if (symtab->global_info_ready)
     603                 :             :     return NULL;
     604                 :             : 
     605                 :     6202333 :   n = cgraph_node::create_alias (alias, decl);
     606                 :     6202333 :   n->cpp_implicit_alias = true;
     607                 :     6202333 :   if (symtab->cpp_implicit_aliases_done)
     608                 :     3463580 :     n->resolve_alias (cgraph_node::get (decl));
     609                 :             :   return n;
     610                 :             : }
     611                 :             : 
     612                 :             : /* Add thunk alias into callgraph.  The alias declaration is ALIAS and it
     613                 :             :    aliases DECL with an adjustments made into the first parameter.
     614                 :             :    See comments in struct cgraph_thunk_info for detail on the parameters.  */
     615                 :             : 
     616                 :             : cgraph_node *
     617                 :        5282 : cgraph_node::create_thunk (tree alias, tree, bool this_adjusting,
     618                 :             :                            HOST_WIDE_INT fixed_offset,
     619                 :             :                            HOST_WIDE_INT virtual_value,
     620                 :             :                            HOST_WIDE_INT indirect_offset,
     621                 :             :                            tree virtual_offset,
     622                 :             :                            tree real_alias)
     623                 :             : {
     624                 :        5282 :   cgraph_node *node;
     625                 :             : 
     626                 :        5282 :   node = cgraph_node::get (alias);
     627                 :        5282 :   if (node)
     628                 :        4392 :     node->reset ();
     629                 :             :   else
     630                 :         890 :     node = cgraph_node::create (alias);
     631                 :             : 
     632                 :             :   /* Make sure that if VIRTUAL_OFFSET is in sync with VIRTUAL_VALUE.  */
     633                 :        5282 :   gcc_checking_assert (virtual_offset
     634                 :             :                        ? virtual_value == wi::to_wide (virtual_offset)
     635                 :             :                        : virtual_value == 0);
     636                 :             : 
     637                 :        5282 :   node->thunk = true;
     638                 :        5282 :   node->definition = true;
     639                 :             : 
     640                 :        5282 :   thunk_info *i;
     641                 :        5282 :   thunk_info local_info;
     642                 :        5282 :   if (symtab->state < CONSTRUCTION)
     643                 :             :     i = &local_info;
     644                 :             :   else
     645                 :           0 :     i = thunk_info::get_create (node);
     646                 :        5282 :   i->fixed_offset = fixed_offset;
     647                 :        5282 :   i->virtual_value = virtual_value;
     648                 :        5282 :   i->indirect_offset = indirect_offset;
     649                 :        5282 :   i->alias = real_alias;
     650                 :        5282 :   i->this_adjusting = this_adjusting;
     651                 :        5282 :   i->virtual_offset_p = virtual_offset != NULL;
     652                 :        5282 :   if (symtab->state < CONSTRUCTION)
     653                 :        5282 :     i->register_early (node);
     654                 :             : 
     655                 :        5282 :   return node;
     656                 :             : }
     657                 :             : 
     658                 :             : /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
     659                 :             :    Return NULL if there's no such node.  */
     660                 :             : 
     661                 :             : cgraph_node *
     662                 :           0 : cgraph_node::get_for_asmname (tree asmname)
     663                 :             : {
     664                 :             :   /* We do not want to look at inline clones.  */
     665                 :           0 :   for (symtab_node *node = symtab_node::get_for_asmname (asmname);
     666                 :           0 :        node;
     667                 :           0 :        node = node->next_sharing_asm_name)
     668                 :             :     {
     669                 :           0 :       cgraph_node *cn = dyn_cast <cgraph_node *> (node);
     670                 :           0 :       if (cn && !cn->inlined_to)
     671                 :           0 :         return cn;
     672                 :             :     }
     673                 :             :   return NULL;
     674                 :             : }
     675                 :             : 
     676                 :             : /* Returns a hash value for X (which really is a cgraph_edge).  */
     677                 :             : 
     678                 :             : hashval_t
     679                 :   199132715 : cgraph_edge_hasher::hash (cgraph_edge *e)
     680                 :             : {
     681                 :             :   /* This is a really poor hash function, but it is what htab_hash_pointer
     682                 :             :      uses.  */
     683                 :   199132715 :   return (hashval_t) ((intptr_t)e->call_stmt >> 3);
     684                 :             : }
     685                 :             : 
     686                 :             : /* Returns a hash value for X (which really is a cgraph_edge).  */
     687                 :             : 
     688                 :             : hashval_t
     689                 :    38869566 : cgraph_edge_hasher::hash (gimple *call_stmt)
     690                 :             : {
     691                 :             :   /* This is a really poor hash function, but it is what htab_hash_pointer
     692                 :             :      uses.  */
     693                 :    38869566 :   return (hashval_t) ((intptr_t)call_stmt >> 3);
     694                 :             : }
     695                 :             : 
     696                 :             : /* Return nonzero if the call_stmt of cgraph_edge X is stmt *Y.  */
     697                 :             : 
     698                 :             : inline bool
     699                 :   249369196 : cgraph_edge_hasher::equal (cgraph_edge *x, gimple *y)
     700                 :             : {
     701                 :   249369196 :   return x->call_stmt == y;
     702                 :             : }
     703                 :             : 
     704                 :             : /* Add call graph edge E to call site hash of its caller.  */
     705                 :             : 
     706                 :             : static inline void
     707                 :        1997 : cgraph_update_edge_in_call_site_hash (cgraph_edge *e)
     708                 :             : {
     709                 :        1997 :   gimple *call = e->call_stmt;
     710                 :        1997 :   *e->caller->call_site_hash->find_slot_with_hash
     711                 :        1997 :       (call, cgraph_edge_hasher::hash (call), INSERT) = e;
     712                 :        1997 : }
     713                 :             : 
     714                 :             : /* Add call graph edge E to call site hash of its caller.  */
     715                 :             : 
     716                 :             : static inline void
     717                 :     7402681 : cgraph_add_edge_to_call_site_hash (cgraph_edge *e)
     718                 :             : {
     719                 :             :   /* There are two speculative edges for every statement (one direct,
     720                 :             :      one indirect); always hash the direct one.  */
     721                 :     7402681 :   if (e->speculative && e->indirect_unknown_callee)
     722                 :             :     return;
     723                 :     7402676 :   cgraph_edge **slot = e->caller->call_site_hash->find_slot_with_hash
     724                 :     7402676 :       (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt), INSERT);
     725                 :     7402676 :   if (*slot)
     726                 :             :     {
     727                 :        1992 :       gcc_assert (((cgraph_edge *)*slot)->speculative);
     728                 :        1992 :       if (e->callee && (!e->prev_callee
     729                 :           0 :                         || !e->prev_callee->speculative
     730                 :           0 :                         || e->prev_callee->call_stmt != e->call_stmt))
     731                 :           0 :         *slot = e;
     732                 :        1992 :       return;
     733                 :             :     }
     734                 :     7400684 :   gcc_assert (!*slot || e->speculative);
     735                 :     7400684 :   *slot = e;
     736                 :             : }
     737                 :             : 
     738                 :             : /* Return the callgraph edge representing the GIMPLE_CALL statement
     739                 :             :    CALL_STMT.  */
     740                 :             : 
     741                 :             : cgraph_edge *
     742                 :   178776938 : cgraph_node::get_edge (gimple *call_stmt)
     743                 :             : {
     744                 :   178776938 :   cgraph_edge *e, *e2;
     745                 :   178776938 :   int n = 0;
     746                 :             : 
     747                 :   178776938 :   if (call_site_hash)
     748                 :    30558734 :     return call_site_hash->find_with_hash
     749                 :    30558734 :         (call_stmt, cgraph_edge_hasher::hash (call_stmt));
     750                 :             : 
     751                 :             :   /* This loop may turn out to be performance problem.  In such case adding
     752                 :             :      hashtables into call nodes with very many edges is probably best
     753                 :             :      solution.  It is not good idea to add pointer into CALL_EXPR itself
     754                 :             :      because we want to make possible having multiple cgraph nodes representing
     755                 :             :      different clones of the same body before the body is actually cloned.  */
     756                 :  1435738269 :   for (e = callees; e; e = e->next_callee)
     757                 :             :     {
     758                 :  1395466421 :       if (e->call_stmt == call_stmt)
     759                 :             :         break;
     760                 :  1287520065 :       n++;
     761                 :             :     }
     762                 :             : 
     763                 :   148218204 :   if (!e)
     764                 :    52999969 :     for (e = indirect_calls; e; e = e->next_callee)
     765                 :             :       {
     766                 :    15476118 :         if (e->call_stmt == call_stmt)
     767                 :             :           break;
     768                 :    12728121 :         n++;
     769                 :             :       }
     770                 :             : 
     771                 :   148218204 :   if (n > 100)
     772                 :             :     {
     773                 :       26223 :       call_site_hash = hash_table<cgraph_edge_hasher>::create_ggc (120);
     774                 :     2699051 :       for (e2 = callees; e2; e2 = e2->next_callee)
     775                 :     2672828 :         cgraph_add_edge_to_call_site_hash (e2);
     776                 :      106738 :       for (e2 = indirect_calls; e2; e2 = e2->next_callee)
     777                 :       80515 :         cgraph_add_edge_to_call_site_hash (e2);
     778                 :             :     }
     779                 :             : 
     780                 :             :   return e;
     781                 :             : }
     782                 :             : 
     783                 :             : 
     784                 :             : /* Change field call_stmt of edge E to NEW_STMT.  If UPDATE_SPECULATIVE and E
     785                 :             :    is any component of speculative edge, then update all components.
     786                 :             :    Speculations can be resolved in the process and EDGE can be removed and
     787                 :             :    deallocated.  Return the edge that now represents the call.  */
     788                 :             : 
     789                 :             : cgraph_edge *
     790                 :     2032874 : cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
     791                 :             :                             bool update_speculative)
     792                 :             : {
     793                 :     2032874 :   tree decl;
     794                 :             : 
     795                 :     2032874 :   cgraph_node *new_direct_callee = NULL;
     796                 :     2032874 :   if ((e->indirect_unknown_callee || e->speculative)
     797                 :     2063308 :       && (decl = gimple_call_fndecl (new_stmt)))
     798                 :             :     {
     799                 :             :       /* Constant propagation and especially inlining can turn an indirect call
     800                 :             :          into a direct one.  */
     801                 :           0 :       new_direct_callee = cgraph_node::get (decl);
     802                 :           0 :       gcc_checking_assert (new_direct_callee);
     803                 :             :     }
     804                 :             : 
     805                 :             :   /* Speculative edges has three component, update all of them
     806                 :             :      when asked to.  */
     807                 :     2032874 :   if (update_speculative && e->speculative
     808                 :             :       /* If we are about to resolve the speculation by calling make_direct
     809                 :             :          below, do not bother going over all the speculative edges now.  */
     810                 :        2015 :       && !new_direct_callee)
     811                 :             :     {
     812                 :        2015 :       cgraph_edge *direct, *indirect, *next;
     813                 :        2015 :       ipa_ref *ref;
     814                 :        2015 :       bool e_indirect = e->indirect_unknown_callee;
     815                 :        2015 :       int n = 0;
     816                 :             : 
     817                 :        2015 :       direct = e->first_speculative_call_target ();
     818                 :        2015 :       indirect = e->speculative_call_indirect_edge ();
     819                 :             : 
     820                 :        2015 :       gcall *old_stmt = direct->call_stmt;
     821                 :        4030 :       for (cgraph_edge *d = direct; d; d = next)
     822                 :             :         {
     823                 :        2015 :           next = d->next_speculative_call_target ();
     824                 :        2015 :           cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
     825                 :        2015 :           gcc_assert (d2 == d);
     826                 :        2015 :           n++;
     827                 :             :         }
     828                 :        2015 :       gcc_checking_assert (indirect->num_speculative_call_targets_p () == n);
     829                 :        5251 :       for (unsigned int i = 0; e->caller->iterate_reference (i, ref); i++)
     830                 :        3236 :         if (ref->speculative && ref->stmt == old_stmt)
     831                 :             :           {
     832                 :        2015 :             ref->stmt = new_stmt;
     833                 :        2015 :             n--;
     834                 :             :           }
     835                 :             : 
     836                 :        2015 :       indirect = set_call_stmt (indirect, new_stmt, false);
     837                 :        2015 :       return e_indirect ? indirect : direct;
     838                 :             :     }
     839                 :             : 
     840                 :     2030859 :   if (new_direct_callee)
     841                 :           0 :     e = make_direct (e, new_direct_callee);
     842                 :             : 
     843                 :             :   /* Only direct speculative edges go to call_site_hash.  */
     844                 :     2030859 :   if (e->caller->call_site_hash
     845                 :      436729 :       && (!e->speculative || !e->indirect_unknown_callee)
     846                 :             :       /* It is possible that edge was previously speculative.  In this case
     847                 :             :          we have different value in call stmt hash which needs preserving.  */
     848                 :     2467588 :       && e->caller->get_edge (e->call_stmt) == e)
     849                 :      434732 :     e->caller->call_site_hash->remove_elt_with_hash
     850                 :      434732 :       (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt));
     851                 :             : 
     852                 :     2030859 :   e->call_stmt = new_stmt;
     853                 :             : 
     854                 :     2030859 :   function *fun = DECL_STRUCT_FUNCTION (e->caller->decl);
     855                 :     2030859 :   e->can_throw_external = stmt_can_throw_external (fun, new_stmt);
     856                 :             :   /* Update call stite hash.  For speculative calls we only record the first
     857                 :             :      direct edge.  */
     858                 :     2030859 :   if (e->caller->call_site_hash
     859                 :      436729 :       && (!e->speculative
     860                 :           0 :           || (e->callee
     861                 :           0 :               && (!e->prev_callee || !e->prev_callee->speculative
     862                 :           0 :                   || e->prev_callee->call_stmt != e->call_stmt))
     863                 :           0 :           || (e->speculative && !e->callee)))
     864                 :      436729 :     cgraph_add_edge_to_call_site_hash (e);
     865                 :             :   return e;
     866                 :             : }
     867                 :             : 
     868                 :             : /* Allocate a cgraph_edge structure and fill it with data according to the
     869                 :             :    parameters of which only CALLEE can be NULL (when creating an indirect call
     870                 :             :    edge).  CLONING_P should be set if properties that are copied from an
     871                 :             :    original edge should not be calculated.  */
     872                 :             : 
     873                 :             : cgraph_edge *
     874                 :    39177756 : symbol_table::create_edge (cgraph_node *caller, cgraph_node *callee,
     875                 :             :                            gcall *call_stmt, profile_count count,
     876                 :             :                            bool indir_unknown_callee, bool cloning_p)
     877                 :             : {
     878                 :    39177756 :   cgraph_edge *edge;
     879                 :             : 
     880                 :             :   /* LTO does not actually have access to the call_stmt since these
     881                 :             :      have not been loaded yet.  */
     882                 :    39177756 :   if (call_stmt)
     883                 :             :     {
     884                 :             :       /* This is a rather expensive check possibly triggering
     885                 :             :          construction of call stmt hashtable.  */
     886                 :    38339616 :       cgraph_edge *e;
     887                 :    38339616 :       gcc_checking_assert (!(e = caller->get_edge (call_stmt))
     888                 :             :                            || e->speculative);
     889                 :             : 
     890                 :    38339616 :       gcc_assert (is_gimple_call (call_stmt));
     891                 :             :     }
     892                 :             : 
     893                 :    39177756 :   edge = ggc_alloc<cgraph_edge> ();
     894                 :    39177756 :   edge->m_summary_id = -1;
     895                 :    39177756 :   edges_count++;
     896                 :             : 
     897                 :    39177756 :   gcc_assert (++edges_max_uid != 0);
     898                 :    39177756 :   edge->m_uid = edges_max_uid;
     899                 :    39177756 :   edge->aux = NULL;
     900                 :    39177756 :   edge->caller = caller;
     901                 :    39177756 :   edge->callee = callee;
     902                 :    39177756 :   edge->prev_caller = NULL;
     903                 :    39177756 :   edge->next_caller = NULL;
     904                 :    39177756 :   edge->prev_callee = NULL;
     905                 :    39177756 :   edge->next_callee = NULL;
     906                 :    39177756 :   edge->lto_stmt_uid = 0;
     907                 :    39177756 :   edge->speculative_id = 0;
     908                 :             : 
     909                 :    39177756 :   edge->count = count;
     910                 :    39177756 :   edge->call_stmt = call_stmt;
     911                 :    39177756 :   edge->indirect_info = NULL;
     912                 :    39177756 :   edge->indirect_inlining_edge = 0;
     913                 :    39177756 :   edge->speculative = false;
     914                 :    39177756 :   edge->indirect_unknown_callee = indir_unknown_callee;
     915                 :    39177756 :   if (call_stmt && caller->call_site_hash)
     916                 :     4212609 :     cgraph_add_edge_to_call_site_hash (edge);
     917                 :             : 
     918                 :    39177756 :   if (cloning_p)
     919                 :             :     return edge;
     920                 :             : 
     921                 :    33984205 :   edge->can_throw_external
     922                 :    33984205 :     = call_stmt ? stmt_can_throw_external (DECL_STRUCT_FUNCTION (caller->decl),
     923                 :             :                                            call_stmt) : false;
     924                 :    33984205 :   edge->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
     925                 :    33984205 :   edge->call_stmt_cannot_inline_p = false;
     926                 :             : 
     927                 :    33984205 :   if (opt_for_fn (edge->caller->decl, flag_devirtualize)
     928                 :    33984205 :       && call_stmt && DECL_STRUCT_FUNCTION (caller->decl))
     929                 :    26204271 :     edge->in_polymorphic_cdtor
     930                 :    26204271 :       = decl_maybe_in_construction_p (NULL, NULL, call_stmt,
     931                 :             :                                       caller->decl);
     932                 :             :   else
     933                 :     7779934 :     edge->in_polymorphic_cdtor = caller->thunk;
     934                 :    33984205 :   if (callee)
     935                 :    33331379 :     caller->calls_declare_variant_alt |= callee->declare_variant_alt;
     936                 :             : 
     937                 :    33331379 :   if (callee && symtab->state != LTO_STREAMING
     938                 :    32746077 :       && edge->callee->comdat_local_p ())
     939                 :        7743 :     edge->caller->calls_comdat_local = true;
     940                 :             : 
     941                 :             :   return edge;
     942                 :             : }
     943                 :             : 
     944                 :             : /* Create edge from a given function to CALLEE in the cgraph.  CLONING_P should
     945                 :             :    be set if properties that are copied from an original edge should not be
     946                 :             :    calculated.  */
     947                 :             : 
     948                 :             : cgraph_edge *
     949                 :    38372939 : cgraph_node::create_edge (cgraph_node *callee,
     950                 :             :                           gcall *call_stmt, profile_count count, bool cloning_p)
     951                 :             : {
     952                 :    38372939 :   cgraph_edge *edge = symtab->create_edge (this, callee, call_stmt, count,
     953                 :             :                                            false, cloning_p);
     954                 :             : 
     955                 :    38372939 :   if (!cloning_p)
     956                 :    33331379 :     initialize_inline_failed (edge);
     957                 :             : 
     958                 :    38372939 :   edge->next_caller = callee->callers;
     959                 :    38372939 :   if (callee->callers)
     960                 :    29586126 :     callee->callers->prev_caller = edge;
     961                 :    38372939 :   edge->next_callee = callees;
     962                 :    38372939 :   if (callees)
     963                 :    29759220 :     callees->prev_callee = edge;
     964                 :    38372939 :   callees = edge;
     965                 :    38372939 :   callee->callers = edge;
     966                 :             : 
     967                 :    38372939 :   return edge;
     968                 :             : }
     969                 :             : 
     970                 :             : /* Allocate cgraph_indirect_call_info and set its fields to default values. */
     971                 :             : 
     972                 :             : cgraph_indirect_call_info *
     973                 :      804817 : cgraph_allocate_init_indirect_info (void)
     974                 :             : {
     975                 :      804817 :   cgraph_indirect_call_info *ii;
     976                 :             : 
     977                 :      804817 :   ii = ggc_cleared_alloc<cgraph_indirect_call_info> ();
     978                 :      804817 :   ii->param_index = -1;
     979                 :      804817 :   return ii;
     980                 :             : }
     981                 :             : 
     982                 :             : /* Create an indirect edge with a yet-undetermined callee where the call
     983                 :             :    statement destination is a formal parameter of the caller with index
     984                 :             :    PARAM_INDEX. CLONING_P should be set if properties that are copied from an
     985                 :             :    original edge should not be calculated and indirect_info structure should
     986                 :             :    not be calculated.  */
     987                 :             : 
     988                 :             : cgraph_edge *
     989                 :      804817 : cgraph_node::create_indirect_edge (gcall *call_stmt, int ecf_flags,
     990                 :             :                                    profile_count count,
     991                 :             :                                    bool cloning_p)
     992                 :             : {
     993                 :      804817 :   cgraph_edge *edge = symtab->create_edge (this, NULL, call_stmt, count, true,
     994                 :             :                                            cloning_p);
     995                 :      804817 :   tree target;
     996                 :             : 
     997                 :      804817 :   if (!cloning_p)
     998                 :      652826 :     initialize_inline_failed (edge);
     999                 :             : 
    1000                 :      804817 :   edge->indirect_info = cgraph_allocate_init_indirect_info ();
    1001                 :      804817 :   edge->indirect_info->ecf_flags = ecf_flags;
    1002                 :      804817 :   edge->indirect_info->vptr_changed = true;
    1003                 :             : 
    1004                 :             :   /* Record polymorphic call info.  */
    1005                 :      804817 :   if (!cloning_p
    1006                 :      804817 :       && call_stmt
    1007                 :      650795 :       && (target = gimple_call_fn (call_stmt))
    1008                 :     1455612 :       && virtual_method_call_p (target))
    1009                 :             :     {
    1010                 :       93628 :       ipa_polymorphic_call_context context (decl, target, call_stmt);
    1011                 :             : 
    1012                 :             :       /* Only record types can have virtual calls.  */
    1013                 :       93628 :       edge->indirect_info->polymorphic = true;
    1014                 :       93628 :       edge->indirect_info->param_index = -1;
    1015                 :       93628 :       edge->indirect_info->otr_token
    1016                 :       93628 :          = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (target));
    1017                 :       93628 :       edge->indirect_info->otr_type = obj_type_ref_class (target);
    1018                 :       93628 :       gcc_assert (TREE_CODE (edge->indirect_info->otr_type) == RECORD_TYPE);
    1019                 :       93628 :       edge->indirect_info->context = context;
    1020                 :             :     }
    1021                 :             : 
    1022                 :      804817 :   edge->next_callee = indirect_calls;
    1023                 :      804817 :   if (indirect_calls)
    1024                 :      389557 :     indirect_calls->prev_callee = edge;
    1025                 :      804817 :   indirect_calls = edge;
    1026                 :             : 
    1027                 :      804817 :   return edge;
    1028                 :             : }
    1029                 :             : 
    1030                 :             : /* Remove the edge from the list of the callees of the caller.  */
    1031                 :             : 
    1032                 :             : void
    1033                 :     3596086 : cgraph_edge::remove_caller (void)
    1034                 :             : {
    1035                 :     3596086 :   if (prev_callee)
    1036                 :     2893799 :     prev_callee->next_callee = next_callee;
    1037                 :     3596086 :   if (next_callee)
    1038                 :     2422999 :     next_callee->prev_callee = prev_callee;
    1039                 :     3596086 :   if (!prev_callee)
    1040                 :             :     {
    1041                 :      702287 :       if (indirect_unknown_callee)
    1042                 :         750 :         caller->indirect_calls = next_callee;
    1043                 :             :       else
    1044                 :      701537 :         caller->callees = next_callee;
    1045                 :             :     }
    1046                 :     3596086 :   if (caller->call_site_hash
    1047                 :     3596086 :       && this == caller->get_edge (call_stmt))
    1048                 :      471427 :     caller->call_site_hash->remove_elt_with_hash
    1049                 :      471427 :         (call_stmt, cgraph_edge_hasher::hash (call_stmt));
    1050                 :     3596086 : }
    1051                 :             : 
    1052                 :             : /* Put the edge onto the free list.  */
    1053                 :             : 
    1054                 :             : void
    1055                 :    38757135 : symbol_table::free_edge (cgraph_edge *e)
    1056                 :             : {
    1057                 :    38757135 :   edges_count--;
    1058                 :    38757135 :   if (e->m_summary_id != -1)
    1059                 :    18165643 :     edge_released_summary_ids.safe_push (e->m_summary_id);
    1060                 :             : 
    1061                 :    38757135 :   if (e->indirect_info)
    1062                 :      799270 :     ggc_free (e->indirect_info);
    1063                 :    38757135 :   ggc_free (e);
    1064                 :    38757135 : }
    1065                 :             : 
    1066                 :             : /* Remove the edge in the cgraph.  */
    1067                 :             : 
    1068                 :             : void
    1069                 :       92741 : cgraph_edge::remove (cgraph_edge *edge)
    1070                 :             : {
    1071                 :             :   /* Call all edge removal hooks.  */
    1072                 :       92741 :   symtab->call_edge_removal_hooks (edge);
    1073                 :             : 
    1074                 :       92741 :   if (!edge->indirect_unknown_callee)
    1075                 :             :     /* Remove from callers list of the callee.  */
    1076                 :       90580 :     edge->remove_callee ();
    1077                 :             : 
    1078                 :             :   /* Remove from callees list of the callers.  */
    1079                 :       92741 :   edge->remove_caller ();
    1080                 :             : 
    1081                 :             :   /* Put the edge onto the free list.  */
    1082                 :       92741 :   symtab->free_edge (edge);
    1083                 :       92741 : }
    1084                 :             : 
    1085                 :             : /* Turn edge into speculative call calling N2. Update
    1086                 :             :    the profile so the direct call is taken COUNT times
    1087                 :             :    with FREQUENCY.  
    1088                 :             : 
    1089                 :             :    At clone materialization time, the indirect call E will
    1090                 :             :    be expanded as:
    1091                 :             : 
    1092                 :             :    if (call_dest == N2)
    1093                 :             :      n2 ();
    1094                 :             :    else
    1095                 :             :      call call_dest
    1096                 :             : 
    1097                 :             :    At this time the function just creates the direct call,
    1098                 :             :    the reference representing the if conditional and attaches
    1099                 :             :    them all to the original indirect call statement.  
    1100                 :             : 
    1101                 :             :    speculative_id is used to link direct calls with their corresponding
    1102                 :             :    IPA_REF_ADDR references when representing speculative calls.
    1103                 :             : 
    1104                 :             :    Return direct edge created.  */
    1105                 :             : 
    1106                 :             : cgraph_edge *
    1107                 :        4881 : cgraph_edge::make_speculative (cgraph_node *n2, profile_count direct_count,
    1108                 :             :                                unsigned int speculative_id)
    1109                 :             : {
    1110                 :        4881 :   cgraph_node *n = caller;
    1111                 :        4881 :   ipa_ref *ref = NULL;
    1112                 :        4881 :   cgraph_edge *e2;
    1113                 :             : 
    1114                 :        4881 :   if (dump_file)
    1115                 :          32 :     fprintf (dump_file, "Indirect call -> speculative call %s => %s\n",
    1116                 :             :              n->dump_name (), n2->dump_name ());
    1117                 :        4881 :   speculative = true;
    1118                 :        4881 :   e2 = n->create_edge (n2, call_stmt, direct_count);
    1119                 :        4881 :   initialize_inline_failed (e2);
    1120                 :        4881 :   e2->speculative = true;
    1121                 :        4881 :   if (TREE_NOTHROW (n2->decl))
    1122                 :        3378 :     e2->can_throw_external = false;
    1123                 :             :   else
    1124                 :        1503 :     e2->can_throw_external = can_throw_external;
    1125                 :        4881 :   e2->lto_stmt_uid = lto_stmt_uid;
    1126                 :        4881 :   e2->speculative_id = speculative_id;
    1127                 :        4881 :   e2->in_polymorphic_cdtor = in_polymorphic_cdtor;
    1128                 :        4881 :   indirect_info->num_speculative_call_targets++;
    1129                 :        4881 :   count -= e2->count;
    1130                 :        4881 :   symtab->call_edge_duplication_hooks (this, e2);
    1131                 :        4881 :   ref = n->create_reference (n2, IPA_REF_ADDR, call_stmt);
    1132                 :        4881 :   ref->lto_stmt_uid = lto_stmt_uid;
    1133                 :        4881 :   ref->speculative_id = speculative_id;
    1134                 :        4881 :   ref->speculative = speculative;
    1135                 :        4881 :   n2->mark_address_taken ();
    1136                 :        4881 :   return e2;
    1137                 :             : }
    1138                 :             : 
    1139                 :             : /* Speculative call consists of an indirect edge and one or more
    1140                 :             :    direct edge+ref pairs.
    1141                 :             : 
    1142                 :             :    Given an edge which is part of speculative call, return the first
    1143                 :             :    direct call edge in the speculative call sequence.  */
    1144                 :             : 
    1145                 :             : cgraph_edge *
    1146                 :       17904 : cgraph_edge::first_speculative_call_target ()
    1147                 :             : {
    1148                 :       17904 :   cgraph_edge *e = this;
    1149                 :             : 
    1150                 :       17904 :   gcc_checking_assert (e->speculative);
    1151                 :       17904 :   if (e->callee)
    1152                 :             :     {
    1153                 :        2040 :       while (e->prev_callee && e->prev_callee->speculative
    1154                 :         354 :              && e->prev_callee->call_stmt == e->call_stmt
    1155                 :       13558 :              && e->prev_callee->lto_stmt_uid == e->lto_stmt_uid)
    1156                 :             :         e = e->prev_callee;
    1157                 :       13558 :       return e;
    1158                 :             :     }
    1159                 :             :   /* Call stmt site hash always points to the first target of the
    1160                 :             :      speculative call sequence.  */
    1161                 :        4346 :   if (e->call_stmt)
    1162                 :        4335 :     return e->caller->get_edge (e->call_stmt);
    1163                 :          22 :   for (cgraph_edge *e2 = e->caller->callees; true; e2 = e2->next_callee)
    1164                 :          22 :     if (e2->speculative
    1165                 :          17 :         && e->call_stmt == e2->call_stmt
    1166                 :          17 :         && e->lto_stmt_uid == e2->lto_stmt_uid)
    1167                 :          11 :       return e2;
    1168                 :             : }
    1169                 :             : 
    1170                 :             : /* We always maintain first direct edge in the call site hash, if one
    1171                 :             :    exists.  E is going to be removed.  See if it is first one and update
    1172                 :             :    hash accordingly.  INDIRECT is the indirect edge of speculative call.
    1173                 :             :    We assume that INDIRECT->num_speculative_call_targets_p () is already
    1174                 :             :    updated for removal of E.  */
    1175                 :             : static void
    1176                 :       12851 : update_call_stmt_hash_for_removing_direct_edge (cgraph_edge *e,
    1177                 :             :                                                 cgraph_edge *indirect)
    1178                 :             : {
    1179                 :       12851 :   if (e->caller->call_site_hash)
    1180                 :             :     {
    1181                 :        1997 :       if (e->caller->get_edge (e->call_stmt) != e)
    1182                 :             :         ;
    1183                 :        1997 :       else if (!indirect->num_speculative_call_targets_p ())
    1184                 :        1997 :         cgraph_update_edge_in_call_site_hash (indirect);
    1185                 :             :       else
    1186                 :             :         {
    1187                 :           0 :           gcc_checking_assert (e->next_callee && e->next_callee->speculative
    1188                 :             :                                && e->next_callee->call_stmt == e->call_stmt);
    1189                 :           0 :           cgraph_update_edge_in_call_site_hash (e->next_callee);
    1190                 :             :         }
    1191                 :             :     }
    1192                 :       12851 : }
    1193                 :             : 
    1194                 :             : /* Speculative call EDGE turned out to be direct call to CALLEE_DECL.  Remove
    1195                 :             :    the speculative call sequence and return edge representing the call, the
    1196                 :             :    original EDGE can be removed and deallocated.  Return the edge that now
    1197                 :             :    represents the call.
    1198                 :             : 
    1199                 :             :    For "speculative" indirect call that contains multiple "speculative"
    1200                 :             :    targets (i.e. edge->indirect_info->num_speculative_call_targets > 1),
    1201                 :             :    decrease the count and only remove current direct edge.
    1202                 :             : 
    1203                 :             :    If no speculative direct call left to the speculative indirect call, remove
    1204                 :             :    the speculative of both the indirect call and corresponding direct edge.
    1205                 :             : 
    1206                 :             :    It is up to caller to iteratively resolve each "speculative" direct call and
    1207                 :             :    redirect the call as appropriate.  */
    1208                 :             : 
    1209                 :             : cgraph_edge *
    1210                 :        1308 : cgraph_edge::resolve_speculation (cgraph_edge *edge, tree callee_decl)
    1211                 :             : {
    1212                 :        1308 :   cgraph_edge *e2;
    1213                 :        1308 :   ipa_ref *ref;
    1214                 :             : 
    1215                 :        1308 :   gcc_assert (edge->speculative && (!callee_decl || edge->callee));
    1216                 :        1308 :   if (!edge->callee)
    1217                 :           0 :     e2 = edge->first_speculative_call_target ();
    1218                 :             :   else
    1219                 :             :     e2 = edge;
    1220                 :        1308 :   ref = e2->speculative_call_target_ref ();
    1221                 :        1308 :   edge = edge->speculative_call_indirect_edge ();
    1222                 :        1308 :   if (!callee_decl
    1223                 :        1826 :       || !ref->referred->semantically_equivalent_p
    1224                 :         518 :            (symtab_node::get (callee_decl)))
    1225                 :             :     {
    1226                 :         999 :       if (dump_file)
    1227                 :             :         {
    1228                 :           0 :           if (callee_decl)
    1229                 :             :             {
    1230                 :           0 :               fprintf (dump_file, "Speculative indirect call %s => %s has "
    1231                 :             :                        "turned out to have contradicting known target ",
    1232                 :           0 :                        edge->caller->dump_name (),
    1233                 :           0 :                        e2->callee->dump_name ());
    1234                 :           0 :               print_generic_expr (dump_file, callee_decl);
    1235                 :           0 :               fprintf (dump_file, "\n");
    1236                 :             :             }
    1237                 :             :           else
    1238                 :             :             {
    1239                 :           0 :               fprintf (dump_file, "Removing speculative call %s => %s\n",
    1240                 :           0 :                        edge->caller->dump_name (),
    1241                 :           0 :                        e2->callee->dump_name ());
    1242                 :             :             }
    1243                 :             :         }
    1244                 :             :     }
    1245                 :             :   else
    1246                 :             :     {
    1247                 :         309 :       cgraph_edge *tmp = edge;
    1248                 :         309 :       if (dump_file)
    1249                 :          48 :         fprintf (dump_file, "Speculative call turned into direct call.\n");
    1250                 :             :       edge = e2;
    1251                 :             :       e2 = tmp;
    1252                 :             :       /* FIXME:  If EDGE is inlined, we should scale up the frequencies
    1253                 :             :          and counts in the functions inlined through it.  */
    1254                 :             :     }
    1255                 :        1308 :   edge->count += e2->count;
    1256                 :        1308 :   if (edge->num_speculative_call_targets_p ())
    1257                 :             :     {
    1258                 :             :       /* The indirect edge has multiple speculative targets, don't remove
    1259                 :             :          speculative until all related direct edges are resolved.  */
    1260                 :         999 :       edge->indirect_info->num_speculative_call_targets--;
    1261                 :         999 :       if (!edge->indirect_info->num_speculative_call_targets)
    1262                 :         995 :         edge->speculative = false;
    1263                 :             :     }
    1264                 :             :   else
    1265                 :         309 :     edge->speculative = false;
    1266                 :        1308 :   e2->speculative = false;
    1267                 :        1308 :   update_call_stmt_hash_for_removing_direct_edge (e2, edge);
    1268                 :        1308 :   ref->remove_reference ();
    1269                 :        1308 :   if (e2->indirect_unknown_callee || e2->inline_failed)
    1270                 :        1275 :     remove (e2);
    1271                 :             :   else
    1272                 :          33 :     e2->callee->remove_symbol_and_inline_clones ();
    1273                 :        1308 :   return edge;
    1274                 :             : }
    1275                 :             : 
    1276                 :             : /* Return edge corresponding to speculative call to a given target.
    1277                 :             :    NULL if speculative call does not have one.  */
    1278                 :             : 
    1279                 :             : cgraph_edge *
    1280                 :           0 : cgraph_edge::speculative_call_for_target (cgraph_node *target)
    1281                 :             : {
    1282                 :           0 :   for (cgraph_edge *direct = first_speculative_call_target ();
    1283                 :           0 :        direct;
    1284                 :           0 :        direct = direct->next_speculative_call_target ())
    1285                 :           0 :     if (direct->speculative_call_target_ref ()
    1286                 :           0 :         ->referred->semantically_equivalent_p (target))
    1287                 :           0 :       return direct;
    1288                 :             :   return NULL;
    1289                 :             : }
    1290                 :             : 
    1291                 :             : /* Make an indirect or speculative EDGE with an unknown callee an ordinary edge
    1292                 :             :    leading to CALLEE.  Speculations can be resolved in the process and EDGE can
    1293                 :             :    be removed and deallocated.  Return the edge that now represents the
    1294                 :             :    call.  */
    1295                 :             : 
    1296                 :             : cgraph_edge *
    1297                 :        3363 : cgraph_edge::make_direct (cgraph_edge *edge, cgraph_node *callee)
    1298                 :             : {
    1299                 :        3363 :   gcc_assert (edge->indirect_unknown_callee || edge->speculative);
    1300                 :             : 
    1301                 :             :   /* If we are redirecting speculative call, make it non-speculative.  */
    1302                 :        3363 :   if (edge->speculative)
    1303                 :             :     {
    1304                 :         341 :       cgraph_edge *found = NULL;
    1305                 :         341 :       cgraph_edge *direct, *next;
    1306                 :             : 
    1307                 :         341 :       edge = edge->speculative_call_indirect_edge ();
    1308                 :             : 
    1309                 :             :       /* Look all speculative targets and remove all but one corresponding
    1310                 :             :          to callee (if it exists).  */
    1311                 :         341 :       for (direct = edge->first_speculative_call_target ();
    1312                 :         686 :            direct;
    1313                 :             :            direct = next)
    1314                 :             :         {
    1315                 :         345 :           next = direct->next_speculative_call_target ();
    1316                 :             : 
    1317                 :             :           /* Compare ref not direct->callee.  Direct edge is possibly
    1318                 :             :              inlined or redirected.  */
    1319                 :         690 :           if (!direct->speculative_call_target_ref ()
    1320                 :         345 :                ->referred->semantically_equivalent_p (callee))
    1321                 :          36 :             edge = direct->resolve_speculation (direct, NULL);
    1322                 :             :           else
    1323                 :             :             {
    1324                 :         309 :               gcc_checking_assert (!found);
    1325                 :             :               found = direct;
    1326                 :             :             }
    1327                 :             :         }
    1328                 :             : 
    1329                 :             :       /* On successful speculation just remove the indirect edge and
    1330                 :             :          return the pre existing direct edge.
    1331                 :             :          It is important to not remove it and redirect because the direct
    1332                 :             :          edge may be inlined or redirected.  */
    1333                 :         341 :       if (found)
    1334                 :             :         {
    1335                 :         309 :           cgraph_edge *e2 = resolve_speculation (found, callee->decl);
    1336                 :         309 :           gcc_checking_assert (!found->speculative && e2 == found);
    1337                 :             :           return found;
    1338                 :             :         }
    1339                 :          32 :       gcc_checking_assert (!edge->speculative);
    1340                 :             :     }
    1341                 :             : 
    1342                 :        3054 :   edge->indirect_unknown_callee = 0;
    1343                 :        3054 :   ggc_free (edge->indirect_info);
    1344                 :        3054 :   edge->indirect_info = NULL;
    1345                 :             : 
    1346                 :             :   /* Get the edge out of the indirect edge list. */
    1347                 :        3054 :   if (edge->prev_callee)
    1348                 :          44 :     edge->prev_callee->next_callee = edge->next_callee;
    1349                 :        3054 :   if (edge->next_callee)
    1350                 :         445 :     edge->next_callee->prev_callee = edge->prev_callee;
    1351                 :        3054 :   if (!edge->prev_callee)
    1352                 :        3010 :     edge->caller->indirect_calls = edge->next_callee;
    1353                 :             : 
    1354                 :             :   /* Put it into the normal callee list */
    1355                 :        3054 :   edge->prev_callee = NULL;
    1356                 :        3054 :   edge->next_callee = edge->caller->callees;
    1357                 :        3054 :   if (edge->caller->callees)
    1358                 :        1698 :     edge->caller->callees->prev_callee = edge;
    1359                 :        3054 :   edge->caller->callees = edge;
    1360                 :             : 
    1361                 :             :   /* Insert to callers list of the new callee.  */
    1362                 :        3054 :   edge->set_callee (callee);
    1363                 :             : 
    1364                 :             :   /* We need to re-determine the inlining status of the edge.  */
    1365                 :        3054 :   initialize_inline_failed (edge);
    1366                 :        3054 :   return edge;
    1367                 :             : }
    1368                 :             : 
    1369                 :             : /* Redirect callee of the edge to N.  The function does not update underlying
    1370                 :             :    call expression.  */
    1371                 :             : 
    1372                 :             : void
    1373                 :     3253405 : cgraph_edge::redirect_callee (cgraph_node *n)
    1374                 :             : {
    1375                 :     3253405 :   bool loc = callee->comdat_local_p ();
    1376                 :             :   /* Remove from callers list of the current callee.  */
    1377                 :     3253405 :   remove_callee ();
    1378                 :             : 
    1379                 :             :   /* Insert to callers list of the new callee.  */
    1380                 :     3253405 :   set_callee (n);
    1381                 :             : 
    1382                 :     3253405 :   if (!inline_failed)
    1383                 :             :     return;
    1384                 :      421884 :   if (!loc && n->comdat_local_p ())
    1385                 :             :     {
    1386                 :          56 :       cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
    1387                 :          56 :       to->calls_comdat_local = true;
    1388                 :             :     }
    1389                 :      421828 :   else if (loc && !n->comdat_local_p ())
    1390                 :             :     {
    1391                 :          79 :       cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
    1392                 :          79 :       gcc_checking_assert (to->calls_comdat_local);
    1393                 :          79 :       to->calls_comdat_local = to->check_calls_comdat_local_p ();
    1394                 :             :     }
    1395                 :             : }
    1396                 :             : 
    1397                 :             : /* If necessary, change the function declaration in the call statement
    1398                 :             :    associated with E so that it corresponds to the edge callee.  Speculations
    1399                 :             :    can be resolved in the process and EDGE can be removed and deallocated.
    1400                 :             : 
    1401                 :             :    The edge could be one of speculative direct call generated from speculative
    1402                 :             :    indirect call.  In this circumstance, decrease the speculative targets
    1403                 :             :    count (i.e. num_speculative_call_targets) and redirect call stmt to the
    1404                 :             :    corresponding i-th target.  If no speculative direct call left to the
    1405                 :             :    speculative indirect call, remove "speculative" of the indirect call and
    1406                 :             :    also redirect stmt to it's final direct target.
    1407                 :             : 
    1408                 :             :    When called from within tree-inline, KILLED_SSAs has to contain the pointer
    1409                 :             :    to killed_new_ssa_names within the copy_body_data structure and SSAs
    1410                 :             :    discovered to be useless (if LHS is removed) will be added to it, otherwise
    1411                 :             :    it needs to be NULL.
    1412                 :             : 
    1413                 :             :    It is up to caller to iteratively transform each "speculative"
    1414                 :             :    direct call as appropriate.  */
    1415                 :             : 
    1416                 :             : gimple *
    1417                 :     8311432 : cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
    1418                 :             :                                            hash_set <tree> *killed_ssas)
    1419                 :             : {
    1420                 :     8311432 :   tree decl = gimple_call_fndecl (e->call_stmt);
    1421                 :     8311432 :   gcall *new_stmt;
    1422                 :             : 
    1423                 :     8311432 :   if (e->speculative)
    1424                 :             :     {
    1425                 :             :       /* If there already is an direct call (i.e. as a result of inliner's
    1426                 :             :          substitution), forget about speculating.  */
    1427                 :       11543 :       if (decl)
    1428                 :           0 :         e = make_direct (e->speculative_call_indirect_edge (),
    1429                 :             :                          cgraph_node::get (decl));
    1430                 :             :       else
    1431                 :             :         {
    1432                 :             :           /* Be sure we redirect all speculative targets before poking
    1433                 :             :              about indirect edge.  */
    1434                 :       11543 :           gcc_checking_assert (e->callee);
    1435                 :       11543 :           cgraph_edge *indirect = e->speculative_call_indirect_edge ();
    1436                 :       11543 :           gcall *new_stmt;
    1437                 :       11543 :           ipa_ref *ref;
    1438                 :             : 
    1439                 :             :           /* Expand speculation into GIMPLE code.  */
    1440                 :       11543 :           if (dump_file)
    1441                 :             :             {
    1442                 :          56 :               fprintf (dump_file,
    1443                 :             :                        "Expanding speculative call of %s -> %s count: ",
    1444                 :          28 :                        e->caller->dump_name (),
    1445                 :             :                        e->callee->dump_name ());
    1446                 :          28 :               e->count.dump (dump_file);
    1447                 :          28 :               fprintf (dump_file, "\n");
    1448                 :             :             }
    1449                 :       11543 :           push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
    1450                 :             : 
    1451                 :       11543 :           profile_count all = indirect->count;
    1452                 :       11543 :           for (cgraph_edge *e2 = e->first_speculative_call_target ();
    1453                 :       23089 :                e2;
    1454                 :       11546 :                e2 = e2->next_speculative_call_target ())
    1455                 :       11546 :             all = all + e2->count;
    1456                 :       11543 :           profile_probability prob = e->count.probability_in (all);
    1457                 :       11543 :           if (!prob.initialized_p ())
    1458                 :         332 :             prob = profile_probability::even ();
    1459                 :       11543 :           ref = e->speculative_call_target_ref ();
    1460                 :       23086 :           new_stmt = gimple_ic (e->call_stmt,
    1461                 :             :                                 dyn_cast<cgraph_node *> (ref->referred),
    1462                 :             :                                 prob);
    1463                 :       11543 :           e->speculative = false;
    1464                 :       11543 :           if (indirect->num_speculative_call_targets_p ())
    1465                 :             :             {
    1466                 :             :               /* The indirect edge has multiple speculative targets, don't
    1467                 :             :                  remove speculative until all related direct edges are
    1468                 :             :                  redirected.  */
    1469                 :       11543 :               indirect->indirect_info->num_speculative_call_targets--;
    1470                 :       11543 :               if (!indirect->indirect_info->num_speculative_call_targets)
    1471                 :       11540 :                 indirect->speculative = false;
    1472                 :             :             }
    1473                 :             :           else
    1474                 :           0 :             indirect->speculative = false;
    1475                 :             :           /* Indirect edges are not both in the call site hash.
    1476                 :             :              get it updated.  */
    1477                 :       11543 :           update_call_stmt_hash_for_removing_direct_edge (e, indirect);
    1478                 :       11543 :           cgraph_edge::set_call_stmt (e, new_stmt, false);
    1479                 :       11543 :           e->count = gimple_bb (e->call_stmt)->count;
    1480                 :             : 
    1481                 :             :           /* Once we are done with expanding the sequence, update also indirect
    1482                 :             :              call probability.  Until then the basic block accounts for the
    1483                 :             :              sum of indirect edge and all non-expanded speculations.  */
    1484                 :       11543 :           if (!indirect->speculative)
    1485                 :       11540 :             indirect->count = gimple_bb (indirect->call_stmt)->count;
    1486                 :       11543 :           ref->speculative = false;
    1487                 :       11543 :           ref->stmt = NULL;
    1488                 :       11543 :           pop_cfun ();
    1489                 :             :           /* Continue redirecting E to proper target.  */
    1490                 :             :         }
    1491                 :             :     }
    1492                 :             : 
    1493                 :             : 
    1494                 :     8311432 :   if (e->indirect_unknown_callee
    1495                 :     8233892 :       || decl == e->callee->decl)
    1496                 :     7573450 :     return e->call_stmt;
    1497                 :             : 
    1498                 :      737982 :   if (decl && ipa_saved_clone_sources)
    1499                 :             :     {
    1500                 :      604214 :       tree *p = ipa_saved_clone_sources->get (e->callee);
    1501                 :      604214 :       if (p && decl == *p)
    1502                 :             :         {
    1503                 :       28307 :           gimple_call_set_fndecl (e->call_stmt, e->callee->decl);
    1504                 :       28307 :           return e->call_stmt;
    1505                 :             :         }
    1506                 :             :     }
    1507                 :      709675 :   if (flag_checking && decl)
    1508                 :             :     {
    1509                 :      695222 :       if (cgraph_node *node = cgraph_node::get (decl))
    1510                 :             :         {
    1511                 :      591919 :           clone_info *info = clone_info::get (node);
    1512                 :      591919 :           gcc_assert (!info || !info->param_adjustments);
    1513                 :             :         }
    1514                 :             :     }
    1515                 :             : 
    1516                 :      709675 :   clone_info *callee_info = clone_info::get (e->callee);
    1517                 :      709675 :   if (symtab->dump_file)
    1518                 :             :     {
    1519                 :           0 :       fprintf (symtab->dump_file, "updating call of %s -> %s: ",
    1520                 :           0 :                e->caller->dump_name (), e->callee->dump_name ());
    1521                 :           0 :       print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
    1522                 :           0 :       if (callee_info && callee_info->param_adjustments)
    1523                 :           0 :         callee_info->param_adjustments->dump (symtab->dump_file);
    1524                 :             :     }
    1525                 :             : 
    1526                 :           0 :   if (ipa_param_adjustments *padjs
    1527                 :      709675 :          = callee_info ? callee_info->param_adjustments : NULL)
    1528                 :             :     {
    1529                 :             :       /* We need to defer cleaning EH info on the new statement to
    1530                 :             :          fixup-cfg.  We may not have dominator information at this point
    1531                 :             :          and thus would end up with unreachable blocks and have no way
    1532                 :             :          to communicate that we need to run CFG cleanup then.  */
    1533                 :      348551 :       int lp_nr = lookup_stmt_eh_lp (e->call_stmt);
    1534                 :      348551 :       if (lp_nr != 0)
    1535                 :      104946 :         remove_stmt_from_eh_lp (e->call_stmt);
    1536                 :             : 
    1537                 :      348551 :       tree old_fntype = gimple_call_fntype (e->call_stmt);
    1538                 :      348551 :       new_stmt = padjs->modify_call (e, false, killed_ssas);
    1539                 :      348551 :       cgraph_node *origin = e->callee;
    1540                 :      498000 :       while (origin->clone_of)
    1541                 :             :         origin = origin->clone_of;
    1542                 :             : 
    1543                 :      348551 :       if ((origin->former_clone_of
    1544                 :      280270 :            && old_fntype == TREE_TYPE (origin->former_clone_of))
    1545                 :      350631 :           || old_fntype == TREE_TYPE (origin->decl))
    1546                 :      278192 :         gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
    1547                 :             :       else
    1548                 :             :         {
    1549                 :       70359 :           tree new_fntype = padjs->build_new_function_type (old_fntype, true);
    1550                 :       70359 :           gimple_call_set_fntype (new_stmt, new_fntype);
    1551                 :             :         }
    1552                 :             : 
    1553                 :      348551 :       if (lp_nr != 0)
    1554                 :      104946 :         add_stmt_to_eh_lp (new_stmt, lp_nr);
    1555                 :             :     }
    1556                 :             :   else
    1557                 :             :     {
    1558                 :      361124 :       if (flag_checking
    1559                 :      361124 :           && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
    1560                 :             :                                                   BUILT_IN_UNREACHABLE_TRAP))
    1561                 :      253290 :         ipa_verify_edge_has_no_modifications (e);
    1562                 :      361124 :       new_stmt = e->call_stmt;
    1563                 :      361124 :       gimple_call_set_fndecl (new_stmt, e->callee->decl);
    1564                 :      361124 :       update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
    1565                 :             :     }
    1566                 :             : 
    1567                 :             :   /* If changing the call to __cxa_pure_virtual or similar noreturn function,
    1568                 :             :      adjust gimple_call_fntype too.  */
    1569                 :      709675 :   if (gimple_call_noreturn_p (new_stmt)
    1570                 :      114940 :       && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (e->callee->decl)))
    1571                 :      114818 :       && TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl))
    1572                 :      824471 :       && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl)))
    1573                 :      114796 :           == void_type_node))
    1574                 :      114068 :     gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
    1575                 :             : 
    1576                 :             :   /* If the call becomes noreturn, remove the LHS if possible.  */
    1577                 :      709675 :   tree lhs = gimple_call_lhs (new_stmt);
    1578                 :      709675 :   if (lhs
    1579                 :      196366 :       && gimple_call_noreturn_p (new_stmt)
    1580                 :      739185 :       && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (new_stmt)))
    1581                 :         112 :           || should_remove_lhs_p (lhs)))
    1582                 :             :     {
    1583                 :       29483 :       gimple_call_set_lhs (new_stmt, NULL_TREE);
    1584                 :             :       /* We need to fix up the SSA name to avoid checking errors.  */
    1585                 :       29483 :       if (TREE_CODE (lhs) == SSA_NAME)
    1586                 :             :         {
    1587                 :       20870 :           tree var = create_tmp_reg_fn (DECL_STRUCT_FUNCTION (e->caller->decl),
    1588                 :       20870 :                                         TREE_TYPE (lhs), NULL);
    1589                 :       20870 :           SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var);
    1590                 :       20870 :           SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
    1591                 :       20870 :           set_ssa_default_def (DECL_STRUCT_FUNCTION (e->caller->decl),
    1592                 :             :                                var, lhs);
    1593                 :             :         }
    1594                 :       29483 :       update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
    1595                 :             :     }
    1596                 :             : 
    1597                 :             :   /* If new callee has no static chain, remove it.  */
    1598                 :      709675 :   if (gimple_call_chain (new_stmt) && !DECL_STATIC_CHAIN (e->callee->decl))
    1599                 :             :     {
    1600                 :          52 :       gimple_call_set_chain (new_stmt, NULL);
    1601                 :          52 :       update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
    1602                 :             :     }
    1603                 :             : 
    1604                 :      709675 :   maybe_remove_unused_call_args (DECL_STRUCT_FUNCTION (e->caller->decl),
    1605                 :             :                                  new_stmt);
    1606                 :             : 
    1607                 :      709675 :   e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt, false);
    1608                 :             : 
    1609                 :      709675 :   if (symtab->dump_file)
    1610                 :             :     {
    1611                 :           0 :       fprintf (symtab->dump_file, "  updated to:");
    1612                 :           0 :       print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
    1613                 :             :     }
    1614                 :             :   return new_stmt;
    1615                 :             : }
    1616                 :             : 
    1617                 :             : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
    1618                 :             :    OLD_STMT changed into NEW_STMT.  OLD_CALL is gimple_call_fndecl
    1619                 :             :    of OLD_STMT if it was previously call statement.
    1620                 :             :    If NEW_STMT is NULL, the call has been dropped without any
    1621                 :             :    replacement.  */
    1622                 :             : 
    1623                 :             : static void
    1624                 :      113226 : cgraph_update_edges_for_call_stmt_node (cgraph_node *node,
    1625                 :             :                                         gimple *old_stmt, tree old_call,
    1626                 :             :                                         gimple *new_stmt)
    1627                 :             : {
    1628                 :      113226 :   tree new_call = (new_stmt && is_gimple_call (new_stmt))
    1629                 :      117415 :                   ? gimple_call_fndecl (new_stmt) : 0;
    1630                 :             : 
    1631                 :             :   /* We are seeing indirect calls, then there is nothing to update.  */
    1632                 :      113226 :   if (!new_call && !old_call)
    1633                 :             :     return;
    1634                 :             :   /* See if we turned indirect call into direct call or folded call to one builtin
    1635                 :             :      into different builtin.  */
    1636                 :      111876 :   if (old_call != new_call)
    1637                 :             :     {
    1638                 :      111116 :       cgraph_edge *e = node->get_edge (old_stmt);
    1639                 :      111116 :       cgraph_edge *ne = NULL;
    1640                 :      111116 :       profile_count count;
    1641                 :             : 
    1642                 :      111116 :       if (e)
    1643                 :             :         {
    1644                 :             :           /* Keep calls marked as dead dead.  */
    1645                 :       89872 :           if (new_stmt && is_gimple_call (new_stmt) && e->callee
    1646                 :       90297 :               && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
    1647                 :             :                                     BUILT_IN_UNREACHABLE_TRAP))
    1648                 :             :             {
    1649                 :           2 :               cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
    1650                 :             :                                           as_a <gcall *> (new_stmt));
    1651                 :          32 :               return;
    1652                 :             :             }
    1653                 :             :           /* See if the edge is already there and has the correct callee.  It
    1654                 :             :              might be so because of indirect inlining has already updated
    1655                 :             :              it.  We also might've cloned and redirected the edge.  */
    1656                 :       89870 :           if (new_call && e->callee)
    1657                 :             :             {
    1658                 :             :               cgraph_node *callee = e->callee;
    1659                 :         847 :               while (callee)
    1660                 :             :                 {
    1661                 :         452 :                   if (callee->decl == new_call
    1662                 :         452 :                       || callee->former_clone_of == new_call)
    1663                 :             :                     {
    1664                 :          28 :                       cgraph_edge::set_call_stmt (e, as_a <gcall *> (new_stmt));
    1665                 :          28 :                       return;
    1666                 :             :                     }
    1667                 :         424 :                   callee = callee->clone_of;
    1668                 :             :                 }
    1669                 :             :             }
    1670                 :             : 
    1671                 :             :           /* Otherwise remove edge and create new one; we can't simply redirect
    1672                 :             :              since function has changed, so inline plan and other information
    1673                 :             :              attached to edge is invalid.  */
    1674                 :       89842 :           count = e->count;
    1675                 :       89842 :           if (e->indirect_unknown_callee || e->inline_failed)
    1676                 :       89842 :             cgraph_edge::remove (e);
    1677                 :             :           else
    1678                 :           0 :             e->callee->remove_symbol_and_inline_clones ();
    1679                 :             :         }
    1680                 :       21244 :       else if (new_call)
    1681                 :             :         {
    1682                 :             :           /* We are seeing new direct call; compute profile info based on BB.  */
    1683                 :           5 :           basic_block bb = gimple_bb (new_stmt);
    1684                 :           5 :           count = bb->count;
    1685                 :             :         }
    1686                 :             : 
    1687                 :       89847 :       if (new_call)
    1688                 :             :         {
    1689                 :        2186 :           ne = node->create_edge (cgraph_node::get_create (new_call),
    1690                 :             :                                   as_a <gcall *> (new_stmt), count);
    1691                 :        2186 :           gcc_assert (ne->inline_failed);
    1692                 :             :         }
    1693                 :             :     }
    1694                 :             :   /* We only updated the call stmt; update pointer in cgraph edge..  */
    1695                 :         760 :   else if (old_stmt != new_stmt)
    1696                 :           0 :     cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
    1697                 :             :                                 as_a <gcall *> (new_stmt));
    1698                 :             : }
    1699                 :             : 
    1700                 :             : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
    1701                 :             :    OLD_STMT changed into NEW_STMT.  OLD_DECL is gimple_call_fndecl
    1702                 :             :    of OLD_STMT before it was updated (updating can happen inplace).  */
    1703                 :             : 
    1704                 :             : void
    1705                 :       91681 : cgraph_update_edges_for_call_stmt (gimple *old_stmt, tree old_decl,
    1706                 :             :                                    gimple *new_stmt)
    1707                 :             : {
    1708                 :       91681 :   cgraph_node *orig = cgraph_node::get (cfun->decl);
    1709                 :       91681 :   cgraph_node *node;
    1710                 :             : 
    1711                 :       91681 :   gcc_checking_assert (orig);
    1712                 :       91681 :   cgraph_update_edges_for_call_stmt_node (orig, old_stmt, old_decl, new_stmt);
    1713                 :       91681 :   if (orig->clones)
    1714                 :       42501 :     for (node = orig->clones; node != orig;)
    1715                 :             :       {
    1716                 :       21545 :         cgraph_update_edges_for_call_stmt_node (node, old_stmt, old_decl,
    1717                 :             :                                                 new_stmt);
    1718                 :       21545 :         if (node->clones)
    1719                 :             :           node = node->clones;
    1720                 :       21537 :         else if (node->next_sibling_clone)
    1721                 :             :           node = node->next_sibling_clone;
    1722                 :             :         else
    1723                 :             :           {
    1724                 :       41920 :             while (node != orig && !node->next_sibling_clone)
    1725                 :       20964 :               node = node->clone_of;
    1726                 :       20956 :             if (node != orig)
    1727                 :           0 :               node = node->next_sibling_clone;
    1728                 :             :           }
    1729                 :             :       }
    1730                 :       91681 : }
    1731                 :             : 
    1732                 :             : 
    1733                 :             : /* Remove all callees from the node.  */
    1734                 :             : 
    1735                 :             : void
    1736                 :   189672151 : cgraph_node::remove_callees (void)
    1737                 :             : {
    1738                 :   189672151 :   cgraph_edge *e, *f;
    1739                 :             : 
    1740                 :   189672151 :   calls_comdat_local = false;
    1741                 :             : 
    1742                 :             :   /* It is sufficient to remove the edges from the lists of callers of
    1743                 :             :      the callees.  The callee list of the node can be zapped with one
    1744                 :             :      assignment.  */
    1745                 :   224036091 :   for (e = callees; e; e = f)
    1746                 :             :     {
    1747                 :    34363940 :       f = e->next_callee;
    1748                 :    34363940 :       symtab->call_edge_removal_hooks (e);
    1749                 :    34363940 :       if (!e->indirect_unknown_callee)
    1750                 :    34363940 :         e->remove_callee ();
    1751                 :    34363940 :       symtab->free_edge (e);
    1752                 :             :     }
    1753                 :   190469260 :   for (e = indirect_calls; e; e = f)
    1754                 :             :     {
    1755                 :      797109 :       f = e->next_callee;
    1756                 :      797109 :       symtab->call_edge_removal_hooks (e);
    1757                 :      797109 :       if (!e->indirect_unknown_callee)
    1758                 :           0 :         e->remove_callee ();
    1759                 :      797109 :       symtab->free_edge (e);
    1760                 :             :     }
    1761                 :   189672151 :   indirect_calls = NULL;
    1762                 :   189672151 :   callees = NULL;
    1763                 :   189672151 :   if (call_site_hash)
    1764                 :             :     {
    1765                 :       26150 :       call_site_hash->empty ();
    1766                 :       26150 :       call_site_hash = NULL;
    1767                 :             :     }
    1768                 :   189672151 : }
    1769                 :             : 
    1770                 :             : /* Remove all callers from the node.  */
    1771                 :             : 
    1772                 :             : void
    1773                 :    84068155 : cgraph_node::remove_callers (void)
    1774                 :             : {
    1775                 :    84068155 :   cgraph_edge *e, *f;
    1776                 :             : 
    1777                 :             :   /* It is sufficient to remove the edges from the lists of callees of
    1778                 :             :      the callers.  The caller list of the node can be zapped with one
    1779                 :             :      assignment.  */
    1780                 :    87571500 :   for (e = callers; e; e = f)
    1781                 :             :     {
    1782                 :     3503345 :       f = e->next_caller;
    1783                 :     3503345 :       symtab->call_edge_removal_hooks (e);
    1784                 :     3503345 :       e->remove_caller ();
    1785                 :     3503345 :       symtab->free_edge (e);
    1786                 :             :     }
    1787                 :    84068155 :   callers = NULL;
    1788                 :    84068155 : }
    1789                 :             : 
    1790                 :             : /* Helper function for cgraph_release_function_body and free_lang_data.
    1791                 :             :    It releases body from function DECL without having to inspect its
    1792                 :             :    possibly non-existent symtab node.  */
    1793                 :             : 
    1794                 :             : void
    1795                 :   100974216 : release_function_body (tree decl)
    1796                 :             : {
    1797                 :   100974216 :   function *fn = DECL_STRUCT_FUNCTION (decl);
    1798                 :   100974216 :   if (fn)
    1799                 :             :     {
    1800                 :    83026164 :       if (fn->cfg
    1801                 :    83026164 :           && loops_for_fn (fn))
    1802                 :             :         {
    1803                 :     1436891 :           fn->curr_properties &= ~PROP_loops;
    1804                 :     1436891 :           loop_optimizer_finalize (fn);
    1805                 :             :         }
    1806                 :    83026164 :       if (fn->gimple_df)
    1807                 :             :         {
    1808                 :     1446588 :           delete_tree_ssa (fn);
    1809                 :     1446588 :           fn->eh = NULL;
    1810                 :             :         }
    1811                 :    83026164 :       if (fn->cfg)
    1812                 :             :         {
    1813                 :     1436892 :           gcc_assert (!dom_info_available_p (fn, CDI_DOMINATORS));
    1814                 :     1436892 :           gcc_assert (!dom_info_available_p (fn, CDI_POST_DOMINATORS));
    1815                 :     1436892 :           delete_tree_cfg_annotations (fn);
    1816                 :     1436892 :           free_cfg (fn);
    1817                 :     1436892 :           fn->cfg = NULL;
    1818                 :             :         }
    1819                 :    83026164 :       if (fn->value_histograms)
    1820                 :          12 :         free_histograms (fn);
    1821                 :    83026164 :       gimple_set_body (decl, NULL);
    1822                 :             :       /* Struct function hangs a lot of data that would leak if we didn't
    1823                 :             :          removed all pointers to it.   */
    1824                 :    83026164 :       ggc_free (fn);
    1825                 :    83026164 :       DECL_STRUCT_FUNCTION (decl) = NULL;
    1826                 :             :     }
    1827                 :   100974216 :   DECL_SAVED_TREE (decl) = NULL;
    1828                 :   100974216 : }
    1829                 :             : 
    1830                 :             : /* Release memory used to represent body of function.
    1831                 :             :    Use this only for functions that are released before being translated to
    1832                 :             :    target code (i.e. RTL).  Functions that are compiled to RTL and beyond
    1833                 :             :    are free'd in final.cc via free_after_compilation().
    1834                 :             :    KEEP_ARGUMENTS are useful only if you want to rebuild body as thunk.  */
    1835                 :             : 
    1836                 :             : void
    1837                 :    94428642 : cgraph_node::release_body (bool keep_arguments)
    1838                 :             : {
    1839                 :    94428642 :   ipa_transforms_to_apply.release ();
    1840                 :    94428642 :   if (!used_as_abstract_origin && symtab->state != PARSING)
    1841                 :             :     {
    1842                 :    93918064 :       DECL_RESULT (decl) = NULL;
    1843                 :             : 
    1844                 :    93918064 :       if (!keep_arguments)
    1845                 :    93888968 :         DECL_ARGUMENTS (decl) = NULL;
    1846                 :             :     }
    1847                 :             :   /* If the node is abstract and needed, then do not clear
    1848                 :             :      DECL_INITIAL of its associated function declaration because it's
    1849                 :             :      needed to emit debug info later.  */
    1850                 :    94428642 :   if (!used_as_abstract_origin && DECL_INITIAL (decl))
    1851                 :    82753157 :     DECL_INITIAL (decl) = error_mark_node;
    1852                 :    94428642 :   release_function_body (decl);
    1853                 :    94428642 :   if (lto_file_data)
    1854                 :             :     {
    1855                 :       46169 :       lto_free_function_in_decl_state_for_node (this);
    1856                 :       46169 :       lto_file_data = NULL;
    1857                 :             :     }
    1858                 :    94428642 :   if (flag_checking && clones)
    1859                 :             :     {
    1860                 :             :       /* It is invalid to release body before materializing clones except
    1861                 :             :          for thunks that don't really need a body.  Verify also that we do
    1862                 :             :          not leak pointers to the call statements.  */
    1863                 :          46 :       for (cgraph_node *node = clones; node;
    1864                 :          27 :            node = node->next_sibling_clone)
    1865                 :          27 :         gcc_assert (node->thunk && !node->callees->call_stmt);
    1866                 :             :     }
    1867                 :    94428642 :   remove_callees ();
    1868                 :    94428642 :   remove_all_references ();
    1869                 :    94428642 : }
    1870                 :             : 
    1871                 :             : /* Remove function from symbol table.  */
    1872                 :             : 
    1873                 :             : void
    1874                 :    84068155 : cgraph_node::remove (void)
    1875                 :             : {
    1876                 :    84068155 :   bool clone_info_set = false;
    1877                 :    84068155 :   clone_info *info, saved_info;
    1878                 :    84068155 :   if (symtab->ipa_clones_dump_file && symtab->cloned_nodes.contains (this))
    1879                 :           0 :     fprintf (symtab->ipa_clones_dump_file,
    1880                 :             :              "Callgraph removal;%s;%d;%s;%d;%d\n", asm_name (), order,
    1881                 :           0 :              DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
    1882                 :           0 :              DECL_SOURCE_COLUMN (decl));
    1883                 :             : 
    1884                 :    84068155 :   if ((info = clone_info::get (this)) != NULL)
    1885                 :             :     {
    1886                 :      279824 :       saved_info = *info;
    1887                 :      279824 :       clone_info_set = true;
    1888                 :             :     }
    1889                 :    84068155 :   symtab->call_cgraph_removal_hooks (this);
    1890                 :    84068155 :   remove_callers ();
    1891                 :    84068155 :   remove_callees ();
    1892                 :    84068155 :   ipa_transforms_to_apply.release ();
    1893                 :    84068155 :   delete_function_version (function_version ());
    1894                 :             : 
    1895                 :             :   /* Incremental inlining access removed nodes stored in the postorder list.
    1896                 :             :      */
    1897                 :    84068155 :   force_output = false;
    1898                 :    84068155 :   forced_by_abi = false;
    1899                 :             : 
    1900                 :   167856486 :   unregister (clone_info_set ? &saved_info : NULL);
    1901                 :    84068155 :   if (prev_sibling_clone)
    1902                 :      560685 :     prev_sibling_clone->next_sibling_clone = next_sibling_clone;
    1903                 :    83507470 :   else if (clone_of)
    1904                 :             :     {
    1905                 :     1348323 :       clone_of->clones = next_sibling_clone;
    1906                 :     1348323 :       if (!clones)
    1907                 :             :         {
    1908                 :     1347573 :           bool need_body = false;
    1909                 :     1347573 :           for (cgraph_node *n = clone_of; n; n = n->clone_of)
    1910                 :     1342355 :             if (n->analyzed || n->clones)
    1911                 :             :               {
    1912                 :             :                 need_body = true;
    1913                 :             :                 break;
    1914                 :             :               }
    1915                 :     1342351 :           if (!need_body)
    1916                 :        5218 :             clone_of->release_body ();
    1917                 :             :         }
    1918                 :             :     }
    1919                 :    84068155 :   if (next_sibling_clone)
    1920                 :      685529 :     next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
    1921                 :    84068155 :   if (clones)
    1922                 :             :     {
    1923                 :       28496 :       cgraph_node *n, *next;
    1924                 :             : 
    1925                 :       28496 :       if (clone_of)
    1926                 :             :         {
    1927                 :      131454 :           for (n = clones; n->next_sibling_clone; n = n->next_sibling_clone)
    1928                 :      102958 :             n->clone_of = clone_of;
    1929                 :       28496 :           n->clone_of = clone_of;
    1930                 :       28496 :           n->next_sibling_clone = clone_of->clones;
    1931                 :       28496 :           if (clone_of->clones)
    1932                 :       24672 :             clone_of->clones->prev_sibling_clone = n;
    1933                 :       28496 :           clone_of->clones = clones;
    1934                 :             :         }
    1935                 :             :       else
    1936                 :             :         {
    1937                 :             :           /* We are removing node with clones.  This makes clones inconsistent,
    1938                 :             :              but assume they will be removed subsequently and just keep clone
    1939                 :             :              tree intact.  This can happen in unreachable function removal since
    1940                 :             :              we remove unreachable functions in random order, not by bottom-up
    1941                 :             :              walk of clone trees.  */
    1942                 :           0 :           for (n = clones; n; n = next)
    1943                 :             :             {
    1944                 :           0 :                next = n->next_sibling_clone;
    1945                 :           0 :                n->next_sibling_clone = NULL;
    1946                 :           0 :                n->prev_sibling_clone = NULL;
    1947                 :           0 :                n->clone_of = NULL;
    1948                 :             :             }
    1949                 :             :         }
    1950                 :             :     }
    1951                 :             : 
    1952                 :             :   /* While all the clones are removed after being proceeded, the function
    1953                 :             :      itself is kept in the cgraph even after it is compiled.  Check whether
    1954                 :             :      we are done with this body and reclaim it proactively if this is the case.
    1955                 :             :      */
    1956                 :    84068155 :   if (symtab->state != LTO_STREAMING)
    1957                 :             :     {
    1958                 :    84066144 :       cgraph_node *n = cgraph_node::get (decl);
    1959                 :    84066144 :       if (!n
    1960                 :    84066144 :           || (!n->clones && !n->clone_of && !n->inlined_to
    1961                 :      865537 :               && ((symtab->global_info_ready || in_lto_p)
    1962                 :        8972 :                   && (TREE_ASM_WRITTEN (n->decl)
    1963                 :        8940 :                       || DECL_EXTERNAL (n->decl)
    1964                 :        4524 :                       || !n->analyzed
    1965                 :        4480 :                       || (!flag_wpa && n->in_other_partition)))))
    1966                 :    81830585 :         release_body ();
    1967                 :             :     }
    1968                 :             :   else
    1969                 :             :     {
    1970                 :        2011 :       lto_free_function_in_decl_state_for_node (this);
    1971                 :        2011 :       lto_file_data = NULL;
    1972                 :             :     }
    1973                 :             : 
    1974                 :    84068155 :   decl = NULL;
    1975                 :    84068155 :   if (call_site_hash)
    1976                 :             :     {
    1977                 :           0 :       call_site_hash->empty ();
    1978                 :           0 :       call_site_hash = NULL;
    1979                 :             :     }
    1980                 :             : 
    1981                 :    84068155 :   symtab->release_symbol (this);
    1982                 :    84068155 : }
    1983                 :             : 
    1984                 :             : /* Likewise indicate that a node is having address taken.  */
    1985                 :             : 
    1986                 :             : void
    1987                 :     4213219 : cgraph_node::mark_address_taken (void)
    1988                 :             : {
    1989                 :             :   /* Indirect inlining can figure out that all uses of the address are
    1990                 :             :      inlined.  */
    1991                 :     4213219 :   if (inlined_to)
    1992                 :             :     {
    1993                 :           0 :       gcc_assert (cfun->after_inlining);
    1994                 :           0 :       gcc_assert (callers->indirect_inlining_edge);
    1995                 :             :       return;
    1996                 :             :     }
    1997                 :             :   /* FIXME: address_taken flag is used both as a shortcut for testing whether
    1998                 :             :      IPA_REF_ADDR reference exists (and thus it should be set on node
    1999                 :             :      representing alias we take address of) and as a test whether address
    2000                 :             :      of the object was taken (and thus it should be set on node alias is
    2001                 :             :      referring to).  We should remove the first use and the remove the
    2002                 :             :      following set.  */
    2003                 :     4213219 :   address_taken = 1;
    2004                 :     4213219 :   cgraph_node *node = ultimate_alias_target ();
    2005                 :     4213219 :   node->address_taken = 1;
    2006                 :             : }
    2007                 :             : 
    2008                 :             : /* Return local info node for the compiled function.  */
    2009                 :             : 
    2010                 :             : cgraph_node *
    2011                 :    11676243 : cgraph_node::local_info_node (tree decl)
    2012                 :             : {
    2013                 :    11676243 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    2014                 :    11676243 :   cgraph_node *node = get (decl);
    2015                 :    11676243 :   if (!node)
    2016                 :             :     return NULL;
    2017                 :    11676243 :   return node->ultimate_alias_target ();
    2018                 :             : }
    2019                 :             : 
    2020                 :             : /* Return RTL info for the compiled function.  */
    2021                 :             : 
    2022                 :             : cgraph_rtl_info *
    2023                 :    49969163 : cgraph_node::rtl_info (const_tree decl)
    2024                 :             : {
    2025                 :    49969163 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    2026                 :    49969163 :   cgraph_node *node = get (decl);
    2027                 :    49969163 :   if (!node)
    2028                 :             :     return NULL;
    2029                 :    49865100 :   enum availability avail;
    2030                 :    49865100 :   node = node->ultimate_alias_target (&avail);
    2031                 :    49865100 :   if (decl != current_function_decl
    2032                 :    47124231 :       && (avail < AVAIL_AVAILABLE
    2033                 :    42577617 :           || (node->decl != current_function_decl
    2034                 :    42511994 :               && !TREE_ASM_WRITTEN (node->decl))))
    2035                 :             :     return NULL;
    2036                 :             :   /* Allocate if it doesn't exist.  */
    2037                 :    42109970 :   if (node->rtl == NULL)
    2038                 :             :     {
    2039                 :     1270247 :       node->rtl = ggc_cleared_alloc<cgraph_rtl_info> ();
    2040                 :     1270247 :       SET_HARD_REG_SET (node->rtl->function_used_regs);
    2041                 :             :     }
    2042                 :    42109970 :   return node->rtl;
    2043                 :             : }
    2044                 :             : 
    2045                 :             : /* Return a string describing the failure REASON.  */
    2046                 :             : 
    2047                 :             : const char*
    2048                 :       10065 : cgraph_inline_failed_string (cgraph_inline_failed_t reason)
    2049                 :             : {
    2050                 :             : #undef DEFCIFCODE
    2051                 :             : #define DEFCIFCODE(code, type, string)  string,
    2052                 :             : 
    2053                 :       10065 :   static const char *cif_string_table[CIF_N_REASONS] = {
    2054                 :             : #include "cif-code.def"
    2055                 :             :   };
    2056                 :             : 
    2057                 :             :   /* Signedness of an enum type is implementation defined, so cast it
    2058                 :             :      to unsigned before testing. */
    2059                 :       10065 :   gcc_assert ((unsigned) reason < CIF_N_REASONS);
    2060                 :       10065 :   return cif_string_table[reason];
    2061                 :             : }
    2062                 :             : 
    2063                 :             : /* Return a type describing the failure REASON.  */
    2064                 :             : 
    2065                 :             : cgraph_inline_failed_type_t
    2066                 :    62800722 : cgraph_inline_failed_type (cgraph_inline_failed_t reason)
    2067                 :             : {
    2068                 :             : #undef DEFCIFCODE
    2069                 :             : #define DEFCIFCODE(code, type, string)  type,
    2070                 :             : 
    2071                 :    62800722 :   static cgraph_inline_failed_type_t cif_type_table[CIF_N_REASONS] = {
    2072                 :             : #include "cif-code.def"
    2073                 :             :   };
    2074                 :             : 
    2075                 :             :   /* Signedness of an enum type is implementation defined, so cast it
    2076                 :             :      to unsigned before testing. */
    2077                 :    62800722 :   gcc_assert ((unsigned) reason < CIF_N_REASONS);
    2078                 :    62800722 :   return cif_type_table[reason];
    2079                 :             : }
    2080                 :             : 
    2081                 :             : /* Names used to print out the availability enum.  */
    2082                 :             : const char * const cgraph_availability_names[] =
    2083                 :             :   {"unset", "not_available", "overwritable", "available", "local"};
    2084                 :             : 
    2085                 :             : /* Output flags of edge to a file F.  */
    2086                 :             : 
    2087                 :             : void
    2088                 :       23549 : cgraph_edge::dump_edge_flags (FILE *f)
    2089                 :             : {
    2090                 :       23549 :   if (speculative)
    2091                 :         183 :     fprintf (f, "(speculative) ");
    2092                 :       23549 :   if (!inline_failed)
    2093                 :        2029 :     fprintf (f, "(inlined) ");
    2094                 :       23549 :   if (call_stmt_cannot_inline_p)
    2095                 :           0 :     fprintf (f, "(call_stmt_cannot_inline_p) ");
    2096                 :       23549 :   if (indirect_inlining_edge)
    2097                 :         422 :     fprintf (f, "(indirect_inlining) ");
    2098                 :       23549 :   if (count.initialized_p ())
    2099                 :             :     {
    2100                 :       22633 :       fprintf (f, "(");
    2101                 :       22633 :       count.dump (f);
    2102                 :       22633 :       fprintf (f, ",");
    2103                 :       22633 :       fprintf (f, "%.2f per call) ", sreal_frequency ().to_double ());
    2104                 :             :     }
    2105                 :       23549 :   if (can_throw_external)
    2106                 :        3489 :     fprintf (f, "(can throw external) ");
    2107                 :       23549 : }
    2108                 :             : 
    2109                 :             : /* Dump edge to stderr.  */
    2110                 :             : 
    2111                 :             : void
    2112                 :           0 : cgraph_edge::debug (void)
    2113                 :             : {
    2114                 :           0 :   fprintf (stderr, "%s -> %s ", caller->dump_asm_name (),
    2115                 :           0 :            callee == NULL ? "(null)" : callee->dump_asm_name ());
    2116                 :           0 :   dump_edge_flags (stderr);
    2117                 :           0 :   fprintf (stderr, "\n\n");
    2118                 :           0 :   caller->debug ();
    2119                 :           0 :   if (callee != NULL)
    2120                 :           0 :     callee->debug ();
    2121                 :           0 : }
    2122                 :             : 
    2123                 :             : /* Dump call graph node to file F.  */
    2124                 :             : 
    2125                 :             : void
    2126                 :        6489 : cgraph_node::dump (FILE *f)
    2127                 :             : {
    2128                 :        6489 :   cgraph_edge *edge;
    2129                 :             : 
    2130                 :        6489 :   dump_base (f);
    2131                 :             : 
    2132                 :        6489 :   if (inlined_to)
    2133                 :         873 :     fprintf (f, "  Function %s is inline copy in %s\n",
    2134                 :             :              dump_name (),
    2135                 :             :              inlined_to->dump_name ());
    2136                 :        6489 :   if (clone_of)
    2137                 :         790 :     fprintf (f, "  Clone of %s\n", clone_of->dump_asm_name ());
    2138                 :        6489 :   if (symtab->function_flags_ready)
    2139                 :       11748 :     fprintf (f, "  Availability: %s\n",
    2140                 :        5874 :              cgraph_availability_names [get_availability ()]);
    2141                 :             : 
    2142                 :        6489 :   if (profile_id)
    2143                 :         143 :     fprintf (f, "  Profile id: %i\n",
    2144                 :             :              profile_id);
    2145                 :        6489 :   if (unit_id)
    2146                 :         129 :     fprintf (f, "  Unit id: %i\n",
    2147                 :             :              unit_id);
    2148                 :        6489 :   cgraph_function_version_info *vi = function_version ();
    2149                 :        6489 :   if (vi != NULL)
    2150                 :             :     {
    2151                 :           0 :       fprintf (f, "  Version info: ");
    2152                 :           0 :       if (vi->prev != NULL)
    2153                 :             :         {
    2154                 :           0 :           fprintf (f, "prev: ");
    2155                 :           0 :           fprintf (f, "%s ", vi->prev->this_node->dump_asm_name ());
    2156                 :             :         }
    2157                 :           0 :       if (vi->next != NULL)
    2158                 :             :         {
    2159                 :           0 :           fprintf (f, "next: ");
    2160                 :           0 :           fprintf (f, "%s ", vi->next->this_node->dump_asm_name ());
    2161                 :             :         }
    2162                 :           0 :       if (vi->dispatcher_resolver != NULL_TREE)
    2163                 :           0 :         fprintf (f, "dispatcher: %s",
    2164                 :           0 :                  lang_hooks.decl_printable_name (vi->dispatcher_resolver, 2));
    2165                 :             : 
    2166                 :           0 :       fprintf (f, "\n");
    2167                 :             :     }
    2168                 :        6489 :   fprintf (f, "  Function flags:");
    2169                 :        6489 :   if (count.initialized_p ())
    2170                 :             :     {
    2171                 :        3996 :       fprintf (f, " count:");
    2172                 :        3996 :       count.dump (f);
    2173                 :             :     }
    2174                 :        6489 :   if (tp_first_run > 0)
    2175                 :          62 :     fprintf (f, " first_run:%" PRId64, (int64_t) tp_first_run);
    2176                 :        6489 :   if (cgraph_node *origin = nested_function_origin (this))
    2177                 :           0 :     fprintf (f, " nested in:%s", origin->dump_asm_name ());
    2178                 :        6489 :   if (gimple_has_body_p (decl))
    2179                 :        4268 :     fprintf (f, " body");
    2180                 :        6489 :   if (process)
    2181                 :           0 :     fprintf (f, " process");
    2182                 :        6489 :   if (local)
    2183                 :        1222 :     fprintf (f, " local");
    2184                 :        6489 :   if (redefined_extern_inline)
    2185                 :           0 :     fprintf (f, " redefined_extern_inline");
    2186                 :        6489 :   if (only_called_at_startup)
    2187                 :         453 :     fprintf (f, " only_called_at_startup");
    2188                 :        6489 :   if (only_called_at_exit)
    2189                 :           6 :     fprintf (f, " only_called_at_exit");
    2190                 :        6489 :   if (tm_clone)
    2191                 :           0 :     fprintf (f, " tm_clone");
    2192                 :        6489 :   if (calls_comdat_local)
    2193                 :          12 :     fprintf (f, " calls_comdat_local");
    2194                 :        6489 :   if (icf_merged)
    2195                 :          27 :     fprintf (f, " icf_merged");
    2196                 :        6489 :   if (merged_comdat)
    2197                 :           0 :     fprintf (f, " merged_comdat");
    2198                 :        6489 :   if (merged_extern_inline)
    2199                 :           0 :     fprintf (f, " merged_extern_inline");
    2200                 :        6489 :   if (split_part)
    2201                 :          27 :     fprintf (f, " split_part");
    2202                 :        6489 :   if (indirect_call_target)
    2203                 :         272 :     fprintf (f, " indirect_call_target");
    2204                 :        6489 :   if (nonfreeing_fn)
    2205                 :         373 :     fprintf (f, " nonfreeing_fn");
    2206                 :        6489 :   if (DECL_STATIC_CONSTRUCTOR (decl))
    2207                 :          55 :     fprintf (f," static_constructor (priority:%i)", get_init_priority ());
    2208                 :        6489 :   if (DECL_STATIC_DESTRUCTOR (decl))
    2209                 :           6 :     fprintf (f," static_destructor (priority:%i)", get_fini_priority ());
    2210                 :        6489 :   if (frequency == NODE_FREQUENCY_HOT)
    2211                 :          55 :     fprintf (f, " hot");
    2212                 :        6489 :   if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
    2213                 :          46 :     fprintf (f, " unlikely_executed");
    2214                 :        6489 :   if (frequency == NODE_FREQUENCY_EXECUTED_ONCE)
    2215                 :         783 :     fprintf (f, " executed_once");
    2216                 :        6489 :   if (opt_for_fn (decl, optimize_size))
    2217                 :         176 :     fprintf (f, " optimize_size");
    2218                 :        6489 :   if (parallelized_function)
    2219                 :           0 :     fprintf (f, " parallelized_function");
    2220                 :        6489 :   if (DECL_IS_MALLOC (decl))
    2221                 :          82 :     fprintf (f, " decl_is_malloc");
    2222                 :        6489 :   if (DECL_IS_OPERATOR_NEW_P (decl))
    2223                 :          45 :     fprintf (f, " %soperator_new",
    2224                 :          45 :              DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
    2225                 :        6489 :   if (DECL_IS_OPERATOR_DELETE_P (decl))
    2226                 :          34 :     fprintf (f, " %soperator_delete",
    2227                 :          34 :              DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
    2228                 :             : 
    2229                 :        6489 :   if (DECL_STATIC_CHAIN (decl))
    2230                 :           6 :     fprintf (f, " static_chain");
    2231                 :             : 
    2232                 :        6489 :   fprintf (f, "\n");
    2233                 :             : 
    2234                 :        6489 :   if (thunk)
    2235                 :             :     {
    2236                 :          57 :       fprintf (f, "  Thunk");
    2237                 :          57 :       thunk_info::get (this)->dump (f);
    2238                 :             :     }
    2239                 :        6432 :   else if (former_thunk_p ())
    2240                 :             :     {
    2241                 :          36 :       fprintf (f, "  Former thunk ");
    2242                 :          36 :       thunk_info::get (this)->dump (f);
    2243                 :             :     }
    2244                 :        6396 :   else gcc_checking_assert (!thunk_info::get (this));
    2245                 :             :   
    2246                 :        6489 :   fprintf (f, "  Called by: ");
    2247                 :             : 
    2248                 :        6489 :   profile_count sum = profile_count::zero ();
    2249                 :       14526 :   for (edge = callers; edge; edge = edge->next_caller)
    2250                 :             :     {
    2251                 :        8037 :       fprintf (f, "%s ", edge->caller->dump_asm_name ());
    2252                 :        8037 :       edge->dump_edge_flags (f);
    2253                 :        8037 :       if (edge->count.initialized_p ())
    2254                 :        7712 :         sum += edge->count.ipa ();
    2255                 :             :     }
    2256                 :             : 
    2257                 :        6489 :   fprintf (f, "\n  Calls: ");
    2258                 :       21127 :   for (edge = callees; edge; edge = edge->next_callee)
    2259                 :             :     {
    2260                 :       14638 :       fprintf (f, "%s ", edge->callee->dump_asm_name ());
    2261                 :       14638 :       edge->dump_edge_flags (f);
    2262                 :             :     }
    2263                 :        6489 :   fprintf (f, "\n");
    2264                 :             : 
    2265                 :        6489 :   if (!body_removed && count.ipa ().initialized_p ())
    2266                 :             :     {
    2267                 :         108 :       bool ok = true;
    2268                 :         108 :       bool min = false;
    2269                 :             :       ipa_ref *ref;
    2270                 :             : 
    2271                 :         108 :       FOR_EACH_ALIAS (this, ref)
    2272                 :           0 :         if (dyn_cast <cgraph_node *> (ref->referring)->count.initialized_p ())
    2273                 :           0 :           sum += dyn_cast <cgraph_node *> (ref->referring)->count.ipa ();
    2274                 :             : 
    2275                 :         108 :       if (inlined_to
    2276                 :         108 :           || (symtab->state < EXPANSION
    2277                 :         108 :               && ultimate_alias_target () == this && only_called_directly_p ()))
    2278                 :           1 :         ok = !count.ipa ().differs_from_p (sum);
    2279                 :         107 :       else if (count.ipa () > profile_count::from_gcov_type (100)
    2280                 :         107 :                && count.ipa () < sum.apply_scale (99, 100))
    2281                 :           0 :         ok = false, min = true;
    2282                 :         108 :       if (!ok)
    2283                 :             :         {
    2284                 :           0 :           fprintf (f, "   Invalid sum of caller counts ");
    2285                 :           0 :           sum.dump (f);
    2286                 :           0 :           if (min)
    2287                 :           0 :             fprintf (f, ", should be at most ");
    2288                 :             :           else
    2289                 :           0 :             fprintf (f, ", should be ");
    2290                 :           0 :           count.ipa ().dump (f);
    2291                 :           0 :           fprintf (f, "\n");
    2292                 :             :         }
    2293                 :             :     }
    2294                 :             : 
    2295                 :        7363 :   for (edge = indirect_calls; edge; edge = edge->next_callee)
    2296                 :             :     {
    2297                 :         874 :       if (edge->indirect_info->polymorphic)
    2298                 :             :         {
    2299                 :         359 :           fprintf (f, "   Polymorphic indirect call of type ");
    2300                 :         359 :           print_generic_expr (f, edge->indirect_info->otr_type, TDF_SLIM);
    2301                 :         359 :           fprintf (f, " token:%i", (int) edge->indirect_info->otr_token);
    2302                 :             :         }
    2303                 :             :       else
    2304                 :         515 :         fprintf (f, "   Indirect call");
    2305                 :         874 :       edge->dump_edge_flags (f);
    2306                 :         874 :       if (edge->indirect_info->param_index != -1)
    2307                 :             :         {
    2308                 :         259 :           fprintf (f, "of param:%i ", edge->indirect_info->param_index);
    2309                 :         259 :           if (edge->indirect_info->agg_contents)
    2310                 :          22 :            fprintf (f, "loaded from %s %s at offset %i ",
    2311                 :          22 :                     edge->indirect_info->member_ptr ? "member ptr" : "aggregate",
    2312                 :          22 :                     edge->indirect_info->by_ref ? "passed by reference":"",
    2313                 :          22 :                     (int)edge->indirect_info->offset);
    2314                 :         259 :           if (edge->indirect_info->vptr_changed)
    2315                 :          26 :             fprintf (f, "(vptr maybe changed) ");
    2316                 :             :         }
    2317                 :         874 :       fprintf (f, "num speculative call targets: %i\n",
    2318                 :         874 :                edge->indirect_info->num_speculative_call_targets);
    2319                 :         874 :       if (edge->indirect_info->polymorphic)
    2320                 :         359 :         edge->indirect_info->context.dump (f);
    2321                 :             :     }
    2322                 :        6489 : }
    2323                 :             : 
    2324                 :             : /* Dump call graph node to file F in graphviz format.  */
    2325                 :             : 
    2326                 :             : void
    2327                 :           0 : cgraph_node::dump_graphviz (FILE *f)
    2328                 :             : {
    2329                 :           0 :   cgraph_edge *edge;
    2330                 :             : 
    2331                 :           0 :   for (edge = callees; edge; edge = edge->next_callee)
    2332                 :             :     {
    2333                 :           0 :       cgraph_node *callee = edge->callee;
    2334                 :             : 
    2335                 :           0 :       fprintf (f, "\t\"%s\" -> \"%s\"\n", dump_name (), callee->dump_name ());
    2336                 :             :     }
    2337                 :           0 : }
    2338                 :             : 
    2339                 :             : 
    2340                 :             : /* Dump call graph node NODE to stderr.  */
    2341                 :             : 
    2342                 :             : DEBUG_FUNCTION void
    2343                 :           0 : cgraph_node::debug (void)
    2344                 :             : {
    2345                 :           0 :   dump (stderr);
    2346                 :           0 : }
    2347                 :             : 
    2348                 :             : /* Dump the callgraph to file F.  */
    2349                 :             : 
    2350                 :             : void
    2351                 :          82 : cgraph_node::dump_cgraph (FILE *f)
    2352                 :             : {
    2353                 :          82 :   cgraph_node *node;
    2354                 :             : 
    2355                 :          82 :   fprintf (f, "callgraph:\n\n");
    2356                 :         796 :   FOR_EACH_FUNCTION (node)
    2357                 :         316 :     node->dump (f);
    2358                 :          82 : }
    2359                 :             : 
    2360                 :             : /* Return true when the DECL can possibly be inlined.  */
    2361                 :             : 
    2362                 :             : bool
    2363                 :    76792986 : cgraph_function_possibly_inlined_p (tree decl)
    2364                 :             : {
    2365                 :    76792986 :   if (!symtab->global_info_ready)
    2366                 :    70924324 :     return !DECL_UNINLINABLE (decl);
    2367                 :     5868662 :   return DECL_POSSIBLY_INLINED (decl);
    2368                 :             : }
    2369                 :             : 
    2370                 :             : /* Return function availability.  See cgraph.h for description of individual
    2371                 :             :    return values.  */
    2372                 :             : enum availability
    2373                 :   659895001 : cgraph_node::get_availability (symtab_node *ref)
    2374                 :             : {
    2375                 :   659895001 :   if (ref)
    2376                 :             :     {
    2377                 :   454989086 :       cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
    2378                 :   454989086 :       if (cref)
    2379                 :   454989086 :         ref = cref->inlined_to;
    2380                 :             :     }
    2381                 :   659895001 :   enum availability avail;
    2382                 :   659895001 :   if (!analyzed && !in_other_partition)
    2383                 :   402480461 :     avail = AVAIL_NOT_AVAILABLE;
    2384                 :   257414540 :   else if (local)
    2385                 :    72064157 :     avail = AVAIL_LOCAL;
    2386                 :   185350383 :   else if (inlined_to)
    2387                 :     1687976 :     avail = AVAIL_AVAILABLE;
    2388                 :   183662407 :   else if (transparent_alias)
    2389                 :         135 :     ultimate_alias_target (&avail, ref);
    2390                 :   183662272 :   else if (ifunc_resolver
    2391                 :   183662272 :            || lookup_attribute ("noipa", DECL_ATTRIBUTES (decl)))
    2392                 :     2485208 :     avail = AVAIL_INTERPOSABLE;
    2393                 :   181177064 :   else if (!externally_visible)
    2394                 :    25960776 :     avail = AVAIL_AVAILABLE;
    2395                 :             :   /* If this is a reference from symbol itself and there are no aliases, we
    2396                 :             :      may be sure that the symbol was not interposed by something else because
    2397                 :             :      the symbol itself would be unreachable otherwise.
    2398                 :             : 
    2399                 :             :      Also comdat groups are always resolved in groups.  */
    2400                 :       37608 :   else if ((this == ref && !has_aliases_p ())
    2401                 :   155217278 :            || (ref && get_comdat_group ()
    2402                 :      957946 :                && get_comdat_group () == ref->get_comdat_group ()))
    2403                 :       39126 :     avail = AVAIL_AVAILABLE;
    2404                 :             :   /* Inline functions are safe to be analyzed even if their symbol can
    2405                 :             :      be overwritten at runtime.  It is not meaningful to enforce any sane
    2406                 :             :      behavior on replacing inline function by different body.  */
    2407                 :   155177162 :   else if (DECL_DECLARED_INLINE_P (decl))
    2408                 :    44056694 :     avail = AVAIL_AVAILABLE;
    2409                 :             : 
    2410                 :             :   /* If the function can be overwritten, return OVERWRITABLE.  Take
    2411                 :             :      care at least of two notable extensions - the COMDAT functions
    2412                 :             :      used to share template instantiations in C++ (this is symmetric
    2413                 :             :      to code cp_cannot_inline_tree_fn and probably shall be shared and
    2414                 :             :      the inlinability hooks completely eliminated).  */
    2415                 :             : 
    2416                 :   111120468 :   else if (decl_replaceable_p (decl, semantic_interposition)
    2417                 :   111120468 :            && !DECL_EXTERNAL (decl))
    2418                 :     8559608 :     avail = AVAIL_INTERPOSABLE;
    2419                 :   102560860 :   else avail = AVAIL_AVAILABLE;
    2420                 :             : 
    2421                 :   659895001 :   return avail;
    2422                 :             : }
    2423                 :             : 
    2424                 :             : /* Worker for cgraph_node_can_be_local_p.  */
    2425                 :             : static bool
    2426                 :      743983 : cgraph_node_cannot_be_local_p_1 (cgraph_node *node, void *)
    2427                 :             : {
    2428                 :     1467279 :   return !(!node->force_output
    2429                 :             :            && !node->ifunc_resolver
    2430                 :             :            /* Limitation of gas requires us to output targets of symver aliases
    2431                 :             :               as global symbols.  This is binutils PR 25295.  */
    2432                 :      743983 :            && !node->symver
    2433                 :      723296 :            && ((DECL_COMDAT (node->decl)
    2434                 :      280896 :                 && !node->forced_by_abi
    2435                 :      259815 :                 && !node->used_from_object_file_p ()
    2436                 :      259815 :                 && !node->same_comdat_group)
    2437                 :      503962 :                || !node->externally_visible));
    2438                 :             : }
    2439                 :             : 
    2440                 :             : /* Return true if cgraph_node can be made local for API change.
    2441                 :             :    Extern inline functions and C++ COMDAT functions can be made local
    2442                 :             :    at the expense of possible code size growth if function is used in multiple
    2443                 :             :    compilation units.  */
    2444                 :             : bool
    2445                 :     1044265 : cgraph_node::can_be_local_p (void)
    2446                 :             : {
    2447                 :     1044265 :   return (!address_taken
    2448                 :     1044265 :           && !call_for_symbol_thunks_and_aliases (cgraph_node_cannot_be_local_p_1,
    2449                 :     1044265 :                                                 NULL, true));
    2450                 :             : }
    2451                 :             : 
    2452                 :             : /* Call callback on cgraph_node, thunks and aliases associated to cgraph_node.
    2453                 :             :    When INCLUDE_OVERWRITABLE is false, overwritable symbols are
    2454                 :             :    skipped.  When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
    2455                 :             :    skipped.  */
    2456                 :             : bool
    2457                 :    84549700 : cgraph_node::call_for_symbol_thunks_and_aliases (bool (*callback)
    2458                 :             :                                                    (cgraph_node *, void *),
    2459                 :             :                                                  void *data,
    2460                 :             :                                                  bool include_overwritable,
    2461                 :             :                                                  bool exclude_virtual_thunks)
    2462                 :             : {
    2463                 :    84549700 :   cgraph_edge *e;
    2464                 :    84549700 :   ipa_ref *ref;
    2465                 :    84549700 :   enum availability avail = AVAIL_AVAILABLE;
    2466                 :             : 
    2467                 :    84549700 :   if (include_overwritable
    2468                 :    84549700 :       || (avail = get_availability ()) > AVAIL_INTERPOSABLE)
    2469                 :             :     {
    2470                 :    84538609 :       if (callback (this, data))
    2471                 :             :         return true;
    2472                 :             :     }
    2473                 :    83507155 :   FOR_EACH_ALIAS (this, ref)
    2474                 :             :     {
    2475                 :     3782470 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    2476                 :     3782470 :       if (include_overwritable
    2477                 :     3782470 :           || alias->get_availability () > AVAIL_INTERPOSABLE)
    2478                 :     3782243 :         if (alias->call_for_symbol_thunks_and_aliases (callback, data,
    2479                 :             :                                                      include_overwritable,
    2480                 :             :                                                      exclude_virtual_thunks))
    2481                 :             :           return true;
    2482                 :             :     }
    2483                 :    79724685 :   if (avail <= AVAIL_INTERPOSABLE)
    2484                 :             :     return false;
    2485                 :    84335405 :   for (e = callers; e; e = e->next_caller)
    2486                 :     4621811 :     if (e->caller->thunk
    2487                 :        2995 :         && (include_overwritable
    2488                 :         488 :             || e->caller->get_availability () > AVAIL_INTERPOSABLE)
    2489                 :     4624806 :         && !(exclude_virtual_thunks
    2490                 :          25 :              && thunk_info::get (e->caller)->virtual_offset_p))
    2491                 :        2982 :       if (e->caller->call_for_symbol_thunks_and_aliases (callback, data,
    2492                 :             :                                                        include_overwritable,
    2493                 :             :                                                        exclude_virtual_thunks))
    2494                 :             :         return true;
    2495                 :             : 
    2496                 :             :   return false;
    2497                 :             : }
    2498                 :             : 
    2499                 :             : /* Worker to bring NODE local.  */
    2500                 :             : 
    2501                 :             : bool
    2502                 :           0 : cgraph_node::make_local (cgraph_node *node, void *)
    2503                 :             : {
    2504                 :           0 :   gcc_checking_assert (node->can_be_local_p ());
    2505                 :           0 :   if (DECL_COMDAT (node->decl) || DECL_EXTERNAL (node->decl))
    2506                 :             :     {
    2507                 :           0 :       node->make_decl_local ();
    2508                 :           0 :       node->set_section (NULL);
    2509                 :           0 :       node->set_comdat_group (NULL);
    2510                 :           0 :       node->externally_visible = false;
    2511                 :           0 :       node->forced_by_abi = false;
    2512                 :           0 :       node->local = true;
    2513                 :           0 :       node->unique_name = ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
    2514                 :           0 :                            || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
    2515                 :           0 :                            && !flag_incremental_link);
    2516                 :           0 :       node->resolution = LDPR_PREVAILING_DEF_IRONLY;
    2517                 :           0 :       gcc_assert (node->get_availability () == AVAIL_LOCAL);
    2518                 :             :     }
    2519                 :           0 :   return false;
    2520                 :             : }
    2521                 :             : 
    2522                 :             : /* Bring cgraph node local.  */
    2523                 :             : 
    2524                 :             : void
    2525                 :           0 : cgraph_node::make_local (void)
    2526                 :             : {
    2527                 :           0 :   call_for_symbol_thunks_and_aliases (cgraph_node::make_local, NULL, true);
    2528                 :           0 : }
    2529                 :             : 
    2530                 :             : /* Worker to set nothrow flag.  */
    2531                 :             : 
    2532                 :             : static void
    2533                 :      842994 : set_nothrow_flag_1 (cgraph_node *node, bool nothrow, bool non_call,
    2534                 :             :                     bool *changed)
    2535                 :             : {
    2536                 :      842994 :   cgraph_edge *e;
    2537                 :             : 
    2538                 :      842994 :   if (nothrow && !TREE_NOTHROW (node->decl))
    2539                 :             :     {
    2540                 :             :       /* With non-call exceptions we can't say for sure if other function body
    2541                 :             :          was not possibly optimized to still throw.  */
    2542                 :      842966 :       if (!non_call || node->binds_to_current_def_p ())
    2543                 :             :         {
    2544                 :      837931 :           TREE_NOTHROW (node->decl) = true;
    2545                 :      837931 :           *changed = true;
    2546                 :     2015109 :           for (e = node->callers; e; e = e->next_caller)
    2547                 :     1177178 :             e->can_throw_external = false;
    2548                 :             :         }
    2549                 :             :     }
    2550                 :           0 :   else if (!nothrow && TREE_NOTHROW (node->decl))
    2551                 :             :     {
    2552                 :           0 :       TREE_NOTHROW (node->decl) = false;
    2553                 :           0 :       *changed = true;
    2554                 :             :     }
    2555                 :             :   ipa_ref *ref;
    2556                 :      890902 :   FOR_EACH_ALIAS (node, ref)
    2557                 :             :     {
    2558                 :       47908 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    2559                 :       47908 :       if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
    2560                 :       47485 :         set_nothrow_flag_1 (alias, nothrow, non_call, changed);
    2561                 :             :     }
    2562                 :     2057110 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    2563                 :     1214116 :     if (e->caller->thunk
    2564                 :     1214116 :         && (!nothrow || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    2565                 :         180 :       set_nothrow_flag_1 (e->caller, nothrow, non_call, changed);
    2566                 :      842994 : }
    2567                 :             : 
    2568                 :             : /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
    2569                 :             :    if any to NOTHROW.  */
    2570                 :             : 
    2571                 :             : bool
    2572                 :      806432 : cgraph_node::set_nothrow_flag (bool nothrow)
    2573                 :             : {
    2574                 :      806432 :   bool changed = false;
    2575                 :      806432 :   bool non_call = opt_for_fn (decl, flag_non_call_exceptions);
    2576                 :             : 
    2577                 :      806432 :   if (!nothrow || get_availability () > AVAIL_INTERPOSABLE)
    2578                 :      794974 :     set_nothrow_flag_1 (this, nothrow, non_call, &changed);
    2579                 :             :   else
    2580                 :             :     {
    2581                 :             :       ipa_ref *ref;
    2582                 :             : 
    2583                 :       18873 :       FOR_EACH_ALIAS (this, ref)
    2584                 :             :         {
    2585                 :        7415 :           cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    2586                 :        7415 :           if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
    2587                 :         355 :             set_nothrow_flag_1 (alias, nothrow, non_call, &changed);
    2588                 :             :         }
    2589                 :             :     }
    2590                 :      806432 :   return changed;
    2591                 :             : }
    2592                 :             : 
    2593                 :             : /* Worker to set malloc flag.  */
    2594                 :             : static void
    2595                 :       19577 : set_malloc_flag_1 (cgraph_node *node, bool malloc_p, bool *changed)
    2596                 :             : {
    2597                 :       19577 :   if (malloc_p && !DECL_IS_MALLOC (node->decl))
    2598                 :             :     {
    2599                 :       19198 :       DECL_IS_MALLOC (node->decl) = true;
    2600                 :       19198 :       *changed = true;
    2601                 :             :     }
    2602                 :             : 
    2603                 :             :   ipa_ref *ref;
    2604                 :       19581 :   FOR_EACH_ALIAS (node, ref)
    2605                 :             :     {
    2606                 :           4 :       cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    2607                 :           4 :       if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    2608                 :           4 :         set_malloc_flag_1 (alias, malloc_p, changed);
    2609                 :             :     }
    2610                 :             : 
    2611                 :       42906 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    2612                 :       23329 :     if (e->caller->thunk
    2613                 :       23329 :         && (!malloc_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    2614                 :           0 :       set_malloc_flag_1 (e->caller, malloc_p, changed);
    2615                 :       19577 : }
    2616                 :             : 
    2617                 :             : /* Set DECL_IS_MALLOC on NODE's decl and on NODE's aliases if any.  */
    2618                 :             : 
    2619                 :             : bool
    2620                 :       19573 : cgraph_node::set_malloc_flag (bool malloc_p)
    2621                 :             : {
    2622                 :       19573 :   bool changed = false;
    2623                 :             : 
    2624                 :       19573 :   if (!malloc_p || get_availability () > AVAIL_INTERPOSABLE)
    2625                 :       19573 :     set_malloc_flag_1 (this, malloc_p, &changed);
    2626                 :             :   else
    2627                 :             :     {
    2628                 :             :       ipa_ref *ref;
    2629                 :             : 
    2630                 :           0 :       FOR_EACH_ALIAS (this, ref)
    2631                 :             :         {
    2632                 :           0 :           cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    2633                 :           0 :           if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    2634                 :           0 :             set_malloc_flag_1 (alias, malloc_p, &changed);
    2635                 :             :         }
    2636                 :             :     }
    2637                 :       19573 :   return changed;
    2638                 :             : }
    2639                 :             : 
    2640                 :             : /* Worker to set malloc flag.  */
    2641                 :             : static void
    2642                 :      201665 : add_detected_attribute_1 (cgraph_node *node, const char *attr, bool *changed)
    2643                 :             : {
    2644                 :      201665 :   if (!lookup_attribute (attr, DECL_ATTRIBUTES (node->decl)))
    2645                 :             :     {
    2646                 :      176684 :       DECL_ATTRIBUTES (node->decl) = tree_cons (get_identifier (attr),
    2647                 :      176684 :                                          NULL_TREE, DECL_ATTRIBUTES (node->decl));
    2648                 :      176684 :       *changed = true;
    2649                 :             :     }
    2650                 :             : 
    2651                 :             :   ipa_ref *ref;
    2652                 :      202690 :   FOR_EACH_ALIAS (node, ref)
    2653                 :             :     {
    2654                 :        1025 :       cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    2655                 :        1025 :       if (alias->get_availability () > AVAIL_INTERPOSABLE)
    2656                 :         600 :         add_detected_attribute_1 (alias, attr, changed);
    2657                 :             :     }
    2658                 :             : 
    2659                 :      616529 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    2660                 :      414864 :     if (e->caller->thunk
    2661                 :      414864 :         && (e->caller->get_availability () > AVAIL_INTERPOSABLE))
    2662                 :          17 :       add_detected_attribute_1 (e->caller, attr, changed);
    2663                 :      201665 : }
    2664                 :             : 
    2665                 :             : /* Add attribyte ATTR to function and its aliases.  */
    2666                 :             : 
    2667                 :             : bool
    2668                 :      204811 : cgraph_node::add_detected_attribute (const char *attr)
    2669                 :             : {
    2670                 :      204811 :   bool changed = false;
    2671                 :             : 
    2672                 :      204811 :   if (get_availability () > AVAIL_INTERPOSABLE)
    2673                 :      201048 :     add_detected_attribute_1 (this, attr, &changed);
    2674                 :             :   else
    2675                 :             :     {
    2676                 :             :       ipa_ref *ref;
    2677                 :             : 
    2678                 :        3787 :       FOR_EACH_ALIAS (this, ref)
    2679                 :             :         {
    2680                 :          24 :           cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    2681                 :          24 :           if (alias->get_availability () > AVAIL_INTERPOSABLE)
    2682                 :           0 :             add_detected_attribute_1 (alias, attr, &changed);
    2683                 :             :         }
    2684                 :             :     }
    2685                 :      204811 :   return changed;
    2686                 :             : }
    2687                 :             : 
    2688                 :             : /* Worker to set noreturng flag.  */
    2689                 :             : static void
    2690                 :       29501 : set_noreturn_flag_1 (cgraph_node *node, bool noreturn_p, bool *changed)
    2691                 :             : {
    2692                 :       29501 :   if (noreturn_p && !TREE_THIS_VOLATILE (node->decl))
    2693                 :             :     {
    2694                 :       29501 :       TREE_THIS_VOLATILE (node->decl) = true;
    2695                 :       29501 :       *changed = true;
    2696                 :             :     }
    2697                 :             : 
    2698                 :             :   ipa_ref *ref;
    2699                 :       30193 :   FOR_EACH_ALIAS (node, ref)
    2700                 :             :     {
    2701                 :         692 :       cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    2702                 :         692 :       if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    2703                 :         692 :         set_noreturn_flag_1 (alias, noreturn_p, changed);
    2704                 :             :     }
    2705                 :             : 
    2706                 :       49559 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    2707                 :       20058 :     if (e->caller->thunk
    2708                 :       20058 :         && (!noreturn_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    2709                 :          22 :       set_noreturn_flag_1 (e->caller, noreturn_p, changed);
    2710                 :       29501 : }
    2711                 :             : 
    2712                 :             : /* Set TREE_THIS_VOLATILE on NODE's decl and on NODE's aliases if any.  */
    2713                 :             : 
    2714                 :             : bool
    2715                 :       28935 : cgraph_node::set_noreturn_flag (bool noreturn_p)
    2716                 :             : {
    2717                 :       28935 :   bool changed = false;
    2718                 :             : 
    2719                 :       28935 :   if (!noreturn_p || get_availability () > AVAIL_INTERPOSABLE)
    2720                 :       28783 :     set_noreturn_flag_1 (this, noreturn_p, &changed);
    2721                 :             :   else
    2722                 :             :     {
    2723                 :             :       ipa_ref *ref;
    2724                 :             : 
    2725                 :         164 :       FOR_EACH_ALIAS (this, ref)
    2726                 :             :         {
    2727                 :          12 :           cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
    2728                 :          12 :           if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
    2729                 :           4 :             set_noreturn_flag_1 (alias, noreturn_p, &changed);
    2730                 :             :         }
    2731                 :             :     }
    2732                 :       28935 :   return changed;
    2733                 :             : }
    2734                 :             : 
    2735                 :             : /* Worker to set_const_flag.  */
    2736                 :             : 
    2737                 :             : static void
    2738                 :      922294 : set_const_flag_1 (cgraph_node *node, bool set_const, bool looping,
    2739                 :             :                   bool *changed)
    2740                 :             : {
    2741                 :             :   /* Static constructors and destructors without a side effect can be
    2742                 :             :      optimized out.  */
    2743                 :      922294 :   if (set_const && !looping)
    2744                 :             :     {
    2745                 :      916450 :       if (DECL_STATIC_CONSTRUCTOR (node->decl))
    2746                 :             :         {
    2747                 :         183 :           DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
    2748                 :         183 :           *changed = true;
    2749                 :             :         }
    2750                 :      916450 :       if (DECL_STATIC_DESTRUCTOR (node->decl))
    2751                 :             :         {
    2752                 :           1 :           DECL_STATIC_DESTRUCTOR (node->decl) = 0;
    2753                 :           1 :           *changed = true;
    2754                 :             :         }
    2755                 :             :     }
    2756                 :      922294 :   if (!set_const)
    2757                 :             :     {
    2758                 :        1925 :       if (TREE_READONLY (node->decl))
    2759                 :             :         {
    2760                 :         162 :           TREE_READONLY (node->decl) = 0;
    2761                 :         162 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    2762                 :         162 :           *changed = true;
    2763                 :             :         }
    2764                 :             :     }
    2765                 :             :   else
    2766                 :             :     {
    2767                 :             :       /* Consider function:
    2768                 :             : 
    2769                 :             :          bool a(int *p)
    2770                 :             :          {
    2771                 :             :            return *p==*p;
    2772                 :             :          }
    2773                 :             : 
    2774                 :             :          During early optimization we will turn this into:
    2775                 :             : 
    2776                 :             :          bool a(int *p)
    2777                 :             :          {
    2778                 :             :            return true;
    2779                 :             :          }
    2780                 :             : 
    2781                 :             :          Now if this function will be detected as CONST however when interposed
    2782                 :             :          it may end up being just pure.  We always must assume the worst
    2783                 :             :          scenario here.  */
    2784                 :      920369 :       if (TREE_READONLY (node->decl))
    2785                 :             :         {
    2786                 :        1047 :           if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
    2787                 :             :             {
    2788                 :         678 :               DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    2789                 :         678 :               *changed = true;
    2790                 :             :             }
    2791                 :             :         }
    2792                 :      919322 :       else if (node->binds_to_current_def_p ())
    2793                 :             :         {
    2794                 :      160425 :           TREE_READONLY (node->decl) = true;
    2795                 :      160425 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
    2796                 :      160425 :           DECL_PURE_P (node->decl) = false;
    2797                 :      160425 :           *changed = true;
    2798                 :             :         }
    2799                 :             :       else
    2800                 :             :         {
    2801                 :      758897 :           if (dump_file && (dump_flags & TDF_DETAILS))
    2802                 :           0 :             fprintf (dump_file, "Dropping state to PURE because function does "
    2803                 :             :                      "not bind to current def.\n");
    2804                 :      758897 :           if (!DECL_PURE_P (node->decl))
    2805                 :             :             {
    2806                 :      362997 :               DECL_PURE_P (node->decl) = true;
    2807                 :      362997 :               DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
    2808                 :      362997 :               *changed = true;
    2809                 :             :             }
    2810                 :      395900 :           else if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
    2811                 :             :             {
    2812                 :         150 :               DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    2813                 :         150 :               *changed = true;
    2814                 :             :             }
    2815                 :             :         }
    2816                 :             :     }
    2817                 :             : 
    2818                 :             :   ipa_ref *ref;
    2819                 :     1048323 :   FOR_EACH_ALIAS (node, ref)
    2820                 :             :     {
    2821                 :      126029 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    2822                 :      126029 :       if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
    2823                 :      125966 :         set_const_flag_1 (alias, set_const, looping, changed);
    2824                 :             :     }
    2825                 :      922414 :   for (struct cgraph_node *n = node->simd_clones; n != NULL;
    2826                 :         120 :        n = n->simdclone->next_clone)
    2827                 :         120 :     set_const_flag_1 (n, set_const, looping, changed);
    2828                 :     2328559 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    2829                 :     1406265 :     if (e->caller->thunk
    2830                 :     1406265 :         && (!set_const || e->caller->get_availability () > AVAIL_INTERPOSABLE))
    2831                 :             :       {
    2832                 :             :         /* Virtual thunks access virtual offset in the vtable, so they can
    2833                 :             :            only be pure, never const.  */
    2834                 :         432 :         if (set_const
    2835                 :         432 :             && (thunk_info::get (e->caller)->virtual_offset_p
    2836                 :         291 :                 || !node->binds_to_current_def_p (e->caller)))
    2837                 :         141 :           *changed |= e->caller->set_pure_flag (true, looping);
    2838                 :             :         else
    2839                 :         291 :           set_const_flag_1 (e->caller, set_const, looping, changed);
    2840                 :             :       }
    2841                 :      922294 : }
    2842                 :             : 
    2843                 :             : /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
    2844                 :             :    If SET_CONST if false, clear the flag.
    2845                 :             : 
    2846                 :             :    When setting the flag be careful about possible interposition and
    2847                 :             :    do not set the flag for functions that can be interposed and set pure
    2848                 :             :    flag for functions that can bind to other definition. 
    2849                 :             : 
    2850                 :             :    Return true if any change was done. */
    2851                 :             : 
    2852                 :             : bool
    2853                 :      821916 : cgraph_node::set_const_flag (bool set_const, bool looping)
    2854                 :             : {
    2855                 :      821916 :   bool changed = false;
    2856                 :      821916 :   if (!set_const || get_availability () > AVAIL_INTERPOSABLE)
    2857                 :      795699 :     set_const_flag_1 (this, set_const, looping, &changed);
    2858                 :             :   else
    2859                 :             :     {
    2860                 :             :       ipa_ref *ref;
    2861                 :             : 
    2862                 :       27114 :       FOR_EACH_ALIAS (this, ref)
    2863                 :             :         {
    2864                 :         897 :           cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    2865                 :         897 :           if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
    2866                 :         218 :             set_const_flag_1 (alias, set_const, looping, &changed);
    2867                 :             :         }
    2868                 :             :     }
    2869                 :      821916 :   return changed;
    2870                 :             : }
    2871                 :             : 
    2872                 :             : /* Info used by set_pure_flag_1.  */
    2873                 :             : 
    2874                 :             : struct set_pure_flag_info
    2875                 :             : {
    2876                 :             :   bool pure;
    2877                 :             :   bool looping;
    2878                 :             :   bool changed;
    2879                 :             : };
    2880                 :             : 
    2881                 :             : /* Worker to set_pure_flag.  */
    2882                 :             : 
    2883                 :             : static bool
    2884                 :      291173 : set_pure_flag_1 (cgraph_node *node, void *data)
    2885                 :             : {
    2886                 :      291173 :   struct set_pure_flag_info *info = (struct set_pure_flag_info *)data;
    2887                 :             :   /* Static constructors and destructors without a side effect can be
    2888                 :             :      optimized out.  */
    2889                 :      291173 :   if (info->pure && !info->looping)
    2890                 :             :     {
    2891                 :      228312 :       if (DECL_STATIC_CONSTRUCTOR (node->decl))
    2892                 :             :         {
    2893                 :           0 :           DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
    2894                 :           0 :           info->changed = true;
    2895                 :             :         }
    2896                 :      228312 :       if (DECL_STATIC_DESTRUCTOR (node->decl))
    2897                 :             :         {
    2898                 :           0 :           DECL_STATIC_DESTRUCTOR (node->decl) = 0;
    2899                 :           0 :           info->changed = true;
    2900                 :             :         }
    2901                 :             :     }
    2902                 :      291173 :   if (info->pure)
    2903                 :             :     {
    2904                 :      289248 :       if (!DECL_PURE_P (node->decl) && !TREE_READONLY (node->decl))
    2905                 :             :         {
    2906                 :      288608 :           DECL_PURE_P (node->decl) = true;
    2907                 :      288608 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = info->looping;
    2908                 :      288608 :           info->changed = true;
    2909                 :             :         }
    2910                 :         640 :       else if (DECL_LOOPING_CONST_OR_PURE_P (node->decl)
    2911                 :         640 :                && !info->looping)
    2912                 :             :         {
    2913                 :         369 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    2914                 :         369 :           info->changed = true;
    2915                 :             :         }
    2916                 :             :     }
    2917                 :             :   else
    2918                 :             :     {
    2919                 :        1925 :       if (DECL_PURE_P (node->decl))
    2920                 :             :         {
    2921                 :          77 :           DECL_PURE_P (node->decl) = false;
    2922                 :          77 :           DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
    2923                 :          77 :           info->changed = true;
    2924                 :             :         }
    2925                 :             :     }
    2926                 :      291173 :   return false;
    2927                 :             : }
    2928                 :             : 
    2929                 :             : /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
    2930                 :             :    if any to PURE.
    2931                 :             : 
    2932                 :             :    When setting the flag, be careful about possible interposition.
    2933                 :             :    Return true if any change was done. */
    2934                 :             : 
    2935                 :             : bool
    2936                 :      299678 : cgraph_node::set_pure_flag (bool pure, bool looping)
    2937                 :             : {
    2938                 :      299678 :   struct set_pure_flag_info info = {pure, looping, false};
    2939                 :      299678 :   call_for_symbol_thunks_and_aliases (set_pure_flag_1, &info, !pure, true);
    2940                 :      299678 :   for (struct cgraph_node *n = simd_clones; n != NULL;
    2941                 :           0 :        n = n->simdclone->next_clone)
    2942                 :           0 :     set_pure_flag_1 (n, &info);
    2943                 :      299678 :   return info.changed;
    2944                 :             : }
    2945                 :             : 
    2946                 :             : /* Return true when cgraph_node cannot return or throw and thus
    2947                 :             :    it is safe to ignore its side effects for IPA analysis.  */
    2948                 :             : 
    2949                 :             : bool
    2950                 :    12267504 : cgraph_node::cannot_return_p (void)
    2951                 :             : {
    2952                 :    12267504 :   int flags = flags_from_decl_or_type (decl);
    2953                 :    12267504 :   if (!opt_for_fn (decl, flag_exceptions))
    2954                 :     4341036 :     return (flags & ECF_NORETURN) != 0;
    2955                 :             :   else
    2956                 :     7926468 :     return ((flags & (ECF_NORETURN | ECF_NOTHROW))
    2957                 :     7926468 :              == (ECF_NORETURN | ECF_NOTHROW));
    2958                 :             : }
    2959                 :             : 
    2960                 :             : /* Return true when call of edge cannot lead to return from caller
    2961                 :             :    and thus it is safe to ignore its side effects for IPA analysis
    2962                 :             :    when computing side effects of the caller.
    2963                 :             :    FIXME: We could actually mark all edges that have no reaching
    2964                 :             :    patch to the exit block or throw to get better results.  */
    2965                 :             : bool
    2966                 :     2506460 : cgraph_edge::cannot_lead_to_return_p (void)
    2967                 :             : {
    2968                 :     2506460 :   if (caller->cannot_return_p ())
    2969                 :             :     return true;
    2970                 :     2419157 :   if (indirect_unknown_callee)
    2971                 :             :     {
    2972                 :       83463 :       int flags = indirect_info->ecf_flags;
    2973                 :       83463 :       if (!opt_for_fn (caller->decl, flag_exceptions))
    2974                 :       18237 :         return (flags & ECF_NORETURN) != 0;
    2975                 :             :       else
    2976                 :       65226 :         return ((flags & (ECF_NORETURN | ECF_NOTHROW))
    2977                 :       65226 :                  == (ECF_NORETURN | ECF_NOTHROW));
    2978                 :             :     }
    2979                 :             :   else
    2980                 :     2335694 :     return callee->cannot_return_p ();
    2981                 :             : }
    2982                 :             : 
    2983                 :             : /* Return true if the edge may be considered hot.  */
    2984                 :             : 
    2985                 :             : bool
    2986                 :     4938125 : cgraph_edge::maybe_hot_p (void)
    2987                 :             : {
    2988                 :     4938125 :   if (!maybe_hot_count_p (NULL, count.ipa ()))
    2989                 :             :     return false;
    2990                 :     4327113 :   if (caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
    2991                 :     4324500 :       || (callee
    2992                 :     3825841 :           && callee->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED))
    2993                 :             :     return false;
    2994                 :     4322099 :   if (caller->frequency > NODE_FREQUENCY_UNLIKELY_EXECUTED
    2995                 :     4322099 :       && (callee
    2996                 :     3823440 :           && callee->frequency <= NODE_FREQUENCY_EXECUTED_ONCE))
    2997                 :             :     return false;
    2998                 :     4188200 :   if (opt_for_fn (caller->decl, optimize_size))
    2999                 :             :     return false;
    3000                 :     4144393 :   if (caller->frequency == NODE_FREQUENCY_HOT)
    3001                 :             :     return true;
    3002                 :     4143853 :   if (!count.initialized_p ())
    3003                 :             :     return true;
    3004                 :     3114057 :   cgraph_node *where = caller->inlined_to ? caller->inlined_to : caller;
    3005                 :     3114057 :   if (!where->count.initialized_p ())
    3006                 :             :     return false;
    3007                 :     3114057 :   if (caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE)
    3008                 :             :     {
    3009                 :       74649 :       if (count * 2 < where->count * 3)
    3010                 :             :         return false;
    3011                 :             :     }
    3012                 :     3039408 :   else if (count * param_hot_bb_frequency_fraction < where->count)
    3013                 :             :     return false;
    3014                 :             :   return true;
    3015                 :             : }
    3016                 :             : 
    3017                 :             : /* Worker for cgraph_can_remove_if_no_direct_calls_p.  */
    3018                 :             : 
    3019                 :             : static bool
    3020                 :      699430 : nonremovable_p (cgraph_node *node, void *)
    3021                 :             : {
    3022                 :      699430 :   return !node->can_remove_if_no_direct_calls_and_refs_p ();
    3023                 :             : }
    3024                 :             : 
    3025                 :             : /* Return true if whole comdat group can be removed if there are no direct
    3026                 :             :    calls to THIS.  */
    3027                 :             : 
    3028                 :             : bool
    3029                 :      885969 : cgraph_node::can_remove_if_no_direct_calls_p (bool will_inline)
    3030                 :             : {
    3031                 :      885969 :   struct ipa_ref *ref;
    3032                 :             : 
    3033                 :             :   /* For local symbols or non-comdat group it is the same as 
    3034                 :             :      can_remove_if_no_direct_calls_p.  */
    3035                 :      885969 :   if (!externally_visible || !same_comdat_group)
    3036                 :             :     {
    3037                 :      701045 :       if (DECL_EXTERNAL (decl))
    3038                 :             :         return true;
    3039                 :      701045 :       if (address_taken)
    3040                 :             :         return false;
    3041                 :      672244 :       return !call_for_symbol_and_aliases (nonremovable_p, NULL, true);
    3042                 :             :     }
    3043                 :             : 
    3044                 :      184924 :   if (will_inline && address_taken)
    3045                 :             :     return false;
    3046                 :             : 
    3047                 :             :   /* Otherwise check if we can remove the symbol itself and then verify
    3048                 :             :      that only uses of the comdat groups are direct call to THIS
    3049                 :             :      or its aliases.   */
    3050                 :      184924 :   if (!can_remove_if_no_direct_calls_and_refs_p ())
    3051                 :             :     return false;
    3052                 :             : 
    3053                 :             :   /* Check that all refs come from within the comdat group.  */
    3054                 :      353112 :   for (int i = 0; iterate_referring (i, ref); i++)
    3055                 :      179915 :     if (ref->referring->get_comdat_group () != get_comdat_group ())
    3056                 :             :       return false;
    3057                 :             : 
    3058                 :      173197 :   struct cgraph_node *target = ultimate_alias_target ();
    3059                 :      173197 :   for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
    3060                 :      530433 :        next != this; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    3061                 :             :     {
    3062                 :      188975 :       if (!externally_visible)
    3063                 :           0 :         continue;
    3064                 :      188975 :       if (!next->alias
    3065                 :      188975 :           && !next->can_remove_if_no_direct_calls_and_refs_p ())
    3066                 :             :         return false;
    3067                 :             : 
    3068                 :             :       /* If we see different symbol than THIS, be sure to check calls.  */
    3069                 :      188975 :       if (next->ultimate_alias_target () != target)
    3070                 :       23671 :         for (cgraph_edge *e = next->callers; e; e = e->next_caller)
    3071                 :        3884 :           if (e->caller->get_comdat_group () != get_comdat_group ()
    3072                 :        3884 :               || will_inline)
    3073                 :             :             return false;
    3074                 :             : 
    3075                 :             :       /* If function is not being inlined, we care only about
    3076                 :             :          references outside of the comdat group.  */
    3077                 :      187552 :       if (!will_inline)
    3078                 :      189555 :         for (int i = 0; next->iterate_referring (i, ref); i++)
    3079                 :       10937 :           if (ref->referring->get_comdat_group () != get_comdat_group ())
    3080                 :             :             return false;
    3081                 :             :     }
    3082                 :             :   return true;
    3083                 :             : }
    3084                 :             : 
    3085                 :             : /* Return true when function cgraph_node can be expected to be removed
    3086                 :             :    from program when direct calls in this compilation unit are removed.
    3087                 :             : 
    3088                 :             :    As a special case COMDAT functions are
    3089                 :             :    cgraph_can_remove_if_no_direct_calls_p while the are not
    3090                 :             :    cgraph_only_called_directly_p (it is possible they are called from other
    3091                 :             :    unit)
    3092                 :             : 
    3093                 :             :    This function behaves as cgraph_only_called_directly_p because eliminating
    3094                 :             :    all uses of COMDAT function does not make it necessarily disappear from
    3095                 :             :    the program unless we are compiling whole program or we do LTO.  In this
    3096                 :             :    case we know we win since dynamic linking will not really discard the
    3097                 :             :    linkonce section.  */
    3098                 :             : 
    3099                 :             : bool
    3100                 :     2925097 : cgraph_node::will_be_removed_from_program_if_no_direct_calls_p
    3101                 :             :          (bool will_inline)
    3102                 :             : {
    3103                 :     2925097 :   gcc_assert (!inlined_to);
    3104                 :     2925097 :   if (DECL_EXTERNAL (decl))
    3105                 :             :     return true;
    3106                 :             : 
    3107                 :     2925097 :   if (!in_lto_p && !flag_whole_program)
    3108                 :             :     {
    3109                 :             :       /* If the symbol is in comdat group, we need to verify that whole comdat
    3110                 :             :          group becomes unreachable.  Technically we could skip references from
    3111                 :             :          within the group, too.  */
    3112                 :     2670917 :       if (!only_called_directly_p ())
    3113                 :             :         return false;
    3114                 :      617667 :       if (same_comdat_group && externally_visible)
    3115                 :             :         {
    3116                 :           0 :           struct cgraph_node *target = ultimate_alias_target ();
    3117                 :             : 
    3118                 :           0 :           if (will_inline && address_taken)
    3119                 :             :             return true;
    3120                 :           0 :           for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
    3121                 :           0 :                next != this;
    3122                 :           0 :                next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    3123                 :             :             {
    3124                 :           0 :               if (!externally_visible)
    3125                 :           0 :                 continue;
    3126                 :           0 :               if (!next->alias
    3127                 :           0 :                   && !next->only_called_directly_p ())
    3128                 :             :                 return false;
    3129                 :             : 
    3130                 :             :               /* If we see different symbol than THIS,
    3131                 :             :                  be sure to check calls.  */
    3132                 :           0 :               if (next->ultimate_alias_target () != target)
    3133                 :           0 :                 for (cgraph_edge *e = next->callers; e; e = e->next_caller)
    3134                 :           0 :                   if (e->caller->get_comdat_group () != get_comdat_group ()
    3135                 :           0 :                       || will_inline)
    3136                 :             :                     return false;
    3137                 :             :             }
    3138                 :             :         }
    3139                 :      617667 :       return true;
    3140                 :             :     }
    3141                 :             :   else
    3142                 :      254180 :     return can_remove_if_no_direct_calls_p (will_inline);
    3143                 :             : }
    3144                 :             : 
    3145                 :             : 
    3146                 :             : /* Worker for cgraph_only_called_directly_p.  */
    3147                 :             : 
    3148                 :             : static bool
    3149                 :    14806857 : cgraph_not_only_called_directly_p_1 (cgraph_node *node, void *)
    3150                 :             : {
    3151                 :    14806857 :   return !node->only_called_directly_or_aliased_p ();
    3152                 :             : }
    3153                 :             : 
    3154                 :             : /* Return true when function cgraph_node and all its aliases are only called
    3155                 :             :    directly.
    3156                 :             :    i.e. it is not externally visible, address was not taken and
    3157                 :             :    it is not used in any other non-standard way.  */
    3158                 :             : 
    3159                 :             : bool
    3160                 :    14741166 : cgraph_node::only_called_directly_p (void)
    3161                 :             : {
    3162                 :    14741166 :   gcc_assert (ultimate_alias_target () == this);
    3163                 :    14741166 :   return !call_for_symbol_and_aliases (cgraph_not_only_called_directly_p_1,
    3164                 :    14741166 :                                        NULL, true);
    3165                 :             : }
    3166                 :             : 
    3167                 :             : 
    3168                 :             : /* Collect all callers of NODE.  Worker for collect_callers_of_node.  */
    3169                 :             : 
    3170                 :             : static bool
    3171                 :      107055 : collect_callers_of_node_1 (cgraph_node *node, void *data)
    3172                 :             : {
    3173                 :      107055 :   vec<cgraph_edge *> *redirect_callers = (vec<cgraph_edge *> *)data;
    3174                 :      107055 :   cgraph_edge *cs;
    3175                 :      107055 :   enum availability avail;
    3176                 :      107055 :   node->ultimate_alias_target (&avail);
    3177                 :             : 
    3178                 :      107055 :   if (avail > AVAIL_INTERPOSABLE)
    3179                 :      357921 :     for (cs = node->callers; cs != NULL; cs = cs->next_caller)
    3180                 :      250866 :       if (!cs->indirect_inlining_edge
    3181                 :      250866 :           && !cs->caller->thunk)
    3182                 :      250813 :         redirect_callers->safe_push (cs);
    3183                 :      107055 :   return false;
    3184                 :             : }
    3185                 :             : 
    3186                 :             : /* Collect all callers of cgraph_node and its aliases that are known to lead to
    3187                 :             :    cgraph_node (i.e. are not overwritable).  */
    3188                 :             : 
    3189                 :             : auto_vec<cgraph_edge *>
    3190                 :      105231 : cgraph_node::collect_callers (void)
    3191                 :             : {
    3192                 :      105231 :   auto_vec<cgraph_edge *> redirect_callers;
    3193                 :      105231 :   call_for_symbol_thunks_and_aliases (collect_callers_of_node_1,
    3194                 :             :                                     &redirect_callers, false);
    3195                 :      105231 :   return redirect_callers;
    3196                 :             : }
    3197                 :             : 
    3198                 :             : 
    3199                 :             : /* Return TRUE if NODE2 a clone of NODE or is equivalent to it.  Return
    3200                 :             :    optimistically true if this cannot be determined.  */
    3201                 :             : 
    3202                 :             : static bool
    3203                 :       16791 : clone_of_p (cgraph_node *node, cgraph_node *node2)
    3204                 :             : {
    3205                 :       16791 :   node = node->ultimate_alias_target ();
    3206                 :       16791 :   node2 = node2->ultimate_alias_target ();
    3207                 :             : 
    3208                 :       16791 :   if (node2->clone_of == node
    3209                 :        1164 :       || node2->former_clone_of == node->decl)
    3210                 :             :     return true;
    3211                 :             : 
    3212                 :        1246 :   if (!node->thunk && !node->former_thunk_p ())
    3213                 :             :     {
    3214                 :             :       while (node2
    3215                 :        3245 :              && node->decl != node2->decl
    3216                 :        5409 :              && node->decl != node2->former_clone_of)
    3217                 :        2163 :         node2 = node2->clone_of;
    3218                 :        1082 :       return node2 != NULL;
    3219                 :             :     }
    3220                 :             : 
    3221                 :             :   /* There are no virtual clones of thunks so check former_clone_of or if we
    3222                 :             :      might have skipped thunks because this adjustments are no longer
    3223                 :             :      necessary.  */
    3224                 :          82 :   while (node->thunk || node->former_thunk_p ())
    3225                 :             :     {
    3226                 :          82 :       if (!thunk_info::get (node)->this_adjusting)
    3227                 :             :         return false;
    3228                 :             :       /* In case of instrumented expanded thunks, which can have multiple calls
    3229                 :             :          in them, we do not know how to continue and just have to be
    3230                 :             :          optimistic.  The same applies if all calls have already been inlined
    3231                 :             :          into the thunk.  */
    3232                 :          82 :       if (!node->callees || node->callees->next_callee)
    3233                 :             :         return true;
    3234                 :          78 :       node = node->callees->callee->ultimate_alias_target ();
    3235                 :             : 
    3236                 :          78 :       clone_info *info = clone_info::get (node2);
    3237                 :          78 :       if (!info || !info->param_adjustments
    3238                 :         156 :           || info->param_adjustments->first_param_intact_p ())
    3239                 :           0 :         return false;
    3240                 :          78 :       if (node2->former_clone_of == node->decl
    3241                 :          78 :           || node2->former_clone_of == node->former_clone_of)
    3242                 :             :         return true;
    3243                 :             : 
    3244                 :             :       cgraph_node *n2 = node2;
    3245                 :           0 :       while (n2 && node->decl != n2->decl)
    3246                 :           0 :         n2 = n2->clone_of;
    3247                 :           0 :       if (n2)
    3248                 :             :         return true;
    3249                 :             :     }
    3250                 :             : 
    3251                 :             :   return false;
    3252                 :             : }
    3253                 :             : 
    3254                 :             : /* Verify edge count and frequency.  */
    3255                 :             : 
    3256                 :             : bool
    3257                 :   172019546 : cgraph_edge::verify_count ()
    3258                 :             : {
    3259                 :   172019546 :   bool error_found = false;
    3260                 :   172019546 :   if (!count.verify ())
    3261                 :             :     {
    3262                 :           0 :       error ("caller edge count invalid");
    3263                 :           0 :       error_found = true;
    3264                 :             :     }
    3265                 :   172019546 :   return error_found;
    3266                 :             : }
    3267                 :             : 
    3268                 :             : /* Switch to THIS_CFUN if needed and print STMT to stderr.  */
    3269                 :             : static void
    3270                 :           0 : cgraph_debug_gimple_stmt (function *this_cfun, gimple *stmt)
    3271                 :             : {
    3272                 :           0 :   bool fndecl_was_null = false;
    3273                 :             :   /* debug_gimple_stmt needs correct cfun */
    3274                 :           0 :   if (cfun != this_cfun)
    3275                 :           0 :     set_cfun (this_cfun);
    3276                 :             :   /* ...and an actual current_function_decl */
    3277                 :           0 :   if (!current_function_decl)
    3278                 :             :     {
    3279                 :           0 :       current_function_decl = this_cfun->decl;
    3280                 :           0 :       fndecl_was_null = true;
    3281                 :             :     }
    3282                 :           0 :   debug_gimple_stmt (stmt);
    3283                 :           0 :   if (fndecl_was_null)
    3284                 :           0 :     current_function_decl = NULL;
    3285                 :           0 : }
    3286                 :             : 
    3287                 :             : /* Verify that call graph edge corresponds to DECL from the associated
    3288                 :             :    statement.  Return true if the verification should fail.  */
    3289                 :             : 
    3290                 :             : bool
    3291                 :    85071837 : cgraph_edge::verify_corresponds_to_fndecl (tree decl)
    3292                 :             : {
    3293                 :    85071837 :   cgraph_node *node;
    3294                 :             : 
    3295                 :    85071837 :   if (!decl || callee->inlined_to)
    3296                 :             :     return false;
    3297                 :    82252185 :   if (symtab->state == LTO_STREAMING)
    3298                 :             :     return false;
    3299                 :    82252185 :   node = cgraph_node::get (decl);
    3300                 :             : 
    3301                 :             :   /* We do not know if a node from a different partition is an alias or what it
    3302                 :             :      aliases and therefore cannot do the former_clone_of check reliably.  When
    3303                 :             :      body_removed is set, we have lost all information about what was alias or
    3304                 :             :      thunk of and also cannot proceed.  */
    3305                 :    82252185 :   if (!node
    3306                 :             :       || node->body_removed
    3307                 :    82170799 :       || node->in_other_partition
    3308                 :    81557566 :       || callee->icf_merged
    3309                 :    81470718 :       || callee->in_other_partition)
    3310                 :             :     return false;
    3311                 :             : 
    3312                 :    81470718 :   node = node->ultimate_alias_target ();
    3313                 :             : 
    3314                 :             :   /* Optimizers can redirect unreachable calls or calls triggering undefined
    3315                 :             :      behavior to __builtin_unreachable or __builtin_unreachable trap.  */
    3316                 :             : 
    3317                 :    81470718 :   if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
    3318                 :             :                                        BUILT_IN_UNREACHABLE_TRAP))
    3319                 :             :     return false;
    3320                 :             : 
    3321                 :    80498401 :   if (callee->former_clone_of != node->decl
    3322                 :    80497995 :       && (node != callee->ultimate_alias_target ())
    3323                 :    80515192 :       && !clone_of_p (node, callee))
    3324                 :             :     return true;
    3325                 :             :   else
    3326                 :    80498401 :     return false;
    3327                 :             : }
    3328                 :             : 
    3329                 :             : /* Disable warnings about missing quoting in GCC diagnostics for
    3330                 :             :    the verification errors.  Their format strings don't follow GCC
    3331                 :             :    diagnostic conventions and the calls are ultimately followed by
    3332                 :             :    one to internal_error.  */
    3333                 :             : #if __GNUC__ >= 10
    3334                 :             : #  pragma GCC diagnostic push
    3335                 :             : #  pragma GCC diagnostic ignored "-Wformat-diag"
    3336                 :             : #endif
    3337                 :             : 
    3338                 :             : /* Verify consistency of speculative call in NODE corresponding to STMT
    3339                 :             :    and LTO_STMT_UID.  If INDIRECT is set, assume that it is the indirect
    3340                 :             :    edge of call sequence. Return true if error is found.
    3341                 :             : 
    3342                 :             :    This function is called to every component of indirect call (direct edges,
    3343                 :             :    indirect edge and refs).  To save duplicated work, do full testing only
    3344                 :             :    in that case.  */
    3345                 :             : static bool
    3346                 :      157156 : verify_speculative_call (struct cgraph_node *node, gimple *stmt,
    3347                 :             :                          unsigned int lto_stmt_uid,
    3348                 :             :                          struct cgraph_edge *indirect)
    3349                 :             : {
    3350                 :      157156 :   if (indirect == NULL)
    3351                 :             :     {
    3352                 :      140150 :       for (indirect = node->indirect_calls; indirect;
    3353                 :       35364 :            indirect = indirect->next_callee)
    3354                 :      140150 :         if (indirect->call_stmt == stmt
    3355                 :      104920 :             && indirect->lto_stmt_uid == lto_stmt_uid)
    3356                 :             :           break;
    3357                 :      104786 :       if (!indirect)
    3358                 :             :         {
    3359                 :           0 :           error ("missing indirect call in speculative call sequence");
    3360                 :           0 :           return true;
    3361                 :             :         }
    3362                 :      104786 :       if (!indirect->speculative)
    3363                 :             :         {
    3364                 :           0 :           error ("indirect call in speculative call sequence has no "
    3365                 :             :                  "speculative flag");
    3366                 :           0 :           return true;
    3367                 :             :         }
    3368                 :             :       return false;
    3369                 :             :     }
    3370                 :             : 
    3371                 :             :   /* Maximal number of targets.  We probably will never want to have more than
    3372                 :             :      this.  */
    3373                 :             :   const unsigned int num = 256;
    3374                 :             :   cgraph_edge *direct_calls[num];
    3375                 :             :   ipa_ref *refs[num];
    3376                 :             : 
    3377                 :    13459090 :   for (unsigned int i = 0; i < num; i++)
    3378                 :             :     {
    3379                 :    13406720 :       direct_calls[i] = NULL;
    3380                 :    13406720 :       refs[i] = NULL;
    3381                 :             :     }
    3382                 :             : 
    3383                 :       52370 :   cgraph_edge *first_call = NULL;
    3384                 :       52370 :   cgraph_edge *prev_call = NULL;
    3385                 :             : 
    3386                 :      273294 :   for (cgraph_edge *direct = node->callees; direct;
    3387                 :      220924 :        direct = direct->next_callee)
    3388                 :      220924 :     if (direct->call_stmt == stmt && direct->lto_stmt_uid == lto_stmt_uid)
    3389                 :             :       {
    3390                 :       52393 :         if (!first_call)
    3391                 :       52370 :           first_call = direct;
    3392                 :       52393 :         if (prev_call && direct != prev_call->next_callee)
    3393                 :             :           {
    3394                 :           0 :             error ("speculative edges are not adjacent");
    3395                 :           0 :             return true;
    3396                 :             :           }
    3397                 :       52393 :         prev_call = direct;
    3398                 :       52393 :         if (!direct->speculative)
    3399                 :             :           {
    3400                 :           0 :             error ("direct call to %s in speculative call sequence has no "
    3401                 :           0 :                    "speculative flag", direct->callee->dump_name ());
    3402                 :           0 :             return true;
    3403                 :             :           }
    3404                 :       52393 :         if (direct->speculative_id >= num)
    3405                 :             :           {
    3406                 :           0 :             error ("direct call to %s in speculative call sequence has "
    3407                 :             :                    "speculative_id %i out of range",
    3408                 :           0 :                    direct->callee->dump_name (), direct->speculative_id);
    3409                 :           0 :             return true;
    3410                 :             :           }
    3411                 :       52393 :         if (direct_calls[direct->speculative_id])
    3412                 :             :           {
    3413                 :           0 :             error ("duplicate direct call to %s in speculative call sequence "
    3414                 :             :                    "with speculative_id %i",
    3415                 :           0 :                    direct->callee->dump_name (), direct->speculative_id);
    3416                 :           0 :             return true;
    3417                 :             :           }
    3418                 :       52393 :         direct_calls[direct->speculative_id] = direct;
    3419                 :             :       }
    3420                 :             : 
    3421                 :       52370 :   if (first_call->call_stmt
    3422                 :       52370 :       && first_call != node->get_edge (first_call->call_stmt))
    3423                 :             :     {
    3424                 :           0 :       error ("call stmt hash does not point to first direct edge of "
    3425                 :             :              "speculative call sequence");
    3426                 :           0 :       return true;
    3427                 :             :     }
    3428                 :             : 
    3429                 :             :   ipa_ref *ref;
    3430                 :      154711 :   for (int i = 0; node->iterate_reference (i, ref); i++)
    3431                 :      102341 :     if (ref->speculative
    3432                 :       76121 :         && ref->stmt == stmt && ref->lto_stmt_uid == lto_stmt_uid)
    3433                 :             :       {
    3434                 :       52393 :         if (ref->speculative_id >= num)
    3435                 :             :           {
    3436                 :           0 :             error ("direct call to %s in speculative call sequence has "
    3437                 :             :                    "speculative_id %i out of range",
    3438                 :           0 :                    ref->referred->dump_name (), ref->speculative_id);
    3439                 :           0 :             return true;
    3440                 :             :           }
    3441                 :       52393 :         if (refs[ref->speculative_id])
    3442                 :             :           {
    3443                 :           0 :             error ("duplicate reference %s in speculative call sequence "
    3444                 :             :                    "with speculative_id %i",
    3445                 :           0 :                    ref->referred->dump_name (), ref->speculative_id);
    3446                 :           0 :             return true;
    3447                 :             :           }
    3448                 :       52393 :         refs[ref->speculative_id] = ref;
    3449                 :             :       }
    3450                 :             : 
    3451                 :             :   int num_targets = 0;
    3452                 :    13459090 :   for (unsigned int i = 0 ; i < num ; i++)
    3453                 :             :     {
    3454                 :    13406720 :       if (refs[i] && !direct_calls[i])
    3455                 :             :         {
    3456                 :           0 :           error ("missing direct call for speculation %i", i);
    3457                 :           0 :           return true;
    3458                 :             :         }
    3459                 :    13406720 :       if (!refs[i] && direct_calls[i])
    3460                 :             :         {
    3461                 :           0 :           error ("missing ref for speculation %i", i);
    3462                 :           0 :           return true;
    3463                 :             :         }
    3464                 :    13406720 :       if (refs[i] != NULL)
    3465                 :       52393 :         num_targets++;
    3466                 :             :     }
    3467                 :             : 
    3468                 :       52370 :   if (num_targets != indirect->num_speculative_call_targets_p ())
    3469                 :             :     {
    3470                 :           0 :       error ("number of speculative targets %i mismatched with "
    3471                 :             :              "num_speculative_call_targets %i",
    3472                 :             :              num_targets,
    3473                 :             :              indirect->num_speculative_call_targets_p ());
    3474                 :           0 :       return true;
    3475                 :             :     }
    3476                 :             :   return false;
    3477                 :             : }
    3478                 :             : 
    3479                 :             : /* Verify cgraph nodes of given cgraph node.  */
    3480                 :             : DEBUG_FUNCTION void
    3481                 :    47020456 : cgraph_node::verify_node (void)
    3482                 :             : {
    3483                 :    47020456 :   cgraph_edge *e;
    3484                 :    47020456 :   function *this_cfun = DECL_STRUCT_FUNCTION (decl);
    3485                 :    47020456 :   basic_block this_block;
    3486                 :    47020456 :   gimple_stmt_iterator gsi;
    3487                 :    47020456 :   bool error_found = false;
    3488                 :    47020456 :   int i;
    3489                 :    47020456 :   ipa_ref *ref = NULL;
    3490                 :             : 
    3491                 :    47020456 :   if (seen_error ())
    3492                 :    47020456 :     return;
    3493                 :             : 
    3494                 :    47020456 :   timevar_push (TV_CGRAPH_VERIFY);
    3495                 :    47020456 :   error_found |= verify_base ();
    3496                 :   138829566 :   for (e = callees; e; e = e->next_callee)
    3497                 :    91809110 :     if (e->aux)
    3498                 :             :       {
    3499                 :           0 :         error ("aux field set for edge %s->%s",
    3500                 :           0 :                identifier_to_locale (e->caller->name ()),
    3501                 :           0 :                identifier_to_locale (e->callee->name ()));
    3502                 :           0 :         error_found = true;
    3503                 :             :       }
    3504                 :    47020456 :   if (!count.verify ())
    3505                 :             :     {
    3506                 :           0 :       error ("cgraph count invalid");
    3507                 :           0 :       error_found = true;
    3508                 :             :     }
    3509                 :    47020456 :   if (inlined_to && same_comdat_group)
    3510                 :             :     {
    3511                 :           0 :       error ("inline clone in same comdat group list");
    3512                 :           0 :       error_found = true;
    3513                 :             :     }
    3514                 :    47020456 :   if (inlined_to && !count.compatible_p (inlined_to->count))
    3515                 :             :     {
    3516                 :           0 :       error ("inline clone count is not compatible");
    3517                 :           0 :       count.debug ();
    3518                 :           0 :       inlined_to->count.debug ();
    3519                 :           0 :       error_found = true;
    3520                 :             :     }
    3521                 :    47020456 :   if (tp_first_run < 0)
    3522                 :             :     {
    3523                 :           0 :       error ("tp_first_run must be non-negative");
    3524                 :           0 :       error_found = true;
    3525                 :             :     }
    3526                 :    47020456 :   if (!definition && !in_other_partition && local)
    3527                 :             :     {
    3528                 :           0 :       error ("local symbols must be defined");
    3529                 :           0 :       error_found = true;
    3530                 :             :     }
    3531                 :    47020456 :   if (inlined_to && externally_visible)
    3532                 :             :     {
    3533                 :           0 :       error ("externally visible inline clone");
    3534                 :           0 :       error_found = true;
    3535                 :             :     }
    3536                 :    47020456 :   if (inlined_to && address_taken)
    3537                 :             :     {
    3538                 :           0 :       error ("inline clone with address taken");
    3539                 :           0 :       error_found = true;
    3540                 :             :     }
    3541                 :    47020456 :   if (inlined_to && force_output)
    3542                 :             :     {
    3543                 :           0 :       error ("inline clone is forced to output");
    3544                 :           0 :       error_found = true;
    3545                 :             :     }
    3546                 :    47020456 :   if (symtab->state != LTO_STREAMING)
    3547                 :             :     {
    3548                 :    46914529 :       if (calls_comdat_local && !same_comdat_group)
    3549                 :             :         {
    3550                 :           0 :           error ("calls_comdat_local is set outside of a comdat group");
    3551                 :           0 :           error_found = true;
    3552                 :             :         }
    3553                 :    46914529 :       if (!inlined_to && calls_comdat_local != check_calls_comdat_local_p ())
    3554                 :             :         {
    3555                 :           0 :           error ("invalid calls_comdat_local flag");
    3556                 :           0 :           error_found = true;
    3557                 :             :         }
    3558                 :             :     }
    3559                 :    47020456 :   if (DECL_IS_MALLOC (decl)
    3560                 :    47020456 :       && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
    3561                 :             :     {
    3562                 :           0 :       error ("malloc attribute should be used for a function that "
    3563                 :             :              "returns a pointer");
    3564                 :           0 :       error_found = true;
    3565                 :             :     }
    3566                 :    47020456 :   if (definition
    3567                 :    47020456 :       && externally_visible
    3568                 :             :       /* For aliases in lto1 free_lang_data doesn't guarantee preservation
    3569                 :             :          of opt_for_fn (decl, flag_semantic_interposition).  See PR105399.  */
    3570                 :    17197675 :       && (!alias || !in_lto_p)
    3571                 :    47020456 :       && semantic_interposition
    3572                 :    17194976 :          != opt_for_fn (decl, flag_semantic_interposition))
    3573                 :             :     {
    3574                 :           0 :       error ("semantic interposition mismatch");
    3575                 :           0 :       error_found = true;
    3576                 :             :     }
    3577                 :    49268443 :   for (e = indirect_calls; e; e = e->next_callee)
    3578                 :             :     {
    3579                 :     2247987 :       if (e->aux)
    3580                 :             :         {
    3581                 :           0 :           error ("aux field set for indirect edge from %s",
    3582                 :           0 :                  identifier_to_locale (e->caller->name ()));
    3583                 :           0 :           error_found = true;
    3584                 :             :         }
    3585                 :     2247987 :       if (!e->count.compatible_p (count))
    3586                 :             :         {
    3587                 :           0 :           error ("edge count is not compatible with function count");
    3588                 :           0 :           e->count.debug ();
    3589                 :           0 :           count.debug ();
    3590                 :           0 :           error_found = true;
    3591                 :             :         }
    3592                 :     2247987 :       if (!e->indirect_unknown_callee
    3593                 :     2247987 :           || !e->indirect_info)
    3594                 :             :         {
    3595                 :           0 :           error ("An indirect edge from %s is not marked as indirect or has "
    3596                 :             :                  "associated indirect_info, the corresponding statement is: ",
    3597                 :           0 :                  identifier_to_locale (e->caller->name ()));
    3598                 :           0 :           cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    3599                 :           0 :           error_found = true;
    3600                 :             :         }
    3601                 :     2247987 :       if (e->call_stmt && e->lto_stmt_uid)
    3602                 :             :         {
    3603                 :           0 :           error ("edge has both call_stmt and lto_stmt_uid set");
    3604                 :           0 :           error_found = true;
    3605                 :             :         }
    3606                 :             :     }
    3607                 :    47020456 :   bool check_comdat = comdat_local_p ();
    3608                 :   124982905 :   for (e = callers; e; e = e->next_caller)
    3609                 :             :     {
    3610                 :    77962449 :       if (e->verify_count ())
    3611                 :           0 :         error_found = true;
    3612                 :    77962449 :       if (check_comdat
    3613                 :    77962449 :           && !in_same_comdat_group_p (e->caller))
    3614                 :             :         {
    3615                 :           0 :           error ("comdat-local function called by %s outside its comdat",
    3616                 :             :                  identifier_to_locale (e->caller->name ()));
    3617                 :           0 :           error_found = true;
    3618                 :             :         }
    3619                 :    77962449 :       if (!e->inline_failed)
    3620                 :             :         {
    3621                 :     6338384 :           if (inlined_to
    3622                 :     6338384 :               != (e->caller->inlined_to
    3623                 :     6338384 :                   ? e->caller->inlined_to : e->caller))
    3624                 :             :             {
    3625                 :           0 :               error ("inlined_to pointer is wrong");
    3626                 :           0 :               error_found = true;
    3627                 :             :             }
    3628                 :     6338384 :           if (callers->next_caller)
    3629                 :             :             {
    3630                 :           0 :               error ("multiple inline callers");
    3631                 :           0 :               error_found = true;
    3632                 :             :             }
    3633                 :             :         }
    3634                 :             :       else
    3635                 :    71624065 :         if (inlined_to)
    3636                 :             :           {
    3637                 :           0 :             error ("inlined_to pointer set for noninline callers");
    3638                 :           0 :             error_found = true;
    3639                 :             :           }
    3640                 :             :     }
    3641                 :   138829566 :   for (e = callees; e; e = e->next_callee)
    3642                 :             :     {
    3643                 :    91809110 :       if (e->verify_count ())
    3644                 :           0 :         error_found = true;
    3645                 :    91809110 :       if (!e->count.compatible_p (count))
    3646                 :             :         {
    3647                 :           0 :           error ("edge count is not compatible with function count");
    3648                 :           0 :           e->count.debug ();
    3649                 :           0 :           count.debug ();
    3650                 :           0 :           error_found = true;
    3651                 :             :         }
    3652                 :    91809110 :       if (gimple_has_body_p (e->caller->decl)
    3653                 :    86603433 :           && !e->caller->inlined_to
    3654                 :    80134440 :           && !e->speculative
    3655                 :             :           /* Optimized out calls are redirected to __builtin_unreachable.  */
    3656                 :    80116502 :           && (e->count.nonzero_p ()
    3657                 :    45091062 :               || ! e->callee->decl
    3658                 :    45091062 :               || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
    3659                 :             :                                      BUILT_IN_UNREACHABLE_TRAP))
    3660                 :             :           && count
    3661                 :    79640088 :               == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
    3662                 :   171441187 :           && (!e->count.ipa_p ()
    3663                 :    36935652 :               && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
    3664                 :             :         {
    3665                 :           0 :           error ("caller edge count does not match BB count");
    3666                 :           0 :           fprintf (stderr, "edge count: ");
    3667                 :           0 :           e->count.dump (stderr);
    3668                 :           0 :           fprintf (stderr, "\n bb count: ");
    3669                 :           0 :           gimple_bb (e->call_stmt)->count.dump (stderr);
    3670                 :           0 :           fprintf (stderr, "\n");
    3671                 :           0 :           error_found = true;
    3672                 :             :         }
    3673                 :    91809110 :       if (e->call_stmt && e->lto_stmt_uid)
    3674                 :             :         {
    3675                 :           0 :           error ("edge has both call_stmt and lto_stmt_uid set");
    3676                 :           0 :           error_found = true;
    3677                 :             :         }
    3678                 :    91809110 :       if (e->speculative
    3679                 :    91809110 :           && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
    3680                 :             :                                       NULL))
    3681                 :             :         error_found = true;
    3682                 :             :     }
    3683                 :    49268443 :   for (e = indirect_calls; e; e = e->next_callee)
    3684                 :             :     {
    3685                 :     2247987 :       if (e->verify_count ())
    3686                 :           0 :         error_found = true;
    3687                 :     2247987 :       if (gimple_has_body_p (e->caller->decl)
    3688                 :     2200931 :           && !e->caller->inlined_to
    3689                 :     1990080 :           && !e->speculative
    3690                 :     1972148 :           && e->count.ipa_p ()
    3691                 :             :           && count
    3692                 :      731092 :               == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
    3693                 :     2979077 :           && (!e->count.ipa_p ()
    3694                 :           0 :               && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
    3695                 :             :         {
    3696                 :           0 :           error ("indirect call count does not match BB count");
    3697                 :           0 :           fprintf (stderr, "edge count: ");
    3698                 :           0 :           e->count.dump (stderr);
    3699                 :           0 :           fprintf (stderr, "\n bb count: ");
    3700                 :           0 :           gimple_bb (e->call_stmt)->count.dump (stderr);
    3701                 :           0 :           fprintf (stderr, "\n");
    3702                 :           0 :           error_found = true;
    3703                 :             :         }
    3704                 :     2247987 :       if (e->speculative
    3705                 :     2247987 :           && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
    3706                 :             :                                       e))
    3707                 :             :         error_found = true;
    3708                 :             :     }
    3709                 :   110056665 :   for (i = 0; iterate_reference (i, ref); i++)
    3710                 :             :     {
    3711                 :    63036209 :       if (ref->stmt && ref->lto_stmt_uid)
    3712                 :             :         {
    3713                 :           0 :           error ("reference has both stmt and lto_stmt_uid set");
    3714                 :           0 :           error_found = true;
    3715                 :             :         }
    3716                 :    63036209 :       if (ref->speculative
    3717                 :    63036209 :           && verify_speculative_call (this, ref->stmt,
    3718                 :             :                                       ref->lto_stmt_uid, NULL))
    3719                 :             :         error_found = true;
    3720                 :             :     }
    3721                 :             : 
    3722                 :    47020456 :   if (!callers && inlined_to)
    3723                 :             :     {
    3724                 :           0 :       error ("inlined_to pointer is set but no predecessors found");
    3725                 :           0 :       error_found = true;
    3726                 :             :     }
    3727                 :    47020456 :   if (inlined_to == this)
    3728                 :             :     {
    3729                 :           0 :       error ("inlined_to pointer refers to itself");
    3730                 :           0 :       error_found = true;
    3731                 :             :     }
    3732                 :             : 
    3733                 :    47020456 :   if (clone_of)
    3734                 :             :     {
    3735                 :     4474157 :       cgraph_node *first_clone = clone_of->clones;
    3736                 :     4474157 :       if (first_clone != this)
    3737                 :             :         {
    3738                 :     2232862 :           if (prev_sibling_clone->clone_of != clone_of)
    3739                 :             :             {
    3740                 :           0 :               error ("cgraph_node has wrong clone_of");
    3741                 :           0 :               error_found = true;
    3742                 :             :             }
    3743                 :             :         }
    3744                 :             :     }
    3745                 :    47020456 :   if (clones)
    3746                 :             :     {
    3747                 :             :       cgraph_node *n;
    3748                 :     6591355 :       for (n = clones; n; n = n->next_sibling_clone)
    3749                 :     5310589 :         if (n->clone_of != this)
    3750                 :             :           break;
    3751                 :     1280766 :       if (n)
    3752                 :             :         {
    3753                 :           0 :           error ("cgraph_node has wrong clone list");
    3754                 :           0 :           error_found = true;
    3755                 :             :         }
    3756                 :             :     }
    3757                 :    47020456 :   if ((prev_sibling_clone || next_sibling_clone) && !clone_of)
    3758                 :             :     {
    3759                 :           0 :        error ("cgraph_node is in clone list but it is not clone");
    3760                 :           0 :        error_found = true;
    3761                 :             :     }
    3762                 :    47020456 :   if (!prev_sibling_clone && clone_of && clone_of->clones != this)
    3763                 :             :     {
    3764                 :           0 :       error ("cgraph_node has wrong prev_clone pointer");
    3765                 :           0 :       error_found = true;
    3766                 :             :     }
    3767                 :    47020456 :   if (prev_sibling_clone && prev_sibling_clone->next_sibling_clone != this)
    3768                 :             :     {
    3769                 :           0 :       error ("double linked list of clones corrupted");
    3770                 :           0 :       error_found = true;
    3771                 :             :     }
    3772                 :             : 
    3773                 :    47020456 :   if (analyzed && alias)
    3774                 :             :     {
    3775                 :     1334875 :       bool ref_found = false;
    3776                 :     1334875 :       int i;
    3777                 :     1334875 :       ipa_ref *ref = NULL;
    3778                 :             : 
    3779                 :     1334875 :       if (callees)
    3780                 :             :         {
    3781                 :           0 :           error ("Alias has call edges");
    3782                 :           0 :           error_found = true;
    3783                 :             :         }
    3784                 :     2669750 :       for (i = 0; iterate_reference (i, ref); i++)
    3785                 :     1334875 :         if (ref->use != IPA_REF_ALIAS)
    3786                 :             :           {
    3787                 :           0 :             error ("Alias has non-alias reference");
    3788                 :           0 :             error_found = true;
    3789                 :             :           }
    3790                 :     1334875 :         else if (ref_found)
    3791                 :             :           {
    3792                 :           0 :             error ("Alias has more than one alias reference");
    3793                 :           0 :             error_found = true;
    3794                 :             :           }
    3795                 :             :         else
    3796                 :             :           ref_found = true;
    3797                 :     1334875 :       if (!ref_found)
    3798                 :             :         {
    3799                 :           0 :           error ("Analyzed alias has no reference");
    3800                 :           0 :           error_found = true;
    3801                 :             :         }
    3802                 :             :     }
    3803                 :             : 
    3804                 :    47020456 :   if (analyzed && thunk)
    3805                 :             :     {
    3806                 :       26797 :       if (!callees)
    3807                 :             :         {
    3808                 :           0 :           error ("No edge out of thunk node");
    3809                 :           0 :           error_found = true;
    3810                 :             :         }
    3811                 :       26797 :       else if (callees->next_callee)
    3812                 :             :         {
    3813                 :           0 :           error ("More than one edge out of thunk node");
    3814                 :           0 :           error_found = true;
    3815                 :             :         }
    3816                 :       26797 :       if (gimple_has_body_p (decl) && !inlined_to)
    3817                 :             :         {
    3818                 :           0 :           error ("Thunk is not supposed to have body");
    3819                 :           0 :           error_found = true;
    3820                 :             :         }
    3821                 :             :     }
    3822                 :    30633010 :   else if (analyzed && gimple_has_body_p (decl)
    3823                 :    26395775 :            && !TREE_ASM_WRITTEN (decl)
    3824                 :    26395775 :            && (!DECL_EXTERNAL (decl) || inlined_to)
    3825                 :    72544266 :            && !flag_wpa)
    3826                 :             :     {
    3827                 :    25524785 :       if ((this_cfun->curr_properties & PROP_assumptions_done) != 0)
    3828                 :             :         ;
    3829                 :    25524684 :       else if (this_cfun->cfg)
    3830                 :             :         {
    3831                 :    25524684 :           hash_set<gimple *> stmts;
    3832                 :             : 
    3833                 :             :           /* Reach the trees by walking over the CFG, and note the
    3834                 :             :              enclosing basic-blocks in the call edges.  */
    3835                 :   209987818 :           FOR_EACH_BB_FN (this_block, this_cfun)
    3836                 :             :             {
    3837                 :   184463134 :               for (gsi = gsi_start_phis (this_block);
    3838                 :   224436861 :                    !gsi_end_p (gsi); gsi_next (&gsi))
    3839                 :    39973727 :                 stmts.add (gsi_stmt (gsi));
    3840                 :   368926268 :               for (gsi = gsi_start_bb (this_block);
    3841                 :  1074983321 :                    !gsi_end_p (gsi);
    3842                 :   890520187 :                    gsi_next (&gsi))
    3843                 :             :                 {
    3844                 :   890520187 :                   gimple *stmt = gsi_stmt (gsi);
    3845                 :   890520187 :                   stmts.add (stmt);
    3846                 :   890520187 :                   if (is_gimple_call (stmt))
    3847                 :             :                     {
    3848                 :    90410876 :                       cgraph_edge *e = get_edge (stmt);
    3849                 :    90410876 :                       tree decl = gimple_call_fndecl (stmt);
    3850                 :    90410876 :                       if (e)
    3851                 :             :                         {
    3852                 :    87199668 :                           if (e->aux)
    3853                 :             :                             {
    3854                 :           0 :                               error ("shared call_stmt:");
    3855                 :           0 :                               cgraph_debug_gimple_stmt (this_cfun, stmt);
    3856                 :           0 :                               error_found = true;
    3857                 :             :                             }
    3858                 :    87199668 :                           if (!e->indirect_unknown_callee)
    3859                 :             :                             {
    3860                 :    85071837 :                               if (e->verify_corresponds_to_fndecl (decl))
    3861                 :             :                                 {
    3862                 :           0 :                                   error ("edge points to wrong declaration:");
    3863                 :           0 :                                   debug_tree (e->callee->decl);
    3864                 :           0 :                                   fprintf (stderr," Instead of:");
    3865                 :           0 :                                   debug_tree (decl);
    3866                 :           0 :                                   error_found = true;
    3867                 :             :                                 }
    3868                 :             :                             }
    3869                 :     2127831 :                           else if (decl)
    3870                 :             :                             {
    3871                 :           0 :                               error ("an indirect edge with unknown callee "
    3872                 :             :                                      "corresponding to a call_stmt with "
    3873                 :             :                                      "a known declaration:");
    3874                 :           0 :                               error_found = true;
    3875                 :           0 :                               cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    3876                 :             :                             }
    3877                 :    87199668 :                           e->aux = (void *)1;
    3878                 :             :                         }
    3879                 :     3211208 :                       else if (decl)
    3880                 :             :                         {
    3881                 :           0 :                           error ("missing callgraph edge for call stmt:");
    3882                 :           0 :                           cgraph_debug_gimple_stmt (this_cfun, stmt);
    3883                 :           0 :                           error_found = true;
    3884                 :             :                         }
    3885                 :             :                     }
    3886                 :             :                 }
    3887                 :             :               }
    3888                 :    92347617 :             for (i = 0; iterate_reference (i, ref); i++)
    3889                 :    58741305 :               if (ref->stmt && !stmts.contains (ref->stmt))
    3890                 :             :                 {
    3891                 :           0 :                   error ("reference to dead statement");
    3892                 :           0 :                   cgraph_debug_gimple_stmt (this_cfun, ref->stmt);
    3893                 :           0 :                   error_found = true;
    3894                 :             :                 }
    3895                 :    25524684 :         }
    3896                 :             :       else
    3897                 :             :         /* No CFG available?!  */
    3898                 :           0 :         gcc_unreachable ();
    3899                 :             : 
    3900                 :   110596629 :       for (e = callees; e; e = e->next_callee)
    3901                 :             :         {
    3902                 :    85071844 :           if (!e->aux && !e->speculative)
    3903                 :             :             {
    3904                 :           0 :               error ("edge %s->%s has no corresponding call_stmt",
    3905                 :           0 :                      identifier_to_locale (e->caller->name ()),
    3906                 :           0 :                      identifier_to_locale (e->callee->name ()));
    3907                 :           0 :               cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    3908                 :           0 :               error_found = true;
    3909                 :             :             }
    3910                 :    85071844 :           e->aux = 0;
    3911                 :             :         }
    3912                 :    27701823 :       for (e = indirect_calls; e; e = e->next_callee)
    3913                 :             :         {
    3914                 :     2177038 :           if (!e->aux && !e->speculative)
    3915                 :             :             {
    3916                 :           0 :               error ("an indirect edge from %s has no corresponding call_stmt",
    3917                 :           0 :                      identifier_to_locale (e->caller->name ()));
    3918                 :           0 :               cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
    3919                 :           0 :               error_found = true;
    3920                 :             :             }
    3921                 :     2177038 :           e->aux = 0;
    3922                 :             :         }
    3923                 :             :     }
    3924                 :             : 
    3925                 :    47020456 :   if (nested_function_info *info = nested_function_info::get (this))
    3926                 :             :     {
    3927                 :           0 :       if (info->nested != NULL)
    3928                 :             :         {
    3929                 :           0 :           for (cgraph_node *n = info->nested; n != NULL;
    3930                 :           0 :                n = next_nested_function (n))
    3931                 :             :             {
    3932                 :           0 :               nested_function_info *ninfo = nested_function_info::get (n);
    3933                 :           0 :               if (ninfo->origin == NULL)
    3934                 :             :                 {
    3935                 :           0 :                   error ("missing origin for a node in a nested list");
    3936                 :           0 :                   error_found = true;
    3937                 :             :                 }
    3938                 :           0 :               else if (ninfo->origin != this)
    3939                 :             :                 {
    3940                 :           0 :                   error ("origin points to a different parent");
    3941                 :           0 :                   error_found = true;
    3942                 :           0 :                   break;
    3943                 :             :                 }
    3944                 :             :             }
    3945                 :             :         }
    3946                 :           0 :       if (info->next_nested != NULL && info->origin == NULL)
    3947                 :             :         {
    3948                 :           0 :           error ("missing origin for a node in a nested list");
    3949                 :           0 :           error_found = true;
    3950                 :             :         }
    3951                 :             :     }
    3952                 :             : 
    3953                 :    47020456 :   if (error_found)
    3954                 :             :     {
    3955                 :           0 :       dump (stderr);
    3956                 :           0 :       internal_error ("verify_cgraph_node failed");
    3957                 :             :     }
    3958                 :    47020456 :   timevar_pop (TV_CGRAPH_VERIFY);
    3959                 :             : }
    3960                 :             : 
    3961                 :             : /* Verify whole cgraph structure.  */
    3962                 :             : DEBUG_FUNCTION void
    3963                 :        1052 : cgraph_node::verify_cgraph_nodes (void)
    3964                 :             : {
    3965                 :        1052 :   cgraph_node *node;
    3966                 :             : 
    3967                 :        1052 :   if (seen_error ())
    3968                 :             :     return;
    3969                 :             : 
    3970                 :       12528 :   FOR_EACH_FUNCTION (node)
    3971                 :        5242 :     node->verify ();
    3972                 :             : }
    3973                 :             : 
    3974                 :             : #if __GNUC__ >= 10
    3975                 :             : #  pragma GCC diagnostic pop
    3976                 :             : #endif
    3977                 :             : 
    3978                 :             : /* Walk the alias chain to return the function cgraph_node is alias of.
    3979                 :             :    Walk through thunks, too.
    3980                 :             :    When AVAILABILITY is non-NULL, get minimal availability in the chain.
    3981                 :             :    When REF is non-NULL, assume that reference happens in symbol REF
    3982                 :             :    when determining the availability.  */
    3983                 :             : 
    3984                 :             : cgraph_node *
    3985                 :   116680920 : cgraph_node::function_symbol (enum availability *availability,
    3986                 :             :                               struct symtab_node *ref)
    3987                 :             : {
    3988                 :   116680920 :   cgraph_node *node = ultimate_alias_target (availability, ref);
    3989                 :             : 
    3990                 :   233367635 :   while (node->thunk)
    3991                 :             :     {
    3992                 :        5795 :       enum availability a;
    3993                 :             : 
    3994                 :        5795 :       ref = node;
    3995                 :        5795 :       node = node->callees->callee;
    3996                 :       10452 :       node = node->ultimate_alias_target (availability ? &a : NULL, ref);
    3997                 :        5795 :       if (availability && a < *availability)
    3998                 :         210 :         *availability = a;
    3999                 :             :     }
    4000                 :   116680920 :   return node;
    4001                 :             : }
    4002                 :             : 
    4003                 :             : /* Walk the alias chain to return the function cgraph_node is alias of.
    4004                 :             :    Walk through non virtual thunks, too.  Thus we return either a function
    4005                 :             :    or a virtual thunk node.
    4006                 :             :    When AVAILABILITY is non-NULL, get minimal availability in the chain. 
    4007                 :             :    When REF is non-NULL, assume that reference happens in symbol REF
    4008                 :             :    when determining the availability.  */
    4009                 :             : 
    4010                 :             : cgraph_node *
    4011                 :    29017889 : cgraph_node::function_or_virtual_thunk_symbol
    4012                 :             :                                 (enum availability *availability,
    4013                 :             :                                  struct symtab_node *ref)
    4014                 :             : {
    4015                 :    29017889 :   cgraph_node *node = ultimate_alias_target (availability, ref);
    4016                 :             : 
    4017                 :    58037458 :   while (node->thunk && !thunk_info::get (node)->virtual_offset_p)
    4018                 :             :     {
    4019                 :        1680 :       enum availability a;
    4020                 :             : 
    4021                 :        1680 :       ref = node;
    4022                 :        1680 :       node = node->callees->callee;
    4023                 :        1680 :       node = node->ultimate_alias_target (availability ? &a : NULL, ref);
    4024                 :        1680 :       if (availability && a < *availability)
    4025                 :         858 :         *availability = a;
    4026                 :             :     }
    4027                 :    29017889 :   return node;
    4028                 :             : }
    4029                 :             : 
    4030                 :             : /* When doing LTO, read cgraph_node's body from disk if it is not already
    4031                 :             :    present.  Also perform any necessary clone materializations.  */
    4032                 :             : 
    4033                 :             : bool
    4034                 :     5112421 : cgraph_node::get_untransformed_body ()
    4035                 :             : {
    4036                 :     5112421 :   lto_file_decl_data *file_data;
    4037                 :     5112421 :   const char *data, *name;
    4038                 :     5112421 :   size_t len;
    4039                 :     5112421 :   tree decl = this->decl;
    4040                 :             : 
    4041                 :             :   /* See if there is clone to be materialized.
    4042                 :             :      (inline clones does not need materialization, but we can be seeing
    4043                 :             :       an inline clone of real clone).  */
    4044                 :     5112421 :   cgraph_node *p = this;
    4045                 :     7140473 :   for (cgraph_node *c = clone_of; c; c = c->clone_of)
    4046                 :             :     {
    4047                 :     2028052 :       if (c->decl != decl)
    4048                 :      103259 :         p->materialize_clone ();
    4049                 :     2028052 :       p = c;
    4050                 :             :     }
    4051                 :             : 
    4052                 :             :   /* Check if body is already there.  Either we have gimple body or
    4053                 :             :      the function is thunk and in that case we set DECL_ARGUMENTS.  */
    4054                 :     5112421 :   if (DECL_ARGUMENTS (decl) || gimple_has_body_p (decl))
    4055                 :     5030566 :     return false;
    4056                 :             : 
    4057                 :      163710 :   gcc_assert (in_lto_p && !DECL_RESULT (decl));
    4058                 :             : 
    4059                 :       81855 :   timevar_push (TV_IPA_LTO_GIMPLE_IN);
    4060                 :             : 
    4061                 :       81855 :   file_data = lto_file_data;
    4062                 :       81855 :   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
    4063                 :             : 
    4064                 :             :   /* We may have renamed the declaration, e.g., a static function.  */
    4065                 :       81855 :   name = lto_get_decl_name_mapping (file_data, name);
    4066                 :       81855 :   struct lto_in_decl_state *decl_state
    4067                 :       81855 :          = lto_get_function_in_decl_state (file_data, decl);
    4068                 :             : 
    4069                 :       81855 :   cgraph_node *origin = this;
    4070                 :      163843 :   while (origin->clone_of)
    4071                 :             :     origin = origin->clone_of;
    4072                 :             : 
    4073                 :       81855 :   int stream_order = origin->order - file_data->order_base;
    4074                 :      163710 :   data = lto_get_section_data (file_data, LTO_section_function_body,
    4075                 :             :                                name, stream_order, &len,
    4076                 :       81855 :                                decl_state->compressed);
    4077                 :       81855 :   if (!data)
    4078                 :           0 :     fatal_error (input_location, "%s: section %s.%d is missing",
    4079                 :             :                  file_data->file_name, name, stream_order);
    4080                 :             : 
    4081                 :       81855 :   gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
    4082                 :             : 
    4083                 :       81855 :   if (!quiet_flag)
    4084                 :           0 :     fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
    4085                 :       81855 :   lto_input_function_body (file_data, this, data);
    4086                 :       81855 :   lto_stats.num_function_bodies++;
    4087                 :       81855 :   lto_free_section_data (file_data, LTO_section_function_body, name,
    4088                 :       81855 :                          data, len, decl_state->compressed);
    4089                 :       81855 :   lto_free_function_in_decl_state_for_node (this);
    4090                 :             :   /* Keep lto file data so ipa-inline-analysis knows about cross module
    4091                 :             :      inlining.  */
    4092                 :             : 
    4093                 :       81855 :   timevar_pop (TV_IPA_LTO_GIMPLE_IN);
    4094                 :             : 
    4095                 :       81855 :   return true;
    4096                 :             : }
    4097                 :             : 
    4098                 :             : /* Prepare function body.  When doing LTO, read cgraph_node's body from disk 
    4099                 :             :    if it is not already present.  When some IPA transformations are scheduled,
    4100                 :             :    apply them.  */
    4101                 :             : 
    4102                 :             : bool
    4103                 :       28423 : cgraph_node::get_body (void)
    4104                 :             : {
    4105                 :       28423 :   bool updated;
    4106                 :             : 
    4107                 :       28423 :   updated = get_untransformed_body ();
    4108                 :             : 
    4109                 :             :   /* Getting transformed body makes no sense for inline clones;
    4110                 :             :      we should never use this on real clones because they are materialized
    4111                 :             :      early.
    4112                 :             :      TODO: Materializing clones here will likely lead to smaller LTRANS
    4113                 :             :      footprint. */
    4114                 :       28423 :   gcc_assert (!inlined_to && !clone_of);
    4115                 :       28423 :   if (ipa_transforms_to_apply.exists ())
    4116                 :             :     {
    4117                 :       12024 :       opt_pass *saved_current_pass = current_pass;
    4118                 :       12024 :       FILE *saved_dump_file = dump_file;
    4119                 :       12024 :       const char *saved_dump_file_name = dump_file_name;
    4120                 :       12024 :       dump_flags_t saved_dump_flags = dump_flags;
    4121                 :       12024 :       dump_file_name = NULL;
    4122                 :       12024 :       set_dump_file (NULL);
    4123                 :             : 
    4124                 :       12024 :       push_cfun (DECL_STRUCT_FUNCTION (decl));
    4125                 :             : 
    4126                 :       12024 :       update_ssa (TODO_update_ssa_only_virtuals);
    4127                 :       12024 :       execute_all_ipa_transforms (true);
    4128                 :       12024 :       cgraph_edge::rebuild_edges ();
    4129                 :       12024 :       free_dominance_info (CDI_DOMINATORS);
    4130                 :       12024 :       free_dominance_info (CDI_POST_DOMINATORS);
    4131                 :       12024 :       pop_cfun ();
    4132                 :       12024 :       updated = true;
    4133                 :             : 
    4134                 :       12024 :       current_pass = saved_current_pass;
    4135                 :       12024 :       set_dump_file (saved_dump_file);
    4136                 :       12024 :       dump_file_name = saved_dump_file_name;
    4137                 :       12024 :       dump_flags = saved_dump_flags;
    4138                 :             :     }
    4139                 :       28423 :   return updated;
    4140                 :             : }
    4141                 :             : 
    4142                 :             : /* Return the DECL_STRUCT_FUNCTION of the function.  */
    4143                 :             : 
    4144                 :             : struct function *
    4145                 :      194651 : cgraph_node::get_fun () const
    4146                 :             : {
    4147                 :      194651 :   const cgraph_node *node = this;
    4148                 :      194651 :   struct function *fun = DECL_STRUCT_FUNCTION (node->decl);
    4149                 :             : 
    4150                 :      194651 :   while (!fun && node->clone_of)
    4151                 :             :     {
    4152                 :           0 :       node = node->clone_of;
    4153                 :           0 :       fun = DECL_STRUCT_FUNCTION (node->decl);
    4154                 :             :     }
    4155                 :             : 
    4156                 :      194651 :   return fun;
    4157                 :             : }
    4158                 :             : 
    4159                 :             : /* Reset all state within cgraph.cc so that we can rerun the compiler
    4160                 :             :    within the same process.  For use by toplev::finalize.  */
    4161                 :             : 
    4162                 :             : void
    4163                 :      252251 : cgraph_cc_finalize (void)
    4164                 :             : {
    4165                 :      252251 :   nested_function_info::release ();
    4166                 :      252251 :   thunk_info::release ();
    4167                 :      252251 :   clone_info::release ();
    4168                 :      252251 :   symtab = NULL;
    4169                 :             : 
    4170                 :      252251 :   x_cgraph_nodes_queue = NULL;
    4171                 :             : 
    4172                 :      252251 :   cgraph_fnver_htab = NULL;
    4173                 :      252251 :   version_info_node = NULL;
    4174                 :      252251 : }
    4175                 :             : 
    4176                 :             : /* A worker for call_for_symbol_and_aliases.  */
    4177                 :             : 
    4178                 :             : bool
    4179                 :      667070 : cgraph_node::call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
    4180                 :             :                                                               void *),
    4181                 :             :                                             void *data,
    4182                 :             :                                             bool include_overwritable)
    4183                 :             : {
    4184                 :      667070 :   ipa_ref *ref;
    4185                 :     1294510 :   FOR_EACH_ALIAS (this, ref)
    4186                 :             :     {
    4187                 :      722082 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    4188                 :      722082 :       if (include_overwritable
    4189                 :      722082 :           || alias->get_availability () > AVAIL_INTERPOSABLE)
    4190                 :      722082 :         if (alias->call_for_symbol_and_aliases (callback, data,
    4191                 :             :                                                 include_overwritable))
    4192                 :             :           return true;
    4193                 :             :     }
    4194                 :             :   return false;
    4195                 :             : }
    4196                 :             : 
    4197                 :             : /* Return true if NODE has thunk.  */
    4198                 :             : 
    4199                 :             : bool
    4200                 :       39467 : cgraph_node::has_thunk_p (cgraph_node *node, void *)
    4201                 :             : {
    4202                 :       73957 :   for (cgraph_edge *e = node->callers; e; e = e->next_caller)
    4203                 :       34490 :     if (e->caller->thunk)
    4204                 :             :       return true;
    4205                 :             :   return false;
    4206                 :             : }
    4207                 :             : 
    4208                 :             : /* Expected frequency of executions within the function.  */
    4209                 :             : 
    4210                 :             : sreal
    4211                 :   179233189 : cgraph_edge::sreal_frequency ()
    4212                 :             : {
    4213                 :   179233189 :   return count.to_sreal_scale (caller->inlined_to
    4214                 :   179233189 :                                ? caller->inlined_to->count
    4215                 :   179233189 :                                : caller->count);
    4216                 :             : }
    4217                 :             : 
    4218                 :             : 
    4219                 :             : /* During LTO stream in this can be used to check whether call can possibly
    4220                 :             :    be internal to the current translation unit.  */
    4221                 :             : 
    4222                 :             : bool
    4223                 :      474261 : cgraph_edge::possibly_call_in_translation_unit_p (void)
    4224                 :             : {
    4225                 :      474261 :   gcc_checking_assert (in_lto_p && caller->prevailing_p ());
    4226                 :             : 
    4227                 :             :   /* While incremental linking we may end up getting function body later.  */
    4228                 :      474261 :   if (flag_incremental_link == INCREMENTAL_LINK_LTO)
    4229                 :             :     return true;
    4230                 :             : 
    4231                 :             :   /* We may be smarter here and avoid streaming in indirect calls we can't
    4232                 :             :      track, but that would require arranging streaming the indirect call
    4233                 :             :      summary first.  */
    4234                 :      474037 :   if (!callee)
    4235                 :             :     return true;
    4236                 :             : 
    4237                 :             :   /* If callee is local to the original translation unit, it will be
    4238                 :             :      defined.  */
    4239                 :      471487 :   if (!TREE_PUBLIC (callee->decl) && !DECL_EXTERNAL (callee->decl))
    4240                 :             :     return true;
    4241                 :             : 
    4242                 :             :   /* Otherwise we need to lookup prevailing symbol (symbol table is not merged,
    4243                 :             :      yet) and see if it is a definition.  In fact we may also resolve aliases,
    4244                 :             :      but that is probably not too important.  */
    4245                 :      475987 :   symtab_node *node = callee;
    4246                 :      475987 :   for (int n = 10; node->previous_sharing_asm_name && n ; n--)
    4247                 :       10072 :     node = node->previous_sharing_asm_name;
    4248                 :      465915 :   if (node->previous_sharing_asm_name)
    4249                 :         234 :     node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (callee->decl));
    4250                 :      465915 :   gcc_assert (TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl));
    4251                 :      465915 :   return node->get_availability () >= AVAIL_INTERPOSABLE;
    4252                 :             : }
    4253                 :             : 
    4254                 :             : /* Return num_speculative_targets of this edge.  */
    4255                 :             : 
    4256                 :             : int
    4257                 :       78637 : cgraph_edge::num_speculative_call_targets_p (void)
    4258                 :             : {
    4259                 :       78637 :   return indirect_info ? indirect_info->num_speculative_call_targets : 0;
    4260                 :             : }
    4261                 :             : 
    4262                 :             : /* Check if function calls comdat local.  This is used to recompute
    4263                 :             :    calls_comdat_local flag after function transformations.  */
    4264                 :             : bool
    4265                 :    44501194 : cgraph_node::check_calls_comdat_local_p ()
    4266                 :             : {
    4267                 :   138520095 :   for (cgraph_edge *e = callees; e; e = e->next_callee)
    4268                 :     2821235 :     if (e->inline_failed
    4269                 :   100672064 :         ? e->callee->comdat_local_p ()
    4270                 :     2821235 :         : e->callee->check_calls_comdat_local_p ())
    4271                 :       46833 :       return true;
    4272                 :             :   return false;
    4273                 :             : }
    4274                 :             : 
    4275                 :             : /* Return true if this node represents a former, i.e. an expanded, thunk.  */
    4276                 :             : 
    4277                 :             : bool
    4278                 :     2967546 : cgraph_node::former_thunk_p (void)
    4279                 :             : {
    4280                 :     2967546 :   if (thunk)
    4281                 :             :     return false;
    4282                 :     2967546 :   thunk_info *i = thunk_info::get (this);
    4283                 :     2967546 :   if (!i)
    4284                 :             :     return false;
    4285                 :          96 :   gcc_checking_assert (i->fixed_offset || i->virtual_offset_p
    4286                 :             :                        || i->indirect_offset);
    4287                 :             :   return true;
    4288                 :             : }
    4289                 :             : 
    4290                 :             : /* A stashed copy of "symtab" for use by selftest::symbol_table_test.
    4291                 :             :    This needs to be a global so that it can be a GC root, and thus
    4292                 :             :    prevent the stashed copy from being garbage-collected if the GC runs
    4293                 :             :    during a symbol_table_test.  */
    4294                 :             : 
    4295                 :             : symbol_table *saved_symtab;
    4296                 :             : 
    4297                 :             : #if CHECKING_P
    4298                 :             : 
    4299                 :             : namespace selftest {
    4300                 :             : 
    4301                 :             : /* class selftest::symbol_table_test.  */
    4302                 :             : 
    4303                 :             : /* Constructor.  Store the old value of symtab, and create a new one.  */
    4304                 :             : 
    4305                 :          64 : symbol_table_test::symbol_table_test ()
    4306                 :             : {
    4307                 :          64 :   gcc_assert (saved_symtab == NULL);
    4308                 :          64 :   saved_symtab = symtab;
    4309                 :          64 :   symtab = new (ggc_alloc<symbol_table> ()) symbol_table ();
    4310                 :          64 : }
    4311                 :             : 
    4312                 :             : /* Destructor.  Restore the old value of symtab.  */
    4313                 :             : 
    4314                 :          64 : symbol_table_test::~symbol_table_test ()
    4315                 :             : {
    4316                 :          64 :   gcc_assert (saved_symtab != NULL);
    4317                 :          64 :   symtab = saved_symtab;
    4318                 :          64 :   saved_symtab = NULL;
    4319                 :          64 : }
    4320                 :             : 
    4321                 :             : /* Verify that symbol_table_test works.  */
    4322                 :             : 
    4323                 :             : static void
    4324                 :           4 : test_symbol_table_test ()
    4325                 :             : {
    4326                 :             :   /* Simulate running two selftests involving symbol tables.  */
    4327                 :          12 :   for (int i = 0; i < 2; i++)
    4328                 :             :     {
    4329                 :           8 :       symbol_table_test stt;
    4330                 :           8 :       tree test_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
    4331                 :             :                                    get_identifier ("test_decl"),
    4332                 :             :                                    build_function_type_list (void_type_node,
    4333                 :             :                                                              NULL_TREE));
    4334                 :           8 :       cgraph_node *node = cgraph_node::get_create (test_decl);
    4335                 :           8 :       gcc_assert (node);
    4336                 :             : 
    4337                 :             :       /* Verify that the node has order 0 on both iterations,
    4338                 :             :          and thus that nodes have predictable dump names in selftests.  */
    4339                 :           8 :       ASSERT_EQ (node->order, 0);
    4340                 :           8 :       ASSERT_STREQ (node->dump_name (), "test_decl/0");
    4341                 :           8 :     }
    4342                 :           4 : }
    4343                 :             : 
    4344                 :             : /* Run all of the selftests within this file.  */
    4345                 :             : 
    4346                 :             : void
    4347                 :           4 : cgraph_cc_tests ()
    4348                 :             : {
    4349                 :           4 :   test_symbol_table_test ();
    4350                 :           4 : }
    4351                 :             : 
    4352                 :             : } // namespace selftest
    4353                 :             : 
    4354                 :             : #endif /* CHECKING_P */
    4355                 :             : 
    4356                 :             : #include "gt-cgraph.h"
        

Generated by: LCOV version 2.1-beta

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