LCOV - code coverage report
Current view: top level - gcc - lto-cgraph.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 87.9 % 1230 1081
Test Date: 2026-11-14 16:39:50 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 "attribs.h"
      42              : #include "alloc-pool.h"
      43              : #include "symbol-summary.h"
      44              : #include "symtab-thunks.h"
      45              : #include "symtab-clones.h"
      46              : #include "callback-info.h"
      47              : 
      48              : static void output_cgraph_opt_summary (void);
      49              : static void input_cgraph_opt_summary (vec<symtab_node *>  nodes);
      50              : 
      51              : /* Number of LDPR values known to GCC.  */
      52              : #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
      53              : 
      54              : /* Cgraph streaming is organized as set of record whose type
      55              :    is indicated by a tag.  */
      56              : enum LTO_symtab_tags
      57              : {
      58              :   /* Must leave 0 for the stopper.  */
      59              : 
      60              :   /* Cgraph node without body available.  */
      61              :   LTO_symtab_unavail_node = 1,
      62              :   /* Cgraph node with function body.  */
      63              :   LTO_symtab_analyzed_node,
      64              :   /* Cgraph edges.  */
      65              :   LTO_symtab_edge,
      66              :   LTO_symtab_indirect_edge,
      67              :   LTO_symtab_variable,
      68              :   LTO_symtab_indirect_function,
      69              :   LTO_symtab_last_tag
      70              : };
      71              : 
      72              : /* Create a new symtab encoder.
      73              :    if FOR_INPUT, the encoder allocate only datastructures needed
      74              :    to read the symtab.  */
      75              : 
      76              : lto_symtab_encoder_t
      77        87397 : lto_symtab_encoder_new (bool for_input)
      78              : {
      79        87397 :   lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
      80              : 
      81        87397 :   if (!for_input)
      82        64963 :     encoder->map = new hash_map<toplevel_node *, size_t>;
      83        87397 :   encoder->nodes.create (0);
      84        87397 :   return encoder;
      85              : }
      86              : 
      87              : 
      88              : /* Delete ENCODER and its components.  */
      89              : 
      90              : void
      91        87397 : lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
      92              : {
      93        87397 :    encoder->nodes.release ();
      94        87397 :    if (encoder->map)
      95        64963 :      delete encoder->map;
      96        87397 :    if (encoder->order_remap)
      97        32481 :      delete encoder->order_remap;
      98        87397 :    free (encoder);
      99        87397 : }
     100              : 
     101              : 
     102              : /* Return the existing reference number of NODE in the symtab encoder in
     103              :    output block OB.  Assign a new reference if this is the first time
     104              :    NODE is encoded.  */
     105              : 
     106              : int
     107      3274333 : lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
     108              :                            toplevel_node *node)
     109              : {
     110      3274333 :   int ref;
     111              : 
     112      3274333 :   if (!encoder->map)
     113              :     {
     114       272429 :       lto_encoder_entry entry (node);
     115              : 
     116       272429 :       ref = encoder->nodes.length ();
     117       272429 :       encoder->nodes.safe_push (entry);
     118       272429 :       return ref;
     119              :     }
     120              : 
     121      3001904 :   size_t *slot = encoder->map->get (node);
     122      3001904 :   if (!slot || !*slot)
     123              :     {
     124      1170516 :       lto_encoder_entry entry (node);
     125      1170516 :       ref = encoder->nodes.length ();
     126      1170516 :       if (!slot)
     127      1170516 :         encoder->map->put (node, ref + 1);
     128      1170516 :       encoder->nodes.safe_push (entry);
     129      1170516 :     }
     130              :   else
     131      1831388 :     ref = *slot - 1;
     132              : 
     133              :   return ref;
     134              : }
     135              : 
     136              : /* Remove NODE from encoder.  */
     137              : 
     138              : bool
     139          224 : lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
     140              :                                 toplevel_node *node)
     141              : {
     142          224 :   int index;
     143              : 
     144          224 :   size_t *slot = encoder->map->get (node);
     145          224 :   if (slot == NULL || !*slot)
     146              :     return false;
     147              : 
     148          224 :   index = *slot - 1;
     149          224 :   gcc_checking_assert (encoder->nodes[index].node == node);
     150              : 
     151              :   /* Remove from vector. We do this by swapping node with the last element
     152              :      of the vector.  */
     153          224 :   lto_encoder_entry last_node = encoder->nodes.pop ();
     154          224 :   if (last_node.node != node)
     155              :     {
     156          223 :       bool existed = encoder->map->put (last_node.node, index + 1);
     157          223 :       gcc_assert (existed);
     158              : 
     159              :       /* Move the last element to the original spot of NODE.  */
     160          223 :       encoder->nodes[index] = last_node;
     161              :     }
     162              : 
     163              :   /* Remove element from hash table.  */
     164          224 :   encoder->map->remove (node);
     165          224 :   return true;
     166              : }
     167              : 
     168              : /* Return TRUE if the NODE and its clones are always inlined.  */
     169              : 
     170              : bool
     171        12098 : lto_symtab_encoder_only_for_inlining_p (lto_symtab_encoder_t encoder,
     172              :                                         struct cgraph_node *node)
     173              : {
     174        12098 :   int index = lto_symtab_encoder_lookup (encoder, node);
     175        12098 :   return encoder->nodes[index].only_for_inlining;
     176              : }
     177              : 
     178              : /* Return TRUE if we should encode the body of NODE (if any).  */
     179              : 
     180              : bool
     181       464492 : lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
     182              :                                   struct cgraph_node *node)
     183              : {
     184       464492 :   int index = lto_symtab_encoder_lookup (encoder, node);
     185       464492 :   return encoder->nodes[index].body;
     186              : }
     187              : 
     188              : /* Return TRUE if we should encode initializer of NODE (if any).  */
     189              : 
     190              : bool
     191       671581 : lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
     192              :                                          varpool_node *node)
     193              : {
     194       671581 :   int index = lto_symtab_encoder_lookup (encoder, node);
     195       671581 :   if (index == LCC_NOT_FOUND)
     196              :     return false;
     197       671559 :   return encoder->nodes[index].initializer;
     198              : }
     199              : 
     200              : /* Specify that we should encode initializer of NODE (if any).  */
     201              : 
     202              : static void
     203       283110 : lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
     204              :                                            varpool_node *node)
     205              : {
     206       283110 :   int index = lto_symtab_encoder_lookup (encoder, node);
     207       283110 :   encoder->nodes[index].initializer = true;
     208       283110 : }
     209              : 
     210              : /* Return TRUE if NODE is in this partition.  */
     211              : 
     212              : bool
     213      8742590 : lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
     214              :                                    toplevel_node *node)
     215              : {
     216      8742590 :   int index = lto_symtab_encoder_lookup (encoder, node);
     217      8742590 :   if (index == LCC_NOT_FOUND)
     218              :     return false;
     219      8598132 :   return encoder->nodes[index].in_partition;
     220              : }
     221              : 
     222              : /* Specify that NODE is in this partition.  */
     223              : 
     224              : void
     225       914996 : lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
     226              :                                      toplevel_node *node)
     227              : {
     228       914996 :   int index = lto_symtab_encoder_encode (encoder, node);
     229       914996 :   if (dump_file)
     230              :     {
     231            0 :       if (symtab_node* snode = dyn_cast<symtab_node*> (node))
     232            0 :         fprintf (dump_file, "Node %s, index %d\n", snode->asm_name (), index);
     233              :       else
     234            0 :         fprintf (dump_file, "Asm node, index %d\n", index);
     235              :     }
     236       914996 :   encoder->nodes[index].in_partition = true;
     237       914996 : }
     238              : 
     239              : /* Output the cgraph EDGE to OB using ENCODER.  */
     240              : 
     241              : static void
     242       637748 : lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
     243              :                  lto_symtab_encoder_t encoder)
     244              : {
     245       637748 :   unsigned int uid;
     246       637748 :   intptr_t ref;
     247       637748 :   struct bitpack_d bp;
     248              : 
     249       637748 :   if (edge->indirect_unknown_callee)
     250         3628 :     streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     251              :                          LTO_symtab_indirect_edge);
     252              :   else
     253       634120 :     streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     254              :                          LTO_symtab_edge);
     255              : 
     256       637748 :   ref = lto_symtab_encoder_lookup (encoder, edge->caller);
     257       637748 :   gcc_assert (ref != LCC_NOT_FOUND);
     258       637748 :   streamer_write_hwi_stream (ob->main_stream, ref);
     259              : 
     260       637748 :   if (!edge->indirect_unknown_callee)
     261              :     {
     262       634120 :       ref = lto_symtab_encoder_lookup (encoder, edge->callee);
     263       634120 :       gcc_assert (ref != LCC_NOT_FOUND);
     264       634120 :       streamer_write_hwi_stream (ob->main_stream, ref);
     265              :     }
     266              : 
     267       637748 :   edge->count.stream_out (ob->main_stream);
     268              : 
     269       637748 :   bp = bitpack_create (ob->main_stream);
     270       637748 :   uid = !edge->call_stmt ? edge->lto_stmt_uid
     271       388610 :                          : gimple_uid (edge->call_stmt) + 1;
     272       637748 :   bp_pack_enum (&bp, cgraph_inline_failed_t,
     273              :                 CIF_N_REASONS, edge->inline_failed);
     274       637748 :   gcc_checking_assert (uid || edge->caller->thunk);
     275       637748 :   bp_pack_var_len_unsigned (&bp, uid);
     276       637748 :   bp_pack_value (&bp, edge->speculative_id, 16);
     277       637748 :   bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
     278       637748 :   bp_pack_value (&bp, edge->speculative, 1);
     279       637748 :   bp_pack_value (&bp, edge->callback, 1);
     280       637748 :   bp_pack_value (&bp, edge->has_callback, 1);
     281       637748 :   bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
     282       637748 :   gcc_assert (!edge->call_stmt_cannot_inline_p
     283              :               || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
     284       637748 :   bp_pack_value (&bp, edge->can_throw_external, 1);
     285       637748 :   bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
     286       637748 :   if (edge->indirect_unknown_callee)
     287              :     {
     288         3628 :       bp_pack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS,
     289              :                     edge->indirect_info->kind);
     290         3628 :       int flags = edge->indirect_info->ecf_flags;
     291         3628 :       bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
     292         3628 :       bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
     293         3628 :       bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
     294         3628 :       bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
     295         3628 :       bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
     296         3628 :       bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
     297              :       /* Flags that should not appear on indirect calls.  */
     298         3628 :       gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
     299              :                              | ECF_MAY_BE_ALLOCA
     300              :                              | ECF_SIBCALL
     301              :                              | ECF_LEAF
     302              :                              | ECF_NOVOPS)));
     303              : 
     304         3628 :       bp_pack_value (&bp, edge->indirect_info->num_speculative_call_targets,
     305              :                      16);
     306              :     }
     307       637748 :   streamer_write_bitpack (&bp);
     308       637748 :   if (edge->callback)
     309              :     {
     310           36 :       callback_info *ci = callback_info_sum->get (edge);
     311           36 :       ci->stream_out (ob);
     312              :     }
     313       637748 : }
     314              : 
     315              : /* Return if NODE contain references from other partitions.  */
     316              : 
     317              : bool
     318       422696 : referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
     319              : {
     320       422696 :   int i;
     321       422696 :   struct ipa_ref *ref = NULL;
     322              : 
     323       902488 :   for (i = 0; node->iterate_referring (i, ref); i++)
     324              :     {
     325              :       /* Ignore references from non-offloadable nodes while streaming NODE into
     326              :          offload LTO section.  */
     327       480102 :       if (!ref->referring->need_lto_streaming)
     328            0 :         continue;
     329              : 
     330       480102 :       if (ref->referring->in_other_partition
     331       480102 :           || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
     332              :         return true;
     333              :     }
     334              :   return false;
     335              : }
     336              : 
     337              : /* Return true when node is reachable from other partition.  */
     338              : 
     339              : bool
     340       142470 : reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
     341              : {
     342       142470 :   struct cgraph_edge *e;
     343       142470 :   if (!node->definition)
     344              :     return false;
     345       142470 :   if (node->inlined_to)
     346              :     return false;
     347       409019 :   for (e = node->callers; e; e = e->next_caller)
     348              :     {
     349              :       /* Ignore references from non-offloadable nodes while streaming NODE into
     350              :          offload LTO section.  */
     351       266673 :       if (!e->caller->need_lto_streaming)
     352            0 :         continue;
     353              : 
     354       266673 :       if (e->caller->in_other_partition
     355       266673 :           || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
     356              :         return true;
     357              :     }
     358              :   return false;
     359              : }
     360              : 
     361              : /* Return if NODE contain references from other partitions.  */
     362              : 
     363              : bool
     364         6634 : referenced_from_this_partition_p (symtab_node *node,
     365              :                                   lto_symtab_encoder_t encoder)
     366              : {
     367         6634 :   int i;
     368         6634 :   struct ipa_ref *ref = NULL;
     369              : 
     370         6660 :   for (i = 0; node->iterate_referring (i, ref); i++)
     371         5140 :     if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
     372              :       return true;
     373              :   return false;
     374              : }
     375              : 
     376              : /* Return true when node is reachable from other partition.  */
     377              : 
     378              : bool
     379         9358 : reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
     380              : {
     381         9358 :   struct cgraph_edge *e;
     382         9360 :   for (e = node->callers; e; e = e->next_caller)
     383         6730 :     if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
     384              :       return true;
     385              :   return false;
     386              : }
     387              : 
     388              : /* Output the cgraph NODE to OB.  ENCODER is used to find the
     389              :    reference number of NODE->inlined_to.  SET is the set of nodes we
     390              :    are writing to the current file.  If NODE is not in SET, then NODE
     391              :    is a boundary of a cgraph_node_set and we pretend NODE just has a
     392              :    decl and no callees.  WRITTEN_DECLS is the set of FUNCTION_DECLs
     393              :    that have had their callgraph node written so far.  This is used to
     394              :    determine if NODE is a clone of a previously written node.  */
     395              : 
     396              : static void
     397       426379 : lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
     398              :                  lto_symtab_encoder_t encoder)
     399              : {
     400       426379 :   unsigned int tag;
     401       426379 :   struct bitpack_d bp;
     402       426379 :   bool boundary_p;
     403       426379 :   intptr_t ref;
     404       426379 :   bool in_other_partition = false;
     405       426379 :   struct cgraph_node *clone_of, *ultimate_clone_of;
     406       426379 :   ipa_opt_pass_d *pass;
     407       426379 :   int i;
     408       426379 :   const char *comdat;
     409       426379 :   const char *section;
     410       426379 :   tree group;
     411              : 
     412       426379 :   boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
     413              : 
     414       426379 :   if (node->analyzed && (!boundary_p || node->alias
     415          260 :                          || (node->thunk && !node->inlined_to)))
     416              :     tag = LTO_symtab_analyzed_node;
     417              :   else
     418       426379 :     tag = LTO_symtab_unavail_node;
     419              : 
     420       426379 :   streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     421              :                        tag);
     422       426379 :   int output_order = *encoder->order_remap->get (node->order);
     423       426379 :   streamer_write_hwi_stream (ob->main_stream, output_order);
     424              : 
     425              :   /* In WPA mode, we only output part of the call-graph.  Also, we
     426              :      fake cgraph node attributes.  There are two cases that we care.
     427              : 
     428              :      Boundary nodes: There are nodes that are not part of SET but are
     429              :      called from within SET.  We artificially make them look like
     430              :      externally visible nodes with no function body.
     431              : 
     432              :      Cherry-picked nodes:  These are nodes we pulled from other
     433              :      translation units into SET during IPA-inlining.  We make them as
     434              :      local static nodes to prevent clashes with other local statics.  */
     435       253357 :   if (boundary_p && node->analyzed
     436       426654 :       && node->get_partitioning_class () == SYMBOL_PARTITION)
     437              :     {
     438              :       /* Inline clones cannot be part of boundary.
     439              :          gcc_assert (!node->inlined_to);
     440              : 
     441              :          FIXME: At the moment they can be, when partition contains an inline
     442              :          clone that is clone of inline clone from outside partition.  We can
     443              :          reshape the clone tree and make other tree to be the root, but it
     444              :          needs a bit extra work and will be promplty done by cgraph_remove_node
     445              :          after reading back.  */
     446              :       in_other_partition = 1;
     447              :     }
     448       426118 :   else if (UNLIKELY (lto_stream_offload_p
     449              :                      && lookup_attribute ("omp target device_ancestor_host",
     450              :                                           DECL_ATTRIBUTES (node->decl))))
     451              :     /* This symbol is only used as argument to IFN_GOMP_TARGET_REV; this IFN
     452              :        is ignored on ACCEL_COMPILER.  Thus, mark it as in_other_partition to silence
     453              :        verify_node_partition diagnostic.  */
     454              :     in_other_partition = 1;
     455              : 
     456       426379 :   clone_of = node->clone_of;
     457       426379 :   while (clone_of
     458       426379 :          && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
     459            0 :     if (clone_of->prev_sibling_clone)
     460              :       clone_of = clone_of->prev_sibling_clone;
     461              :     else
     462            0 :       clone_of = clone_of->clone_of;
     463              : 
     464              :   /* See if body of the master function is output.  If not, we are seeing only
     465              :      an declaration and we do not need to pass down clone tree. */
     466       426379 :   ultimate_clone_of = clone_of;
     467       445797 :   while (ultimate_clone_of && ultimate_clone_of->clone_of)
     468              :     ultimate_clone_of = ultimate_clone_of->clone_of;
     469              : 
     470       426379 :   if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
     471              :     clone_of = NULL;
     472              : 
     473       426379 :   if (tag == LTO_symtab_analyzed_node)
     474       173041 :     gcc_assert (clone_of || !node->clone_of);
     475       403455 :   if (!clone_of)
     476       403003 :     streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
     477              :   else
     478        23376 :     streamer_write_hwi_stream (ob->main_stream, ref);
     479              : 
     480              : 
     481       426379 :   lto_output_fn_decl_ref (ob->decl_state, ob->main_stream, node->decl);
     482       426379 :   node->count.stream_out (ob->main_stream);
     483       426379 :   streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
     484              : 
     485       852758 :   streamer_write_hwi_stream (ob->main_stream,
     486       426379 :                              node->ipa_transforms_to_apply.length ());
     487       922360 :   FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
     488        69602 :     streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
     489              : 
     490       426379 :   if (tag == LTO_symtab_analyzed_node)
     491              :     {
     492       173041 :       if (node->inlined_to)
     493              :         {
     494        21587 :           ref = lto_symtab_encoder_lookup (encoder, node->inlined_to);
     495        21587 :           gcc_assert (ref != LCC_NOT_FOUND);
     496              :         }
     497              :       else
     498              :         ref = LCC_NOT_FOUND;
     499              : 
     500       173041 :       streamer_write_hwi_stream (ob->main_stream, ref);
     501              :     }
     502              : 
     503       426379 :   group = node->get_comdat_group ();
     504       426379 :   if (group)
     505         9061 :     comdat = IDENTIFIER_POINTER (group);
     506              :   else
     507              :     comdat = "";
     508       426379 :   streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
     509              : 
     510       426379 :   if (group)
     511              :     {
     512         9061 :       if (node->same_comdat_group)
     513              :         {
     514              :           ref = LCC_NOT_FOUND;
     515         4522 :           for (struct symtab_node *n = node->same_comdat_group;
     516         9043 :                ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
     517         4522 :             ref = lto_symtab_encoder_lookup (encoder, n);
     518              :         }
     519              :       else
     520              :         ref = LCC_NOT_FOUND;
     521         9061 :       streamer_write_hwi_stream (ob->main_stream, ref);
     522              :     }
     523              : 
     524       426379 :   section = node->get_section ();
     525          342 :   if (!section)
     526       426037 :     section = "";
     527              : 
     528       426379 :   streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
     529              : 
     530       426379 :   bp = bitpack_create (ob->main_stream);
     531       426379 :   bp_pack_value (&bp, node->local, 1);
     532       426379 :   bp_pack_value (&bp, node->externally_visible, 1);
     533       426379 :   bp_pack_value (&bp, node->no_reorder, 1);
     534       426379 :   bp_pack_value (&bp, node->definition, 1);
     535       426379 :   bp_pack_value (&bp, node->versionable, 1);
     536       426379 :   bp_pack_value (&bp, node->can_change_signature, 1);
     537       426379 :   bp_pack_value (&bp, node->redefined_extern_inline, 1);
     538       426379 :   bp_pack_value (&bp, node->force_output, 1);
     539       426379 :   bp_pack_value (&bp, node->forced_by_abi, 1);
     540       426379 :   bp_pack_value (&bp, node->ref_by_asm, 1);
     541       426379 :   bp_pack_value (&bp, node->must_remain_in_tu_name, 1);
     542       426379 :   bp_pack_value (&bp, node->must_remain_in_tu_body, 1);
     543       426379 :   bp_pack_value (&bp, node->unique_name, 1);
     544       426379 :   bp_pack_value (&bp, node->body_removed, 1);
     545       426379 :   bp_pack_value (&bp, node->semantic_interposition, 1);
     546       426379 :   bp_pack_value (&bp, node->implicit_section, 1);
     547       426379 :   bp_pack_value (&bp, node->address_taken, 1);
     548       426379 :   bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
     549       173041 :                  && node->get_partitioning_class () == SYMBOL_PARTITION
     550       568849 :                  && (reachable_from_other_partition_p (node, encoder)
     551       142346 :                      || referenced_from_other_partition_p (node, encoder)), 1);
     552       426379 :   bp_pack_value (&bp, node->lowered, 1);
     553       426379 :   bp_pack_value (&bp, in_other_partition, 1);
     554       426379 :   bp_pack_value (&bp, node->alias, 1);
     555       426379 :   bp_pack_value (&bp, node->transparent_alias, 1);
     556       426379 :   bp_pack_value (&bp, node->weakref, 1);
     557       426379 :   bp_pack_value (&bp, node->symver, 1);
     558       426379 :   bp_pack_value (&bp, node->frequency, 2);
     559       426379 :   bp_pack_value (&bp, node->only_called_at_startup, 1);
     560       426379 :   bp_pack_value (&bp, node->only_called_at_exit, 1);
     561       426379 :   bp_pack_value (&bp, node->tm_clone, 1);
     562       426379 :   bp_pack_value (&bp, node->calls_comdat_local, 1);
     563       426379 :   bp_pack_value (&bp, node->icf_merged, 1);
     564       426379 :   bp_pack_value (&bp, node->assume_function, 1);
     565       426379 :   bp_pack_value (&bp, node->nonfreeing_fn, 1);
     566       426379 :   bp_pack_value (&bp, node->merged_comdat, 1);
     567       426379 :   bp_pack_value (&bp, node->merged_extern_inline, 1);
     568       426379 :   bp_pack_value (&bp, node->thunk, 1);
     569       426379 :   bp_pack_value (&bp, node->parallelized_function, 1);
     570       426379 :   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       426379 :   struct thunk_info *thunk = node->definition ? thunk_info::get (node) : NULL;
     577              : 
     578       426379 :   bp_pack_value (&bp, thunk != NULL, 1);
     579              : 
     580       426379 :   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       426379 :   bp_pack_value (&bp, node->split_part, 1);
     587       426379 :   streamer_write_bitpack (&bp);
     588       426379 :   streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
     589              : 
     590       426379 :   streamer_write_hwi_stream (ob->main_stream, node->profile_id);
     591       426379 :   streamer_write_hwi_stream (ob->main_stream, node->unit_id);
     592       426379 :   if (DECL_STATIC_CONSTRUCTOR (node->decl))
     593          258 :     streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
     594       426379 :   if (DECL_STATIC_DESTRUCTOR (node->decl))
     595           71 :     streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
     596              : 
     597       426379 :   if (thunk)
     598          239 :     thunk_info::get (node)->stream_out (ob);
     599       426379 : }
     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       287609 : lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
     606              :                          lto_symtab_encoder_t encoder)
     607              : {
     608       287609 :   bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
     609       287609 :   bool encode_initializer_p
     610       287609 :          = (node->definition
     611       287609 :             && lto_symtab_encoder_encode_initializer_p (encoder, node));
     612       282983 :   struct bitpack_d bp;
     613       282983 :   int ref;
     614       282983 :   const char *comdat;
     615       282983 :   const char *section;
     616       282983 :   tree group;
     617              : 
     618       282983 :   gcc_assert (!encode_initializer_p || node->definition);
     619       287609 :   gcc_assert (boundary_p || encode_initializer_p);
     620              : 
     621       287609 :   streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
     622              :                        LTO_symtab_variable);
     623       287609 :   int output_order = *encoder->order_remap->get (node->order);
     624       287609 :   streamer_write_hwi_stream (ob->main_stream, output_order);
     625       287609 :   lto_output_var_decl_ref (ob->decl_state, ob->main_stream, node->decl);
     626       287609 :   bp = bitpack_create (ob->main_stream);
     627       287609 :   bp_pack_value (&bp, node->externally_visible, 1);
     628       287609 :   bp_pack_value (&bp, node->no_reorder, 1);
     629       287609 :   bp_pack_value (&bp, node->force_output, 1);
     630       287609 :   bp_pack_value (&bp, node->forced_by_abi, 1);
     631       287609 :   bp_pack_value (&bp, node->ref_by_asm, 1);
     632       287609 :   bp_pack_value (&bp, node->must_remain_in_tu_name, 1);
     633       287609 :   bp_pack_value (&bp, node->must_remain_in_tu_body, 1);
     634       287609 :   bp_pack_value (&bp, node->unique_name, 1);
     635       287609 :   bp_pack_value (&bp,
     636       287609 :                  node->body_removed
     637       287609 :                  || (!encode_initializer_p && !node->alias && node->definition),
     638              :                  1);
     639       287609 :   bp_pack_value (&bp, node->semantic_interposition, 1);
     640       287609 :   bp_pack_value (&bp, node->implicit_section, 1);
     641       287609 :   bp_pack_value (&bp, node->writeonly, 1);
     642       570593 :   bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias),
     643              :                  1);
     644       287609 :   bp_pack_value (&bp, node->alias, 1);
     645       287609 :   bp_pack_value (&bp, node->transparent_alias, 1);
     646       287609 :   bp_pack_value (&bp, node->weakref, 1);
     647       287609 :   bp_pack_value (&bp, node->symver, 1);
     648       570576 :   bp_pack_value (&bp, node->analyzed && (!boundary_p || node->alias), 1);
     649       287609 :   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       287609 :   if (node->get_partitioning_class () != SYMBOL_PARTITION)
     654              :     {
     655         7259 :       bp_pack_value (&bp, 0, 1);  /* used_from_other_parition.  */
     656         7259 :       bp_pack_value (&bp, 0, 1);  /* in_other_partition.  */
     657              :     }
     658              :   else
     659              :     {
     660       280350 :       bp_pack_value (&bp, node->definition
     661       280350 :                      && referenced_from_other_partition_p (node, encoder), 1);
     662       280350 :       bp_pack_value (&bp, node->analyzed
     663       280350 :                      && boundary_p && !DECL_EXTERNAL (node->decl), 1);
     664              :           /* in_other_partition.  */
     665              :     }
     666       287609 :   bp_pack_value (&bp, node->tls_model, 3);
     667       287609 :   bp_pack_value (&bp, node->used_by_single_function, 1);
     668       287609 :   bp_pack_value (&bp, node->dynamically_initialized, 1);
     669       287609 :   streamer_write_bitpack (&bp);
     670              : 
     671       287609 :   group = node->get_comdat_group ();
     672       287609 :   if (group)
     673         3462 :     comdat = IDENTIFIER_POINTER (group);
     674              :   else
     675              :     comdat = "";
     676       287609 :   streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
     677              : 
     678       287609 :   if (group)
     679              :     {
     680         3462 :       if (node->same_comdat_group)
     681              :         {
     682              :           ref = LCC_NOT_FOUND;
     683          380 :           for (struct symtab_node *n = node->same_comdat_group;
     684          760 :                ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
     685          380 :             ref = lto_symtab_encoder_lookup (encoder, n);
     686              :         }
     687              :       else
     688              :         ref = LCC_NOT_FOUND;
     689         3462 :       streamer_write_hwi_stream (ob->main_stream, ref);
     690              :     }
     691              : 
     692       287609 :   section = node->get_section ();
     693         2359 :   if (!section)
     694       285250 :     section = "";
     695       287609 :   streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
     696              : 
     697       287609 :   streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
     698              :                        LDPR_NUM_KNOWN, node->resolution);
     699       287609 : }
     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       705810 : lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
     706              :                 lto_symtab_encoder_t encoder)
     707              : {
     708       705810 :   struct bitpack_d bp;
     709       705810 :   int nref;
     710       705810 :   int uid = !ref->stmt ? ref->lto_stmt_uid : gimple_uid (ref->stmt) + 1;
     711       705810 :   struct cgraph_node *node;
     712              : 
     713       705810 :   bp = bitpack_create (ob->main_stream);
     714       705810 :   bp_pack_value (&bp, ref->use, 3);
     715       705810 :   bp_pack_value (&bp, ref->speculative, 1);
     716       705810 :   streamer_write_bitpack (&bp);
     717       705810 :   nref = lto_symtab_encoder_lookup (encoder, ref->referred);
     718       705810 :   gcc_assert (nref != LCC_NOT_FOUND);
     719       705810 :   streamer_write_hwi_stream (ob->main_stream, nref);
     720              : 
     721       705810 :   node = dyn_cast <cgraph_node *> (ref->referring);
     722       480027 :   if (node)
     723              :     {
     724       480027 :       if (ref->stmt)
     725       282873 :         uid = gimple_uid (ref->stmt) + 1;
     726       480027 :       streamer_write_hwi_stream (ob->main_stream, uid);
     727       480027 :       bp_pack_value (&bp, ref->speculative_id, 16);
     728       480027 :       streamer_write_bitpack (&bp);
     729              :     }
     730       705810 : }
     731              : 
     732              : /* Stream out profile_summary to OB.  */
     733              : 
     734              : static void
     735        32481 : output_profile_summary (struct lto_simple_output_block *ob)
     736              : {
     737        32481 :   if (profile_info)
     738              :     {
     739           13 :       unsigned runs = (profile_info->runs);
     740           13 :       streamer_write_uhwi_stream (ob->main_stream, runs);
     741           13 :       streamer_write_gcov_count_stream (ob->main_stream,
     742              :                                         profile_info->sum_max);
     743           13 :       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           13 :        if (flag_wpa)
     749            5 :          streamer_write_gcov_count_stream (ob->main_stream,
     750              :                                            get_hot_bb_threshold ());
     751              :     }
     752              :   else
     753        32468 :     streamer_write_uhwi_stream (ob->main_stream, 0);
     754        32481 : }
     755              : 
     756              : /* Output all callees or indirect outgoing edges.  EDGE must be the first such
     757              :    edge.  */
     758              : 
     759              : static void
     760       346052 : output_outgoing_cgraph_edges (struct cgraph_edge *edge,
     761              :                               struct lto_simple_output_block *ob,
     762              :                               lto_symtab_encoder_t encoder)
     763              : {
     764       346052 :   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       637748 :   while (edge->next_callee)
     770              :     edge = edge->next_callee;
     771       753421 :   for (; edge; edge = edge->prev_callee)
     772       637748 :     lto_output_edge (ob, edge, encoder);
     773              : }
     774              : 
     775              : /* Output the part of the cgraph in SET.  */
     776              : 
     777              : static void
     778        32481 : output_refs (lto_symtab_encoder_t encoder)
     779              : {
     780        32481 :   struct lto_simple_output_block *ob;
     781        32481 :   int count;
     782        32481 :   struct ipa_ref *ref;
     783              : 
     784        32481 :   ob = lto_create_simple_output_block (LTO_section_refs);
     785              : 
     786      1525490 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
     787              :     {
     788       714144 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
     789       714144 :       symtab_node *node = dyn_cast <symtab_node *> (tnode);
     790       714144 :       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       713988 :       if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node))
     797       257944 :         continue;
     798              : 
     799       787165 :       count = node->ref_list.nreferences ();
     800        73021 :       if (count)
     801              :         {
     802        73004 :           streamer_write_gcov_count_stream (ob->main_stream, count);
     803       146008 :           streamer_write_uhwi_stream (ob->main_stream,
     804        73004 :                                      lto_symtab_encoder_lookup (encoder, node));
     805      1565962 :           for (int i = 0; node->iterate_reference (i, ref); i++)
     806       705810 :             lto_output_ref (ob, ref, encoder);
     807              :         }
     808              :     }
     809              : 
     810        32481 :   streamer_write_uhwi_stream (ob->main_stream, 0);
     811              : 
     812        32481 :   lto_destroy_simple_output_block (ob);
     813        32481 : }
     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       790674 : add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
     820              :              bool include_body, bool not_inlined)
     821              : {
     822       790674 :   if (node->clone_of)
     823        42359 :     add_node_to (encoder, node->clone_of, include_body, not_inlined);
     824              : 
     825       790674 :   int index = lto_symtab_encoder_encode (encoder, node);
     826       790674 :   gcc_checking_assert (encoder->nodes[index].node == node);
     827              : 
     828       790674 :   if (include_body)
     829       215364 :     encoder->nodes[index].body = true;
     830       790674 :   if (not_inlined)
     831       154610 :     encoder->nodes[index].only_for_inlining = false;
     832       790674 : }
     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       748315 : add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
     839              :              bool include_body)
     840              : {
     841       434255 :   add_node_to (encoder, node, include_body, include_body && !node->inlined_to);
     842       173022 : }
     843              : 
     844              : /* Add all references in NODE to encoders.  */
     845              : 
     846              : static void
     847       468917 : create_references (lto_symtab_encoder_t encoder, symtab_node *node)
     848              : {
     849       468917 :   int i;
     850       468917 :   struct ipa_ref *ref = NULL;
     851      1187513 :   for (i = 0; node->iterate_reference (i, ref); i++)
     852       718596 :     if (is_a <cgraph_node *> (ref->referred))
     853       239639 :       add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
     854              :     else
     855       478957 :       lto_symtab_encoder_encode (encoder, ref->referred);
     856       468917 : }
     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        32090 : select_what_to_stream (void)
     862              : {
     863        32090 :   struct symtab_node *snode;
     864       745523 :   FOR_EACH_SYMBOL (snode)
     865      1426866 :     snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable;
     866        32090 : }
     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        32481 : compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
     878              : {
     879        32481 :   struct cgraph_edge *edge;
     880        32481 :   int i;
     881        32481 :   lto_symtab_encoder_t encoder;
     882        32481 :   lto_symtab_encoder_iterator lsei;
     883        32481 :   hash_set<void *> reachable_call_targets;
     884              : 
     885        32481 :   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        32481 :   for (lsei = lsei_start_function_in_partition (in_encoder);
     891       205503 :        !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
     892              :     {
     893       173022 :       struct cgraph_node *node = lsei_cgraph_node (lsei);
     894       173022 :       if (!node->need_lto_streaming)
     895            0 :         continue;
     896       173022 :       add_node_to (encoder, node, true);
     897       173022 :       lto_set_symtab_encoder_in_partition (encoder, node);
     898       173022 :       create_references (encoder, node);
     899              :     }
     900        32481 :   for (lsei = lsei_start_variable_in_partition (in_encoder);
     901       315447 :        !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
     902              :     {
     903       282966 :       varpool_node *vnode = lsei_varpool_node (lsei);
     904              : 
     905       282966 :       if (!vnode->need_lto_streaming)
     906            0 :         continue;
     907       282966 :       lto_set_symtab_encoder_in_partition (encoder, vnode);
     908       282966 :       lto_set_symtab_encoder_encode_initializer (encoder, vnode);
     909       282966 :       create_references (encoder, vnode);
     910              :     }
     911       977009 :   for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next (&lsei))
     912              :     {
     913       456144 :       toplevel_node *tnode = lsei_node (lsei);
     914       912288 :       if (asm_node* node = dyn_cast <asm_node*> (tnode))
     915              :         {
     916              :           symtab_node* ref;
     917       456224 :           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      1396789 :   for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
     933              :     {
     934       666035 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
     935      1332070 :       if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
     936              :         {
     937       287608 :           if (!lto_symtab_encoder_encode_initializer_p (encoder,
     938              :                                                         vnode)
     939       287608 :               && (((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        32481 :   for (lsei = lsei_start_function_in_partition (encoder);
     953       410763 :        !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
     954              :     {
     955       173022 :       struct cgraph_node *node = lsei_cgraph_node (lsei);
     956       807138 :       for (edge = node->callees; edge; edge = edge->next_callee)
     957              :         {
     958       634116 :           struct cgraph_node *callee = edge->callee;
     959       634116 :           if (!lto_symtab_encoder_in_partition_p (encoder, callee))
     960              :             {
     961              :               /* We should have moved all the inlines.  */
     962       335462 :               gcc_assert (!callee->inlined_to);
     963       335462 :               add_node_to (encoder, callee, false);
     964              :             }
     965              :         }
     966              :       /* Add all possible targets for late devirtualization.  */
     967       173022 :       if (flag_ltrans_devirtualize || !flag_wpa)
     968       110214 :         for (edge = node->indirect_calls; edge; edge = edge->next_callee)
     969         5422 :           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      1492695 :   for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
    1000              :     {
    1001       713988 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    1002       713988 :       symtab_node *node = dyn_cast <symtab_node *> (tnode);
    1003       713988 :       if (!node)
    1004            0 :         continue;
    1005              : 
    1006       713988 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    1007              : 
    1008       713988 :       if (node->alias && node->analyzed)
    1009        12785 :         create_references (encoder, node);
    1010       713988 :       if (cnode
    1011       426379 :           && cnode->thunk && !cnode->inlined_to)
    1012          173 :         add_node_to (encoder, cnode->callees->callee, false);
    1013       713995 :       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       488625 :   for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next (&lsei))
    1025              :     {
    1026       456144 :       toplevel_node *tnode = lsei_node (lsei);
    1027       912288 :       if (asm_node* node = dyn_cast <asm_node*> (tnode))
    1028          156 :         lto_set_symtab_encoder_in_partition (encoder, node);
    1029              :     }
    1030        32481 :   lto_symtab_encoder_delete (in_encoder);
    1031        32481 :   return encoder;
    1032        32481 : }
    1033              : 
    1034              : /* Output the part of the symtab in SET and VSET.  */
    1035              : 
    1036              : void
    1037        32481 : output_symtab (void)
    1038              : {
    1039        32481 :   struct cgraph_node *node;
    1040        32481 :   struct lto_simple_output_block *ob;
    1041        32481 :   int i, n_nodes;
    1042        32481 :   lto_symtab_encoder_t encoder;
    1043              : 
    1044        32481 :   if (flag_wpa)
    1045         8538 :     output_cgraph_opt_summary ();
    1046              : 
    1047        32481 :   ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
    1048              : 
    1049        32481 :   output_profile_summary (ob);
    1050              : 
    1051              :   /* An encoder for cgraph nodes should have been created by
    1052              :      ipa_write_summaries_1.  */
    1053        32481 :   gcc_assert (ob->decl_state->symtab_node_encoder);
    1054        32481 :   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        32481 :   n_nodes = lto_symtab_encoder_size (encoder);
    1060       746625 :   for (i = 0; i < n_nodes; i++)
    1061              :     {
    1062       714144 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
    1063       714144 :       if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
    1064       426379 :         lto_output_node (ob, cnode, encoder);
    1065      1001909 :       else if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
    1066       287609 :         lto_output_varpool_node (ob, vnode, encoder);
    1067              :     }
    1068              : 
    1069        32481 :   callback_info_sum_t::check_create_info_sum ();
    1070              :   /* Go over the nodes in SET again to write edges.  */
    1071      1525490 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    1072              :     {
    1073      1428288 :       node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
    1074       426379 :       if (node
    1075       426379 :           && ((node->thunk && !node->inlined_to)
    1076       426206 :               || lto_symtab_encoder_in_partition_p (encoder, node)))
    1077              :         {
    1078       173026 :           output_outgoing_cgraph_edges (node->callees, ob, encoder);
    1079       173026 :           output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
    1080              :         }
    1081              :     }
    1082              : 
    1083        32481 :   streamer_write_uhwi_stream (ob->main_stream, 0);
    1084              : 
    1085        32481 :   lto_destroy_simple_output_block (ob);
    1086              : 
    1087              :   /* Emit toplevel asms.  */
    1088        32481 :   if (!lto_stream_offload_p)
    1089        32481 :     lto_output_toplevel_asms (encoder);
    1090              : 
    1091        32481 :   output_refs (encoder);
    1092        32481 : }
    1093              : 
    1094              : /* Return identifier encoded in IB as a plain string.  */
    1095              : 
    1096              : static tree
    1097       272429 : read_identifier (class lto_input_block *ib)
    1098              : {
    1099       272429 :   unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
    1100       272429 :   tree id;
    1101              : 
    1102       272429 :   if (ib->data[ib->p + len])
    1103            0 :     lto_section_overrun (ib);
    1104       272429 :   if (!len)
    1105              :     {
    1106       262309 :       ib->p++;
    1107       262309 :       return NULL;
    1108              :     }
    1109        10120 :   id = get_identifier (ib->data + ib->p);
    1110        10120 :   ib->p += len + 1;
    1111        10120 :   return id;
    1112              : }
    1113              : 
    1114              : /* Return string encoded in IB, NULL if string is empty.  */
    1115              : 
    1116              : static const char *
    1117       272429 : read_string (class lto_input_block *ib)
    1118              : {
    1119       272429 :   unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
    1120       272429 :   const char *str;
    1121              : 
    1122       272429 :   if (ib->data[ib->p + len])
    1123            0 :     lto_section_overrun (ib);
    1124       272429 :   if (!len)
    1125              :     {
    1126       269888 :       ib->p++;
    1127       269888 :       return NULL;
    1128              :     }
    1129         2541 :   str = ib->data + ib->p;
    1130         2541 :   ib->p += len + 1;
    1131         2541 :   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         8147 : output_offload_tables (void)
    1142              : {
    1143        16294 :   bool output_requires = (flag_openmp
    1144         8147 :                           && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0);
    1145         8147 :   if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars)
    1146         8147 :       && !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       272429 : verify_node_partition (symtab_node *node)
    1210              : {
    1211       272429 :   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       162083 :   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       200414 : 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       200414 :   node->aux = (void *) tag;
    1256       200414 :   node->lto_file_data = file_data;
    1257              : 
    1258       200414 :   node->local = bp_unpack_value (bp, 1);
    1259       200414 :   node->externally_visible = bp_unpack_value (bp, 1);
    1260       200414 :   node->no_reorder = bp_unpack_value (bp, 1);
    1261       200414 :   node->definition = bp_unpack_value (bp, 1);
    1262       200414 :   node->versionable = bp_unpack_value (bp, 1);
    1263       200414 :   node->can_change_signature = bp_unpack_value (bp, 1);
    1264       200414 :   node->redefined_extern_inline = bp_unpack_value (bp, 1);
    1265       200414 :   node->force_output = bp_unpack_value (bp, 1);
    1266       200414 :   node->forced_by_abi = bp_unpack_value (bp, 1);
    1267       200414 :   node->ref_by_asm = bp_unpack_value (bp, 1);
    1268       200414 :   node->must_remain_in_tu_name = bp_unpack_value (bp, 1);
    1269       200414 :   node->must_remain_in_tu_body = bp_unpack_value (bp, 1);
    1270       200414 :   node->unique_name = bp_unpack_value (bp, 1);
    1271       200414 :   node->body_removed = bp_unpack_value (bp, 1);
    1272       200414 :   node->semantic_interposition = bp_unpack_value (bp, 1);
    1273       200414 :   node->implicit_section = bp_unpack_value (bp, 1);
    1274       200414 :   node->address_taken = bp_unpack_value (bp, 1);
    1275       200414 :   node->used_from_other_partition = bp_unpack_value (bp, 1);
    1276       200414 :   node->lowered = bp_unpack_value (bp, 1);
    1277       200414 :   node->analyzed = tag == LTO_symtab_analyzed_node;
    1278       200414 :   node->in_other_partition = bp_unpack_value (bp, 1);
    1279       200414 :   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          261 :       && (!node->clone_of
    1288            0 :           || node->clone_of->decl != node->decl))
    1289              :     {
    1290          261 :       DECL_EXTERNAL (node->decl) = 1;
    1291          261 :       TREE_STATIC (node->decl) = 0;
    1292              :     }
    1293       200414 :   node->alias = bp_unpack_value (bp, 1);
    1294       200414 :   node->transparent_alias = bp_unpack_value (bp, 1);
    1295       200414 :   node->weakref = bp_unpack_value (bp, 1);
    1296       200414 :   node->symver = bp_unpack_value (bp, 1);
    1297       200414 :   node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
    1298       200414 :   node->only_called_at_startup = bp_unpack_value (bp, 1);
    1299       200414 :   node->only_called_at_exit = bp_unpack_value (bp, 1);
    1300       200414 :   node->tm_clone = bp_unpack_value (bp, 1);
    1301       200414 :   node->calls_comdat_local = bp_unpack_value (bp, 1);
    1302       200414 :   node->icf_merged = bp_unpack_value (bp, 1);
    1303       200414 :   node->assume_function = bp_unpack_value (bp, 1);
    1304       200414 :   node->nonfreeing_fn = bp_unpack_value (bp, 1);
    1305       200414 :   node->merged_comdat = bp_unpack_value (bp, 1);
    1306       200414 :   node->merged_extern_inline = bp_unpack_value (bp, 1);
    1307       200414 :   node->thunk = bp_unpack_value (bp, 1);
    1308       200414 :   node->parallelized_function = bp_unpack_value (bp, 1);
    1309       200414 :   node->has_omp_variant_constructs = bp_unpack_value (bp, 1);
    1310       200414 :   *has_thunk_info = bp_unpack_value (bp, 1);
    1311       200414 :   node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
    1312              :                                      LDPR_NUM_KNOWN);
    1313       200414 :   node->split_part = bp_unpack_value (bp, 1);
    1314       200414 :   verify_node_partition (node);
    1315       200414 : }
    1316              : 
    1317              : /* Return string alias is alias of.  */
    1318              : 
    1319              : static tree
    1320           24 : get_alias_symbol (tree decl)
    1321              : {
    1322           24 :   tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
    1323           24 :   return get_identifier (TREE_STRING_POINTER
    1324              :                           (TREE_VALUE (TREE_VALUE (alias))));
    1325              : }
    1326              : 
    1327              : /* Read a node from input_block IB.  TAG is the node's tag just read.
    1328              :    Return the node read or overwritten.  */
    1329              : 
    1330              : static struct cgraph_node *
    1331       200414 : input_node (struct lto_file_decl_data *file_data,
    1332              :             class lto_input_block *ib,
    1333              :             enum LTO_symtab_tags tag,
    1334              :             vec<symtab_node *> nodes)
    1335              : {
    1336       200414 :   gcc::pass_manager *passes = g->get_passes ();
    1337       200414 :   tree fn_decl;
    1338       200414 :   struct cgraph_node *node;
    1339       200414 :   struct bitpack_d bp;
    1340       200414 :   int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
    1341       200414 :   int clone_ref;
    1342       200414 :   int order;
    1343       200414 :   int i, count;
    1344       200414 :   tree group;
    1345       200414 :   const char *section;
    1346       200414 :   order = streamer_read_hwi (ib) + file_data->order_base;
    1347       200414 :   clone_ref = streamer_read_hwi (ib);
    1348       200414 :   bool has_thunk_info;
    1349              : 
    1350       200414 :   fn_decl = lto_input_fn_decl_ref (ib, file_data);
    1351              : 
    1352       200414 :   if (clone_ref != LCC_NOT_FOUND)
    1353              :     {
    1354        46752 :       node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
    1355              :         profile_count::uninitialized (), false,
    1356        23376 :         vNULL, false, NULL, NULL, NULL);
    1357              :     }
    1358              :   else
    1359              :     {
    1360              :       /* Declaration of functions can be already merged with a declaration
    1361              :          from other input file.  We keep cgraph unmerged until after streaming
    1362              :          of ipa passes is done.  Alays forcingly create a fresh node.  */
    1363       177038 :       node = symtab->create_empty ();
    1364       177038 :       node->decl = fn_decl;
    1365       177038 :       if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl)))
    1366           19 :         node->ifunc_resolver = 1;
    1367       177038 :       node->register_symbol ();
    1368              :     }
    1369              : 
    1370       200414 :   node->order = order;
    1371       200414 :   if (order >= symtab->order)
    1372        15094 :     symtab->order = order + 1;
    1373              : 
    1374       200414 :   node->count = profile_count::stream_in (ib);
    1375       200414 :   node->count_materialization_scale = streamer_read_hwi (ib);
    1376              : 
    1377       200414 :   count = streamer_read_hwi (ib);
    1378       200414 :   node->ipa_transforms_to_apply = vNULL;
    1379       270016 :   for (i = 0; i < count; i++)
    1380              :     {
    1381        69602 :       opt_pass *pass;
    1382        69602 :       int pid = streamer_read_hwi (ib);
    1383              : 
    1384        69602 :       gcc_assert (pid < passes->passes_by_id_size);
    1385        69602 :       pass = passes->passes_by_id[pid];
    1386        69602 :       node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
    1387              :     }
    1388              : 
    1389       200414 :   if (tag == LTO_symtab_analyzed_node)
    1390       155806 :     ref = streamer_read_hwi (ib);
    1391              : 
    1392       200414 :   group = read_identifier (ib);
    1393       200414 :   if (group)
    1394         7640 :     ref2 = streamer_read_hwi (ib);
    1395              : 
    1396              :   /* Make sure that we have not read this node before.  Nodes that
    1397              :      have already been read will have their tag stored in the 'aux'
    1398              :      field.  Since built-in functions can be referenced in multiple
    1399              :      functions, they are expected to be read more than once.  */
    1400       200414 :   if (node->aux && !fndecl_built_in_p (node->decl))
    1401            0 :     internal_error ("bytecode stream: found multiple instances of cgraph "
    1402              :                     "node with uid %d", node->get_uid ());
    1403              : 
    1404       200414 :   node->tp_first_run = streamer_read_uhwi (ib);
    1405              : 
    1406       200414 :   bp = streamer_read_bitpack (ib);
    1407              : 
    1408       200414 :   input_overwrite_node (file_data, node, tag, &bp, &has_thunk_info);
    1409              : 
    1410              :   /* Store a reference for now, and fix up later to be a pointer.  */
    1411       200414 :   node->inlined_to = (cgraph_node *) (intptr_t) ref;
    1412              : 
    1413       200414 :   if (group)
    1414              :     {
    1415         7640 :       node->set_comdat_group (group);
    1416              :       /* Store a reference for now, and fix up later to be a pointer.  */
    1417         7640 :       node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
    1418              :     }
    1419              :   else
    1420              :     node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
    1421       200414 :   section = read_string (ib);
    1422       200414 :   if (section)
    1423          206 :     node->set_section_for_node (section);
    1424              : 
    1425       200414 :   if (node->alias && !node->analyzed && node->weakref)
    1426           24 :     node->alias_target = get_alias_symbol (node->decl);
    1427       200414 :   node->profile_id = streamer_read_hwi (ib);
    1428       200414 :   node->unit_id = streamer_read_hwi (ib) + file_data->unit_base;
    1429       200414 :   if (symtab->max_unit < node->unit_id)
    1430        22572 :     symtab->max_unit = node->unit_id;
    1431       200414 :   if (DECL_STATIC_CONSTRUCTOR (node->decl))
    1432          152 :     node->set_init_priority (streamer_read_hwi (ib));
    1433       200414 :   if (DECL_STATIC_DESTRUCTOR (node->decl))
    1434           56 :     node->set_fini_priority (streamer_read_hwi (ib));
    1435              : 
    1436       200414 :   if (has_thunk_info)
    1437          171 :     thunk_info::get_create (node)->stream_in (ib);
    1438              : 
    1439       200414 :   return node;
    1440              : }
    1441              : 
    1442              : /* Read a node from input_block IB.  TAG is the node's tag just read.
    1443              :    Return the node read or overwritten.  */
    1444              : 
    1445              : static varpool_node *
    1446        72015 : input_varpool_node (struct lto_file_decl_data *file_data,
    1447              :                     class lto_input_block *ib)
    1448              : {
    1449        72015 :   tree var_decl;
    1450        72015 :   varpool_node *node;
    1451        72015 :   struct bitpack_d bp;
    1452        72015 :   int ref = LCC_NOT_FOUND;
    1453        72015 :   int order;
    1454        72015 :   tree group;
    1455        72015 :   const char *section;
    1456              : 
    1457        72015 :   order = streamer_read_hwi (ib) + file_data->order_base;
    1458        72015 :   var_decl = lto_input_var_decl_ref (ib, file_data);
    1459              : 
    1460              :   /* Declaration of functions can be already merged with a declaration
    1461              :      from other input file.  We keep cgraph unmerged until after streaming
    1462              :      of ipa passes is done.  Alays forcingly create a fresh node.  */
    1463        72015 :   node = varpool_node::create_empty ();
    1464        72015 :   node->decl = var_decl;
    1465        72015 :   node->register_symbol ();
    1466              : 
    1467        72015 :   node->order = order;
    1468        72015 :   if (order >= symtab->order)
    1469         1710 :     symtab->order = order + 1;
    1470        72015 :   node->lto_file_data = file_data;
    1471              : 
    1472        72015 :   bp = streamer_read_bitpack (ib);
    1473        72015 :   node->externally_visible = bp_unpack_value (&bp, 1);
    1474        72015 :   node->no_reorder = bp_unpack_value (&bp, 1);
    1475        72015 :   node->force_output = bp_unpack_value (&bp, 1);
    1476        72015 :   node->forced_by_abi = bp_unpack_value (&bp, 1);
    1477        72015 :   node->ref_by_asm = bp_unpack_value (&bp, 1);
    1478        72015 :   node->must_remain_in_tu_name = bp_unpack_value (&bp, 1);
    1479        72015 :   node->must_remain_in_tu_body = bp_unpack_value (&bp, 1);
    1480        72015 :   node->unique_name = bp_unpack_value (&bp, 1);
    1481        72015 :   node->body_removed = bp_unpack_value (&bp, 1);
    1482        72015 :   node->semantic_interposition = bp_unpack_value (&bp, 1);
    1483        72015 :   node->implicit_section = bp_unpack_value (&bp, 1);
    1484        72015 :   node->writeonly = bp_unpack_value (&bp, 1);
    1485        72015 :   node->definition = bp_unpack_value (&bp, 1);
    1486        72015 :   node->alias = bp_unpack_value (&bp, 1);
    1487        72015 :   node->transparent_alias = bp_unpack_value (&bp, 1);
    1488        72015 :   node->weakref = bp_unpack_value (&bp, 1);
    1489        72015 :   node->symver = bp_unpack_value (&bp, 1);
    1490        72015 :   node->analyzed = bp_unpack_value (&bp, 1);
    1491        72015 :   node->used_from_other_partition = bp_unpack_value (&bp, 1);
    1492        72015 :   node->in_other_partition = bp_unpack_value (&bp, 1);
    1493        72015 :   if (node->in_other_partition)
    1494              :     {
    1495          209 :       DECL_EXTERNAL (node->decl) = 1;
    1496          209 :       TREE_STATIC (node->decl) = 0;
    1497              :     }
    1498        72015 :   if (node->alias && !node->analyzed && node->weakref)
    1499            0 :     node->alias_target = get_alias_symbol (node->decl);
    1500        72015 :   node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
    1501        72015 :   node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
    1502        72015 :   node->dynamically_initialized = bp_unpack_value (&bp, 1);
    1503        72015 :   group = read_identifier (ib);
    1504        72015 :   if (group)
    1505              :     {
    1506         2480 :       node->set_comdat_group (group);
    1507         2480 :       ref = streamer_read_hwi (ib);
    1508              :       /* Store a reference for now, and fix up later to be a pointer.  */
    1509         2480 :       node->same_comdat_group = (symtab_node *) (intptr_t) ref;
    1510              :     }
    1511              :   else
    1512              :     node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
    1513        72015 :   section = read_string (ib);
    1514        72015 :   if (section)
    1515         2335 :     node->set_section_for_node (section);
    1516        72015 :   node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
    1517              :                                                 LDPR_NUM_KNOWN);
    1518        72015 :   verify_node_partition (node);
    1519        72015 :   return node;
    1520              : }
    1521              : 
    1522              : /* Read a node from input_block IB.  TAG is the node's tag just read.
    1523              :    Return the node read or overwritten.  */
    1524              : 
    1525              : static void
    1526       476300 : input_ref (class lto_input_block *ib,
    1527              :            symtab_node *referring_node,
    1528              :            vec<symtab_node *> nodes)
    1529              : {
    1530       476300 :   symtab_node *node = NULL;
    1531       476300 :   struct bitpack_d bp;
    1532       476300 :   enum ipa_ref_use use;
    1533       476300 :   bool speculative;
    1534       476300 :   struct ipa_ref *ref;
    1535              : 
    1536       476300 :   bp = streamer_read_bitpack (ib);
    1537       476300 :   use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
    1538       476300 :   speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
    1539       476300 :   node = nodes[streamer_read_hwi (ib)];
    1540       476300 :   ref = referring_node->create_reference (node, use);
    1541       476300 :   ref->speculative = speculative;
    1542       476300 :   if (is_a <cgraph_node *> (referring_node))
    1543              :     {
    1544       455416 :       ref->lto_stmt_uid = streamer_read_hwi (ib);
    1545       455416 :       bp = streamer_read_bitpack (ib);
    1546       455416 :       ref->speculative_id = bp_unpack_value (&bp, 16);
    1547              :     }
    1548       476300 : }
    1549              : 
    1550              : /* Read an edge from IB.  NODES points to a vector of previously read nodes for
    1551              :    decoding caller and callee of the edge to be read.  If INDIRECT is true, the
    1552              :    edge being read is indirect (in the sense that it has
    1553              :    indirect_unknown_callee set).  */
    1554              : 
    1555              : static void
    1556       605919 : input_edge (class lto_input_block *ib, vec<symtab_node *> nodes,
    1557              :             bool indirect)
    1558              : {
    1559       605919 :   struct cgraph_node *caller, *callee;
    1560       605919 :   struct cgraph_edge *edge;
    1561       605919 :   unsigned int stmt_id, speculative_id;
    1562       605919 :   profile_count count;
    1563       605919 :   cgraph_inline_failed_t inline_failed;
    1564       605919 :   struct bitpack_d bp;
    1565              : 
    1566       605919 :   caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
    1567       605919 :   if (caller == NULL || caller->decl == NULL_TREE)
    1568            0 :     internal_error ("bytecode stream: no caller found while reading edge");
    1569              : 
    1570       605919 :   if (!indirect)
    1571              :     {
    1572       603499 :       callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
    1573       603499 :       if (callee == NULL || callee->decl == NULL_TREE)
    1574            0 :         internal_error ("bytecode stream: no callee found while reading edge");
    1575              :     }
    1576              :   else
    1577              :     callee = NULL;
    1578              : 
    1579       605919 :   count = profile_count::stream_in (ib);
    1580              : 
    1581       605919 :   bp = streamer_read_bitpack (ib);
    1582       605919 :   inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
    1583       605919 :   stmt_id = bp_unpack_var_len_unsigned (&bp);
    1584       605919 :   speculative_id = bp_unpack_value (&bp, 16);
    1585              : 
    1586       605919 :   if (indirect)
    1587         2420 :     edge = caller->create_indirect_edge (NULL, 0, count, true);
    1588              :   else
    1589       603499 :     edge = caller->create_edge (callee, NULL, count);
    1590              : 
    1591       605919 :   edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
    1592       605919 :   edge->speculative = bp_unpack_value (&bp, 1);
    1593       605919 :   edge->callback = bp_unpack_value(&bp, 1);
    1594       605919 :   edge->has_callback = bp_unpack_value(&bp, 1);
    1595              : 
    1596       605919 :   if (edge->callback)
    1597              :     {
    1598           21 :       callback_info *ci = callback_info_sum->get_create (edge);
    1599           21 :       ci->stream_in (ib);
    1600              :     }
    1601              : 
    1602       605919 :   edge->lto_stmt_uid = stmt_id;
    1603       605919 :   edge->speculative_id = speculative_id;
    1604       605919 :   edge->inline_failed = inline_failed;
    1605       605919 :   edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
    1606       605919 :   edge->can_throw_external = bp_unpack_value (&bp, 1);
    1607       605919 :   edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
    1608       605919 :   if (indirect)
    1609              :     {
    1610         2420 :       enum cgraph_indirect_info_kind ii_kind
    1611         2420 :         = bp_unpack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS);
    1612         2420 :       int ecf_flags = 0;
    1613         2420 :       if (bp_unpack_value (&bp, 1))
    1614            0 :         ecf_flags |= ECF_CONST;
    1615         2420 :       if (bp_unpack_value (&bp, 1))
    1616            0 :         ecf_flags |= ECF_PURE;
    1617         2420 :       if (bp_unpack_value (&bp, 1))
    1618            0 :         ecf_flags |= ECF_NORETURN;
    1619         2420 :       if (bp_unpack_value (&bp, 1))
    1620            0 :         ecf_flags |= ECF_MALLOC;
    1621         2420 :       if (bp_unpack_value (&bp, 1))
    1622          288 :         ecf_flags |= ECF_NOTHROW;
    1623         2420 :       if (bp_unpack_value (&bp, 1))
    1624            0 :         ecf_flags |= ECF_RETURNS_TWICE;
    1625              : 
    1626         2420 :       if (ii_kind == CIIK_POLYMORPHIC)
    1627          426 :         edge->indirect_info
    1628          426 :           = (new (ggc_alloc<cgraph_polymorphic_indirect_info> ())
    1629          426 :              cgraph_polymorphic_indirect_info (ecf_flags));
    1630         1994 :       else if (ii_kind == CIIK_SIMPLE)
    1631         1980 :         edge->indirect_info
    1632         1980 :           = (new (ggc_alloc<cgraph_simple_indirect_info> ())
    1633         1980 :              cgraph_simple_indirect_info (ecf_flags));
    1634              :       else
    1635           14 :         edge->indirect_info
    1636           14 :           = (new (ggc_alloc<cgraph_indirect_call_info> ())
    1637           14 :              cgraph_indirect_call_info(CIIK_UNSPECIFIED, ecf_flags));
    1638              : 
    1639         4840 :       edge->indirect_info->num_speculative_call_targets
    1640         2420 :         = bp_unpack_value (&bp, 16);
    1641              :     }
    1642       605919 : }
    1643              : 
    1644              : 
    1645              : /* Read a cgraph from IB using the info in FILE_DATA.  */
    1646              : 
    1647              : static vec<symtab_node *>
    1648        22434 : input_cgraph_1 (struct lto_file_decl_data *file_data,
    1649              :                 class lto_input_block *ib)
    1650              : {
    1651        22434 :   enum LTO_symtab_tags tag;
    1652        22434 :   vec<symtab_node *> nodes = vNULL;
    1653        22434 :   symtab_node *node;
    1654        22434 :   unsigned i;
    1655              : 
    1656        22434 :   tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    1657        22434 :   file_data->order_base = symtab->order;
    1658        22434 :   file_data->unit_base = symtab->max_unit + 1;
    1659        22434 :   callback_info_sum_t::check_create_info_sum ();
    1660       923216 :   while (tag)
    1661              :     {
    1662       878348 :       if (tag == LTO_symtab_edge)
    1663       603499 :         input_edge (ib, nodes, false);
    1664       274849 :       else if (tag == LTO_symtab_indirect_edge)
    1665         2420 :         input_edge (ib, nodes, true);
    1666       272429 :       else if (tag == LTO_symtab_variable)
    1667              :         {
    1668        72015 :           node = input_varpool_node (file_data, ib);
    1669        72015 :           nodes.safe_push (node);
    1670        72015 :           lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
    1671              :         }
    1672              :       else
    1673              :         {
    1674       200414 :           node = input_node (file_data, ib, tag, nodes);
    1675       200414 :           if (node == NULL || node->decl == NULL_TREE)
    1676            0 :             internal_error ("bytecode stream: found empty cgraph node");
    1677       200414 :           nodes.safe_push (node);
    1678       200414 :           lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
    1679              :         }
    1680              : 
    1681       878348 :       tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    1682              :     }
    1683              : 
    1684              :   /* AUX pointers should be all non-zero for function nodes read from the stream.  */
    1685        22434 :   if (flag_checking)
    1686              :     {
    1687       317236 :       FOR_EACH_VEC_ELT (nodes, i, node)
    1688       272429 :         gcc_assert (node->aux || !is_a <cgraph_node *> (node));
    1689              :     }
    1690       317236 :   FOR_EACH_VEC_ELT (nodes, i, node)
    1691              :     {
    1692       272429 :       int ref;
    1693       272429 :       if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
    1694              :         {
    1695       200414 :           ref = (int) (intptr_t) cnode->inlined_to;
    1696              : 
    1697              :           /* We share declaration of builtins, so we may read same node twice.  */
    1698       200414 :           if (!node->aux)
    1699            0 :             continue;
    1700       200414 :           node->aux = NULL;
    1701              : 
    1702              :           /* Fixup inlined_to from reference to pointer.  */
    1703       200414 :           if (ref != LCC_NOT_FOUND)
    1704        43174 :             dyn_cast<cgraph_node *> (node)->inlined_to
    1705        43174 :               = dyn_cast<cgraph_node *> (nodes[ref]);
    1706              :           else
    1707       178827 :             cnode->inlined_to = NULL;
    1708              :         }
    1709              : 
    1710       272429 :       ref = (int) (intptr_t) node->same_comdat_group;
    1711              : 
    1712              :       /* Fixup same_comdat_group from reference to pointer.  */
    1713       272429 :       if (ref != LCC_NOT_FOUND)
    1714         3979 :         node->same_comdat_group = nodes[ref];
    1715              :       else
    1716       268450 :         node->same_comdat_group = NULL;
    1717              :     }
    1718       294863 :   FOR_EACH_VEC_ELT (nodes, i, node)
    1719       544858 :     node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
    1720        22434 :   return nodes;
    1721              : }
    1722              : 
    1723              : /* Input ipa_refs.  */
    1724              : 
    1725              : static void
    1726        22434 : input_refs (class lto_input_block *ib,
    1727              :             vec<symtab_node *> nodes)
    1728              : {
    1729        88413 :   int count;
    1730        88413 :   int idx;
    1731        88413 :   while (true)
    1732              :     {
    1733        88413 :       symtab_node *node;
    1734        88413 :       count = streamer_read_uhwi (ib);
    1735        88413 :       if (!count)
    1736              :         break;
    1737        65979 :       idx = streamer_read_uhwi (ib);
    1738        65979 :       node = nodes[idx];
    1739       542279 :       while (count)
    1740              :         {
    1741       476300 :           input_ref (ib, node, nodes);
    1742       476300 :           count--;
    1743              :         }
    1744              :     }
    1745        22434 : }
    1746              : 
    1747              : /* Input profile_info from IB.  */
    1748              : static void
    1749        22434 : input_profile_summary (class lto_input_block *ib,
    1750              :                        struct lto_file_decl_data *file_data)
    1751              : {
    1752        22434 :   unsigned int runs = streamer_read_uhwi (ib);
    1753        22434 :   if (runs)
    1754              :     {
    1755           13 :       file_data->profile_info.runs = runs;
    1756           13 :       file_data->profile_info.sum_max = streamer_read_gcov_count (ib);
    1757           13 :       file_data->profile_info.cutoff = streamer_read_gcov_count (ib);
    1758              : 
    1759              :       /* IPA-profile computes hot bb threshold based on cumulated
    1760              :          whole program profile.  We need to stream it down to ltrans.  */
    1761           13 :       if (flag_ltrans)
    1762            5 :         set_hot_bb_threshold (streamer_read_gcov_count (ib));
    1763              :     }
    1764              : 
    1765        22434 : }
    1766              : 
    1767              : /* Rescale profile summaries to the same number of runs in the whole unit.  */
    1768              : 
    1769              : static void
    1770        21320 : merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
    1771              : {
    1772        21320 :   struct lto_file_decl_data *file_data;
    1773        21320 :   unsigned int j;
    1774        21320 :   gcov_unsigned_t max_runs = 0;
    1775        21320 :   struct cgraph_node *node;
    1776        21320 :   struct cgraph_edge *edge;
    1777              : 
    1778              :   /* Find unit with maximal number of runs.  If we ever get serious about
    1779              :      roundoff errors, we might also consider computing smallest common
    1780              :      multiply.  */
    1781        43754 :   for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
    1782        22434 :     if (max_runs < file_data->profile_info.runs)
    1783              :       max_runs = file_data->profile_info.runs;
    1784              : 
    1785        21320 :   if (!max_runs)
    1786              :     return;
    1787              : 
    1788              :   /* Simple overflow check.  We probably don't need to support that many train
    1789              :      runs. Such a large value probably imply data corruption anyway.  */
    1790           10 :   if (max_runs > INT_MAX / REG_BR_PROB_BASE)
    1791              :     {
    1792            0 :       sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
    1793              :              INT_MAX / REG_BR_PROB_BASE);
    1794            0 :       return;
    1795              :     }
    1796              : 
    1797           10 :   profile_info = XCNEW (gcov_summary);
    1798           10 :   profile_info->runs = max_runs;
    1799           10 :   profile_info->sum_max = 0;
    1800           10 :   profile_info->cutoff = 0;
    1801              : 
    1802              :   /* If merging already happent at WPA time, we are done.  */
    1803           10 :   if (flag_ltrans)
    1804              :     return;
    1805              : 
    1806              :   /* Now compute count_materialization_scale of each node.
    1807              :      During LTRANS we already have values of count_materialization_scale
    1808              :      computed, so just update them.  */
    1809           32 :   FOR_EACH_FUNCTION (node)
    1810           27 :     if (node->lto_file_data
    1811           27 :         && node->lto_file_data->profile_info.runs)
    1812              :       {
    1813           27 :         int scale;
    1814              : 
    1815           27 :         scale = RDIV (node->count_materialization_scale * max_runs,
    1816              :                       node->lto_file_data->profile_info.runs);
    1817           27 :         gcov_type sum_max = RDIV (node->lto_file_data->profile_info.sum_max * max_runs,
    1818              :                                   node->lto_file_data->profile_info.runs);
    1819           27 :         gcov_type cutoff = RDIV (node->lto_file_data->profile_info.cutoff * max_runs,
    1820              :                                  node->lto_file_data->profile_info.runs);
    1821           27 :         if (sum_max > profile_info->sum_max)
    1822            5 :           profile_info->sum_max = sum_max;
    1823           27 :         if (cutoff > profile_info->cutoff)
    1824            5 :           profile_info->cutoff = cutoff;
    1825           27 :         node->count_materialization_scale = scale;
    1826           27 :         if (scale < 0)
    1827            0 :           fatal_error (input_location, "Profile information in %s corrupted",
    1828              :                        file_data->file_name);
    1829              : 
    1830           27 :         if (scale == REG_BR_PROB_BASE)
    1831           27 :           continue;
    1832            0 :         for (edge = node->callees; edge; edge = edge->next_callee)
    1833            0 :           if (edge->count.ipa ().nonzero_p ())
    1834            0 :             edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
    1835            0 :         for (edge = node->indirect_calls; edge; edge = edge->next_callee)
    1836            0 :           if (edge->count.ipa ().nonzero_p ())
    1837            0 :             edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
    1838            0 :         if (node->count.ipa ().nonzero_p ())
    1839            0 :           node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE);
    1840              :       }
    1841              : }
    1842              : 
    1843              : /* Input and merge the symtab from each of the .o files passed to
    1844              :    lto1.  */
    1845              : 
    1846              : void
    1847        21320 : input_symtab (void)
    1848              : {
    1849        21320 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    1850        21320 :   struct lto_file_decl_data *file_data;
    1851        21320 :   unsigned int j = 0;
    1852        21320 :   struct cgraph_node *node;
    1853              : 
    1854        65074 :   while ((file_data = file_data_vec[j++]))
    1855              :     {
    1856        22434 :       const char *data;
    1857        22434 :       size_t len;
    1858        22434 :       class lto_input_block *ib;
    1859        22434 :       vec<symtab_node *> nodes;
    1860              : 
    1861        22434 :       ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
    1862              :                                           &data, &len);
    1863        22434 :       if (!ib)
    1864            0 :         fatal_error (input_location,
    1865              :                      "cannot find LTO cgraph in %s", file_data->file_name);
    1866        22434 :       input_profile_summary (ib, file_data);
    1867        22434 :       file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
    1868        22434 :       nodes = input_cgraph_1 (file_data, ib);
    1869        22434 :       lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
    1870              :                                       ib, data, len);
    1871              : 
    1872        22434 :       ib = lto_create_simple_input_block (file_data, LTO_section_refs,
    1873              :                                           &data, &len);
    1874        22434 :       if (!ib)
    1875            0 :         fatal_error (input_location, "cannot find LTO section refs in %s",
    1876              :                      file_data->file_name);
    1877        22434 :       input_refs (ib, nodes);
    1878        22434 :       lto_destroy_simple_input_block (file_data, LTO_section_refs,
    1879              :                                       ib, data, len);
    1880        22434 :       if (flag_ltrans)
    1881         8538 :         input_cgraph_opt_summary (nodes);
    1882        22434 :       nodes.release ();
    1883              :     }
    1884              : 
    1885        21320 :   merge_profile_summaries (file_data_vec);
    1886              : 
    1887              :   /* Clear out the aux field that was used to store enough state to
    1888              :      tell which nodes should be overwritten.  */
    1889       221734 :   FOR_EACH_FUNCTION (node)
    1890              :     {
    1891              :       /* Some nodes may have been created by cgraph_node.  This
    1892              :          happens when the callgraph contains nested functions.  If the
    1893              :          node for the parent function was never emitted to the gimple
    1894              :          file, cgraph_node will create a node for it when setting the
    1895              :          context of the nested function.  */
    1896       200414 :       if (node->lto_file_data)
    1897       200414 :         node->aux = NULL;
    1898              :     }
    1899        21320 : }
    1900              : 
    1901              : /* Input toplevel asms from each of the .o files passed to lto1.
    1902              :    Must be called after merging of decls.  */
    1903              : void
    1904        21320 : input_toplevel_asms (void)
    1905              : {
    1906        21320 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    1907        21320 :   struct lto_file_decl_data *file_data;
    1908        21320 :   unsigned int j = 0;
    1909              : 
    1910        65074 :   while ((file_data = file_data_vec[j++]))
    1911        22434 :     lto_input_toplevel_asms (file_data, file_data->order_base);
    1912        21320 : }
    1913              : 
    1914              : static void
    1915            0 : omp_requires_to_name (char *buf, size_t size, HOST_WIDE_INT requires_mask)
    1916              : {
    1917            0 :   char *end = buf + size, *p = buf;
    1918            0 :   if (requires_mask & GOMP_REQUIRES_UNIFIED_ADDRESS)
    1919            0 :     p += snprintf (p, end - p, "unified_address");
    1920            0 :   if (requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY)
    1921            0 :     p += snprintf (p, end - p, "%sunified_shared_memory",
    1922              :                    (p == buf ? "" : ", "));
    1923            0 :   if (requires_mask & GOMP_REQUIRES_SELF_MAPS)
    1924            0 :     p += snprintf (p, end - p, "%sself_maps",
    1925              :                    (p == buf ? "" : ", "));
    1926            0 :   if (requires_mask & GOMP_REQUIRES_REVERSE_OFFLOAD)
    1927            0 :     p += snprintf (p, end - p, "%sreverse_offload",
    1928              :                    (p == buf ? "" : ", "));
    1929            0 : }
    1930              : 
    1931              : /* Input function/variable tables that will allow libgomp to look up offload
    1932              :    target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS.  */
    1933              : 
    1934              : void
    1935        21320 : input_offload_tables (bool do_force_output)
    1936              : {
    1937        21320 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    1938        21320 :   struct lto_file_decl_data *file_data;
    1939        21320 :   unsigned int j = 0;
    1940        21320 :   const char *requires_fn = NULL;
    1941        21320 :   tree requires_decl = NULL_TREE;
    1942              : 
    1943        21320 :   omp_requires_mask = (omp_requires) 0;
    1944              : 
    1945        43754 :   while ((file_data = file_data_vec[j++]))
    1946              :     {
    1947        22434 :       const char *data;
    1948        22434 :       size_t len;
    1949        22434 :       class lto_input_block *ib
    1950        22434 :         = lto_create_simple_input_block (file_data, LTO_section_offload_table,
    1951              :                                          &data, &len);
    1952        22434 :       if (!ib)
    1953        22434 :         continue;
    1954              : 
    1955            0 :       tree tmp_decl = NULL_TREE;
    1956            0 :       enum LTO_symtab_tags tag
    1957            0 :         = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    1958            0 :       while (tag)
    1959              :         {
    1960              :           if (tag == LTO_symtab_unavail_node)
    1961              :             {
    1962            0 :               tree fn_decl
    1963            0 :                 = lto_input_fn_decl_ref (ib, file_data);
    1964            0 :               vec_safe_push (offload_funcs, fn_decl);
    1965              : 
    1966              :               /* Prevent IPA from removing fn_decl as unreachable, since there
    1967              :                  may be no refs from the parent function to child_fn in offload
    1968              :                  LTO mode.  */
    1969            0 :               if (do_force_output)
    1970            0 :                 cgraph_node::get (fn_decl)->mark_force_output ();
    1971            0 :               tmp_decl = fn_decl;
    1972              :             }
    1973              :           else if (tag == LTO_symtab_variable)
    1974              :             {
    1975            0 :               tree var_decl
    1976            0 :                 = lto_input_var_decl_ref (ib, file_data);
    1977            0 :               vec_safe_push (offload_vars, var_decl);
    1978              : 
    1979              :               /* Prevent IPA from removing var_decl as unused, since there
    1980              :                  may be no refs to var_decl in offload LTO mode.  */
    1981            0 :               if (do_force_output)
    1982            0 :                 varpool_node::get (var_decl)->force_output = 1;
    1983            0 :               tmp_decl = var_decl;
    1984              :             }
    1985              :           else if (tag == LTO_symtab_indirect_function)
    1986              :             {
    1987            0 :               tree fn_decl
    1988            0 :                 = lto_input_fn_decl_ref (ib, file_data);
    1989            0 :               vec_safe_push (offload_ind_funcs, fn_decl);
    1990              : 
    1991              :               /* Prevent IPA from removing fn_decl as unreachable, since there
    1992              :                  may be no refs from the parent function to child_fn in offload
    1993              :                  LTO mode.  */
    1994            0 :               if (do_force_output)
    1995            0 :                 cgraph_node::get (fn_decl)->mark_force_output ();
    1996            0 :               tmp_decl = fn_decl;
    1997              :             }
    1998              :           else if (tag == LTO_symtab_edge)
    1999              :             {
    2000            0 :               static bool error_emitted = false;
    2001            0 :               HOST_WIDE_INT val = streamer_read_hwi (ib);
    2002              : 
    2003            0 :               if (omp_requires_mask == 0)
    2004              :                 {
    2005            0 :                   omp_requires_mask = (omp_requires) val;
    2006            0 :                   requires_decl = tmp_decl;
    2007            0 :                   requires_fn = file_data->file_name;
    2008              :                 }
    2009            0 :               else if (omp_requires_mask != val && !error_emitted)
    2010              :                 {
    2011            0 :                   const char *fn1 = requires_fn;
    2012            0 :                   if (requires_decl != NULL_TREE)
    2013              :                     {
    2014            0 :                       while (DECL_CONTEXT (requires_decl) != NULL_TREE
    2015            0 :                              && TREE_CODE (requires_decl) != TRANSLATION_UNIT_DECL)
    2016            0 :                         requires_decl = DECL_CONTEXT (requires_decl);
    2017            0 :                       if (requires_decl != NULL_TREE)
    2018            0 :                         fn1 = IDENTIFIER_POINTER (DECL_NAME (requires_decl));
    2019              :                     }
    2020              : 
    2021            0 :                   const char *fn2 = file_data->file_name;
    2022            0 :                   if (tmp_decl != NULL_TREE)
    2023              :                     {
    2024            0 :                       while (DECL_CONTEXT (tmp_decl) != NULL_TREE
    2025            0 :                              && TREE_CODE (tmp_decl) != TRANSLATION_UNIT_DECL)
    2026            0 :                         tmp_decl = DECL_CONTEXT (tmp_decl);
    2027            0 :                       if (tmp_decl != NULL_TREE)
    2028            0 :                         fn2 = IDENTIFIER_POINTER (DECL_NAME (tmp_decl));
    2029              :                     }
    2030            0 :                   if (fn1 == fn2)
    2031              :                     {
    2032            0 :                       fn1 = requires_fn;
    2033            0 :                       fn2 = file_data->file_name;
    2034              :                     }
    2035              : 
    2036            0 :                   char buf1[sizeof ("unified_address, unified_shared_memory, "
    2037              :                                     "reverse_offload")];
    2038            0 :                   char buf2[sizeof ("unified_address, unified_shared_memory, "
    2039              :                                     "reverse_offload")];
    2040            0 :                   omp_requires_to_name (buf2, sizeof (buf2),
    2041              :                                         val != OMP_REQUIRES_TARGET_USED
    2042              :                                         ? val
    2043              :                                         : (HOST_WIDE_INT) omp_requires_mask);
    2044            0 :                   if (val != OMP_REQUIRES_TARGET_USED
    2045            0 :                       && omp_requires_mask != OMP_REQUIRES_TARGET_USED)
    2046              :                     {
    2047            0 :                       omp_requires_to_name (buf1, sizeof (buf1),
    2048              :                                             omp_requires_mask);
    2049            0 :                       error ("OpenMP %<requires%> directive with non-identical "
    2050              :                              "clauses in multiple compilation units: %qs vs. "
    2051              :                              "%qs", buf1, buf2);
    2052            0 :                       inform (UNKNOWN_LOCATION, "%qs has %qs", fn1, buf1);
    2053            0 :                       inform (UNKNOWN_LOCATION, "%qs has %qs", fn2, buf2);
    2054              :                     }
    2055              :                   else
    2056              :                     {
    2057            0 :                       error ("OpenMP %<requires%> directive with %qs specified "
    2058              :                              "only in some compilation units", buf2);
    2059            0 :                       inform (UNKNOWN_LOCATION, "%qs has %qs",
    2060              :                               val != OMP_REQUIRES_TARGET_USED ? fn2 : fn1,
    2061              :                               buf2);
    2062            0 :                       inform (UNKNOWN_LOCATION, "but %qs has not",
    2063              :                               val != OMP_REQUIRES_TARGET_USED ? fn1 : fn2);
    2064              :                     }
    2065            0 :                   error_emitted = true;
    2066              :                 }
    2067              :             }
    2068              :           else
    2069            0 :             fatal_error (input_location,
    2070              :                          "invalid offload table in %s", file_data->file_name);
    2071              : 
    2072            0 :           tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
    2073              :         }
    2074              : 
    2075            0 :       lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
    2076              :                                       ib, data, len);
    2077              :     }
    2078              : #ifdef ACCEL_COMPILER
    2079              :   char *omp_requires_file = getenv ("GCC_OFFLOAD_OMP_REQUIRES_FILE");
    2080              :   if (omp_requires_file == NULL || omp_requires_file[0] == '\0')
    2081              :     fatal_error (input_location, "GCC_OFFLOAD_OMP_REQUIRES_FILE unset");
    2082              :   FILE *f = fopen (omp_requires_file, "wb");
    2083              :   if (!f)
    2084              :     fatal_error (input_location, "Cannot open omp_requires file %qs",
    2085              :                  omp_requires_file);
    2086              :   uint32_t req_mask = omp_requires_mask;
    2087              :   fwrite (&req_mask, sizeof (req_mask), 1, f);
    2088              :   fclose (f);
    2089              : #endif
    2090        21320 : }
    2091              : 
    2092              : /* True when we need optimization summary for NODE.  */
    2093              : 
    2094              : static int
    2095       169976 : output_cgraph_opt_summary_p (struct cgraph_node *node)
    2096              : {
    2097       169976 :   if (node->clone_of || node->former_clone_of)
    2098              :     return true;
    2099       123208 :   clone_info *info = clone_info::get (node);
    2100       123208 :   return info && (info->tree_map || info->param_adjustments);
    2101              : }
    2102              : 
    2103              : /* Output optimization summary for EDGE to OB.  */
    2104              : static void
    2105            0 : output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
    2106              :                          struct cgraph_edge *edge ATTRIBUTE_UNUSED)
    2107              : {
    2108            0 : }
    2109              : 
    2110              : /* Output optimization summary for NODE to OB.  */
    2111              : 
    2112              : static void
    2113        23384 : output_node_opt_summary (struct output_block *ob,
    2114              :                          struct cgraph_node *node,
    2115              :                          lto_symtab_encoder_t encoder)
    2116              : {
    2117        23384 :   struct ipa_replace_map *map;
    2118        23384 :   int i;
    2119        23384 :   struct cgraph_edge *e;
    2120              : 
    2121              :   /* TODO: Should this code be moved to ipa-param-manipulation?  */
    2122        23384 :   struct bitpack_d bp;
    2123        23384 :   bp = bitpack_create (ob->main_stream);
    2124        23384 :   clone_info *info = clone_info::get (node);
    2125              : 
    2126        26998 :   bp_pack_value (&bp, (info && info->param_adjustments != NULL), 1);
    2127        23384 :   streamer_write_bitpack (&bp);
    2128        19965 :   if (ipa_param_adjustments *adjustments
    2129        23384 :                  = info ? info->param_adjustments : NULL)
    2130              :     {
    2131        19770 :       streamer_write_uhwi (ob, vec_safe_length (adjustments->m_adj_params));
    2132        19770 :       ipa_adjusted_param *adj;
    2133        77201 :       FOR_EACH_VEC_SAFE_ELT (adjustments->m_adj_params, i, adj)
    2134              :         {
    2135        37661 :           bp = bitpack_create (ob->main_stream);
    2136        37661 :           bp_pack_value (&bp, adj->base_index, IPA_PARAM_MAX_INDEX_BITS);
    2137        37661 :           bp_pack_value (&bp, adj->prev_clone_index, IPA_PARAM_MAX_INDEX_BITS);
    2138        37661 :           bp_pack_value (&bp, adj->op, 2);
    2139        37661 :           bp_pack_value (&bp, adj->param_prefix_index, 2);
    2140        37661 :           bp_pack_value (&bp, adj->prev_clone_adjustment, 1);
    2141        37661 :           bp_pack_value (&bp, adj->reverse, 1);
    2142        37661 :           bp_pack_value (&bp, adj->user_flag, 1);
    2143        37661 :           streamer_write_bitpack (&bp);
    2144        37661 :           if (adj->op == IPA_PARAM_OP_SPLIT
    2145        37661 :               || adj->op == IPA_PARAM_OP_NEW)
    2146              :             {
    2147          676 :               stream_write_tree (ob, adj->type, true);
    2148          676 :               if (adj->op == IPA_PARAM_OP_SPLIT)
    2149              :                 {
    2150          676 :                   stream_write_tree (ob, adj->alias_ptr_type, true);
    2151          676 :                   streamer_write_uhwi (ob, adj->unit_offset);
    2152              :                 }
    2153              :             }
    2154              :         }
    2155        19770 :       streamer_write_hwi (ob, adjustments->m_always_copy_start);
    2156        19770 :       bp = bitpack_create (ob->main_stream);
    2157        19770 :       bp_pack_value (&bp, info->param_adjustments->m_skip_return, 1);
    2158        19770 :       streamer_write_bitpack (&bp);
    2159              :     }
    2160              : 
    2161        26762 :   streamer_write_uhwi (ob, info ? vec_safe_length (info->tree_map) : 0);
    2162        23384 :   if (info)
    2163        25812 :     FOR_EACH_VEC_SAFE_ELT (info->tree_map, i, map)
    2164              :       {
    2165         5847 :         streamer_write_uhwi (ob, map->parm_num);
    2166         5847 :         gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
    2167         5847 :         stream_write_tree (ob, map->new_tree, true);
    2168              :       }
    2169              : 
    2170        23384 :   if (lto_symtab_encoder_in_partition_p (encoder, node))
    2171              :     {
    2172              :       for (e = node->callees; e; e = e->next_callee)
    2173              :         output_edge_opt_summary (ob, e);
    2174              :       for (e = node->indirect_calls; e; e = e->next_callee)
    2175              :         output_edge_opt_summary (ob, e);
    2176              :     }
    2177        23384 : }
    2178              : 
    2179              : /* Output optimization summaries stored in callgraph.
    2180              :    At the moment it is the clone info structure.  */
    2181              : 
    2182              : static void
    2183         8538 : output_cgraph_opt_summary (void)
    2184              : {
    2185         8538 :   int i, n_nodes;
    2186         8538 :   lto_symtab_encoder_t encoder;
    2187         8538 :   struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
    2188         8538 :   unsigned count = 0;
    2189              : 
    2190         8538 :   ob->symbol = NULL;
    2191         8538 :   encoder = ob->decl_state->symtab_node_encoder;
    2192         8538 :   n_nodes = lto_symtab_encoder_size (encoder);
    2193       118956 :   for (i = 0; i < n_nodes; i++)
    2194              :     {
    2195       110418 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
    2196       220836 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    2197        84988 :       if (cnode && output_cgraph_opt_summary_p (cnode))
    2198        23384 :         count++;
    2199              :     }
    2200         8538 :   streamer_write_uhwi (ob, count);
    2201       127494 :   for (i = 0; i < n_nodes; i++)
    2202              :     {
    2203       110418 :       toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
    2204       220836 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
    2205        84988 :       if (cnode && output_cgraph_opt_summary_p (cnode))
    2206              :         {
    2207        23384 :           streamer_write_uhwi (ob, i);
    2208        23384 :           output_node_opt_summary (ob, cnode, encoder);
    2209              :         }
    2210              :     }
    2211         8538 :   produce_asm (ob);
    2212         8538 :   destroy_output_block (ob);
    2213         8538 : }
    2214              : 
    2215              : /* Input optimisation summary of EDGE.  */
    2216              : 
    2217              : static void
    2218            0 : input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
    2219              :                         class lto_input_block *ib_main ATTRIBUTE_UNUSED)
    2220              : {
    2221            0 : }
    2222              : 
    2223              : /* Input optimisation summary of NODE.  */
    2224              : 
    2225              : static void
    2226        23384 : input_node_opt_summary (struct cgraph_node *node,
    2227              :                         class lto_input_block *ib_main,
    2228              :                         class data_in *data_in)
    2229              : {
    2230        23384 :   int i;
    2231        23384 :   int count;
    2232        23384 :   struct cgraph_edge *e;
    2233              : 
    2234              :   /* TODO: Should this code be moved to ipa-param-manipulation?  */
    2235        23384 :   struct bitpack_d bp;
    2236        23384 :   bp = streamer_read_bitpack (ib_main);
    2237        23384 :   bool have_adjustments = bp_unpack_value (&bp, 1);
    2238        23384 :   clone_info *info = clone_info::get_create (node);
    2239              : 
    2240        23384 :   if (have_adjustments)
    2241              :     {
    2242        19770 :       count = streamer_read_uhwi (ib_main);
    2243        19770 :       vec<ipa_adjusted_param, va_gc> *new_params = NULL;
    2244        57431 :       for (i = 0; i < count; i++)
    2245              :         {
    2246        37661 :           ipa_adjusted_param adj;
    2247        37661 :           memset (&adj, 0, sizeof (adj));
    2248        37661 :           bp = streamer_read_bitpack (ib_main);
    2249        37661 :           adj.base_index = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
    2250        37661 :           adj.prev_clone_index
    2251        37661 :             = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
    2252        37661 :           adj.op = (enum ipa_parm_op) bp_unpack_value (&bp, 2);
    2253        37661 :           adj.param_prefix_index = bp_unpack_value (&bp, 2);
    2254        37661 :           adj.prev_clone_adjustment = bp_unpack_value (&bp, 1);
    2255        37661 :           adj.reverse = bp_unpack_value (&bp, 1);
    2256        37661 :           adj.user_flag = bp_unpack_value (&bp, 1);
    2257        37661 :           if (adj.op == IPA_PARAM_OP_SPLIT
    2258        37661 :               || adj.op == IPA_PARAM_OP_NEW)
    2259              :             {
    2260          676 :               adj.type = stream_read_tree (ib_main, data_in);
    2261          676 :               if (adj.op == IPA_PARAM_OP_SPLIT)
    2262              :                 {
    2263          676 :                   adj.alias_ptr_type = stream_read_tree (ib_main, data_in);
    2264          676 :                   adj.unit_offset = streamer_read_uhwi (ib_main);
    2265              :                 }
    2266              :             }
    2267        37661 :           vec_safe_push (new_params, adj);
    2268              :         }
    2269        19770 :       int always_copy_start = streamer_read_hwi (ib_main);
    2270        19770 :       bp = streamer_read_bitpack (ib_main);
    2271        19770 :       bool skip_return = bp_unpack_value (&bp, 1);
    2272        19770 :       info->param_adjustments
    2273        19770 :         = (new (ggc_alloc <ipa_param_adjustments> ())
    2274        19770 :            ipa_param_adjustments (new_params, always_copy_start, skip_return));
    2275              :     }
    2276              : 
    2277        23384 :   count = streamer_read_uhwi (ib_main);
    2278        29231 :   for (i = 0; i < count; i++)
    2279              :     {
    2280         5847 :       struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
    2281              : 
    2282         5847 :       vec_safe_push (info->tree_map, map);
    2283         5847 :       map->parm_num = streamer_read_uhwi (ib_main);
    2284         5847 :       map->new_tree = stream_read_tree (ib_main, data_in);
    2285              :     }
    2286        23384 :   for (e = node->callees; e; e = e->next_callee)
    2287              :     input_edge_opt_summary (e, ib_main);
    2288        23384 :   for (e = node->indirect_calls; e; e = e->next_callee)
    2289              :     input_edge_opt_summary (e, ib_main);
    2290        23384 : }
    2291              : 
    2292              : /* Read section in file FILE_DATA of length LEN with data DATA.  */
    2293              : 
    2294              : static void
    2295         8538 : input_cgraph_opt_section (struct lto_file_decl_data *file_data,
    2296              :                           const char *data, size_t len,
    2297              :                           vec<symtab_node *> nodes)
    2298              : {
    2299         8538 :   const struct lto_function_header *header =
    2300              :     (const struct lto_function_header *) data;
    2301         8538 :   const int cfg_offset = sizeof (struct lto_function_header);
    2302         8538 :   const int main_offset = cfg_offset + header->cfg_size;
    2303         8538 :   const int string_offset = main_offset + header->main_size;
    2304         8538 :   class data_in *data_in;
    2305         8538 :   unsigned int i;
    2306         8538 :   unsigned int count;
    2307              : 
    2308         8538 :   lto_input_block ib_main ((const char *) data + main_offset,
    2309         8538 :                            header->main_size, file_data);
    2310              : 
    2311         8538 :   data_in =
    2312        17076 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    2313         8538 :                         header->string_size, vNULL);
    2314         8538 :   count = streamer_read_uhwi (&ib_main);
    2315              : 
    2316        31922 :   for (i = 0; i < count; i++)
    2317              :     {
    2318        23384 :       int ref = streamer_read_uhwi (&ib_main);
    2319        46768 :       input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
    2320              :                               &ib_main, data_in);
    2321              :     }
    2322         8538 :   lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
    2323              :                          len);
    2324         8538 :   lto_data_in_delete (data_in);
    2325         8538 : }
    2326              : 
    2327              : /* Input optimization summary of cgraph.  */
    2328              : 
    2329              : static void
    2330         8538 : input_cgraph_opt_summary (vec<symtab_node *> nodes)
    2331              : {
    2332         8538 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    2333         8538 :   struct lto_file_decl_data *file_data;
    2334         8538 :   unsigned int j = 0;
    2335              : 
    2336        25614 :   while ((file_data = file_data_vec[j++]))
    2337              :     {
    2338         8538 :       size_t len;
    2339         8538 :       const char *data
    2340         8538 :         = lto_get_summary_section_data (file_data, LTO_section_cgraph_opt_sum,
    2341              :                                         &len);
    2342         8538 :       if (data)
    2343         8538 :         input_cgraph_opt_section (file_data, data, len, nodes);
    2344              :     }
    2345         8538 : }
        

Generated by: LCOV version 2.5.0-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.