1 /* Write and read the cgraph to the memory mapped representation of a
4 Copyright (C) 2009-2015 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"
30 #include "fold-const.h"
31 #include "stringpool.h"
33 #include "hard-reg-set.h"
35 #include "basic-block.h"
36 #include "tree-ssa-alias.h"
37 #include "internal-fn.h"
38 #include "gimple-expr.h"
42 #include "insn-config.h"
52 #include "langhooks.h"
54 #include "diagnostic-core.h"
57 #include "plugin-api.h"
60 #include "lto-streamer.h"
61 #include "data-streamer.h"
62 #include "tree-streamer.h"
64 #include "tree-pass.h"
67 #include "pass_manager.h"
68 #include "ipa-utils.h"
72 /* True when asm nodes has been output. */
73 bool asm_nodes_output
= false;
75 static void output_cgraph_opt_summary (void);
76 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
78 /* Number of LDPR values known to GCC. */
79 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
81 /* All node orders are ofsetted by ORDER_BASE. */
82 static int order_base
;
84 /* Cgraph streaming is organized as set of record whose type
85 is indicated by a tag. */
88 /* Must leave 0 for the stopper. */
90 /* Cgraph node without body available. */
91 LTO_symtab_unavail_node
= 1,
92 /* Cgraph node with function body. */
93 LTO_symtab_analyzed_node
,
96 LTO_symtab_indirect_edge
,
101 /* Create a new symtab encoder.
102 if FOR_INPUT, the encoder allocate only datastructures needed
103 to read the symtab. */
106 lto_symtab_encoder_new (bool for_input
)
108 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
111 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
112 encoder
->nodes
.create (0);
117 /* Delete ENCODER and its components. */
120 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
122 encoder
->nodes
.release ();
129 /* Return the existing reference number of NODE in the symtab encoder in
130 output block OB. Assign a new reference if this is the first time
134 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
141 lto_encoder_entry entry
= {node
, false, false, false};
143 ref
= encoder
->nodes
.length ();
144 encoder
->nodes
.safe_push (entry
);
148 size_t *slot
= encoder
->map
->get (node
);
151 lto_encoder_entry entry
= {node
, false, false, false};
152 ref
= encoder
->nodes
.length ();
154 encoder
->map
->put (node
, ref
+ 1);
155 encoder
->nodes
.safe_push (entry
);
163 /* Remove NODE from encoder. */
166 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
170 lto_encoder_entry last_node
;
172 size_t *slot
= encoder
->map
->get (node
);
173 if (slot
== NULL
|| !*slot
)
177 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
179 /* Remove from vector. We do this by swapping node with the last element
181 last_node
= encoder
->nodes
.pop ();
182 if (last_node
.node
!= node
)
184 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
186 /* Move the last element to the original spot of NODE. */
187 encoder
->nodes
[index
] = last_node
;
190 /* Remove element from hash table. */
191 encoder
->map
->remove (node
);
196 /* Return TRUE if we should encode the body of NODE (if any). */
199 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
200 struct cgraph_node
*node
)
202 int index
= lto_symtab_encoder_lookup (encoder
, node
);
203 return encoder
->nodes
[index
].body
;
206 /* Specify that we encode the body of NODE in this partition. */
209 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
210 struct cgraph_node
*node
)
212 int index
= lto_symtab_encoder_encode (encoder
, node
);
213 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
214 encoder
->nodes
[index
].body
= true;
217 /* Return TRUE if we should encode initializer of NODE (if any). */
220 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
223 int index
= lto_symtab_encoder_lookup (encoder
, node
);
224 if (index
== LCC_NOT_FOUND
)
226 return encoder
->nodes
[index
].initializer
;
229 /* Specify that we should encode initializer of NODE (if any). */
232 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
235 int index
= lto_symtab_encoder_lookup (encoder
, node
);
236 encoder
->nodes
[index
].initializer
= true;
239 /* Return TRUE if NODE is in this partition. */
242 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder
,
245 int index
= lto_symtab_encoder_lookup (encoder
, node
);
246 if (index
== LCC_NOT_FOUND
)
248 return encoder
->nodes
[index
].in_partition
;
251 /* Specify that NODE is in this partition. */
254 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
257 int index
= lto_symtab_encoder_encode (encoder
, node
);
258 encoder
->nodes
[index
].in_partition
= true;
261 /* Output the cgraph EDGE to OB using ENCODER. */
264 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
265 lto_symtab_encoder_t encoder
)
271 if (edge
->indirect_unknown_callee
)
272 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
273 LTO_symtab_indirect_edge
);
275 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
278 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
279 gcc_assert (ref
!= LCC_NOT_FOUND
);
280 streamer_write_hwi_stream (ob
->main_stream
, ref
);
282 if (!edge
->indirect_unknown_callee
)
284 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
285 gcc_assert (ref
!= LCC_NOT_FOUND
);
286 streamer_write_hwi_stream (ob
->main_stream
, ref
);
289 streamer_write_gcov_count_stream (ob
->main_stream
, edge
->count
);
291 bp
= bitpack_create (ob
->main_stream
);
292 uid
= (!gimple_has_body_p (edge
->caller
->decl
)
293 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
) + 1);
294 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
295 CIF_N_REASONS
, edge
->inline_failed
);
296 bp_pack_var_len_unsigned (&bp
, uid
);
297 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
298 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
299 bp_pack_value (&bp
, edge
->speculative
, 1);
300 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
301 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
302 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
303 if (edge
->indirect_unknown_callee
)
305 int flags
= edge
->indirect_info
->ecf_flags
;
306 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
307 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
308 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
309 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
310 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
311 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
312 /* Flags that should not appear on indirect calls. */
313 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
319 streamer_write_bitpack (&bp
);
320 if (edge
->indirect_unknown_callee
)
322 streamer_write_hwi_stream (ob
->main_stream
,
323 edge
->indirect_info
->common_target_id
);
324 if (edge
->indirect_info
->common_target_id
)
325 streamer_write_hwi_stream
326 (ob
->main_stream
, edge
->indirect_info
->common_target_probability
);
330 /* Return if NODE contain references from other partitions. */
333 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
336 struct ipa_ref
*ref
= NULL
;
338 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
340 /* Ignore references from non-offloadable nodes while streaming NODE into
341 offload LTO section. */
342 if (!ref
->referring
->need_lto_streaming
)
345 if (ref
->referring
->in_other_partition
346 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
352 /* Return true when node is reachable from other partition. */
355 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
357 struct cgraph_edge
*e
;
358 if (!node
->definition
)
360 if (node
->global
.inlined_to
)
362 for (e
= node
->callers
; e
; e
= e
->next_caller
)
364 /* Ignore references from non-offloadable nodes while streaming NODE into
365 offload LTO section. */
366 if (!e
->caller
->need_lto_streaming
)
369 if (e
->caller
->in_other_partition
370 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
376 /* Return if NODE contain references from other partitions. */
379 referenced_from_this_partition_p (symtab_node
*node
,
380 lto_symtab_encoder_t encoder
)
383 struct ipa_ref
*ref
= NULL
;
385 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
386 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
391 /* Return true when node is reachable from other partition. */
394 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
396 struct cgraph_edge
*e
;
397 for (e
= node
->callers
; e
; e
= e
->next_caller
)
398 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
403 /* Output the cgraph NODE to OB. ENCODER is used to find the
404 reference number of NODE->inlined_to. SET is the set of nodes we
405 are writing to the current file. If NODE is not in SET, then NODE
406 is a boundary of a cgraph_node_set and we pretend NODE just has a
407 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
408 that have had their callgraph node written so far. This is used to
409 determine if NODE is a clone of a previously written node. */
412 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
413 lto_symtab_encoder_t encoder
)
419 bool in_other_partition
= false;
420 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
421 ipa_opt_pass_d
*pass
;
427 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
429 if (node
->analyzed
&& (!boundary_p
|| node
->alias
|| node
->thunk
.thunk_p
))
430 tag
= LTO_symtab_analyzed_node
;
432 tag
= LTO_symtab_unavail_node
;
434 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
436 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
438 /* In WPA mode, we only output part of the call-graph. Also, we
439 fake cgraph node attributes. There are two cases that we care.
441 Boundary nodes: There are nodes that are not part of SET but are
442 called from within SET. We artificially make them look like
443 externally visible nodes with no function body.
445 Cherry-picked nodes: These are nodes we pulled from other
446 translation units into SET during IPA-inlining. We make them as
447 local static nodes to prevent clashes with other local statics. */
448 if (boundary_p
&& node
->analyzed
449 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
451 /* Inline clones can not be part of boundary.
452 gcc_assert (!node->global.inlined_to);
454 FIXME: At the moment they can be, when partition contains an inline
455 clone that is clone of inline clone from outside partition. We can
456 reshape the clone tree and make other tree to be the root, but it
457 needs a bit extra work and will be promplty done by cgraph_remove_node
458 after reading back. */
459 in_other_partition
= 1;
462 clone_of
= node
->clone_of
;
464 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
465 if (clone_of
->prev_sibling_clone
)
466 clone_of
= clone_of
->prev_sibling_clone
;
468 clone_of
= clone_of
->clone_of
;
470 /* See if body of the master function is output. If not, we are seeing only
471 an declaration and we do not need to pass down clone tree. */
472 ultimate_clone_of
= clone_of
;
473 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
474 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
476 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
479 if (tag
== LTO_symtab_analyzed_node
)
480 gcc_assert (clone_of
|| !node
->clone_of
);
482 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
484 streamer_write_hwi_stream (ob
->main_stream
, ref
);
487 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
488 streamer_write_gcov_count_stream (ob
->main_stream
, node
->count
);
489 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
491 streamer_write_hwi_stream (ob
->main_stream
,
492 node
->ipa_transforms_to_apply
.length ());
493 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
494 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
496 if (tag
== LTO_symtab_analyzed_node
)
498 if (node
->global
.inlined_to
)
500 ref
= lto_symtab_encoder_lookup (encoder
, node
->global
.inlined_to
);
501 gcc_assert (ref
!= LCC_NOT_FOUND
);
506 streamer_write_hwi_stream (ob
->main_stream
, ref
);
509 group
= node
->get_comdat_group ();
511 comdat
= IDENTIFIER_POINTER (group
);
514 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
518 if (node
->same_comdat_group
&& !boundary_p
)
520 ref
= lto_symtab_encoder_lookup (encoder
,
521 node
->same_comdat_group
);
522 gcc_assert (ref
!= LCC_NOT_FOUND
);
526 streamer_write_hwi_stream (ob
->main_stream
, ref
);
529 section
= node
->get_section ();
533 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
535 bp
= bitpack_create (ob
->main_stream
);
536 bp_pack_value (&bp
, node
->local
.local
, 1);
537 bp_pack_value (&bp
, node
->externally_visible
, 1);
538 bp_pack_value (&bp
, node
->no_reorder
, 1);
539 bp_pack_value (&bp
, node
->definition
, 1);
540 bp_pack_value (&bp
, node
->local
.versionable
, 1);
541 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
542 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
543 bp_pack_value (&bp
, node
->force_output
, 1);
544 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
545 bp_pack_value (&bp
, node
->unique_name
, 1);
546 bp_pack_value (&bp
, node
->body_removed
, 1);
547 bp_pack_value (&bp
, node
->implicit_section
, 1);
548 bp_pack_value (&bp
, node
->address_taken
, 1);
549 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
550 && node
->get_partitioning_class () == SYMBOL_PARTITION
551 && (reachable_from_other_partition_p (node
, encoder
)
552 || referenced_from_other_partition_p (node
, encoder
)), 1);
553 bp_pack_value (&bp
, node
->lowered
, 1);
554 bp_pack_value (&bp
, in_other_partition
, 1);
555 bp_pack_value (&bp
, node
->alias
, 1);
556 bp_pack_value (&bp
, node
->weakref
, 1);
557 bp_pack_value (&bp
, node
->frequency
, 2);
558 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
559 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
560 bp_pack_value (&bp
, node
->tm_clone
, 1);
561 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
562 bp_pack_value (&bp
, node
->icf_merged
, 1);
563 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
564 bp_pack_value (&bp
, node
->thunk
.thunk_p
, 1);
565 bp_pack_value (&bp
, node
->parallelized_function
, 1);
566 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
567 LDPR_NUM_KNOWN
, node
->resolution
);
568 bp_pack_value (&bp
, node
->instrumentation_clone
, 1);
569 bp_pack_value (&bp
, node
->split_part
, 1);
570 streamer_write_bitpack (&bp
);
571 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
573 if (node
->thunk
.thunk_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
);
601 bool encode_initializer_p
603 && lto_symtab_encoder_encode_initializer_p (encoder
, node
));
610 gcc_assert (!encode_initializer_p
|| node
->definition
);
611 gcc_assert (boundary_p
|| encode_initializer_p
);
613 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
614 LTO_symtab_variable
);
615 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
616 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
617 bp
= bitpack_create (ob
->main_stream
);
618 bp_pack_value (&bp
, node
->externally_visible
, 1);
619 bp_pack_value (&bp
, node
->no_reorder
, 1);
620 bp_pack_value (&bp
, node
->force_output
, 1);
621 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
622 bp_pack_value (&bp
, node
->unique_name
, 1);
625 || (!encode_initializer_p
&& !node
->alias
&& node
->definition
),
627 bp_pack_value (&bp
, node
->implicit_section
, 1);
628 bp_pack_value (&bp
, node
->writeonly
, 1);
629 bp_pack_value (&bp
, node
->definition
&& (encode_initializer_p
|| node
->alias
),
631 bp_pack_value (&bp
, node
->alias
, 1);
632 bp_pack_value (&bp
, node
->weakref
, 1);
633 bp_pack_value (&bp
, node
->analyzed
&& !boundary_p
, 1);
634 gcc_assert (node
->definition
|| !node
->analyzed
);
635 /* Constant pool initializers can be de-unified into individual ltrans units.
636 FIXME: Alternatively at -Os we may want to avoid generating for them the local
637 labels and share them across LTRANS partitions. */
638 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
640 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
641 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
645 bp_pack_value (&bp
, node
->definition
646 && referenced_from_other_partition_p (node
, encoder
), 1);
647 bp_pack_value (&bp
, node
->analyzed
648 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
649 /* in_other_partition. */
651 bp_pack_value (&bp
, node
->tls_model
, 3);
652 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
653 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
654 streamer_write_bitpack (&bp
);
656 group
= node
->get_comdat_group ();
658 comdat
= IDENTIFIER_POINTER (group
);
661 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
665 if (node
->same_comdat_group
&& !boundary_p
)
667 ref
= lto_symtab_encoder_lookup (encoder
,
668 node
->same_comdat_group
);
669 gcc_assert (ref
!= LCC_NOT_FOUND
);
673 streamer_write_hwi_stream (ob
->main_stream
, ref
);
676 section
= node
->get_section ();
679 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
681 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
682 LDPR_NUM_KNOWN
, node
->resolution
);
685 /* Output the varpool NODE to OB.
686 If NODE is not in SET, then NODE is a boundary. */
689 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
690 lto_symtab_encoder_t encoder
)
694 int uid
= ref
->lto_stmt_uid
;
695 struct cgraph_node
*node
;
697 bp
= bitpack_create (ob
->main_stream
);
698 bp_pack_value (&bp
, ref
->use
, 3);
699 bp_pack_value (&bp
, ref
->speculative
, 1);
700 streamer_write_bitpack (&bp
);
701 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
702 gcc_assert (nref
!= LCC_NOT_FOUND
);
703 streamer_write_hwi_stream (ob
->main_stream
, nref
);
705 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
709 uid
= gimple_uid (ref
->stmt
) + 1;
710 streamer_write_hwi_stream (ob
->main_stream
, uid
);
714 /* Stream out profile_summary to OB. */
717 output_profile_summary (struct lto_simple_output_block
*ob
)
724 /* We do not output num and run_max, they are not used by
725 GCC profile feedback and they are difficult to merge from multiple
727 gcc_assert (profile_info
->runs
);
728 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
729 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
731 /* sum_all is needed for computing the working set with the
733 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
735 /* Create and output a bitpack of non-zero histogram entries indices. */
736 bp
= bitpack_create (ob
->main_stream
);
737 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
738 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
739 streamer_write_bitpack (&bp
);
740 /* Now stream out only those non-zero entries. */
741 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
743 if (!profile_info
->histogram
[h_ix
].num_counters
)
745 streamer_write_gcov_count_stream (ob
->main_stream
,
746 profile_info
->histogram
[h_ix
].num_counters
);
747 streamer_write_gcov_count_stream (ob
->main_stream
,
748 profile_info
->histogram
[h_ix
].min_value
);
749 streamer_write_gcov_count_stream (ob
->main_stream
,
750 profile_info
->histogram
[h_ix
].cum_value
);
752 /* IPA-profile computes hot bb threshold based on cumulated
753 whole program profile. We need to stream it down to ltrans. */
755 streamer_write_gcov_count_stream (ob
->main_stream
,
756 get_hot_bb_threshold ());
759 streamer_write_uhwi_stream (ob
->main_stream
, 0);
762 /* Output all callees or indirect outgoing edges. EDGE must be the first such
766 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
767 struct lto_simple_output_block
*ob
,
768 lto_symtab_encoder_t encoder
)
773 /* Output edges in backward direction, so the reconstructed callgraph match
774 and it is easy to associate call sites in the IPA pass summaries. */
775 while (edge
->next_callee
)
776 edge
= edge
->next_callee
;
777 for (; edge
; edge
= edge
->prev_callee
)
778 lto_output_edge (ob
, edge
, encoder
);
781 /* Output the part of the cgraph in SET. */
784 output_refs (lto_symtab_encoder_t encoder
)
786 struct lto_simple_output_block
*ob
;
790 ob
= lto_create_simple_output_block (LTO_section_refs
);
792 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
794 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
796 /* IPA_REF_ALIAS and IPA_REF_CHKP references are always preserved
797 in the boundary. Alias node can't have other references and
798 can be always handled as if it's not in the boundary. */
799 if (!node
->alias
&& !lto_symtab_encoder_in_partition_p (encoder
, node
))
801 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
802 /* Output IPA_REF_CHKP reference. */
804 && cnode
->instrumented_version
805 && !cnode
->instrumentation_clone
)
807 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
808 if (ref
->use
== IPA_REF_CHKP
)
810 if (lto_symtab_encoder_lookup (encoder
, ref
->referred
)
813 int nref
= lto_symtab_encoder_lookup (encoder
, node
);
814 streamer_write_gcov_count_stream (ob
->main_stream
, 1);
815 streamer_write_uhwi_stream (ob
->main_stream
, nref
);
816 lto_output_ref (ob
, ref
, encoder
);
824 count
= node
->ref_list
.nreferences ();
827 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
828 streamer_write_uhwi_stream (ob
->main_stream
,
829 lto_symtab_encoder_lookup (encoder
, node
));
830 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
831 lto_output_ref (ob
, ref
, encoder
);
835 streamer_write_uhwi_stream (ob
->main_stream
, 0);
837 lto_destroy_simple_output_block (ob
);
840 /* Add NODE into encoder as well as nodes it is cloned from.
841 Do it in a way so clones appear first. */
844 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
848 add_node_to (encoder
, node
->clone_of
, include_body
);
849 else if (include_body
)
850 lto_set_symtab_encoder_encode_body (encoder
, node
);
851 lto_symtab_encoder_encode (encoder
, node
);
854 /* Add all references in NODE to encoders. */
857 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
860 struct ipa_ref
*ref
= NULL
;
861 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
862 if (is_a
<cgraph_node
*> (ref
->referred
))
863 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
865 lto_symtab_encoder_encode (encoder
, ref
->referred
);
868 /* Select what needs to be streamed out. In regular lto mode stream everything.
869 In offload lto mode stream only nodes marked as offloadable. */
871 select_what_to_stream (void)
873 struct symtab_node
*snode
;
874 FOR_EACH_SYMBOL (snode
)
875 snode
->need_lto_streaming
= !lto_stream_offload_p
|| snode
->offloadable
;
878 /* Find all symbols we want to stream into given partition and insert them
881 The function actually replaces IN_ENCODER by new one. The reason is that
882 streaming code needs clone's origin to be streamed before clone. This
883 means that we need to insert the nodes in specific order. This order is
884 ignored by the partitioning logic earlier. */
887 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
889 struct cgraph_edge
*edge
;
891 lto_symtab_encoder_t encoder
;
892 lto_symtab_encoder_iterator lsei
;
893 hash_set
<void *> reachable_call_targets
;
895 encoder
= lto_symtab_encoder_new (false);
897 /* Go over all entries in the IN_ENCODER and duplicate them to
898 ENCODER. At the same time insert masters of clones so
899 every master appears before clone. */
900 for (lsei
= lsei_start_function_in_partition (in_encoder
);
901 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
903 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
904 if (!node
->need_lto_streaming
)
906 add_node_to (encoder
, node
, true);
907 lto_set_symtab_encoder_in_partition (encoder
, node
);
908 create_references (encoder
, node
);
909 /* For proper debug info, we need to ship the origins, too. */
910 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
912 struct cgraph_node
*origin_node
913 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (node
->decl
));
914 origin_node
->used_as_abstract_origin
= true;
915 add_node_to (encoder
, origin_node
, true);
918 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
919 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
921 varpool_node
*vnode
= lsei_varpool_node (lsei
);
923 if (!vnode
->need_lto_streaming
)
925 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
926 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
927 create_references (encoder
, vnode
);
928 /* For proper debug info, we need to ship the origins, too. */
929 if (DECL_ABSTRACT_ORIGIN (vnode
->decl
))
931 varpool_node
*origin_node
932 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode
->decl
));
933 lto_set_symtab_encoder_in_partition (encoder
, origin_node
);
936 /* Pickle in also the initializer of all referenced readonly variables
937 to help folding. Constant pool variables are not shared, so we must
939 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
941 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
942 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
944 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
946 && (((vnode
->ctor_useable_for_folding_p ()
947 && (!DECL_VIRTUAL_P (vnode
->decl
)
949 || flag_ltrans_devirtualize
))
950 || POINTER_BOUNDS_P (vnode
->decl
))))
952 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
953 create_references (encoder
, vnode
);
958 /* Go over all the nodes again to include callees that are not in
960 for (lsei
= lsei_start_function_in_partition (encoder
);
961 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
963 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
964 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
966 struct cgraph_node
*callee
= edge
->callee
;
967 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
969 /* We should have moved all the inlines. */
970 gcc_assert (!callee
->global
.inlined_to
);
971 add_node_to (encoder
, callee
, false);
974 /* Add all possible targets for late devirtualization. */
975 if (flag_ltrans_devirtualize
|| !flag_wpa
)
976 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
977 if (edge
->indirect_info
->polymorphic
)
982 vec
<cgraph_node
*>targets
983 = possible_polymorphic_call_targets
984 (edge
, &final
, &cache_token
);
985 if (!reachable_call_targets
.add (cache_token
))
987 for (i
= 0; i
< targets
.length (); i
++)
989 struct cgraph_node
*callee
= targets
[i
];
991 /* Adding an external declarations into the unit serves
992 no purpose and just increases its boundary. */
993 if (callee
->definition
994 && !lto_symtab_encoder_in_partition_p
997 gcc_assert (!callee
->global
.inlined_to
);
998 add_node_to (encoder
, callee
, false);
1004 /* Be sure to also insert alias targert and thunk callees. These needs
1005 to stay to aid local calling conventions. */
1006 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1008 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1009 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1011 if (node
->alias
&& node
->analyzed
)
1012 create_references (encoder
, node
);
1014 && cnode
->thunk
.thunk_p
)
1015 add_node_to (encoder
, cnode
->callees
->callee
, false);
1017 lto_symtab_encoder_delete (in_encoder
);
1021 /* Output the part of the symtab in SET and VSET. */
1024 output_symtab (void)
1026 struct cgraph_node
*node
;
1027 struct lto_simple_output_block
*ob
;
1029 lto_symtab_encoder_t encoder
;
1032 output_cgraph_opt_summary ();
1034 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
1036 output_profile_summary (ob
);
1038 /* An encoder for cgraph nodes should have been created by
1039 ipa_write_summaries_1. */
1040 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
1041 encoder
= ob
->decl_state
->symtab_node_encoder
;
1043 /* Write out the nodes. We must first output a node and then its clones,
1044 otherwise at a time reading back the node there would be nothing to clone
1046 n_nodes
= lto_symtab_encoder_size (encoder
);
1047 for (i
= 0; i
< n_nodes
; i
++)
1049 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1050 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1051 lto_output_node (ob
, cnode
, encoder
);
1053 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1056 /* Go over the nodes in SET again to write edges. */
1057 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1059 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
, i
));
1061 && (node
->thunk
.thunk_p
1062 || lto_symtab_encoder_in_partition_p (encoder
, node
)))
1064 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1065 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1069 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1071 lto_destroy_simple_output_block (ob
);
1073 /* Emit toplevel asms.
1074 When doing WPA we must output every asm just once. Since we do not partition asm
1075 nodes at all, output them to first output. This is kind of hack, but should work
1077 if (!asm_nodes_output
)
1079 asm_nodes_output
= true;
1080 lto_output_toplevel_asms ();
1083 output_refs (encoder
);
1086 /* Return identifier encoded in IB as a plain string. */
1089 read_identifier (struct lto_input_block
*ib
)
1091 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1094 if (ib
->data
[ib
->p
+ len
])
1095 lto_section_overrun (ib
);
1101 id
= get_identifier (ib
->data
+ ib
->p
);
1106 /* Return string encoded in IB, NULL if string is empty. */
1109 read_string (struct lto_input_block
*ib
)
1111 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1114 if (ib
->data
[ib
->p
+ len
])
1115 lto_section_overrun (ib
);
1121 str
= ib
->data
+ ib
->p
;
1126 /* Output function/variable tables that will allow libgomp to look up offload
1128 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1129 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1130 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1133 output_offload_tables (void)
1135 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1138 struct lto_simple_output_block
*ob
1139 = lto_create_simple_output_block (LTO_section_offload_table
);
1141 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1143 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1144 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1145 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1146 (*offload_funcs
)[i
]);
1149 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1151 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1152 LTO_symtab_last_tag
, LTO_symtab_variable
);
1153 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1154 (*offload_vars
)[i
]);
1157 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1158 lto_destroy_simple_output_block (ob
);
1160 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1161 streamed to one partition only. That's why we free offload_funcs and
1162 offload_vars after the first call of output_offload_tables. */
1165 vec_free (offload_funcs
);
1166 vec_free (offload_vars
);
1170 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1171 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1172 NODE or to replace the values in it, for instance because the first
1173 time we saw it, the function body was not available but now it
1174 is. BP is a bitpack with all the bitflags for NODE read from the
1178 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1179 struct cgraph_node
*node
,
1180 enum LTO_symtab_tags tag
,
1181 struct bitpack_d
*bp
)
1183 node
->aux
= (void *) tag
;
1184 node
->lto_file_data
= file_data
;
1186 node
->local
.local
= bp_unpack_value (bp
, 1);
1187 node
->externally_visible
= bp_unpack_value (bp
, 1);
1188 node
->no_reorder
= bp_unpack_value (bp
, 1);
1189 node
->definition
= bp_unpack_value (bp
, 1);
1190 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1191 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1192 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1193 node
->force_output
= bp_unpack_value (bp
, 1);
1194 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1195 node
->unique_name
= bp_unpack_value (bp
, 1);
1196 node
->body_removed
= bp_unpack_value (bp
, 1);
1197 node
->implicit_section
= bp_unpack_value (bp
, 1);
1198 node
->address_taken
= bp_unpack_value (bp
, 1);
1199 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1200 node
->lowered
= bp_unpack_value (bp
, 1);
1201 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1202 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1203 if (node
->in_other_partition
1204 /* Avoid updating decl when we are seeing just inline clone.
1205 When inlining function that has functions already inlined into it,
1206 we produce clones of inline clones.
1208 WPA partitioning might put each clone into different unit and
1209 we might end up streaming inline clone from other partition
1210 to support clone we are interested in. */
1212 || node
->clone_of
->decl
!= node
->decl
))
1214 DECL_EXTERNAL (node
->decl
) = 1;
1215 TREE_STATIC (node
->decl
) = 0;
1217 node
->alias
= bp_unpack_value (bp
, 1);
1218 node
->weakref
= bp_unpack_value (bp
, 1);
1219 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1220 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1221 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1222 node
->tm_clone
= bp_unpack_value (bp
, 1);
1223 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1224 node
->icf_merged
= bp_unpack_value (bp
, 1);
1225 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1226 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1227 node
->parallelized_function
= bp_unpack_value (bp
, 1);
1228 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1230 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1231 node
->split_part
= bp_unpack_value (bp
, 1);
1232 gcc_assert (flag_ltrans
1233 || (!node
->in_other_partition
1234 && !node
->used_from_other_partition
));
1237 /* Return string alias is alias of. */
1240 get_alias_symbol (tree decl
)
1242 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1243 return get_identifier (TREE_STRING_POINTER
1244 (TREE_VALUE (TREE_VALUE (alias
))));
1247 /* Read a node from input_block IB. TAG is the node's tag just read.
1248 Return the node read or overwriten. */
1250 static struct cgraph_node
*
1251 input_node (struct lto_file_decl_data
*file_data
,
1252 struct lto_input_block
*ib
,
1253 enum LTO_symtab_tags tag
,
1254 vec
<symtab_node
*> nodes
)
1256 gcc::pass_manager
*passes
= g
->get_passes ();
1258 struct cgraph_node
*node
;
1259 struct bitpack_d bp
;
1260 unsigned decl_index
;
1261 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1266 const char *section
;
1267 order
= streamer_read_hwi (ib
) + order_base
;
1268 clone_ref
= streamer_read_hwi (ib
);
1270 decl_index
= streamer_read_uhwi (ib
);
1271 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1273 if (clone_ref
!= LCC_NOT_FOUND
)
1275 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1276 0, CGRAPH_FREQ_BASE
, false,
1277 vNULL
, false, NULL
, NULL
);
1281 /* Declaration of functions can be already merged with a declaration
1282 from other input file. We keep cgraph unmerged until after streaming
1283 of ipa passes is done. Alays forcingly create a fresh node. */
1284 node
= symtab
->create_empty ();
1285 node
->decl
= fn_decl
;
1286 node
->register_symbol ();
1289 node
->order
= order
;
1290 if (order
>= symtab
->order
)
1291 symtab
->order
= order
+ 1;
1293 node
->count
= streamer_read_gcov_count (ib
);
1294 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1296 count
= streamer_read_hwi (ib
);
1297 node
->ipa_transforms_to_apply
= vNULL
;
1298 for (i
= 0; i
< count
; i
++)
1301 int pid
= streamer_read_hwi (ib
);
1303 gcc_assert (pid
< passes
->passes_by_id_size
);
1304 pass
= passes
->passes_by_id
[pid
];
1305 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1308 if (tag
== LTO_symtab_analyzed_node
)
1309 ref
= streamer_read_hwi (ib
);
1311 group
= read_identifier (ib
);
1313 ref2
= streamer_read_hwi (ib
);
1315 /* Make sure that we have not read this node before. Nodes that
1316 have already been read will have their tag stored in the 'aux'
1317 field. Since built-in functions can be referenced in multiple
1318 functions, they are expected to be read more than once. */
1319 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1320 internal_error ("bytecode stream: found multiple instances of cgraph "
1321 "node with uid %d", node
->uid
);
1323 node
->tp_first_run
= streamer_read_uhwi (ib
);
1325 bp
= streamer_read_bitpack (ib
);
1327 input_overwrite_node (file_data
, node
, tag
, &bp
);
1329 /* Store a reference for now, and fix up later to be a pointer. */
1330 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1334 node
->set_comdat_group (group
);
1335 /* Store a reference for now, and fix up later to be a pointer. */
1336 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1339 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1340 section
= read_string (ib
);
1342 node
->set_section_for_node (section
);
1344 if (node
->thunk
.thunk_p
)
1346 int type
= streamer_read_uhwi (ib
);
1347 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1348 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1350 node
->thunk
.fixed_offset
= fixed_offset
;
1351 node
->thunk
.this_adjusting
= (type
& 2);
1352 node
->thunk
.virtual_value
= virtual_value
;
1353 node
->thunk
.virtual_offset_p
= (type
& 4);
1354 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1356 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1357 node
->alias_target
= get_alias_symbol (node
->decl
);
1358 node
->profile_id
= streamer_read_hwi (ib
);
1359 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1360 node
->set_init_priority (streamer_read_hwi (ib
));
1361 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1362 node
->set_fini_priority (streamer_read_hwi (ib
));
1364 if (node
->instrumentation_clone
)
1366 decl_index
= streamer_read_uhwi (ib
);
1367 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1368 node
->orig_decl
= fn_decl
;
1374 /* Read a node from input_block IB. TAG is the node's tag just read.
1375 Return the node read or overwriten. */
1377 static varpool_node
*
1378 input_varpool_node (struct lto_file_decl_data
*file_data
,
1379 struct lto_input_block
*ib
)
1384 struct bitpack_d bp
;
1385 int ref
= LCC_NOT_FOUND
;
1388 const char *section
;
1390 order
= streamer_read_hwi (ib
) + order_base
;
1391 decl_index
= streamer_read_uhwi (ib
);
1392 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1394 /* Declaration of functions can be already merged with a declaration
1395 from other input file. We keep cgraph unmerged until after streaming
1396 of ipa passes is done. Alays forcingly create a fresh node. */
1397 node
= varpool_node::create_empty ();
1398 node
->decl
= var_decl
;
1399 node
->register_symbol ();
1401 node
->order
= order
;
1402 if (order
>= symtab
->order
)
1403 symtab
->order
= order
+ 1;
1404 node
->lto_file_data
= file_data
;
1406 bp
= streamer_read_bitpack (ib
);
1407 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1408 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1409 node
->force_output
= bp_unpack_value (&bp
, 1);
1410 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1411 node
->unique_name
= bp_unpack_value (&bp
, 1);
1412 node
->body_removed
= bp_unpack_value (&bp
, 1);
1413 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1414 node
->writeonly
= bp_unpack_value (&bp
, 1);
1415 node
->definition
= bp_unpack_value (&bp
, 1);
1416 node
->alias
= bp_unpack_value (&bp
, 1);
1417 node
->weakref
= bp_unpack_value (&bp
, 1);
1418 node
->analyzed
= bp_unpack_value (&bp
, 1);
1419 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1420 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1421 if (node
->in_other_partition
)
1423 DECL_EXTERNAL (node
->decl
) = 1;
1424 TREE_STATIC (node
->decl
) = 0;
1426 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1427 node
->alias_target
= get_alias_symbol (node
->decl
);
1428 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1429 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1430 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1431 group
= read_identifier (ib
);
1434 node
->set_comdat_group (group
);
1435 ref
= streamer_read_hwi (ib
);
1436 /* Store a reference for now, and fix up later to be a pointer. */
1437 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1440 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1441 section
= read_string (ib
);
1443 node
->set_section_for_node (section
);
1444 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1446 gcc_assert (flag_ltrans
1447 || (!node
->in_other_partition
1448 && !node
->used_from_other_partition
));
1453 /* Read a node from input_block IB. TAG is the node's tag just read.
1454 Return the node read or overwriten. */
1457 input_ref (struct lto_input_block
*ib
,
1458 symtab_node
*referring_node
,
1459 vec
<symtab_node
*> nodes
)
1461 symtab_node
*node
= NULL
;
1462 struct bitpack_d bp
;
1463 enum ipa_ref_use use
;
1465 struct ipa_ref
*ref
;
1467 bp
= streamer_read_bitpack (ib
);
1468 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1469 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1470 node
= nodes
[streamer_read_hwi (ib
)];
1471 ref
= referring_node
->create_reference (node
, use
);
1472 ref
->speculative
= speculative
;
1473 if (is_a
<cgraph_node
*> (referring_node
))
1474 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1477 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1478 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1479 edge being read is indirect (in the sense that it has
1480 indirect_unknown_callee set). */
1483 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1486 struct cgraph_node
*caller
, *callee
;
1487 struct cgraph_edge
*edge
;
1488 unsigned int stmt_id
;
1491 cgraph_inline_failed_t inline_failed
;
1492 struct bitpack_d bp
;
1495 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1496 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1497 internal_error ("bytecode stream: no caller found while reading edge");
1501 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1502 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1503 internal_error ("bytecode stream: no callee found while reading edge");
1508 count
= streamer_read_gcov_count (ib
);
1510 bp
= streamer_read_bitpack (ib
);
1511 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1512 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1513 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1516 edge
= caller
->create_indirect_edge (NULL
, 0, count
, freq
);
1518 edge
= caller
->create_edge (callee
, NULL
, count
, freq
);
1520 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1521 edge
->speculative
= bp_unpack_value (&bp
, 1);
1522 edge
->lto_stmt_uid
= stmt_id
;
1523 edge
->inline_failed
= inline_failed
;
1524 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1525 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1526 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1529 if (bp_unpack_value (&bp
, 1))
1530 ecf_flags
|= ECF_CONST
;
1531 if (bp_unpack_value (&bp
, 1))
1532 ecf_flags
|= ECF_PURE
;
1533 if (bp_unpack_value (&bp
, 1))
1534 ecf_flags
|= ECF_NORETURN
;
1535 if (bp_unpack_value (&bp
, 1))
1536 ecf_flags
|= ECF_MALLOC
;
1537 if (bp_unpack_value (&bp
, 1))
1538 ecf_flags
|= ECF_NOTHROW
;
1539 if (bp_unpack_value (&bp
, 1))
1540 ecf_flags
|= ECF_RETURNS_TWICE
;
1541 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1542 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1543 if (edge
->indirect_info
->common_target_id
)
1544 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1549 /* Read a cgraph from IB using the info in FILE_DATA. */
1551 static vec
<symtab_node
*>
1552 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1553 struct lto_input_block
*ib
)
1555 enum LTO_symtab_tags tag
;
1556 vec
<symtab_node
*> nodes
= vNULL
;
1560 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1561 order_base
= symtab
->order
;
1564 if (tag
== LTO_symtab_edge
)
1565 input_edge (ib
, nodes
, false);
1566 else if (tag
== LTO_symtab_indirect_edge
)
1567 input_edge (ib
, nodes
, true);
1568 else if (tag
== LTO_symtab_variable
)
1570 node
= input_varpool_node (file_data
, ib
);
1571 nodes
.safe_push (node
);
1572 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1576 node
= input_node (file_data
, ib
, tag
, nodes
);
1577 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1578 internal_error ("bytecode stream: found empty cgraph node");
1579 nodes
.safe_push (node
);
1580 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1583 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1586 lto_input_toplevel_asms (file_data
, order_base
);
1588 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1589 #ifdef ENABLE_CHECKING
1590 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1591 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1593 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1596 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1598 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1600 /* We share declaration of builtins, so we may read same node twice. */
1605 /* Fixup inlined_to from reference to pointer. */
1606 if (ref
!= LCC_NOT_FOUND
)
1607 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1608 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1610 cnode
->global
.inlined_to
= NULL
;
1612 /* Compute instrumented_version. */
1613 if (cnode
->instrumentation_clone
)
1615 gcc_assert (cnode
->orig_decl
);
1617 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1618 if (cnode
->instrumented_version
)
1620 /* We may have multiple nodes for a single function which
1621 will be merged later. To have a proper merge we need
1622 to keep instrumentation_version reference between nodes
1623 consistent: each instrumented_version reference should
1624 have proper reverse reference. Thus don't break existing
1625 instrumented_version reference if it already exists. */
1626 if (cnode
->instrumented_version
->instrumented_version
)
1627 cnode
->instrumented_version
= NULL
;
1629 cnode
->instrumented_version
->instrumented_version
= cnode
;
1632 /* Restore decl names reference except for wrapper functions. */
1633 if (!chkp_wrap_function (cnode
->orig_decl
))
1635 tree name
= DECL_ASSEMBLER_NAME (cnode
->decl
);
1636 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
1637 TREE_CHAIN (name
) = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1642 ref
= (int) (intptr_t) node
->same_comdat_group
;
1644 /* Fixup same_comdat_group from reference to pointer. */
1645 if (ref
!= LCC_NOT_FOUND
)
1646 node
->same_comdat_group
= nodes
[ref
];
1648 node
->same_comdat_group
= NULL
;
1650 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1651 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1655 /* Input ipa_refs. */
1658 input_refs (struct lto_input_block
*ib
,
1659 vec
<symtab_node
*> nodes
)
1666 count
= streamer_read_uhwi (ib
);
1669 idx
= streamer_read_uhwi (ib
);
1673 input_ref (ib
, node
, nodes
);
1680 static struct gcov_ctr_summary lto_gcov_summary
;
1682 /* Input profile_info from IB. */
1684 input_profile_summary (struct lto_input_block
*ib
,
1685 struct lto_file_decl_data
*file_data
)
1688 struct bitpack_d bp
;
1689 unsigned int runs
= streamer_read_uhwi (ib
);
1692 file_data
->profile_info
.runs
= runs
;
1693 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1694 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1696 memset (file_data
->profile_info
.histogram
, 0,
1697 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1698 /* Input the bitpack of non-zero histogram indices. */
1699 bp
= streamer_read_bitpack (ib
);
1700 /* Read in and unpack the full bitpack, flagging non-zero
1701 histogram entries by setting the num_counters non-zero. */
1702 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1704 file_data
->profile_info
.histogram
[h_ix
].num_counters
1705 = bp_unpack_value (&bp
, 1);
1707 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1709 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1712 file_data
->profile_info
.histogram
[h_ix
].num_counters
1713 = streamer_read_gcov_count (ib
);
1714 file_data
->profile_info
.histogram
[h_ix
].min_value
1715 = streamer_read_gcov_count (ib
);
1716 file_data
->profile_info
.histogram
[h_ix
].cum_value
1717 = streamer_read_gcov_count (ib
);
1719 /* IPA-profile computes hot bb threshold based on cumulated
1720 whole program profile. We need to stream it down to ltrans. */
1722 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1727 /* Rescale profile summaries to the same number of runs in the whole unit. */
1730 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1732 struct lto_file_decl_data
*file_data
;
1733 unsigned int j
, h_ix
;
1734 gcov_unsigned_t max_runs
= 0;
1735 struct cgraph_node
*node
;
1736 struct cgraph_edge
*edge
;
1737 gcov_type saved_sum_all
= 0;
1738 gcov_ctr_summary
*saved_profile_info
= 0;
1739 int saved_scale
= 0;
1741 /* Find unit with maximal number of runs. If we ever get serious about
1742 roundoff errors, we might also consider computing smallest common
1744 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1745 if (max_runs
< file_data
->profile_info
.runs
)
1746 max_runs
= file_data
->profile_info
.runs
;
1751 /* Simple overflow check. We probably don't need to support that many train
1752 runs. Such a large value probably imply data corruption anyway. */
1753 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1755 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1756 INT_MAX
/ REG_BR_PROB_BASE
);
1760 profile_info
= <o_gcov_summary
;
1761 lto_gcov_summary
.runs
= max_runs
;
1762 lto_gcov_summary
.sum_max
= 0;
1763 memset (lto_gcov_summary
.histogram
, 0,
1764 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1766 /* Rescale all units to the maximal number of runs.
1767 sum_max can not be easily merged, as we have no idea what files come from
1768 the same run. We do not use the info anyway, so leave it 0. */
1769 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1770 if (file_data
->profile_info
.runs
)
1772 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1773 file_data
->profile_info
.runs
);
1774 lto_gcov_summary
.sum_max
1775 = MAX (lto_gcov_summary
.sum_max
,
1776 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1777 lto_gcov_summary
.sum_all
1778 = MAX (lto_gcov_summary
.sum_all
,
1779 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1780 /* Save a pointer to the profile_info with the largest
1781 scaled sum_all and the scale for use in merging the
1783 if (!saved_profile_info
1784 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1786 saved_profile_info
= &file_data
->profile_info
;
1787 saved_sum_all
= lto_gcov_summary
.sum_all
;
1788 saved_scale
= scale
;
1792 gcc_assert (saved_profile_info
);
1794 /* Scale up the histogram from the profile that had the largest
1795 scaled sum_all above. */
1796 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1798 /* Scale up the min value as we did the corresponding sum_all
1799 above. Use that to find the new histogram index. */
1800 gcov_type scaled_min
1801 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1803 /* The new index may be shared with another scaled histogram entry,
1804 so we need to account for a non-zero histogram entry at new_ix. */
1805 unsigned new_ix
= gcov_histo_index (scaled_min
);
1806 lto_gcov_summary
.histogram
[new_ix
].min_value
1807 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1808 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1810 /* Some of the scaled counter values would ostensibly need to be placed
1811 into different (larger) histogram buckets, but we keep things simple
1812 here and place the scaled cumulative counter value in the bucket
1813 corresponding to the scaled minimum counter value. */
1814 lto_gcov_summary
.histogram
[new_ix
].cum_value
1815 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1817 lto_gcov_summary
.histogram
[new_ix
].num_counters
1818 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1821 /* Watch roundoff errors. */
1822 if (lto_gcov_summary
.sum_max
< max_runs
)
1823 lto_gcov_summary
.sum_max
= max_runs
;
1825 /* If merging already happent at WPA time, we are done. */
1829 /* Now compute count_materialization_scale of each node.
1830 During LTRANS we already have values of count_materialization_scale
1831 computed, so just update them. */
1832 FOR_EACH_FUNCTION (node
)
1833 if (node
->lto_file_data
1834 && node
->lto_file_data
->profile_info
.runs
)
1838 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1839 node
->lto_file_data
->profile_info
.runs
);
1840 node
->count_materialization_scale
= scale
;
1842 fatal_error (input_location
, "Profile information in %s corrupted",
1843 file_data
->file_name
);
1845 if (scale
== REG_BR_PROB_BASE
)
1847 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1848 edge
->count
= apply_scale (edge
->count
, scale
);
1849 node
->count
= apply_scale (node
->count
, scale
);
1853 /* Input and merge the symtab from each of the .o files passed to
1859 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1860 struct lto_file_decl_data
*file_data
;
1862 struct cgraph_node
*node
;
1864 while ((file_data
= file_data_vec
[j
++]))
1868 struct lto_input_block
*ib
;
1869 vec
<symtab_node
*> nodes
;
1871 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1874 fatal_error (input_location
,
1875 "cannot find LTO cgraph in %s", file_data
->file_name
);
1876 input_profile_summary (ib
, file_data
);
1877 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1878 nodes
= input_cgraph_1 (file_data
, ib
);
1879 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1882 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1885 fatal_error (input_location
, "cannot find LTO section refs in %s",
1886 file_data
->file_name
);
1887 input_refs (ib
, nodes
);
1888 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1891 input_cgraph_opt_summary (nodes
);
1895 merge_profile_summaries (file_data_vec
);
1896 get_working_sets ();
1899 /* Clear out the aux field that was used to store enough state to
1900 tell which nodes should be overwritten. */
1901 FOR_EACH_FUNCTION (node
)
1903 /* Some nodes may have been created by cgraph_node. This
1904 happens when the callgraph contains nested functions. If the
1905 node for the parent function was never emitted to the gimple
1906 file, cgraph_node will create a node for it when setting the
1907 context of the nested function. */
1908 if (node
->lto_file_data
)
1913 /* Input function/variable tables that will allow libgomp to look up offload
1914 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1917 input_offload_tables (void)
1919 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1920 struct lto_file_decl_data
*file_data
;
1923 while ((file_data
= file_data_vec
[j
++]))
1927 struct lto_input_block
*ib
1928 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1933 enum LTO_symtab_tags tag
1934 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1937 if (tag
== LTO_symtab_unavail_node
)
1939 int decl_index
= streamer_read_uhwi (ib
);
1941 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1942 vec_safe_push (offload_funcs
, fn_decl
);
1944 else if (tag
== LTO_symtab_variable
)
1946 int decl_index
= streamer_read_uhwi (ib
);
1948 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1949 vec_safe_push (offload_vars
, var_decl
);
1952 fatal_error (input_location
,
1953 "invalid offload table in %s", file_data
->file_name
);
1955 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1958 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1963 /* True when we need optimization summary for NODE. */
1966 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1968 return (node
->clone_of
1969 && (node
->clone
.tree_map
1970 || node
->clone
.args_to_skip
1971 || node
->clone
.combined_args_to_skip
));
1974 /* Output optimization summary for EDGE to OB. */
1976 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1977 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1981 /* Output optimization summary for NODE to OB. */
1984 output_node_opt_summary (struct output_block
*ob
,
1985 struct cgraph_node
*node
,
1986 lto_symtab_encoder_t encoder
)
1990 struct ipa_replace_map
*map
;
1991 struct bitpack_d bp
;
1993 struct cgraph_edge
*e
;
1995 if (node
->clone
.args_to_skip
)
1997 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1998 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1999 streamer_write_uhwi (ob
, index
);
2002 streamer_write_uhwi (ob
, 0);
2003 if (node
->clone
.combined_args_to_skip
)
2005 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
2006 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
2007 streamer_write_uhwi (ob
, index
);
2010 streamer_write_uhwi (ob
, 0);
2011 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
2012 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
2014 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
2015 mechanism to store function local declarations into summaries. */
2016 gcc_assert (!map
->old_tree
);
2017 streamer_write_uhwi (ob
, map
->parm_num
);
2018 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
2019 stream_write_tree (ob
, map
->new_tree
, true);
2020 bp
= bitpack_create (ob
->main_stream
);
2021 bp_pack_value (&bp
, map
->replace_p
, 1);
2022 bp_pack_value (&bp
, map
->ref_p
, 1);
2023 streamer_write_bitpack (&bp
);
2026 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
2028 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2029 output_edge_opt_summary (ob
, e
);
2030 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2031 output_edge_opt_summary (ob
, e
);
2035 /* Output optimization summaries stored in callgraph.
2036 At the moment it is the clone info structure. */
2039 output_cgraph_opt_summary (void)
2042 lto_symtab_encoder_t encoder
;
2043 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
2047 encoder
= ob
->decl_state
->symtab_node_encoder
;
2048 n_nodes
= lto_symtab_encoder_size (encoder
);
2049 for (i
= 0; i
< n_nodes
; i
++)
2051 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2052 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2053 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2056 streamer_write_uhwi (ob
, count
);
2057 for (i
= 0; i
< n_nodes
; i
++)
2059 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2060 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2061 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2063 streamer_write_uhwi (ob
, i
);
2064 output_node_opt_summary (ob
, cnode
, encoder
);
2067 produce_asm (ob
, NULL
);
2068 destroy_output_block (ob
);
2071 /* Input optimisation summary of EDGE. */
2074 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2075 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2079 /* Input optimisation summary of NODE. */
2082 input_node_opt_summary (struct cgraph_node
*node
,
2083 struct lto_input_block
*ib_main
,
2084 struct data_in
*data_in
)
2089 struct bitpack_d bp
;
2090 struct cgraph_edge
*e
;
2092 count
= streamer_read_uhwi (ib_main
);
2094 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2095 for (i
= 0; i
< count
; i
++)
2097 bit
= streamer_read_uhwi (ib_main
);
2098 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2100 count
= streamer_read_uhwi (ib_main
);
2102 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2103 for (i
= 0; i
< count
; i
++)
2105 bit
= streamer_read_uhwi (ib_main
);
2106 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2108 count
= streamer_read_uhwi (ib_main
);
2109 for (i
= 0; i
< count
; i
++)
2111 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2113 vec_safe_push (node
->clone
.tree_map
, map
);
2114 map
->parm_num
= streamer_read_uhwi (ib_main
);
2115 map
->old_tree
= NULL
;
2116 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2117 bp
= streamer_read_bitpack (ib_main
);
2118 map
->replace_p
= bp_unpack_value (&bp
, 1);
2119 map
->ref_p
= bp_unpack_value (&bp
, 1);
2121 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2122 input_edge_opt_summary (e
, ib_main
);
2123 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2124 input_edge_opt_summary (e
, ib_main
);
2127 /* Read section in file FILE_DATA of length LEN with data DATA. */
2130 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2131 const char *data
, size_t len
,
2132 vec
<symtab_node
*> nodes
)
2134 const struct lto_function_header
*header
=
2135 (const struct lto_function_header
*) data
;
2136 const int cfg_offset
= sizeof (struct lto_function_header
);
2137 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2138 const int string_offset
= main_offset
+ header
->main_size
;
2139 struct data_in
*data_in
;
2143 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2144 header
->main_size
, file_data
->mode_table
);
2147 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2148 header
->string_size
, vNULL
);
2149 count
= streamer_read_uhwi (&ib_main
);
2151 for (i
= 0; i
< count
; i
++)
2153 int ref
= streamer_read_uhwi (&ib_main
);
2154 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2157 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2159 lto_data_in_delete (data_in
);
2162 /* Input optimization summary of cgraph. */
2165 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2167 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2168 struct lto_file_decl_data
*file_data
;
2171 while ((file_data
= file_data_vec
[j
++]))
2175 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2179 input_cgraph_opt_section (file_data
, data
, len
, nodes
);