LCOV - code coverage report
Current view: top level - gcc - lto-cgraph.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 87.8 % 1226 1077
Test Date: 2026-02-28 14:20:25 Functions: 94.3 % 53 50
Legend: Lines:     hit not hit

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

Generated by: LCOV version 2.4-beta

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