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"
48 #include "tree-pass.h"
50 static void output_cgraph_opt_summary (void);
51 static void input_cgraph_opt_summary (vec
<symtab_node
> nodes
);
53 /* Number of LDPR values known to GCC. */
54 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
56 /* All node orders are ofsetted by ORDER_BASE. */
57 static int order_base
;
59 /* Cgraph streaming is organized as set of record whose type
60 is indicated by a tag. */
63 /* Must leave 0 for the stopper. */
65 /* Cgraph node without body available. */
66 LTO_symtab_unavail_node
= 1,
67 /* Cgraph node with function body. */
68 LTO_symtab_analyzed_node
,
71 LTO_symtab_indirect_edge
,
76 /* Create a new symtab encoder.
77 if FOR_INPUT, the encoder allocate only datastructures needed
78 to read the symtab. */
81 lto_symtab_encoder_new (bool for_input
)
83 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
86 encoder
->map
= pointer_map_create ();
87 encoder
->nodes
.create (0);
92 /* Delete ENCODER and its components. */
95 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
97 encoder
->nodes
.release ();
99 pointer_map_destroy (encoder
->map
);
104 /* Return the existing reference number of NODE in the symtab encoder in
105 output block OB. Assign a new reference if this is the first time
109 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
117 lto_encoder_entry entry
= {node
, false, false, false};
119 ref
= encoder
->nodes
.length ();
120 encoder
->nodes
.safe_push (entry
);
124 slot
= pointer_map_contains (encoder
->map
, node
);
127 lto_encoder_entry entry
= {node
, false, false, false};
128 ref
= encoder
->nodes
.length ();
130 slot
= pointer_map_insert (encoder
->map
, node
);
131 *slot
= (void *) (intptr_t) (ref
+ 1);
132 encoder
->nodes
.safe_push (entry
);
135 ref
= (size_t) *slot
- 1;
140 /* Remove NODE from encoder. */
143 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
146 void **slot
, **last_slot
;
148 lto_encoder_entry last_node
;
150 slot
= pointer_map_contains (encoder
->map
, node
);
151 if (slot
== NULL
|| !*slot
)
154 index
= (size_t) *slot
- 1;
155 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
157 /* Remove from vector. We do this by swapping node with the last element
159 last_node
= encoder
->nodes
.pop ();
160 if (last_node
.node
!= node
)
162 last_slot
= pointer_map_contains (encoder
->map
, last_node
.node
);
163 gcc_checking_assert (last_slot
&& *last_slot
);
164 *last_slot
= (void *)(size_t) (index
+ 1);
166 /* Move the last element to the original spot of NODE. */
167 encoder
->nodes
[index
] = last_node
;
170 /* Remove element from hash table. */
176 /* Return TRUE if we should encode initializer of NODE (if any). */
179 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
180 struct cgraph_node
*node
)
182 int index
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)node
);
183 return encoder
->nodes
[index
].body
;
186 /* Return TRUE if we should encode body of NODE (if any). */
189 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
190 struct cgraph_node
*node
)
192 int index
= lto_symtab_encoder_encode (encoder
, (symtab_node
)node
);
193 gcc_checking_assert (encoder
->nodes
[index
].node
== (symtab_node
)node
);
194 encoder
->nodes
[index
].body
= true;
197 /* Return TRUE if we should encode initializer of NODE (if any). */
200 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
201 struct varpool_node
*node
)
203 int index
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)node
);
204 if (index
== LCC_NOT_FOUND
)
206 return encoder
->nodes
[index
].initializer
;
209 /* Return TRUE if we should encode initializer of NODE (if any). */
212 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
213 struct varpool_node
*node
)
215 int index
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)node
);
216 encoder
->nodes
[index
].initializer
= true;
219 /* Return TRUE if we should encode initializer of NODE (if any). */
222 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder
,
225 int index
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)node
);
226 if (index
== LCC_NOT_FOUND
)
228 return encoder
->nodes
[index
].in_partition
;
231 /* Return TRUE if we should encode body of NODE (if any). */
234 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
237 int index
= lto_symtab_encoder_encode (encoder
, (symtab_node
)node
);
238 encoder
->nodes
[index
].in_partition
= true;
241 /* Output the cgraph EDGE to OB using ENCODER. */
244 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
245 lto_symtab_encoder_t encoder
)
251 if (edge
->indirect_unknown_callee
)
252 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
253 LTO_symtab_indirect_edge
);
255 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
258 ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)edge
->caller
);
259 gcc_assert (ref
!= LCC_NOT_FOUND
);
260 streamer_write_hwi_stream (ob
->main_stream
, ref
);
262 if (!edge
->indirect_unknown_callee
)
264 ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)edge
->callee
);
265 gcc_assert (ref
!= LCC_NOT_FOUND
);
266 streamer_write_hwi_stream (ob
->main_stream
, ref
);
269 streamer_write_hwi_stream (ob
->main_stream
, edge
->count
);
271 bp
= bitpack_create (ob
->main_stream
);
272 uid
= (!gimple_has_body_p (edge
->caller
->symbol
.decl
)
273 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
));
274 bp_pack_enum (&bp
, cgraph_inline_failed_enum
,
275 CIF_N_REASONS
, edge
->inline_failed
);
276 bp_pack_var_len_unsigned (&bp
, uid
);
277 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
278 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
279 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
280 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
281 if (edge
->indirect_unknown_callee
)
283 int flags
= edge
->indirect_info
->ecf_flags
;
284 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
285 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
286 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
287 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
288 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
289 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
290 /* Flags that should not appear on indirect calls. */
291 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
297 streamer_write_bitpack (&bp
);
300 /* Return if LIST contain references from other partitions. */
303 referenced_from_other_partition_p (struct ipa_ref_list
*list
, lto_symtab_encoder_t encoder
)
307 for (i
= 0; ipa_ref_list_referring_iterate (list
, i
, ref
); i
++)
309 if (ref
->referring
->symbol
.in_other_partition
310 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
316 /* Return true when node is reachable from other partition. */
319 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
321 struct cgraph_edge
*e
;
324 if (node
->global
.inlined_to
)
326 for (e
= node
->callers
; e
; e
= e
->next_caller
)
327 if (e
->caller
->symbol
.in_other_partition
328 || !lto_symtab_encoder_in_partition_p (encoder
, (symtab_node
)e
->caller
))
333 /* Return if LIST contain references from other partitions. */
336 referenced_from_this_partition_p (struct ipa_ref_list
*list
,
337 lto_symtab_encoder_t encoder
)
341 for (i
= 0; ipa_ref_list_referring_iterate (list
, i
, ref
); i
++)
342 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
347 /* Return true when node is reachable from other partition. */
350 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
352 struct cgraph_edge
*e
;
353 for (e
= node
->callers
; e
; e
= e
->next_caller
)
354 if (lto_symtab_encoder_in_partition_p (encoder
, (symtab_node
)e
->caller
))
359 /* Output the cgraph NODE to OB. ENCODER is used to find the
360 reference number of NODE->inlined_to. SET is the set of nodes we
361 are writing to the current file. If NODE is not in SET, then NODE
362 is a boundary of a cgraph_node_set and we pretend NODE just has a
363 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
364 that have had their callgraph node written so far. This is used to
365 determine if NODE is a clone of a previously written node. */
368 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
369 lto_symtab_encoder_t encoder
)
375 bool in_other_partition
= false;
376 struct cgraph_node
*clone_of
;
377 struct ipa_opt_pass_d
*pass
;
380 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, (symtab_node
)node
);
382 if (node
->analyzed
&& !boundary_p
)
383 tag
= LTO_symtab_analyzed_node
;
385 tag
= LTO_symtab_unavail_node
;
387 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
389 streamer_write_hwi_stream (ob
->main_stream
, node
->symbol
.order
);
391 /* In WPA mode, we only output part of the call-graph. Also, we
392 fake cgraph node attributes. There are two cases that we care.
394 Boundary nodes: There are nodes that are not part of SET but are
395 called from within SET. We artificially make them look like
396 externally visible nodes with no function body.
398 Cherry-picked nodes: These are nodes we pulled from other
399 translation units into SET during IPA-inlining. We make them as
400 local static nodes to prevent clashes with other local statics. */
401 if (boundary_p
&& node
->analyzed
&& !DECL_EXTERNAL (node
->symbol
.decl
))
403 /* Inline clones can not be part of boundary.
404 gcc_assert (!node->global.inlined_to);
406 FIXME: At the moment they can be, when partition contains an inline
407 clone that is clone of inline clone from outside partition. We can
408 reshape the clone tree and make other tree to be the root, but it
409 needs a bit extra work and will be promplty done by cgraph_remove_node
410 after reading back. */
411 in_other_partition
= 1;
414 clone_of
= node
->clone_of
;
416 && (ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)clone_of
)) == LCC_NOT_FOUND
)
417 if (clone_of
->prev_sibling_clone
)
418 clone_of
= clone_of
->prev_sibling_clone
;
420 clone_of
= clone_of
->clone_of
;
422 if (LTO_symtab_analyzed_node
)
423 gcc_assert (clone_of
|| !node
->clone_of
);
425 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
427 streamer_write_hwi_stream (ob
->main_stream
, ref
);
430 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->symbol
.decl
);
431 streamer_write_hwi_stream (ob
->main_stream
, node
->count
);
432 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
434 streamer_write_hwi_stream (ob
->main_stream
,
435 node
->ipa_transforms_to_apply
.length ());
436 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
437 streamer_write_hwi_stream (ob
->main_stream
, pass
->pass
.static_pass_number
);
439 if (tag
== LTO_symtab_analyzed_node
)
441 if (node
->global
.inlined_to
)
443 ref
= lto_symtab_encoder_lookup (encoder
, (symtab_node
)node
->global
.inlined_to
);
444 gcc_assert (ref
!= LCC_NOT_FOUND
);
449 streamer_write_hwi_stream (ob
->main_stream
, ref
);
452 if (node
->symbol
.same_comdat_group
&& !boundary_p
)
454 ref
= lto_symtab_encoder_lookup (encoder
,
455 node
->symbol
.same_comdat_group
);
456 gcc_assert (ref
!= LCC_NOT_FOUND
);
460 streamer_write_hwi_stream (ob
->main_stream
, ref
);
462 bp
= bitpack_create (ob
->main_stream
);
463 bp_pack_value (&bp
, node
->local
.local
, 1);
464 bp_pack_value (&bp
, node
->symbol
.externally_visible
, 1);
465 bp_pack_value (&bp
, node
->local
.finalized
, 1);
466 bp_pack_value (&bp
, node
->local
.versionable
, 1);
467 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
468 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
469 bp_pack_value (&bp
, node
->symbol
.force_output
, 1);
470 bp_pack_value (&bp
, node
->symbol
.address_taken
, 1);
471 bp_pack_value (&bp
, node
->abstract_and_needed
, 1);
472 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
473 && !DECL_EXTERNAL (node
->symbol
.decl
)
474 && !DECL_COMDAT (node
->symbol
.decl
)
475 && (reachable_from_other_partition_p (node
, encoder
)
476 || referenced_from_other_partition_p (&node
->symbol
.ref_list
,
478 bp_pack_value (&bp
, node
->lowered
, 1);
479 bp_pack_value (&bp
, in_other_partition
, 1);
480 /* Real aliases in a boundary become non-aliases. However we still stream
481 alias info on weakrefs.
482 TODO: We lose a bit of information here - when we know that variable is
483 defined in other unit, we may use the info on aliases to resolve
484 symbol1 != symbol2 type tests that we can do only for locally defined objects
486 bp_pack_value (&bp
, node
->alias
&& (!boundary_p
|| DECL_EXTERNAL (node
->symbol
.decl
)), 1);
487 bp_pack_value (&bp
, node
->frequency
, 2);
488 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
489 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
490 bp_pack_value (&bp
, node
->tm_clone
, 1);
491 bp_pack_value (&bp
, node
->thunk
.thunk_p
&& !boundary_p
, 1);
492 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
493 LDPR_NUM_KNOWN
, node
->symbol
.resolution
);
494 streamer_write_bitpack (&bp
);
496 if (node
->thunk
.thunk_p
&& !boundary_p
)
498 streamer_write_uhwi_stream
500 1 + (node
->thunk
.this_adjusting
!= 0) * 2
501 + (node
->thunk
.virtual_offset_p
!= 0) * 4);
502 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
503 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
505 if ((node
->alias
|| node
->thunk
.thunk_p
)
506 && (!boundary_p
|| (node
->alias
&& DECL_EXTERNAL (node
->symbol
.decl
))))
508 streamer_write_hwi_in_range (ob
->main_stream
, 0, 1,
509 node
->thunk
.alias
!= NULL
);
510 if (node
->thunk
.alias
!= NULL
)
511 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
516 /* Output the varpool NODE to OB.
517 If NODE is not in SET, then NODE is a boundary. */
520 lto_output_varpool_node (struct lto_simple_output_block
*ob
, struct varpool_node
*node
,
521 lto_symtab_encoder_t encoder
)
523 bool boundary_p
= (node
->analyzed
524 && !lto_symtab_encoder_in_partition_p (encoder
, (symtab_node
)node
));
528 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
529 LTO_symtab_variable
);
530 streamer_write_hwi_stream (ob
->main_stream
, node
->symbol
.order
);
531 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->symbol
.decl
);
532 bp
= bitpack_create (ob
->main_stream
);
533 bp_pack_value (&bp
, node
->symbol
.externally_visible
, 1);
534 bp_pack_value (&bp
, node
->symbol
.force_output
, 1);
535 bp_pack_value (&bp
, node
->finalized
, 1);
536 bp_pack_value (&bp
, node
->alias
, 1);
537 bp_pack_value (&bp
, node
->alias_of
!= NULL
, 1);
538 gcc_assert (node
->finalized
|| !node
->analyzed
);
539 /* Constant pool initializers can be de-unified into individual ltrans units.
540 FIXME: Alternatively at -Os we may want to avoid generating for them the local
541 labels and share them across LTRANS partitions. */
542 if (DECL_IN_CONSTANT_POOL (node
->symbol
.decl
)
543 && !DECL_EXTERNAL (node
->symbol
.decl
)
544 && !DECL_COMDAT (node
->symbol
.decl
))
546 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
547 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
551 bp_pack_value (&bp
, node
->analyzed
552 && referenced_from_other_partition_p (&node
->symbol
.ref_list
,
554 bp_pack_value (&bp
, boundary_p
&& !DECL_EXTERNAL (node
->symbol
.decl
), 1);
555 /* in_other_partition. */
557 streamer_write_bitpack (&bp
);
559 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->alias_of
);
560 if (node
->symbol
.same_comdat_group
&& !boundary_p
)
562 ref
= lto_symtab_encoder_lookup (encoder
,
563 node
->symbol
.same_comdat_group
);
564 gcc_assert (ref
!= LCC_NOT_FOUND
);
568 streamer_write_hwi_stream (ob
->main_stream
, ref
);
569 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
570 LDPR_NUM_KNOWN
, node
->symbol
.resolution
);
573 /* Output the varpool NODE to OB.
574 If NODE is not in SET, then NODE is a boundary. */
577 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
578 lto_symtab_encoder_t encoder
)
583 bp
= bitpack_create (ob
->main_stream
);
584 bp_pack_value (&bp
, ref
->use
, 2);
585 streamer_write_bitpack (&bp
);
586 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
587 gcc_assert (nref
!= LCC_NOT_FOUND
);
588 streamer_write_hwi_stream (ob
->main_stream
, nref
);
591 /* Stream out profile_summary to OB. */
594 output_profile_summary (struct lto_simple_output_block
*ob
)
598 /* We do not output num, sum_all and run_max, they are not used by
599 GCC profile feedback and they are difficult to merge from multiple
601 gcc_assert (profile_info
->runs
);
602 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
603 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->sum_max
);
606 streamer_write_uhwi_stream (ob
->main_stream
, 0);
609 /* Output all callees or indirect outgoing edges. EDGE must be the first such
613 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
614 struct lto_simple_output_block
*ob
,
615 lto_symtab_encoder_t encoder
)
620 /* Output edges in backward direction, so the reconstructed callgraph match
621 and it is easy to associate call sites in the IPA pass summaries. */
622 while (edge
->next_callee
)
623 edge
= edge
->next_callee
;
624 for (; edge
; edge
= edge
->prev_callee
)
625 lto_output_edge (ob
, edge
, encoder
);
628 /* Output the part of the cgraph in SET. */
631 output_refs (lto_symtab_encoder_t encoder
)
633 lto_symtab_encoder_iterator lsei
;
634 struct lto_simple_output_block
*ob
;
639 ob
= lto_create_simple_output_block (LTO_section_refs
);
641 for (lsei
= lsei_start_in_partition (encoder
); !lsei_end_p (lsei
);
642 lsei_next_in_partition (&lsei
))
644 symtab_node node
= lsei_node (lsei
);
646 count
= ipa_ref_list_nreferences (&node
->symbol
.ref_list
);
649 streamer_write_uhwi_stream (ob
->main_stream
, count
);
650 streamer_write_uhwi_stream (ob
->main_stream
,
651 lto_symtab_encoder_lookup (encoder
, node
));
652 for (i
= 0; ipa_ref_list_reference_iterate (&node
->symbol
.ref_list
,
654 lto_output_ref (ob
, ref
, encoder
);
658 streamer_write_uhwi_stream (ob
->main_stream
, 0);
660 lto_destroy_simple_output_block (ob
);
663 /* Add NODE into encoder as well as nodes it is cloned from.
664 Do it in a way so clones appear first. */
667 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
671 add_node_to (encoder
, node
->clone_of
, include_body
);
672 else if (include_body
)
673 lto_set_symtab_encoder_encode_body (encoder
, node
);
674 lto_symtab_encoder_encode (encoder
, (symtab_node
)node
);
677 /* Add all references in LIST to encoders. */
680 add_references (lto_symtab_encoder_t encoder
,
681 struct ipa_ref_list
*list
)
685 for (i
= 0; ipa_ref_list_reference_iterate (list
, i
, ref
); i
++)
686 if (is_a
<cgraph_node
> (ref
->referred
))
687 add_node_to (encoder
, ipa_ref_node (ref
), false);
689 lto_symtab_encoder_encode (encoder
, ref
->referred
);
692 /* Find all symbols we want to stream into given partition and insert them
695 The function actually replaces IN_ENCODER by new one. The reason is that
696 streaming code needs clone's origin to be streamed before clone. This
697 means that we need to insert the nodes in specific order. This order is
698 ignored by the partitioning logic earlier. */
701 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
703 struct cgraph_node
*node
;
704 struct cgraph_edge
*edge
;
706 lto_symtab_encoder_t encoder
;
707 lto_symtab_encoder_iterator lsei
;
709 encoder
= lto_symtab_encoder_new (false);
711 /* Go over all entries in the IN_ENCODER and duplicate them to
712 ENCODER. At the same time insert masters of clones so
713 every master appears before clone. */
714 for (lsei
= lsei_start_function_in_partition (in_encoder
);
715 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
717 node
= lsei_cgraph_node (lsei
);
718 add_node_to (encoder
, node
, true);
719 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)node
);
720 add_references (encoder
, &node
->symbol
.ref_list
);
722 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
723 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
725 struct varpool_node
*vnode
= lsei_varpool_node (lsei
);
726 gcc_assert (!vnode
->alias
|| vnode
->alias_of
);
727 lto_set_symtab_encoder_in_partition (encoder
, (symtab_node
)vnode
);
728 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
729 add_references (encoder
, &vnode
->symbol
.ref_list
);
731 /* Pickle in also the initializer of all referenced readonly variables
732 to help folding. Constant pool variables are not shared, so we must
734 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
736 symtab_node node
= lto_symtab_encoder_deref (encoder
, i
);
737 if (varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
))
739 if (DECL_INITIAL (vnode
->symbol
.decl
)
740 && !lto_symtab_encoder_encode_initializer_p (encoder
,
742 && const_value_known_p (vnode
->symbol
.decl
))
744 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
745 add_references (encoder
, &vnode
->symbol
.ref_list
);
750 /* Go over all the nodes again to include callees that are not in
752 for (lsei
= lsei_start_function_in_partition (encoder
);
753 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
755 node
= lsei_cgraph_node (lsei
);
756 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
758 struct cgraph_node
*callee
= edge
->callee
;
759 if (!lto_symtab_encoder_in_partition_p (encoder
, (symtab_node
)callee
))
761 /* We should have moved all the inlines. */
762 gcc_assert (!callee
->global
.inlined_to
);
763 add_node_to (encoder
, callee
, false);
767 lto_symtab_encoder_delete (in_encoder
);
771 /* Output the part of the symtab in SET and VSET. */
776 struct cgraph_node
*node
;
777 struct lto_simple_output_block
*ob
;
778 lto_symtab_encoder_iterator lsei
;
780 lto_symtab_encoder_t encoder
;
781 static bool asm_nodes_output
= false;
784 output_cgraph_opt_summary ();
786 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
788 output_profile_summary (ob
);
790 /* An encoder for cgraph nodes should have been created by
791 ipa_write_summaries_1. */
792 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
793 encoder
= ob
->decl_state
->symtab_node_encoder
;
795 /* Write out the nodes. We must first output a node and then its clones,
796 otherwise at a time reading back the node there would be nothing to clone
798 n_nodes
= lto_symtab_encoder_size (encoder
);
799 for (i
= 0; i
< n_nodes
; i
++)
801 symtab_node node
= lto_symtab_encoder_deref (encoder
, i
);
802 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
))
803 lto_output_node (ob
, cnode
, encoder
);
805 lto_output_varpool_node (ob
, varpool (node
), encoder
);
809 /* Go over the nodes in SET again to write edges. */
810 for (lsei
= lsei_start_function_in_partition (encoder
); !lsei_end_p (lsei
);
811 lsei_next_function_in_partition (&lsei
))
813 node
= lsei_cgraph_node (lsei
);
814 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
815 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
818 streamer_write_uhwi_stream (ob
->main_stream
, 0);
820 lto_destroy_simple_output_block (ob
);
822 /* Emit toplevel asms.
823 When doing WPA we must output every asm just once. Since we do not partition asm
824 nodes at all, output them to first output. This is kind of hack, but should work
826 if (!asm_nodes_output
)
828 asm_nodes_output
= true;
829 lto_output_toplevel_asms ();
832 output_refs (encoder
);
835 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
836 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
837 NODE or to replace the values in it, for instance because the first
838 time we saw it, the function body was not available but now it
839 is. BP is a bitpack with all the bitflags for NODE read from the
843 input_overwrite_node (struct lto_file_decl_data
*file_data
,
844 struct cgraph_node
*node
,
845 enum LTO_symtab_tags tag
,
846 struct bitpack_d
*bp
)
848 node
->symbol
.aux
= (void *) tag
;
849 node
->symbol
.lto_file_data
= file_data
;
851 node
->local
.local
= bp_unpack_value (bp
, 1);
852 node
->symbol
.externally_visible
= bp_unpack_value (bp
, 1);
853 node
->local
.finalized
= bp_unpack_value (bp
, 1);
854 node
->local
.versionable
= bp_unpack_value (bp
, 1);
855 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
856 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
857 node
->symbol
.force_output
= bp_unpack_value (bp
, 1);
858 node
->symbol
.address_taken
= bp_unpack_value (bp
, 1);
859 node
->abstract_and_needed
= bp_unpack_value (bp
, 1);
860 node
->symbol
.used_from_other_partition
= bp_unpack_value (bp
, 1);
861 node
->lowered
= bp_unpack_value (bp
, 1);
862 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
863 node
->symbol
.in_other_partition
= bp_unpack_value (bp
, 1);
864 if (node
->symbol
.in_other_partition
865 /* Avoid updating decl when we are seeing just inline clone.
866 When inlining function that has functions already inlined into it,
867 we produce clones of inline clones.
869 WPA partitioning might put each clone into different unit and
870 we might end up streaming inline clone from other partition
871 to support clone we are interested in. */
873 || node
->clone_of
->symbol
.decl
!= node
->symbol
.decl
))
875 DECL_EXTERNAL (node
->symbol
.decl
) = 1;
876 TREE_STATIC (node
->symbol
.decl
) = 0;
878 node
->alias
= bp_unpack_value (bp
, 1);
879 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
880 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
881 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
882 node
->tm_clone
= bp_unpack_value (bp
, 1);
883 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
884 node
->symbol
.resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
888 /* Read a node from input_block IB. TAG is the node's tag just read.
889 Return the node read or overwriten. */
891 static struct cgraph_node
*
892 input_node (struct lto_file_decl_data
*file_data
,
893 struct lto_input_block
*ib
,
894 enum LTO_symtab_tags tag
,
895 vec
<symtab_node
> nodes
)
898 struct cgraph_node
*node
;
901 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
906 order
= streamer_read_hwi (ib
) + order_base
;
907 clone_ref
= streamer_read_hwi (ib
);
909 decl_index
= streamer_read_uhwi (ib
);
910 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
912 if (clone_ref
!= LCC_NOT_FOUND
)
914 node
= cgraph_clone_node (cgraph (nodes
[clone_ref
]), fn_decl
,
915 0, CGRAPH_FREQ_BASE
, false,
916 vec
<cgraph_edge_p
>(), false);
919 node
= cgraph_get_create_node (fn_decl
);
921 node
->symbol
.order
= order
;
922 if (order
>= symtab_order
)
923 symtab_order
= order
+ 1;
925 node
->count
= streamer_read_hwi (ib
);
926 node
->count_materialization_scale
= streamer_read_hwi (ib
);
928 count
= streamer_read_hwi (ib
);
929 node
->ipa_transforms_to_apply
= vec
<ipa_opt_pass
>();
930 for (i
= 0; i
< count
; i
++)
932 struct opt_pass
*pass
;
933 int pid
= streamer_read_hwi (ib
);
935 gcc_assert (pid
< passes_by_id_size
);
936 pass
= passes_by_id
[pid
];
937 node
->ipa_transforms_to_apply
.safe_push ((struct ipa_opt_pass_d
*) pass
);
940 if (tag
== LTO_symtab_analyzed_node
)
941 ref
= streamer_read_hwi (ib
);
943 ref2
= streamer_read_hwi (ib
);
945 /* Make sure that we have not read this node before. Nodes that
946 have already been read will have their tag stored in the 'aux'
947 field. Since built-in functions can be referenced in multiple
948 functions, they are expected to be read more than once. */
949 if (node
->symbol
.aux
&& !DECL_BUILT_IN (node
->symbol
.decl
))
950 internal_error ("bytecode stream: found multiple instances of cgraph "
951 "node %d", node
->uid
);
953 bp
= streamer_read_bitpack (ib
);
954 input_overwrite_node (file_data
, node
, tag
, &bp
);
956 /* Store a reference for now, and fix up later to be a pointer. */
957 node
->global
.inlined_to
= (cgraph_node_ptr
) (intptr_t) ref
;
959 /* Store a reference for now, and fix up later to be a pointer. */
960 node
->symbol
.same_comdat_group
= (symtab_node
) (intptr_t) ref2
;
962 if (node
->thunk
.thunk_p
)
964 int type
= streamer_read_uhwi (ib
);
965 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
966 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
968 node
->thunk
.fixed_offset
= fixed_offset
;
969 node
->thunk
.this_adjusting
= (type
& 2);
970 node
->thunk
.virtual_value
= virtual_value
;
971 node
->thunk
.virtual_offset_p
= (type
& 4);
973 if (node
->thunk
.thunk_p
|| node
->alias
)
975 if (streamer_read_hwi_in_range (ib
, "alias nonzero flag", 0, 1))
977 decl_index
= streamer_read_uhwi (ib
);
978 node
->thunk
.alias
= lto_file_decl_data_get_fn_decl (file_data
,
985 /* Read a node from input_block IB. TAG is the node's tag just read.
986 Return the node read or overwriten. */
988 static struct varpool_node
*
989 input_varpool_node (struct lto_file_decl_data
*file_data
,
990 struct lto_input_block
*ib
)
994 struct varpool_node
*node
;
996 int ref
= LCC_NOT_FOUND
;
997 bool non_null_aliasof
;
1000 order
= streamer_read_hwi (ib
) + order_base
;
1001 decl_index
= streamer_read_uhwi (ib
);
1002 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1003 node
= varpool_node_for_decl (var_decl
);
1004 node
->symbol
.order
= order
;
1005 if (order
>= symtab_order
)
1006 symtab_order
= order
+ 1;
1007 node
->symbol
.lto_file_data
= file_data
;
1009 bp
= streamer_read_bitpack (ib
);
1010 node
->symbol
.externally_visible
= bp_unpack_value (&bp
, 1);
1011 node
->symbol
.force_output
= bp_unpack_value (&bp
, 1);
1012 node
->finalized
= bp_unpack_value (&bp
, 1);
1013 node
->alias
= bp_unpack_value (&bp
, 1);
1014 non_null_aliasof
= bp_unpack_value (&bp
, 1);
1015 node
->symbol
.used_from_other_partition
= bp_unpack_value (&bp
, 1);
1016 node
->symbol
.in_other_partition
= bp_unpack_value (&bp
, 1);
1017 node
->analyzed
= (node
->finalized
&& (!node
->alias
|| !node
->symbol
.in_other_partition
));
1018 if (node
->symbol
.in_other_partition
)
1020 DECL_EXTERNAL (node
->symbol
.decl
) = 1;
1021 TREE_STATIC (node
->symbol
.decl
) = 0;
1023 if (non_null_aliasof
)
1025 decl_index
= streamer_read_uhwi (ib
);
1026 node
->alias_of
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1028 ref
= streamer_read_hwi (ib
);
1029 /* Store a reference for now, and fix up later to be a pointer. */
1030 node
->symbol
.same_comdat_group
= (symtab_node
) (intptr_t) ref
;
1031 node
->symbol
.resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1037 /* Read a node from input_block IB. TAG is the node's tag just read.
1038 Return the node read or overwriten. */
1041 input_ref (struct lto_input_block
*ib
,
1042 symtab_node referring_node
,
1043 vec
<symtab_node
> nodes
)
1045 symtab_node node
= NULL
;
1046 struct bitpack_d bp
;
1047 enum ipa_ref_use use
;
1049 bp
= streamer_read_bitpack (ib
);
1050 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 2);
1051 node
= nodes
[streamer_read_hwi (ib
)];
1052 ipa_record_reference (referring_node
, node
, use
, NULL
);
1055 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1056 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1057 edge being read is indirect (in the sense that it has
1058 indirect_unknown_callee set). */
1061 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
> nodes
,
1064 struct cgraph_node
*caller
, *callee
;
1065 struct cgraph_edge
*edge
;
1066 unsigned int stmt_id
;
1069 cgraph_inline_failed_t inline_failed
;
1070 struct bitpack_d bp
;
1073 caller
= cgraph (nodes
[streamer_read_hwi (ib
)]);
1074 if (caller
== NULL
|| caller
->symbol
.decl
== NULL_TREE
)
1075 internal_error ("bytecode stream: no caller found while reading edge");
1079 callee
= cgraph (nodes
[streamer_read_hwi (ib
)]);
1080 if (callee
== NULL
|| callee
->symbol
.decl
== NULL_TREE
)
1081 internal_error ("bytecode stream: no callee found while reading edge");
1086 count
= (gcov_type
) streamer_read_hwi (ib
);
1088 bp
= streamer_read_bitpack (ib
);
1089 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_enum
, CIF_N_REASONS
);
1090 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1091 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1094 edge
= cgraph_create_indirect_edge (caller
, NULL
, 0, count
, freq
);
1096 edge
= cgraph_create_edge (caller
, callee
, NULL
, count
, freq
);
1098 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1099 edge
->lto_stmt_uid
= stmt_id
;
1100 edge
->inline_failed
= inline_failed
;
1101 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1102 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1105 if (bp_unpack_value (&bp
, 1))
1106 ecf_flags
|= ECF_CONST
;
1107 if (bp_unpack_value (&bp
, 1))
1108 ecf_flags
|= ECF_PURE
;
1109 if (bp_unpack_value (&bp
, 1))
1110 ecf_flags
|= ECF_NORETURN
;
1111 if (bp_unpack_value (&bp
, 1))
1112 ecf_flags
|= ECF_MALLOC
;
1113 if (bp_unpack_value (&bp
, 1))
1114 ecf_flags
|= ECF_NOTHROW
;
1115 if (bp_unpack_value (&bp
, 1))
1116 ecf_flags
|= ECF_RETURNS_TWICE
;
1117 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1122 /* Read a cgraph from IB using the info in FILE_DATA. */
1124 static vec
<symtab_node
>
1125 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1126 struct lto_input_block
*ib
)
1128 enum LTO_symtab_tags tag
;
1129 vec
<symtab_node
> nodes
= vec
<symtab_node
>();
1133 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1134 order_base
= symtab_order
;
1137 if (tag
== LTO_symtab_edge
)
1138 input_edge (ib
, nodes
, false);
1139 else if (tag
== LTO_symtab_indirect_edge
)
1140 input_edge (ib
, nodes
, true);
1141 else if (tag
== LTO_symtab_variable
)
1143 node
= (symtab_node
)input_varpool_node (file_data
, ib
);
1144 nodes
.safe_push (node
);
1145 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1149 node
= (symtab_node
)input_node (file_data
, ib
, tag
, nodes
);
1150 if (node
== NULL
|| node
->symbol
.decl
== NULL_TREE
)
1151 internal_error ("bytecode stream: found empty cgraph node");
1152 nodes
.safe_push (node
);
1153 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1156 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1159 lto_input_toplevel_asms (file_data
, order_base
);
1161 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1162 #ifdef ENABLE_CHECKING
1163 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1164 gcc_assert (node
->symbol
.aux
|| !is_a
<cgraph_node
> (node
));
1166 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1169 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
))
1171 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1173 /* We share declaration of builtins, so we may read same node twice. */
1174 if (!node
->symbol
.aux
)
1176 node
->symbol
.aux
= NULL
;
1178 /* Fixup inlined_to from reference to pointer. */
1179 if (ref
!= LCC_NOT_FOUND
)
1180 cgraph (node
)->global
.inlined_to
= cgraph (nodes
[ref
]);
1182 cnode
->global
.inlined_to
= NULL
;
1185 ref
= (int) (intptr_t) node
->symbol
.same_comdat_group
;
1187 /* Fixup same_comdat_group from reference to pointer. */
1188 if (ref
!= LCC_NOT_FOUND
)
1189 node
->symbol
.same_comdat_group
= nodes
[ref
];
1191 node
->symbol
.same_comdat_group
= NULL
;
1193 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1194 node
->symbol
.aux
= is_a
<cgraph_node
> (node
) ? (void *)1 : NULL
;
1198 /* Input ipa_refs. */
1201 input_refs (struct lto_input_block
*ib
,
1202 vec
<symtab_node
> nodes
)
1209 count
= streamer_read_uhwi (ib
);
1212 idx
= streamer_read_uhwi (ib
);
1216 input_ref (ib
, node
, nodes
);
1223 static struct gcov_ctr_summary lto_gcov_summary
;
1225 /* Input profile_info from IB. */
1227 input_profile_summary (struct lto_input_block
*ib
,
1228 struct lto_file_decl_data
*file_data
)
1230 unsigned int runs
= streamer_read_uhwi (ib
);
1233 file_data
->profile_info
.runs
= runs
;
1234 file_data
->profile_info
.sum_max
= streamer_read_uhwi (ib
);
1239 /* Rescale profile summaries to the same number of runs in the whole unit. */
1242 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1244 struct lto_file_decl_data
*file_data
;
1246 gcov_unsigned_t max_runs
= 0;
1247 struct cgraph_node
*node
;
1248 struct cgraph_edge
*edge
;
1250 /* Find unit with maximal number of runs. If we ever get serious about
1251 roundoff errors, we might also consider computing smallest common
1253 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1254 if (max_runs
< file_data
->profile_info
.runs
)
1255 max_runs
= file_data
->profile_info
.runs
;
1260 /* Simple overflow check. We probably don't need to support that many train
1261 runs. Such a large value probably imply data corruption anyway. */
1262 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1264 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1265 INT_MAX
/ REG_BR_PROB_BASE
);
1269 profile_info
= <o_gcov_summary
;
1270 lto_gcov_summary
.runs
= max_runs
;
1271 lto_gcov_summary
.sum_max
= 0;
1273 /* Rescale all units to the maximal number of runs.
1274 sum_max can not be easily merged, as we have no idea what files come from
1275 the same run. We do not use the info anyway, so leave it 0. */
1276 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1277 if (file_data
->profile_info
.runs
)
1279 int scale
= ((REG_BR_PROB_BASE
* max_runs
1280 + file_data
->profile_info
.runs
/ 2)
1281 / file_data
->profile_info
.runs
);
1282 lto_gcov_summary
.sum_max
= MAX (lto_gcov_summary
.sum_max
,
1283 (file_data
->profile_info
.sum_max
1285 + REG_BR_PROB_BASE
/ 2)
1286 / REG_BR_PROB_BASE
);
1289 /* Watch roundoff errors. */
1290 if (lto_gcov_summary
.sum_max
< max_runs
)
1291 lto_gcov_summary
.sum_max
= max_runs
;
1293 /* If merging already happent at WPA time, we are done. */
1297 /* Now compute count_materialization_scale of each node.
1298 During LTRANS we already have values of count_materialization_scale
1299 computed, so just update them. */
1300 FOR_EACH_FUNCTION (node
)
1301 if (node
->symbol
.lto_file_data
1302 && node
->symbol
.lto_file_data
->profile_info
.runs
)
1307 ((node
->count_materialization_scale
* max_runs
1308 + node
->symbol
.lto_file_data
->profile_info
.runs
/ 2)
1309 / node
->symbol
.lto_file_data
->profile_info
.runs
);
1310 node
->count_materialization_scale
= scale
;
1312 fatal_error ("Profile information in %s corrupted",
1313 file_data
->file_name
);
1315 if (scale
== REG_BR_PROB_BASE
)
1317 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1318 edge
->count
= ((edge
->count
* scale
+ REG_BR_PROB_BASE
/ 2)
1319 / REG_BR_PROB_BASE
);
1320 node
->count
= ((node
->count
* scale
+ REG_BR_PROB_BASE
/ 2)
1321 / REG_BR_PROB_BASE
);
1325 /* Input and merge the symtab from each of the .o files passed to
1331 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1332 struct lto_file_decl_data
*file_data
;
1334 struct cgraph_node
*node
;
1336 cgraph_state
= CGRAPH_STATE_IPA_SSA
;
1338 while ((file_data
= file_data_vec
[j
++]))
1342 struct lto_input_block
*ib
;
1343 vec
<symtab_node
> nodes
;
1345 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1348 fatal_error ("cannot find LTO cgraph in %s", file_data
->file_name
);
1349 input_profile_summary (ib
, file_data
);
1350 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1351 nodes
= input_cgraph_1 (file_data
, ib
);
1352 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1355 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1358 fatal_error("cannot find LTO section refs in %s", file_data
->file_name
);
1359 input_refs (ib
, nodes
);
1360 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1363 input_cgraph_opt_summary (nodes
);
1367 merge_profile_summaries (file_data_vec
);
1369 /* Clear out the aux field that was used to store enough state to
1370 tell which nodes should be overwritten. */
1371 FOR_EACH_FUNCTION (node
)
1373 /* Some nodes may have been created by cgraph_node. This
1374 happens when the callgraph contains nested functions. If the
1375 node for the parent function was never emitted to the gimple
1376 file, cgraph_node will create a node for it when setting the
1377 context of the nested function. */
1378 if (node
->symbol
.lto_file_data
)
1379 node
->symbol
.aux
= NULL
;
1383 /* True when we need optimization summary for NODE. */
1386 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1388 return (node
->clone_of
1389 && (node
->clone
.tree_map
1390 || node
->clone
.args_to_skip
1391 || node
->clone
.combined_args_to_skip
));
1394 /* Output optimization summary for EDGE to OB. */
1396 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1397 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1401 /* Output optimization summary for NODE to OB. */
1404 output_node_opt_summary (struct output_block
*ob
,
1405 struct cgraph_node
*node
,
1406 lto_symtab_encoder_t encoder
)
1410 struct ipa_replace_map
*map
;
1411 struct bitpack_d bp
;
1413 struct cgraph_edge
*e
;
1415 if (node
->clone
.args_to_skip
)
1417 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1418 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1419 streamer_write_uhwi (ob
, index
);
1422 streamer_write_uhwi (ob
, 0);
1423 if (node
->clone
.combined_args_to_skip
)
1425 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1426 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
1427 streamer_write_uhwi (ob
, index
);
1430 streamer_write_uhwi (ob
, 0);
1431 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
1432 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
1437 for (parm_num
= 0, parm
= DECL_ARGUMENTS (node
->symbol
.decl
); parm
;
1438 parm
= DECL_CHAIN (parm
), parm_num
++)
1439 if (map
->old_tree
== parm
)
1441 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1442 mechanism to store function local declarations into summaries. */
1444 streamer_write_uhwi (ob
, parm_num
);
1445 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
1446 stream_write_tree (ob
, map
->new_tree
, true);
1447 bp
= bitpack_create (ob
->main_stream
);
1448 bp_pack_value (&bp
, map
->replace_p
, 1);
1449 bp_pack_value (&bp
, map
->ref_p
, 1);
1450 streamer_write_bitpack (&bp
);
1453 if (lto_symtab_encoder_in_partition_p (encoder
, (symtab_node
) node
))
1455 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1456 output_edge_opt_summary (ob
, e
);
1457 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
1458 output_edge_opt_summary (ob
, e
);
1462 /* Output optimization summaries stored in callgraph.
1463 At the moment it is the clone info structure. */
1466 output_cgraph_opt_summary (void)
1469 lto_symtab_encoder_t encoder
;
1470 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
1473 ob
->cgraph_node
= NULL
;
1474 encoder
= ob
->decl_state
->symtab_node_encoder
;
1475 n_nodes
= lto_symtab_encoder_size (encoder
);
1476 for (i
= 0; i
< n_nodes
; i
++)
1478 symtab_node node
= lto_symtab_encoder_deref (encoder
, i
);
1479 cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
);
1480 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
1483 streamer_write_uhwi (ob
, count
);
1484 for (i
= 0; i
< n_nodes
; i
++)
1486 symtab_node node
= lto_symtab_encoder_deref (encoder
, i
);
1487 cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
);
1488 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
1490 streamer_write_uhwi (ob
, i
);
1491 output_node_opt_summary (ob
, cnode
, encoder
);
1494 produce_asm (ob
, NULL
);
1495 destroy_output_block (ob
);
1498 /* Input optimisation summary of EDGE. */
1501 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
1502 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
1506 /* Input optimisation summary of NODE. */
1509 input_node_opt_summary (struct cgraph_node
*node
,
1510 struct lto_input_block
*ib_main
,
1511 struct data_in
*data_in
)
1516 struct bitpack_d bp
;
1517 struct cgraph_edge
*e
;
1519 count
= streamer_read_uhwi (ib_main
);
1521 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
1522 for (i
= 0; i
< count
; i
++)
1524 bit
= streamer_read_uhwi (ib_main
);
1525 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
1527 count
= streamer_read_uhwi (ib_main
);
1529 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
1530 for (i
= 0; i
< count
; i
++)
1532 bit
= streamer_read_uhwi (ib_main
);
1533 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
1535 count
= streamer_read_uhwi (ib_main
);
1536 for (i
= 0; i
< count
; i
++)
1538 struct ipa_replace_map
*map
= ggc_alloc_ipa_replace_map ();
1540 vec_safe_push (node
->clone
.tree_map
, map
);
1541 map
->parm_num
= streamer_read_uhwi (ib_main
);
1542 map
->old_tree
= NULL
;
1543 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
1544 bp
= streamer_read_bitpack (ib_main
);
1545 map
->replace_p
= bp_unpack_value (&bp
, 1);
1546 map
->ref_p
= bp_unpack_value (&bp
, 1);
1548 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1549 input_edge_opt_summary (e
, ib_main
);
1550 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
1551 input_edge_opt_summary (e
, ib_main
);
1554 /* Read section in file FILE_DATA of length LEN with data DATA. */
1557 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
1558 const char *data
, size_t len
,
1559 vec
<symtab_node
> nodes
)
1561 const struct lto_function_header
*header
=
1562 (const struct lto_function_header
*) data
;
1563 const int cfg_offset
= sizeof (struct lto_function_header
);
1564 const int main_offset
= cfg_offset
+ header
->cfg_size
;
1565 const int string_offset
= main_offset
+ header
->main_size
;
1566 struct data_in
*data_in
;
1567 struct lto_input_block ib_main
;
1571 LTO_INIT_INPUT_BLOCK (ib_main
, (const char *) data
+ main_offset
, 0,
1575 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
1576 header
->string_size
,
1577 vec
<ld_plugin_symbol_resolution_t
>());
1578 count
= streamer_read_uhwi (&ib_main
);
1580 for (i
= 0; i
< count
; i
++)
1582 int ref
= streamer_read_uhwi (&ib_main
);
1583 input_node_opt_summary (cgraph (nodes
[ref
]),
1586 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
1588 lto_data_in_delete (data_in
);
1591 /* Input optimization summary of cgraph. */
1594 input_cgraph_opt_summary (vec
<symtab_node
> nodes
)
1596 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1597 struct lto_file_decl_data
*file_data
;
1600 while ((file_data
= file_data_vec
[j
++]))
1604 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
1608 input_cgraph_opt_section (file_data
, data
, len
, nodes
);