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