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
619 || !lto_symtab_encoder_encode_initializer_p (encoder
, node
), 1);
620 bp_pack_value (&bp
, node
->implicit_section
, 1);
621 bp_pack_value (&bp
, node
->writeonly
, 1);
622 bp_pack_value (&bp
, node
->definition
, 1);
623 alias_p
= node
->alias
&& (!boundary_p
|| node
->weakref
);
624 bp_pack_value (&bp
, alias_p
, 1);
625 bp_pack_value (&bp
, node
->weakref
, 1);
626 bp_pack_value (&bp
, node
->analyzed
&& !boundary_p
, 1);
627 gcc_assert (node
->definition
|| !node
->analyzed
);
628 /* Constant pool initializers can be de-unified into individual ltrans units.
629 FIXME: Alternatively at -Os we may want to avoid generating for them the local
630 labels and share them across LTRANS partitions. */
631 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
633 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
634 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
638 bp_pack_value (&bp
, node
->definition
639 && referenced_from_other_partition_p (node
, encoder
), 1);
640 bp_pack_value (&bp
, node
->analyzed
641 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
642 /* in_other_partition. */
644 bp_pack_value (&bp
, node
->tls_model
, 3);
645 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
646 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
647 streamer_write_bitpack (&bp
);
649 group
= node
->get_comdat_group ();
651 comdat
= IDENTIFIER_POINTER (group
);
654 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
658 if (node
->same_comdat_group
&& !boundary_p
)
660 ref
= lto_symtab_encoder_lookup (encoder
,
661 node
->same_comdat_group
);
662 gcc_assert (ref
!= LCC_NOT_FOUND
);
666 streamer_write_hwi_stream (ob
->main_stream
, ref
);
669 section
= node
->get_section ();
672 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
674 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
675 LDPR_NUM_KNOWN
, node
->resolution
);
678 /* Output the varpool NODE to OB.
679 If NODE is not in SET, then NODE is a boundary. */
682 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
683 lto_symtab_encoder_t encoder
)
687 int uid
= ref
->lto_stmt_uid
;
688 struct cgraph_node
*node
;
690 bp
= bitpack_create (ob
->main_stream
);
691 bp_pack_value (&bp
, ref
->use
, 3);
692 bp_pack_value (&bp
, ref
->speculative
, 1);
693 streamer_write_bitpack (&bp
);
694 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
695 gcc_assert (nref
!= LCC_NOT_FOUND
);
696 streamer_write_hwi_stream (ob
->main_stream
, nref
);
698 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
702 uid
= gimple_uid (ref
->stmt
) + 1;
703 streamer_write_hwi_stream (ob
->main_stream
, uid
);
707 /* Stream out profile_summary to OB. */
710 output_profile_summary (struct lto_simple_output_block
*ob
)
717 /* We do not output num and run_max, they are not used by
718 GCC profile feedback and they are difficult to merge from multiple
720 gcc_assert (profile_info
->runs
);
721 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
722 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
724 /* sum_all is needed for computing the working set with the
726 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
728 /* Create and output a bitpack of non-zero histogram entries indices. */
729 bp
= bitpack_create (ob
->main_stream
);
730 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
731 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
732 streamer_write_bitpack (&bp
);
733 /* Now stream out only those non-zero entries. */
734 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
736 if (!profile_info
->histogram
[h_ix
].num_counters
)
738 streamer_write_gcov_count_stream (ob
->main_stream
,
739 profile_info
->histogram
[h_ix
].num_counters
);
740 streamer_write_gcov_count_stream (ob
->main_stream
,
741 profile_info
->histogram
[h_ix
].min_value
);
742 streamer_write_gcov_count_stream (ob
->main_stream
,
743 profile_info
->histogram
[h_ix
].cum_value
);
745 /* IPA-profile computes hot bb threshold based on cumulated
746 whole program profile. We need to stream it down to ltrans. */
748 streamer_write_gcov_count_stream (ob
->main_stream
,
749 get_hot_bb_threshold ());
752 streamer_write_uhwi_stream (ob
->main_stream
, 0);
755 /* Output all callees or indirect outgoing edges. EDGE must be the first such
759 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
760 struct lto_simple_output_block
*ob
,
761 lto_symtab_encoder_t encoder
)
766 /* Output edges in backward direction, so the reconstructed callgraph match
767 and it is easy to associate call sites in the IPA pass summaries. */
768 while (edge
->next_callee
)
769 edge
= edge
->next_callee
;
770 for (; edge
; edge
= edge
->prev_callee
)
771 lto_output_edge (ob
, edge
, encoder
);
774 /* Output the part of the cgraph in SET. */
777 output_refs (lto_symtab_encoder_t encoder
)
779 lto_symtab_encoder_iterator lsei
;
780 struct lto_simple_output_block
*ob
;
785 ob
= lto_create_simple_output_block (LTO_section_refs
);
787 for (lsei
= lsei_start_in_partition (encoder
); !lsei_end_p (lsei
);
788 lsei_next_in_partition (&lsei
))
790 symtab_node
*node
= lsei_node (lsei
);
792 count
= node
->ref_list
.nreferences ();
795 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
796 streamer_write_uhwi_stream (ob
->main_stream
,
797 lto_symtab_encoder_lookup (encoder
, node
));
798 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
799 lto_output_ref (ob
, ref
, encoder
);
803 streamer_write_uhwi_stream (ob
->main_stream
, 0);
805 lto_destroy_simple_output_block (ob
);
808 /* Add NODE into encoder as well as nodes it is cloned from.
809 Do it in a way so clones appear first. */
812 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
816 add_node_to (encoder
, node
->clone_of
, include_body
);
817 else if (include_body
)
818 lto_set_symtab_encoder_encode_body (encoder
, node
);
819 lto_symtab_encoder_encode (encoder
, node
);
822 /* Add all references in NODE to encoders. */
825 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
828 struct ipa_ref
*ref
= NULL
;
829 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
830 if (is_a
<cgraph_node
*> (ref
->referred
))
831 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
833 lto_symtab_encoder_encode (encoder
, ref
->referred
);
836 /* Select what needs to be streamed out. In regular lto mode stream everything.
837 In offload lto mode stream only nodes marked as offloadable. */
839 select_what_to_stream (bool offload_lto_mode
)
841 struct symtab_node
*snode
;
842 FOR_EACH_SYMBOL (snode
)
843 snode
->need_lto_streaming
= !offload_lto_mode
|| snode
->offloadable
;
846 /* Find all symbols we want to stream into given partition and insert them
849 The function actually replaces IN_ENCODER by new one. The reason is that
850 streaming code needs clone's origin to be streamed before clone. This
851 means that we need to insert the nodes in specific order. This order is
852 ignored by the partitioning logic earlier. */
855 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
857 struct cgraph_edge
*edge
;
859 lto_symtab_encoder_t encoder
;
860 lto_symtab_encoder_iterator lsei
;
861 hash_set
<void *> reachable_call_targets
;
863 encoder
= lto_symtab_encoder_new (false);
865 /* Go over all entries in the IN_ENCODER and duplicate them to
866 ENCODER. At the same time insert masters of clones so
867 every master appears before clone. */
868 for (lsei
= lsei_start_function_in_partition (in_encoder
);
869 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
871 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
872 if (!node
->need_lto_streaming
)
874 add_node_to (encoder
, node
, true);
875 lto_set_symtab_encoder_in_partition (encoder
, node
);
876 create_references (encoder
, node
);
877 /* For proper debug info, we need to ship the origins, too. */
878 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
880 struct cgraph_node
*origin_node
881 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (node
->decl
));
882 origin_node
->used_as_abstract_origin
= true;
883 add_node_to (encoder
, origin_node
, true);
886 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
887 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
889 varpool_node
*vnode
= lsei_varpool_node (lsei
);
891 if (!vnode
->need_lto_streaming
)
893 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
894 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
895 create_references (encoder
, vnode
);
896 /* For proper debug info, we need to ship the origins, too. */
897 if (DECL_ABSTRACT_ORIGIN (vnode
->decl
))
899 varpool_node
*origin_node
900 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode
->decl
));
901 lto_set_symtab_encoder_in_partition (encoder
, origin_node
);
904 /* Pickle in also the initializer of all referenced readonly variables
905 to help folding. Constant pool variables are not shared, so we must
907 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
909 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
910 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
912 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
914 && (((vnode
->ctor_useable_for_folding_p ()
915 && (!DECL_VIRTUAL_P (vnode
->decl
)
917 || flag_ltrans_devirtualize
))
918 || POINTER_BOUNDS_P (vnode
->decl
))))
920 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
921 create_references (encoder
, vnode
);
926 /* Go over all the nodes again to include callees that are not in
928 for (lsei
= lsei_start_function_in_partition (encoder
);
929 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
931 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
932 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
934 struct cgraph_node
*callee
= edge
->callee
;
935 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
937 /* We should have moved all the inlines. */
938 gcc_assert (!callee
->global
.inlined_to
);
939 add_node_to (encoder
, callee
, false);
942 /* Add all possible targets for late devirtualization. */
943 if (flag_ltrans_devirtualize
|| !flag_wpa
)
944 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
945 if (edge
->indirect_info
->polymorphic
)
950 vec
<cgraph_node
*>targets
951 = possible_polymorphic_call_targets
952 (edge
, &final
, &cache_token
);
953 if (!reachable_call_targets
.add (cache_token
))
955 for (i
= 0; i
< targets
.length (); i
++)
957 struct cgraph_node
*callee
= targets
[i
];
959 /* Adding an external declarations into the unit serves
960 no purpose and just increases its boundary. */
961 if (callee
->definition
962 && !lto_symtab_encoder_in_partition_p
965 gcc_assert (!callee
->global
.inlined_to
);
966 add_node_to (encoder
, callee
, false);
972 lto_symtab_encoder_delete (in_encoder
);
976 /* Output the part of the symtab in SET and VSET. */
981 struct cgraph_node
*node
;
982 struct lto_simple_output_block
*ob
;
983 lto_symtab_encoder_iterator lsei
;
985 lto_symtab_encoder_t encoder
;
988 output_cgraph_opt_summary ();
990 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
992 output_profile_summary (ob
);
994 /* An encoder for cgraph nodes should have been created by
995 ipa_write_summaries_1. */
996 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
997 encoder
= ob
->decl_state
->symtab_node_encoder
;
999 /* Write out the nodes. We must first output a node and then its clones,
1000 otherwise at a time reading back the node there would be nothing to clone
1002 n_nodes
= lto_symtab_encoder_size (encoder
);
1003 for (i
= 0; i
< n_nodes
; i
++)
1005 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1006 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1007 lto_output_node (ob
, cnode
, encoder
);
1009 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1012 /* Go over the nodes in SET again to write edges. */
1013 for (lsei
= lsei_start_function_in_partition (encoder
); !lsei_end_p (lsei
);
1014 lsei_next_function_in_partition (&lsei
))
1016 node
= lsei_cgraph_node (lsei
);
1017 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1018 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1021 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1023 lto_destroy_simple_output_block (ob
);
1025 /* Emit toplevel asms.
1026 When doing WPA we must output every asm just once. Since we do not partition asm
1027 nodes at all, output them to first output. This is kind of hack, but should work
1029 if (!asm_nodes_output
)
1031 asm_nodes_output
= true;
1032 lto_output_toplevel_asms ();
1035 output_refs (encoder
);
1038 /* Return identifier encoded in IB as a plain string. */
1041 read_identifier (struct lto_input_block
*ib
)
1043 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1046 if (ib
->data
[ib
->p
+ len
])
1047 lto_section_overrun (ib
);
1053 id
= get_identifier (ib
->data
+ ib
->p
);
1058 /* Return string encoded in IB, NULL if string is empty. */
1061 read_string (struct lto_input_block
*ib
)
1063 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1066 if (ib
->data
[ib
->p
+ len
])
1067 lto_section_overrun (ib
);
1073 str
= ib
->data
+ ib
->p
;
1078 /* Output function/variable tables that will allow libgomp to look up offload
1080 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1081 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1082 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1085 output_offload_tables (void)
1087 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1090 struct lto_simple_output_block
*ob
1091 = lto_create_simple_output_block (LTO_section_offload_table
);
1093 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1095 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1096 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1097 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1098 (*offload_funcs
)[i
]);
1101 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1103 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1104 LTO_symtab_last_tag
, LTO_symtab_variable
);
1105 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1106 (*offload_vars
)[i
]);
1109 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1110 lto_destroy_simple_output_block (ob
);
1112 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1113 streamed to one partition only. That's why we free offload_funcs and
1114 offload_vars after the first call of output_offload_tables. */
1117 vec_free (offload_funcs
);
1118 vec_free (offload_vars
);
1122 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1123 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1124 NODE or to replace the values in it, for instance because the first
1125 time we saw it, the function body was not available but now it
1126 is. BP is a bitpack with all the bitflags for NODE read from the
1130 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1131 struct cgraph_node
*node
,
1132 enum LTO_symtab_tags tag
,
1133 struct bitpack_d
*bp
)
1135 node
->aux
= (void *) tag
;
1136 node
->lto_file_data
= file_data
;
1138 node
->local
.local
= bp_unpack_value (bp
, 1);
1139 node
->externally_visible
= bp_unpack_value (bp
, 1);
1140 node
->no_reorder
= bp_unpack_value (bp
, 1);
1141 node
->definition
= bp_unpack_value (bp
, 1);
1142 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1143 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1144 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1145 node
->force_output
= bp_unpack_value (bp
, 1);
1146 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1147 node
->unique_name
= bp_unpack_value (bp
, 1);
1148 node
->body_removed
= bp_unpack_value (bp
, 1);
1149 node
->implicit_section
= bp_unpack_value (bp
, 1);
1150 node
->address_taken
= bp_unpack_value (bp
, 1);
1151 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1152 node
->lowered
= bp_unpack_value (bp
, 1);
1153 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1154 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1155 if (node
->in_other_partition
1156 /* Avoid updating decl when we are seeing just inline clone.
1157 When inlining function that has functions already inlined into it,
1158 we produce clones of inline clones.
1160 WPA partitioning might put each clone into different unit and
1161 we might end up streaming inline clone from other partition
1162 to support clone we are interested in. */
1164 || node
->clone_of
->decl
!= node
->decl
))
1166 DECL_EXTERNAL (node
->decl
) = 1;
1167 TREE_STATIC (node
->decl
) = 0;
1169 node
->alias
= bp_unpack_value (bp
, 1);
1170 node
->weakref
= bp_unpack_value (bp
, 1);
1171 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1172 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1173 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1174 node
->tm_clone
= bp_unpack_value (bp
, 1);
1175 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1176 node
->icf_merged
= bp_unpack_value (bp
, 1);
1177 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1178 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1179 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1181 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1182 gcc_assert (flag_ltrans
1183 || (!node
->in_other_partition
1184 && !node
->used_from_other_partition
));
1187 /* Return string alias is alias of. */
1190 get_alias_symbol (tree decl
)
1192 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1193 return get_identifier (TREE_STRING_POINTER
1194 (TREE_VALUE (TREE_VALUE (alias
))));
1197 /* Read a node from input_block IB. TAG is the node's tag just read.
1198 Return the node read or overwriten. */
1200 static struct cgraph_node
*
1201 input_node (struct lto_file_decl_data
*file_data
,
1202 struct lto_input_block
*ib
,
1203 enum LTO_symtab_tags tag
,
1204 vec
<symtab_node
*> nodes
)
1206 gcc::pass_manager
*passes
= g
->get_passes ();
1208 struct cgraph_node
*node
;
1209 struct bitpack_d bp
;
1210 unsigned decl_index
;
1211 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1216 const char *section
;
1217 order
= streamer_read_hwi (ib
) + order_base
;
1218 clone_ref
= streamer_read_hwi (ib
);
1220 decl_index
= streamer_read_uhwi (ib
);
1221 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1223 if (clone_ref
!= LCC_NOT_FOUND
)
1225 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1226 0, CGRAPH_FREQ_BASE
, false,
1227 vNULL
, false, NULL
, NULL
);
1231 /* Declaration of functions can be already merged with a declaration
1232 from other input file. We keep cgraph unmerged until after streaming
1233 of ipa passes is done. Alays forcingly create a fresh node. */
1234 node
= symtab
->create_empty ();
1235 node
->decl
= fn_decl
;
1236 node
->register_symbol ();
1239 node
->order
= order
;
1240 if (order
>= symtab
->order
)
1241 symtab
->order
= order
+ 1;
1243 node
->count
= streamer_read_gcov_count (ib
);
1244 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1246 count
= streamer_read_hwi (ib
);
1247 node
->ipa_transforms_to_apply
= vNULL
;
1248 for (i
= 0; i
< count
; i
++)
1251 int pid
= streamer_read_hwi (ib
);
1253 gcc_assert (pid
< passes
->passes_by_id_size
);
1254 pass
= passes
->passes_by_id
[pid
];
1255 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1258 if (tag
== LTO_symtab_analyzed_node
)
1259 ref
= streamer_read_hwi (ib
);
1261 group
= read_identifier (ib
);
1263 ref2
= streamer_read_hwi (ib
);
1265 /* Make sure that we have not read this node before. Nodes that
1266 have already been read will have their tag stored in the 'aux'
1267 field. Since built-in functions can be referenced in multiple
1268 functions, they are expected to be read more than once. */
1269 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1270 internal_error ("bytecode stream: found multiple instances of cgraph "
1271 "node with uid %d", node
->uid
);
1273 node
->tp_first_run
= streamer_read_uhwi (ib
);
1275 bp
= streamer_read_bitpack (ib
);
1277 input_overwrite_node (file_data
, node
, tag
, &bp
);
1279 /* Store a reference for now, and fix up later to be a pointer. */
1280 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1284 node
->set_comdat_group (group
);
1285 /* Store a reference for now, and fix up later to be a pointer. */
1286 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1289 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1290 section
= read_string (ib
);
1292 node
->set_section_for_node (section
);
1294 if (node
->thunk
.thunk_p
)
1296 int type
= streamer_read_uhwi (ib
);
1297 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1298 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1300 node
->thunk
.fixed_offset
= fixed_offset
;
1301 node
->thunk
.this_adjusting
= (type
& 2);
1302 node
->thunk
.virtual_value
= virtual_value
;
1303 node
->thunk
.virtual_offset_p
= (type
& 4);
1304 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1306 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1307 node
->alias_target
= get_alias_symbol (node
->decl
);
1308 node
->profile_id
= streamer_read_hwi (ib
);
1309 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1310 node
->set_init_priority (streamer_read_hwi (ib
));
1311 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1312 node
->set_fini_priority (streamer_read_hwi (ib
));
1314 if (node
->instrumentation_clone
)
1316 decl_index
= streamer_read_uhwi (ib
);
1317 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1318 node
->orig_decl
= fn_decl
;
1324 /* Read a node from input_block IB. TAG is the node's tag just read.
1325 Return the node read or overwriten. */
1327 static varpool_node
*
1328 input_varpool_node (struct lto_file_decl_data
*file_data
,
1329 struct lto_input_block
*ib
)
1334 struct bitpack_d bp
;
1335 int ref
= LCC_NOT_FOUND
;
1338 const char *section
;
1340 order
= streamer_read_hwi (ib
) + order_base
;
1341 decl_index
= streamer_read_uhwi (ib
);
1342 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1344 /* Declaration of functions can be already merged with a declaration
1345 from other input file. We keep cgraph unmerged until after streaming
1346 of ipa passes is done. Alays forcingly create a fresh node. */
1347 node
= varpool_node::create_empty ();
1348 node
->decl
= var_decl
;
1349 node
->register_symbol ();
1351 node
->order
= order
;
1352 if (order
>= symtab
->order
)
1353 symtab
->order
= order
+ 1;
1354 node
->lto_file_data
= file_data
;
1356 bp
= streamer_read_bitpack (ib
);
1357 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1358 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1359 node
->force_output
= bp_unpack_value (&bp
, 1);
1360 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1361 node
->unique_name
= bp_unpack_value (&bp
, 1);
1362 node
->body_removed
= bp_unpack_value (&bp
, 1);
1363 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1364 node
->writeonly
= bp_unpack_value (&bp
, 1);
1365 node
->definition
= bp_unpack_value (&bp
, 1);
1366 node
->alias
= bp_unpack_value (&bp
, 1);
1367 node
->weakref
= bp_unpack_value (&bp
, 1);
1368 node
->analyzed
= bp_unpack_value (&bp
, 1);
1369 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1370 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1371 if (node
->in_other_partition
)
1373 DECL_EXTERNAL (node
->decl
) = 1;
1374 TREE_STATIC (node
->decl
) = 0;
1376 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1377 node
->alias_target
= get_alias_symbol (node
->decl
);
1378 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1379 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1380 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1381 group
= read_identifier (ib
);
1384 node
->set_comdat_group (group
);
1385 ref
= streamer_read_hwi (ib
);
1386 /* Store a reference for now, and fix up later to be a pointer. */
1387 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1390 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1391 section
= read_string (ib
);
1393 node
->set_section_for_node (section
);
1394 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1396 gcc_assert (flag_ltrans
1397 || (!node
->in_other_partition
1398 && !node
->used_from_other_partition
));
1403 /* Read a node from input_block IB. TAG is the node's tag just read.
1404 Return the node read or overwriten. */
1407 input_ref (struct lto_input_block
*ib
,
1408 symtab_node
*referring_node
,
1409 vec
<symtab_node
*> nodes
)
1411 symtab_node
*node
= NULL
;
1412 struct bitpack_d bp
;
1413 enum ipa_ref_use use
;
1415 struct ipa_ref
*ref
;
1417 bp
= streamer_read_bitpack (ib
);
1418 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1419 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1420 node
= nodes
[streamer_read_hwi (ib
)];
1421 ref
= referring_node
->create_reference (node
, use
);
1422 ref
->speculative
= speculative
;
1423 if (is_a
<cgraph_node
*> (referring_node
))
1424 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1427 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1428 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1429 edge being read is indirect (in the sense that it has
1430 indirect_unknown_callee set). */
1433 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1436 struct cgraph_node
*caller
, *callee
;
1437 struct cgraph_edge
*edge
;
1438 unsigned int stmt_id
;
1441 cgraph_inline_failed_t inline_failed
;
1442 struct bitpack_d bp
;
1445 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1446 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1447 internal_error ("bytecode stream: no caller found while reading edge");
1451 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1452 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1453 internal_error ("bytecode stream: no callee found while reading edge");
1458 count
= streamer_read_gcov_count (ib
);
1460 bp
= streamer_read_bitpack (ib
);
1461 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1462 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1463 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1466 edge
= caller
->create_indirect_edge (NULL
, 0, count
, freq
);
1468 edge
= caller
->create_edge (callee
, NULL
, count
, freq
);
1470 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1471 edge
->speculative
= bp_unpack_value (&bp
, 1);
1472 edge
->lto_stmt_uid
= stmt_id
;
1473 edge
->inline_failed
= inline_failed
;
1474 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1475 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1476 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1479 if (bp_unpack_value (&bp
, 1))
1480 ecf_flags
|= ECF_CONST
;
1481 if (bp_unpack_value (&bp
, 1))
1482 ecf_flags
|= ECF_PURE
;
1483 if (bp_unpack_value (&bp
, 1))
1484 ecf_flags
|= ECF_NORETURN
;
1485 if (bp_unpack_value (&bp
, 1))
1486 ecf_flags
|= ECF_MALLOC
;
1487 if (bp_unpack_value (&bp
, 1))
1488 ecf_flags
|= ECF_NOTHROW
;
1489 if (bp_unpack_value (&bp
, 1))
1490 ecf_flags
|= ECF_RETURNS_TWICE
;
1491 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1492 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1493 if (edge
->indirect_info
->common_target_id
)
1494 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1499 /* Read a cgraph from IB using the info in FILE_DATA. */
1501 static vec
<symtab_node
*>
1502 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1503 struct lto_input_block
*ib
)
1505 enum LTO_symtab_tags tag
;
1506 vec
<symtab_node
*> nodes
= vNULL
;
1510 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1511 order_base
= symtab
->order
;
1514 if (tag
== LTO_symtab_edge
)
1515 input_edge (ib
, nodes
, false);
1516 else if (tag
== LTO_symtab_indirect_edge
)
1517 input_edge (ib
, nodes
, true);
1518 else if (tag
== LTO_symtab_variable
)
1520 node
= input_varpool_node (file_data
, ib
);
1521 nodes
.safe_push (node
);
1522 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1526 node
= input_node (file_data
, ib
, tag
, nodes
);
1527 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1528 internal_error ("bytecode stream: found empty cgraph node");
1529 nodes
.safe_push (node
);
1530 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1533 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1536 lto_input_toplevel_asms (file_data
, order_base
);
1538 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1539 #ifdef ENABLE_CHECKING
1540 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1541 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1543 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1546 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1548 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1550 /* We share declaration of builtins, so we may read same node twice. */
1555 /* Fixup inlined_to from reference to pointer. */
1556 if (ref
!= LCC_NOT_FOUND
)
1557 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1558 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1560 cnode
->global
.inlined_to
= NULL
;
1562 /* Compute instrumented_version. */
1563 if (cnode
->instrumentation_clone
)
1565 gcc_assert (cnode
->orig_decl
);
1567 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1568 if (cnode
->instrumented_version
)
1570 /* We may have multiple nodes for a single function which
1571 will be merged later. To have a proper merge we need
1572 to keep instrumentation_version reference between nodes
1573 consistent: each instrumented_version reference should
1574 have proper reverse reference. Thus don't break existing
1575 instrumented_version reference if it already exists. */
1576 if (cnode
->instrumented_version
->instrumented_version
)
1577 cnode
->instrumented_version
= NULL
;
1579 cnode
->instrumented_version
->instrumented_version
= cnode
;
1582 /* Restore decl names reference. */
1583 if (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (cnode
->decl
))
1584 && !TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode
->decl
)))
1585 TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode
->decl
))
1586 = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1590 ref
= (int) (intptr_t) node
->same_comdat_group
;
1592 /* Fixup same_comdat_group from reference to pointer. */
1593 if (ref
!= LCC_NOT_FOUND
)
1594 node
->same_comdat_group
= nodes
[ref
];
1596 node
->same_comdat_group
= NULL
;
1598 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1599 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1603 /* Input ipa_refs. */
1606 input_refs (struct lto_input_block
*ib
,
1607 vec
<symtab_node
*> nodes
)
1614 count
= streamer_read_uhwi (ib
);
1617 idx
= streamer_read_uhwi (ib
);
1621 input_ref (ib
, node
, nodes
);
1628 static struct gcov_ctr_summary lto_gcov_summary
;
1630 /* Input profile_info from IB. */
1632 input_profile_summary (struct lto_input_block
*ib
,
1633 struct lto_file_decl_data
*file_data
)
1636 struct bitpack_d bp
;
1637 unsigned int runs
= streamer_read_uhwi (ib
);
1640 file_data
->profile_info
.runs
= runs
;
1641 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1642 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1644 memset (file_data
->profile_info
.histogram
, 0,
1645 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1646 /* Input the bitpack of non-zero histogram indices. */
1647 bp
= streamer_read_bitpack (ib
);
1648 /* Read in and unpack the full bitpack, flagging non-zero
1649 histogram entries by setting the num_counters non-zero. */
1650 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1652 file_data
->profile_info
.histogram
[h_ix
].num_counters
1653 = bp_unpack_value (&bp
, 1);
1655 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1657 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1660 file_data
->profile_info
.histogram
[h_ix
].num_counters
1661 = streamer_read_gcov_count (ib
);
1662 file_data
->profile_info
.histogram
[h_ix
].min_value
1663 = streamer_read_gcov_count (ib
);
1664 file_data
->profile_info
.histogram
[h_ix
].cum_value
1665 = streamer_read_gcov_count (ib
);
1667 /* IPA-profile computes hot bb threshold based on cumulated
1668 whole program profile. We need to stream it down to ltrans. */
1670 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1675 /* Rescale profile summaries to the same number of runs in the whole unit. */
1678 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1680 struct lto_file_decl_data
*file_data
;
1681 unsigned int j
, h_ix
;
1682 gcov_unsigned_t max_runs
= 0;
1683 struct cgraph_node
*node
;
1684 struct cgraph_edge
*edge
;
1685 gcov_type saved_sum_all
= 0;
1686 gcov_ctr_summary
*saved_profile_info
= 0;
1687 int saved_scale
= 0;
1689 /* Find unit with maximal number of runs. If we ever get serious about
1690 roundoff errors, we might also consider computing smallest common
1692 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1693 if (max_runs
< file_data
->profile_info
.runs
)
1694 max_runs
= file_data
->profile_info
.runs
;
1699 /* Simple overflow check. We probably don't need to support that many train
1700 runs. Such a large value probably imply data corruption anyway. */
1701 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1703 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1704 INT_MAX
/ REG_BR_PROB_BASE
);
1708 profile_info
= <o_gcov_summary
;
1709 lto_gcov_summary
.runs
= max_runs
;
1710 lto_gcov_summary
.sum_max
= 0;
1711 memset (lto_gcov_summary
.histogram
, 0,
1712 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1714 /* Rescale all units to the maximal number of runs.
1715 sum_max can not be easily merged, as we have no idea what files come from
1716 the same run. We do not use the info anyway, so leave it 0. */
1717 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1718 if (file_data
->profile_info
.runs
)
1720 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1721 file_data
->profile_info
.runs
);
1722 lto_gcov_summary
.sum_max
1723 = MAX (lto_gcov_summary
.sum_max
,
1724 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1725 lto_gcov_summary
.sum_all
1726 = MAX (lto_gcov_summary
.sum_all
,
1727 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1728 /* Save a pointer to the profile_info with the largest
1729 scaled sum_all and the scale for use in merging the
1731 if (!saved_profile_info
1732 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1734 saved_profile_info
= &file_data
->profile_info
;
1735 saved_sum_all
= lto_gcov_summary
.sum_all
;
1736 saved_scale
= scale
;
1740 gcc_assert (saved_profile_info
);
1742 /* Scale up the histogram from the profile that had the largest
1743 scaled sum_all above. */
1744 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1746 /* Scale up the min value as we did the corresponding sum_all
1747 above. Use that to find the new histogram index. */
1748 gcov_type scaled_min
1749 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1751 /* The new index may be shared with another scaled histogram entry,
1752 so we need to account for a non-zero histogram entry at new_ix. */
1753 unsigned new_ix
= gcov_histo_index (scaled_min
);
1754 lto_gcov_summary
.histogram
[new_ix
].min_value
1755 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1756 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1758 /* Some of the scaled counter values would ostensibly need to be placed
1759 into different (larger) histogram buckets, but we keep things simple
1760 here and place the scaled cumulative counter value in the bucket
1761 corresponding to the scaled minimum counter value. */
1762 lto_gcov_summary
.histogram
[new_ix
].cum_value
1763 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1765 lto_gcov_summary
.histogram
[new_ix
].num_counters
1766 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1769 /* Watch roundoff errors. */
1770 if (lto_gcov_summary
.sum_max
< max_runs
)
1771 lto_gcov_summary
.sum_max
= max_runs
;
1773 /* If merging already happent at WPA time, we are done. */
1777 /* Now compute count_materialization_scale of each node.
1778 During LTRANS we already have values of count_materialization_scale
1779 computed, so just update them. */
1780 FOR_EACH_FUNCTION (node
)
1781 if (node
->lto_file_data
1782 && node
->lto_file_data
->profile_info
.runs
)
1786 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1787 node
->lto_file_data
->profile_info
.runs
);
1788 node
->count_materialization_scale
= scale
;
1790 fatal_error ("Profile information in %s corrupted",
1791 file_data
->file_name
);
1793 if (scale
== REG_BR_PROB_BASE
)
1795 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1796 edge
->count
= apply_scale (edge
->count
, scale
);
1797 node
->count
= apply_scale (node
->count
, scale
);
1801 /* Input and merge the symtab from each of the .o files passed to
1807 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1808 struct lto_file_decl_data
*file_data
;
1810 struct cgraph_node
*node
;
1812 while ((file_data
= file_data_vec
[j
++]))
1816 struct lto_input_block
*ib
;
1817 vec
<symtab_node
*> nodes
;
1819 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1822 fatal_error ("cannot find LTO cgraph in %s", file_data
->file_name
);
1823 input_profile_summary (ib
, file_data
);
1824 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1825 nodes
= input_cgraph_1 (file_data
, ib
);
1826 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1829 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1832 fatal_error ("cannot find LTO section refs in %s",
1833 file_data
->file_name
);
1834 input_refs (ib
, nodes
);
1835 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1838 input_cgraph_opt_summary (nodes
);
1842 merge_profile_summaries (file_data_vec
);
1843 get_working_sets ();
1846 /* Clear out the aux field that was used to store enough state to
1847 tell which nodes should be overwritten. */
1848 FOR_EACH_FUNCTION (node
)
1850 /* Some nodes may have been created by cgraph_node. This
1851 happens when the callgraph contains nested functions. If the
1852 node for the parent function was never emitted to the gimple
1853 file, cgraph_node will create a node for it when setting the
1854 context of the nested function. */
1855 if (node
->lto_file_data
)
1860 /* Input function/variable tables that will allow libgomp to look up offload
1861 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1864 input_offload_tables (void)
1866 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1867 struct lto_file_decl_data
*file_data
;
1870 while ((file_data
= file_data_vec
[j
++]))
1874 struct lto_input_block
*ib
1875 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1880 enum LTO_symtab_tags tag
1881 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1884 if (tag
== LTO_symtab_unavail_node
)
1886 int decl_index
= streamer_read_uhwi (ib
);
1888 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1889 vec_safe_push (offload_funcs
, fn_decl
);
1891 else if (tag
== LTO_symtab_variable
)
1893 int decl_index
= streamer_read_uhwi (ib
);
1895 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1896 vec_safe_push (offload_vars
, var_decl
);
1899 fatal_error ("invalid offload table in %s", file_data
->file_name
);
1901 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1904 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1909 /* True when we need optimization summary for NODE. */
1912 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1914 return (node
->clone_of
1915 && (node
->clone
.tree_map
1916 || node
->clone
.args_to_skip
1917 || node
->clone
.combined_args_to_skip
));
1920 /* Output optimization summary for EDGE to OB. */
1922 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1923 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1927 /* Output optimization summary for NODE to OB. */
1930 output_node_opt_summary (struct output_block
*ob
,
1931 struct cgraph_node
*node
,
1932 lto_symtab_encoder_t encoder
)
1936 struct ipa_replace_map
*map
;
1937 struct bitpack_d bp
;
1939 struct cgraph_edge
*e
;
1941 if (node
->clone
.args_to_skip
)
1943 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1944 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1945 streamer_write_uhwi (ob
, index
);
1948 streamer_write_uhwi (ob
, 0);
1949 if (node
->clone
.combined_args_to_skip
)
1951 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1952 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
1953 streamer_write_uhwi (ob
, index
);
1956 streamer_write_uhwi (ob
, 0);
1957 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
1958 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
1960 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1961 mechanism to store function local declarations into summaries. */
1962 gcc_assert (!map
->old_tree
);
1963 streamer_write_uhwi (ob
, map
->parm_num
);
1964 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
1965 stream_write_tree (ob
, map
->new_tree
, true);
1966 bp
= bitpack_create (ob
->main_stream
);
1967 bp_pack_value (&bp
, map
->replace_p
, 1);
1968 bp_pack_value (&bp
, map
->ref_p
, 1);
1969 streamer_write_bitpack (&bp
);
1972 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
1974 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1975 output_edge_opt_summary (ob
, e
);
1976 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
1977 output_edge_opt_summary (ob
, e
);
1981 /* Output optimization summaries stored in callgraph.
1982 At the moment it is the clone info structure. */
1985 output_cgraph_opt_summary (void)
1988 lto_symtab_encoder_t encoder
;
1989 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
1993 encoder
= ob
->decl_state
->symtab_node_encoder
;
1994 n_nodes
= lto_symtab_encoder_size (encoder
);
1995 for (i
= 0; i
< n_nodes
; i
++)
1997 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1998 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1999 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2002 streamer_write_uhwi (ob
, count
);
2003 for (i
= 0; i
< n_nodes
; i
++)
2005 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2006 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2007 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2009 streamer_write_uhwi (ob
, i
);
2010 output_node_opt_summary (ob
, cnode
, encoder
);
2013 produce_asm (ob
, NULL
);
2014 destroy_output_block (ob
);
2017 /* Input optimisation summary of EDGE. */
2020 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2021 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2025 /* Input optimisation summary of NODE. */
2028 input_node_opt_summary (struct cgraph_node
*node
,
2029 struct lto_input_block
*ib_main
,
2030 struct data_in
*data_in
)
2035 struct bitpack_d bp
;
2036 struct cgraph_edge
*e
;
2038 count
= streamer_read_uhwi (ib_main
);
2040 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2041 for (i
= 0; i
< count
; i
++)
2043 bit
= streamer_read_uhwi (ib_main
);
2044 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2046 count
= streamer_read_uhwi (ib_main
);
2048 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2049 for (i
= 0; i
< count
; i
++)
2051 bit
= streamer_read_uhwi (ib_main
);
2052 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2054 count
= streamer_read_uhwi (ib_main
);
2055 for (i
= 0; i
< count
; i
++)
2057 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2059 vec_safe_push (node
->clone
.tree_map
, map
);
2060 map
->parm_num
= streamer_read_uhwi (ib_main
);
2061 map
->old_tree
= NULL
;
2062 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2063 bp
= streamer_read_bitpack (ib_main
);
2064 map
->replace_p
= bp_unpack_value (&bp
, 1);
2065 map
->ref_p
= bp_unpack_value (&bp
, 1);
2067 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2068 input_edge_opt_summary (e
, ib_main
);
2069 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2070 input_edge_opt_summary (e
, ib_main
);
2073 /* Read section in file FILE_DATA of length LEN with data DATA. */
2076 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2077 const char *data
, size_t len
,
2078 vec
<symtab_node
*> nodes
)
2080 const struct lto_function_header
*header
=
2081 (const struct lto_function_header
*) data
;
2082 const int cfg_offset
= sizeof (struct lto_function_header
);
2083 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2084 const int string_offset
= main_offset
+ header
->main_size
;
2085 struct data_in
*data_in
;
2089 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2093 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2094 header
->string_size
, vNULL
);
2095 count
= streamer_read_uhwi (&ib_main
);
2097 for (i
= 0; i
< count
; i
++)
2099 int ref
= streamer_read_uhwi (&ib_main
);
2100 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2103 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2105 lto_data_in_delete (data_in
);
2108 /* Input optimization summary of cgraph. */
2111 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2113 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2114 struct lto_file_decl_data
*file_data
;
2117 while ((file_data
= file_data_vec
[j
++]))
2121 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2125 input_cgraph_opt_section (file_data
, data
, len
, nodes
);