svn merge -r215707:216846 svn+ssh://gcc.gnu.org/svn/gcc/trunk
[official-gcc.git] / gcc / lto-cgraph.c
blob20052a0126fa1ab38169941360d6b05aeddcb533
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"
64 #include "omp-low.h"
66 /* True when asm nodes has been output. */
67 bool asm_nodes_output = false;
69 static void output_cgraph_opt_summary (void);
70 static void input_cgraph_opt_summary (vec<symtab_node *> nodes);
72 /* Number of LDPR values known to GCC. */
73 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
75 /* All node orders are ofsetted by ORDER_BASE. */
76 static int order_base;
78 /* Cgraph streaming is organized as set of record whose type
79 is indicated by a tag. */
80 enum LTO_symtab_tags
82 /* Must leave 0 for the stopper. */
84 /* Cgraph node without body available. */
85 LTO_symtab_unavail_node = 1,
86 /* Cgraph node with function body. */
87 LTO_symtab_analyzed_node,
88 /* Cgraph edges. */
89 LTO_symtab_edge,
90 LTO_symtab_indirect_edge,
91 LTO_symtab_variable,
92 LTO_symtab_last_tag
95 /* Create a new symtab encoder.
96 if FOR_INPUT, the encoder allocate only datastructures needed
97 to read the symtab. */
99 lto_symtab_encoder_t
100 lto_symtab_encoder_new (bool for_input)
102 lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
104 if (!for_input)
105 encoder->map = new hash_map<symtab_node *, size_t>;
106 encoder->nodes.create (0);
107 return encoder;
111 /* Delete ENCODER and its components. */
113 void
114 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
116 encoder->nodes.release ();
117 if (encoder->map)
118 delete encoder->map;
119 free (encoder);
123 /* Return the existing reference number of NODE in the symtab encoder in
124 output block OB. Assign a new reference if this is the first time
125 NODE is encoded. */
128 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
129 symtab_node *node)
131 int ref;
133 if (!encoder->map)
135 lto_encoder_entry entry = {node, false, false, false};
137 ref = encoder->nodes.length ();
138 encoder->nodes.safe_push (entry);
139 return ref;
142 size_t *slot = encoder->map->get (node);
143 if (!slot || !*slot)
145 lto_encoder_entry entry = {node, false, false, false};
146 ref = encoder->nodes.length ();
147 if (!slot)
148 encoder->map->put (node, ref + 1);
149 encoder->nodes.safe_push (entry);
151 else
152 ref = *slot - 1;
154 return ref;
157 /* Remove NODE from encoder. */
159 bool
160 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
161 symtab_node *node)
163 int index;
164 lto_encoder_entry last_node;
166 size_t *slot = encoder->map->get (node);
167 if (slot == NULL || !*slot)
168 return false;
170 index = *slot - 1;
171 gcc_checking_assert (encoder->nodes[index].node == node);
173 /* Remove from vector. We do this by swapping node with the last element
174 of the vector. */
175 last_node = encoder->nodes.pop ();
176 if (last_node.node != node)
178 gcc_assert (encoder->map->put (last_node.node, index + 1));
180 /* Move the last element to the original spot of NODE. */
181 encoder->nodes[index] = last_node;
184 /* Remove element from hash table. */
185 encoder->map->remove (node);
186 return true;
190 /* Return TRUE if we should encode initializer of NODE (if any). */
192 bool
193 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
194 struct cgraph_node *node)
196 int index = lto_symtab_encoder_lookup (encoder, node);
197 return encoder->nodes[index].body;
200 /* Return TRUE if we should encode body of NODE (if any). */
202 static void
203 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder,
204 struct cgraph_node *node)
206 int index = lto_symtab_encoder_encode (encoder, node);
207 gcc_checking_assert (encoder->nodes[index].node == node);
208 encoder->nodes[index].body = true;
211 /* Return TRUE if we should encode initializer of NODE (if any). */
213 bool
214 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
215 varpool_node *node)
217 int index = lto_symtab_encoder_lookup (encoder, node);
218 if (index == LCC_NOT_FOUND)
219 return false;
220 return encoder->nodes[index].initializer;
223 /* Return TRUE if we should encode initializer of NODE (if any). */
225 static void
226 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
227 varpool_node *node)
229 int index = lto_symtab_encoder_lookup (encoder, node);
230 encoder->nodes[index].initializer = true;
233 /* Return TRUE if we should encode initializer of NODE (if any). */
235 bool
236 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
237 symtab_node *node)
239 int index = lto_symtab_encoder_lookup (encoder, node);
240 if (index == LCC_NOT_FOUND)
241 return false;
242 return encoder->nodes[index].in_partition;
245 /* Return TRUE if we should encode body of NODE (if any). */
247 void
248 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
249 symtab_node *node)
251 /* Ignore not needed nodes. */
252 if (!node->need_dump)
253 return;
254 int index = lto_symtab_encoder_encode (encoder, node);
255 encoder->nodes[index].in_partition = true;
258 /* Output the cgraph EDGE to OB using ENCODER. */
260 static void
261 lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
262 lto_symtab_encoder_t encoder)
264 unsigned int uid;
265 intptr_t ref;
266 struct bitpack_d bp;
268 if (edge->indirect_unknown_callee)
269 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
270 LTO_symtab_indirect_edge);
271 else
272 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
273 LTO_symtab_edge);
275 ref = lto_symtab_encoder_lookup (encoder, edge->caller);
276 gcc_assert (ref != LCC_NOT_FOUND);
277 streamer_write_hwi_stream (ob->main_stream, ref);
279 if (!edge->indirect_unknown_callee)
281 ref = lto_symtab_encoder_lookup (encoder, edge->callee);
282 gcc_assert (ref != LCC_NOT_FOUND);
283 streamer_write_hwi_stream (ob->main_stream, ref);
286 streamer_write_gcov_count_stream (ob->main_stream, edge->count);
288 bp = bitpack_create (ob->main_stream);
289 uid = (!gimple_has_body_p (edge->caller->decl)
290 ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt) + 1);
291 bp_pack_enum (&bp, cgraph_inline_failed_t,
292 CIF_N_REASONS, edge->inline_failed);
293 bp_pack_var_len_unsigned (&bp, uid);
294 bp_pack_var_len_unsigned (&bp, edge->frequency);
295 bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
296 bp_pack_value (&bp, edge->speculative, 1);
297 bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
298 bp_pack_value (&bp, edge->can_throw_external, 1);
299 bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
300 if (edge->indirect_unknown_callee)
302 int flags = edge->indirect_info->ecf_flags;
303 bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
304 bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
305 bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
306 bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
307 bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
308 bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
309 /* Flags that should not appear on indirect calls. */
310 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
311 | ECF_MAY_BE_ALLOCA
312 | ECF_SIBCALL
313 | ECF_LEAF
314 | ECF_NOVOPS)));
316 streamer_write_bitpack (&bp);
317 if (edge->indirect_unknown_callee)
319 streamer_write_hwi_stream (ob->main_stream,
320 edge->indirect_info->common_target_id);
321 if (edge->indirect_info->common_target_id)
322 streamer_write_hwi_stream
323 (ob->main_stream, edge->indirect_info->common_target_probability);
327 /* Return if NODE contain references from other partitions. */
329 bool
330 referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
332 int i;
333 struct ipa_ref *ref = NULL;
335 for (i = 0; node->iterate_referring (i, ref); i++)
337 if (ref->referring->in_other_partition
338 || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
339 return true;
341 return false;
344 /* Return true when node is reachable from other partition. */
346 bool
347 reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
349 struct cgraph_edge *e;
350 if (!node->definition)
351 return false;
352 if (node->global.inlined_to)
353 return false;
354 for (e = node->callers; e; e = e->next_caller)
355 if (e->caller->in_other_partition
356 || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
357 return true;
358 return false;
361 /* Return if NODE contain references from other partitions. */
363 bool
364 referenced_from_this_partition_p (symtab_node *node,
365 lto_symtab_encoder_t encoder)
367 int i;
368 struct ipa_ref *ref = NULL;
370 for (i = 0; node->iterate_referring (i, ref); i++)
371 if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
372 return true;
373 return false;
376 /* Return true when node is reachable from other partition. */
378 bool
379 reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
381 struct cgraph_edge *e;
382 for (e = node->callers; e; e = e->next_caller)
383 if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
384 return true;
385 return false;
388 /* Output the cgraph NODE to OB. ENCODER is used to find the
389 reference number of NODE->inlined_to. SET is the set of nodes we
390 are writing to the current file. If NODE is not in SET, then NODE
391 is a boundary of a cgraph_node_set and we pretend NODE just has a
392 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
393 that have had their callgraph node written so far. This is used to
394 determine if NODE is a clone of a previously written node. */
396 static void
397 lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
398 lto_symtab_encoder_t encoder)
400 unsigned int tag;
401 struct bitpack_d bp;
402 bool boundary_p;
403 intptr_t ref;
404 bool in_other_partition = false;
405 struct cgraph_node *clone_of, *ultimate_clone_of;
406 ipa_opt_pass_d *pass;
407 int i;
408 bool alias_p;
409 const char *comdat;
410 const char *section;
411 tree group;
413 boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
415 if (node->analyzed && !boundary_p)
416 tag = LTO_symtab_analyzed_node;
417 else
418 tag = LTO_symtab_unavail_node;
420 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
421 tag);
422 streamer_write_hwi_stream (ob->main_stream, node->order);
424 /* In WPA mode, we only output part of the call-graph. Also, we
425 fake cgraph node attributes. There are two cases that we care.
427 Boundary nodes: There are nodes that are not part of SET but are
428 called from within SET. We artificially make them look like
429 externally visible nodes with no function body.
431 Cherry-picked nodes: These are nodes we pulled from other
432 translation units into SET during IPA-inlining. We make them as
433 local static nodes to prevent clashes with other local statics. */
434 if (boundary_p && node->analyzed
435 && node->get_partitioning_class () == SYMBOL_PARTITION)
437 /* Inline clones can not be part of boundary.
438 gcc_assert (!node->global.inlined_to);
440 FIXME: At the moment they can be, when partition contains an inline
441 clone that is clone of inline clone from outside partition. We can
442 reshape the clone tree and make other tree to be the root, but it
443 needs a bit extra work and will be promplty done by cgraph_remove_node
444 after reading back. */
445 in_other_partition = 1;
448 clone_of = node->clone_of;
449 while (clone_of
450 && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
451 if (clone_of->prev_sibling_clone)
452 clone_of = clone_of->prev_sibling_clone;
453 else
454 clone_of = clone_of->clone_of;
456 /* See if body of the master function is output. If not, we are seeing only
457 an declaration and we do not need to pass down clone tree. */
458 ultimate_clone_of = clone_of;
459 while (ultimate_clone_of && ultimate_clone_of->clone_of)
460 ultimate_clone_of = ultimate_clone_of->clone_of;
462 if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
463 clone_of = NULL;
465 if (tag == LTO_symtab_analyzed_node)
466 gcc_assert (clone_of || !node->clone_of);
467 if (!clone_of)
468 streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
469 else
470 streamer_write_hwi_stream (ob->main_stream, ref);
473 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
474 streamer_write_gcov_count_stream (ob->main_stream, node->count);
475 streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
477 streamer_write_hwi_stream (ob->main_stream,
478 node->ipa_transforms_to_apply.length ());
479 FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
480 streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
482 if (tag == LTO_symtab_analyzed_node)
484 if (node->global.inlined_to)
486 ref = lto_symtab_encoder_lookup (encoder, node->global.inlined_to);
487 gcc_assert (ref != LCC_NOT_FOUND);
489 else
490 ref = LCC_NOT_FOUND;
492 streamer_write_hwi_stream (ob->main_stream, ref);
495 group = node->get_comdat_group ();
496 if (group)
497 comdat = IDENTIFIER_POINTER (group);
498 else
499 comdat = "";
500 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
502 if (group)
504 if (node->same_comdat_group && !boundary_p)
506 ref = lto_symtab_encoder_lookup (encoder,
507 node->same_comdat_group);
508 gcc_assert (ref != LCC_NOT_FOUND);
510 else
511 ref = LCC_NOT_FOUND;
512 streamer_write_hwi_stream (ob->main_stream, ref);
515 section = node->get_section ();
516 if (!section)
517 section = "";
519 streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
521 bp = bitpack_create (ob->main_stream);
522 bp_pack_value (&bp, node->local.local, 1);
523 bp_pack_value (&bp, node->externally_visible, 1);
524 bp_pack_value (&bp, node->no_reorder, 1);
525 bp_pack_value (&bp, node->definition, 1);
526 bp_pack_value (&bp, node->local.versionable, 1);
527 bp_pack_value (&bp, node->local.can_change_signature, 1);
528 bp_pack_value (&bp, node->local.redefined_extern_inline, 1);
529 bp_pack_value (&bp, node->force_output, 1);
530 bp_pack_value (&bp, node->forced_by_abi, 1);
531 bp_pack_value (&bp, node->unique_name, 1);
532 bp_pack_value (&bp, node->body_removed, 1);
533 bp_pack_value (&bp, node->implicit_section, 1);
534 bp_pack_value (&bp, node->address_taken, 1);
535 bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
536 && node->get_partitioning_class () == SYMBOL_PARTITION
537 && (reachable_from_other_partition_p (node, encoder)
538 || referenced_from_other_partition_p (node, encoder)), 1);
539 bp_pack_value (&bp, node->lowered, 1);
540 bp_pack_value (&bp, in_other_partition, 1);
541 /* Real aliases in a boundary become non-aliases. However we still stream
542 alias info on weakrefs.
543 TODO: We lose a bit of information here - when we know that variable is
544 defined in other unit, we may use the info on aliases to resolve
545 symbol1 != symbol2 type tests that we can do only for locally defined objects
546 otherwise. */
547 alias_p = node->alias && (!boundary_p || node->weakref);
548 bp_pack_value (&bp, alias_p, 1);
549 bp_pack_value (&bp, node->weakref, 1);
550 bp_pack_value (&bp, node->frequency, 2);
551 bp_pack_value (&bp, node->only_called_at_startup, 1);
552 bp_pack_value (&bp, node->only_called_at_exit, 1);
553 bp_pack_value (&bp, node->tm_clone, 1);
554 bp_pack_value (&bp, node->calls_comdat_local, 1);
555 bp_pack_value (&bp, node->icf_merged, 1);
556 bp_pack_value (&bp, node->thunk.thunk_p && !boundary_p, 1);
557 bp_pack_enum (&bp, ld_plugin_symbol_resolution,
558 LDPR_NUM_KNOWN, node->resolution);
559 streamer_write_bitpack (&bp);
560 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
562 if (node->thunk.thunk_p && !boundary_p)
564 streamer_write_uhwi_stream
565 (ob->main_stream,
566 1 + (node->thunk.this_adjusting != 0) * 2
567 + (node->thunk.virtual_offset_p != 0) * 4);
568 streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset);
569 streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value);
571 streamer_write_hwi_stream (ob->main_stream, node->profile_id);
572 if (DECL_STATIC_CONSTRUCTOR (node->decl))
573 streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
574 if (DECL_STATIC_DESTRUCTOR (node->decl))
575 streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
578 /* Output the varpool NODE to OB.
579 If NODE is not in SET, then NODE is a boundary. */
581 static void
582 lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
583 lto_symtab_encoder_t encoder)
585 bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
586 struct bitpack_d bp;
587 int ref;
588 bool alias_p;
589 const char *comdat;
590 const char *section;
591 tree group;
593 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
594 LTO_symtab_variable);
595 streamer_write_hwi_stream (ob->main_stream, node->order);
596 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl);
597 bp = bitpack_create (ob->main_stream);
598 bp_pack_value (&bp, node->externally_visible, 1);
599 bp_pack_value (&bp, node->no_reorder, 1);
600 bp_pack_value (&bp, node->force_output, 1);
601 bp_pack_value (&bp, node->forced_by_abi, 1);
602 bp_pack_value (&bp, node->unique_name, 1);
603 bp_pack_value (&bp, node->body_removed, 1);
604 bp_pack_value (&bp, node->implicit_section, 1);
605 bp_pack_value (&bp, node->writeonly, 1);
606 bp_pack_value (&bp, node->definition, 1);
607 alias_p = node->alias && (!boundary_p || node->weakref);
608 bp_pack_value (&bp, alias_p, 1);
609 bp_pack_value (&bp, node->weakref, 1);
610 bp_pack_value (&bp, node->analyzed && !boundary_p, 1);
611 gcc_assert (node->definition || !node->analyzed);
612 /* Constant pool initializers can be de-unified into individual ltrans units.
613 FIXME: Alternatively at -Os we may want to avoid generating for them the local
614 labels and share them across LTRANS partitions. */
615 if (node->get_partitioning_class () != SYMBOL_PARTITION)
617 bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */
618 bp_pack_value (&bp, 0, 1); /* in_other_partition. */
620 else
622 bp_pack_value (&bp, node->definition
623 && referenced_from_other_partition_p (node, encoder), 1);
624 bp_pack_value (&bp, node->analyzed
625 && boundary_p && !DECL_EXTERNAL (node->decl), 1);
626 /* in_other_partition. */
628 bp_pack_value (&bp, node->tls_model, 3);
629 bp_pack_value (&bp, node->used_by_single_function, 1);
630 streamer_write_bitpack (&bp);
632 group = node->get_comdat_group ();
633 if (group)
634 comdat = IDENTIFIER_POINTER (group);
635 else
636 comdat = "";
637 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
639 if (group)
641 if (node->same_comdat_group && !boundary_p)
643 ref = lto_symtab_encoder_lookup (encoder,
644 node->same_comdat_group);
645 gcc_assert (ref != LCC_NOT_FOUND);
647 else
648 ref = LCC_NOT_FOUND;
649 streamer_write_hwi_stream (ob->main_stream, ref);
652 section = node->get_section ();
653 if (!section)
654 section = "";
655 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
657 streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
658 LDPR_NUM_KNOWN, node->resolution);
661 /* Output the varpool NODE to OB.
662 If NODE is not in SET, then NODE is a boundary. */
664 static void
665 lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
666 lto_symtab_encoder_t encoder)
668 struct bitpack_d bp;
669 int nref;
670 int uid = ref->lto_stmt_uid;
671 struct cgraph_node *node;
673 bp = bitpack_create (ob->main_stream);
674 bp_pack_value (&bp, ref->use, 2);
675 bp_pack_value (&bp, ref->speculative, 1);
676 streamer_write_bitpack (&bp);
677 nref = lto_symtab_encoder_lookup (encoder, ref->referred);
678 gcc_assert (nref != LCC_NOT_FOUND);
679 streamer_write_hwi_stream (ob->main_stream, nref);
681 node = dyn_cast <cgraph_node *> (ref->referring);
682 if (node)
684 if (ref->stmt)
685 uid = gimple_uid (ref->stmt) + 1;
686 streamer_write_hwi_stream (ob->main_stream, uid);
690 /* Stream out profile_summary to OB. */
692 static void
693 output_profile_summary (struct lto_simple_output_block *ob)
695 unsigned h_ix;
696 struct bitpack_d bp;
698 if (profile_info)
700 /* We do not output num and run_max, they are not used by
701 GCC profile feedback and they are difficult to merge from multiple
702 units. */
703 gcc_assert (profile_info->runs);
704 streamer_write_uhwi_stream (ob->main_stream, profile_info->runs);
705 streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_max);
707 /* sum_all is needed for computing the working set with the
708 histogram. */
709 streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_all);
711 /* Create and output a bitpack of non-zero histogram entries indices. */
712 bp = bitpack_create (ob->main_stream);
713 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
714 bp_pack_value (&bp, profile_info->histogram[h_ix].num_counters > 0, 1);
715 streamer_write_bitpack (&bp);
716 /* Now stream out only those non-zero entries. */
717 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
719 if (!profile_info->histogram[h_ix].num_counters)
720 continue;
721 streamer_write_gcov_count_stream (ob->main_stream,
722 profile_info->histogram[h_ix].num_counters);
723 streamer_write_gcov_count_stream (ob->main_stream,
724 profile_info->histogram[h_ix].min_value);
725 streamer_write_gcov_count_stream (ob->main_stream,
726 profile_info->histogram[h_ix].cum_value);
728 /* IPA-profile computes hot bb threshold based on cumulated
729 whole program profile. We need to stream it down to ltrans. */
730 if (flag_wpa)
731 streamer_write_gcov_count_stream (ob->main_stream,
732 get_hot_bb_threshold ());
734 else
735 streamer_write_uhwi_stream (ob->main_stream, 0);
738 /* Output all callees or indirect outgoing edges. EDGE must be the first such
739 edge. */
741 static void
742 output_outgoing_cgraph_edges (struct cgraph_edge *edge,
743 struct lto_simple_output_block *ob,
744 lto_symtab_encoder_t encoder)
746 if (!edge)
747 return;
749 /* Output edges in backward direction, so the reconstructed callgraph match
750 and it is easy to associate call sites in the IPA pass summaries. */
751 while (edge->next_callee)
752 edge = edge->next_callee;
753 for (; edge; edge = edge->prev_callee)
754 lto_output_edge (ob, edge, encoder);
757 /* Output the part of the cgraph in SET. */
759 static void
760 output_refs (lto_symtab_encoder_t encoder)
762 lto_symtab_encoder_iterator lsei;
763 struct lto_simple_output_block *ob;
764 int count;
765 struct ipa_ref *ref;
766 int i;
768 ob = lto_create_simple_output_block (LTO_section_refs);
770 for (lsei = lsei_start_in_partition (encoder); !lsei_end_p (lsei);
771 lsei_next_in_partition (&lsei))
773 symtab_node *node = lsei_node (lsei);
775 count = node->ref_list.nreferences ();
776 if (count)
778 streamer_write_gcov_count_stream (ob->main_stream, count);
779 streamer_write_uhwi_stream (ob->main_stream,
780 lto_symtab_encoder_lookup (encoder, node));
781 for (i = 0; node->iterate_reference (i, ref); i++)
782 lto_output_ref (ob, ref, encoder);
786 streamer_write_uhwi_stream (ob->main_stream, 0);
788 lto_destroy_simple_output_block (ob);
791 /* Add NODE into encoder as well as nodes it is cloned from.
792 Do it in a way so clones appear first. */
794 static void
795 add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
796 bool include_body)
798 if (node->clone_of)
799 add_node_to (encoder, node->clone_of, include_body);
800 else if (include_body)
801 lto_set_symtab_encoder_encode_body (encoder, node);
802 lto_symtab_encoder_encode (encoder, node);
805 /* Add all references in NODE to encoders. */
807 static void
808 create_references (lto_symtab_encoder_t encoder, symtab_node *node)
810 int i;
811 struct ipa_ref *ref = NULL;
812 for (i = 0; node->iterate_reference (i, ref); i++)
813 if (is_a <cgraph_node *> (ref->referred))
814 add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
815 else
816 lto_symtab_encoder_encode (encoder, ref->referred);
819 /* Select what needs to be dumped. In lto case dump everything.
820 In omp target case only dump stuff makrked with attribute. */
821 void
822 select_what_to_dump (bool is_omp)
824 struct symtab_node *snode;
825 FOR_EACH_SYMBOL(snode)
826 snode->need_dump = !is_omp || lookup_attribute ("omp declare target",
827 DECL_ATTRIBUTES (snode->decl));
830 /* Find all symbols we want to stream into given partition and insert them
831 to encoders.
833 The function actually replaces IN_ENCODER by new one. The reason is that
834 streaming code needs clone's origin to be streamed before clone. This
835 means that we need to insert the nodes in specific order. This order is
836 ignored by the partitioning logic earlier. */
838 lto_symtab_encoder_t
839 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
841 struct cgraph_edge *edge;
842 int i;
843 lto_symtab_encoder_t encoder;
844 lto_symtab_encoder_iterator lsei;
845 hash_set<void *> reachable_call_targets;
847 encoder = lto_symtab_encoder_new (false);
849 /* Go over all entries in the IN_ENCODER and duplicate them to
850 ENCODER. At the same time insert masters of clones so
851 every master appears before clone. */
852 for (lsei = lsei_start_function_in_partition (in_encoder);
853 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
855 struct cgraph_node *node = lsei_cgraph_node (lsei);
856 add_node_to (encoder, node, true);
857 lto_set_symtab_encoder_in_partition (encoder, node);
858 create_references (encoder, node);
859 /* For proper debug info, we need to ship the origins, too. */
860 if (DECL_ABSTRACT_ORIGIN (node->decl))
862 struct cgraph_node *origin_node
863 = cgraph_node::get (DECL_ABSTRACT_ORIGIN (node->decl));
864 add_node_to (encoder, origin_node, true);
867 for (lsei = lsei_start_variable_in_partition (in_encoder);
868 !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
870 varpool_node *vnode = lsei_varpool_node (lsei);
872 lto_set_symtab_encoder_in_partition (encoder, vnode);
873 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
874 create_references (encoder, vnode);
875 /* For proper debug info, we need to ship the origins, too. */
876 if (DECL_ABSTRACT_ORIGIN (vnode->decl))
878 varpool_node *origin_node
879 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode->decl));
880 lto_set_symtab_encoder_in_partition (encoder, origin_node);
883 /* Pickle in also the initializer of all referenced readonly variables
884 to help folding. Constant pool variables are not shared, so we must
885 pickle those too. */
886 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
888 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
889 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
891 if (!lto_symtab_encoder_encode_initializer_p (encoder,
892 vnode)
893 && vnode->ctor_useable_for_folding_p ())
895 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
896 create_references (encoder, vnode);
901 /* Go over all the nodes again to include callees that are not in
902 SET. */
903 for (lsei = lsei_start_function_in_partition (encoder);
904 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
906 struct cgraph_node *node = lsei_cgraph_node (lsei);
907 for (edge = node->callees; edge; edge = edge->next_callee)
909 struct cgraph_node *callee = edge->callee;
910 if (!lto_symtab_encoder_in_partition_p (encoder, callee))
912 /* We should have moved all the inlines. */
913 gcc_assert (!callee->global.inlined_to);
914 add_node_to (encoder, callee, false);
917 /* Add all possible targets for late devirtualization. */
918 if (flag_devirtualize)
919 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
920 if (edge->indirect_info->polymorphic)
922 unsigned int i;
923 void *cache_token;
924 bool final;
925 vec <cgraph_node *>targets
926 = possible_polymorphic_call_targets
927 (edge, &final, &cache_token);
928 if (!reachable_call_targets.add (cache_token))
930 for (i = 0; i < targets.length (); i++)
932 struct cgraph_node *callee = targets[i];
934 /* Adding an external declarations into the unit serves
935 no purpose and just increases its boundary. */
936 if (callee->definition
937 && !lto_symtab_encoder_in_partition_p
938 (encoder, callee))
940 gcc_assert (!callee->global.inlined_to);
941 add_node_to (encoder, callee, false);
947 lto_symtab_encoder_delete (in_encoder);
948 return encoder;
951 /* Output the part of the symtab in SET and VSET. */
953 void
954 output_symtab (void)
956 struct cgraph_node *node;
957 struct lto_simple_output_block *ob;
958 lto_symtab_encoder_iterator lsei;
959 int i, n_nodes;
960 lto_symtab_encoder_t encoder;
962 if (flag_wpa)
963 output_cgraph_opt_summary ();
965 ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
967 output_profile_summary (ob);
969 /* An encoder for cgraph nodes should have been created by
970 ipa_write_summaries_1. */
971 gcc_assert (ob->decl_state->symtab_node_encoder);
972 encoder = ob->decl_state->symtab_node_encoder;
974 /* Write out the nodes. We must first output a node and then its clones,
975 otherwise at a time reading back the node there would be nothing to clone
976 from. */
977 n_nodes = lto_symtab_encoder_size (encoder);
978 for (i = 0; i < n_nodes; i++)
980 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
981 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
982 lto_output_node (ob, cnode, encoder);
983 else
984 lto_output_varpool_node (ob, dyn_cast<varpool_node *> (node), encoder);
987 /* Go over the nodes in SET again to write edges. */
988 for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
989 lsei_next_function_in_partition (&lsei))
991 node = lsei_cgraph_node (lsei);
992 output_outgoing_cgraph_edges (node->callees, ob, encoder);
993 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
996 streamer_write_uhwi_stream (ob->main_stream, 0);
998 lto_destroy_simple_output_block (ob);
1000 /* Emit toplevel asms.
1001 When doing WPA we must output every asm just once. Since we do not partition asm
1002 nodes at all, output them to first output. This is kind of hack, but should work
1003 well. */
1004 if (!asm_nodes_output)
1006 asm_nodes_output = true;
1007 lto_output_toplevel_asms ();
1010 output_refs (encoder);
1013 /* Return identifier encoded in IB as a plain string. */
1015 static tree
1016 read_identifier (struct lto_input_block *ib)
1018 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1019 tree id;
1021 if (ib->data[ib->p + len])
1022 lto_section_overrun (ib);
1023 if (!len)
1025 ib->p++;
1026 return NULL;
1028 id = get_identifier (ib->data + ib->p);
1029 ib->p += len + 1;
1030 return id;
1033 /* Return string encoded in IB, NULL if string is empty. */
1035 static const char *
1036 read_string (struct lto_input_block *ib)
1038 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1039 const char *str;
1041 if (ib->data[ib->p + len])
1042 lto_section_overrun (ib);
1043 if (!len)
1045 ib->p++;
1046 return NULL;
1048 str = ib->data + ib->p;
1049 ib->p += len + 1;
1050 return str;
1053 /* Output function/variable tables that will allow libgomp to look up offload
1054 target code. OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is
1055 filled in ipa_passes. In WHOPR (partitioned) mode during the WPA stage both
1056 OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1058 void
1059 output_offload_tables (void)
1061 if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars))
1062 return;
1064 struct lto_simple_output_block *ob
1065 = lto_create_simple_output_block (LTO_section_offload_table);
1067 for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
1069 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1070 LTO_symtab_last_tag, LTO_symtab_unavail_node);
1071 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
1072 (*offload_funcs)[i]);
1075 for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
1077 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1078 LTO_symtab_last_tag, LTO_symtab_variable);
1079 lto_output_var_decl_index (ob->decl_state, ob->main_stream,
1080 (*offload_vars)[i]);
1083 streamer_write_uhwi_stream (ob->main_stream, 0);
1084 lto_destroy_simple_output_block (ob);
1086 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1087 streamed to one partition only. That's why we free offload_funcs and
1088 offload_vars after the first call of output_offload_tables. */
1089 if (flag_wpa)
1091 vec_free (offload_funcs);
1092 vec_free (offload_vars);
1096 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1097 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1098 NODE or to replace the values in it, for instance because the first
1099 time we saw it, the function body was not available but now it
1100 is. BP is a bitpack with all the bitflags for NODE read from the
1101 stream. */
1103 static void
1104 input_overwrite_node (struct lto_file_decl_data *file_data,
1105 struct cgraph_node *node,
1106 enum LTO_symtab_tags tag,
1107 struct bitpack_d *bp)
1109 node->aux = (void *) tag;
1110 node->lto_file_data = file_data;
1112 node->local.local = bp_unpack_value (bp, 1);
1113 node->externally_visible = bp_unpack_value (bp, 1);
1114 node->no_reorder = bp_unpack_value (bp, 1);
1115 node->definition = bp_unpack_value (bp, 1);
1116 node->local.versionable = bp_unpack_value (bp, 1);
1117 node->local.can_change_signature = bp_unpack_value (bp, 1);
1118 node->local.redefined_extern_inline = bp_unpack_value (bp, 1);
1119 node->force_output = bp_unpack_value (bp, 1);
1120 node->forced_by_abi = bp_unpack_value (bp, 1);
1121 node->unique_name = bp_unpack_value (bp, 1);
1122 node->body_removed = bp_unpack_value (bp, 1);
1123 node->implicit_section = bp_unpack_value (bp, 1);
1124 node->address_taken = bp_unpack_value (bp, 1);
1125 node->used_from_other_partition = bp_unpack_value (bp, 1);
1126 node->lowered = bp_unpack_value (bp, 1);
1127 node->analyzed = tag == LTO_symtab_analyzed_node;
1128 node->in_other_partition = bp_unpack_value (bp, 1);
1129 if (node->in_other_partition
1130 /* Avoid updating decl when we are seeing just inline clone.
1131 When inlining function that has functions already inlined into it,
1132 we produce clones of inline clones.
1134 WPA partitioning might put each clone into different unit and
1135 we might end up streaming inline clone from other partition
1136 to support clone we are interested in. */
1137 && (!node->clone_of
1138 || node->clone_of->decl != node->decl))
1140 DECL_EXTERNAL (node->decl) = 1;
1141 TREE_STATIC (node->decl) = 0;
1143 node->alias = bp_unpack_value (bp, 1);
1144 node->weakref = bp_unpack_value (bp, 1);
1145 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
1146 node->only_called_at_startup = bp_unpack_value (bp, 1);
1147 node->only_called_at_exit = bp_unpack_value (bp, 1);
1148 node->tm_clone = bp_unpack_value (bp, 1);
1149 node->calls_comdat_local = bp_unpack_value (bp, 1);
1150 node->icf_merged = bp_unpack_value (bp, 1);
1151 node->thunk.thunk_p = bp_unpack_value (bp, 1);
1152 node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
1153 LDPR_NUM_KNOWN);
1154 gcc_assert (flag_ltrans
1155 || (!node->in_other_partition
1156 && !node->used_from_other_partition));
1159 /* Return string alias is alias of. */
1161 static tree
1162 get_alias_symbol (tree decl)
1164 tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1165 return get_identifier (TREE_STRING_POINTER
1166 (TREE_VALUE (TREE_VALUE (alias))));
1169 /* Read a node from input_block IB. TAG is the node's tag just read.
1170 Return the node read or overwriten. */
1172 static struct cgraph_node *
1173 input_node (struct lto_file_decl_data *file_data,
1174 struct lto_input_block *ib,
1175 enum LTO_symtab_tags tag,
1176 vec<symtab_node *> nodes)
1178 gcc::pass_manager *passes = g->get_passes ();
1179 tree fn_decl;
1180 struct cgraph_node *node;
1181 struct bitpack_d bp;
1182 unsigned decl_index;
1183 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
1184 int clone_ref;
1185 int order;
1186 int i, count;
1187 tree group;
1188 const char *section;
1189 order = streamer_read_hwi (ib) + order_base;
1190 clone_ref = streamer_read_hwi (ib);
1192 decl_index = streamer_read_uhwi (ib);
1193 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1195 if (clone_ref != LCC_NOT_FOUND)
1197 node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
1198 0, CGRAPH_FREQ_BASE, false,
1199 vNULL, false, NULL, NULL);
1201 else
1203 /* Declaration of functions can be already merged with a declaration
1204 from other input file. We keep cgraph unmerged until after streaming
1205 of ipa passes is done. Alays forcingly create a fresh node. */
1206 node = symtab->create_empty ();
1207 node->decl = fn_decl;
1208 node->register_symbol ();
1211 node->order = order;
1212 if (order >= symtab->order)
1213 symtab->order = order + 1;
1215 node->count = streamer_read_gcov_count (ib);
1216 node->count_materialization_scale = streamer_read_hwi (ib);
1218 count = streamer_read_hwi (ib);
1219 node->ipa_transforms_to_apply = vNULL;
1220 for (i = 0; i < count; i++)
1222 opt_pass *pass;
1223 int pid = streamer_read_hwi (ib);
1225 gcc_assert (pid < passes->passes_by_id_size);
1226 pass = passes->passes_by_id[pid];
1227 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
1230 if (tag == LTO_symtab_analyzed_node)
1231 ref = streamer_read_hwi (ib);
1233 group = read_identifier (ib);
1234 if (group)
1235 ref2 = streamer_read_hwi (ib);
1237 /* Make sure that we have not read this node before. Nodes that
1238 have already been read will have their tag stored in the 'aux'
1239 field. Since built-in functions can be referenced in multiple
1240 functions, they are expected to be read more than once. */
1241 if (node->aux && !DECL_BUILT_IN (node->decl))
1242 internal_error ("bytecode stream: found multiple instances of cgraph "
1243 "node with uid %d", node->uid);
1245 node->tp_first_run = streamer_read_uhwi (ib);
1247 bp = streamer_read_bitpack (ib);
1249 input_overwrite_node (file_data, node, tag, &bp);
1251 /* Store a reference for now, and fix up later to be a pointer. */
1252 node->global.inlined_to = (cgraph_node *) (intptr_t) ref;
1254 if (group)
1256 node->set_comdat_group (group);
1257 /* Store a reference for now, and fix up later to be a pointer. */
1258 node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
1260 else
1261 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1262 section = read_string (ib);
1263 if (section)
1264 node->set_section_for_node (section);
1266 if (node->thunk.thunk_p)
1268 int type = streamer_read_uhwi (ib);
1269 HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
1270 HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib);
1272 node->thunk.fixed_offset = fixed_offset;
1273 node->thunk.this_adjusting = (type & 2);
1274 node->thunk.virtual_value = virtual_value;
1275 node->thunk.virtual_offset_p = (type & 4);
1277 if (node->alias && !node->analyzed && node->weakref)
1278 node->alias_target = get_alias_symbol (node->decl);
1279 node->profile_id = streamer_read_hwi (ib);
1280 if (DECL_STATIC_CONSTRUCTOR (node->decl))
1281 node->set_init_priority (streamer_read_hwi (ib));
1282 if (DECL_STATIC_DESTRUCTOR (node->decl))
1283 node->set_fini_priority (streamer_read_hwi (ib));
1284 return node;
1287 /* Read a node from input_block IB. TAG is the node's tag just read.
1288 Return the node read or overwriten. */
1290 static varpool_node *
1291 input_varpool_node (struct lto_file_decl_data *file_data,
1292 struct lto_input_block *ib)
1294 int decl_index;
1295 tree var_decl;
1296 varpool_node *node;
1297 struct bitpack_d bp;
1298 int ref = LCC_NOT_FOUND;
1299 int order;
1300 tree group;
1301 const char *section;
1303 order = streamer_read_hwi (ib) + order_base;
1304 decl_index = streamer_read_uhwi (ib);
1305 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
1307 /* Declaration of functions can be already merged with a declaration
1308 from other input file. We keep cgraph unmerged until after streaming
1309 of ipa passes is done. Alays forcingly create a fresh node. */
1310 node = varpool_node::create_empty ();
1311 node->decl = var_decl;
1312 node->register_symbol ();
1314 node->order = order;
1315 if (order >= symtab->order)
1316 symtab->order = order + 1;
1317 node->lto_file_data = file_data;
1319 bp = streamer_read_bitpack (ib);
1320 node->externally_visible = bp_unpack_value (&bp, 1);
1321 node->no_reorder = bp_unpack_value (&bp, 1);
1322 node->force_output = bp_unpack_value (&bp, 1);
1323 node->forced_by_abi = bp_unpack_value (&bp, 1);
1324 node->unique_name = bp_unpack_value (&bp, 1);
1325 node->body_removed = bp_unpack_value (&bp, 1);
1326 node->implicit_section = bp_unpack_value (&bp, 1);
1327 node->writeonly = bp_unpack_value (&bp, 1);
1328 node->definition = bp_unpack_value (&bp, 1);
1329 node->alias = bp_unpack_value (&bp, 1);
1330 node->weakref = bp_unpack_value (&bp, 1);
1331 node->analyzed = bp_unpack_value (&bp, 1);
1332 node->used_from_other_partition = bp_unpack_value (&bp, 1);
1333 node->in_other_partition = bp_unpack_value (&bp, 1);
1334 if (node->in_other_partition)
1336 DECL_EXTERNAL (node->decl) = 1;
1337 TREE_STATIC (node->decl) = 0;
1339 if (node->alias && !node->analyzed && node->weakref)
1340 node->alias_target = get_alias_symbol (node->decl);
1341 node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
1342 node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
1343 group = read_identifier (ib);
1344 if (group)
1346 node->set_comdat_group (group);
1347 ref = streamer_read_hwi (ib);
1348 /* Store a reference for now, and fix up later to be a pointer. */
1349 node->same_comdat_group = (symtab_node *) (intptr_t) ref;
1351 else
1352 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1353 section = read_string (ib);
1354 if (section)
1355 node->set_section_for_node (section);
1356 node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
1357 LDPR_NUM_KNOWN);
1358 gcc_assert (flag_ltrans
1359 || (!node->in_other_partition
1360 && !node->used_from_other_partition));
1362 return node;
1365 /* Read a node from input_block IB. TAG is the node's tag just read.
1366 Return the node read or overwriten. */
1368 static void
1369 input_ref (struct lto_input_block *ib,
1370 symtab_node *referring_node,
1371 vec<symtab_node *> nodes)
1373 symtab_node *node = NULL;
1374 struct bitpack_d bp;
1375 enum ipa_ref_use use;
1376 bool speculative;
1377 struct ipa_ref *ref;
1379 bp = streamer_read_bitpack (ib);
1380 use = (enum ipa_ref_use) bp_unpack_value (&bp, 2);
1381 speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
1382 node = nodes[streamer_read_hwi (ib)];
1383 ref = referring_node->create_reference (node, use);
1384 ref->speculative = speculative;
1385 if (is_a <cgraph_node *> (referring_node))
1386 ref->lto_stmt_uid = streamer_read_hwi (ib);
1389 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1390 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1391 edge being read is indirect (in the sense that it has
1392 indirect_unknown_callee set). */
1394 static void
1395 input_edge (struct lto_input_block *ib, vec<symtab_node *> nodes,
1396 bool indirect)
1398 struct cgraph_node *caller, *callee;
1399 struct cgraph_edge *edge;
1400 unsigned int stmt_id;
1401 gcov_type count;
1402 int freq;
1403 cgraph_inline_failed_t inline_failed;
1404 struct bitpack_d bp;
1405 int ecf_flags = 0;
1407 caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1408 if (caller == NULL || caller->decl == NULL_TREE)
1409 internal_error ("bytecode stream: no caller found while reading edge");
1411 if (!indirect)
1413 callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1414 if (callee == NULL || callee->decl == NULL_TREE)
1415 internal_error ("bytecode stream: no callee found while reading edge");
1417 else
1418 callee = NULL;
1420 count = streamer_read_gcov_count (ib);
1422 bp = streamer_read_bitpack (ib);
1423 inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
1424 stmt_id = bp_unpack_var_len_unsigned (&bp);
1425 freq = (int) bp_unpack_var_len_unsigned (&bp);
1427 if (indirect)
1428 edge = caller->create_indirect_edge (NULL, 0, count, freq);
1429 else
1430 edge = caller->create_edge (callee, NULL, count, freq);
1432 edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
1433 edge->speculative = bp_unpack_value (&bp, 1);
1434 edge->lto_stmt_uid = stmt_id;
1435 edge->inline_failed = inline_failed;
1436 edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1437 edge->can_throw_external = bp_unpack_value (&bp, 1);
1438 edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
1439 if (indirect)
1441 if (bp_unpack_value (&bp, 1))
1442 ecf_flags |= ECF_CONST;
1443 if (bp_unpack_value (&bp, 1))
1444 ecf_flags |= ECF_PURE;
1445 if (bp_unpack_value (&bp, 1))
1446 ecf_flags |= ECF_NORETURN;
1447 if (bp_unpack_value (&bp, 1))
1448 ecf_flags |= ECF_MALLOC;
1449 if (bp_unpack_value (&bp, 1))
1450 ecf_flags |= ECF_NOTHROW;
1451 if (bp_unpack_value (&bp, 1))
1452 ecf_flags |= ECF_RETURNS_TWICE;
1453 edge->indirect_info->ecf_flags = ecf_flags;
1454 edge->indirect_info->common_target_id = streamer_read_hwi (ib);
1455 if (edge->indirect_info->common_target_id)
1456 edge->indirect_info->common_target_probability = streamer_read_hwi (ib);
1461 /* Read a cgraph from IB using the info in FILE_DATA. */
1463 static vec<symtab_node *>
1464 input_cgraph_1 (struct lto_file_decl_data *file_data,
1465 struct lto_input_block *ib)
1467 enum LTO_symtab_tags tag;
1468 vec<symtab_node *> nodes = vNULL;
1469 symtab_node *node;
1470 unsigned i;
1472 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1473 order_base = symtab->order;
1474 while (tag)
1476 if (tag == LTO_symtab_edge)
1477 input_edge (ib, nodes, false);
1478 else if (tag == LTO_symtab_indirect_edge)
1479 input_edge (ib, nodes, true);
1480 else if (tag == LTO_symtab_variable)
1482 node = input_varpool_node (file_data, ib);
1483 nodes.safe_push (node);
1484 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1486 else
1488 node = input_node (file_data, ib, tag, nodes);
1489 if (node == NULL || node->decl == NULL_TREE)
1490 internal_error ("bytecode stream: found empty cgraph node");
1491 nodes.safe_push (node);
1492 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1495 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1498 lto_input_toplevel_asms (file_data, order_base);
1500 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1501 #ifdef ENABLE_CHECKING
1502 FOR_EACH_VEC_ELT (nodes, i, node)
1503 gcc_assert (node->aux || !is_a <cgraph_node *> (node));
1504 #endif
1505 FOR_EACH_VEC_ELT (nodes, i, node)
1507 int ref;
1508 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
1510 ref = (int) (intptr_t) cnode->global.inlined_to;
1512 /* We share declaration of builtins, so we may read same node twice. */
1513 if (!node->aux)
1514 continue;
1515 node->aux = NULL;
1517 /* Fixup inlined_to from reference to pointer. */
1518 if (ref != LCC_NOT_FOUND)
1519 dyn_cast<cgraph_node *> (node)->global.inlined_to
1520 = dyn_cast<cgraph_node *> (nodes[ref]);
1521 else
1522 cnode->global.inlined_to = NULL;
1525 ref = (int) (intptr_t) node->same_comdat_group;
1527 /* Fixup same_comdat_group from reference to pointer. */
1528 if (ref != LCC_NOT_FOUND)
1529 node->same_comdat_group = nodes[ref];
1530 else
1531 node->same_comdat_group = NULL;
1533 FOR_EACH_VEC_ELT (nodes, i, node)
1534 node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
1535 return nodes;
1538 /* Input ipa_refs. */
1540 static void
1541 input_refs (struct lto_input_block *ib,
1542 vec<symtab_node *> nodes)
1544 int count;
1545 int idx;
1546 while (true)
1548 symtab_node *node;
1549 count = streamer_read_uhwi (ib);
1550 if (!count)
1551 break;
1552 idx = streamer_read_uhwi (ib);
1553 node = nodes[idx];
1554 while (count)
1556 input_ref (ib, node, nodes);
1557 count--;
1563 static struct gcov_ctr_summary lto_gcov_summary;
1565 /* Input profile_info from IB. */
1566 static void
1567 input_profile_summary (struct lto_input_block *ib,
1568 struct lto_file_decl_data *file_data)
1570 unsigned h_ix;
1571 struct bitpack_d bp;
1572 unsigned int runs = streamer_read_uhwi (ib);
1573 if (runs)
1575 file_data->profile_info.runs = runs;
1576 file_data->profile_info.sum_max = streamer_read_gcov_count (ib);
1577 file_data->profile_info.sum_all = streamer_read_gcov_count (ib);
1579 memset (file_data->profile_info.histogram, 0,
1580 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
1581 /* Input the bitpack of non-zero histogram indices. */
1582 bp = streamer_read_bitpack (ib);
1583 /* Read in and unpack the full bitpack, flagging non-zero
1584 histogram entries by setting the num_counters non-zero. */
1585 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1587 file_data->profile_info.histogram[h_ix].num_counters
1588 = bp_unpack_value (&bp, 1);
1590 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1592 if (!file_data->profile_info.histogram[h_ix].num_counters)
1593 continue;
1595 file_data->profile_info.histogram[h_ix].num_counters
1596 = streamer_read_gcov_count (ib);
1597 file_data->profile_info.histogram[h_ix].min_value
1598 = streamer_read_gcov_count (ib);
1599 file_data->profile_info.histogram[h_ix].cum_value
1600 = streamer_read_gcov_count (ib);
1602 /* IPA-profile computes hot bb threshold based on cumulated
1603 whole program profile. We need to stream it down to ltrans. */
1604 if (flag_ltrans)
1605 set_hot_bb_threshold (streamer_read_gcov_count (ib));
1610 /* Rescale profile summaries to the same number of runs in the whole unit. */
1612 static void
1613 merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1615 struct lto_file_decl_data *file_data;
1616 unsigned int j, h_ix;
1617 gcov_unsigned_t max_runs = 0;
1618 struct cgraph_node *node;
1619 struct cgraph_edge *edge;
1620 gcov_type saved_sum_all = 0;
1621 gcov_ctr_summary *saved_profile_info = 0;
1622 int saved_scale = 0;
1624 /* Find unit with maximal number of runs. If we ever get serious about
1625 roundoff errors, we might also consider computing smallest common
1626 multiply. */
1627 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1628 if (max_runs < file_data->profile_info.runs)
1629 max_runs = file_data->profile_info.runs;
1631 if (!max_runs)
1632 return;
1634 /* Simple overflow check. We probably don't need to support that many train
1635 runs. Such a large value probably imply data corruption anyway. */
1636 if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1638 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1639 INT_MAX / REG_BR_PROB_BASE);
1640 return;
1643 profile_info = &lto_gcov_summary;
1644 lto_gcov_summary.runs = max_runs;
1645 lto_gcov_summary.sum_max = 0;
1646 memset (lto_gcov_summary.histogram, 0,
1647 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
1649 /* Rescale all units to the maximal number of runs.
1650 sum_max can not be easily merged, as we have no idea what files come from
1651 the same run. We do not use the info anyway, so leave it 0. */
1652 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1653 if (file_data->profile_info.runs)
1655 int scale = GCOV_COMPUTE_SCALE (max_runs,
1656 file_data->profile_info.runs);
1657 lto_gcov_summary.sum_max
1658 = MAX (lto_gcov_summary.sum_max,
1659 apply_scale (file_data->profile_info.sum_max, scale));
1660 lto_gcov_summary.sum_all
1661 = MAX (lto_gcov_summary.sum_all,
1662 apply_scale (file_data->profile_info.sum_all, scale));
1663 /* Save a pointer to the profile_info with the largest
1664 scaled sum_all and the scale for use in merging the
1665 histogram. */
1666 if (!saved_profile_info
1667 || lto_gcov_summary.sum_all > saved_sum_all)
1669 saved_profile_info = &file_data->profile_info;
1670 saved_sum_all = lto_gcov_summary.sum_all;
1671 saved_scale = scale;
1675 gcc_assert (saved_profile_info);
1677 /* Scale up the histogram from the profile that had the largest
1678 scaled sum_all above. */
1679 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1681 /* Scale up the min value as we did the corresponding sum_all
1682 above. Use that to find the new histogram index. */
1683 gcov_type scaled_min
1684 = apply_scale (saved_profile_info->histogram[h_ix].min_value,
1685 saved_scale);
1686 /* The new index may be shared with another scaled histogram entry,
1687 so we need to account for a non-zero histogram entry at new_ix. */
1688 unsigned new_ix = gcov_histo_index (scaled_min);
1689 lto_gcov_summary.histogram[new_ix].min_value
1690 = (lto_gcov_summary.histogram[new_ix].num_counters
1691 ? MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min)
1692 : scaled_min);
1693 /* Some of the scaled counter values would ostensibly need to be placed
1694 into different (larger) histogram buckets, but we keep things simple
1695 here and place the scaled cumulative counter value in the bucket
1696 corresponding to the scaled minimum counter value. */
1697 lto_gcov_summary.histogram[new_ix].cum_value
1698 += apply_scale (saved_profile_info->histogram[h_ix].cum_value,
1699 saved_scale);
1700 lto_gcov_summary.histogram[new_ix].num_counters
1701 += saved_profile_info->histogram[h_ix].num_counters;
1704 /* Watch roundoff errors. */
1705 if (lto_gcov_summary.sum_max < max_runs)
1706 lto_gcov_summary.sum_max = max_runs;
1708 /* If merging already happent at WPA time, we are done. */
1709 if (flag_ltrans)
1710 return;
1712 /* Now compute count_materialization_scale of each node.
1713 During LTRANS we already have values of count_materialization_scale
1714 computed, so just update them. */
1715 FOR_EACH_FUNCTION (node)
1716 if (node->lto_file_data
1717 && node->lto_file_data->profile_info.runs)
1719 int scale;
1721 scale = RDIV (node->count_materialization_scale * max_runs,
1722 node->lto_file_data->profile_info.runs);
1723 node->count_materialization_scale = scale;
1724 if (scale < 0)
1725 fatal_error ("Profile information in %s corrupted",
1726 file_data->file_name);
1728 if (scale == REG_BR_PROB_BASE)
1729 continue;
1730 for (edge = node->callees; edge; edge = edge->next_callee)
1731 edge->count = apply_scale (edge->count, scale);
1732 node->count = apply_scale (node->count, scale);
1736 /* Input and merge the symtab from each of the .o files passed to
1737 lto1. */
1739 void
1740 input_symtab (void)
1742 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1743 struct lto_file_decl_data *file_data;
1744 unsigned int j = 0;
1745 struct cgraph_node *node;
1747 while ((file_data = file_data_vec[j++]))
1749 const char *data;
1750 size_t len;
1751 struct lto_input_block *ib;
1752 vec<symtab_node *> nodes;
1754 ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
1755 &data, &len);
1756 if (!ib)
1757 fatal_error ("cannot find LTO cgraph in %s", file_data->file_name);
1758 input_profile_summary (ib, file_data);
1759 file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
1760 nodes = input_cgraph_1 (file_data, ib);
1761 lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
1762 ib, data, len);
1764 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1765 &data, &len);
1766 if (!ib)
1767 fatal_error ("cannot find LTO section refs in %s",
1768 file_data->file_name);
1769 input_refs (ib, nodes);
1770 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1771 ib, data, len);
1772 if (flag_ltrans)
1773 input_cgraph_opt_summary (nodes);
1774 nodes.release ();
1777 merge_profile_summaries (file_data_vec);
1778 get_working_sets ();
1781 /* Clear out the aux field that was used to store enough state to
1782 tell which nodes should be overwritten. */
1783 FOR_EACH_FUNCTION (node)
1785 /* Some nodes may have been created by cgraph_node. This
1786 happens when the callgraph contains nested functions. If the
1787 node for the parent function was never emitted to the gimple
1788 file, cgraph_node will create a node for it when setting the
1789 context of the nested function. */
1790 if (node->lto_file_data)
1791 node->aux = NULL;
1795 /* Input function/variable tables that will allow libgomp to look up offload
1796 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1798 void
1799 input_offload_tables (void)
1801 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1802 struct lto_file_decl_data *file_data;
1803 unsigned int j = 0;
1805 while ((file_data = file_data_vec[j++]))
1807 const char *data;
1808 size_t len;
1809 struct lto_input_block *ib
1810 = lto_create_simple_input_block (file_data, LTO_section_offload_table,
1811 &data, &len);
1812 if (!ib)
1813 continue;
1815 enum LTO_symtab_tags tag
1816 = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1817 while (tag)
1819 if (tag == LTO_symtab_unavail_node)
1821 int decl_index = streamer_read_uhwi (ib);
1822 tree fn_decl
1823 = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1824 vec_safe_push (offload_funcs, fn_decl);
1826 else if (tag == LTO_symtab_variable)
1828 int decl_index = streamer_read_uhwi (ib);
1829 tree var_decl
1830 = lto_file_decl_data_get_var_decl (file_data, decl_index);
1831 vec_safe_push (offload_vars, var_decl);
1833 else
1834 fatal_error ("invalid offload table in %s", file_data->file_name);
1836 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1839 lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
1840 ib, data, len);
1844 /* True when we need optimization summary for NODE. */
1846 static int
1847 output_cgraph_opt_summary_p (struct cgraph_node *node)
1849 return (node->clone_of
1850 && (node->clone.tree_map
1851 || node->clone.args_to_skip
1852 || node->clone.combined_args_to_skip));
1855 /* Output optimization summary for EDGE to OB. */
1856 static void
1857 output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
1858 struct cgraph_edge *edge ATTRIBUTE_UNUSED)
1862 /* Output optimization summary for NODE to OB. */
1864 static void
1865 output_node_opt_summary (struct output_block *ob,
1866 struct cgraph_node *node,
1867 lto_symtab_encoder_t encoder)
1869 unsigned int index;
1870 bitmap_iterator bi;
1871 struct ipa_replace_map *map;
1872 struct bitpack_d bp;
1873 int i;
1874 struct cgraph_edge *e;
1876 if (node->clone.args_to_skip)
1878 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.args_to_skip));
1879 EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi)
1880 streamer_write_uhwi (ob, index);
1882 else
1883 streamer_write_uhwi (ob, 0);
1884 if (node->clone.combined_args_to_skip)
1886 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.combined_args_to_skip));
1887 EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi)
1888 streamer_write_uhwi (ob, index);
1890 else
1891 streamer_write_uhwi (ob, 0);
1892 streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map));
1893 FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map)
1895 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1896 mechanism to store function local declarations into summaries. */
1897 gcc_assert (!map->old_tree);
1898 streamer_write_uhwi (ob, map->parm_num);
1899 gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
1900 stream_write_tree (ob, map->new_tree, true);
1901 bp = bitpack_create (ob->main_stream);
1902 bp_pack_value (&bp, map->replace_p, 1);
1903 bp_pack_value (&bp, map->ref_p, 1);
1904 streamer_write_bitpack (&bp);
1907 if (lto_symtab_encoder_in_partition_p (encoder, node))
1909 for (e = node->callees; e; e = e->next_callee)
1910 output_edge_opt_summary (ob, e);
1911 for (e = node->indirect_calls; e; e = e->next_callee)
1912 output_edge_opt_summary (ob, e);
1916 /* Output optimization summaries stored in callgraph.
1917 At the moment it is the clone info structure. */
1919 static void
1920 output_cgraph_opt_summary (void)
1922 int i, n_nodes;
1923 lto_symtab_encoder_t encoder;
1924 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
1925 unsigned count = 0;
1927 ob->symbol = NULL;
1928 encoder = ob->decl_state->symtab_node_encoder;
1929 n_nodes = lto_symtab_encoder_size (encoder);
1930 for (i = 0; i < n_nodes; i++)
1932 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1933 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1934 if (cnode && output_cgraph_opt_summary_p (cnode))
1935 count++;
1937 streamer_write_uhwi (ob, count);
1938 for (i = 0; i < n_nodes; i++)
1940 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1941 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1942 if (cnode && output_cgraph_opt_summary_p (cnode))
1944 streamer_write_uhwi (ob, i);
1945 output_node_opt_summary (ob, cnode, encoder);
1948 produce_asm (ob, NULL);
1949 destroy_output_block (ob);
1952 /* Input optimisation summary of EDGE. */
1954 static void
1955 input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
1956 struct lto_input_block *ib_main ATTRIBUTE_UNUSED)
1960 /* Input optimisation summary of NODE. */
1962 static void
1963 input_node_opt_summary (struct cgraph_node *node,
1964 struct lto_input_block *ib_main,
1965 struct data_in *data_in)
1967 int i;
1968 int count;
1969 int bit;
1970 struct bitpack_d bp;
1971 struct cgraph_edge *e;
1973 count = streamer_read_uhwi (ib_main);
1974 if (count)
1975 node->clone.args_to_skip = BITMAP_GGC_ALLOC ();
1976 for (i = 0; i < count; i++)
1978 bit = streamer_read_uhwi (ib_main);
1979 bitmap_set_bit (node->clone.args_to_skip, bit);
1981 count = streamer_read_uhwi (ib_main);
1982 if (count)
1983 node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC ();
1984 for (i = 0; i < count; i++)
1986 bit = streamer_read_uhwi (ib_main);
1987 bitmap_set_bit (node->clone.combined_args_to_skip, bit);
1989 count = streamer_read_uhwi (ib_main);
1990 for (i = 0; i < count; i++)
1992 struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
1994 vec_safe_push (node->clone.tree_map, map);
1995 map->parm_num = streamer_read_uhwi (ib_main);
1996 map->old_tree = NULL;
1997 map->new_tree = stream_read_tree (ib_main, data_in);
1998 bp = streamer_read_bitpack (ib_main);
1999 map->replace_p = bp_unpack_value (&bp, 1);
2000 map->ref_p = bp_unpack_value (&bp, 1);
2002 for (e = node->callees; e; e = e->next_callee)
2003 input_edge_opt_summary (e, ib_main);
2004 for (e = node->indirect_calls; e; e = e->next_callee)
2005 input_edge_opt_summary (e, ib_main);
2008 /* Read section in file FILE_DATA of length LEN with data DATA. */
2010 static void
2011 input_cgraph_opt_section (struct lto_file_decl_data *file_data,
2012 const char *data, size_t len,
2013 vec<symtab_node *> nodes)
2015 const struct lto_function_header *header =
2016 (const struct lto_function_header *) data;
2017 const int cfg_offset = sizeof (struct lto_function_header);
2018 const int main_offset = cfg_offset + header->cfg_size;
2019 const int string_offset = main_offset + header->main_size;
2020 struct data_in *data_in;
2021 unsigned int i;
2022 unsigned int count;
2024 lto_input_block ib_main ((const char *) data + main_offset,
2025 header->main_size);
2027 data_in =
2028 lto_data_in_create (file_data, (const char *) data + string_offset,
2029 header->string_size, vNULL);
2030 count = streamer_read_uhwi (&ib_main);
2032 for (i = 0; i < count; i++)
2034 int ref = streamer_read_uhwi (&ib_main);
2035 input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
2036 &ib_main, data_in);
2038 lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
2039 len);
2040 lto_data_in_delete (data_in);
2043 /* Input optimization summary of cgraph. */
2045 static void
2046 input_cgraph_opt_summary (vec<symtab_node *> nodes)
2048 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2049 struct lto_file_decl_data *file_data;
2050 unsigned int j = 0;
2052 while ((file_data = file_data_vec[j++]))
2054 size_t len;
2055 const char *data =
2056 lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL,
2057 &len);
2059 if (data)
2060 input_cgraph_opt_section (file_data, data, len, nodes);