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