2015-03-03 Andrew Sutton <andrew.n.sutton@gmail.com>
[official-gcc.git] / gcc / lto-cgraph.c
blobda1f0e446822f33d6e9b39b7148b2f7df37d80aa
1 /* Write and read the cgraph to the memory mapped representation of a
2 .o file.
4 Copyright (C) 2009-2014 Free Software Foundation, Inc.
5 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "stringpool.h"
29 #include "predict.h"
30 #include "vec.h"
31 #include "hashtab.h"
32 #include "hash-set.h"
33 #include "machmode.h"
34 #include "hard-reg-set.h"
35 #include "input.h"
36 #include "function.h"
37 #include "basic-block.h"
38 #include "tree-ssa-alias.h"
39 #include "internal-fn.h"
40 #include "gimple-expr.h"
41 #include "is-a.h"
42 #include "gimple.h"
43 #include "expr.h"
44 #include "flags.h"
45 #include "params.h"
46 #include "langhooks.h"
47 #include "bitmap.h"
48 #include "diagnostic-core.h"
49 #include "except.h"
50 #include "timevar.h"
51 #include "hash-map.h"
52 #include "plugin-api.h"
53 #include "ipa-ref.h"
54 #include "cgraph.h"
55 #include "lto-streamer.h"
56 #include "data-streamer.h"
57 #include "tree-streamer.h"
58 #include "gcov-io.h"
59 #include "tree-pass.h"
60 #include "profile.h"
61 #include "context.h"
62 #include "pass_manager.h"
63 #include "ipa-utils.h"
65 /* True when asm nodes has been output. */
66 bool asm_nodes_output = false;
68 static void output_cgraph_opt_summary (void);
69 static void input_cgraph_opt_summary (vec<symtab_node *> nodes);
71 /* Number of LDPR values known to GCC. */
72 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
74 /* All node orders are ofsetted by ORDER_BASE. */
75 static int order_base;
77 /* Cgraph streaming is organized as set of record whose type
78 is indicated by a tag. */
79 enum LTO_symtab_tags
81 /* Must leave 0 for the stopper. */
83 /* Cgraph node without body available. */
84 LTO_symtab_unavail_node = 1,
85 /* Cgraph node with function body. */
86 LTO_symtab_analyzed_node,
87 /* Cgraph edges. */
88 LTO_symtab_edge,
89 LTO_symtab_indirect_edge,
90 LTO_symtab_variable,
91 LTO_symtab_last_tag
94 /* Create a new symtab encoder.
95 if FOR_INPUT, the encoder allocate only datastructures needed
96 to read the symtab. */
98 lto_symtab_encoder_t
99 lto_symtab_encoder_new (bool for_input)
101 lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
103 if (!for_input)
104 encoder->map = new hash_map<symtab_node *, size_t>;
105 encoder->nodes.create (0);
106 return encoder;
110 /* Delete ENCODER and its components. */
112 void
113 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
115 encoder->nodes.release ();
116 if (encoder->map)
117 delete encoder->map;
118 free (encoder);
122 /* Return the existing reference number of NODE in the symtab encoder in
123 output block OB. Assign a new reference if this is the first time
124 NODE is encoded. */
127 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
128 symtab_node *node)
130 int ref;
132 if (!encoder->map)
134 lto_encoder_entry entry = {node, false, false, false};
136 ref = encoder->nodes.length ();
137 encoder->nodes.safe_push (entry);
138 return ref;
141 size_t *slot = encoder->map->get (node);
142 if (!slot || !*slot)
144 lto_encoder_entry entry = {node, false, false, false};
145 ref = encoder->nodes.length ();
146 if (!slot)
147 encoder->map->put (node, ref + 1);
148 encoder->nodes.safe_push (entry);
150 else
151 ref = *slot - 1;
153 return ref;
156 /* Remove NODE from encoder. */
158 bool
159 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
160 symtab_node *node)
162 int index;
163 lto_encoder_entry last_node;
165 size_t *slot = encoder->map->get (node);
166 if (slot == NULL || !*slot)
167 return false;
169 index = *slot - 1;
170 gcc_checking_assert (encoder->nodes[index].node == node);
172 /* Remove from vector. We do this by swapping node with the last element
173 of the vector. */
174 last_node = encoder->nodes.pop ();
175 if (last_node.node != node)
177 gcc_assert (encoder->map->put (last_node.node, index + 1));
179 /* Move the last element to the original spot of NODE. */
180 encoder->nodes[index] = last_node;
183 /* Remove element from hash table. */
184 encoder->map->remove (node);
185 return true;
189 /* Return TRUE if we should encode initializer of NODE (if any). */
191 bool
192 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
193 struct cgraph_node *node)
195 int index = lto_symtab_encoder_lookup (encoder, node);
196 return encoder->nodes[index].body;
199 /* Return TRUE if we should encode body of NODE (if any). */
201 static void
202 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder,
203 struct cgraph_node *node)
205 int index = lto_symtab_encoder_encode (encoder, node);
206 gcc_checking_assert (encoder->nodes[index].node == node);
207 encoder->nodes[index].body = true;
210 /* Return TRUE if we should encode initializer of NODE (if any). */
212 bool
213 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
214 varpool_node *node)
216 int index = lto_symtab_encoder_lookup (encoder, node);
217 if (index == LCC_NOT_FOUND)
218 return false;
219 return encoder->nodes[index].initializer;
222 /* Return TRUE if we should encode initializer of NODE (if any). */
224 static void
225 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
226 varpool_node *node)
228 int index = lto_symtab_encoder_lookup (encoder, node);
229 encoder->nodes[index].initializer = true;
232 /* Return TRUE if we should encode initializer of NODE (if any). */
234 bool
235 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
236 symtab_node *node)
238 int index = lto_symtab_encoder_lookup (encoder, node);
239 if (index == LCC_NOT_FOUND)
240 return false;
241 return encoder->nodes[index].in_partition;
244 /* Return TRUE if we should encode body of NODE (if any). */
246 void
247 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
248 symtab_node *node)
250 int index = lto_symtab_encoder_encode (encoder, node);
251 encoder->nodes[index].in_partition = true;
254 /* Output the cgraph EDGE to OB using ENCODER. */
256 static void
257 lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
258 lto_symtab_encoder_t encoder)
260 unsigned int uid;
261 intptr_t ref;
262 struct bitpack_d bp;
264 if (edge->indirect_unknown_callee)
265 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
266 LTO_symtab_indirect_edge);
267 else
268 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
269 LTO_symtab_edge);
271 ref = lto_symtab_encoder_lookup (encoder, edge->caller);
272 gcc_assert (ref != LCC_NOT_FOUND);
273 streamer_write_hwi_stream (ob->main_stream, ref);
275 if (!edge->indirect_unknown_callee)
277 ref = lto_symtab_encoder_lookup (encoder, edge->callee);
278 gcc_assert (ref != LCC_NOT_FOUND);
279 streamer_write_hwi_stream (ob->main_stream, ref);
282 streamer_write_gcov_count_stream (ob->main_stream, edge->count);
284 bp = bitpack_create (ob->main_stream);
285 uid = (!gimple_has_body_p (edge->caller->decl)
286 ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt) + 1);
287 bp_pack_enum (&bp, cgraph_inline_failed_t,
288 CIF_N_REASONS, edge->inline_failed);
289 bp_pack_var_len_unsigned (&bp, uid);
290 bp_pack_var_len_unsigned (&bp, edge->frequency);
291 bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
292 bp_pack_value (&bp, edge->speculative, 1);
293 bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
294 bp_pack_value (&bp, edge->can_throw_external, 1);
295 bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
296 if (edge->indirect_unknown_callee)
298 int flags = edge->indirect_info->ecf_flags;
299 bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
300 bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
301 bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
302 bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
303 bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
304 bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
305 /* Flags that should not appear on indirect calls. */
306 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
307 | ECF_MAY_BE_ALLOCA
308 | ECF_SIBCALL
309 | ECF_LEAF
310 | ECF_NOVOPS)));
312 streamer_write_bitpack (&bp);
313 if (edge->indirect_unknown_callee)
315 streamer_write_hwi_stream (ob->main_stream,
316 edge->indirect_info->common_target_id);
317 if (edge->indirect_info->common_target_id)
318 streamer_write_hwi_stream
319 (ob->main_stream, edge->indirect_info->common_target_probability);
323 /* Return if NODE contain references from other partitions. */
325 bool
326 referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
328 int i;
329 struct ipa_ref *ref = NULL;
331 for (i = 0; node->iterate_referring (i, ref); i++)
333 if (ref->referring->in_other_partition
334 || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
335 return true;
337 return false;
340 /* Return true when node is reachable from other partition. */
342 bool
343 reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
345 struct cgraph_edge *e;
346 if (!node->definition)
347 return false;
348 if (node->global.inlined_to)
349 return false;
350 for (e = node->callers; e; e = e->next_caller)
351 if (e->caller->in_other_partition
352 || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
353 return true;
354 return false;
357 /* Return if NODE contain references from other partitions. */
359 bool
360 referenced_from_this_partition_p (symtab_node *node,
361 lto_symtab_encoder_t encoder)
363 int i;
364 struct ipa_ref *ref = NULL;
366 for (i = 0; node->iterate_referring (i, ref); i++)
367 if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
368 return true;
369 return false;
372 /* Return true when node is reachable from other partition. */
374 bool
375 reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
377 struct cgraph_edge *e;
378 for (e = node->callers; e; e = e->next_caller)
379 if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
380 return true;
381 return false;
384 /* Output the cgraph NODE to OB. ENCODER is used to find the
385 reference number of NODE->inlined_to. SET is the set of nodes we
386 are writing to the current file. If NODE is not in SET, then NODE
387 is a boundary of a cgraph_node_set and we pretend NODE just has a
388 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
389 that have had their callgraph node written so far. This is used to
390 determine if NODE is a clone of a previously written node. */
392 static void
393 lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
394 lto_symtab_encoder_t encoder)
396 unsigned int tag;
397 struct bitpack_d bp;
398 bool boundary_p;
399 intptr_t ref;
400 bool in_other_partition = false;
401 struct cgraph_node *clone_of, *ultimate_clone_of;
402 ipa_opt_pass_d *pass;
403 int i;
404 bool alias_p;
405 const char *comdat;
406 const char *section;
407 tree group;
409 boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
411 if (node->analyzed && !boundary_p)
412 tag = LTO_symtab_analyzed_node;
413 else
414 tag = LTO_symtab_unavail_node;
416 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
417 tag);
418 streamer_write_hwi_stream (ob->main_stream, node->order);
420 /* In WPA mode, we only output part of the call-graph. Also, we
421 fake cgraph node attributes. There are two cases that we care.
423 Boundary nodes: There are nodes that are not part of SET but are
424 called from within SET. We artificially make them look like
425 externally visible nodes with no function body.
427 Cherry-picked nodes: These are nodes we pulled from other
428 translation units into SET during IPA-inlining. We make them as
429 local static nodes to prevent clashes with other local statics. */
430 if (boundary_p && node->analyzed
431 && node->get_partitioning_class () == SYMBOL_PARTITION)
433 /* Inline clones can not be part of boundary.
434 gcc_assert (!node->global.inlined_to);
436 FIXME: At the moment they can be, when partition contains an inline
437 clone that is clone of inline clone from outside partition. We can
438 reshape the clone tree and make other tree to be the root, but it
439 needs a bit extra work and will be promplty done by cgraph_remove_node
440 after reading back. */
441 in_other_partition = 1;
444 clone_of = node->clone_of;
445 while (clone_of
446 && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
447 if (clone_of->prev_sibling_clone)
448 clone_of = clone_of->prev_sibling_clone;
449 else
450 clone_of = clone_of->clone_of;
452 /* See if body of the master function is output. If not, we are seeing only
453 an declaration and we do not need to pass down clone tree. */
454 ultimate_clone_of = clone_of;
455 while (ultimate_clone_of && ultimate_clone_of->clone_of)
456 ultimate_clone_of = ultimate_clone_of->clone_of;
458 if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
459 clone_of = NULL;
461 if (tag == LTO_symtab_analyzed_node)
462 gcc_assert (clone_of || !node->clone_of);
463 if (!clone_of)
464 streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
465 else
466 streamer_write_hwi_stream (ob->main_stream, ref);
469 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
470 streamer_write_gcov_count_stream (ob->main_stream, node->count);
471 streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
473 streamer_write_hwi_stream (ob->main_stream,
474 node->ipa_transforms_to_apply.length ());
475 FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
476 streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
478 if (tag == LTO_symtab_analyzed_node)
480 if (node->global.inlined_to)
482 ref = lto_symtab_encoder_lookup (encoder, node->global.inlined_to);
483 gcc_assert (ref != LCC_NOT_FOUND);
485 else
486 ref = LCC_NOT_FOUND;
488 streamer_write_hwi_stream (ob->main_stream, ref);
491 group = node->get_comdat_group ();
492 if (group)
493 comdat = IDENTIFIER_POINTER (group);
494 else
495 comdat = "";
496 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
498 if (group)
500 if (node->same_comdat_group && !boundary_p)
502 ref = lto_symtab_encoder_lookup (encoder,
503 node->same_comdat_group);
504 gcc_assert (ref != LCC_NOT_FOUND);
506 else
507 ref = LCC_NOT_FOUND;
508 streamer_write_hwi_stream (ob->main_stream, ref);
511 section = node->get_section ();
512 if (!section)
513 section = "";
515 streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
517 bp = bitpack_create (ob->main_stream);
518 bp_pack_value (&bp, node->local.local, 1);
519 bp_pack_value (&bp, node->externally_visible, 1);
520 bp_pack_value (&bp, node->no_reorder, 1);
521 bp_pack_value (&bp, node->definition, 1);
522 bp_pack_value (&bp, node->local.versionable, 1);
523 bp_pack_value (&bp, node->local.can_change_signature, 1);
524 bp_pack_value (&bp, node->local.redefined_extern_inline, 1);
525 bp_pack_value (&bp, node->force_output, 1);
526 bp_pack_value (&bp, node->forced_by_abi, 1);
527 bp_pack_value (&bp, node->unique_name, 1);
528 bp_pack_value (&bp, node->body_removed, 1);
529 bp_pack_value (&bp, node->implicit_section, 1);
530 bp_pack_value (&bp, node->address_taken, 1);
531 bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
532 && node->get_partitioning_class () == SYMBOL_PARTITION
533 && (reachable_from_other_partition_p (node, encoder)
534 || referenced_from_other_partition_p (node, encoder)), 1);
535 bp_pack_value (&bp, node->lowered, 1);
536 bp_pack_value (&bp, in_other_partition, 1);
537 /* Real aliases in a boundary become non-aliases. However we still stream
538 alias info on weakrefs.
539 TODO: We lose a bit of information here - when we know that variable is
540 defined in other unit, we may use the info on aliases to resolve
541 symbol1 != symbol2 type tests that we can do only for locally defined objects
542 otherwise. */
543 alias_p = node->alias && (!boundary_p || node->weakref);
544 bp_pack_value (&bp, alias_p, 1);
545 bp_pack_value (&bp, node->weakref, 1);
546 bp_pack_value (&bp, node->frequency, 2);
547 bp_pack_value (&bp, node->only_called_at_startup, 1);
548 bp_pack_value (&bp, node->only_called_at_exit, 1);
549 bp_pack_value (&bp, node->tm_clone, 1);
550 bp_pack_value (&bp, node->calls_comdat_local, 1);
551 bp_pack_value (&bp, node->icf_merged, 1);
552 bp_pack_value (&bp, node->thunk.thunk_p && !boundary_p, 1);
553 bp_pack_enum (&bp, ld_plugin_symbol_resolution,
554 LDPR_NUM_KNOWN, node->resolution);
555 bp_pack_value (&bp, node->instrumentation_clone, 1);
556 streamer_write_bitpack (&bp);
557 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
559 if (node->thunk.thunk_p && !boundary_p)
561 streamer_write_uhwi_stream
562 (ob->main_stream,
563 1 + (node->thunk.this_adjusting != 0) * 2
564 + (node->thunk.virtual_offset_p != 0) * 4
565 + (node->thunk.add_pointer_bounds_args != 0) * 8);
566 streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset);
567 streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value);
569 streamer_write_hwi_stream (ob->main_stream, node->profile_id);
570 if (DECL_STATIC_CONSTRUCTOR (node->decl))
571 streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
572 if (DECL_STATIC_DESTRUCTOR (node->decl))
573 streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
575 if (node->instrumentation_clone)
576 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->orig_decl);
579 /* Output the varpool NODE to OB.
580 If NODE is not in SET, then NODE is a boundary. */
582 static void
583 lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
584 lto_symtab_encoder_t encoder)
586 bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
587 struct bitpack_d bp;
588 int ref;
589 bool alias_p;
590 const char *comdat;
591 const char *section;
592 tree group;
594 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
595 LTO_symtab_variable);
596 streamer_write_hwi_stream (ob->main_stream, node->order);
597 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl);
598 bp = bitpack_create (ob->main_stream);
599 bp_pack_value (&bp, node->externally_visible, 1);
600 bp_pack_value (&bp, node->no_reorder, 1);
601 bp_pack_value (&bp, node->force_output, 1);
602 bp_pack_value (&bp, node->forced_by_abi, 1);
603 bp_pack_value (&bp, node->unique_name, 1);
604 bp_pack_value (&bp, node->body_removed, 1);
605 bp_pack_value (&bp, node->implicit_section, 1);
606 bp_pack_value (&bp, node->writeonly, 1);
607 bp_pack_value (&bp, node->definition, 1);
608 alias_p = node->alias && (!boundary_p || node->weakref);
609 bp_pack_value (&bp, alias_p, 1);
610 bp_pack_value (&bp, node->weakref, 1);
611 bp_pack_value (&bp, node->analyzed && !boundary_p, 1);
612 gcc_assert (node->definition || !node->analyzed);
613 /* Constant pool initializers can be de-unified into individual ltrans units.
614 FIXME: Alternatively at -Os we may want to avoid generating for them the local
615 labels and share them across LTRANS partitions. */
616 if (node->get_partitioning_class () != SYMBOL_PARTITION)
618 bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */
619 bp_pack_value (&bp, 0, 1); /* in_other_partition. */
621 else
623 bp_pack_value (&bp, node->definition
624 && referenced_from_other_partition_p (node, encoder), 1);
625 bp_pack_value (&bp, node->analyzed
626 && boundary_p && !DECL_EXTERNAL (node->decl), 1);
627 /* in_other_partition. */
629 bp_pack_value (&bp, node->tls_model, 3);
630 bp_pack_value (&bp, node->used_by_single_function, 1);
631 bp_pack_value (&bp, node->need_bounds_init, 1);
632 streamer_write_bitpack (&bp);
634 group = node->get_comdat_group ();
635 if (group)
636 comdat = IDENTIFIER_POINTER (group);
637 else
638 comdat = "";
639 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
641 if (group)
643 if (node->same_comdat_group && !boundary_p)
645 ref = lto_symtab_encoder_lookup (encoder,
646 node->same_comdat_group);
647 gcc_assert (ref != LCC_NOT_FOUND);
649 else
650 ref = LCC_NOT_FOUND;
651 streamer_write_hwi_stream (ob->main_stream, ref);
654 section = node->get_section ();
655 if (!section)
656 section = "";
657 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
659 streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
660 LDPR_NUM_KNOWN, node->resolution);
663 /* Output the varpool NODE to OB.
664 If NODE is not in SET, then NODE is a boundary. */
666 static void
667 lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
668 lto_symtab_encoder_t encoder)
670 struct bitpack_d bp;
671 int nref;
672 int uid = ref->lto_stmt_uid;
673 struct cgraph_node *node;
675 bp = bitpack_create (ob->main_stream);
676 bp_pack_value (&bp, ref->use, 3);
677 bp_pack_value (&bp, ref->speculative, 1);
678 streamer_write_bitpack (&bp);
679 nref = lto_symtab_encoder_lookup (encoder, ref->referred);
680 gcc_assert (nref != LCC_NOT_FOUND);
681 streamer_write_hwi_stream (ob->main_stream, nref);
683 node = dyn_cast <cgraph_node *> (ref->referring);
684 if (node)
686 if (ref->stmt)
687 uid = gimple_uid (ref->stmt) + 1;
688 streamer_write_hwi_stream (ob->main_stream, uid);
692 /* Stream out profile_summary to OB. */
694 static void
695 output_profile_summary (struct lto_simple_output_block *ob)
697 unsigned h_ix;
698 struct bitpack_d bp;
700 if (profile_info)
702 /* We do not output num and run_max, they are not used by
703 GCC profile feedback and they are difficult to merge from multiple
704 units. */
705 gcc_assert (profile_info->runs);
706 streamer_write_uhwi_stream (ob->main_stream, profile_info->runs);
707 streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_max);
709 /* sum_all is needed for computing the working set with the
710 histogram. */
711 streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_all);
713 /* Create and output a bitpack of non-zero histogram entries indices. */
714 bp = bitpack_create (ob->main_stream);
715 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
716 bp_pack_value (&bp, profile_info->histogram[h_ix].num_counters > 0, 1);
717 streamer_write_bitpack (&bp);
718 /* Now stream out only those non-zero entries. */
719 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
721 if (!profile_info->histogram[h_ix].num_counters)
722 continue;
723 streamer_write_gcov_count_stream (ob->main_stream,
724 profile_info->histogram[h_ix].num_counters);
725 streamer_write_gcov_count_stream (ob->main_stream,
726 profile_info->histogram[h_ix].min_value);
727 streamer_write_gcov_count_stream (ob->main_stream,
728 profile_info->histogram[h_ix].cum_value);
730 /* IPA-profile computes hot bb threshold based on cumulated
731 whole program profile. We need to stream it down to ltrans. */
732 if (flag_wpa)
733 streamer_write_gcov_count_stream (ob->main_stream,
734 get_hot_bb_threshold ());
736 else
737 streamer_write_uhwi_stream (ob->main_stream, 0);
740 /* Output all callees or indirect outgoing edges. EDGE must be the first such
741 edge. */
743 static void
744 output_outgoing_cgraph_edges (struct cgraph_edge *edge,
745 struct lto_simple_output_block *ob,
746 lto_symtab_encoder_t encoder)
748 if (!edge)
749 return;
751 /* Output edges in backward direction, so the reconstructed callgraph match
752 and it is easy to associate call sites in the IPA pass summaries. */
753 while (edge->next_callee)
754 edge = edge->next_callee;
755 for (; edge; edge = edge->prev_callee)
756 lto_output_edge (ob, edge, encoder);
759 /* Output the part of the cgraph in SET. */
761 static void
762 output_refs (lto_symtab_encoder_t encoder)
764 lto_symtab_encoder_iterator lsei;
765 struct lto_simple_output_block *ob;
766 int count;
767 struct ipa_ref *ref;
768 int i;
770 ob = lto_create_simple_output_block (LTO_section_refs);
772 for (lsei = lsei_start_in_partition (encoder); !lsei_end_p (lsei);
773 lsei_next_in_partition (&lsei))
775 symtab_node *node = lsei_node (lsei);
777 count = node->ref_list.nreferences ();
778 if (count)
780 streamer_write_gcov_count_stream (ob->main_stream, count);
781 streamer_write_uhwi_stream (ob->main_stream,
782 lto_symtab_encoder_lookup (encoder, node));
783 for (i = 0; node->iterate_reference (i, ref); i++)
784 lto_output_ref (ob, ref, encoder);
788 streamer_write_uhwi_stream (ob->main_stream, 0);
790 lto_destroy_simple_output_block (ob);
793 /* Add NODE into encoder as well as nodes it is cloned from.
794 Do it in a way so clones appear first. */
796 static void
797 add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
798 bool include_body)
800 if (node->clone_of)
801 add_node_to (encoder, node->clone_of, include_body);
802 else if (include_body)
803 lto_set_symtab_encoder_encode_body (encoder, node);
804 lto_symtab_encoder_encode (encoder, node);
807 /* Add all references in NODE to encoders. */
809 static void
810 create_references (lto_symtab_encoder_t encoder, symtab_node *node)
812 int i;
813 struct ipa_ref *ref = NULL;
814 for (i = 0; node->iterate_reference (i, ref); i++)
815 if (is_a <cgraph_node *> (ref->referred))
816 add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
817 else
818 lto_symtab_encoder_encode (encoder, ref->referred);
821 /* Find all symbols we want to stream into given partition and insert them
822 to encoders.
824 The function actually replaces IN_ENCODER by new one. The reason is that
825 streaming code needs clone's origin to be streamed before clone. This
826 means that we need to insert the nodes in specific order. This order is
827 ignored by the partitioning logic earlier. */
829 lto_symtab_encoder_t
830 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
832 struct cgraph_edge *edge;
833 int i;
834 lto_symtab_encoder_t encoder;
835 lto_symtab_encoder_iterator lsei;
836 hash_set<void *> reachable_call_targets;
838 encoder = lto_symtab_encoder_new (false);
840 /* Go over all entries in the IN_ENCODER and duplicate them to
841 ENCODER. At the same time insert masters of clones so
842 every master appears before clone. */
843 for (lsei = lsei_start_function_in_partition (in_encoder);
844 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
846 struct cgraph_node *node = lsei_cgraph_node (lsei);
847 add_node_to (encoder, node, true);
848 lto_set_symtab_encoder_in_partition (encoder, node);
849 create_references (encoder, node);
850 /* For proper debug info, we need to ship the origins, too. */
851 if (DECL_ABSTRACT_ORIGIN (node->decl))
853 struct cgraph_node *origin_node
854 = cgraph_node::get (DECL_ABSTRACT_ORIGIN (node->decl));
855 add_node_to (encoder, origin_node, true);
858 for (lsei = lsei_start_variable_in_partition (in_encoder);
859 !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
861 varpool_node *vnode = lsei_varpool_node (lsei);
863 lto_set_symtab_encoder_in_partition (encoder, vnode);
864 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
865 create_references (encoder, vnode);
866 /* For proper debug info, we need to ship the origins, too. */
867 if (DECL_ABSTRACT_ORIGIN (vnode->decl))
869 varpool_node *origin_node
870 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode->decl));
871 lto_set_symtab_encoder_in_partition (encoder, origin_node);
874 /* Pickle in also the initializer of all referenced readonly variables
875 to help folding. Constant pool variables are not shared, so we must
876 pickle those too. */
877 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
879 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
880 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
882 if (!lto_symtab_encoder_encode_initializer_p (encoder,
883 vnode)
884 && (vnode->ctor_useable_for_folding_p ()
885 || POINTER_BOUNDS_P (vnode->decl)))
887 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
888 create_references (encoder, vnode);
893 /* Go over all the nodes again to include callees that are not in
894 SET. */
895 for (lsei = lsei_start_function_in_partition (encoder);
896 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
898 struct cgraph_node *node = lsei_cgraph_node (lsei);
899 for (edge = node->callees; edge; edge = edge->next_callee)
901 struct cgraph_node *callee = edge->callee;
902 if (!lto_symtab_encoder_in_partition_p (encoder, callee))
904 /* We should have moved all the inlines. */
905 gcc_assert (!callee->global.inlined_to);
906 add_node_to (encoder, callee, false);
909 /* Add all possible targets for late devirtualization. */
910 if (flag_devirtualize)
911 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
912 if (edge->indirect_info->polymorphic)
914 unsigned int i;
915 void *cache_token;
916 bool final;
917 vec <cgraph_node *>targets
918 = possible_polymorphic_call_targets
919 (edge, &final, &cache_token);
920 if (!reachable_call_targets.add (cache_token))
922 for (i = 0; i < targets.length (); i++)
924 struct cgraph_node *callee = targets[i];
926 /* Adding an external declarations into the unit serves
927 no purpose and just increases its boundary. */
928 if (callee->definition
929 && !lto_symtab_encoder_in_partition_p
930 (encoder, callee))
932 gcc_assert (!callee->global.inlined_to);
933 add_node_to (encoder, callee, false);
939 lto_symtab_encoder_delete (in_encoder);
940 return encoder;
943 /* Output the part of the symtab in SET and VSET. */
945 void
946 output_symtab (void)
948 struct cgraph_node *node;
949 struct lto_simple_output_block *ob;
950 lto_symtab_encoder_iterator lsei;
951 int i, n_nodes;
952 lto_symtab_encoder_t encoder;
954 if (flag_wpa)
955 output_cgraph_opt_summary ();
957 ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
959 output_profile_summary (ob);
961 /* An encoder for cgraph nodes should have been created by
962 ipa_write_summaries_1. */
963 gcc_assert (ob->decl_state->symtab_node_encoder);
964 encoder = ob->decl_state->symtab_node_encoder;
966 /* Write out the nodes. We must first output a node and then its clones,
967 otherwise at a time reading back the node there would be nothing to clone
968 from. */
969 n_nodes = lto_symtab_encoder_size (encoder);
970 for (i = 0; i < n_nodes; i++)
972 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
973 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
974 lto_output_node (ob, cnode, encoder);
975 else
976 lto_output_varpool_node (ob, dyn_cast<varpool_node *> (node), encoder);
979 /* Go over the nodes in SET again to write edges. */
980 for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
981 lsei_next_function_in_partition (&lsei))
983 node = lsei_cgraph_node (lsei);
984 output_outgoing_cgraph_edges (node->callees, ob, encoder);
985 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
988 streamer_write_uhwi_stream (ob->main_stream, 0);
990 lto_destroy_simple_output_block (ob);
992 /* Emit toplevel asms.
993 When doing WPA we must output every asm just once. Since we do not partition asm
994 nodes at all, output them to first output. This is kind of hack, but should work
995 well. */
996 if (!asm_nodes_output)
998 asm_nodes_output = true;
999 lto_output_toplevel_asms ();
1002 output_refs (encoder);
1005 /* Return identifier encoded in IB as a plain string. */
1007 static tree
1008 read_identifier (struct lto_input_block *ib)
1010 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1011 tree id;
1013 if (ib->data[ib->p + len])
1014 lto_section_overrun (ib);
1015 if (!len)
1017 ib->p++;
1018 return NULL;
1020 id = get_identifier (ib->data + ib->p);
1021 ib->p += len + 1;
1022 return id;
1025 /* Return string encoded in IB, NULL if string is empty. */
1027 static const char *
1028 read_string (struct lto_input_block *ib)
1030 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1031 const char *str;
1033 if (ib->data[ib->p + len])
1034 lto_section_overrun (ib);
1035 if (!len)
1037 ib->p++;
1038 return NULL;
1040 str = ib->data + ib->p;
1041 ib->p += len + 1;
1042 return str;
1045 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1046 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1047 NODE or to replace the values in it, for instance because the first
1048 time we saw it, the function body was not available but now it
1049 is. BP is a bitpack with all the bitflags for NODE read from the
1050 stream. */
1052 static void
1053 input_overwrite_node (struct lto_file_decl_data *file_data,
1054 struct cgraph_node *node,
1055 enum LTO_symtab_tags tag,
1056 struct bitpack_d *bp)
1058 node->aux = (void *) tag;
1059 node->lto_file_data = file_data;
1061 node->local.local = bp_unpack_value (bp, 1);
1062 node->externally_visible = bp_unpack_value (bp, 1);
1063 node->no_reorder = bp_unpack_value (bp, 1);
1064 node->definition = bp_unpack_value (bp, 1);
1065 node->local.versionable = bp_unpack_value (bp, 1);
1066 node->local.can_change_signature = bp_unpack_value (bp, 1);
1067 node->local.redefined_extern_inline = bp_unpack_value (bp, 1);
1068 node->force_output = bp_unpack_value (bp, 1);
1069 node->forced_by_abi = bp_unpack_value (bp, 1);
1070 node->unique_name = bp_unpack_value (bp, 1);
1071 node->body_removed = bp_unpack_value (bp, 1);
1072 node->implicit_section = bp_unpack_value (bp, 1);
1073 node->address_taken = bp_unpack_value (bp, 1);
1074 node->used_from_other_partition = bp_unpack_value (bp, 1);
1075 node->lowered = bp_unpack_value (bp, 1);
1076 node->analyzed = tag == LTO_symtab_analyzed_node;
1077 node->in_other_partition = bp_unpack_value (bp, 1);
1078 if (node->in_other_partition
1079 /* Avoid updating decl when we are seeing just inline clone.
1080 When inlining function that has functions already inlined into it,
1081 we produce clones of inline clones.
1083 WPA partitioning might put each clone into different unit and
1084 we might end up streaming inline clone from other partition
1085 to support clone we are interested in. */
1086 && (!node->clone_of
1087 || node->clone_of->decl != node->decl))
1089 DECL_EXTERNAL (node->decl) = 1;
1090 TREE_STATIC (node->decl) = 0;
1092 node->alias = bp_unpack_value (bp, 1);
1093 node->weakref = bp_unpack_value (bp, 1);
1094 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
1095 node->only_called_at_startup = bp_unpack_value (bp, 1);
1096 node->only_called_at_exit = bp_unpack_value (bp, 1);
1097 node->tm_clone = bp_unpack_value (bp, 1);
1098 node->calls_comdat_local = bp_unpack_value (bp, 1);
1099 node->icf_merged = bp_unpack_value (bp, 1);
1100 node->thunk.thunk_p = bp_unpack_value (bp, 1);
1101 node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
1102 LDPR_NUM_KNOWN);
1103 node->instrumentation_clone = bp_unpack_value (bp, 1);
1104 gcc_assert (flag_ltrans
1105 || (!node->in_other_partition
1106 && !node->used_from_other_partition));
1109 /* Return string alias is alias of. */
1111 static tree
1112 get_alias_symbol (tree decl)
1114 tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1115 return get_identifier (TREE_STRING_POINTER
1116 (TREE_VALUE (TREE_VALUE (alias))));
1119 /* Read a node from input_block IB. TAG is the node's tag just read.
1120 Return the node read or overwriten. */
1122 static struct cgraph_node *
1123 input_node (struct lto_file_decl_data *file_data,
1124 struct lto_input_block *ib,
1125 enum LTO_symtab_tags tag,
1126 vec<symtab_node *> nodes)
1128 gcc::pass_manager *passes = g->get_passes ();
1129 tree fn_decl;
1130 struct cgraph_node *node;
1131 struct bitpack_d bp;
1132 unsigned decl_index;
1133 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
1134 int clone_ref;
1135 int order;
1136 int i, count;
1137 tree group;
1138 const char *section;
1139 order = streamer_read_hwi (ib) + order_base;
1140 clone_ref = streamer_read_hwi (ib);
1142 decl_index = streamer_read_uhwi (ib);
1143 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1145 if (clone_ref != LCC_NOT_FOUND)
1147 node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
1148 0, CGRAPH_FREQ_BASE, false,
1149 vNULL, false, NULL, NULL);
1151 else
1153 /* Declaration of functions can be already merged with a declaration
1154 from other input file. We keep cgraph unmerged until after streaming
1155 of ipa passes is done. Alays forcingly create a fresh node. */
1156 node = symtab->create_empty ();
1157 node->decl = fn_decl;
1158 node->register_symbol ();
1161 node->order = order;
1162 if (order >= symtab->order)
1163 symtab->order = order + 1;
1165 node->count = streamer_read_gcov_count (ib);
1166 node->count_materialization_scale = streamer_read_hwi (ib);
1168 count = streamer_read_hwi (ib);
1169 node->ipa_transforms_to_apply = vNULL;
1170 for (i = 0; i < count; i++)
1172 opt_pass *pass;
1173 int pid = streamer_read_hwi (ib);
1175 gcc_assert (pid < passes->passes_by_id_size);
1176 pass = passes->passes_by_id[pid];
1177 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
1180 if (tag == LTO_symtab_analyzed_node)
1181 ref = streamer_read_hwi (ib);
1183 group = read_identifier (ib);
1184 if (group)
1185 ref2 = streamer_read_hwi (ib);
1187 /* Make sure that we have not read this node before. Nodes that
1188 have already been read will have their tag stored in the 'aux'
1189 field. Since built-in functions can be referenced in multiple
1190 functions, they are expected to be read more than once. */
1191 if (node->aux && !DECL_BUILT_IN (node->decl))
1192 internal_error ("bytecode stream: found multiple instances of cgraph "
1193 "node with uid %d", node->uid);
1195 node->tp_first_run = streamer_read_uhwi (ib);
1197 bp = streamer_read_bitpack (ib);
1199 input_overwrite_node (file_data, node, tag, &bp);
1201 /* Store a reference for now, and fix up later to be a pointer. */
1202 node->global.inlined_to = (cgraph_node *) (intptr_t) ref;
1204 if (group)
1206 node->set_comdat_group (group);
1207 /* Store a reference for now, and fix up later to be a pointer. */
1208 node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
1210 else
1211 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1212 section = read_string (ib);
1213 if (section)
1214 node->set_section_for_node (section);
1216 if (node->thunk.thunk_p)
1218 int type = streamer_read_uhwi (ib);
1219 HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
1220 HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib);
1222 node->thunk.fixed_offset = fixed_offset;
1223 node->thunk.this_adjusting = (type & 2);
1224 node->thunk.virtual_value = virtual_value;
1225 node->thunk.virtual_offset_p = (type & 4);
1226 node->thunk.add_pointer_bounds_args = (type & 8);
1228 if (node->alias && !node->analyzed && node->weakref)
1229 node->alias_target = get_alias_symbol (node->decl);
1230 node->profile_id = streamer_read_hwi (ib);
1231 if (DECL_STATIC_CONSTRUCTOR (node->decl))
1232 node->set_init_priority (streamer_read_hwi (ib));
1233 if (DECL_STATIC_DESTRUCTOR (node->decl))
1234 node->set_fini_priority (streamer_read_hwi (ib));
1236 if (node->instrumentation_clone)
1238 decl_index = streamer_read_uhwi (ib);
1239 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1240 node->orig_decl = fn_decl;
1243 return node;
1246 /* Read a node from input_block IB. TAG is the node's tag just read.
1247 Return the node read or overwriten. */
1249 static varpool_node *
1250 input_varpool_node (struct lto_file_decl_data *file_data,
1251 struct lto_input_block *ib)
1253 int decl_index;
1254 tree var_decl;
1255 varpool_node *node;
1256 struct bitpack_d bp;
1257 int ref = LCC_NOT_FOUND;
1258 int order;
1259 tree group;
1260 const char *section;
1262 order = streamer_read_hwi (ib) + order_base;
1263 decl_index = streamer_read_uhwi (ib);
1264 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
1266 /* Declaration of functions can be already merged with a declaration
1267 from other input file. We keep cgraph unmerged until after streaming
1268 of ipa passes is done. Alays forcingly create a fresh node. */
1269 node = varpool_node::create_empty ();
1270 node->decl = var_decl;
1271 node->register_symbol ();
1273 node->order = order;
1274 if (order >= symtab->order)
1275 symtab->order = order + 1;
1276 node->lto_file_data = file_data;
1278 bp = streamer_read_bitpack (ib);
1279 node->externally_visible = bp_unpack_value (&bp, 1);
1280 node->no_reorder = bp_unpack_value (&bp, 1);
1281 node->force_output = bp_unpack_value (&bp, 1);
1282 node->forced_by_abi = bp_unpack_value (&bp, 1);
1283 node->unique_name = bp_unpack_value (&bp, 1);
1284 node->body_removed = bp_unpack_value (&bp, 1);
1285 node->implicit_section = bp_unpack_value (&bp, 1);
1286 node->writeonly = bp_unpack_value (&bp, 1);
1287 node->definition = bp_unpack_value (&bp, 1);
1288 node->alias = bp_unpack_value (&bp, 1);
1289 node->weakref = bp_unpack_value (&bp, 1);
1290 node->analyzed = bp_unpack_value (&bp, 1);
1291 node->used_from_other_partition = bp_unpack_value (&bp, 1);
1292 node->in_other_partition = bp_unpack_value (&bp, 1);
1293 if (node->in_other_partition)
1295 DECL_EXTERNAL (node->decl) = 1;
1296 TREE_STATIC (node->decl) = 0;
1298 if (node->alias && !node->analyzed && node->weakref)
1299 node->alias_target = get_alias_symbol (node->decl);
1300 node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
1301 node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
1302 node->need_bounds_init = bp_unpack_value (&bp, 1);
1303 group = read_identifier (ib);
1304 if (group)
1306 node->set_comdat_group (group);
1307 ref = streamer_read_hwi (ib);
1308 /* Store a reference for now, and fix up later to be a pointer. */
1309 node->same_comdat_group = (symtab_node *) (intptr_t) ref;
1311 else
1312 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1313 section = read_string (ib);
1314 if (section)
1315 node->set_section_for_node (section);
1316 node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
1317 LDPR_NUM_KNOWN);
1318 gcc_assert (flag_ltrans
1319 || (!node->in_other_partition
1320 && !node->used_from_other_partition));
1322 return node;
1325 /* Read a node from input_block IB. TAG is the node's tag just read.
1326 Return the node read or overwriten. */
1328 static void
1329 input_ref (struct lto_input_block *ib,
1330 symtab_node *referring_node,
1331 vec<symtab_node *> nodes)
1333 symtab_node *node = NULL;
1334 struct bitpack_d bp;
1335 enum ipa_ref_use use;
1336 bool speculative;
1337 struct ipa_ref *ref;
1339 bp = streamer_read_bitpack (ib);
1340 use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
1341 speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
1342 node = nodes[streamer_read_hwi (ib)];
1343 ref = referring_node->create_reference (node, use);
1344 ref->speculative = speculative;
1345 if (is_a <cgraph_node *> (referring_node))
1346 ref->lto_stmt_uid = streamer_read_hwi (ib);
1349 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1350 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1351 edge being read is indirect (in the sense that it has
1352 indirect_unknown_callee set). */
1354 static void
1355 input_edge (struct lto_input_block *ib, vec<symtab_node *> nodes,
1356 bool indirect)
1358 struct cgraph_node *caller, *callee;
1359 struct cgraph_edge *edge;
1360 unsigned int stmt_id;
1361 gcov_type count;
1362 int freq;
1363 cgraph_inline_failed_t inline_failed;
1364 struct bitpack_d bp;
1365 int ecf_flags = 0;
1367 caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1368 if (caller == NULL || caller->decl == NULL_TREE)
1369 internal_error ("bytecode stream: no caller found while reading edge");
1371 if (!indirect)
1373 callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1374 if (callee == NULL || callee->decl == NULL_TREE)
1375 internal_error ("bytecode stream: no callee found while reading edge");
1377 else
1378 callee = NULL;
1380 count = streamer_read_gcov_count (ib);
1382 bp = streamer_read_bitpack (ib);
1383 inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
1384 stmt_id = bp_unpack_var_len_unsigned (&bp);
1385 freq = (int) bp_unpack_var_len_unsigned (&bp);
1387 if (indirect)
1388 edge = caller->create_indirect_edge (NULL, 0, count, freq);
1389 else
1390 edge = caller->create_edge (callee, NULL, count, freq);
1392 edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
1393 edge->speculative = bp_unpack_value (&bp, 1);
1394 edge->lto_stmt_uid = stmt_id;
1395 edge->inline_failed = inline_failed;
1396 edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1397 edge->can_throw_external = bp_unpack_value (&bp, 1);
1398 edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
1399 if (indirect)
1401 if (bp_unpack_value (&bp, 1))
1402 ecf_flags |= ECF_CONST;
1403 if (bp_unpack_value (&bp, 1))
1404 ecf_flags |= ECF_PURE;
1405 if (bp_unpack_value (&bp, 1))
1406 ecf_flags |= ECF_NORETURN;
1407 if (bp_unpack_value (&bp, 1))
1408 ecf_flags |= ECF_MALLOC;
1409 if (bp_unpack_value (&bp, 1))
1410 ecf_flags |= ECF_NOTHROW;
1411 if (bp_unpack_value (&bp, 1))
1412 ecf_flags |= ECF_RETURNS_TWICE;
1413 edge->indirect_info->ecf_flags = ecf_flags;
1414 edge->indirect_info->common_target_id = streamer_read_hwi (ib);
1415 if (edge->indirect_info->common_target_id)
1416 edge->indirect_info->common_target_probability = streamer_read_hwi (ib);
1421 /* Read a cgraph from IB using the info in FILE_DATA. */
1423 static vec<symtab_node *>
1424 input_cgraph_1 (struct lto_file_decl_data *file_data,
1425 struct lto_input_block *ib)
1427 enum LTO_symtab_tags tag;
1428 vec<symtab_node *> nodes = vNULL;
1429 symtab_node *node;
1430 unsigned i;
1432 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1433 order_base = symtab->order;
1434 while (tag)
1436 if (tag == LTO_symtab_edge)
1437 input_edge (ib, nodes, false);
1438 else if (tag == LTO_symtab_indirect_edge)
1439 input_edge (ib, nodes, true);
1440 else if (tag == LTO_symtab_variable)
1442 node = input_varpool_node (file_data, ib);
1443 nodes.safe_push (node);
1444 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1446 else
1448 node = input_node (file_data, ib, tag, nodes);
1449 if (node == NULL || node->decl == NULL_TREE)
1450 internal_error ("bytecode stream: found empty cgraph node");
1451 nodes.safe_push (node);
1452 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1455 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1458 lto_input_toplevel_asms (file_data, order_base);
1460 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1461 #ifdef ENABLE_CHECKING
1462 FOR_EACH_VEC_ELT (nodes, i, node)
1463 gcc_assert (node->aux || !is_a <cgraph_node *> (node));
1464 #endif
1465 FOR_EACH_VEC_ELT (nodes, i, node)
1467 int ref;
1468 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
1470 ref = (int) (intptr_t) cnode->global.inlined_to;
1472 /* We share declaration of builtins, so we may read same node twice. */
1473 if (!node->aux)
1474 continue;
1475 node->aux = NULL;
1477 /* Fixup inlined_to from reference to pointer. */
1478 if (ref != LCC_NOT_FOUND)
1479 dyn_cast<cgraph_node *> (node)->global.inlined_to
1480 = dyn_cast<cgraph_node *> (nodes[ref]);
1481 else
1482 cnode->global.inlined_to = NULL;
1484 /* Compute instrumented_version. */
1485 if (cnode->instrumentation_clone)
1487 gcc_assert (cnode->orig_decl);
1489 cnode->instrumented_version = cgraph_node::get (cnode->orig_decl);
1490 if (cnode->instrumented_version)
1491 cnode->instrumented_version->instrumented_version = cnode;
1493 /* Restore decl names reference. */
1494 if (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (cnode->decl))
1495 && !TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode->decl)))
1496 TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode->decl))
1497 = DECL_ASSEMBLER_NAME (cnode->orig_decl);
1501 ref = (int) (intptr_t) node->same_comdat_group;
1503 /* Fixup same_comdat_group from reference to pointer. */
1504 if (ref != LCC_NOT_FOUND)
1505 node->same_comdat_group = nodes[ref];
1506 else
1507 node->same_comdat_group = NULL;
1509 FOR_EACH_VEC_ELT (nodes, i, node)
1510 node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
1511 return nodes;
1514 /* Input ipa_refs. */
1516 static void
1517 input_refs (struct lto_input_block *ib,
1518 vec<symtab_node *> nodes)
1520 int count;
1521 int idx;
1522 while (true)
1524 symtab_node *node;
1525 count = streamer_read_uhwi (ib);
1526 if (!count)
1527 break;
1528 idx = streamer_read_uhwi (ib);
1529 node = nodes[idx];
1530 while (count)
1532 input_ref (ib, node, nodes);
1533 count--;
1539 static struct gcov_ctr_summary lto_gcov_summary;
1541 /* Input profile_info from IB. */
1542 static void
1543 input_profile_summary (struct lto_input_block *ib,
1544 struct lto_file_decl_data *file_data)
1546 unsigned h_ix;
1547 struct bitpack_d bp;
1548 unsigned int runs = streamer_read_uhwi (ib);
1549 if (runs)
1551 file_data->profile_info.runs = runs;
1552 file_data->profile_info.sum_max = streamer_read_gcov_count (ib);
1553 file_data->profile_info.sum_all = streamer_read_gcov_count (ib);
1555 memset (file_data->profile_info.histogram, 0,
1556 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
1557 /* Input the bitpack of non-zero histogram indices. */
1558 bp = streamer_read_bitpack (ib);
1559 /* Read in and unpack the full bitpack, flagging non-zero
1560 histogram entries by setting the num_counters non-zero. */
1561 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1563 file_data->profile_info.histogram[h_ix].num_counters
1564 = bp_unpack_value (&bp, 1);
1566 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1568 if (!file_data->profile_info.histogram[h_ix].num_counters)
1569 continue;
1571 file_data->profile_info.histogram[h_ix].num_counters
1572 = streamer_read_gcov_count (ib);
1573 file_data->profile_info.histogram[h_ix].min_value
1574 = streamer_read_gcov_count (ib);
1575 file_data->profile_info.histogram[h_ix].cum_value
1576 = streamer_read_gcov_count (ib);
1578 /* IPA-profile computes hot bb threshold based on cumulated
1579 whole program profile. We need to stream it down to ltrans. */
1580 if (flag_ltrans)
1581 set_hot_bb_threshold (streamer_read_gcov_count (ib));
1586 /* Rescale profile summaries to the same number of runs in the whole unit. */
1588 static void
1589 merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1591 struct lto_file_decl_data *file_data;
1592 unsigned int j, h_ix;
1593 gcov_unsigned_t max_runs = 0;
1594 struct cgraph_node *node;
1595 struct cgraph_edge *edge;
1596 gcov_type saved_sum_all = 0;
1597 gcov_ctr_summary *saved_profile_info = 0;
1598 int saved_scale = 0;
1600 /* Find unit with maximal number of runs. If we ever get serious about
1601 roundoff errors, we might also consider computing smallest common
1602 multiply. */
1603 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1604 if (max_runs < file_data->profile_info.runs)
1605 max_runs = file_data->profile_info.runs;
1607 if (!max_runs)
1608 return;
1610 /* Simple overflow check. We probably don't need to support that many train
1611 runs. Such a large value probably imply data corruption anyway. */
1612 if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1614 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1615 INT_MAX / REG_BR_PROB_BASE);
1616 return;
1619 profile_info = &lto_gcov_summary;
1620 lto_gcov_summary.runs = max_runs;
1621 lto_gcov_summary.sum_max = 0;
1622 memset (lto_gcov_summary.histogram, 0,
1623 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
1625 /* Rescale all units to the maximal number of runs.
1626 sum_max can not be easily merged, as we have no idea what files come from
1627 the same run. We do not use the info anyway, so leave it 0. */
1628 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1629 if (file_data->profile_info.runs)
1631 int scale = GCOV_COMPUTE_SCALE (max_runs,
1632 file_data->profile_info.runs);
1633 lto_gcov_summary.sum_max
1634 = MAX (lto_gcov_summary.sum_max,
1635 apply_scale (file_data->profile_info.sum_max, scale));
1636 lto_gcov_summary.sum_all
1637 = MAX (lto_gcov_summary.sum_all,
1638 apply_scale (file_data->profile_info.sum_all, scale));
1639 /* Save a pointer to the profile_info with the largest
1640 scaled sum_all and the scale for use in merging the
1641 histogram. */
1642 if (!saved_profile_info
1643 || lto_gcov_summary.sum_all > saved_sum_all)
1645 saved_profile_info = &file_data->profile_info;
1646 saved_sum_all = lto_gcov_summary.sum_all;
1647 saved_scale = scale;
1651 gcc_assert (saved_profile_info);
1653 /* Scale up the histogram from the profile that had the largest
1654 scaled sum_all above. */
1655 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1657 /* Scale up the min value as we did the corresponding sum_all
1658 above. Use that to find the new histogram index. */
1659 gcov_type scaled_min
1660 = apply_scale (saved_profile_info->histogram[h_ix].min_value,
1661 saved_scale);
1662 /* The new index may be shared with another scaled histogram entry,
1663 so we need to account for a non-zero histogram entry at new_ix. */
1664 unsigned new_ix = gcov_histo_index (scaled_min);
1665 lto_gcov_summary.histogram[new_ix].min_value
1666 = (lto_gcov_summary.histogram[new_ix].num_counters
1667 ? MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min)
1668 : scaled_min);
1669 /* Some of the scaled counter values would ostensibly need to be placed
1670 into different (larger) histogram buckets, but we keep things simple
1671 here and place the scaled cumulative counter value in the bucket
1672 corresponding to the scaled minimum counter value. */
1673 lto_gcov_summary.histogram[new_ix].cum_value
1674 += apply_scale (saved_profile_info->histogram[h_ix].cum_value,
1675 saved_scale);
1676 lto_gcov_summary.histogram[new_ix].num_counters
1677 += saved_profile_info->histogram[h_ix].num_counters;
1680 /* Watch roundoff errors. */
1681 if (lto_gcov_summary.sum_max < max_runs)
1682 lto_gcov_summary.sum_max = max_runs;
1684 /* If merging already happent at WPA time, we are done. */
1685 if (flag_ltrans)
1686 return;
1688 /* Now compute count_materialization_scale of each node.
1689 During LTRANS we already have values of count_materialization_scale
1690 computed, so just update them. */
1691 FOR_EACH_FUNCTION (node)
1692 if (node->lto_file_data
1693 && node->lto_file_data->profile_info.runs)
1695 int scale;
1697 scale = RDIV (node->count_materialization_scale * max_runs,
1698 node->lto_file_data->profile_info.runs);
1699 node->count_materialization_scale = scale;
1700 if (scale < 0)
1701 fatal_error ("Profile information in %s corrupted",
1702 file_data->file_name);
1704 if (scale == REG_BR_PROB_BASE)
1705 continue;
1706 for (edge = node->callees; edge; edge = edge->next_callee)
1707 edge->count = apply_scale (edge->count, scale);
1708 node->count = apply_scale (node->count, scale);
1712 /* Input and merge the symtab from each of the .o files passed to
1713 lto1. */
1715 void
1716 input_symtab (void)
1718 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1719 struct lto_file_decl_data *file_data;
1720 unsigned int j = 0;
1721 struct cgraph_node *node;
1723 while ((file_data = file_data_vec[j++]))
1725 const char *data;
1726 size_t len;
1727 struct lto_input_block *ib;
1728 vec<symtab_node *> nodes;
1730 ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
1731 &data, &len);
1732 if (!ib)
1733 fatal_error ("cannot find LTO cgraph in %s", file_data->file_name);
1734 input_profile_summary (ib, file_data);
1735 file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
1736 nodes = input_cgraph_1 (file_data, ib);
1737 lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
1738 ib, data, len);
1740 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1741 &data, &len);
1742 if (!ib)
1743 fatal_error ("cannot find LTO section refs in %s",
1744 file_data->file_name);
1745 input_refs (ib, nodes);
1746 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1747 ib, data, len);
1748 if (flag_ltrans)
1749 input_cgraph_opt_summary (nodes);
1750 nodes.release ();
1753 merge_profile_summaries (file_data_vec);
1754 get_working_sets ();
1757 /* Clear out the aux field that was used to store enough state to
1758 tell which nodes should be overwritten. */
1759 FOR_EACH_FUNCTION (node)
1761 /* Some nodes may have been created by cgraph_node. This
1762 happens when the callgraph contains nested functions. If the
1763 node for the parent function was never emitted to the gimple
1764 file, cgraph_node will create a node for it when setting the
1765 context of the nested function. */
1766 if (node->lto_file_data)
1767 node->aux = NULL;
1771 /* True when we need optimization summary for NODE. */
1773 static int
1774 output_cgraph_opt_summary_p (struct cgraph_node *node)
1776 return (node->clone_of
1777 && (node->clone.tree_map
1778 || node->clone.args_to_skip
1779 || node->clone.combined_args_to_skip));
1782 /* Output optimization summary for EDGE to OB. */
1783 static void
1784 output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
1785 struct cgraph_edge *edge ATTRIBUTE_UNUSED)
1789 /* Output optimization summary for NODE to OB. */
1791 static void
1792 output_node_opt_summary (struct output_block *ob,
1793 struct cgraph_node *node,
1794 lto_symtab_encoder_t encoder)
1796 unsigned int index;
1797 bitmap_iterator bi;
1798 struct ipa_replace_map *map;
1799 struct bitpack_d bp;
1800 int i;
1801 struct cgraph_edge *e;
1803 if (node->clone.args_to_skip)
1805 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.args_to_skip));
1806 EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi)
1807 streamer_write_uhwi (ob, index);
1809 else
1810 streamer_write_uhwi (ob, 0);
1811 if (node->clone.combined_args_to_skip)
1813 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.combined_args_to_skip));
1814 EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi)
1815 streamer_write_uhwi (ob, index);
1817 else
1818 streamer_write_uhwi (ob, 0);
1819 streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map));
1820 FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map)
1822 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1823 mechanism to store function local declarations into summaries. */
1824 gcc_assert (!map->old_tree);
1825 streamer_write_uhwi (ob, map->parm_num);
1826 gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
1827 stream_write_tree (ob, map->new_tree, true);
1828 bp = bitpack_create (ob->main_stream);
1829 bp_pack_value (&bp, map->replace_p, 1);
1830 bp_pack_value (&bp, map->ref_p, 1);
1831 streamer_write_bitpack (&bp);
1834 if (lto_symtab_encoder_in_partition_p (encoder, node))
1836 for (e = node->callees; e; e = e->next_callee)
1837 output_edge_opt_summary (ob, e);
1838 for (e = node->indirect_calls; e; e = e->next_callee)
1839 output_edge_opt_summary (ob, e);
1843 /* Output optimization summaries stored in callgraph.
1844 At the moment it is the clone info structure. */
1846 static void
1847 output_cgraph_opt_summary (void)
1849 int i, n_nodes;
1850 lto_symtab_encoder_t encoder;
1851 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
1852 unsigned count = 0;
1854 ob->symbol = NULL;
1855 encoder = ob->decl_state->symtab_node_encoder;
1856 n_nodes = lto_symtab_encoder_size (encoder);
1857 for (i = 0; i < n_nodes; i++)
1859 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1860 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1861 if (cnode && output_cgraph_opt_summary_p (cnode))
1862 count++;
1864 streamer_write_uhwi (ob, count);
1865 for (i = 0; i < n_nodes; i++)
1867 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1868 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1869 if (cnode && output_cgraph_opt_summary_p (cnode))
1871 streamer_write_uhwi (ob, i);
1872 output_node_opt_summary (ob, cnode, encoder);
1875 produce_asm (ob, NULL);
1876 destroy_output_block (ob);
1879 /* Input optimisation summary of EDGE. */
1881 static void
1882 input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
1883 struct lto_input_block *ib_main ATTRIBUTE_UNUSED)
1887 /* Input optimisation summary of NODE. */
1889 static void
1890 input_node_opt_summary (struct cgraph_node *node,
1891 struct lto_input_block *ib_main,
1892 struct data_in *data_in)
1894 int i;
1895 int count;
1896 int bit;
1897 struct bitpack_d bp;
1898 struct cgraph_edge *e;
1900 count = streamer_read_uhwi (ib_main);
1901 if (count)
1902 node->clone.args_to_skip = BITMAP_GGC_ALLOC ();
1903 for (i = 0; i < count; i++)
1905 bit = streamer_read_uhwi (ib_main);
1906 bitmap_set_bit (node->clone.args_to_skip, bit);
1908 count = streamer_read_uhwi (ib_main);
1909 if (count)
1910 node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC ();
1911 for (i = 0; i < count; i++)
1913 bit = streamer_read_uhwi (ib_main);
1914 bitmap_set_bit (node->clone.combined_args_to_skip, bit);
1916 count = streamer_read_uhwi (ib_main);
1917 for (i = 0; i < count; i++)
1919 struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
1921 vec_safe_push (node->clone.tree_map, map);
1922 map->parm_num = streamer_read_uhwi (ib_main);
1923 map->old_tree = NULL;
1924 map->new_tree = stream_read_tree (ib_main, data_in);
1925 bp = streamer_read_bitpack (ib_main);
1926 map->replace_p = bp_unpack_value (&bp, 1);
1927 map->ref_p = bp_unpack_value (&bp, 1);
1929 for (e = node->callees; e; e = e->next_callee)
1930 input_edge_opt_summary (e, ib_main);
1931 for (e = node->indirect_calls; e; e = e->next_callee)
1932 input_edge_opt_summary (e, ib_main);
1935 /* Read section in file FILE_DATA of length LEN with data DATA. */
1937 static void
1938 input_cgraph_opt_section (struct lto_file_decl_data *file_data,
1939 const char *data, size_t len,
1940 vec<symtab_node *> nodes)
1942 const struct lto_function_header *header =
1943 (const struct lto_function_header *) data;
1944 const int cfg_offset = sizeof (struct lto_function_header);
1945 const int main_offset = cfg_offset + header->cfg_size;
1946 const int string_offset = main_offset + header->main_size;
1947 struct data_in *data_in;
1948 unsigned int i;
1949 unsigned int count;
1951 lto_input_block ib_main ((const char *) data + main_offset,
1952 header->main_size);
1954 data_in =
1955 lto_data_in_create (file_data, (const char *) data + string_offset,
1956 header->string_size, vNULL);
1957 count = streamer_read_uhwi (&ib_main);
1959 for (i = 0; i < count; i++)
1961 int ref = streamer_read_uhwi (&ib_main);
1962 input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
1963 &ib_main, data_in);
1965 lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
1966 len);
1967 lto_data_in_delete (data_in);
1970 /* Input optimization summary of cgraph. */
1972 static void
1973 input_cgraph_opt_summary (vec<symtab_node *> nodes)
1975 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1976 struct lto_file_decl_data *file_data;
1977 unsigned int j = 0;
1979 while ((file_data = file_data_vec[j++]))
1981 size_t len;
1982 const char *data =
1983 lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL,
1984 &len);
1986 if (data)
1987 input_cgraph_opt_section (file_data, data, len, nodes);