LCOV - code coverage report
Current view: top level - gcc - cgraphunit.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.6 % 1195 1107
Test Date: 2025-03-15 13:07:15 Functions: 100.0 % 41 41
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Driver of optimization process
       2                 :             :    Copyright (C) 2003-2025 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 module implements main driver of compilation process.
      22                 :             : 
      23                 :             :    The main scope of this file is to act as an interface in between
      24                 :             :    tree based frontends and the backend.
      25                 :             : 
      26                 :             :    The front-end is supposed to use following functionality:
      27                 :             : 
      28                 :             :     - finalize_function
      29                 :             : 
      30                 :             :       This function is called once front-end has parsed whole body of function
      31                 :             :       and it is certain that the function body nor the declaration will change.
      32                 :             : 
      33                 :             :       (There is one exception needed for implementing GCC extern inline
      34                 :             :         function.)
      35                 :             : 
      36                 :             :     - varpool_finalize_decl
      37                 :             : 
      38                 :             :       This function has same behavior as the above but is used for static
      39                 :             :       variables.
      40                 :             : 
      41                 :             :     - add_asm_node
      42                 :             : 
      43                 :             :       Insert new toplevel ASM statement
      44                 :             : 
      45                 :             :     - finalize_compilation_unit
      46                 :             : 
      47                 :             :       This function is called once (source level) compilation unit is finalized
      48                 :             :       and it will no longer change.
      49                 :             : 
      50                 :             :       The symbol table is constructed starting from the trivially needed
      51                 :             :       symbols finalized by the frontend.  Functions are lowered into
      52                 :             :       GIMPLE representation and callgraph/reference lists are constructed.
      53                 :             :       Those are used to discover other necessary functions and variables.
      54                 :             : 
      55                 :             :       At the end the bodies of unreachable functions are removed.
      56                 :             : 
      57                 :             :       The function can be called multiple times when multiple source level
      58                 :             :       compilation units are combined.
      59                 :             : 
      60                 :             :     - compile
      61                 :             : 
      62                 :             :       This passes control to the back-end.  Optimizations are performed and
      63                 :             :       final assembler is generated.  This is done in the following way. Note
      64                 :             :       that with link time optimization the process is split into three
      65                 :             :       stages (compile time, linktime analysis and parallel linktime as
      66                 :             :       indicated bellow).
      67                 :             : 
      68                 :             :       Compile time:
      69                 :             : 
      70                 :             :         1) Inter-procedural optimization.
      71                 :             :            (ipa_passes)
      72                 :             : 
      73                 :             :            This part is further split into:
      74                 :             : 
      75                 :             :            a) early optimizations. These are local passes executed in
      76                 :             :               the topological order on the callgraph.
      77                 :             : 
      78                 :             :               The purpose of early optimizations is to optimize away simple
      79                 :             :               things that may otherwise confuse IP analysis. Very simple
      80                 :             :               propagation across the callgraph is done i.e. to discover
      81                 :             :               functions without side effects and simple inlining is performed.
      82                 :             : 
      83                 :             :            b) early small interprocedural passes.
      84                 :             : 
      85                 :             :               Those are interprocedural passes executed only at compilation
      86                 :             :               time.  These include, for example, transactional memory lowering,
      87                 :             :               unreachable code removal and other simple transformations.
      88                 :             : 
      89                 :             :            c) IP analysis stage.  All interprocedural passes do their
      90                 :             :               analysis.
      91                 :             : 
      92                 :             :               Interprocedural passes differ from small interprocedural
      93                 :             :               passes by their ability to operate across whole program
      94                 :             :               at linktime.  Their analysis stage is performed early to
      95                 :             :               both reduce linking times and linktime memory usage by
      96                 :             :               not having to represent whole program in memory.
      97                 :             : 
      98                 :             :            d) LTO streaming.  When doing LTO, everything important gets
      99                 :             :               streamed into the object file.
     100                 :             : 
     101                 :             :        Compile time and or linktime analysis stage (WPA):
     102                 :             : 
     103                 :             :               At linktime units gets streamed back and symbol table is
     104                 :             :               merged.  Function bodies are not streamed in and not
     105                 :             :               available.
     106                 :             :            e) IP propagation stage.  All IP passes execute their
     107                 :             :               IP propagation. This is done based on the earlier analysis
     108                 :             :               without having function bodies at hand.
     109                 :             :            f) Ltrans streaming.  When doing WHOPR LTO, the program
     110                 :             :               is partitioned and streamed into multiple object files.
     111                 :             : 
     112                 :             :        Compile time and/or parallel linktime stage (ltrans)
     113                 :             : 
     114                 :             :               Each of the object files is streamed back and compiled
     115                 :             :               separately.  Now the function bodies becomes available
     116                 :             :               again.
     117                 :             : 
     118                 :             :          2) Virtual clone materialization
     119                 :             :             (cgraph_materialize_clone)
     120                 :             : 
     121                 :             :             IP passes can produce copies of existing functions (such
     122                 :             :             as versioned clones or inline clones) without actually
     123                 :             :             manipulating their bodies by creating virtual clones in
     124                 :             :             the callgraph. At this time the virtual clones are
     125                 :             :             turned into real functions
     126                 :             :          3) IP transformation
     127                 :             : 
     128                 :             :             All IP passes transform function bodies based on earlier
     129                 :             :             decision of the IP propagation.
     130                 :             : 
     131                 :             :          4) late small IP passes
     132                 :             : 
     133                 :             :             Simple IP passes working within single program partition.
     134                 :             : 
     135                 :             :          5) Expansion
     136                 :             :             (expand_all_functions)
     137                 :             : 
     138                 :             :             At this stage functions that needs to be output into
     139                 :             :             assembler are identified and compiled in topological order
     140                 :             :          6) Output of variables and aliases
     141                 :             :             Now it is known what variable references was not optimized
     142                 :             :             out and thus all variables are output to the file.
     143                 :             : 
     144                 :             :             Note that with -fno-toplevel-reorder passes 5 and 6
     145                 :             :             are combined together in cgraph_output_in_order.
     146                 :             : 
     147                 :             :    Finally there are functions to manipulate the callgraph from
     148                 :             :    backend.
     149                 :             :     - cgraph_add_new_function is used to add backend produced
     150                 :             :       functions introduced after the unit is finalized.
     151                 :             :       The functions are enqueue for later processing and inserted
     152                 :             :       into callgraph with cgraph_process_new_functions.
     153                 :             : 
     154                 :             :     - cgraph_function_versioning
     155                 :             : 
     156                 :             :       produces a copy of function into new one (a version)
     157                 :             :       and apply simple transformations
     158                 :             : */
     159                 :             : 
     160                 :             : #include "config.h"
     161                 :             : #include "system.h"
     162                 :             : #include "coretypes.h"
     163                 :             : #include "backend.h"
     164                 :             : #include "target.h"
     165                 :             : #include "rtl.h"
     166                 :             : #include "tree.h"
     167                 :             : #include "gimple.h"
     168                 :             : #include "cfghooks.h"
     169                 :             : #include "regset.h"     /* FIXME: For reg_obstack.  */
     170                 :             : #include "alloc-pool.h"
     171                 :             : #include "tree-pass.h"
     172                 :             : #include "stringpool.h"
     173                 :             : #include "gimple-ssa.h"
     174                 :             : #include "cgraph.h"
     175                 :             : #include "coverage.h"
     176                 :             : #include "lto-streamer.h"
     177                 :             : #include "fold-const.h"
     178                 :             : #include "varasm.h"
     179                 :             : #include "stor-layout.h"
     180                 :             : #include "output.h"
     181                 :             : #include "cfgcleanup.h"
     182                 :             : #include "gimple-iterator.h"
     183                 :             : #include "gimple-fold.h"
     184                 :             : #include "gimplify.h"
     185                 :             : #include "gimplify-me.h"
     186                 :             : #include "tree-cfg.h"
     187                 :             : #include "tree-into-ssa.h"
     188                 :             : #include "tree-ssa.h"
     189                 :             : #include "langhooks.h"
     190                 :             : #include "toplev.h"
     191                 :             : #include "debug.h"
     192                 :             : #include "symbol-summary.h"
     193                 :             : #include "tree-vrp.h"
     194                 :             : #include "sreal.h"
     195                 :             : #include "ipa-cp.h"
     196                 :             : #include "ipa-prop.h"
     197                 :             : #include "gimple-pretty-print.h"
     198                 :             : #include "plugin.h"
     199                 :             : #include "ipa-fnsummary.h"
     200                 :             : #include "ipa-utils.h"
     201                 :             : #include "except.h"
     202                 :             : #include "cfgloop.h"
     203                 :             : #include "context.h"
     204                 :             : #include "pass_manager.h"
     205                 :             : #include "tree-nested.h"
     206                 :             : #include "dbgcnt.h"
     207                 :             : #include "lto-section-names.h"
     208                 :             : #include "stringpool.h"
     209                 :             : #include "attribs.h"
     210                 :             : #include "ipa-inline.h"
     211                 :             : #include "omp-offload.h"
     212                 :             : #include "symtab-thunks.h"
     213                 :             : 
     214                 :             : /* Queue of cgraph nodes scheduled to be added into cgraph.  This is a
     215                 :             :    secondary queue used during optimization to accommodate passes that
     216                 :             :    may generate new functions that need to be optimized and expanded.  */
     217                 :             : vec<cgraph_node *> cgraph_new_nodes;
     218                 :             : 
     219                 :             : static void expand_all_functions (void);
     220                 :             : static void mark_functions_to_output (void);
     221                 :             : static void handle_alias_pairs (void);
     222                 :             : 
     223                 :             : /* Return true if this symbol is a function from the C frontend specified
     224                 :             :    directly in RTL form (with "__RTL").  */
     225                 :             : 
     226                 :             : bool
     227                 :   195416536 : symtab_node::native_rtl_p () const
     228                 :             : {
     229                 :   195416536 :   if (TREE_CODE (decl) != FUNCTION_DECL)
     230                 :             :     return false;
     231                 :   173199023 :   if (!DECL_STRUCT_FUNCTION (decl))
     232                 :             :     return false;
     233                 :   171175768 :   return DECL_STRUCT_FUNCTION (decl)->curr_properties & PROP_rtl;
     234                 :             : }
     235                 :             : 
     236                 :             : /* Determine if symbol declaration is needed.  That is, visible to something
     237                 :             :    either outside this translation unit, something magic in the system
     238                 :             :    configury */
     239                 :             : bool
     240                 :   114086598 : symtab_node::needed_p (void)
     241                 :             : {
     242                 :             :   /* Double check that no one output the function into assembly file
     243                 :             :      early.  */
     244                 :   114086598 :   if (!native_rtl_p ())
     245                 :   114086581 :       gcc_checking_assert
     246                 :             :         (!DECL_ASSEMBLER_NAME_SET_P (decl)
     247                 :             :          || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)));
     248                 :             : 
     249                 :   114086598 :   if (!definition)
     250                 :             :     return false;
     251                 :             : 
     252                 :   103712474 :   if (DECL_EXTERNAL (decl))
     253                 :             :     return false;
     254                 :             : 
     255                 :             :   /* If the user told us it is used, then it must be so.  */
     256                 :    49231862 :   if (force_output)
     257                 :             :     return true;
     258                 :             : 
     259                 :             :   /* ABI forced symbols are needed when they are external.  */
     260                 :    48299866 :   if (forced_by_abi && TREE_PUBLIC (decl))
     261                 :             :     return true;
     262                 :             : 
     263                 :             :   /* Keep constructors, destructors and virtual functions.  */
     264                 :    48263623 :    if (TREE_CODE (decl) == FUNCTION_DECL
     265                 :    48263623 :        && (DECL_STATIC_CONSTRUCTOR (decl) || DECL_STATIC_DESTRUCTOR (decl)))
     266                 :             :     return true;
     267                 :             : 
     268                 :             :   /* Externally visible variables must be output.  The exception is
     269                 :             :      COMDAT variables that must be output only when they are needed.  */
     270                 :    48253840 :   if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
     271                 :     1877616 :     return true;
     272                 :             : 
     273                 :             :   return false;
     274                 :             : }
     275                 :             : 
     276                 :             : /* Head and terminator of the queue of nodes to be processed while building
     277                 :             :    callgraph.  */
     278                 :             : 
     279                 :             : static symtab_node symtab_terminator (SYMTAB_SYMBOL);
     280                 :             : static symtab_node *queued_nodes = &symtab_terminator;
     281                 :             : 
     282                 :             : /* Add NODE to queue starting at QUEUED_NODES.
     283                 :             :    The queue is linked via AUX pointers and terminated by pointer to 1.  */
     284                 :             : 
     285                 :             : static void
     286                 :    15999907 : enqueue_node (symtab_node *node)
     287                 :             : {
     288                 :    15999907 :   if (node->aux)
     289                 :             :     return;
     290                 :     6107628 :   gcc_checking_assert (queued_nodes);
     291                 :     6107628 :   node->aux = queued_nodes;
     292                 :     6107628 :   queued_nodes = node;
     293                 :             : }
     294                 :             : 
     295                 :             : /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
     296                 :             :    functions into callgraph in a way so they look like ordinary reachable
     297                 :             :    functions inserted into callgraph already at construction time.  */
     298                 :             : 
     299                 :             : void
     300                 :    19650331 : symbol_table::process_new_functions (void)
     301                 :             : {
     302                 :    19650331 :   tree fndecl;
     303                 :             : 
     304                 :    19650331 :   if (!cgraph_new_nodes.exists ())
     305                 :             :     return;
     306                 :             : 
     307                 :       18911 :   handle_alias_pairs ();
     308                 :             :   /*  Note that this queue may grow as its being processed, as the new
     309                 :             :       functions may generate new ones.  */
     310                 :       62734 :   for (unsigned i = 0; i < cgraph_new_nodes.length (); i++)
     311                 :             :     {
     312                 :       43823 :       cgraph_node *node = cgraph_new_nodes[i];
     313                 :       43823 :       fndecl = node->decl;
     314                 :       43823 :       bitmap_obstack_initialize (NULL);
     315                 :       43823 :       switch (state)
     316                 :             :         {
     317                 :       42773 :         case CONSTRUCTION:
     318                 :             :           /* At construction time we just need to finalize function and move
     319                 :             :              it into reachable functions list.  */
     320                 :             : 
     321                 :       42773 :           cgraph_node::finalize_function (fndecl, false);
     322                 :       42773 :           call_cgraph_insertion_hooks (node);
     323                 :       42773 :           enqueue_node (node);
     324                 :       42773 :           break;
     325                 :             : 
     326                 :         846 :         case IPA:
     327                 :         846 :         case IPA_SSA:
     328                 :         846 :         case IPA_SSA_AFTER_INLINING:
     329                 :             :           /* When IPA optimization already started, do all essential
     330                 :             :              transformations that has been already performed on the whole
     331                 :             :              cgraph but not on this function.  */
     332                 :             : 
     333                 :         846 :           gimple_register_cfg_hooks ();
     334                 :         846 :           if (!node->analyzed)
     335                 :         846 :             node->analyze ();
     336                 :         846 :           push_cfun (DECL_STRUCT_FUNCTION (fndecl));
     337                 :         846 :           if ((state == IPA_SSA || state == IPA_SSA_AFTER_INLINING)
     338                 :        1692 :               && !gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)))
     339                 :             :             {
     340                 :         846 :               bool summaried_computed = ipa_fn_summaries != NULL;
     341                 :         846 :               g->get_passes ()->execute_early_local_passes ();
     342                 :             :               /* Early passes compute inline parameters to do inlining
     343                 :             :                  and splitting.  This is redundant for functions added late.
     344                 :             :                  Just throw away whatever it did.  */
     345                 :         846 :               if (!summaried_computed)
     346                 :             :                 {
     347                 :         774 :                   ipa_free_fn_summary ();
     348                 :         774 :                   ipa_free_size_summary ();
     349                 :             :                 }
     350                 :             :             }
     351                 :           0 :           else if (ipa_fn_summaries != NULL)
     352                 :           0 :             compute_fn_summary (node, true);
     353                 :         846 :           free_dominance_info (CDI_POST_DOMINATORS);
     354                 :         846 :           free_dominance_info (CDI_DOMINATORS);
     355                 :         846 :           pop_cfun ();
     356                 :         846 :           call_cgraph_insertion_hooks (node);
     357                 :         846 :           break;
     358                 :             : 
     359                 :         204 :         case EXPANSION:
     360                 :             :           /* Functions created during expansion shall be compiled
     361                 :             :              directly.  */
     362                 :         204 :           node->process = 0;
     363                 :         204 :           call_cgraph_insertion_hooks (node);
     364                 :         204 :           node->expand ();
     365                 :         204 :           break;
     366                 :             : 
     367                 :           0 :         default:
     368                 :           0 :           gcc_unreachable ();
     369                 :       43823 :           break;
     370                 :             :         }
     371                 :       43823 :       bitmap_obstack_release (NULL);
     372                 :             :     }
     373                 :             : 
     374                 :       18911 :   cgraph_new_nodes.release ();
     375                 :             : }
     376                 :             : 
     377                 :             : /* As an GCC extension we allow redefinition of the function.  The
     378                 :             :    semantics when both copies of bodies differ is not well defined.
     379                 :             :    We replace the old body with new body so in unit at a time mode
     380                 :             :    we always use new body, while in normal mode we may end up with
     381                 :             :    old body inlined into some functions and new body expanded and
     382                 :             :    inlined in others.
     383                 :             : 
     384                 :             :    ??? It may make more sense to use one body for inlining and other
     385                 :             :    body for expanding the function but this is difficult to do.
     386                 :             : 
     387                 :             :    This is also used to cancel C++ mangling aliases, which can be for
     388                 :             :    functions or variables.  */
     389                 :             : 
     390                 :             : void
     391                 :       34838 : symtab_node::reset (bool preserve_comdat_group)
     392                 :             : {
     393                 :             :   /* Reset our data structures so we can analyze the function again.  */
     394                 :       34838 :   analyzed = false;
     395                 :       34838 :   definition = false;
     396                 :       34838 :   alias = false;
     397                 :       34838 :   transparent_alias = false;
     398                 :       34838 :   weakref = false;
     399                 :       34838 :   cpp_implicit_alias = false;
     400                 :             : 
     401                 :       34838 :   remove_all_references ();
     402                 :       34838 :   if (!preserve_comdat_group)
     403                 :       34371 :     remove_from_same_comdat_group ();
     404                 :             : 
     405                 :       34838 :   if (cgraph_node *cn = dyn_cast <cgraph_node *> (this))
     406                 :             :     {
     407                 :             :       /* If process is set, then we have already begun whole-unit analysis.
     408                 :             :          This is *not* testing for whether we've already emitted the function.
     409                 :             :          That case can be sort-of legitimately seen with real function
     410                 :             :          redefinition errors.  I would argue that the front end should never
     411                 :             :          present us with such a case, but don't enforce that for now.  */
     412                 :       34834 :       gcc_assert (!cn->process);
     413                 :             : 
     414                 :       34834 :       memset (&cn->rtl, 0, sizeof (cn->rtl));
     415                 :       34834 :       cn->inlined_to = NULL;
     416                 :       34834 :       cn->remove_callees ();
     417                 :             :     }
     418                 :       34838 : }
     419                 :             : 
     420                 :             : /* Return true when there are references to the node.  INCLUDE_SELF is
     421                 :             :    true if a self reference counts as a reference.  */
     422                 :             : 
     423                 :             : bool
     424                 :   111516532 : symtab_node::referred_to_p (bool include_self)
     425                 :             : {
     426                 :   111516532 :   ipa_ref *ref = NULL;
     427                 :             : 
     428                 :             :   /* See if there are any references at all.  */
     429                 :   111516532 :   if (iterate_referring (0, ref))
     430                 :             :     return true;
     431                 :             :   /* For functions check also calls.  */
     432                 :   109234578 :   cgraph_node *cn = dyn_cast <cgraph_node *> (this);
     433                 :    90529632 :   if (cn && cn->callers)
     434                 :             :     {
     435                 :     2770533 :       if (include_self)
     436                 :             :         return true;
     437                 :     1799871 :       for (cgraph_edge *e = cn->callers; e; e = e->next_caller)
     438                 :     1799605 :         if (e->caller != this)
     439                 :             :           return true;
     440                 :             :     }
     441                 :             :   return false;
     442                 :             : }
     443                 :             : 
     444                 :             : /* DECL has been parsed.  Take it, queue it, compile it at the whim of the
     445                 :             :    logic in effect.  If NO_COLLECT is true, then our caller cannot stand to have
     446                 :             :    the garbage collector run at the moment.  We would need to either create
     447                 :             :    a new GC context, or just not compile right now.  */
     448                 :             : 
     449                 :             : void
     450                 :    77117885 : cgraph_node::finalize_function (tree decl, bool no_collect)
     451                 :             : {
     452                 :    77117885 :   cgraph_node *node = cgraph_node::get_create (decl);
     453                 :             : 
     454                 :    77117885 :   if (node->definition)
     455                 :             :     {
     456                 :             :       /* Nested functions should only be defined once.  */
     457                 :         141 :       gcc_assert (!DECL_CONTEXT (decl)
     458                 :             :                   || TREE_CODE (DECL_CONTEXT (decl)) != FUNCTION_DECL);
     459                 :         141 :       node->reset ();
     460                 :         141 :       node->redefined_extern_inline = true;
     461                 :             :     }
     462                 :             : 
     463                 :             :   /* Set definition first before calling notice_global_symbol so that
     464                 :             :      it is available to notice_global_symbol.  */
     465                 :    77117885 :   node->definition = true;
     466                 :    77117885 :   notice_global_symbol (decl);
     467                 :    77117885 :   node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL;
     468                 :    77117885 :   node->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
     469                 :    77117885 :   if (!flag_toplevel_reorder)
     470                 :     2457831 :     node->no_reorder = true;
     471                 :             : 
     472                 :             :   /* With -fkeep-inline-functions we are keeping all inline functions except
     473                 :             :      for extern inline ones.  */
     474                 :    77117885 :   if (flag_keep_inline_functions
     475                 :       25296 :       && DECL_DECLARED_INLINE_P (decl)
     476                 :       25165 :       && !DECL_EXTERNAL (decl)
     477                 :    77119607 :       && !DECL_DISREGARD_INLINE_LIMITS (decl))
     478                 :        1563 :     node->force_output = 1;
     479                 :             : 
     480                 :             :   /* __RTL functions were already output as soon as they were parsed (due
     481                 :             :      to the large amount of global state in the backend).
     482                 :             :      Mark such functions as "force_output" to reflect the fact that they
     483                 :             :      will be in the asm file when considering the symbols they reference.
     484                 :             :      The attempt to output them later on will bail out immediately.  */
     485                 :    77117885 :   if (node->native_rtl_p ())
     486                 :         111 :     node->force_output = 1;
     487                 :             : 
     488                 :             :   /* When not optimizing, also output the static functions. (see
     489                 :             :      PR24561), but don't do so for always_inline functions, functions
     490                 :             :      declared inline and nested functions.  These were optimized out
     491                 :             :      in the original implementation and it is unclear whether we want
     492                 :             :      to change the behavior here.  */
     493                 :   151881520 :   if (((!opt_for_fn (decl, optimize) || flag_keep_static_functions
     494                 :    74763634 :         || node->no_reorder)
     495                 :     2457930 :        && !node->cpp_implicit_alias
     496                 :     2457930 :        && !DECL_DISREGARD_INLINE_LIMITS (decl)
     497                 :     1317545 :        && !DECL_DECLARED_INLINE_P (decl)
     498                 :      486291 :        && !(DECL_CONTEXT (decl)
     499                 :      227940 :             && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL))
     500                 :    77589949 :       && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
     501                 :      432320 :     node->force_output = 1;
     502                 :             : 
     503                 :             :   /* If we've not yet emitted decl, tell the debug info about it.  */
     504                 :    77117885 :   if (!TREE_ASM_WRITTEN (decl))
     505                 :    77117885 :     (*debug_hooks->deferred_inline_function) (decl);
     506                 :             : 
     507                 :    77117885 :   if (!no_collect)
     508                 :    69566899 :     ggc_collect ();
     509                 :             : 
     510                 :    77117885 :   if (symtab->state == CONSTRUCTION
     511                 :    77117885 :       && (node->needed_p () || node->referred_to_p ()))
     512                 :       42999 :     enqueue_node (node);
     513                 :    77117885 : }
     514                 :             : 
     515                 :             : /* Add the function FNDECL to the call graph.
     516                 :             :    Unlike finalize_function, this function is intended to be used
     517                 :             :    by middle end and allows insertion of new function at arbitrary point
     518                 :             :    of compilation.  The function can be either in high, low or SSA form
     519                 :             :    GIMPLE.
     520                 :             : 
     521                 :             :    The function is assumed to be reachable and have address taken (so no
     522                 :             :    API breaking optimizations are performed on it).
     523                 :             : 
     524                 :             :    Main work done by this function is to enqueue the function for later
     525                 :             :    processing to avoid need the passes to be re-entrant.  */
     526                 :             : 
     527                 :             : void
     528                 :       47781 : cgraph_node::add_new_function (tree fndecl, bool lowered)
     529                 :             : {
     530                 :       47781 :   gcc::pass_manager *passes = g->get_passes ();
     531                 :       47781 :   cgraph_node *node;
     532                 :             : 
     533                 :       47781 :   if (dump_file)
     534                 :             :     {
     535                 :          53 :       struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
     536                 :          53 :       const char *function_type = ((gimple_has_body_p (fndecl))
     537                 :          53 :                                    ? (lowered
     538                 :         104 :                                       ? (gimple_in_ssa_p (fn)
     539                 :             :                                          ? "ssa gimple"
     540                 :             :                                          : "low gimple")
     541                 :             :                                       : "high gimple")
     542                 :          53 :                                    : "to-be-gimplified");
     543                 :          53 :       fprintf (dump_file,
     544                 :             :                "Added new %s function %s to callgraph\n",
     545                 :             :                function_type,
     546                 :             :                fndecl_name (fndecl));
     547                 :             :     }
     548                 :             : 
     549                 :       47781 :   switch (symtab->state)
     550                 :             :     {
     551                 :           0 :       case PARSING:
     552                 :           0 :         cgraph_node::finalize_function (fndecl, false);
     553                 :           0 :         break;
     554                 :       42776 :       case CONSTRUCTION:
     555                 :             :         /* Just enqueue function to be processed at nearest occurrence.  */
     556                 :       42776 :         node = cgraph_node::get_create (fndecl);
     557                 :       42776 :         if (lowered)
     558                 :       42147 :           node->lowered = true;
     559                 :       42776 :         cgraph_new_nodes.safe_push (node);
     560                 :       42776 :         break;
     561                 :             : 
     562                 :        1050 :       case IPA:
     563                 :        1050 :       case IPA_SSA:
     564                 :        1050 :       case IPA_SSA_AFTER_INLINING:
     565                 :        1050 :       case EXPANSION:
     566                 :             :         /* Bring the function into finalized state and enqueue for later
     567                 :             :            analyzing and compilation.  */
     568                 :        1050 :         node = cgraph_node::get_create (fndecl);
     569                 :        1050 :         node->local = false;
     570                 :        1050 :         node->definition = true;
     571                 :        1050 :         node->semantic_interposition = opt_for_fn (fndecl,
     572                 :             :                                                    flag_semantic_interposition);
     573                 :        1050 :         node->force_output = true;
     574                 :        1050 :         if (TREE_PUBLIC (fndecl))
     575                 :          43 :           node->externally_visible = true;
     576                 :        1050 :         if (!lowered && symtab->state == EXPANSION)
     577                 :             :           {
     578                 :           0 :             push_cfun (DECL_STRUCT_FUNCTION (fndecl));
     579                 :           0 :             gimple_register_cfg_hooks ();
     580                 :           0 :             bitmap_obstack_initialize (NULL);
     581                 :           0 :             execute_pass_list (cfun, passes->all_lowering_passes);
     582                 :           0 :             passes->execute_early_local_passes ();
     583                 :           0 :             bitmap_obstack_release (NULL);
     584                 :           0 :             pop_cfun ();
     585                 :             : 
     586                 :           0 :             lowered = true;
     587                 :             :           }
     588                 :           0 :         if (lowered)
     589                 :         268 :           node->lowered = true;
     590                 :        1050 :         cgraph_new_nodes.safe_push (node);
     591                 :        1050 :         break;
     592                 :             : 
     593                 :        3955 :       case FINISHED:
     594                 :             :         /* At the very end of compilation we have to do all the work up
     595                 :             :            to expansion.  */
     596                 :        3955 :         node = cgraph_node::create (fndecl);
     597                 :        3955 :         if (lowered)
     598                 :           0 :           node->lowered = true;
     599                 :        3955 :         node->definition = true;
     600                 :        3955 :         node->semantic_interposition = opt_for_fn (fndecl,
     601                 :             :                                                    flag_semantic_interposition);
     602                 :        3955 :         node->analyze ();
     603                 :        3955 :         push_cfun (DECL_STRUCT_FUNCTION (fndecl));
     604                 :        3955 :         gimple_register_cfg_hooks ();
     605                 :        3955 :         bitmap_obstack_initialize (NULL);
     606                 :        3955 :         if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)))
     607                 :        3955 :           g->get_passes ()->execute_early_local_passes ();
     608                 :        3955 :         bitmap_obstack_release (NULL);
     609                 :        3955 :         pop_cfun ();
     610                 :        3955 :         node->expand ();
     611                 :        3955 :         break;
     612                 :             : 
     613                 :           0 :       default:
     614                 :           0 :         gcc_unreachable ();
     615                 :             :     }
     616                 :             : 
     617                 :             :   /* Set a personality if required and we already passed EH lowering.  */
     618                 :       47781 :   if (lowered
     619                 :       90196 :       && (function_needs_eh_personality (DECL_STRUCT_FUNCTION (fndecl))
     620                 :             :           == eh_personality_lang))
     621                 :        1858 :     DECL_FUNCTION_PERSONALITY (fndecl) = lang_hooks.eh_personality ();
     622                 :       47781 : }
     623                 :             : 
     624                 :             : /* Analyze the function scheduled to be output.  */
     625                 :             : void
     626                 :     2779523 : cgraph_node::analyze (void)
     627                 :             : {
     628                 :     2779523 :   if (native_rtl_p ())
     629                 :             :     {
     630                 :          17 :       analyzed = true;
     631                 :          17 :       return;
     632                 :             :     }
     633                 :             : 
     634                 :     2779506 :   tree decl = this->decl;
     635                 :     2779506 :   location_t saved_loc = input_location;
     636                 :     2779506 :   input_location = DECL_SOURCE_LOCATION (decl);
     637                 :     2779506 :   semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
     638                 :             : 
     639                 :     2779506 :   if (thunk)
     640                 :             :     {
     641                 :        3256 :       thunk_info *info = thunk_info::get (this);
     642                 :        3256 :       cgraph_node *t = cgraph_node::get (info->alias);
     643                 :             : 
     644                 :        3256 :       create_edge (t, NULL, t->count);
     645                 :        3256 :       callees->can_throw_external = !TREE_NOTHROW (t->decl);
     646                 :             :       /* Target code in expand_thunk may need the thunk's target
     647                 :             :          to be analyzed, so recurse here.  */
     648                 :        3256 :       if (!t->analyzed && t->definition)
     649                 :           0 :         t->analyze ();
     650                 :        3256 :       if (t->alias)
     651                 :             :         {
     652                 :        3256 :           t = t->get_alias_target ();
     653                 :        3256 :           if (!t->analyzed && t->definition)
     654                 :        1242 :             t->analyze ();
     655                 :             :         }
     656                 :        3256 :       bool ret = expand_thunk (this, false, false);
     657                 :        3256 :       thunk_info::get (this)->alias = NULL;
     658                 :        3256 :       if (!ret)
     659                 :             :         return;
     660                 :             :     }
     661                 :     2776411 :   if (alias)
     662                 :        4999 :     resolve_alias (cgraph_node::get (alias_target), transparent_alias);
     663                 :     2771412 :   else if (dispatcher_function)
     664                 :             :     {
     665                 :             :       /* Generate the dispatcher body of multi-versioned functions.  */
     666                 :          96 :       cgraph_function_version_info *dispatcher_version_info
     667                 :          96 :         = function_version ();
     668                 :          96 :       if (dispatcher_version_info != NULL
     669                 :          96 :           && (dispatcher_version_info->dispatcher_resolver
     670                 :             :               == NULL_TREE))
     671                 :             :         {
     672                 :          96 :           tree resolver = NULL_TREE;
     673                 :          96 :           gcc_assert (targetm.generate_version_dispatcher_body);
     674                 :          96 :           resolver = targetm.generate_version_dispatcher_body (this);
     675                 :          96 :           gcc_assert (resolver != NULL_TREE);
     676                 :             :         }
     677                 :             :     }
     678                 :             :   else
     679                 :             :     {
     680                 :     2771316 :       push_cfun (DECL_STRUCT_FUNCTION (decl));
     681                 :             : 
     682                 :     2771316 :       assign_assembler_name_if_needed (decl);
     683                 :             : 
     684                 :             :       /* Make sure to gimplify bodies only once.  During analyzing a
     685                 :             :          function we lower it, which will require gimplified nested
     686                 :             :          functions, so we can end up here with an already gimplified
     687                 :             :          body.  */
     688                 :     2771316 :       if (!gimple_has_body_p (decl))
     689                 :     2679169 :         gimplify_function_tree (decl);
     690                 :             : 
     691                 :             :       /* Lower the function.  */
     692                 :     2771316 :       if (!lowered)
     693                 :             :         {
     694                 :     2720096 :           if (first_nested_function (this))
     695                 :        9089 :             lower_nested_functions (decl);
     696                 :             : 
     697                 :     2711007 :           gimple_register_cfg_hooks ();
     698                 :     2711007 :           bitmap_obstack_initialize (NULL);
     699                 :     2711007 :           execute_pass_list (cfun, g->get_passes ()->all_lowering_passes);
     700                 :     2710993 :           compact_blocks ();
     701                 :     2710993 :           bitmap_obstack_release (NULL);
     702                 :     2710993 :           lowered = true;
     703                 :             :         }
     704                 :             : 
     705                 :     2771302 :       pop_cfun ();
     706                 :             :     }
     707                 :     2776397 :   analyzed = true;
     708                 :             : 
     709                 :     2776397 :   input_location = saved_loc;
     710                 :             : }
     711                 :             : 
     712                 :             : /* C++ frontend produce same body aliases all over the place, even before PCH
     713                 :             :    gets streamed out. It relies on us linking the aliases with their function
     714                 :             :    in order to do the fixups, but ipa-ref is not PCH safe.  Consequently we
     715                 :             :    first produce aliases without links, but once C++ FE is sure he won't stream
     716                 :             :    PCH we build the links via this function.  */
     717                 :             : 
     718                 :             : void
     719                 :       92023 : symbol_table::process_same_body_aliases (void)
     720                 :             : {
     721                 :       92023 :   symtab_node *node;
     722                 :    41458269 :   FOR_EACH_SYMBOL (node)
     723                 :    41366246 :     if (node->cpp_implicit_alias && !node->analyzed)
     724                 :     3110632 :       node->resolve_alias
     725                 :     6221264 :         (VAR_P (node->alias_target)
     726                 :           0 :          ? (symtab_node *)varpool_node::get_create (node->alias_target)
     727                 :     3110632 :          : (symtab_node *)cgraph_node::get_create (node->alias_target));
     728                 :       92023 :   cpp_implicit_aliases_done = true;
     729                 :       92023 : }
     730                 :             : 
     731                 :             : /* Process a symver attribute.  */
     732                 :             : 
     733                 :             : static void
     734                 :   111980253 : process_symver_attribute (symtab_node *n)
     735                 :             : {
     736                 :   111980253 :   tree value = lookup_attribute ("symver", DECL_ATTRIBUTES (n->decl));
     737                 :             : 
     738                 :   111980255 :   for (; value != NULL; value = TREE_CHAIN (value))
     739                 :             :     {
     740                 :             :       /* Starting from bintuils 2.35 gas supports:
     741                 :             :           # Assign foo to bar@V1 and baz@V2.
     742                 :             :           .symver foo, bar@V1
     743                 :             :           .symver foo, baz@V2
     744                 :             :       */
     745                 :           2 :       const char *purpose = IDENTIFIER_POINTER (TREE_PURPOSE (value));
     746                 :           2 :       if (strcmp (purpose, "symver") != 0)
     747                 :           0 :         continue;
     748                 :             : 
     749                 :           2 :       tree symver = get_identifier_with_length
     750                 :           4 :         (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (value))),
     751                 :           2 :          TREE_STRING_LENGTH (TREE_VALUE (TREE_VALUE (value))));
     752                 :           2 :       symtab_node *def = symtab_node::get_for_asmname (symver);
     753                 :             : 
     754                 :           2 :       if (def)
     755                 :             :         {
     756                 :           0 :           error_at (DECL_SOURCE_LOCATION (n->decl),
     757                 :             :                     "duplicate definition of a symbol version");
     758                 :           0 :           inform (DECL_SOURCE_LOCATION (def->decl),
     759                 :             :                   "same version was previously defined here");
     760                 :           0 :           return;
     761                 :             :         }
     762                 :           2 :       if (!n->definition)
     763                 :             :         {
     764                 :           0 :           error_at (DECL_SOURCE_LOCATION (n->decl),
     765                 :             :                     "symbol needs to be defined to have a version");
     766                 :           0 :           return;
     767                 :             :         }
     768                 :           2 :       if (DECL_COMMON (n->decl))
     769                 :             :         {
     770                 :           0 :           error_at (DECL_SOURCE_LOCATION (n->decl),
     771                 :             :                     "common symbol cannot be versioned");
     772                 :           0 :           return;
     773                 :             :         }
     774                 :           2 :       if (DECL_COMDAT (n->decl))
     775                 :             :         {
     776                 :           0 :           error_at (DECL_SOURCE_LOCATION (n->decl),
     777                 :             :                     "comdat symbol cannot be versioned");
     778                 :           0 :           return;
     779                 :             :         }
     780                 :           2 :       if (n->weakref)
     781                 :             :         {
     782                 :           0 :           error_at (DECL_SOURCE_LOCATION (n->decl),
     783                 :             :                     "%<weakref%> cannot be versioned");
     784                 :           0 :           return;
     785                 :             :         }
     786                 :           2 :       if (!TREE_PUBLIC (n->decl))
     787                 :             :         {
     788                 :           0 :           error_at (DECL_SOURCE_LOCATION (n->decl),
     789                 :             :                     "versioned symbol must be public");
     790                 :           0 :           return;
     791                 :             :         }
     792                 :           2 :       if (DECL_VISIBILITY (n->decl) != VISIBILITY_DEFAULT)
     793                 :             :         {
     794                 :           0 :           error_at (DECL_SOURCE_LOCATION (n->decl),
     795                 :             :                     "versioned symbol must have default visibility");
     796                 :           0 :           return;
     797                 :             :         }
     798                 :             : 
     799                 :             :       /* Create new symbol table entry representing the version.  */
     800                 :           2 :       tree new_decl = copy_node (n->decl);
     801                 :             : 
     802                 :           2 :       DECL_INITIAL (new_decl) = NULL_TREE;
     803                 :           2 :       if (TREE_CODE (new_decl) == FUNCTION_DECL)
     804                 :           2 :         DECL_STRUCT_FUNCTION (new_decl) = NULL;
     805                 :           2 :       SET_DECL_ASSEMBLER_NAME (new_decl, symver);
     806                 :           2 :       TREE_PUBLIC (new_decl) = 1;
     807                 :           2 :       DECL_ATTRIBUTES (new_decl) = NULL;
     808                 :             : 
     809                 :           2 :       symtab_node *symver_node = symtab_node::get_create (new_decl);
     810                 :           2 :       symver_node->alias = true;
     811                 :           2 :       symver_node->definition = true;
     812                 :           2 :       symver_node->symver = true;
     813                 :           2 :       symver_node->create_reference (n, IPA_REF_ALIAS, NULL);
     814                 :           2 :       symver_node->analyzed = true;
     815                 :             :     }
     816                 :             : }
     817                 :             : 
     818                 :             : /* Process attributes common for vars and functions.  */
     819                 :             : 
     820                 :             : static void
     821                 :   111980253 : process_common_attributes (symtab_node *node, tree decl)
     822                 :             : {
     823                 :   111980253 :   tree weakref = lookup_attribute ("weakref", DECL_ATTRIBUTES (decl));
     824                 :             : 
     825                 :   111980253 :   if (weakref && !lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
     826                 :             :     {
     827                 :           1 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
     828                 :             :                   "%<weakref%> attribute should be accompanied with"
     829                 :             :                   " an %<alias%> attribute");
     830                 :           1 :       DECL_WEAK (decl) = 0;
     831                 :           1 :       DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
     832                 :           1 :                                                  DECL_ATTRIBUTES (decl));
     833                 :             :     }
     834                 :             : 
     835                 :   111980253 :   if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (decl)))
     836                 :          17 :     node->no_reorder = 1;
     837                 :   111980253 :   process_symver_attribute (node);
     838                 :   111980253 : }
     839                 :             : 
     840                 :             : /* Look for externally_visible and used attributes and mark cgraph nodes
     841                 :             :    accordingly.
     842                 :             : 
     843                 :             :    We cannot mark the nodes at the point the attributes are processed (in
     844                 :             :    handle_*_attribute) because the copy of the declarations available at that
     845                 :             :    point may not be canonical.  For example, in:
     846                 :             : 
     847                 :             :     void f();
     848                 :             :     void f() __attribute__((used));
     849                 :             : 
     850                 :             :    the declaration we see in handle_used_attribute will be the second
     851                 :             :    declaration -- but the front end will subsequently merge that declaration
     852                 :             :    with the original declaration and discard the second declaration.
     853                 :             : 
     854                 :             :    Furthermore, we can't mark these nodes in finalize_function because:
     855                 :             : 
     856                 :             :     void f() {}
     857                 :             :     void f() __attribute__((externally_visible));
     858                 :             : 
     859                 :             :    is valid.
     860                 :             : 
     861                 :             :    So, we walk the nodes at the end of the translation unit, applying the
     862                 :             :    attributes at that point.  */
     863                 :             : 
     864                 :             : static void
     865                 :      741804 : process_function_and_variable_attributes (cgraph_node *first,
     866                 :             :                                           varpool_node *first_var)
     867                 :             : {
     868                 :      741804 :   cgraph_node *node;
     869                 :      741804 :   varpool_node *vnode;
     870                 :             : 
     871                 :    93285662 :   for (node = symtab->first_function (); node != first;
     872                 :   184345912 :        node = symtab->next_function (node))
     873                 :             :     {
     874                 :    91802054 :       tree decl = node->decl;
     875                 :             : 
     876                 :    91802054 :       if (node->alias
     877                 :    91802054 :           && lookup_attribute ("flatten", DECL_ATTRIBUTES (decl)))
     878                 :             :         {
     879                 :           8 :           tree tdecl = node->get_alias_target_tree ();
     880                 :           8 :           if (!tdecl || !DECL_P (tdecl)
     881                 :          16 :               || !lookup_attribute ("flatten", DECL_ATTRIBUTES (tdecl)))
     882                 :           1 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
     883                 :             :                         "%<flatten%> attribute is ignored on aliases");
     884                 :             :         }
     885                 :    91802054 :       if (DECL_PRESERVE_P (decl))
     886                 :        4118 :         node->mark_force_output ();
     887                 :    91797936 :       else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
     888                 :             :         {
     889                 :       37944 :           if (! TREE_PUBLIC (node->decl))
     890                 :           4 :             warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
     891                 :             :                         "%<externally_visible%>"
     892                 :             :                         " attribute have effect only on public objects");
     893                 :             :         }
     894                 :    91802054 :       if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
     895                 :         388 :           && node->definition
     896                 :    91802104 :           && (!node->alias || DECL_INITIAL (decl) != error_mark_node))
     897                 :             :         {
     898                 :             :           /* NODE->DEFINITION && NODE->ALIAS is nonzero for valid weakref
     899                 :             :              function declarations; DECL_INITIAL is non-null for invalid
     900                 :             :              weakref functions that are also defined.  */
     901                 :           3 :           warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
     902                 :             :                       "%<weakref%> attribute ignored"
     903                 :             :                       " because function is defined");
     904                 :           3 :           DECL_WEAK (decl) = 0;
     905                 :           3 :           DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
     906                 :           3 :                                                      DECL_ATTRIBUTES (decl));
     907                 :           3 :           DECL_ATTRIBUTES (decl) = remove_attribute ("alias",
     908                 :           3 :                                                      DECL_ATTRIBUTES (decl));
     909                 :           3 :           node->alias = false;
     910                 :           3 :           node->weakref = false;
     911                 :           3 :           node->transparent_alias = false;
     912                 :             :         }
     913                 :    91802051 :       else if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl))
     914                 :             :           && node->definition
     915                 :    91802051 :           && !node->alias)
     916                 :           1 :         warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
     917                 :             :                     "%<alias%> attribute ignored"
     918                 :             :                     " because function is defined");
     919                 :             : 
     920                 :    91802054 :       if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl))
     921                 :    41836397 :           && !DECL_DECLARED_INLINE_P (decl)
     922                 :             :           /* redefining extern inline function makes it DECL_UNINLINABLE.  */
     923                 :    91870638 :           && !DECL_UNINLINABLE (decl))
     924                 :       68579 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
     925                 :             :                     "%<always_inline%> function might not be inlinable"
     926                 :             :                     " unless also declared %<inline%>");
     927                 :             : 
     928                 :    91802054 :       process_common_attributes (node, decl);
     929                 :             :     }
     930                 :    21661807 :   for (vnode = symtab->first_variable (); vnode != first_var;
     931                 :    41098202 :        vnode = symtab->next_variable (vnode))
     932                 :             :     {
     933                 :    20178199 :       tree decl = vnode->decl;
     934                 :    20178199 :       if (DECL_EXTERNAL (decl)
     935                 :    20178199 :           && DECL_INITIAL (decl))
     936                 :     1805344 :         varpool_node::finalize_decl (decl);
     937                 :    20178199 :       if (DECL_PRESERVE_P (decl))
     938                 :        2960 :         vnode->force_output = true;
     939                 :    20175239 :       else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
     940                 :             :         {
     941                 :          42 :           if (! TREE_PUBLIC (vnode->decl))
     942                 :           4 :             warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes,
     943                 :             :                         "%<externally_visible%>"
     944                 :             :                         " attribute have effect only on public objects");
     945                 :             :         }
     946                 :    20178199 :       if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
     947                 :          69 :           && vnode->definition
     948                 :    20178212 :           && DECL_INITIAL (decl))
     949                 :             :         {
     950                 :           1 :           warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes,
     951                 :             :                       "%<weakref%> attribute ignored"
     952                 :             :                       " because variable is initialized");
     953                 :           1 :           DECL_WEAK (decl) = 0;
     954                 :           1 :           DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
     955                 :           1 :                                                       DECL_ATTRIBUTES (decl));
     956                 :             :         }
     957                 :    20178199 :       process_common_attributes (vnode, decl);
     958                 :             :     }
     959                 :      741804 : }
     960                 :             : 
     961                 :             : /* Mark DECL as finalized.  By finalizing the declaration, frontend instruct the
     962                 :             :    middle end to output the variable to asm file, if needed or externally
     963                 :             :    visible.  */
     964                 :             : 
     965                 :             : void
     966                 :    18261053 : varpool_node::finalize_decl (tree decl)
     967                 :             : {
     968                 :    18261053 :   varpool_node *node = varpool_node::get_create (decl);
     969                 :             : 
     970                 :    18261053 :   gcc_assert (TREE_STATIC (decl) || DECL_EXTERNAL (decl));
     971                 :             : 
     972                 :    18261053 :   if (node->definition)
     973                 :             :     return;
     974                 :             :   /* Set definition first before calling notice_global_symbol so that
     975                 :             :      it is available to notice_global_symbol.  */
     976                 :    18237502 :   node->definition = true;
     977                 :    18237502 :   node->semantic_interposition = flag_semantic_interposition;
     978                 :    18237502 :   notice_global_symbol (decl);
     979                 :    18237502 :   if (!flag_toplevel_reorder)
     980                 :     1471422 :     node->no_reorder = true;
     981                 :    18147226 :   if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl)
     982                 :             :       /* Traditionally we do not eliminate static variables when not
     983                 :             :          optimizing and when not doing toplevel reorder.  */
     984                 :    36381697 :       || (node->no_reorder && !DECL_COMDAT (node->decl)
     985                 :     1035523 :           && !DECL_ARTIFICIAL (node->decl)))
     986                 :      451054 :     node->force_output = true;
     987                 :             : 
     988                 :    18237502 :   if (flag_openmp)
     989                 :             :     {
     990                 :       63439 :       tree attr = lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl));
     991                 :       63439 :       if (attr)
     992                 :             :         {
     993                 :          21 :           tree align = TREE_VALUE (TREE_VALUE (attr));
     994                 :          21 :           if (align)
     995                 :          16 :             SET_DECL_ALIGN (decl, MAX (tree_to_uhwi (align) * BITS_PER_UNIT,
     996                 :             :                                        DECL_ALIGN (decl)));
     997                 :             :         }
     998                 :             :     }
     999                 :             : 
    1000                 :    18237502 :   if (symtab->state == CONSTRUCTION
    1001                 :    18237502 :       && (node->needed_p () || node->referred_to_p ()))
    1002                 :      234137 :     enqueue_node (node);
    1003                 :    18237502 :   if (symtab->state >= IPA_SSA)
    1004                 :       28807 :     node->analyze ();
    1005                 :             :   /* Some frontends produce various interface variables after compilation
    1006                 :             :      finished.  */
    1007                 :    18237502 :   if (symtab->state == FINISHED
    1008                 :    18233154 :       || (node->no_reorder
    1009                 :     1470813 :           && symtab->state == EXPANSION))
    1010                 :       11738 :     node->assemble_decl ();
    1011                 :             : }
    1012                 :             : 
    1013                 :             : /* EDGE is an polymorphic call.  Mark all possible targets as reachable
    1014                 :             :    and if there is only one target, perform trivial devirtualization.
    1015                 :             :    REACHABLE_CALL_TARGETS collects target lists we already walked to
    1016                 :             :    avoid duplicate work.  */
    1017                 :             : 
    1018                 :             : static void
    1019                 :       18045 : walk_polymorphic_call_targets (hash_set<void *> *reachable_call_targets,
    1020                 :             :                                cgraph_edge *edge)
    1021                 :             : {
    1022                 :       18045 :   unsigned int i;
    1023                 :       18045 :   void *cache_token;
    1024                 :       18045 :   bool final;
    1025                 :       18045 :   vec <cgraph_node *>targets
    1026                 :             :     = possible_polymorphic_call_targets
    1027                 :       18045 :         (edge, &final, &cache_token);
    1028                 :             : 
    1029                 :       18045 :   if (cache_token != NULL && !reachable_call_targets->add (cache_token))
    1030                 :             :     {
    1031                 :       15007 :       if (symtab->dump_file)
    1032                 :          12 :         dump_possible_polymorphic_call_targets
    1033                 :          12 :           (symtab->dump_file, edge);
    1034                 :             : 
    1035                 :       41469 :       for (i = 0; i < targets.length (); i++)
    1036                 :             :         {
    1037                 :             :           /* Do not bother to mark virtual methods in anonymous namespace;
    1038                 :             :              either we will find use of virtual table defining it, or it is
    1039                 :             :              unused.  */
    1040                 :       26462 :           if (targets[i]->definition
    1041                 :       17781 :               && TREE_CODE
    1042                 :             :                   (TREE_TYPE (targets[i]->decl))
    1043                 :             :                    == METHOD_TYPE
    1044                 :       44243 :               && !type_in_anonymous_namespace_p
    1045                 :       17781 :                    (TYPE_METHOD_BASETYPE (TREE_TYPE (targets[i]->decl))))
    1046                 :       17051 :             enqueue_node (targets[i]);
    1047                 :             :         }
    1048                 :             :     }
    1049                 :             : 
    1050                 :             :   /* Very trivial devirtualization; when the type is
    1051                 :             :      final or anonymous (so we know all its derivation)
    1052                 :             :      and there is only one possible virtual call target,
    1053                 :             :      make the edge direct.  */
    1054                 :       18045 :   if (final)
    1055                 :             :     {
    1056                 :          36 :       if (targets.length () <= 1 && dbg_cnt (devirt))
    1057                 :             :         {
    1058                 :           0 :           cgraph_node *target;
    1059                 :           0 :           if (targets.length () == 1)
    1060                 :           0 :             target = targets[0];
    1061                 :             :           else
    1062                 :           0 :             target = cgraph_node::create (builtin_decl_unreachable ());
    1063                 :             : 
    1064                 :           0 :           if (symtab->dump_file)
    1065                 :             :             {
    1066                 :           0 :               fprintf (symtab->dump_file,
    1067                 :             :                        "Devirtualizing call: ");
    1068                 :           0 :               print_gimple_stmt (symtab->dump_file,
    1069                 :           0 :                                  edge->call_stmt, 0,
    1070                 :             :                                  TDF_SLIM);
    1071                 :             :             }
    1072                 :           0 :           if (dump_enabled_p ())
    1073                 :             :             {
    1074                 :           0 :               dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, edge->call_stmt,
    1075                 :             :                                "devirtualizing call in %s to %s\n",
    1076                 :           0 :                                edge->caller->dump_name (),
    1077                 :             :                                target->dump_name ());
    1078                 :             :             }
    1079                 :             : 
    1080                 :           0 :           edge = cgraph_edge::make_direct (edge, target);
    1081                 :           0 :           gimple *new_call = cgraph_edge::redirect_call_stmt_to_callee (edge);
    1082                 :             : 
    1083                 :           0 :           if (symtab->dump_file)
    1084                 :             :             {
    1085                 :           0 :               fprintf (symtab->dump_file, "Devirtualized as: ");
    1086                 :           0 :               print_gimple_stmt (symtab->dump_file, new_call, 0, TDF_SLIM);
    1087                 :             :             }
    1088                 :             :         }
    1089                 :             :     }
    1090                 :       18045 : }
    1091                 :             : 
    1092                 :             : /* Issue appropriate warnings for the global declaration DECL.  */
    1093                 :             : 
    1094                 :             : static void
    1095                 :   112116866 : check_global_declaration (symtab_node *snode)
    1096                 :             : {
    1097                 :   112116866 :   const char *decl_file;
    1098                 :   112116866 :   tree decl = snode->decl;
    1099                 :             : 
    1100                 :             :   /* Warn about any function declared static but not defined.  We don't
    1101                 :             :      warn about variables, because many programs have static variables
    1102                 :             :      that exist only to get some text into the object file.  */
    1103                 :   112116866 :   if (TREE_CODE (decl) == FUNCTION_DECL
    1104                 :    91933894 :       && DECL_INITIAL (decl) == 0
    1105                 :     1815010 :       && DECL_EXTERNAL (decl)
    1106                 :     1810051 :       && ! DECL_ARTIFICIAL (decl)
    1107                 :   113787142 :       && ! TREE_PUBLIC (decl))
    1108                 :             :     {
    1109                 :         154 :       if (warning_suppressed_p (decl, OPT_Wunused))
    1110                 :             :         ;
    1111                 :         106 :       else if (snode->referred_to_p (/*include_self=*/false))
    1112                 :         103 :         pedwarn (input_location, 0, "%q+F used but never defined", decl);
    1113                 :             :       else
    1114                 :           3 :         warning (OPT_Wunused_function, "%q+F declared %<static%> but never "
    1115                 :             :                                        "defined", decl);
    1116                 :             :     }
    1117                 :             : 
    1118                 :             :   /* Warn about static fns or vars defined but not used.  */
    1119                 :     4910857 :   if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
    1120                 :   107574951 :        || (((warn_unused_variable && ! TREE_READONLY (decl))
    1121                 :   107521451 :             || (warn_unused_const_variable > 0 && TREE_READONLY (decl)
    1122                 :        4555 :                 && (warn_unused_const_variable == 2
    1123                 :        4549 :                     || (main_input_filename != NULL
    1124                 :   112120790 :                         && (decl_file = DECL_SOURCE_FILE (decl)) != NULL
    1125                 :        4542 :                         && filename_cmp (main_input_filename,
    1126                 :             :                                          decl_file) == 0))))
    1127                 :       57393 :            && VAR_P (decl)))
    1128                 :     4587451 :       && ! DECL_IN_SYSTEM_HEADER (decl)
    1129                 :      834778 :       && ! snode->referred_to_p (/*include_self=*/false)
    1130                 :             :       /* This TREE_USED check is needed in addition to referred_to_p
    1131                 :             :          above, because the `__unused__' attribute is not being
    1132                 :             :          considered for referred_to_p.  */
    1133                 :      531869 :       && ! TREE_USED (decl)
    1134                 :             :       /* The TREE_USED bit for file-scope decls is kept in the identifier,
    1135                 :             :          to handle multiple external decls in different scopes.  */
    1136                 :      304117 :       && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
    1137                 :      304117 :       && ! DECL_EXTERNAL (decl)
    1138                 :      135793 :       && ! DECL_ARTIFICIAL (decl)
    1139                 :      135138 :       && ! DECL_ABSTRACT_ORIGIN (decl)
    1140                 :      108412 :       && ! TREE_PUBLIC (decl)
    1141                 :             :       /* A volatile variable might be used in some non-obvious way.  */
    1142                 :       17378 :       && (! VAR_P (decl) || ! TREE_THIS_VOLATILE (decl))
    1143                 :             :       /* Global register variables must be declared to reserve them.  */
    1144                 :       17377 :       && ! (VAR_P (decl) && DECL_REGISTER (decl))
    1145                 :             :       /* Global ctors and dtors are called by the runtime.  */
    1146                 :       17377 :       && (TREE_CODE (decl) != FUNCTION_DECL
    1147                 :       17303 :           || (!DECL_STATIC_CONSTRUCTOR (decl)
    1148                 :       17303 :               && !DECL_STATIC_DESTRUCTOR (decl)))
    1149                 :       17377 :       && (! VAR_P (decl) || !warning_suppressed_p (decl, OPT_Wunused_variable))
    1150                 :             :       /* Otherwise, ask the language.  */
    1151                 :   112134236 :       && lang_hooks.decls.warn_unused_global (decl))
    1152                 :         618 :     warning_at (DECL_SOURCE_LOCATION (decl),
    1153                 :         618 :                 (TREE_CODE (decl) == FUNCTION_DECL)
    1154                 :          67 :                 ? OPT_Wunused_function
    1155                 :          67 :                 : (TREE_READONLY (decl)
    1156                 :             :                    ? OPT_Wunused_const_variable_
    1157                 :             :                    : OPT_Wunused_variable),
    1158                 :             :                 "%qD defined but not used", decl);
    1159                 :   112116866 : }
    1160                 :             : 
    1161                 :             : /* Discover all functions and variables that are trivially needed, analyze
    1162                 :             :    them as well as all functions and variables referred by them  */
    1163                 :             : static cgraph_node *first_analyzed;
    1164                 :             : static varpool_node *first_analyzed_var;
    1165                 :             : 
    1166                 :             : /* FIRST_TIME is set to TRUE for the first time we are called for a
    1167                 :             :    translation unit from finalize_compilation_unit() or false
    1168                 :             :    otherwise.  */
    1169                 :             : 
    1170                 :             : static void
    1171                 :      504296 : analyze_functions (bool first_time)
    1172                 :             : {
    1173                 :             :   /* Keep track of already processed nodes when called multiple times for
    1174                 :             :      intermodule optimization.  */
    1175                 :      504296 :   cgraph_node *first_handled = first_analyzed;
    1176                 :      504296 :   varpool_node *first_handled_var = first_analyzed_var;
    1177                 :      504296 :   hash_set<void *> reachable_call_targets;
    1178                 :             : 
    1179                 :      504296 :   symtab_node *node;
    1180                 :      504296 :   symtab_node *next;
    1181                 :      504296 :   int i;
    1182                 :      504296 :   ipa_ref *ref;
    1183                 :      504296 :   bool changed = true;
    1184                 :      504296 :   location_t saved_loc = input_location;
    1185                 :             : 
    1186                 :      504296 :   bitmap_obstack_initialize (NULL);
    1187                 :      504296 :   symtab->state = CONSTRUCTION;
    1188                 :      504296 :   input_location = UNKNOWN_LOCATION;
    1189                 :             : 
    1190                 :      504296 :   thunk_info::process_early_thunks ();
    1191                 :             : 
    1192                 :             :   /* Ugly, but the fixup cannot happen at a time same body alias is created;
    1193                 :             :      C++ FE is confused about the COMDAT groups being right.  */
    1194                 :      504296 :   if (symtab->cpp_implicit_aliases_done)
    1195                 :    72515432 :     FOR_EACH_SYMBOL (node)
    1196                 :    72331603 :       if (node->cpp_implicit_alias)
    1197                 :     6836847 :           node->fixup_same_cpp_alias_visibility (node->get_alias_target ());
    1198                 :      504296 :   build_type_inheritance_graph ();
    1199                 :             : 
    1200                 :      504296 :   if (flag_openmp && first_time)
    1201                 :        8546 :     omp_discover_implicit_declare_target ();
    1202                 :             : 
    1203                 :             :   /* Analysis adds static variables that in turn adds references to new functions.
    1204                 :             :      So we need to iterate the process until it stabilize.  */
    1205                 :     1246086 :   while (changed)
    1206                 :             :     {
    1207                 :      741804 :       changed = false;
    1208                 :      741804 :       process_function_and_variable_attributes (first_analyzed,
    1209                 :             :                                                 first_analyzed_var);
    1210                 :             : 
    1211                 :             :       /* First identify the trivially needed symbols.  */
    1212                 :      741804 :       for (node = symtab->first_symbol ();
    1213                 :   112722059 :            node != first_analyzed
    1214                 :   112722059 :            && node != first_analyzed_var; node = node->next)
    1215                 :             :         {
    1216                 :             :           /* Convert COMDAT group designators to IDENTIFIER_NODEs.  */
    1217                 :   111980255 :           node->get_comdat_group_id ();
    1218                 :   111980255 :           if (node->needed_p ())
    1219                 :             :             {
    1220                 :     2774096 :               enqueue_node (node);
    1221                 :     2774096 :               if (!changed && symtab->dump_file)
    1222                 :          75 :                 fprintf (symtab->dump_file, "Trivially needed symbols:");
    1223                 :     2774096 :               changed = true;
    1224                 :     2774096 :               if (symtab->dump_file)
    1225                 :         128 :                 fprintf (symtab->dump_file, " %s", node->dump_asm_name ());
    1226                 :             :             }
    1227                 :   111980255 :           if (node == first_analyzed
    1228                 :   111980255 :               || node == first_analyzed_var)
    1229                 :             :             break;
    1230                 :             :         }
    1231                 :      741804 :       symtab->process_new_functions ();
    1232                 :      741804 :       first_analyzed_var = symtab->first_variable ();
    1233                 :      741804 :       first_analyzed = symtab->first_function ();
    1234                 :             : 
    1235                 :      741804 :       if (changed && symtab->dump_file)
    1236                 :          75 :         fprintf (symtab->dump_file, "\n");
    1237                 :             : 
    1238                 :             :       /* Lower representation, build callgraph edges and references for all trivially
    1239                 :             :          needed symbols and all symbols referred by them.  */
    1240                 :     6849404 :       while (queued_nodes != &symtab_terminator)
    1241                 :             :         {
    1242                 :     6107614 :           changed = true;
    1243                 :     6107614 :           node = queued_nodes;
    1244                 :     6107614 :           queued_nodes = (symtab_node *)queued_nodes->aux;
    1245                 :     6107614 :           cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    1246                 :     3104799 :           if (cnode && cnode->definition)
    1247                 :             :             {
    1248                 :     3104362 :               cgraph_edge *edge;
    1249                 :     3104362 :               tree decl = cnode->decl;
    1250                 :             : 
    1251                 :             :               /* ??? It is possible to create extern inline function
    1252                 :             :               and later using weak alias attribute to kill its body.
    1253                 :             :               See gcc.c-torture/compile/20011119-1.c  */
    1254                 :     3104362 :               if (!DECL_STRUCT_FUNCTION (decl)
    1255                 :       29430 :                   && !cnode->alias
    1256                 :             :                   && !cnode->thunk
    1257                 :     3107664 :                   && !cnode->dispatcher_function)
    1258                 :             :                 {
    1259                 :           0 :                   cnode->reset ();
    1260                 :           0 :                   cnode->redefined_extern_inline = true;
    1261                 :           0 :                   continue;
    1262                 :             :                 }
    1263                 :             : 
    1264                 :     3104362 :               if (!cnode->analyzed)
    1265                 :     2755691 :                 cnode->analyze ();
    1266                 :             : 
    1267                 :    12330878 :               for (edge = cnode->callees; edge; edge = edge->next_callee)
    1268                 :     9226530 :                 if (edge->callee->definition
    1269                 :     9226530 :                     && (!DECL_EXTERNAL (edge->callee->decl)
    1270                 :             :                         /* When not optimizing, do not try to analyze extern
    1271                 :             :                            inline functions.  Doing so is pointless.  */
    1272                 :      487702 :                         || opt_for_fn (edge->callee->decl, optimize)
    1273                 :             :                         /* Weakrefs needs to be preserved.  */
    1274                 :        4070 :                         || edge->callee->alias
    1275                 :             :                         /* always_inline functions are inlined even at -O0.  */
    1276                 :        2658 :                         || lookup_attribute
    1277                 :        2658 :                                  ("always_inline",
    1278                 :        2658 :                                   DECL_ATTRIBUTES (edge->callee->decl))
    1279                 :             :                         /* Multiversioned functions needs the dispatcher to
    1280                 :             :                            be produced locally even for extern functions.  */
    1281                 :        1574 :                         || edge->callee->function_version ()))
    1282                 :     4570747 :                    enqueue_node (edge->callee);
    1283                 :     3104348 :               if (opt_for_fn (cnode->decl, optimize)
    1284                 :     3104348 :                   && opt_for_fn (cnode->decl, flag_devirtualize))
    1285                 :             :                 {
    1286                 :     2496946 :                   cgraph_edge *next;
    1287                 :             : 
    1288                 :     2626293 :                   for (edge = cnode->indirect_calls; edge; edge = next)
    1289                 :             :                     {
    1290                 :      129347 :                       next = edge->next_callee;
    1291                 :      129347 :                       if (edge->indirect_info->polymorphic)
    1292                 :       18045 :                         walk_polymorphic_call_targets (&reachable_call_targets,
    1293                 :             :                                                        edge);
    1294                 :             :                     }
    1295                 :             :                 }
    1296                 :             : 
    1297                 :             :               /* If decl is a clone of an abstract function,
    1298                 :             :                  mark that abstract function so that we don't release its body.
    1299                 :             :                  The DECL_INITIAL() of that abstract function declaration
    1300                 :             :                  will be later needed to output debug info.  */
    1301                 :     3104348 :               if (DECL_ABSTRACT_ORIGIN (decl))
    1302                 :             :                 {
    1303                 :      689758 :                   cgraph_node *origin_node
    1304                 :      689758 :                     = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (decl));
    1305                 :      689758 :                   origin_node->used_as_abstract_origin = true;
    1306                 :             :                 }
    1307                 :             :               /* Preserve a functions function context node.  It will
    1308                 :             :                  later be needed to output debug info.  */
    1309                 :     3104348 :               if (tree fn = decl_function_context (decl))
    1310                 :             :                 {
    1311                 :      112984 :                   cgraph_node *origin_node = cgraph_node::get_create (fn);
    1312                 :      112984 :                   enqueue_node (origin_node);
    1313                 :             :                 }
    1314                 :             :             }
    1315                 :             :           else
    1316                 :             :             {
    1317                 :     3003252 :               varpool_node *vnode = dyn_cast <varpool_node *> (node);
    1318                 :     3002815 :               if (vnode && vnode->definition && !vnode->analyzed)
    1319                 :     3002805 :                 vnode->analyze ();
    1320                 :             :             }
    1321                 :             : 
    1322                 :     6107600 :           if (node->same_comdat_group)
    1323                 :             :             {
    1324                 :             :               symtab_node *next;
    1325                 :      921018 :               for (next = node->same_comdat_group;
    1326                 :     1565195 :                    next != node;
    1327                 :      921018 :                    next = next->same_comdat_group)
    1328                 :     1842036 :                 if (!next->comdat_local_p ())
    1329                 :      909655 :                   enqueue_node (next);
    1330                 :             :             }
    1331                 :    17184056 :           for (i = 0; node->iterate_reference (i, ref); i++)
    1332                 :    11076456 :             if (ref->referred->definition
    1333                 :    11076456 :                 && (!DECL_EXTERNAL (ref->referred->decl)
    1334                 :       71013 :                     || ((TREE_CODE (ref->referred->decl) != FUNCTION_DECL
    1335                 :       25256 :                          && optimize)
    1336                 :       46091 :                         || (TREE_CODE (ref->referred->decl) == FUNCTION_DECL
    1337                 :       45757 :                             && opt_for_fn (ref->referred->decl, optimize))
    1338                 :         884 :                     || node->alias
    1339                 :         555 :                     || ref->referred->alias)))
    1340                 :     7295465 :               enqueue_node (ref->referred);
    1341                 :     6107600 :           symtab->process_new_functions ();
    1342                 :             :         }
    1343                 :             :     }
    1344                 :      504282 :   update_type_inheritance_graph ();
    1345                 :             : 
    1346                 :             :   /* Collect entry points to the unit.  */
    1347                 :      504282 :   if (symtab->dump_file)
    1348                 :             :     {
    1349                 :         150 :       fprintf (symtab->dump_file, "\n\nInitial ");
    1350                 :         150 :       symtab->dump (symtab->dump_file);
    1351                 :             :     }
    1352                 :             : 
    1353                 :      504282 :   if (first_time)
    1354                 :             :     {
    1355                 :      252141 :       symtab_node *snode;
    1356                 :   112369007 :       FOR_EACH_SYMBOL (snode)
    1357                 :   112116866 :         check_global_declaration (snode);
    1358                 :             :     }
    1359                 :             : 
    1360                 :      504282 :   if (symtab->dump_file)
    1361                 :         150 :     fprintf (symtab->dump_file, "\nRemoving unused symbols:");
    1362                 :             : 
    1363                 :      504282 :   for (node = symtab->first_symbol ();
    1364                 :   112621472 :        node != first_handled
    1365                 :   112621472 :        && node != first_handled_var; node = next)
    1366                 :             :     {
    1367                 :   112117190 :       next = node->next;
    1368                 :             :       /* For symbols declared locally we clear TREE_READONLY when emitting
    1369                 :             :          the constructor (if one is needed).  For external declarations we can
    1370                 :             :          not safely assume that the type is readonly because we may be called
    1371                 :             :          during its construction.  */
    1372                 :   112117190 :       if (TREE_CODE (node->decl) == VAR_DECL
    1373                 :    20183016 :           && TYPE_P (TREE_TYPE (node->decl))
    1374                 :    20182161 :           && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (node->decl))
    1375                 :   112549833 :           && DECL_EXTERNAL (node->decl))
    1376                 :      317832 :         TREE_READONLY (node->decl) = 0;
    1377                 :   112117190 :       if (!node->aux && !node->referred_to_p ())
    1378                 :             :         {
    1379                 :   103904601 :           if (symtab->dump_file)
    1380                 :          21 :             fprintf (symtab->dump_file, " %s", node->dump_name ());
    1381                 :             : 
    1382                 :             :           /* See if the debugger can use anything before the DECL
    1383                 :             :              passes away.  Perhaps it can notice a DECL that is now a
    1384                 :             :              constant and can tag the early DIE with an appropriate
    1385                 :             :              attribute.
    1386                 :             : 
    1387                 :             :              Otherwise, this is the last chance the debug_hooks have
    1388                 :             :              at looking at optimized away DECLs, since
    1389                 :             :              late_global_decl will subsequently be called from the
    1390                 :             :              contents of the now pruned symbol table.  */
    1391                 :   103904601 :           if (VAR_P (node->decl)
    1392                 :   103904601 :               && !decl_function_context (node->decl))
    1393                 :             :             {
    1394                 :             :               /* We are reclaiming totally unreachable code and variables
    1395                 :             :                  so they effectively appear as readonly.  Show that to
    1396                 :             :                  the debug machinery.  */
    1397                 :    16764428 :               TREE_READONLY (node->decl) = 1;
    1398                 :    16764428 :               node->definition = false;
    1399                 :    16764428 :               (*debug_hooks->late_global_decl) (node->decl);
    1400                 :             :             }
    1401                 :             : 
    1402                 :   103904601 :           node->remove ();
    1403                 :   103904601 :           continue;
    1404                 :             :         }
    1405                 :     8212589 :       if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
    1406                 :             :         {
    1407                 :     4915374 :           tree decl = node->decl;
    1408                 :             : 
    1409                 :     3105095 :           if (cnode->definition && !gimple_has_body_p (decl)
    1410                 :      356391 :               && !cnode->alias
    1411                 :     4919243 :               && !cnode->thunk)
    1412                 :         774 :             cnode->reset ();
    1413                 :             : 
    1414                 :     4915374 :           gcc_assert (!cnode->definition || cnode->thunk
    1415                 :             :                       || cnode->alias
    1416                 :             :                       || gimple_has_body_p (decl)
    1417                 :             :                       || cnode->native_rtl_p ());
    1418                 :     4915374 :           gcc_assert (cnode->analyzed == cnode->definition);
    1419                 :             :         }
    1420                 :     8212589 :       node->aux = NULL;
    1421                 :             :     }
    1422                 :     8716870 :   for (;node; node = node->next)
    1423                 :     8212588 :     node->aux = NULL;
    1424                 :      504282 :   first_analyzed = symtab->first_function ();
    1425                 :      504282 :   first_analyzed_var = symtab->first_variable ();
    1426                 :      504282 :   if (symtab->dump_file)
    1427                 :             :     {
    1428                 :         150 :       fprintf (symtab->dump_file, "\n\nReclaimed ");
    1429                 :         150 :       symtab->dump (symtab->dump_file);
    1430                 :             :     }
    1431                 :      504282 :   bitmap_obstack_release (NULL);
    1432                 :      504282 :   ggc_collect ();
    1433                 :             :   /* Initialize assembler name hash, in particular we want to trigger C++
    1434                 :             :      mangling and same body alias creation before we free DECL_ARGUMENTS
    1435                 :             :      used by it.  */
    1436                 :      504282 :   if (!seen_error ())
    1437                 :      454516 :     symtab->symtab_initialize_asm_name_hash ();
    1438                 :             : 
    1439                 :      504282 :   input_location = saved_loc;
    1440                 :      504282 : }
    1441                 :             : 
    1442                 :             : /* Check declaration of the type of ALIAS for compatibility with its TARGET
    1443                 :             :    (which may be an ifunc resolver) and issue a diagnostic when they are
    1444                 :             :    not compatible according to language rules (plus a C++ extension for
    1445                 :             :    non-static member functions).  */
    1446                 :             : 
    1447                 :             : static void
    1448                 :        5028 : maybe_diag_incompatible_alias (tree alias, tree target)
    1449                 :             : {
    1450                 :        5028 :   tree altype = TREE_TYPE (alias);
    1451                 :        5028 :   tree targtype = TREE_TYPE (target);
    1452                 :             : 
    1453                 :        5028 :   bool ifunc = cgraph_node::get (alias)->ifunc_resolver;
    1454                 :        5028 :   tree funcptr = altype;
    1455                 :             : 
    1456                 :        5028 :   if (ifunc)
    1457                 :             :     {
    1458                 :             :       /* Handle attribute ifunc first.  */
    1459                 :         119 :       if (TREE_CODE (altype) == METHOD_TYPE)
    1460                 :             :         {
    1461                 :             :           /* Set FUNCPTR to the type of the alias target.  If the type
    1462                 :             :              is a non-static member function of class C, construct a type
    1463                 :             :              of an ordinary function taking C* as the first argument,
    1464                 :             :              followed by the member function argument list, and use it
    1465                 :             :              instead to check for incompatibility.  This conversion is
    1466                 :             :              not defined by the language but an extension provided by
    1467                 :             :              G++.  */
    1468                 :             : 
    1469                 :          21 :           tree rettype = TREE_TYPE (altype);
    1470                 :          21 :           tree args = TYPE_ARG_TYPES (altype);
    1471                 :          21 :           altype = build_function_type (rettype, args);
    1472                 :          21 :           funcptr = altype;
    1473                 :             :         }
    1474                 :             : 
    1475                 :         119 :       targtype = TREE_TYPE (targtype);
    1476                 :             : 
    1477                 :         119 :       if (POINTER_TYPE_P (targtype))
    1478                 :             :         {
    1479                 :         115 :           targtype = TREE_TYPE (targtype);
    1480                 :             : 
    1481                 :             :           /* Only issue Wattribute-alias for conversions to void* with
    1482                 :             :              -Wextra.  */
    1483                 :         115 :           if (VOID_TYPE_P (targtype) && !extra_warnings)
    1484                 :             :             return;
    1485                 :             : 
    1486                 :             :           /* Proceed to handle incompatible ifunc resolvers below.  */
    1487                 :             :         }
    1488                 :             :       else
    1489                 :             :         {
    1490                 :           4 :           funcptr = build_pointer_type (funcptr);
    1491                 :             : 
    1492                 :           4 :           error_at (DECL_SOURCE_LOCATION (target),
    1493                 :             :                     "%<ifunc%> resolver for %qD must return %qT",
    1494                 :             :                  alias, funcptr);
    1495                 :           4 :           inform (DECL_SOURCE_LOCATION (alias),
    1496                 :             :                   "resolver indirect function declared here");
    1497                 :           4 :           return;
    1498                 :             :         }
    1499                 :             :     }
    1500                 :             : 
    1501                 :        5024 :   if ((!FUNC_OR_METHOD_TYPE_P (targtype)
    1502                 :        5024 :        || (prototype_p (altype)
    1503                 :        4898 :            && prototype_p (targtype)
    1504                 :        4896 :            && !types_compatible_p (altype, targtype))))
    1505                 :             :     {
    1506                 :             :       /* Warn for incompatibilities.  Avoid warning for functions
    1507                 :             :          without a prototype to make it possible to declare aliases
    1508                 :             :          without knowing the exact type, as libstdc++ does.  */
    1509                 :          16 :       if (ifunc)
    1510                 :             :         {
    1511                 :           5 :           funcptr = build_pointer_type (funcptr);
    1512                 :             : 
    1513                 :           5 :           auto_diagnostic_group d;
    1514                 :           5 :           if (warning_at (DECL_SOURCE_LOCATION (target),
    1515                 :             :                           OPT_Wattribute_alias_,
    1516                 :             :                           "%<ifunc%> resolver for %qD should return %qT",
    1517                 :             :                           alias, funcptr))
    1518                 :           5 :             inform (DECL_SOURCE_LOCATION (alias),
    1519                 :             :                     "resolver indirect function declared here");
    1520                 :           5 :         }
    1521                 :             :       else
    1522                 :             :         {
    1523                 :          11 :           auto_diagnostic_group d;
    1524                 :          11 :           if (warning_at (DECL_SOURCE_LOCATION (alias),
    1525                 :             :                             OPT_Wattribute_alias_,
    1526                 :             :                             "%qD alias between functions of incompatible "
    1527                 :             :                             "types %qT and %qT", alias, altype, targtype))
    1528                 :           3 :             inform (DECL_SOURCE_LOCATION (target),
    1529                 :             :                     "aliased declaration here");
    1530                 :          11 :         }
    1531                 :             :     }
    1532                 :             : }
    1533                 :             : 
    1534                 :             : /* Translate the ugly representation of aliases as alias pairs into nice
    1535                 :             :    representation in callgraph.  We don't handle all cases yet,
    1536                 :             :    unfortunately.  */
    1537                 :             : 
    1538                 :             : static void
    1539                 :      523207 : handle_alias_pairs (void)
    1540                 :             : {
    1541                 :      523207 :   alias_pair *p;
    1542                 :      523207 :   unsigned i;
    1543                 :             : 
    1544                 :      528779 :   for (i = 0; alias_pairs && alias_pairs->iterate (i, &p);)
    1545                 :             :     {
    1546                 :        5572 :       symtab_node *target_node = symtab_node::get_for_asmname (p->target);
    1547                 :             : 
    1548                 :             :       /* Weakrefs with target not defined in current unit are easy to handle:
    1549                 :             :          they behave just as external variables except we need to note the
    1550                 :             :          alias flag to later output the weakref pseudo op into asm file.  */
    1551                 :        5572 :       if (!target_node
    1552                 :        5572 :           && lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)) != NULL)
    1553                 :             :         {
    1554                 :         396 :           symtab_node *node = symtab_node::get (p->decl);
    1555                 :         396 :           if (node)
    1556                 :             :             {
    1557                 :         396 :               node->alias_target = p->target;
    1558                 :         396 :               node->weakref = true;
    1559                 :         396 :               node->alias = true;
    1560                 :         396 :               node->transparent_alias = true;
    1561                 :             :             }
    1562                 :         396 :           alias_pairs->unordered_remove (i);
    1563                 :         396 :           continue;
    1564                 :         396 :         }
    1565                 :        5176 :       else if (!target_node)
    1566                 :             :         {
    1567                 :           8 :           error ("%q+D aliased to undefined symbol %qE", p->decl, p->target);
    1568                 :           8 :           symtab_node *node = symtab_node::get (p->decl);
    1569                 :           8 :           if (node)
    1570                 :           8 :             node->alias = false;
    1571                 :           8 :           alias_pairs->unordered_remove (i);
    1572                 :           8 :           continue;
    1573                 :           8 :         }
    1574                 :             : 
    1575                 :        5168 :       if (DECL_EXTERNAL (target_node->decl)
    1576                 :             :           /* We use local aliases for C++ thunks to force the tailcall
    1577                 :             :              to bind locally.  This is a hack - to keep it working do
    1578                 :             :              the following (which is not strictly correct).  */
    1579                 :          24 :           && (TREE_CODE (target_node->decl) != FUNCTION_DECL
    1580                 :          24 :               || ! DECL_VIRTUAL_P (target_node->decl))
    1581                 :        5192 :           && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
    1582                 :             :         {
    1583                 :           0 :           error ("%q+D aliased to external symbol %qE",
    1584                 :             :                  p->decl, p->target);
    1585                 :             :         }
    1586                 :             : 
    1587                 :        5168 :       if (TREE_CODE (p->decl) == FUNCTION_DECL
    1588                 :        5168 :           && target_node && is_a <cgraph_node *> (target_node))
    1589                 :             :         {
    1590                 :        5028 :           maybe_diag_incompatible_alias (p->decl, target_node->decl);
    1591                 :             : 
    1592                 :        5028 :           maybe_diag_alias_attributes (p->decl, target_node->decl);
    1593                 :             : 
    1594                 :        5028 :           cgraph_node *src_node = cgraph_node::get (p->decl);
    1595                 :        5028 :           if (src_node && src_node->definition)
    1596                 :          18 :             src_node->reset ();
    1597                 :        5028 :           cgraph_node::create_alias (p->decl, target_node->decl);
    1598                 :        5028 :           alias_pairs->unordered_remove (i);
    1599                 :             :         }
    1600                 :         140 :       else if (VAR_P (p->decl)
    1601                 :         140 :                && target_node && is_a <varpool_node *> (target_node))
    1602                 :             :         {
    1603                 :         139 :           varpool_node::create_alias (p->decl, target_node->decl);
    1604                 :         139 :           alias_pairs->unordered_remove (i);
    1605                 :             :         }
    1606                 :             :       else
    1607                 :             :         {
    1608                 :           1 :           error ("%q+D alias between function and variable is not supported",
    1609                 :             :                  p->decl);
    1610                 :           1 :           inform (DECL_SOURCE_LOCATION (target_node->decl),
    1611                 :             :                   "aliased declaration here");
    1612                 :             : 
    1613                 :           1 :           alias_pairs->unordered_remove (i);
    1614                 :             :         }
    1615                 :             :     }
    1616                 :      523207 :   vec_free (alias_pairs);
    1617                 :      523207 : }
    1618                 :             : 
    1619                 :             : 
    1620                 :             : /* Figure out what functions we want to assemble.  */
    1621                 :             : 
    1622                 :             : static void
    1623                 :      227036 : mark_functions_to_output (void)
    1624                 :             : {
    1625                 :      227036 :   bool check_same_comdat_groups = false;
    1626                 :      227036 :   cgraph_node *node;
    1627                 :             : 
    1628                 :      227036 :   if (flag_checking)
    1629                 :     9170666 :     FOR_EACH_FUNCTION (node)
    1630                 :     4358311 :       gcc_assert (!node->process);
    1631                 :             : 
    1632                 :     4812430 :   FOR_EACH_FUNCTION (node)
    1633                 :             :     {
    1634                 :     4358358 :       tree decl = node->decl;
    1635                 :             : 
    1636                 :     4358358 :       gcc_assert (!node->process || node->same_comdat_group);
    1637                 :     4358358 :       if (node->process)
    1638                 :        9145 :         continue;
    1639                 :             : 
    1640                 :             :       /* We need to output all local functions that are used and not
    1641                 :             :          always inlined, as well as those that are reachable from
    1642                 :             :          outside the current compilation unit.  */
    1643                 :     4349213 :       if (node->analyzed
    1644                 :     2617389 :           && !node->thunk
    1645                 :     2615466 :           && !node->alias
    1646                 :     2555407 :           && !node->inlined_to
    1647                 :     1419290 :           && !TREE_ASM_WRITTEN (decl)
    1648                 :     5768503 :           && !DECL_EXTERNAL (decl))
    1649                 :             :         {
    1650                 :     1419290 :           node->process = 1;
    1651                 :     1419290 :           if (node->same_comdat_group)
    1652                 :             :             {
    1653                 :       42191 :               cgraph_node *next;
    1654                 :       42191 :               for (next = dyn_cast<cgraph_node *> (node->same_comdat_group);
    1655                 :      111152 :                    next != node;
    1656                 :      111152 :                    next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    1657                 :       67602 :                 if (!next->thunk && !next->alias
    1658                 :      166333 :                     && !next->comdat_local_p ())
    1659                 :       11457 :                   next->process = 1;
    1660                 :             :             }
    1661                 :             :         }
    1662                 :     2929923 :       else if (node->same_comdat_group)
    1663                 :             :         {
    1664                 :       39014 :           if (flag_checking)
    1665                 :     4358358 :             check_same_comdat_groups = true;
    1666                 :             :         }
    1667                 :             :       else
    1668                 :             :         {
    1669                 :             :           /* We should've reclaimed all functions that are not needed.  */
    1670                 :     2890909 :           if (flag_checking
    1671                 :     2890882 :               && !node->inlined_to
    1672                 :     1754613 :               && gimple_has_body_p (decl)
    1673                 :             :               /* FIXME: in ltrans unit when offline copy is outside partition but inline copies
    1674                 :             :                  are inside partition, we can end up not removing the body since we no longer
    1675                 :             :                  have analyzed node pointing to it.  */
    1676                 :             :               && !node->in_other_partition
    1677                 :      106088 :               && !node->alias
    1678                 :      106088 :               && !node->clones
    1679                 :     2890909 :               && !DECL_EXTERNAL (decl))
    1680                 :             :             {
    1681                 :           0 :               node->debug ();
    1682                 :           0 :               internal_error ("failed to reclaim unneeded function");
    1683                 :             :             }
    1684                 :     2890909 :           gcc_assert (node->inlined_to
    1685                 :             :                       || !gimple_has_body_p (decl)
    1686                 :             :                       || node->in_other_partition
    1687                 :             :                       || node->clones
    1688                 :             :                       || DECL_ARTIFICIAL (decl)
    1689                 :             :                       || DECL_EXTERNAL (decl));
    1690                 :             : 
    1691                 :             :         }
    1692                 :             : 
    1693                 :             :     }
    1694                 :      227036 :   if (flag_checking && check_same_comdat_groups)
    1695                 :     2328098 :     FOR_EACH_FUNCTION (node)
    1696                 :     1153609 :       if (node->same_comdat_group && !node->process)
    1697                 :             :         {
    1698                 :       39014 :           tree decl = node->decl;
    1699                 :       39014 :           if (!node->inlined_to
    1700                 :       39014 :               && gimple_has_body_p (decl)
    1701                 :             :               /* FIXME: in an ltrans unit when the offline copy is outside a
    1702                 :             :                  partition but inline copies are inside a partition, we can
    1703                 :             :                  end up not removing the body since we no longer have an
    1704                 :             :                  analyzed node pointing to it.  */
    1705                 :          15 :               && !node->in_other_partition
    1706                 :          15 :               && !node->clones
    1707                 :       39014 :               && !DECL_EXTERNAL (decl))
    1708                 :             :             {
    1709                 :           0 :               node->debug ();
    1710                 :           0 :               internal_error ("failed to reclaim unneeded function in same "
    1711                 :             :                               "comdat group");
    1712                 :             :             }
    1713                 :             :         }
    1714                 :      227036 : }
    1715                 :             : 
    1716                 :             : /* DECL is FUNCTION_DECL.  Initialize datastructures so DECL is a function
    1717                 :             :    in lowered gimple form.  IN_SSA is true if the gimple is in SSA.
    1718                 :             : 
    1719                 :             :    Set current_function_decl and cfun to newly constructed empty function body.
    1720                 :             :    return basic block in the function body.  */
    1721                 :             : 
    1722                 :             : basic_block
    1723                 :       18776 : init_lowered_empty_function (tree decl, bool in_ssa, profile_count count)
    1724                 :             : {
    1725                 :       18776 :   basic_block bb;
    1726                 :       18776 :   edge e;
    1727                 :             : 
    1728                 :       18776 :   current_function_decl = decl;
    1729                 :       18776 :   allocate_struct_function (decl, false);
    1730                 :       18776 :   gimple_register_cfg_hooks ();
    1731                 :       18776 :   init_empty_tree_cfg ();
    1732                 :       18776 :   init_tree_ssa (cfun);
    1733                 :             : 
    1734                 :       18776 :   if (in_ssa)
    1735                 :             :     {
    1736                 :       18616 :       init_ssa_operands (cfun);
    1737                 :       18616 :       cfun->gimple_df->in_ssa_p = true;
    1738                 :       18616 :       cfun->curr_properties |= PROP_ssa;
    1739                 :             :     }
    1740                 :             : 
    1741                 :       18776 :   DECL_INITIAL (decl) = make_node (BLOCK);
    1742                 :       18776 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (decl)) = decl;
    1743                 :             : 
    1744                 :       18776 :   DECL_SAVED_TREE (decl) = error_mark_node;
    1745                 :       18776 :   cfun->curr_properties |= (PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_any
    1746                 :             :                             | PROP_cfg | PROP_loops);
    1747                 :             : 
    1748                 :       18776 :   set_loops_for_fn (cfun, ggc_cleared_alloc<loops> ());
    1749                 :       18776 :   init_loops_structure (cfun, loops_for_fn (cfun), 1);
    1750                 :       18776 :   loops_for_fn (cfun)->state |= LOOPS_MAY_HAVE_MULTIPLE_LATCHES;
    1751                 :             : 
    1752                 :             :   /* Create BB for body of the function and connect it properly.  */
    1753                 :       18776 :   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = count;
    1754                 :       18776 :   EXIT_BLOCK_PTR_FOR_FN (cfun)->count = count;
    1755                 :       18776 :   bb = create_basic_block (NULL, ENTRY_BLOCK_PTR_FOR_FN (cfun));
    1756                 :       18776 :   bb->count = count;
    1757                 :       18776 :   e = make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, EDGE_FALLTHRU);
    1758                 :       18776 :   e->probability = profile_probability::always ();
    1759                 :       18776 :   e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
    1760                 :       18776 :   e->probability = profile_probability::always ();
    1761                 :       18776 :   add_bb_to_loop (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);
    1762                 :             : 
    1763                 :       18776 :   return bb;
    1764                 :             : }
    1765                 :             : 
    1766                 :             : /* Assemble thunks and aliases associated to node.  */
    1767                 :             : 
    1768                 :             : void
    1769                 :     1493587 : cgraph_node::assemble_thunks_and_aliases (void)
    1770                 :             : {
    1771                 :     1493587 :   cgraph_edge *e;
    1772                 :     1493587 :   ipa_ref *ref;
    1773                 :             : 
    1774                 :     2927351 :   for (e = callers; e;)
    1775                 :     1433764 :     if (e->caller->thunk
    1776                 :        1788 :         && !e->caller->inlined_to)
    1777                 :             :       {
    1778                 :        1764 :         cgraph_node *thunk = e->caller;
    1779                 :             : 
    1780                 :        1764 :         e = e->next_caller;
    1781                 :        1764 :         expand_thunk (thunk, !rtl_dump_and_exit, false);
    1782                 :        1764 :         thunk->assemble_thunks_and_aliases ();
    1783                 :        1764 :       }
    1784                 :             :     else
    1785                 :     1432000 :       e = e->next_caller;
    1786                 :             : 
    1787                 :     1553000 :   FOR_EACH_ALIAS (this, ref)
    1788                 :             :     {
    1789                 :       59413 :       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
    1790                 :       59413 :       if (!alias->transparent_alias)
    1791                 :             :         {
    1792                 :       59407 :           bool saved_written = TREE_ASM_WRITTEN (decl);
    1793                 :             : 
    1794                 :             :           /* Force assemble_alias to really output the alias this time instead
    1795                 :             :              of buffering it in same alias pairs.  */
    1796                 :       59407 :           TREE_ASM_WRITTEN (decl) = 1;
    1797                 :       59407 :           if (alias->symver)
    1798                 :           2 :             do_assemble_symver (alias->decl,
    1799                 :             :                                 DECL_ASSEMBLER_NAME (decl));
    1800                 :             :           else
    1801                 :       59405 :             do_assemble_alias (alias->decl,
    1802                 :             :                                DECL_ASSEMBLER_NAME (decl));
    1803                 :       59407 :           alias->assemble_thunks_and_aliases ();
    1804                 :       59407 :           TREE_ASM_WRITTEN (decl) = saved_written;
    1805                 :             :         }
    1806                 :             :     }
    1807                 :     1493587 : }
    1808                 :             : 
    1809                 :             : /* Expand function specified by node.  */
    1810                 :             : 
    1811                 :             : void
    1812                 :     1432530 : cgraph_node::expand (void)
    1813                 :             : {
    1814                 :     1432530 :   location_t saved_loc;
    1815                 :             : 
    1816                 :             :   /* We ought to not compile any inline clones.  */
    1817                 :     1432530 :   gcc_assert (!inlined_to);
    1818                 :             : 
    1819                 :             :   /* __RTL functions are compiled as soon as they are parsed, so don't
    1820                 :             :      do it again.  */
    1821                 :     1432530 :   if (native_rtl_p ())
    1822                 :             :     return;
    1823                 :             : 
    1824                 :     1432530 :   announce_function (decl);
    1825                 :     1432530 :   process = 0;
    1826                 :     1432530 :   gcc_assert (lowered);
    1827                 :             : 
    1828                 :             :   /* Initialize the default bitmap obstack.  */
    1829                 :     1432530 :   bitmap_obstack_initialize (NULL);
    1830                 :     1432530 :   get_untransformed_body ();
    1831                 :             : 
    1832                 :             :   /* Generate RTL for the body of DECL.  */
    1833                 :             : 
    1834                 :     1432530 :   timevar_push (TV_REST_OF_COMPILATION);
    1835                 :             : 
    1836                 :     1432530 :   gcc_assert (symtab->global_info_ready);
    1837                 :             : 
    1838                 :             :   /* Initialize the RTL code for the function.  */
    1839                 :     1432530 :   saved_loc = input_location;
    1840                 :     1432530 :   input_location = DECL_SOURCE_LOCATION (decl);
    1841                 :             : 
    1842                 :     1432530 :   gcc_assert (DECL_STRUCT_FUNCTION (decl));
    1843                 :     1432530 :   push_cfun (DECL_STRUCT_FUNCTION (decl));
    1844                 :     1432530 :   init_function_start (decl);
    1845                 :             : 
    1846                 :     1432530 :   gimple_register_cfg_hooks ();
    1847                 :             : 
    1848                 :     1432530 :   bitmap_obstack_initialize (&reg_obstack); /* FIXME, only at RTL generation*/
    1849                 :             : 
    1850                 :     1432530 :   update_ssa (TODO_update_ssa_only_virtuals);
    1851                 :     1432530 :   if (ipa_transforms_to_apply.exists ())
    1852                 :     1411912 :     execute_all_ipa_transforms (false);
    1853                 :             : 
    1854                 :             :   /* Perform all tree transforms and optimizations.  */
    1855                 :             : 
    1856                 :             :   /* Signal the start of passes.  */
    1857                 :     1432530 :   invoke_plugin_callbacks (PLUGIN_ALL_PASSES_START, NULL);
    1858                 :             : 
    1859                 :     1432530 :   execute_pass_list (cfun, g->get_passes ()->all_passes);
    1860                 :             : 
    1861                 :             :   /* Signal the end of passes.  */
    1862                 :     1432524 :   invoke_plugin_callbacks (PLUGIN_ALL_PASSES_END, NULL);
    1863                 :             : 
    1864                 :     1432524 :   bitmap_obstack_release (&reg_obstack);
    1865                 :             : 
    1866                 :             :   /* Release the default bitmap obstack.  */
    1867                 :     1432524 :   bitmap_obstack_release (NULL);
    1868                 :             : 
    1869                 :             :   /* If requested, warn about function definitions where the function will
    1870                 :             :      return a value (usually of some struct or union type) which itself will
    1871                 :             :      take up a lot of stack space.  */
    1872                 :     1432524 :   if (!DECL_EXTERNAL (decl) && TREE_TYPE (decl))
    1873                 :             :     {
    1874                 :     1432524 :       tree ret_type = TREE_TYPE (TREE_TYPE (decl));
    1875                 :             : 
    1876                 :     1432524 :       if (ret_type && TYPE_SIZE_UNIT (ret_type)
    1877                 :      766957 :           && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
    1878                 :     2199448 :           && compare_tree_int (TYPE_SIZE_UNIT (ret_type),
    1879                 :      766924 :                                warn_larger_than_size) > 0)
    1880                 :             :         {
    1881                 :           0 :           unsigned int size_as_int
    1882                 :           0 :             = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
    1883                 :             : 
    1884                 :           0 :           if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
    1885                 :           0 :             warning (OPT_Wlarger_than_,
    1886                 :             :                      "size of return value of %q+D is %u bytes",
    1887                 :             :                      decl, size_as_int);
    1888                 :             :           else
    1889                 :           0 :             warning (OPT_Wlarger_than_,
    1890                 :             :                      "size of return value of %q+D is larger than %wu bytes",
    1891                 :             :                      decl, warn_larger_than_size);
    1892                 :             :         }
    1893                 :             :     }
    1894                 :             : 
    1895                 :     1432524 :   gimple_set_body (decl, NULL);
    1896                 :     1432524 :   if (DECL_STRUCT_FUNCTION (decl) == 0)
    1897                 :             :     {
    1898                 :             :       /* Stop pointing to the local nodes about to be freed.
    1899                 :             :          But DECL_INITIAL must remain nonzero so we know this
    1900                 :             :          was an actual function definition.  */
    1901                 :          62 :       if (DECL_INITIAL (decl) != 0)
    1902                 :          62 :         DECL_INITIAL (decl) = error_mark_node;
    1903                 :             :     }
    1904                 :             : 
    1905                 :     1432524 :   input_location = saved_loc;
    1906                 :             : 
    1907                 :     1432524 :   ggc_collect ();
    1908                 :     1432524 :   timevar_pop (TV_REST_OF_COMPILATION);
    1909                 :             : 
    1910                 :     1432524 :   if (DECL_STRUCT_FUNCTION (decl)
    1911                 :     1432524 :       && DECL_STRUCT_FUNCTION (decl)->assume_function)
    1912                 :             :     {
    1913                 :             :       /* Assume functions aren't expanded into RTL, on the other side
    1914                 :             :          we don't want to release their body.  */
    1915                 :         108 :       if (cfun)
    1916                 :           0 :         pop_cfun ();
    1917                 :         108 :       return;
    1918                 :             :     }
    1919                 :             : 
    1920                 :             :   /* Make sure that BE didn't give up on compiling.  */
    1921                 :     1432416 :   gcc_assert (TREE_ASM_WRITTEN (decl));
    1922                 :     1432416 :   if (cfun)
    1923                 :     1432354 :     pop_cfun ();
    1924                 :             : 
    1925                 :             :   /* It would make a lot more sense to output thunks before function body to
    1926                 :             :      get more forward and fewer backward jumps.  This however would need
    1927                 :             :      solving problem with comdats.  See PR48668.  Also aliases must come after
    1928                 :             :      function itself to make one pass assemblers, like one on AIX, happy.
    1929                 :             :      See PR 50689.
    1930                 :             :      FIXME: Perhaps thunks should be move before function IFF they are not in
    1931                 :             :      comdat groups.  */
    1932                 :     1432416 :   assemble_thunks_and_aliases ();
    1933                 :     1432416 :   release_body ();
    1934                 :             : }
    1935                 :             : 
    1936                 :             : /* Node comparator that is responsible for the order that corresponds
    1937                 :             :    to time when a function was launched for the first time.  */
    1938                 :             : 
    1939                 :             : int
    1940                 :      843215 : tp_first_run_node_cmp (const void *pa, const void *pb)
    1941                 :             : {
    1942                 :      843215 :   const cgraph_node *a = *(const cgraph_node * const *) pa;
    1943                 :      843215 :   const cgraph_node *b = *(const cgraph_node * const *) pb;
    1944                 :      843215 :   unsigned int tp_first_run_a = a->tp_first_run;
    1945                 :      843215 :   unsigned int tp_first_run_b = b->tp_first_run;
    1946                 :             : 
    1947                 :      843215 :   if (!opt_for_fn (a->decl, flag_profile_reorder_functions)
    1948                 :      843215 :       || a->no_reorder)
    1949                 :             :     tp_first_run_a = 0;
    1950                 :      843215 :   if (!opt_for_fn (b->decl, flag_profile_reorder_functions)
    1951                 :      843215 :       || b->no_reorder)
    1952                 :             :     tp_first_run_b = 0;
    1953                 :             : 
    1954                 :      843215 :   if (tp_first_run_a == tp_first_run_b)
    1955                 :      841709 :     return a->order - b->order;
    1956                 :             : 
    1957                 :             :   /* Functions with time profile must be before these without profile.  */
    1958                 :        1506 :   tp_first_run_a = (tp_first_run_a - 1) & INT_MAX;
    1959                 :        1506 :   tp_first_run_b = (tp_first_run_b - 1) & INT_MAX;
    1960                 :             : 
    1961                 :        1506 :   return tp_first_run_a - tp_first_run_b;
    1962                 :             : }
    1963                 :             : 
    1964                 :             : /* Expand all functions that must be output.
    1965                 :             : 
    1966                 :             :    Attempt to topologically sort the nodes so function is output when
    1967                 :             :    all called functions are already assembled to allow data to be
    1968                 :             :    propagated across the callgraph.  Use a stack to get smaller distance
    1969                 :             :    between a function and its callees (later we may choose to use a more
    1970                 :             :    sophisticated algorithm for function reordering; we will likely want
    1971                 :             :    to use subsections to make the output functions appear in top-down
    1972                 :             :    order).  */
    1973                 :             : 
    1974                 :             : static void
    1975                 :      227030 : expand_all_functions (void)
    1976                 :             : {
    1977                 :      227030 :   cgraph_node *node;
    1978                 :      227030 :   cgraph_node **order = XCNEWVEC (cgraph_node *,
    1979                 :             :                                          symtab->cgraph_count);
    1980                 :      227030 :   cgraph_node **tp_first_run_order = XCNEWVEC (cgraph_node *,
    1981                 :             :                                          symtab->cgraph_count);
    1982                 :      227030 :   unsigned int expanded_func_count = 0, profiled_func_count = 0;
    1983                 :      227030 :   int order_pos, tp_first_run_order_pos = 0, new_order_pos = 0;
    1984                 :      227030 :   int i;
    1985                 :             : 
    1986                 :      227030 :   order_pos = ipa_reverse_postorder (order);
    1987                 :      227030 :   gcc_assert (order_pos == symtab->cgraph_count);
    1988                 :             : 
    1989                 :             :   /* Garbage collector may remove inline clones we eliminate during
    1990                 :             :      optimization.  So we must be sure to not reference them.  */
    1991                 :     4550247 :   for (i = 0; i < order_pos; i++)
    1992                 :     4323217 :     if (order[i]->process)
    1993                 :             :       {
    1994                 :      902631 :         if (order[i]->tp_first_run
    1995                 :      902631 :             && opt_for_fn (order[i]->decl, flag_profile_reorder_functions))
    1996                 :         226 :           tp_first_run_order[tp_first_run_order_pos++] = order[i];
    1997                 :             :         else
    1998                 :      902405 :           order[new_order_pos++] = order[i];
    1999                 :             :       }
    2000                 :             : 
    2001                 :             :   /* First output functions with time profile in specified order.  */
    2002                 :      227030 :   qsort (tp_first_run_order, tp_first_run_order_pos,
    2003                 :             :          sizeof (cgraph_node *), tp_first_run_node_cmp);
    2004                 :      454286 :   for (i = 0; i < tp_first_run_order_pos; i++)
    2005                 :             :     {
    2006                 :         226 :       node = tp_first_run_order[i];
    2007                 :             : 
    2008                 :         226 :       if (node->process)
    2009                 :             :         {
    2010                 :         226 :           expanded_func_count++;
    2011                 :         226 :           profiled_func_count++;
    2012                 :             : 
    2013                 :         226 :           if (symtab->dump_file)
    2014                 :           0 :             fprintf (symtab->dump_file,
    2015                 :             :                      "Time profile order in expand_all_functions:%s:%d\n",
    2016                 :             :                      node->dump_asm_name (), node->tp_first_run);
    2017                 :         226 :           node->process = 0;
    2018                 :         226 :           node->expand ();
    2019                 :             :         }
    2020                 :             :     }
    2021                 :             : 
    2022                 :             :   /* Output functions in RPO so callees get optimized before callers.  This
    2023                 :             :      makes ipa-ra and other propagators to work.
    2024                 :             :      FIXME: This is far from optimal code layout.
    2025                 :             :      Make multiple passes over the list to defer processing of gc
    2026                 :             :      candidates until all potential uses are seen.  */
    2027                 :             :   int gc_candidates = 0;
    2028                 :             :   int prev_gc_candidates = 0;
    2029                 :             : 
    2030                 :      227077 :   while (1)
    2031                 :             :     {
    2032                 :     1130067 :       for (i = new_order_pos - 1; i >= 0; i--)
    2033                 :             :         {
    2034                 :      902990 :           node = order[i];
    2035                 :             : 
    2036                 :      902990 :           if (node->gc_candidate)
    2037                 :         166 :             gc_candidates++;
    2038                 :      902824 :           else if (node->process)
    2039                 :             :             {
    2040                 :      902341 :               expanded_func_count++;
    2041                 :      902341 :               node->process = 0;
    2042                 :      902341 :               node->expand ();
    2043                 :             :             }
    2044                 :             :         }
    2045                 :      227077 :       if (!gc_candidates || gc_candidates == prev_gc_candidates)
    2046                 :             :         break;
    2047                 :             :       prev_gc_candidates = gc_candidates;
    2048                 :             :       gc_candidates = 0;
    2049                 :             :     }
    2050                 :             : 
    2051                 :             :   /* Free any unused gc_candidate functions.  */
    2052                 :      227030 :   if (gc_candidates)
    2053                 :         374 :     for (i = new_order_pos - 1; i >= 0; i--)
    2054                 :             :       {
    2055                 :         342 :         node = order[i];
    2056                 :         342 :         if (node->gc_candidate)
    2057                 :             :           {
    2058                 :          64 :             struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
    2059                 :          64 :             if (symtab->dump_file)
    2060                 :           8 :               fprintf (symtab->dump_file,
    2061                 :             :                        "Deleting unused function %s\n",
    2062                 :           4 :                        IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
    2063                 :          64 :             node->process = false;
    2064                 :          64 :             free_dominance_info (fn, CDI_DOMINATORS);
    2065                 :          64 :             free_dominance_info (fn, CDI_POST_DOMINATORS);
    2066                 :          64 :             node->release_body (false);
    2067                 :             :           }
    2068                 :             :       }
    2069                 :             : 
    2070                 :      227030 :   if (dump_file)
    2071                 :           0 :     fprintf (dump_file, "Expanded functions with time profile (%s):%u/%u\n",
    2072                 :             :              main_input_filename, profiled_func_count, expanded_func_count);
    2073                 :             : 
    2074                 :      227030 :   if (symtab->dump_file && tp_first_run_order_pos)
    2075                 :           0 :     fprintf (symtab->dump_file, "Expanded functions with time profile:%u/%u\n",
    2076                 :             :              profiled_func_count, expanded_func_count);
    2077                 :             : 
    2078                 :      227030 :   symtab->process_new_functions ();
    2079                 :      227030 :   free_gimplify_stack ();
    2080                 :      227030 :   delete ipa_saved_clone_sources;
    2081                 :      227030 :   ipa_saved_clone_sources = NULL;
    2082                 :      227030 :   free (order);
    2083                 :      227030 :   free (tp_first_run_order);
    2084                 :      227030 : }
    2085                 :             : 
    2086                 :             : /* This is used to sort the node types by the cgraph order number.  */
    2087                 :             : 
    2088                 :             : enum cgraph_order_sort_kind
    2089                 :             : {
    2090                 :             :   ORDER_FUNCTION,
    2091                 :             :   ORDER_VAR,
    2092                 :             :   ORDER_VAR_UNDEF,
    2093                 :             :   ORDER_ASM
    2094                 :             : };
    2095                 :             : 
    2096                 :             : struct cgraph_order_sort
    2097                 :             : {
    2098                 :             :   /* Construct from a cgraph_node.  */
    2099                 :      525804 :   cgraph_order_sort (cgraph_node *node)
    2100                 :      525804 :   : kind (ORDER_FUNCTION), order (node->order)
    2101                 :             :   {
    2102                 :      525804 :     u.f = node;
    2103                 :             :   }
    2104                 :             : 
    2105                 :             :   /* Construct from a varpool_node.  */
    2106                 :      981863 :   cgraph_order_sort (varpool_node *node)
    2107                 :     1963726 :   : kind (node->definition ? ORDER_VAR : ORDER_VAR_UNDEF), order (node->order)
    2108                 :             :   {
    2109                 :      981863 :     u.v = node;
    2110                 :             :   }
    2111                 :             : 
    2112                 :             :   /* Construct from a asm_node.  */
    2113                 :       12328 :   cgraph_order_sort (asm_node *node)
    2114                 :       12328 :   : kind (ORDER_ASM), order (node->order)
    2115                 :             :   {
    2116                 :       12328 :     u.a = node;
    2117                 :             :   }
    2118                 :             : 
    2119                 :             :   /* Assembly cgraph_order_sort based on its type.  */
    2120                 :             :   void process ();
    2121                 :             : 
    2122                 :             :   enum cgraph_order_sort_kind kind;
    2123                 :             :   union
    2124                 :             :   {
    2125                 :             :     cgraph_node *f;
    2126                 :             :     varpool_node *v;
    2127                 :             :     asm_node *a;
    2128                 :             :   } u;
    2129                 :             :   int order;
    2130                 :             : };
    2131                 :             : 
    2132                 :             : /* Assembly cgraph_order_sort based on its type.  */
    2133                 :             : 
    2134                 :             : void
    2135                 :     1519995 : cgraph_order_sort::process ()
    2136                 :             : {
    2137                 :     1519995 :   switch (kind)
    2138                 :             :     {
    2139                 :      525804 :     case ORDER_FUNCTION:
    2140                 :      525804 :       u.f->process = 0;
    2141                 :      525804 :       u.f->expand ();
    2142                 :      525804 :       break;
    2143                 :      981361 :     case ORDER_VAR:
    2144                 :      981361 :       u.v->assemble_decl ();
    2145                 :      981361 :       break;
    2146                 :         502 :     case ORDER_VAR_UNDEF:
    2147                 :         502 :       assemble_undefined_decl (u.v->decl);
    2148                 :         502 :       break;
    2149                 :       12328 :     case ORDER_ASM:
    2150                 :       12328 :       assemble_asm (u.a->asm_str);
    2151                 :       12328 :       break;
    2152                 :           0 :     default:
    2153                 :           0 :       gcc_unreachable ();
    2154                 :             :     }
    2155                 :     1519989 : }
    2156                 :             : 
    2157                 :             : /* Compare cgraph_order_sort by order.  */
    2158                 :             : 
    2159                 :             : static int
    2160                 :    62577383 : cgraph_order_cmp (const void *a_p, const void *b_p)
    2161                 :             : {
    2162                 :    62577383 :   const cgraph_order_sort *nodea = (const cgraph_order_sort *)a_p;
    2163                 :    62577383 :   const cgraph_order_sort *nodeb = (const cgraph_order_sort *)b_p;
    2164                 :             : 
    2165                 :    62577383 :   return nodea->order - nodeb->order;
    2166                 :             : }
    2167                 :             : 
    2168                 :             : /* Output all functions, variables, and asm statements in the order
    2169                 :             :    according to their order fields, which is the order in which they
    2170                 :             :    appeared in the file.  This implements -fno-toplevel-reorder.  In
    2171                 :             :    this mode we may output functions and variables which don't really
    2172                 :             :    need to be output.  */
    2173                 :             : 
    2174                 :             : static void
    2175                 :      227036 : output_in_order (void)
    2176                 :             : {
    2177                 :      227036 :   int i;
    2178                 :      227036 :   cgraph_node *cnode;
    2179                 :      227036 :   varpool_node *vnode;
    2180                 :      227036 :   asm_node *anode;
    2181                 :      227036 :   auto_vec<cgraph_order_sort> nodes;
    2182                 :      227036 :   cgraph_order_sort *node;
    2183                 :             : 
    2184                 :     2853571 :   FOR_EACH_DEFINED_FUNCTION (cnode)
    2185                 :     2626535 :     if (cnode->process && !cnode->thunk
    2186                 :     1428435 :         && !cnode->alias && cnode->no_reorder)
    2187                 :      525804 :       nodes.safe_push (cgraph_order_sort (cnode));
    2188                 :             : 
    2189                 :             :   /* There is a similar loop in symbol_table::output_variables.
    2190                 :             :      Please keep them in sync.  */
    2191                 :     6720084 :   FOR_EACH_VARIABLE (vnode)
    2192                 :     3133006 :     if (vnode->no_reorder
    2193                 :      981885 :         && !DECL_HARD_REGISTER (vnode->decl)
    2194                 :     4114869 :         && !DECL_HAS_VALUE_EXPR_P (vnode->decl))
    2195                 :      982365 :       nodes.safe_push (cgraph_order_sort (vnode));
    2196                 :             : 
    2197                 :      239364 :   for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
    2198                 :       12328 :     nodes.safe_push (cgraph_order_sort (anode));
    2199                 :             : 
    2200                 :             :   /* Sort nodes by order.  */
    2201                 :      227036 :   nodes.qsort (cgraph_order_cmp);
    2202                 :             : 
    2203                 :             :   /* In toplevel reorder mode we output all statics; mark them as needed.  */
    2204                 :     1747031 :   FOR_EACH_VEC_ELT (nodes, i, node)
    2205                 :     1519995 :     if (node->kind == ORDER_VAR)
    2206                 :      981361 :       node->u.v->finalize_named_section_flags ();
    2207                 :             : 
    2208                 :     1747025 :   FOR_EACH_VEC_ELT (nodes, i, node)
    2209                 :     1519995 :     node->process ();
    2210                 :             : 
    2211                 :      227030 :   symtab->clear_asm_symbols ();
    2212                 :      227030 : }
    2213                 :             : 
    2214                 :             : static void
    2215                 :      240593 : ipa_passes (void)
    2216                 :             : {
    2217                 :      240593 :   gcc::pass_manager *passes = g->get_passes ();
    2218                 :             : 
    2219                 :      240593 :   set_cfun (NULL);
    2220                 :      240593 :   current_function_decl = NULL;
    2221                 :      240593 :   gimple_register_cfg_hooks ();
    2222                 :      240593 :   bitmap_obstack_initialize (NULL);
    2223                 :             : 
    2224                 :      240593 :   invoke_plugin_callbacks (PLUGIN_ALL_IPA_PASSES_START, NULL);
    2225                 :             : 
    2226                 :      240593 :   if (!in_lto_p)
    2227                 :             :     {
    2228                 :      227253 :       execute_ipa_pass_list (passes->all_small_ipa_passes);
    2229                 :      227253 :       if (seen_error ())
    2230                 :             :         return;
    2231                 :             :     }
    2232                 :             : 
    2233                 :             :   /* This extra symtab_remove_unreachable_nodes pass tends to catch some
    2234                 :             :      devirtualization and other changes where removal iterate.  */
    2235                 :      240451 :   symtab->remove_unreachable_nodes (symtab->dump_file);
    2236                 :             : 
    2237                 :             :   /* If pass_all_early_optimizations was not scheduled, the state of
    2238                 :             :      the cgraph will not be properly updated.  Update it now.  */
    2239                 :      240451 :   if (symtab->state < IPA_SSA)
    2240                 :       13340 :     symtab->state = IPA_SSA;
    2241                 :             : 
    2242                 :      240451 :   if (!in_lto_p)
    2243                 :             :     {
    2244                 :             :       /* Generate coverage variables and constructors.  */
    2245                 :      227111 :       coverage_finish ();
    2246                 :             : 
    2247                 :             :       /* Process new functions added.  */
    2248                 :      227111 :       set_cfun (NULL);
    2249                 :      227111 :       current_function_decl = NULL;
    2250                 :      227111 :       symtab->process_new_functions ();
    2251                 :             : 
    2252                 :      227111 :       execute_ipa_summary_passes
    2253                 :      227111 :         ((ipa_opt_pass_d *) passes->all_regular_ipa_passes);
    2254                 :             :     }
    2255                 :             : 
    2256                 :             :   /* Some targets need to handle LTO assembler output specially.  */
    2257                 :      240451 :   if (flag_generate_lto || flag_generate_offload)
    2258                 :       23943 :     targetm.asm_out.lto_start ();
    2259                 :             : 
    2260                 :      240451 :   if (!in_lto_p
    2261                 :       13340 :       || flag_incremental_link == INCREMENTAL_LINK_LTO)
    2262                 :             :     {
    2263                 :      227144 :       if (!quiet_flag)
    2264                 :           0 :         fprintf (stderr, "Streaming LTO\n");
    2265                 :      227144 :       if (g->have_offload)
    2266                 :             :         {
    2267                 :           0 :           section_name_prefix = OFFLOAD_SECTION_NAME_PREFIX;
    2268                 :           0 :           lto_stream_offload_p = true;
    2269                 :           0 :           ipa_write_summaries ();
    2270                 :           0 :           lto_stream_offload_p = false;
    2271                 :             :         }
    2272                 :      227144 :       if (flag_lto)
    2273                 :             :         {
    2274                 :       23943 :           section_name_prefix = LTO_SECTION_NAME_PREFIX;
    2275                 :       23943 :           lto_stream_offload_p = false;
    2276                 :       23943 :           ipa_write_summaries ();
    2277                 :             :         }
    2278                 :             :     }
    2279                 :             : 
    2280                 :      240451 :   if (flag_generate_lto || flag_generate_offload)
    2281                 :       23943 :     targetm.asm_out.lto_end ();
    2282                 :             : 
    2283                 :      240451 :   if (!flag_ltrans
    2284                 :      231330 :       && ((in_lto_p && flag_incremental_link != INCREMENTAL_LINK_LTO)
    2285                 :      227144 :           || !flag_lto || flag_fat_lto_objects))
    2286                 :      217924 :     execute_ipa_pass_list (passes->all_regular_ipa_passes);
    2287                 :      240451 :   invoke_plugin_callbacks (PLUGIN_ALL_IPA_PASSES_END, NULL);
    2288                 :             : 
    2289                 :      240451 :   bitmap_obstack_release (NULL);
    2290                 :             : }
    2291                 :             : 
    2292                 :             : 
    2293                 :             : /* Weakrefs may be associated to external decls and thus not output
    2294                 :             :    at expansion time.  Emit all necessary aliases.  */
    2295                 :             : 
    2296                 :             : void
    2297                 :      227030 : symbol_table::output_weakrefs (void)
    2298                 :             : {
    2299                 :      227030 :   symtab_node *node;
    2300                 :     6563344 :   FOR_EACH_SYMBOL (node)
    2301                 :     6336314 :     if (node->alias
    2302                 :       64682 :         && !TREE_ASM_WRITTEN (node->decl)
    2303                 :         779 :         && node->weakref)
    2304                 :             :       {
    2305                 :         127 :         tree target;
    2306                 :             : 
    2307                 :             :         /* Weakrefs are special by not requiring target definition in current
    2308                 :             :            compilation unit.  It is thus bit hard to work out what we want to
    2309                 :             :            alias.
    2310                 :             :            When alias target is defined, we need to fetch it from symtab reference,
    2311                 :             :            otherwise it is pointed to by alias_target.  */
    2312                 :         127 :         if (node->alias_target)
    2313                 :         122 :           target = (DECL_P (node->alias_target)
    2314                 :         122 :                     ? DECL_ASSEMBLER_NAME (node->alias_target)
    2315                 :             :                     : node->alias_target);
    2316                 :           5 :         else if (node->analyzed)
    2317                 :           5 :           target = DECL_ASSEMBLER_NAME (node->get_alias_target ()->decl);
    2318                 :             :         else
    2319                 :           0 :           gcc_unreachable ();
    2320                 :         127 :         do_assemble_alias (node->decl, target);
    2321                 :             :       }
    2322                 :      227030 : }
    2323                 :             : 
    2324                 :             : /* Perform simple optimizations based on callgraph.  */
    2325                 :             : 
    2326                 :             : void
    2327                 :      265481 : symbol_table::compile (void)
    2328                 :             : {
    2329                 :      265481 :   if (seen_error ())
    2330                 :             :     return;
    2331                 :             : 
    2332                 :      240593 :   symtab_node::checking_verify_symtab_nodes ();
    2333                 :             : 
    2334                 :      240593 :   symtab_node::check_ifunc_callee_symtab_nodes ();
    2335                 :             : 
    2336                 :      240593 :   timevar_push (TV_CGRAPHOPT);
    2337                 :      240593 :   if (pre_ipa_mem_report)
    2338                 :           0 :     dump_memory_report ("Memory consumption before IPA");
    2339                 :      240593 :   if (!quiet_flag)
    2340                 :           0 :     fprintf (stderr, "Performing interprocedural optimizations\n");
    2341                 :      240593 :   state = IPA;
    2342                 :             : 
    2343                 :             :   /* If LTO is enabled, initialize the streamer hooks needed by GIMPLE.  */
    2344                 :      240593 :   if (flag_generate_lto || flag_generate_offload)
    2345                 :       23955 :     lto_streamer_hooks_init ();
    2346                 :             : 
    2347                 :             :   /* Don't run the IPA passes if there was any error or sorry messages.  */
    2348                 :      240593 :   if (!seen_error ())
    2349                 :             :   {
    2350                 :      240593 :     timevar_start (TV_CGRAPH_IPA_PASSES);
    2351                 :      240593 :     ipa_passes ();
    2352                 :      240593 :     timevar_stop (TV_CGRAPH_IPA_PASSES);
    2353                 :             :   }
    2354                 :             :   /* Do nothing else if any IPA pass found errors or if we are just streaming LTO.  */
    2355                 :      240593 :   if (seen_error ()
    2356                 :      240593 :       || ((!in_lto_p || flag_incremental_link == INCREMENTAL_LINK_LTO)
    2357                 :      227135 :           && flag_lto && !flag_fat_lto_objects))
    2358                 :             :     {
    2359                 :       13557 :       timevar_pop (TV_CGRAPHOPT);
    2360                 :       13557 :       return;
    2361                 :             :     }
    2362                 :             : 
    2363                 :      227036 :   global_info_ready = true;
    2364                 :      227036 :   if (dump_file)
    2365                 :             :     {
    2366                 :          72 :       fprintf (dump_file, "Optimized ");
    2367                 :          72 :       symtab->dump (dump_file);
    2368                 :             :     }
    2369                 :      227036 :   if (post_ipa_mem_report)
    2370                 :           0 :     dump_memory_report ("Memory consumption after IPA");
    2371                 :      227036 :   timevar_pop (TV_CGRAPHOPT);
    2372                 :             : 
    2373                 :             :   /* Output everything.  */
    2374                 :      227036 :   switch_to_section (text_section);
    2375                 :      227036 :   (*debug_hooks->assembly_start) ();
    2376                 :      227036 :   if (!quiet_flag)
    2377                 :           0 :     fprintf (stderr, "Assembling functions:\n");
    2378                 :      227036 :   symtab_node::checking_verify_symtab_nodes ();
    2379                 :             : 
    2380                 :      227036 :   bitmap_obstack_initialize (NULL);
    2381                 :      227036 :   execute_ipa_pass_list (g->get_passes ()->all_late_ipa_passes);
    2382                 :      227036 :   bitmap_obstack_release (NULL);
    2383                 :      227036 :   mark_functions_to_output ();
    2384                 :             : 
    2385                 :             :   /* When weakref support is missing, we automatically translate all
    2386                 :             :      references to NODE to references to its ultimate alias target.
    2387                 :             :      The renaming mechanism uses flag IDENTIFIER_TRANSPARENT_ALIAS and
    2388                 :             :      TREE_CHAIN.
    2389                 :             : 
    2390                 :             :      Set up this mapping before we output any assembler but once we are sure
    2391                 :             :      that all symbol renaming is done.
    2392                 :             : 
    2393                 :             :      FIXME: All this ugliness can go away if we just do renaming at gimple
    2394                 :             :      level by physically rewriting the IL.  At the moment we can only redirect
    2395                 :             :      calls, so we need infrastructure for renaming references as well.  */
    2396                 :             : #ifndef ASM_OUTPUT_WEAKREF
    2397                 :             :   symtab_node *node;
    2398                 :             : 
    2399                 :             :   FOR_EACH_SYMBOL (node)
    2400                 :             :     if (node->alias
    2401                 :             :         && lookup_attribute ("weakref", DECL_ATTRIBUTES (node->decl)))
    2402                 :             :       {
    2403                 :             :         IDENTIFIER_TRANSPARENT_ALIAS
    2404                 :             :            (DECL_ASSEMBLER_NAME (node->decl)) = 1;
    2405                 :             :         TREE_CHAIN (DECL_ASSEMBLER_NAME (node->decl))
    2406                 :             :            = (node->alias_target ? node->alias_target
    2407                 :             :               : DECL_ASSEMBLER_NAME (node->get_alias_target ()->decl));
    2408                 :             :       }
    2409                 :             : #endif
    2410                 :             : 
    2411                 :      227036 :   state = EXPANSION;
    2412                 :             : 
    2413                 :             :   /* Output first asm statements and anything ordered. The process
    2414                 :             :      flag is cleared for these nodes, so we skip them later.  */
    2415                 :      227036 :   output_in_order ();
    2416                 :             : 
    2417                 :      227030 :   timevar_start (TV_CGRAPH_FUNC_EXPANSION);
    2418                 :      227030 :   expand_all_functions ();
    2419                 :      227030 :   timevar_stop (TV_CGRAPH_FUNC_EXPANSION);
    2420                 :             : 
    2421                 :      227030 :   output_variables ();
    2422                 :             : 
    2423                 :      227030 :   process_new_functions ();
    2424                 :      227030 :   state = FINISHED;
    2425                 :      227030 :   output_weakrefs ();
    2426                 :             : 
    2427                 :      227030 :   if (dump_file)
    2428                 :             :     {
    2429                 :          72 :       fprintf (dump_file, "\nFinal ");
    2430                 :          72 :       symtab->dump (dump_file);
    2431                 :             :     }
    2432                 :      227030 :   if (!flag_checking)
    2433                 :             :     return;
    2434                 :      227016 :   symtab_node::verify_symtab_nodes ();
    2435                 :             :   /* Double check that all inline clones are gone and that all
    2436                 :             :      function bodies have been released from memory.  */
    2437                 :      227016 :   if (!seen_error ())
    2438                 :             :     {
    2439                 :      226756 :       cgraph_node *node;
    2440                 :      226756 :       bool error_found = false;
    2441                 :             : 
    2442                 :     1716368 :       FOR_EACH_DEFINED_FUNCTION (node)
    2443                 :     1489612 :         if (node->inlined_to
    2444                 :     1489612 :             || gimple_has_body_p (node->decl))
    2445                 :             :           {
    2446                 :         108 :             if (DECL_STRUCT_FUNCTION (node->decl)
    2447                 :         108 :                 && (DECL_STRUCT_FUNCTION (node->decl)->curr_properties
    2448                 :         108 :                     & PROP_assumptions_done) != 0)
    2449                 :         108 :               continue;
    2450                 :           0 :             error_found = true;
    2451                 :           0 :             node->debug ();
    2452                 :             :           }
    2453                 :      226756 :       if (error_found)
    2454                 :           0 :         internal_error ("nodes with unreleased memory found");
    2455                 :             :     }
    2456                 :             : }
    2457                 :             : 
    2458                 :             : /* Earlydebug dump file, flags, and number.  */
    2459                 :             : 
    2460                 :             : static int debuginfo_early_dump_nr;
    2461                 :             : static FILE *debuginfo_early_dump_file;
    2462                 :             : static dump_flags_t debuginfo_early_dump_flags;
    2463                 :             : 
    2464                 :             : /* Debug dump file, flags, and number.  */
    2465                 :             : 
    2466                 :             : static int debuginfo_dump_nr;
    2467                 :             : static FILE *debuginfo_dump_file;
    2468                 :             : static dump_flags_t debuginfo_dump_flags;
    2469                 :             : 
    2470                 :             : /* Register the debug and earlydebug dump files.  */
    2471                 :             : 
    2472                 :             : void
    2473                 :      282866 : debuginfo_early_init (void)
    2474                 :             : {
    2475                 :      282866 :   gcc::dump_manager *dumps = g->get_dumps ();
    2476                 :      282866 :   debuginfo_early_dump_nr = dumps->dump_register (".earlydebug", "earlydebug",
    2477                 :             :                                                   "earlydebug", DK_tree,
    2478                 :             :                                                   OPTGROUP_NONE,
    2479                 :             :                                                   false);
    2480                 :      282866 :   debuginfo_dump_nr = dumps->dump_register (".debug", "debug",
    2481                 :             :                                              "debug", DK_tree,
    2482                 :             :                                              OPTGROUP_NONE,
    2483                 :             :                                              false);
    2484                 :      282866 : }
    2485                 :             : 
    2486                 :             : /* Initialize the debug and earlydebug dump files.  */
    2487                 :             : 
    2488                 :             : void
    2489                 :      276515 : debuginfo_init (void)
    2490                 :             : {
    2491                 :      276515 :   gcc::dump_manager *dumps = g->get_dumps ();
    2492                 :      276515 :   debuginfo_dump_file = dump_begin (debuginfo_dump_nr, NULL);
    2493                 :      276515 :   debuginfo_dump_flags = dumps->get_dump_file_info (debuginfo_dump_nr)->pflags;
    2494                 :      276515 :   debuginfo_early_dump_file = dump_begin (debuginfo_early_dump_nr, NULL);
    2495                 :      276515 :   debuginfo_early_dump_flags
    2496                 :      276515 :     = dumps->get_dump_file_info (debuginfo_early_dump_nr)->pflags;
    2497                 :      276515 : }
    2498                 :             : 
    2499                 :             : /* Finalize the debug and earlydebug dump files.  */
    2500                 :             : 
    2501                 :             : void
    2502                 :      274826 : debuginfo_fini (void)
    2503                 :             : {
    2504                 :      274826 :   if (debuginfo_dump_file)
    2505                 :          46 :     dump_end (debuginfo_dump_nr, debuginfo_dump_file);
    2506                 :      274826 :   if (debuginfo_early_dump_file)
    2507                 :          46 :     dump_end (debuginfo_early_dump_nr, debuginfo_early_dump_file);
    2508                 :      274826 : }
    2509                 :             : 
    2510                 :             : /* Set dump_file to the debug dump file.  */
    2511                 :             : 
    2512                 :             : void
    2513                 :      226770 : debuginfo_start (void)
    2514                 :             : {
    2515                 :      226770 :   set_dump_file (debuginfo_dump_file);
    2516                 :      226770 : }
    2517                 :             : 
    2518                 :             : /* Undo setting dump_file to the debug dump file.  */
    2519                 :             : 
    2520                 :             : void
    2521                 :      226770 : debuginfo_stop (void)
    2522                 :             : {
    2523                 :      226770 :   set_dump_file (NULL);
    2524                 :      226770 : }
    2525                 :             : 
    2526                 :             : /* Set dump_file to the earlydebug dump file.  */
    2527                 :             : 
    2528                 :             : void
    2529                 :      240593 : debuginfo_early_start (void)
    2530                 :             : {
    2531                 :      240593 :   set_dump_file (debuginfo_early_dump_file);
    2532                 :      240593 : }
    2533                 :             : 
    2534                 :             : /* Undo setting dump_file to the earlydebug dump file.  */
    2535                 :             : 
    2536                 :             : void
    2537                 :      240593 : debuginfo_early_stop (void)
    2538                 :             : {
    2539                 :      240593 :   set_dump_file (NULL);
    2540                 :      240593 : }
    2541                 :             : 
    2542                 :             : /* Analyze the whole compilation unit once it is parsed completely.  */
    2543                 :             : 
    2544                 :             : void
    2545                 :      252155 : symbol_table::finalize_compilation_unit (void)
    2546                 :             : {
    2547                 :      252155 :   timevar_push (TV_CGRAPH);
    2548                 :             : 
    2549                 :             :   /* If we're here there's no current function anymore.  Some frontends
    2550                 :             :      are lazy in clearing these.  */
    2551                 :      252155 :   current_function_decl = NULL;
    2552                 :      252155 :   set_cfun (NULL);
    2553                 :             : 
    2554                 :             :   /* Do not skip analyzing the functions if there were errors, we
    2555                 :             :      miss diagnostics for following functions otherwise.  */
    2556                 :             : 
    2557                 :             :   /* Emit size functions we didn't inline.  */
    2558                 :      252155 :   finalize_size_functions ();
    2559                 :             : 
    2560                 :             :   /* Mark alias targets necessary and emit diagnostics.  */
    2561                 :      252155 :   handle_alias_pairs ();
    2562                 :             : 
    2563                 :      252155 :   if (!quiet_flag)
    2564                 :             :     {
    2565                 :           0 :       fprintf (stderr, "\nAnalyzing compilation unit\n");
    2566                 :           0 :       fflush (stderr);
    2567                 :             :     }
    2568                 :             : 
    2569                 :      252155 :   if (flag_dump_passes)
    2570                 :           5 :     dump_passes ();
    2571                 :             : 
    2572                 :             :   /* Gimplify and lower all functions, compute reachability and
    2573                 :             :      remove unreachable nodes.  */
    2574                 :      252155 :   analyze_functions (/*first_time=*/true);
    2575                 :             : 
    2576                 :             :   /* Mark alias targets necessary and emit diagnostics.  */
    2577                 :      252141 :   handle_alias_pairs ();
    2578                 :             : 
    2579                 :             :   /* Gimplify and lower thunks.  */
    2580                 :      252141 :   analyze_functions (/*first_time=*/false);
    2581                 :             : 
    2582                 :             :   /* All nested functions should be lowered now.  */
    2583                 :      252141 :   nested_function_info::release ();
    2584                 :             : 
    2585                 :             :   /* Offloading requires LTO infrastructure.  */
    2586                 :      252141 :   if (!in_lto_p && g->have_offload)
    2587                 :           0 :     flag_generate_offload = 1;
    2588                 :             : 
    2589                 :      252141 :   if (!seen_error ())
    2590                 :             :     {
    2591                 :             :       /* Give the frontends the chance to emit early debug based on
    2592                 :             :          what is still reachable in the TU.  */
    2593                 :      227253 :       (*lang_hooks.finalize_early_debug) ();
    2594                 :             : 
    2595                 :             :       /* Clean up anything that needs cleaning up after initial debug
    2596                 :             :          generation.  */
    2597                 :      227253 :       debuginfo_early_start ();
    2598                 :      227253 :       (*debug_hooks->early_finish) (main_input_filename);
    2599                 :      227253 :       debuginfo_early_stop ();
    2600                 :             :     }
    2601                 :             : 
    2602                 :             :   /* Finally drive the pass manager.  */
    2603                 :      252141 :   compile ();
    2604                 :             : 
    2605                 :      252135 :   timevar_pop (TV_CGRAPH);
    2606                 :      252135 : }
    2607                 :             : 
    2608                 :             : /* Reset all state within cgraphunit.cc so that we can rerun the compiler
    2609                 :             :    within the same process.  For use by toplev::finalize.  */
    2610                 :             : 
    2611                 :             : void
    2612                 :      255021 : cgraphunit_cc_finalize (void)
    2613                 :             : {
    2614                 :      255021 :   gcc_assert (cgraph_new_nodes.length () == 0);
    2615                 :      255021 :   cgraph_new_nodes.truncate (0);
    2616                 :             : 
    2617                 :      255021 :   queued_nodes = &symtab_terminator;
    2618                 :             : 
    2619                 :      255021 :   first_analyzed = NULL;
    2620                 :      255021 :   first_analyzed_var = NULL;
    2621                 :      255021 : }
    2622                 :             : 
    2623                 :             : /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
    2624                 :             :    kind of wrapper method.  */
    2625                 :             : 
    2626                 :             : void
    2627                 :       16855 : cgraph_node::create_wrapper (cgraph_node *target)
    2628                 :             : {
    2629                 :             :   /* Preserve DECL_RESULT so we get right by reference flag.  */
    2630                 :       16855 :   tree decl_result = DECL_RESULT (decl);
    2631                 :             : 
    2632                 :             :   /* Remove the function's body but keep arguments to be reused
    2633                 :             :      for thunk.  */
    2634                 :       16855 :   release_body (true);
    2635                 :       16855 :   reset ();
    2636                 :             : 
    2637                 :       16855 :   DECL_UNINLINABLE (decl) = false;
    2638                 :       16855 :   DECL_RESULT (decl) = decl_result;
    2639                 :       16855 :   DECL_INITIAL (decl) = NULL;
    2640                 :       16855 :   allocate_struct_function (decl, false);
    2641                 :       16855 :   set_cfun (NULL);
    2642                 :             : 
    2643                 :             :   /* Turn alias into thunk and expand it into GIMPLE representation.  */
    2644                 :       16855 :   definition = true;
    2645                 :       16855 :   semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
    2646                 :             : 
    2647                 :             :   /* Create empty thunk, but be sure we did not keep former thunk around.
    2648                 :             :      In that case we would need to preserve the info.  */
    2649                 :       16855 :   gcc_checking_assert (!thunk_info::get (this));
    2650                 :       16855 :   thunk_info::get_create (this);
    2651                 :       16855 :   thunk = true;
    2652                 :       16855 :   create_edge (target, NULL, count);
    2653                 :       16855 :   callees->can_throw_external = !TREE_NOTHROW (target->decl);
    2654                 :             : 
    2655                 :       16855 :   tree arguments = DECL_ARGUMENTS (decl);
    2656                 :             : 
    2657                 :       44967 :   while (arguments)
    2658                 :             :     {
    2659                 :       28112 :       TREE_ADDRESSABLE (arguments) = false;
    2660                 :       28112 :       arguments = TREE_CHAIN (arguments);
    2661                 :             :     }
    2662                 :             : 
    2663                 :       16855 :   expand_thunk (this, false, true);
    2664                 :       16855 :   thunk_info::remove (this);
    2665                 :             : 
    2666                 :             :   /* Inline summary set-up.  */
    2667                 :       16855 :   analyze ();
    2668                 :       16855 :   inline_analyze_function (this);
    2669                 :       16855 : }
        

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.