]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/lto-cgraph.c
This patch rewrites the old VEC macro-based interface into a new one
[thirdparty/gcc.git] / gcc / lto-cgraph.c
CommitLineData
7bfefa9d 1/* Write and read the cgraph to the memory mapped representation of a
2 .o file.
3
b6a800c7 4 Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
7bfefa9d 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"
26#include "tm.h"
7bfefa9d 27#include "tree.h"
28#include "expr.h"
29#include "flags.h"
30#include "params.h"
31#include "input.h"
7bfefa9d 32#include "hashtab.h"
33#include "langhooks.h"
34#include "basic-block.h"
35#include "tree-flow.h"
36#include "cgraph.h"
37#include "function.h"
38#include "ggc.h"
852f689e 39#include "diagnostic-core.h"
7bfefa9d 40#include "except.h"
41#include "vec.h"
42#include "timevar.h"
7bfefa9d 43#include "pointer-set.h"
44#include "lto-streamer.h"
2541503d 45#include "data-streamer.h"
46#include "tree-streamer.h"
6c0782b1 47#include "gcov-io.h"
b9e2d290 48#include "tree-pass.h"
7bfefa9d 49
eab36a5a 50static void output_cgraph_opt_summary (void);
f1f41a6c 51static void input_cgraph_opt_summary (vec<symtab_node> nodes);
1bf41320 52
7857a7b7 53/* Number of LDPR values known to GCC. */
da722561 54#define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
a238367f 55
f1007c72 56/* All node orders are ofsetted by ORDER_BASE. */
57static int order_base;
58
b7e3aeb1 59/* Cgraph streaming is organized as set of record whose type
60 is indicated by a tag. */
70225339 61enum LTO_symtab_tags
b7e3aeb1 62{
63 /* Must leave 0 for the stopper. */
64
65 /* Cgraph node without body available. */
70225339 66 LTO_symtab_unavail_node = 1,
b7e3aeb1 67 /* Cgraph node with function body. */
70225339 68 LTO_symtab_analyzed_node,
b7e3aeb1 69 /* Cgraph edges. */
70225339 70 LTO_symtab_edge,
71 LTO_symtab_indirect_edge,
72 LTO_symtab_variable,
73 LTO_symtab_last_tag
b7e3aeb1 74};
75
b8925abd 76/* Create a new symtab encoder.
77 if FOR_INPUT, the encoder allocate only datastructures needed
78 to read the symtab. */
7bfefa9d 79
70225339 80lto_symtab_encoder_t
b8925abd 81lto_symtab_encoder_new (bool for_input)
7bfefa9d 82{
70225339 83 lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
b8925abd 84
85 if (!for_input)
86 encoder->map = pointer_map_create ();
f1f41a6c 87 encoder->nodes.create (0);
7bfefa9d 88 return encoder;
89}
90
91
92/* Delete ENCODER and its components. */
93
94void
70225339 95lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
7bfefa9d 96{
f1f41a6c 97 encoder->nodes.release ();
b8925abd 98 if (encoder->map)
99 pointer_map_destroy (encoder->map);
7bfefa9d 100 free (encoder);
101}
102
103
70225339 104/* Return the existing reference number of NODE in the symtab encoder in
7bfefa9d 105 output block OB. Assign a new reference if this is the first time
106 NODE is encoded. */
107
108int
70225339 109lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
110 symtab_node node)
7bfefa9d 111{
112 int ref;
113 void **slot;
48e1416a 114
b8925abd 115 if (!encoder->map)
116 {
117 lto_encoder_entry entry = {node, false, false, false};
118
f1f41a6c 119 ref = encoder->nodes.length ();
120 encoder->nodes.safe_push (entry);
b8925abd 121 return ref;
122 }
123
7bfefa9d 124 slot = pointer_map_contains (encoder->map, node);
5cf7e051 125 if (!slot || !*slot)
7bfefa9d 126 {
5cf7e051 127 lto_encoder_entry entry = {node, false, false, false};
f1f41a6c 128 ref = encoder->nodes.length ();
5cf7e051 129 if (!slot)
130 slot = pointer_map_insert (encoder->map, node);
131 *slot = (void *) (intptr_t) (ref + 1);
f1f41a6c 132 encoder->nodes.safe_push (entry);
7bfefa9d 133 }
134 else
5cf7e051 135 ref = (size_t) *slot - 1;
7bfefa9d 136
137 return ref;
138}
139
5cf7e051 140/* Remove NODE from encoder. */
7bfefa9d 141
5cf7e051 142bool
143lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
144 symtab_node node)
7bfefa9d 145{
5cf7e051 146 void **slot, **last_slot;
147 int index;
148 lto_encoder_entry last_node;
149
150 slot = pointer_map_contains (encoder->map, node);
151 if (slot == NULL || !*slot)
152 return false;
153
154 index = (size_t) *slot - 1;
f1f41a6c 155 gcc_checking_assert (encoder->nodes[index].node == node);
5cf7e051 156
157 /* Remove from vector. We do this by swapping node with the last element
158 of the vector. */
f1f41a6c 159 last_node = encoder->nodes.pop ();
5cf7e051 160 if (last_node.node != node)
161 {
162 last_slot = pointer_map_contains (encoder->map, last_node.node);
163 gcc_checking_assert (last_slot && *last_slot);
164 *last_slot = (void *)(size_t) (index + 1);
165
166 /* Move the last element to the original spot of NODE. */
f1f41a6c 167 encoder->nodes[index] = last_node;
5cf7e051 168 }
169
170 /* Remove element from hash table. */
171 *slot = NULL;
172 return true;
7bfefa9d 173}
174
175
02b2818c 176/* Return TRUE if we should encode initializer of NODE (if any). */
7bfefa9d 177
02b2818c 178bool
70225339 179lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
02b2818c 180 struct cgraph_node *node)
181{
5cf7e051 182 int index = lto_symtab_encoder_lookup (encoder, (symtab_node)node);
f1f41a6c 183 return encoder->nodes[index].body;
02b2818c 184}
185
186/* Return TRUE if we should encode body of NODE (if any). */
187
188static void
70225339 189lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder,
02b2818c 190 struct cgraph_node *node)
7bfefa9d 191{
5cf7e051 192 int index = lto_symtab_encoder_encode (encoder, (symtab_node)node);
f1f41a6c 193 gcc_checking_assert (encoder->nodes[index].node == (symtab_node)node);
194 encoder->nodes[index].body = true;
7bfefa9d 195}
196
a238367f 197/* Return TRUE if we should encode initializer of NODE (if any). */
198
199bool
70225339 200lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
201 struct varpool_node *node)
a238367f 202{
5cf7e051 203 int index = lto_symtab_encoder_lookup (encoder, (symtab_node)node);
204 if (index == LCC_NOT_FOUND)
205 return false;
f1f41a6c 206 return encoder->nodes[index].initializer;
a238367f 207}
208
209/* Return TRUE if we should encode initializer of NODE (if any). */
210
211static void
70225339 212lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
213 struct varpool_node *node)
a238367f 214{
5cf7e051 215 int index = lto_symtab_encoder_lookup (encoder, (symtab_node)node);
f1f41a6c 216 encoder->nodes[index].initializer = true;
a238367f 217}
7bfefa9d 218
eab36a5a 219/* Return TRUE if we should encode initializer of NODE (if any). */
220
221bool
222lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
223 symtab_node node)
224{
5cf7e051 225 int index = lto_symtab_encoder_lookup (encoder, (symtab_node)node);
226 if (index == LCC_NOT_FOUND)
227 return false;
f1f41a6c 228 return encoder->nodes[index].in_partition;
eab36a5a 229}
230
231/* Return TRUE if we should encode body of NODE (if any). */
232
233void
234lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
235 symtab_node node)
236{
5cf7e051 237 int index = lto_symtab_encoder_encode (encoder, (symtab_node)node);
f1f41a6c 238 encoder->nodes[index].in_partition = true;
eab36a5a 239}
240
7bfefa9d 241/* Output the cgraph EDGE to OB using ENCODER. */
242
243static void
244lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
70225339 245 lto_symtab_encoder_t encoder)
7bfefa9d 246{
247 unsigned int uid;
248 intptr_t ref;
30baba90 249 struct bitpack_d bp;
7bfefa9d 250
799c8711 251 if (edge->indirect_unknown_callee)
70225339 252 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
253 LTO_symtab_indirect_edge);
799c8711 254 else
70225339 255 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
256 LTO_symtab_edge);
7bfefa9d 257
70225339 258 ref = lto_symtab_encoder_lookup (encoder, (symtab_node)edge->caller);
48e1416a 259 gcc_assert (ref != LCC_NOT_FOUND);
7f385784 260 streamer_write_hwi_stream (ob->main_stream, ref);
7bfefa9d 261
799c8711 262 if (!edge->indirect_unknown_callee)
263 {
70225339 264 ref = lto_symtab_encoder_lookup (encoder, (symtab_node)edge->callee);
799c8711 265 gcc_assert (ref != LCC_NOT_FOUND);
7f385784 266 streamer_write_hwi_stream (ob->main_stream, ref);
799c8711 267 }
7bfefa9d 268
7f385784 269 streamer_write_hwi_stream (ob->main_stream, edge->count);
7bfefa9d 270
30baba90 271 bp = bitpack_create (ob->main_stream);
7d0d0ce1 272 uid = (!gimple_has_body_p (edge->caller->symbol.decl)
c5cc4842 273 ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt));
7857a7b7 274 bp_pack_enum (&bp, cgraph_inline_failed_enum,
275 CIF_N_REASONS, edge->inline_failed);
276 bp_pack_var_len_unsigned (&bp, uid);
277 bp_pack_var_len_unsigned (&bp, edge->frequency);
30baba90 278 bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
279 bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
280 bp_pack_value (&bp, edge->can_throw_external, 1);
f8b7e3ec 281 if (edge->indirect_unknown_callee)
282 {
283 int flags = edge->indirect_info->ecf_flags;
30baba90 284 bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
285 bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
286 bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
287 bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
288 bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
289 bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
f8b7e3ec 290 /* Flags that should not appear on indirect calls. */
291 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
292 | ECF_MAY_BE_ALLOCA
293 | ECF_SIBCALL
c470c5a9 294 | ECF_LEAF
f8b7e3ec 295 | ECF_NOVOPS)));
296 }
7f385784 297 streamer_write_bitpack (&bp);
7bfefa9d 298}
299
8d810329 300/* Return if LIST contain references from other partitions. */
d97be713 301
8d810329 302bool
eab36a5a 303referenced_from_other_partition_p (struct ipa_ref_list *list, lto_symtab_encoder_t encoder)
8d810329 304{
305 int i;
306 struct ipa_ref *ref;
04ec15fa 307 for (i = 0; ipa_ref_list_referring_iterate (list, i, ref); i++)
8d810329 308 {
eab36a5a 309 if (ref->referring->symbol.in_other_partition
310 || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
311 return true;
8d810329 312 }
313 return false;
314}
315
08843223 316/* Return true when node is reachable from other partition. */
317
25429dc2 318bool
eab36a5a 319reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
08843223 320{
321 struct cgraph_edge *e;
08843223 322 if (!node->analyzed)
323 return false;
324 if (node->global.inlined_to)
325 return false;
326 for (e = node->callers; e; e = e->next_caller)
7d0d0ce1 327 if (e->caller->symbol.in_other_partition
eab36a5a 328 || !lto_symtab_encoder_in_partition_p (encoder, (symtab_node)e->caller))
08843223 329 return true;
330 return false;
331}
7bfefa9d 332
d97be713 333/* Return if LIST contain references from other partitions. */
334
335bool
eab36a5a 336referenced_from_this_partition_p (struct ipa_ref_list *list,
337 lto_symtab_encoder_t encoder)
d97be713 338{
339 int i;
340 struct ipa_ref *ref;
04ec15fa 341 for (i = 0; ipa_ref_list_referring_iterate (list, i, ref); i++)
eab36a5a 342 if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
343 return true;
d97be713 344 return false;
345}
346
347/* Return true when node is reachable from other partition. */
348
349bool
eab36a5a 350reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
d97be713 351{
352 struct cgraph_edge *e;
d97be713 353 for (e = node->callers; e; e = e->next_caller)
eab36a5a 354 if (lto_symtab_encoder_in_partition_p (encoder, (symtab_node)e->caller))
d97be713 355 return true;
356 return false;
357}
358
7bfefa9d 359/* Output the cgraph NODE to OB. ENCODER is used to find the
360 reference number of NODE->inlined_to. SET is the set of nodes we
361 are writing to the current file. If NODE is not in SET, then NODE
362 is a boundary of a cgraph_node_set and we pretend NODE just has a
363 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
364 that have had their callgraph node written so far. This is used to
365 determine if NODE is a clone of a previously written node. */
366
367static void
368lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
eab36a5a 369 lto_symtab_encoder_t encoder)
7bfefa9d 370{
371 unsigned int tag;
30baba90 372 struct bitpack_d bp;
02b2818c 373 bool boundary_p;
7bfefa9d 374 intptr_t ref;
08843223 375 bool in_other_partition = false;
02b2818c 376 struct cgraph_node *clone_of;
b9e2d290 377 struct ipa_opt_pass_d *pass;
378 int i;
7bfefa9d 379
eab36a5a 380 boundary_p = !lto_symtab_encoder_in_partition_p (encoder, (symtab_node)node);
7bfefa9d 381
b7e3aeb1 382 if (node->analyzed && !boundary_p)
70225339 383 tag = LTO_symtab_analyzed_node;
b7e3aeb1 384 else
70225339 385 tag = LTO_symtab_unavail_node;
7bfefa9d 386
70225339 387 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
7f385784 388 tag);
7d0d0ce1 389 streamer_write_hwi_stream (ob->main_stream, node->symbol.order);
7bfefa9d 390
7bfefa9d 391 /* In WPA mode, we only output part of the call-graph. Also, we
392 fake cgraph node attributes. There are two cases that we care.
393
394 Boundary nodes: There are nodes that are not part of SET but are
395 called from within SET. We artificially make them look like
48e1416a 396 externally visible nodes with no function body.
7bfefa9d 397
398 Cherry-picked nodes: These are nodes we pulled from other
399 translation units into SET during IPA-inlining. We make them as
400 local static nodes to prevent clashes with other local statics. */
aa419a52 401 if (boundary_p && node->analyzed && !DECL_EXTERNAL (node->symbol.decl))
7bfefa9d 402 {
08843223 403 /* Inline clones can not be part of boundary.
404 gcc_assert (!node->global.inlined_to);
405
406 FIXME: At the moment they can be, when partition contains an inline
407 clone that is clone of inline clone from outside partition. We can
408 reshape the clone tree and make other tree to be the root, but it
409 needs a bit extra work and will be promplty done by cgraph_remove_node
410 after reading back. */
411 in_other_partition = 1;
7bfefa9d 412 }
7bfefa9d 413
02b2818c 414 clone_of = node->clone_of;
415 while (clone_of
70225339 416 && (ref = lto_symtab_encoder_lookup (encoder, (symtab_node)clone_of)) == LCC_NOT_FOUND)
02b2818c 417 if (clone_of->prev_sibling_clone)
418 clone_of = clone_of->prev_sibling_clone;
419 else
420 clone_of = clone_of->clone_of;
083e227a 421
70225339 422 if (LTO_symtab_analyzed_node)
083e227a 423 gcc_assert (clone_of || !node->clone_of);
02b2818c 424 if (!clone_of)
7f385784 425 streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
02b2818c 426 else
7f385784 427 streamer_write_hwi_stream (ob->main_stream, ref);
7bfefa9d 428
7bfefa9d 429
7d0d0ce1 430 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->symbol.decl);
7f385784 431 streamer_write_hwi_stream (ob->main_stream, node->count);
432 streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
7bfefa9d 433
b9e2d290 434 streamer_write_hwi_stream (ob->main_stream,
f1f41a6c 435 node->ipa_transforms_to_apply.length ());
436 FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
b9e2d290 437 streamer_write_hwi_stream (ob->main_stream, pass->pass.static_pass_number);
438
70225339 439 if (tag == LTO_symtab_analyzed_node)
7bfefa9d 440 {
b7e3aeb1 441 if (node->global.inlined_to)
442 {
70225339 443 ref = lto_symtab_encoder_lookup (encoder, (symtab_node)node->global.inlined_to);
b7e3aeb1 444 gcc_assert (ref != LCC_NOT_FOUND);
445 }
446 else
447 ref = LCC_NOT_FOUND;
7bfefa9d 448
7f385784 449 streamer_write_hwi_stream (ob->main_stream, ref);
7bfefa9d 450 }
7bfefa9d 451
7d0d0ce1 452 if (node->symbol.same_comdat_group && !boundary_p)
61c2c7b1 453 {
70225339 454 ref = lto_symtab_encoder_lookup (encoder,
455 node->symbol.same_comdat_group);
61c2c7b1 456 gcc_assert (ref != LCC_NOT_FOUND);
457 }
458 else
459 ref = LCC_NOT_FOUND;
7f385784 460 streamer_write_hwi_stream (ob->main_stream, ref);
61c2c7b1 461
30baba90 462 bp = bitpack_create (ob->main_stream);
463 bp_pack_value (&bp, node->local.local, 1);
7d0d0ce1 464 bp_pack_value (&bp, node->symbol.externally_visible, 1);
30baba90 465 bp_pack_value (&bp, node->local.finalized, 1);
c8d92fc1 466 bp_pack_value (&bp, node->local.versionable, 1);
3c97c75d 467 bp_pack_value (&bp, node->local.can_change_signature, 1);
30baba90 468 bp_pack_value (&bp, node->local.redefined_extern_inline, 1);
8efa224a 469 bp_pack_value (&bp, node->symbol.force_output, 1);
7d0d0ce1 470 bp_pack_value (&bp, node->symbol.address_taken, 1);
30baba90 471 bp_pack_value (&bp, node->abstract_and_needed, 1);
70225339 472 bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
7d0d0ce1 473 && !DECL_EXTERNAL (node->symbol.decl)
474 && !DECL_COMDAT (node->symbol.decl)
eab36a5a 475 && (reachable_from_other_partition_p (node, encoder)
7d0d0ce1 476 || referenced_from_other_partition_p (&node->symbol.ref_list,
eab36a5a 477 encoder)), 1);
30baba90 478 bp_pack_value (&bp, node->lowered, 1);
479 bp_pack_value (&bp, in_other_partition, 1);
badeded8 480 /* Real aliases in a boundary become non-aliases. However we still stream
481 alias info on weakrefs.
482 TODO: We lose a bit of information here - when we know that variable is
483 defined in other unit, we may use the info on aliases to resolve
484 symbol1 != symbol2 type tests that we can do only for locally defined objects
485 otherwise. */
7d0d0ce1 486 bp_pack_value (&bp, node->alias && (!boundary_p || DECL_EXTERNAL (node->symbol.decl)), 1);
30baba90 487 bp_pack_value (&bp, node->frequency, 2);
0f9fb931 488 bp_pack_value (&bp, node->only_called_at_startup, 1);
489 bp_pack_value (&bp, node->only_called_at_exit, 1);
ea0e88d1 490 bp_pack_value (&bp, node->tm_clone, 1);
91bf9d9a 491 bp_pack_value (&bp, node->thunk.thunk_p && !boundary_p, 1);
7857a7b7 492 bp_pack_enum (&bp, ld_plugin_symbol_resolution,
7d0d0ce1 493 LDPR_NUM_KNOWN, node->symbol.resolution);
7f385784 494 streamer_write_bitpack (&bp);
30baba90 495
91bf9d9a 496 if (node->thunk.thunk_p && !boundary_p)
497 {
7f385784 498 streamer_write_uhwi_stream
91bf9d9a 499 (ob->main_stream,
500 1 + (node->thunk.this_adjusting != 0) * 2
501 + (node->thunk.virtual_offset_p != 0) * 4);
7f385784 502 streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset);
503 streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value);
91bf9d9a 504 }
badeded8 505 if ((node->alias || node->thunk.thunk_p)
7d0d0ce1 506 && (!boundary_p || (node->alias && DECL_EXTERNAL (node->symbol.decl))))
ed772161 507 {
7f385784 508 streamer_write_hwi_in_range (ob->main_stream, 0, 1,
509 node->thunk.alias != NULL);
c70f46b0 510 if (node->thunk.alias != NULL)
511 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
512 node->thunk.alias);
ed772161 513 }
7bfefa9d 514}
515
0cddb138 516/* Output the varpool NODE to OB.
517 If NODE is not in SET, then NODE is a boundary. */
518
519static void
520lto_output_varpool_node (struct lto_simple_output_block *ob, struct varpool_node *node,
eab36a5a 521 lto_symtab_encoder_t encoder)
0cddb138 522{
eab36a5a 523 bool boundary_p = (node->analyzed
524 && !lto_symtab_encoder_in_partition_p (encoder, (symtab_node)node));
30baba90 525 struct bitpack_d bp;
933b10c6 526 int ref;
0cddb138 527
70225339 528 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
529 LTO_symtab_variable);
7d0d0ce1 530 streamer_write_hwi_stream (ob->main_stream, node->symbol.order);
531 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->symbol.decl);
30baba90 532 bp = bitpack_create (ob->main_stream);
7d0d0ce1 533 bp_pack_value (&bp, node->symbol.externally_visible, 1);
8efa224a 534 bp_pack_value (&bp, node->symbol.force_output, 1);
30baba90 535 bp_pack_value (&bp, node->finalized, 1);
536 bp_pack_value (&bp, node->alias, 1);
e0eaac80 537 bp_pack_value (&bp, node->alias_of != NULL, 1);
0cddb138 538 gcc_assert (node->finalized || !node->analyzed);
da67d826 539 /* Constant pool initializers can be de-unified into individual ltrans units.
540 FIXME: Alternatively at -Os we may want to avoid generating for them the local
541 labels and share them across LTRANS partitions. */
7d0d0ce1 542 if (DECL_IN_CONSTANT_POOL (node->symbol.decl)
aa419a52 543 && !DECL_EXTERNAL (node->symbol.decl)
7d0d0ce1 544 && !DECL_COMDAT (node->symbol.decl))
da67d826 545 {
30baba90 546 bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */
547 bp_pack_value (&bp, 0, 1); /* in_other_partition. */
da67d826 548 }
549 else
550 {
30baba90 551 bp_pack_value (&bp, node->analyzed
7d0d0ce1 552 && referenced_from_other_partition_p (&node->symbol.ref_list,
eab36a5a 553 encoder), 1);
aa419a52 554 bp_pack_value (&bp, boundary_p && !DECL_EXTERNAL (node->symbol.decl), 1);
555 /* in_other_partition. */
da67d826 556 }
7f385784 557 streamer_write_bitpack (&bp);
e0eaac80 558 if (node->alias_of)
559 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->alias_of);
7d0d0ce1 560 if (node->symbol.same_comdat_group && !boundary_p)
933b10c6 561 {
70225339 562 ref = lto_symtab_encoder_lookup (encoder,
563 node->symbol.same_comdat_group);
933b10c6 564 gcc_assert (ref != LCC_NOT_FOUND);
565 }
566 else
567 ref = LCC_NOT_FOUND;
7f385784 568 streamer_write_hwi_stream (ob->main_stream, ref);
569 streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
7d0d0ce1 570 LDPR_NUM_KNOWN, node->symbol.resolution);
0cddb138 571}
572
8d810329 573/* Output the varpool NODE to OB.
574 If NODE is not in SET, then NODE is a boundary. */
575
576static void
577lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
70225339 578 lto_symtab_encoder_t encoder)
8d810329 579{
30baba90 580 struct bitpack_d bp;
70225339 581 int nref;
582
30baba90 583 bp = bitpack_create (ob->main_stream);
30baba90 584 bp_pack_value (&bp, ref->use, 2);
7f385784 585 streamer_write_bitpack (&bp);
70225339 586 nref = lto_symtab_encoder_lookup (encoder, ref->referred);
587 gcc_assert (nref != LCC_NOT_FOUND);
588 streamer_write_hwi_stream (ob->main_stream, nref);
8d810329 589}
590
6c0782b1 591/* Stream out profile_summary to OB. */
592
593static void
594output_profile_summary (struct lto_simple_output_block *ob)
595{
596 if (profile_info)
597 {
c470c5a9 598 /* We do not output num, sum_all and run_max, they are not used by
599 GCC profile feedback and they are difficult to merge from multiple
600 units. */
6c0782b1 601 gcc_assert (profile_info->runs);
7f385784 602 streamer_write_uhwi_stream (ob->main_stream, profile_info->runs);
603 streamer_write_uhwi_stream (ob->main_stream, profile_info->sum_max);
6c0782b1 604 }
605 else
7f385784 606 streamer_write_uhwi_stream (ob->main_stream, 0);
6c0782b1 607}
608
799c8711 609/* Output all callees or indirect outgoing edges. EDGE must be the first such
610 edge. */
611
612static void
613output_outgoing_cgraph_edges (struct cgraph_edge *edge,
614 struct lto_simple_output_block *ob,
70225339 615 lto_symtab_encoder_t encoder)
799c8711 616{
617 if (!edge)
618 return;
619
620 /* Output edges in backward direction, so the reconstructed callgraph match
621 and it is easy to associate call sites in the IPA pass summaries. */
622 while (edge->next_callee)
623 edge = edge->next_callee;
624 for (; edge; edge = edge->prev_callee)
625 lto_output_edge (ob, edge, encoder);
626}
627
8d810329 628/* Output the part of the cgraph in SET. */
629
630static void
eab36a5a 631output_refs (lto_symtab_encoder_t encoder)
8d810329 632{
eab36a5a 633 lto_symtab_encoder_iterator lsei;
8d810329 634 struct lto_simple_output_block *ob;
635 int count;
636 struct ipa_ref *ref;
637 int i;
638
639 ob = lto_create_simple_output_block (LTO_section_refs);
640
eab36a5a 641 for (lsei = lsei_start_in_partition (encoder); !lsei_end_p (lsei);
642 lsei_next_in_partition (&lsei))
8d810329 643 {
eab36a5a 644 symtab_node node = lsei_node (lsei);
8d810329 645
7d0d0ce1 646 count = ipa_ref_list_nreferences (&node->symbol.ref_list);
8d810329 647 if (count)
648 {
7f385784 649 streamer_write_uhwi_stream (ob->main_stream, count);
650 streamer_write_uhwi_stream (ob->main_stream,
eab36a5a 651 lto_symtab_encoder_lookup (encoder, node));
7d0d0ce1 652 for (i = 0; ipa_ref_list_reference_iterate (&node->symbol.ref_list,
653 i, ref); i++)
70225339 654 lto_output_ref (ob, ref, encoder);
8d810329 655 }
656 }
657
7f385784 658 streamer_write_uhwi_stream (ob->main_stream, 0);
8d810329 659
660 lto_destroy_simple_output_block (ob);
661}
662
724462b0 663/* Add NODE into encoder as well as nodes it is cloned from.
664 Do it in a way so clones appear first. */
665
666static void
667add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
668 bool include_body)
669{
670 if (node->clone_of)
671 add_node_to (encoder, node->clone_of, include_body);
672 else if (include_body)
673 lto_set_symtab_encoder_encode_body (encoder, node);
674 lto_symtab_encoder_encode (encoder, (symtab_node)node);
675}
676
677/* Add all references in LIST to encoders. */
678
679static void
680add_references (lto_symtab_encoder_t encoder,
681 struct ipa_ref_list *list)
682{
683 int i;
684 struct ipa_ref *ref;
685 for (i = 0; ipa_ref_list_reference_iterate (list, i, ref); i++)
2dc9831f 686 if (is_a <cgraph_node> (ref->referred))
724462b0 687 add_node_to (encoder, ipa_ref_node (ref), false);
688 else
c9aa6453 689 lto_symtab_encoder_encode (encoder, ref->referred);
724462b0 690}
691
692/* Find all symbols we want to stream into given partition and insert them
693 to encoders.
694
695 The function actually replaces IN_ENCODER by new one. The reason is that
696 streaming code needs clone's origin to be streamed before clone. This
697 means that we need to insert the nodes in specific order. This order is
698 ignored by the partitioning logic earlier. */
699
700lto_symtab_encoder_t
701compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
7bfefa9d 702{
703 struct cgraph_node *node;
7bfefa9d 704 struct cgraph_edge *edge;
d97be713 705 int i;
70225339 706 lto_symtab_encoder_t encoder;
5cf7e051 707 lto_symtab_encoder_iterator lsei;
6c0782b1 708
b8925abd 709 encoder = lto_symtab_encoder_new (false);
7bfefa9d 710
5cf7e051 711 /* Go over all entries in the IN_ENCODER and duplicate them to
712 ENCODER. At the same time insert masters of clones so
713 every master appears before clone. */
714 for (lsei = lsei_start_function_in_partition (in_encoder);
715 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
7bfefa9d 716 {
5cf7e051 717 node = lsei_cgraph_node (lsei);
02b2818c 718 add_node_to (encoder, node, true);
eab36a5a 719 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)node);
70225339 720 add_references (encoder, &node->symbol.ref_list);
7bfefa9d 721 }
5cf7e051 722 for (lsei = lsei_start_variable_in_partition (in_encoder);
723 !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
a238367f 724 {
5cf7e051 725 struct varpool_node *vnode = lsei_varpool_node (lsei);
e0eaac80 726 gcc_assert (!vnode->alias || vnode->alias_of);
eab36a5a 727 lto_set_symtab_encoder_in_partition (encoder, (symtab_node)vnode);
70225339 728 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
729 add_references (encoder, &vnode->symbol.ref_list);
a238367f 730 }
a238367f 731 /* Pickle in also the initializer of all referenced readonly variables
732 to help folding. Constant pool variables are not shared, so we must
733 pickle those too. */
70225339 734 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
a238367f 735 {
70225339 736 symtab_node node = lto_symtab_encoder_deref (encoder, i);
2dc9831f 737 if (varpool_node *vnode = dyn_cast <varpool_node> (node))
a238367f 738 {
70225339 739 if (DECL_INITIAL (vnode->symbol.decl)
740 && !lto_symtab_encoder_encode_initializer_p (encoder,
741 vnode)
742 && const_value_known_p (vnode->symbol.decl))
743 {
744 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
745 add_references (encoder, &vnode->symbol.ref_list);
746 }
70225339 747 }
a238367f 748 }
7bfefa9d 749
750 /* Go over all the nodes again to include callees that are not in
751 SET. */
5cf7e051 752 for (lsei = lsei_start_function_in_partition (encoder);
753 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
7bfefa9d 754 {
5cf7e051 755 node = lsei_cgraph_node (lsei);
7bfefa9d 756 for (edge = node->callees; edge; edge = edge->next_callee)
757 {
758 struct cgraph_node *callee = edge->callee;
5cf7e051 759 if (!lto_symtab_encoder_in_partition_p (encoder, (symtab_node)callee))
7bfefa9d 760 {
761 /* We should have moved all the inlines. */
762 gcc_assert (!callee->global.inlined_to);
02b2818c 763 add_node_to (encoder, callee, false);
7bfefa9d 764 }
765 }
766 }
724462b0 767 lto_symtab_encoder_delete (in_encoder);
768 return encoder;
d97be713 769}
770
02b699d5 771/* Output the part of the symtab in SET and VSET. */
d97be713 772
773void
eab36a5a 774output_symtab (void)
d97be713 775{
776 struct cgraph_node *node;
777 struct lto_simple_output_block *ob;
eab36a5a 778 lto_symtab_encoder_iterator lsei;
d97be713 779 int i, n_nodes;
70225339 780 lto_symtab_encoder_t encoder;
14c5d106 781 static bool asm_nodes_output = false;
d97be713 782
1bf41320 783 if (flag_wpa)
eab36a5a 784 output_cgraph_opt_summary ();
1bf41320 785
02b699d5 786 ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
d97be713 787
788 output_profile_summary (ob);
789
790 /* An encoder for cgraph nodes should have been created by
791 ipa_write_summaries_1. */
70225339 792 gcc_assert (ob->decl_state->symtab_node_encoder);
793 encoder = ob->decl_state->symtab_node_encoder;
d97be713 794
08843223 795 /* Write out the nodes. We must first output a node and then its clones,
796 otherwise at a time reading back the node there would be nothing to clone
797 from. */
70225339 798 n_nodes = lto_symtab_encoder_size (encoder);
7bfefa9d 799 for (i = 0; i < n_nodes; i++)
800 {
70225339 801 symtab_node node = lto_symtab_encoder_deref (encoder, i);
2dc9831f 802 if (cgraph_node *cnode = dyn_cast <cgraph_node> (node))
803 lto_output_node (ob, cnode, encoder);
70225339 804 else
eab36a5a 805 lto_output_varpool_node (ob, varpool (node), encoder);
70225339 806
7bfefa9d 807 }
808
7bfefa9d 809 /* Go over the nodes in SET again to write edges. */
eab36a5a 810 for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
811 lsei_next_function_in_partition (&lsei))
7bfefa9d 812 {
eab36a5a 813 node = lsei_cgraph_node (lsei);
799c8711 814 output_outgoing_cgraph_edges (node->callees, ob, encoder);
815 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
7bfefa9d 816 }
817
7f385784 818 streamer_write_uhwi_stream (ob->main_stream, 0);
7bfefa9d 819
65d1b157 820 lto_destroy_simple_output_block (ob);
821
2b7c48a1 822 /* Emit toplevel asms.
823 When doing WPA we must output every asm just once. Since we do not partition asm
824 nodes at all, output them to first output. This is kind of hack, but should work
825 well. */
826 if (!asm_nodes_output)
90f477a9 827 {
2b7c48a1 828 asm_nodes_output = true;
65d1b157 829 lto_output_toplevel_asms ();
90f477a9 830 }
831
eab36a5a 832 output_refs (encoder);
7bfefa9d 833}
834
7bfefa9d 835/* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
836 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
837 NODE or to replace the values in it, for instance because the first
838 time we saw it, the function body was not available but now it
839 is. BP is a bitpack with all the bitflags for NODE read from the
840 stream. */
841
842static void
843input_overwrite_node (struct lto_file_decl_data *file_data,
844 struct cgraph_node *node,
70225339 845 enum LTO_symtab_tags tag,
7857a7b7 846 struct bitpack_d *bp)
7bfefa9d 847{
7d0d0ce1 848 node->symbol.aux = (void *) tag;
849 node->symbol.lto_file_data = file_data;
7bfefa9d 850
851 node->local.local = bp_unpack_value (bp, 1);
7d0d0ce1 852 node->symbol.externally_visible = bp_unpack_value (bp, 1);
7bfefa9d 853 node->local.finalized = bp_unpack_value (bp, 1);
c8d92fc1 854 node->local.versionable = bp_unpack_value (bp, 1);
3c97c75d 855 node->local.can_change_signature = bp_unpack_value (bp, 1);
7bfefa9d 856 node->local.redefined_extern_inline = bp_unpack_value (bp, 1);
8efa224a 857 node->symbol.force_output = bp_unpack_value (bp, 1);
7d0d0ce1 858 node->symbol.address_taken = bp_unpack_value (bp, 1);
7bfefa9d 859 node->abstract_and_needed = bp_unpack_value (bp, 1);
7d0d0ce1 860 node->symbol.used_from_other_partition = bp_unpack_value (bp, 1);
7bfefa9d 861 node->lowered = bp_unpack_value (bp, 1);
70225339 862 node->analyzed = tag == LTO_symtab_analyzed_node;
7d0d0ce1 863 node->symbol.in_other_partition = bp_unpack_value (bp, 1);
864 if (node->symbol.in_other_partition
cdc58a66 865 /* Avoid updating decl when we are seeing just inline clone.
866 When inlining function that has functions already inlined into it,
867 we produce clones of inline clones.
868
869 WPA partitioning might put each clone into different unit and
870 we might end up streaming inline clone from other partition
871 to support clone we are interested in. */
872 && (!node->clone_of
7d0d0ce1 873 || node->clone_of->symbol.decl != node->symbol.decl))
eb0bc81b 874 {
7d0d0ce1 875 DECL_EXTERNAL (node->symbol.decl) = 1;
876 TREE_STATIC (node->symbol.decl) = 0;
eb0bc81b 877 }
7bfefa9d 878 node->alias = bp_unpack_value (bp, 1);
125b6d78 879 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
0f9fb931 880 node->only_called_at_startup = bp_unpack_value (bp, 1);
881 node->only_called_at_exit = bp_unpack_value (bp, 1);
ea0e88d1 882 node->tm_clone = bp_unpack_value (bp, 1);
91bf9d9a 883 node->thunk.thunk_p = bp_unpack_value (bp, 1);
7d0d0ce1 884 node->symbol.resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
7857a7b7 885 LDPR_NUM_KNOWN);
7bfefa9d 886}
887
48e1416a 888/* Read a node from input_block IB. TAG is the node's tag just read.
7bfefa9d 889 Return the node read or overwriten. */
48e1416a 890
7bfefa9d 891static struct cgraph_node *
892input_node (struct lto_file_decl_data *file_data,
893 struct lto_input_block *ib,
70225339 894 enum LTO_symtab_tags tag,
f1f41a6c 895 vec<symtab_node> nodes)
7bfefa9d 896{
897 tree fn_decl;
898 struct cgraph_node *node;
30baba90 899 struct bitpack_d bp;
7bfefa9d 900 unsigned decl_index;
61c2c7b1 901 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
02b2818c 902 int clone_ref;
f1007c72 903 int order;
b9e2d290 904 int i, count;
7bfefa9d 905
f1007c72 906 order = streamer_read_hwi (ib) + order_base;
7f385784 907 clone_ref = streamer_read_hwi (ib);
7bfefa9d 908
7f385784 909 decl_index = streamer_read_uhwi (ib);
7bfefa9d 910 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
911
02b2818c 912 if (clone_ref != LCC_NOT_FOUND)
913 {
f1f41a6c 914 node = cgraph_clone_node (cgraph (nodes[clone_ref]), fn_decl,
915 0, CGRAPH_FREQ_BASE, false,
916 vec<cgraph_edge_p>(), false);
02b2818c 917 }
7bfefa9d 918 else
5a90471f 919 node = cgraph_get_create_node (fn_decl);
7bfefa9d 920
7d0d0ce1 921 node->symbol.order = order;
0704fb2e 922 if (order >= symtab_order)
923 symtab_order = order + 1;
f1007c72 924
7f385784 925 node->count = streamer_read_hwi (ib);
926 node->count_materialization_scale = streamer_read_hwi (ib);
48e1416a 927
b9e2d290 928 count = streamer_read_hwi (ib);
f1f41a6c 929 node->ipa_transforms_to_apply = vec<ipa_opt_pass>();
b9e2d290 930 for (i = 0; i < count; i++)
931 {
932 struct opt_pass *pass;
933 int pid = streamer_read_hwi (ib);
934
935 gcc_assert (pid < passes_by_id_size);
936 pass = passes_by_id[pid];
f1f41a6c 937 node->ipa_transforms_to_apply.safe_push ((struct ipa_opt_pass_d *) pass);
b9e2d290 938 }
939
70225339 940 if (tag == LTO_symtab_analyzed_node)
7f385784 941 ref = streamer_read_hwi (ib);
7bfefa9d 942
7f385784 943 ref2 = streamer_read_hwi (ib);
7bfefa9d 944
945 /* Make sure that we have not read this node before. Nodes that
946 have already been read will have their tag stored in the 'aux'
947 field. Since built-in functions can be referenced in multiple
948 functions, they are expected to be read more than once. */
7d0d0ce1 949 if (node->symbol.aux && !DECL_BUILT_IN (node->symbol.decl))
7bfefa9d 950 internal_error ("bytecode stream: found multiple instances of cgraph "
951 "node %d", node->uid);
952
7f385784 953 bp = streamer_read_bitpack (ib);
7857a7b7 954 input_overwrite_node (file_data, node, tag, &bp);
7bfefa9d 955
7bfefa9d 956 /* Store a reference for now, and fix up later to be a pointer. */
957 node->global.inlined_to = (cgraph_node_ptr) (intptr_t) ref;
958
61c2c7b1 959 /* Store a reference for now, and fix up later to be a pointer. */
7d0d0ce1 960 node->symbol.same_comdat_group = (symtab_node) (intptr_t) ref2;
61c2c7b1 961
91bf9d9a 962 if (node->thunk.thunk_p)
963 {
7f385784 964 int type = streamer_read_uhwi (ib);
965 HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
966 HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib);
91bf9d9a 967
91bf9d9a 968 node->thunk.fixed_offset = fixed_offset;
969 node->thunk.this_adjusting = (type & 2);
970 node->thunk.virtual_value = virtual_value;
971 node->thunk.virtual_offset_p = (type & 4);
91bf9d9a 972 }
c70f46b0 973 if (node->thunk.thunk_p || node->alias)
ed772161 974 {
7f385784 975 if (streamer_read_hwi_in_range (ib, "alias nonzero flag", 0, 1))
c70f46b0 976 {
7f385784 977 decl_index = streamer_read_uhwi (ib);
c70f46b0 978 node->thunk.alias = lto_file_decl_data_get_fn_decl (file_data,
979 decl_index);
980 }
ed772161 981 }
7bfefa9d 982 return node;
983}
984
0cddb138 985/* Read a node from input_block IB. TAG is the node's tag just read.
986 Return the node read or overwriten. */
987
988static struct varpool_node *
989input_varpool_node (struct lto_file_decl_data *file_data,
990 struct lto_input_block *ib)
991{
992 int decl_index;
993 tree var_decl;
994 struct varpool_node *node;
30baba90 995 struct bitpack_d bp;
933b10c6 996 int ref = LCC_NOT_FOUND;
e0eaac80 997 bool non_null_aliasof;
f1007c72 998 int order;
0cddb138 999
f1007c72 1000 order = streamer_read_hwi (ib) + order_base;
7f385784 1001 decl_index = streamer_read_uhwi (ib);
0cddb138 1002 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
2dc9831f 1003 node = varpool_node_for_decl (var_decl);
7d0d0ce1 1004 node->symbol.order = order;
0704fb2e 1005 if (order >= symtab_order)
1006 symtab_order = order + 1;
7d0d0ce1 1007 node->symbol.lto_file_data = file_data;
0cddb138 1008
7f385784 1009 bp = streamer_read_bitpack (ib);
7d0d0ce1 1010 node->symbol.externally_visible = bp_unpack_value (&bp, 1);
8efa224a 1011 node->symbol.force_output = bp_unpack_value (&bp, 1);
30baba90 1012 node->finalized = bp_unpack_value (&bp, 1);
1013 node->alias = bp_unpack_value (&bp, 1);
e0eaac80 1014 non_null_aliasof = bp_unpack_value (&bp, 1);
7d0d0ce1 1015 node->symbol.used_from_other_partition = bp_unpack_value (&bp, 1);
1016 node->symbol.in_other_partition = bp_unpack_value (&bp, 1);
ff2a5ada 1017 node->analyzed = (node->finalized && (!node->alias || !node->symbol.in_other_partition));
7d0d0ce1 1018 if (node->symbol.in_other_partition)
eb0bc81b 1019 {
7d0d0ce1 1020 DECL_EXTERNAL (node->symbol.decl) = 1;
1021 TREE_STATIC (node->symbol.decl) = 0;
eb0bc81b 1022 }
e0eaac80 1023 if (non_null_aliasof)
1024 {
7f385784 1025 decl_index = streamer_read_uhwi (ib);
e0eaac80 1026 node->alias_of = lto_file_decl_data_get_var_decl (file_data, decl_index);
1027 }
7f385784 1028 ref = streamer_read_hwi (ib);
933b10c6 1029 /* Store a reference for now, and fix up later to be a pointer. */
7d0d0ce1 1030 node->symbol.same_comdat_group = (symtab_node) (intptr_t) ref;
1031 node->symbol.resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
1032 LDPR_NUM_KNOWN);
e0eaac80 1033
0cddb138 1034 return node;
1035}
1036
8d810329 1037/* Read a node from input_block IB. TAG is the node's tag just read.
1038 Return the node read or overwriten. */
1039
1040static void
1041input_ref (struct lto_input_block *ib,
04ec15fa 1042 symtab_node referring_node,
f1f41a6c 1043 vec<symtab_node> nodes)
8d810329 1044{
70225339 1045 symtab_node node = NULL;
30baba90 1046 struct bitpack_d bp;
8d810329 1047 enum ipa_ref_use use;
1048
7f385784 1049 bp = streamer_read_bitpack (ib);
30baba90 1050 use = (enum ipa_ref_use) bp_unpack_value (&bp, 2);
f1f41a6c 1051 node = nodes[streamer_read_hwi (ib)];
70225339 1052 ipa_record_reference (referring_node, node, use, NULL);
8d810329 1053}
7bfefa9d 1054
799c8711 1055/* Read an edge from IB. NODES points to a vector of previously read nodes for
1056 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1057 edge being read is indirect (in the sense that it has
1058 indirect_unknown_callee set). */
7bfefa9d 1059
1060static void
f1f41a6c 1061input_edge (struct lto_input_block *ib, vec<symtab_node> nodes,
799c8711 1062 bool indirect)
7bfefa9d 1063{
1064 struct cgraph_node *caller, *callee;
1065 struct cgraph_edge *edge;
1066 unsigned int stmt_id;
1067 gcov_type count;
1068 int freq;
7bfefa9d 1069 cgraph_inline_failed_t inline_failed;
30baba90 1070 struct bitpack_d bp;
f8b7e3ec 1071 int ecf_flags = 0;
7bfefa9d 1072
f1f41a6c 1073 caller = cgraph (nodes[streamer_read_hwi (ib)]);
7d0d0ce1 1074 if (caller == NULL || caller->symbol.decl == NULL_TREE)
7bfefa9d 1075 internal_error ("bytecode stream: no caller found while reading edge");
1076
799c8711 1077 if (!indirect)
1078 {
f1f41a6c 1079 callee = cgraph (nodes[streamer_read_hwi (ib)]);
7d0d0ce1 1080 if (callee == NULL || callee->symbol.decl == NULL_TREE)
799c8711 1081 internal_error ("bytecode stream: no callee found while reading edge");
1082 }
1083 else
1084 callee = NULL;
7bfefa9d 1085
7f385784 1086 count = (gcov_type) streamer_read_hwi (ib);
7bfefa9d 1087
7f385784 1088 bp = streamer_read_bitpack (ib);
7857a7b7 1089 inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_enum, CIF_N_REASONS);
1090 stmt_id = bp_unpack_var_len_unsigned (&bp);
1091 freq = (int) bp_unpack_var_len_unsigned (&bp);
7bfefa9d 1092
799c8711 1093 if (indirect)
0835ad03 1094 edge = cgraph_create_indirect_edge (caller, NULL, 0, count, freq);
799c8711 1095 else
0835ad03 1096 edge = cgraph_create_edge (caller, callee, NULL, count, freq);
799c8711 1097
30baba90 1098 edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
7bfefa9d 1099 edge->lto_stmt_uid = stmt_id;
1100 edge->inline_failed = inline_failed;
30baba90 1101 edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1102 edge->can_throw_external = bp_unpack_value (&bp, 1);
f8b7e3ec 1103 if (indirect)
1104 {
30baba90 1105 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1106 ecf_flags |= ECF_CONST;
30baba90 1107 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1108 ecf_flags |= ECF_PURE;
30baba90 1109 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1110 ecf_flags |= ECF_NORETURN;
30baba90 1111 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1112 ecf_flags |= ECF_MALLOC;
30baba90 1113 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1114 ecf_flags |= ECF_NOTHROW;
30baba90 1115 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1116 ecf_flags |= ECF_RETURNS_TWICE;
1117 edge->indirect_info->ecf_flags = ecf_flags;
1118 }
7bfefa9d 1119}
1120
1121
1122/* Read a cgraph from IB using the info in FILE_DATA. */
1123
f1f41a6c 1124static vec<symtab_node>
7bfefa9d 1125input_cgraph_1 (struct lto_file_decl_data *file_data,
1126 struct lto_input_block *ib)
1127{
70225339 1128 enum LTO_symtab_tags tag;
f1f41a6c 1129 vec<symtab_node> nodes = vec<symtab_node>();
70225339 1130 symtab_node node;
7bfefa9d 1131 unsigned i;
1132
70225339 1133 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
0704fb2e 1134 order_base = symtab_order;
7bfefa9d 1135 while (tag)
1136 {
70225339 1137 if (tag == LTO_symtab_edge)
799c8711 1138 input_edge (ib, nodes, false);
70225339 1139 else if (tag == LTO_symtab_indirect_edge)
799c8711 1140 input_edge (ib, nodes, true);
70225339 1141 else if (tag == LTO_symtab_variable)
1142 {
1143 node = (symtab_node)input_varpool_node (file_data, ib);
f1f41a6c 1144 nodes.safe_push (node);
70225339 1145 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1146 }
48e1416a 1147 else
7bfefa9d 1148 {
70225339 1149 node = (symtab_node)input_node (file_data, ib, tag, nodes);
7d0d0ce1 1150 if (node == NULL || node->symbol.decl == NULL_TREE)
7bfefa9d 1151 internal_error ("bytecode stream: found empty cgraph node");
f1f41a6c 1152 nodes.safe_push (node);
70225339 1153 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
7bfefa9d 1154 }
1155
70225339 1156 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
7bfefa9d 1157 }
1158
f1007c72 1159 lto_input_toplevel_asms (file_data, order_base);
90f477a9 1160
70225339 1161 /* AUX pointers should be all non-zero for function nodes read from the stream. */
d47cadab 1162#ifdef ENABLE_CHECKING
f1f41a6c 1163 FOR_EACH_VEC_ELT (nodes, i, node)
2dc9831f 1164 gcc_assert (node->symbol.aux || !is_a <cgraph_node> (node));
d47cadab 1165#endif
f1f41a6c 1166 FOR_EACH_VEC_ELT (nodes, i, node)
7bfefa9d 1167 {
70225339 1168 int ref;
2dc9831f 1169 if (cgraph_node *cnode = dyn_cast <cgraph_node> (node))
70225339 1170 {
2dc9831f 1171 ref = (int) (intptr_t) cnode->global.inlined_to;
70225339 1172
1173 /* We share declaration of builtins, so we may read same node twice. */
1174 if (!node->symbol.aux)
1175 continue;
1176 node->symbol.aux = NULL;
1177
1178 /* Fixup inlined_to from reference to pointer. */
1179 if (ref != LCC_NOT_FOUND)
f1f41a6c 1180 cgraph (node)->global.inlined_to = cgraph (nodes[ref]);
70225339 1181 else
2dc9831f 1182 cnode->global.inlined_to = NULL;
70225339 1183 }
61c2c7b1 1184
7d0d0ce1 1185 ref = (int) (intptr_t) node->symbol.same_comdat_group;
61c2c7b1 1186
1187 /* Fixup same_comdat_group from reference to pointer. */
1188 if (ref != LCC_NOT_FOUND)
f1f41a6c 1189 node->symbol.same_comdat_group = nodes[ref];
61c2c7b1 1190 else
7d0d0ce1 1191 node->symbol.same_comdat_group = NULL;
7bfefa9d 1192 }
f1f41a6c 1193 FOR_EACH_VEC_ELT (nodes, i, node)
2dc9831f 1194 node->symbol.aux = is_a <cgraph_node> (node) ? (void *)1 : NULL;
a238367f 1195 return nodes;
7bfefa9d 1196}
1197
8d810329 1198/* Input ipa_refs. */
1199
1200static void
1201input_refs (struct lto_input_block *ib,
f1f41a6c 1202 vec<symtab_node> nodes)
8d810329 1203{
1204 int count;
1205 int idx;
1206 while (true)
1207 {
eab36a5a 1208 symtab_node node;
7f385784 1209 count = streamer_read_uhwi (ib);
8d810329 1210 if (!count)
1211 break;
7f385784 1212 idx = streamer_read_uhwi (ib);
f1f41a6c 1213 node = nodes[idx];
8d810329 1214 while (count)
1215 {
eab36a5a 1216 input_ref (ib, node, nodes);
8d810329 1217 count--;
1218 }
1219 }
1220}
1221
a238367f 1222
6c0782b1 1223static struct gcov_ctr_summary lto_gcov_summary;
1224
1225/* Input profile_info from IB. */
1226static void
c470c5a9 1227input_profile_summary (struct lto_input_block *ib,
1228 struct lto_file_decl_data *file_data)
6c0782b1 1229{
7f385784 1230 unsigned int runs = streamer_read_uhwi (ib);
6c0782b1 1231 if (runs)
1232 {
c470c5a9 1233 file_data->profile_info.runs = runs;
7f385784 1234 file_data->profile_info.sum_max = streamer_read_uhwi (ib);
6c0782b1 1235 }
1236
1237}
7bfefa9d 1238
c470c5a9 1239/* Rescale profile summaries to the same number of runs in the whole unit. */
1240
1241static void
1242merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1243{
1244 struct lto_file_decl_data *file_data;
1245 unsigned int j;
1246 gcov_unsigned_t max_runs = 0;
1247 struct cgraph_node *node;
1248 struct cgraph_edge *edge;
1249
1250 /* Find unit with maximal number of runs. If we ever get serious about
1251 roundoff errors, we might also consider computing smallest common
1252 multiply. */
1253 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1254 if (max_runs < file_data->profile_info.runs)
1255 max_runs = file_data->profile_info.runs;
1256
1257 if (!max_runs)
1258 return;
1259
1260 /* Simple overflow check. We probably don't need to support that many train
1261 runs. Such a large value probably imply data corruption anyway. */
1262 if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1263 {
1264 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1265 INT_MAX / REG_BR_PROB_BASE);
1266 return;
1267 }
1268
1269 profile_info = &lto_gcov_summary;
1270 lto_gcov_summary.runs = max_runs;
1271 lto_gcov_summary.sum_max = 0;
1272
1273 /* Rescale all units to the maximal number of runs.
1274 sum_max can not be easily merged, as we have no idea what files come from
1275 the same run. We do not use the info anyway, so leave it 0. */
1276 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1277 if (file_data->profile_info.runs)
1278 {
1279 int scale = ((REG_BR_PROB_BASE * max_runs
1280 + file_data->profile_info.runs / 2)
1281 / file_data->profile_info.runs);
1282 lto_gcov_summary.sum_max = MAX (lto_gcov_summary.sum_max,
1283 (file_data->profile_info.sum_max
1284 * scale
1285 + REG_BR_PROB_BASE / 2)
1286 / REG_BR_PROB_BASE);
1287 }
1288
1289 /* Watch roundoff errors. */
1290 if (lto_gcov_summary.sum_max < max_runs)
1291 lto_gcov_summary.sum_max = max_runs;
1292
1293 /* If merging already happent at WPA time, we are done. */
1294 if (flag_ltrans)
1295 return;
1296
1297 /* Now compute count_materialization_scale of each node.
1298 During LTRANS we already have values of count_materialization_scale
1299 computed, so just update them. */
7c455d87 1300 FOR_EACH_FUNCTION (node)
7d0d0ce1 1301 if (node->symbol.lto_file_data
1302 && node->symbol.lto_file_data->profile_info.runs)
c470c5a9 1303 {
1304 int scale;
555491e2 1305
1306 scale =
1307 ((node->count_materialization_scale * max_runs
7d0d0ce1 1308 + node->symbol.lto_file_data->profile_info.runs / 2)
1309 / node->symbol.lto_file_data->profile_info.runs);
c470c5a9 1310 node->count_materialization_scale = scale;
1311 if (scale < 0)
1312 fatal_error ("Profile information in %s corrupted",
1313 file_data->file_name);
1314
1315 if (scale == REG_BR_PROB_BASE)
1316 continue;
1317 for (edge = node->callees; edge; edge = edge->next_callee)
1318 edge->count = ((edge->count * scale + REG_BR_PROB_BASE / 2)
1319 / REG_BR_PROB_BASE);
1320 node->count = ((node->count * scale + REG_BR_PROB_BASE / 2)
1321 / REG_BR_PROB_BASE);
1322 }
1323}
1324
02b699d5 1325/* Input and merge the symtab from each of the .o files passed to
7bfefa9d 1326 lto1. */
1327
1328void
02b699d5 1329input_symtab (void)
7bfefa9d 1330{
1331 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1332 struct lto_file_decl_data *file_data;
1333 unsigned int j = 0;
1334 struct cgraph_node *node;
1335
ff2a5ada 1336 cgraph_state = CGRAPH_STATE_IPA_SSA;
1337
7bfefa9d 1338 while ((file_data = file_data_vec[j++]))
1339 {
1340 const char *data;
1341 size_t len;
1342 struct lto_input_block *ib;
f1f41a6c 1343 vec<symtab_node> nodes;
7bfefa9d 1344
02b699d5 1345 ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
7bfefa9d 1346 &data, &len);
fd30d60a 1347 if (!ib)
bf776685 1348 fatal_error ("cannot find LTO cgraph in %s", file_data->file_name);
c470c5a9 1349 input_profile_summary (ib, file_data);
b8925abd 1350 file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
a238367f 1351 nodes = input_cgraph_1 (file_data, ib);
02b699d5 1352 lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
7bfefa9d 1353 ib, data, len);
48e1416a 1354
8d810329 1355 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1356 &data, &len);
fd30d60a 1357 if (!ib)
bf776685 1358 fatal_error("cannot find LTO section refs in %s", file_data->file_name);
70225339 1359 input_refs (ib, nodes);
8d810329 1360 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1361 ib, data, len);
1bf41320 1362 if (flag_ltrans)
1363 input_cgraph_opt_summary (nodes);
f1f41a6c 1364 nodes.release ();
48e1416a 1365 }
30f589a5 1366
c470c5a9 1367 merge_profile_summaries (file_data_vec);
7bfefa9d 1368
1369 /* Clear out the aux field that was used to store enough state to
1370 tell which nodes should be overwritten. */
7c455d87 1371 FOR_EACH_FUNCTION (node)
7bfefa9d 1372 {
1373 /* Some nodes may have been created by cgraph_node. This
1374 happens when the callgraph contains nested functions. If the
1375 node for the parent function was never emitted to the gimple
1376 file, cgraph_node will create a node for it when setting the
1377 context of the nested function. */
7d0d0ce1 1378 if (node->symbol.lto_file_data)
1379 node->symbol.aux = NULL;
7bfefa9d 1380 }
1381}
1bf41320 1382
1383/* True when we need optimization summary for NODE. */
1384
1385static int
eab36a5a 1386output_cgraph_opt_summary_p (struct cgraph_node *node)
1bf41320 1387{
2b36ac0b 1388 return (node->clone_of
1389 && (node->clone.tree_map
1390 || node->clone.args_to_skip
1391 || node->clone.combined_args_to_skip));
1bf41320 1392}
1393
9bab6a70 1394/* Output optimization summary for EDGE to OB. */
1395static void
d4e80e2b 1396output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
1397 struct cgraph_edge *edge ATTRIBUTE_UNUSED)
9bab6a70 1398{
9bab6a70 1399}
1400
1bf41320 1401/* Output optimization summary for NODE to OB. */
1402
1403static void
1404output_node_opt_summary (struct output_block *ob,
2b36ac0b 1405 struct cgraph_node *node,
eab36a5a 1406 lto_symtab_encoder_t encoder)
1bf41320 1407{
1408 unsigned int index;
1409 bitmap_iterator bi;
1410 struct ipa_replace_map *map;
30baba90 1411 struct bitpack_d bp;
1bf41320 1412 int i;
9bab6a70 1413 struct cgraph_edge *e;
1bf41320 1414
29413d70 1415 if (node->clone.args_to_skip)
1416 {
7f385784 1417 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.args_to_skip));
29413d70 1418 EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi)
7f385784 1419 streamer_write_uhwi (ob, index);
29413d70 1420 }
1421 else
7f385784 1422 streamer_write_uhwi (ob, 0);
29413d70 1423 if (node->clone.combined_args_to_skip)
1424 {
7f385784 1425 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.combined_args_to_skip));
29413d70 1426 EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi)
7f385784 1427 streamer_write_uhwi (ob, index);
29413d70 1428 }
1429 else
7f385784 1430 streamer_write_uhwi (ob, 0);
f1f41a6c 1431 streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map));
1432 FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map)
1bf41320 1433 {
1434 int parm_num;
1435 tree parm;
1436
7d0d0ce1 1437 for (parm_num = 0, parm = DECL_ARGUMENTS (node->symbol.decl); parm;
1767a056 1438 parm = DECL_CHAIN (parm), parm_num++)
1bf41320 1439 if (map->old_tree == parm)
1440 break;
1441 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1442 mechanism to store function local declarations into summaries. */
1443 gcc_assert (parm);
7f385784 1444 streamer_write_uhwi (ob, parm_num);
8e7408e3 1445 gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
515cf651 1446 stream_write_tree (ob, map->new_tree, true);
30baba90 1447 bp = bitpack_create (ob->main_stream);
1448 bp_pack_value (&bp, map->replace_p, 1);
1449 bp_pack_value (&bp, map->ref_p, 1);
7f385784 1450 streamer_write_bitpack (&bp);
1bf41320 1451 }
2b36ac0b 1452
eab36a5a 1453 if (lto_symtab_encoder_in_partition_p (encoder, (symtab_node) node))
2b36ac0b 1454 {
1455 for (e = node->callees; e; e = e->next_callee)
1456 output_edge_opt_summary (ob, e);
1457 for (e = node->indirect_calls; e; e = e->next_callee)
1458 output_edge_opt_summary (ob, e);
1459 }
1bf41320 1460}
1461
1462/* Output optimization summaries stored in callgraph.
1463 At the moment it is the clone info structure. */
1464
1465static void
eab36a5a 1466output_cgraph_opt_summary (void)
1bf41320 1467{
1bf41320 1468 int i, n_nodes;
70225339 1469 lto_symtab_encoder_t encoder;
1bf41320 1470 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
1471 unsigned count = 0;
1472
1473 ob->cgraph_node = NULL;
70225339 1474 encoder = ob->decl_state->symtab_node_encoder;
1475 n_nodes = lto_symtab_encoder_size (encoder);
1bf41320 1476 for (i = 0; i < n_nodes; i++)
2dc9831f 1477 {
1478 symtab_node node = lto_symtab_encoder_deref (encoder, i);
1479 cgraph_node *cnode = dyn_cast <cgraph_node> (node);
1480 if (cnode && output_cgraph_opt_summary_p (cnode))
1481 count++;
1482 }
7f385784 1483 streamer_write_uhwi (ob, count);
1bf41320 1484 for (i = 0; i < n_nodes; i++)
1485 {
2dc9831f 1486 symtab_node node = lto_symtab_encoder_deref (encoder, i);
1487 cgraph_node *cnode = dyn_cast <cgraph_node> (node);
1488 if (cnode && output_cgraph_opt_summary_p (cnode))
1bf41320 1489 {
7f385784 1490 streamer_write_uhwi (ob, i);
2dc9831f 1491 output_node_opt_summary (ob, cnode, encoder);
1bf41320 1492 }
1493 }
1494 produce_asm (ob, NULL);
1495 destroy_output_block (ob);
1496}
1497
9bab6a70 1498/* Input optimisation summary of EDGE. */
1499
1500static void
d4e80e2b 1501input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
1502 struct lto_input_block *ib_main ATTRIBUTE_UNUSED)
9bab6a70 1503{
9bab6a70 1504}
1505
1506/* Input optimisation summary of NODE. */
1bf41320 1507
1508static void
1509input_node_opt_summary (struct cgraph_node *node,
1510 struct lto_input_block *ib_main,
1511 struct data_in *data_in)
1512{
1513 int i;
1514 int count;
1515 int bit;
30baba90 1516 struct bitpack_d bp;
9bab6a70 1517 struct cgraph_edge *e;
1bf41320 1518
7f385784 1519 count = streamer_read_uhwi (ib_main);
1bf41320 1520 if (count)
1521 node->clone.args_to_skip = BITMAP_GGC_ALLOC ();
1522 for (i = 0; i < count; i++)
1523 {
7f385784 1524 bit = streamer_read_uhwi (ib_main);
1bf41320 1525 bitmap_set_bit (node->clone.args_to_skip, bit);
1526 }
7f385784 1527 count = streamer_read_uhwi (ib_main);
1bf41320 1528 if (count)
1529 node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC ();
1530 for (i = 0; i < count; i++)
1531 {
7f385784 1532 bit = streamer_read_uhwi (ib_main);
1bf41320 1533 bitmap_set_bit (node->clone.combined_args_to_skip, bit);
1534 }
7f385784 1535 count = streamer_read_uhwi (ib_main);
1bf41320 1536 for (i = 0; i < count; i++)
1537 {
ba72912a 1538 struct ipa_replace_map *map = ggc_alloc_ipa_replace_map ();
1bf41320 1539
f1f41a6c 1540 vec_safe_push (node->clone.tree_map, map);
7f385784 1541 map->parm_num = streamer_read_uhwi (ib_main);
1bf41320 1542 map->old_tree = NULL;
515cf651 1543 map->new_tree = stream_read_tree (ib_main, data_in);
7f385784 1544 bp = streamer_read_bitpack (ib_main);
30baba90 1545 map->replace_p = bp_unpack_value (&bp, 1);
1546 map->ref_p = bp_unpack_value (&bp, 1);
1bf41320 1547 }
9bab6a70 1548 for (e = node->callees; e; e = e->next_callee)
1549 input_edge_opt_summary (e, ib_main);
1550 for (e = node->indirect_calls; e; e = e->next_callee)
1551 input_edge_opt_summary (e, ib_main);
1bf41320 1552}
1553
1554/* Read section in file FILE_DATA of length LEN with data DATA. */
1555
1556static void
1557input_cgraph_opt_section (struct lto_file_decl_data *file_data,
f1f41a6c 1558 const char *data, size_t len,
1559 vec<symtab_node> nodes)
1bf41320 1560{
1561 const struct lto_function_header *header =
1562 (const struct lto_function_header *) data;
949e5786 1563 const int cfg_offset = sizeof (struct lto_function_header);
1564 const int main_offset = cfg_offset + header->cfg_size;
1565 const int string_offset = main_offset + header->main_size;
1bf41320 1566 struct data_in *data_in;
1567 struct lto_input_block ib_main;
1568 unsigned int i;
1569 unsigned int count;
1570
1571 LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
1572 header->main_size);
1573
1574 data_in =
1575 lto_data_in_create (file_data, (const char *) data + string_offset,
f1f41a6c 1576 header->string_size,
1577 vec<ld_plugin_symbol_resolution_t>());
7f385784 1578 count = streamer_read_uhwi (&ib_main);
1bf41320 1579
1580 for (i = 0; i < count; i++)
1581 {
7f385784 1582 int ref = streamer_read_uhwi (&ib_main);
f1f41a6c 1583 input_node_opt_summary (cgraph (nodes[ref]),
1bf41320 1584 &ib_main, data_in);
1585 }
783bc09c 1586 lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
1bf41320 1587 len);
1588 lto_data_in_delete (data_in);
1589}
1590
1591/* Input optimization summary of cgraph. */
1592
1593static void
f1f41a6c 1594input_cgraph_opt_summary (vec<symtab_node> nodes)
1bf41320 1595{
1596 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1597 struct lto_file_decl_data *file_data;
1598 unsigned int j = 0;
1599
1600 while ((file_data = file_data_vec[j++]))
1601 {
1602 size_t len;
1603 const char *data =
1604 lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL,
1605 &len);
1606
1607 if (data)
1608 input_cgraph_opt_section (file_data, data, len, nodes);
1609 }
1610}