1 /* Write and read the cgraph to the memory mapped representation of a
4 Copyright (C) 2009-2014 Free Software Foundation, Inc.
5 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
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"
28 #include "stringpool.h"
34 #include "hard-reg-set.h"
37 #include "basic-block.h"
38 #include "tree-ssa-alias.h"
39 #include "internal-fn.h"
40 #include "gimple-expr.h"
46 #include "langhooks.h"
48 #include "diagnostic-core.h"
52 #include "plugin-api.h"
55 #include "lto-streamer.h"
56 #include "data-streamer.h"
57 #include "tree-streamer.h"
59 #include "tree-pass.h"
62 #include "pass_manager.h"
63 #include "ipa-utils.h"
66 /* True when asm nodes has been output. */
67 bool asm_nodes_output
= false;
69 static void output_cgraph_opt_summary (void);
70 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
72 /* Number of LDPR values known to GCC. */
73 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
75 /* All node orders are ofsetted by ORDER_BASE. */
76 static int order_base
;
78 /* Cgraph streaming is organized as set of record whose type
79 is indicated by a tag. */
82 /* Must leave 0 for the stopper. */
84 /* Cgraph node without body available. */
85 LTO_symtab_unavail_node
= 1,
86 /* Cgraph node with function body. */
87 LTO_symtab_analyzed_node
,
90 LTO_symtab_indirect_edge
,
95 /* Create a new symtab encoder.
96 if FOR_INPUT, the encoder allocate only datastructures needed
97 to read the symtab. */
100 lto_symtab_encoder_new (bool for_input
)
102 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
105 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
106 encoder
->nodes
.create (0);
111 /* Delete ENCODER and its components. */
114 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
116 encoder
->nodes
.release ();
123 /* Return the existing reference number of NODE in the symtab encoder in
124 output block OB. Assign a new reference if this is the first time
128 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
135 lto_encoder_entry entry
= {node
, false, false, false};
137 ref
= encoder
->nodes
.length ();
138 encoder
->nodes
.safe_push (entry
);
142 size_t *slot
= encoder
->map
->get (node
);
145 lto_encoder_entry entry
= {node
, false, false, false};
146 ref
= encoder
->nodes
.length ();
148 encoder
->map
->put (node
, ref
+ 1);
149 encoder
->nodes
.safe_push (entry
);
157 /* Remove NODE from encoder. */
160 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
164 lto_encoder_entry last_node
;
166 size_t *slot
= encoder
->map
->get (node
);
167 if (slot
== NULL
|| !*slot
)
171 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
173 /* Remove from vector. We do this by swapping node with the last element
175 last_node
= encoder
->nodes
.pop ();
176 if (last_node
.node
!= node
)
178 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
180 /* Move the last element to the original spot of NODE. */
181 encoder
->nodes
[index
] = last_node
;
184 /* Remove element from hash table. */
185 encoder
->map
->remove (node
);
190 /* Return TRUE if we should encode initializer of NODE (if any). */
193 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
194 struct cgraph_node
*node
)
196 int index
= lto_symtab_encoder_lookup (encoder
, node
);
197 return encoder
->nodes
[index
].body
;
200 /* Return TRUE if we should encode body of NODE (if any). */
203 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
204 struct cgraph_node
*node
)
206 int index
= lto_symtab_encoder_encode (encoder
, node
);
207 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
208 encoder
->nodes
[index
].body
= true;
211 /* Return TRUE if we should encode initializer of NODE (if any). */
214 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
217 int index
= lto_symtab_encoder_lookup (encoder
, node
);
218 if (index
== LCC_NOT_FOUND
)
220 return encoder
->nodes
[index
].initializer
;
223 /* Return TRUE if we should encode initializer of NODE (if any). */
226 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
229 int index
= lto_symtab_encoder_lookup (encoder
, node
);
230 encoder
->nodes
[index
].initializer
= true;
233 /* Return TRUE if we should encode initializer of NODE (if any). */
236 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder
,
239 int index
= lto_symtab_encoder_lookup (encoder
, node
);
240 if (index
== LCC_NOT_FOUND
)
242 return encoder
->nodes
[index
].in_partition
;
245 /* Return TRUE if we should encode body of NODE (if any). */
248 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
251 int index
= lto_symtab_encoder_encode (encoder
, node
);
252 encoder
->nodes
[index
].in_partition
= true;
255 /* Output the cgraph EDGE to OB using ENCODER. */
258 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
259 lto_symtab_encoder_t encoder
)
265 if (edge
->indirect_unknown_callee
)
266 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
267 LTO_symtab_indirect_edge
);
269 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
272 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
273 gcc_assert (ref
!= LCC_NOT_FOUND
);
274 streamer_write_hwi_stream (ob
->main_stream
, ref
);
276 if (!edge
->indirect_unknown_callee
)
278 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
279 gcc_assert (ref
!= LCC_NOT_FOUND
);
280 streamer_write_hwi_stream (ob
->main_stream
, ref
);
283 streamer_write_gcov_count_stream (ob
->main_stream
, edge
->count
);
285 bp
= bitpack_create (ob
->main_stream
);
286 uid
= (!gimple_has_body_p (edge
->caller
->decl
)
287 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
) + 1);
288 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
289 CIF_N_REASONS
, edge
->inline_failed
);
290 bp_pack_var_len_unsigned (&bp
, uid
);
291 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
292 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
293 bp_pack_value (&bp
, edge
->speculative
, 1);
294 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
295 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
296 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
297 if (edge
->indirect_unknown_callee
)
299 int flags
= edge
->indirect_info
->ecf_flags
;
300 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
301 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
302 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
303 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
304 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
305 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
306 /* Flags that should not appear on indirect calls. */
307 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
313 streamer_write_bitpack (&bp
);
314 if (edge
->indirect_unknown_callee
)
316 streamer_write_hwi_stream (ob
->main_stream
,
317 edge
->indirect_info
->common_target_id
);
318 if (edge
->indirect_info
->common_target_id
)
319 streamer_write_hwi_stream
320 (ob
->main_stream
, edge
->indirect_info
->common_target_probability
);
324 /* Return if NODE contain references from other partitions. */
327 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
330 struct ipa_ref
*ref
= NULL
;
332 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
334 /* Ignore references from non-offloadable nodes while streaming NODE into
335 offload LTO section. */
336 if (!ref
->referring
->need_lto_streaming
)
339 if (ref
->referring
->in_other_partition
340 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
346 /* Return true when node is reachable from other partition. */
349 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
351 struct cgraph_edge
*e
;
352 if (!node
->definition
)
354 if (node
->global
.inlined_to
)
356 for (e
= node
->callers
; e
; e
= e
->next_caller
)
358 /* Ignore references from non-offloadable nodes while streaming NODE into
359 offload LTO section. */
360 if (!e
->caller
->need_lto_streaming
)
363 if (e
->caller
->in_other_partition
364 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
370 /* Return if NODE contain references from other partitions. */
373 referenced_from_this_partition_p (symtab_node
*node
,
374 lto_symtab_encoder_t encoder
)
377 struct ipa_ref
*ref
= NULL
;
379 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
380 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
385 /* Return true when node is reachable from other partition. */
388 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
390 struct cgraph_edge
*e
;
391 for (e
= node
->callers
; e
; e
= e
->next_caller
)
392 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
397 /* Output the cgraph NODE to OB. ENCODER is used to find the
398 reference number of NODE->inlined_to. SET is the set of nodes we
399 are writing to the current file. If NODE is not in SET, then NODE
400 is a boundary of a cgraph_node_set and we pretend NODE just has a
401 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
402 that have had their callgraph node written so far. This is used to
403 determine if NODE is a clone of a previously written node. */
406 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
407 lto_symtab_encoder_t encoder
)
413 bool in_other_partition
= false;
414 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
415 ipa_opt_pass_d
*pass
;
422 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
424 if (node
->analyzed
&& !boundary_p
)
425 tag
= LTO_symtab_analyzed_node
;
427 tag
= LTO_symtab_unavail_node
;
429 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
431 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
433 /* In WPA mode, we only output part of the call-graph. Also, we
434 fake cgraph node attributes. There are two cases that we care.
436 Boundary nodes: There are nodes that are not part of SET but are
437 called from within SET. We artificially make them look like
438 externally visible nodes with no function body.
440 Cherry-picked nodes: These are nodes we pulled from other
441 translation units into SET during IPA-inlining. We make them as
442 local static nodes to prevent clashes with other local statics. */
443 if (boundary_p
&& node
->analyzed
444 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
446 /* Inline clones can not be part of boundary.
447 gcc_assert (!node->global.inlined_to);
449 FIXME: At the moment they can be, when partition contains an inline
450 clone that is clone of inline clone from outside partition. We can
451 reshape the clone tree and make other tree to be the root, but it
452 needs a bit extra work and will be promplty done by cgraph_remove_node
453 after reading back. */
454 in_other_partition
= 1;
457 clone_of
= node
->clone_of
;
459 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
460 if (clone_of
->prev_sibling_clone
)
461 clone_of
= clone_of
->prev_sibling_clone
;
463 clone_of
= clone_of
->clone_of
;
465 /* See if body of the master function is output. If not, we are seeing only
466 an declaration and we do not need to pass down clone tree. */
467 ultimate_clone_of
= clone_of
;
468 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
469 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
471 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
474 if (tag
== LTO_symtab_analyzed_node
)
475 gcc_assert (clone_of
|| !node
->clone_of
);
477 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
479 streamer_write_hwi_stream (ob
->main_stream
, ref
);
482 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
483 streamer_write_gcov_count_stream (ob
->main_stream
, node
->count
);
484 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
486 streamer_write_hwi_stream (ob
->main_stream
,
487 node
->ipa_transforms_to_apply
.length ());
488 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
489 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
491 if (tag
== LTO_symtab_analyzed_node
)
493 if (node
->global
.inlined_to
)
495 ref
= lto_symtab_encoder_lookup (encoder
, node
->global
.inlined_to
);
496 gcc_assert (ref
!= LCC_NOT_FOUND
);
501 streamer_write_hwi_stream (ob
->main_stream
, ref
);
504 group
= node
->get_comdat_group ();
506 comdat
= IDENTIFIER_POINTER (group
);
509 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
513 if (node
->same_comdat_group
&& !boundary_p
)
515 ref
= lto_symtab_encoder_lookup (encoder
,
516 node
->same_comdat_group
);
517 gcc_assert (ref
!= LCC_NOT_FOUND
);
521 streamer_write_hwi_stream (ob
->main_stream
, ref
);
524 section
= node
->get_section ();
528 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
530 bp
= bitpack_create (ob
->main_stream
);
531 bp_pack_value (&bp
, node
->local
.local
, 1);
532 bp_pack_value (&bp
, node
->externally_visible
, 1);
533 bp_pack_value (&bp
, node
->no_reorder
, 1);
534 bp_pack_value (&bp
, node
->definition
, 1);
535 bp_pack_value (&bp
, node
->local
.versionable
, 1);
536 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
537 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
538 bp_pack_value (&bp
, node
->force_output
, 1);
539 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
540 bp_pack_value (&bp
, node
->unique_name
, 1);
541 bp_pack_value (&bp
, node
->body_removed
, 1);
542 bp_pack_value (&bp
, node
->implicit_section
, 1);
543 bp_pack_value (&bp
, node
->address_taken
, 1);
544 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
545 && node
->get_partitioning_class () == SYMBOL_PARTITION
546 && (reachable_from_other_partition_p (node
, encoder
)
547 || referenced_from_other_partition_p (node
, encoder
)), 1);
548 bp_pack_value (&bp
, node
->lowered
, 1);
549 bp_pack_value (&bp
, in_other_partition
, 1);
550 /* Real aliases in a boundary become non-aliases. However we still stream
551 alias info on weakrefs.
552 TODO: We lose a bit of information here - when we know that variable is
553 defined in other unit, we may use the info on aliases to resolve
554 symbol1 != symbol2 type tests that we can do only for locally defined objects
556 alias_p
= node
->alias
&& (!boundary_p
|| node
->weakref
);
557 bp_pack_value (&bp
, alias_p
, 1);
558 bp_pack_value (&bp
, node
->weakref
, 1);
559 bp_pack_value (&bp
, node
->frequency
, 2);
560 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
561 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
562 bp_pack_value (&bp
, node
->tm_clone
, 1);
563 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
564 bp_pack_value (&bp
, node
->icf_merged
, 1);
565 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
566 bp_pack_value (&bp
, node
->thunk
.thunk_p
&& !boundary_p
, 1);
567 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
568 LDPR_NUM_KNOWN
, node
->resolution
);
569 bp_pack_value (&bp
, node
->instrumentation_clone
, 1);
570 streamer_write_bitpack (&bp
);
571 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
573 if (node
->thunk
.thunk_p
&& !boundary_p
)
575 streamer_write_uhwi_stream
577 1 + (node
->thunk
.this_adjusting
!= 0) * 2
578 + (node
->thunk
.virtual_offset_p
!= 0) * 4
579 + (node
->thunk
.add_pointer_bounds_args
!= 0) * 8);
580 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
581 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
583 streamer_write_hwi_stream (ob
->main_stream
, node
->profile_id
);
584 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
585 streamer_write_hwi_stream (ob
->main_stream
, node
->get_init_priority ());
586 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
587 streamer_write_hwi_stream (ob
->main_stream
, node
->get_fini_priority ());
589 if (node
->instrumentation_clone
)
590 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->orig_decl
);
593 /* Output the varpool NODE to OB.
594 If NODE is not in SET, then NODE is a boundary. */
597 lto_output_varpool_node (struct lto_simple_output_block
*ob
, varpool_node
*node
,
598 lto_symtab_encoder_t encoder
)
600 bool boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
608 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
609 LTO_symtab_variable
);
610 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
611 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
612 bp
= bitpack_create (ob
->main_stream
);
613 bp_pack_value (&bp
, node
->externally_visible
, 1);
614 bp_pack_value (&bp
, node
->no_reorder
, 1);
615 bp_pack_value (&bp
, node
->force_output
, 1);
616 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
617 bp_pack_value (&bp
, node
->unique_name
, 1);
618 bp_pack_value (&bp
, node
->body_removed
, 1);
619 bp_pack_value (&bp
, node
->implicit_section
, 1);
620 bp_pack_value (&bp
, node
->writeonly
, 1);
621 bp_pack_value (&bp
, node
->definition
, 1);
622 alias_p
= node
->alias
&& (!boundary_p
|| node
->weakref
);
623 bp_pack_value (&bp
, alias_p
, 1);
624 bp_pack_value (&bp
, node
->weakref
, 1);
625 bp_pack_value (&bp
, node
->analyzed
&& !boundary_p
, 1);
626 gcc_assert (node
->definition
|| !node
->analyzed
);
627 /* Constant pool initializers can be de-unified into individual ltrans units.
628 FIXME: Alternatively at -Os we may want to avoid generating for them the local
629 labels and share them across LTRANS partitions. */
630 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
632 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
633 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
637 bp_pack_value (&bp
, node
->definition
638 && referenced_from_other_partition_p (node
, encoder
), 1);
639 bp_pack_value (&bp
, node
->analyzed
640 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
641 /* in_other_partition. */
643 bp_pack_value (&bp
, node
->tls_model
, 3);
644 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
645 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
646 streamer_write_bitpack (&bp
);
648 group
= node
->get_comdat_group ();
650 comdat
= IDENTIFIER_POINTER (group
);
653 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
657 if (node
->same_comdat_group
&& !boundary_p
)
659 ref
= lto_symtab_encoder_lookup (encoder
,
660 node
->same_comdat_group
);
661 gcc_assert (ref
!= LCC_NOT_FOUND
);
665 streamer_write_hwi_stream (ob
->main_stream
, ref
);
668 section
= node
->get_section ();
671 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
673 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
674 LDPR_NUM_KNOWN
, node
->resolution
);
677 /* Output the varpool NODE to OB.
678 If NODE is not in SET, then NODE is a boundary. */
681 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
682 lto_symtab_encoder_t encoder
)
686 int uid
= ref
->lto_stmt_uid
;
687 struct cgraph_node
*node
;
689 bp
= bitpack_create (ob
->main_stream
);
690 bp_pack_value (&bp
, ref
->use
, 3);
691 bp_pack_value (&bp
, ref
->speculative
, 1);
692 streamer_write_bitpack (&bp
);
693 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
694 gcc_assert (nref
!= LCC_NOT_FOUND
);
695 streamer_write_hwi_stream (ob
->main_stream
, nref
);
697 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
701 uid
= gimple_uid (ref
->stmt
) + 1;
702 streamer_write_hwi_stream (ob
->main_stream
, uid
);
706 /* Stream out profile_summary to OB. */
709 output_profile_summary (struct lto_simple_output_block
*ob
)
716 /* We do not output num and run_max, they are not used by
717 GCC profile feedback and they are difficult to merge from multiple
719 gcc_assert (profile_info
->runs
);
720 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
721 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
723 /* sum_all is needed for computing the working set with the
725 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
727 /* Create and output a bitpack of non-zero histogram entries indices. */
728 bp
= bitpack_create (ob
->main_stream
);
729 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
730 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
731 streamer_write_bitpack (&bp
);
732 /* Now stream out only those non-zero entries. */
733 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
735 if (!profile_info
->histogram
[h_ix
].num_counters
)
737 streamer_write_gcov_count_stream (ob
->main_stream
,
738 profile_info
->histogram
[h_ix
].num_counters
);
739 streamer_write_gcov_count_stream (ob
->main_stream
,
740 profile_info
->histogram
[h_ix
].min_value
);
741 streamer_write_gcov_count_stream (ob
->main_stream
,
742 profile_info
->histogram
[h_ix
].cum_value
);
744 /* IPA-profile computes hot bb threshold based on cumulated
745 whole program profile. We need to stream it down to ltrans. */
747 streamer_write_gcov_count_stream (ob
->main_stream
,
748 get_hot_bb_threshold ());
751 streamer_write_uhwi_stream (ob
->main_stream
, 0);
754 /* Output all callees or indirect outgoing edges. EDGE must be the first such
758 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
759 struct lto_simple_output_block
*ob
,
760 lto_symtab_encoder_t encoder
)
765 /* Output edges in backward direction, so the reconstructed callgraph match
766 and it is easy to associate call sites in the IPA pass summaries. */
767 while (edge
->next_callee
)
768 edge
= edge
->next_callee
;
769 for (; edge
; edge
= edge
->prev_callee
)
770 lto_output_edge (ob
, edge
, encoder
);
773 /* Output the part of the cgraph in SET. */
776 output_refs (lto_symtab_encoder_t encoder
)
778 lto_symtab_encoder_iterator lsei
;
779 struct lto_simple_output_block
*ob
;
784 ob
= lto_create_simple_output_block (LTO_section_refs
);
786 for (lsei
= lsei_start_in_partition (encoder
); !lsei_end_p (lsei
);
787 lsei_next_in_partition (&lsei
))
789 symtab_node
*node
= lsei_node (lsei
);
791 count
= node
->ref_list
.nreferences ();
794 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
795 streamer_write_uhwi_stream (ob
->main_stream
,
796 lto_symtab_encoder_lookup (encoder
, node
));
797 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
798 lto_output_ref (ob
, ref
, encoder
);
802 streamer_write_uhwi_stream (ob
->main_stream
, 0);
804 lto_destroy_simple_output_block (ob
);
807 /* Add NODE into encoder as well as nodes it is cloned from.
808 Do it in a way so clones appear first. */
811 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
815 add_node_to (encoder
, node
->clone_of
, include_body
);
816 else if (include_body
)
817 lto_set_symtab_encoder_encode_body (encoder
, node
);
818 lto_symtab_encoder_encode (encoder
, node
);
821 /* Add all references in NODE to encoders. */
824 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
827 struct ipa_ref
*ref
= NULL
;
828 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
829 if (is_a
<cgraph_node
*> (ref
->referred
))
830 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
832 lto_symtab_encoder_encode (encoder
, ref
->referred
);
835 /* Select what needs to be streamed out. In regular lto mode stream everything.
836 In offload lto mode stream only nodes marked as offloadable. */
838 select_what_to_stream (bool offload_lto_mode
)
840 struct symtab_node
*snode
;
841 FOR_EACH_SYMBOL (snode
)
842 snode
->need_lto_streaming
= !offload_lto_mode
|| snode
->offloadable
;
845 /* Find all symbols we want to stream into given partition and insert them
848 The function actually replaces IN_ENCODER by new one. The reason is that
849 streaming code needs clone's origin to be streamed before clone. This
850 means that we need to insert the nodes in specific order. This order is
851 ignored by the partitioning logic earlier. */
854 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
856 struct cgraph_edge
*edge
;
858 lto_symtab_encoder_t encoder
;
859 lto_symtab_encoder_iterator lsei
;
860 hash_set
<void *> reachable_call_targets
;
862 encoder
= lto_symtab_encoder_new (false);
864 /* Go over all entries in the IN_ENCODER and duplicate them to
865 ENCODER. At the same time insert masters of clones so
866 every master appears before clone. */
867 for (lsei
= lsei_start_function_in_partition (in_encoder
);
868 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
870 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
871 if (!node
->need_lto_streaming
)
873 add_node_to (encoder
, node
, true);
874 lto_set_symtab_encoder_in_partition (encoder
, node
);
875 create_references (encoder
, node
);
876 /* For proper debug info, we need to ship the origins, too. */
877 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
879 struct cgraph_node
*origin_node
880 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (node
->decl
));
881 origin_node
->used_as_abstract_origin
= true;
882 add_node_to (encoder
, origin_node
, true);
885 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
886 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
888 varpool_node
*vnode
= lsei_varpool_node (lsei
);
890 if (!vnode
->need_lto_streaming
)
892 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
893 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
894 create_references (encoder
, vnode
);
895 /* For proper debug info, we need to ship the origins, too. */
896 if (DECL_ABSTRACT_ORIGIN (vnode
->decl
))
898 varpool_node
*origin_node
899 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode
->decl
));
900 lto_set_symtab_encoder_in_partition (encoder
, origin_node
);
903 /* Pickle in also the initializer of all referenced readonly variables
904 to help folding. Constant pool variables are not shared, so we must
906 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
908 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
909 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
911 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
913 && (vnode
->ctor_useable_for_folding_p ()
914 || POINTER_BOUNDS_P (vnode
->decl
)))
916 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
917 create_references (encoder
, vnode
);
922 /* Go over all the nodes again to include callees that are not in
924 for (lsei
= lsei_start_function_in_partition (encoder
);
925 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
927 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
928 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
930 struct cgraph_node
*callee
= edge
->callee
;
931 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
933 /* We should have moved all the inlines. */
934 gcc_assert (!callee
->global
.inlined_to
);
935 add_node_to (encoder
, callee
, false);
938 /* Add all possible targets for late devirtualization. */
939 if (flag_devirtualize
)
940 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
941 if (edge
->indirect_info
->polymorphic
)
946 vec
<cgraph_node
*>targets
947 = possible_polymorphic_call_targets
948 (edge
, &final
, &cache_token
);
949 if (!reachable_call_targets
.add (cache_token
))
951 for (i
= 0; i
< targets
.length (); i
++)
953 struct cgraph_node
*callee
= targets
[i
];
955 /* Adding an external declarations into the unit serves
956 no purpose and just increases its boundary. */
957 if (callee
->definition
958 && !lto_symtab_encoder_in_partition_p
961 gcc_assert (!callee
->global
.inlined_to
);
962 add_node_to (encoder
, callee
, false);
968 lto_symtab_encoder_delete (in_encoder
);
972 /* Output the part of the symtab in SET and VSET. */
977 struct cgraph_node
*node
;
978 struct lto_simple_output_block
*ob
;
979 lto_symtab_encoder_iterator lsei
;
981 lto_symtab_encoder_t encoder
;
984 output_cgraph_opt_summary ();
986 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
988 output_profile_summary (ob
);
990 /* An encoder for cgraph nodes should have been created by
991 ipa_write_summaries_1. */
992 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
993 encoder
= ob
->decl_state
->symtab_node_encoder
;
995 /* Write out the nodes. We must first output a node and then its clones,
996 otherwise at a time reading back the node there would be nothing to clone
998 n_nodes
= lto_symtab_encoder_size (encoder
);
999 for (i
= 0; i
< n_nodes
; i
++)
1001 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1002 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1003 lto_output_node (ob
, cnode
, encoder
);
1005 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1008 /* Go over the nodes in SET again to write edges. */
1009 for (lsei
= lsei_start_function_in_partition (encoder
); !lsei_end_p (lsei
);
1010 lsei_next_function_in_partition (&lsei
))
1012 node
= lsei_cgraph_node (lsei
);
1013 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1014 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1017 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1019 lto_destroy_simple_output_block (ob
);
1021 /* Emit toplevel asms.
1022 When doing WPA we must output every asm just once. Since we do not partition asm
1023 nodes at all, output them to first output. This is kind of hack, but should work
1025 if (!asm_nodes_output
)
1027 asm_nodes_output
= true;
1028 lto_output_toplevel_asms ();
1031 output_refs (encoder
);
1034 /* Return identifier encoded in IB as a plain string. */
1037 read_identifier (struct lto_input_block
*ib
)
1039 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1042 if (ib
->data
[ib
->p
+ len
])
1043 lto_section_overrun (ib
);
1049 id
= get_identifier (ib
->data
+ ib
->p
);
1054 /* Return string encoded in IB, NULL if string is empty. */
1057 read_string (struct lto_input_block
*ib
)
1059 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1062 if (ib
->data
[ib
->p
+ len
])
1063 lto_section_overrun (ib
);
1069 str
= ib
->data
+ ib
->p
;
1074 /* Output function/variable tables that will allow libgomp to look up offload
1076 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1077 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1078 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1081 output_offload_tables (void)
1083 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1086 struct lto_simple_output_block
*ob
1087 = lto_create_simple_output_block (LTO_section_offload_table
);
1089 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1091 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1092 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1093 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1094 (*offload_funcs
)[i
]);
1097 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1099 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1100 LTO_symtab_last_tag
, LTO_symtab_variable
);
1101 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1102 (*offload_vars
)[i
]);
1105 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1106 lto_destroy_simple_output_block (ob
);
1108 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1109 streamed to one partition only. That's why we free offload_funcs and
1110 offload_vars after the first call of output_offload_tables. */
1113 vec_free (offload_funcs
);
1114 vec_free (offload_vars
);
1118 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1119 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1120 NODE or to replace the values in it, for instance because the first
1121 time we saw it, the function body was not available but now it
1122 is. BP is a bitpack with all the bitflags for NODE read from the
1126 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1127 struct cgraph_node
*node
,
1128 enum LTO_symtab_tags tag
,
1129 struct bitpack_d
*bp
)
1131 node
->aux
= (void *) tag
;
1132 node
->lto_file_data
= file_data
;
1134 node
->local
.local
= bp_unpack_value (bp
, 1);
1135 node
->externally_visible
= bp_unpack_value (bp
, 1);
1136 node
->no_reorder
= bp_unpack_value (bp
, 1);
1137 node
->definition
= bp_unpack_value (bp
, 1);
1138 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1139 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1140 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1141 node
->force_output
= bp_unpack_value (bp
, 1);
1142 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1143 node
->unique_name
= bp_unpack_value (bp
, 1);
1144 node
->body_removed
= bp_unpack_value (bp
, 1);
1145 node
->implicit_section
= bp_unpack_value (bp
, 1);
1146 node
->address_taken
= bp_unpack_value (bp
, 1);
1147 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1148 node
->lowered
= bp_unpack_value (bp
, 1);
1149 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1150 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1151 if (node
->in_other_partition
1152 /* Avoid updating decl when we are seeing just inline clone.
1153 When inlining function that has functions already inlined into it,
1154 we produce clones of inline clones.
1156 WPA partitioning might put each clone into different unit and
1157 we might end up streaming inline clone from other partition
1158 to support clone we are interested in. */
1160 || node
->clone_of
->decl
!= node
->decl
))
1162 DECL_EXTERNAL (node
->decl
) = 1;
1163 TREE_STATIC (node
->decl
) = 0;
1165 node
->alias
= bp_unpack_value (bp
, 1);
1166 node
->weakref
= bp_unpack_value (bp
, 1);
1167 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1168 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1169 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1170 node
->tm_clone
= bp_unpack_value (bp
, 1);
1171 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1172 node
->icf_merged
= bp_unpack_value (bp
, 1);
1173 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1174 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1175 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1177 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1178 gcc_assert (flag_ltrans
1179 || (!node
->in_other_partition
1180 && !node
->used_from_other_partition
));
1183 /* Return string alias is alias of. */
1186 get_alias_symbol (tree decl
)
1188 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1189 return get_identifier (TREE_STRING_POINTER
1190 (TREE_VALUE (TREE_VALUE (alias
))));
1193 /* Read a node from input_block IB. TAG is the node's tag just read.
1194 Return the node read or overwriten. */
1196 static struct cgraph_node
*
1197 input_node (struct lto_file_decl_data
*file_data
,
1198 struct lto_input_block
*ib
,
1199 enum LTO_symtab_tags tag
,
1200 vec
<symtab_node
*> nodes
)
1202 gcc::pass_manager
*passes
= g
->get_passes ();
1204 struct cgraph_node
*node
;
1205 struct bitpack_d bp
;
1206 unsigned decl_index
;
1207 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1212 const char *section
;
1213 order
= streamer_read_hwi (ib
) + order_base
;
1214 clone_ref
= streamer_read_hwi (ib
);
1216 decl_index
= streamer_read_uhwi (ib
);
1217 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1219 if (clone_ref
!= LCC_NOT_FOUND
)
1221 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1222 0, CGRAPH_FREQ_BASE
, false,
1223 vNULL
, false, NULL
, NULL
);
1227 /* Declaration of functions can be already merged with a declaration
1228 from other input file. We keep cgraph unmerged until after streaming
1229 of ipa passes is done. Alays forcingly create a fresh node. */
1230 node
= symtab
->create_empty ();
1231 node
->decl
= fn_decl
;
1232 node
->register_symbol ();
1235 node
->order
= order
;
1236 if (order
>= symtab
->order
)
1237 symtab
->order
= order
+ 1;
1239 node
->count
= streamer_read_gcov_count (ib
);
1240 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1242 count
= streamer_read_hwi (ib
);
1243 node
->ipa_transforms_to_apply
= vNULL
;
1244 for (i
= 0; i
< count
; i
++)
1247 int pid
= streamer_read_hwi (ib
);
1249 gcc_assert (pid
< passes
->passes_by_id_size
);
1250 pass
= passes
->passes_by_id
[pid
];
1251 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1254 if (tag
== LTO_symtab_analyzed_node
)
1255 ref
= streamer_read_hwi (ib
);
1257 group
= read_identifier (ib
);
1259 ref2
= streamer_read_hwi (ib
);
1261 /* Make sure that we have not read this node before. Nodes that
1262 have already been read will have their tag stored in the 'aux'
1263 field. Since built-in functions can be referenced in multiple
1264 functions, they are expected to be read more than once. */
1265 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1266 internal_error ("bytecode stream: found multiple instances of cgraph "
1267 "node with uid %d", node
->uid
);
1269 node
->tp_first_run
= streamer_read_uhwi (ib
);
1271 bp
= streamer_read_bitpack (ib
);
1273 input_overwrite_node (file_data
, node
, tag
, &bp
);
1275 /* Store a reference for now, and fix up later to be a pointer. */
1276 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1280 node
->set_comdat_group (group
);
1281 /* Store a reference for now, and fix up later to be a pointer. */
1282 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1285 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1286 section
= read_string (ib
);
1288 node
->set_section_for_node (section
);
1290 if (node
->thunk
.thunk_p
)
1292 int type
= streamer_read_uhwi (ib
);
1293 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1294 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1296 node
->thunk
.fixed_offset
= fixed_offset
;
1297 node
->thunk
.this_adjusting
= (type
& 2);
1298 node
->thunk
.virtual_value
= virtual_value
;
1299 node
->thunk
.virtual_offset_p
= (type
& 4);
1300 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1302 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1303 node
->alias_target
= get_alias_symbol (node
->decl
);
1304 node
->profile_id
= streamer_read_hwi (ib
);
1305 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1306 node
->set_init_priority (streamer_read_hwi (ib
));
1307 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1308 node
->set_fini_priority (streamer_read_hwi (ib
));
1310 if (node
->instrumentation_clone
)
1312 decl_index
= streamer_read_uhwi (ib
);
1313 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1314 node
->orig_decl
= fn_decl
;
1320 /* Read a node from input_block IB. TAG is the node's tag just read.
1321 Return the node read or overwriten. */
1323 static varpool_node
*
1324 input_varpool_node (struct lto_file_decl_data
*file_data
,
1325 struct lto_input_block
*ib
)
1330 struct bitpack_d bp
;
1331 int ref
= LCC_NOT_FOUND
;
1334 const char *section
;
1336 order
= streamer_read_hwi (ib
) + order_base
;
1337 decl_index
= streamer_read_uhwi (ib
);
1338 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1340 /* Declaration of functions can be already merged with a declaration
1341 from other input file. We keep cgraph unmerged until after streaming
1342 of ipa passes is done. Alays forcingly create a fresh node. */
1343 node
= varpool_node::create_empty ();
1344 node
->decl
= var_decl
;
1345 node
->register_symbol ();
1347 node
->order
= order
;
1348 if (order
>= symtab
->order
)
1349 symtab
->order
= order
+ 1;
1350 node
->lto_file_data
= file_data
;
1352 bp
= streamer_read_bitpack (ib
);
1353 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1354 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1355 node
->force_output
= bp_unpack_value (&bp
, 1);
1356 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1357 node
->unique_name
= bp_unpack_value (&bp
, 1);
1358 node
->body_removed
= bp_unpack_value (&bp
, 1);
1359 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1360 node
->writeonly
= bp_unpack_value (&bp
, 1);
1361 node
->definition
= bp_unpack_value (&bp
, 1);
1362 node
->alias
= bp_unpack_value (&bp
, 1);
1363 node
->weakref
= bp_unpack_value (&bp
, 1);
1364 node
->analyzed
= bp_unpack_value (&bp
, 1);
1365 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1366 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1367 if (node
->in_other_partition
)
1369 DECL_EXTERNAL (node
->decl
) = 1;
1370 TREE_STATIC (node
->decl
) = 0;
1372 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1373 node
->alias_target
= get_alias_symbol (node
->decl
);
1374 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1375 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1376 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1377 group
= read_identifier (ib
);
1380 node
->set_comdat_group (group
);
1381 ref
= streamer_read_hwi (ib
);
1382 /* Store a reference for now, and fix up later to be a pointer. */
1383 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1386 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1387 section
= read_string (ib
);
1389 node
->set_section_for_node (section
);
1390 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1392 gcc_assert (flag_ltrans
1393 || (!node
->in_other_partition
1394 && !node
->used_from_other_partition
));
1399 /* Read a node from input_block IB. TAG is the node's tag just read.
1400 Return the node read or overwriten. */
1403 input_ref (struct lto_input_block
*ib
,
1404 symtab_node
*referring_node
,
1405 vec
<symtab_node
*> nodes
)
1407 symtab_node
*node
= NULL
;
1408 struct bitpack_d bp
;
1409 enum ipa_ref_use use
;
1411 struct ipa_ref
*ref
;
1413 bp
= streamer_read_bitpack (ib
);
1414 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1415 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1416 node
= nodes
[streamer_read_hwi (ib
)];
1417 ref
= referring_node
->create_reference (node
, use
);
1418 ref
->speculative
= speculative
;
1419 if (is_a
<cgraph_node
*> (referring_node
))
1420 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1423 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1424 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1425 edge being read is indirect (in the sense that it has
1426 indirect_unknown_callee set). */
1429 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1432 struct cgraph_node
*caller
, *callee
;
1433 struct cgraph_edge
*edge
;
1434 unsigned int stmt_id
;
1437 cgraph_inline_failed_t inline_failed
;
1438 struct bitpack_d bp
;
1441 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1442 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1443 internal_error ("bytecode stream: no caller found while reading edge");
1447 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1448 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1449 internal_error ("bytecode stream: no callee found while reading edge");
1454 count
= streamer_read_gcov_count (ib
);
1456 bp
= streamer_read_bitpack (ib
);
1457 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1458 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1459 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1462 edge
= caller
->create_indirect_edge (NULL
, 0, count
, freq
);
1464 edge
= caller
->create_edge (callee
, NULL
, count
, freq
);
1466 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1467 edge
->speculative
= bp_unpack_value (&bp
, 1);
1468 edge
->lto_stmt_uid
= stmt_id
;
1469 edge
->inline_failed
= inline_failed
;
1470 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1471 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1472 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1475 if (bp_unpack_value (&bp
, 1))
1476 ecf_flags
|= ECF_CONST
;
1477 if (bp_unpack_value (&bp
, 1))
1478 ecf_flags
|= ECF_PURE
;
1479 if (bp_unpack_value (&bp
, 1))
1480 ecf_flags
|= ECF_NORETURN
;
1481 if (bp_unpack_value (&bp
, 1))
1482 ecf_flags
|= ECF_MALLOC
;
1483 if (bp_unpack_value (&bp
, 1))
1484 ecf_flags
|= ECF_NOTHROW
;
1485 if (bp_unpack_value (&bp
, 1))
1486 ecf_flags
|= ECF_RETURNS_TWICE
;
1487 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1488 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1489 if (edge
->indirect_info
->common_target_id
)
1490 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1495 /* Read a cgraph from IB using the info in FILE_DATA. */
1497 static vec
<symtab_node
*>
1498 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1499 struct lto_input_block
*ib
)
1501 enum LTO_symtab_tags tag
;
1502 vec
<symtab_node
*> nodes
= vNULL
;
1506 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1507 order_base
= symtab
->order
;
1510 if (tag
== LTO_symtab_edge
)
1511 input_edge (ib
, nodes
, false);
1512 else if (tag
== LTO_symtab_indirect_edge
)
1513 input_edge (ib
, nodes
, true);
1514 else if (tag
== LTO_symtab_variable
)
1516 node
= input_varpool_node (file_data
, ib
);
1517 nodes
.safe_push (node
);
1518 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1522 node
= input_node (file_data
, ib
, tag
, nodes
);
1523 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1524 internal_error ("bytecode stream: found empty cgraph node");
1525 nodes
.safe_push (node
);
1526 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1529 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1532 lto_input_toplevel_asms (file_data
, order_base
);
1534 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1535 #ifdef ENABLE_CHECKING
1536 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1537 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1539 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1542 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1544 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1546 /* We share declaration of builtins, so we may read same node twice. */
1551 /* Fixup inlined_to from reference to pointer. */
1552 if (ref
!= LCC_NOT_FOUND
)
1553 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1554 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1556 cnode
->global
.inlined_to
= NULL
;
1558 /* Compute instrumented_version. */
1559 if (cnode
->instrumentation_clone
)
1561 gcc_assert (cnode
->orig_decl
);
1563 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1564 if (cnode
->instrumented_version
)
1565 cnode
->instrumented_version
->instrumented_version
= cnode
;
1567 /* Restore decl names reference. */
1568 if (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (cnode
->decl
))
1569 && !TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode
->decl
)))
1570 TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode
->decl
))
1571 = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1575 ref
= (int) (intptr_t) node
->same_comdat_group
;
1577 /* Fixup same_comdat_group from reference to pointer. */
1578 if (ref
!= LCC_NOT_FOUND
)
1579 node
->same_comdat_group
= nodes
[ref
];
1581 node
->same_comdat_group
= NULL
;
1583 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1584 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1588 /* Input ipa_refs. */
1591 input_refs (struct lto_input_block
*ib
,
1592 vec
<symtab_node
*> nodes
)
1599 count
= streamer_read_uhwi (ib
);
1602 idx
= streamer_read_uhwi (ib
);
1606 input_ref (ib
, node
, nodes
);
1613 static struct gcov_ctr_summary lto_gcov_summary
;
1615 /* Input profile_info from IB. */
1617 input_profile_summary (struct lto_input_block
*ib
,
1618 struct lto_file_decl_data
*file_data
)
1621 struct bitpack_d bp
;
1622 unsigned int runs
= streamer_read_uhwi (ib
);
1625 file_data
->profile_info
.runs
= runs
;
1626 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1627 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1629 memset (file_data
->profile_info
.histogram
, 0,
1630 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1631 /* Input the bitpack of non-zero histogram indices. */
1632 bp
= streamer_read_bitpack (ib
);
1633 /* Read in and unpack the full bitpack, flagging non-zero
1634 histogram entries by setting the num_counters non-zero. */
1635 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1637 file_data
->profile_info
.histogram
[h_ix
].num_counters
1638 = bp_unpack_value (&bp
, 1);
1640 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1642 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1645 file_data
->profile_info
.histogram
[h_ix
].num_counters
1646 = streamer_read_gcov_count (ib
);
1647 file_data
->profile_info
.histogram
[h_ix
].min_value
1648 = streamer_read_gcov_count (ib
);
1649 file_data
->profile_info
.histogram
[h_ix
].cum_value
1650 = streamer_read_gcov_count (ib
);
1652 /* IPA-profile computes hot bb threshold based on cumulated
1653 whole program profile. We need to stream it down to ltrans. */
1655 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1660 /* Rescale profile summaries to the same number of runs in the whole unit. */
1663 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1665 struct lto_file_decl_data
*file_data
;
1666 unsigned int j
, h_ix
;
1667 gcov_unsigned_t max_runs
= 0;
1668 struct cgraph_node
*node
;
1669 struct cgraph_edge
*edge
;
1670 gcov_type saved_sum_all
= 0;
1671 gcov_ctr_summary
*saved_profile_info
= 0;
1672 int saved_scale
= 0;
1674 /* Find unit with maximal number of runs. If we ever get serious about
1675 roundoff errors, we might also consider computing smallest common
1677 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1678 if (max_runs
< file_data
->profile_info
.runs
)
1679 max_runs
= file_data
->profile_info
.runs
;
1684 /* Simple overflow check. We probably don't need to support that many train
1685 runs. Such a large value probably imply data corruption anyway. */
1686 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1688 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1689 INT_MAX
/ REG_BR_PROB_BASE
);
1693 profile_info
= <o_gcov_summary
;
1694 lto_gcov_summary
.runs
= max_runs
;
1695 lto_gcov_summary
.sum_max
= 0;
1696 memset (lto_gcov_summary
.histogram
, 0,
1697 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1699 /* Rescale all units to the maximal number of runs.
1700 sum_max can not be easily merged, as we have no idea what files come from
1701 the same run. We do not use the info anyway, so leave it 0. */
1702 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1703 if (file_data
->profile_info
.runs
)
1705 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1706 file_data
->profile_info
.runs
);
1707 lto_gcov_summary
.sum_max
1708 = MAX (lto_gcov_summary
.sum_max
,
1709 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1710 lto_gcov_summary
.sum_all
1711 = MAX (lto_gcov_summary
.sum_all
,
1712 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1713 /* Save a pointer to the profile_info with the largest
1714 scaled sum_all and the scale for use in merging the
1716 if (!saved_profile_info
1717 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1719 saved_profile_info
= &file_data
->profile_info
;
1720 saved_sum_all
= lto_gcov_summary
.sum_all
;
1721 saved_scale
= scale
;
1725 gcc_assert (saved_profile_info
);
1727 /* Scale up the histogram from the profile that had the largest
1728 scaled sum_all above. */
1729 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1731 /* Scale up the min value as we did the corresponding sum_all
1732 above. Use that to find the new histogram index. */
1733 gcov_type scaled_min
1734 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1736 /* The new index may be shared with another scaled histogram entry,
1737 so we need to account for a non-zero histogram entry at new_ix. */
1738 unsigned new_ix
= gcov_histo_index (scaled_min
);
1739 lto_gcov_summary
.histogram
[new_ix
].min_value
1740 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1741 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1743 /* Some of the scaled counter values would ostensibly need to be placed
1744 into different (larger) histogram buckets, but we keep things simple
1745 here and place the scaled cumulative counter value in the bucket
1746 corresponding to the scaled minimum counter value. */
1747 lto_gcov_summary
.histogram
[new_ix
].cum_value
1748 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1750 lto_gcov_summary
.histogram
[new_ix
].num_counters
1751 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1754 /* Watch roundoff errors. */
1755 if (lto_gcov_summary
.sum_max
< max_runs
)
1756 lto_gcov_summary
.sum_max
= max_runs
;
1758 /* If merging already happent at WPA time, we are done. */
1762 /* Now compute count_materialization_scale of each node.
1763 During LTRANS we already have values of count_materialization_scale
1764 computed, so just update them. */
1765 FOR_EACH_FUNCTION (node
)
1766 if (node
->lto_file_data
1767 && node
->lto_file_data
->profile_info
.runs
)
1771 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1772 node
->lto_file_data
->profile_info
.runs
);
1773 node
->count_materialization_scale
= scale
;
1775 fatal_error ("Profile information in %s corrupted",
1776 file_data
->file_name
);
1778 if (scale
== REG_BR_PROB_BASE
)
1780 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1781 edge
->count
= apply_scale (edge
->count
, scale
);
1782 node
->count
= apply_scale (node
->count
, scale
);
1786 /* Input and merge the symtab from each of the .o files passed to
1792 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1793 struct lto_file_decl_data
*file_data
;
1795 struct cgraph_node
*node
;
1797 while ((file_data
= file_data_vec
[j
++]))
1801 struct lto_input_block
*ib
;
1802 vec
<symtab_node
*> nodes
;
1804 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1807 fatal_error ("cannot find LTO cgraph in %s", file_data
->file_name
);
1808 input_profile_summary (ib
, file_data
);
1809 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1810 nodes
= input_cgraph_1 (file_data
, ib
);
1811 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1814 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1817 fatal_error ("cannot find LTO section refs in %s",
1818 file_data
->file_name
);
1819 input_refs (ib
, nodes
);
1820 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1823 input_cgraph_opt_summary (nodes
);
1827 merge_profile_summaries (file_data_vec
);
1828 get_working_sets ();
1831 /* Clear out the aux field that was used to store enough state to
1832 tell which nodes should be overwritten. */
1833 FOR_EACH_FUNCTION (node
)
1835 /* Some nodes may have been created by cgraph_node. This
1836 happens when the callgraph contains nested functions. If the
1837 node for the parent function was never emitted to the gimple
1838 file, cgraph_node will create a node for it when setting the
1839 context of the nested function. */
1840 if (node
->lto_file_data
)
1845 /* Input function/variable tables that will allow libgomp to look up offload
1846 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1849 input_offload_tables (void)
1851 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1852 struct lto_file_decl_data
*file_data
;
1855 while ((file_data
= file_data_vec
[j
++]))
1859 struct lto_input_block
*ib
1860 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1865 enum LTO_symtab_tags tag
1866 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1869 if (tag
== LTO_symtab_unavail_node
)
1871 int decl_index
= streamer_read_uhwi (ib
);
1873 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1874 vec_safe_push (offload_funcs
, fn_decl
);
1876 else if (tag
== LTO_symtab_variable
)
1878 int decl_index
= streamer_read_uhwi (ib
);
1880 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1881 vec_safe_push (offload_vars
, var_decl
);
1884 fatal_error ("invalid offload table in %s", file_data
->file_name
);
1886 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1889 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1894 /* True when we need optimization summary for NODE. */
1897 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1899 return (node
->clone_of
1900 && (node
->clone
.tree_map
1901 || node
->clone
.args_to_skip
1902 || node
->clone
.combined_args_to_skip
));
1905 /* Output optimization summary for EDGE to OB. */
1907 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1908 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1912 /* Output optimization summary for NODE to OB. */
1915 output_node_opt_summary (struct output_block
*ob
,
1916 struct cgraph_node
*node
,
1917 lto_symtab_encoder_t encoder
)
1921 struct ipa_replace_map
*map
;
1922 struct bitpack_d bp
;
1924 struct cgraph_edge
*e
;
1926 if (node
->clone
.args_to_skip
)
1928 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1929 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1930 streamer_write_uhwi (ob
, index
);
1933 streamer_write_uhwi (ob
, 0);
1934 if (node
->clone
.combined_args_to_skip
)
1936 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1937 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
1938 streamer_write_uhwi (ob
, index
);
1941 streamer_write_uhwi (ob
, 0);
1942 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
1943 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
1945 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1946 mechanism to store function local declarations into summaries. */
1947 gcc_assert (!map
->old_tree
);
1948 streamer_write_uhwi (ob
, map
->parm_num
);
1949 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
1950 stream_write_tree (ob
, map
->new_tree
, true);
1951 bp
= bitpack_create (ob
->main_stream
);
1952 bp_pack_value (&bp
, map
->replace_p
, 1);
1953 bp_pack_value (&bp
, map
->ref_p
, 1);
1954 streamer_write_bitpack (&bp
);
1957 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
1959 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1960 output_edge_opt_summary (ob
, e
);
1961 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
1962 output_edge_opt_summary (ob
, e
);
1966 /* Output optimization summaries stored in callgraph.
1967 At the moment it is the clone info structure. */
1970 output_cgraph_opt_summary (void)
1973 lto_symtab_encoder_t encoder
;
1974 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
1978 encoder
= ob
->decl_state
->symtab_node_encoder
;
1979 n_nodes
= lto_symtab_encoder_size (encoder
);
1980 for (i
= 0; i
< n_nodes
; i
++)
1982 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1983 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1984 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
1987 streamer_write_uhwi (ob
, count
);
1988 for (i
= 0; i
< n_nodes
; i
++)
1990 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1991 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1992 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
1994 streamer_write_uhwi (ob
, i
);
1995 output_node_opt_summary (ob
, cnode
, encoder
);
1998 produce_asm (ob
, NULL
);
1999 destroy_output_block (ob
);
2002 /* Input optimisation summary of EDGE. */
2005 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2006 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2010 /* Input optimisation summary of NODE. */
2013 input_node_opt_summary (struct cgraph_node
*node
,
2014 struct lto_input_block
*ib_main
,
2015 struct data_in
*data_in
)
2020 struct bitpack_d bp
;
2021 struct cgraph_edge
*e
;
2023 count
= streamer_read_uhwi (ib_main
);
2025 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2026 for (i
= 0; i
< count
; i
++)
2028 bit
= streamer_read_uhwi (ib_main
);
2029 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2031 count
= streamer_read_uhwi (ib_main
);
2033 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2034 for (i
= 0; i
< count
; i
++)
2036 bit
= streamer_read_uhwi (ib_main
);
2037 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2039 count
= streamer_read_uhwi (ib_main
);
2040 for (i
= 0; i
< count
; i
++)
2042 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2044 vec_safe_push (node
->clone
.tree_map
, map
);
2045 map
->parm_num
= streamer_read_uhwi (ib_main
);
2046 map
->old_tree
= NULL
;
2047 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2048 bp
= streamer_read_bitpack (ib_main
);
2049 map
->replace_p
= bp_unpack_value (&bp
, 1);
2050 map
->ref_p
= bp_unpack_value (&bp
, 1);
2052 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2053 input_edge_opt_summary (e
, ib_main
);
2054 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2055 input_edge_opt_summary (e
, ib_main
);
2058 /* Read section in file FILE_DATA of length LEN with data DATA. */
2061 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2062 const char *data
, size_t len
,
2063 vec
<symtab_node
*> nodes
)
2065 const struct lto_function_header
*header
=
2066 (const struct lto_function_header
*) data
;
2067 const int cfg_offset
= sizeof (struct lto_function_header
);
2068 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2069 const int string_offset
= main_offset
+ header
->main_size
;
2070 struct data_in
*data_in
;
2074 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2078 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2079 header
->string_size
, vNULL
);
2080 count
= streamer_read_uhwi (&ib_main
);
2082 for (i
= 0; i
< count
; i
++)
2084 int ref
= streamer_read_uhwi (&ib_main
);
2085 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2088 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2090 lto_data_in_delete (data_in
);
2093 /* Input optimization summary of cgraph. */
2096 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2098 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2099 struct lto_file_decl_data
*file_data
;
2102 while ((file_data
= file_data_vec
[j
++]))
2106 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2110 input_cgraph_opt_section (file_data
, data
, len
, nodes
);