Line data Source code
1 : /* Write and read the cgraph to the memory mapped representation of a
2 : .o file.
3 :
4 : Copyright (C) 2009-2026 Free Software Foundation, Inc.
5 : Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
6 :
7 : This file is part of GCC.
8 :
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
12 : version.
13 :
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
17 : for more details.
18 :
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/>. */
22 :
23 : #include "config.h"
24 : #include "system.h"
25 : #include "coretypes.h"
26 : #include "backend.h"
27 : #include "rtl.h"
28 : #include "tree.h"
29 : #include "gimple.h"
30 : #include "predict.h"
31 : #include "stringpool.h"
32 : #include "tree-streamer.h"
33 : #include "cgraph.h"
34 : #include "tree-pass.h"
35 : #include "profile.h"
36 : #include "context.h"
37 : #include "pass_manager.h"
38 : #include "ipa-utils.h"
39 : #include "omp-offload.h"
40 : #include "omp-general.h"
41 : #include "attribs.h"
42 : #include "alloc-pool.h"
43 : #include "symbol-summary.h"
44 : #include "symtab-thunks.h"
45 : #include "symtab-clones.h"
46 : #include "callback-info.h"
47 :
48 : static void output_cgraph_opt_summary (void);
49 : static void input_cgraph_opt_summary (vec<symtab_node *> nodes);
50 :
51 : /* Number of LDPR values known to GCC. */
52 : #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
53 :
54 : /* Cgraph streaming is organized as set of record whose type
55 : is indicated by a tag. */
56 : enum LTO_symtab_tags
57 : {
58 : /* Must leave 0 for the stopper. */
59 :
60 : /* Cgraph node without body available. */
61 : LTO_symtab_unavail_node = 1,
62 : /* Cgraph node with function body. */
63 : LTO_symtab_analyzed_node,
64 : /* Cgraph edges. */
65 : LTO_symtab_edge,
66 : LTO_symtab_indirect_edge,
67 : LTO_symtab_variable,
68 : LTO_symtab_indirect_function,
69 : LTO_symtab_last_tag
70 : };
71 :
72 : /* Create a new symtab encoder.
73 : if FOR_INPUT, the encoder allocate only datastructures needed
74 : to read the symtab. */
75 :
76 : lto_symtab_encoder_t
77 85638 : lto_symtab_encoder_new (bool for_input)
78 : {
79 85638 : lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
80 :
81 85638 : if (!for_input)
82 63745 : encoder->map = new hash_map<toplevel_node *, size_t>;
83 85638 : encoder->nodes.create (0);
84 85638 : return encoder;
85 : }
86 :
87 :
88 : /* Delete ENCODER and its components. */
89 :
90 : void
91 85638 : lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
92 : {
93 85638 : encoder->nodes.release ();
94 85638 : if (encoder->map)
95 63745 : delete encoder->map;
96 85638 : if (encoder->order_remap)
97 31872 : delete encoder->order_remap;
98 85638 : free (encoder);
99 85638 : }
100 :
101 :
102 : /* Return the existing reference number of NODE in the symtab encoder in
103 : output block OB. Assign a new reference if this is the first time
104 : NODE is encoded. */
105 :
106 : int
107 3226236 : lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
108 : toplevel_node *node)
109 : {
110 3226236 : int ref;
111 :
112 3226236 : if (!encoder->map)
113 : {
114 268873 : lto_encoder_entry entry (node);
115 :
116 268873 : ref = encoder->nodes.length ();
117 268873 : encoder->nodes.safe_push (entry);
118 268873 : return ref;
119 : }
120 :
121 2957363 : size_t *slot = encoder->map->get (node);
122 2957363 : if (!slot || !*slot)
123 : {
124 1163888 : lto_encoder_entry entry (node);
125 1163888 : ref = encoder->nodes.length ();
126 1163888 : if (!slot)
127 1163888 : encoder->map->put (node, ref + 1);
128 1163888 : encoder->nodes.safe_push (entry);
129 1163888 : }
130 : else
131 1793475 : ref = *slot - 1;
132 :
133 : return ref;
134 : }
135 :
136 : /* Remove NODE from encoder. */
137 :
138 : bool
139 224 : lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
140 : toplevel_node *node)
141 : {
142 224 : int index;
143 :
144 224 : size_t *slot = encoder->map->get (node);
145 224 : if (slot == NULL || !*slot)
146 : return false;
147 :
148 224 : index = *slot - 1;
149 224 : gcc_checking_assert (encoder->nodes[index].node == node);
150 :
151 : /* Remove from vector. We do this by swapping node with the last element
152 : of the vector. */
153 224 : lto_encoder_entry last_node = encoder->nodes.pop ();
154 224 : if (last_node.node != node)
155 : {
156 223 : bool existed = encoder->map->put (last_node.node, index + 1);
157 223 : gcc_assert (existed);
158 :
159 : /* Move the last element to the original spot of NODE. */
160 223 : encoder->nodes[index] = last_node;
161 : }
162 :
163 : /* Remove element from hash table. */
164 224 : encoder->map->remove (node);
165 224 : return true;
166 : }
167 :
168 : /* Return TRUE if the NODE and its clones are always inlined. */
169 :
170 : bool
171 12053 : lto_symtab_encoder_only_for_inlining_p (lto_symtab_encoder_t encoder,
172 : struct cgraph_node *node)
173 : {
174 12053 : int index = lto_symtab_encoder_lookup (encoder, node);
175 12053 : return encoder->nodes[index].only_for_inlining;
176 : }
177 :
178 : /* Return TRUE if we should encode the body of NODE (if any). */
179 :
180 : bool
181 461415 : lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
182 : struct cgraph_node *node)
183 : {
184 461415 : int index = lto_symtab_encoder_lookup (encoder, node);
185 461415 : return encoder->nodes[index].body;
186 : }
187 :
188 : /* Return TRUE if we should encode initializer of NODE (if any). */
189 :
190 : bool
191 668328 : lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
192 : varpool_node *node)
193 : {
194 668328 : int index = lto_symtab_encoder_lookup (encoder, node);
195 668328 : if (index == LCC_NOT_FOUND)
196 : return false;
197 668306 : return encoder->nodes[index].initializer;
198 : }
199 :
200 : /* Specify that we should encode initializer of NODE (if any). */
201 :
202 : static void
203 282239 : lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
204 : varpool_node *node)
205 : {
206 282239 : int index = lto_symtab_encoder_lookup (encoder, node);
207 282239 : encoder->nodes[index].initializer = true;
208 282239 : }
209 :
210 : /* Return TRUE if NODE is in this partition. */
211 :
212 : bool
213 8671319 : lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
214 : toplevel_node *node)
215 : {
216 8671319 : int index = lto_symtab_encoder_lookup (encoder, node);
217 8671319 : if (index == LCC_NOT_FOUND)
218 : return false;
219 8528834 : return encoder->nodes[index].in_partition;
220 : }
221 :
222 : /* Specify that NODE is in this partition. */
223 :
224 : void
225 909152 : lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
226 : toplevel_node *node)
227 : {
228 909152 : int index = lto_symtab_encoder_encode (encoder, node);
229 909152 : if (dump_file)
230 : {
231 0 : if (symtab_node* snode = dyn_cast<symtab_node*> (node))
232 0 : fprintf (dump_file, "Node %s, index %d\n", snode->asm_name (), index);
233 : else
234 0 : fprintf (dump_file, "Asm node, index %d\n", index);
235 : }
236 909152 : encoder->nodes[index].in_partition = true;
237 909152 : }
238 :
239 : /* Output the cgraph EDGE to OB using ENCODER. */
240 :
241 : static void
242 634116 : lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
243 : lto_symtab_encoder_t encoder)
244 : {
245 634116 : unsigned int uid;
246 634116 : intptr_t ref;
247 634116 : struct bitpack_d bp;
248 :
249 634116 : if (edge->indirect_unknown_callee)
250 3617 : streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
251 : LTO_symtab_indirect_edge);
252 : else
253 630499 : streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
254 : LTO_symtab_edge);
255 :
256 634116 : ref = lto_symtab_encoder_lookup (encoder, edge->caller);
257 634116 : gcc_assert (ref != LCC_NOT_FOUND);
258 634116 : streamer_write_hwi_stream (ob->main_stream, ref);
259 :
260 634116 : if (!edge->indirect_unknown_callee)
261 : {
262 630499 : ref = lto_symtab_encoder_lookup (encoder, edge->callee);
263 630499 : gcc_assert (ref != LCC_NOT_FOUND);
264 630499 : streamer_write_hwi_stream (ob->main_stream, ref);
265 : }
266 :
267 634116 : edge->count.stream_out (ob->main_stream);
268 :
269 634116 : bp = bitpack_create (ob->main_stream);
270 634116 : uid = !edge->call_stmt ? edge->lto_stmt_uid
271 386242 : : gimple_uid (edge->call_stmt) + 1;
272 634116 : bp_pack_enum (&bp, cgraph_inline_failed_t,
273 : CIF_N_REASONS, edge->inline_failed);
274 634116 : gcc_checking_assert (uid || edge->caller->thunk);
275 634116 : bp_pack_var_len_unsigned (&bp, uid);
276 634116 : bp_pack_value (&bp, edge->speculative_id, 16);
277 634116 : bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
278 634116 : bp_pack_value (&bp, edge->speculative, 1);
279 634116 : bp_pack_value (&bp, edge->callback, 1);
280 634116 : bp_pack_value (&bp, edge->has_callback, 1);
281 634116 : bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
282 634116 : gcc_assert (!edge->call_stmt_cannot_inline_p
283 : || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
284 634116 : bp_pack_value (&bp, edge->can_throw_external, 1);
285 634116 : bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
286 634116 : if (edge->indirect_unknown_callee)
287 : {
288 3617 : bp_pack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS,
289 : edge->indirect_info->kind);
290 3617 : int flags = edge->indirect_info->ecf_flags;
291 3617 : bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
292 3617 : bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
293 3617 : bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
294 3617 : bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
295 3617 : bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
296 3617 : bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
297 : /* Flags that should not appear on indirect calls. */
298 3617 : gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
299 : | ECF_MAY_BE_ALLOCA
300 : | ECF_SIBCALL
301 : | ECF_LEAF
302 : | ECF_NOVOPS)));
303 :
304 3617 : bp_pack_value (&bp, edge->indirect_info->num_speculative_call_targets,
305 : 16);
306 : }
307 634116 : streamer_write_bitpack (&bp);
308 634116 : if (edge->callback)
309 : {
310 13 : callback_info *ci = callback_info_sum->get (edge);
311 13 : ci->stream_out (ob);
312 : }
313 634116 : }
314 :
315 : /* Return if NODE contain references from other partitions. */
316 :
317 : bool
318 419978 : referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
319 : {
320 419978 : int i;
321 419978 : struct ipa_ref *ref = NULL;
322 :
323 872433 : for (i = 0; node->iterate_referring (i, ref); i++)
324 : {
325 : /* Ignore references from non-offloadable nodes while streaming NODE into
326 : offload LTO section. */
327 452756 : if (!ref->referring->need_lto_streaming)
328 0 : continue;
329 :
330 452756 : if (ref->referring->in_other_partition
331 452756 : || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
332 : return true;
333 : }
334 : return false;
335 : }
336 :
337 : /* Return true when node is reachable from other partition. */
338 :
339 : bool
340 140584 : reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
341 : {
342 140584 : struct cgraph_edge *e;
343 140584 : if (!node->definition)
344 : return false;
345 140584 : if (node->inlined_to)
346 : return false;
347 405370 : for (e = node->callers; e; e = e->next_caller)
348 : {
349 : /* Ignore references from non-offloadable nodes while streaming NODE into
350 : offload LTO section. */
351 264907 : if (!e->caller->need_lto_streaming)
352 0 : continue;
353 :
354 264907 : if (e->caller->in_other_partition
355 264907 : || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
356 : return true;
357 : }
358 : return false;
359 : }
360 :
361 : /* Return if NODE contain references from other partitions. */
362 :
363 : bool
364 6514 : referenced_from_this_partition_p (symtab_node *node,
365 : lto_symtab_encoder_t encoder)
366 : {
367 6514 : int i;
368 6514 : struct ipa_ref *ref = NULL;
369 :
370 6540 : for (i = 0; node->iterate_referring (i, ref); i++)
371 5024 : if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
372 : return true;
373 : return false;
374 : }
375 :
376 : /* Return true when node is reachable from other partition. */
377 :
378 : bool
379 9308 : reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
380 : {
381 9308 : struct cgraph_edge *e;
382 9310 : for (e = node->callers; e; e = e->next_caller)
383 6704 : if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
384 : return true;
385 : return false;
386 : }
387 :
388 : /* Output the cgraph NODE to OB. ENCODER is used to find the
389 : reference number of NODE->inlined_to. SET is the set of nodes we
390 : are writing to the current file. If NODE is not in SET, then NODE
391 : is a boundary of a cgraph_node_set and we pretend NODE just has a
392 : decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
393 : that have had their callgraph node written so far. This is used to
394 : determine if NODE is a clone of a previously written node. */
395 :
396 : static void
397 423568 : lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
398 : lto_symtab_encoder_t encoder)
399 : {
400 423568 : unsigned int tag;
401 423568 : struct bitpack_d bp;
402 423568 : bool boundary_p;
403 423568 : intptr_t ref;
404 423568 : bool in_other_partition = false;
405 423568 : struct cgraph_node *clone_of, *ultimate_clone_of;
406 423568 : ipa_opt_pass_d *pass;
407 423568 : int i;
408 423568 : const char *comdat;
409 423568 : const char *section;
410 423568 : tree group;
411 :
412 423568 : boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
413 :
414 423568 : if (node->analyzed && (!boundary_p || node->alias
415 254 : || (node->thunk && !node->inlined_to)))
416 : tag = LTO_symtab_analyzed_node;
417 : else
418 423568 : tag = LTO_symtab_unavail_node;
419 :
420 423568 : streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
421 : tag);
422 423568 : int output_order = *encoder->order_remap->get (node->order);
423 423568 : streamer_write_hwi_stream (ob->main_stream, output_order);
424 :
425 : /* In WPA mode, we only output part of the call-graph. Also, we
426 : fake cgraph node attributes. There are two cases that we care.
427 :
428 : Boundary nodes: There are nodes that are not part of SET but are
429 : called from within SET. We artificially make them look like
430 : externally visible nodes with no function body.
431 :
432 : Cherry-picked nodes: These are nodes we pulled from other
433 : translation units into SET during IPA-inlining. We make them as
434 : local static nodes to prevent clashes with other local statics. */
435 252591 : if (boundary_p && node->analyzed
436 423837 : && node->get_partitioning_class () == SYMBOL_PARTITION)
437 : {
438 : /* Inline clones cannot be part of boundary.
439 : gcc_assert (!node->inlined_to);
440 :
441 : FIXME: At the moment they can be, when partition contains an inline
442 : clone that is clone of inline clone from outside partition. We can
443 : reshape the clone tree and make other tree to be the root, but it
444 : needs a bit extra work and will be promplty done by cgraph_remove_node
445 : after reading back. */
446 : in_other_partition = 1;
447 : }
448 423313 : else if (UNLIKELY (lto_stream_offload_p
449 : && lookup_attribute ("omp target device_ancestor_host",
450 : DECL_ATTRIBUTES (node->decl))))
451 : /* This symbol is only used as argument to IFN_GOMP_TARGET_REV; this IFN
452 : is ignored on ACCEL_COMPILER. Thus, mark it as in_other_partition to silence
453 : verify_node_partition diagnostic. */
454 : in_other_partition = 1;
455 :
456 423568 : clone_of = node->clone_of;
457 423568 : while (clone_of
458 423568 : && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
459 0 : if (clone_of->prev_sibling_clone)
460 : clone_of = clone_of->prev_sibling_clone;
461 : else
462 0 : clone_of = clone_of->clone_of;
463 :
464 : /* See if body of the master function is output. If not, we are seeing only
465 : an declaration and we do not need to pass down clone tree. */
466 423568 : ultimate_clone_of = clone_of;
467 442967 : while (ultimate_clone_of && ultimate_clone_of->clone_of)
468 : ultimate_clone_of = ultimate_clone_of->clone_of;
469 :
470 423568 : if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
471 : clone_of = NULL;
472 :
473 423568 : if (tag == LTO_symtab_analyzed_node)
474 170996 : gcc_assert (clone_of || !node->clone_of);
475 400723 : if (!clone_of)
476 400276 : streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
477 : else
478 23292 : streamer_write_hwi_stream (ob->main_stream, ref);
479 :
480 :
481 423568 : lto_output_fn_decl_ref (ob->decl_state, ob->main_stream, node->decl);
482 423568 : node->count.stream_out (ob->main_stream);
483 423568 : streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
484 :
485 847136 : streamer_write_hwi_stream (ob->main_stream,
486 423568 : node->ipa_transforms_to_apply.length ());
487 915466 : FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
488 68330 : streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
489 :
490 423568 : if (tag == LTO_symtab_analyzed_node)
491 : {
492 170996 : if (node->inlined_to)
493 : {
494 21468 : ref = lto_symtab_encoder_lookup (encoder, node->inlined_to);
495 21468 : gcc_assert (ref != LCC_NOT_FOUND);
496 : }
497 : else
498 : ref = LCC_NOT_FOUND;
499 :
500 170996 : streamer_write_hwi_stream (ob->main_stream, ref);
501 : }
502 :
503 423568 : group = node->get_comdat_group ();
504 423568 : if (group)
505 9011 : comdat = IDENTIFIER_POINTER (group);
506 : else
507 : comdat = "";
508 423568 : streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
509 :
510 423568 : if (group)
511 : {
512 9011 : if (node->same_comdat_group)
513 : {
514 : ref = LCC_NOT_FOUND;
515 4480 : for (struct symtab_node *n = node->same_comdat_group;
516 8959 : ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
517 4480 : ref = lto_symtab_encoder_lookup (encoder, n);
518 : }
519 : else
520 : ref = LCC_NOT_FOUND;
521 9011 : streamer_write_hwi_stream (ob->main_stream, ref);
522 : }
523 :
524 423568 : section = node->get_section ();
525 318 : if (!section)
526 423250 : section = "";
527 :
528 423568 : streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
529 :
530 423568 : bp = bitpack_create (ob->main_stream);
531 423568 : bp_pack_value (&bp, node->local, 1);
532 423568 : bp_pack_value (&bp, node->externally_visible, 1);
533 423568 : bp_pack_value (&bp, node->no_reorder, 1);
534 423568 : bp_pack_value (&bp, node->definition, 1);
535 423568 : bp_pack_value (&bp, node->versionable, 1);
536 423568 : bp_pack_value (&bp, node->can_change_signature, 1);
537 423568 : bp_pack_value (&bp, node->redefined_extern_inline, 1);
538 423568 : bp_pack_value (&bp, node->force_output, 1);
539 423568 : bp_pack_value (&bp, node->forced_by_abi, 1);
540 423568 : bp_pack_value (&bp, node->ref_by_asm, 1);
541 423568 : bp_pack_value (&bp, node->must_remain_in_tu_name, 1);
542 423568 : bp_pack_value (&bp, node->must_remain_in_tu_body, 1);
543 423568 : bp_pack_value (&bp, node->unique_name, 1);
544 423568 : bp_pack_value (&bp, node->body_removed, 1);
545 423568 : bp_pack_value (&bp, node->semantic_interposition, 1);
546 423568 : bp_pack_value (&bp, node->implicit_section, 1);
547 423568 : bp_pack_value (&bp, node->address_taken, 1);
548 423568 : bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
549 170996 : && node->get_partitioning_class () == SYMBOL_PARTITION
550 564152 : && (reachable_from_other_partition_p (node, encoder)
551 140463 : || referenced_from_other_partition_p (node, encoder)), 1);
552 423568 : bp_pack_value (&bp, node->lowered, 1);
553 423568 : bp_pack_value (&bp, in_other_partition, 1);
554 423568 : bp_pack_value (&bp, node->alias, 1);
555 423568 : bp_pack_value (&bp, node->transparent_alias, 1);
556 423568 : bp_pack_value (&bp, node->weakref, 1);
557 423568 : bp_pack_value (&bp, node->symver, 1);
558 423568 : bp_pack_value (&bp, node->frequency, 2);
559 423568 : bp_pack_value (&bp, node->only_called_at_startup, 1);
560 423568 : bp_pack_value (&bp, node->only_called_at_exit, 1);
561 423568 : bp_pack_value (&bp, node->tm_clone, 1);
562 423568 : bp_pack_value (&bp, node->calls_comdat_local, 1);
563 423568 : bp_pack_value (&bp, node->icf_merged, 1);
564 423568 : bp_pack_value (&bp, node->nonfreeing_fn, 1);
565 423568 : bp_pack_value (&bp, node->merged_comdat, 1);
566 423568 : bp_pack_value (&bp, node->merged_extern_inline, 1);
567 423568 : bp_pack_value (&bp, node->thunk, 1);
568 423568 : bp_pack_value (&bp, node->parallelized_function, 1);
569 423568 : bp_pack_value (&bp, node->has_omp_variant_constructs, 1);
570 :
571 : /* Stream thunk info always because we use it in
572 : ipa_polymorphic_call_context::ipa_polymorphic_call_context
573 : to properly interpret THIS pointers for thunks that has been converted
574 : to Gimple. */
575 423568 : struct thunk_info *thunk = node->definition ? thunk_info::get (node) : NULL;
576 :
577 423568 : bp_pack_value (&bp, thunk != NULL, 1);
578 :
579 423568 : bp_pack_enum (&bp, ld_plugin_symbol_resolution,
580 : LDPR_NUM_KNOWN,
581 : /* When doing incremental link, we will get new resolution
582 : info next time we process the file. */
583 : flag_incremental_link == INCREMENTAL_LINK_LTO
584 : ? LDPR_UNKNOWN : node->resolution);
585 423568 : bp_pack_value (&bp, node->split_part, 1);
586 423568 : streamer_write_bitpack (&bp);
587 423568 : streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
588 :
589 423568 : streamer_write_hwi_stream (ob->main_stream, node->profile_id);
590 423568 : streamer_write_hwi_stream (ob->main_stream, node->unit_id);
591 423568 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
592 258 : streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
593 423568 : if (DECL_STATIC_DESTRUCTOR (node->decl))
594 71 : streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
595 :
596 423568 : if (thunk)
597 227 : thunk_info::get (node)->stream_out (ob);
598 423568 : }
599 :
600 : /* Output the varpool NODE to OB.
601 : If NODE is not in SET, then NODE is a boundary. */
602 :
603 : static void
604 286708 : lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
605 : lto_symtab_encoder_t encoder)
606 : {
607 286708 : bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
608 286708 : bool encode_initializer_p
609 286708 : = (node->definition
610 286708 : && lto_symtab_encoder_encode_initializer_p (encoder, node));
611 282112 : struct bitpack_d bp;
612 282112 : int ref;
613 282112 : const char *comdat;
614 282112 : const char *section;
615 282112 : tree group;
616 :
617 282112 : gcc_assert (!encode_initializer_p || node->definition);
618 286708 : gcc_assert (boundary_p || encode_initializer_p);
619 :
620 286708 : streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
621 : LTO_symtab_variable);
622 286708 : int output_order = *encoder->order_remap->get (node->order);
623 286708 : streamer_write_hwi_stream (ob->main_stream, output_order);
624 286708 : lto_output_var_decl_ref (ob->decl_state, ob->main_stream, node->decl);
625 286708 : bp = bitpack_create (ob->main_stream);
626 286708 : bp_pack_value (&bp, node->externally_visible, 1);
627 286708 : bp_pack_value (&bp, node->no_reorder, 1);
628 286708 : bp_pack_value (&bp, node->force_output, 1);
629 286708 : bp_pack_value (&bp, node->forced_by_abi, 1);
630 286708 : bp_pack_value (&bp, node->ref_by_asm, 1);
631 286708 : bp_pack_value (&bp, node->must_remain_in_tu_name, 1);
632 286708 : bp_pack_value (&bp, node->must_remain_in_tu_body, 1);
633 286708 : bp_pack_value (&bp, node->unique_name, 1);
634 286708 : bp_pack_value (&bp,
635 286708 : node->body_removed
636 286708 : || (!encode_initializer_p && !node->alias && node->definition),
637 : 1);
638 286708 : bp_pack_value (&bp, node->semantic_interposition, 1);
639 286708 : bp_pack_value (&bp, node->implicit_section, 1);
640 286708 : bp_pack_value (&bp, node->writeonly, 1);
641 568821 : bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias),
642 : 1);
643 286708 : bp_pack_value (&bp, node->alias, 1);
644 286708 : bp_pack_value (&bp, node->transparent_alias, 1);
645 286708 : bp_pack_value (&bp, node->weakref, 1);
646 286708 : bp_pack_value (&bp, node->symver, 1);
647 568804 : bp_pack_value (&bp, node->analyzed && (!boundary_p || node->alias), 1);
648 286708 : gcc_assert (node->definition || !node->analyzed);
649 : /* Constant pool initializers can be de-unified into individual ltrans units.
650 : FIXME: Alternatively at -Os we may want to avoid generating for them the local
651 : labels and share them across LTRANS partitions. */
652 286708 : if (node->get_partitioning_class () != SYMBOL_PARTITION)
653 : {
654 7193 : bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */
655 7193 : bp_pack_value (&bp, 0, 1); /* in_other_partition. */
656 : }
657 : else
658 : {
659 279515 : bp_pack_value (&bp, node->definition
660 279515 : && referenced_from_other_partition_p (node, encoder), 1);
661 279515 : bp_pack_value (&bp, node->analyzed
662 279515 : && boundary_p && !DECL_EXTERNAL (node->decl), 1);
663 : /* in_other_partition. */
664 : }
665 286708 : bp_pack_value (&bp, node->tls_model, 3);
666 286708 : bp_pack_value (&bp, node->used_by_single_function, 1);
667 286708 : bp_pack_value (&bp, node->dynamically_initialized, 1);
668 286708 : streamer_write_bitpack (&bp);
669 :
670 286708 : group = node->get_comdat_group ();
671 286708 : if (group)
672 3420 : comdat = IDENTIFIER_POINTER (group);
673 : else
674 : comdat = "";
675 286708 : streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
676 :
677 286708 : if (group)
678 : {
679 3420 : if (node->same_comdat_group)
680 : {
681 : ref = LCC_NOT_FOUND;
682 370 : for (struct symtab_node *n = node->same_comdat_group;
683 740 : ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
684 370 : ref = lto_symtab_encoder_lookup (encoder, n);
685 : }
686 : else
687 : ref = LCC_NOT_FOUND;
688 3420 : streamer_write_hwi_stream (ob->main_stream, ref);
689 : }
690 :
691 286708 : section = node->get_section ();
692 2353 : if (!section)
693 284355 : section = "";
694 286708 : streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
695 :
696 286708 : streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
697 : LDPR_NUM_KNOWN, node->resolution);
698 286708 : }
699 :
700 : /* Output the varpool NODE to OB.
701 : If NODE is not in SET, then NODE is a boundary. */
702 :
703 : static void
704 678314 : lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
705 : lto_symtab_encoder_t encoder)
706 : {
707 678314 : struct bitpack_d bp;
708 678314 : int nref;
709 678314 : int uid = !ref->stmt ? ref->lto_stmt_uid : gimple_uid (ref->stmt) + 1;
710 678314 : struct cgraph_node *node;
711 :
712 678314 : bp = bitpack_create (ob->main_stream);
713 678314 : bp_pack_value (&bp, ref->use, 3);
714 678314 : bp_pack_value (&bp, ref->speculative, 1);
715 678314 : streamer_write_bitpack (&bp);
716 678314 : nref = lto_symtab_encoder_lookup (encoder, ref->referred);
717 678314 : gcc_assert (nref != LCC_NOT_FOUND);
718 678314 : streamer_write_hwi_stream (ob->main_stream, nref);
719 :
720 678314 : node = dyn_cast <cgraph_node *> (ref->referring);
721 452712 : if (node)
722 : {
723 452712 : if (ref->stmt)
724 264770 : uid = gimple_uid (ref->stmt) + 1;
725 452712 : streamer_write_hwi_stream (ob->main_stream, uid);
726 452712 : bp_pack_value (&bp, ref->speculative_id, 16);
727 452712 : streamer_write_bitpack (&bp);
728 : }
729 678314 : }
730 :
731 : /* Stream out profile_summary to OB. */
732 :
733 : static void
734 31872 : output_profile_summary (struct lto_simple_output_block *ob)
735 : {
736 31872 : if (profile_info)
737 : {
738 13 : unsigned runs = (profile_info->runs);
739 13 : streamer_write_uhwi_stream (ob->main_stream, runs);
740 13 : streamer_write_gcov_count_stream (ob->main_stream,
741 : profile_info->sum_max);
742 13 : streamer_write_gcov_count_stream (ob->main_stream,
743 : profile_info->cutoff);
744 :
745 : /* IPA-profile computes hot bb threshold based on cumulated
746 : whole program profile. We need to stream it down to ltrans. */
747 13 : if (flag_wpa)
748 5 : streamer_write_gcov_count_stream (ob->main_stream,
749 : get_hot_bb_threshold ());
750 : }
751 : else
752 31859 : streamer_write_uhwi_stream (ob->main_stream, 0);
753 31872 : }
754 :
755 : /* Output all callees or indirect outgoing edges. EDGE must be the first such
756 : edge. */
757 :
758 : static void
759 341962 : output_outgoing_cgraph_edges (struct cgraph_edge *edge,
760 : struct lto_simple_output_block *ob,
761 : lto_symtab_encoder_t encoder)
762 : {
763 341962 : if (!edge)
764 : return;
765 :
766 : /* Output edges in backward direction, so the reconstructed callgraph match
767 : and it is easy to associate call sites in the IPA pass summaries. */
768 634116 : while (edge->next_callee)
769 : edge = edge->next_callee;
770 748811 : for (; edge; edge = edge->prev_callee)
771 634116 : lto_output_edge (ob, edge, encoder);
772 : }
773 :
774 : /* Output the part of the cgraph in SET. */
775 :
776 : static void
777 31872 : output_refs (lto_symtab_encoder_t encoder)
778 : {
779 31872 : struct lto_simple_output_block *ob;
780 31872 : int count;
781 31872 : struct ipa_ref *ref;
782 :
783 31872 : ob = lto_create_simple_output_block (LTO_section_refs);
784 :
785 1516245 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
786 : {
787 710432 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
788 710432 : symtab_node *node = dyn_cast <symtab_node *> (tnode);
789 710432 : if (!node)
790 156 : continue;
791 :
792 : /* IPA_REF_ALIAS references are always preserved
793 : in the boundary. Alias node can't have other references and
794 : can be always handled as if it's not in the boundary. */
795 710276 : if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node))
796 257148 : continue;
797 :
798 782711 : count = node->ref_list.nreferences ();
799 72279 : if (count)
800 : {
801 72265 : streamer_write_gcov_count_stream (ob->main_stream, count);
802 144530 : streamer_write_uhwi_stream (ob->main_stream,
803 72265 : lto_symtab_encoder_lookup (encoder, node));
804 1533276 : for (int i = 0; node->iterate_reference (i, ref); i++)
805 678314 : lto_output_ref (ob, ref, encoder);
806 : }
807 : }
808 :
809 31872 : streamer_write_uhwi_stream (ob->main_stream, 0);
810 :
811 31872 : lto_destroy_simple_output_block (ob);
812 31872 : }
813 :
814 : /* Add NODE into encoder as well as nodes it is cloned from.
815 : Do it in a way so clones appear first. */
816 :
817 : static void
818 786583 : add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
819 : bool include_body, bool not_inlined)
820 : {
821 786583 : if (node->clone_of)
822 42252 : add_node_to (encoder, node->clone_of, include_body, not_inlined);
823 :
824 786583 : int index = lto_symtab_encoder_encode (encoder, node);
825 786583 : gcc_checking_assert (encoder->nodes[index].node == node);
826 :
827 786583 : if (include_body)
828 213221 : encoder->nodes[index].body = true;
829 786583 : if (not_inlined)
830 152667 : encoder->nodes[index].only_for_inlining = false;
831 786583 : }
832 :
833 : /* Add NODE into encoder as well as nodes it is cloned from.
834 : Do it in a way so clones appear first. */
835 :
836 : static void
837 744331 : add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
838 : bool include_body)
839 : {
840 431890 : add_node_to (encoder, node, include_body, include_body && !node->inlined_to);
841 170977 : }
842 :
843 : /* Add all references in NODE to encoders. */
844 :
845 : static void
846 465983 : create_references (lto_symtab_encoder_t encoder, symtab_node *node)
847 : {
848 465983 : int i;
849 465983 : struct ipa_ref *ref = NULL;
850 1157065 : for (i = 0; node->iterate_reference (i, ref); i++)
851 691082 : if (is_a <cgraph_node *> (ref->referred))
852 239438 : add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
853 : else
854 451644 : lto_symtab_encoder_encode (encoder, ref->referred);
855 465983 : }
856 :
857 : /* Select what needs to be streamed out. In regular lto mode stream everything.
858 : In offload lto mode stream only nodes marked as offloadable. */
859 : void
860 31487 : select_what_to_stream (void)
861 : {
862 31487 : struct symtab_node *snode;
863 741220 : FOR_EACH_SYMBOL (snode)
864 1419466 : snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable;
865 31487 : }
866 :
867 : /* Find all symbols we want to stream into given partition and insert them
868 : to encoders.
869 :
870 : The function actually replaces IN_ENCODER by new one. The reason is that
871 : streaming code needs clone's origin to be streamed before clone. This
872 : means that we need to insert the nodes in specific order. This order is
873 : ignored by the partitioning logic earlier. */
874 :
875 : lto_symtab_encoder_t
876 31872 : compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
877 : {
878 31872 : struct cgraph_edge *edge;
879 31872 : int i;
880 31872 : lto_symtab_encoder_t encoder;
881 31872 : lto_symtab_encoder_iterator lsei;
882 31872 : hash_set<void *> reachable_call_targets;
883 :
884 31872 : encoder = lto_symtab_encoder_new (false);
885 :
886 : /* Go over all entries in the IN_ENCODER and duplicate them to
887 : ENCODER. At the same time insert masters of clones so
888 : every master appears before clone. */
889 31872 : for (lsei = lsei_start_function_in_partition (in_encoder);
890 202849 : !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
891 : {
892 170977 : struct cgraph_node *node = lsei_cgraph_node (lsei);
893 170977 : if (!node->need_lto_streaming)
894 0 : continue;
895 170977 : add_node_to (encoder, node, true);
896 170977 : lto_set_symtab_encoder_in_partition (encoder, node);
897 170977 : create_references (encoder, node);
898 : }
899 31872 : for (lsei = lsei_start_variable_in_partition (in_encoder);
900 313967 : !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
901 : {
902 282095 : varpool_node *vnode = lsei_varpool_node (lsei);
903 :
904 282095 : if (!vnode->need_lto_streaming)
905 0 : continue;
906 282095 : lto_set_symtab_encoder_in_partition (encoder, vnode);
907 282095 : lto_set_symtab_encoder_encode_initializer (encoder, vnode);
908 282095 : create_references (encoder, vnode);
909 : }
910 969965 : for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next (&lsei))
911 : {
912 453228 : toplevel_node *tnode = lsei_node (lsei);
913 906456 : if (asm_node* node = dyn_cast <asm_node*> (tnode))
914 : {
915 : symtab_node* ref;
916 453308 : for (unsigned i = 0; node->symbols_referenced.iterate (i, &ref); i++)
917 : {
918 40 : if (!lto_symtab_encoder_in_partition_p (encoder, ref))
919 : {
920 38 : if (cgraph_node* cref = dyn_cast <cgraph_node*> (ref))
921 12 : add_node_to (encoder, cref, false);
922 66 : else if (varpool_node *vref = dyn_cast <varpool_node *> (ref))
923 26 : lto_symtab_encoder_encode (encoder, vref);
924 : }
925 : }
926 : }
927 : }
928 : /* Pickle in also the initializer of all referenced readonly variables
929 : to help folding. Constant pool variables are not shared, so we must
930 : pickle those too. */
931 1389597 : for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
932 : {
933 663045 : toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
934 1326090 : if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
935 : {
936 286707 : if (!lto_symtab_encoder_encode_initializer_p (encoder,
937 : vnode)
938 286707 : && (((vnode->ctor_useable_for_folding_p ()
939 156 : && (!DECL_VIRTUAL_P (vnode->decl)
940 132 : || !flag_wpa
941 12 : || flag_ltrans_devirtualize)))))
942 : {
943 144 : lto_set_symtab_encoder_encode_initializer (encoder, vnode);
944 144 : create_references (encoder, vnode);
945 : }
946 : }
947 : }
948 :
949 : /* Go over all the nodes again to include callees that are not in
950 : SET. */
951 31872 : for (lsei = lsei_start_function_in_partition (encoder);
952 405461 : !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
953 : {
954 170977 : struct cgraph_node *node = lsei_cgraph_node (lsei);
955 801472 : for (edge = node->callees; edge; edge = edge->next_callee)
956 : {
957 630495 : struct cgraph_node *callee = edge->callee;
958 630495 : if (!lto_symtab_encoder_in_partition_p (encoder, callee))
959 : {
960 : /* We should have moved all the inlines. */
961 333732 : gcc_assert (!callee->inlined_to);
962 333732 : add_node_to (encoder, callee, false);
963 : }
964 : }
965 : /* Add all possible targets for late devirtualization. */
966 170977 : if (flag_ltrans_devirtualize || !flag_wpa)
967 108910 : for (edge = node->indirect_calls; edge; edge = edge->next_callee)
968 5406 : if (usable_polymorphic_info_p (edge->indirect_info))
969 : {
970 1070 : unsigned int i;
971 1070 : void *cache_token;
972 1070 : bool final;
973 1070 : vec <cgraph_node *>targets
974 : = possible_polymorphic_call_targets
975 1070 : (edge, &final, &cache_token);
976 1070 : if (cache_token != NULL
977 1070 : && !reachable_call_targets.add (cache_token))
978 : {
979 1474 : for (i = 0; i < targets.length (); i++)
980 : {
981 404 : struct cgraph_node *callee = targets[i];
982 :
983 : /* Adding an external declarations into the unit serves
984 : no purpose and just increases its boundary. */
985 404 : if (callee->definition
986 703 : && !lto_symtab_encoder_in_partition_p
987 299 : (encoder, callee))
988 : {
989 0 : gcc_assert (!callee->inlined_to);
990 0 : add_node_to (encoder, callee, false);
991 : }
992 : }
993 : }
994 : }
995 : }
996 : /* Be sure to also insert alias targert and thunk callees. These needs
997 : to stay to aid local calling conventions. */
998 1484059 : for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
999 : {
1000 710276 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
1001 710276 : symtab_node *node = dyn_cast <symtab_node *> (tnode);
1002 710276 : if (!node)
1003 0 : continue;
1004 :
1005 710276 : cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1006 :
1007 710276 : if (node->alias && node->analyzed)
1008 12767 : create_references (encoder, node);
1009 710276 : if (cnode
1010 423568 : && cnode->thunk && !cnode->inlined_to)
1011 165 : add_node_to (encoder, cnode->callees->callee, false);
1012 710283 : while (node->transparent_alias && node->analyzed)
1013 : {
1014 7 : node = node->get_alias_target ();
1015 7 : if (is_a <cgraph_node *> (node))
1016 7 : add_node_to (encoder, dyn_cast <cgraph_node *> (node),
1017 : false);
1018 : else
1019 0 : lto_symtab_encoder_encode (encoder, node);
1020 : }
1021 : }
1022 :
1023 485100 : for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next (&lsei))
1024 : {
1025 453228 : toplevel_node *tnode = lsei_node (lsei);
1026 906456 : if (asm_node* node = dyn_cast <asm_node*> (tnode))
1027 156 : lto_set_symtab_encoder_in_partition (encoder, node);
1028 : }
1029 31872 : lto_symtab_encoder_delete (in_encoder);
1030 31872 : return encoder;
1031 31872 : }
1032 :
1033 : /* Output the part of the symtab in SET and VSET. */
1034 :
1035 : void
1036 31872 : output_symtab (void)
1037 : {
1038 31872 : struct cgraph_node *node;
1039 31872 : struct lto_simple_output_block *ob;
1040 31872 : int i, n_nodes;
1041 31872 : lto_symtab_encoder_t encoder;
1042 :
1043 31872 : if (flag_wpa)
1044 8333 : output_cgraph_opt_summary ();
1045 :
1046 31872 : ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
1047 :
1048 31872 : output_profile_summary (ob);
1049 :
1050 : /* An encoder for cgraph nodes should have been created by
1051 : ipa_write_summaries_1. */
1052 31872 : gcc_assert (ob->decl_state->symtab_node_encoder);
1053 31872 : encoder = ob->decl_state->symtab_node_encoder;
1054 :
1055 : /* Write out the nodes. We must first output a node and then its clones,
1056 : otherwise at a time reading back the node there would be nothing to clone
1057 : from. */
1058 31872 : n_nodes = lto_symtab_encoder_size (encoder);
1059 742304 : for (i = 0; i < n_nodes; i++)
1060 : {
1061 710432 : toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
1062 710432 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
1063 423568 : lto_output_node (ob, cnode, encoder);
1064 997296 : else if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1065 286708 : lto_output_varpool_node (ob, vnode, encoder);
1066 : }
1067 :
1068 31872 : callback_info_sum_t::check_create_info_sum ();
1069 : /* Go over the nodes in SET again to write edges. */
1070 1516245 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
1071 : {
1072 1420864 : node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
1073 423568 : if (node
1074 423568 : && ((node->thunk && !node->inlined_to)
1075 423403 : || lto_symtab_encoder_in_partition_p (encoder, node)))
1076 : {
1077 170981 : output_outgoing_cgraph_edges (node->callees, ob, encoder);
1078 170981 : output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
1079 : }
1080 : }
1081 :
1082 31872 : streamer_write_uhwi_stream (ob->main_stream, 0);
1083 :
1084 31872 : lto_destroy_simple_output_block (ob);
1085 :
1086 : /* Emit toplevel asms. */
1087 31872 : if (!lto_stream_offload_p)
1088 31872 : lto_output_toplevel_asms (encoder);
1089 :
1090 31872 : output_refs (encoder);
1091 31872 : }
1092 :
1093 : /* Return identifier encoded in IB as a plain string. */
1094 :
1095 : static tree
1096 268873 : read_identifier (class lto_input_block *ib)
1097 : {
1098 268873 : unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1099 268873 : tree id;
1100 :
1101 268873 : if (ib->data[ib->p + len])
1102 0 : lto_section_overrun (ib);
1103 268873 : if (!len)
1104 : {
1105 258844 : ib->p++;
1106 258844 : return NULL;
1107 : }
1108 10029 : id = get_identifier (ib->data + ib->p);
1109 10029 : ib->p += len + 1;
1110 10029 : return id;
1111 : }
1112 :
1113 : /* Return string encoded in IB, NULL if string is empty. */
1114 :
1115 : static const char *
1116 268873 : read_string (class lto_input_block *ib)
1117 : {
1118 268873 : unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1119 268873 : const char *str;
1120 :
1121 268873 : if (ib->data[ib->p + len])
1122 0 : lto_section_overrun (ib);
1123 268873 : if (!len)
1124 : {
1125 266362 : ib->p++;
1126 266362 : return NULL;
1127 : }
1128 2511 : str = ib->data + ib->p;
1129 2511 : ib->p += len + 1;
1130 2511 : return str;
1131 : }
1132 :
1133 : /* Output function/variable tables that will allow libgomp to look up offload
1134 : target code.
1135 : OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1136 : varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1137 : both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1138 :
1139 : void
1140 7948 : output_offload_tables (void)
1141 : {
1142 15896 : bool output_requires = (flag_openmp
1143 7948 : && (omp_requires_mask & OMP_REQUIRES_TARGET_USED) != 0);
1144 7948 : if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars)
1145 7948 : && !output_requires)
1146 : return;
1147 :
1148 0 : struct lto_simple_output_block *ob
1149 0 : = lto_create_simple_output_block (LTO_section_offload_table);
1150 :
1151 0 : for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
1152 : {
1153 0 : symtab_node *node = symtab_node::get ((*offload_funcs)[i]);
1154 0 : if (!node)
1155 0 : continue;
1156 0 : node->force_output = true;
1157 0 : streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1158 : LTO_symtab_last_tag, LTO_symtab_unavail_node);
1159 0 : lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
1160 0 : (*offload_funcs)[i]);
1161 : }
1162 :
1163 0 : for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
1164 : {
1165 0 : symtab_node *node = symtab_node::get ((*offload_vars)[i]);
1166 0 : if (!node)
1167 0 : continue;
1168 0 : node->force_output = true;
1169 0 : streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1170 : LTO_symtab_last_tag, LTO_symtab_variable);
1171 0 : lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
1172 0 : (*offload_vars)[i]);
1173 : }
1174 :
1175 0 : for (unsigned i = 0; i < vec_safe_length (offload_ind_funcs); i++)
1176 : {
1177 0 : symtab_node *node = symtab_node::get ((*offload_ind_funcs)[i]);
1178 0 : if (!node)
1179 0 : continue;
1180 0 : node->force_output = true;
1181 0 : streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1182 : LTO_symtab_last_tag, LTO_symtab_indirect_function);
1183 0 : lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
1184 0 : (*offload_ind_funcs)[i]);
1185 : }
1186 :
1187 0 : if (output_requires)
1188 : {
1189 0 : HOST_WIDE_INT val = ((HOST_WIDE_INT) omp_requires_mask
1190 : & (OMP_REQUIRES_UNIFIED_ADDRESS
1191 : | OMP_REQUIRES_UNIFIED_SHARED_MEMORY
1192 : | OMP_REQUIRES_SELF_MAPS
1193 : | OMP_REQUIRES_REVERSE_OFFLOAD
1194 : | OMP_REQUIRES_TARGET_USED));
1195 : /* (Mis)use LTO_symtab_edge for this variable. */
1196 0 : streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1197 : LTO_symtab_last_tag, LTO_symtab_edge);
1198 0 : streamer_write_hwi_stream (ob->main_stream, val);
1199 : }
1200 :
1201 0 : streamer_write_uhwi_stream (ob->main_stream, 0);
1202 0 : lto_destroy_simple_output_block (ob);
1203 : }
1204 :
1205 : /* Verify the partitioning of NODE. */
1206 :
1207 : static inline void
1208 268873 : verify_node_partition (symtab_node *node)
1209 : {
1210 268873 : if (flag_ltrans)
1211 : return;
1212 :
1213 : #ifdef ACCEL_COMPILER
1214 : if (node->in_other_partition)
1215 : {
1216 : if (TREE_CODE (node->decl) == FUNCTION_DECL)
1217 : {
1218 : if (lookup_attribute ("omp target device_ancestor_host",
1219 : DECL_ATTRIBUTES (node->decl)) != NULL)
1220 : return;
1221 : error_at (DECL_SOURCE_LOCATION (node->decl),
1222 : "function %qs has been referenced in offloaded code but"
1223 : " hasn%'t been marked to be included in the offloaded code",
1224 : node->name ());
1225 : }
1226 : else if (VAR_P (node->decl))
1227 : error_at (DECL_SOURCE_LOCATION (node->decl),
1228 : "variable %qs has been referenced in offloaded code but"
1229 : " hasn%'t been marked to be included in the offloaded code",
1230 : node->name ());
1231 : else
1232 : gcc_unreachable ();
1233 : }
1234 : #else
1235 159894 : gcc_assert (!node->in_other_partition
1236 : && !node->used_from_other_partition);
1237 : #endif
1238 : }
1239 :
1240 : /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1241 : STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1242 : NODE or to replace the values in it, for instance because the first
1243 : time we saw it, the function body was not available but now it
1244 : is. BP is a bitpack with all the bitflags for NODE read from the
1245 : stream. Initialize HAS_THUNK_INFO to indicate if thunk info should
1246 : be streamed in. */
1247 :
1248 : static void
1249 197750 : input_overwrite_node (struct lto_file_decl_data *file_data,
1250 : struct cgraph_node *node,
1251 : enum LTO_symtab_tags tag,
1252 : struct bitpack_d *bp, bool *has_thunk_info)
1253 : {
1254 197750 : node->aux = (void *) tag;
1255 197750 : node->lto_file_data = file_data;
1256 :
1257 197750 : node->local = bp_unpack_value (bp, 1);
1258 197750 : node->externally_visible = bp_unpack_value (bp, 1);
1259 197750 : node->no_reorder = bp_unpack_value (bp, 1);
1260 197750 : node->definition = bp_unpack_value (bp, 1);
1261 197750 : node->versionable = bp_unpack_value (bp, 1);
1262 197750 : node->can_change_signature = bp_unpack_value (bp, 1);
1263 197750 : node->redefined_extern_inline = bp_unpack_value (bp, 1);
1264 197750 : node->force_output = bp_unpack_value (bp, 1);
1265 197750 : node->forced_by_abi = bp_unpack_value (bp, 1);
1266 197750 : node->ref_by_asm = bp_unpack_value (bp, 1);
1267 197750 : node->must_remain_in_tu_name = bp_unpack_value (bp, 1);
1268 197750 : node->must_remain_in_tu_body = bp_unpack_value (bp, 1);
1269 197750 : node->unique_name = bp_unpack_value (bp, 1);
1270 197750 : node->body_removed = bp_unpack_value (bp, 1);
1271 197750 : node->semantic_interposition = bp_unpack_value (bp, 1);
1272 197750 : node->implicit_section = bp_unpack_value (bp, 1);
1273 197750 : node->address_taken = bp_unpack_value (bp, 1);
1274 197750 : node->used_from_other_partition = bp_unpack_value (bp, 1);
1275 197750 : node->lowered = bp_unpack_value (bp, 1);
1276 197750 : node->analyzed = tag == LTO_symtab_analyzed_node;
1277 197750 : node->in_other_partition = bp_unpack_value (bp, 1);
1278 197750 : if (node->in_other_partition
1279 : /* Avoid updating decl when we are seeing just inline clone.
1280 : When inlining function that has functions already inlined into it,
1281 : we produce clones of inline clones.
1282 :
1283 : WPA partitioning might put each clone into different unit and
1284 : we might end up streaming inline clone from other partition
1285 : to support clone we are interested in. */
1286 255 : && (!node->clone_of
1287 0 : || node->clone_of->decl != node->decl))
1288 : {
1289 255 : DECL_EXTERNAL (node->decl) = 1;
1290 255 : TREE_STATIC (node->decl) = 0;
1291 : }
1292 197750 : node->alias = bp_unpack_value (bp, 1);
1293 197750 : node->transparent_alias = bp_unpack_value (bp, 1);
1294 197750 : node->weakref = bp_unpack_value (bp, 1);
1295 197750 : node->symver = bp_unpack_value (bp, 1);
1296 197750 : node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
1297 197750 : node->only_called_at_startup = bp_unpack_value (bp, 1);
1298 197750 : node->only_called_at_exit = bp_unpack_value (bp, 1);
1299 197750 : node->tm_clone = bp_unpack_value (bp, 1);
1300 197750 : node->calls_comdat_local = bp_unpack_value (bp, 1);
1301 197750 : node->icf_merged = bp_unpack_value (bp, 1);
1302 197750 : node->nonfreeing_fn = bp_unpack_value (bp, 1);
1303 197750 : node->merged_comdat = bp_unpack_value (bp, 1);
1304 197750 : node->merged_extern_inline = bp_unpack_value (bp, 1);
1305 197750 : node->thunk = bp_unpack_value (bp, 1);
1306 197750 : node->parallelized_function = bp_unpack_value (bp, 1);
1307 197750 : node->has_omp_variant_constructs = bp_unpack_value (bp, 1);
1308 197750 : *has_thunk_info = bp_unpack_value (bp, 1);
1309 197750 : node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
1310 : LDPR_NUM_KNOWN);
1311 197750 : node->split_part = bp_unpack_value (bp, 1);
1312 197750 : verify_node_partition (node);
1313 197750 : }
1314 :
1315 : /* Return string alias is alias of. */
1316 :
1317 : static tree
1318 24 : get_alias_symbol (tree decl)
1319 : {
1320 24 : tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1321 24 : return get_identifier (TREE_STRING_POINTER
1322 : (TREE_VALUE (TREE_VALUE (alias))));
1323 : }
1324 :
1325 : /* Read a node from input_block IB. TAG is the node's tag just read.
1326 : Return the node read or overwritten. */
1327 :
1328 : static struct cgraph_node *
1329 197750 : input_node (struct lto_file_decl_data *file_data,
1330 : class lto_input_block *ib,
1331 : enum LTO_symtab_tags tag,
1332 : vec<symtab_node *> nodes)
1333 : {
1334 197750 : gcc::pass_manager *passes = g->get_passes ();
1335 197750 : tree fn_decl;
1336 197750 : struct cgraph_node *node;
1337 197750 : struct bitpack_d bp;
1338 197750 : int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
1339 197750 : int clone_ref;
1340 197750 : int order;
1341 197750 : int i, count;
1342 197750 : tree group;
1343 197750 : const char *section;
1344 197750 : order = streamer_read_hwi (ib) + file_data->order_base;
1345 197750 : clone_ref = streamer_read_hwi (ib);
1346 197750 : bool has_thunk_info;
1347 :
1348 197750 : fn_decl = lto_input_fn_decl_ref (ib, file_data);
1349 :
1350 197750 : if (clone_ref != LCC_NOT_FOUND)
1351 : {
1352 46584 : node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
1353 : profile_count::uninitialized (), false,
1354 23292 : vNULL, false, NULL, NULL, NULL);
1355 : }
1356 : else
1357 : {
1358 : /* Declaration of functions can be already merged with a declaration
1359 : from other input file. We keep cgraph unmerged until after streaming
1360 : of ipa passes is done. Alays forcingly create a fresh node. */
1361 174458 : node = symtab->create_empty ();
1362 174458 : node->decl = fn_decl;
1363 174458 : if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl)))
1364 19 : node->ifunc_resolver = 1;
1365 174458 : node->register_symbol ();
1366 : }
1367 :
1368 197750 : node->order = order;
1369 197750 : if (order >= symtab->order)
1370 14714 : symtab->order = order + 1;
1371 :
1372 197750 : node->count = profile_count::stream_in (ib);
1373 197750 : node->count_materialization_scale = streamer_read_hwi (ib);
1374 :
1375 197750 : count = streamer_read_hwi (ib);
1376 197750 : node->ipa_transforms_to_apply = vNULL;
1377 266080 : for (i = 0; i < count; i++)
1378 : {
1379 68330 : opt_pass *pass;
1380 68330 : int pid = streamer_read_hwi (ib);
1381 :
1382 68330 : gcc_assert (pid < passes->passes_by_id_size);
1383 68330 : pass = passes->passes_by_id[pid];
1384 68330 : node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
1385 : }
1386 :
1387 197750 : if (tag == LTO_symtab_analyzed_node)
1388 153854 : ref = streamer_read_hwi (ib);
1389 :
1390 197750 : group = read_identifier (ib);
1391 197750 : if (group)
1392 7591 : ref2 = streamer_read_hwi (ib);
1393 :
1394 : /* Make sure that we have not read this node before. Nodes that
1395 : have already been read will have their tag stored in the 'aux'
1396 : field. Since built-in functions can be referenced in multiple
1397 : functions, they are expected to be read more than once. */
1398 197750 : if (node->aux && !fndecl_built_in_p (node->decl))
1399 0 : internal_error ("bytecode stream: found multiple instances of cgraph "
1400 : "node with uid %d", node->get_uid ());
1401 :
1402 197750 : node->tp_first_run = streamer_read_uhwi (ib);
1403 :
1404 197750 : bp = streamer_read_bitpack (ib);
1405 :
1406 197750 : input_overwrite_node (file_data, node, tag, &bp, &has_thunk_info);
1407 :
1408 : /* Store a reference for now, and fix up later to be a pointer. */
1409 197750 : node->inlined_to = (cgraph_node *) (intptr_t) ref;
1410 :
1411 197750 : if (group)
1412 : {
1413 7591 : node->set_comdat_group (group);
1414 : /* Store a reference for now, and fix up later to be a pointer. */
1415 7591 : node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
1416 : }
1417 : else
1418 : node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1419 197750 : section = read_string (ib);
1420 197750 : if (section)
1421 182 : node->set_section_for_node (section);
1422 :
1423 197750 : if (node->alias && !node->analyzed && node->weakref)
1424 24 : node->alias_target = get_alias_symbol (node->decl);
1425 197750 : node->profile_id = streamer_read_hwi (ib);
1426 197750 : node->unit_id = streamer_read_hwi (ib) + file_data->unit_base;
1427 197750 : if (symtab->max_unit < node->unit_id)
1428 22015 : symtab->max_unit = node->unit_id;
1429 197750 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
1430 152 : node->set_init_priority (streamer_read_hwi (ib));
1431 197750 : if (DECL_STATIC_DESTRUCTOR (node->decl))
1432 56 : node->set_fini_priority (streamer_read_hwi (ib));
1433 :
1434 197750 : if (has_thunk_info)
1435 159 : thunk_info::get_create (node)->stream_in (ib);
1436 :
1437 197750 : return node;
1438 : }
1439 :
1440 : /* Read a node from input_block IB. TAG is the node's tag just read.
1441 : Return the node read or overwritten. */
1442 :
1443 : static varpool_node *
1444 71123 : input_varpool_node (struct lto_file_decl_data *file_data,
1445 : class lto_input_block *ib)
1446 : {
1447 71123 : tree var_decl;
1448 71123 : varpool_node *node;
1449 71123 : struct bitpack_d bp;
1450 71123 : int ref = LCC_NOT_FOUND;
1451 71123 : int order;
1452 71123 : tree group;
1453 71123 : const char *section;
1454 :
1455 71123 : order = streamer_read_hwi (ib) + file_data->order_base;
1456 71123 : var_decl = lto_input_var_decl_ref (ib, file_data);
1457 :
1458 : /* Declaration of functions can be already merged with a declaration
1459 : from other input file. We keep cgraph unmerged until after streaming
1460 : of ipa passes is done. Alays forcingly create a fresh node. */
1461 71123 : node = varpool_node::create_empty ();
1462 71123 : node->decl = var_decl;
1463 71123 : node->register_symbol ();
1464 :
1465 71123 : node->order = order;
1466 71123 : if (order >= symtab->order)
1467 1698 : symtab->order = order + 1;
1468 71123 : node->lto_file_data = file_data;
1469 :
1470 71123 : bp = streamer_read_bitpack (ib);
1471 71123 : node->externally_visible = bp_unpack_value (&bp, 1);
1472 71123 : node->no_reorder = bp_unpack_value (&bp, 1);
1473 71123 : node->force_output = bp_unpack_value (&bp, 1);
1474 71123 : node->forced_by_abi = bp_unpack_value (&bp, 1);
1475 71123 : node->ref_by_asm = bp_unpack_value (&bp, 1);
1476 71123 : node->must_remain_in_tu_name = bp_unpack_value (&bp, 1);
1477 71123 : node->must_remain_in_tu_body = bp_unpack_value (&bp, 1);
1478 71123 : node->unique_name = bp_unpack_value (&bp, 1);
1479 71123 : node->body_removed = bp_unpack_value (&bp, 1);
1480 71123 : node->semantic_interposition = bp_unpack_value (&bp, 1);
1481 71123 : node->implicit_section = bp_unpack_value (&bp, 1);
1482 71123 : node->writeonly = bp_unpack_value (&bp, 1);
1483 71123 : node->definition = bp_unpack_value (&bp, 1);
1484 71123 : node->alias = bp_unpack_value (&bp, 1);
1485 71123 : node->transparent_alias = bp_unpack_value (&bp, 1);
1486 71123 : node->weakref = bp_unpack_value (&bp, 1);
1487 71123 : node->symver = bp_unpack_value (&bp, 1);
1488 71123 : node->analyzed = bp_unpack_value (&bp, 1);
1489 71123 : node->used_from_other_partition = bp_unpack_value (&bp, 1);
1490 71123 : node->in_other_partition = bp_unpack_value (&bp, 1);
1491 71123 : if (node->in_other_partition)
1492 : {
1493 203 : DECL_EXTERNAL (node->decl) = 1;
1494 203 : TREE_STATIC (node->decl) = 0;
1495 : }
1496 71123 : if (node->alias && !node->analyzed && node->weakref)
1497 0 : node->alias_target = get_alias_symbol (node->decl);
1498 71123 : node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
1499 71123 : node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
1500 71123 : node->dynamically_initialized = bp_unpack_value (&bp, 1);
1501 71123 : group = read_identifier (ib);
1502 71123 : if (group)
1503 : {
1504 2438 : node->set_comdat_group (group);
1505 2438 : ref = streamer_read_hwi (ib);
1506 : /* Store a reference for now, and fix up later to be a pointer. */
1507 2438 : node->same_comdat_group = (symtab_node *) (intptr_t) ref;
1508 : }
1509 : else
1510 : node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1511 71123 : section = read_string (ib);
1512 71123 : if (section)
1513 2329 : node->set_section_for_node (section);
1514 71123 : node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
1515 : LDPR_NUM_KNOWN);
1516 71123 : verify_node_partition (node);
1517 71123 : return node;
1518 : }
1519 :
1520 : /* Read a node from input_block IB. TAG is the node's tag just read.
1521 : Return the node read or overwritten. */
1522 :
1523 : static void
1524 448780 : input_ref (class lto_input_block *ib,
1525 : symtab_node *referring_node,
1526 : vec<symtab_node *> nodes)
1527 : {
1528 448780 : symtab_node *node = NULL;
1529 448780 : struct bitpack_d bp;
1530 448780 : enum ipa_ref_use use;
1531 448780 : bool speculative;
1532 448780 : struct ipa_ref *ref;
1533 :
1534 448780 : bp = streamer_read_bitpack (ib);
1535 448780 : use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
1536 448780 : speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
1537 448780 : node = nodes[streamer_read_hwi (ib)];
1538 448780 : ref = referring_node->create_reference (node, use);
1539 448780 : ref->speculative = speculative;
1540 448780 : if (is_a <cgraph_node *> (referring_node))
1541 : {
1542 428077 : ref->lto_stmt_uid = streamer_read_hwi (ib);
1543 428077 : bp = streamer_read_bitpack (ib);
1544 428077 : ref->speculative_id = bp_unpack_value (&bp, 16);
1545 : }
1546 448780 : }
1547 :
1548 : /* Read an edge from IB. NODES points to a vector of previously read nodes for
1549 : decoding caller and callee of the edge to be read. If INDIRECT is true, the
1550 : edge being read is indirect (in the sense that it has
1551 : indirect_unknown_callee set). */
1552 :
1553 : static void
1554 602387 : input_edge (class lto_input_block *ib, vec<symtab_node *> nodes,
1555 : bool indirect)
1556 : {
1557 602387 : struct cgraph_node *caller, *callee;
1558 602387 : struct cgraph_edge *edge;
1559 602387 : unsigned int stmt_id, speculative_id;
1560 602387 : profile_count count;
1561 602387 : cgraph_inline_failed_t inline_failed;
1562 602387 : struct bitpack_d bp;
1563 :
1564 602387 : caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1565 602387 : if (caller == NULL || caller->decl == NULL_TREE)
1566 0 : internal_error ("bytecode stream: no caller found while reading edge");
1567 :
1568 602387 : if (!indirect)
1569 : {
1570 599978 : callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1571 599978 : if (callee == NULL || callee->decl == NULL_TREE)
1572 0 : internal_error ("bytecode stream: no callee found while reading edge");
1573 : }
1574 : else
1575 : callee = NULL;
1576 :
1577 602387 : count = profile_count::stream_in (ib);
1578 :
1579 602387 : bp = streamer_read_bitpack (ib);
1580 602387 : inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
1581 602387 : stmt_id = bp_unpack_var_len_unsigned (&bp);
1582 602387 : speculative_id = bp_unpack_value (&bp, 16);
1583 :
1584 602387 : if (indirect)
1585 2409 : edge = caller->create_indirect_edge (NULL, 0, count, true);
1586 : else
1587 599978 : edge = caller->create_edge (callee, NULL, count);
1588 :
1589 602387 : edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
1590 602387 : edge->speculative = bp_unpack_value (&bp, 1);
1591 602387 : edge->callback = bp_unpack_value(&bp, 1);
1592 602387 : edge->has_callback = bp_unpack_value(&bp, 1);
1593 :
1594 602387 : if (edge->callback)
1595 : {
1596 4 : callback_info *ci = callback_info_sum->get_create (edge);
1597 4 : ci->stream_in (ib);
1598 : }
1599 :
1600 602387 : edge->lto_stmt_uid = stmt_id;
1601 602387 : edge->speculative_id = speculative_id;
1602 602387 : edge->inline_failed = inline_failed;
1603 602387 : edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1604 602387 : edge->can_throw_external = bp_unpack_value (&bp, 1);
1605 602387 : edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
1606 602387 : if (indirect)
1607 : {
1608 2409 : enum cgraph_indirect_info_kind ii_kind
1609 2409 : = bp_unpack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS);
1610 2409 : int ecf_flags = 0;
1611 2409 : if (bp_unpack_value (&bp, 1))
1612 0 : ecf_flags |= ECF_CONST;
1613 2409 : if (bp_unpack_value (&bp, 1))
1614 0 : ecf_flags |= ECF_PURE;
1615 2409 : if (bp_unpack_value (&bp, 1))
1616 0 : ecf_flags |= ECF_NORETURN;
1617 2409 : if (bp_unpack_value (&bp, 1))
1618 0 : ecf_flags |= ECF_MALLOC;
1619 2409 : if (bp_unpack_value (&bp, 1))
1620 288 : ecf_flags |= ECF_NOTHROW;
1621 2409 : if (bp_unpack_value (&bp, 1))
1622 0 : ecf_flags |= ECF_RETURNS_TWICE;
1623 :
1624 2409 : if (ii_kind == CIIK_POLYMORPHIC)
1625 426 : edge->indirect_info
1626 426 : = (new (ggc_alloc<cgraph_polymorphic_indirect_info> ())
1627 426 : cgraph_polymorphic_indirect_info (ecf_flags));
1628 1983 : else if (ii_kind == CIIK_SIMPLE)
1629 1969 : edge->indirect_info
1630 1969 : = (new (ggc_alloc<cgraph_simple_indirect_info> ())
1631 1969 : cgraph_simple_indirect_info (ecf_flags));
1632 : else
1633 14 : edge->indirect_info
1634 14 : = (new (ggc_alloc<cgraph_indirect_call_info> ())
1635 14 : cgraph_indirect_call_info(CIIK_UNSPECIFIED, ecf_flags));
1636 :
1637 4818 : edge->indirect_info->num_speculative_call_targets
1638 2409 : = bp_unpack_value (&bp, 16);
1639 : }
1640 602387 : }
1641 :
1642 :
1643 : /* Read a cgraph from IB using the info in FILE_DATA. */
1644 :
1645 : static vec<symtab_node *>
1646 21893 : input_cgraph_1 (struct lto_file_decl_data *file_data,
1647 : class lto_input_block *ib)
1648 : {
1649 21893 : enum LTO_symtab_tags tag;
1650 21893 : vec<symtab_node *> nodes = vNULL;
1651 21893 : symtab_node *node;
1652 21893 : unsigned i;
1653 :
1654 21893 : tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1655 21893 : file_data->order_base = symtab->order;
1656 21893 : file_data->unit_base = symtab->max_unit + 1;
1657 21893 : callback_info_sum_t::check_create_info_sum ();
1658 915046 : while (tag)
1659 : {
1660 871260 : if (tag == LTO_symtab_edge)
1661 599978 : input_edge (ib, nodes, false);
1662 271282 : else if (tag == LTO_symtab_indirect_edge)
1663 2409 : input_edge (ib, nodes, true);
1664 268873 : else if (tag == LTO_symtab_variable)
1665 : {
1666 71123 : node = input_varpool_node (file_data, ib);
1667 71123 : nodes.safe_push (node);
1668 71123 : lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1669 : }
1670 : else
1671 : {
1672 197750 : node = input_node (file_data, ib, tag, nodes);
1673 197750 : if (node == NULL || node->decl == NULL_TREE)
1674 0 : internal_error ("bytecode stream: found empty cgraph node");
1675 197750 : nodes.safe_push (node);
1676 197750 : lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1677 : }
1678 :
1679 871260 : tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1680 : }
1681 :
1682 : /* AUX pointers should be all non-zero for function nodes read from the stream. */
1683 21893 : if (flag_checking)
1684 : {
1685 312598 : FOR_EACH_VEC_ELT (nodes, i, node)
1686 268873 : gcc_assert (node->aux || !is_a <cgraph_node *> (node));
1687 : }
1688 312598 : FOR_EACH_VEC_ELT (nodes, i, node)
1689 : {
1690 268873 : int ref;
1691 268873 : if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
1692 : {
1693 197750 : ref = (int) (intptr_t) cnode->inlined_to;
1694 :
1695 : /* We share declaration of builtins, so we may read same node twice. */
1696 197750 : if (!node->aux)
1697 0 : continue;
1698 197750 : node->aux = NULL;
1699 :
1700 : /* Fixup inlined_to from reference to pointer. */
1701 197750 : if (ref != LCC_NOT_FOUND)
1702 42936 : dyn_cast<cgraph_node *> (node)->inlined_to
1703 42936 : = dyn_cast<cgraph_node *> (nodes[ref]);
1704 : else
1705 176282 : cnode->inlined_to = NULL;
1706 : }
1707 :
1708 268873 : ref = (int) (intptr_t) node->same_comdat_group;
1709 :
1710 : /* Fixup same_comdat_group from reference to pointer. */
1711 268873 : if (ref != LCC_NOT_FOUND)
1712 3927 : node->same_comdat_group = nodes[ref];
1713 : else
1714 264946 : node->same_comdat_group = NULL;
1715 : }
1716 290766 : FOR_EACH_VEC_ELT (nodes, i, node)
1717 537746 : node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
1718 21893 : return nodes;
1719 : }
1720 :
1721 : /* Input ipa_refs. */
1722 :
1723 : static void
1724 21893 : input_refs (class lto_input_block *ib,
1725 : vec<symtab_node *> nodes)
1726 : {
1727 87152 : int count;
1728 87152 : int idx;
1729 87152 : while (true)
1730 : {
1731 87152 : symtab_node *node;
1732 87152 : count = streamer_read_uhwi (ib);
1733 87152 : if (!count)
1734 : break;
1735 65259 : idx = streamer_read_uhwi (ib);
1736 65259 : node = nodes[idx];
1737 514039 : while (count)
1738 : {
1739 448780 : input_ref (ib, node, nodes);
1740 448780 : count--;
1741 : }
1742 : }
1743 21893 : }
1744 :
1745 : /* Input profile_info from IB. */
1746 : static void
1747 21893 : input_profile_summary (class lto_input_block *ib,
1748 : struct lto_file_decl_data *file_data)
1749 : {
1750 21893 : unsigned int runs = streamer_read_uhwi (ib);
1751 21893 : if (runs)
1752 : {
1753 13 : file_data->profile_info.runs = runs;
1754 13 : file_data->profile_info.sum_max = streamer_read_gcov_count (ib);
1755 13 : file_data->profile_info.cutoff = streamer_read_gcov_count (ib);
1756 :
1757 : /* IPA-profile computes hot bb threshold based on cumulated
1758 : whole program profile. We need to stream it down to ltrans. */
1759 13 : if (flag_ltrans)
1760 5 : set_hot_bb_threshold (streamer_read_gcov_count (ib));
1761 : }
1762 :
1763 21893 : }
1764 :
1765 : /* Rescale profile summaries to the same number of runs in the whole unit. */
1766 :
1767 : static void
1768 20801 : merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1769 : {
1770 20801 : struct lto_file_decl_data *file_data;
1771 20801 : unsigned int j;
1772 20801 : gcov_unsigned_t max_runs = 0;
1773 20801 : struct cgraph_node *node;
1774 20801 : struct cgraph_edge *edge;
1775 :
1776 : /* Find unit with maximal number of runs. If we ever get serious about
1777 : roundoff errors, we might also consider computing smallest common
1778 : multiply. */
1779 42694 : for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1780 21893 : if (max_runs < file_data->profile_info.runs)
1781 : max_runs = file_data->profile_info.runs;
1782 :
1783 20801 : if (!max_runs)
1784 : return;
1785 :
1786 : /* Simple overflow check. We probably don't need to support that many train
1787 : runs. Such a large value probably imply data corruption anyway. */
1788 10 : if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1789 : {
1790 0 : sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1791 : INT_MAX / REG_BR_PROB_BASE);
1792 0 : return;
1793 : }
1794 :
1795 10 : profile_info = XCNEW (gcov_summary);
1796 10 : profile_info->runs = max_runs;
1797 10 : profile_info->sum_max = 0;
1798 10 : profile_info->cutoff = 0;
1799 :
1800 : /* If merging already happent at WPA time, we are done. */
1801 10 : if (flag_ltrans)
1802 : return;
1803 :
1804 : /* Now compute count_materialization_scale of each node.
1805 : During LTRANS we already have values of count_materialization_scale
1806 : computed, so just update them. */
1807 32 : FOR_EACH_FUNCTION (node)
1808 27 : if (node->lto_file_data
1809 27 : && node->lto_file_data->profile_info.runs)
1810 : {
1811 27 : int scale;
1812 :
1813 27 : scale = RDIV (node->count_materialization_scale * max_runs,
1814 : node->lto_file_data->profile_info.runs);
1815 27 : gcov_type sum_max = RDIV (node->lto_file_data->profile_info.sum_max * max_runs,
1816 : node->lto_file_data->profile_info.runs);
1817 27 : gcov_type cutoff = RDIV (node->lto_file_data->profile_info.cutoff * max_runs,
1818 : node->lto_file_data->profile_info.runs);
1819 27 : if (sum_max > profile_info->sum_max)
1820 5 : profile_info->sum_max = sum_max;
1821 27 : if (cutoff > profile_info->cutoff)
1822 5 : profile_info->cutoff = cutoff;
1823 27 : node->count_materialization_scale = scale;
1824 27 : if (scale < 0)
1825 0 : fatal_error (input_location, "Profile information in %s corrupted",
1826 : file_data->file_name);
1827 :
1828 27 : if (scale == REG_BR_PROB_BASE)
1829 27 : continue;
1830 0 : for (edge = node->callees; edge; edge = edge->next_callee)
1831 0 : if (edge->count.ipa ().nonzero_p ())
1832 0 : edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1833 0 : for (edge = node->indirect_calls; edge; edge = edge->next_callee)
1834 0 : if (edge->count.ipa ().nonzero_p ())
1835 0 : edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1836 0 : if (node->count.ipa ().nonzero_p ())
1837 0 : node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE);
1838 : }
1839 : }
1840 :
1841 : /* Input and merge the symtab from each of the .o files passed to
1842 : lto1. */
1843 :
1844 : void
1845 20801 : input_symtab (void)
1846 : {
1847 20801 : struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1848 20801 : struct lto_file_decl_data *file_data;
1849 20801 : unsigned int j = 0;
1850 20801 : struct cgraph_node *node;
1851 :
1852 63495 : while ((file_data = file_data_vec[j++]))
1853 : {
1854 21893 : const char *data;
1855 21893 : size_t len;
1856 21893 : class lto_input_block *ib;
1857 21893 : vec<symtab_node *> nodes;
1858 :
1859 21893 : ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
1860 : &data, &len);
1861 21893 : if (!ib)
1862 0 : fatal_error (input_location,
1863 : "cannot find LTO cgraph in %s", file_data->file_name);
1864 21893 : input_profile_summary (ib, file_data);
1865 21893 : file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
1866 21893 : nodes = input_cgraph_1 (file_data, ib);
1867 21893 : lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
1868 : ib, data, len);
1869 :
1870 21893 : ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1871 : &data, &len);
1872 21893 : if (!ib)
1873 0 : fatal_error (input_location, "cannot find LTO section refs in %s",
1874 : file_data->file_name);
1875 21893 : input_refs (ib, nodes);
1876 21893 : lto_destroy_simple_input_block (file_data, LTO_section_refs,
1877 : ib, data, len);
1878 21893 : if (flag_ltrans)
1879 8333 : input_cgraph_opt_summary (nodes);
1880 21893 : nodes.release ();
1881 : }
1882 :
1883 20801 : merge_profile_summaries (file_data_vec);
1884 :
1885 : /* Clear out the aux field that was used to store enough state to
1886 : tell which nodes should be overwritten. */
1887 218551 : FOR_EACH_FUNCTION (node)
1888 : {
1889 : /* Some nodes may have been created by cgraph_node. This
1890 : happens when the callgraph contains nested functions. If the
1891 : node for the parent function was never emitted to the gimple
1892 : file, cgraph_node will create a node for it when setting the
1893 : context of the nested function. */
1894 197750 : if (node->lto_file_data)
1895 197750 : node->aux = NULL;
1896 : }
1897 20801 : }
1898 :
1899 : /* Input toplevel asms from each of the .o files passed to lto1.
1900 : Must be called after merging of decls. */
1901 : void
1902 20801 : input_toplevel_asms (void)
1903 : {
1904 20801 : struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1905 20801 : struct lto_file_decl_data *file_data;
1906 20801 : unsigned int j = 0;
1907 :
1908 63495 : while ((file_data = file_data_vec[j++]))
1909 21893 : lto_input_toplevel_asms (file_data, file_data->order_base);
1910 20801 : }
1911 :
1912 : static void
1913 0 : omp_requires_to_name (char *buf, size_t size, HOST_WIDE_INT requires_mask)
1914 : {
1915 0 : char *end = buf + size, *p = buf;
1916 0 : if (requires_mask & GOMP_REQUIRES_UNIFIED_ADDRESS)
1917 0 : p += snprintf (p, end - p, "unified_address");
1918 0 : if (requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY)
1919 0 : p += snprintf (p, end - p, "%sunified_shared_memory",
1920 : (p == buf ? "" : ", "));
1921 0 : if (requires_mask & GOMP_REQUIRES_SELF_MAPS)
1922 0 : p += snprintf (p, end - p, "%sself_maps",
1923 : (p == buf ? "" : ", "));
1924 0 : if (requires_mask & GOMP_REQUIRES_REVERSE_OFFLOAD)
1925 0 : p += snprintf (p, end - p, "%sreverse_offload",
1926 : (p == buf ? "" : ", "));
1927 0 : }
1928 :
1929 : /* Input function/variable tables that will allow libgomp to look up offload
1930 : target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1931 :
1932 : void
1933 20801 : input_offload_tables (bool do_force_output)
1934 : {
1935 20801 : struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1936 20801 : struct lto_file_decl_data *file_data;
1937 20801 : unsigned int j = 0;
1938 20801 : const char *requires_fn = NULL;
1939 20801 : tree requires_decl = NULL_TREE;
1940 :
1941 20801 : omp_requires_mask = (omp_requires) 0;
1942 :
1943 42694 : while ((file_data = file_data_vec[j++]))
1944 : {
1945 21893 : const char *data;
1946 21893 : size_t len;
1947 21893 : class lto_input_block *ib
1948 21893 : = lto_create_simple_input_block (file_data, LTO_section_offload_table,
1949 : &data, &len);
1950 21893 : if (!ib)
1951 21893 : continue;
1952 :
1953 0 : tree tmp_decl = NULL_TREE;
1954 0 : enum LTO_symtab_tags tag
1955 0 : = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1956 0 : while (tag)
1957 : {
1958 : if (tag == LTO_symtab_unavail_node)
1959 : {
1960 0 : tree fn_decl
1961 0 : = lto_input_fn_decl_ref (ib, file_data);
1962 0 : vec_safe_push (offload_funcs, fn_decl);
1963 :
1964 : /* Prevent IPA from removing fn_decl as unreachable, since there
1965 : may be no refs from the parent function to child_fn in offload
1966 : LTO mode. */
1967 0 : if (do_force_output)
1968 0 : cgraph_node::get (fn_decl)->mark_force_output ();
1969 0 : tmp_decl = fn_decl;
1970 : }
1971 : else if (tag == LTO_symtab_variable)
1972 : {
1973 0 : tree var_decl
1974 0 : = lto_input_var_decl_ref (ib, file_data);
1975 0 : vec_safe_push (offload_vars, var_decl);
1976 :
1977 : /* Prevent IPA from removing var_decl as unused, since there
1978 : may be no refs to var_decl in offload LTO mode. */
1979 0 : if (do_force_output)
1980 0 : varpool_node::get (var_decl)->force_output = 1;
1981 0 : tmp_decl = var_decl;
1982 : }
1983 : else if (tag == LTO_symtab_indirect_function)
1984 : {
1985 0 : tree fn_decl
1986 0 : = lto_input_fn_decl_ref (ib, file_data);
1987 0 : vec_safe_push (offload_ind_funcs, fn_decl);
1988 :
1989 : /* Prevent IPA from removing fn_decl as unreachable, since there
1990 : may be no refs from the parent function to child_fn in offload
1991 : LTO mode. */
1992 0 : if (do_force_output)
1993 0 : cgraph_node::get (fn_decl)->mark_force_output ();
1994 0 : tmp_decl = fn_decl;
1995 : }
1996 : else if (tag == LTO_symtab_edge)
1997 : {
1998 0 : static bool error_emitted = false;
1999 0 : HOST_WIDE_INT val = streamer_read_hwi (ib);
2000 :
2001 0 : if (omp_requires_mask == 0)
2002 : {
2003 0 : omp_requires_mask = (omp_requires) val;
2004 0 : requires_decl = tmp_decl;
2005 0 : requires_fn = file_data->file_name;
2006 : }
2007 0 : else if (omp_requires_mask != val && !error_emitted)
2008 : {
2009 0 : const char *fn1 = requires_fn;
2010 0 : if (requires_decl != NULL_TREE)
2011 : {
2012 0 : while (DECL_CONTEXT (requires_decl) != NULL_TREE
2013 0 : && TREE_CODE (requires_decl) != TRANSLATION_UNIT_DECL)
2014 0 : requires_decl = DECL_CONTEXT (requires_decl);
2015 0 : if (requires_decl != NULL_TREE)
2016 0 : fn1 = IDENTIFIER_POINTER (DECL_NAME (requires_decl));
2017 : }
2018 :
2019 0 : const char *fn2 = file_data->file_name;
2020 0 : if (tmp_decl != NULL_TREE)
2021 : {
2022 0 : while (DECL_CONTEXT (tmp_decl) != NULL_TREE
2023 0 : && TREE_CODE (tmp_decl) != TRANSLATION_UNIT_DECL)
2024 0 : tmp_decl = DECL_CONTEXT (tmp_decl);
2025 0 : if (tmp_decl != NULL_TREE)
2026 0 : fn2 = IDENTIFIER_POINTER (DECL_NAME (tmp_decl));
2027 : }
2028 0 : if (fn1 == fn2)
2029 : {
2030 0 : fn1 = requires_fn;
2031 0 : fn2 = file_data->file_name;
2032 : }
2033 :
2034 0 : char buf1[sizeof ("unified_address, unified_shared_memory, "
2035 : "reverse_offload")];
2036 0 : char buf2[sizeof ("unified_address, unified_shared_memory, "
2037 : "reverse_offload")];
2038 0 : omp_requires_to_name (buf2, sizeof (buf2),
2039 : val != OMP_REQUIRES_TARGET_USED
2040 : ? val
2041 : : (HOST_WIDE_INT) omp_requires_mask);
2042 0 : if (val != OMP_REQUIRES_TARGET_USED
2043 0 : && omp_requires_mask != OMP_REQUIRES_TARGET_USED)
2044 : {
2045 0 : omp_requires_to_name (buf1, sizeof (buf1),
2046 : omp_requires_mask);
2047 0 : error ("OpenMP %<requires%> directive with non-identical "
2048 : "clauses in multiple compilation units: %qs vs. "
2049 : "%qs", buf1, buf2);
2050 0 : inform (UNKNOWN_LOCATION, "%qs has %qs", fn1, buf1);
2051 0 : inform (UNKNOWN_LOCATION, "%qs has %qs", fn2, buf2);
2052 : }
2053 : else
2054 : {
2055 0 : error ("OpenMP %<requires%> directive with %qs specified "
2056 : "only in some compilation units", buf2);
2057 0 : inform (UNKNOWN_LOCATION, "%qs has %qs",
2058 : val != OMP_REQUIRES_TARGET_USED ? fn2 : fn1,
2059 : buf2);
2060 0 : inform (UNKNOWN_LOCATION, "but %qs has not",
2061 : val != OMP_REQUIRES_TARGET_USED ? fn1 : fn2);
2062 : }
2063 0 : error_emitted = true;
2064 : }
2065 : }
2066 : else
2067 0 : fatal_error (input_location,
2068 : "invalid offload table in %s", file_data->file_name);
2069 :
2070 0 : tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
2071 : }
2072 :
2073 0 : lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
2074 : ib, data, len);
2075 : }
2076 : #ifdef ACCEL_COMPILER
2077 : char *omp_requires_file = getenv ("GCC_OFFLOAD_OMP_REQUIRES_FILE");
2078 : if (omp_requires_file == NULL || omp_requires_file[0] == '\0')
2079 : fatal_error (input_location, "GCC_OFFLOAD_OMP_REQUIRES_FILE unset");
2080 : FILE *f = fopen (omp_requires_file, "wb");
2081 : if (!f)
2082 : fatal_error (input_location, "Cannot open omp_requires file %qs",
2083 : omp_requires_file);
2084 : uint32_t req_mask = omp_requires_mask;
2085 : fwrite (&req_mask, sizeof (req_mask), 1, f);
2086 : fclose (f);
2087 : #endif
2088 20801 : }
2089 :
2090 : /* True when we need optimization summary for NODE. */
2091 :
2092 : static int
2093 167872 : output_cgraph_opt_summary_p (struct cgraph_node *node)
2094 : {
2095 167872 : if (node->clone_of || node->former_clone_of)
2096 : return true;
2097 121272 : clone_info *info = clone_info::get (node);
2098 121272 : return info && (info->tree_map || info->param_adjustments);
2099 : }
2100 :
2101 : /* Output optimization summary for EDGE to OB. */
2102 : static void
2103 0 : output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
2104 : struct cgraph_edge *edge ATTRIBUTE_UNUSED)
2105 : {
2106 0 : }
2107 :
2108 : /* Output optimization summary for NODE to OB. */
2109 :
2110 : static void
2111 23300 : output_node_opt_summary (struct output_block *ob,
2112 : struct cgraph_node *node,
2113 : lto_symtab_encoder_t encoder)
2114 : {
2115 23300 : struct ipa_replace_map *map;
2116 23300 : int i;
2117 23300 : struct cgraph_edge *e;
2118 :
2119 : /* TODO: Should this code be moved to ipa-param-manipulation? */
2120 23300 : struct bitpack_d bp;
2121 23300 : bp = bitpack_create (ob->main_stream);
2122 23300 : clone_info *info = clone_info::get (node);
2123 :
2124 26882 : bp_pack_value (&bp, (info && info->param_adjustments != NULL), 1);
2125 23300 : streamer_write_bitpack (&bp);
2126 19913 : if (ipa_param_adjustments *adjustments
2127 23300 : = info ? info->param_adjustments : NULL)
2128 : {
2129 19718 : streamer_write_uhwi (ob, vec_safe_length (adjustments->m_adj_params));
2130 19718 : ipa_adjusted_param *adj;
2131 77039 : FOR_EACH_VEC_SAFE_ELT (adjustments->m_adj_params, i, adj)
2132 : {
2133 37603 : bp = bitpack_create (ob->main_stream);
2134 37603 : bp_pack_value (&bp, adj->base_index, IPA_PARAM_MAX_INDEX_BITS);
2135 37603 : bp_pack_value (&bp, adj->prev_clone_index, IPA_PARAM_MAX_INDEX_BITS);
2136 37603 : bp_pack_value (&bp, adj->op, 2);
2137 37603 : bp_pack_value (&bp, adj->param_prefix_index, 2);
2138 37603 : bp_pack_value (&bp, adj->prev_clone_adjustment, 1);
2139 37603 : bp_pack_value (&bp, adj->reverse, 1);
2140 37603 : bp_pack_value (&bp, adj->user_flag, 1);
2141 37603 : streamer_write_bitpack (&bp);
2142 37603 : if (adj->op == IPA_PARAM_OP_SPLIT
2143 37603 : || adj->op == IPA_PARAM_OP_NEW)
2144 : {
2145 667 : stream_write_tree (ob, adj->type, true);
2146 667 : if (adj->op == IPA_PARAM_OP_SPLIT)
2147 : {
2148 667 : stream_write_tree (ob, adj->alias_ptr_type, true);
2149 667 : streamer_write_uhwi (ob, adj->unit_offset);
2150 : }
2151 : }
2152 : }
2153 19718 : streamer_write_hwi (ob, adjustments->m_always_copy_start);
2154 19718 : bp = bitpack_create (ob->main_stream);
2155 19718 : bp_pack_value (&bp, info->param_adjustments->m_skip_return, 1);
2156 19718 : streamer_write_bitpack (&bp);
2157 : }
2158 :
2159 26655 : streamer_write_uhwi (ob, info ? vec_safe_length (info->tree_map) : 0);
2160 23300 : if (info)
2161 25731 : FOR_EACH_VEC_SAFE_ELT (info->tree_map, i, map)
2162 : {
2163 5818 : streamer_write_uhwi (ob, map->parm_num);
2164 5818 : gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
2165 5818 : stream_write_tree (ob, map->new_tree, true);
2166 : }
2167 :
2168 23300 : if (lto_symtab_encoder_in_partition_p (encoder, node))
2169 : {
2170 : for (e = node->callees; e; e = e->next_callee)
2171 : output_edge_opt_summary (ob, e);
2172 : for (e = node->indirect_calls; e; e = e->next_callee)
2173 : output_edge_opt_summary (ob, e);
2174 : }
2175 23300 : }
2176 :
2177 : /* Output optimization summaries stored in callgraph.
2178 : At the moment it is the clone info structure. */
2179 :
2180 : static void
2181 8333 : output_cgraph_opt_summary (void)
2182 : {
2183 8333 : int i, n_nodes;
2184 8333 : lto_symtab_encoder_t encoder;
2185 8333 : struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
2186 8333 : unsigned count = 0;
2187 :
2188 8333 : ob->symbol = NULL;
2189 8333 : encoder = ob->decl_state->symtab_node_encoder;
2190 8333 : n_nodes = lto_symtab_encoder_size (encoder);
2191 117384 : for (i = 0; i < n_nodes; i++)
2192 : {
2193 109051 : toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
2194 218102 : cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
2195 83936 : if (cnode && output_cgraph_opt_summary_p (cnode))
2196 23300 : count++;
2197 : }
2198 8333 : streamer_write_uhwi (ob, count);
2199 125717 : for (i = 0; i < n_nodes; i++)
2200 : {
2201 109051 : toplevel_node *node = lto_symtab_encoder_deref (encoder, i);
2202 218102 : cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
2203 83936 : if (cnode && output_cgraph_opt_summary_p (cnode))
2204 : {
2205 23300 : streamer_write_uhwi (ob, i);
2206 23300 : output_node_opt_summary (ob, cnode, encoder);
2207 : }
2208 : }
2209 8333 : produce_asm (ob);
2210 8333 : destroy_output_block (ob);
2211 8333 : }
2212 :
2213 : /* Input optimisation summary of EDGE. */
2214 :
2215 : static void
2216 0 : input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
2217 : class lto_input_block *ib_main ATTRIBUTE_UNUSED)
2218 : {
2219 0 : }
2220 :
2221 : /* Input optimisation summary of NODE. */
2222 :
2223 : static void
2224 23300 : input_node_opt_summary (struct cgraph_node *node,
2225 : class lto_input_block *ib_main,
2226 : class data_in *data_in)
2227 : {
2228 23300 : int i;
2229 23300 : int count;
2230 23300 : struct cgraph_edge *e;
2231 :
2232 : /* TODO: Should this code be moved to ipa-param-manipulation? */
2233 23300 : struct bitpack_d bp;
2234 23300 : bp = streamer_read_bitpack (ib_main);
2235 23300 : bool have_adjustments = bp_unpack_value (&bp, 1);
2236 23300 : clone_info *info = clone_info::get_create (node);
2237 :
2238 23300 : if (have_adjustments)
2239 : {
2240 19718 : count = streamer_read_uhwi (ib_main);
2241 19718 : vec<ipa_adjusted_param, va_gc> *new_params = NULL;
2242 57321 : for (i = 0; i < count; i++)
2243 : {
2244 37603 : ipa_adjusted_param adj;
2245 37603 : memset (&adj, 0, sizeof (adj));
2246 37603 : bp = streamer_read_bitpack (ib_main);
2247 37603 : adj.base_index = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
2248 37603 : adj.prev_clone_index
2249 37603 : = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
2250 37603 : adj.op = (enum ipa_parm_op) bp_unpack_value (&bp, 2);
2251 37603 : adj.param_prefix_index = bp_unpack_value (&bp, 2);
2252 37603 : adj.prev_clone_adjustment = bp_unpack_value (&bp, 1);
2253 37603 : adj.reverse = bp_unpack_value (&bp, 1);
2254 37603 : adj.user_flag = bp_unpack_value (&bp, 1);
2255 37603 : if (adj.op == IPA_PARAM_OP_SPLIT
2256 37603 : || adj.op == IPA_PARAM_OP_NEW)
2257 : {
2258 667 : adj.type = stream_read_tree (ib_main, data_in);
2259 667 : if (adj.op == IPA_PARAM_OP_SPLIT)
2260 : {
2261 667 : adj.alias_ptr_type = stream_read_tree (ib_main, data_in);
2262 667 : adj.unit_offset = streamer_read_uhwi (ib_main);
2263 : }
2264 : }
2265 37603 : vec_safe_push (new_params, adj);
2266 : }
2267 19718 : int always_copy_start = streamer_read_hwi (ib_main);
2268 19718 : bp = streamer_read_bitpack (ib_main);
2269 19718 : bool skip_return = bp_unpack_value (&bp, 1);
2270 19718 : info->param_adjustments
2271 19718 : = (new (ggc_alloc <ipa_param_adjustments> ())
2272 19718 : ipa_param_adjustments (new_params, always_copy_start, skip_return));
2273 : }
2274 :
2275 23300 : count = streamer_read_uhwi (ib_main);
2276 29118 : for (i = 0; i < count; i++)
2277 : {
2278 5818 : struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
2279 :
2280 5818 : vec_safe_push (info->tree_map, map);
2281 5818 : map->parm_num = streamer_read_uhwi (ib_main);
2282 5818 : map->new_tree = stream_read_tree (ib_main, data_in);
2283 : }
2284 23300 : for (e = node->callees; e; e = e->next_callee)
2285 : input_edge_opt_summary (e, ib_main);
2286 23300 : for (e = node->indirect_calls; e; e = e->next_callee)
2287 : input_edge_opt_summary (e, ib_main);
2288 23300 : }
2289 :
2290 : /* Read section in file FILE_DATA of length LEN with data DATA. */
2291 :
2292 : static void
2293 8333 : input_cgraph_opt_section (struct lto_file_decl_data *file_data,
2294 : const char *data, size_t len,
2295 : vec<symtab_node *> nodes)
2296 : {
2297 8333 : const struct lto_function_header *header =
2298 : (const struct lto_function_header *) data;
2299 8333 : const int cfg_offset = sizeof (struct lto_function_header);
2300 8333 : const int main_offset = cfg_offset + header->cfg_size;
2301 8333 : const int string_offset = main_offset + header->main_size;
2302 8333 : class data_in *data_in;
2303 8333 : unsigned int i;
2304 8333 : unsigned int count;
2305 :
2306 8333 : lto_input_block ib_main ((const char *) data + main_offset,
2307 8333 : header->main_size, file_data);
2308 :
2309 8333 : data_in =
2310 16666 : lto_data_in_create (file_data, (const char *) data + string_offset,
2311 8333 : header->string_size, vNULL);
2312 8333 : count = streamer_read_uhwi (&ib_main);
2313 :
2314 31633 : for (i = 0; i < count; i++)
2315 : {
2316 23300 : int ref = streamer_read_uhwi (&ib_main);
2317 46600 : input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
2318 : &ib_main, data_in);
2319 : }
2320 8333 : lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
2321 : len);
2322 8333 : lto_data_in_delete (data_in);
2323 8333 : }
2324 :
2325 : /* Input optimization summary of cgraph. */
2326 :
2327 : static void
2328 8333 : input_cgraph_opt_summary (vec<symtab_node *> nodes)
2329 : {
2330 8333 : struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2331 8333 : struct lto_file_decl_data *file_data;
2332 8333 : unsigned int j = 0;
2333 :
2334 24999 : while ((file_data = file_data_vec[j++]))
2335 : {
2336 8333 : size_t len;
2337 8333 : const char *data
2338 8333 : = lto_get_summary_section_data (file_data, LTO_section_cgraph_opt_sum,
2339 : &len);
2340 8333 : if (data)
2341 8333 : input_cgraph_opt_section (file_data, data, len, nodes);
2342 : }
2343 8333 : }
|