]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/lto-cgraph.c
Don't mark IFUNC resolver as only called directly
[thirdparty/gcc.git] / gcc / lto-cgraph.c
CommitLineData
7bfefa9d 1/* Write and read the cgraph to the memory mapped representation of a
2 .o file.
3
8e8f6434 4 Copyright (C) 2009-2018 Free Software Foundation, Inc.
7bfefa9d 5 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
6
7This file is part of GCC.
8
9GCC is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 3, or (at your option) any later
12version.
13
14GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17for more details.
18
19You should have received a copy of the GNU General Public License
20along 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"
9ef16211 26#include "backend.h"
7c29e30e 27#include "rtl.h"
7bfefa9d 28#include "tree.h"
9ef16211 29#include "gimple.h"
7c29e30e 30#include "predict.h"
7c29e30e 31#include "stringpool.h"
7c29e30e 32#include "tree-streamer.h"
33#include "cgraph.h"
b9e2d290 34#include "tree-pass.h"
e3ba12e8 35#include "profile.h"
3ea50c01 36#include "context.h"
37#include "pass_manager.h"
b855a50e 38#include "ipa-utils.h"
4954efd4 39#include "omp-offload.h"
9664a778 40#include "ipa-chkp.h"
30a86690 41#include "stringpool.h"
42#include "attribs.h"
7bfefa9d 43
3e17769e 44/* True when asm nodes has been output. */
45bool asm_nodes_output = false;
46
eab36a5a 47static void output_cgraph_opt_summary (void);
452659af 48static void input_cgraph_opt_summary (vec<symtab_node *> nodes);
1bf41320 49
7857a7b7 50/* Number of LDPR values known to GCC. */
da722561 51#define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
a238367f 52
f1007c72 53/* All node orders are ofsetted by ORDER_BASE. */
54static int order_base;
55
b7e3aeb1 56/* Cgraph streaming is organized as set of record whose type
57 is indicated by a tag. */
70225339 58enum LTO_symtab_tags
b7e3aeb1 59{
60 /* Must leave 0 for the stopper. */
61
62 /* Cgraph node without body available. */
70225339 63 LTO_symtab_unavail_node = 1,
b7e3aeb1 64 /* Cgraph node with function body. */
70225339 65 LTO_symtab_analyzed_node,
b7e3aeb1 66 /* Cgraph edges. */
70225339 67 LTO_symtab_edge,
68 LTO_symtab_indirect_edge,
69 LTO_symtab_variable,
70 LTO_symtab_last_tag
b7e3aeb1 71};
72
b8925abd 73/* Create a new symtab encoder.
74 if FOR_INPUT, the encoder allocate only datastructures needed
75 to read the symtab. */
7bfefa9d 76
70225339 77lto_symtab_encoder_t
b8925abd 78lto_symtab_encoder_new (bool for_input)
7bfefa9d 79{
70225339 80 lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
b8925abd 81
82 if (!for_input)
06ecf488 83 encoder->map = new hash_map<symtab_node *, size_t>;
f1f41a6c 84 encoder->nodes.create (0);
7bfefa9d 85 return encoder;
86}
87
88
89/* Delete ENCODER and its components. */
90
91void
70225339 92lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
7bfefa9d 93{
f1f41a6c 94 encoder->nodes.release ();
b8925abd 95 if (encoder->map)
06ecf488 96 delete encoder->map;
7bfefa9d 97 free (encoder);
98}
99
100
70225339 101/* Return the existing reference number of NODE in the symtab encoder in
7bfefa9d 102 output block OB. Assign a new reference if this is the first time
103 NODE is encoded. */
104
105int
70225339 106lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
452659af 107 symtab_node *node)
7bfefa9d 108{
109 int ref;
48e1416a 110
b8925abd 111 if (!encoder->map)
112 {
113 lto_encoder_entry entry = {node, false, false, false};
114
f1f41a6c 115 ref = encoder->nodes.length ();
116 encoder->nodes.safe_push (entry);
b8925abd 117 return ref;
118 }
119
06ecf488 120 size_t *slot = encoder->map->get (node);
5cf7e051 121 if (!slot || !*slot)
7bfefa9d 122 {
5cf7e051 123 lto_encoder_entry entry = {node, false, false, false};
f1f41a6c 124 ref = encoder->nodes.length ();
5cf7e051 125 if (!slot)
06ecf488 126 encoder->map->put (node, ref + 1);
f1f41a6c 127 encoder->nodes.safe_push (entry);
7bfefa9d 128 }
129 else
06ecf488 130 ref = *slot - 1;
7bfefa9d 131
132 return ref;
133}
134
5cf7e051 135/* Remove NODE from encoder. */
7bfefa9d 136
5cf7e051 137bool
138lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
452659af 139 symtab_node *node)
7bfefa9d 140{
5cf7e051 141 int index;
142 lto_encoder_entry last_node;
143
06ecf488 144 size_t *slot = encoder->map->get (node);
5cf7e051 145 if (slot == NULL || !*slot)
146 return false;
147
06ecf488 148 index = *slot - 1;
f1f41a6c 149 gcc_checking_assert (encoder->nodes[index].node == node);
5cf7e051 150
151 /* Remove from vector. We do this by swapping node with the last element
152 of the vector. */
f1f41a6c 153 last_node = encoder->nodes.pop ();
5cf7e051 154 if (last_node.node != node)
155 {
06ecf488 156 gcc_assert (encoder->map->put (last_node.node, index + 1));
5cf7e051 157
158 /* Move the last element to the original spot of NODE. */
f1f41a6c 159 encoder->nodes[index] = last_node;
5cf7e051 160 }
161
162 /* Remove element from hash table. */
06ecf488 163 encoder->map->remove (node);
5cf7e051 164 return true;
7bfefa9d 165}
166
167
1cd6246c 168/* Return TRUE if we should encode the body of NODE (if any). */
7bfefa9d 169
02b2818c 170bool
70225339 171lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
02b2818c 172 struct cgraph_node *node)
173{
02774f2d 174 int index = lto_symtab_encoder_lookup (encoder, node);
f1f41a6c 175 return encoder->nodes[index].body;
02b2818c 176}
177
1cd6246c 178/* Specify that we encode the body of NODE in this partition. */
02b2818c 179
180static void
70225339 181lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder,
02b2818c 182 struct cgraph_node *node)
7bfefa9d 183{
02774f2d 184 int index = lto_symtab_encoder_encode (encoder, node);
185 gcc_checking_assert (encoder->nodes[index].node == node);
f1f41a6c 186 encoder->nodes[index].body = true;
7bfefa9d 187}
188
a238367f 189/* Return TRUE if we should encode initializer of NODE (if any). */
190
191bool
70225339 192lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
098f44bc 193 varpool_node *node)
a238367f 194{
02774f2d 195 int index = lto_symtab_encoder_lookup (encoder, node);
5cf7e051 196 if (index == LCC_NOT_FOUND)
197 return false;
f1f41a6c 198 return encoder->nodes[index].initializer;
a238367f 199}
200
1cd6246c 201/* Specify that we should encode initializer of NODE (if any). */
a238367f 202
203static void
70225339 204lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
098f44bc 205 varpool_node *node)
a238367f 206{
02774f2d 207 int index = lto_symtab_encoder_lookup (encoder, node);
f1f41a6c 208 encoder->nodes[index].initializer = true;
a238367f 209}
7bfefa9d 210
1cd6246c 211/* Return TRUE if NODE is in this partition. */
eab36a5a 212
213bool
214lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
452659af 215 symtab_node *node)
eab36a5a 216{
02774f2d 217 int index = lto_symtab_encoder_lookup (encoder, node);
5cf7e051 218 if (index == LCC_NOT_FOUND)
219 return false;
f1f41a6c 220 return encoder->nodes[index].in_partition;
eab36a5a 221}
222
1cd6246c 223/* Specify that NODE is in this partition. */
eab36a5a 224
225void
226lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
452659af 227 symtab_node *node)
eab36a5a 228{
02774f2d 229 int index = lto_symtab_encoder_encode (encoder, node);
f1f41a6c 230 encoder->nodes[index].in_partition = true;
eab36a5a 231}
232
7bfefa9d 233/* Output the cgraph EDGE to OB using ENCODER. */
234
235static void
236lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
70225339 237 lto_symtab_encoder_t encoder)
7bfefa9d 238{
239 unsigned int uid;
240 intptr_t ref;
30baba90 241 struct bitpack_d bp;
7bfefa9d 242
799c8711 243 if (edge->indirect_unknown_callee)
70225339 244 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
245 LTO_symtab_indirect_edge);
799c8711 246 else
70225339 247 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
248 LTO_symtab_edge);
7bfefa9d 249
02774f2d 250 ref = lto_symtab_encoder_lookup (encoder, edge->caller);
48e1416a 251 gcc_assert (ref != LCC_NOT_FOUND);
7f385784 252 streamer_write_hwi_stream (ob->main_stream, ref);
7bfefa9d 253
799c8711 254 if (!edge->indirect_unknown_callee)
255 {
02774f2d 256 ref = lto_symtab_encoder_lookup (encoder, edge->callee);
799c8711 257 gcc_assert (ref != LCC_NOT_FOUND);
7f385784 258 streamer_write_hwi_stream (ob->main_stream, ref);
799c8711 259 }
7bfefa9d 260
db9cef39 261 edge->count.stream_out (ob->main_stream);
7bfefa9d 262
30baba90 263 bp = bitpack_create (ob->main_stream);
6a353dda 264 uid = (!gimple_has_body_p (edge->caller->decl) || edge->caller->thunk.thunk_p
4d044066 265 ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt) + 1);
b3e7c666 266 bp_pack_enum (&bp, cgraph_inline_failed_t,
7857a7b7 267 CIF_N_REASONS, edge->inline_failed);
268 bp_pack_var_len_unsigned (&bp, uid);
30baba90 269 bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
4d044066 270 bp_pack_value (&bp, edge->speculative, 1);
30baba90 271 bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
0754a747 272 gcc_assert (!edge->call_stmt_cannot_inline_p
273 || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
30baba90 274 bp_pack_value (&bp, edge->can_throw_external, 1);
007a6c27 275 bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
f8b7e3ec 276 if (edge->indirect_unknown_callee)
277 {
278 int flags = edge->indirect_info->ecf_flags;
30baba90 279 bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
280 bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
281 bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
282 bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
283 bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
284 bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
f8b7e3ec 285 /* Flags that should not appear on indirect calls. */
286 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
287 | ECF_MAY_BE_ALLOCA
288 | ECF_SIBCALL
c470c5a9 289 | ECF_LEAF
f8b7e3ec 290 | ECF_NOVOPS)));
291 }
7f385784 292 streamer_write_bitpack (&bp);
6a261305 293 if (edge->indirect_unknown_callee)
294 {
295 streamer_write_hwi_stream (ob->main_stream,
296 edge->indirect_info->common_target_id);
297 if (edge->indirect_info->common_target_id)
298 streamer_write_hwi_stream
299 (ob->main_stream, edge->indirect_info->common_target_probability);
300 }
7bfefa9d 301}
302
51ce5652 303/* Return if NODE contain references from other partitions. */
d97be713 304
8d810329 305bool
51ce5652 306referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
8d810329 307{
308 int i;
51ce5652 309 struct ipa_ref *ref = NULL;
310
311 for (i = 0; node->iterate_referring (i, ref); i++)
8d810329 312 {
b0c5e347 313 /* Ignore references from non-offloadable nodes while streaming NODE into
314 offload LTO section. */
315 if (!ref->referring->need_lto_streaming)
316 continue;
317
02774f2d 318 if (ref->referring->in_other_partition
eab36a5a 319 || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
320 return true;
8d810329 321 }
322 return false;
323}
324
08843223 325/* Return true when node is reachable from other partition. */
326
25429dc2 327bool
eab36a5a 328reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
08843223 329{
330 struct cgraph_edge *e;
02774f2d 331 if (!node->definition)
08843223 332 return false;
333 if (node->global.inlined_to)
334 return false;
335 for (e = node->callers; e; e = e->next_caller)
b0c5e347 336 {
337 /* Ignore references from non-offloadable nodes while streaming NODE into
338 offload LTO section. */
339 if (!e->caller->need_lto_streaming)
340 continue;
341
342 if (e->caller->in_other_partition
343 || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
344 return true;
345 }
08843223 346 return false;
347}
7bfefa9d 348
51ce5652 349/* Return if NODE contain references from other partitions. */
d97be713 350
351bool
51ce5652 352referenced_from_this_partition_p (symtab_node *node,
eab36a5a 353 lto_symtab_encoder_t encoder)
d97be713 354{
355 int i;
51ce5652 356 struct ipa_ref *ref = NULL;
357
358 for (i = 0; node->iterate_referring (i, ref); i++)
eab36a5a 359 if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
360 return true;
d97be713 361 return false;
362}
363
364/* Return true when node is reachable from other partition. */
365
366bool
eab36a5a 367reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
d97be713 368{
369 struct cgraph_edge *e;
d97be713 370 for (e = node->callers; e; e = e->next_caller)
02774f2d 371 if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
d97be713 372 return true;
373 return false;
374}
375
7bfefa9d 376/* Output the cgraph NODE to OB. ENCODER is used to find the
377 reference number of NODE->inlined_to. SET is the set of nodes we
378 are writing to the current file. If NODE is not in SET, then NODE
379 is a boundary of a cgraph_node_set and we pretend NODE just has a
380 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
381 that have had their callgraph node written so far. This is used to
382 determine if NODE is a clone of a previously written node. */
383
384static void
385lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
eab36a5a 386 lto_symtab_encoder_t encoder)
7bfefa9d 387{
388 unsigned int tag;
30baba90 389 struct bitpack_d bp;
02b2818c 390 bool boundary_p;
7bfefa9d 391 intptr_t ref;
08843223 392 bool in_other_partition = false;
eaad46f2 393 struct cgraph_node *clone_of, *ultimate_clone_of;
b23e5d49 394 ipa_opt_pass_d *pass;
b9e2d290 395 int i;
8c016392 396 const char *comdat;
71e19e54 397 const char *section;
8c016392 398 tree group;
7bfefa9d 399
02774f2d 400 boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
7bfefa9d 401
6a353dda 402 if (node->analyzed && (!boundary_p || node->alias
403 || (node->thunk.thunk_p && !node->global.inlined_to)))
70225339 404 tag = LTO_symtab_analyzed_node;
b7e3aeb1 405 else
70225339 406 tag = LTO_symtab_unavail_node;
7bfefa9d 407
70225339 408 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
7f385784 409 tag);
02774f2d 410 streamer_write_hwi_stream (ob->main_stream, node->order);
7bfefa9d 411
7bfefa9d 412 /* In WPA mode, we only output part of the call-graph. Also, we
413 fake cgraph node attributes. There are two cases that we care.
414
415 Boundary nodes: There are nodes that are not part of SET but are
416 called from within SET. We artificially make them look like
48e1416a 417 externally visible nodes with no function body.
7bfefa9d 418
419 Cherry-picked nodes: These are nodes we pulled from other
420 translation units into SET during IPA-inlining. We make them as
421 local static nodes to prevent clashes with other local statics. */
94107507 422 if (boundary_p && node->analyzed
415d1b9a 423 && node->get_partitioning_class () == SYMBOL_PARTITION)
7bfefa9d 424 {
08843223 425 /* Inline clones can not be part of boundary.
426 gcc_assert (!node->global.inlined_to);
427
428 FIXME: At the moment they can be, when partition contains an inline
429 clone that is clone of inline clone from outside partition. We can
430 reshape the clone tree and make other tree to be the root, but it
431 needs a bit extra work and will be promplty done by cgraph_remove_node
432 after reading back. */
433 in_other_partition = 1;
7bfefa9d 434 }
7bfefa9d 435
02b2818c 436 clone_of = node->clone_of;
437 while (clone_of
02774f2d 438 && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
02b2818c 439 if (clone_of->prev_sibling_clone)
440 clone_of = clone_of->prev_sibling_clone;
441 else
442 clone_of = clone_of->clone_of;
083e227a 443
eaad46f2 444 /* See if body of the master function is output. If not, we are seeing only
445 an declaration and we do not need to pass down clone tree. */
446 ultimate_clone_of = clone_of;
447 while (ultimate_clone_of && ultimate_clone_of->clone_of)
448 ultimate_clone_of = ultimate_clone_of->clone_of;
449
450 if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
451 clone_of = NULL;
452
453 if (tag == LTO_symtab_analyzed_node)
083e227a 454 gcc_assert (clone_of || !node->clone_of);
02b2818c 455 if (!clone_of)
7f385784 456 streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
02b2818c 457 else
7f385784 458 streamer_write_hwi_stream (ob->main_stream, ref);
7bfefa9d 459
7bfefa9d 460
02774f2d 461 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
db9cef39 462 node->count.stream_out (ob->main_stream);
7f385784 463 streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
7bfefa9d 464
b9e2d290 465 streamer_write_hwi_stream (ob->main_stream,
f1f41a6c 466 node->ipa_transforms_to_apply.length ());
467 FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
bcfddb5b 468 streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
b9e2d290 469
70225339 470 if (tag == LTO_symtab_analyzed_node)
7bfefa9d 471 {
b7e3aeb1 472 if (node->global.inlined_to)
473 {
02774f2d 474 ref = lto_symtab_encoder_lookup (encoder, node->global.inlined_to);
b7e3aeb1 475 gcc_assert (ref != LCC_NOT_FOUND);
476 }
477 else
478 ref = LCC_NOT_FOUND;
7bfefa9d 479
7f385784 480 streamer_write_hwi_stream (ob->main_stream, ref);
7bfefa9d 481 }
7bfefa9d 482
8c016392 483 group = node->get_comdat_group ();
484 if (group)
485 comdat = IDENTIFIER_POINTER (group);
486 else
487 comdat = "";
a797f9ee 488 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
71e19e54 489
8c016392 490 if (group)
61c2c7b1 491 {
e0dec29d 492 if (node->same_comdat_group)
8c016392 493 {
e0dec29d 494 ref = LCC_NOT_FOUND;
495 for (struct symtab_node *n = node->same_comdat_group;
496 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
497 ref = lto_symtab_encoder_lookup (encoder, n);
8c016392 498 }
499 else
500 ref = LCC_NOT_FOUND;
501 streamer_write_hwi_stream (ob->main_stream, ref);
61c2c7b1 502 }
61c2c7b1 503
e4c07a06 504 section = node->get_section ();
505 if (!section)
71e19e54 506 section = "";
71e19e54 507
38fe12e3 508 streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
509
30baba90 510 bp = bitpack_create (ob->main_stream);
511 bp_pack_value (&bp, node->local.local, 1);
02774f2d 512 bp_pack_value (&bp, node->externally_visible, 1);
6b722052 513 bp_pack_value (&bp, node->no_reorder, 1);
02774f2d 514 bp_pack_value (&bp, node->definition, 1);
c8d92fc1 515 bp_pack_value (&bp, node->local.versionable, 1);
3c97c75d 516 bp_pack_value (&bp, node->local.can_change_signature, 1);
30baba90 517 bp_pack_value (&bp, node->local.redefined_extern_inline, 1);
02774f2d 518 bp_pack_value (&bp, node->force_output, 1);
519 bp_pack_value (&bp, node->forced_by_abi, 1);
520 bp_pack_value (&bp, node->unique_name, 1);
dda4feee 521 bp_pack_value (&bp, node->body_removed, 1);
e4c07a06 522 bp_pack_value (&bp, node->implicit_section, 1);
02774f2d 523 bp_pack_value (&bp, node->address_taken, 1);
70225339 524 bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
415d1b9a 525 && node->get_partitioning_class () == SYMBOL_PARTITION
eab36a5a 526 && (reachable_from_other_partition_p (node, encoder)
51ce5652 527 || referenced_from_other_partition_p (node, encoder)), 1);
30baba90 528 bp_pack_value (&bp, node->lowered, 1);
529 bp_pack_value (&bp, in_other_partition, 1);
c5e076fc 530 bp_pack_value (&bp, node->alias, 1);
e0dec29d 531 bp_pack_value (&bp, node->transparent_alias, 1);
02774f2d 532 bp_pack_value (&bp, node->weakref, 1);
30baba90 533 bp_pack_value (&bp, node->frequency, 2);
0f9fb931 534 bp_pack_value (&bp, node->only_called_at_startup, 1);
535 bp_pack_value (&bp, node->only_called_at_exit, 1);
ea0e88d1 536 bp_pack_value (&bp, node->tm_clone, 1);
468088ac 537 bp_pack_value (&bp, node->calls_comdat_local, 1);
52200d03 538 bp_pack_value (&bp, node->icf_merged, 1);
04c849b3 539 bp_pack_value (&bp, node->nonfreeing_fn, 1);
c5e076fc 540 bp_pack_value (&bp, node->thunk.thunk_p, 1);
66460ec1 541 bp_pack_value (&bp, node->parallelized_function, 1);
7857a7b7 542 bp_pack_enum (&bp, ld_plugin_symbol_resolution,
02774f2d 543 LDPR_NUM_KNOWN, node->resolution);
058a1b7a 544 bp_pack_value (&bp, node->instrumentation_clone, 1);
71e37927 545 bp_pack_value (&bp, node->split_part, 1);
7f385784 546 streamer_write_bitpack (&bp);
a797f9ee 547 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
30baba90 548
c5e076fc 549 if (node->thunk.thunk_p)
91bf9d9a 550 {
7f385784 551 streamer_write_uhwi_stream
91bf9d9a 552 (ob->main_stream,
553 1 + (node->thunk.this_adjusting != 0) * 2
058a1b7a 554 + (node->thunk.virtual_offset_p != 0) * 4
555 + (node->thunk.add_pointer_bounds_args != 0) * 8);
7f385784 556 streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset);
557 streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value);
91bf9d9a 558 }
6a261305 559 streamer_write_hwi_stream (ob->main_stream, node->profile_id);
9db80d42 560 if (DECL_STATIC_CONSTRUCTOR (node->decl))
68ce6e1a 561 streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
9db80d42 562 if (DECL_STATIC_DESTRUCTOR (node->decl))
68ce6e1a 563 streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
058a1b7a 564
565 if (node->instrumentation_clone)
566 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->orig_decl);
7bfefa9d 567}
568
0cddb138 569/* Output the varpool NODE to OB.
570 If NODE is not in SET, then NODE is a boundary. */
571
572static void
098f44bc 573lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
eab36a5a 574 lto_symtab_encoder_t encoder)
0cddb138 575{
02774f2d 576 bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
ddd4cdce 577 bool encode_initializer_p
578 = (node->definition
579 && lto_symtab_encoder_encode_initializer_p (encoder, node));
30baba90 580 struct bitpack_d bp;
933b10c6 581 int ref;
8c016392 582 const char *comdat;
71e19e54 583 const char *section;
8c016392 584 tree group;
0cddb138 585
ddd4cdce 586 gcc_assert (!encode_initializer_p || node->definition);
587 gcc_assert (boundary_p || encode_initializer_p);
588
70225339 589 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
590 LTO_symtab_variable);
02774f2d 591 streamer_write_hwi_stream (ob->main_stream, node->order);
592 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl);
30baba90 593 bp = bitpack_create (ob->main_stream);
02774f2d 594 bp_pack_value (&bp, node->externally_visible, 1);
6b722052 595 bp_pack_value (&bp, node->no_reorder, 1);
02774f2d 596 bp_pack_value (&bp, node->force_output, 1);
597 bp_pack_value (&bp, node->forced_by_abi, 1);
598 bp_pack_value (&bp, node->unique_name, 1);
ddd4cdce 599 bp_pack_value (&bp,
600 node->body_removed
601 || (!encode_initializer_p && !node->alias && node->definition),
602 1);
e4c07a06 603 bp_pack_value (&bp, node->implicit_section, 1);
703ad42c 604 bp_pack_value (&bp, node->writeonly, 1);
ddd4cdce 605 bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias),
606 1);
c5e076fc 607 bp_pack_value (&bp, node->alias, 1);
e0dec29d 608 bp_pack_value (&bp, node->transparent_alias, 1);
02774f2d 609 bp_pack_value (&bp, node->weakref, 1);
e0dec29d 610 bp_pack_value (&bp, node->analyzed && (!boundary_p || node->alias), 1);
02774f2d 611 gcc_assert (node->definition || !node->analyzed);
da67d826 612 /* Constant pool initializers can be de-unified into individual ltrans units.
613 FIXME: Alternatively at -Os we may want to avoid generating for them the local
614 labels and share them across LTRANS partitions. */
415d1b9a 615 if (node->get_partitioning_class () != SYMBOL_PARTITION)
da67d826 616 {
30baba90 617 bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */
618 bp_pack_value (&bp, 0, 1); /* in_other_partition. */
da67d826 619 }
620 else
621 {
02774f2d 622 bp_pack_value (&bp, node->definition
51ce5652 623 && referenced_from_other_partition_p (node, encoder), 1);
02774f2d 624 bp_pack_value (&bp, node->analyzed
625 && boundary_p && !DECL_EXTERNAL (node->decl), 1);
aa419a52 626 /* in_other_partition. */
da67d826 627 }
5e68df57 628 bp_pack_value (&bp, node->tls_model, 3);
3f1f2be0 629 bp_pack_value (&bp, node->used_by_single_function, 1);
945b86eb 630 bp_pack_value (&bp, node->dynamically_initialized, 1);
058a1b7a 631 bp_pack_value (&bp, node->need_bounds_init, 1);
7f385784 632 streamer_write_bitpack (&bp);
71e19e54 633
8c016392 634 group = node->get_comdat_group ();
635 if (group)
636 comdat = IDENTIFIER_POINTER (group);
637 else
638 comdat = "";
a797f9ee 639 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
71e19e54 640
8c016392 641 if (group)
933b10c6 642 {
e0dec29d 643 if (node->same_comdat_group)
8c016392 644 {
e0dec29d 645 ref = LCC_NOT_FOUND;
646 for (struct symtab_node *n = node->same_comdat_group;
647 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
648 ref = lto_symtab_encoder_lookup (encoder, n);
8c016392 649 }
650 else
651 ref = LCC_NOT_FOUND;
652 streamer_write_hwi_stream (ob->main_stream, ref);
933b10c6 653 }
71e19e54 654
e4c07a06 655 section = node->get_section ();
656 if (!section)
71e19e54 657 section = "";
a797f9ee 658 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
71e19e54 659
7f385784 660 streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
02774f2d 661 LDPR_NUM_KNOWN, node->resolution);
0cddb138 662}
663
8d810329 664/* Output the varpool NODE to OB.
665 If NODE is not in SET, then NODE is a boundary. */
666
667static void
668lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
70225339 669 lto_symtab_encoder_t encoder)
8d810329 670{
30baba90 671 struct bitpack_d bp;
70225339 672 int nref;
4d044066 673 int uid = ref->lto_stmt_uid;
674 struct cgraph_node *node;
70225339 675
30baba90 676 bp = bitpack_create (ob->main_stream);
058a1b7a 677 bp_pack_value (&bp, ref->use, 3);
4d044066 678 bp_pack_value (&bp, ref->speculative, 1);
7f385784 679 streamer_write_bitpack (&bp);
70225339 680 nref = lto_symtab_encoder_lookup (encoder, ref->referred);
681 gcc_assert (nref != LCC_NOT_FOUND);
682 streamer_write_hwi_stream (ob->main_stream, nref);
4d044066 683
13cbeaac 684 node = dyn_cast <cgraph_node *> (ref->referring);
4d044066 685 if (node)
686 {
687 if (ref->stmt)
688 uid = gimple_uid (ref->stmt) + 1;
689 streamer_write_hwi_stream (ob->main_stream, uid);
690 }
8d810329 691}
692
6c0782b1 693/* Stream out profile_summary to OB. */
694
695static void
696output_profile_summary (struct lto_simple_output_block *ob)
697{
e3ba12e8 698 unsigned h_ix;
699 struct bitpack_d bp;
700
6c0782b1 701 if (profile_info)
702 {
e3ba12e8 703 /* We do not output num and run_max, they are not used by
704 GCC profile feedback and they are difficult to merge from multiple
705 units. */
6c0782b1 706 gcc_assert (profile_info->runs);
7f385784 707 streamer_write_uhwi_stream (ob->main_stream, profile_info->runs);
9e179a64 708 streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_max);
e3ba12e8 709
710 /* sum_all is needed for computing the working set with the
711 histogram. */
9e179a64 712 streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_all);
e3ba12e8 713
714 /* Create and output a bitpack of non-zero histogram entries indices. */
715 bp = bitpack_create (ob->main_stream);
716 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
717 bp_pack_value (&bp, profile_info->histogram[h_ix].num_counters > 0, 1);
718 streamer_write_bitpack (&bp);
719 /* Now stream out only those non-zero entries. */
720 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
721 {
722 if (!profile_info->histogram[h_ix].num_counters)
723 continue;
9e179a64 724 streamer_write_gcov_count_stream (ob->main_stream,
e3ba12e8 725 profile_info->histogram[h_ix].num_counters);
9e179a64 726 streamer_write_gcov_count_stream (ob->main_stream,
e3ba12e8 727 profile_info->histogram[h_ix].min_value);
9e179a64 728 streamer_write_gcov_count_stream (ob->main_stream,
e3ba12e8 729 profile_info->histogram[h_ix].cum_value);
9e179a64 730 }
731 /* IPA-profile computes hot bb threshold based on cumulated
732 whole program profile. We need to stream it down to ltrans. */
733 if (flag_wpa)
734 streamer_write_gcov_count_stream (ob->main_stream,
735 get_hot_bb_threshold ());
6c0782b1 736 }
737 else
7f385784 738 streamer_write_uhwi_stream (ob->main_stream, 0);
6c0782b1 739}
740
799c8711 741/* Output all callees or indirect outgoing edges. EDGE must be the first such
742 edge. */
743
744static void
745output_outgoing_cgraph_edges (struct cgraph_edge *edge,
746 struct lto_simple_output_block *ob,
70225339 747 lto_symtab_encoder_t encoder)
799c8711 748{
749 if (!edge)
750 return;
751
752 /* Output edges in backward direction, so the reconstructed callgraph match
753 and it is easy to associate call sites in the IPA pass summaries. */
754 while (edge->next_callee)
755 edge = edge->next_callee;
756 for (; edge; edge = edge->prev_callee)
757 lto_output_edge (ob, edge, encoder);
758}
759
8d810329 760/* Output the part of the cgraph in SET. */
761
762static void
eab36a5a 763output_refs (lto_symtab_encoder_t encoder)
8d810329 764{
8d810329 765 struct lto_simple_output_block *ob;
766 int count;
767 struct ipa_ref *ref;
8d810329 768
769 ob = lto_create_simple_output_block (LTO_section_refs);
770
c5e076fc 771 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
8d810329 772 {
c5e076fc 773 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
774
7f0dce59 775 /* IPA_REF_ALIAS and IPA_REF_CHKP references are always preserved
776 in the boundary. Alias node can't have other references and
777 can be always handled as if it's not in the boundary. */
c5e076fc 778 if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node))
7f0dce59 779 {
780 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
781 /* Output IPA_REF_CHKP reference. */
782 if (cnode
783 && cnode->instrumented_version
784 && !cnode->instrumentation_clone)
785 {
786 for (int i = 0; node->iterate_reference (i, ref); i++)
787 if (ref->use == IPA_REF_CHKP)
788 {
789 if (lto_symtab_encoder_lookup (encoder, ref->referred)
790 != LCC_NOT_FOUND)
791 {
792 int nref = lto_symtab_encoder_lookup (encoder, node);
793 streamer_write_gcov_count_stream (ob->main_stream, 1);
794 streamer_write_uhwi_stream (ob->main_stream, nref);
795 lto_output_ref (ob, ref, encoder);
796 }
797 break;
798 }
799 }
800 continue;
801 }
8d810329 802
51ce5652 803 count = node->ref_list.nreferences ();
8d810329 804 if (count)
805 {
6a1c0403 806 streamer_write_gcov_count_stream (ob->main_stream, count);
7f385784 807 streamer_write_uhwi_stream (ob->main_stream,
eab36a5a 808 lto_symtab_encoder_lookup (encoder, node));
c5e076fc 809 for (int i = 0; node->iterate_reference (i, ref); i++)
70225339 810 lto_output_ref (ob, ref, encoder);
8d810329 811 }
812 }
813
7f385784 814 streamer_write_uhwi_stream (ob->main_stream, 0);
8d810329 815
816 lto_destroy_simple_output_block (ob);
817}
818
724462b0 819/* Add NODE into encoder as well as nodes it is cloned from.
820 Do it in a way so clones appear first. */
821
822static void
823add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
824 bool include_body)
825{
826 if (node->clone_of)
827 add_node_to (encoder, node->clone_of, include_body);
828 else if (include_body)
829 lto_set_symtab_encoder_encode_body (encoder, node);
02774f2d 830 lto_symtab_encoder_encode (encoder, node);
724462b0 831}
832
51ce5652 833/* Add all references in NODE to encoders. */
724462b0 834
835static void
35ee1c66 836create_references (lto_symtab_encoder_t encoder, symtab_node *node)
724462b0 837{
838 int i;
51ce5652 839 struct ipa_ref *ref = NULL;
840 for (i = 0; node->iterate_reference (i, ref); i++)
13cbeaac 841 if (is_a <cgraph_node *> (ref->referred))
51ce5652 842 add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
724462b0 843 else
c9aa6453 844 lto_symtab_encoder_encode (encoder, ref->referred);
724462b0 845}
846
b0c5e347 847/* Select what needs to be streamed out. In regular lto mode stream everything.
848 In offload lto mode stream only nodes marked as offloadable. */
849void
9d65fe51 850select_what_to_stream (void)
b0c5e347 851{
852 struct symtab_node *snode;
853 FOR_EACH_SYMBOL (snode)
9d65fe51 854 snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable;
b0c5e347 855}
856
724462b0 857/* Find all symbols we want to stream into given partition and insert them
858 to encoders.
859
860 The function actually replaces IN_ENCODER by new one. The reason is that
861 streaming code needs clone's origin to be streamed before clone. This
862 means that we need to insert the nodes in specific order. This order is
863 ignored by the partitioning logic earlier. */
864
865lto_symtab_encoder_t
866compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
7bfefa9d 867{
7bfefa9d 868 struct cgraph_edge *edge;
d97be713 869 int i;
70225339 870 lto_symtab_encoder_t encoder;
5cf7e051 871 lto_symtab_encoder_iterator lsei;
431205b7 872 hash_set<void *> reachable_call_targets;
6c0782b1 873
b8925abd 874 encoder = lto_symtab_encoder_new (false);
7bfefa9d 875
5cf7e051 876 /* Go over all entries in the IN_ENCODER and duplicate them to
877 ENCODER. At the same time insert masters of clones so
878 every master appears before clone. */
879 for (lsei = lsei_start_function_in_partition (in_encoder);
880 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
7bfefa9d 881 {
5abc516d 882 struct cgraph_node *node = lsei_cgraph_node (lsei);
b0c5e347 883 if (!node->need_lto_streaming)
884 continue;
02b2818c 885 add_node_to (encoder, node, true);
02774f2d 886 lto_set_symtab_encoder_in_partition (encoder, node);
35ee1c66 887 create_references (encoder, node);
7bfefa9d 888 }
5cf7e051 889 for (lsei = lsei_start_variable_in_partition (in_encoder);
890 !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
a238367f 891 {
098f44bc 892 varpool_node *vnode = lsei_varpool_node (lsei);
48669653 893
b0c5e347 894 if (!vnode->need_lto_streaming)
895 continue;
02774f2d 896 lto_set_symtab_encoder_in_partition (encoder, vnode);
70225339 897 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
35ee1c66 898 create_references (encoder, vnode);
a238367f 899 }
a238367f 900 /* Pickle in also the initializer of all referenced readonly variables
901 to help folding. Constant pool variables are not shared, so we must
902 pickle those too. */
70225339 903 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
a238367f 904 {
452659af 905 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
13cbeaac 906 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
a238367f 907 {
df8d3e89 908 if (!lto_symtab_encoder_encode_initializer_p (encoder,
909 vnode)
a8aa8251 910 && (((vnode->ctor_useable_for_folding_p ()
911 && (!DECL_VIRTUAL_P (vnode->decl)
912 || !flag_wpa
913 || flag_ltrans_devirtualize))
914 || POINTER_BOUNDS_P (vnode->decl))))
70225339 915 {
916 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
35ee1c66 917 create_references (encoder, vnode);
70225339 918 }
70225339 919 }
a238367f 920 }
7bfefa9d 921
922 /* Go over all the nodes again to include callees that are not in
923 SET. */
5cf7e051 924 for (lsei = lsei_start_function_in_partition (encoder);
925 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
7bfefa9d 926 {
5abc516d 927 struct cgraph_node *node = lsei_cgraph_node (lsei);
7bfefa9d 928 for (edge = node->callees; edge; edge = edge->next_callee)
929 {
930 struct cgraph_node *callee = edge->callee;
02774f2d 931 if (!lto_symtab_encoder_in_partition_p (encoder, callee))
7bfefa9d 932 {
933 /* We should have moved all the inlines. */
934 gcc_assert (!callee->global.inlined_to);
02b2818c 935 add_node_to (encoder, callee, false);
7bfefa9d 936 }
937 }
b855a50e 938 /* Add all possible targets for late devirtualization. */
a8aa8251 939 if (flag_ltrans_devirtualize || !flag_wpa)
b855a50e 940 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
941 if (edge->indirect_info->polymorphic)
942 {
943 unsigned int i;
944 void *cache_token;
945 bool final;
946 vec <cgraph_node *>targets
947 = possible_polymorphic_call_targets
948 (edge, &final, &cache_token);
431205b7 949 if (!reachable_call_targets.add (cache_token))
b855a50e 950 {
9af5ce0c 951 for (i = 0; i < targets.length (); i++)
b855a50e 952 {
953 struct cgraph_node *callee = targets[i];
954
955 /* Adding an external declarations into the unit serves
956 no purpose and just increases its boundary. */
02774f2d 957 if (callee->definition
b855a50e 958 && !lto_symtab_encoder_in_partition_p
02774f2d 959 (encoder, callee))
b855a50e 960 {
961 gcc_assert (!callee->global.inlined_to);
962 add_node_to (encoder, callee, false);
963 }
964 }
965 }
966 }
7bfefa9d 967 }
c5e076fc 968 /* Be sure to also insert alias targert and thunk callees. These needs
969 to stay to aid local calling conventions. */
970 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
971 {
972 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
973 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
974
975 if (node->alias && node->analyzed)
976 create_references (encoder, node);
977 if (cnode
99aee6e3 978 && cnode->thunk.thunk_p && !cnode->global.inlined_to)
c5e076fc 979 add_node_to (encoder, cnode->callees->callee, false);
4d2c990f 980 while (node->transparent_alias && node->analyzed)
981 {
982 node = node->get_alias_target ();
983 if (is_a <cgraph_node *> (node))
984 add_node_to (encoder, dyn_cast <cgraph_node *> (node),
985 false);
986 else
987 lto_symtab_encoder_encode (encoder, node);
988 }
c5e076fc 989 }
b855a50e 990 lto_symtab_encoder_delete (in_encoder);
b855a50e 991 return encoder;
d97be713 992}
993
02b699d5 994/* Output the part of the symtab in SET and VSET. */
d97be713 995
996void
eab36a5a 997output_symtab (void)
d97be713 998{
999 struct cgraph_node *node;
1000 struct lto_simple_output_block *ob;
d97be713 1001 int i, n_nodes;
70225339 1002 lto_symtab_encoder_t encoder;
d97be713 1003
1bf41320 1004 if (flag_wpa)
eab36a5a 1005 output_cgraph_opt_summary ();
1bf41320 1006
02b699d5 1007 ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
d97be713 1008
1009 output_profile_summary (ob);
1010
1011 /* An encoder for cgraph nodes should have been created by
1012 ipa_write_summaries_1. */
70225339 1013 gcc_assert (ob->decl_state->symtab_node_encoder);
1014 encoder = ob->decl_state->symtab_node_encoder;
d97be713 1015
08843223 1016 /* Write out the nodes. We must first output a node and then its clones,
1017 otherwise at a time reading back the node there would be nothing to clone
1018 from. */
70225339 1019 n_nodes = lto_symtab_encoder_size (encoder);
7bfefa9d 1020 for (i = 0; i < n_nodes; i++)
1021 {
452659af 1022 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
13cbeaac 1023 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
2dc9831f 1024 lto_output_node (ob, cnode, encoder);
70225339 1025 else
415d1b9a 1026 lto_output_varpool_node (ob, dyn_cast<varpool_node *> (node), encoder);
7bfefa9d 1027 }
1028
7bfefa9d 1029 /* Go over the nodes in SET again to write edges. */
c5e076fc 1030 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
7bfefa9d 1031 {
c5e076fc 1032 node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
1033 if (node
99aee6e3 1034 && ((node->thunk.thunk_p && !node->global.inlined_to)
c5e076fc 1035 || lto_symtab_encoder_in_partition_p (encoder, node)))
1036 {
1037 output_outgoing_cgraph_edges (node->callees, ob, encoder);
1038 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
1039 }
7bfefa9d 1040 }
1041
7f385784 1042 streamer_write_uhwi_stream (ob->main_stream, 0);
7bfefa9d 1043
65d1b157 1044 lto_destroy_simple_output_block (ob);
1045
2b7c48a1 1046 /* Emit toplevel asms.
1047 When doing WPA we must output every asm just once. Since we do not partition asm
1048 nodes at all, output them to first output. This is kind of hack, but should work
1049 well. */
1050 if (!asm_nodes_output)
90f477a9 1051 {
2b7c48a1 1052 asm_nodes_output = true;
65d1b157 1053 lto_output_toplevel_asms ();
90f477a9 1054 }
1055
eab36a5a 1056 output_refs (encoder);
7bfefa9d 1057}
1058
71e19e54 1059/* Return identifier encoded in IB as a plain string. */
8c016392 1060
1061static tree
71e19e54 1062read_identifier (struct lto_input_block *ib)
8c016392 1063{
1064 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
71e19e54 1065 tree id;
1066
1067 if (ib->data[ib->p + len])
1068 lto_section_overrun (ib);
1069 if (!len)
1070 {
1071 ib->p++;
1072 return NULL;
1073 }
1074 id = get_identifier (ib->data + ib->p);
1075 ib->p += len + 1;
1076 return id;
1077}
1078
738a6bda 1079/* Return string encoded in IB, NULL if string is empty. */
71e19e54 1080
738a6bda 1081static const char *
1082read_string (struct lto_input_block *ib)
71e19e54 1083{
1084 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
738a6bda 1085 const char *str;
8c016392 1086
1087 if (ib->data[ib->p + len])
1088 lto_section_overrun (ib);
1089 if (!len)
1090 {
1091 ib->p++;
1092 return NULL;
1093 }
738a6bda 1094 str = ib->data + ib->p;
8c016392 1095 ib->p += len + 1;
738a6bda 1096 return str;
8c016392 1097}
1098
dccabdd1 1099/* Output function/variable tables that will allow libgomp to look up offload
1100 target code.
1101 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1102 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1103 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1104
1105void
1106output_offload_tables (void)
1107{
1108 if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars))
1109 return;
1110
1111 struct lto_simple_output_block *ob
1112 = lto_create_simple_output_block (LTO_section_offload_table);
1113
1114 for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
1115 {
1116 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1117 LTO_symtab_last_tag, LTO_symtab_unavail_node);
1118 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
1119 (*offload_funcs)[i]);
1120 }
1121
1122 for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
1123 {
1124 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1125 LTO_symtab_last_tag, LTO_symtab_variable);
1126 lto_output_var_decl_index (ob->decl_state, ob->main_stream,
1127 (*offload_vars)[i]);
1128 }
1129
1130 streamer_write_uhwi_stream (ob->main_stream, 0);
1131 lto_destroy_simple_output_block (ob);
1132
1133 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1134 streamed to one partition only. That's why we free offload_funcs and
1135 offload_vars after the first call of output_offload_tables. */
1136 if (flag_wpa)
1137 {
1138 vec_free (offload_funcs);
1139 vec_free (offload_vars);
1140 }
1141}
1142
7bfefa9d 1143/* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1144 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1145 NODE or to replace the values in it, for instance because the first
1146 time we saw it, the function body was not available but now it
1147 is. BP is a bitpack with all the bitflags for NODE read from the
1148 stream. */
1149
1150static void
1151input_overwrite_node (struct lto_file_decl_data *file_data,
1152 struct cgraph_node *node,
70225339 1153 enum LTO_symtab_tags tag,
7857a7b7 1154 struct bitpack_d *bp)
7bfefa9d 1155{
02774f2d 1156 node->aux = (void *) tag;
1157 node->lto_file_data = file_data;
7bfefa9d 1158
1159 node->local.local = bp_unpack_value (bp, 1);
02774f2d 1160 node->externally_visible = bp_unpack_value (bp, 1);
6b722052 1161 node->no_reorder = bp_unpack_value (bp, 1);
02774f2d 1162 node->definition = bp_unpack_value (bp, 1);
c8d92fc1 1163 node->local.versionable = bp_unpack_value (bp, 1);
3c97c75d 1164 node->local.can_change_signature = bp_unpack_value (bp, 1);
7bfefa9d 1165 node->local.redefined_extern_inline = bp_unpack_value (bp, 1);
02774f2d 1166 node->force_output = bp_unpack_value (bp, 1);
1167 node->forced_by_abi = bp_unpack_value (bp, 1);
1168 node->unique_name = bp_unpack_value (bp, 1);
dda4feee 1169 node->body_removed = bp_unpack_value (bp, 1);
e4c07a06 1170 node->implicit_section = bp_unpack_value (bp, 1);
02774f2d 1171 node->address_taken = bp_unpack_value (bp, 1);
1172 node->used_from_other_partition = bp_unpack_value (bp, 1);
7bfefa9d 1173 node->lowered = bp_unpack_value (bp, 1);
02774f2d 1174 node->analyzed = tag == LTO_symtab_analyzed_node;
1175 node->in_other_partition = bp_unpack_value (bp, 1);
1176 if (node->in_other_partition
cdc58a66 1177 /* Avoid updating decl when we are seeing just inline clone.
1178 When inlining function that has functions already inlined into it,
1179 we produce clones of inline clones.
1180
1181 WPA partitioning might put each clone into different unit and
1182 we might end up streaming inline clone from other partition
1183 to support clone we are interested in. */
1184 && (!node->clone_of
02774f2d 1185 || node->clone_of->decl != node->decl))
eb0bc81b 1186 {
02774f2d 1187 DECL_EXTERNAL (node->decl) = 1;
1188 TREE_STATIC (node->decl) = 0;
eb0bc81b 1189 }
02774f2d 1190 node->alias = bp_unpack_value (bp, 1);
e0dec29d 1191 node->transparent_alias = bp_unpack_value (bp, 1);
02774f2d 1192 node->weakref = bp_unpack_value (bp, 1);
125b6d78 1193 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
0f9fb931 1194 node->only_called_at_startup = bp_unpack_value (bp, 1);
1195 node->only_called_at_exit = bp_unpack_value (bp, 1);
ea0e88d1 1196 node->tm_clone = bp_unpack_value (bp, 1);
468088ac 1197 node->calls_comdat_local = bp_unpack_value (bp, 1);
52200d03 1198 node->icf_merged = bp_unpack_value (bp, 1);
04c849b3 1199 node->nonfreeing_fn = bp_unpack_value (bp, 1);
91bf9d9a 1200 node->thunk.thunk_p = bp_unpack_value (bp, 1);
66460ec1 1201 node->parallelized_function = bp_unpack_value (bp, 1);
02774f2d 1202 node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
7857a7b7 1203 LDPR_NUM_KNOWN);
058a1b7a 1204 node->instrumentation_clone = bp_unpack_value (bp, 1);
71e37927 1205 node->split_part = bp_unpack_value (bp, 1);
f0d26d57 1206 gcc_assert (flag_ltrans
1207 || (!node->in_other_partition
1208 && !node->used_from_other_partition));
7bfefa9d 1209}
1210
48669653 1211/* Return string alias is alias of. */
1212
1213static tree
1214get_alias_symbol (tree decl)
1215{
1216 tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
48669653 1217 return get_identifier (TREE_STRING_POINTER
1218 (TREE_VALUE (TREE_VALUE (alias))));
1219}
1220
48e1416a 1221/* Read a node from input_block IB. TAG is the node's tag just read.
7bfefa9d 1222 Return the node read or overwriten. */
48e1416a 1223
7bfefa9d 1224static struct cgraph_node *
1225input_node (struct lto_file_decl_data *file_data,
1226 struct lto_input_block *ib,
70225339 1227 enum LTO_symtab_tags tag,
452659af 1228 vec<symtab_node *> nodes)
7bfefa9d 1229{
3ea50c01 1230 gcc::pass_manager *passes = g->get_passes ();
7bfefa9d 1231 tree fn_decl;
1232 struct cgraph_node *node;
30baba90 1233 struct bitpack_d bp;
7bfefa9d 1234 unsigned decl_index;
61c2c7b1 1235 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
02b2818c 1236 int clone_ref;
f1007c72 1237 int order;
b9e2d290 1238 int i, count;
8c016392 1239 tree group;
738a6bda 1240 const char *section;
f1007c72 1241 order = streamer_read_hwi (ib) + order_base;
7f385784 1242 clone_ref = streamer_read_hwi (ib);
7bfefa9d 1243
7f385784 1244 decl_index = streamer_read_uhwi (ib);
7bfefa9d 1245 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1246
02b2818c 1247 if (clone_ref != LCC_NOT_FOUND)
1248 {
415d1b9a 1249 node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
151b9ff5 1250 profile_count::uninitialized (), false,
415d1b9a 1251 vNULL, false, NULL, NULL);
02b2818c 1252 }
7bfefa9d 1253 else
9e9c3e92 1254 {
1255 /* Declaration of functions can be already merged with a declaration
1256 from other input file. We keep cgraph unmerged until after streaming
1257 of ipa passes is done. Alays forcingly create a fresh node. */
35ee1c66 1258 node = symtab->create_empty ();
02774f2d 1259 node->decl = fn_decl;
b859b598 1260 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl)))
1261 node->ifunc_resolver = 1;
415d1b9a 1262 node->register_symbol ();
9e9c3e92 1263 }
7bfefa9d 1264
02774f2d 1265 node->order = order;
35ee1c66 1266 if (order >= symtab->order)
1267 symtab->order = order + 1;
f1007c72 1268
db9cef39 1269 node->count = profile_count::stream_in (ib);
7f385784 1270 node->count_materialization_scale = streamer_read_hwi (ib);
48e1416a 1271
b9e2d290 1272 count = streamer_read_hwi (ib);
1e094109 1273 node->ipa_transforms_to_apply = vNULL;
b9e2d290 1274 for (i = 0; i < count; i++)
1275 {
b23e5d49 1276 opt_pass *pass;
b9e2d290 1277 int pid = streamer_read_hwi (ib);
1278
3ea50c01 1279 gcc_assert (pid < passes->passes_by_id_size);
1280 pass = passes->passes_by_id[pid];
b23e5d49 1281 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
b9e2d290 1282 }
1283
70225339 1284 if (tag == LTO_symtab_analyzed_node)
7f385784 1285 ref = streamer_read_hwi (ib);
7bfefa9d 1286
71e19e54 1287 group = read_identifier (ib);
8c016392 1288 if (group)
1289 ref2 = streamer_read_hwi (ib);
7bfefa9d 1290
1291 /* Make sure that we have not read this node before. Nodes that
1292 have already been read will have their tag stored in the 'aux'
1293 field. Since built-in functions can be referenced in multiple
1294 functions, they are expected to be read more than once. */
02774f2d 1295 if (node->aux && !DECL_BUILT_IN (node->decl))
7bfefa9d 1296 internal_error ("bytecode stream: found multiple instances of cgraph "
15c999e3 1297 "node with uid %d", node->uid);
7bfefa9d 1298
38fe12e3 1299 node->tp_first_run = streamer_read_uhwi (ib);
1300
7f385784 1301 bp = streamer_read_bitpack (ib);
38fe12e3 1302
7857a7b7 1303 input_overwrite_node (file_data, node, tag, &bp);
7bfefa9d 1304
7bfefa9d 1305 /* Store a reference for now, and fix up later to be a pointer. */
415d1b9a 1306 node->global.inlined_to = (cgraph_node *) (intptr_t) ref;
7bfefa9d 1307
8c016392 1308 if (group)
1309 {
1310 node->set_comdat_group (group);
1311 /* Store a reference for now, and fix up later to be a pointer. */
1312 node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
1313 }
1314 else
1315 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
738a6bda 1316 section = read_string (ib);
71e19e54 1317 if (section)
e4c07a06 1318 node->set_section_for_node (section);
61c2c7b1 1319
91bf9d9a 1320 if (node->thunk.thunk_p)
1321 {
7f385784 1322 int type = streamer_read_uhwi (ib);
1323 HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
1324 HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib);
91bf9d9a 1325
91bf9d9a 1326 node->thunk.fixed_offset = fixed_offset;
1327 node->thunk.this_adjusting = (type & 2);
1328 node->thunk.virtual_value = virtual_value;
1329 node->thunk.virtual_offset_p = (type & 4);
058a1b7a 1330 node->thunk.add_pointer_bounds_args = (type & 8);
91bf9d9a 1331 }
02774f2d 1332 if (node->alias && !node->analyzed && node->weakref)
1333 node->alias_target = get_alias_symbol (node->decl);
6a261305 1334 node->profile_id = streamer_read_hwi (ib);
9db80d42 1335 if (DECL_STATIC_CONSTRUCTOR (node->decl))
68ce6e1a 1336 node->set_init_priority (streamer_read_hwi (ib));
9db80d42 1337 if (DECL_STATIC_DESTRUCTOR (node->decl))
68ce6e1a 1338 node->set_fini_priority (streamer_read_hwi (ib));
058a1b7a 1339
1340 if (node->instrumentation_clone)
1341 {
1342 decl_index = streamer_read_uhwi (ib);
1343 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1344 node->orig_decl = fn_decl;
1345 }
1346
7bfefa9d 1347 return node;
1348}
1349
0cddb138 1350/* Read a node from input_block IB. TAG is the node's tag just read.
1351 Return the node read or overwriten. */
1352
098f44bc 1353static varpool_node *
0cddb138 1354input_varpool_node (struct lto_file_decl_data *file_data,
1355 struct lto_input_block *ib)
1356{
1357 int decl_index;
1358 tree var_decl;
098f44bc 1359 varpool_node *node;
30baba90 1360 struct bitpack_d bp;
933b10c6 1361 int ref = LCC_NOT_FOUND;
f1007c72 1362 int order;
8c016392 1363 tree group;
738a6bda 1364 const char *section;
0cddb138 1365
f1007c72 1366 order = streamer_read_hwi (ib) + order_base;
7f385784 1367 decl_index = streamer_read_uhwi (ib);
0cddb138 1368 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
9e9c3e92 1369
1370 /* Declaration of functions can be already merged with a declaration
1371 from other input file. We keep cgraph unmerged until after streaming
1372 of ipa passes is done. Alays forcingly create a fresh node. */
97221fd7 1373 node = varpool_node::create_empty ();
02774f2d 1374 node->decl = var_decl;
415d1b9a 1375 node->register_symbol ();
9e9c3e92 1376
02774f2d 1377 node->order = order;
35ee1c66 1378 if (order >= symtab->order)
1379 symtab->order = order + 1;
02774f2d 1380 node->lto_file_data = file_data;
0cddb138 1381
7f385784 1382 bp = streamer_read_bitpack (ib);
02774f2d 1383 node->externally_visible = bp_unpack_value (&bp, 1);
6b722052 1384 node->no_reorder = bp_unpack_value (&bp, 1);
02774f2d 1385 node->force_output = bp_unpack_value (&bp, 1);
1386 node->forced_by_abi = bp_unpack_value (&bp, 1);
1387 node->unique_name = bp_unpack_value (&bp, 1);
dda4feee 1388 node->body_removed = bp_unpack_value (&bp, 1);
e4c07a06 1389 node->implicit_section = bp_unpack_value (&bp, 1);
703ad42c 1390 node->writeonly = bp_unpack_value (&bp, 1);
02774f2d 1391 node->definition = bp_unpack_value (&bp, 1);
1392 node->alias = bp_unpack_value (&bp, 1);
e0dec29d 1393 node->transparent_alias = bp_unpack_value (&bp, 1);
02774f2d 1394 node->weakref = bp_unpack_value (&bp, 1);
1395 node->analyzed = bp_unpack_value (&bp, 1);
1396 node->used_from_other_partition = bp_unpack_value (&bp, 1);
1397 node->in_other_partition = bp_unpack_value (&bp, 1);
1398 if (node->in_other_partition)
eb0bc81b 1399 {
02774f2d 1400 DECL_EXTERNAL (node->decl) = 1;
1401 TREE_STATIC (node->decl) = 0;
eb0bc81b 1402 }
02774f2d 1403 if (node->alias && !node->analyzed && node->weakref)
1404 node->alias_target = get_alias_symbol (node->decl);
5e68df57 1405 node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
3f1f2be0 1406 node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
945b86eb 1407 node->dynamically_initialized = bp_unpack_value (&bp, 1);
058a1b7a 1408 node->need_bounds_init = bp_unpack_value (&bp, 1);
71e19e54 1409 group = read_identifier (ib);
8c016392 1410 if (group)
1411 {
1412 node->set_comdat_group (group);
1413 ref = streamer_read_hwi (ib);
1414 /* Store a reference for now, and fix up later to be a pointer. */
1415 node->same_comdat_group = (symtab_node *) (intptr_t) ref;
1416 }
1417 else
1418 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
738a6bda 1419 section = read_string (ib);
71e19e54 1420 if (section)
e4c07a06 1421 node->set_section_for_node (section);
02774f2d 1422 node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
7d0d0ce1 1423 LDPR_NUM_KNOWN);
f0d26d57 1424 gcc_assert (flag_ltrans
1425 || (!node->in_other_partition
1426 && !node->used_from_other_partition));
e0eaac80 1427
0cddb138 1428 return node;
1429}
1430
8d810329 1431/* Read a node from input_block IB. TAG is the node's tag just read.
1432 Return the node read or overwriten. */
1433
1434static void
1435input_ref (struct lto_input_block *ib,
452659af 1436 symtab_node *referring_node,
1437 vec<symtab_node *> nodes)
8d810329 1438{
452659af 1439 symtab_node *node = NULL;
30baba90 1440 struct bitpack_d bp;
8d810329 1441 enum ipa_ref_use use;
4d044066 1442 bool speculative;
1443 struct ipa_ref *ref;
8d810329 1444
7f385784 1445 bp = streamer_read_bitpack (ib);
058a1b7a 1446 use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
4d044066 1447 speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
f1f41a6c 1448 node = nodes[streamer_read_hwi (ib)];
35ee1c66 1449 ref = referring_node->create_reference (node, use);
4d044066 1450 ref->speculative = speculative;
13cbeaac 1451 if (is_a <cgraph_node *> (referring_node))
4d044066 1452 ref->lto_stmt_uid = streamer_read_hwi (ib);
8d810329 1453}
7bfefa9d 1454
799c8711 1455/* Read an edge from IB. NODES points to a vector of previously read nodes for
1456 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1457 edge being read is indirect (in the sense that it has
1458 indirect_unknown_callee set). */
7bfefa9d 1459
1460static void
452659af 1461input_edge (struct lto_input_block *ib, vec<symtab_node *> nodes,
799c8711 1462 bool indirect)
7bfefa9d 1463{
1464 struct cgraph_node *caller, *callee;
1465 struct cgraph_edge *edge;
1466 unsigned int stmt_id;
db9cef39 1467 profile_count count;
7bfefa9d 1468 cgraph_inline_failed_t inline_failed;
30baba90 1469 struct bitpack_d bp;
f8b7e3ec 1470 int ecf_flags = 0;
7bfefa9d 1471
415d1b9a 1472 caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
02774f2d 1473 if (caller == NULL || caller->decl == NULL_TREE)
7bfefa9d 1474 internal_error ("bytecode stream: no caller found while reading edge");
1475
799c8711 1476 if (!indirect)
1477 {
415d1b9a 1478 callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
02774f2d 1479 if (callee == NULL || callee->decl == NULL_TREE)
799c8711 1480 internal_error ("bytecode stream: no callee found while reading edge");
1481 }
1482 else
1483 callee = NULL;
7bfefa9d 1484
db9cef39 1485 count = profile_count::stream_in (ib);
7bfefa9d 1486
7f385784 1487 bp = streamer_read_bitpack (ib);
b3e7c666 1488 inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
7857a7b7 1489 stmt_id = bp_unpack_var_len_unsigned (&bp);
7bfefa9d 1490
799c8711 1491 if (indirect)
151b9ff5 1492 edge = caller->create_indirect_edge (NULL, 0, count);
799c8711 1493 else
151b9ff5 1494 edge = caller->create_edge (callee, NULL, count);
799c8711 1495
30baba90 1496 edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
4d044066 1497 edge->speculative = bp_unpack_value (&bp, 1);
7bfefa9d 1498 edge->lto_stmt_uid = stmt_id;
1499 edge->inline_failed = inline_failed;
30baba90 1500 edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1501 edge->can_throw_external = bp_unpack_value (&bp, 1);
007a6c27 1502 edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
f8b7e3ec 1503 if (indirect)
1504 {
30baba90 1505 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1506 ecf_flags |= ECF_CONST;
30baba90 1507 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1508 ecf_flags |= ECF_PURE;
30baba90 1509 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1510 ecf_flags |= ECF_NORETURN;
30baba90 1511 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1512 ecf_flags |= ECF_MALLOC;
30baba90 1513 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1514 ecf_flags |= ECF_NOTHROW;
30baba90 1515 if (bp_unpack_value (&bp, 1))
f8b7e3ec 1516 ecf_flags |= ECF_RETURNS_TWICE;
1517 edge->indirect_info->ecf_flags = ecf_flags;
6a261305 1518 edge->indirect_info->common_target_id = streamer_read_hwi (ib);
1519 if (edge->indirect_info->common_target_id)
1520 edge->indirect_info->common_target_probability = streamer_read_hwi (ib);
f8b7e3ec 1521 }
7bfefa9d 1522}
1523
1524
1525/* Read a cgraph from IB using the info in FILE_DATA. */
1526
452659af 1527static vec<symtab_node *>
7bfefa9d 1528input_cgraph_1 (struct lto_file_decl_data *file_data,
1529 struct lto_input_block *ib)
1530{
70225339 1531 enum LTO_symtab_tags tag;
452659af 1532 vec<symtab_node *> nodes = vNULL;
1533 symtab_node *node;
7bfefa9d 1534 unsigned i;
1535
70225339 1536 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
35ee1c66 1537 order_base = symtab->order;
7bfefa9d 1538 while (tag)
1539 {
70225339 1540 if (tag == LTO_symtab_edge)
799c8711 1541 input_edge (ib, nodes, false);
70225339 1542 else if (tag == LTO_symtab_indirect_edge)
799c8711 1543 input_edge (ib, nodes, true);
70225339 1544 else if (tag == LTO_symtab_variable)
1545 {
02774f2d 1546 node = input_varpool_node (file_data, ib);
f1f41a6c 1547 nodes.safe_push (node);
70225339 1548 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1549 }
48e1416a 1550 else
7bfefa9d 1551 {
02774f2d 1552 node = input_node (file_data, ib, tag, nodes);
1553 if (node == NULL || node->decl == NULL_TREE)
7bfefa9d 1554 internal_error ("bytecode stream: found empty cgraph node");
f1f41a6c 1555 nodes.safe_push (node);
70225339 1556 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
7bfefa9d 1557 }
1558
70225339 1559 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
7bfefa9d 1560 }
1561
f1007c72 1562 lto_input_toplevel_asms (file_data, order_base);
90f477a9 1563
70225339 1564 /* AUX pointers should be all non-zero for function nodes read from the stream. */
382ecba7 1565 if (flag_checking)
1566 {
1567 FOR_EACH_VEC_ELT (nodes, i, node)
1568 gcc_assert (node->aux || !is_a <cgraph_node *> (node));
1569 }
f1f41a6c 1570 FOR_EACH_VEC_ELT (nodes, i, node)
7bfefa9d 1571 {
70225339 1572 int ref;
13cbeaac 1573 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
70225339 1574 {
2dc9831f 1575 ref = (int) (intptr_t) cnode->global.inlined_to;
70225339 1576
1577 /* We share declaration of builtins, so we may read same node twice. */
02774f2d 1578 if (!node->aux)
70225339 1579 continue;
02774f2d 1580 node->aux = NULL;
70225339 1581
1582 /* Fixup inlined_to from reference to pointer. */
1583 if (ref != LCC_NOT_FOUND)
415d1b9a 1584 dyn_cast<cgraph_node *> (node)->global.inlined_to
1585 = dyn_cast<cgraph_node *> (nodes[ref]);
70225339 1586 else
2dc9831f 1587 cnode->global.inlined_to = NULL;
058a1b7a 1588
1589 /* Compute instrumented_version. */
1590 if (cnode->instrumentation_clone)
1591 {
1592 gcc_assert (cnode->orig_decl);
1593
1594 cnode->instrumented_version = cgraph_node::get (cnode->orig_decl);
1595 if (cnode->instrumented_version)
15d46991 1596 {
1597 /* We may have multiple nodes for a single function which
1598 will be merged later. To have a proper merge we need
1599 to keep instrumentation_version reference between nodes
1600 consistent: each instrumented_version reference should
1601 have proper reverse reference. Thus don't break existing
1602 instrumented_version reference if it already exists. */
1603 if (cnode->instrumented_version->instrumented_version)
1604 cnode->instrumented_version = NULL;
1605 else
1606 cnode->instrumented_version->instrumented_version = cnode;
1607 }
058a1b7a 1608
9664a778 1609 /* Restore decl names reference except for wrapper functions. */
1610 if (!chkp_wrap_function (cnode->orig_decl))
1611 {
1612 tree name = DECL_ASSEMBLER_NAME (cnode->decl);
1613 IDENTIFIER_TRANSPARENT_ALIAS (name) = 1;
1614 TREE_CHAIN (name) = DECL_ASSEMBLER_NAME (cnode->orig_decl);
1615 }
058a1b7a 1616 }
70225339 1617 }
61c2c7b1 1618
02774f2d 1619 ref = (int) (intptr_t) node->same_comdat_group;
61c2c7b1 1620
1621 /* Fixup same_comdat_group from reference to pointer. */
1622 if (ref != LCC_NOT_FOUND)
02774f2d 1623 node->same_comdat_group = nodes[ref];
61c2c7b1 1624 else
02774f2d 1625 node->same_comdat_group = NULL;
7bfefa9d 1626 }
f1f41a6c 1627 FOR_EACH_VEC_ELT (nodes, i, node)
13cbeaac 1628 node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
a238367f 1629 return nodes;
7bfefa9d 1630}
1631
8d810329 1632/* Input ipa_refs. */
1633
1634static void
1635input_refs (struct lto_input_block *ib,
452659af 1636 vec<symtab_node *> nodes)
8d810329 1637{
1638 int count;
1639 int idx;
1640 while (true)
1641 {
452659af 1642 symtab_node *node;
7f385784 1643 count = streamer_read_uhwi (ib);
8d810329 1644 if (!count)
1645 break;
7f385784 1646 idx = streamer_read_uhwi (ib);
f1f41a6c 1647 node = nodes[idx];
8d810329 1648 while (count)
1649 {
eab36a5a 1650 input_ref (ib, node, nodes);
8d810329 1651 count--;
1652 }
1653 }
1654}
1655
a238367f 1656
6c0782b1 1657static struct gcov_ctr_summary lto_gcov_summary;
1658
1659/* Input profile_info from IB. */
1660static void
c470c5a9 1661input_profile_summary (struct lto_input_block *ib,
1662 struct lto_file_decl_data *file_data)
6c0782b1 1663{
e3ba12e8 1664 unsigned h_ix;
1665 struct bitpack_d bp;
7f385784 1666 unsigned int runs = streamer_read_uhwi (ib);
6c0782b1 1667 if (runs)
1668 {
c470c5a9 1669 file_data->profile_info.runs = runs;
9e179a64 1670 file_data->profile_info.sum_max = streamer_read_gcov_count (ib);
1671 file_data->profile_info.sum_all = streamer_read_gcov_count (ib);
e3ba12e8 1672
1673 memset (file_data->profile_info.histogram, 0,
1674 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
1675 /* Input the bitpack of non-zero histogram indices. */
1676 bp = streamer_read_bitpack (ib);
1677 /* Read in and unpack the full bitpack, flagging non-zero
1678 histogram entries by setting the num_counters non-zero. */
1679 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1680 {
1681 file_data->profile_info.histogram[h_ix].num_counters
1682 = bp_unpack_value (&bp, 1);
1683 }
1684 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1685 {
1686 if (!file_data->profile_info.histogram[h_ix].num_counters)
1687 continue;
1688
1689 file_data->profile_info.histogram[h_ix].num_counters
9e179a64 1690 = streamer_read_gcov_count (ib);
e3ba12e8 1691 file_data->profile_info.histogram[h_ix].min_value
9e179a64 1692 = streamer_read_gcov_count (ib);
e3ba12e8 1693 file_data->profile_info.histogram[h_ix].cum_value
9e179a64 1694 = streamer_read_gcov_count (ib);
e3ba12e8 1695 }
9e179a64 1696 /* IPA-profile computes hot bb threshold based on cumulated
1697 whole program profile. We need to stream it down to ltrans. */
1698 if (flag_ltrans)
1699 set_hot_bb_threshold (streamer_read_gcov_count (ib));
6c0782b1 1700 }
1701
1702}
7bfefa9d 1703
c470c5a9 1704/* Rescale profile summaries to the same number of runs in the whole unit. */
1705
1706static void
1707merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1708{
1709 struct lto_file_decl_data *file_data;
e3ba12e8 1710 unsigned int j, h_ix;
c470c5a9 1711 gcov_unsigned_t max_runs = 0;
1712 struct cgraph_node *node;
1713 struct cgraph_edge *edge;
e3ba12e8 1714 gcov_type saved_sum_all = 0;
1715 gcov_ctr_summary *saved_profile_info = 0;
1716 int saved_scale = 0;
c470c5a9 1717
1718 /* Find unit with maximal number of runs. If we ever get serious about
1719 roundoff errors, we might also consider computing smallest common
1720 multiply. */
1721 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1722 if (max_runs < file_data->profile_info.runs)
1723 max_runs = file_data->profile_info.runs;
1724
1725 if (!max_runs)
1726 return;
1727
1728 /* Simple overflow check. We probably don't need to support that many train
1729 runs. Such a large value probably imply data corruption anyway. */
1730 if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1731 {
1732 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1733 INT_MAX / REG_BR_PROB_BASE);
1734 return;
1735 }
1736
1737 profile_info = &lto_gcov_summary;
1738 lto_gcov_summary.runs = max_runs;
1739 lto_gcov_summary.sum_max = 0;
e3ba12e8 1740 memset (lto_gcov_summary.histogram, 0,
1741 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
c470c5a9 1742
1743 /* Rescale all units to the maximal number of runs.
1744 sum_max can not be easily merged, as we have no idea what files come from
1745 the same run. We do not use the info anyway, so leave it 0. */
1746 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1747 if (file_data->profile_info.runs)
1748 {
f9d4b7f4 1749 int scale = GCOV_COMPUTE_SCALE (max_runs,
1750 file_data->profile_info.runs);
1751 lto_gcov_summary.sum_max
1752 = MAX (lto_gcov_summary.sum_max,
e2bc4ec8 1753 apply_scale (file_data->profile_info.sum_max, scale));
f9d4b7f4 1754 lto_gcov_summary.sum_all
1755 = MAX (lto_gcov_summary.sum_all,
e2bc4ec8 1756 apply_scale (file_data->profile_info.sum_all, scale));
e3ba12e8 1757 /* Save a pointer to the profile_info with the largest
1758 scaled sum_all and the scale for use in merging the
1759 histogram. */
3672a36a 1760 if (!saved_profile_info
1761 || lto_gcov_summary.sum_all > saved_sum_all)
e3ba12e8 1762 {
1763 saved_profile_info = &file_data->profile_info;
1764 saved_sum_all = lto_gcov_summary.sum_all;
1765 saved_scale = scale;
1766 }
c470c5a9 1767 }
1768
e3ba12e8 1769 gcc_assert (saved_profile_info);
1770
1771 /* Scale up the histogram from the profile that had the largest
1772 scaled sum_all above. */
1773 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
1774 {
1775 /* Scale up the min value as we did the corresponding sum_all
1776 above. Use that to find the new histogram index. */
f9d4b7f4 1777 gcov_type scaled_min
e2bc4ec8 1778 = apply_scale (saved_profile_info->histogram[h_ix].min_value,
1779 saved_scale);
3672a36a 1780 /* The new index may be shared with another scaled histogram entry,
1781 so we need to account for a non-zero histogram entry at new_ix. */
e3ba12e8 1782 unsigned new_ix = gcov_histo_index (scaled_min);
3672a36a 1783 lto_gcov_summary.histogram[new_ix].min_value
e90a82bd 1784 = (lto_gcov_summary.histogram[new_ix].num_counters
1785 ? MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min)
1786 : scaled_min);
e3ba12e8 1787 /* Some of the scaled counter values would ostensibly need to be placed
1788 into different (larger) histogram buckets, but we keep things simple
1789 here and place the scaled cumulative counter value in the bucket
1790 corresponding to the scaled minimum counter value. */
1791 lto_gcov_summary.histogram[new_ix].cum_value
e2bc4ec8 1792 += apply_scale (saved_profile_info->histogram[h_ix].cum_value,
1793 saved_scale);
e3ba12e8 1794 lto_gcov_summary.histogram[new_ix].num_counters
3672a36a 1795 += saved_profile_info->histogram[h_ix].num_counters;
e3ba12e8 1796 }
1797
c470c5a9 1798 /* Watch roundoff errors. */
1799 if (lto_gcov_summary.sum_max < max_runs)
1800 lto_gcov_summary.sum_max = max_runs;
1801
1802 /* If merging already happent at WPA time, we are done. */
1803 if (flag_ltrans)
1804 return;
1805
1806 /* Now compute count_materialization_scale of each node.
1807 During LTRANS we already have values of count_materialization_scale
1808 computed, so just update them. */
7c455d87 1809 FOR_EACH_FUNCTION (node)
02774f2d 1810 if (node->lto_file_data
1811 && node->lto_file_data->profile_info.runs)
c470c5a9 1812 {
1813 int scale;
555491e2 1814
e3ba12e8 1815 scale = RDIV (node->count_materialization_scale * max_runs,
02774f2d 1816 node->lto_file_data->profile_info.runs);
c470c5a9 1817 node->count_materialization_scale = scale;
1818 if (scale < 0)
c05be867 1819 fatal_error (input_location, "Profile information in %s corrupted",
c470c5a9 1820 file_data->file_name);
1821
1822 if (scale == REG_BR_PROB_BASE)
1823 continue;
1824 for (edge = node->callees; edge; edge = edge->next_callee)
151b9ff5 1825 if (edge->count.ipa ().nonzero_p ())
1826 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1827 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
1828 if (edge->count.ipa ().nonzero_p ())
1829 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1830 if (node->count.ipa ().nonzero_p ())
1831 node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE);
c470c5a9 1832 }
1833}
1834
02b699d5 1835/* Input and merge the symtab from each of the .o files passed to
7bfefa9d 1836 lto1. */
1837
1838void
02b699d5 1839input_symtab (void)
7bfefa9d 1840{
1841 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1842 struct lto_file_decl_data *file_data;
1843 unsigned int j = 0;
1844 struct cgraph_node *node;
1845
1846 while ((file_data = file_data_vec[j++]))
1847 {
1848 const char *data;
1849 size_t len;
1850 struct lto_input_block *ib;
452659af 1851 vec<symtab_node *> nodes;
7bfefa9d 1852
02b699d5 1853 ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
7bfefa9d 1854 &data, &len);
fd30d60a 1855 if (!ib)
c05be867 1856 fatal_error (input_location,
1857 "cannot find LTO cgraph in %s", file_data->file_name);
c470c5a9 1858 input_profile_summary (ib, file_data);
b8925abd 1859 file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
a238367f 1860 nodes = input_cgraph_1 (file_data, ib);
02b699d5 1861 lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
7bfefa9d 1862 ib, data, len);
48e1416a 1863
8d810329 1864 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1865 &data, &len);
fd30d60a 1866 if (!ib)
c05be867 1867 fatal_error (input_location, "cannot find LTO section refs in %s",
9af5ce0c 1868 file_data->file_name);
70225339 1869 input_refs (ib, nodes);
8d810329 1870 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1871 ib, data, len);
1bf41320 1872 if (flag_ltrans)
1873 input_cgraph_opt_summary (nodes);
f1f41a6c 1874 nodes.release ();
48e1416a 1875 }
30f589a5 1876
c470c5a9 1877 merge_profile_summaries (file_data_vec);
f81d7a38 1878
1879 if (!flag_auto_profile)
1880 get_working_sets ();
e3ba12e8 1881
7bfefa9d 1882
1883 /* Clear out the aux field that was used to store enough state to
1884 tell which nodes should be overwritten. */
7c455d87 1885 FOR_EACH_FUNCTION (node)
7bfefa9d 1886 {
1887 /* Some nodes may have been created by cgraph_node. This
1888 happens when the callgraph contains nested functions. If the
1889 node for the parent function was never emitted to the gimple
1890 file, cgraph_node will create a node for it when setting the
1891 context of the nested function. */
02774f2d 1892 if (node->lto_file_data)
1893 node->aux = NULL;
7bfefa9d 1894 }
1895}
1bf41320 1896
dccabdd1 1897/* Input function/variable tables that will allow libgomp to look up offload
1898 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1899
1900void
bd5653d0 1901input_offload_tables (bool do_force_output)
dccabdd1 1902{
1903 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1904 struct lto_file_decl_data *file_data;
1905 unsigned int j = 0;
1906
1907 while ((file_data = file_data_vec[j++]))
1908 {
1909 const char *data;
1910 size_t len;
1911 struct lto_input_block *ib
1912 = lto_create_simple_input_block (file_data, LTO_section_offload_table,
1913 &data, &len);
1914 if (!ib)
1915 continue;
1916
1917 enum LTO_symtab_tags tag
1918 = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1919 while (tag)
1920 {
1921 if (tag == LTO_symtab_unavail_node)
1922 {
1923 int decl_index = streamer_read_uhwi (ib);
1924 tree fn_decl
1925 = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1926 vec_safe_push (offload_funcs, fn_decl);
4c39e3a5 1927
1928 /* Prevent IPA from removing fn_decl as unreachable, since there
1929 may be no refs from the parent function to child_fn in offload
1930 LTO mode. */
bd5653d0 1931 if (do_force_output)
1932 cgraph_node::get (fn_decl)->mark_force_output ();
dccabdd1 1933 }
1934 else if (tag == LTO_symtab_variable)
1935 {
1936 int decl_index = streamer_read_uhwi (ib);
1937 tree var_decl
1938 = lto_file_decl_data_get_var_decl (file_data, decl_index);
1939 vec_safe_push (offload_vars, var_decl);
4c39e3a5 1940
1941 /* Prevent IPA from removing var_decl as unused, since there
1942 may be no refs to var_decl in offload LTO mode. */
bd5653d0 1943 if (do_force_output)
1944 varpool_node::get (var_decl)->force_output = 1;
dccabdd1 1945 }
1946 else
c05be867 1947 fatal_error (input_location,
1948 "invalid offload table in %s", file_data->file_name);
dccabdd1 1949
1950 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1951 }
1952
1953 lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
1954 ib, data, len);
1955 }
1956}
1957
1bf41320 1958/* True when we need optimization summary for NODE. */
1959
1960static int
eab36a5a 1961output_cgraph_opt_summary_p (struct cgraph_node *node)
1bf41320 1962{
0c0a1a78 1963 return ((node->clone_of || node->former_clone_of)
2b36ac0b 1964 && (node->clone.tree_map
1965 || node->clone.args_to_skip
1966 || node->clone.combined_args_to_skip));
1bf41320 1967}
1968
9bab6a70 1969/* Output optimization summary for EDGE to OB. */
1970static void
d4e80e2b 1971output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
1972 struct cgraph_edge *edge ATTRIBUTE_UNUSED)
9bab6a70 1973{
9bab6a70 1974}
1975
1bf41320 1976/* Output optimization summary for NODE to OB. */
1977
1978static void
1979output_node_opt_summary (struct output_block *ob,
2b36ac0b 1980 struct cgraph_node *node,
eab36a5a 1981 lto_symtab_encoder_t encoder)
1bf41320 1982{
1983 unsigned int index;
1984 bitmap_iterator bi;
1985 struct ipa_replace_map *map;
30baba90 1986 struct bitpack_d bp;
1bf41320 1987 int i;
9bab6a70 1988 struct cgraph_edge *e;
1bf41320 1989
29413d70 1990 if (node->clone.args_to_skip)
1991 {
7f385784 1992 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.args_to_skip));
29413d70 1993 EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi)
7f385784 1994 streamer_write_uhwi (ob, index);
29413d70 1995 }
1996 else
7f385784 1997 streamer_write_uhwi (ob, 0);
29413d70 1998 if (node->clone.combined_args_to_skip)
1999 {
7f385784 2000 streamer_write_uhwi (ob, bitmap_count_bits (node->clone.combined_args_to_skip));
29413d70 2001 EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi)
7f385784 2002 streamer_write_uhwi (ob, index);
29413d70 2003 }
2004 else
7f385784 2005 streamer_write_uhwi (ob, 0);
f1f41a6c 2006 streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map));
2007 FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map)
1bf41320 2008 {
1bf41320 2009 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
2010 mechanism to store function local declarations into summaries. */
79e830ee 2011 gcc_assert (!map->old_tree);
2012 streamer_write_uhwi (ob, map->parm_num);
8e7408e3 2013 gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
515cf651 2014 stream_write_tree (ob, map->new_tree, true);
30baba90 2015 bp = bitpack_create (ob->main_stream);
2016 bp_pack_value (&bp, map->replace_p, 1);
2017 bp_pack_value (&bp, map->ref_p, 1);
7f385784 2018 streamer_write_bitpack (&bp);
1bf41320 2019 }
2b36ac0b 2020
02774f2d 2021 if (lto_symtab_encoder_in_partition_p (encoder, node))
2b36ac0b 2022 {
2023 for (e = node->callees; e; e = e->next_callee)
2024 output_edge_opt_summary (ob, e);
2025 for (e = node->indirect_calls; e; e = e->next_callee)
2026 output_edge_opt_summary (ob, e);
2027 }
1bf41320 2028}
2029
2030/* Output optimization summaries stored in callgraph.
2031 At the moment it is the clone info structure. */
2032
2033static void
eab36a5a 2034output_cgraph_opt_summary (void)
1bf41320 2035{
1bf41320 2036 int i, n_nodes;
70225339 2037 lto_symtab_encoder_t encoder;
1bf41320 2038 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
2039 unsigned count = 0;
2040
afb0d513 2041 ob->symbol = NULL;
70225339 2042 encoder = ob->decl_state->symtab_node_encoder;
2043 n_nodes = lto_symtab_encoder_size (encoder);
1bf41320 2044 for (i = 0; i < n_nodes; i++)
2dc9831f 2045 {
452659af 2046 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
13cbeaac 2047 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
2dc9831f 2048 if (cnode && output_cgraph_opt_summary_p (cnode))
2049 count++;
2050 }
7f385784 2051 streamer_write_uhwi (ob, count);
1bf41320 2052 for (i = 0; i < n_nodes; i++)
2053 {
452659af 2054 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
13cbeaac 2055 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
2dc9831f 2056 if (cnode && output_cgraph_opt_summary_p (cnode))
1bf41320 2057 {
7f385784 2058 streamer_write_uhwi (ob, i);
2dc9831f 2059 output_node_opt_summary (ob, cnode, encoder);
1bf41320 2060 }
2061 }
2062 produce_asm (ob, NULL);
2063 destroy_output_block (ob);
2064}
2065
9bab6a70 2066/* Input optimisation summary of EDGE. */
2067
2068static void
d4e80e2b 2069input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
2070 struct lto_input_block *ib_main ATTRIBUTE_UNUSED)
9bab6a70 2071{
9bab6a70 2072}
2073
2074/* Input optimisation summary of NODE. */
1bf41320 2075
2076static void
2077input_node_opt_summary (struct cgraph_node *node,
2078 struct lto_input_block *ib_main,
2079 struct data_in *data_in)
2080{
2081 int i;
2082 int count;
2083 int bit;
30baba90 2084 struct bitpack_d bp;
9bab6a70 2085 struct cgraph_edge *e;
1bf41320 2086
7f385784 2087 count = streamer_read_uhwi (ib_main);
1bf41320 2088 if (count)
2089 node->clone.args_to_skip = BITMAP_GGC_ALLOC ();
2090 for (i = 0; i < count; i++)
2091 {
7f385784 2092 bit = streamer_read_uhwi (ib_main);
1bf41320 2093 bitmap_set_bit (node->clone.args_to_skip, bit);
2094 }
7f385784 2095 count = streamer_read_uhwi (ib_main);
1bf41320 2096 if (count)
2097 node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC ();
2098 for (i = 0; i < count; i++)
2099 {
7f385784 2100 bit = streamer_read_uhwi (ib_main);
1bf41320 2101 bitmap_set_bit (node->clone.combined_args_to_skip, bit);
2102 }
7f385784 2103 count = streamer_read_uhwi (ib_main);
1bf41320 2104 for (i = 0; i < count; i++)
2105 {
25a27413 2106 struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
1bf41320 2107
f1f41a6c 2108 vec_safe_push (node->clone.tree_map, map);
7f385784 2109 map->parm_num = streamer_read_uhwi (ib_main);
1bf41320 2110 map->old_tree = NULL;
515cf651 2111 map->new_tree = stream_read_tree (ib_main, data_in);
7f385784 2112 bp = streamer_read_bitpack (ib_main);
30baba90 2113 map->replace_p = bp_unpack_value (&bp, 1);
2114 map->ref_p = bp_unpack_value (&bp, 1);
1bf41320 2115 }
9bab6a70 2116 for (e = node->callees; e; e = e->next_callee)
2117 input_edge_opt_summary (e, ib_main);
2118 for (e = node->indirect_calls; e; e = e->next_callee)
2119 input_edge_opt_summary (e, ib_main);
1bf41320 2120}
2121
2122/* Read section in file FILE_DATA of length LEN with data DATA. */
2123
2124static void
2125input_cgraph_opt_section (struct lto_file_decl_data *file_data,
f1f41a6c 2126 const char *data, size_t len,
452659af 2127 vec<symtab_node *> nodes)
1bf41320 2128{
2129 const struct lto_function_header *header =
2130 (const struct lto_function_header *) data;
949e5786 2131 const int cfg_offset = sizeof (struct lto_function_header);
2132 const int main_offset = cfg_offset + header->cfg_size;
2133 const int string_offset = main_offset + header->main_size;
1bf41320 2134 struct data_in *data_in;
1bf41320 2135 unsigned int i;
2136 unsigned int count;
2137
472ca566 2138 lto_input_block ib_main ((const char *) data + main_offset,
2e971afd 2139 header->main_size, file_data->mode_table);
1bf41320 2140
2141 data_in =
2142 lto_data_in_create (file_data, (const char *) data + string_offset,
1e094109 2143 header->string_size, vNULL);
7f385784 2144 count = streamer_read_uhwi (&ib_main);
1bf41320 2145
2146 for (i = 0; i < count; i++)
2147 {
7f385784 2148 int ref = streamer_read_uhwi (&ib_main);
415d1b9a 2149 input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
1bf41320 2150 &ib_main, data_in);
2151 }
783bc09c 2152 lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
1bf41320 2153 len);
2154 lto_data_in_delete (data_in);
2155}
2156
2157/* Input optimization summary of cgraph. */
2158
2159static void
452659af 2160input_cgraph_opt_summary (vec<symtab_node *> nodes)
1bf41320 2161{
2162 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2163 struct lto_file_decl_data *file_data;
2164 unsigned int j = 0;
2165
2166 while ((file_data = file_data_vec[j++]))
2167 {
2168 size_t len;
2169 const char *data =
2170 lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL,
2171 &len);
2172
2173 if (data)
2174 input_cgraph_opt_section (file_data, data, len, nodes);
2175 }
2176}