1 /* Write and read the cgraph to the memory mapped representation of a
4 Copyright 2009, 2010 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
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
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/>. */
25 #include "coretypes.h"
34 #include "langhooks.h"
35 #include "basic-block.h"
36 #include "tree-flow.h"
40 #include "diagnostic-core.h"
45 #include "pointer-set.h"
46 #include "lto-streamer.h"
49 static void output_varpool (cgraph_node_set, varpool_node_set);
50 static void output_cgraph_opt_summary (void);
51 static void input_cgraph_opt_summary (VEC (cgraph_node_ptr, heap) * nodes);
54 /* Cgraph streaming is organized as set of record whose type
55 is indicated by a tag. */
58 /* Must leave 0 for the stopper. */
60 /* Cgraph node without body available. */
61 LTO_cgraph_unavail_node = 1,
62 /* Cgraph node with function body. */
63 LTO_cgraph_analyzed_node,
66 LTO_cgraph_indirect_edge
69 /* Create a new cgraph encoder. */
72 lto_cgraph_encoder_new (void)
74 lto_cgraph_encoder_t encoder = XCNEW (struct lto_cgraph_encoder_d);
75 encoder->map = pointer_map_create ();
76 encoder->nodes = NULL;
77 encoder->body = pointer_set_create ();
82 /* Delete ENCODER and its components. */
85 lto_cgraph_encoder_delete (lto_cgraph_encoder_t encoder)
87 VEC_free (cgraph_node_ptr, heap, encoder->nodes);
88 pointer_map_destroy (encoder->map);
89 pointer_set_destroy (encoder->body);
94 /* Return the existing reference number of NODE in the cgraph encoder in
95 output block OB. Assign a new reference if this is the first time
99 lto_cgraph_encoder_encode (lto_cgraph_encoder_t encoder,
100 struct cgraph_node *node)
105 slot = pointer_map_contains (encoder->map, node);
108 ref = VEC_length (cgraph_node_ptr, encoder->nodes);
109 slot = pointer_map_insert (encoder->map, node);
110 *slot = (void *) (intptr_t) ref;
111 VEC_safe_push (cgraph_node_ptr, heap, encoder->nodes, node);
114 ref = (int) (intptr_t) *slot;
119 #define LCC_NOT_FOUND (-1)
121 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
122 or LCC_NOT_FOUND if it is not there. */
125 lto_cgraph_encoder_lookup (lto_cgraph_encoder_t encoder,
126 struct cgraph_node *node)
128 void **slot = pointer_map_contains (encoder->map, node);
129 return (slot ? (int) (intptr_t) *slot : LCC_NOT_FOUND);
133 /* Return the cgraph node corresponding to REF using ENCODER. */
136 lto_cgraph_encoder_deref (lto_cgraph_encoder_t encoder, int ref)
138 if (ref == LCC_NOT_FOUND)
141 return VEC_index (cgraph_node_ptr, encoder->nodes, ref);
145 /* Return TRUE if we should encode initializer of NODE (if any). */
148 lto_cgraph_encoder_encode_body_p (lto_cgraph_encoder_t encoder,
149 struct cgraph_node *node)
151 return pointer_set_contains (encoder->body, node);
154 /* Return TRUE if we should encode body of NODE (if any). */
157 lto_set_cgraph_encoder_encode_body (lto_cgraph_encoder_t encoder,
158 struct cgraph_node *node)
160 pointer_set_insert (encoder->body, node);
163 /* Create a new varpool encoder. */
165 lto_varpool_encoder_t
166 lto_varpool_encoder_new (void)
168 lto_varpool_encoder_t encoder = XCNEW (struct lto_varpool_encoder_d);
169 encoder->map = pointer_map_create ();
170 encoder->initializer = pointer_set_create ();
171 encoder->nodes = NULL;
176 /* Delete ENCODER and its components. */
179 lto_varpool_encoder_delete (lto_varpool_encoder_t encoder)
181 VEC_free (varpool_node_ptr, heap, encoder->nodes);
182 pointer_map_destroy (encoder->map);
183 pointer_set_destroy (encoder->initializer);
188 /* Return the existing reference number of NODE in the varpool encoder in
189 output block OB. Assign a new reference if this is the first time
193 lto_varpool_encoder_encode (lto_varpool_encoder_t encoder,
194 struct varpool_node *node)
199 slot = pointer_map_contains (encoder->map, node);
202 ref = VEC_length (varpool_node_ptr, encoder->nodes);
203 slot = pointer_map_insert (encoder->map, node);
204 *slot = (void *) (intptr_t) ref;
205 VEC_safe_push (varpool_node_ptr, heap, encoder->nodes, node);
208 ref = (int) (intptr_t) *slot;
213 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
214 or LCC_NOT_FOUND if it is not there. */
217 lto_varpool_encoder_lookup (lto_varpool_encoder_t encoder,
218 struct varpool_node *node)
220 void **slot = pointer_map_contains (encoder->map, node);
221 return (slot ? (int) (intptr_t) *slot : LCC_NOT_FOUND);
225 /* Return the varpool node corresponding to REF using ENCODER. */
227 struct varpool_node *
228 lto_varpool_encoder_deref (lto_varpool_encoder_t encoder, int ref)
230 if (ref == LCC_NOT_FOUND)
233 return VEC_index (varpool_node_ptr, encoder->nodes, ref);
237 /* Return TRUE if we should encode initializer of NODE (if any). */
240 lto_varpool_encoder_encode_initializer_p (lto_varpool_encoder_t encoder,
241 struct varpool_node *node)
243 return pointer_set_contains (encoder->initializer, node);
246 /* Return TRUE if we should encode initializer of NODE (if any). */
249 lto_set_varpool_encoder_encode_initializer (lto_varpool_encoder_t encoder,
250 struct varpool_node *node)
252 pointer_set_insert (encoder->initializer, node);
255 /* Output the cgraph EDGE to OB using ENCODER. */
258 lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
259 lto_cgraph_encoder_t encoder)
263 struct bitpack_d *bp;
265 if (edge->indirect_unknown_callee)
266 lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_indirect_edge);
268 lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_edge);
270 ref = lto_cgraph_encoder_lookup (encoder, edge->caller);
271 gcc_assert (ref != LCC_NOT_FOUND);
272 lto_output_sleb128_stream (ob->main_stream, ref);
274 if (!edge->indirect_unknown_callee)
276 ref = lto_cgraph_encoder_lookup (encoder, edge->callee);
277 gcc_assert (ref != LCC_NOT_FOUND);
278 lto_output_sleb128_stream (ob->main_stream, ref);
281 lto_output_sleb128_stream (ob->main_stream, edge->count);
283 bp = bitpack_create ();
284 uid = flag_wpa ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt);
285 bp_pack_value (bp, uid, HOST_BITS_PER_INT);
286 bp_pack_value (bp, edge->inline_failed, HOST_BITS_PER_INT);
287 bp_pack_value (bp, edge->frequency, HOST_BITS_PER_INT);
288 bp_pack_value (bp, edge->loop_nest, 30);
289 bp_pack_value (bp, edge->indirect_inlining_edge, 1);
290 bp_pack_value (bp, edge->call_stmt_cannot_inline_p, 1);
291 bp_pack_value (bp, edge->can_throw_external, 1);
292 if (edge->indirect_unknown_callee)
294 int flags = edge->indirect_info->ecf_flags;
295 bp_pack_value (bp, (flags & ECF_CONST) != 0, 1);
296 bp_pack_value (bp, (flags & ECF_PURE) != 0, 1);
297 bp_pack_value (bp, (flags & ECF_NORETURN) != 0, 1);
298 bp_pack_value (bp, (flags & ECF_MALLOC) != 0, 1);
299 bp_pack_value (bp, (flags & ECF_NOTHROW) != 0, 1);
300 bp_pack_value (bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
301 /* Flags that should not appear on indirect calls. */
302 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
307 lto_output_bitpack (ob->main_stream, bp);
311 /* Return if LIST contain references from other partitions. */
314 referenced_from_other_partition_p (struct ipa_ref_list *list, cgraph_node_set set,
315 varpool_node_set vset)
319 for (i = 0; ipa_ref_list_refering_iterate (list, i, ref); i++)
321 if (ref->refering_type == IPA_REF_CGRAPH)
323 if (!cgraph_node_in_set_p (ipa_ref_refering_node (ref), set))
328 if (!varpool_node_in_set_p (ipa_ref_refering_varpool_node (ref),
336 /* Return true when node is reachable from other partition. */
339 reachable_from_other_partition_p (struct cgraph_node *node, cgraph_node_set set)
341 struct cgraph_edge *e;
344 if (node->global.inlined_to)
346 for (e = node->callers; e; e = e->next_caller)
347 if (!cgraph_node_in_set_p (e->caller, set))
352 /* Return if LIST contain references from other partitions. */
355 referenced_from_this_partition_p (struct ipa_ref_list *list, cgraph_node_set set,
356 varpool_node_set vset)
360 for (i = 0; ipa_ref_list_refering_iterate (list, i, ref); i++)
362 if (ref->refering_type == IPA_REF_CGRAPH)
364 if (cgraph_node_in_set_p (ipa_ref_refering_node (ref), set))
369 if (varpool_node_in_set_p (ipa_ref_refering_varpool_node (ref),
377 /* Return true when node is reachable from other partition. */
380 reachable_from_this_partition_p (struct cgraph_node *node, cgraph_node_set set)
382 struct cgraph_edge *e;
385 if (node->global.inlined_to)
387 for (e = node->callers; e; e = e->next_caller)
388 if (cgraph_node_in_set_p (e->caller, set))
393 /* Output the cgraph NODE to OB. ENCODER is used to find the
394 reference number of NODE->inlined_to. SET is the set of nodes we
395 are writing to the current file. If NODE is not in SET, then NODE
396 is a boundary of a cgraph_node_set and we pretend NODE just has a
397 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
398 that have had their callgraph node written so far. This is used to
399 determine if NODE is a clone of a previously written node. */
402 lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
403 lto_cgraph_encoder_t encoder, cgraph_node_set set,
404 varpool_node_set vset)
407 struct bitpack_d *bp;
410 bool in_other_partition = false;
411 struct cgraph_node *clone_of;
413 boundary_p = !cgraph_node_in_set_p (node, set);
415 if (node->analyzed && !boundary_p)
416 tag = LTO_cgraph_analyzed_node;
418 tag = LTO_cgraph_unavail_node;
420 lto_output_uleb128_stream (ob->main_stream, tag);
422 /* In WPA mode, we only output part of the call-graph. Also, we
423 fake cgraph node attributes. There are two cases that we care.
425 Boundary nodes: There are nodes that are not part of SET but are
426 called from within SET. We artificially make them look like
427 externally visible nodes with no function body.
429 Cherry-picked nodes: These are nodes we pulled from other
430 translation units into SET during IPA-inlining. We make them as
431 local static nodes to prevent clashes with other local statics. */
432 if (boundary_p && node->analyzed)
434 /* Inline clones can not be part of boundary.
435 gcc_assert (!node->global.inlined_to);
437 FIXME: At the moment they can be, when partition contains an inline
438 clone that is clone of inline clone from outside partition. We can
439 reshape the clone tree and make other tree to be the root, but it
440 needs a bit extra work and will be promplty done by cgraph_remove_node
441 after reading back. */
442 in_other_partition = 1;
445 clone_of = node->clone_of;
447 && (ref = lto_cgraph_encoder_lookup (encoder, node->clone_of)) == LCC_NOT_FOUND)
448 if (clone_of->prev_sibling_clone)
449 clone_of = clone_of->prev_sibling_clone;
451 clone_of = clone_of->clone_of;
453 lto_output_sleb128_stream (ob->main_stream, LCC_NOT_FOUND);
455 lto_output_sleb128_stream (ob->main_stream, ref);
458 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
459 lto_output_sleb128_stream (ob->main_stream, node->count);
461 bp = bitpack_create ();
462 bp_pack_value (bp, node->local.local, 1);
463 bp_pack_value (bp, node->local.externally_visible, 1);
464 bp_pack_value (bp, node->local.finalized, 1);
465 bp_pack_value (bp, node->local.inlinable, 1);
466 bp_pack_value (bp, node->local.versionable, 1);
467 bp_pack_value (bp, node->local.disregard_inline_limits, 1);
468 bp_pack_value (bp, node->local.redefined_extern_inline, 1);
469 bp_pack_value (bp, node->local.vtable_method, 1);
470 bp_pack_value (bp, node->needed, 1);
471 bp_pack_value (bp, node->address_taken, 1);
472 bp_pack_value (bp, node->abstract_and_needed, 1);
473 bp_pack_value (bp, tag == LTO_cgraph_analyzed_node
474 && !DECL_EXTERNAL (node->decl)
475 && (reachable_from_other_partition_p (node, set)
476 || referenced_from_other_partition_p (&node->ref_list, set, vset)), 1);
477 bp_pack_value (bp, node->lowered, 1);
478 bp_pack_value (bp, in_other_partition, 1);
479 bp_pack_value (bp, node->alias, 1);
480 bp_pack_value (bp, node->finalized_by_frontend, 1);
481 bp_pack_value (bp, node->frequency, 2);
482 lto_output_bitpack (ob->main_stream, bp);
485 if (tag == LTO_cgraph_analyzed_node)
487 lto_output_sleb128_stream (ob->main_stream,
488 node->local.inline_summary.estimated_self_stack_size);
489 lto_output_sleb128_stream (ob->main_stream,
490 node->local.inline_summary.self_size);
491 lto_output_sleb128_stream (ob->main_stream,
492 node->local.inline_summary.size_inlining_benefit);
493 lto_output_sleb128_stream (ob->main_stream,
494 node->local.inline_summary.self_time);
495 lto_output_sleb128_stream (ob->main_stream,
496 node->local.inline_summary.time_inlining_benefit);
497 if (node->global.inlined_to)
499 ref = lto_cgraph_encoder_lookup (encoder, node->global.inlined_to);
500 gcc_assert (ref != LCC_NOT_FOUND);
505 lto_output_sleb128_stream (ob->main_stream, ref);
508 if (node->same_comdat_group && !boundary_p)
510 ref = lto_cgraph_encoder_lookup (encoder, node->same_comdat_group);
511 gcc_assert (ref != LCC_NOT_FOUND);
515 lto_output_sleb128_stream (ob->main_stream, ref);
519 struct cgraph_node *alias;
520 unsigned long alias_count = 1;
521 for (alias = node->same_body; alias->next; alias = alias->next)
523 lto_output_uleb128_stream (ob->main_stream, alias_count);
526 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
528 if (alias->thunk.thunk_p)
530 lto_output_uleb128_stream
532 1 + (alias->thunk.this_adjusting != 0) * 2
533 + (alias->thunk.virtual_offset_p != 0) * 4);
534 lto_output_uleb128_stream (ob->main_stream,
535 alias->thunk.fixed_offset);
536 lto_output_uleb128_stream (ob->main_stream,
537 alias->thunk.virtual_value);
538 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
543 lto_output_uleb128_stream (ob->main_stream, 0);
544 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
547 alias = alias->previous;
552 lto_output_uleb128_stream (ob->main_stream, 0);
555 /* Output the varpool NODE to OB.
556 If NODE is not in SET, then NODE is a boundary. */
559 lto_output_varpool_node (struct lto_simple_output_block *ob, struct varpool_node *node,
560 lto_varpool_encoder_t varpool_encoder,
561 cgraph_node_set set, varpool_node_set vset)
563 bool boundary_p = !varpool_node_in_set_p (node, vset) && node->analyzed;
564 struct bitpack_d *bp;
565 struct varpool_node *alias;
569 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl);
570 bp = bitpack_create ();
571 bp_pack_value (bp, node->externally_visible, 1);
572 bp_pack_value (bp, node->force_output, 1);
573 bp_pack_value (bp, node->finalized, 1);
574 bp_pack_value (bp, node->alias, 1);
575 gcc_assert (!node->alias || !node->extra_name);
576 gcc_assert (node->finalized || !node->analyzed);
577 gcc_assert (node->needed);
578 /* Constant pool initializers can be de-unified into individual ltrans units.
579 FIXME: Alternatively at -Os we may want to avoid generating for them the local
580 labels and share them across LTRANS partitions. */
581 if (DECL_IN_CONSTANT_POOL (node->decl))
583 bp_pack_value (bp, 0, 1); /* used_from_other_parition. */
584 bp_pack_value (bp, 0, 1); /* in_other_partition. */
588 bp_pack_value (bp, node->analyzed
589 && referenced_from_other_partition_p (&node->ref_list,
591 bp_pack_value (bp, boundary_p, 1); /* in_other_partition. */
593 /* Also emit any extra name aliases. */
594 for (alias = node->extra_name; alias; alias = alias->next)
596 bp_pack_value (bp, count != 0, 1);
597 lto_output_bitpack (ob->main_stream, bp);
599 if (node->same_comdat_group && !boundary_p)
601 ref = lto_varpool_encoder_lookup (varpool_encoder, node->same_comdat_group);
602 gcc_assert (ref != LCC_NOT_FOUND);
606 lto_output_sleb128_stream (ob->main_stream, ref);
610 lto_output_uleb128_stream (ob->main_stream, count);
611 for (alias = node->extra_name; alias; alias = alias->next)
612 lto_output_var_decl_index (ob->decl_state, ob->main_stream, alias->decl);
616 /* Output the varpool NODE to OB.
617 If NODE is not in SET, then NODE is a boundary. */
620 lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
621 lto_cgraph_encoder_t encoder,
622 lto_varpool_encoder_t varpool_encoder)
624 struct bitpack_d *bp = bitpack_create ();
625 bp_pack_value (bp, ref->refered_type, 1);
626 bp_pack_value (bp, ref->use, 2);
627 lto_output_bitpack (ob->main_stream, bp);
629 if (ref->refered_type == IPA_REF_CGRAPH)
631 int nref = lto_cgraph_encoder_lookup (encoder, ipa_ref_node (ref));
632 gcc_assert (nref != LCC_NOT_FOUND);
633 lto_output_sleb128_stream (ob->main_stream, nref);
637 int nref = lto_varpool_encoder_lookup (varpool_encoder,
638 ipa_ref_varpool_node (ref));
639 gcc_assert (nref != LCC_NOT_FOUND);
640 lto_output_sleb128_stream (ob->main_stream, nref);
644 /* Stream out profile_summary to OB. */
647 output_profile_summary (struct lto_simple_output_block *ob)
651 /* We do not output num, it is not terribly useful. */
652 gcc_assert (profile_info->runs);
653 lto_output_uleb128_stream (ob->main_stream, profile_info->runs);
654 lto_output_sleb128_stream (ob->main_stream, profile_info->sum_all);
655 lto_output_sleb128_stream (ob->main_stream, profile_info->run_max);
656 lto_output_sleb128_stream (ob->main_stream, profile_info->sum_max);
659 lto_output_uleb128_stream (ob->main_stream, 0);
662 /* Add NODE into encoder as well as nodes it is cloned from.
663 Do it in a way so clones appear first. */
666 add_node_to (lto_cgraph_encoder_t encoder, struct cgraph_node *node,
670 add_node_to (encoder, node->clone_of, include_body);
671 else if (include_body)
672 lto_set_cgraph_encoder_encode_body (encoder, node);
673 lto_cgraph_encoder_encode (encoder, node);
676 /* Add all references in LIST to encoders. */
679 add_references (lto_cgraph_encoder_t encoder,
680 lto_varpool_encoder_t varpool_encoder,
681 struct ipa_ref_list *list)
685 for (i = 0; ipa_ref_list_reference_iterate (list, i, ref); i++)
686 if (ref->refered_type == IPA_REF_CGRAPH)
687 add_node_to (encoder, ipa_ref_node (ref), false);
690 struct varpool_node *vnode = ipa_ref_varpool_node (ref);
691 lto_varpool_encoder_encode (varpool_encoder, vnode);
695 /* Output all callees or indirect outgoing edges. EDGE must be the first such
699 output_outgoing_cgraph_edges (struct cgraph_edge *edge,
700 struct lto_simple_output_block *ob,
701 lto_cgraph_encoder_t encoder)
706 /* Output edges in backward direction, so the reconstructed callgraph match
707 and it is easy to associate call sites in the IPA pass summaries. */
708 while (edge->next_callee)
709 edge = edge->next_callee;
710 for (; edge; edge = edge->prev_callee)
711 lto_output_edge (ob, edge, encoder);
714 /* Output the part of the cgraph in SET. */
717 output_refs (cgraph_node_set set, varpool_node_set vset,
718 lto_cgraph_encoder_t encoder,
719 lto_varpool_encoder_t varpool_encoder)
721 cgraph_node_set_iterator csi;
722 varpool_node_set_iterator vsi;
723 struct lto_simple_output_block *ob;
728 ob = lto_create_simple_output_block (LTO_section_refs);
730 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
732 struct cgraph_node *node = csi_node (csi);
734 count = ipa_ref_list_nreferences (&node->ref_list);
737 lto_output_uleb128_stream (ob->main_stream, count);
738 lto_output_uleb128_stream (ob->main_stream,
739 lto_cgraph_encoder_lookup (encoder, node));
740 for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, i, ref); i++)
741 lto_output_ref (ob, ref, encoder, varpool_encoder);
745 lto_output_uleb128_stream (ob->main_stream, 0);
747 for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi))
749 struct varpool_node *node = vsi_node (vsi);
751 count = ipa_ref_list_nreferences (&node->ref_list);
754 lto_output_uleb128_stream (ob->main_stream, count);
755 lto_output_uleb128_stream (ob->main_stream,
756 lto_varpool_encoder_lookup (varpool_encoder,
758 for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, i, ref); i++)
759 lto_output_ref (ob, ref, encoder, varpool_encoder);
763 lto_output_uleb128_stream (ob->main_stream, 0);
765 lto_destroy_simple_output_block (ob);
768 /* Find out all cgraph and varpool nodes we want to encode in current unit
769 and insert them to encoders. */
771 compute_ltrans_boundary (struct lto_out_decl_state *state,
772 cgraph_node_set set, varpool_node_set vset)
774 struct cgraph_node *node;
775 cgraph_node_set_iterator csi;
776 varpool_node_set_iterator vsi;
777 struct cgraph_edge *edge;
779 lto_cgraph_encoder_t encoder;
780 lto_varpool_encoder_t varpool_encoder;
782 encoder = state->cgraph_node_encoder = lto_cgraph_encoder_new ();
783 varpool_encoder = state->varpool_node_encoder = lto_varpool_encoder_new ();
785 /* Go over all the nodes in SET and assign references. */
786 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
788 node = csi_node (csi);
789 add_node_to (encoder, node, true);
790 add_references (encoder, varpool_encoder, &node->ref_list);
792 for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi))
794 struct varpool_node *vnode = vsi_node (vsi);
795 gcc_assert (!vnode->alias);
796 lto_varpool_encoder_encode (varpool_encoder, vnode);
797 lto_set_varpool_encoder_encode_initializer (varpool_encoder, vnode);
798 add_references (encoder, varpool_encoder, &vnode->ref_list);
800 /* Pickle in also the initializer of all referenced readonly variables
801 to help folding. Constant pool variables are not shared, so we must
803 for (i = 0; i < lto_varpool_encoder_size (varpool_encoder); i++)
805 struct varpool_node *vnode = lto_varpool_encoder_deref (varpool_encoder, i);
806 if (DECL_INITIAL (vnode->decl)
807 && !lto_varpool_encoder_encode_initializer_p (varpool_encoder,
809 && (DECL_IN_CONSTANT_POOL (vnode->decl)
810 || TREE_READONLY (vnode->decl)))
812 lto_set_varpool_encoder_encode_initializer (varpool_encoder, vnode);
813 add_references (encoder, varpool_encoder, &vnode->ref_list);
817 /* Go over all the nodes again to include callees that are not in
819 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
821 node = csi_node (csi);
822 for (edge = node->callees; edge; edge = edge->next_callee)
824 struct cgraph_node *callee = edge->callee;
825 if (!cgraph_node_in_set_p (callee, set))
827 /* We should have moved all the inlines. */
828 gcc_assert (!callee->global.inlined_to);
829 add_node_to (encoder, callee, false);
835 /* Output the part of the cgraph in SET. */
838 output_cgraph (cgraph_node_set set, varpool_node_set vset)
840 struct cgraph_node *node;
841 struct lto_simple_output_block *ob;
842 cgraph_node_set_iterator csi;
844 lto_cgraph_encoder_t encoder;
845 lto_varpool_encoder_t varpool_encoder;
846 struct cgraph_asm_node *can;
849 output_cgraph_opt_summary ();
851 ob = lto_create_simple_output_block (LTO_section_cgraph);
853 output_profile_summary (ob);
855 /* An encoder for cgraph nodes should have been created by
856 ipa_write_summaries_1. */
857 gcc_assert (ob->decl_state->cgraph_node_encoder);
858 gcc_assert (ob->decl_state->varpool_node_encoder);
859 encoder = ob->decl_state->cgraph_node_encoder;
860 varpool_encoder = ob->decl_state->varpool_node_encoder;
862 /* Write out the nodes. We must first output a node and then its clones,
863 otherwise at a time reading back the node there would be nothing to clone
865 n_nodes = lto_cgraph_encoder_size (encoder);
866 for (i = 0; i < n_nodes; i++)
868 node = lto_cgraph_encoder_deref (encoder, i);
869 lto_output_node (ob, node, encoder, set, vset);
872 /* Go over the nodes in SET again to write edges. */
873 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
875 node = csi_node (csi);
876 output_outgoing_cgraph_edges (node->callees, ob, encoder);
877 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
880 lto_output_uleb128_stream (ob->main_stream, 0);
882 /* Emit toplevel asms. */
883 for (can = cgraph_asm_nodes; can; can = can->next)
885 int len = TREE_STRING_LENGTH (can->asm_str);
886 lto_output_uleb128_stream (ob->main_stream, len);
887 for (i = 0; i < len; ++i)
888 lto_output_1_stream (ob->main_stream,
889 TREE_STRING_POINTER (can->asm_str)[i]);
892 lto_output_uleb128_stream (ob->main_stream, 0);
894 lto_destroy_simple_output_block (ob);
895 output_varpool (set, vset);
896 output_refs (set, vset, encoder, varpool_encoder);
899 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
900 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
901 NODE or to replace the values in it, for instance because the first
902 time we saw it, the function body was not available but now it
903 is. BP is a bitpack with all the bitflags for NODE read from the
907 input_overwrite_node (struct lto_file_decl_data *file_data,
908 struct cgraph_node *node,
909 enum LTO_cgraph_tags tag,
910 struct bitpack_d *bp,
911 unsigned int stack_size,
912 unsigned int self_time,
913 unsigned int time_inlining_benefit,
914 unsigned int self_size,
915 unsigned int size_inlining_benefit)
917 node->aux = (void *) tag;
918 node->local.inline_summary.estimated_self_stack_size = stack_size;
919 node->local.inline_summary.self_time = self_time;
920 node->local.inline_summary.time_inlining_benefit = time_inlining_benefit;
921 node->local.inline_summary.self_size = self_size;
922 node->local.inline_summary.size_inlining_benefit = size_inlining_benefit;
923 node->global.time = self_time;
924 node->global.size = self_size;
925 node->global.estimated_stack_size = stack_size;
926 node->global.estimated_growth = INT_MIN;
927 node->local.lto_file_data = file_data;
929 node->local.local = bp_unpack_value (bp, 1);
930 node->local.externally_visible = bp_unpack_value (bp, 1);
931 node->local.finalized = bp_unpack_value (bp, 1);
932 node->local.inlinable = bp_unpack_value (bp, 1);
933 node->local.versionable = bp_unpack_value (bp, 1);
934 node->local.disregard_inline_limits = bp_unpack_value (bp, 1);
935 node->local.redefined_extern_inline = bp_unpack_value (bp, 1);
936 node->local.vtable_method = bp_unpack_value (bp, 1);
937 node->needed = bp_unpack_value (bp, 1);
938 node->address_taken = bp_unpack_value (bp, 1);
939 node->abstract_and_needed = bp_unpack_value (bp, 1);
940 node->reachable_from_other_partition = bp_unpack_value (bp, 1);
941 node->lowered = bp_unpack_value (bp, 1);
942 node->analyzed = tag == LTO_cgraph_analyzed_node;
943 node->in_other_partition = bp_unpack_value (bp, 1);
944 node->alias = bp_unpack_value (bp, 1);
945 node->finalized_by_frontend = bp_unpack_value (bp, 1);
946 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
949 /* Output the part of the cgraph in SET. */
952 output_varpool (cgraph_node_set set, varpool_node_set vset)
954 struct lto_simple_output_block *ob = lto_create_simple_output_block (LTO_section_varpool);
955 lto_varpool_encoder_t varpool_encoder = ob->decl_state->varpool_node_encoder;
956 int len = lto_varpool_encoder_size (varpool_encoder), i;
958 lto_output_uleb128_stream (ob->main_stream, len);
960 /* Write out the nodes. We must first output a node and then its clones,
961 otherwise at a time reading back the node there would be nothing to clone
963 for (i = 0; i < len; i++)
965 lto_output_varpool_node (ob, lto_varpool_encoder_deref (varpool_encoder, i),
970 lto_destroy_simple_output_block (ob);
973 /* Read a node from input_block IB. TAG is the node's tag just read.
974 Return the node read or overwriten. */
976 static struct cgraph_node *
977 input_node (struct lto_file_decl_data *file_data,
978 struct lto_input_block *ib,
979 enum LTO_cgraph_tags tag,
980 VEC(cgraph_node_ptr, heap) *nodes)
983 struct cgraph_node *node;
984 struct bitpack_d *bp;
987 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
990 int time_inlining_benefit = 0;
991 int size_inlining_benefit = 0;
992 unsigned long same_body_count = 0;
995 clone_ref = lto_input_sleb128 (ib);
997 decl_index = lto_input_uleb128 (ib);
998 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1000 if (clone_ref != LCC_NOT_FOUND)
1002 node = cgraph_clone_node (VEC_index (cgraph_node_ptr, nodes, clone_ref), fn_decl,
1003 0, CGRAPH_FREQ_BASE, 0, false, NULL);
1006 node = cgraph_node (fn_decl);
1008 node->count = lto_input_sleb128 (ib);
1009 bp = lto_input_bitpack (ib);
1011 if (tag == LTO_cgraph_analyzed_node)
1013 stack_size = lto_input_sleb128 (ib);
1014 self_size = lto_input_sleb128 (ib);
1015 size_inlining_benefit = lto_input_sleb128 (ib);
1016 self_time = lto_input_sleb128 (ib);
1017 time_inlining_benefit = lto_input_sleb128 (ib);
1019 ref = lto_input_sleb128 (ib);
1022 ref2 = lto_input_sleb128 (ib);
1023 same_body_count = lto_input_uleb128 (ib);
1025 /* Make sure that we have not read this node before. Nodes that
1026 have already been read will have their tag stored in the 'aux'
1027 field. Since built-in functions can be referenced in multiple
1028 functions, they are expected to be read more than once. */
1029 if (node->aux && !DECL_IS_BUILTIN (node->decl))
1030 internal_error ("bytecode stream: found multiple instances of cgraph "
1031 "node %d", node->uid);
1033 input_overwrite_node (file_data, node, tag, bp, stack_size, self_time,
1034 time_inlining_benefit, self_size,
1035 size_inlining_benefit);
1036 bitpack_delete (bp);
1038 /* Store a reference for now, and fix up later to be a pointer. */
1039 node->global.inlined_to = (cgraph_node_ptr) (intptr_t) ref;
1041 /* Store a reference for now, and fix up later to be a pointer. */
1042 node->same_comdat_group = (cgraph_node_ptr) (intptr_t) ref2;
1044 while (same_body_count-- > 0)
1048 decl_index = lto_input_uleb128 (ib);
1049 alias_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1050 type = lto_input_uleb128 (ib);
1054 decl_index = lto_input_uleb128 (ib);
1055 real_alias = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1056 cgraph_same_body_alias (alias_decl, real_alias);
1060 HOST_WIDE_INT fixed_offset = lto_input_uleb128 (ib);
1061 HOST_WIDE_INT virtual_value = lto_input_uleb128 (ib);
1063 decl_index = lto_input_uleb128 (ib);
1064 real_alias = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1065 cgraph_add_thunk (alias_decl, fn_decl, type & 2, fixed_offset,
1067 (type & 4) ? size_int (virtual_value) : NULL_TREE,
1074 /* Read a node from input_block IB. TAG is the node's tag just read.
1075 Return the node read or overwriten. */
1077 static struct varpool_node *
1078 input_varpool_node (struct lto_file_decl_data *file_data,
1079 struct lto_input_block *ib)
1083 struct varpool_node *node;
1084 struct bitpack_d *bp;
1087 int ref = LCC_NOT_FOUND;
1089 decl_index = lto_input_uleb128 (ib);
1090 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
1091 node = varpool_node (var_decl);
1092 node->lto_file_data = file_data;
1094 bp = lto_input_bitpack (ib);
1095 node->externally_visible = bp_unpack_value (bp, 1);
1096 node->force_output = bp_unpack_value (bp, 1);
1097 node->finalized = bp_unpack_value (bp, 1);
1098 node->alias = bp_unpack_value (bp, 1);
1099 node->analyzed = node->finalized;
1100 node->used_from_other_partition = bp_unpack_value (bp, 1);
1101 node->in_other_partition = bp_unpack_value (bp, 1);
1102 aliases_p = bp_unpack_value (bp, 1);
1103 if (node->finalized)
1104 varpool_mark_needed_node (node);
1105 bitpack_delete (bp);
1106 ref = lto_input_sleb128 (ib);
1107 /* Store a reference for now, and fix up later to be a pointer. */
1108 node->same_comdat_group = (struct varpool_node *) (intptr_t) ref;
1111 count = lto_input_uleb128 (ib);
1112 for (; count > 0; count --)
1114 tree decl = lto_file_decl_data_get_var_decl (file_data,
1115 lto_input_uleb128 (ib));
1116 varpool_extra_name_alias (decl, var_decl);
1122 /* Read a node from input_block IB. TAG is the node's tag just read.
1123 Return the node read or overwriten. */
1126 input_ref (struct lto_input_block *ib,
1127 struct cgraph_node *refering_node,
1128 struct varpool_node *refering_varpool_node,
1129 VEC(cgraph_node_ptr, heap) *nodes,
1130 VEC(varpool_node_ptr, heap) *varpool_nodes)
1132 struct cgraph_node *node = NULL;
1133 struct varpool_node *varpool_node = NULL;
1134 struct bitpack_d *bp;
1135 enum ipa_ref_type type;
1136 enum ipa_ref_use use;
1138 bp = lto_input_bitpack (ib);
1139 type = (enum ipa_ref_type) bp_unpack_value (bp, 1);
1140 use = (enum ipa_ref_use) bp_unpack_value (bp, 2);
1141 bitpack_delete (bp);
1142 if (type == IPA_REF_CGRAPH)
1143 node = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
1145 varpool_node = VEC_index (varpool_node_ptr, varpool_nodes, lto_input_sleb128 (ib));
1146 ipa_record_reference (refering_node, refering_varpool_node,
1147 node, varpool_node, use, NULL);
1150 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1151 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1152 edge being read is indirect (in the sense that it has
1153 indirect_unknown_callee set). */
1156 input_edge (struct lto_input_block *ib, VEC(cgraph_node_ptr, heap) *nodes,
1159 struct cgraph_node *caller, *callee;
1160 struct cgraph_edge *edge;
1161 unsigned int stmt_id;
1165 cgraph_inline_failed_t inline_failed;
1166 struct bitpack_d *bp;
1167 enum ld_plugin_symbol_resolution caller_resolution;
1170 caller = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
1171 if (caller == NULL || caller->decl == NULL_TREE)
1172 internal_error ("bytecode stream: no caller found while reading edge");
1176 callee = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
1177 if (callee == NULL || callee->decl == NULL_TREE)
1178 internal_error ("bytecode stream: no callee found while reading edge");
1183 count = (gcov_type) lto_input_sleb128 (ib);
1185 bp = lto_input_bitpack (ib);
1186 stmt_id = (unsigned int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1187 inline_failed = (cgraph_inline_failed_t) bp_unpack_value (bp,
1189 freq = (int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1190 nest = (unsigned) bp_unpack_value (bp, 30);
1192 /* If the caller was preempted, don't create the edge.
1193 ??? Should we ever have edges from a preempted caller? */
1194 caller_resolution = lto_symtab_get_resolution (caller->decl);
1195 if (caller_resolution == LDPR_PREEMPTED_REG
1196 || caller_resolution == LDPR_PREEMPTED_IR)
1200 edge = cgraph_create_indirect_edge (caller, NULL, 0, count, freq, nest);
1202 edge = cgraph_create_edge (caller, callee, NULL, count, freq, nest);
1204 edge->indirect_inlining_edge = bp_unpack_value (bp, 1);
1205 edge->lto_stmt_uid = stmt_id;
1206 edge->inline_failed = inline_failed;
1207 edge->call_stmt_cannot_inline_p = bp_unpack_value (bp, 1);
1208 edge->can_throw_external = bp_unpack_value (bp, 1);
1211 if (bp_unpack_value (bp, 1))
1212 ecf_flags |= ECF_CONST;
1213 if (bp_unpack_value (bp, 1))
1214 ecf_flags |= ECF_PURE;
1215 if (bp_unpack_value (bp, 1))
1216 ecf_flags |= ECF_NORETURN;
1217 if (bp_unpack_value (bp, 1))
1218 ecf_flags |= ECF_MALLOC;
1219 if (bp_unpack_value (bp, 1))
1220 ecf_flags |= ECF_NOTHROW;
1221 if (bp_unpack_value (bp, 1))
1222 ecf_flags |= ECF_RETURNS_TWICE;
1223 edge->indirect_info->ecf_flags = ecf_flags;
1225 bitpack_delete (bp);
1229 /* Read a cgraph from IB using the info in FILE_DATA. */
1231 static VEC(cgraph_node_ptr, heap) *
1232 input_cgraph_1 (struct lto_file_decl_data *file_data,
1233 struct lto_input_block *ib)
1235 enum LTO_cgraph_tags tag;
1236 VEC(cgraph_node_ptr, heap) *nodes = NULL;
1237 struct cgraph_node *node;
1239 unsigned HOST_WIDE_INT len;
1241 tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib);
1244 if (tag == LTO_cgraph_edge)
1245 input_edge (ib, nodes, false);
1246 else if (tag == LTO_cgraph_indirect_edge)
1247 input_edge (ib, nodes, true);
1250 node = input_node (file_data, ib, tag,nodes);
1251 if (node == NULL || node->decl == NULL_TREE)
1252 internal_error ("bytecode stream: found empty cgraph node");
1253 VEC_safe_push (cgraph_node_ptr, heap, nodes, node);
1254 lto_cgraph_encoder_encode (file_data->cgraph_node_encoder, node);
1257 tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib);
1260 /* Input toplevel asms. */
1261 len = lto_input_uleb128 (ib);
1264 char *str = (char *)xmalloc (len + 1);
1265 for (i = 0; i < len; ++i)
1266 str[i] = lto_input_1_unsigned (ib);
1267 cgraph_add_asm_node (build_string (len, str));
1270 len = lto_input_uleb128 (ib);
1273 for (i = 0; VEC_iterate (cgraph_node_ptr, nodes, i, node); i++)
1275 int ref = (int) (intptr_t) node->global.inlined_to;
1277 /* Fixup inlined_to from reference to pointer. */
1278 if (ref != LCC_NOT_FOUND)
1279 node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref);
1281 node->global.inlined_to = NULL;
1283 ref = (int) (intptr_t) node->same_comdat_group;
1285 /* Fixup same_comdat_group from reference to pointer. */
1286 if (ref != LCC_NOT_FOUND)
1287 node->same_comdat_group = VEC_index (cgraph_node_ptr, nodes, ref);
1289 node->same_comdat_group = NULL;
1294 /* Read a varpool from IB using the info in FILE_DATA. */
1296 static VEC(varpool_node_ptr, heap) *
1297 input_varpool_1 (struct lto_file_decl_data *file_data,
1298 struct lto_input_block *ib)
1300 unsigned HOST_WIDE_INT len;
1301 VEC(varpool_node_ptr, heap) *varpool = NULL;
1303 struct varpool_node *node;
1305 len = lto_input_uleb128 (ib);
1308 VEC_safe_push (varpool_node_ptr, heap, varpool,
1309 input_varpool_node (file_data, ib));
1312 for (i = 0; VEC_iterate (varpool_node_ptr, varpool, i, node); i++)
1314 int ref = (int) (intptr_t) node->same_comdat_group;
1316 /* Fixup same_comdat_group from reference to pointer. */
1317 if (ref != LCC_NOT_FOUND)
1318 node->same_comdat_group = VEC_index (varpool_node_ptr, varpool, ref);
1320 node->same_comdat_group = NULL;
1325 /* Input ipa_refs. */
1328 input_refs (struct lto_input_block *ib,
1329 VEC(cgraph_node_ptr, heap) *nodes,
1330 VEC(varpool_node_ptr, heap) *varpool)
1336 struct cgraph_node *node;
1337 count = lto_input_uleb128 (ib);
1340 idx = lto_input_uleb128 (ib);
1341 node = VEC_index (cgraph_node_ptr, nodes, idx);
1344 input_ref (ib, node, NULL, nodes, varpool);
1350 struct varpool_node *node;
1351 count = lto_input_uleb128 (ib);
1354 node = VEC_index (varpool_node_ptr, varpool, lto_input_uleb128 (ib));
1357 input_ref (ib, NULL, node, nodes, varpool);
1364 static struct gcov_ctr_summary lto_gcov_summary;
1366 /* Input profile_info from IB. */
1368 input_profile_summary (struct lto_input_block *ib)
1370 unsigned int runs = lto_input_uleb128 (ib);
1375 profile_info = <o_gcov_summary;
1376 lto_gcov_summary.runs = runs;
1377 lto_gcov_summary.sum_all = lto_input_sleb128 (ib);
1378 lto_gcov_summary.run_max = lto_input_sleb128 (ib);
1379 lto_gcov_summary.sum_max = lto_input_sleb128 (ib);
1381 /* We can support this by scaling all counts to nearest common multiple
1382 of all different runs, but it is perhaps not worth the effort. */
1383 else if (profile_info->runs != runs
1384 || profile_info->sum_all != lto_input_sleb128 (ib)
1385 || profile_info->run_max != lto_input_sleb128 (ib)
1386 || profile_info->sum_max != lto_input_sleb128 (ib))
1387 sorry ("Combining units with different profiles is not supported.");
1388 /* We allow some units to have profile and other to not have one. This will
1389 just make unprofiled units to be size optimized that is sane. */
1394 /* Input and merge the cgraph from each of the .o files passed to
1400 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1401 struct lto_file_decl_data *file_data;
1403 struct cgraph_node *node;
1405 while ((file_data = file_data_vec[j++]))
1409 struct lto_input_block *ib;
1410 VEC(cgraph_node_ptr, heap) *nodes;
1411 VEC(varpool_node_ptr, heap) *varpool;
1413 ib = lto_create_simple_input_block (file_data, LTO_section_cgraph,
1415 input_profile_summary (ib);
1416 file_data->cgraph_node_encoder = lto_cgraph_encoder_new ();
1417 nodes = input_cgraph_1 (file_data, ib);
1418 lto_destroy_simple_input_block (file_data, LTO_section_cgraph,
1421 ib = lto_create_simple_input_block (file_data, LTO_section_varpool,
1423 varpool = input_varpool_1 (file_data, ib);
1424 lto_destroy_simple_input_block (file_data, LTO_section_varpool,
1427 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1429 input_refs (ib, nodes, varpool);
1430 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1433 input_cgraph_opt_summary (nodes);
1434 VEC_free (cgraph_node_ptr, heap, nodes);
1435 VEC_free (varpool_node_ptr, heap, varpool);
1438 /* Clear out the aux field that was used to store enough state to
1439 tell which nodes should be overwritten. */
1440 for (node = cgraph_nodes; node; node = node->next)
1442 /* Some nodes may have been created by cgraph_node. This
1443 happens when the callgraph contains nested functions. If the
1444 node for the parent function was never emitted to the gimple
1445 file, cgraph_node will create a node for it when setting the
1446 context of the nested function. */
1447 if (node->local.lto_file_data)
1452 /* True when we need optimization summary for NODE. */
1455 output_cgraph_opt_summary_p (struct cgraph_node *node)
1457 if (!node->clone_of)
1459 return (node->clone.tree_map
1460 || node->clone.args_to_skip
1461 || node->clone.combined_args_to_skip);
1464 /* Output optimization summary for NODE to OB. */
1467 output_node_opt_summary (struct output_block *ob,
1468 struct cgraph_node *node)
1472 struct ipa_replace_map *map;
1473 struct bitpack_d *bp;
1476 lto_output_uleb128_stream (ob->main_stream,
1477 bitmap_count_bits (node->clone.args_to_skip));
1478 EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi)
1479 lto_output_uleb128_stream (ob->main_stream, index);
1480 lto_output_uleb128_stream (ob->main_stream,
1481 bitmap_count_bits (node->clone.combined_args_to_skip));
1482 EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi)
1483 lto_output_uleb128_stream (ob->main_stream, index);
1484 lto_output_uleb128_stream (ob->main_stream,
1485 VEC_length (ipa_replace_map_p, node->clone.tree_map));
1486 for (i = 0; VEC_iterate (ipa_replace_map_p, node->clone.tree_map, i, map); i++)
1491 for (parm_num = 0, parm = DECL_ARGUMENTS (node->decl); parm;
1492 parm = TREE_CHAIN (parm), parm_num++)
1493 if (map->old_tree == parm)
1495 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1496 mechanism to store function local declarations into summaries. */
1498 lto_output_uleb128_stream (ob->main_stream, parm_num);
1499 lto_output_tree (ob, map->new_tree, true);
1500 bp = bitpack_create ();
1501 bp_pack_value (bp, map->replace_p, 1);
1502 bp_pack_value (bp, map->ref_p, 1);
1503 lto_output_bitpack (ob->main_stream, bp);
1504 bitpack_delete (bp);
1508 /* Output optimization summaries stored in callgraph.
1509 At the moment it is the clone info structure. */
1512 output_cgraph_opt_summary (void)
1514 struct cgraph_node *node;
1516 lto_cgraph_encoder_t encoder;
1517 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
1520 ob->cgraph_node = NULL;
1521 encoder = ob->decl_state->cgraph_node_encoder;
1522 n_nodes = lto_cgraph_encoder_size (encoder);
1523 for (i = 0; i < n_nodes; i++)
1524 if (output_cgraph_opt_summary_p (lto_cgraph_encoder_deref (encoder, i)))
1526 lto_output_uleb128_stream (ob->main_stream, count);
1527 for (i = 0; i < n_nodes; i++)
1529 node = lto_cgraph_encoder_deref (encoder, i);
1530 if (output_cgraph_opt_summary_p (node))
1532 lto_output_uleb128_stream (ob->main_stream, i);
1533 output_node_opt_summary (ob, node);
1536 produce_asm (ob, NULL);
1537 destroy_output_block (ob);
1540 /* Input optimiation summary of NODE. */
1543 input_node_opt_summary (struct cgraph_node *node,
1544 struct lto_input_block *ib_main,
1545 struct data_in *data_in)
1550 struct bitpack_d *bp;
1552 count = lto_input_uleb128 (ib_main);
1554 node->clone.args_to_skip = BITMAP_GGC_ALLOC ();
1555 for (i = 0; i < count; i++)
1557 bit = lto_input_uleb128 (ib_main);
1558 bitmap_set_bit (node->clone.args_to_skip, bit);
1560 count = lto_input_uleb128 (ib_main);
1562 node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC ();
1563 for (i = 0; i < count; i++)
1565 bit = lto_input_uleb128 (ib_main);
1566 bitmap_set_bit (node->clone.combined_args_to_skip, bit);
1568 count = lto_input_uleb128 (ib_main);
1569 for (i = 0; i < count; i++)
1573 struct ipa_replace_map *map = GGC_NEW (struct ipa_replace_map);
1575 VEC_safe_push (ipa_replace_map_p, gc, node->clone.tree_map, map);
1576 for (parm_num = 0, parm = DECL_ARGUMENTS (node->decl); parm_num;
1577 parm = TREE_CHAIN (parm))
1579 map->parm_num = lto_input_uleb128 (ib_main);
1580 map->old_tree = NULL;
1581 map->new_tree = lto_input_tree (ib_main, data_in);
1582 bp = lto_input_bitpack (ib_main);
1583 map->replace_p = bp_unpack_value (bp, 1);
1584 map->ref_p = bp_unpack_value (bp, 1);
1585 bitpack_delete (bp);
1589 /* Read section in file FILE_DATA of length LEN with data DATA. */
1592 input_cgraph_opt_section (struct lto_file_decl_data *file_data,
1593 const char *data, size_t len, VEC (cgraph_node_ptr,
1596 const struct lto_function_header *header =
1597 (const struct lto_function_header *) data;
1598 const int32_t cfg_offset = sizeof (struct lto_function_header);
1599 const int32_t main_offset = cfg_offset + header->cfg_size;
1600 const int32_t string_offset = main_offset + header->main_size;
1601 struct data_in *data_in;
1602 struct lto_input_block ib_main;
1606 LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
1610 lto_data_in_create (file_data, (const char *) data + string_offset,
1611 header->string_size, NULL);
1612 count = lto_input_uleb128 (&ib_main);
1614 for (i = 0; i < count; i++)
1616 int ref = lto_input_uleb128 (&ib_main);
1617 input_node_opt_summary (VEC_index (cgraph_node_ptr, nodes, ref),
1620 lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data,
1622 lto_data_in_delete (data_in);
1625 /* Input optimization summary of cgraph. */
1628 input_cgraph_opt_summary (VEC (cgraph_node_ptr, heap) * nodes)
1630 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1631 struct lto_file_decl_data *file_data;
1634 while ((file_data = file_data_vec[j++]))
1638 lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL,
1642 input_cgraph_opt_section (file_data, data, len, nodes);