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