]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/lto-cgraph.c
[C] Add a target hook that allows targets to verify type usage
[thirdparty/gcc.git] / gcc / lto-cgraph.c
CommitLineData
d7f09764
DN
1/* Write and read the cgraph to the memory mapped representation of a
2 .o file.
3
a5544970 4 Copyright (C) 2009-2019 Free Software Foundation, Inc.
d7f09764
DN
5 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
6
7This file is part of GCC.
8
9GCC is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 3, or (at your option) any later
12version.
13
14GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17for more details.
18
19You should have received a copy of the GNU General Public License
20along 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"
c7131fb2 26#include "backend.h"
957060b5 27#include "rtl.h"
d7f09764 28#include "tree.h"
c7131fb2 29#include "gimple.h"
957060b5 30#include "predict.h"
957060b5 31#include "stringpool.h"
957060b5
AM
32#include "tree-streamer.h"
33#include "cgraph.h"
7d57274b 34#include "tree-pass.h"
2730ada7 35#include "profile.h"
315f8c0e
DM
36#include "context.h"
37#include "pass_manager.h"
82d618d3 38#include "ipa-utils.h"
629b3d75 39#include "omp-offload.h"
314e6352
ML
40#include "stringpool.h"
41#include "attribs.h"
d7f09764 42
f300e7b8
JH
43/* True when asm nodes has been output. */
44bool asm_nodes_output = false;
45
f27c1867 46static void output_cgraph_opt_summary (void);
5e20cdc9 47static void input_cgraph_opt_summary (vec<symtab_node *> nodes);
922f15c2 48
533c07c5 49/* Number of LDPR values known to GCC. */
ed0d2da0 50#define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
2f41ecf5 51
8b4765bf
JH
52/* Cgraph streaming is organized as set of record whose type
53 is indicated by a tag. */
7380e6ef 54enum LTO_symtab_tags
8b4765bf
JH
55{
56 /* Must leave 0 for the stopper. */
57
58 /* Cgraph node without body available. */
7380e6ef 59 LTO_symtab_unavail_node = 1,
8b4765bf 60 /* Cgraph node with function body. */
7380e6ef 61 LTO_symtab_analyzed_node,
8b4765bf 62 /* Cgraph edges. */
7380e6ef
JH
63 LTO_symtab_edge,
64 LTO_symtab_indirect_edge,
65 LTO_symtab_variable,
66 LTO_symtab_last_tag
8b4765bf
JH
67};
68
e75f8f79
JH
69/* Create a new symtab encoder.
70 if FOR_INPUT, the encoder allocate only datastructures needed
71 to read the symtab. */
d7f09764 72
7380e6ef 73lto_symtab_encoder_t
e75f8f79 74lto_symtab_encoder_new (bool for_input)
d7f09764 75{
7380e6ef 76 lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
e75f8f79
JH
77
78 if (!for_input)
b787e7a2 79 encoder->map = new hash_map<symtab_node *, size_t>;
9771b263 80 encoder->nodes.create (0);
d7f09764
DN
81 return encoder;
82}
83
84
85/* Delete ENCODER and its components. */
86
87void
7380e6ef 88lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
d7f09764 89{
9771b263 90 encoder->nodes.release ();
e75f8f79 91 if (encoder->map)
b787e7a2 92 delete encoder->map;
d7f09764
DN
93 free (encoder);
94}
95
96
7380e6ef 97/* Return the existing reference number of NODE in the symtab encoder in
d7f09764
DN
98 output block OB. Assign a new reference if this is the first time
99 NODE is encoded. */
100
101int
7380e6ef 102lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
5e20cdc9 103 symtab_node *node)
d7f09764
DN
104{
105 int ref;
b8698a0f 106
e75f8f79
JH
107 if (!encoder->map)
108 {
109 lto_encoder_entry entry = {node, false, false, false};
110
9771b263
DN
111 ref = encoder->nodes.length ();
112 encoder->nodes.safe_push (entry);
e75f8f79
JH
113 return ref;
114 }
115
b787e7a2 116 size_t *slot = encoder->map->get (node);
7b99cca4 117 if (!slot || !*slot)
d7f09764 118 {
7b99cca4 119 lto_encoder_entry entry = {node, false, false, false};
9771b263 120 ref = encoder->nodes.length ();
7b99cca4 121 if (!slot)
b787e7a2 122 encoder->map->put (node, ref + 1);
9771b263 123 encoder->nodes.safe_push (entry);
d7f09764
DN
124 }
125 else
b787e7a2 126 ref = *slot - 1;
d7f09764
DN
127
128 return ref;
129}
130
7b99cca4 131/* Remove NODE from encoder. */
d7f09764 132
7b99cca4
JH
133bool
134lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
5e20cdc9 135 symtab_node *node)
d7f09764 136{
7b99cca4
JH
137 int index;
138 lto_encoder_entry last_node;
139
b787e7a2 140 size_t *slot = encoder->map->get (node);
7b99cca4
JH
141 if (slot == NULL || !*slot)
142 return false;
143
b787e7a2 144 index = *slot - 1;
9771b263 145 gcc_checking_assert (encoder->nodes[index].node == node);
7b99cca4
JH
146
147 /* Remove from vector. We do this by swapping node with the last element
148 of the vector. */
9771b263 149 last_node = encoder->nodes.pop ();
7b99cca4
JH
150 if (last_node.node != node)
151 {
b787e7a2 152 gcc_assert (encoder->map->put (last_node.node, index + 1));
7b99cca4
JH
153
154 /* Move the last element to the original spot of NODE. */
9771b263 155 encoder->nodes[index] = last_node;
7b99cca4
JH
156 }
157
158 /* Remove element from hash table. */
b787e7a2 159 encoder->map->remove (node);
7b99cca4 160 return true;
d7f09764
DN
161}
162
163
2ead7928 164/* Return TRUE if we should encode the body of NODE (if any). */
d7f09764 165
91fbf0c7 166bool
7380e6ef 167lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
91fbf0c7
JH
168 struct cgraph_node *node)
169{
67348ccc 170 int index = lto_symtab_encoder_lookup (encoder, node);
9771b263 171 return encoder->nodes[index].body;
91fbf0c7
JH
172}
173
2ead7928 174/* Specify that we encode the body of NODE in this partition. */
91fbf0c7
JH
175
176static void
7380e6ef 177lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder,
91fbf0c7 178 struct cgraph_node *node)
d7f09764 179{
67348ccc
DM
180 int index = lto_symtab_encoder_encode (encoder, node);
181 gcc_checking_assert (encoder->nodes[index].node == node);
9771b263 182 encoder->nodes[index].body = true;
d7f09764
DN
183}
184
2f41ecf5
JH
185/* Return TRUE if we should encode initializer of NODE (if any). */
186
187bool
7380e6ef 188lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
2c8326a5 189 varpool_node *node)
2f41ecf5 190{
67348ccc 191 int index = lto_symtab_encoder_lookup (encoder, node);
7b99cca4
JH
192 if (index == LCC_NOT_FOUND)
193 return false;
9771b263 194 return encoder->nodes[index].initializer;
2f41ecf5
JH
195}
196
2ead7928 197/* Specify that we should encode initializer of NODE (if any). */
2f41ecf5
JH
198
199static void
7380e6ef 200lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
2c8326a5 201 varpool_node *node)
2f41ecf5 202{
67348ccc 203 int index = lto_symtab_encoder_lookup (encoder, node);
9771b263 204 encoder->nodes[index].initializer = true;
2f41ecf5 205}
d7f09764 206
2ead7928 207/* Return TRUE if NODE is in this partition. */
f27c1867
JH
208
209bool
210lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
5e20cdc9 211 symtab_node *node)
f27c1867 212{
67348ccc 213 int index = lto_symtab_encoder_lookup (encoder, node);
7b99cca4
JH
214 if (index == LCC_NOT_FOUND)
215 return false;
9771b263 216 return encoder->nodes[index].in_partition;
f27c1867
JH
217}
218
2ead7928 219/* Specify that NODE is in this partition. */
f27c1867
JH
220
221void
222lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
5e20cdc9 223 symtab_node *node)
f27c1867 224{
67348ccc 225 int index = lto_symtab_encoder_encode (encoder, node);
9771b263 226 encoder->nodes[index].in_partition = true;
f27c1867
JH
227}
228
d7f09764
DN
229/* Output the cgraph EDGE to OB using ENCODER. */
230
231static void
232lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
7380e6ef 233 lto_symtab_encoder_t encoder)
d7f09764
DN
234{
235 unsigned int uid;
236 intptr_t ref;
2465dcc2 237 struct bitpack_d bp;
d7f09764 238
e33c6cd6 239 if (edge->indirect_unknown_callee)
7380e6ef
JH
240 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
241 LTO_symtab_indirect_edge);
e33c6cd6 242 else
7380e6ef
JH
243 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
244 LTO_symtab_edge);
d7f09764 245
67348ccc 246 ref = lto_symtab_encoder_lookup (encoder, edge->caller);
b8698a0f 247 gcc_assert (ref != LCC_NOT_FOUND);
412288f1 248 streamer_write_hwi_stream (ob->main_stream, ref);
d7f09764 249
e33c6cd6
MJ
250 if (!edge->indirect_unknown_callee)
251 {
67348ccc 252 ref = lto_symtab_encoder_lookup (encoder, edge->callee);
e33c6cd6 253 gcc_assert (ref != LCC_NOT_FOUND);
412288f1 254 streamer_write_hwi_stream (ob->main_stream, ref);
e33c6cd6 255 }
d7f09764 256
3995f3a2 257 edge->count.stream_out (ob->main_stream);
d7f09764 258
2465dcc2 259 bp = bitpack_create (ob->main_stream);
ec6a1e35 260 uid = (!gimple_has_body_p (edge->caller->decl) || edge->caller->thunk.thunk_p
042ae7d2 261 ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt) + 1);
84562394 262 bp_pack_enum (&bp, cgraph_inline_failed_t,
533c07c5
JH
263 CIF_N_REASONS, edge->inline_failed);
264 bp_pack_var_len_unsigned (&bp, uid);
2465dcc2 265 bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
042ae7d2 266 bp_pack_value (&bp, edge->speculative, 1);
2465dcc2 267 bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
1a0bf5e1
JH
268 gcc_assert (!edge->call_stmt_cannot_inline_p
269 || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
2465dcc2 270 bp_pack_value (&bp, edge->can_throw_external, 1);
f9bb202b 271 bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
5f902d76
JH
272 if (edge->indirect_unknown_callee)
273 {
274 int flags = edge->indirect_info->ecf_flags;
2465dcc2
RG
275 bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
276 bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
277 bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
278 bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
279 bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
280 bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
5f902d76
JH
281 /* Flags that should not appear on indirect calls. */
282 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
283 | ECF_MAY_BE_ALLOCA
284 | ECF_SIBCALL
db0bf14f 285 | ECF_LEAF
5f902d76
JH
286 | ECF_NOVOPS)));
287 }
412288f1 288 streamer_write_bitpack (&bp);
634ab819
JH
289 if (edge->indirect_unknown_callee)
290 {
291 streamer_write_hwi_stream (ob->main_stream,
292 edge->indirect_info->common_target_id);
293 if (edge->indirect_info->common_target_id)
294 streamer_write_hwi_stream
295 (ob->main_stream, edge->indirect_info->common_target_probability);
296 }
d7f09764
DN
297}
298
d122681a 299/* Return if NODE contain references from other partitions. */
f3380641 300
369451ec 301bool
d122681a 302referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
369451ec
JH
303{
304 int i;
d122681a
ML
305 struct ipa_ref *ref = NULL;
306
307 for (i = 0; node->iterate_referring (i, ref); i++)
369451ec 308 {
1f6be682
IV
309 /* Ignore references from non-offloadable nodes while streaming NODE into
310 offload LTO section. */
311 if (!ref->referring->need_lto_streaming)
312 continue;
313
67348ccc 314 if (ref->referring->in_other_partition
f27c1867
JH
315 || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
316 return true;
369451ec
JH
317 }
318 return false;
319}
320
a837268b
JH
321/* Return true when node is reachable from other partition. */
322
9a809897 323bool
f27c1867 324reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
a837268b
JH
325{
326 struct cgraph_edge *e;
67348ccc 327 if (!node->definition)
a837268b 328 return false;
a62bfab5 329 if (node->inlined_to)
a837268b
JH
330 return false;
331 for (e = node->callers; e; e = e->next_caller)
1f6be682
IV
332 {
333 /* Ignore references from non-offloadable nodes while streaming NODE into
334 offload LTO section. */
335 if (!e->caller->need_lto_streaming)
336 continue;
337
338 if (e->caller->in_other_partition
339 || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
340 return true;
341 }
a837268b
JH
342 return false;
343}
d7f09764 344
d122681a 345/* Return if NODE contain references from other partitions. */
f3380641
JH
346
347bool
d122681a 348referenced_from_this_partition_p (symtab_node *node,
f27c1867 349 lto_symtab_encoder_t encoder)
f3380641
JH
350{
351 int i;
d122681a
ML
352 struct ipa_ref *ref = NULL;
353
354 for (i = 0; node->iterate_referring (i, ref); i++)
f27c1867
JH
355 if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
356 return true;
f3380641
JH
357 return false;
358}
359
360/* Return true when node is reachable from other partition. */
361
362bool
f27c1867 363reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
f3380641
JH
364{
365 struct cgraph_edge *e;
f3380641 366 for (e = node->callers; e; e = e->next_caller)
67348ccc 367 if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
f3380641
JH
368 return true;
369 return false;
370}
371
d7f09764
DN
372/* Output the cgraph NODE to OB. ENCODER is used to find the
373 reference number of NODE->inlined_to. SET is the set of nodes we
374 are writing to the current file. If NODE is not in SET, then NODE
375 is a boundary of a cgraph_node_set and we pretend NODE just has a
376 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
377 that have had their callgraph node written so far. This is used to
378 determine if NODE is a clone of a previously written node. */
379
380static void
381lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
f27c1867 382 lto_symtab_encoder_t encoder)
d7f09764
DN
383{
384 unsigned int tag;
2465dcc2 385 struct bitpack_d bp;
91fbf0c7 386 bool boundary_p;
d7f09764 387 intptr_t ref;
a837268b 388 bool in_other_partition = false;
a2e2a668 389 struct cgraph_node *clone_of, *ultimate_clone_of;
6a5ac314 390 ipa_opt_pass_d *pass;
7d57274b 391 int i;
aede2c10 392 const char *comdat;
24d047a3 393 const char *section;
aede2c10 394 tree group;
d7f09764 395
67348ccc 396 boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
d7f09764 397
ec6a1e35 398 if (node->analyzed && (!boundary_p || node->alias
a62bfab5 399 || (node->thunk.thunk_p && !node->inlined_to)))
7380e6ef 400 tag = LTO_symtab_analyzed_node;
8b4765bf 401 else
7380e6ef 402 tag = LTO_symtab_unavail_node;
d7f09764 403
7380e6ef 404 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
412288f1 405 tag);
67348ccc 406 streamer_write_hwi_stream (ob->main_stream, node->order);
d7f09764 407
d7f09764
DN
408 /* In WPA mode, we only output part of the call-graph. Also, we
409 fake cgraph node attributes. There are two cases that we care.
410
411 Boundary nodes: There are nodes that are not part of SET but are
412 called from within SET. We artificially make them look like
b8698a0f 413 externally visible nodes with no function body.
d7f09764
DN
414
415 Cherry-picked nodes: These are nodes we pulled from other
416 translation units into SET during IPA-inlining. We make them as
417 local static nodes to prevent clashes with other local statics. */
96451279 418 if (boundary_p && node->analyzed
d52f5295 419 && node->get_partitioning_class () == SYMBOL_PARTITION)
d7f09764 420 {
67914693 421 /* Inline clones cannot be part of boundary.
a62bfab5 422 gcc_assert (!node->inlined_to);
a837268b
JH
423
424 FIXME: At the moment they can be, when partition contains an inline
425 clone that is clone of inline clone from outside partition. We can
426 reshape the clone tree and make other tree to be the root, but it
427 needs a bit extra work and will be promplty done by cgraph_remove_node
428 after reading back. */
429 in_other_partition = 1;
d7f09764 430 }
d7f09764 431
91fbf0c7
JH
432 clone_of = node->clone_of;
433 while (clone_of
67348ccc 434 && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
91fbf0c7
JH
435 if (clone_of->prev_sibling_clone)
436 clone_of = clone_of->prev_sibling_clone;
437 else
438 clone_of = clone_of->clone_of;
0cac82a0 439
a2e2a668
JH
440 /* See if body of the master function is output. If not, we are seeing only
441 an declaration and we do not need to pass down clone tree. */
442 ultimate_clone_of = clone_of;
443 while (ultimate_clone_of && ultimate_clone_of->clone_of)
444 ultimate_clone_of = ultimate_clone_of->clone_of;
445
446 if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
447 clone_of = NULL;
448
449 if (tag == LTO_symtab_analyzed_node)
0cac82a0 450 gcc_assert (clone_of || !node->clone_of);
91fbf0c7 451 if (!clone_of)
412288f1 452 streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
91fbf0c7 453 else
412288f1 454 streamer_write_hwi_stream (ob->main_stream, ref);
d7f09764 455
d7f09764 456
67348ccc 457 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
3995f3a2 458 node->count.stream_out (ob->main_stream);
412288f1 459 streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
d7f09764 460
7d57274b 461 streamer_write_hwi_stream (ob->main_stream,
9771b263
DN
462 node->ipa_transforms_to_apply.length ());
463 FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
f7695dbf 464 streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
7d57274b 465
7380e6ef 466 if (tag == LTO_symtab_analyzed_node)
d7f09764 467 {
a62bfab5 468 if (node->inlined_to)
8b4765bf 469 {
a62bfab5 470 ref = lto_symtab_encoder_lookup (encoder, node->inlined_to);
8b4765bf
JH
471 gcc_assert (ref != LCC_NOT_FOUND);
472 }
473 else
474 ref = LCC_NOT_FOUND;
d7f09764 475
412288f1 476 streamer_write_hwi_stream (ob->main_stream, ref);
d7f09764 477 }
d7f09764 478
aede2c10
JH
479 group = node->get_comdat_group ();
480 if (group)
481 comdat = IDENTIFIER_POINTER (group);
482 else
483 comdat = "";
bfa2ebe3 484 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
24d047a3 485
aede2c10 486 if (group)
b66887e4 487 {
71e54687 488 if (node->same_comdat_group)
aede2c10 489 {
71e54687
JH
490 ref = LCC_NOT_FOUND;
491 for (struct symtab_node *n = node->same_comdat_group;
492 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
493 ref = lto_symtab_encoder_lookup (encoder, n);
aede2c10
JH
494 }
495 else
496 ref = LCC_NOT_FOUND;
497 streamer_write_hwi_stream (ob->main_stream, ref);
b66887e4 498 }
b66887e4 499
e257a17c
JH
500 section = node->get_section ();
501 if (!section)
24d047a3 502 section = "";
24d047a3 503
86ce5d2f
ML
504 streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
505
2465dcc2 506 bp = bitpack_create (ob->main_stream);
87f94429 507 bp_pack_value (&bp, node->local, 1);
67348ccc 508 bp_pack_value (&bp, node->externally_visible, 1);
7861b648 509 bp_pack_value (&bp, node->no_reorder, 1);
67348ccc 510 bp_pack_value (&bp, node->definition, 1);
87f94429
ML
511 bp_pack_value (&bp, node->versionable, 1);
512 bp_pack_value (&bp, node->can_change_signature, 1);
513 bp_pack_value (&bp, node->redefined_extern_inline, 1);
67348ccc
DM
514 bp_pack_value (&bp, node->force_output, 1);
515 bp_pack_value (&bp, node->forced_by_abi, 1);
516 bp_pack_value (&bp, node->unique_name, 1);
4a5798de 517 bp_pack_value (&bp, node->body_removed, 1);
e257a17c 518 bp_pack_value (&bp, node->implicit_section, 1);
67348ccc 519 bp_pack_value (&bp, node->address_taken, 1);
7380e6ef 520 bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
d52f5295 521 && node->get_partitioning_class () == SYMBOL_PARTITION
f27c1867 522 && (reachable_from_other_partition_p (node, encoder)
d122681a 523 || referenced_from_other_partition_p (node, encoder)), 1);
2465dcc2
RG
524 bp_pack_value (&bp, node->lowered, 1);
525 bp_pack_value (&bp, in_other_partition, 1);
4bd019b8 526 bp_pack_value (&bp, node->alias, 1);
71e54687 527 bp_pack_value (&bp, node->transparent_alias, 1);
67348ccc 528 bp_pack_value (&bp, node->weakref, 1);
2465dcc2 529 bp_pack_value (&bp, node->frequency, 2);
844db5d0
JH
530 bp_pack_value (&bp, node->only_called_at_startup, 1);
531 bp_pack_value (&bp, node->only_called_at_exit, 1);
57ac2606 532 bp_pack_value (&bp, node->tm_clone, 1);
1f26ac87 533 bp_pack_value (&bp, node->calls_comdat_local, 1);
b84d4347 534 bp_pack_value (&bp, node->icf_merged, 1);
8413ca87 535 bp_pack_value (&bp, node->nonfreeing_fn, 1);
b74d8dc4
JH
536 bp_pack_value (&bp, node->merged_comdat, 1);
537 bp_pack_value (&bp, node->merged_extern_inline, 1);
4bd019b8 538 bp_pack_value (&bp, node->thunk.thunk_p, 1);
a79b7ec5 539 bp_pack_value (&bp, node->parallelized_function, 1);
533c07c5 540 bp_pack_enum (&bp, ld_plugin_symbol_resolution,
5b42d196
JH
541 LDPR_NUM_KNOWN,
542 /* When doing incremental link, we will get new resolution
543 info next time we process the file. */
544 flag_incremental_link ? LDPR_UNKNOWN : node->resolution);
41f669d8 545 bp_pack_value (&bp, node->split_part, 1);
412288f1 546 streamer_write_bitpack (&bp);
bfa2ebe3 547 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
2465dcc2 548
ffdcdc0b
JH
549 /* Stream thunk info always because we use it in
550 ipa_polymorphic_call_context::ipa_polymorphic_call_context
551 to properly interpret THIS pointers for thunks that has been converted
552 to Gimple. */
553 if (node->definition)
c47d0034 554 {
412288f1 555 streamer_write_uhwi_stream
c47d0034
JH
556 (ob->main_stream,
557 1 + (node->thunk.this_adjusting != 0) * 2
dbcdd561 558 + (node->thunk.virtual_offset_p != 0) * 4);
412288f1
DN
559 streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset);
560 streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value);
44662f68 561 streamer_write_uhwi_stream (ob->main_stream, node->thunk.indirect_offset);
c47d0034 562 }
634ab819 563 streamer_write_hwi_stream (ob->main_stream, node->profile_id);
b74d8dc4 564 streamer_write_hwi_stream (ob->main_stream, node->unit_id);
569b1784 565 if (DECL_STATIC_CONSTRUCTOR (node->decl))
1cff83e2 566 streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
569b1784 567 if (DECL_STATIC_DESTRUCTOR (node->decl))
1cff83e2 568 streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
d7f09764
DN
569}
570
2942c502
JH
571/* Output the varpool NODE to OB.
572 If NODE is not in SET, then NODE is a boundary. */
573
574static void
2c8326a5 575lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
f27c1867 576 lto_symtab_encoder_t encoder)
2942c502 577{
67348ccc 578 bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
87be7f0c
JH
579 bool encode_initializer_p
580 = (node->definition
581 && lto_symtab_encoder_encode_initializer_p (encoder, node));
2465dcc2 582 struct bitpack_d bp;
9f90e80a 583 int ref;
aede2c10 584 const char *comdat;
24d047a3 585 const char *section;
aede2c10 586 tree group;
2942c502 587
87be7f0c
JH
588 gcc_assert (!encode_initializer_p || node->definition);
589 gcc_assert (boundary_p || encode_initializer_p);
590
7380e6ef
JH
591 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
592 LTO_symtab_variable);
67348ccc
DM
593 streamer_write_hwi_stream (ob->main_stream, node->order);
594 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl);
2465dcc2 595 bp = bitpack_create (ob->main_stream);
67348ccc 596 bp_pack_value (&bp, node->externally_visible, 1);
7861b648 597 bp_pack_value (&bp, node->no_reorder, 1);
67348ccc
DM
598 bp_pack_value (&bp, node->force_output, 1);
599 bp_pack_value (&bp, node->forced_by_abi, 1);
600 bp_pack_value (&bp, node->unique_name, 1);
87be7f0c
JH
601 bp_pack_value (&bp,
602 node->body_removed
603 || (!encode_initializer_p && !node->alias && node->definition),
604 1);
e257a17c 605 bp_pack_value (&bp, node->implicit_section, 1);
6de88c6a 606 bp_pack_value (&bp, node->writeonly, 1);
87be7f0c
JH
607 bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias),
608 1);
4bd019b8 609 bp_pack_value (&bp, node->alias, 1);
71e54687 610 bp_pack_value (&bp, node->transparent_alias, 1);
67348ccc 611 bp_pack_value (&bp, node->weakref, 1);
71e54687 612 bp_pack_value (&bp, node->analyzed && (!boundary_p || node->alias), 1);
67348ccc 613 gcc_assert (node->definition || !node->analyzed);
05575e07
JH
614 /* Constant pool initializers can be de-unified into individual ltrans units.
615 FIXME: Alternatively at -Os we may want to avoid generating for them the local
616 labels and share them across LTRANS partitions. */
d52f5295 617 if (node->get_partitioning_class () != SYMBOL_PARTITION)
05575e07 618 {
2465dcc2
RG
619 bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */
620 bp_pack_value (&bp, 0, 1); /* in_other_partition. */
05575e07
JH
621 }
622 else
623 {
67348ccc 624 bp_pack_value (&bp, node->definition
d122681a 625 && referenced_from_other_partition_p (node, encoder), 1);
67348ccc
DM
626 bp_pack_value (&bp, node->analyzed
627 && boundary_p && !DECL_EXTERNAL (node->decl), 1);
6649df51 628 /* in_other_partition. */
05575e07 629 }
56363ffd 630 bp_pack_value (&bp, node->tls_model, 3);
eb6a09a7 631 bp_pack_value (&bp, node->used_by_single_function, 1);
ca280d38 632 bp_pack_value (&bp, node->dynamically_initialized, 1);
412288f1 633 streamer_write_bitpack (&bp);
24d047a3 634
aede2c10
JH
635 group = node->get_comdat_group ();
636 if (group)
637 comdat = IDENTIFIER_POINTER (group);
638 else
639 comdat = "";
bfa2ebe3 640 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
24d047a3 641
aede2c10 642 if (group)
9f90e80a 643 {
71e54687 644 if (node->same_comdat_group)
aede2c10 645 {
71e54687
JH
646 ref = LCC_NOT_FOUND;
647 for (struct symtab_node *n = node->same_comdat_group;
648 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
649 ref = lto_symtab_encoder_lookup (encoder, n);
aede2c10
JH
650 }
651 else
652 ref = LCC_NOT_FOUND;
653 streamer_write_hwi_stream (ob->main_stream, ref);
9f90e80a 654 }
24d047a3 655
e257a17c
JH
656 section = node->get_section ();
657 if (!section)
24d047a3 658 section = "";
bfa2ebe3 659 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
24d047a3 660
412288f1 661 streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
67348ccc 662 LDPR_NUM_KNOWN, node->resolution);
2942c502
JH
663}
664
369451ec
JH
665/* Output the varpool NODE to OB.
666 If NODE is not in SET, then NODE is a boundary. */
667
668static void
669lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
7380e6ef 670 lto_symtab_encoder_t encoder)
369451ec 671{
2465dcc2 672 struct bitpack_d bp;
7380e6ef 673 int nref;
042ae7d2
JH
674 int uid = ref->lto_stmt_uid;
675 struct cgraph_node *node;
7380e6ef 676
2465dcc2 677 bp = bitpack_create (ob->main_stream);
d5e254e1 678 bp_pack_value (&bp, ref->use, 3);
042ae7d2 679 bp_pack_value (&bp, ref->speculative, 1);
412288f1 680 streamer_write_bitpack (&bp);
7380e6ef
JH
681 nref = lto_symtab_encoder_lookup (encoder, ref->referred);
682 gcc_assert (nref != LCC_NOT_FOUND);
683 streamer_write_hwi_stream (ob->main_stream, nref);
042ae7d2 684
7de90a6c 685 node = dyn_cast <cgraph_node *> (ref->referring);
042ae7d2
JH
686 if (node)
687 {
688 if (ref->stmt)
689 uid = gimple_uid (ref->stmt) + 1;
690 streamer_write_hwi_stream (ob->main_stream, uid);
691 }
369451ec
JH
692}
693
0bc1b77f
JH
694/* Stream out profile_summary to OB. */
695
696static void
697output_profile_summary (struct lto_simple_output_block *ob)
698{
699 if (profile_info)
700 {
2730ada7
TJ
701 /* We do not output num and run_max, they are not used by
702 GCC profile feedback and they are difficult to merge from multiple
703 units. */
512cc015
ML
704 unsigned runs = (profile_info->runs);
705 streamer_write_uhwi_stream (ob->main_stream, runs);
706
0208f7da
JH
707 /* IPA-profile computes hot bb threshold based on cumulated
708 whole program profile. We need to stream it down to ltrans. */
709 if (flag_wpa)
710 streamer_write_gcov_count_stream (ob->main_stream,
711 get_hot_bb_threshold ());
0bc1b77f
JH
712 }
713 else
412288f1 714 streamer_write_uhwi_stream (ob->main_stream, 0);
0bc1b77f
JH
715}
716
e33c6cd6
MJ
717/* Output all callees or indirect outgoing edges. EDGE must be the first such
718 edge. */
719
720static void
721output_outgoing_cgraph_edges (struct cgraph_edge *edge,
722 struct lto_simple_output_block *ob,
7380e6ef 723 lto_symtab_encoder_t encoder)
e33c6cd6
MJ
724{
725 if (!edge)
726 return;
727
728 /* Output edges in backward direction, so the reconstructed callgraph match
729 and it is easy to associate call sites in the IPA pass summaries. */
730 while (edge->next_callee)
731 edge = edge->next_callee;
732 for (; edge; edge = edge->prev_callee)
733 lto_output_edge (ob, edge, encoder);
734}
735
369451ec
JH
736/* Output the part of the cgraph in SET. */
737
738static void
f27c1867 739output_refs (lto_symtab_encoder_t encoder)
369451ec 740{
369451ec
JH
741 struct lto_simple_output_block *ob;
742 int count;
743 struct ipa_ref *ref;
369451ec
JH
744
745 ob = lto_create_simple_output_block (LTO_section_refs);
746
4bd019b8 747 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
369451ec 748 {
4bd019b8
JH
749 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
750
31db0fe0 751 /* IPA_REF_ALIAS references are always preserved
48de5d37
IE
752 in the boundary. Alias node can't have other references and
753 can be always handled as if it's not in the boundary. */
4bd019b8 754 if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node))
31db0fe0 755 continue;
369451ec 756
d122681a 757 count = node->ref_list.nreferences ();
369451ec
JH
758 if (count)
759 {
edb983b2 760 streamer_write_gcov_count_stream (ob->main_stream, count);
412288f1 761 streamer_write_uhwi_stream (ob->main_stream,
f27c1867 762 lto_symtab_encoder_lookup (encoder, node));
4bd019b8 763 for (int i = 0; node->iterate_reference (i, ref); i++)
7380e6ef 764 lto_output_ref (ob, ref, encoder);
369451ec
JH
765 }
766 }
767
412288f1 768 streamer_write_uhwi_stream (ob->main_stream, 0);
369451ec
JH
769
770 lto_destroy_simple_output_block (ob);
771}
772
b4661bfe
JH
773/* Add NODE into encoder as well as nodes it is cloned from.
774 Do it in a way so clones appear first. */
775
776static void
777add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
778 bool include_body)
779{
780 if (node->clone_of)
781 add_node_to (encoder, node->clone_of, include_body);
782 else if (include_body)
783 lto_set_symtab_encoder_encode_body (encoder, node);
67348ccc 784 lto_symtab_encoder_encode (encoder, node);
b4661bfe
JH
785}
786
d122681a 787/* Add all references in NODE to encoders. */
b4661bfe
JH
788
789static void
3dafb85c 790create_references (lto_symtab_encoder_t encoder, symtab_node *node)
b4661bfe
JH
791{
792 int i;
d122681a
ML
793 struct ipa_ref *ref = NULL;
794 for (i = 0; node->iterate_reference (i, ref); i++)
7de90a6c 795 if (is_a <cgraph_node *> (ref->referred))
d122681a 796 add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
b4661bfe 797 else
b5493fb2 798 lto_symtab_encoder_encode (encoder, ref->referred);
b4661bfe
JH
799}
800
1f6be682
IV
801/* Select what needs to be streamed out. In regular lto mode stream everything.
802 In offload lto mode stream only nodes marked as offloadable. */
803void
837bac8c 804select_what_to_stream (void)
1f6be682
IV
805{
806 struct symtab_node *snode;
807 FOR_EACH_SYMBOL (snode)
837bac8c 808 snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable;
1f6be682
IV
809}
810
b4661bfe
JH
811/* Find all symbols we want to stream into given partition and insert them
812 to encoders.
813
814 The function actually replaces IN_ENCODER by new one. The reason is that
815 streaming code needs clone's origin to be streamed before clone. This
816 means that we need to insert the nodes in specific order. This order is
817 ignored by the partitioning logic earlier. */
818
819lto_symtab_encoder_t
820compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
d7f09764 821{
d7f09764 822 struct cgraph_edge *edge;
f3380641 823 int i;
7380e6ef 824 lto_symtab_encoder_t encoder;
7b99cca4 825 lto_symtab_encoder_iterator lsei;
6e2830c3 826 hash_set<void *> reachable_call_targets;
0bc1b77f 827
e75f8f79 828 encoder = lto_symtab_encoder_new (false);
d7f09764 829
7b99cca4
JH
830 /* Go over all entries in the IN_ENCODER and duplicate them to
831 ENCODER. At the same time insert masters of clones so
832 every master appears before clone. */
833 for (lsei = lsei_start_function_in_partition (in_encoder);
834 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
d7f09764 835 {
224dbc07 836 struct cgraph_node *node = lsei_cgraph_node (lsei);
1f6be682
IV
837 if (!node->need_lto_streaming)
838 continue;
91fbf0c7 839 add_node_to (encoder, node, true);
67348ccc 840 lto_set_symtab_encoder_in_partition (encoder, node);
3dafb85c 841 create_references (encoder, node);
d7f09764 842 }
7b99cca4
JH
843 for (lsei = lsei_start_variable_in_partition (in_encoder);
844 !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
2f41ecf5 845 {
2c8326a5 846 varpool_node *vnode = lsei_varpool_node (lsei);
40a7fe1e 847
1f6be682
IV
848 if (!vnode->need_lto_streaming)
849 continue;
67348ccc 850 lto_set_symtab_encoder_in_partition (encoder, vnode);
7380e6ef 851 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
3dafb85c 852 create_references (encoder, vnode);
2f41ecf5 853 }
2f41ecf5
JH
854 /* Pickle in also the initializer of all referenced readonly variables
855 to help folding. Constant pool variables are not shared, so we must
856 pickle those too. */
7380e6ef 857 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
2f41ecf5 858 {
5e20cdc9 859 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
7de90a6c 860 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
2f41ecf5 861 {
6a6dac52
JH
862 if (!lto_symtab_encoder_encode_initializer_p (encoder,
863 vnode)
1e29e4d3
JH
864 && (((vnode->ctor_useable_for_folding_p ()
865 && (!DECL_VIRTUAL_P (vnode->decl)
866 || !flag_wpa
31db0fe0 867 || flag_ltrans_devirtualize)))))
7380e6ef
JH
868 {
869 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
3dafb85c 870 create_references (encoder, vnode);
7380e6ef 871 }
7380e6ef 872 }
2f41ecf5 873 }
d7f09764
DN
874
875 /* Go over all the nodes again to include callees that are not in
876 SET. */
7b99cca4
JH
877 for (lsei = lsei_start_function_in_partition (encoder);
878 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
d7f09764 879 {
224dbc07 880 struct cgraph_node *node = lsei_cgraph_node (lsei);
d7f09764
DN
881 for (edge = node->callees; edge; edge = edge->next_callee)
882 {
883 struct cgraph_node *callee = edge->callee;
67348ccc 884 if (!lto_symtab_encoder_in_partition_p (encoder, callee))
d7f09764
DN
885 {
886 /* We should have moved all the inlines. */
a62bfab5 887 gcc_assert (!callee->inlined_to);
91fbf0c7 888 add_node_to (encoder, callee, false);
d7f09764
DN
889 }
890 }
82d618d3 891 /* Add all possible targets for late devirtualization. */
1e29e4d3 892 if (flag_ltrans_devirtualize || !flag_wpa)
82d618d3
JH
893 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
894 if (edge->indirect_info->polymorphic)
895 {
896 unsigned int i;
897 void *cache_token;
898 bool final;
899 vec <cgraph_node *>targets
900 = possible_polymorphic_call_targets
901 (edge, &final, &cache_token);
6e2830c3 902 if (!reachable_call_targets.add (cache_token))
82d618d3 903 {
c3284718 904 for (i = 0; i < targets.length (); i++)
82d618d3
JH
905 {
906 struct cgraph_node *callee = targets[i];
907
908 /* Adding an external declarations into the unit serves
909 no purpose and just increases its boundary. */
67348ccc 910 if (callee->definition
82d618d3 911 && !lto_symtab_encoder_in_partition_p
67348ccc 912 (encoder, callee))
82d618d3 913 {
a62bfab5 914 gcc_assert (!callee->inlined_to);
82d618d3
JH
915 add_node_to (encoder, callee, false);
916 }
917 }
918 }
919 }
d7f09764 920 }
4bd019b8
JH
921 /* Be sure to also insert alias targert and thunk callees. These needs
922 to stay to aid local calling conventions. */
923 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
924 {
925 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
926 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
927
928 if (node->alias && node->analyzed)
929 create_references (encoder, node);
930 if (cnode
a62bfab5 931 && cnode->thunk.thunk_p && !cnode->inlined_to)
4bd019b8 932 add_node_to (encoder, cnode->callees->callee, false);
2b73ad1d
JH
933 while (node->transparent_alias && node->analyzed)
934 {
935 node = node->get_alias_target ();
936 if (is_a <cgraph_node *> (node))
937 add_node_to (encoder, dyn_cast <cgraph_node *> (node),
938 false);
939 else
940 lto_symtab_encoder_encode (encoder, node);
941 }
4bd019b8 942 }
82d618d3 943 lto_symtab_encoder_delete (in_encoder);
82d618d3 944 return encoder;
f3380641
JH
945}
946
ab96cc5b 947/* Output the part of the symtab in SET and VSET. */
f3380641
JH
948
949void
f27c1867 950output_symtab (void)
f3380641
JH
951{
952 struct cgraph_node *node;
953 struct lto_simple_output_block *ob;
f3380641 954 int i, n_nodes;
7380e6ef 955 lto_symtab_encoder_t encoder;
f3380641 956
922f15c2 957 if (flag_wpa)
f27c1867 958 output_cgraph_opt_summary ();
922f15c2 959
ab96cc5b 960 ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
f3380641
JH
961
962 output_profile_summary (ob);
963
964 /* An encoder for cgraph nodes should have been created by
965 ipa_write_summaries_1. */
7380e6ef
JH
966 gcc_assert (ob->decl_state->symtab_node_encoder);
967 encoder = ob->decl_state->symtab_node_encoder;
f3380641 968
a837268b
JH
969 /* Write out the nodes. We must first output a node and then its clones,
970 otherwise at a time reading back the node there would be nothing to clone
971 from. */
7380e6ef 972 n_nodes = lto_symtab_encoder_size (encoder);
d7f09764
DN
973 for (i = 0; i < n_nodes; i++)
974 {
5e20cdc9 975 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
7de90a6c 976 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
5d59b5e1 977 lto_output_node (ob, cnode, encoder);
7380e6ef 978 else
d52f5295 979 lto_output_varpool_node (ob, dyn_cast<varpool_node *> (node), encoder);
d7f09764
DN
980 }
981
d7f09764 982 /* Go over the nodes in SET again to write edges. */
4bd019b8 983 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
d7f09764 984 {
4bd019b8
JH
985 node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
986 if (node
a62bfab5 987 && ((node->thunk.thunk_p && !node->inlined_to)
4bd019b8
JH
988 || lto_symtab_encoder_in_partition_p (encoder, node)))
989 {
990 output_outgoing_cgraph_edges (node->callees, ob, encoder);
991 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
992 }
d7f09764
DN
993 }
994
412288f1 995 streamer_write_uhwi_stream (ob->main_stream, 0);
d7f09764 996
49f836ba
JB
997 lto_destroy_simple_output_block (ob);
998
b0d9e663
JH
999 /* Emit toplevel asms.
1000 When doing WPA we must output every asm just once. Since we do not partition asm
1001 nodes at all, output them to first output. This is kind of hack, but should work
1002 well. */
1003 if (!asm_nodes_output)
a9cc4458 1004 {
b0d9e663 1005 asm_nodes_output = true;
49f836ba 1006 lto_output_toplevel_asms ();
a9cc4458
RG
1007 }
1008
f27c1867 1009 output_refs (encoder);
d7f09764
DN
1010}
1011
24d047a3 1012/* Return identifier encoded in IB as a plain string. */
aede2c10
JH
1013
1014static tree
99b1c316 1015read_identifier (class lto_input_block *ib)
aede2c10
JH
1016{
1017 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
24d047a3
JH
1018 tree id;
1019
1020 if (ib->data[ib->p + len])
1021 lto_section_overrun (ib);
1022 if (!len)
1023 {
1024 ib->p++;
1025 return NULL;
1026 }
1027 id = get_identifier (ib->data + ib->p);
1028 ib->p += len + 1;
1029 return id;
1030}
1031
f961457f 1032/* Return string encoded in IB, NULL if string is empty. */
24d047a3 1033
f961457f 1034static const char *
99b1c316 1035read_string (class lto_input_block *ib)
24d047a3
JH
1036{
1037 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
f961457f 1038 const char *str;
aede2c10
JH
1039
1040 if (ib->data[ib->p + len])
1041 lto_section_overrun (ib);
1042 if (!len)
1043 {
1044 ib->p++;
1045 return NULL;
1046 }
f961457f 1047 str = ib->data + ib->p;
aede2c10 1048 ib->p += len + 1;
f961457f 1049 return str;
aede2c10
JH
1050}
1051
ec6fe917
IV
1052/* Output function/variable tables that will allow libgomp to look up offload
1053 target code.
1054 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1055 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1056 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1057
1058void
1059output_offload_tables (void)
1060{
1061 if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars))
1062 return;
1063
1064 struct lto_simple_output_block *ob
1065 = lto_create_simple_output_block (LTO_section_offload_table);
1066
1067 for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
1068 {
1069 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1070 LTO_symtab_last_tag, LTO_symtab_unavail_node);
1071 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
1072 (*offload_funcs)[i]);
1073 }
1074
1075 for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
1076 {
1077 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1078 LTO_symtab_last_tag, LTO_symtab_variable);
1079 lto_output_var_decl_index (ob->decl_state, ob->main_stream,
1080 (*offload_vars)[i]);
1081 }
1082
1083 streamer_write_uhwi_stream (ob->main_stream, 0);
1084 lto_destroy_simple_output_block (ob);
1085
1086 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1087 streamed to one partition only. That's why we free offload_funcs and
1088 offload_vars after the first call of output_offload_tables. */
1089 if (flag_wpa)
1090 {
1091 vec_free (offload_funcs);
1092 vec_free (offload_vars);
1093 }
1094}
1095
b0aba46c
TV
1096/* Verify the partitioning of NODE. */
1097
1098static inline void
1099verify_node_partition (symtab_node *node)
1100{
1101 if (flag_ltrans)
1102 return;
1103
1104#ifdef ACCEL_COMPILER
1105 if (node->in_other_partition)
1106 {
1107 if (TREE_CODE (node->decl) == FUNCTION_DECL)
1108 error_at (DECL_SOURCE_LOCATION (node->decl),
1109 "function %qs has been referenced in offloaded code but"
1110 " hasn%'t been marked to be included in the offloaded code",
1111 node->name ());
1112 else if (VAR_P (node->decl))
1113 error_at (DECL_SOURCE_LOCATION (node->decl),
1114 "variable %qs has been referenced in offloaded code but"
1115 " hasn%'t been marked to be included in the offloaded code",
1116 node->name ());
1117 else
1118 gcc_unreachable ();
1119 }
1120#else
1121 gcc_assert (!node->in_other_partition
1122 && !node->used_from_other_partition);
1123#endif
1124}
1125
d7f09764
DN
1126/* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1127 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1128 NODE or to replace the values in it, for instance because the first
1129 time we saw it, the function body was not available but now it
1130 is. BP is a bitpack with all the bitflags for NODE read from the
1131 stream. */
1132
1133static void
1134input_overwrite_node (struct lto_file_decl_data *file_data,
1135 struct cgraph_node *node,
7380e6ef 1136 enum LTO_symtab_tags tag,
533c07c5 1137 struct bitpack_d *bp)
d7f09764 1138{
67348ccc
DM
1139 node->aux = (void *) tag;
1140 node->lto_file_data = file_data;
d7f09764 1141
87f94429 1142 node->local = bp_unpack_value (bp, 1);
67348ccc 1143 node->externally_visible = bp_unpack_value (bp, 1);
7861b648 1144 node->no_reorder = bp_unpack_value (bp, 1);
67348ccc 1145 node->definition = bp_unpack_value (bp, 1);
87f94429
ML
1146 node->versionable = bp_unpack_value (bp, 1);
1147 node->can_change_signature = bp_unpack_value (bp, 1);
1148 node->redefined_extern_inline = bp_unpack_value (bp, 1);
67348ccc
DM
1149 node->force_output = bp_unpack_value (bp, 1);
1150 node->forced_by_abi = bp_unpack_value (bp, 1);
1151 node->unique_name = bp_unpack_value (bp, 1);
4a5798de 1152 node->body_removed = bp_unpack_value (bp, 1);
e257a17c 1153 node->implicit_section = bp_unpack_value (bp, 1);
67348ccc
DM
1154 node->address_taken = bp_unpack_value (bp, 1);
1155 node->used_from_other_partition = bp_unpack_value (bp, 1);
d7f09764 1156 node->lowered = bp_unpack_value (bp, 1);
67348ccc
DM
1157 node->analyzed = tag == LTO_symtab_analyzed_node;
1158 node->in_other_partition = bp_unpack_value (bp, 1);
1159 if (node->in_other_partition
52b3b3c7
JH
1160 /* Avoid updating decl when we are seeing just inline clone.
1161 When inlining function that has functions already inlined into it,
1162 we produce clones of inline clones.
1163
1164 WPA partitioning might put each clone into different unit and
1165 we might end up streaming inline clone from other partition
1166 to support clone we are interested in. */
1167 && (!node->clone_of
67348ccc 1168 || node->clone_of->decl != node->decl))
1c7b11d2 1169 {
67348ccc
DM
1170 DECL_EXTERNAL (node->decl) = 1;
1171 TREE_STATIC (node->decl) = 0;
1c7b11d2 1172 }
67348ccc 1173 node->alias = bp_unpack_value (bp, 1);
71e54687 1174 node->transparent_alias = bp_unpack_value (bp, 1);
67348ccc 1175 node->weakref = bp_unpack_value (bp, 1);
5fefcf92 1176 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
844db5d0
JH
1177 node->only_called_at_startup = bp_unpack_value (bp, 1);
1178 node->only_called_at_exit = bp_unpack_value (bp, 1);
57ac2606 1179 node->tm_clone = bp_unpack_value (bp, 1);
1f26ac87 1180 node->calls_comdat_local = bp_unpack_value (bp, 1);
b84d4347 1181 node->icf_merged = bp_unpack_value (bp, 1);
8413ca87 1182 node->nonfreeing_fn = bp_unpack_value (bp, 1);
b74d8dc4
JH
1183 node->merged_comdat = bp_unpack_value (bp, 1);
1184 node->merged_extern_inline = bp_unpack_value (bp, 1);
c47d0034 1185 node->thunk.thunk_p = bp_unpack_value (bp, 1);
a79b7ec5 1186 node->parallelized_function = bp_unpack_value (bp, 1);
67348ccc 1187 node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
533c07c5 1188 LDPR_NUM_KNOWN);
41f669d8 1189 node->split_part = bp_unpack_value (bp, 1);
b0aba46c 1190 verify_node_partition (node);
d7f09764
DN
1191}
1192
40a7fe1e
JH
1193/* Return string alias is alias of. */
1194
1195static tree
1196get_alias_symbol (tree decl)
1197{
1198 tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
40a7fe1e
JH
1199 return get_identifier (TREE_STRING_POINTER
1200 (TREE_VALUE (TREE_VALUE (alias))));
1201}
1202
b8698a0f 1203/* Read a node from input_block IB. TAG is the node's tag just read.
d7f09764 1204 Return the node read or overwriten. */
b8698a0f 1205
d7f09764
DN
1206static struct cgraph_node *
1207input_node (struct lto_file_decl_data *file_data,
99b1c316 1208 class lto_input_block *ib,
7380e6ef 1209 enum LTO_symtab_tags tag,
5e20cdc9 1210 vec<symtab_node *> nodes)
d7f09764 1211{
315f8c0e 1212 gcc::pass_manager *passes = g->get_passes ();
d7f09764
DN
1213 tree fn_decl;
1214 struct cgraph_node *node;
2465dcc2 1215 struct bitpack_d bp;
d7f09764 1216 unsigned decl_index;
b66887e4 1217 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
91fbf0c7 1218 int clone_ref;
398f05da 1219 int order;
7d57274b 1220 int i, count;
aede2c10 1221 tree group;
f961457f 1222 const char *section;
3c56d8d8 1223 order = streamer_read_hwi (ib) + file_data->order_base;
412288f1 1224 clone_ref = streamer_read_hwi (ib);
d7f09764 1225
412288f1 1226 decl_index = streamer_read_uhwi (ib);
d7f09764
DN
1227 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1228
91fbf0c7
JH
1229 if (clone_ref != LCC_NOT_FOUND)
1230 {
d52f5295 1231 node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
1bad9c18 1232 profile_count::uninitialized (), false,
d52f5295 1233 vNULL, false, NULL, NULL);
91fbf0c7 1234 }
d7f09764 1235 else
bbf9ad07
JH
1236 {
1237 /* Declaration of functions can be already merged with a declaration
1238 from other input file. We keep cgraph unmerged until after streaming
1239 of ipa passes is done. Alays forcingly create a fresh node. */
3dafb85c 1240 node = symtab->create_empty ();
67348ccc 1241 node->decl = fn_decl;
aab778d3
L
1242 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl)))
1243 node->ifunc_resolver = 1;
d52f5295 1244 node->register_symbol ();
bbf9ad07 1245 }
d7f09764 1246
67348ccc 1247 node->order = order;
3dafb85c
ML
1248 if (order >= symtab->order)
1249 symtab->order = order + 1;
398f05da 1250
3995f3a2 1251 node->count = profile_count::stream_in (ib);
412288f1 1252 node->count_materialization_scale = streamer_read_hwi (ib);
b8698a0f 1253
7d57274b 1254 count = streamer_read_hwi (ib);
6e1aa848 1255 node->ipa_transforms_to_apply = vNULL;
7d57274b
MJ
1256 for (i = 0; i < count; i++)
1257 {
6a5ac314 1258 opt_pass *pass;
7d57274b
MJ
1259 int pid = streamer_read_hwi (ib);
1260
315f8c0e
DM
1261 gcc_assert (pid < passes->passes_by_id_size);
1262 pass = passes->passes_by_id[pid];
6a5ac314 1263 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
7d57274b
MJ
1264 }
1265
7380e6ef 1266 if (tag == LTO_symtab_analyzed_node)
412288f1 1267 ref = streamer_read_hwi (ib);
d7f09764 1268
24d047a3 1269 group = read_identifier (ib);
aede2c10
JH
1270 if (group)
1271 ref2 = streamer_read_hwi (ib);
d7f09764
DN
1272
1273 /* Make sure that we have not read this node before. Nodes that
1274 have already been read will have their tag stored in the 'aux'
1275 field. Since built-in functions can be referenced in multiple
1276 functions, they are expected to be read more than once. */
3d78e008 1277 if (node->aux && !fndecl_built_in_p (node->decl))
d7f09764 1278 internal_error ("bytecode stream: found multiple instances of cgraph "
4325656f 1279 "node with uid %d", node->get_uid ());
d7f09764 1280
86ce5d2f
ML
1281 node->tp_first_run = streamer_read_uhwi (ib);
1282
412288f1 1283 bp = streamer_read_bitpack (ib);
86ce5d2f 1284
533c07c5 1285 input_overwrite_node (file_data, node, tag, &bp);
d7f09764 1286
d7f09764 1287 /* Store a reference for now, and fix up later to be a pointer. */
a62bfab5 1288 node->inlined_to = (cgraph_node *) (intptr_t) ref;
d7f09764 1289
aede2c10
JH
1290 if (group)
1291 {
1292 node->set_comdat_group (group);
1293 /* Store a reference for now, and fix up later to be a pointer. */
1294 node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
1295 }
1296 else
1297 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
f961457f 1298 section = read_string (ib);
24d047a3 1299 if (section)
e257a17c 1300 node->set_section_for_node (section);
b66887e4 1301
ffdcdc0b 1302 if (node->definition)
c47d0034 1303 {
412288f1
DN
1304 int type = streamer_read_uhwi (ib);
1305 HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
1306 HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib);
44662f68 1307 HOST_WIDE_INT indirect_offset = streamer_read_uhwi (ib);
c47d0034 1308
c47d0034 1309 node->thunk.fixed_offset = fixed_offset;
c47d0034 1310 node->thunk.virtual_value = virtual_value;
44662f68
EB
1311 node->thunk.indirect_offset = indirect_offset;
1312 node->thunk.this_adjusting = (type & 2);
c47d0034 1313 node->thunk.virtual_offset_p = (type & 4);
c47d0034 1314 }
67348ccc
DM
1315 if (node->alias && !node->analyzed && node->weakref)
1316 node->alias_target = get_alias_symbol (node->decl);
634ab819 1317 node->profile_id = streamer_read_hwi (ib);
b74d8dc4
JH
1318 node->unit_id = streamer_read_hwi (ib) + file_data->unit_base;
1319 if (symtab->max_unit < node->unit_id)
1320 symtab->max_unit = node->unit_id;
569b1784 1321 if (DECL_STATIC_CONSTRUCTOR (node->decl))
1cff83e2 1322 node->set_init_priority (streamer_read_hwi (ib));
569b1784 1323 if (DECL_STATIC_DESTRUCTOR (node->decl))
1cff83e2 1324 node->set_fini_priority (streamer_read_hwi (ib));
d5e254e1 1325
d7f09764
DN
1326 return node;
1327}
1328
2942c502
JH
1329/* Read a node from input_block IB. TAG is the node's tag just read.
1330 Return the node read or overwriten. */
1331
2c8326a5 1332static varpool_node *
2942c502 1333input_varpool_node (struct lto_file_decl_data *file_data,
99b1c316 1334 class lto_input_block *ib)
2942c502
JH
1335{
1336 int decl_index;
1337 tree var_decl;
2c8326a5 1338 varpool_node *node;
2465dcc2 1339 struct bitpack_d bp;
9f90e80a 1340 int ref = LCC_NOT_FOUND;
398f05da 1341 int order;
aede2c10 1342 tree group;
f961457f 1343 const char *section;
2942c502 1344
3c56d8d8 1345 order = streamer_read_hwi (ib) + file_data->order_base;
412288f1 1346 decl_index = streamer_read_uhwi (ib);
2942c502 1347 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
bbf9ad07
JH
1348
1349 /* Declaration of functions can be already merged with a declaration
1350 from other input file. We keep cgraph unmerged until after streaming
1351 of ipa passes is done. Alays forcingly create a fresh node. */
9041d2e6 1352 node = varpool_node::create_empty ();
67348ccc 1353 node->decl = var_decl;
d52f5295 1354 node->register_symbol ();
bbf9ad07 1355
67348ccc 1356 node->order = order;
3dafb85c
ML
1357 if (order >= symtab->order)
1358 symtab->order = order + 1;
67348ccc 1359 node->lto_file_data = file_data;
2942c502 1360
412288f1 1361 bp = streamer_read_bitpack (ib);
67348ccc 1362 node->externally_visible = bp_unpack_value (&bp, 1);
7861b648 1363 node->no_reorder = bp_unpack_value (&bp, 1);
67348ccc
DM
1364 node->force_output = bp_unpack_value (&bp, 1);
1365 node->forced_by_abi = bp_unpack_value (&bp, 1);
1366 node->unique_name = bp_unpack_value (&bp, 1);
4a5798de 1367 node->body_removed = bp_unpack_value (&bp, 1);
e257a17c 1368 node->implicit_section = bp_unpack_value (&bp, 1);
6de88c6a 1369 node->writeonly = bp_unpack_value (&bp, 1);
67348ccc
DM
1370 node->definition = bp_unpack_value (&bp, 1);
1371 node->alias = bp_unpack_value (&bp, 1);
71e54687 1372 node->transparent_alias = bp_unpack_value (&bp, 1);
67348ccc
DM
1373 node->weakref = bp_unpack_value (&bp, 1);
1374 node->analyzed = bp_unpack_value (&bp, 1);
1375 node->used_from_other_partition = bp_unpack_value (&bp, 1);
1376 node->in_other_partition = bp_unpack_value (&bp, 1);
1377 if (node->in_other_partition)
1c7b11d2 1378 {
67348ccc
DM
1379 DECL_EXTERNAL (node->decl) = 1;
1380 TREE_STATIC (node->decl) = 0;
1c7b11d2 1381 }
67348ccc
DM
1382 if (node->alias && !node->analyzed && node->weakref)
1383 node->alias_target = get_alias_symbol (node->decl);
56363ffd 1384 node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
eb6a09a7 1385 node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
ca280d38 1386 node->dynamically_initialized = bp_unpack_value (&bp, 1);
24d047a3 1387 group = read_identifier (ib);
aede2c10
JH
1388 if (group)
1389 {
1390 node->set_comdat_group (group);
1391 ref = streamer_read_hwi (ib);
1392 /* Store a reference for now, and fix up later to be a pointer. */
1393 node->same_comdat_group = (symtab_node *) (intptr_t) ref;
1394 }
1395 else
1396 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
f961457f 1397 section = read_string (ib);
24d047a3 1398 if (section)
e257a17c 1399 node->set_section_for_node (section);
67348ccc 1400 node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
960bfb69 1401 LDPR_NUM_KNOWN);
b0aba46c 1402 verify_node_partition (node);
2942c502
JH
1403 return node;
1404}
1405
369451ec
JH
1406/* Read a node from input_block IB. TAG is the node's tag just read.
1407 Return the node read or overwriten. */
1408
1409static void
99b1c316 1410input_ref (class lto_input_block *ib,
5e20cdc9
DM
1411 symtab_node *referring_node,
1412 vec<symtab_node *> nodes)
369451ec 1413{
5e20cdc9 1414 symtab_node *node = NULL;
2465dcc2 1415 struct bitpack_d bp;
369451ec 1416 enum ipa_ref_use use;
042ae7d2
JH
1417 bool speculative;
1418 struct ipa_ref *ref;
369451ec 1419
412288f1 1420 bp = streamer_read_bitpack (ib);
d5e254e1 1421 use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
042ae7d2 1422 speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
9771b263 1423 node = nodes[streamer_read_hwi (ib)];
3dafb85c 1424 ref = referring_node->create_reference (node, use);
042ae7d2 1425 ref->speculative = speculative;
7de90a6c 1426 if (is_a <cgraph_node *> (referring_node))
042ae7d2 1427 ref->lto_stmt_uid = streamer_read_hwi (ib);
369451ec 1428}
d7f09764 1429
e33c6cd6
MJ
1430/* Read an edge from IB. NODES points to a vector of previously read nodes for
1431 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1432 edge being read is indirect (in the sense that it has
1433 indirect_unknown_callee set). */
d7f09764
DN
1434
1435static void
99b1c316 1436input_edge (class lto_input_block *ib, vec<symtab_node *> nodes,
e33c6cd6 1437 bool indirect)
d7f09764
DN
1438{
1439 struct cgraph_node *caller, *callee;
1440 struct cgraph_edge *edge;
1441 unsigned int stmt_id;
3995f3a2 1442 profile_count count;
d7f09764 1443 cgraph_inline_failed_t inline_failed;
2465dcc2 1444 struct bitpack_d bp;
5f902d76 1445 int ecf_flags = 0;
d7f09764 1446
d52f5295 1447 caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
67348ccc 1448 if (caller == NULL || caller->decl == NULL_TREE)
d7f09764
DN
1449 internal_error ("bytecode stream: no caller found while reading edge");
1450
e33c6cd6
MJ
1451 if (!indirect)
1452 {
d52f5295 1453 callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
67348ccc 1454 if (callee == NULL || callee->decl == NULL_TREE)
e33c6cd6
MJ
1455 internal_error ("bytecode stream: no callee found while reading edge");
1456 }
1457 else
1458 callee = NULL;
d7f09764 1459
3995f3a2 1460 count = profile_count::stream_in (ib);
d7f09764 1461
412288f1 1462 bp = streamer_read_bitpack (ib);
84562394 1463 inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
533c07c5 1464 stmt_id = bp_unpack_var_len_unsigned (&bp);
d7f09764 1465
e33c6cd6 1466 if (indirect)
1bad9c18 1467 edge = caller->create_indirect_edge (NULL, 0, count);
e33c6cd6 1468 else
1bad9c18 1469 edge = caller->create_edge (callee, NULL, count);
e33c6cd6 1470
2465dcc2 1471 edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
042ae7d2 1472 edge->speculative = bp_unpack_value (&bp, 1);
d7f09764
DN
1473 edge->lto_stmt_uid = stmt_id;
1474 edge->inline_failed = inline_failed;
2465dcc2
RG
1475 edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1476 edge->can_throw_external = bp_unpack_value (&bp, 1);
f9bb202b 1477 edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
5f902d76
JH
1478 if (indirect)
1479 {
2465dcc2 1480 if (bp_unpack_value (&bp, 1))
5f902d76 1481 ecf_flags |= ECF_CONST;
2465dcc2 1482 if (bp_unpack_value (&bp, 1))
5f902d76 1483 ecf_flags |= ECF_PURE;
2465dcc2 1484 if (bp_unpack_value (&bp, 1))
5f902d76 1485 ecf_flags |= ECF_NORETURN;
2465dcc2 1486 if (bp_unpack_value (&bp, 1))
5f902d76 1487 ecf_flags |= ECF_MALLOC;
2465dcc2 1488 if (bp_unpack_value (&bp, 1))
5f902d76 1489 ecf_flags |= ECF_NOTHROW;
2465dcc2 1490 if (bp_unpack_value (&bp, 1))
5f902d76
JH
1491 ecf_flags |= ECF_RETURNS_TWICE;
1492 edge->indirect_info->ecf_flags = ecf_flags;
634ab819
JH
1493 edge->indirect_info->common_target_id = streamer_read_hwi (ib);
1494 if (edge->indirect_info->common_target_id)
1495 edge->indirect_info->common_target_probability = streamer_read_hwi (ib);
5f902d76 1496 }
d7f09764
DN
1497}
1498
1499
1500/* Read a cgraph from IB using the info in FILE_DATA. */
1501
5e20cdc9 1502static vec<symtab_node *>
d7f09764 1503input_cgraph_1 (struct lto_file_decl_data *file_data,
99b1c316 1504 class lto_input_block *ib)
d7f09764 1505{
7380e6ef 1506 enum LTO_symtab_tags tag;
5e20cdc9
DM
1507 vec<symtab_node *> nodes = vNULL;
1508 symtab_node *node;
d7f09764
DN
1509 unsigned i;
1510
7380e6ef 1511 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
3c56d8d8 1512 file_data->order_base = symtab->order;
b74d8dc4 1513 file_data->unit_base = symtab->max_unit + 1;
d7f09764
DN
1514 while (tag)
1515 {
7380e6ef 1516 if (tag == LTO_symtab_edge)
e33c6cd6 1517 input_edge (ib, nodes, false);
7380e6ef 1518 else if (tag == LTO_symtab_indirect_edge)
e33c6cd6 1519 input_edge (ib, nodes, true);
7380e6ef
JH
1520 else if (tag == LTO_symtab_variable)
1521 {
67348ccc 1522 node = input_varpool_node (file_data, ib);
9771b263 1523 nodes.safe_push (node);
7380e6ef
JH
1524 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1525 }
b8698a0f 1526 else
d7f09764 1527 {
67348ccc
DM
1528 node = input_node (file_data, ib, tag, nodes);
1529 if (node == NULL || node->decl == NULL_TREE)
d7f09764 1530 internal_error ("bytecode stream: found empty cgraph node");
9771b263 1531 nodes.safe_push (node);
7380e6ef 1532 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
d7f09764
DN
1533 }
1534
7380e6ef 1535 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
d7f09764
DN
1536 }
1537
3c56d8d8 1538 lto_input_toplevel_asms (file_data, file_data->order_base);
a9cc4458 1539
7380e6ef 1540 /* AUX pointers should be all non-zero for function nodes read from the stream. */
b2b29377
MM
1541 if (flag_checking)
1542 {
1543 FOR_EACH_VEC_ELT (nodes, i, node)
1544 gcc_assert (node->aux || !is_a <cgraph_node *> (node));
1545 }
9771b263 1546 FOR_EACH_VEC_ELT (nodes, i, node)
d7f09764 1547 {
7380e6ef 1548 int ref;
7de90a6c 1549 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
7380e6ef 1550 {
a62bfab5 1551 ref = (int) (intptr_t) cnode->inlined_to;
7380e6ef
JH
1552
1553 /* We share declaration of builtins, so we may read same node twice. */
67348ccc 1554 if (!node->aux)
7380e6ef 1555 continue;
67348ccc 1556 node->aux = NULL;
7380e6ef
JH
1557
1558 /* Fixup inlined_to from reference to pointer. */
1559 if (ref != LCC_NOT_FOUND)
a62bfab5 1560 dyn_cast<cgraph_node *> (node)->inlined_to
d52f5295 1561 = dyn_cast<cgraph_node *> (nodes[ref]);
7380e6ef 1562 else
a62bfab5 1563 cnode->inlined_to = NULL;
7380e6ef 1564 }
b66887e4 1565
67348ccc 1566 ref = (int) (intptr_t) node->same_comdat_group;
b66887e4
JJ
1567
1568 /* Fixup same_comdat_group from reference to pointer. */
1569 if (ref != LCC_NOT_FOUND)
67348ccc 1570 node->same_comdat_group = nodes[ref];
b66887e4 1571 else
67348ccc 1572 node->same_comdat_group = NULL;
d7f09764 1573 }
9771b263 1574 FOR_EACH_VEC_ELT (nodes, i, node)
7de90a6c 1575 node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
2f41ecf5 1576 return nodes;
d7f09764
DN
1577}
1578
369451ec
JH
1579/* Input ipa_refs. */
1580
1581static void
99b1c316 1582input_refs (class lto_input_block *ib,
5e20cdc9 1583 vec<symtab_node *> nodes)
369451ec
JH
1584{
1585 int count;
1586 int idx;
1587 while (true)
1588 {
5e20cdc9 1589 symtab_node *node;
412288f1 1590 count = streamer_read_uhwi (ib);
369451ec
JH
1591 if (!count)
1592 break;
412288f1 1593 idx = streamer_read_uhwi (ib);
9771b263 1594 node = nodes[idx];
369451ec
JH
1595 while (count)
1596 {
f27c1867 1597 input_ref (ib, node, nodes);
369451ec
JH
1598 count--;
1599 }
1600 }
1601}
1602
0bc1b77f
JH
1603/* Input profile_info from IB. */
1604static void
99b1c316 1605input_profile_summary (class lto_input_block *ib,
db0bf14f 1606 struct lto_file_decl_data *file_data)
0bc1b77f 1607{
412288f1 1608 unsigned int runs = streamer_read_uhwi (ib);
0bc1b77f
JH
1609 if (runs)
1610 {
db0bf14f 1611 file_data->profile_info.runs = runs;
512cc015 1612
0208f7da
JH
1613 /* IPA-profile computes hot bb threshold based on cumulated
1614 whole program profile. We need to stream it down to ltrans. */
1615 if (flag_ltrans)
1616 set_hot_bb_threshold (streamer_read_gcov_count (ib));
0bc1b77f
JH
1617 }
1618
1619}
d7f09764 1620
db0bf14f
JH
1621/* Rescale profile summaries to the same number of runs in the whole unit. */
1622
1623static void
1624merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1625{
1626 struct lto_file_decl_data *file_data;
512cc015 1627 unsigned int j;
db0bf14f
JH
1628 gcov_unsigned_t max_runs = 0;
1629 struct cgraph_node *node;
1630 struct cgraph_edge *edge;
1631
1632 /* Find unit with maximal number of runs. If we ever get serious about
1633 roundoff errors, we might also consider computing smallest common
1634 multiply. */
1635 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1636 if (max_runs < file_data->profile_info.runs)
1637 max_runs = file_data->profile_info.runs;
1638
1639 if (!max_runs)
1640 return;
1641
1642 /* Simple overflow check. We probably don't need to support that many train
1643 runs. Such a large value probably imply data corruption anyway. */
1644 if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1645 {
1646 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1647 INT_MAX / REG_BR_PROB_BASE);
1648 return;
1649 }
1650
512cc015
ML
1651 profile_info = XCNEW (gcov_summary);
1652 profile_info->runs = max_runs;
db0bf14f
JH
1653
1654 /* If merging already happent at WPA time, we are done. */
1655 if (flag_ltrans)
1656 return;
1657
1658 /* Now compute count_materialization_scale of each node.
1659 During LTRANS we already have values of count_materialization_scale
1660 computed, so just update them. */
65c70e6b 1661 FOR_EACH_FUNCTION (node)
67348ccc
DM
1662 if (node->lto_file_data
1663 && node->lto_file_data->profile_info.runs)
db0bf14f
JH
1664 {
1665 int scale;
40e584a1 1666
2730ada7 1667 scale = RDIV (node->count_materialization_scale * max_runs,
67348ccc 1668 node->lto_file_data->profile_info.runs);
db0bf14f
JH
1669 node->count_materialization_scale = scale;
1670 if (scale < 0)
40fecdd6 1671 fatal_error (input_location, "Profile information in %s corrupted",
db0bf14f
JH
1672 file_data->file_name);
1673
1674 if (scale == REG_BR_PROB_BASE)
1675 continue;
1676 for (edge = node->callees; edge; edge = edge->next_callee)
1bad9c18
JH
1677 if (edge->count.ipa ().nonzero_p ())
1678 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1679 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
1680 if (edge->count.ipa ().nonzero_p ())
1681 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1682 if (node->count.ipa ().nonzero_p ())
1683 node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE);
db0bf14f
JH
1684 }
1685}
1686
ab96cc5b 1687/* Input and merge the symtab from each of the .o files passed to
d7f09764
DN
1688 lto1. */
1689
1690void
ab96cc5b 1691input_symtab (void)
d7f09764
DN
1692{
1693 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1694 struct lto_file_decl_data *file_data;
1695 unsigned int j = 0;
1696 struct cgraph_node *node;
1697
1698 while ((file_data = file_data_vec[j++]))
1699 {
1700 const char *data;
1701 size_t len;
99b1c316 1702 class lto_input_block *ib;
5e20cdc9 1703 vec<symtab_node *> nodes;
d7f09764 1704
ab96cc5b 1705 ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
d7f09764 1706 &data, &len);
f1e92a43 1707 if (!ib)
40fecdd6
JM
1708 fatal_error (input_location,
1709 "cannot find LTO cgraph in %s", file_data->file_name);
db0bf14f 1710 input_profile_summary (ib, file_data);
e75f8f79 1711 file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
2f41ecf5 1712 nodes = input_cgraph_1 (file_data, ib);
ab96cc5b 1713 lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
d7f09764 1714 ib, data, len);
b8698a0f 1715
369451ec
JH
1716 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1717 &data, &len);
f1e92a43 1718 if (!ib)
40fecdd6 1719 fatal_error (input_location, "cannot find LTO section refs in %s",
c3284718 1720 file_data->file_name);
7380e6ef 1721 input_refs (ib, nodes);
369451ec
JH
1722 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1723 ib, data, len);
922f15c2
JH
1724 if (flag_ltrans)
1725 input_cgraph_opt_summary (nodes);
9771b263 1726 nodes.release ();
b8698a0f 1727 }
beb628e1 1728
db0bf14f 1729 merge_profile_summaries (file_data_vec);
10c9ea62 1730
d7f09764
DN
1731 /* Clear out the aux field that was used to store enough state to
1732 tell which nodes should be overwritten. */
65c70e6b 1733 FOR_EACH_FUNCTION (node)
d7f09764
DN
1734 {
1735 /* Some nodes may have been created by cgraph_node. This
1736 happens when the callgraph contains nested functions. If the
1737 node for the parent function was never emitted to the gimple
1738 file, cgraph_node will create a node for it when setting the
1739 context of the nested function. */
67348ccc
DM
1740 if (node->lto_file_data)
1741 node->aux = NULL;
d7f09764
DN
1742 }
1743}
922f15c2 1744
ec6fe917
IV
1745/* Input function/variable tables that will allow libgomp to look up offload
1746 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1747
1748void
ed5d948d 1749input_offload_tables (bool do_force_output)
ec6fe917
IV
1750{
1751 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1752 struct lto_file_decl_data *file_data;
1753 unsigned int j = 0;
1754
1755 while ((file_data = file_data_vec[j++]))
1756 {
1757 const char *data;
1758 size_t len;
99b1c316 1759 class lto_input_block *ib
ec6fe917
IV
1760 = lto_create_simple_input_block (file_data, LTO_section_offload_table,
1761 &data, &len);
1762 if (!ib)
1763 continue;
1764
1765 enum LTO_symtab_tags tag
1766 = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1767 while (tag)
1768 {
1769 if (tag == LTO_symtab_unavail_node)
1770 {
1771 int decl_index = streamer_read_uhwi (ib);
1772 tree fn_decl
1773 = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1774 vec_safe_push (offload_funcs, fn_decl);
e6d6ec9e
TV
1775
1776 /* Prevent IPA from removing fn_decl as unreachable, since there
1777 may be no refs from the parent function to child_fn in offload
1778 LTO mode. */
ed5d948d
TV
1779 if (do_force_output)
1780 cgraph_node::get (fn_decl)->mark_force_output ();
ec6fe917
IV
1781 }
1782 else if (tag == LTO_symtab_variable)
1783 {
1784 int decl_index = streamer_read_uhwi (ib);
1785 tree var_decl
1786 = lto_file_decl_data_get_var_decl (file_data, decl_index);
1787 vec_safe_push (offload_vars, var_decl);
e6d6ec9e
TV
1788
1789 /* Prevent IPA from removing var_decl as unused, since there
1790 may be no refs to var_decl in offload LTO mode. */
ed5d948d
TV
1791 if (do_force_output)
1792 varpool_node::get (var_decl)->force_output = 1;
ec6fe917
IV
1793 }
1794 else
40fecdd6
JM
1795 fatal_error (input_location,
1796 "invalid offload table in %s", file_data->file_name);
ec6fe917
IV
1797
1798 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1799 }
1800
1801 lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
1802 ib, data, len);
1803 }
1804}
1805
922f15c2
JH
1806/* True when we need optimization summary for NODE. */
1807
1808static int
f27c1867 1809output_cgraph_opt_summary_p (struct cgraph_node *node)
922f15c2 1810{
a50e9b2f 1811 return ((node->clone_of || node->former_clone_of)
644e637f 1812 && (node->clone.tree_map
ff6686d2 1813 || node->clone.param_adjustments));
922f15c2
JH
1814}
1815
ce47fda3
MJ
1816/* Output optimization summary for EDGE to OB. */
1817static void
81fa35bd
MJ
1818output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
1819 struct cgraph_edge *edge ATTRIBUTE_UNUSED)
ce47fda3 1820{
ce47fda3
MJ
1821}
1822
922f15c2
JH
1823/* Output optimization summary for NODE to OB. */
1824
1825static void
1826output_node_opt_summary (struct output_block *ob,
644e637f 1827 struct cgraph_node *node,
f27c1867 1828 lto_symtab_encoder_t encoder)
922f15c2 1829{
922f15c2 1830 struct ipa_replace_map *map;
922f15c2 1831 int i;
ce47fda3 1832 struct cgraph_edge *e;
922f15c2 1833
ff6686d2
MJ
1834 /* TODO: Should this code be moved to ipa-param-manipulation? */
1835 struct bitpack_d bp;
1836 bp = bitpack_create (ob->main_stream);
1837 bp_pack_value (&bp, (node->clone.param_adjustments != NULL), 1);
1838 streamer_write_bitpack (&bp);
1839 if (ipa_param_adjustments *adjustments = node->clone.param_adjustments)
26740835 1840 {
ff6686d2
MJ
1841 streamer_write_uhwi (ob, vec_safe_length (adjustments->m_adj_params));
1842 ipa_adjusted_param *adj;
1843 FOR_EACH_VEC_SAFE_ELT (adjustments->m_adj_params, i, adj)
1844 {
1845 bp = bitpack_create (ob->main_stream);
1846 bp_pack_value (&bp, adj->base_index, IPA_PARAM_MAX_INDEX_BITS);
1847 bp_pack_value (&bp, adj->prev_clone_index, IPA_PARAM_MAX_INDEX_BITS);
1848 bp_pack_value (&bp, adj->op, 2);
1849 bp_pack_value (&bp, adj->param_prefix_index, 2);
1850 bp_pack_value (&bp, adj->prev_clone_adjustment, 1);
1851 bp_pack_value (&bp, adj->reverse, 1);
1852 bp_pack_value (&bp, adj->user_flag, 1);
1853 streamer_write_bitpack (&bp);
1854 if (adj->op == IPA_PARAM_OP_SPLIT
1855 || adj->op == IPA_PARAM_OP_NEW)
1856 {
1857 stream_write_tree (ob, adj->type, true);
1858 if (adj->op == IPA_PARAM_OP_SPLIT)
1859 {
1860 stream_write_tree (ob, adj->alias_ptr_type, true);
1861 streamer_write_uhwi (ob, adj->unit_offset);
1862 }
1863 }
1864 }
1865 streamer_write_hwi (ob, adjustments->m_always_copy_start);
1866 bp = bitpack_create (ob->main_stream);
1867 bp_pack_value (&bp, node->clone.param_adjustments->m_skip_return, 1);
1868 streamer_write_bitpack (&bp);
26740835 1869 }
ff6686d2 1870
9771b263
DN
1871 streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map));
1872 FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map)
922f15c2 1873 {
49bde175 1874 streamer_write_uhwi (ob, map->parm_num);
2f13f2de 1875 gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
b9393656 1876 stream_write_tree (ob, map->new_tree, true);
922f15c2 1877 }
644e637f 1878
67348ccc 1879 if (lto_symtab_encoder_in_partition_p (encoder, node))
644e637f
MJ
1880 {
1881 for (e = node->callees; e; e = e->next_callee)
1882 output_edge_opt_summary (ob, e);
1883 for (e = node->indirect_calls; e; e = e->next_callee)
1884 output_edge_opt_summary (ob, e);
1885 }
922f15c2
JH
1886}
1887
1888/* Output optimization summaries stored in callgraph.
1889 At the moment it is the clone info structure. */
1890
1891static void
f27c1867 1892output_cgraph_opt_summary (void)
922f15c2 1893{
922f15c2 1894 int i, n_nodes;
7380e6ef 1895 lto_symtab_encoder_t encoder;
922f15c2
JH
1896 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
1897 unsigned count = 0;
1898
0b83e688 1899 ob->symbol = NULL;
7380e6ef
JH
1900 encoder = ob->decl_state->symtab_node_encoder;
1901 n_nodes = lto_symtab_encoder_size (encoder);
922f15c2 1902 for (i = 0; i < n_nodes; i++)
5d59b5e1 1903 {
5e20cdc9 1904 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
7de90a6c 1905 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
5d59b5e1
LC
1906 if (cnode && output_cgraph_opt_summary_p (cnode))
1907 count++;
1908 }
412288f1 1909 streamer_write_uhwi (ob, count);
922f15c2
JH
1910 for (i = 0; i < n_nodes; i++)
1911 {
5e20cdc9 1912 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
7de90a6c 1913 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
5d59b5e1 1914 if (cnode && output_cgraph_opt_summary_p (cnode))
922f15c2 1915 {
412288f1 1916 streamer_write_uhwi (ob, i);
5d59b5e1 1917 output_node_opt_summary (ob, cnode, encoder);
922f15c2
JH
1918 }
1919 }
1920 produce_asm (ob, NULL);
1921 destroy_output_block (ob);
1922}
1923
ce47fda3
MJ
1924/* Input optimisation summary of EDGE. */
1925
1926static void
81fa35bd 1927input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
99b1c316 1928 class lto_input_block *ib_main ATTRIBUTE_UNUSED)
ce47fda3 1929{
ce47fda3
MJ
1930}
1931
1932/* Input optimisation summary of NODE. */
922f15c2
JH
1933
1934static void
1935input_node_opt_summary (struct cgraph_node *node,
99b1c316
MS
1936 class lto_input_block *ib_main,
1937 class data_in *data_in)
922f15c2
JH
1938{
1939 int i;
1940 int count;
ce47fda3 1941 struct cgraph_edge *e;
922f15c2 1942
ff6686d2
MJ
1943 /* TODO: Should this code be moved to ipa-param-manipulation? */
1944 struct bitpack_d bp;
1945 bp = streamer_read_bitpack (ib_main);
1946 bool have_adjustments = bp_unpack_value (&bp, 1);
1947 if (have_adjustments)
922f15c2 1948 {
ff6686d2
MJ
1949 count = streamer_read_uhwi (ib_main);
1950 vec<ipa_adjusted_param, va_gc> *new_params = NULL;
1951 for (i = 0; i < count; i++)
1952 {
1953 ipa_adjusted_param adj;
1954 memset (&adj, 0, sizeof (adj));
1955 bp = streamer_read_bitpack (ib_main);
1956 adj.base_index = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
1957 adj.prev_clone_index
1958 = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
1959 adj.op = (enum ipa_parm_op) bp_unpack_value (&bp, 2);
1960 adj.param_prefix_index = bp_unpack_value (&bp, 2);
1961 adj.prev_clone_adjustment = bp_unpack_value (&bp, 1);
1962 adj.reverse = bp_unpack_value (&bp, 1);
1963 adj.user_flag = bp_unpack_value (&bp, 1);
1964 if (adj.op == IPA_PARAM_OP_SPLIT
1965 || adj.op == IPA_PARAM_OP_NEW)
1966 {
1967 adj.type = stream_read_tree (ib_main, data_in);
1968 if (adj.op == IPA_PARAM_OP_SPLIT)
1969 {
1970 adj.alias_ptr_type = stream_read_tree (ib_main, data_in);
1971 adj.unit_offset = streamer_read_uhwi (ib_main);
1972 }
1973 }
1974 vec_safe_push (new_params, adj);
1975 }
1976 int always_copy_start = streamer_read_hwi (ib_main);
1977 bp = streamer_read_bitpack (ib_main);
1978 bool skip_return = bp_unpack_value (&bp, 1);
1979 node->clone.param_adjustments
1980 = (new (ggc_alloc <ipa_param_adjustments> ())
1981 ipa_param_adjustments (new_params, always_copy_start, skip_return));
922f15c2 1982 }
ff6686d2 1983
412288f1 1984 count = streamer_read_uhwi (ib_main);
922f15c2
JH
1985 for (i = 0; i < count; i++)
1986 {
766090c2 1987 struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
922f15c2 1988
9771b263 1989 vec_safe_push (node->clone.tree_map, map);
412288f1 1990 map->parm_num = streamer_read_uhwi (ib_main);
b9393656 1991 map->new_tree = stream_read_tree (ib_main, data_in);
922f15c2 1992 }
ce47fda3
MJ
1993 for (e = node->callees; e; e = e->next_callee)
1994 input_edge_opt_summary (e, ib_main);
1995 for (e = node->indirect_calls; e; e = e->next_callee)
1996 input_edge_opt_summary (e, ib_main);
922f15c2
JH
1997}
1998
1999/* Read section in file FILE_DATA of length LEN with data DATA. */
2000
2001static void
2002input_cgraph_opt_section (struct lto_file_decl_data *file_data,
9771b263 2003 const char *data, size_t len,
5e20cdc9 2004 vec<symtab_node *> nodes)
922f15c2
JH
2005{
2006 const struct lto_function_header *header =
2007 (const struct lto_function_header *) data;
4ad9a9de
EB
2008 const int cfg_offset = sizeof (struct lto_function_header);
2009 const int main_offset = cfg_offset + header->cfg_size;
2010 const int string_offset = main_offset + header->main_size;
99b1c316 2011 class data_in *data_in;
922f15c2
JH
2012 unsigned int i;
2013 unsigned int count;
2014
207c68cd 2015 lto_input_block ib_main ((const char *) data + main_offset,
db847fa8 2016 header->main_size, file_data->mode_table);
922f15c2
JH
2017
2018 data_in =
2019 lto_data_in_create (file_data, (const char *) data + string_offset,
6e1aa848 2020 header->string_size, vNULL);
412288f1 2021 count = streamer_read_uhwi (&ib_main);
922f15c2
JH
2022
2023 for (i = 0; i < count; i++)
2024 {
412288f1 2025 int ref = streamer_read_uhwi (&ib_main);
d52f5295 2026 input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
922f15c2
JH
2027 &ib_main, data_in);
2028 }
839d549b 2029 lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
922f15c2
JH
2030 len);
2031 lto_data_in_delete (data_in);
2032}
2033
2034/* Input optimization summary of cgraph. */
2035
2036static void
5e20cdc9 2037input_cgraph_opt_summary (vec<symtab_node *> nodes)
922f15c2
JH
2038{
2039 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2040 struct lto_file_decl_data *file_data;
2041 unsigned int j = 0;
2042
2043 while ((file_data = file_data_vec[j++]))
2044 {
2045 size_t len;
3c56d8d8
ML
2046 const char *data
2047 = lto_get_summary_section_data (file_data, LTO_section_cgraph_opt_sum,
2048 &len);
922f15c2
JH
2049 if (data)
2050 input_cgraph_opt_section (file_data, data, len, nodes);
2051 }
2052}