LCOV - code coverage report
Current view: top level - gcc - lto-cgraph.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 87.9 % 1228 1079
Test Date: 2026-08-22 16:33:35 Functions: 94.3 % 53 50
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Write and read the cgraph to the memory mapped representation of a
       2              :    .o file.
       3              : 
       4              :    Copyright (C) 2009-2026 Free Software Foundation, Inc.
       5              :    Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
       6              : 
       7              : This file is part of GCC.
       8              : 
       9              : GCC is free software; you can redistribute it and/or modify it under
      10              : the terms of the GNU General Public License as published by the Free
      11              : Software Foundation; either version 3, or (at your option) any later
      12              : version.
      13              : 
      14              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      15              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      16              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      17              : for more details.
      18              : 
      19              : You should have received a copy of the GNU General Public License
      20              : along with GCC; see the file COPYING3.  If not see
      21              : <http://www.gnu.org/licenses/>.  */
      22              : 
      23              : #include "config.h"
      24              : #include "system.h"
      25              : #include "coretypes.h"
      26              : #include "backend.h"
      27              : #include "rtl.h"
      28              : #include "tree.h"
      29              : #include "gimple.h"
      30              : #include "predict.h"
      31              : #include "stringpool.h"
      32              : #include "tree-streamer.h"
      33              : #include "cgraph.h"
      34              : #include "tree-pass.h"
      35              : #include "profile.h"
      36              : #include "context.h"
      37              : #include "pass_manager.h"
      38              : #include "ipa-utils.h"
      39              : #include "omp-offload.h"
      40              : #include "omp-general.h"
      41              : #include "stringpool.h"
      42              : #include "attribs.h"
      43              : #include "alloc-pool.h"
      44              : #include "symbol-summary.h"
      45              : #include "symtab-thunks.h"
      46              : #include "symtab-clones.h"
      47              : #include "callback-info.h"
      48              : 
      49              : static void output_cgraph_opt_summary (void);
      50              : static void input_cgraph_opt_summary (vec<symtab_node *>  nodes);
      51              : 
      52              : /* Number of LDPR values known to GCC.  */
      53              : #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
      54              : 
      55              : /* Cgraph streaming is organized as set of record whose type
      56              :    is indicated by a tag.  */
      57              : enum LTO_symtab_tags
      58              : {
      59              :   /* Must leave 0 for the stopper.  */
      60              : 
      61              :   /* Cgraph node without body available.  */
      62              :   LTO_symtab_unavail_node = 1,
      63              :   /* Cgraph node with function body.  */
      64              :   LTO_symtab_analyzed_node,
      65              :   /* Cgraph edges.  */
      66              :   LTO_symtab_edge,
      67              :   LTO_symtab_indirect_edge,
      68              :   LTO_symtab_variable,
      69              :   LTO_symtab_indirect_function,
      70              :   LTO_symtab_last_tag
      71              : };
      72              : 
      73              : /* Create a new symtab encoder.
      74              :    if FOR_INPUT, the encoder allocate only datastructures needed
      75              :    to read the symtab.  */
      76              : 
      77              : lto_symtab_encoder_t
      78        85129 : lto_symtab_encoder_new (bool for_input)
      79              : {
      80        85129 :   lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
      81              : 
      82        85129 :   if (!for_input)
      83        63389 :     encoder->map = new hash_map<toplevel_node *, size_t>;
      84        85129 :   encoder->nodes.create (0);
      85        85129 :   return encoder;
      86              : }
      87              : 
      88              : 
      89              : /* Delete ENCODER and its components.  */
      90              : 
      91              : void
      92        85129 : lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
      93              : {
      94        85129 :    encoder->nodes.release ();
      95        85129 :    if (encoder->map)
      96        63389 :      delete encoder->map;
      97        85129 :    if (encoder->order_remap)
      98        31694 :      delete encoder->order_remap;
      99        85129 :    free (encoder);
     100        85129 : }
     101              : 
     102              : 
     103              : /* Return the existing reference number of NODE in the symtab encoder in
     104              :    output block OB.  Assign a new reference if this is the first time
     105              :    NODE is encoded.  */
     106              : 
     107              : int
     108      3217674 : lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
     109              :                            toplevel_node *node)
     110              : {
     111      3217674 :   int ref;
     112              : 
     113      3217674 :   if (!encoder->map)
     114              :     {
     115       267627 :       lto_encoder_entry entry (node);
     116              : 
     117       267627 :       ref = encoder->nodes.length ();
     118       267627 :       encoder->nodes.safe_push (entry);
     119       267627 :       return ref;
     120              :     }
     121              : 
     122      2950047 :   size_t *slot = encoder->map->get (node);
     123      2950047 :   if (!slot || !*slot)
     124              :     {
     125      1161437 :       lto_encoder_entry entry (node);
     126      1161437 :       ref = encoder->nodes.length ();
     127      1161437 :       if (!slot)
     128      1161437 :         encoder->map->put (node, ref + 1);
     129      1161437 :       encoder->nodes.safe_push (entry);
     130      1161437 :     }
     131              :   else
     132      1788610 :     ref = *slot - 1;
     133              : 
     134              :   return ref;
     135              : }
     136              : 
     137              : /* Remove NODE from encoder.  */
     138              : 
     139              : bool
     140          224 : lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
     141              :                                 toplevel_node *node)
     142              : {
     143          224 :   int index;
     144              : 
     145          224 :   size_t *slot = encoder->map->get (node);
     146          224 :   if (slot == NULL || !*slot)
     147              :     return false;
     148              : 
     149          224 :   index = *slot - 1;
     150          224 :   gcc_checking_assert (encoder->nodes[index].node == node);
     151              : 
     152              :   /* Remove from vector. We do this by swapping node with the last element
     153              :      of the vector.  */
     154          224 :   lto_encoder_entry last_node = encoder->nodes.pop ();
     155          224 :   if (last_node.node != node)
     156              :     {
     157          223 :       bool existed = encoder->map->put (last_node.node, index + 1);
     158          223 :       gcc_assert (existed);
     159              : 
     160              :       /* Move the last element to the original spot of NODE.  */
     161          223 :       encoder->nodes[index] = last_node;
     162              :     }
     163              : 
     164              :   /* Remove element from hash table.  */
     165          224 :   encoder->map->remove (node);
     166          224 :   return true;
     167              : }
     168              : 
     169              : /* Return TRUE if the NODE and its clones are always inlined.  */
     170              : 
     171              : bool
     172        12010 : lto_symtab_encoder_only_for_inlining_p (lto_symtab_encoder_t encoder,
     173              :                                         struct cgraph_node *node)
     174              : {
     175        12010 :   int index = lto_symtab_encoder_lookup (encoder, node);
     176        12010 :   return encoder->nodes[index].only_for_inlining;
     177              : }
     178              : 
     179              : /* Return TRUE if we should encode the body of NODE (if any).  */
     180              : 
     181              : bool
     182       460148 : lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
     183              :                                   struct cgraph_node *node)
     184              : {
     185       460148 :   int index = lto_symtab_encoder_lookup (encoder, node);
     186       460148 :   return encoder->nodes[index].body;
     187              : }
     188              : 
     189              : /* Return TRUE if we should encode initializer of NODE (if any).  */
     190              : 
     191              : bool
     192       667556 : lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
     193              :                                          varpool_node *node)
     194              : {
     195       667556 :   int index = lto_symtab_encoder_lookup (encoder, node);
     196       667556 :   if (index == LCC_NOT_FOUND)
     197              :     return false;
     198       667534 :   return encoder->nodes[index].initializer;
     199              : }
     200              : 
     201              : /* Specify that we should encode initializer of NODE (if any).  */
     202              : 
     203              : static void
     204       281969 : lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
     205              :                                            varpool_node *node)
     206              : {
     207       281969 :   int index = lto_symtab_encoder_lookup (encoder, node);
     208       281969 :   encoder->nodes[index].initializer = true;
     209       281969 : }
     210              : 
     211              : /* Return TRUE if NODE is in this partition.  */
     212              : 
     213              : bool
     214      8654071 : lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
     215              :                                    toplevel_node *node)
     216              : {
     217      8654071 :   int index = lto_symtab_encoder_lookup (encoder, node);
     218      8654071 :   if (index == LCC_NOT_FOUND)
     219              :     return false;
     220      8512201 :   return encoder->nodes[index].in_partition;
     221              : }
     222              : 
     223              : /* Specify that NODE is in this partition.  */
     224              : 
     225              : void
     226       907022 : lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
     227              :                                      toplevel_node *node)
     228              : {
     229       907022 :   int index = lto_symtab_encoder_encode (encoder, node);
     230       907022 :   if (dump_file)
     231              :     {
     232            0 :       if (symtab_node* snode = dyn_cast<symtab_node*> (node))
     233            0 :         fprintf (dump_file, "Node %s, index %d\n", snode->asm_name (), index);
     234              :       else
     235            0 :         fprintf (dump_file, "Asm node, index %d\n", index);
     236              :     }
     237       907022 :   encoder->nodes[index].in_partition = true;
     238       907022 : }
     239              : 
     240              : /* Output the cgraph EDGE to OB using ENCODER.  */
     241              : 
     242              : static void
     243       633082 : lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
     244              :                  lto_symtab_encoder_t encoder)
     245              : {
     246       633082 :   unsigned int uid;
     247       633082 :   intptr_t ref;
     248       633082 :   struct bitpack_d bp;
     249              : 
     250       633082 :   if (edge->indirect_unknown_callee)
     251         3613 :     streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     252              :                          LTO_symtab_indirect_edge);
     253              :   else
     254       629469 :     streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     255              :                          LTO_symtab_edge);
     256              : 
     257       633082 :   ref = lto_symtab_encoder_lookup (encoder, edge->caller);
     258       633082 :   gcc_assert (ref != LCC_NOT_FOUND);
     259       633082 :   streamer_write_hwi_stream (ob->main_stream, ref);
     260              : 
     261       633082 :   if (!edge->indirect_unknown_callee)
     262              :     {
     263       629469 :       ref = lto_symtab_encoder_lookup (encoder, edge->callee);
     264       629469 :       gcc_assert (ref != LCC_NOT_FOUND);
     265       629469 :       streamer_write_hwi_stream (ob->main_stream, ref);
     266              :     }
     267              : 
     268       633082 :   edge->count.stream_out (ob->main_stream);
     269              : 
     270       633082 :   bp = bitpack_create (ob->main_stream);
     271       633082 :   uid = !edge->call_stmt ? edge->lto_stmt_uid
     272       385584 :                          : gimple_uid (edge->call_stmt) + 1;
     273       633082 :   bp_pack_enum (&bp, cgraph_inline_failed_t,
     274              :                 CIF_N_REASONS, edge->inline_failed);
     275       633082 :   gcc_checking_assert (uid || edge->caller->thunk);
     276       633082 :   bp_pack_var_len_unsigned (&bp, uid);
     277       633082 :   bp_pack_value (&bp, edge->speculative_id, 16);
     278       633082 :   bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
     279       633082 :   bp_pack_value (&bp, edge->speculative, 1);
     280       633082 :   bp_pack_value (&bp, edge->callback, 1);
     281       633082 :   bp_pack_value (&bp, edge->has_callback, 1);
     282       633082 :   bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
     283       633082 :   gcc_assert (!edge->call_stmt_cannot_inline_p
     284              :               || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
     285       633082 :   bp_pack_value (&bp, edge->can_throw_external, 1);
     286       633082 :   bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
     287       633082 :   if (edge->indirect_unknown_callee)
     288              :     {
     289         3613 :       bp_pack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS,
     290              :                     edge->indirect_info->kind);
     291         3613 :       int flags = edge->indirect_info->ecf_flags;
     292         3613 :       bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
     293         3613 :       bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
     294         3613 :       bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
     295         3613 :       bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
     296         3613 :       bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
     297         3613 :       bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
     298              :       /* Flags that should not appear on indirect calls.  */
     299         3613 :       gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
     300              :                              | ECF_MAY_BE_ALLOCA
     301              :                              | ECF_SIBCALL
     302              :                              | ECF_LEAF
     303              :                              | ECF_NOVOPS)));
     304              : 
     305         3613 :       bp_pack_value (&bp, edge->indirect_info->num_speculative_call_targets,
     306              :                      16);
     307              :     }
     308       633082 :   streamer_write_bitpack (&bp);
     309       633082 :   if (edge->callback)
     310              :     {
     311           13 :       callback_info *ci = callback_info_sum->get (edge);
     312           13 :       ci->stream_out (ob);
     313              :     }
     314       633082 : }
     315              : 
     316              : /* Return if NODE contain references from other partitions.  */
     317              : 
     318              : bool
     319       419093 : referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
     320              : {
     321       419093 :   int i;
     322       419093 :   struct ipa_ref *ref = NULL;
     323              : 
     324       870998 :   for (i = 0; node->iterate_referring (i, ref); i++)
     325              :     {
     326              :       /* Ignore references from non-offloadable nodes while streaming NODE into
     327              :          offload LTO section.  */
     328       452206 :       if (!ref->referring->need_lto_streaming)
     329            0 :         continue;
     330              : 
     331       452206 :       if (ref->referring->in_other_partition
     332       452206 :           || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
     333              :         return true;
     334              :     }
     335              :   return false;
     336              : }
     337              : 
     338              : /* Return true when node is reachable from other partition.  */
     339              : 
     340              : bool
     341       139969 : reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
     342              : {
     343       139969 :   struct cgraph_edge *e;
     344       139969 :   if (!node->definition)
     345              :     return false;
     346       139969 :   if (node->inlined_to)
     347              :     return false;
     348       404421 :   for (e = node->callers; e; e = e->next_caller)
     349              :     {
     350              :       /* Ignore references from non-offloadable nodes while streaming NODE into
     351              :          offload LTO section.  */
     352       264573 :       if (!e->caller->need_lto_streaming)
     353            0 :         continue;
     354              : 
     355       264573 :       if (e->caller->in_other_partition
     356       264573 :           || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
     357              :         return true;
     358              :     }
     359              :   return false;
     360              : }
     361              : 
     362              : /* Return if NODE contain references from other partitions.  */
     363              : 
     364              : bool
     365         6466 : referenced_from_this_partition_p (symtab_node *node,
     366              :                                   lto_symtab_encoder_t encoder)
     367              : {
     368         6466 :   int i;
     369         6466 :   struct ipa_ref *ref = NULL;
     370              : 
     371         6492 :   for (i = 0; node->iterate_referring (i, ref); i++)
     372         4980 :     if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
     373              :       return true;
     374              :   return false;
     375              : }
     376              : 
     377              : /* Return true when node is reachable from other partition.  */
     378              : 
     379              : bool
     380         9286 : reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
     381              : {
     382         9286 :   struct cgraph_edge *e;
     383         9288 :   for (e = node->callers; e; e = e->next_caller)
     384         6690 :     if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
     385              :       return true;
     386              :   return false;
     387              : }
     388              : 
     389              : /* Output the cgraph NODE to OB.  ENCODER is used to find the
     390              :    reference number of NODE->inlined_to.  SET is the set of nodes we
     391              :    are writing to the current file.  If NODE is not in SET, then NODE
     392              :    is a boundary of a cgraph_node_set and we pretend NODE just has a
     393              :    decl and no callees.  WRITTEN_DECLS is the set of FUNCTION_DECLs
     394              :    that have had their callgraph node written so far.  This is used to
     395              :    determine if NODE is a clone of a previously written node.  */
     396              : 
     397              : static void
     398       422446 : lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
     399              :                  lto_symtab_encoder_t encoder)
     400              : {
     401       422446 :   unsigned int tag;
     402       422446 :   struct bitpack_d bp;
     403       422446 :   bool boundary_p;
     404       422446 :   intptr_t ref;
     405       422446 :   bool in_other_partition = false;
     406       422446 :   struct cgraph_node *clone_of, *ultimate_clone_of;
     407       422446 :   ipa_opt_pass_d *pass;
     408       422446 :   int i;
     409       422446 :   const char *comdat;
     410       422446 :   const char *section;
     411       422446 :   tree group;
     412              : 
     413       422446 :   boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
     414              : 
     415       422446 :   if (node->analyzed && (!boundary_p || node->alias
     416          254 :                          || (node->thunk && !node->inlined_to)))
     417              :     tag = LTO_symtab_analyzed_node;
     418              :   else
     419       422446 :     tag = LTO_symtab_unavail_node;
     420              : 
     421       422446 :   streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     422              :                        tag);
     423       422446 :   int output_order = *encoder->order_remap->get (node->order);
     424       422446 :   streamer_write_hwi_stream (ob->main_stream, output_order);
     425              : 
     426              :   /* In WPA mode, we only output part of the call-graph.  Also, we
     427              :      fake cgraph node attributes.  There are two cases that we care.
     428              : 
     429              :      Boundary nodes: There are nodes that are not part of SET but are
     430              :      called from within SET.  We artificially make them look like
     431              :      externally visible nodes with no function body.
     432              : 
     433              :      Cherry-picked nodes:  These are nodes we pulled from other
     434              :      translation units into SET during IPA-inlining.  We make them as
     435              :      local static nodes to prevent clashes with other local statics.  */
     436       252254 :   if (boundary_p && node->analyzed
     437       422715 :       && node->get_partitioning_class () == SYMBOL_PARTITION)
     438              :     {
     439              :       /* Inline clones cannot be part of boundary.
     440              :          gcc_assert (!node->inlined_to);
     441              : 
     442              :          FIXME: At the moment they can be, when partition contains an inline
     443              :          clone that is clone of inline clone from outside partition.  We can
     444              :          reshape the clone tree and make other tree to be the root, but it
     445              :          needs a bit extra work and will be promplty done by cgraph_remove_node
     446              :          after reading back.  */
     447              :       in_other_partition = 1;
     448              :     }
     449       422191 :   else if (UNLIKELY (lto_stream_offload_p
     450              :                      && lookup_attribute ("omp target device_ancestor_host",
     451              :                                           DECL_ATTRIBUTES (node->decl))))
     452              :     /* This symbol is only used as argument to IFN_GOMP_TARGET_REV; this IFN
     453              :        is ignored on ACCEL_COMPILER.  Thus, mark it as in_other_partition to silence
     454              :        verify_node_partition diagnostic.  */
     455              :     in_other_partition = 1;
     456              : 
     457       422446 :   clone_of = node->clone_of;
     458       422446 :   while (clone_of
     459       422446 :          && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
     460            0 :     if (clone_of->prev_sibling_clone)
     461              :       clone_of = clone_of->prev_sibling_clone;
     462              :     else
     463            0 :       clone_of = clone_of->clone_of;
     464              : 
     465              :   /* See if body of the master function is output.  If not, we are seeing only
     466              :      an declaration and we do not need to pass down clone tree. */
     467       422446 :   ultimate_clone_of = clone_of;
     468       441839 :   while (ultimate_clone_of && ultimate_clone_of->clone_of)
     469              :     ultimate_clone_of = ultimate_clone_of->clone_of;
     470              : 
     471       422446 :   if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
     472              :     clone_of = NULL;
     473              : 
     474       422446 :   if (tag == LTO_symtab_analyzed_node)
     475       170211 :     gcc_assert (clone_of || !node->clone_of);
     476       399662 :   if (!clone_of)
     477       399217 :     streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
     478              :   else
     479        23229 :     streamer_write_hwi_stream (ob->main_stream, ref);
     480              : 
     481              : 
     482       422446 :   lto_output_fn_decl_ref (ob->decl_state, ob->main_stream, node->decl);
     483       422446 :   node->count.stream_out (ob->main_stream);
     484       422446 :   streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
     485              : 
     486       844892 :   streamer_write_hwi_stream (ob->main_stream,
     487       422446 :                              node->ipa_transforms_to_apply.length ());
     488       912860 :   FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
     489        67968 :     streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
     490              : 
     491       422446 :   if (tag == LTO_symtab_analyzed_node)
     492              :     {
     493       170211 :       if (node->inlined_to)
     494              :         {
     495        21402 :           ref = lto_symtab_encoder_lookup (encoder, node->inlined_to);
     496        21402 :           gcc_assert (ref != LCC_NOT_FOUND);
     497              :         }
     498              :       else
     499              :         ref = LCC_NOT_FOUND;
     500              : 
     501       170211 :       streamer_write_hwi_stream (ob->main_stream, ref);
     502              :     }
     503              : 
     504       422446 :   group = node->get_comdat_group ();
     505       422446 :   if (group)
     506         8907 :     comdat = IDENTIFIER_POINTER (group);
     507              :   else
     508              :     comdat = "";
     509       422446 :   streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
     510              : 
     511       422446 :   if (group)
     512              :     {
     513         8907 :       if (node->same_comdat_group)
     514              :         {
     515              :           ref = LCC_NOT_FOUND;
     516         4440 :           for (struct symtab_node *n = node->same_comdat_group;
     517         8879 :                ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
     518         4440 :             ref = lto_symtab_encoder_lookup (encoder, n);
     519              :         }
     520              :       else
     521              :         ref = LCC_NOT_FOUND;
     522         8907 :       streamer_write_hwi_stream (ob->main_stream, ref);
     523              :     }
     524              : 
     525       422446 :   section = node->get_section ();
     526          318 :   if (!section)
     527       422128 :     section = "";
     528              : 
     529       422446 :   streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
     530              : 
     531       422446 :   bp = bitpack_create (ob->main_stream);
     532       422446 :   bp_pack_value (&bp, node->local, 1);
     533       422446 :   bp_pack_value (&bp, node->externally_visible, 1);
     534       422446 :   bp_pack_value (&bp, node->no_reorder, 1);
     535       422446 :   bp_pack_value (&bp, node->definition, 1);
     536       422446 :   bp_pack_value (&bp, node->versionable, 1);
     537       422446 :   bp_pack_value (&bp, node->can_change_signature, 1);
     538       422446 :   bp_pack_value (&bp, node->redefined_extern_inline, 1);
     539       422446 :   bp_pack_value (&bp, node->force_output, 1);
     540       422446 :   bp_pack_value (&bp, node->forced_by_abi, 1);
     541       422446 :   bp_pack_value (&bp, node->ref_by_asm, 1);
     542       422446 :   bp_pack_value (&bp, node->must_remain_in_tu_name, 1);
     543       422446 :   bp_pack_value (&bp, node->must_remain_in_tu_body, 1);
     544       422446 :   bp_pack_value (&bp, node->unique_name, 1);
     545       422446 :   bp_pack_value (&bp, node->body_removed, 1);
     546       422446 :   bp_pack_value (&bp, node->semantic_interposition, 1);
     547       422446 :   bp_pack_value (&bp, node->implicit_section, 1);
     548       422446 :   bp_pack_value (&bp, node->address_taken, 1);
     549       422446 :   bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
     550       170211 :                  && node->get_partitioning_class () == SYMBOL_PARTITION
     551       562415 :                  && (reachable_from_other_partition_p (node, encoder)
     552       139848 :                      || referenced_from_other_partition_p (node, encoder)), 1);
     553       422446 :   bp_pack_value (&bp, node->lowered, 1);
     554       422446 :   bp_pack_value (&bp, in_other_partition, 1);
     555       422446 :   bp_pack_value (&bp, node->alias, 1);
     556       422446 :   bp_pack_value (&bp, node->transparent_alias, 1);
     557       422446 :   bp_pack_value (&bp, node->weakref, 1);
     558       422446 :   bp_pack_value (&bp, node->symver, 1);
     559       422446 :   bp_pack_value (&bp, node->frequency, 2);
     560       422446 :   bp_pack_value (&bp, node->only_called_at_startup, 1);
     561       422446 :   bp_pack_value (&bp, node->only_called_at_exit, 1);
     562       422446 :   bp_pack_value (&bp, node->tm_clone, 1);
     563       422446 :   bp_pack_value (&bp, node->calls_comdat_local, 1);
     564       422446 :   bp_pack_value (&bp, node->icf_merged, 1);
     565       422446 :   bp_pack_value (&bp, node->nonfreeing_fn, 1);
     566       422446 :   bp_pack_value (&bp, node->merged_comdat, 1);
     567       422446 :   bp_pack_value (&bp, node->merged_extern_inline, 1);
     568       422446 :   bp_pack_value (&bp, node->thunk, 1);
     569       422446 :   bp_pack_value (&bp, node->parallelized_function, 1);
     570       422446 :   bp_pack_value (&bp, node->has_omp_variant_constructs, 1);
     571              : 
     572              :   /* Stream thunk info always because we use it in
     573              :      ipa_polymorphic_call_context::ipa_polymorphic_call_context
     574              :      to properly interpret THIS pointers for thunks that has been converted
     575              :      to Gimple.  */
     576       422446 :   struct thunk_info *thunk = node->definition ? thunk_info::get (node) : NULL;
     577              : 
     578       422446 :   bp_pack_value (&bp, thunk != NULL, 1);
     579              : 
     580       422446 :   bp_pack_enum (&bp, ld_plugin_symbol_resolution,
     581              :                 LDPR_NUM_KNOWN,
     582              :                 /* When doing incremental link, we will get new resolution
     583              :                    info next time we process the file.  */
     584              :                 flag_incremental_link == INCREMENTAL_LINK_LTO
     585              :                 ? LDPR_UNKNOWN : node->resolution);
     586       422446 :   bp_pack_value (&bp, node->split_part, 1);
     587       422446 :   streamer_write_bitpack (&bp);
     588       422446 :   streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
     589              : 
     590       422446 :   streamer_write_hwi_stream (ob->main_stream, node->profile_id);
     591       422446 :   streamer_write_hwi_stream (ob->main_stream, node->unit_id);
     592       422446 :   if (DECL_STATIC_CONSTRUCTOR (node->decl))
     593          256 :     streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
     594       422446 :   if (DECL_STATIC_DESTRUCTOR (node->decl))
     595           69 :     streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
     596              : 
     597       422446 :   if (thunk)
     598          227 :     thunk_info::get (node)->stream_out (ob);
     599       422446 : }
     600              : 
     601              : /* Output the varpool NODE to OB.
     602              :    If NODE is not in SET, then NODE is a boundary.  */
     603              : 
     604              : static void
     605       286434 : lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
     606              :                          lto_symtab_encoder_t encoder)
     607              : {
     608       286434 :   bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
     609       286434 :   bool encode_initializer_p
     610       286434 :          = (node->definition
     611       286434 :             && lto_symtab_encoder_encode_initializer_p (encoder, node));
     612       281842 :   struct bitpack_d bp;
     613       281842 :   int ref;
     614       281842 :   const char *comdat;
     615       281842 :   const char *section;
     616       281842 :   tree group;
     617              : 
     618       281842 :   gcc_assert (!encode_initializer_p || node->definition);
     619       286434 :   gcc_assert (boundary_p || encode_initializer_p);
     620              : 
     621       286434 :   streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     622              :                        LTO_symtab_variable);
     623       286434 :   int output_order = *encoder->order_remap->get (node->order);
     624       286434 :   streamer_write_hwi_stream (ob->main_stream, output_order);
     625       286434 :   lto_output_var_decl_ref (ob->decl_state, ob->main_stream, node->decl);
     626       286434 :   bp = bitpack_create (ob->main_stream);
     627       286434 :   bp_pack_value (&bp, node->externally_visible, 1);
     628       286434 :   bp_pack_value (&bp, node->no_reorder, 1);
     629       286434 :   bp_pack_value (&bp, node->force_output, 1);
     630       286434 :   bp_pack_value (&bp, node->forced_by_abi, 1);
     631       286434 :   bp_pack_value (&bp, node->ref_by_asm, 1);
     632       286434 :   bp_pack_value (&bp, node->must_remain_in_tu_name, 1);
     633       286434 :   bp_pack_value (&bp, node->must_remain_in_tu_body, 1);
     634       286434 :   bp_pack_value (&bp, node->unique_name, 1);
     635       286434 :   bp_pack_value (&bp,
     636       286434 :                  node->body_removed
     637       286434 :                  || (!encode_initializer_p && !node->alias && node->definition),
     638              :                  1);
     639       286434 :   bp_pack_value (&bp, node->semantic_interposition, 1);
     640       286434 :   bp_pack_value (&bp, node->implicit_section, 1);
     641       286434 :   bp_pack_value (&bp, node->writeonly, 1);
     642       568277 :   bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias),
     643              :                  1);
     644       286434 :   bp_pack_value (&bp, node->alias, 1);
     645       286434 :   bp_pack_value (&bp, node->transparent_alias, 1);
     646       286434 :   bp_pack_value (&bp, node->weakref, 1);
     647       286434 :   bp_pack_value (&bp, node->symver, 1);
     648       568260 :   bp_pack_value (&bp, node->analyzed && (!boundary_p || node->alias), 1);
     649       286434 :   gcc_assert (node->definition || !node->analyzed);
     650              :   /* Constant pool initializers can be de-unified into individual ltrans units.
     651              :      FIXME: Alternatively at -Os we may want to avoid generating for them the local
     652              :      labels and share them across LTRANS partitions.  */
     653       286434 :   if (node->get_partitioning_class () != SYMBOL_PARTITION)
     654              :     {
     655         7189 :       bp_pack_value (&bp, 0, 1);  /* used_from_other_parition.  */
     656         7189 :       bp_pack_value (&bp, 0, 1);  /* in_other_partition.  */
     657              :     }
     658              :   else
     659              :     {
     660       279245 :       bp_pack_value (&bp, node->definition
     661       279245 :                      && referenced_from_other_partition_p (node, encoder), 1);
     662       279245 :       bp_pack_value (&bp, node->analyzed
     663       279245 :                      && boundary_p && !DECL_EXTERNAL (node->decl), 1);
     664              :           /* in_other_partition.  */
     665              :     }
     666       286434 :   bp_pack_value (&bp, node->tls_model, 3);
     667       286434 :   bp_pack_value (&bp, node->used_by_single_function, 1);
     668       286434 :   bp_pack_value (&bp, node->dynamically_initialized, 1);
     669       286434 :   streamer_write_bitpack (&bp);
     670              : 
     671       286434 :   group = node->get_comdat_group ();
     672       286434 :   if (group)
     673         3420 :     comdat = IDENTIFIER_POINTER (group);
     674              :   else
     675              :     comdat = "";
     676       286434 :   streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
     677              : 
     678       286434 :   if (group)
     679              :     {
     680         3420 :       if (node->same_comdat_group)
     681              :         {
     682              :           ref = LCC_NOT_FOUND;
     683          370 :           for (struct symtab_node *n = node->same_comdat_group;
     684          740 :                ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
     685          370 :             ref = lto_symtab_encoder_lookup (encoder, n);
     686              :         }
     687              :       else
     688              :         ref = LCC_NOT_FOUND;
     689         3420 :       streamer_write_hwi_stream (ob->main_stream, ref);
     690              :     }
     691              : 
     692       286434 :   section = node->get_section ();
     693         2353 :   if (!section)
     694       284081 :     section = "";
     695       286434 :   streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
     696              : 
     697       286434 :   streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
     698              :                        LDPR_NUM_KNOWN, node->resolution);
     699       286434 : }
     700              : 
     701              : /* Output the varpool NODE to OB.
     702              :    If NODE is not in SET, then NODE is a boundary.  */
     703              : 
     704              : static void
     705       677714 : lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
     706              :                 lto_symtab_encoder_t encoder)
     707              : {
     708       677714 :   struct bitpack_d bp;
     709       677714 :   int nref;
     710       677714 :   int uid = !ref->stmt ? ref->lto_stmt_uid : gimple_uid (ref->stmt) + 1;
     711       677714 :   struct cgraph_node *node;
     712              : 
     713       677714 :   bp = bitpack_create (ob->main_stream);
     714       677714 :   bp_pack_value (&bp, ref->use, 3);
     715       677714 :   bp_pack_value (&bp, ref->speculative, 1);
     716       677714 :   streamer_write_bitpack (&bp);
     717       677714 :   nref = lto_symtab_encoder_lookup (encoder, ref->referred);
     718       677714 :   gcc_assert (nref != LCC_NOT_FOUND);
     719       677714 :   streamer_write_hwi_stream (ob->main_stream, nref);
     720              : 
     721       677714 :   node = dyn_cast <cgraph_node *> (ref->referring);
     722       452153 :   if (node)
     723              :     {
     724       452153 :       if (ref->stmt)
     725       264417 :         uid = gimple_uid (ref->stmt) + 1;
     726       452153 :       streamer_write_hwi_stream (ob->main_stream, uid);
     727       452153 :       bp_pack_value (&bp, ref->speculative_id, 16);
     728       452153 :       streamer_write_bitpack (&bp);
     729              :     }
     730       677714 : }
     731              : 
     732              : /* Stream out profile_summary to OB.  */
     733              : 
     734              : static void
     735        31694 : output_profile_summary (struct lto_simple_output_block *ob)
     736              : {
     737        31694 :   if (profile_info)
     738              :     {
     739           11 :       unsigned runs = (profile_info->runs);
     740           11 :       streamer_write_uhwi_stream (ob->main_stream, runs);
     741           11 :       streamer_write_gcov_count_stream (ob->main_stream,
     742              :                                         profile_info->sum_max);
     743           11 :       streamer_write_gcov_count_stream (ob->main_stream,
     744              :                                         profile_info->cutoff);
     745              : 
     746              :       /* IPA-profile computes hot bb threshold based on cumulated
     747              :          whole program profile.  We need to stream it down to ltrans.  */
     748           11 :        if (flag_wpa)
     749            4 :          streamer_write_gcov_count_stream (ob->main_stream,
     750              :                                            get_hot_bb_threshold ());
     751              :     }
     752              :   else
     753        31683 :     streamer_write_uhwi_stream (ob->main_stream, 0);
     754        31694 : }
     755              : 
     756              : /* Output all callees or indirect outgoing edges.  EDGE must be the first such
     757              :    edge.  */
     758              : 
     759              : static void
     760       340392 : output_outgoing_cgraph_edges (struct cgraph_edge *edge,
     761              :                               struct lto_simple_output_block *ob,
     762              :                               lto_symtab_encoder_t encoder)
     763              : {
     764       340392 :   if (!edge)
     765              :     return;
     766              : 
     767              :   /* Output edges in backward direction, so the reconstructed callgraph match
     768              :      and it is easy to associate call sites in the IPA pass summaries.  */
     769       633082 :   while (edge->next_callee)
     770              :     edge = edge->next_callee;
     771       747388 :   for (; edge; edge = edge->prev_callee)
     772       633082 :     lto_output_edge (ob, edge, encoder);
     773              : }
     774              : 
     775              : /* Output the part of the cgraph in SET.  */
     776              : 
     777              : static void
     778        31694 : output_refs (lto_symtab_encoder_t encoder)
     779              : {
     780        31694 :   struct lto_simple_output_block *ob;
     781        31694 :   int count;
     782        31694 :   struct ipa_ref *ref;
     783              : 
     784        31694 :   ob = lto_create_simple_output_block (LTO_section_refs);
     785              : 
     786      1512919 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
     787              :     {
     788       709036 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
     789       709036 :       symtab_node *node = dyn_cast <symtab_node *> (tnode);
     790       709036 :       if (!node)
     791          156 :         continue;
     792              : 
     793              :       /* IPA_REF_ALIAS references are always preserved
     794              :          in the boundary.  Alias node can't have other references and
     795              :          can be always handled as if it's not in the boundary.  */
     796       708880 :       if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node))
     797       256807 :         continue;
     798              : 
     799       781086 :       count = node->ref_list.nreferences ();
     800        72050 :       if (count)
     801              :         {
     802        72036 :           streamer_write_gcov_count_stream (ob->main_stream, count);
     803       144072 :           streamer_write_uhwi_stream (ob->main_stream,
     804        72036 :                                      lto_symtab_encoder_lookup (encoder, node));
     805      1530822 :           for (int i = 0; node->iterate_reference (i, ref); i++)
     806       677714 :             lto_output_ref (ob, ref, encoder);
     807              :         }
     808              :     }
     809              : 
     810        31694 :   streamer_write_uhwi_stream (ob->main_stream, 0);
     811              : 
     812        31694 :   lto_destroy_simple_output_block (ob);
     813        31694 : }
     814              : 
     815              : /* Add NODE into encoder as well as nodes it is cloned from.
     816              :    Do it in a way so clones appear first.  */
     817              : 
     818              : static void
     819       785091 : add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
     820              :              bool include_body, bool not_inlined)
     821              : {
     822       785091 :   if (node->clone_of)
     823        42185 :     add_node_to (encoder, node->clone_of, include_body, not_inlined);
     824              : 
     825       785091 :   int index = lto_symtab_encoder_encode (encoder, node);
     826       785091 :   gcc_checking_assert (encoder->nodes[index].node == node);
     827              : 
     828       785091 :   if (include_body)
     829       212369 :     encoder->nodes[index].body = true;
     830       785091 :   if (not_inlined)
     831       151944 :     encoder->nodes[index].only_for_inlining = false;
     832       785091 : }
     833              : 
     834              : /* Add NODE into encoder as well as nodes it is cloned from.
     835              :    Do it in a way so clones appear first.  */
     836              : 
     837              : static void
     838       742906 : add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
     839              :              bool include_body)
     840              : {
     841       430935 :   add_node_to (encoder, node, include_body, include_body && !node->inlined_to);
     842       170192 : }
     843              : 
     844              : /* Add all references in NODE to encoders.  */
     845              : 
     846              : static void
     847       464906 : create_references (lto_symtab_encoder_t encoder, symtab_node *node)
     848              : {
     849       464906 :   int i;
     850       464906 :   struct ipa_ref *ref = NULL;
     851      1155366 :   for (i = 0; node->iterate_reference (i, ref); i++)
     852       690460 :     if (is_a <cgraph_node *> (ref->referred))
     853       239334 :       add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
     854              :     else
     855       451126 :       lto_symtab_encoder_encode (encoder, ref->referred);
     856       464906 : }
     857              : 
     858              : /* Select what needs to be streamed out.  In regular lto mode stream everything.
     859              :    In offload lto mode stream only nodes marked as offloadable.  */
     860              : void
     861        31309 : select_what_to_stream (void)
     862              : {
     863        31309 :   struct symtab_node *snode;
     864       739646 :   FOR_EACH_SYMBOL (snode)
     865      1416674 :     snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable;
     866        31309 : }
     867              : 
     868              : /* Find all symbols we want to stream into given partition and insert them
     869              :    to encoders.
     870              : 
     871              :    The function actually replaces IN_ENCODER by new one.  The reason is that
     872              :    streaming code needs clone's origin to be streamed before clone.  This
     873              :    means that we need to insert the nodes in specific order.  This order is
     874              :    ignored by the partitioning logic earlier.  */
     875              : 
     876              : lto_symtab_encoder_t
     877        31694 : compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
     878              : {
     879        31694 :   struct cgraph_edge *edge;
     880        31694 :   int i;
     881        31694 :   lto_symtab_encoder_t encoder;
     882        31694 :   lto_symtab_encoder_iterator lsei;
     883        31694 :   hash_set<void *> reachable_call_targets;
     884              : 
     885        31694 :   encoder = lto_symtab_encoder_new (false);
     886              : 
     887              :   /* Go over all entries in the IN_ENCODER and duplicate them to
     888              :      ENCODER. At the same time insert masters of clones so
     889              :      every master appears before clone.  */
     890        31694 :   for (lsei = lsei_start_function_in_partition (in_encoder);
     891       201886 :        !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
     892              :     {
     893       170192 :       struct cgraph_node *node = lsei_cgraph_node (lsei);
     894       170192 :       if (!node->need_lto_streaming)
     895            0 :         continue;
     896       170192 :       add_node_to (encoder, node, true);
     897       170192 :       lto_set_symtab_encoder_in_partition (encoder, node);
     898       170192 :       create_references (encoder, node);
     899              :     }
     900        31694 :   for (lsei = lsei_start_variable_in_partition (in_encoder);
     901       313519 :        !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
     902              :     {
     903       281825 :       varpool_node *vnode = lsei_varpool_node (lsei);
     904              : 
     905       281825 :       if (!vnode->need_lto_streaming)
     906            0 :         continue;
     907       281825 :       lto_set_symtab_encoder_in_partition (encoder, vnode);
     908       281825 :       lto_set_symtab_encoder_encode_initializer (encoder, vnode);
     909       281825 :       create_references (encoder, vnode);
     910              :     }
     911       967499 :   for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next (&lsei))
     912              :     {
     913       452173 :       toplevel_node *tnode = lsei_node (lsei);
     914       904346 :       if (asm_node* node = dyn_cast <asm_node*> (tnode))
     915              :         {
     916              :           symtab_node* ref;
     917       452253 :           for (unsigned i = 0; node->symbols_referenced.iterate (i, &ref); i++)
     918              :             {
     919           40 :               if (!lto_symtab_encoder_in_partition_p (encoder, ref))
     920              :                 {
     921           38 :                   if (cgraph_node* cref = dyn_cast <cgraph_node*> (ref))
     922           12 :                     add_node_to (encoder, cref, false);
     923           66 :                   else if (varpool_node *vref = dyn_cast <varpool_node *> (ref))
     924           26 :                     lto_symtab_encoder_encode (encoder, vref);
     925              :                 }
     926              :             }
     927              :         }
     928              :     }
     929              :   /* Pickle in also the initializer of all referenced readonly variables
     930              :      to help folding.  Constant pool variables are not shared, so we must
     931              :      pickle those too.  */
     932      1387019 :   for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
     933              :     {
     934       661934 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
     935      1323868 :       if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
     936              :         {
     937       286433 :           if (!lto_symtab_encoder_encode_initializer_p (encoder,
     938              :                                                         vnode)
     939       286433 :               && (((vnode->ctor_useable_for_folding_p ()
     940          156 :                    && (!DECL_VIRTUAL_P (vnode->decl)
     941          132 :                        || !flag_wpa
     942           12 :                        || flag_ltrans_devirtualize)))))
     943              :             {
     944          144 :               lto_set_symtab_encoder_encode_initializer (encoder, vnode);
     945          144 :               create_references (encoder, vnode);
     946              :             }
     947              :        }
     948              :     }
     949              : 
     950              :   /* Go over all the nodes again to include callees that are not in
     951              :      SET.  */
     952        31694 :   for (lsei = lsei_start_function_in_partition (encoder);
     953       403535 :        !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
     954              :     {
     955       170192 :       struct cgraph_node *node = lsei_cgraph_node (lsei);
     956       799657 :       for (edge = node->callees; edge; edge = edge->next_callee)
     957              :         {
     958       629465 :           struct cgraph_node *callee = edge->callee;
     959       629465 :           if (!lto_symtab_encoder_in_partition_p (encoder, callee))
     960              :             {
     961              :               /* We should have moved all the inlines.  */
     962       333196 :               gcc_assert (!callee->inlined_to);
     963       333196 :               add_node_to (encoder, callee, false);
     964              :             }
     965              :         }
     966              :       /* Add all possible targets for late devirtualization.  */
     967       170192 :       if (flag_ltrans_devirtualize || !flag_wpa)
     968       108362 :         for (edge = node->indirect_calls; edge; edge = edge->next_callee)
     969         5402 :           if (usable_polymorphic_info_p (edge->indirect_info))
     970              :             {
     971         1070 :               unsigned int i;
     972         1070 :               void *cache_token;
     973         1070 :               bool final;
     974         1070 :               vec <cgraph_node *>targets
     975              :                 = possible_polymorphic_call_targets
     976         1070 :                     (edge, &final, &cache_token);
     977         1070 :               if (cache_token != NULL
     978         1070 :                   && !reachable_call_targets.add (cache_token))
     979              :                 {
     980         1474 :                   for (i = 0; i < targets.length (); i++)
     981              :                     {
     982          404 :                       struct cgraph_node *callee = targets[i];
     983              : 
     984              :                       /* Adding an external declarations into the unit serves
     985              :                          no purpose and just increases its boundary.  */
     986          404 :                       if (callee->definition
     987          703 :                           && !lto_symtab_encoder_in_partition_p
     988          299 :                                (encoder, callee))
     989              :                         {
     990            0 :                           gcc_assert (!callee->inlined_to);
     991            0 :                           add_node_to (encoder, callee, false);
     992              :                         }
     993              :                     }
     994              :                 }
     995              :             }
     996              :     }
     997              :   /* Be sure to also insert alias targert and thunk callees.  These needs
     998              :      to stay to aid local calling conventions.  */
     999      1480911 :   for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
    1000              :     {
    1001       708880 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    1002       708880 :       symtab_node *node = dyn_cast <symtab_node *> (tnode);
    1003       708880 :       if (!node)
    1004            0 :         continue;
    1005              : 
    1006       708880 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    1007              : 
    1008       708880 :       if (node->alias && node->analyzed)
    1009        12745 :         create_references (encoder, node);
    1010       708880 :       if (cnode
    1011       422446 :           && cnode->thunk && !cnode->inlined_to)
    1012          165 :         add_node_to (encoder, cnode->callees->callee, false);
    1013       708887 :       while (node->transparent_alias && node->analyzed)
    1014              :         {
    1015            7 :           node = node->get_alias_target ();
    1016            7 :           if (is_a <cgraph_node *> (node))
    1017            7 :             add_node_to (encoder, dyn_cast <cgraph_node *> (node),
    1018              :                          false);
    1019              :           else
    1020            0 :             lto_symtab_encoder_encode (encoder, node);
    1021              :         }
    1022              :     }
    1023              : 
    1024       483867 :   for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next (&lsei))
    1025              :     {
    1026       452173 :       toplevel_node *tnode = lsei_node (lsei);
    1027       904346 :       if (asm_node* node = dyn_cast <asm_node*> (tnode))
    1028          156 :         lto_set_symtab_encoder_in_partition (encoder, node);
    1029              :     }
    1030        31694 :   lto_symtab_encoder_delete (in_encoder);
    1031        31694 :   return encoder;
    1032        31694 : }
    1033              : 
    1034              : /* Output the part of the symtab in SET and VSET.  */
    1035              : 
    1036              : void
    1037        31694 : output_symtab (void)
    1038              : {
    1039        31694 :   struct cgraph_node *node;
    1040        31694 :   struct lto_simple_output_block *ob;
    1041        31694 :   int i, n_nodes;
    1042        31694 :   lto_symtab_encoder_t encoder;
    1043              : 
    1044        31694 :   if (flag_wpa)
    1045         8274 :     output_cgraph_opt_summary ();
    1046              : 
    1047        31694 :   ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
    1048              : 
    1049        31694 :   output_profile_summary (ob);
    1050              : 
    1051              :   /* An encoder for cgraph nodes should have been created by
    1052              :      ipa_write_summaries_1.  */
    1053        31694 :   gcc_assert (ob->decl_state->symtab_node_encoder);
    1054        31694 :   encoder = ob->decl_state->symtab_node_encoder;
    1055              : 
    1056              :   /* Write out the nodes.  We must first output a node and then its clones,
    1057              :      otherwise at a time reading back the node there would be nothing to clone
    1058              :      from.  */
    1059        31694 :   n_nodes = lto_symtab_encoder_size (encoder);
    1060       740730 :   for (i = 0; i < n_nodes; i++)
    1061              :     {
    1062       709036 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
    1063       709036 :       if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
    1064       422446 :         lto_output_node (ob, cnode, encoder);
    1065       995626 :       else if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
    1066       286434 :         lto_output_varpool_node (ob, vnode, encoder);
    1067              :     }
    1068              : 
    1069        31694 :   callback_info_sum_t::check_create_info_sum ();
    1070              :   /* Go over the nodes in SET again to write edges.  */
    1071      1512919 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    1072              :     {
    1073      1418072 :       node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
    1074       422446 :       if (node
    1075       422446 :           && ((node->thunk && !node->inlined_to)
    1076       422281 :               || lto_symtab_encoder_in_partition_p (encoder, node)))
    1077              :         {
    1078       170196 :           output_outgoing_cgraph_edges (node->callees, ob, encoder);
    1079       170196 :           output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
    1080              :         }
    1081              :     }
    1082              : 
    1083        31694 :   streamer_write_uhwi_stream (ob->main_stream, 0);
    1084              : 
    1085        31694 :   lto_destroy_simple_output_block (ob);
    1086              : 
    1087              :   /* Emit toplevel asms.  */
    1088        31694 :   if (!lto_stream_offload_p)
    1089        31694 :     lto_output_toplevel_asms (encoder);
    1090              : 
    1091        31694 :   output_refs (encoder);
    1092        31694 : }
    1093              : 
    1094              : /* Return identifier encoded in IB as a plain string.  */
    1095              : 
    1096              : static tree
    1097       267627 : read_identifier (class lto_input_block *ib)
    1098              : {
    1099       267627 :   unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
    1100       267627 :   tree id;
    1101              : 
    1102       267627 :   if (ib->data[ib->p + len])
    1103            0 :     lto_section_overrun (ib);
    1104       267627 :   if (!len)
    1105              :     {
    1106       257700 :       ib->p++;
    1107       257700 :       return NULL;
    1108              :     }
    1109         9927 :   id = get_identifier (ib->data + ib->p);
    1110         9927 :   ib->p += len + 1;
    1111         9927 :   return id;
    1112              : }
    1113              : 
    1114              : /* Return string encoded in IB, NULL if string is empty.  */
    1115              : 
    1116              : static const char *
    1117       267627 : read_string (class lto_input_block *ib)
    1118              : {
    1119       267627 :   unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
    1120       267627 :   const char *str;
    1121              : 
    1122       267627 :   if (ib->data[ib->p + len])
    1123            0 :     lto_section_overrun (ib);
    1124       267627 :   if (!len)
    1125              :     {
    1126       265116 :       ib->p++;
    1127       265116 :       return NULL;
    1128              :     }
    1129         2511 :   str = ib->data + ib->p;
    1130         2511 :   ib->p += len + 1;
    1131         2511 :   return str;
    1132              : }
    1133              : 
    1134              : /* Output function/variable tables that will allow libgomp to look up offload
    1135              :    target code.
    1136              :    OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
    1137              :    varpool_node::get_create.  In WHOPR (partitioned) mode during the WPA stage
    1138              :    both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables.  */
    1139              : 
    1140              : void
    1141         7889 : output_offload_tables (void)
    1142              : {
    1143        15778 :   bool output_requires = (flag_openmp
    1144         7889 :                           && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0);
    1145         7889 :   if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars)
    1146         7889 :       && !output_requires)
    1147              :     return;
    1148              : 
    1149            0 :   struct lto_simple_output_block *ob
    1150            0 :     = lto_create_simple_output_block (LTO_section_offload_table);
    1151              : 
    1152            0 :   for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
    1153              :     {
    1154            0 :       symtab_node *node = symtab_node::get ((*offload_funcs)[i]);
    1155            0 :       if (!node)
    1156            0 :         continue;
    1157            0 :       node->force_output = true;
    1158            0 :       streamer_write_enum (ob->main_stream, LTO_symtab_tags,
    1159              :                            LTO_symtab_last_tag, LTO_symtab_unavail_node);
    1160            0 :       lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
    1161            0 :                               (*offload_funcs)[i]);
    1162              :     }
    1163              : 
    1164            0 :   for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
    1165              :     {
    1166            0 :       symtab_node *node = symtab_node::get ((*offload_vars)[i]);
    1167            0 :       if (!node)
    1168            0 :         continue;
    1169            0 :       node->force_output = true;
    1170            0 :       streamer_write_enum (ob->main_stream, LTO_symtab_tags,
    1171              :                            LTO_symtab_last_tag, LTO_symtab_variable);
    1172            0 :       lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
    1173            0 :                                (*offload_vars)[i]);
    1174              :     }
    1175              : 
    1176            0 :   for (unsigned i = 0; i < vec_safe_length (offload_ind_funcs); i++)
    1177              :     {
    1178            0 :       symtab_node *node = symtab_node::get ((*offload_ind_funcs)[i]);
    1179            0 :       if (!node)
    1180            0 :         continue;
    1181            0 :       node->force_output = true;
    1182            0 :       streamer_write_enum (ob->main_stream, LTO_symtab_tags,
    1183              :                            LTO_symtab_last_tag, LTO_symtab_indirect_function);
    1184            0 :       lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
    1185            0 :                               (*offload_ind_funcs)[i]);
    1186              :     }
    1187              : 
    1188            0 :   if (output_requires)
    1189              :     {
    1190            0 :       HOST_WIDE_INT val = ((HOST_WIDE_INT) omp_requires_mask
    1191              :                            & (OMP_REQUIRES_UNIFIED_ADDRESS
    1192              :                               | OMP_REQUIRES_UNIFIED_SHARED_MEMORY
    1193              :                               | OMP_REQUIRES_SELF_MAPS
    1194              :                               | OMP_REQUIRES_REVERSE_OFFLOAD
    1195              :                               | OMP_REQUIRES_TARGET_USED));
    1196              :       /* (Mis)use LTO_symtab_edge for this variable.  */
    1197            0 :       streamer_write_enum (ob->main_stream, LTO_symtab_tags,
    1198              :                            LTO_symtab_last_tag, LTO_symtab_edge);
    1199            0 :       streamer_write_hwi_stream (ob->main_stream, val);
    1200              :     }
    1201              : 
    1202            0 :   streamer_write_uhwi_stream (ob->main_stream, 0);
    1203            0 :   lto_destroy_simple_output_block (ob);
    1204              : }
    1205              : 
    1206              : /* Verify the partitioning of NODE.  */
    1207              : 
    1208              : static inline void
    1209       267627 : verify_node_partition (symtab_node *node)
    1210              : {
    1211       267627 :   if (flag_ltrans)
    1212              :     return;
    1213              : 
    1214              : #ifdef ACCEL_COMPILER
    1215              :   if (node->in_other_partition)
    1216              :     {
    1217              :       if (TREE_CODE (node->decl) == FUNCTION_DECL)
    1218              :         {
    1219              :           if (lookup_attribute ("omp target device_ancestor_host",
    1220              :                                 DECL_ATTRIBUTES (node->decl)) != NULL)
    1221              :             return;
    1222              :           error_at (DECL_SOURCE_LOCATION (node->decl),
    1223              :                     "function %qs has been referenced in offloaded code but"
    1224              :                     " hasn%'t been marked to be included in the offloaded code",
    1225              :                     node->name ());
    1226              :         }
    1227              :       else if (VAR_P (node->decl))
    1228              :         error_at (DECL_SOURCE_LOCATION (node->decl),
    1229              :                   "variable %qs has been referenced in offloaded code but"
    1230              :                   " hasn%'t been marked to be included in the offloaded code",
    1231              :                   node->name ());
    1232              :       else
    1233              :         gcc_unreachable ();
    1234              :     }
    1235              : #else
    1236       159117 :   gcc_assert (!node->in_other_partition
    1237              :               && !node->used_from_other_partition);
    1238              : #endif
    1239              : }
    1240              : 
    1241              : /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
    1242              :    STACK_SIZE, SELF_TIME and SELF_SIZE.  This is called either to initialize
    1243              :    NODE or to replace the values in it, for instance because the first
    1244              :    time we saw it, the function body was not available but now it
    1245              :    is.  BP is a bitpack with all the bitflags for NODE read from the
    1246              :    stream.  Initialize HAS_THUNK_INFO to indicate if thunk info should
    1247              :    be streamed in.  */
    1248              : 
    1249              : static void
    1250       196702 : input_overwrite_node (struct lto_file_decl_data *file_data,
    1251              :                       struct cgraph_node *node,
    1252              :                       enum LTO_symtab_tags tag,
    1253              :                       struct bitpack_d *bp, bool *has_thunk_info)
    1254              : {
    1255       196702 :   node->aux = (void *) tag;
    1256       196702 :   node->lto_file_data = file_data;
    1257              : 
    1258       196702 :   node->local = bp_unpack_value (bp, 1);
    1259       196702 :   node->externally_visible = bp_unpack_value (bp, 1);
    1260       196702 :   node->no_reorder = bp_unpack_value (bp, 1);
    1261       196702 :   node->definition = bp_unpack_value (bp, 1);
    1262       196702 :   node->versionable = bp_unpack_value (bp, 1);
    1263       196702 :   node->can_change_signature = bp_unpack_value (bp, 1);
    1264       196702 :   node->redefined_extern_inline = bp_unpack_value (bp, 1);
    1265       196702 :   node->force_output = bp_unpack_value (bp, 1);
    1266       196702 :   node->forced_by_abi = bp_unpack_value (bp, 1);
    1267       196702 :   node->ref_by_asm = bp_unpack_value (bp, 1);
    1268       196702 :   node->must_remain_in_tu_name = bp_unpack_value (bp, 1);
    1269       196702 :   node->must_remain_in_tu_body = bp_unpack_value (bp, 1);
    1270       196702 :   node->unique_name = bp_unpack_value (bp, 1);
    1271       196702 :   node->body_removed = bp_unpack_value (bp, 1);
    1272       196702 :   node->semantic_interposition = bp_unpack_value (bp, 1);
    1273       196702 :   node->implicit_section = bp_unpack_value (bp, 1);
    1274       196702 :   node->address_taken = bp_unpack_value (bp, 1);
    1275       196702 :   node->used_from_other_partition = bp_unpack_value (bp, 1);
    1276       196702 :   node->lowered = bp_unpack_value (bp, 1);
    1277       196702 :   node->analyzed = tag == LTO_symtab_analyzed_node;
    1278       196702 :   node->in_other_partition = bp_unpack_value (bp, 1);
    1279       196702 :   if (node->in_other_partition
    1280              :       /* Avoid updating decl when we are seeing just inline clone.
    1281              :          When inlining function that has functions already inlined into it,
    1282              :          we produce clones of inline clones.
    1283              : 
    1284              :          WPA partitioning might put each clone into different unit and
    1285              :          we might end up streaming inline clone from other partition
    1286              :          to support clone we are interested in. */
    1287          255 :       && (!node->clone_of
    1288            0 :           || node->clone_of->decl != node->decl))
    1289              :     {
    1290          255 :       DECL_EXTERNAL (node->decl) = 1;
    1291          255 :       TREE_STATIC (node->decl) = 0;
    1292              :     }
    1293       196702 :   node->alias = bp_unpack_value (bp, 1);
    1294       196702 :   node->transparent_alias = bp_unpack_value (bp, 1);
    1295       196702 :   node->weakref = bp_unpack_value (bp, 1);
    1296       196702 :   node->symver = bp_unpack_value (bp, 1);
    1297       196702 :   node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
    1298       196702 :   node->only_called_at_startup = bp_unpack_value (bp, 1);
    1299       196702 :   node->only_called_at_exit = bp_unpack_value (bp, 1);
    1300       196702 :   node->tm_clone = bp_unpack_value (bp, 1);
    1301       196702 :   node->calls_comdat_local = bp_unpack_value (bp, 1);
    1302       196702 :   node->icf_merged = bp_unpack_value (bp, 1);
    1303       196702 :   node->nonfreeing_fn = bp_unpack_value (bp, 1);
    1304       196702 :   node->merged_comdat = bp_unpack_value (bp, 1);
    1305       196702 :   node->merged_extern_inline = bp_unpack_value (bp, 1);
    1306       196702 :   node->thunk = bp_unpack_value (bp, 1);
    1307       196702 :   node->parallelized_function = bp_unpack_value (bp, 1);
    1308       196702 :   node->has_omp_variant_constructs = bp_unpack_value (bp, 1);
    1309       196702 :   *has_thunk_info = bp_unpack_value (bp, 1);
    1310       196702 :   node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
    1311              :                                      LDPR_NUM_KNOWN);
    1312       196702 :   node->split_part = bp_unpack_value (bp, 1);
    1313       196702 :   verify_node_partition (node);
    1314       196702 : }
    1315              : 
    1316              : /* Return string alias is alias of.  */
    1317              : 
    1318              : static tree
    1319           24 : get_alias_symbol (tree decl)
    1320              : {
    1321           24 :   tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
    1322           24 :   return get_identifier (TREE_STRING_POINTER
    1323              :                           (TREE_VALUE (TREE_VALUE (alias))));
    1324              : }
    1325              : 
    1326              : /* Read a node from input_block IB.  TAG is the node's tag just read.
    1327              :    Return the node read or overwritten.  */
    1328              : 
    1329              : static struct cgraph_node *
    1330       196702 : input_node (struct lto_file_decl_data *file_data,
    1331              :             class lto_input_block *ib,
    1332              :             enum LTO_symtab_tags tag,
    1333              :             vec<symtab_node *> nodes)
    1334              : {
    1335       196702 :   gcc::pass_manager *passes = g->get_passes ();
    1336       196702 :   tree fn_decl;
    1337       196702 :   struct cgraph_node *node;
    1338       196702 :   struct bitpack_d bp;
    1339       196702 :   int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
    1340       196702 :   int clone_ref;
    1341       196702 :   int order;
    1342       196702 :   int i, count;
    1343       196702 :   tree group;
    1344       196702 :   const char *section;
    1345       196702 :   order = streamer_read_hwi (ib) + file_data->order_base;
    1346       196702 :   clone_ref = streamer_read_hwi (ib);
    1347       196702 :   bool has_thunk_info;
    1348              : 
    1349       196702 :   fn_decl = lto_input_fn_decl_ref (ib, file_data);
    1350              : 
    1351       196702 :   if (clone_ref != LCC_NOT_FOUND)
    1352              :     {
    1353        46458 :       node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
    1354              :         profile_count::uninitialized (), false,
    1355        23229 :         vNULL, false, NULL, NULL, NULL);
    1356              :     }
    1357              :   else
    1358              :     {
    1359              :       /* Declaration of functions can be already merged with a declaration
    1360              :          from other input file.  We keep cgraph unmerged until after streaming
    1361              :          of ipa passes is done.  Alays forcingly create a fresh node.  */
    1362       173473 :       node = symtab->create_empty ();
    1363       173473 :       node->decl = fn_decl;
    1364       173473 :       if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl)))
    1365           19 :         node->ifunc_resolver = 1;
    1366       173473 :       node->register_symbol ();
    1367              :     }
    1368              : 
    1369       196702 :   node->order = order;
    1370       196702 :   if (order >= symtab->order)
    1371        14601 :     symtab->order = order + 1;
    1372              : 
    1373       196702 :   node->count = profile_count::stream_in (ib);
    1374       196702 :   node->count_materialization_scale = streamer_read_hwi (ib);
    1375              : 
    1376       196702 :   count = streamer_read_hwi (ib);
    1377       196702 :   node->ipa_transforms_to_apply = vNULL;
    1378       264670 :   for (i = 0; i < count; i++)
    1379              :     {
    1380        67968 :       opt_pass *pass;
    1381        67968 :       int pid = streamer_read_hwi (ib);
    1382              : 
    1383        67968 :       gcc_assert (pid < passes->passes_by_id_size);
    1384        67968 :       pass = passes->passes_by_id[pid];
    1385        67968 :       node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
    1386              :     }
    1387              : 
    1388       196702 :   if (tag == LTO_symtab_analyzed_node)
    1389       153122 :     ref = streamer_read_hwi (ib);
    1390              : 
    1391       196702 :   group = read_identifier (ib);
    1392       196702 :   if (group)
    1393         7489 :     ref2 = streamer_read_hwi (ib);
    1394              : 
    1395              :   /* Make sure that we have not read this node before.  Nodes that
    1396              :      have already been read will have their tag stored in the 'aux'
    1397              :      field.  Since built-in functions can be referenced in multiple
    1398              :      functions, they are expected to be read more than once.  */
    1399       196702 :   if (node->aux && !fndecl_built_in_p (node->decl))
    1400            0 :     internal_error ("bytecode stream: found multiple instances of cgraph "
    1401              :                     "node with uid %d", node->get_uid ());
    1402              : 
    1403       196702 :   node->tp_first_run = streamer_read_uhwi (ib);
    1404              : 
    1405       196702 :   bp = streamer_read_bitpack (ib);
    1406              : 
    1407       196702 :   input_overwrite_node (file_data, node, tag, &bp, &has_thunk_info);
    1408              : 
    1409              :   /* Store a reference for now, and fix up later to be a pointer.  */
    1410       196702 :   node->inlined_to = (cgraph_node *) (intptr_t) ref;
    1411              : 
    1412       196702 :   if (group)
    1413              :     {
    1414         7489 :       node->set_comdat_group (group);
    1415              :       /* Store a reference for now, and fix up later to be a pointer.  */
    1416         7489 :       node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
    1417              :     }
    1418              :   else
    1419              :     node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
    1420       196702 :   section = read_string (ib);
    1421       196702 :   if (section)
    1422          182 :     node->set_section_for_node (section);
    1423              : 
    1424       196702 :   if (node->alias && !node->analyzed && node->weakref)
    1425           24 :     node->alias_target = get_alias_symbol (node->decl);
    1426       196702 :   node->profile_id = streamer_read_hwi (ib);
    1427       196702 :   node->unit_id = streamer_read_hwi (ib) + file_data->unit_base;
    1428       196702 :   if (symtab->max_unit < node->unit_id)
    1429        21856 :     symtab->max_unit = node->unit_id;
    1430       196702 :   if (DECL_STATIC_CONSTRUCTOR (node->decl))
    1431          150 :     node->set_init_priority (streamer_read_hwi (ib));
    1432       196702 :   if (DECL_STATIC_DESTRUCTOR (node->decl))
    1433           54 :     node->set_fini_priority (streamer_read_hwi (ib));
    1434              : 
    1435       196702 :   if (has_thunk_info)
    1436          159 :     thunk_info::get_create (node)->stream_in (ib);
    1437              : 
    1438       196702 :   return node;
    1439              : }
    1440              : 
    1441              : /* Read a node from input_block IB.  TAG is the node's tag just read.
    1442              :    Return the node read or overwritten.  */
    1443              : 
    1444              : static varpool_node *
    1445        70925 : input_varpool_node (struct lto_file_decl_data *file_data,
    1446              :                     class lto_input_block *ib)
    1447              : {
    1448        70925 :   tree var_decl;
    1449        70925 :   varpool_node *node;
    1450        70925 :   struct bitpack_d bp;
    1451        70925 :   int ref = LCC_NOT_FOUND;
    1452        70925 :   int order;
    1453        70925 :   tree group;
    1454        70925 :   const char *section;
    1455              : 
    1456        70925 :   order = streamer_read_hwi (ib) + file_data->order_base;
    1457        70925 :   var_decl = lto_input_var_decl_ref (ib, file_data);
    1458              : 
    1459              :   /* Declaration of functions can be already merged with a declaration
    1460              :      from other input file.  We keep cgraph unmerged until after streaming
    1461              :      of ipa passes is done.  Alays forcingly create a fresh node.  */
    1462        70925 :   node = varpool_node::create_empty ();
    1463        70925 :   node->decl = var_decl;
    1464        70925 :   node->register_symbol ();
    1465              : 
    1466        70925 :   node->order = order;
    1467        70925 :   if (order >= symtab->order)
    1468         1693 :     symtab->order = order + 1;
    1469        70925 :   node->lto_file_data = file_data;
    1470              : 
    1471        70925 :   bp = streamer_read_bitpack (ib);
    1472        70925 :   node->externally_visible = bp_unpack_value (&bp, 1);
    1473        70925 :   node->no_reorder = bp_unpack_value (&bp, 1);
    1474        70925 :   node->force_output = bp_unpack_value (&bp, 1);
    1475        70925 :   node->forced_by_abi = bp_unpack_value (&bp, 1);
    1476        70925 :   node->ref_by_asm = bp_unpack_value (&bp, 1);
    1477        70925 :   node->must_remain_in_tu_name = bp_unpack_value (&bp, 1);
    1478        70925 :   node->must_remain_in_tu_body = bp_unpack_value (&bp, 1);
    1479        70925 :   node->unique_name = bp_unpack_value (&bp, 1);
    1480        70925 :   node->body_removed = bp_unpack_value (&bp, 1);
    1481        70925 :   node->semantic_interposition = bp_unpack_value (&bp, 1);
    1482        70925 :   node->implicit_section = bp_unpack_value (&bp, 1);
    1483        70925 :   node->writeonly = bp_unpack_value (&bp, 1);
    1484        70925 :   node->definition = bp_unpack_value (&bp, 1);
    1485        70925 :   node->alias = bp_unpack_value (&bp, 1);
    1486        70925 :   node->transparent_alias = bp_unpack_value (&bp, 1);
    1487        70925 :   node->weakref = bp_unpack_value (&bp, 1);
    1488        70925 :   node->symver = bp_unpack_value (&bp, 1);
    1489        70925 :   node->analyzed = bp_unpack_value (&bp, 1);
    1490        70925 :   node->used_from_other_partition = bp_unpack_value (&bp, 1);
    1491        70925 :   node->in_other_partition = bp_unpack_value (&bp, 1);
    1492        70925 :   if (node->in_other_partition)
    1493              :     {
    1494          203 :       DECL_EXTERNAL (node->decl) = 1;
    1495          203 :       TREE_STATIC (node->decl) = 0;
    1496              :     }
    1497        70925 :   if (node->alias && !node->analyzed && node->weakref)
    1498            0 :     node->alias_target = get_alias_symbol (node->decl);
    1499        70925 :   node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
    1500        70925 :   node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
    1501        70925 :   node->dynamically_initialized = bp_unpack_value (&bp, 1);
    1502        70925 :   group = read_identifier (ib);
    1503        70925 :   if (group)
    1504              :     {
    1505         2438 :       node->set_comdat_group (group);
    1506         2438 :       ref = streamer_read_hwi (ib);
    1507              :       /* Store a reference for now, and fix up later to be a pointer.  */
    1508         2438 :       node->same_comdat_group = (symtab_node *) (intptr_t) ref;
    1509              :     }
    1510              :   else
    1511              :     node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
    1512        70925 :   section = read_string (ib);
    1513        70925 :   if (section)
    1514         2329 :     node->set_section_for_node (section);
    1515        70925 :   node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
    1516              :                                                 LDPR_NUM_KNOWN);
    1517        70925 :   verify_node_partition (node);
    1518        70925 :   return node;
    1519              : }
    1520              : 
    1521              : /* Read a node from input_block IB.  TAG is the node's tag just read.
    1522              :    Return the node read or overwritten.  */
    1523              : 
    1524              : static void
    1525       448293 : input_ref (class lto_input_block *ib,
    1526              :            symtab_node *referring_node,
    1527              :            vec<symtab_node *> nodes)
    1528              : {
    1529       448293 :   symtab_node *node = NULL;
    1530       448293 :   struct bitpack_d bp;
    1531       448293 :   enum ipa_ref_use use;
    1532       448293 :   bool speculative;
    1533       448293 :   struct ipa_ref *ref;
    1534              : 
    1535       448293 :   bp = streamer_read_bitpack (ib);
    1536       448293 :   use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
    1537       448293 :   speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
    1538       448293 :   node = nodes[streamer_read_hwi (ib)];
    1539       448293 :   ref = referring_node->create_reference (node, use);
    1540       448293 :   ref->speculative = speculative;
    1541       448293 :   if (is_a <cgraph_node *> (referring_node))
    1542              :     {
    1543       427630 :       ref->lto_stmt_uid = streamer_read_hwi (ib);
    1544       427630 :       bp = streamer_read_bitpack (ib);
    1545       427630 :       ref->speculative_id = bp_unpack_value (&bp, 16);
    1546              :     }
    1547       448293 : }
    1548              : 
    1549              : /* Read an edge from IB.  NODES points to a vector of previously read nodes for
    1550              :    decoding caller and callee of the edge to be read.  If INDIRECT is true, the
    1551              :    edge being read is indirect (in the sense that it has
    1552              :    indirect_unknown_callee set).  */
    1553              : 
    1554              : static void
    1555       601397 : input_edge (class lto_input_block *ib, vec<symtab_node *> nodes,
    1556              :             bool indirect)
    1557              : {
    1558       601397 :   struct cgraph_node *caller, *callee;
    1559       601397 :   struct cgraph_edge *edge;
    1560       601397 :   unsigned int stmt_id, speculative_id;
    1561       601397 :   profile_count count;
    1562       601397 :   cgraph_inline_failed_t inline_failed;
    1563       601397 :   struct bitpack_d bp;
    1564              : 
    1565       601397 :   caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
    1566       601397 :   if (caller == NULL || caller->decl == NULL_TREE)
    1567            0 :     internal_error ("bytecode stream: no caller found while reading edge");
    1568              : 
    1569       601397 :   if (!indirect)
    1570              :     {
    1571       598992 :       callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
    1572       598992 :       if (callee == NULL || callee->decl == NULL_TREE)
    1573            0 :         internal_error ("bytecode stream: no callee found while reading edge");
    1574              :     }
    1575              :   else
    1576              :     callee = NULL;
    1577              : 
    1578       601397 :   count = profile_count::stream_in (ib);
    1579              : 
    1580       601397 :   bp = streamer_read_bitpack (ib);
    1581       601397 :   inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
    1582       601397 :   stmt_id = bp_unpack_var_len_unsigned (&bp);
    1583       601397 :   speculative_id = bp_unpack_value (&bp, 16);
    1584              : 
    1585       601397 :   if (indirect)
    1586         2405 :     edge = caller->create_indirect_edge (NULL, 0, count, true);
    1587              :   else
    1588       598992 :     edge = caller->create_edge (callee, NULL, count);
    1589              : 
    1590       601397 :   edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
    1591       601397 :   edge->speculative = bp_unpack_value (&bp, 1);
    1592       601397 :   edge->callback = bp_unpack_value(&bp, 1);
    1593       601397 :   edge->has_callback = bp_unpack_value(&bp, 1);
    1594              : 
    1595       601397 :   if (edge->callback)
    1596              :     {
    1597            4 :       callback_info *ci = callback_info_sum->get_create (edge);
    1598            4 :       ci->stream_in (ib);
    1599              :     }
    1600              : 
    1601       601397 :   edge->lto_stmt_uid = stmt_id;
    1602       601397 :   edge->speculative_id = speculative_id;
    1603       601397 :   edge->inline_failed = inline_failed;
    1604       601397 :   edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
    1605       601397 :   edge->can_throw_external = bp_unpack_value (&bp, 1);
    1606       601397 :   edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
    1607       601397 :   if (indirect)
    1608              :     {
    1609         2405 :       enum cgraph_indirect_info_kind ii_kind
    1610         2405 :         = bp_unpack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS);
    1611         2405 :       int ecf_flags = 0;
    1612         2405 :       if (bp_unpack_value (&bp, 1))
    1613            0 :         ecf_flags |= ECF_CONST;
    1614         2405 :       if (bp_unpack_value (&bp, 1))
    1615            0 :         ecf_flags |= ECF_PURE;
    1616         2405 :       if (bp_unpack_value (&bp, 1))
    1617            0 :         ecf_flags |= ECF_NORETURN;
    1618         2405 :       if (bp_unpack_value (&bp, 1))
    1619            0 :         ecf_flags |= ECF_MALLOC;
    1620         2405 :       if (bp_unpack_value (&bp, 1))
    1621          288 :         ecf_flags |= ECF_NOTHROW;
    1622         2405 :       if (bp_unpack_value (&bp, 1))
    1623            0 :         ecf_flags |= ECF_RETURNS_TWICE;
    1624              : 
    1625         2405 :       if (ii_kind == CIIK_POLYMORPHIC)
    1626          426 :         edge->indirect_info
    1627          426 :           = (new (ggc_alloc<cgraph_polymorphic_indirect_info> ())
    1628          426 :              cgraph_polymorphic_indirect_info (ecf_flags));
    1629         1979 :       else if (ii_kind == CIIK_SIMPLE)
    1630         1965 :         edge->indirect_info
    1631         1965 :           = (new (ggc_alloc<cgraph_simple_indirect_info> ())
    1632         1965 :              cgraph_simple_indirect_info (ecf_flags));
    1633              :       else
    1634           14 :         edge->indirect_info
    1635           14 :           = (new (ggc_alloc<cgraph_indirect_call_info> ())
    1636           14 :              cgraph_indirect_call_info(CIIK_UNSPECIFIED, ecf_flags));
    1637              : 
    1638         4810 :       edge->indirect_info->num_speculative_call_targets
    1639         2405 :         = bp_unpack_value (&bp, 16);
    1640              :     }
    1641       601397 : }
    1642              : 
    1643              : 
    1644              : /* Read a cgraph from IB using the info in FILE_DATA.  */
    1645              : 
    1646              : static vec<symtab_node *>
    1647        21740 : input_cgraph_1 (struct lto_file_decl_data *file_data,
    1648              :                 class lto_input_block *ib)
    1649              : {
    1650        21740 :   enum LTO_symtab_tags tag;
    1651        21740 :   vec<symtab_node *> nodes = vNULL;
    1652        21740 :   symtab_node *node;
    1653        21740 :   unsigned i;
    1654              : 
    1655        21740 :   tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    1656        21740 :   file_data->order_base = symtab->order;
    1657        21740 :   file_data->unit_base = symtab->max_unit + 1;
    1658        21740 :   callback_info_sum_t::check_create_info_sum ();
    1659       912504 :   while (tag)
    1660              :     {
    1661       869024 :       if (tag == LTO_symtab_edge)
    1662       598992 :         input_edge (ib, nodes, false);
    1663       270032 :       else if (tag == LTO_symtab_indirect_edge)
    1664         2405 :         input_edge (ib, nodes, true);
    1665       267627 :       else if (tag == LTO_symtab_variable)
    1666              :         {
    1667        70925 :           node = input_varpool_node (file_data, ib);
    1668        70925 :           nodes.safe_push (node);
    1669        70925 :           lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
    1670              :         }
    1671              :       else
    1672              :         {
    1673       196702 :           node = input_node (file_data, ib, tag, nodes);
    1674       196702 :           if (node == NULL || node->decl == NULL_TREE)
    1675            0 :             internal_error ("bytecode stream: found empty cgraph node");
    1676       196702 :           nodes.safe_push (node);
    1677       196702 :           lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
    1678              :         }
    1679              : 
    1680       869024 :       tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    1681              :     }
    1682              : 
    1683              :   /* AUX pointers should be all non-zero for function nodes read from the stream.  */
    1684        21740 :   if (flag_checking)
    1685              :     {
    1686       311046 :       FOR_EACH_VEC_ELT (nodes, i, node)
    1687       267627 :         gcc_assert (node->aux || !is_a <cgraph_node *> (node));
    1688              :     }
    1689       311046 :   FOR_EACH_VEC_ELT (nodes, i, node)
    1690              :     {
    1691       267627 :       int ref;
    1692       267627 :       if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
    1693              :         {
    1694       196702 :           ref = (int) (intptr_t) cnode->inlined_to;
    1695              : 
    1696              :           /* We share declaration of builtins, so we may read same node twice.  */
    1697       196702 :           if (!node->aux)
    1698            0 :             continue;
    1699       196702 :           node->aux = NULL;
    1700              : 
    1701              :           /* Fixup inlined_to from reference to pointer.  */
    1702       196702 :           if (ref != LCC_NOT_FOUND)
    1703        42804 :             dyn_cast<cgraph_node *> (node)->inlined_to
    1704        42804 :               = dyn_cast<cgraph_node *> (nodes[ref]);
    1705              :           else
    1706       175300 :             cnode->inlined_to = NULL;
    1707              :         }
    1708              : 
    1709       267627 :       ref = (int) (intptr_t) node->same_comdat_group;
    1710              : 
    1711              :       /* Fixup same_comdat_group from reference to pointer.  */
    1712       267627 :       if (ref != LCC_NOT_FOUND)
    1713         3891 :         node->same_comdat_group = nodes[ref];
    1714              :       else
    1715       263736 :         node->same_comdat_group = NULL;
    1716              :     }
    1717       289367 :   FOR_EACH_VEC_ELT (nodes, i, node)
    1718       535254 :     node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
    1719        21740 :   return nodes;
    1720              : }
    1721              : 
    1722              : /* Input ipa_refs.  */
    1723              : 
    1724              : static void
    1725        21740 : input_refs (class lto_input_block *ib,
    1726              :             vec<symtab_node *> nodes)
    1727              : {
    1728        86800 :   int count;
    1729        86800 :   int idx;
    1730        86800 :   while (true)
    1731              :     {
    1732        86800 :       symtab_node *node;
    1733        86800 :       count = streamer_read_uhwi (ib);
    1734        86800 :       if (!count)
    1735              :         break;
    1736        65060 :       idx = streamer_read_uhwi (ib);
    1737        65060 :       node = nodes[idx];
    1738       513353 :       while (count)
    1739              :         {
    1740       448293 :           input_ref (ib, node, nodes);
    1741       448293 :           count--;
    1742              :         }
    1743              :     }
    1744        21740 : }
    1745              : 
    1746              : /* Input profile_info from IB.  */
    1747              : static void
    1748        21740 : input_profile_summary (class lto_input_block *ib,
    1749              :                        struct lto_file_decl_data *file_data)
    1750              : {
    1751        21740 :   unsigned int runs = streamer_read_uhwi (ib);
    1752        21740 :   if (runs)
    1753              :     {
    1754           11 :       file_data->profile_info.runs = runs;
    1755           11 :       file_data->profile_info.sum_max = streamer_read_gcov_count (ib);
    1756           11 :       file_data->profile_info.cutoff = streamer_read_gcov_count (ib);
    1757              : 
    1758              :       /* IPA-profile computes hot bb threshold based on cumulated
    1759              :          whole program profile.  We need to stream it down to ltrans.  */
    1760           11 :       if (flag_ltrans)
    1761            4 :         set_hot_bb_threshold (streamer_read_gcov_count (ib));
    1762              :     }
    1763              : 
    1764        21740 : }
    1765              : 
    1766              : /* Rescale profile summaries to the same number of runs in the whole unit.  */
    1767              : 
    1768              : static void
    1769        20654 : merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
    1770              : {
    1771        20654 :   struct lto_file_decl_data *file_data;
    1772        20654 :   unsigned int j;
    1773        20654 :   gcov_unsigned_t max_runs = 0;
    1774        20654 :   struct cgraph_node *node;
    1775        20654 :   struct cgraph_edge *edge;
    1776              : 
    1777              :   /* Find unit with maximal number of runs.  If we ever get serious about
    1778              :      roundoff errors, we might also consider computing smallest common
    1779              :      multiply.  */
    1780        42394 :   for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
    1781        21740 :     if (max_runs < file_data->profile_info.runs)
    1782              :       max_runs = file_data->profile_info.runs;
    1783              : 
    1784        20654 :   if (!max_runs)
    1785              :     return;
    1786              : 
    1787              :   /* Simple overflow check.  We probably don't need to support that many train
    1788              :      runs. Such a large value probably imply data corruption anyway.  */
    1789            8 :   if (max_runs > INT_MAX / REG_BR_PROB_BASE)
    1790              :     {
    1791            0 :       sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
    1792              :              INT_MAX / REG_BR_PROB_BASE);
    1793            0 :       return;
    1794              :     }
    1795              : 
    1796            8 :   profile_info = XCNEW (gcov_summary);
    1797            8 :   profile_info->runs = max_runs;
    1798            8 :   profile_info->sum_max = 0;
    1799            8 :   profile_info->cutoff = 0;
    1800              : 
    1801              :   /* If merging already happent at WPA time, we are done.  */
    1802            8 :   if (flag_ltrans)
    1803              :     return;
    1804              : 
    1805              :   /* Now compute count_materialization_scale of each node.
    1806              :      During LTRANS we already have values of count_materialization_scale
    1807              :      computed, so just update them.  */
    1808           29 :   FOR_EACH_FUNCTION (node)
    1809           25 :     if (node->lto_file_data
    1810           25 :         && node->lto_file_data->profile_info.runs)
    1811              :       {
    1812           25 :         int scale;
    1813              : 
    1814           25 :         scale = RDIV (node->count_materialization_scale * max_runs,
    1815              :                       node->lto_file_data->profile_info.runs);
    1816           25 :         gcov_type sum_max = RDIV (node->lto_file_data->profile_info.sum_max * max_runs,
    1817              :                                   node->lto_file_data->profile_info.runs);
    1818           25 :         gcov_type cutoff = RDIV (node->lto_file_data->profile_info.cutoff * max_runs,
    1819              :                                  node->lto_file_data->profile_info.runs);
    1820           25 :         if (sum_max > profile_info->sum_max)
    1821            4 :           profile_info->sum_max = sum_max;
    1822           25 :         if (cutoff > profile_info->cutoff)
    1823            4 :           profile_info->cutoff = cutoff;
    1824           25 :         node->count_materialization_scale = scale;
    1825           25 :         if (scale < 0)
    1826            0 :           fatal_error (input_location, "Profile information in %s corrupted",
    1827              :                        file_data->file_name);
    1828              : 
    1829           25 :         if (scale == REG_BR_PROB_BASE)
    1830           25 :           continue;
    1831            0 :         for (edge = node->callees; edge; edge = edge->next_callee)
    1832            0 :           if (edge->count.ipa ().nonzero_p ())
    1833            0 :             edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
    1834            0 :         for (edge = node->indirect_calls; edge; edge = edge->next_callee)
    1835            0 :           if (edge->count.ipa ().nonzero_p ())
    1836            0 :             edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
    1837            0 :         if (node->count.ipa ().nonzero_p ())
    1838            0 :           node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE);
    1839              :       }
    1840              : }
    1841              : 
    1842              : /* Input and merge the symtab from each of the .o files passed to
    1843              :    lto1.  */
    1844              : 
    1845              : void
    1846        20654 : input_symtab (void)
    1847              : {
    1848        20654 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    1849        20654 :   struct lto_file_decl_data *file_data;
    1850        20654 :   unsigned int j = 0;
    1851        20654 :   struct cgraph_node *node;
    1852              : 
    1853        63048 :   while ((file_data = file_data_vec[j++]))
    1854              :     {
    1855        21740 :       const char *data;
    1856        21740 :       size_t len;
    1857        21740 :       class lto_input_block *ib;
    1858        21740 :       vec<symtab_node *> nodes;
    1859              : 
    1860        21740 :       ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
    1861              :                                           &data, &len);
    1862        21740 :       if (!ib)
    1863            0 :         fatal_error (input_location,
    1864              :                      "cannot find LTO cgraph in %s", file_data->file_name);
    1865        21740 :       input_profile_summary (ib, file_data);
    1866        21740 :       file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
    1867        21740 :       nodes = input_cgraph_1 (file_data, ib);
    1868        21740 :       lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
    1869              :                                       ib, data, len);
    1870              : 
    1871        21740 :       ib = lto_create_simple_input_block (file_data, LTO_section_refs,
    1872              :                                           &data, &len);
    1873        21740 :       if (!ib)
    1874            0 :         fatal_error (input_location, "cannot find LTO section refs in %s",
    1875              :                      file_data->file_name);
    1876        21740 :       input_refs (ib, nodes);
    1877        21740 :       lto_destroy_simple_input_block (file_data, LTO_section_refs,
    1878              :                                       ib, data, len);
    1879        21740 :       if (flag_ltrans)
    1880         8274 :         input_cgraph_opt_summary (nodes);
    1881        21740 :       nodes.release ();
    1882              :     }
    1883              : 
    1884        20654 :   merge_profile_summaries (file_data_vec);
    1885              : 
    1886              :   /* Clear out the aux field that was used to store enough state to
    1887              :      tell which nodes should be overwritten.  */
    1888       217356 :   FOR_EACH_FUNCTION (node)
    1889              :     {
    1890              :       /* Some nodes may have been created by cgraph_node.  This
    1891              :          happens when the callgraph contains nested functions.  If the
    1892              :          node for the parent function was never emitted to the gimple
    1893              :          file, cgraph_node will create a node for it when setting the
    1894              :          context of the nested function.  */
    1895       196702 :       if (node->lto_file_data)
    1896       196702 :         node->aux = NULL;
    1897              :     }
    1898        20654 : }
    1899              : 
    1900              : /* Input toplevel asms from each of the .o files passed to lto1.
    1901              :    Must be called after merging of decls.  */
    1902              : void
    1903        20654 : input_toplevel_asms (void)
    1904              : {
    1905        20654 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    1906        20654 :   struct lto_file_decl_data *file_data;
    1907        20654 :   unsigned int j = 0;
    1908              : 
    1909        63048 :   while ((file_data = file_data_vec[j++]))
    1910        21740 :     lto_input_toplevel_asms (file_data, file_data->order_base);
    1911        20654 : }
    1912              : 
    1913              : static void
    1914            0 : omp_requires_to_name (char *buf, size_t size, HOST_WIDE_INT requires_mask)
    1915              : {
    1916            0 :   char *end = buf + size, *p = buf;
    1917            0 :   if (requires_mask & GOMP_REQUIRES_UNIFIED_ADDRESS)
    1918            0 :     p += snprintf (p, end - p, "unified_address");
    1919            0 :   if (requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY)
    1920            0 :     p += snprintf (p, end - p, "%sunified_shared_memory",
    1921              :                    (p == buf ? "" : ", "));
    1922            0 :   if (requires_mask & GOMP_REQUIRES_SELF_MAPS)
    1923            0 :     p += snprintf (p, end - p, "%sself_maps",
    1924              :                    (p == buf ? "" : ", "));
    1925            0 :   if (requires_mask & GOMP_REQUIRES_REVERSE_OFFLOAD)
    1926            0 :     p += snprintf (p, end - p, "%sreverse_offload",
    1927              :                    (p == buf ? "" : ", "));
    1928            0 : }
    1929              : 
    1930              : /* Input function/variable tables that will allow libgomp to look up offload
    1931              :    target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS.  */
    1932              : 
    1933              : void
    1934        20654 : input_offload_tables (bool do_force_output)
    1935              : {
    1936        20654 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    1937        20654 :   struct lto_file_decl_data *file_data;
    1938        20654 :   unsigned int j = 0;
    1939        20654 :   const char *requires_fn = NULL;
    1940        20654 :   tree requires_decl = NULL_TREE;
    1941              : 
    1942        20654 :   omp_requires_mask = (omp_requires) 0;
    1943              : 
    1944        42394 :   while ((file_data = file_data_vec[j++]))
    1945              :     {
    1946        21740 :       const char *data;
    1947        21740 :       size_t len;
    1948        21740 :       class lto_input_block *ib
    1949        21740 :         = lto_create_simple_input_block (file_data, LTO_section_offload_table,
    1950              :                                          &data, &len);
    1951        21740 :       if (!ib)
    1952        21740 :         continue;
    1953              : 
    1954            0 :       tree tmp_decl = NULL_TREE;
    1955            0 :       enum LTO_symtab_tags tag
    1956            0 :         = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    1957            0 :       while (tag)
    1958              :         {
    1959              :           if (tag == LTO_symtab_unavail_node)
    1960              :             {
    1961            0 :               tree fn_decl
    1962            0 :                 = lto_input_fn_decl_ref (ib, file_data);
    1963            0 :               vec_safe_push (offload_funcs, fn_decl);
    1964              : 
    1965              :               /* Prevent IPA from removing fn_decl as unreachable, since there
    1966              :                  may be no refs from the parent function to child_fn in offload
    1967              :                  LTO mode.  */
    1968            0 :               if (do_force_output)
    1969            0 :                 cgraph_node::get (fn_decl)->mark_force_output ();
    1970            0 :               tmp_decl = fn_decl;
    1971              :             }
    1972              :           else if (tag == LTO_symtab_variable)
    1973              :             {
    1974            0 :               tree var_decl
    1975            0 :                 = lto_input_var_decl_ref (ib, file_data);
    1976            0 :               vec_safe_push (offload_vars, var_decl);
    1977              : 
    1978              :               /* Prevent IPA from removing var_decl as unused, since there
    1979              :                  may be no refs to var_decl in offload LTO mode.  */
    1980            0 :               if (do_force_output)
    1981            0 :                 varpool_node::get (var_decl)->force_output = 1;
    1982            0 :               tmp_decl = var_decl;
    1983              :             }
    1984              :           else if (tag == LTO_symtab_indirect_function)
    1985              :             {
    1986            0 :               tree fn_decl
    1987            0 :                 = lto_input_fn_decl_ref (ib, file_data);
    1988            0 :               vec_safe_push (offload_ind_funcs, fn_decl);
    1989              : 
    1990              :               /* Prevent IPA from removing fn_decl as unreachable, since there
    1991              :                  may be no refs from the parent function to child_fn in offload
    1992              :                  LTO mode.  */
    1993            0 :               if (do_force_output)
    1994            0 :                 cgraph_node::get (fn_decl)->mark_force_output ();
    1995            0 :               tmp_decl = fn_decl;
    1996              :             }
    1997              :           else if (tag == LTO_symtab_edge)
    1998              :             {
    1999            0 :               static bool error_emitted = false;
    2000            0 :               HOST_WIDE_INT val = streamer_read_hwi (ib);
    2001              : 
    2002            0 :               if (omp_requires_mask == 0)
    2003              :                 {
    2004            0 :                   omp_requires_mask = (omp_requires) val;
    2005            0 :                   requires_decl = tmp_decl;
    2006            0 :                   requires_fn = file_data->file_name;
    2007              :                 }
    2008            0 :               else if (omp_requires_mask != val && !error_emitted)
    2009              :                 {
    2010            0 :                   const char *fn1 = requires_fn;
    2011            0 :                   if (requires_decl != NULL_TREE)
    2012              :                     {
    2013            0 :                       while (DECL_CONTEXT (requires_decl) != NULL_TREE
    2014            0 :                              && TREE_CODE (requires_decl) != TRANSLATION_UNIT_DECL)
    2015            0 :                         requires_decl = DECL_CONTEXT (requires_decl);
    2016            0 :                       if (requires_decl != NULL_TREE)
    2017            0 :                         fn1 = IDENTIFIER_POINTER (DECL_NAME (requires_decl));
    2018              :                     }
    2019              : 
    2020            0 :                   const char *fn2 = file_data->file_name;
    2021            0 :                   if (tmp_decl != NULL_TREE)
    2022              :                     {
    2023            0 :                       while (DECL_CONTEXT (tmp_decl) != NULL_TREE
    2024            0 :                              && TREE_CODE (tmp_decl) != TRANSLATION_UNIT_DECL)
    2025            0 :                         tmp_decl = DECL_CONTEXT (tmp_decl);
    2026            0 :                       if (tmp_decl != NULL_TREE)
    2027            0 :                         fn2 = IDENTIFIER_POINTER (DECL_NAME (tmp_decl));
    2028              :                     }
    2029            0 :                   if (fn1 == fn2)
    2030              :                     {
    2031            0 :                       fn1 = requires_fn;
    2032            0 :                       fn2 = file_data->file_name;
    2033              :                     }
    2034              : 
    2035            0 :                   char buf1[sizeof ("unified_address, unified_shared_memory, "
    2036              :                                     "reverse_offload")];
    2037            0 :                   char buf2[sizeof ("unified_address, unified_shared_memory, "
    2038              :                                     "reverse_offload")];
    2039            0 :                   omp_requires_to_name (buf2, sizeof (buf2),
    2040              :                                         val != OMP_REQUIRES_TARGET_USED
    2041              :                                         ? val
    2042              :                                         : (HOST_WIDE_INT) omp_requires_mask);
    2043            0 :                   if (val != OMP_REQUIRES_TARGET_USED
    2044            0 :                       && omp_requires_mask != OMP_REQUIRES_TARGET_USED)
    2045              :                     {
    2046            0 :                       omp_requires_to_name (buf1, sizeof (buf1),
    2047              :                                             omp_requires_mask);
    2048            0 :                       error ("OpenMP %<requires%> directive with non-identical "
    2049              :                              "clauses in multiple compilation units: %qs vs. "
    2050              :                              "%qs", buf1, buf2);
    2051            0 :                       inform (UNKNOWN_LOCATION, "%qs has %qs", fn1, buf1);
    2052            0 :                       inform (UNKNOWN_LOCATION, "%qs has %qs", fn2, buf2);
    2053              :                     }
    2054              :                   else
    2055              :                     {
    2056            0 :                       error ("OpenMP %<requires%> directive with %qs specified "
    2057              :                              "only in some compilation units", buf2);
    2058            0 :                       inform (UNKNOWN_LOCATION, "%qs has %qs",
    2059              :                               val != OMP_REQUIRES_TARGET_USED ? fn2 : fn1,
    2060              :                               buf2);
    2061            0 :                       inform (UNKNOWN_LOCATION, "but %qs has not",
    2062              :                               val != OMP_REQUIRES_TARGET_USED ? fn1 : fn2);
    2063              :                     }
    2064            0 :                   error_emitted = true;
    2065              :                 }
    2066              :             }
    2067              :           else
    2068            0 :             fatal_error (input_location,
    2069              :                          "invalid offload table in %s", file_data->file_name);
    2070              : 
    2071            0 :           tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    2072              :         }
    2073              : 
    2074            0 :       lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
    2075              :                                       ib, data, len);
    2076              :     }
    2077              : #ifdef ACCEL_COMPILER
    2078              :   char *omp_requires_file = getenv ("GCC_OFFLOAD_OMP_REQUIRES_FILE");
    2079              :   if (omp_requires_file == NULL || omp_requires_file[0] == '\0')
    2080              :     fatal_error (input_location, "GCC_OFFLOAD_OMP_REQUIRES_FILE unset");
    2081              :   FILE *f = fopen (omp_requires_file, "wb");
    2082              :   if (!f)
    2083              :     fatal_error (input_location, "Cannot open omp_requires file %qs",
    2084              :                  omp_requires_file);
    2085              :   uint32_t req_mask = omp_requires_mask;
    2086              :   fwrite (&req_mask, sizeof (req_mask), 1, f);
    2087              :   fclose (f);
    2088              : #endif
    2089        20654 : }
    2090              : 
    2091              : /* True when we need optimization summary for NODE.  */
    2092              : 
    2093              : static int
    2094       167090 : output_cgraph_opt_summary_p (struct cgraph_node *node)
    2095              : {
    2096       167090 :   if (node->clone_of || node->former_clone_of)
    2097              :     return true;
    2098       120616 :   clone_info *info = clone_info::get (node);
    2099       120616 :   return info && (info->tree_map || info->param_adjustments);
    2100              : }
    2101              : 
    2102              : /* Output optimization summary for EDGE to OB.  */
    2103              : static void
    2104            0 : output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
    2105              :                          struct cgraph_edge *edge ATTRIBUTE_UNUSED)
    2106              : {
    2107            0 : }
    2108              : 
    2109              : /* Output optimization summary for NODE to OB.  */
    2110              : 
    2111              : static void
    2112        23237 : output_node_opt_summary (struct output_block *ob,
    2113              :                          struct cgraph_node *node,
    2114              :                          lto_symtab_encoder_t encoder)
    2115              : {
    2116        23237 :   struct ipa_replace_map *map;
    2117        23237 :   int i;
    2118        23237 :   struct cgraph_edge *e;
    2119              : 
    2120              :   /* TODO: Should this code be moved to ipa-param-manipulation?  */
    2121        23237 :   struct bitpack_d bp;
    2122        23237 :   bp = bitpack_create (ob->main_stream);
    2123        23237 :   clone_info *info = clone_info::get (node);
    2124              : 
    2125        26803 :   bp_pack_value (&bp, (info && info->param_adjustments != NULL), 1);
    2126        23237 :   streamer_write_bitpack (&bp);
    2127        19865 :   if (ipa_param_adjustments *adjustments
    2128        23237 :                  = info ? info->param_adjustments : NULL)
    2129              :     {
    2130        19671 :       streamer_write_uhwi (ob, vec_safe_length (adjustments->m_adj_params));
    2131        19671 :       ipa_adjusted_param *adj;
    2132        76873 :       FOR_EACH_VEC_SAFE_ELT (adjustments->m_adj_params, i, adj)
    2133              :         {
    2134        37531 :           bp = bitpack_create (ob->main_stream);
    2135        37531 :           bp_pack_value (&bp, adj->base_index, IPA_PARAM_MAX_INDEX_BITS);
    2136        37531 :           bp_pack_value (&bp, adj->prev_clone_index, IPA_PARAM_MAX_INDEX_BITS);
    2137        37531 :           bp_pack_value (&bp, adj->op, 2);
    2138        37531 :           bp_pack_value (&bp, adj->param_prefix_index, 2);
    2139        37531 :           bp_pack_value (&bp, adj->prev_clone_adjustment, 1);
    2140        37531 :           bp_pack_value (&bp, adj->reverse, 1);
    2141        37531 :           bp_pack_value (&bp, adj->user_flag, 1);
    2142        37531 :           streamer_write_bitpack (&bp);
    2143        37531 :           if (adj->op == IPA_PARAM_OP_SPLIT
    2144        37531 :               || adj->op == IPA_PARAM_OP_NEW)
    2145              :             {
    2146          653 :               stream_write_tree (ob, adj->type, true);
    2147          653 :               if (adj->op == IPA_PARAM_OP_SPLIT)
    2148              :                 {
    2149          653 :                   stream_write_tree (ob, adj->alias_ptr_type, true);
    2150          653 :                   streamer_write_uhwi (ob, adj->unit_offset);
    2151              :                 }
    2152              :             }
    2153              :         }
    2154        19671 :       streamer_write_hwi (ob, adjustments->m_always_copy_start);
    2155        19671 :       bp = bitpack_create (ob->main_stream);
    2156        19671 :       bp_pack_value (&bp, info->param_adjustments->m_skip_return, 1);
    2157        19671 :       streamer_write_bitpack (&bp);
    2158              :     }
    2159              : 
    2160        26568 :   streamer_write_uhwi (ob, info ? vec_safe_length (info->tree_map) : 0);
    2161        23237 :   if (info)
    2162        25657 :     FOR_EACH_VEC_SAFE_ELT (info->tree_map, i, map)
    2163              :       {
    2164         5792 :         streamer_write_uhwi (ob, map->parm_num);
    2165         5792 :         gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
    2166         5792 :         stream_write_tree (ob, map->new_tree, true);
    2167              :       }
    2168              : 
    2169        23237 :   if (lto_symtab_encoder_in_partition_p (encoder, node))
    2170              :     {
    2171              :       for (e = node->callees; e; e = e->next_callee)
    2172              :         output_edge_opt_summary (ob, e);
    2173              :       for (e = node->indirect_calls; e; e = e->next_callee)
    2174              :         output_edge_opt_summary (ob, e);
    2175              :     }
    2176        23237 : }
    2177              : 
    2178              : /* Output optimization summaries stored in callgraph.
    2179              :    At the moment it is the clone info structure.  */
    2180              : 
    2181              : static void
    2182         8274 : output_cgraph_opt_summary (void)
    2183              : {
    2184         8274 :   int i, n_nodes;
    2185         8274 :   lto_symtab_encoder_t encoder;
    2186         8274 :   struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
    2187         8274 :   unsigned count = 0;
    2188              : 
    2189         8274 :   ob->symbol = NULL;
    2190         8274 :   encoder = ob->decl_state->symtab_node_encoder;
    2191         8274 :   n_nodes = lto_symtab_encoder_size (encoder);
    2192       116856 :   for (i = 0; i < n_nodes; i++)
    2193              :     {
    2194       108582 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
    2195       217164 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    2196        83545 :       if (cnode && output_cgraph_opt_summary_p (cnode))
    2197        23237 :         count++;
    2198              :     }
    2199         8274 :   streamer_write_uhwi (ob, count);
    2200       125130 :   for (i = 0; i < n_nodes; i++)
    2201              :     {
    2202       108582 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
    2203       217164 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    2204        83545 :       if (cnode && output_cgraph_opt_summary_p (cnode))
    2205              :         {
    2206        23237 :           streamer_write_uhwi (ob, i);
    2207        23237 :           output_node_opt_summary (ob, cnode, encoder);
    2208              :         }
    2209              :     }
    2210         8274 :   produce_asm (ob);
    2211         8274 :   destroy_output_block (ob);
    2212         8274 : }
    2213              : 
    2214              : /* Input optimisation summary of EDGE.  */
    2215              : 
    2216              : static void
    2217            0 : input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
    2218              :                         class lto_input_block *ib_main ATTRIBUTE_UNUSED)
    2219              : {
    2220            0 : }
    2221              : 
    2222              : /* Input optimisation summary of NODE.  */
    2223              : 
    2224              : static void
    2225        23237 : input_node_opt_summary (struct cgraph_node *node,
    2226              :                         class lto_input_block *ib_main,
    2227              :                         class data_in *data_in)
    2228              : {
    2229        23237 :   int i;
    2230        23237 :   int count;
    2231        23237 :   struct cgraph_edge *e;
    2232              : 
    2233              :   /* TODO: Should this code be moved to ipa-param-manipulation?  */
    2234        23237 :   struct bitpack_d bp;
    2235        23237 :   bp = streamer_read_bitpack (ib_main);
    2236        23237 :   bool have_adjustments = bp_unpack_value (&bp, 1);
    2237        23237 :   clone_info *info = clone_info::get_create (node);
    2238              : 
    2239        23237 :   if (have_adjustments)
    2240              :     {
    2241        19671 :       count = streamer_read_uhwi (ib_main);
    2242        19671 :       vec<ipa_adjusted_param, va_gc> *new_params = NULL;
    2243        57202 :       for (i = 0; i < count; i++)
    2244              :         {
    2245        37531 :           ipa_adjusted_param adj;
    2246        37531 :           memset (&adj, 0, sizeof (adj));
    2247        37531 :           bp = streamer_read_bitpack (ib_main);
    2248        37531 :           adj.base_index = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
    2249        37531 :           adj.prev_clone_index
    2250        37531 :             = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
    2251        37531 :           adj.op = (enum ipa_parm_op) bp_unpack_value (&bp, 2);
    2252        37531 :           adj.param_prefix_index = bp_unpack_value (&bp, 2);
    2253        37531 :           adj.prev_clone_adjustment = bp_unpack_value (&bp, 1);
    2254        37531 :           adj.reverse = bp_unpack_value (&bp, 1);
    2255        37531 :           adj.user_flag = bp_unpack_value (&bp, 1);
    2256        37531 :           if (adj.op == IPA_PARAM_OP_SPLIT
    2257        37531 :               || adj.op == IPA_PARAM_OP_NEW)
    2258              :             {
    2259          653 :               adj.type = stream_read_tree (ib_main, data_in);
    2260          653 :               if (adj.op == IPA_PARAM_OP_SPLIT)
    2261              :                 {
    2262          653 :                   adj.alias_ptr_type = stream_read_tree (ib_main, data_in);
    2263          653 :                   adj.unit_offset = streamer_read_uhwi (ib_main);
    2264              :                 }
    2265              :             }
    2266        37531 :           vec_safe_push (new_params, adj);
    2267              :         }
    2268        19671 :       int always_copy_start = streamer_read_hwi (ib_main);
    2269        19671 :       bp = streamer_read_bitpack (ib_main);
    2270        19671 :       bool skip_return = bp_unpack_value (&bp, 1);
    2271        19671 :       info->param_adjustments
    2272        19671 :         = (new (ggc_alloc <ipa_param_adjustments> ())
    2273        19671 :            ipa_param_adjustments (new_params, always_copy_start, skip_return));
    2274              :     }
    2275              : 
    2276        23237 :   count = streamer_read_uhwi (ib_main);
    2277        29029 :   for (i = 0; i < count; i++)
    2278              :     {
    2279         5792 :       struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
    2280              : 
    2281         5792 :       vec_safe_push (info->tree_map, map);
    2282         5792 :       map->parm_num = streamer_read_uhwi (ib_main);
    2283         5792 :       map->new_tree = stream_read_tree (ib_main, data_in);
    2284              :     }
    2285        23237 :   for (e = node->callees; e; e = e->next_callee)
    2286              :     input_edge_opt_summary (e, ib_main);
    2287        23237 :   for (e = node->indirect_calls; e; e = e->next_callee)
    2288              :     input_edge_opt_summary (e, ib_main);
    2289        23237 : }
    2290              : 
    2291              : /* Read section in file FILE_DATA of length LEN with data DATA.  */
    2292              : 
    2293              : static void
    2294         8274 : input_cgraph_opt_section (struct lto_file_decl_data *file_data,
    2295              :                           const char *data, size_t len,
    2296              :                           vec<symtab_node *> nodes)
    2297              : {
    2298         8274 :   const struct lto_function_header *header =
    2299              :     (const struct lto_function_header *) data;
    2300         8274 :   const int cfg_offset = sizeof (struct lto_function_header);
    2301         8274 :   const int main_offset = cfg_offset + header->cfg_size;
    2302         8274 :   const int string_offset = main_offset + header->main_size;
    2303         8274 :   class data_in *data_in;
    2304         8274 :   unsigned int i;
    2305         8274 :   unsigned int count;
    2306              : 
    2307         8274 :   lto_input_block ib_main ((const char *) data + main_offset,
    2308         8274 :                            header->main_size, file_data);
    2309              : 
    2310         8274 :   data_in =
    2311        16548 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    2312         8274 :                         header->string_size, vNULL);
    2313         8274 :   count = streamer_read_uhwi (&ib_main);
    2314              : 
    2315        31511 :   for (i = 0; i < count; i++)
    2316              :     {
    2317        23237 :       int ref = streamer_read_uhwi (&ib_main);
    2318        46474 :       input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
    2319              :                               &ib_main, data_in);
    2320              :     }
    2321         8274 :   lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
    2322              :                          len);
    2323         8274 :   lto_data_in_delete (data_in);
    2324         8274 : }
    2325              : 
    2326              : /* Input optimization summary of cgraph.  */
    2327              : 
    2328              : static void
    2329         8274 : input_cgraph_opt_summary (vec<symtab_node *> nodes)
    2330              : {
    2331         8274 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    2332         8274 :   struct lto_file_decl_data *file_data;
    2333         8274 :   unsigned int j = 0;
    2334              : 
    2335        24822 :   while ((file_data = file_data_vec[j++]))
    2336              :     {
    2337         8274 :       size_t len;
    2338         8274 :       const char *data
    2339         8274 :         = lto_get_summary_section_data (file_data, LTO_section_cgraph_opt_sum,
    2340              :                                         &len);
    2341         8274 :       if (data)
    2342         8274 :         input_cgraph_opt_section (file_data, data, len, nodes);
    2343              :     }
    2344         8274 : }
        

Generated by: LCOV version 2.4-beta

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