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