1 /* Write and read the cgraph to the memory mapped representation of a
4 Copyright (C) 2009-2024 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"
31 #include "stringpool.h"
32 #include "tree-streamer.h"
34 #include "tree-pass.h"
37 #include "pass_manager.h"
38 #include "ipa-utils.h"
39 #include "omp-offload.h"
40 #include "omp-general.h"
41 #include "stringpool.h"
43 #include "alloc-pool.h"
44 #include "symbol-summary.h"
45 #include "symtab-thunks.h"
46 #include "symtab-clones.h"
48 /* True when asm nodes has been output. */
49 bool asm_nodes_output
= false;
51 static void output_cgraph_opt_summary (void);
52 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
54 /* Number of LDPR values known to GCC. */
55 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
57 /* Cgraph streaming is organized as set of record whose type
58 is indicated by a tag. */
61 /* Must leave 0 for the stopper. */
63 /* Cgraph node without body available. */
64 LTO_symtab_unavail_node
= 1,
65 /* Cgraph node with function body. */
66 LTO_symtab_analyzed_node
,
69 LTO_symtab_indirect_edge
,
71 LTO_symtab_indirect_function
,
75 /* Create a new symtab encoder.
76 if FOR_INPUT, the encoder allocate only datastructures needed
77 to read the symtab. */
80 lto_symtab_encoder_new (bool for_input
)
82 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
85 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
86 encoder
->nodes
.create (0);
91 /* Delete ENCODER and its components. */
94 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
96 encoder
->nodes
.release ();
103 /* Return the existing reference number of NODE in the symtab encoder in
104 output block OB. Assign a new reference if this is the first time
108 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
115 lto_encoder_entry entry
= {node
, false, false, false};
117 ref
= encoder
->nodes
.length ();
118 encoder
->nodes
.safe_push (entry
);
122 size_t *slot
= encoder
->map
->get (node
);
125 lto_encoder_entry entry
= {node
, false, false, false};
126 ref
= encoder
->nodes
.length ();
128 encoder
->map
->put (node
, ref
+ 1);
129 encoder
->nodes
.safe_push (entry
);
137 /* Remove NODE from encoder. */
140 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
144 lto_encoder_entry last_node
;
146 size_t *slot
= encoder
->map
->get (node
);
147 if (slot
== NULL
|| !*slot
)
151 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
153 /* Remove from vector. We do this by swapping node with the last element
155 last_node
= encoder
->nodes
.pop ();
156 if (last_node
.node
!= node
)
158 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
160 /* Move the last element to the original spot of NODE. */
161 encoder
->nodes
[index
] = last_node
;
164 /* Remove element from hash table. */
165 encoder
->map
->remove (node
);
170 /* Return TRUE if we should encode the body of NODE (if any). */
173 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
174 struct cgraph_node
*node
)
176 int index
= lto_symtab_encoder_lookup (encoder
, node
);
177 return encoder
->nodes
[index
].body
;
180 /* Specify that we encode the body of NODE in this partition. */
183 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
184 struct cgraph_node
*node
)
186 int index
= lto_symtab_encoder_encode (encoder
, node
);
187 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
188 encoder
->nodes
[index
].body
= true;
191 /* Return TRUE if we should encode initializer of NODE (if any). */
194 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
197 int index
= lto_symtab_encoder_lookup (encoder
, node
);
198 if (index
== LCC_NOT_FOUND
)
200 return encoder
->nodes
[index
].initializer
;
203 /* Specify that we should encode initializer of NODE (if any). */
206 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
209 int index
= lto_symtab_encoder_lookup (encoder
, node
);
210 encoder
->nodes
[index
].initializer
= true;
213 /* Return TRUE if NODE is in this partition. */
216 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder
,
219 int index
= lto_symtab_encoder_lookup (encoder
, node
);
220 if (index
== LCC_NOT_FOUND
)
222 return encoder
->nodes
[index
].in_partition
;
225 /* Specify that NODE is in this partition. */
228 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
231 int index
= lto_symtab_encoder_encode (encoder
, node
);
232 encoder
->nodes
[index
].in_partition
= true;
235 /* Output the cgraph EDGE to OB using ENCODER. */
238 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
239 lto_symtab_encoder_t encoder
)
245 if (edge
->indirect_unknown_callee
)
246 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
247 LTO_symtab_indirect_edge
);
249 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
252 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
253 gcc_assert (ref
!= LCC_NOT_FOUND
);
254 streamer_write_hwi_stream (ob
->main_stream
, ref
);
256 if (!edge
->indirect_unknown_callee
)
258 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
259 gcc_assert (ref
!= LCC_NOT_FOUND
);
260 streamer_write_hwi_stream (ob
->main_stream
, ref
);
263 edge
->count
.stream_out (ob
->main_stream
);
265 bp
= bitpack_create (ob
->main_stream
);
266 uid
= !edge
->call_stmt
? edge
->lto_stmt_uid
267 : gimple_uid (edge
->call_stmt
) + 1;
268 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
269 CIF_N_REASONS
, edge
->inline_failed
);
270 gcc_checking_assert (uid
|| edge
->caller
->thunk
);
271 bp_pack_var_len_unsigned (&bp
, uid
);
272 bp_pack_value (&bp
, edge
->speculative_id
, 16);
273 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
274 bp_pack_value (&bp
, edge
->speculative
, 1);
275 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
276 gcc_assert (!edge
->call_stmt_cannot_inline_p
277 || edge
->inline_failed
!= CIF_BODY_NOT_AVAILABLE
);
278 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
279 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
280 if (edge
->indirect_unknown_callee
)
282 int flags
= edge
->indirect_info
->ecf_flags
;
283 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
284 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
285 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
286 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
287 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
288 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
289 /* Flags that should not appear on indirect calls. */
290 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
296 bp_pack_value (&bp
, edge
->indirect_info
->num_speculative_call_targets
,
299 streamer_write_bitpack (&bp
);
302 /* Return if NODE contain references from other partitions. */
305 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
308 struct ipa_ref
*ref
= NULL
;
310 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
312 /* Ignore references from non-offloadable nodes while streaming NODE into
313 offload LTO section. */
314 if (!ref
->referring
->need_lto_streaming
)
317 if (ref
->referring
->in_other_partition
318 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
324 /* Return true when node is reachable from other partition. */
327 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
329 struct cgraph_edge
*e
;
330 if (!node
->definition
)
332 if (node
->inlined_to
)
334 for (e
= node
->callers
; e
; e
= e
->next_caller
)
336 /* Ignore references from non-offloadable nodes while streaming NODE into
337 offload LTO section. */
338 if (!e
->caller
->need_lto_streaming
)
341 if (e
->caller
->in_other_partition
342 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
348 /* Return if NODE contain references from other partitions. */
351 referenced_from_this_partition_p (symtab_node
*node
,
352 lto_symtab_encoder_t encoder
)
355 struct ipa_ref
*ref
= NULL
;
357 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
358 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
363 /* Return true when node is reachable from other partition. */
366 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
368 struct cgraph_edge
*e
;
369 for (e
= node
->callers
; e
; e
= e
->next_caller
)
370 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
375 /* Output the cgraph NODE to OB. ENCODER is used to find the
376 reference number of NODE->inlined_to. SET is the set of nodes we
377 are writing to the current file. If NODE is not in SET, then NODE
378 is a boundary of a cgraph_node_set and we pretend NODE just has a
379 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
380 that have had their callgraph node written so far. This is used to
381 determine if NODE is a clone of a previously written node. */
384 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
385 lto_symtab_encoder_t encoder
)
391 bool in_other_partition
= false;
392 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
393 ipa_opt_pass_d
*pass
;
399 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
401 if (node
->analyzed
&& (!boundary_p
|| node
->alias
402 || (node
->thunk
&& !node
->inlined_to
)))
403 tag
= LTO_symtab_analyzed_node
;
405 tag
= LTO_symtab_unavail_node
;
407 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
409 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
411 /* In WPA mode, we only output part of the call-graph. Also, we
412 fake cgraph node attributes. There are two cases that we care.
414 Boundary nodes: There are nodes that are not part of SET but are
415 called from within SET. We artificially make them look like
416 externally visible nodes with no function body.
418 Cherry-picked nodes: These are nodes we pulled from other
419 translation units into SET during IPA-inlining. We make them as
420 local static nodes to prevent clashes with other local statics. */
421 if (boundary_p
&& node
->analyzed
422 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
424 /* Inline clones cannot be part of boundary.
425 gcc_assert (!node->inlined_to);
427 FIXME: At the moment they can be, when partition contains an inline
428 clone that is clone of inline clone from outside partition. We can
429 reshape the clone tree and make other tree to be the root, but it
430 needs a bit extra work and will be promplty done by cgraph_remove_node
431 after reading back. */
432 in_other_partition
= 1;
434 else if (UNLIKELY (lto_stream_offload_p
435 && lookup_attribute ("omp target device_ancestor_host",
436 DECL_ATTRIBUTES (node
->decl
))))
437 /* This symbol is only used as argument to IFN_GOMP_TARGET_REV; this IFN
438 is ignored on ACCEL_COMPILER. Thus, mark it as in_other_partition to silence
439 verify_node_partition diagnostic. */
440 in_other_partition
= 1;
442 clone_of
= node
->clone_of
;
444 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
445 if (clone_of
->prev_sibling_clone
)
446 clone_of
= clone_of
->prev_sibling_clone
;
448 clone_of
= clone_of
->clone_of
;
450 /* See if body of the master function is output. If not, we are seeing only
451 an declaration and we do not need to pass down clone tree. */
452 ultimate_clone_of
= clone_of
;
453 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
454 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
456 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
459 if (tag
== LTO_symtab_analyzed_node
)
460 gcc_assert (clone_of
|| !node
->clone_of
);
462 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
464 streamer_write_hwi_stream (ob
->main_stream
, ref
);
467 lto_output_fn_decl_ref (ob
->decl_state
, ob
->main_stream
, node
->decl
);
468 node
->count
.stream_out (ob
->main_stream
);
469 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
471 streamer_write_hwi_stream (ob
->main_stream
,
472 node
->ipa_transforms_to_apply
.length ());
473 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
474 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
476 if (tag
== LTO_symtab_analyzed_node
)
478 if (node
->inlined_to
)
480 ref
= lto_symtab_encoder_lookup (encoder
, node
->inlined_to
);
481 gcc_assert (ref
!= LCC_NOT_FOUND
);
486 streamer_write_hwi_stream (ob
->main_stream
, ref
);
489 group
= node
->get_comdat_group ();
491 comdat
= IDENTIFIER_POINTER (group
);
494 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
498 if (node
->same_comdat_group
)
501 for (struct symtab_node
*n
= node
->same_comdat_group
;
502 ref
== LCC_NOT_FOUND
&& n
!= node
; n
= n
->same_comdat_group
)
503 ref
= lto_symtab_encoder_lookup (encoder
, n
);
507 streamer_write_hwi_stream (ob
->main_stream
, ref
);
510 section
= node
->get_section ();
514 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
516 bp
= bitpack_create (ob
->main_stream
);
517 bp_pack_value (&bp
, node
->local
, 1);
518 bp_pack_value (&bp
, node
->externally_visible
, 1);
519 bp_pack_value (&bp
, node
->no_reorder
, 1);
520 bp_pack_value (&bp
, node
->definition
, 1);
521 bp_pack_value (&bp
, node
->versionable
, 1);
522 bp_pack_value (&bp
, node
->can_change_signature
, 1);
523 bp_pack_value (&bp
, node
->redefined_extern_inline
, 1);
524 bp_pack_value (&bp
, node
->force_output
, 1);
525 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
526 bp_pack_value (&bp
, node
->unique_name
, 1);
527 bp_pack_value (&bp
, node
->body_removed
, 1);
528 bp_pack_value (&bp
, node
->semantic_interposition
, 1);
529 bp_pack_value (&bp
, node
->implicit_section
, 1);
530 bp_pack_value (&bp
, node
->address_taken
, 1);
531 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
532 && node
->get_partitioning_class () == SYMBOL_PARTITION
533 && (reachable_from_other_partition_p (node
, encoder
)
534 || referenced_from_other_partition_p (node
, encoder
)), 1);
535 bp_pack_value (&bp
, node
->lowered
, 1);
536 bp_pack_value (&bp
, in_other_partition
, 1);
537 bp_pack_value (&bp
, node
->alias
, 1);
538 bp_pack_value (&bp
, node
->transparent_alias
, 1);
539 bp_pack_value (&bp
, node
->weakref
, 1);
540 bp_pack_value (&bp
, node
->symver
, 1);
541 bp_pack_value (&bp
, node
->frequency
, 2);
542 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
543 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
544 bp_pack_value (&bp
, node
->tm_clone
, 1);
545 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
546 bp_pack_value (&bp
, node
->icf_merged
, 1);
547 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
548 bp_pack_value (&bp
, node
->merged_comdat
, 1);
549 bp_pack_value (&bp
, node
->merged_extern_inline
, 1);
550 bp_pack_value (&bp
, node
->thunk
, 1);
551 bp_pack_value (&bp
, node
->parallelized_function
, 1);
552 bp_pack_value (&bp
, node
->declare_variant_alt
, 1);
553 bp_pack_value (&bp
, node
->calls_declare_variant_alt
, 1);
555 /* Stream thunk info always because we use it in
556 ipa_polymorphic_call_context::ipa_polymorphic_call_context
557 to properly interpret THIS pointers for thunks that has been converted
559 struct thunk_info
*thunk
= node
->definition
? thunk_info::get (node
) : NULL
;
561 bp_pack_value (&bp
, thunk
!= NULL
, 1);
563 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
565 /* When doing incremental link, we will get new resolution
566 info next time we process the file. */
567 flag_incremental_link
== INCREMENTAL_LINK_LTO
568 ? LDPR_UNKNOWN
: node
->resolution
);
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 streamer_write_hwi_stream (ob
->main_stream
, node
->profile_id
);
574 streamer_write_hwi_stream (ob
->main_stream
, node
->unit_id
);
575 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
576 streamer_write_hwi_stream (ob
->main_stream
, node
->get_init_priority ());
577 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
578 streamer_write_hwi_stream (ob
->main_stream
, node
->get_fini_priority ());
581 thunk_info::get (node
)->stream_out (ob
);
584 /* Output the varpool NODE to OB.
585 If NODE is not in SET, then NODE is a boundary. */
588 lto_output_varpool_node (struct lto_simple_output_block
*ob
, varpool_node
*node
,
589 lto_symtab_encoder_t encoder
)
591 bool boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
592 bool encode_initializer_p
594 && lto_symtab_encoder_encode_initializer_p (encoder
, node
));
601 gcc_assert (!encode_initializer_p
|| node
->definition
);
602 gcc_assert (boundary_p
|| encode_initializer_p
);
604 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
605 LTO_symtab_variable
);
606 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
607 lto_output_var_decl_ref (ob
->decl_state
, ob
->main_stream
, node
->decl
);
608 bp
= bitpack_create (ob
->main_stream
);
609 bp_pack_value (&bp
, node
->externally_visible
, 1);
610 bp_pack_value (&bp
, node
->no_reorder
, 1);
611 bp_pack_value (&bp
, node
->force_output
, 1);
612 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
613 bp_pack_value (&bp
, node
->unique_name
, 1);
616 || (!encode_initializer_p
&& !node
->alias
&& node
->definition
),
618 bp_pack_value (&bp
, node
->semantic_interposition
, 1);
619 bp_pack_value (&bp
, node
->implicit_section
, 1);
620 bp_pack_value (&bp
, node
->writeonly
, 1);
621 bp_pack_value (&bp
, node
->definition
&& (encode_initializer_p
|| node
->alias
),
623 bp_pack_value (&bp
, node
->alias
, 1);
624 bp_pack_value (&bp
, node
->transparent_alias
, 1);
625 bp_pack_value (&bp
, node
->weakref
, 1);
626 bp_pack_value (&bp
, node
->symver
, 1);
627 bp_pack_value (&bp
, node
->analyzed
&& (!boundary_p
|| node
->alias
), 1);
628 gcc_assert (node
->definition
|| !node
->analyzed
);
629 /* Constant pool initializers can be de-unified into individual ltrans units.
630 FIXME: Alternatively at -Os we may want to avoid generating for them the local
631 labels and share them across LTRANS partitions. */
632 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
634 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
635 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
639 bp_pack_value (&bp
, node
->definition
640 && referenced_from_other_partition_p (node
, encoder
), 1);
641 bp_pack_value (&bp
, node
->analyzed
642 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
643 /* in_other_partition. */
645 bp_pack_value (&bp
, node
->tls_model
, 3);
646 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
647 bp_pack_value (&bp
, node
->dynamically_initialized
, 1);
648 streamer_write_bitpack (&bp
);
650 group
= node
->get_comdat_group ();
652 comdat
= IDENTIFIER_POINTER (group
);
655 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
659 if (node
->same_comdat_group
)
662 for (struct symtab_node
*n
= node
->same_comdat_group
;
663 ref
== LCC_NOT_FOUND
&& n
!= node
; n
= n
->same_comdat_group
)
664 ref
= lto_symtab_encoder_lookup (encoder
, n
);
668 streamer_write_hwi_stream (ob
->main_stream
, ref
);
671 section
= node
->get_section ();
674 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
676 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
677 LDPR_NUM_KNOWN
, node
->resolution
);
680 /* Output the varpool NODE to OB.
681 If NODE is not in SET, then NODE is a boundary. */
684 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
685 lto_symtab_encoder_t encoder
)
689 int uid
= !ref
->stmt
? ref
->lto_stmt_uid
: gimple_uid (ref
->stmt
) + 1;
690 struct cgraph_node
*node
;
692 bp
= bitpack_create (ob
->main_stream
);
693 bp_pack_value (&bp
, ref
->use
, 3);
694 bp_pack_value (&bp
, ref
->speculative
, 1);
695 streamer_write_bitpack (&bp
);
696 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
697 gcc_assert (nref
!= LCC_NOT_FOUND
);
698 streamer_write_hwi_stream (ob
->main_stream
, nref
);
700 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
704 uid
= gimple_uid (ref
->stmt
) + 1;
705 streamer_write_hwi_stream (ob
->main_stream
, uid
);
706 bp_pack_value (&bp
, ref
->speculative_id
, 16);
707 streamer_write_bitpack (&bp
);
711 /* Stream out profile_summary to OB. */
714 output_profile_summary (struct lto_simple_output_block
*ob
)
718 /* We do not output num and run_max, they are not used by
719 GCC profile feedback and they are difficult to merge from multiple
721 unsigned runs
= (profile_info
->runs
);
722 streamer_write_uhwi_stream (ob
->main_stream
, runs
);
724 /* IPA-profile computes hot bb threshold based on cumulated
725 whole program profile. We need to stream it down to ltrans. */
727 streamer_write_gcov_count_stream (ob
->main_stream
,
728 get_hot_bb_threshold ());
731 streamer_write_uhwi_stream (ob
->main_stream
, 0);
734 /* Output all callees or indirect outgoing edges. EDGE must be the first such
738 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
739 struct lto_simple_output_block
*ob
,
740 lto_symtab_encoder_t encoder
)
745 /* Output edges in backward direction, so the reconstructed callgraph match
746 and it is easy to associate call sites in the IPA pass summaries. */
747 while (edge
->next_callee
)
748 edge
= edge
->next_callee
;
749 for (; edge
; edge
= edge
->prev_callee
)
750 lto_output_edge (ob
, edge
, encoder
);
753 /* Output the part of the cgraph in SET. */
756 output_refs (lto_symtab_encoder_t encoder
)
758 struct lto_simple_output_block
*ob
;
762 ob
= lto_create_simple_output_block (LTO_section_refs
);
764 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
766 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
768 /* IPA_REF_ALIAS references are always preserved
769 in the boundary. Alias node can't have other references and
770 can be always handled as if it's not in the boundary. */
771 if (!node
->alias
&& !lto_symtab_encoder_in_partition_p (encoder
, node
))
774 count
= node
->ref_list
.nreferences ();
777 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
778 streamer_write_uhwi_stream (ob
->main_stream
,
779 lto_symtab_encoder_lookup (encoder
, node
));
780 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
781 lto_output_ref (ob
, ref
, encoder
);
783 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
784 if (cnode
->declare_variant_alt
)
785 omp_lto_output_declare_variant_alt (ob
, cnode
, encoder
);
788 streamer_write_uhwi_stream (ob
->main_stream
, 0);
790 lto_destroy_simple_output_block (ob
);
793 /* Add NODE into encoder as well as nodes it is cloned from.
794 Do it in a way so clones appear first. */
797 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
801 add_node_to (encoder
, node
->clone_of
, include_body
);
803 lto_set_symtab_encoder_encode_body (encoder
, node
);
804 lto_symtab_encoder_encode (encoder
, node
);
807 /* Add all references in NODE to encoders. */
810 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
813 struct ipa_ref
*ref
= NULL
;
814 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
815 if (is_a
<cgraph_node
*> (ref
->referred
))
816 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
818 lto_symtab_encoder_encode (encoder
, ref
->referred
);
821 /* Select what needs to be streamed out. In regular lto mode stream everything.
822 In offload lto mode stream only nodes marked as offloadable. */
824 select_what_to_stream (void)
826 struct symtab_node
*snode
;
827 FOR_EACH_SYMBOL (snode
)
828 snode
->need_lto_streaming
= !lto_stream_offload_p
|| snode
->offloadable
;
831 /* Find all symbols we want to stream into given partition and insert them
834 The function actually replaces IN_ENCODER by new one. The reason is that
835 streaming code needs clone's origin to be streamed before clone. This
836 means that we need to insert the nodes in specific order. This order is
837 ignored by the partitioning logic earlier. */
840 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
842 struct cgraph_edge
*edge
;
844 lto_symtab_encoder_t encoder
;
845 lto_symtab_encoder_iterator lsei
;
846 hash_set
<void *> reachable_call_targets
;
848 encoder
= lto_symtab_encoder_new (false);
850 /* Go over all entries in the IN_ENCODER and duplicate them to
851 ENCODER. At the same time insert masters of clones so
852 every master appears before clone. */
853 for (lsei
= lsei_start_function_in_partition (in_encoder
);
854 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
856 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
857 if (!node
->need_lto_streaming
)
859 add_node_to (encoder
, node
, true);
860 lto_set_symtab_encoder_in_partition (encoder
, node
);
861 create_references (encoder
, node
);
863 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
864 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
866 varpool_node
*vnode
= lsei_varpool_node (lsei
);
868 if (!vnode
->need_lto_streaming
)
870 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
871 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
872 create_references (encoder
, vnode
);
874 /* Pickle in also the initializer of all referenced readonly variables
875 to help folding. Constant pool variables are not shared, so we must
877 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
879 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
880 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
882 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
884 && (((vnode
->ctor_useable_for_folding_p ()
885 && (!DECL_VIRTUAL_P (vnode
->decl
)
887 || flag_ltrans_devirtualize
)))))
889 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
890 create_references (encoder
, vnode
);
895 /* Go over all the nodes again to include callees that are not in
897 for (lsei
= lsei_start_function_in_partition (encoder
);
898 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
900 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
901 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
903 struct cgraph_node
*callee
= edge
->callee
;
904 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
906 /* We should have moved all the inlines. */
907 gcc_assert (!callee
->inlined_to
);
908 add_node_to (encoder
, callee
, false);
911 /* Add all possible targets for late devirtualization. */
912 if (flag_ltrans_devirtualize
|| !flag_wpa
)
913 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
914 if (edge
->indirect_info
->polymorphic
)
919 vec
<cgraph_node
*>targets
920 = possible_polymorphic_call_targets
921 (edge
, &final
, &cache_token
);
922 if (cache_token
!= NULL
923 && !reachable_call_targets
.add (cache_token
))
925 for (i
= 0; i
< targets
.length (); i
++)
927 struct cgraph_node
*callee
= targets
[i
];
929 /* Adding an external declarations into the unit serves
930 no purpose and just increases its boundary. */
931 if (callee
->definition
932 && !lto_symtab_encoder_in_partition_p
935 gcc_assert (!callee
->inlined_to
);
936 add_node_to (encoder
, callee
, false);
942 /* Be sure to also insert alias targert and thunk callees. These needs
943 to stay to aid local calling conventions. */
944 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
946 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
947 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
949 if (node
->alias
&& node
->analyzed
)
950 create_references (encoder
, node
);
952 && cnode
->thunk
&& !cnode
->inlined_to
)
953 add_node_to (encoder
, cnode
->callees
->callee
, false);
954 while (node
->transparent_alias
&& node
->analyzed
)
956 node
= node
->get_alias_target ();
957 if (is_a
<cgraph_node
*> (node
))
958 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (node
),
961 lto_symtab_encoder_encode (encoder
, node
);
964 lto_symtab_encoder_delete (in_encoder
);
968 /* Output the part of the symtab in SET and VSET. */
973 struct cgraph_node
*node
;
974 struct lto_simple_output_block
*ob
;
976 lto_symtab_encoder_t encoder
;
979 output_cgraph_opt_summary ();
981 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
983 output_profile_summary (ob
);
985 /* An encoder for cgraph nodes should have been created by
986 ipa_write_summaries_1. */
987 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
988 encoder
= ob
->decl_state
->symtab_node_encoder
;
990 /* Write out the nodes. We must first output a node and then its clones,
991 otherwise at a time reading back the node there would be nothing to clone
993 n_nodes
= lto_symtab_encoder_size (encoder
);
994 for (i
= 0; i
< n_nodes
; i
++)
996 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
997 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
998 lto_output_node (ob
, cnode
, encoder
);
1000 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1003 /* Go over the nodes in SET again to write edges. */
1004 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1006 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
, i
));
1008 && ((node
->thunk
&& !node
->inlined_to
)
1009 || lto_symtab_encoder_in_partition_p (encoder
, node
)))
1011 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1012 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1016 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1018 lto_destroy_simple_output_block (ob
);
1020 /* Emit toplevel asms.
1021 When doing WPA we must output every asm just once. Since we do not partition asm
1022 nodes at all, output them to first output. This is kind of hack, but should work
1024 if (!asm_nodes_output
&& !lto_stream_offload_p
)
1026 asm_nodes_output
= true;
1027 lto_output_toplevel_asms ();
1030 output_refs (encoder
);
1033 /* Return identifier encoded in IB as a plain string. */
1036 read_identifier (class lto_input_block
*ib
)
1038 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1041 if (ib
->data
[ib
->p
+ len
])
1042 lto_section_overrun (ib
);
1048 id
= get_identifier (ib
->data
+ ib
->p
);
1053 /* Return string encoded in IB, NULL if string is empty. */
1056 read_string (class lto_input_block
*ib
)
1058 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1061 if (ib
->data
[ib
->p
+ len
])
1062 lto_section_overrun (ib
);
1068 str
= ib
->data
+ ib
->p
;
1073 /* Output function/variable tables that will allow libgomp to look up offload
1075 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1076 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1077 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1080 output_offload_tables (void)
1082 bool output_requires
= (flag_openmp
1083 && (omp_requires_mask
& OMP_REQUIRES_TARGET_USED
) != 0);
1084 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
)
1085 && !output_requires
)
1088 struct lto_simple_output_block
*ob
1089 = lto_create_simple_output_block (LTO_section_offload_table
);
1091 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1093 symtab_node
*node
= symtab_node::get ((*offload_funcs
)[i
]);
1096 node
->force_output
= true;
1097 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1098 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1099 lto_output_fn_decl_ref (ob
->decl_state
, ob
->main_stream
,
1100 (*offload_funcs
)[i
]);
1103 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1105 symtab_node
*node
= symtab_node::get ((*offload_vars
)[i
]);
1108 node
->force_output
= true;
1109 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1110 LTO_symtab_last_tag
, LTO_symtab_variable
);
1111 lto_output_var_decl_ref (ob
->decl_state
, ob
->main_stream
,
1112 (*offload_vars
)[i
]);
1115 for (unsigned i
= 0; i
< vec_safe_length (offload_ind_funcs
); i
++)
1117 symtab_node
*node
= symtab_node::get ((*offload_ind_funcs
)[i
]);
1120 node
->force_output
= true;
1121 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1122 LTO_symtab_last_tag
, LTO_symtab_indirect_function
);
1123 lto_output_fn_decl_ref (ob
->decl_state
, ob
->main_stream
,
1124 (*offload_ind_funcs
)[i
]);
1127 if (output_requires
)
1129 HOST_WIDE_INT val
= ((HOST_WIDE_INT
) omp_requires_mask
1130 & (OMP_REQUIRES_UNIFIED_ADDRESS
1131 | OMP_REQUIRES_UNIFIED_SHARED_MEMORY
1132 | OMP_REQUIRES_SELF_MAPS
1133 | OMP_REQUIRES_REVERSE_OFFLOAD
1134 | OMP_REQUIRES_TARGET_USED
));
1135 /* (Mis)use LTO_symtab_edge for this variable. */
1136 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1137 LTO_symtab_last_tag
, LTO_symtab_edge
);
1138 streamer_write_hwi_stream (ob
->main_stream
, val
);
1141 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1142 lto_destroy_simple_output_block (ob
);
1145 /* Verify the partitioning of NODE. */
1148 verify_node_partition (symtab_node
*node
)
1153 #ifdef ACCEL_COMPILER
1154 if (node
->in_other_partition
)
1156 if (TREE_CODE (node
->decl
) == FUNCTION_DECL
)
1158 if (lookup_attribute ("omp target device_ancestor_host",
1159 DECL_ATTRIBUTES (node
->decl
)) != NULL
)
1161 error_at (DECL_SOURCE_LOCATION (node
->decl
),
1162 "function %qs has been referenced in offloaded code but"
1163 " hasn%'t been marked to be included in the offloaded code",
1166 else if (VAR_P (node
->decl
))
1167 error_at (DECL_SOURCE_LOCATION (node
->decl
),
1168 "variable %qs has been referenced in offloaded code but"
1169 " hasn%'t been marked to be included in the offloaded code",
1175 gcc_assert (!node
->in_other_partition
1176 && !node
->used_from_other_partition
);
1180 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1181 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1182 NODE or to replace the values in it, for instance because the first
1183 time we saw it, the function body was not available but now it
1184 is. BP is a bitpack with all the bitflags for NODE read from the
1185 stream. Initialize HAS_THUNK_INFO to indicate if thunk info should
1189 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1190 struct cgraph_node
*node
,
1191 enum LTO_symtab_tags tag
,
1192 struct bitpack_d
*bp
, bool *has_thunk_info
)
1194 node
->aux
= (void *) tag
;
1195 node
->lto_file_data
= file_data
;
1197 node
->local
= bp_unpack_value (bp
, 1);
1198 node
->externally_visible
= bp_unpack_value (bp
, 1);
1199 node
->no_reorder
= bp_unpack_value (bp
, 1);
1200 node
->definition
= bp_unpack_value (bp
, 1);
1201 node
->versionable
= bp_unpack_value (bp
, 1);
1202 node
->can_change_signature
= bp_unpack_value (bp
, 1);
1203 node
->redefined_extern_inline
= bp_unpack_value (bp
, 1);
1204 node
->force_output
= bp_unpack_value (bp
, 1);
1205 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1206 node
->unique_name
= bp_unpack_value (bp
, 1);
1207 node
->body_removed
= bp_unpack_value (bp
, 1);
1208 node
->semantic_interposition
= bp_unpack_value (bp
, 1);
1209 node
->implicit_section
= bp_unpack_value (bp
, 1);
1210 node
->address_taken
= bp_unpack_value (bp
, 1);
1211 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1212 node
->lowered
= bp_unpack_value (bp
, 1);
1213 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1214 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1215 if (node
->in_other_partition
1216 /* Avoid updating decl when we are seeing just inline clone.
1217 When inlining function that has functions already inlined into it,
1218 we produce clones of inline clones.
1220 WPA partitioning might put each clone into different unit and
1221 we might end up streaming inline clone from other partition
1222 to support clone we are interested in. */
1224 || node
->clone_of
->decl
!= node
->decl
))
1226 DECL_EXTERNAL (node
->decl
) = 1;
1227 TREE_STATIC (node
->decl
) = 0;
1229 node
->alias
= bp_unpack_value (bp
, 1);
1230 node
->transparent_alias
= bp_unpack_value (bp
, 1);
1231 node
->weakref
= bp_unpack_value (bp
, 1);
1232 node
->symver
= bp_unpack_value (bp
, 1);
1233 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1234 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1235 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1236 node
->tm_clone
= bp_unpack_value (bp
, 1);
1237 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1238 node
->icf_merged
= bp_unpack_value (bp
, 1);
1239 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1240 node
->merged_comdat
= bp_unpack_value (bp
, 1);
1241 node
->merged_extern_inline
= bp_unpack_value (bp
, 1);
1242 node
->thunk
= bp_unpack_value (bp
, 1);
1243 node
->parallelized_function
= bp_unpack_value (bp
, 1);
1244 node
->declare_variant_alt
= bp_unpack_value (bp
, 1);
1245 node
->calls_declare_variant_alt
= bp_unpack_value (bp
, 1);
1246 *has_thunk_info
= bp_unpack_value (bp
, 1);
1247 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1249 node
->split_part
= bp_unpack_value (bp
, 1);
1250 verify_node_partition (node
);
1253 /* Return string alias is alias of. */
1256 get_alias_symbol (tree decl
)
1258 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1259 return get_identifier (TREE_STRING_POINTER
1260 (TREE_VALUE (TREE_VALUE (alias
))));
1263 /* Read a node from input_block IB. TAG is the node's tag just read.
1264 Return the node read or overwriten. */
1266 static struct cgraph_node
*
1267 input_node (struct lto_file_decl_data
*file_data
,
1268 class lto_input_block
*ib
,
1269 enum LTO_symtab_tags tag
,
1270 vec
<symtab_node
*> nodes
)
1272 gcc::pass_manager
*passes
= g
->get_passes ();
1274 struct cgraph_node
*node
;
1275 struct bitpack_d bp
;
1276 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1281 const char *section
;
1282 order
= streamer_read_hwi (ib
) + file_data
->order_base
;
1283 clone_ref
= streamer_read_hwi (ib
);
1284 bool has_thunk_info
;
1286 fn_decl
= lto_input_fn_decl_ref (ib
, file_data
);
1288 if (clone_ref
!= LCC_NOT_FOUND
)
1290 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1291 profile_count::uninitialized (), false,
1292 vNULL
, false, NULL
, NULL
);
1296 /* Declaration of functions can be already merged with a declaration
1297 from other input file. We keep cgraph unmerged until after streaming
1298 of ipa passes is done. Alays forcingly create a fresh node. */
1299 node
= symtab
->create_empty ();
1300 node
->decl
= fn_decl
;
1301 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl
)))
1302 node
->ifunc_resolver
= 1;
1303 node
->register_symbol ();
1306 node
->order
= order
;
1307 if (order
>= symtab
->order
)
1308 symtab
->order
= order
+ 1;
1310 node
->count
= profile_count::stream_in (ib
);
1311 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1313 count
= streamer_read_hwi (ib
);
1314 node
->ipa_transforms_to_apply
= vNULL
;
1315 for (i
= 0; i
< count
; i
++)
1318 int pid
= streamer_read_hwi (ib
);
1320 gcc_assert (pid
< passes
->passes_by_id_size
);
1321 pass
= passes
->passes_by_id
[pid
];
1322 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1325 if (tag
== LTO_symtab_analyzed_node
)
1326 ref
= streamer_read_hwi (ib
);
1328 group
= read_identifier (ib
);
1330 ref2
= streamer_read_hwi (ib
);
1332 /* Make sure that we have not read this node before. Nodes that
1333 have already been read will have their tag stored in the 'aux'
1334 field. Since built-in functions can be referenced in multiple
1335 functions, they are expected to be read more than once. */
1336 if (node
->aux
&& !fndecl_built_in_p (node
->decl
))
1337 internal_error ("bytecode stream: found multiple instances of cgraph "
1338 "node with uid %d", node
->get_uid ());
1340 node
->tp_first_run
= streamer_read_uhwi (ib
);
1342 bp
= streamer_read_bitpack (ib
);
1344 input_overwrite_node (file_data
, node
, tag
, &bp
, &has_thunk_info
);
1346 /* Store a reference for now, and fix up later to be a pointer. */
1347 node
->inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1351 node
->set_comdat_group (group
);
1352 /* Store a reference for now, and fix up later to be a pointer. */
1353 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1356 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1357 section
= read_string (ib
);
1359 node
->set_section_for_node (section
);
1361 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1362 node
->alias_target
= get_alias_symbol (node
->decl
);
1363 node
->profile_id
= streamer_read_hwi (ib
);
1364 node
->unit_id
= streamer_read_hwi (ib
) + file_data
->unit_base
;
1365 if (symtab
->max_unit
< node
->unit_id
)
1366 symtab
->max_unit
= node
->unit_id
;
1367 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1368 node
->set_init_priority (streamer_read_hwi (ib
));
1369 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1370 node
->set_fini_priority (streamer_read_hwi (ib
));
1373 thunk_info::get_create (node
)->stream_in (ib
);
1378 /* Read a node from input_block IB. TAG is the node's tag just read.
1379 Return the node read or overwriten. */
1381 static varpool_node
*
1382 input_varpool_node (struct lto_file_decl_data
*file_data
,
1383 class lto_input_block
*ib
)
1387 struct bitpack_d bp
;
1388 int ref
= LCC_NOT_FOUND
;
1391 const char *section
;
1393 order
= streamer_read_hwi (ib
) + file_data
->order_base
;
1394 var_decl
= lto_input_var_decl_ref (ib
, file_data
);
1396 /* Declaration of functions can be already merged with a declaration
1397 from other input file. We keep cgraph unmerged until after streaming
1398 of ipa passes is done. Alays forcingly create a fresh node. */
1399 node
= varpool_node::create_empty ();
1400 node
->decl
= var_decl
;
1401 node
->register_symbol ();
1403 node
->order
= order
;
1404 if (order
>= symtab
->order
)
1405 symtab
->order
= order
+ 1;
1406 node
->lto_file_data
= file_data
;
1408 bp
= streamer_read_bitpack (ib
);
1409 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1410 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1411 node
->force_output
= bp_unpack_value (&bp
, 1);
1412 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1413 node
->unique_name
= bp_unpack_value (&bp
, 1);
1414 node
->body_removed
= bp_unpack_value (&bp
, 1);
1415 node
->semantic_interposition
= bp_unpack_value (&bp
, 1);
1416 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1417 node
->writeonly
= bp_unpack_value (&bp
, 1);
1418 node
->definition
= bp_unpack_value (&bp
, 1);
1419 node
->alias
= bp_unpack_value (&bp
, 1);
1420 node
->transparent_alias
= bp_unpack_value (&bp
, 1);
1421 node
->weakref
= bp_unpack_value (&bp
, 1);
1422 node
->symver
= bp_unpack_value (&bp
, 1);
1423 node
->analyzed
= bp_unpack_value (&bp
, 1);
1424 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1425 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1426 if (node
->in_other_partition
)
1428 DECL_EXTERNAL (node
->decl
) = 1;
1429 TREE_STATIC (node
->decl
) = 0;
1431 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1432 node
->alias_target
= get_alias_symbol (node
->decl
);
1433 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1434 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1435 node
->dynamically_initialized
= bp_unpack_value (&bp
, 1);
1436 group
= read_identifier (ib
);
1439 node
->set_comdat_group (group
);
1440 ref
= streamer_read_hwi (ib
);
1441 /* Store a reference for now, and fix up later to be a pointer. */
1442 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1445 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1446 section
= read_string (ib
);
1448 node
->set_section_for_node (section
);
1449 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1451 verify_node_partition (node
);
1455 /* Read a node from input_block IB. TAG is the node's tag just read.
1456 Return the node read or overwriten. */
1459 input_ref (class lto_input_block
*ib
,
1460 symtab_node
*referring_node
,
1461 vec
<symtab_node
*> nodes
)
1463 symtab_node
*node
= NULL
;
1464 struct bitpack_d bp
;
1465 enum ipa_ref_use use
;
1467 struct ipa_ref
*ref
;
1469 bp
= streamer_read_bitpack (ib
);
1470 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1471 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1472 node
= nodes
[streamer_read_hwi (ib
)];
1473 ref
= referring_node
->create_reference (node
, use
);
1474 ref
->speculative
= speculative
;
1475 if (is_a
<cgraph_node
*> (referring_node
))
1477 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1478 bp
= streamer_read_bitpack (ib
);
1479 ref
->speculative_id
= bp_unpack_value (&bp
, 16);
1483 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1484 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1485 edge being read is indirect (in the sense that it has
1486 indirect_unknown_callee set). */
1489 input_edge (class lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1492 struct cgraph_node
*caller
, *callee
;
1493 struct cgraph_edge
*edge
;
1494 unsigned int stmt_id
, speculative_id
;
1495 profile_count count
;
1496 cgraph_inline_failed_t inline_failed
;
1497 struct bitpack_d bp
;
1500 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1501 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1502 internal_error ("bytecode stream: no caller found while reading edge");
1506 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1507 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1508 internal_error ("bytecode stream: no callee found while reading edge");
1513 count
= profile_count::stream_in (ib
);
1515 bp
= streamer_read_bitpack (ib
);
1516 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1517 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1518 speculative_id
= bp_unpack_value (&bp
, 16);
1521 edge
= caller
->create_indirect_edge (NULL
, 0, count
);
1523 edge
= caller
->create_edge (callee
, NULL
, count
);
1525 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1526 edge
->speculative
= bp_unpack_value (&bp
, 1);
1527 edge
->lto_stmt_uid
= stmt_id
;
1528 edge
->speculative_id
= speculative_id
;
1529 edge
->inline_failed
= inline_failed
;
1530 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1531 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1532 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1535 if (bp_unpack_value (&bp
, 1))
1536 ecf_flags
|= ECF_CONST
;
1537 if (bp_unpack_value (&bp
, 1))
1538 ecf_flags
|= ECF_PURE
;
1539 if (bp_unpack_value (&bp
, 1))
1540 ecf_flags
|= ECF_NORETURN
;
1541 if (bp_unpack_value (&bp
, 1))
1542 ecf_flags
|= ECF_MALLOC
;
1543 if (bp_unpack_value (&bp
, 1))
1544 ecf_flags
|= ECF_NOTHROW
;
1545 if (bp_unpack_value (&bp
, 1))
1546 ecf_flags
|= ECF_RETURNS_TWICE
;
1547 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1549 edge
->indirect_info
->num_speculative_call_targets
1550 = bp_unpack_value (&bp
, 16);
1555 /* Read a cgraph from IB using the info in FILE_DATA. */
1557 static vec
<symtab_node
*>
1558 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1559 class lto_input_block
*ib
)
1561 enum LTO_symtab_tags tag
;
1562 vec
<symtab_node
*> nodes
= vNULL
;
1566 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1567 file_data
->order_base
= symtab
->order
;
1568 file_data
->unit_base
= symtab
->max_unit
+ 1;
1571 if (tag
== LTO_symtab_edge
)
1572 input_edge (ib
, nodes
, false);
1573 else if (tag
== LTO_symtab_indirect_edge
)
1574 input_edge (ib
, nodes
, true);
1575 else if (tag
== LTO_symtab_variable
)
1577 node
= input_varpool_node (file_data
, ib
);
1578 nodes
.safe_push (node
);
1579 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1583 node
= input_node (file_data
, ib
, tag
, nodes
);
1584 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1585 internal_error ("bytecode stream: found empty cgraph node");
1586 nodes
.safe_push (node
);
1587 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1590 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1593 lto_input_toplevel_asms (file_data
, file_data
->order_base
);
1595 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1598 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1599 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1601 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1604 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1606 ref
= (int) (intptr_t) cnode
->inlined_to
;
1608 /* We share declaration of builtins, so we may read same node twice. */
1613 /* Fixup inlined_to from reference to pointer. */
1614 if (ref
!= LCC_NOT_FOUND
)
1615 dyn_cast
<cgraph_node
*> (node
)->inlined_to
1616 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1618 cnode
->inlined_to
= NULL
;
1621 ref
= (int) (intptr_t) node
->same_comdat_group
;
1623 /* Fixup same_comdat_group from reference to pointer. */
1624 if (ref
!= LCC_NOT_FOUND
)
1625 node
->same_comdat_group
= nodes
[ref
];
1627 node
->same_comdat_group
= NULL
;
1629 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1630 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1634 /* Input ipa_refs. */
1637 input_refs (class lto_input_block
*ib
,
1638 vec
<symtab_node
*> nodes
)
1645 count
= streamer_read_uhwi (ib
);
1648 idx
= streamer_read_uhwi (ib
);
1652 input_ref (ib
, node
, nodes
);
1655 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1656 if (cnode
->declare_variant_alt
)
1657 omp_lto_input_declare_variant_alt (ib
, cnode
, nodes
);
1661 /* Input profile_info from IB. */
1663 input_profile_summary (class lto_input_block
*ib
,
1664 struct lto_file_decl_data
*file_data
)
1666 unsigned int runs
= streamer_read_uhwi (ib
);
1669 file_data
->profile_info
.runs
= runs
;
1671 /* IPA-profile computes hot bb threshold based on cumulated
1672 whole program profile. We need to stream it down to ltrans. */
1674 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1679 /* Rescale profile summaries to the same number of runs in the whole unit. */
1682 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1684 struct lto_file_decl_data
*file_data
;
1686 gcov_unsigned_t max_runs
= 0;
1687 struct cgraph_node
*node
;
1688 struct cgraph_edge
*edge
;
1690 /* Find unit with maximal number of runs. If we ever get serious about
1691 roundoff errors, we might also consider computing smallest common
1693 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1694 if (max_runs
< file_data
->profile_info
.runs
)
1695 max_runs
= file_data
->profile_info
.runs
;
1700 /* Simple overflow check. We probably don't need to support that many train
1701 runs. Such a large value probably imply data corruption anyway. */
1702 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1704 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1705 INT_MAX
/ REG_BR_PROB_BASE
);
1709 profile_info
= XCNEW (gcov_summary
);
1710 profile_info
->runs
= max_runs
;
1712 /* If merging already happent at WPA time, we are done. */
1716 /* Now compute count_materialization_scale of each node.
1717 During LTRANS we already have values of count_materialization_scale
1718 computed, so just update them. */
1719 FOR_EACH_FUNCTION (node
)
1720 if (node
->lto_file_data
1721 && node
->lto_file_data
->profile_info
.runs
)
1725 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1726 node
->lto_file_data
->profile_info
.runs
);
1727 node
->count_materialization_scale
= scale
;
1729 fatal_error (input_location
, "Profile information in %s corrupted",
1730 file_data
->file_name
);
1732 if (scale
== REG_BR_PROB_BASE
)
1734 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1735 if (edge
->count
.ipa ().nonzero_p ())
1736 edge
->count
= edge
->count
.apply_scale (scale
, REG_BR_PROB_BASE
);
1737 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
1738 if (edge
->count
.ipa ().nonzero_p ())
1739 edge
->count
= edge
->count
.apply_scale (scale
, REG_BR_PROB_BASE
);
1740 if (node
->count
.ipa ().nonzero_p ())
1741 node
->count
= node
->count
.apply_scale (scale
, REG_BR_PROB_BASE
);
1745 /* Input and merge the symtab from each of the .o files passed to
1751 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1752 struct lto_file_decl_data
*file_data
;
1754 struct cgraph_node
*node
;
1756 while ((file_data
= file_data_vec
[j
++]))
1760 class lto_input_block
*ib
;
1761 vec
<symtab_node
*> nodes
;
1763 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1766 fatal_error (input_location
,
1767 "cannot find LTO cgraph in %s", file_data
->file_name
);
1768 input_profile_summary (ib
, file_data
);
1769 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1770 nodes
= input_cgraph_1 (file_data
, ib
);
1771 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1774 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1777 fatal_error (input_location
, "cannot find LTO section refs in %s",
1778 file_data
->file_name
);
1779 input_refs (ib
, nodes
);
1780 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1783 input_cgraph_opt_summary (nodes
);
1787 merge_profile_summaries (file_data_vec
);
1789 /* Clear out the aux field that was used to store enough state to
1790 tell which nodes should be overwritten. */
1791 FOR_EACH_FUNCTION (node
)
1793 /* Some nodes may have been created by cgraph_node. This
1794 happens when the callgraph contains nested functions. If the
1795 node for the parent function was never emitted to the gimple
1796 file, cgraph_node will create a node for it when setting the
1797 context of the nested function. */
1798 if (node
->lto_file_data
)
1804 omp_requires_to_name (char *buf
, size_t size
, HOST_WIDE_INT requires_mask
)
1806 char *end
= buf
+ size
, *p
= buf
;
1807 if (requires_mask
& GOMP_REQUIRES_UNIFIED_ADDRESS
)
1808 p
+= snprintf (p
, end
- p
, "unified_address");
1809 if (requires_mask
& GOMP_REQUIRES_UNIFIED_SHARED_MEMORY
)
1810 p
+= snprintf (p
, end
- p
, "%sunified_shared_memory",
1811 (p
== buf
? "" : ", "));
1812 if (requires_mask
& GOMP_REQUIRES_SELF_MAPS
)
1813 p
+= snprintf (p
, end
- p
, "%sself_maps",
1814 (p
== buf
? "" : ", "));
1815 if (requires_mask
& GOMP_REQUIRES_REVERSE_OFFLOAD
)
1816 p
+= snprintf (p
, end
- p
, "%sreverse_offload",
1817 (p
== buf
? "" : ", "));
1820 /* Input function/variable tables that will allow libgomp to look up offload
1821 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1824 input_offload_tables (bool do_force_output
)
1826 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1827 struct lto_file_decl_data
*file_data
;
1829 const char *requires_fn
= NULL
;
1830 tree requires_decl
= NULL_TREE
;
1832 omp_requires_mask
= (omp_requires
) 0;
1834 while ((file_data
= file_data_vec
[j
++]))
1838 class lto_input_block
*ib
1839 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1844 tree tmp_decl
= NULL_TREE
;
1845 enum LTO_symtab_tags tag
1846 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1849 if (tag
== LTO_symtab_unavail_node
)
1852 = lto_input_fn_decl_ref (ib
, file_data
);
1853 vec_safe_push (offload_funcs
, fn_decl
);
1855 /* Prevent IPA from removing fn_decl as unreachable, since there
1856 may be no refs from the parent function to child_fn in offload
1858 if (do_force_output
)
1859 cgraph_node::get (fn_decl
)->mark_force_output ();
1862 else if (tag
== LTO_symtab_variable
)
1865 = lto_input_var_decl_ref (ib
, file_data
);
1866 vec_safe_push (offload_vars
, var_decl
);
1868 /* Prevent IPA from removing var_decl as unused, since there
1869 may be no refs to var_decl in offload LTO mode. */
1870 if (do_force_output
)
1871 varpool_node::get (var_decl
)->force_output
= 1;
1872 tmp_decl
= var_decl
;
1874 else if (tag
== LTO_symtab_indirect_function
)
1877 = lto_input_fn_decl_ref (ib
, file_data
);
1878 vec_safe_push (offload_ind_funcs
, fn_decl
);
1880 /* Prevent IPA from removing fn_decl as unreachable, since there
1881 may be no refs from the parent function to child_fn in offload
1883 if (do_force_output
)
1884 cgraph_node::get (fn_decl
)->mark_force_output ();
1887 else if (tag
== LTO_symtab_edge
)
1889 static bool error_emitted
= false;
1890 HOST_WIDE_INT val
= streamer_read_hwi (ib
);
1892 if (omp_requires_mask
== 0)
1894 omp_requires_mask
= (omp_requires
) val
;
1895 requires_decl
= tmp_decl
;
1896 requires_fn
= file_data
->file_name
;
1898 else if (omp_requires_mask
!= val
&& !error_emitted
)
1900 const char *fn1
= requires_fn
;
1901 if (requires_decl
!= NULL_TREE
)
1903 while (DECL_CONTEXT (requires_decl
) != NULL_TREE
1904 && TREE_CODE (requires_decl
) != TRANSLATION_UNIT_DECL
)
1905 requires_decl
= DECL_CONTEXT (requires_decl
);
1906 if (requires_decl
!= NULL_TREE
)
1907 fn1
= IDENTIFIER_POINTER (DECL_NAME (requires_decl
));
1910 const char *fn2
= file_data
->file_name
;
1911 if (tmp_decl
!= NULL_TREE
)
1913 while (DECL_CONTEXT (tmp_decl
) != NULL_TREE
1914 && TREE_CODE (tmp_decl
) != TRANSLATION_UNIT_DECL
)
1915 tmp_decl
= DECL_CONTEXT (tmp_decl
);
1916 if (tmp_decl
!= NULL_TREE
)
1917 fn2
= IDENTIFIER_POINTER (DECL_NAME (tmp_decl
));
1922 fn2
= file_data
->file_name
;
1925 char buf1
[sizeof ("unified_address, unified_shared_memory, "
1926 "reverse_offload")];
1927 char buf2
[sizeof ("unified_address, unified_shared_memory, "
1928 "reverse_offload")];
1929 omp_requires_to_name (buf2
, sizeof (buf2
),
1930 val
!= OMP_REQUIRES_TARGET_USED
1932 : (HOST_WIDE_INT
) omp_requires_mask
);
1933 if (val
!= OMP_REQUIRES_TARGET_USED
1934 && omp_requires_mask
!= OMP_REQUIRES_TARGET_USED
)
1936 omp_requires_to_name (buf1
, sizeof (buf1
),
1938 error ("OpenMP %<requires%> directive with non-identical "
1939 "clauses in multiple compilation units: %qs vs. "
1941 inform (UNKNOWN_LOCATION
, "%qs has %qs", fn1
, buf1
);
1942 inform (UNKNOWN_LOCATION
, "%qs has %qs", fn2
, buf2
);
1946 error ("OpenMP %<requires%> directive with %qs specified "
1947 "only in some compilation units", buf2
);
1948 inform (UNKNOWN_LOCATION
, "%qs has %qs",
1949 val
!= OMP_REQUIRES_TARGET_USED
? fn2
: fn1
,
1951 inform (UNKNOWN_LOCATION
, "but %qs has not",
1952 val
!= OMP_REQUIRES_TARGET_USED
? fn1
: fn2
);
1954 error_emitted
= true;
1958 fatal_error (input_location
,
1959 "invalid offload table in %s", file_data
->file_name
);
1961 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1964 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1967 #ifdef ACCEL_COMPILER
1968 char *omp_requires_file
= getenv ("GCC_OFFLOAD_OMP_REQUIRES_FILE");
1969 if (omp_requires_file
== NULL
|| omp_requires_file
[0] == '\0')
1970 fatal_error (input_location
, "GCC_OFFLOAD_OMP_REQUIRES_FILE unset");
1971 FILE *f
= fopen (omp_requires_file
, "wb");
1973 fatal_error (input_location
, "Cannot open omp_requires file %qs",
1975 uint32_t req_mask
= omp_requires_mask
;
1976 fwrite (&req_mask
, sizeof (req_mask
), 1, f
);
1981 /* True when we need optimization summary for NODE. */
1984 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1986 if (node
->clone_of
|| node
->former_clone_of
)
1988 clone_info
*info
= clone_info::get (node
);
1989 return info
&& (info
->tree_map
|| info
->param_adjustments
);
1992 /* Output optimization summary for EDGE to OB. */
1994 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1995 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1999 /* Output optimization summary for NODE to OB. */
2002 output_node_opt_summary (struct output_block
*ob
,
2003 struct cgraph_node
*node
,
2004 lto_symtab_encoder_t encoder
)
2006 struct ipa_replace_map
*map
;
2008 struct cgraph_edge
*e
;
2010 /* TODO: Should this code be moved to ipa-param-manipulation? */
2011 struct bitpack_d bp
;
2012 bp
= bitpack_create (ob
->main_stream
);
2013 clone_info
*info
= clone_info::get (node
);
2015 bp_pack_value (&bp
, (info
&& info
->param_adjustments
!= NULL
), 1);
2016 streamer_write_bitpack (&bp
);
2017 if (ipa_param_adjustments
*adjustments
2018 = info
? info
->param_adjustments
: NULL
)
2020 streamer_write_uhwi (ob
, vec_safe_length (adjustments
->m_adj_params
));
2021 ipa_adjusted_param
*adj
;
2022 FOR_EACH_VEC_SAFE_ELT (adjustments
->m_adj_params
, i
, adj
)
2024 bp
= bitpack_create (ob
->main_stream
);
2025 bp_pack_value (&bp
, adj
->base_index
, IPA_PARAM_MAX_INDEX_BITS
);
2026 bp_pack_value (&bp
, adj
->prev_clone_index
, IPA_PARAM_MAX_INDEX_BITS
);
2027 bp_pack_value (&bp
, adj
->op
, 2);
2028 bp_pack_value (&bp
, adj
->param_prefix_index
, 2);
2029 bp_pack_value (&bp
, adj
->prev_clone_adjustment
, 1);
2030 bp_pack_value (&bp
, adj
->reverse
, 1);
2031 bp_pack_value (&bp
, adj
->user_flag
, 1);
2032 streamer_write_bitpack (&bp
);
2033 if (adj
->op
== IPA_PARAM_OP_SPLIT
2034 || adj
->op
== IPA_PARAM_OP_NEW
)
2036 stream_write_tree (ob
, adj
->type
, true);
2037 if (adj
->op
== IPA_PARAM_OP_SPLIT
)
2039 stream_write_tree (ob
, adj
->alias_ptr_type
, true);
2040 streamer_write_uhwi (ob
, adj
->unit_offset
);
2044 streamer_write_hwi (ob
, adjustments
->m_always_copy_start
);
2045 bp
= bitpack_create (ob
->main_stream
);
2046 bp_pack_value (&bp
, info
->param_adjustments
->m_skip_return
, 1);
2047 streamer_write_bitpack (&bp
);
2050 streamer_write_uhwi (ob
, info
? vec_safe_length (info
->tree_map
) : 0);
2052 FOR_EACH_VEC_SAFE_ELT (info
->tree_map
, i
, map
)
2054 streamer_write_uhwi (ob
, map
->parm_num
);
2055 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
2056 stream_write_tree (ob
, map
->new_tree
, true);
2059 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
2061 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2062 output_edge_opt_summary (ob
, e
);
2063 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2064 output_edge_opt_summary (ob
, e
);
2068 /* Output optimization summaries stored in callgraph.
2069 At the moment it is the clone info structure. */
2072 output_cgraph_opt_summary (void)
2075 lto_symtab_encoder_t encoder
;
2076 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
2080 encoder
= ob
->decl_state
->symtab_node_encoder
;
2081 n_nodes
= lto_symtab_encoder_size (encoder
);
2082 for (i
= 0; i
< n_nodes
; i
++)
2084 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2085 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2086 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2089 streamer_write_uhwi (ob
, count
);
2090 for (i
= 0; i
< n_nodes
; i
++)
2092 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2093 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2094 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2096 streamer_write_uhwi (ob
, i
);
2097 output_node_opt_summary (ob
, cnode
, encoder
);
2100 produce_asm (ob
, NULL
);
2101 destroy_output_block (ob
);
2104 /* Input optimisation summary of EDGE. */
2107 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2108 class lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2112 /* Input optimisation summary of NODE. */
2115 input_node_opt_summary (struct cgraph_node
*node
,
2116 class lto_input_block
*ib_main
,
2117 class data_in
*data_in
)
2121 struct cgraph_edge
*e
;
2123 /* TODO: Should this code be moved to ipa-param-manipulation? */
2124 struct bitpack_d bp
;
2125 bp
= streamer_read_bitpack (ib_main
);
2126 bool have_adjustments
= bp_unpack_value (&bp
, 1);
2127 clone_info
*info
= clone_info::get_create (node
);
2129 if (have_adjustments
)
2131 count
= streamer_read_uhwi (ib_main
);
2132 vec
<ipa_adjusted_param
, va_gc
> *new_params
= NULL
;
2133 for (i
= 0; i
< count
; i
++)
2135 ipa_adjusted_param adj
;
2136 memset (&adj
, 0, sizeof (adj
));
2137 bp
= streamer_read_bitpack (ib_main
);
2138 adj
.base_index
= bp_unpack_value (&bp
, IPA_PARAM_MAX_INDEX_BITS
);
2139 adj
.prev_clone_index
2140 = bp_unpack_value (&bp
, IPA_PARAM_MAX_INDEX_BITS
);
2141 adj
.op
= (enum ipa_parm_op
) bp_unpack_value (&bp
, 2);
2142 adj
.param_prefix_index
= bp_unpack_value (&bp
, 2);
2143 adj
.prev_clone_adjustment
= bp_unpack_value (&bp
, 1);
2144 adj
.reverse
= bp_unpack_value (&bp
, 1);
2145 adj
.user_flag
= bp_unpack_value (&bp
, 1);
2146 if (adj
.op
== IPA_PARAM_OP_SPLIT
2147 || adj
.op
== IPA_PARAM_OP_NEW
)
2149 adj
.type
= stream_read_tree (ib_main
, data_in
);
2150 if (adj
.op
== IPA_PARAM_OP_SPLIT
)
2152 adj
.alias_ptr_type
= stream_read_tree (ib_main
, data_in
);
2153 adj
.unit_offset
= streamer_read_uhwi (ib_main
);
2156 vec_safe_push (new_params
, adj
);
2158 int always_copy_start
= streamer_read_hwi (ib_main
);
2159 bp
= streamer_read_bitpack (ib_main
);
2160 bool skip_return
= bp_unpack_value (&bp
, 1);
2161 info
->param_adjustments
2162 = (new (ggc_alloc
<ipa_param_adjustments
> ())
2163 ipa_param_adjustments (new_params
, always_copy_start
, skip_return
));
2166 count
= streamer_read_uhwi (ib_main
);
2167 for (i
= 0; i
< count
; i
++)
2169 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2171 vec_safe_push (info
->tree_map
, map
);
2172 map
->parm_num
= streamer_read_uhwi (ib_main
);
2173 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2175 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2176 input_edge_opt_summary (e
, ib_main
);
2177 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2178 input_edge_opt_summary (e
, ib_main
);
2181 /* Read section in file FILE_DATA of length LEN with data DATA. */
2184 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2185 const char *data
, size_t len
,
2186 vec
<symtab_node
*> nodes
)
2188 const struct lto_function_header
*header
=
2189 (const struct lto_function_header
*) data
;
2190 const int cfg_offset
= sizeof (struct lto_function_header
);
2191 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2192 const int string_offset
= main_offset
+ header
->main_size
;
2193 class data_in
*data_in
;
2197 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2198 header
->main_size
, file_data
);
2201 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2202 header
->string_size
, vNULL
);
2203 count
= streamer_read_uhwi (&ib_main
);
2205 for (i
= 0; i
< count
; i
++)
2207 int ref
= streamer_read_uhwi (&ib_main
);
2208 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2211 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2213 lto_data_in_delete (data_in
);
2216 /* Input optimization summary of cgraph. */
2219 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2221 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2222 struct lto_file_decl_data
*file_data
;
2225 while ((file_data
= file_data_vec
[j
++]))
2229 = lto_get_summary_section_data (file_data
, LTO_section_cgraph_opt_sum
,
2232 input_cgraph_opt_section (file_data
, data
, len
, nodes
);