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