1 /* Write and read the cgraph to the memory mapped representation of a
4 Copyright 2009, 2010, 2011 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"
33 #include "langhooks.h"
34 #include "basic-block.h"
35 #include "tree-flow.h"
39 #include "diagnostic-core.h"
43 #include "pointer-set.h"
44 #include "lto-streamer.h"
45 #include "data-streamer.h"
46 #include "tree-streamer.h"
49 static void output_cgraph_opt_summary (cgraph_node_set set
);
50 static void input_cgraph_opt_summary (VEC (symtab_node
, heap
) * nodes
);
52 /* Number of LDPR values known to GCC. */
53 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
55 /* All node orders are ofsetted by ORDER_BASE. */
56 static int order_base
;
58 /* Cgraph streaming is organized as set of record whose type
59 is indicated by a tag. */
62 /* Must leave 0 for the stopper. */
64 /* Cgraph node without body available. */
65 LTO_symtab_unavail_node
= 1,
66 /* Cgraph node with function body. */
67 LTO_symtab_analyzed_node
,
70 LTO_symtab_indirect_edge
,
75 /* Create a new symtab encoder. */
78 lto_symtab_encoder_new (void)
80 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
81 encoder
->map
= pointer_map_create ();
82 encoder
->nodes
= NULL
;
83 encoder
->body
= pointer_set_create ();
84 encoder
->initializer
= pointer_set_create ();
89 /* Delete ENCODER and its components. */
92 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
94 VEC_free (symtab_node
, heap
, encoder
->nodes
);
95 pointer_map_destroy (encoder
->map
);
96 pointer_set_destroy (encoder
->body
);
97 pointer_set_destroy (encoder
->initializer
);
102 /* Return the existing reference number of NODE in the symtab encoder in
103 output block OB. Assign a new reference if this is the first time
107 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
113 slot
= pointer_map_contains (encoder
->map
, node
);
116 ref
= VEC_length (symtab_node
, encoder
->nodes
);
117 slot
= pointer_map_insert (encoder
->map
, node
);
118 *slot
= (void *) (intptr_t) ref
;
119 VEC_safe_push (symtab_node
, heap
, encoder
->nodes
, node
);
122 ref
= (int) (intptr_t) *slot
;
127 #define LCC_NOT_FOUND (-1)
129 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
130 or LCC_NOT_FOUND if it is not there. */
133 lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder
,
136 void **slot
= pointer_map_contains (encoder
->map
, node
);
137 return (slot
? (int) (intptr_t) *slot
: LCC_NOT_FOUND
);
141 /* Return the cgraph node corresponding to REF using ENCODER. */
144 lto_symtab_encoder_deref (lto_symtab_encoder_t encoder
, int ref
)
146 if (ref
== LCC_NOT_FOUND
)
149 return VEC_index (symtab_node
, encoder
->nodes
, ref
);
153 /* Return TRUE if we should encode initializer of NODE (if any). */
156 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
157 struct cgraph_node
*node
)
159 return pointer_set_contains (encoder
->body
, node
);
162 /* Return TRUE if we should encode body of NODE (if any). */
165 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
166 struct cgraph_node
*node
)
168 pointer_set_insert (encoder
->body
, node
);
171 /* Return TRUE if we should encode initializer of NODE (if any). */
174 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
175 struct varpool_node
*node
)
177 return pointer_set_contains (encoder
->initializer
, node
);
180 /* Return TRUE if we should encode initializer of NODE (if any). */
183 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
184 struct varpool_node
*node
)
186 pointer_set_insert (encoder
->initializer
, node
);
189 /* Output the cgraph EDGE to OB using ENCODER. */
192 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
193 lto_symtab_encoder_t encoder
)
199 if (edge
->indirect_unknown_callee
)
200 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
201 LTO_symtab_indirect_edge
);
203 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
206 ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)edge
->caller
);
207 gcc_assert (ref
!= LCC_NOT_FOUND
);
208 streamer_write_hwi_stream (ob
->main_stream
, ref
);
210 if (!edge
->indirect_unknown_callee
)
212 ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)edge
->callee
);
213 gcc_assert (ref
!= LCC_NOT_FOUND
);
214 streamer_write_hwi_stream (ob
->main_stream
, ref
);
217 streamer_write_hwi_stream (ob
->main_stream
, edge
->count
);
219 bp
= bitpack_create (ob
->main_stream
);
220 uid
= (!gimple_has_body_p (edge
->caller
->symbol
.decl
)
221 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
));
222 bp_pack_enum (&bp
, cgraph_inline_failed_enum
,
223 CIF_N_REASONS
, edge
->inline_failed
);
224 bp_pack_var_len_unsigned (&bp
, uid
);
225 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
226 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
227 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
228 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
229 if (edge
->indirect_unknown_callee
)
231 int flags
= edge
->indirect_info
->ecf_flags
;
232 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
233 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
234 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
235 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
236 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
237 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
238 /* Flags that should not appear on indirect calls. */
239 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
245 streamer_write_bitpack (&bp
);
248 /* Return if LIST contain references from other partitions. */
251 referenced_from_other_partition_p (struct ipa_ref_list
*list
, cgraph_node_set set
,
252 varpool_node_set vset
)
256 for (i
= 0; ipa_ref_list_referring_iterate (list
, i
, ref
); i
++)
258 if (symtab_function_p (ref
->referring
))
260 if (ipa_ref_referring_node (ref
)->symbol
.in_other_partition
261 || !cgraph_node_in_set_p (ipa_ref_referring_node (ref
), set
))
266 if (ipa_ref_referring_varpool_node (ref
)->symbol
.in_other_partition
267 || !varpool_node_in_set_p (ipa_ref_referring_varpool_node (ref
),
275 /* Return true when node is reachable from other partition. */
278 reachable_from_other_partition_p (struct cgraph_node
*node
, cgraph_node_set set
)
280 struct cgraph_edge
*e
;
283 if (node
->global
.inlined_to
)
285 for (e
= node
->callers
; e
; e
= e
->next_caller
)
286 if (e
->caller
->symbol
.in_other_partition
287 || !cgraph_node_in_set_p (e
->caller
, set
))
292 /* Return if LIST contain references from other partitions. */
295 referenced_from_this_partition_p (struct ipa_ref_list
*list
, cgraph_node_set set
,
296 varpool_node_set vset
)
300 for (i
= 0; ipa_ref_list_referring_iterate (list
, i
, ref
); i
++)
302 if (symtab_function_p (ref
->referring
))
304 if (cgraph_node_in_set_p (ipa_ref_referring_node (ref
), set
))
309 if (varpool_node_in_set_p (ipa_ref_referring_varpool_node (ref
),
317 /* Return true when node is reachable from other partition. */
320 reachable_from_this_partition_p (struct cgraph_node
*node
, cgraph_node_set set
)
322 struct cgraph_edge
*e
;
323 for (e
= node
->callers
; e
; e
= e
->next_caller
)
324 if (cgraph_node_in_set_p (e
->caller
, set
))
329 /* Output the cgraph NODE to OB. ENCODER is used to find the
330 reference number of NODE->inlined_to. SET is the set of nodes we
331 are writing to the current file. If NODE is not in SET, then NODE
332 is a boundary of a cgraph_node_set and we pretend NODE just has a
333 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
334 that have had their callgraph node written so far. This is used to
335 determine if NODE is a clone of a previously written node. */
338 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
339 lto_symtab_encoder_t encoder
, cgraph_node_set set
,
340 varpool_node_set vset
)
346 bool in_other_partition
= false;
347 struct cgraph_node
*clone_of
;
349 boundary_p
= !cgraph_node_in_set_p (node
, set
);
351 if (node
->analyzed
&& !boundary_p
)
352 tag
= LTO_symtab_analyzed_node
;
354 tag
= LTO_symtab_unavail_node
;
356 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
358 streamer_write_hwi_stream (ob
->main_stream
, node
->symbol
.order
);
360 /* In WPA mode, we only output part of the call-graph. Also, we
361 fake cgraph node attributes. There are two cases that we care.
363 Boundary nodes: There are nodes that are not part of SET but are
364 called from within SET. We artificially make them look like
365 externally visible nodes with no function body.
367 Cherry-picked nodes: These are nodes we pulled from other
368 translation units into SET during IPA-inlining. We make them as
369 local static nodes to prevent clashes with other local statics. */
370 if (boundary_p
&& node
->analyzed
&& !DECL_EXTERNAL (node
->symbol
.decl
))
372 /* Inline clones can not be part of boundary.
373 gcc_assert (!node->global.inlined_to);
375 FIXME: At the moment they can be, when partition contains an inline
376 clone that is clone of inline clone from outside partition. We can
377 reshape the clone tree and make other tree to be the root, but it
378 needs a bit extra work and will be promplty done by cgraph_remove_node
379 after reading back. */
380 in_other_partition
= 1;
383 clone_of
= node
->clone_of
;
385 && (ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)clone_of
)) == LCC_NOT_FOUND
)
386 if (clone_of
->prev_sibling_clone
)
387 clone_of
= clone_of
->prev_sibling_clone
;
389 clone_of
= clone_of
->clone_of
;
391 if (LTO_symtab_analyzed_node
)
392 gcc_assert (clone_of
|| !node
->clone_of
);
394 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
396 streamer_write_hwi_stream (ob
->main_stream
, ref
);
399 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->symbol
.decl
);
400 streamer_write_hwi_stream (ob
->main_stream
, node
->count
);
401 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
403 if (tag
== LTO_symtab_analyzed_node
)
405 if (node
->global
.inlined_to
)
407 ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)node
->global
.inlined_to
);
408 gcc_assert (ref
!= LCC_NOT_FOUND
);
413 streamer_write_hwi_stream (ob
->main_stream
, ref
);
416 if (node
->symbol
.same_comdat_group
&& !boundary_p
)
418 ref
= lto_symtab_encoder_lookup (encoder
,
419 node
->symbol
.same_comdat_group
);
420 gcc_assert (ref
!= LCC_NOT_FOUND
);
424 streamer_write_hwi_stream (ob
->main_stream
, ref
);
426 bp
= bitpack_create (ob
->main_stream
);
427 bp_pack_value (&bp
, node
->local
.local
, 1);
428 bp_pack_value (&bp
, node
->symbol
.externally_visible
, 1);
429 bp_pack_value (&bp
, node
->local
.finalized
, 1);
430 bp_pack_value (&bp
, node
->local
.versionable
, 1);
431 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
432 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
433 bp_pack_value (&bp
, node
->symbol
.force_output
, 1);
434 bp_pack_value (&bp
, node
->symbol
.address_taken
, 1);
435 bp_pack_value (&bp
, node
->abstract_and_needed
, 1);
436 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
437 && !DECL_EXTERNAL (node
->symbol
.decl
)
438 && !DECL_COMDAT (node
->symbol
.decl
)
439 && (reachable_from_other_partition_p (node
, set
)
440 || referenced_from_other_partition_p (&node
->symbol
.ref_list
,
442 bp_pack_value (&bp
, node
->lowered
, 1);
443 bp_pack_value (&bp
, in_other_partition
, 1);
444 /* Real aliases in a boundary become non-aliases. However we still stream
445 alias info on weakrefs.
446 TODO: We lose a bit of information here - when we know that variable is
447 defined in other unit, we may use the info on aliases to resolve
448 symbol1 != symbol2 type tests that we can do only for locally defined objects
450 bp_pack_value (&bp
, node
->alias
&& (!boundary_p
|| DECL_EXTERNAL (node
->symbol
.decl
)), 1);
451 bp_pack_value (&bp
, node
->frequency
, 2);
452 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
453 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
454 bp_pack_value (&bp
, node
->tm_clone
, 1);
455 bp_pack_value (&bp
, node
->thunk
.thunk_p
&& !boundary_p
, 1);
456 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
457 LDPR_NUM_KNOWN
, node
->symbol
.resolution
);
458 streamer_write_bitpack (&bp
);
460 if (node
->thunk
.thunk_p
&& !boundary_p
)
462 streamer_write_uhwi_stream
464 1 + (node
->thunk
.this_adjusting
!= 0) * 2
465 + (node
->thunk
.virtual_offset_p
!= 0) * 4);
466 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
467 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
469 if ((node
->alias
|| node
->thunk
.thunk_p
)
470 && (!boundary_p
|| (node
->alias
&& DECL_EXTERNAL (node
->symbol
.decl
))))
472 streamer_write_hwi_in_range (ob
->main_stream
, 0, 1,
473 node
->thunk
.alias
!= NULL
);
474 if (node
->thunk
.alias
!= NULL
)
475 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
480 /* Output the varpool NODE to OB.
481 If NODE is not in SET, then NODE is a boundary. */
484 lto_output_varpool_node (struct lto_simple_output_block
*ob
, struct varpool_node
*node
,
485 lto_symtab_encoder_t encoder
,
486 cgraph_node_set set
, varpool_node_set vset
)
488 bool boundary_p
= !varpool_node_in_set_p (node
, vset
) && node
->analyzed
;
492 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
493 LTO_symtab_variable
);
494 streamer_write_hwi_stream (ob
->main_stream
, node
->symbol
.order
);
495 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->symbol
.decl
);
496 bp
= bitpack_create (ob
->main_stream
);
497 bp_pack_value (&bp
, node
->symbol
.externally_visible
, 1);
498 bp_pack_value (&bp
, node
->symbol
.force_output
, 1);
499 bp_pack_value (&bp
, node
->finalized
, 1);
500 bp_pack_value (&bp
, node
->alias
, 1);
501 bp_pack_value (&bp
, node
->alias_of
!= NULL
, 1);
502 gcc_assert (node
->finalized
|| !node
->analyzed
);
503 /* Constant pool initializers can be de-unified into individual ltrans units.
504 FIXME: Alternatively at -Os we may want to avoid generating for them the local
505 labels and share them across LTRANS partitions. */
506 if (DECL_IN_CONSTANT_POOL (node
->symbol
.decl
)
507 && !DECL_EXTERNAL (node
->symbol
.decl
)
508 && !DECL_COMDAT (node
->symbol
.decl
))
510 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
511 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
515 bp_pack_value (&bp
, node
->analyzed
516 && referenced_from_other_partition_p (&node
->symbol
.ref_list
,
518 bp_pack_value (&bp
, boundary_p
&& !DECL_EXTERNAL (node
->symbol
.decl
), 1);
519 /* in_other_partition. */
521 streamer_write_bitpack (&bp
);
523 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->alias_of
);
524 if (node
->symbol
.same_comdat_group
&& !boundary_p
)
526 ref
= lto_symtab_encoder_lookup (encoder
,
527 node
->symbol
.same_comdat_group
);
528 gcc_assert (ref
!= LCC_NOT_FOUND
);
532 streamer_write_hwi_stream (ob
->main_stream
, ref
);
533 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
534 LDPR_NUM_KNOWN
, node
->symbol
.resolution
);
537 /* Output the varpool NODE to OB.
538 If NODE is not in SET, then NODE is a boundary. */
541 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
542 lto_symtab_encoder_t encoder
)
547 bp
= bitpack_create (ob
->main_stream
);
548 bp_pack_value (&bp
, ref
->use
, 2);
549 streamer_write_bitpack (&bp
);
550 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
551 gcc_assert (nref
!= LCC_NOT_FOUND
);
552 streamer_write_hwi_stream (ob
->main_stream
, nref
);
555 /* Stream out profile_summary to OB. */
558 output_profile_summary (struct lto_simple_output_block
*ob
)
562 /* We do not output num, sum_all and run_max, they are not used by
563 GCC profile feedback and they are difficult to merge from multiple
565 gcc_assert (profile_info
->runs
);
566 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
567 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->sum_max
);
570 streamer_write_uhwi_stream (ob
->main_stream
, 0);
573 /* Add NODE into encoder as well as nodes it is cloned from.
574 Do it in a way so clones appear first. */
577 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
581 add_node_to (encoder
, node
->clone_of
, include_body
);
582 else if (include_body
)
583 lto_set_symtab_encoder_encode_body (encoder
, node
);
584 lto_symtab_encoder_encode (encoder
, (symtab_node
)node
);
587 /* Add all references in LIST to encoders. */
590 add_references (lto_symtab_encoder_t encoder
,
591 struct ipa_ref_list
*list
)
595 for (i
= 0; ipa_ref_list_reference_iterate (list
, i
, ref
); i
++)
596 if (symtab_function_p (ref
->referred
))
597 add_node_to (encoder
, ipa_ref_node (ref
), false);
600 struct varpool_node
*vnode
= ipa_ref_varpool_node (ref
);
601 lto_symtab_encoder_encode (encoder
, (symtab_node
)vnode
);
605 /* Output all callees or indirect outgoing edges. EDGE must be the first such
609 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
610 struct lto_simple_output_block
*ob
,
611 lto_symtab_encoder_t encoder
)
616 /* Output edges in backward direction, so the reconstructed callgraph match
617 and it is easy to associate call sites in the IPA pass summaries. */
618 while (edge
->next_callee
)
619 edge
= edge
->next_callee
;
620 for (; edge
; edge
= edge
->prev_callee
)
621 lto_output_edge (ob
, edge
, encoder
);
624 /* Output the part of the cgraph in SET. */
627 output_refs (cgraph_node_set set
, varpool_node_set vset
,
628 lto_symtab_encoder_t encoder
)
630 cgraph_node_set_iterator csi
;
631 varpool_node_set_iterator vsi
;
632 struct lto_simple_output_block
*ob
;
637 ob
= lto_create_simple_output_block (LTO_section_refs
);
639 for (csi
= csi_start (set
); !csi_end_p (csi
); csi_next (&csi
))
641 struct cgraph_node
*node
= csi_node (csi
);
643 count
= ipa_ref_list_nreferences (&node
->symbol
.ref_list
);
646 streamer_write_uhwi_stream (ob
->main_stream
, count
);
647 streamer_write_uhwi_stream (ob
->main_stream
,
648 lto_symtab_encoder_lookup (encoder
,
650 for (i
= 0; ipa_ref_list_reference_iterate (&node
->symbol
.ref_list
,
652 lto_output_ref (ob
, ref
, encoder
);
656 streamer_write_uhwi_stream (ob
->main_stream
, 0);
658 for (vsi
= vsi_start (vset
); !vsi_end_p (vsi
); vsi_next (&vsi
))
660 struct varpool_node
*node
= vsi_node (vsi
);
662 count
= ipa_ref_list_nreferences (&node
->symbol
.ref_list
);
665 streamer_write_uhwi_stream (ob
->main_stream
, count
);
666 streamer_write_uhwi_stream (ob
->main_stream
,
667 lto_symtab_encoder_lookup (encoder
,
669 for (i
= 0; ipa_ref_list_reference_iterate (&node
->symbol
.ref_list
,
671 lto_output_ref (ob
, ref
, encoder
);
675 streamer_write_uhwi_stream (ob
->main_stream
, 0);
677 lto_destroy_simple_output_block (ob
);
680 /* Find out all cgraph and varpool nodes we want to encode in current unit
681 and insert them to encoders. */
683 compute_ltrans_boundary (struct lto_out_decl_state
*state
,
684 cgraph_node_set set
, varpool_node_set vset
)
686 struct cgraph_node
*node
;
687 cgraph_node_set_iterator csi
;
688 varpool_node_set_iterator vsi
;
689 struct cgraph_edge
*edge
;
691 lto_symtab_encoder_t encoder
;
693 encoder
= state
->symtab_node_encoder
= lto_symtab_encoder_new ();
695 /* Go over all the nodes in SET and assign references. */
696 for (csi
= csi_start (set
); !csi_end_p (csi
); csi_next (&csi
))
698 node
= csi_node (csi
);
699 add_node_to (encoder
, node
, true);
700 add_references (encoder
, &node
->symbol
.ref_list
);
702 for (vsi
= vsi_start (vset
); !vsi_end_p (vsi
); vsi_next (&vsi
))
704 struct varpool_node
*vnode
= vsi_node (vsi
);
705 gcc_assert (!vnode
->alias
|| vnode
->alias_of
);
706 lto_symtab_encoder_encode (encoder
, (symtab_node
)vnode
);
707 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
708 add_references (encoder
, &vnode
->symbol
.ref_list
);
710 /* Pickle in also the initializer of all referenced readonly variables
711 to help folding. Constant pool variables are not shared, so we must
713 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
715 symtab_node node
= lto_symtab_encoder_deref (encoder
, i
);
716 if (symtab_variable_p (node
))
718 struct varpool_node
*vnode
= varpool (node
);
719 if (DECL_INITIAL (vnode
->symbol
.decl
)
720 && !lto_symtab_encoder_encode_initializer_p (encoder
,
722 && const_value_known_p (vnode
->symbol
.decl
))
724 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
725 add_references (encoder
, &vnode
->symbol
.ref_list
);
727 else if (vnode
->alias
|| vnode
->alias_of
)
728 add_references (encoder
, &vnode
->symbol
.ref_list
);
732 /* Go over all the nodes again to include callees that are not in
734 for (csi
= csi_start (set
); !csi_end_p (csi
); csi_next (&csi
))
736 node
= csi_node (csi
);
737 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
739 struct cgraph_node
*callee
= edge
->callee
;
740 if (!cgraph_node_in_set_p (callee
, set
))
742 /* We should have moved all the inlines. */
743 gcc_assert (!callee
->global
.inlined_to
);
744 add_node_to (encoder
, callee
, false);
750 /* Output the part of the cgraph in SET. */
753 output_cgraph (cgraph_node_set set
, varpool_node_set vset
)
755 struct cgraph_node
*node
;
756 struct lto_simple_output_block
*ob
;
757 cgraph_node_set_iterator csi
;
759 lto_symtab_encoder_t encoder
;
760 static bool asm_nodes_output
= false;
763 output_cgraph_opt_summary (set
);
765 ob
= lto_create_simple_output_block (LTO_section_cgraph
);
767 output_profile_summary (ob
);
769 /* An encoder for cgraph nodes should have been created by
770 ipa_write_summaries_1. */
771 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
772 encoder
= ob
->decl_state
->symtab_node_encoder
;
774 /* Write out the nodes. We must first output a node and then its clones,
775 otherwise at a time reading back the node there would be nothing to clone
777 n_nodes
= lto_symtab_encoder_size (encoder
);
778 for (i
= 0; i
< n_nodes
; i
++)
780 symtab_node node
= lto_symtab_encoder_deref (encoder
, i
);
781 if (symtab_function_p (node
))
782 lto_output_node (ob
, cgraph (node
), encoder
, set
, vset
);
784 lto_output_varpool_node (ob
, varpool (node
), encoder
,
789 /* Go over the nodes in SET again to write edges. */
790 for (csi
= csi_start (set
); !csi_end_p (csi
); csi_next (&csi
))
792 node
= csi_node (csi
);
793 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
794 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
797 streamer_write_uhwi_stream (ob
->main_stream
, 0);
799 lto_destroy_simple_output_block (ob
);
801 /* Emit toplevel asms.
802 When doing WPA we must output every asm just once. Since we do not partition asm
803 nodes at all, output them to first output. This is kind of hack, but should work
805 if (!asm_nodes_output
)
807 asm_nodes_output
= true;
808 lto_output_toplevel_asms ();
811 output_refs (set
, vset
, encoder
);
814 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
815 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
816 NODE or to replace the values in it, for instance because the first
817 time we saw it, the function body was not available but now it
818 is. BP is a bitpack with all the bitflags for NODE read from the
822 input_overwrite_node (struct lto_file_decl_data
*file_data
,
823 struct cgraph_node
*node
,
824 enum LTO_symtab_tags tag
,
825 struct bitpack_d
*bp
)
827 node
->symbol
.aux
= (void *) tag
;
828 node
->symbol
.lto_file_data
= file_data
;
830 node
->local
.local
= bp_unpack_value (bp
, 1);
831 node
->symbol
.externally_visible
= bp_unpack_value (bp
, 1);
832 node
->local
.finalized
= bp_unpack_value (bp
, 1);
833 node
->local
.versionable
= bp_unpack_value (bp
, 1);
834 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
835 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
836 node
->symbol
.force_output
= bp_unpack_value (bp
, 1);
837 node
->symbol
.address_taken
= bp_unpack_value (bp
, 1);
838 node
->abstract_and_needed
= bp_unpack_value (bp
, 1);
839 node
->symbol
.used_from_other_partition
= bp_unpack_value (bp
, 1);
840 node
->lowered
= bp_unpack_value (bp
, 1);
841 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
842 node
->symbol
.in_other_partition
= bp_unpack_value (bp
, 1);
843 if (node
->symbol
.in_other_partition
844 /* Avoid updating decl when we are seeing just inline clone.
845 When inlining function that has functions already inlined into it,
846 we produce clones of inline clones.
848 WPA partitioning might put each clone into different unit and
849 we might end up streaming inline clone from other partition
850 to support clone we are interested in. */
852 || node
->clone_of
->symbol
.decl
!= node
->symbol
.decl
))
854 DECL_EXTERNAL (node
->symbol
.decl
) = 1;
855 TREE_STATIC (node
->symbol
.decl
) = 0;
857 node
->alias
= bp_unpack_value (bp
, 1);
858 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
859 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
860 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
861 node
->tm_clone
= bp_unpack_value (bp
, 1);
862 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
863 node
->symbol
.resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
867 /* Read a node from input_block IB. TAG is the node's tag just read.
868 Return the node read or overwriten. */
870 static struct cgraph_node
*
871 input_node (struct lto_file_decl_data
*file_data
,
872 struct lto_input_block
*ib
,
873 enum LTO_symtab_tags tag
,
874 VEC(symtab_node
, heap
) *nodes
)
877 struct cgraph_node
*node
;
880 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
884 order
= streamer_read_hwi (ib
) + order_base
;
885 clone_ref
= streamer_read_hwi (ib
);
887 decl_index
= streamer_read_uhwi (ib
);
888 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
890 if (clone_ref
!= LCC_NOT_FOUND
)
892 node
= cgraph_clone_node (cgraph (VEC_index (symtab_node
, nodes
, clone_ref
)), fn_decl
,
893 0, CGRAPH_FREQ_BASE
, false, NULL
, false);
896 node
= cgraph_get_create_node (fn_decl
);
898 node
->symbol
.order
= order
;
899 if (order
>= symtab_order
)
900 symtab_order
= order
+ 1;
902 node
->count
= streamer_read_hwi (ib
);
903 node
->count_materialization_scale
= streamer_read_hwi (ib
);
905 if (tag
== LTO_symtab_analyzed_node
)
906 ref
= streamer_read_hwi (ib
);
908 ref2
= streamer_read_hwi (ib
);
910 /* Make sure that we have not read this node before. Nodes that
911 have already been read will have their tag stored in the 'aux'
912 field. Since built-in functions can be referenced in multiple
913 functions, they are expected to be read more than once. */
914 if (node
->symbol
.aux
&& !DECL_BUILT_IN (node
->symbol
.decl
))
915 internal_error ("bytecode stream: found multiple instances of cgraph "
916 "node %d", node
->uid
);
918 bp
= streamer_read_bitpack (ib
);
919 input_overwrite_node (file_data
, node
, tag
, &bp
);
921 /* Store a reference for now, and fix up later to be a pointer. */
922 node
->global
.inlined_to
= (cgraph_node_ptr
) (intptr_t) ref
;
924 /* Store a reference for now, and fix up later to be a pointer. */
925 node
->symbol
.same_comdat_group
= (symtab_node
) (intptr_t) ref2
;
927 if (node
->thunk
.thunk_p
)
929 int type
= streamer_read_uhwi (ib
);
930 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
931 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
933 node
->thunk
.fixed_offset
= fixed_offset
;
934 node
->thunk
.this_adjusting
= (type
& 2);
935 node
->thunk
.virtual_value
= virtual_value
;
936 node
->thunk
.virtual_offset_p
= (type
& 4);
938 if (node
->thunk
.thunk_p
|| node
->alias
)
940 if (streamer_read_hwi_in_range (ib
, "alias nonzero flag", 0, 1))
942 decl_index
= streamer_read_uhwi (ib
);
943 node
->thunk
.alias
= lto_file_decl_data_get_fn_decl (file_data
,
950 /* Read a node from input_block IB. TAG is the node's tag just read.
951 Return the node read or overwriten. */
953 static struct varpool_node
*
954 input_varpool_node (struct lto_file_decl_data
*file_data
,
955 struct lto_input_block
*ib
)
959 struct varpool_node
*node
;
961 int ref
= LCC_NOT_FOUND
;
962 bool non_null_aliasof
;
965 order
= streamer_read_hwi (ib
) + order_base
;
966 decl_index
= streamer_read_uhwi (ib
);
967 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
968 node
= varpool_node (var_decl
);
969 node
->symbol
.order
= order
;
970 if (order
>= symtab_order
)
971 symtab_order
= order
+ 1;
972 node
->symbol
.lto_file_data
= file_data
;
974 bp
= streamer_read_bitpack (ib
);
975 node
->symbol
.externally_visible
= bp_unpack_value (&bp
, 1);
976 node
->symbol
.force_output
= bp_unpack_value (&bp
, 1);
977 node
->finalized
= bp_unpack_value (&bp
, 1);
978 node
->alias
= bp_unpack_value (&bp
, 1);
979 non_null_aliasof
= bp_unpack_value (&bp
, 1);
980 node
->symbol
.used_from_other_partition
= bp_unpack_value (&bp
, 1);
981 node
->symbol
.in_other_partition
= bp_unpack_value (&bp
, 1);
982 node
->analyzed
= (node
->finalized
&& (!node
->alias
|| !node
->symbol
.in_other_partition
));
983 if (node
->symbol
.in_other_partition
)
985 DECL_EXTERNAL (node
->symbol
.decl
) = 1;
986 TREE_STATIC (node
->symbol
.decl
) = 0;
988 if (non_null_aliasof
)
990 decl_index
= streamer_read_uhwi (ib
);
991 node
->alias_of
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
993 ref
= streamer_read_hwi (ib
);
994 /* Store a reference for now, and fix up later to be a pointer. */
995 node
->symbol
.same_comdat_group
= (symtab_node
) (intptr_t) ref
;
996 node
->symbol
.resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1002 /* Read a node from input_block IB. TAG is the node's tag just read.
1003 Return the node read or overwriten. */
1006 input_ref (struct lto_input_block
*ib
,
1007 symtab_node referring_node
,
1008 VEC(symtab_node
, heap
) *nodes
)
1010 symtab_node node
= NULL
;
1011 struct bitpack_d bp
;
1012 enum ipa_ref_use use
;
1014 bp
= streamer_read_bitpack (ib
);
1015 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 2);
1016 node
= VEC_index (symtab_node
, nodes
, streamer_read_hwi (ib
));
1017 ipa_record_reference (referring_node
, node
, use
, NULL
);
1020 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1021 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1022 edge being read is indirect (in the sense that it has
1023 indirect_unknown_callee set). */
1026 input_edge (struct lto_input_block
*ib
, VEC(symtab_node
, heap
) *nodes
,
1029 struct cgraph_node
*caller
, *callee
;
1030 struct cgraph_edge
*edge
;
1031 unsigned int stmt_id
;
1034 cgraph_inline_failed_t inline_failed
;
1035 struct bitpack_d bp
;
1038 caller
= cgraph (VEC_index (symtab_node
, nodes
, streamer_read_hwi (ib
)));
1039 if (caller
== NULL
|| caller
->symbol
.decl
== NULL_TREE
)
1040 internal_error ("bytecode stream: no caller found while reading edge");
1044 callee
= cgraph (VEC_index (symtab_node
, nodes
, streamer_read_hwi (ib
)));
1045 if (callee
== NULL
|| callee
->symbol
.decl
== NULL_TREE
)
1046 internal_error ("bytecode stream: no callee found while reading edge");
1051 count
= (gcov_type
) streamer_read_hwi (ib
);
1053 bp
= streamer_read_bitpack (ib
);
1054 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_enum
, CIF_N_REASONS
);
1055 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1056 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1059 edge
= cgraph_create_indirect_edge (caller
, NULL
, 0, count
, freq
);
1061 edge
= cgraph_create_edge (caller
, callee
, NULL
, count
, freq
);
1063 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1064 edge
->lto_stmt_uid
= stmt_id
;
1065 edge
->inline_failed
= inline_failed
;
1066 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1067 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1070 if (bp_unpack_value (&bp
, 1))
1071 ecf_flags
|= ECF_CONST
;
1072 if (bp_unpack_value (&bp
, 1))
1073 ecf_flags
|= ECF_PURE
;
1074 if (bp_unpack_value (&bp
, 1))
1075 ecf_flags
|= ECF_NORETURN
;
1076 if (bp_unpack_value (&bp
, 1))
1077 ecf_flags
|= ECF_MALLOC
;
1078 if (bp_unpack_value (&bp
, 1))
1079 ecf_flags
|= ECF_NOTHROW
;
1080 if (bp_unpack_value (&bp
, 1))
1081 ecf_flags
|= ECF_RETURNS_TWICE
;
1082 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1087 /* Read a cgraph from IB using the info in FILE_DATA. */
1089 static VEC(symtab_node
, heap
) *
1090 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1091 struct lto_input_block
*ib
)
1093 enum LTO_symtab_tags tag
;
1094 VEC(symtab_node
, heap
) *nodes
= NULL
;
1098 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1099 order_base
= symtab_order
;
1102 if (tag
== LTO_symtab_edge
)
1103 input_edge (ib
, nodes
, false);
1104 else if (tag
== LTO_symtab_indirect_edge
)
1105 input_edge (ib
, nodes
, true);
1106 else if (tag
== LTO_symtab_variable
)
1108 node
= (symtab_node
)input_varpool_node (file_data
, ib
);
1109 VEC_safe_push (symtab_node
, heap
, nodes
, node
);
1110 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1114 node
= (symtab_node
)input_node (file_data
, ib
, tag
, nodes
);
1115 if (node
== NULL
|| node
->symbol
.decl
== NULL_TREE
)
1116 internal_error ("bytecode stream: found empty cgraph node");
1117 VEC_safe_push (symtab_node
, heap
, nodes
, node
);
1118 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1121 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1124 lto_input_toplevel_asms (file_data
, order_base
);
1126 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1127 #ifdef ENABLE_CHECKING
1128 FOR_EACH_VEC_ELT (symtab_node
, nodes
, i
, node
)
1129 gcc_assert (node
->symbol
.aux
|| !symtab_function_p (node
));
1131 FOR_EACH_VEC_ELT (symtab_node
, nodes
, i
, node
)
1134 if (symtab_function_p (node
))
1136 ref
= (int) (intptr_t) cgraph (node
)->global
.inlined_to
;
1138 /* We share declaration of builtins, so we may read same node twice. */
1139 if (!node
->symbol
.aux
)
1141 node
->symbol
.aux
= NULL
;
1143 /* Fixup inlined_to from reference to pointer. */
1144 if (ref
!= LCC_NOT_FOUND
)
1145 cgraph (node
)->global
.inlined_to
= cgraph (VEC_index (symtab_node
, nodes
, ref
));
1147 cgraph (node
)->global
.inlined_to
= NULL
;
1150 ref
= (int) (intptr_t) node
->symbol
.same_comdat_group
;
1152 /* Fixup same_comdat_group from reference to pointer. */
1153 if (ref
!= LCC_NOT_FOUND
)
1154 node
->symbol
.same_comdat_group
= VEC_index (symtab_node
, nodes
, ref
);
1156 node
->symbol
.same_comdat_group
= NULL
;
1158 FOR_EACH_VEC_ELT (symtab_node
, nodes
, i
, node
)
1159 node
->symbol
.aux
= symtab_function_p (node
) ? (void *)1 : NULL
;
1163 /* Input ipa_refs. */
1166 input_refs (struct lto_input_block
*ib
,
1167 VEC(symtab_node
, heap
) *nodes
)
1173 struct cgraph_node
*node
;
1174 count
= streamer_read_uhwi (ib
);
1177 idx
= streamer_read_uhwi (ib
);
1178 node
= cgraph (VEC_index (symtab_node
, nodes
, idx
));
1181 input_ref (ib
, (symtab_node
) node
, nodes
);
1187 struct varpool_node
*node
;
1188 count
= streamer_read_uhwi (ib
);
1191 node
= varpool (VEC_index (symtab_node
, nodes
,
1192 streamer_read_uhwi (ib
)));
1195 input_ref (ib
, (symtab_node
) node
, nodes
);
1202 static struct gcov_ctr_summary lto_gcov_summary
;
1204 /* Input profile_info from IB. */
1206 input_profile_summary (struct lto_input_block
*ib
,
1207 struct lto_file_decl_data
*file_data
)
1209 unsigned int runs
= streamer_read_uhwi (ib
);
1212 file_data
->profile_info
.runs
= runs
;
1213 file_data
->profile_info
.sum_max
= streamer_read_uhwi (ib
);
1218 /* Rescale profile summaries to the same number of runs in the whole unit. */
1221 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1223 struct lto_file_decl_data
*file_data
;
1225 gcov_unsigned_t max_runs
= 0;
1226 struct cgraph_node
*node
;
1227 struct cgraph_edge
*edge
;
1229 /* Find unit with maximal number of runs. If we ever get serious about
1230 roundoff errors, we might also consider computing smallest common
1232 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1233 if (max_runs
< file_data
->profile_info
.runs
)
1234 max_runs
= file_data
->profile_info
.runs
;
1239 /* Simple overflow check. We probably don't need to support that many train
1240 runs. Such a large value probably imply data corruption anyway. */
1241 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1243 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1244 INT_MAX
/ REG_BR_PROB_BASE
);
1248 profile_info
= <o_gcov_summary
;
1249 lto_gcov_summary
.runs
= max_runs
;
1250 lto_gcov_summary
.sum_max
= 0;
1252 /* Rescale all units to the maximal number of runs.
1253 sum_max can not be easily merged, as we have no idea what files come from
1254 the same run. We do not use the info anyway, so leave it 0. */
1255 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1256 if (file_data
->profile_info
.runs
)
1258 int scale
= ((REG_BR_PROB_BASE
* max_runs
1259 + file_data
->profile_info
.runs
/ 2)
1260 / file_data
->profile_info
.runs
);
1261 lto_gcov_summary
.sum_max
= MAX (lto_gcov_summary
.sum_max
,
1262 (file_data
->profile_info
.sum_max
1264 + REG_BR_PROB_BASE
/ 2)
1265 / REG_BR_PROB_BASE
);
1268 /* Watch roundoff errors. */
1269 if (lto_gcov_summary
.sum_max
< max_runs
)
1270 lto_gcov_summary
.sum_max
= max_runs
;
1272 /* If merging already happent at WPA time, we are done. */
1276 /* Now compute count_materialization_scale of each node.
1277 During LTRANS we already have values of count_materialization_scale
1278 computed, so just update them. */
1279 FOR_EACH_FUNCTION (node
)
1280 if (node
->symbol
.lto_file_data
1281 && node
->symbol
.lto_file_data
->profile_info
.runs
)
1286 ((node
->count_materialization_scale
* max_runs
1287 + node
->symbol
.lto_file_data
->profile_info
.runs
/ 2)
1288 / node
->symbol
.lto_file_data
->profile_info
.runs
);
1289 node
->count_materialization_scale
= scale
;
1291 fatal_error ("Profile information in %s corrupted",
1292 file_data
->file_name
);
1294 if (scale
== REG_BR_PROB_BASE
)
1296 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1297 edge
->count
= ((edge
->count
* scale
+ REG_BR_PROB_BASE
/ 2)
1298 / REG_BR_PROB_BASE
);
1299 node
->count
= ((node
->count
* scale
+ REG_BR_PROB_BASE
/ 2)
1300 / REG_BR_PROB_BASE
);
1304 /* Input and merge the cgraph from each of the .o files passed to
1310 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1311 struct lto_file_decl_data
*file_data
;
1313 struct cgraph_node
*node
;
1315 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
1317 while ((file_data
= file_data_vec
[j
++]))
1321 struct lto_input_block
*ib
;
1322 VEC(symtab_node
, heap
) *nodes
;
1324 ib
= lto_create_simple_input_block (file_data
, LTO_section_cgraph
,
1327 fatal_error ("cannot find LTO cgraph in %s", file_data
->file_name
);
1328 input_profile_summary (ib
, file_data
);
1329 file_data
->symtab_node_encoder
= lto_symtab_encoder_new ();
1330 nodes
= input_cgraph_1 (file_data
, ib
);
1331 lto_destroy_simple_input_block (file_data
, LTO_section_cgraph
,
1334 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1337 fatal_error("cannot find LTO section refs in %s", file_data
->file_name
);
1338 input_refs (ib
, nodes
);
1339 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1342 input_cgraph_opt_summary (nodes
);
1343 VEC_free (symtab_node
, heap
, nodes
);
1346 merge_profile_summaries (file_data_vec
);
1348 /* Clear out the aux field that was used to store enough state to
1349 tell which nodes should be overwritten. */
1350 FOR_EACH_FUNCTION (node
)
1352 /* Some nodes may have been created by cgraph_node. This
1353 happens when the callgraph contains nested functions. If the
1354 node for the parent function was never emitted to the gimple
1355 file, cgraph_node will create a node for it when setting the
1356 context of the nested function. */
1357 if (node
->symbol
.lto_file_data
)
1358 node
->symbol
.aux
= NULL
;
1362 /* True when we need optimization summary for NODE. */
1365 output_cgraph_opt_summary_p (struct cgraph_node
*node
,
1366 cgraph_node_set set ATTRIBUTE_UNUSED
)
1368 return (node
->clone_of
1369 && (node
->clone
.tree_map
1370 || node
->clone
.args_to_skip
1371 || node
->clone
.combined_args_to_skip
));
1374 /* Output optimization summary for EDGE to OB. */
1376 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1377 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1381 /* Output optimization summary for NODE to OB. */
1384 output_node_opt_summary (struct output_block
*ob
,
1385 struct cgraph_node
*node
,
1386 cgraph_node_set set
)
1390 struct ipa_replace_map
*map
;
1391 struct bitpack_d bp
;
1393 struct cgraph_edge
*e
;
1395 if (node
->clone
.args_to_skip
)
1397 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1398 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1399 streamer_write_uhwi (ob
, index
);
1402 streamer_write_uhwi (ob
, 0);
1403 if (node
->clone
.combined_args_to_skip
)
1405 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1406 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
1407 streamer_write_uhwi (ob
, index
);
1410 streamer_write_uhwi (ob
, 0);
1411 streamer_write_uhwi (ob
, VEC_length (ipa_replace_map_p
,
1412 node
->clone
.tree_map
));
1413 FOR_EACH_VEC_ELT (ipa_replace_map_p
, node
->clone
.tree_map
, i
, map
)
1418 for (parm_num
= 0, parm
= DECL_ARGUMENTS (node
->symbol
.decl
); parm
;
1419 parm
= DECL_CHAIN (parm
), parm_num
++)
1420 if (map
->old_tree
== parm
)
1422 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1423 mechanism to store function local declarations into summaries. */
1425 streamer_write_uhwi (ob
, parm_num
);
1426 stream_write_tree (ob
, map
->new_tree
, true);
1427 bp
= bitpack_create (ob
->main_stream
);
1428 bp_pack_value (&bp
, map
->replace_p
, 1);
1429 bp_pack_value (&bp
, map
->ref_p
, 1);
1430 streamer_write_bitpack (&bp
);
1433 if (cgraph_node_in_set_p (node
, set
))
1435 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1436 output_edge_opt_summary (ob
, e
);
1437 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
1438 output_edge_opt_summary (ob
, e
);
1442 /* Output optimization summaries stored in callgraph.
1443 At the moment it is the clone info structure. */
1446 output_cgraph_opt_summary (cgraph_node_set set
)
1450 lto_symtab_encoder_t encoder
;
1451 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
1454 ob
->cgraph_node
= NULL
;
1455 encoder
= ob
->decl_state
->symtab_node_encoder
;
1456 n_nodes
= lto_symtab_encoder_size (encoder
);
1457 for (i
= 0; i
< n_nodes
; i
++)
1458 if (symtab_function_p (node
= lto_symtab_encoder_deref (encoder
, i
))
1459 && output_cgraph_opt_summary_p (cgraph (node
), set
))
1461 streamer_write_uhwi (ob
, count
);
1462 for (i
= 0; i
< n_nodes
; i
++)
1464 node
= lto_symtab_encoder_deref (encoder
, i
);
1465 if (symtab_function_p (node
)
1466 && output_cgraph_opt_summary_p (cgraph (node
), set
))
1468 streamer_write_uhwi (ob
, i
);
1469 output_node_opt_summary (ob
, cgraph (node
), set
);
1472 produce_asm (ob
, NULL
);
1473 destroy_output_block (ob
);
1476 /* Input optimisation summary of EDGE. */
1479 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
1480 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
1484 /* Input optimisation summary of NODE. */
1487 input_node_opt_summary (struct cgraph_node
*node
,
1488 struct lto_input_block
*ib_main
,
1489 struct data_in
*data_in
)
1494 struct bitpack_d bp
;
1495 struct cgraph_edge
*e
;
1497 count
= streamer_read_uhwi (ib_main
);
1499 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
1500 for (i
= 0; i
< count
; i
++)
1502 bit
= streamer_read_uhwi (ib_main
);
1503 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
1505 count
= streamer_read_uhwi (ib_main
);
1507 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
1508 for (i
= 0; i
< count
; i
++)
1510 bit
= streamer_read_uhwi (ib_main
);
1511 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
1513 count
= streamer_read_uhwi (ib_main
);
1514 for (i
= 0; i
< count
; i
++)
1518 struct ipa_replace_map
*map
= ggc_alloc_ipa_replace_map ();
1520 VEC_safe_push (ipa_replace_map_p
, gc
, node
->clone
.tree_map
, map
);
1521 for (parm_num
= 0, parm
= DECL_ARGUMENTS (node
->symbol
.decl
); parm_num
;
1522 parm
= DECL_CHAIN (parm
))
1524 map
->parm_num
= streamer_read_uhwi (ib_main
);
1525 map
->old_tree
= NULL
;
1526 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
1527 bp
= streamer_read_bitpack (ib_main
);
1528 map
->replace_p
= bp_unpack_value (&bp
, 1);
1529 map
->ref_p
= bp_unpack_value (&bp
, 1);
1531 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1532 input_edge_opt_summary (e
, ib_main
);
1533 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
1534 input_edge_opt_summary (e
, ib_main
);
1537 /* Read section in file FILE_DATA of length LEN with data DATA. */
1540 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
1541 const char *data
, size_t len
, VEC (symtab_node
,
1544 const struct lto_function_header
*header
=
1545 (const struct lto_function_header
*) data
;
1546 const int cfg_offset
= sizeof (struct lto_function_header
);
1547 const int main_offset
= cfg_offset
+ header
->cfg_size
;
1548 const int string_offset
= main_offset
+ header
->main_size
;
1549 struct data_in
*data_in
;
1550 struct lto_input_block ib_main
;
1554 LTO_INIT_INPUT_BLOCK (ib_main
, (const char *) data
+ main_offset
, 0,
1558 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
1559 header
->string_size
, NULL
);
1560 count
= streamer_read_uhwi (&ib_main
);
1562 for (i
= 0; i
< count
; i
++)
1564 int ref
= streamer_read_uhwi (&ib_main
);
1565 input_node_opt_summary (cgraph (VEC_index (symtab_node
, nodes
, ref
)),
1568 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
1570 lto_data_in_delete (data_in
);
1573 /* Input optimization summary of cgraph. */
1576 input_cgraph_opt_summary (VEC (symtab_node
, heap
) * nodes
)
1578 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1579 struct lto_file_decl_data
*file_data
;
1582 while ((file_data
= file_data_vec
[j
++]))
1586 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
1590 input_cgraph_opt_section (file_data
, data
, len
, nodes
);