Line data Source code
1 : /* Write the GIMPLE representation to a file stream.
2 :
3 : Copyright (C) 2009-2026 Free Software Foundation, Inc.
4 : Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 : Re-implemented by Diego Novillo <dnovillo@google.com>
6 :
7 : This file is part of GCC.
8 :
9 : GCC is free software; you can redistribute it and/or modify it under
10 : the terms of the GNU General Public License as published by the Free
11 : Software Foundation; either version 3, or (at your option) any later
12 : version.
13 :
14 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 : for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with GCC; see the file COPYING3. If not see
21 : <http://www.gnu.org/licenses/>. */
22 :
23 : #include "config.h"
24 : #include "system.h"
25 : #include "coretypes.h"
26 : #include "backend.h"
27 : #include "target.h"
28 : #include "rtl.h"
29 : #include "tree.h"
30 : #include "gimple.h"
31 : #include "tree-pass.h"
32 : #include "ssa.h"
33 : #include "gimple-streamer.h"
34 : #include "alias.h"
35 : #include "stor-layout.h"
36 : #include "gimple-iterator.h"
37 : #include "except.h"
38 : #include "lto-symtab.h"
39 : #include "cgraph.h"
40 : #include "cfgloop.h"
41 : #include "builtins.h"
42 : #include "gomp-constants.h"
43 : #include "debug.h"
44 : #include "omp-offload.h"
45 : #include "print-tree.h"
46 : #include "tree-dfa.h"
47 : #include "file-prefix-map.h" /* remap_debug_filename() */
48 : #include "output.h"
49 : #include "ipa-utils.h"
50 : #include "toplev.h"
51 :
52 :
53 : static void lto_write_tree (struct output_block*, tree, bool);
54 :
55 : /* Clear the line info stored in DATA_IN. */
56 :
57 : static void
58 357689 : clear_line_info (struct output_block *ob)
59 : {
60 : /* Initialize to something that will never appear as block,
61 : so that the first location with block in a function etc.
62 : always streams a change_block bit and the first block. */
63 357689 : ob->current_block = void_node;
64 357689 : ob->current_discr = UINT_MAX;
65 357689 : ob->current_map_idx = 0;
66 357689 : ob->current_loc_offset = 0;
67 357689 : ob->current_linemap_id = -1U;
68 0 : }
69 :
70 :
71 : /* Create the output block and return it. SECTION_TYPE is
72 : LTO_section_function_body or LTO_static_initializer. */
73 :
74 : struct output_block *
75 357689 : create_output_block (enum lto_section_type section_type)
76 : {
77 357689 : struct output_block *ob = XCNEW (struct output_block);
78 357689 : if (streamer_dump_file)
79 44 : fprintf (streamer_dump_file, "Creating output block for %s\n",
80 44 : lto_section_name[section_type]);
81 :
82 357689 : ob->section_type = section_type;
83 357689 : ob->decl_state = lto_get_out_decl_state ();
84 : /* Only global decl stream in non-wpa will ever be considered by tree
85 : merging. */
86 357689 : if (!flag_wpa && section_type == LTO_section_decls)
87 23943 : ob->local_trees = new (hash_set <tree>);
88 357689 : ob->main_stream = XCNEW (struct lto_output_stream);
89 357689 : ob->string_stream = XCNEW (struct lto_output_stream);
90 357689 : ob->writer_cache = streamer_tree_cache_create (!flag_wpa, true, false);
91 :
92 357689 : if (section_type == LTO_section_function_body)
93 121655 : ob->cfg_stream = XCNEW (struct lto_output_stream);
94 :
95 357689 : clear_line_info (ob);
96 :
97 357689 : ob->string_hash_table = new hash_table<string_slot_hasher> (37);
98 357689 : gcc_obstack_init (&ob->obstack);
99 :
100 357689 : return ob;
101 : }
102 :
103 :
104 : /* Destroy the output block OB. */
105 :
106 : void
107 357689 : destroy_output_block (struct output_block *ob)
108 : {
109 357689 : enum lto_section_type section_type = ob->section_type;
110 :
111 357689 : delete ob->string_hash_table;
112 357689 : ob->string_hash_table = NULL;
113 381632 : delete ob->local_trees;
114 :
115 357689 : free (ob->main_stream);
116 357689 : free (ob->string_stream);
117 357689 : if (section_type == LTO_section_function_body)
118 121655 : free (ob->cfg_stream);
119 :
120 357689 : streamer_tree_cache_delete (ob->writer_cache);
121 357689 : obstack_free (&ob->obstack, NULL);
122 :
123 357689 : free (ob);
124 357689 : }
125 :
126 :
127 : /* Wrapper around variably_modified_type_p avoiding type modification
128 : during WPA streaming. */
129 :
130 : bool
131 14738177 : lto_variably_modified_type_p (tree type)
132 : {
133 14738177 : return (in_lto_p
134 14738177 : ? TYPE_LANG_FLAG_0 (TYPE_MAIN_VARIANT (type))
135 14432225 : : variably_modified_type_p (type, NULL_TREE));
136 : }
137 :
138 :
139 : /* Return true if tree node T is written to various tables. For these
140 : nodes, we sometimes want to write their physical representation
141 : (via lto_output_tree), and sometimes we need to emit an index
142 : reference into a table (via lto_output_tree_ref). */
143 :
144 : static bool
145 36738997 : tree_is_indexable (tree t)
146 : {
147 : /* Parameters and return values of functions of variably modified types
148 : must go to global stream, because they may be used in the type
149 : definition. */
150 35620357 : if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
151 37076492 : && DECL_CONTEXT (t))
152 1456135 : return lto_variably_modified_type_p (TREE_TYPE (DECL_CONTEXT (t)));
153 : /* IMPORTED_DECL is put into BLOCK and thus it never can be shared.
154 : We should no longer need to stream it. */
155 35282862 : else if (TREE_CODE (t) == IMPORTED_DECL)
156 0 : gcc_unreachable ();
157 35282862 : else if (TREE_CODE (t) == LABEL_DECL)
158 84049 : return FORCED_LABEL (t) || DECL_NONLOCAL (t);
159 1724637 : else if (((VAR_P (t) && !TREE_STATIC (t))
160 : || TREE_CODE (t) == TYPE_DECL
161 : || TREE_CODE (t) == CONST_DECL
162 : || TREE_CODE (t) == NAMELIST_DECL)
163 36106227 : && decl_function_context (t))
164 : return false;
165 34301322 : else if (TREE_CODE (t) == DEBUG_EXPR_DECL)
166 : return false;
167 : /* Variably modified types need to be streamed alongside function
168 : bodies because they can refer to local entities. Together with
169 : them we have to localize their members as well.
170 : ??? In theory that includes non-FIELD_DECLs as well. */
171 34299388 : else if (TYPE_P (t)
172 34299388 : && lto_variably_modified_type_p (t))
173 : return false;
174 34287545 : else if (TREE_CODE (t) == FIELD_DECL
175 34287545 : && lto_variably_modified_type_p (DECL_CONTEXT (t)))
176 : return false;
177 : else
178 34287116 : return (IS_TYPE_OR_DECL_P (t) || TREE_CODE (t) == SSA_NAME);
179 : }
180 :
181 : namespace {
182 :
183 : /* Compute a 32-bit hash of the linemap details. This is currently used to
184 : ensure that WPA streamed output will change whenever the linemap details
185 : change, otherwise there could be potential issues with the validity of
186 : the cache used to implement -flto-incremental. */
187 :
188 : hashval_t
189 63947 : compute_map_hash (const line_map_ordinary *map)
190 : {
191 63947 : inchash::hash h;
192 63947 : h.add_int (map->sysp);
193 63947 : h.add_int (map->m_column_and_range_bits - map->m_range_bits);
194 63947 : h.add_int (map->to_line);
195 63947 : h.add_object (map->included_from);
196 63947 : h.add (map->to_file, strlen (map->to_file));
197 63947 : return h.end ();
198 : }
199 :
200 : class location_output
201 : {
202 : public:
203 :
204 : struct map_id_t
205 : {
206 : size_t idx;
207 : unsigned linemap_id;
208 : hashval_t hash;
209 : };
210 :
211 : struct location_id_t
212 : {
213 : map_id_t map_id;
214 : location_t offset;
215 : };
216 :
217 : location_id_t record_location (location_t loc);
218 :
219 21236 : void register_map_id (size_t map_idx, unsigned linemap_id)
220 : {
221 34296 : gcc_checking_assert (LINEMAPS_ORDINARY_USED (line_table)
222 : == orig_map_ids.length () + 1);
223 21236 : const auto map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
224 21236 : const hashval_t hash = compute_map_hash (map);
225 21236 : orig_map_ids.safe_push (map_id_t{map_idx, linemap_id, hash});
226 21236 : }
227 :
228 : void produce_linemap_section ();
229 :
230 : private:
231 : struct map_data
232 : {
233 : size_t idx;
234 : hashval_t hash;
235 : location_t highest_location;
236 : };
237 : hash_map<nofree_ptr_hash<const line_map_ordinary>, map_data> map_data_map;
238 : vec<map_id_t> orig_map_ids = {};
239 : };
240 :
241 : location_output::location_id_t
242 7095857 : location_output::record_location (location_t loc)
243 : {
244 : /* Strip away any macro expansion data or embedded range information. */
245 7095857 : loc = linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
246 : nullptr);
247 7095857 : loc = get_pure_location (loc);
248 7095857 : location_id_t loc_id = {};
249 7095857 : if (loc < RESERVED_LOCATION_COUNT)
250 : {
251 : /* IDX 0 is for reserved locations. */
252 2484845 : loc_id.offset = loc;
253 2484845 : return loc_id;
254 : }
255 :
256 4611012 : const auto map = linemap_check_ordinary (linemap_lookup (line_table, loc));
257 :
258 4611012 : if (flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
259 : {
260 : /* In these modes, we don't create new locations, we only work with what
261 : was read, so we will re-output the locations in the same way. */
262 392060 : gcc_checking_assert (orig_map_ids.length ()
263 : == LINEMAPS_ORDINARY_USED (line_table));
264 196030 : gcc_checking_assert (!map->m_range_bits);
265 196030 : loc_id.map_id = orig_map_ids[map - line_table->info_ordinary.maps];
266 196030 : loc_id.offset = loc - map->start_location;
267 196030 : return loc_id;
268 : }
269 :
270 : /* Represent each location_t as the offset from the map start,
271 : without any range bits. */
272 4414982 : map_data &md = map_data_map.get_or_insert (map);
273 4414982 : if (!md.idx)
274 : {
275 42711 : md.idx = map_data_map.elements ();
276 42711 : md.hash = compute_map_hash (map);
277 : }
278 4414982 : md.highest_location = MAX (md.highest_location, loc);
279 4414982 : loc_id.map_id.idx = md.idx;
280 4414982 : loc_id.map_id.hash = md.hash;
281 4414982 : loc_id.offset = (loc - map->start_location) >> map->m_range_bits;
282 4414982 : return loc_id;
283 : }
284 :
285 : /* Bitpack packing is more efficient for small values since every 4th bit is a
286 : continuation bit, so it helps to pack values as the delta from the previous
287 : if they can get large. */
288 : template<typename Int>
289 : static void
290 9046694 : bp_pack_delta (bitpack_d *bp, Int val, Int &prev)
291 : {
292 9046694 : const bool decrease = (val < prev);
293 9046694 : bp_pack_value (bp, decrease, 1);
294 9046694 : bp_pack_var_len_unsigned (bp, decrease ? prev - val : val - prev);
295 9046694 : prev = val;
296 9046694 : }
297 :
298 : void
299 23907 : location_output::produce_linemap_section ()
300 : {
301 23907 : timevar_push (TV_IPA_LTO_LINEMAP_OUT);
302 :
303 23907 : const auto ob = create_output_block (LTO_section_linemap);
304 23907 : auto bp = bitpack_create (ob->main_stream);
305 :
306 : /* Prepare the diagnostic classification history. To make life easier on the
307 : reader, which will need to build the line map before processing the
308 : classification history, we will stream it out after the line map data. But
309 : we need to call record_location() now. */
310 23907 : const auto &chist = global_dc->get_classification_history ();
311 91833 : for (auto &c : chist)
312 65188 : record_location (c.location);
313 :
314 : /* Sort the maps in the order they need to be inserted later. */
315 23907 : const size_t nmaps = map_data_map.elements ();
316 23907 : using KV = std::pair<const line_map_ordinary *, map_data>;
317 66618 : const std::unique_ptr<KV[]> sorted_maps{new KV[nmaps]};
318 23907 : size_t map_i = 0;
319 66618 : for (auto iter = map_data_map.begin (), end = map_data_map.end ();
320 66618 : iter != end; ++iter)
321 42711 : sorted_maps[map_i++] = *iter;
322 23907 : gcc_qsort (sorted_maps.get (), nmaps, sizeof (KV),
323 : [] (const void *p1, const void *p2)
324 : {
325 : const auto map1 = static_cast<const KV *> (p1)->first;
326 : const auto map2 = static_cast<const KV *> (p2)->first;
327 : const location_t loc1 = map1->start_location;
328 : const location_t loc2 = map2->start_location;
329 : return (loc2 < loc1) - (loc1 < loc2);
330 : });
331 :
332 : /* Output the maps. */
333 23907 : bp_pack_var_len_unsigned (&bp, nmaps);
334 23907 : const char *current_file = nullptr;
335 23907 : bool emit_pwd = true;
336 23907 : size_t prev_idx = 0;
337 23907 : linenum_type prev_line = 0;
338 66618 : for (map_i = 0; map_i != nmaps; ++map_i)
339 : {
340 42711 : const auto map = sorted_maps[map_i].first;
341 42711 : const map_data &md = sorted_maps[map_i].second;
342 42711 : bp_pack_delta (&bp, md.idx, prev_idx);
343 42711 : const auto num_lines
344 42711 : = 1 + ((md.highest_location - map->start_location)
345 42711 : >> map->m_column_and_range_bits);
346 42711 : bp_pack_var_len_unsigned (&bp, num_lines);
347 42711 : bp_pack_value (&bp, map->sysp != 0, 1);
348 42711 : bp_pack_value (&bp, map->m_column_and_range_bits - map->m_range_bits, 8);
349 42711 : bp_pack_delta (&bp, map->to_line, prev_line);
350 42711 : const bool file_change = (map->to_file != current_file);
351 42711 : bp_pack_value (&bp, file_change, 1);
352 42711 : if (file_change)
353 : {
354 42711 : bool stream_pwd = false;
355 42711 : const char *remapped = remap_debug_filename (map->to_file);
356 42711 : if (emit_pwd && remapped && !IS_ABSOLUTE_PATH (remapped))
357 : {
358 1979 : stream_pwd = true;
359 1979 : emit_pwd = false;
360 : }
361 42711 : bp_pack_value (&bp, stream_pwd, 1);
362 42711 : if (stream_pwd)
363 1979 : bp_pack_string (ob, &bp, get_src_pwd (), true);
364 42711 : bp_pack_string (ob, &bp, remapped, true);
365 : }
366 : }
367 :
368 : /* Output the diagnostics classification history. */
369 25276 : bp_pack_var_len_unsigned (&bp, chist.length ());
370 91833 : for (auto &c : chist)
371 : {
372 65188 : const location_id_t loc_id = record_location (c.location);
373 65188 : bp_pack_var_len_unsigned (&bp, loc_id.map_id.idx);
374 65188 : bp_pack_var_len_unsigned (&bp, loc_id.offset);
375 65188 : bp_pack_var_len_int (&bp, c.option);
376 65188 : using DK = diagnostics::kind;
377 65188 : bp_pack_enum (&bp, DK, DK::tot_num_diagnostic_kinds, c.kind);
378 : }
379 :
380 : /* Finalize the section. */
381 23907 : streamer_write_bitpack (&bp);
382 23907 : {
383 23907 : const auto section_name
384 23907 : = lto_get_section_name (LTO_section_linemap, nullptr, 0, nullptr);
385 23907 : lto_begin_section (section_name, true);
386 23907 : free (section_name);
387 : }
388 :
389 23907 : lto_simple_header_with_strings header = {};
390 23907 : header.main_size = ob->main_stream->total_size;
391 23907 : header.string_size = ob->string_stream->total_size;
392 23907 : lto_write_data (&header, sizeof header);
393 23907 : lto_write_stream (ob->main_stream);
394 23907 : lto_write_stream (ob->string_stream);
395 23907 : lto_end_section ();
396 23907 : destroy_output_block (ob);
397 :
398 23907 : timevar_pop (TV_IPA_LTO_LINEMAP_OUT);
399 23907 : }
400 :
401 : location_output loc_output;
402 :
403 : } /* unnamed namespace */
404 :
405 : /* Get a mapping index for LOC and stream it along with optional ancillary
406 : data. */
407 :
408 : static void
409 6965481 : lto_output_location_1 (struct output_block *ob, struct bitpack_d *bp,
410 : location_t loc, bool block_p)
411 : {
412 6965481 : const auto loc_id = loc_output.record_location (loc);
413 6965481 : if (!loc_id.map_id.idx)
414 : {
415 2484845 : bp_pack_value (bp, true, 1);
416 2484845 : bp_pack_int_in_range (bp, 0, RESERVED_LOCATION_COUNT - 1, loc_id.offset);
417 : }
418 : else
419 : {
420 4480636 : bp_pack_value (bp, false, 1);
421 4480636 : if (loc_id.map_id.linemap_id == ob->current_linemap_id)
422 4336027 : bp_pack_value (bp, false, 1);
423 : else
424 : {
425 144609 : bp_pack_value (bp, true, 1);
426 144609 : bp_pack_var_len_unsigned (bp, loc_id.map_id.linemap_id);
427 144609 : ob->current_linemap_id = loc_id.map_id.linemap_id;
428 : }
429 4480636 : const bool is_new_map = (loc_id.map_id.idx != ob->current_map_idx);
430 4480636 : bp_pack_delta (bp, loc_id.map_id.idx, ob->current_map_idx);
431 4480636 : bp_pack_delta (bp, loc_id.offset, ob->current_loc_offset);
432 4480636 : if (is_new_map)
433 227523 : bp_pack_var_len_unsigned (bp, loc_id.map_id.hash);
434 4480636 : const unsigned discr = get_discriminator_from_loc (loc);
435 4480636 : bp_pack_value (bp, ob->current_discr != discr, 1);
436 4480636 : if (ob->current_discr != discr)
437 : {
438 1349505 : bp_pack_var_len_unsigned (bp, discr);
439 1349505 : ob->current_discr = discr;
440 : }
441 : }
442 :
443 6965481 : if (block_p)
444 : {
445 3025741 : tree block = LOCATION_BLOCK (loc);
446 3025741 : bp_pack_value (bp, ob->current_block != block, 1);
447 3025741 : streamer_write_bitpack (bp);
448 3025741 : if (ob->current_block != block)
449 : {
450 657911 : lto_output_tree (ob, block, true, true);
451 657911 : ob->current_block = block;
452 : }
453 : }
454 6965481 : }
455 :
456 : /* Output info about new location into bitpack BP.
457 : After outputting bitpack, lto_output_location_data has
458 : to be done to output actual data. */
459 :
460 : void
461 3939740 : lto_output_location (struct output_block *ob, struct bitpack_d *bp,
462 : location_t loc)
463 : {
464 3939740 : lto_output_location_1 (ob, bp, loc, false);
465 3939740 : }
466 :
467 : /* Output info about new location into bitpack BP.
468 : After outputting bitpack, lto_output_location_data has
469 : to be done to output actual data. Like lto_output_location, but
470 : additionally output LOCATION_BLOCK info too and write the BP bitpack. */
471 :
472 : void
473 3025741 : lto_output_location_and_block (struct output_block *ob, struct bitpack_d *bp,
474 : location_t loc)
475 : {
476 3025741 : lto_output_location_1 (ob, bp, loc, true);
477 3025741 : }
478 :
479 :
480 : /* Lookup NAME in ENCODER. If NAME is not found, create a new entry in
481 : ENCODER for NAME with the next available index of ENCODER, then
482 : print the index to OBS.
483 : Return the index. */
484 :
485 :
486 : static unsigned
487 8191833 : lto_get_index (struct lto_tree_ref_encoder *encoder, tree t)
488 : {
489 8191833 : bool existed_p;
490 :
491 8191833 : unsigned int &index
492 8191833 : = encoder->tree_hash_table->get_or_insert (t, &existed_p);
493 8191833 : if (!existed_p)
494 : {
495 2235537 : index = encoder->trees.length ();
496 2235537 : if (streamer_dump_file)
497 : {
498 176 : print_node_brief (streamer_dump_file, " Encoding indexable ",
499 : t, 4);
500 176 : fprintf (streamer_dump_file, " as %i \n", index);
501 : }
502 2235537 : encoder->trees.safe_push (t);
503 : }
504 :
505 8191833 : return index;
506 : }
507 :
508 :
509 : /* If EXPR is an indexable tree node, output a reference to it to
510 : output block OB. Otherwise, output the physical representation of
511 : EXPR to OB. */
512 :
513 : static void
514 9724705 : lto_indexable_tree_ref (struct output_block *ob, tree expr,
515 : enum LTO_tags *tag, unsigned *index)
516 : {
517 9724705 : gcc_checking_assert (tree_is_indexable (expr));
518 :
519 9724705 : if (TREE_CODE (expr) == SSA_NAME)
520 : {
521 2250470 : *tag = LTO_ssa_name_ref;
522 2250470 : *index = SSA_NAME_VERSION (expr);
523 : }
524 : else
525 : {
526 7474235 : *tag = LTO_global_stream_ref;
527 7474235 : *index = lto_get_index (&ob->decl_state->streams[LTO_DECL_STREAM], expr);
528 : }
529 9724705 : }
530 :
531 :
532 : /* Output a static or extern var DECL to OBS. */
533 :
534 : void
535 291219 : lto_output_var_decl_ref (struct lto_out_decl_state *decl_state,
536 : struct lto_output_stream * obs, tree decl)
537 : {
538 291219 : gcc_checking_assert (VAR_P (decl));
539 291219 : streamer_write_uhwi_stream
540 291219 : (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM],
541 : decl));
542 291219 : }
543 :
544 :
545 : /* Output a static or extern var DECL to OBS. */
546 :
547 : void
548 426379 : lto_output_fn_decl_ref (struct lto_out_decl_state *decl_state,
549 : struct lto_output_stream * obs, tree decl)
550 : {
551 426379 : gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
552 426379 : streamer_write_uhwi_stream
553 426379 : (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM], decl));
554 426379 : }
555 :
556 : /* Return true if EXPR is a tree node that can be written to disk. */
557 :
558 : static inline bool
559 7267501 : lto_is_streamable (tree expr)
560 : {
561 7267501 : enum tree_code code = TREE_CODE (expr);
562 :
563 : /* Notice that we reject SSA_NAMEs as well. We only emit the SSA
564 : name version in lto_output_tree_ref (see output_ssa_names). */
565 7267501 : return !is_lang_specific (expr)
566 7267501 : && code != SSA_NAME
567 7267501 : && code != LANG_TYPE
568 : && code != MODIFY_EXPR
569 7267501 : && code != INIT_EXPR
570 7267501 : && code != TARGET_EXPR
571 7267501 : && code != BIND_EXPR
572 7267501 : && code != WITH_CLEANUP_EXPR
573 7267501 : && code != STATEMENT_LIST
574 7267501 : && (code == CASE_LABEL_EXPR
575 7267501 : || code == DECL_EXPR
576 7258929 : || code == ASM_EXPR
577 7258889 : || TREE_CODE_CLASS (code) != tcc_statement);
578 : }
579 :
580 : /* Very rough estimate of streaming size of the initializer. If we ignored
581 : presence of strings, we could simply just count number of non-indexable
582 : tree nodes and number of references to indexable nodes. Strings however
583 : may be very large and we do not want to dump them into the global stream.
584 :
585 : Count the size of initializer until the size in DATA is positive. */
586 :
587 : static tree
588 103315 : subtract_estimated_size (tree *tp, int *ws, void *data)
589 : {
590 103315 : long *sum = (long *)data;
591 103315 : if (tree_is_indexable (*tp))
592 : {
593 : /* Indexable tree is one reference to global stream.
594 : Guess it may be about 4 bytes. */
595 1599 : *sum -= 4;
596 1599 : *ws = 0;
597 : }
598 : /* String table entry + base of tree node needs to be streamed. */
599 103315 : if (TREE_CODE (*tp) == STRING_CST)
600 7986 : *sum -= TREE_STRING_LENGTH (*tp) + 8;
601 : else
602 : {
603 : /* Identifiers are also variable length but should not appear
604 : naked in constructor. */
605 95329 : gcc_checking_assert (TREE_CODE (*tp) != IDENTIFIER_NODE);
606 : /* We do not really make attempt to work out size of pickled tree, as
607 : it is very variable. Make it bigger than the reference. */
608 95329 : *sum -= 16;
609 : }
610 103315 : if (*sum < 0)
611 33923 : return *tp;
612 : return NULL_TREE;
613 : }
614 :
615 :
616 : /* For EXPR lookup and return what we want to stream to OB as DECL_INITIAL. */
617 :
618 : static tree
619 2465749 : get_symbol_initial_value (lto_symtab_encoder_t encoder, tree expr)
620 : {
621 2465749 : gcc_checking_assert (DECL_P (expr)
622 : && TREE_CODE (expr) != FUNCTION_DECL
623 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL);
624 :
625 : /* Handle DECL_INITIAL for symbols. */
626 2465749 : tree initial = DECL_INITIAL (expr);
627 2465749 : if (VAR_P (expr)
628 1224717 : && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
629 865981 : && !DECL_IN_CONSTANT_POOL (expr)
630 3331598 : && initial)
631 : {
632 87467 : varpool_node *vnode;
633 : /* Extra section needs about 30 bytes; do not produce it for simple
634 : scalar values. */
635 87467 : if (!(vnode = varpool_node::get (expr))
636 87467 : || !lto_symtab_encoder_encode_initializer_p (encoder, vnode))
637 3289 : initial = error_mark_node;
638 87467 : if (initial != error_mark_node)
639 : {
640 70238 : long max_size = 30;
641 70238 : if (walk_tree (&initial, subtract_estimated_size, (void *)&max_size,
642 : NULL))
643 33923 : initial = error_mark_node;
644 : }
645 : }
646 :
647 2465749 : return initial;
648 : }
649 :
650 :
651 : /* Output reference to tree T to the stream.
652 : Assume that T is already in encoder cache.
653 : This is used to stream tree bodies where we know the DFS walk arranged
654 : everything to cache. Must be matched with stream_read_tree_ref. */
655 :
656 : void
657 32976219 : stream_write_tree_ref (struct output_block *ob, tree t)
658 : {
659 32976219 : if (!t)
660 12598601 : streamer_write_zero (ob);
661 : else
662 : {
663 20377618 : unsigned int ix;
664 20377618 : bool existed_p = streamer_tree_cache_lookup (ob->writer_cache, t, &ix);
665 20377618 : if (existed_p)
666 15804480 : streamer_write_hwi (ob, ix + 1);
667 : else
668 : {
669 4573138 : enum LTO_tags tag;
670 4573138 : unsigned ix;
671 4573138 : int id = 0;
672 :
673 4573138 : lto_indexable_tree_ref (ob, t, &tag, &ix);
674 4573138 : if (tag == LTO_ssa_name_ref)
675 : id = 1;
676 : else
677 4362375 : gcc_checking_assert (tag == LTO_global_stream_ref);
678 4573138 : streamer_write_hwi (ob, -(int)(ix * 2 + id + 1));
679 : }
680 : }
681 32976219 : }
682 :
683 :
684 :
685 : /* Write a physical representation of tree node EXPR to output block
686 : OB. If REF_P is true, the leaves of EXPR are emitted as references
687 : via lto_output_tree_ref. IX is the index into the streamer cache
688 : where EXPR is stored. */
689 :
690 : static void
691 7267501 : lto_write_tree_1 (struct output_block *ob, tree expr, bool ref_p)
692 : {
693 7267501 : if (streamer_dump_file)
694 : {
695 420 : print_node_brief (streamer_dump_file, " Streaming body of ",
696 : expr, 4);
697 420 : fprintf (streamer_dump_file, " to %s\n",
698 420 : lto_section_name[ob->section_type]);
699 : }
700 :
701 : /* Pack all the non-pointer fields in EXPR into a bitpack and write
702 : the resulting bitpack. */
703 7267501 : streamer_write_tree_bitfields (ob, expr);
704 :
705 : /* Write all the pointer fields in EXPR. */
706 7267501 : streamer_write_tree_body (ob, expr);
707 :
708 : /* Write any LTO-specific data to OB. */
709 7267501 : if (DECL_P (expr)
710 1560812 : && TREE_CODE (expr) != FUNCTION_DECL
711 1120337 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
712 : {
713 : /* Handle DECL_INITIAL for symbols. */
714 1087359 : tree initial = get_symbol_initial_value
715 1087359 : (ob->decl_state->symtab_node_encoder, expr);
716 1087359 : stream_write_tree (ob, initial, ref_p);
717 : }
718 :
719 : /* Stream references to early generated DIEs. Keep in sync with the
720 : trees handled in dwarf2out_die_ref_for_decl. */
721 7267501 : if ((DECL_P (expr)
722 : && TREE_CODE (expr) != FIELD_DECL
723 : && TREE_CODE (expr) != DEBUG_EXPR_DECL
724 : && TREE_CODE (expr) != TYPE_DECL)
725 5848009 : || TREE_CODE (expr) == BLOCK)
726 : {
727 1777071 : const char *sym;
728 1777071 : unsigned HOST_WIDE_INT off;
729 1777071 : if (debug_info_level > DINFO_LEVEL_NONE
730 1777071 : && debug_hooks->die_ref_for_decl (expr, &sym, &off))
731 : {
732 49541 : streamer_write_string (ob, ob->main_stream, sym, true);
733 49541 : streamer_write_uhwi (ob, off);
734 : }
735 : else
736 1727530 : streamer_write_string (ob, ob->main_stream, NULL, true);
737 : }
738 7267501 : }
739 :
740 : /* Write a physical representation of tree node EXPR to output block
741 : OB. If REF_P is true, the leaves of EXPR are emitted as references
742 : via lto_output_tree_ref. IX is the index into the streamer cache
743 : where EXPR is stored. */
744 :
745 : static void
746 6984842 : lto_write_tree (struct output_block *ob, tree expr, bool ref_p)
747 : {
748 6984842 : if (!lto_is_streamable (expr))
749 0 : internal_error ("tree code %qs is not supported in LTO streams",
750 0 : get_tree_code_name (TREE_CODE (expr)));
751 :
752 : /* Write the header, containing everything needed to materialize
753 : EXPR on the reading side. */
754 6984842 : streamer_write_tree_header (ob, expr);
755 :
756 6984842 : lto_write_tree_1 (ob, expr, ref_p);
757 6984842 : }
758 :
759 : /* Emit the physical representation of tree node EXPR to output block OB,
760 : If THIS_REF_P is true, the leaves of EXPR are emitted as references via
761 : lto_output_tree_ref. REF_P is used for streaming siblings of EXPR. */
762 :
763 : static void
764 8092070 : lto_output_tree_1 (struct output_block *ob, tree expr, hashval_t hash,
765 : bool ref_p, bool this_ref_p)
766 : {
767 8092070 : unsigned ix;
768 :
769 8092070 : gcc_checking_assert (expr != NULL_TREE
770 : && !(this_ref_p && tree_is_indexable (expr)));
771 :
772 8092070 : bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
773 : expr, hash, &ix);
774 8092070 : gcc_assert (!exists_p);
775 8092070 : if (TREE_CODE (expr) == INTEGER_CST
776 8092070 : && !TREE_OVERFLOW (expr))
777 : {
778 : /* Shared INTEGER_CST nodes are special because they need their
779 : original type to be materialized by the reader (to implement
780 : TYPE_CACHED_VALUES). */
781 1107228 : streamer_write_integer_cst (ob, expr);
782 : }
783 : else
784 : {
785 : /* This is the first time we see EXPR, write its fields
786 : to OB. */
787 6984842 : lto_write_tree (ob, expr, ref_p);
788 : }
789 8092070 : }
790 :
791 : class DFS
792 : {
793 : public:
794 : DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p,
795 : bool single_p);
796 : ~DFS ();
797 :
798 : struct scc_entry
799 : {
800 : tree t;
801 : hashval_t hash;
802 : };
803 : auto_vec<scc_entry,32> sccstack;
804 :
805 : private:
806 : struct sccs
807 : {
808 : unsigned int dfsnum;
809 : unsigned int low;
810 : };
811 : struct worklist
812 : {
813 : tree expr;
814 : sccs *from_state;
815 : sccs *cstate;
816 : bool ref_p;
817 : bool this_ref_p;
818 : };
819 : /* Maximum index of scc stack containing a local tree. */
820 : int max_local_entry;
821 :
822 : static int scc_entry_compare (const void *, const void *);
823 :
824 : void DFS_write_tree_body (struct output_block *ob,
825 : tree expr, sccs *expr_state, bool ref_p);
826 :
827 : void DFS_write_tree (struct output_block *ob, sccs *from_state,
828 : tree expr, bool ref_p, bool this_ref_p);
829 :
830 : hashval_t
831 : hash_scc (struct output_block *ob, unsigned first, unsigned size,
832 : bool ref_p, bool this_ref_p);
833 :
834 : hash_map<tree, sccs *> sccstate;
835 : auto_vec<worklist, 32> worklist_vec;
836 : struct obstack sccstate_obstack;
837 : };
838 :
839 : /* Return true if type can not be merged with structurally same tree in
840 : other translation unit. During stream out this information is propagated
841 : to all trees referring to T and they are not streamed with additional
842 : information needed by the tree merging in lto-common.cc (in particular,
843 : scc hash codes are not streamed).
844 :
845 : TRANSLATION_UNIT_DECL is handled specially since references to it does
846 : not make other trees local as well. */
847 :
848 : static bool
849 2929992 : local_tree_p (tree t)
850 : {
851 2929992 : switch (TREE_CODE (t))
852 : {
853 : case LABEL_DECL:
854 : return true;
855 1675 : case NAMESPACE_DECL:
856 1675 : return !DECL_NAME (t);
857 625155 : case VAR_DECL:
858 625155 : case FUNCTION_DECL:
859 625155 : return !TREE_PUBLIC (t) && !DECL_EXTERNAL (t);
860 75679 : case RECORD_TYPE:
861 75679 : case UNION_TYPE:
862 75679 : case ENUMERAL_TYPE:
863 : /* Anonymous namespace types are local.
864 : Only work hard for main variants;
865 : variant types will inherit locality. */
866 75679 : return TYPE_MAIN_VARIANT (t) == t
867 60393 : && odr_type_p (t) && type_with_linkage_p (t)
868 96372 : && type_in_anonymous_namespace_p (t);
869 : default:
870 : return false;
871 : }
872 : }
873 :
874 : /* Emit the physical representation of tree node EXPR to output block OB,
875 : using depth-first search on the subgraph. If THIS_REF_P is true, the
876 : leaves of EXPR are emitted as references via lto_output_tree_ref.
877 : REF_P is used for streaming siblings of EXPR. If SINGLE_P is true,
878 : this is for a rewalk of a single leaf SCC. */
879 :
880 3078835 : DFS::DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p,
881 3078835 : bool single_p)
882 : {
883 3078835 : unsigned int next_dfs_num = 1;
884 :
885 3078835 : max_local_entry = -1;
886 3078835 : gcc_obstack_init (&sccstate_obstack);
887 3078835 : DFS_write_tree (ob, NULL, expr, ref_p, this_ref_p);
888 22349175 : while (!worklist_vec.is_empty ())
889 : {
890 18320335 : worklist &w = worklist_vec.last ();
891 18320335 : expr = w.expr;
892 18320335 : sccs *from_state = w.from_state;
893 18320335 : sccs *cstate = w.cstate;
894 18320335 : ref_p = w.ref_p;
895 18320335 : this_ref_p = w.this_ref_p;
896 18320335 : if (cstate == NULL)
897 : {
898 9934656 : sccs **slot = &sccstate.get_or_insert (expr);
899 9934656 : cstate = *slot;
900 9934656 : if (cstate)
901 : {
902 1548977 : gcc_checking_assert (from_state);
903 1548977 : if (cstate->dfsnum < from_state->dfsnum)
904 197359 : from_state->low = MIN (cstate->dfsnum, from_state->low);
905 1548977 : worklist_vec.pop ();
906 1548977 : continue;
907 : }
908 :
909 8385679 : scc_entry e = { expr, 0 };
910 : /* Not yet visited. DFS recurse and push it onto the stack. */
911 8385679 : *slot = cstate = XOBNEW (&sccstate_obstack, struct sccs);
912 8385679 : if (ob->local_trees && local_tree_p (expr))
913 88846 : max_local_entry = sccstack.length ();
914 8385679 : sccstack.safe_push (e);
915 8385679 : cstate->dfsnum = next_dfs_num++;
916 8385679 : cstate->low = cstate->dfsnum;
917 8385679 : w.cstate = cstate;
918 :
919 8385679 : if (TREE_CODE (expr) == INTEGER_CST
920 8385679 : && !TREE_OVERFLOW (expr))
921 1153664 : DFS_write_tree (ob, cstate, TREE_TYPE (expr), ref_p, ref_p);
922 : else
923 : {
924 7232015 : DFS_write_tree_body (ob, expr, cstate, ref_p);
925 :
926 : /* Walk any LTO-specific edges. */
927 7232015 : if (DECL_P (expr)
928 1564522 : && TREE_CODE (expr) != FUNCTION_DECL
929 1124047 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
930 : {
931 : /* Handle DECL_INITIAL for symbols. */
932 1091069 : tree initial
933 1091069 : = get_symbol_initial_value (ob->decl_state->symtab_node_encoder,
934 : expr);
935 1091069 : DFS_write_tree (ob, cstate, initial, ref_p, ref_p);
936 : }
937 : }
938 8385679 : continue;
939 8385679 : }
940 :
941 : /* See if we found an SCC. */
942 8385679 : if (cstate->low == cstate->dfsnum)
943 : {
944 8176644 : unsigned first, size;
945 8176644 : tree x;
946 :
947 : /* If we are re-walking a single leaf SCC just pop it,
948 : let earlier worklist item access the sccstack. */
949 8176644 : if (single_p)
950 : {
951 347 : worklist_vec.pop ();
952 347 : continue;
953 : }
954 :
955 : /* Pop the SCC and compute its size. */
956 16352594 : first = sccstack.length ();
957 8374729 : do
958 : {
959 8374729 : x = sccstack[--first].t;
960 : }
961 8374729 : while (x != expr);
962 8176297 : size = sccstack.length () - first;
963 :
964 : /* No need to compute hashes for LTRANS units, we don't perform
965 : any merging there. */
966 8176297 : hashval_t scc_hash = 0;
967 8176297 : unsigned scc_entry_len = 0;
968 21810070 : bool local_to_unit = !ob->local_trees
969 8176297 : || max_local_entry >= (int)first;
970 :
971 : /* Remember that trees are local so info gets propagated to other
972 : SCCs. */
973 5457476 : if (local_to_unit && ob->local_trees)
974 : {
975 98990 : for (unsigned i = 0; i < size; ++i)
976 50979 : ob->local_trees->add (sccstack[first + i].t);
977 : }
978 :
979 : /* As a special case do not stream TRANSLATION_UNIT_DECL as shared
980 : tree. We can not mark it local because references to it does not
981 : make other trees local (all global decls refer to it via
982 : CONTEXT). */
983 8176297 : if (size == 1
984 8176297 : && TREE_CODE (sccstack[first].t) == TRANSLATION_UNIT_DECL)
985 : local_to_unit = true;
986 :
987 8143319 : if (!local_to_unit)
988 : {
989 2695098 : scc_hash = hash_scc (ob, first, size, ref_p, this_ref_p);
990 :
991 : /* Put the entries with the least number of collisions first. */
992 2695098 : unsigned entry_start = 0;
993 2695098 : scc_entry_len = size + 1;
994 5539438 : for (unsigned i = 0; i < size;)
995 : {
996 2844340 : unsigned from = i;
997 2844340 : for (i = i + 1; i < size
998 2844340 : && (sccstack[first + i].hash
999 149242 : == sccstack[first + from].hash); ++i)
1000 : ;
1001 2844340 : if (i - from < scc_entry_len)
1002 : {
1003 2695098 : scc_entry_len = i - from;
1004 2695098 : entry_start = from;
1005 : }
1006 : }
1007 5390196 : for (unsigned i = 0; i < scc_entry_len; ++i)
1008 2695098 : std::swap (sccstack[first + i],
1009 2695098 : sccstack[first + entry_start + i]);
1010 :
1011 : /* We already sorted SCC deterministically in hash_scc. */
1012 :
1013 : /* Check that we have only one SCC.
1014 : Naturally we may have conflicts if hash function is not
1015 : strong enough. Lets see how far this gets. */
1016 2695098 : gcc_checking_assert (scc_entry_len == 1);
1017 : }
1018 :
1019 8176297 : worklist_vec.pop ();
1020 :
1021 8176297 : unsigned int prev_size = ob->main_stream->total_size;
1022 :
1023 : /* Only global decl sections are considered by tree merging. */
1024 8176297 : if (ob->section_type != LTO_section_decls)
1025 : {
1026 : /* If this is the original tree we stream and it forms SCC
1027 : by itself then we do not need to stream SCC at all. */
1028 4656015 : if (worklist_vec.is_empty () && first == 0 && size == 1)
1029 : return;
1030 2527185 : if (streamer_dump_file)
1031 : {
1032 140 : fprintf (streamer_dump_file,
1033 : " Start of LTO_trees of size %i\n", size);
1034 : }
1035 2527185 : streamer_write_record_start (ob, LTO_trees);
1036 2527185 : streamer_write_uhwi (ob, size);
1037 : }
1038 : /* Write LTO_tree_scc if tree merging is going to be performed. */
1039 3520282 : else if (!local_to_unit
1040 : /* These are special since sharing is not done by tree
1041 : merging machinery. We can not special case them earlier
1042 : because we still need to compute hash for further sharing
1043 : of trees referring to them. */
1044 3520282 : && (size != 1
1045 2626988 : || (TREE_CODE (sccstack[first].t) != IDENTIFIER_NODE
1046 1735893 : && (TREE_CODE (sccstack[first].t) != INTEGER_CST
1047 159897 : || TREE_OVERFLOW (sccstack[first].t)))))
1048 :
1049 : {
1050 1644108 : gcc_checking_assert (ob->section_type == LTO_section_decls);
1051 1644108 : if (streamer_dump_file)
1052 : {
1053 172 : fprintf (streamer_dump_file,
1054 : " Start of LTO_tree_scc of size %i\n", size);
1055 : }
1056 1644108 : streamer_write_record_start (ob, LTO_tree_scc);
1057 : /* In wast majority of cases scc_entry_len is 1 and size is small
1058 : integer. Use extra bit of size to stream info about
1059 : exceptions. */
1060 1644108 : streamer_write_uhwi (ob, size * 2 + (scc_entry_len != 1));
1061 1644108 : if (scc_entry_len != 1)
1062 0 : streamer_write_uhwi (ob, scc_entry_len);
1063 1644108 : streamer_write_uhwi (ob, scc_hash);
1064 : }
1065 : /* Non-trivial SCCs must be packed to trees blocks so forward
1066 : references work correctly. */
1067 1876174 : else if (size != 1)
1068 : {
1069 15983 : if (streamer_dump_file)
1070 : {
1071 0 : fprintf (streamer_dump_file,
1072 : " Start of LTO_trees of size %i\n", size);
1073 : }
1074 15983 : streamer_write_record_start (ob, LTO_trees);
1075 15983 : streamer_write_uhwi (ob, size);
1076 : }
1077 1860191 : else if (streamer_dump_file)
1078 : {
1079 108 : fprintf (streamer_dump_file, " Streaming single tree\n");
1080 : }
1081 :
1082 : /* Write size-1 SCCs without wrapping them inside SCC bundles.
1083 : All INTEGER_CSTs need to be handled this way as we need
1084 : their type to materialize them. Also builtins are handled
1085 : this way. */
1086 6047467 : if (size == 1)
1087 5963240 : lto_output_tree_1 (ob, expr, scc_hash, ref_p, this_ref_p);
1088 : else
1089 : {
1090 :
1091 : /* Write all headers and populate the streamer cache. */
1092 366886 : for (unsigned i = 0; i < size; ++i)
1093 : {
1094 282659 : hashval_t hash = sccstack[first+i].hash;
1095 282659 : tree t = sccstack[first+i].t;
1096 282659 : bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
1097 : t, hash, NULL);
1098 282659 : gcc_assert (!exists_p);
1099 :
1100 282659 : if (!lto_is_streamable (t))
1101 0 : internal_error ("tree code %qs is not supported "
1102 : "in LTO streams",
1103 0 : get_tree_code_name (TREE_CODE (t)));
1104 :
1105 : /* Write the header, containing everything needed to
1106 : materialize EXPR on the reading side. */
1107 282659 : streamer_write_tree_header (ob, t);
1108 : }
1109 :
1110 : /* Write the bitpacks and tree references. */
1111 366886 : for (unsigned i = 0; i < size; ++i)
1112 282659 : lto_write_tree_1 (ob, sccstack[first+i].t, ref_p);
1113 : }
1114 6047467 : if (streamer_dump_file)
1115 420 : fprintf (streamer_dump_file, " %u bytes\n",
1116 420 : ob->main_stream->total_size - prev_size);
1117 :
1118 : /* Finally truncate the vector. */
1119 6047467 : sccstack.truncate (first);
1120 6047467 : if ((int)first <= max_local_entry)
1121 48011 : max_local_entry = first - 1;
1122 :
1123 6047467 : if (from_state)
1124 5097809 : from_state->low = MIN (from_state->low, cstate->low);
1125 6047467 : continue;
1126 6047467 : }
1127 :
1128 209035 : gcc_checking_assert (from_state);
1129 209035 : from_state->low = MIN (from_state->low, cstate->low);
1130 209035 : if (cstate->dfsnum < from_state->dfsnum)
1131 0 : from_state->low = MIN (cstate->dfsnum, from_state->low);
1132 209035 : worklist_vec.pop ();
1133 : }
1134 : }
1135 :
1136 3078835 : DFS::~DFS ()
1137 : {
1138 3078835 : obstack_free (&sccstate_obstack, NULL);
1139 3078835 : }
1140 :
1141 : /* Handle the tree EXPR in the DFS walk with SCC state EXPR_STATE and
1142 : DFS recurse for all tree edges originating from it. */
1143 :
1144 : void
1145 7232015 : DFS::DFS_write_tree_body (struct output_block *ob,
1146 : tree expr, sccs *expr_state, bool ref_p)
1147 : {
1148 : #define DFS_follow_tree_edge(DEST) \
1149 : DFS_write_tree (ob, expr_state, DEST, ref_p, ref_p)
1150 :
1151 7232015 : enum tree_code code;
1152 :
1153 7232015 : code = TREE_CODE (expr);
1154 :
1155 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
1156 : {
1157 6810118 : if (TREE_CODE (expr) != IDENTIFIER_NODE)
1158 5289235 : DFS_follow_tree_edge (TREE_TYPE (expr));
1159 : }
1160 :
1161 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
1162 : {
1163 6156 : unsigned int count = vector_cst_encoded_nelts (expr);
1164 32957 : for (unsigned int i = 0; i < count; ++i)
1165 20645 : DFS_follow_tree_edge (VECTOR_CST_ENCODED_ELT (expr, i));
1166 : }
1167 :
1168 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_POLY_INT_CST))
1169 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1170 0 : DFS_follow_tree_edge (POLY_INT_CST_COEFF (expr, i));
1171 :
1172 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
1173 : {
1174 8013 : DFS_follow_tree_edge (TREE_REALPART (expr));
1175 8013 : DFS_follow_tree_edge (TREE_IMAGPART (expr));
1176 : }
1177 :
1178 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
1179 : {
1180 : /* Drop names that were created for anonymous entities. */
1181 1564522 : if (DECL_NAME (expr)
1182 1376312 : && TREE_CODE (DECL_NAME (expr)) == IDENTIFIER_NODE
1183 2940834 : && IDENTIFIER_ANON_P (DECL_NAME (expr)))
1184 : ;
1185 : else
1186 1563909 : DFS_follow_tree_edge (DECL_NAME (expr));
1187 1564522 : if (TREE_CODE (expr) != TRANSLATION_UNIT_DECL
1188 1564522 : && ! DECL_CONTEXT (expr))
1189 15913 : DFS_follow_tree_edge ((*all_translation_units)[0]);
1190 : else
1191 1548609 : DFS_follow_tree_edge (DECL_CONTEXT (expr));
1192 : }
1193 :
1194 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1195 : {
1196 1564522 : DFS_follow_tree_edge (DECL_SIZE (expr));
1197 1564522 : DFS_follow_tree_edge (DECL_SIZE_UNIT (expr));
1198 :
1199 : /* Note, DECL_INITIAL is not handled here. Since DECL_INITIAL needs
1200 : special handling in LTO, it must be handled by streamer hooks. */
1201 :
1202 1564522 : DFS_follow_tree_edge (DECL_ATTRIBUTES (expr));
1203 :
1204 : /* We use DECL_ABSTRACT_ORIGIN == error_mark_node to mark
1205 : declarations which should be eliminated by decl merging. Be sure none
1206 : leaks to this point. */
1207 1564522 : gcc_assert (DECL_ABSTRACT_ORIGIN (expr) != error_mark_node);
1208 1564522 : DFS_follow_tree_edge (DECL_ABSTRACT_ORIGIN (expr));
1209 :
1210 1564522 : if ((VAR_P (expr)
1211 1564522 : || TREE_CODE (expr) == PARM_DECL)
1212 1564522 : && DECL_HAS_VALUE_EXPR_P (expr))
1213 6633 : DFS_follow_tree_edge (DECL_VALUE_EXPR (expr));
1214 1564522 : if (VAR_P (expr)
1215 1564522 : && DECL_HAS_DEBUG_EXPR_P (expr))
1216 1713 : DFS_follow_tree_edge (DECL_DEBUG_EXPR (expr));
1217 : }
1218 :
1219 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1220 : {
1221 : /* Make sure we don't inadvertently set the assembler name. */
1222 940229 : if (DECL_ASSEMBLER_NAME_SET_P (expr))
1223 757295 : DFS_follow_tree_edge (DECL_ASSEMBLER_NAME (expr));
1224 : }
1225 :
1226 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
1227 : {
1228 115765 : DFS_follow_tree_edge (DECL_FIELD_OFFSET (expr));
1229 115765 : DFS_follow_tree_edge (DECL_BIT_FIELD_TYPE (expr));
1230 115765 : DFS_follow_tree_edge (DECL_BIT_FIELD_REPRESENTATIVE (expr));
1231 115765 : DFS_follow_tree_edge (DECL_FIELD_BIT_OFFSET (expr));
1232 115765 : gcc_checking_assert (!DECL_FCONTEXT (expr));
1233 : }
1234 :
1235 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1236 : {
1237 440475 : gcc_checking_assert (DECL_VINDEX (expr) == NULL);
1238 440475 : DFS_follow_tree_edge (DECL_FUNCTION_PERSONALITY (expr));
1239 440475 : DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_TARGET (expr));
1240 440475 : DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr));
1241 : }
1242 :
1243 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1244 : {
1245 675471 : DFS_follow_tree_edge (TYPE_SIZE (expr));
1246 675471 : DFS_follow_tree_edge (TYPE_SIZE_UNIT (expr));
1247 675471 : DFS_follow_tree_edge (TYPE_ATTRIBUTES (expr));
1248 675471 : DFS_follow_tree_edge (TYPE_NAME (expr));
1249 : /* Do not follow TYPE_POINTER_TO or TYPE_REFERENCE_TO. They will be
1250 : reconstructed during fixup. */
1251 : /* Do not follow TYPE_NEXT_VARIANT, we reconstruct the variant lists
1252 : during fixup. */
1253 675471 : DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr));
1254 675471 : DFS_follow_tree_edge (TYPE_CONTEXT (expr));
1255 : /* TYPE_CANONICAL is re-computed during type merging, so no need
1256 : to follow it here. */
1257 : /* Do not stream TYPE_STUB_DECL; it is not needed by LTO but currently
1258 : it cannot be freed by free_lang_data without triggering ICEs in
1259 : langhooks. */
1260 : }
1261 :
1262 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1263 : {
1264 675471 : if (TREE_CODE (expr) == ARRAY_TYPE)
1265 47718 : DFS_follow_tree_edge (TYPE_DOMAIN (expr));
1266 627753 : else if (RECORD_OR_UNION_TYPE_P (expr))
1267 250131 : for (tree t = TYPE_FIELDS (expr); t; t = TREE_CHAIN (t))
1268 153422 : DFS_follow_tree_edge (t);
1269 531044 : else if (FUNC_OR_METHOD_TYPE_P (expr))
1270 179811 : DFS_follow_tree_edge (TYPE_ARG_TYPES (expr));
1271 :
1272 675471 : if (!POINTER_TYPE_P (expr))
1273 409243 : DFS_follow_tree_edge (TYPE_MIN_VALUE_RAW (expr));
1274 675471 : DFS_follow_tree_edge (TYPE_MAX_VALUE_RAW (expr));
1275 : }
1276 :
1277 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1278 : {
1279 696735 : DFS_follow_tree_edge (TREE_PURPOSE (expr));
1280 696735 : DFS_follow_tree_edge (TREE_VALUE (expr));
1281 696735 : DFS_follow_tree_edge (TREE_CHAIN (expr));
1282 : }
1283 :
1284 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1285 : {
1286 10 : for (int i = 0; i < TREE_VEC_LENGTH (expr); i++)
1287 8 : DFS_follow_tree_edge (TREE_VEC_ELT (expr, i));
1288 : }
1289 :
1290 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_EXP))
1291 : {
1292 4415285 : for (int i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
1293 2617994 : DFS_follow_tree_edge (TREE_OPERAND (expr, i));
1294 1797291 : DFS_follow_tree_edge (TREE_BLOCK (expr));
1295 : }
1296 :
1297 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1298 : {
1299 506812 : for (tree t = BLOCK_VARS (expr); t; t = TREE_CHAIN (t))
1300 : {
1301 : /* We would have to stream externals in the block chain as
1302 : non-references but we should have dropped them in
1303 : free-lang-data. */
1304 149233 : gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
1305 149233 : DFS_follow_tree_edge (t);
1306 : }
1307 :
1308 357579 : DFS_follow_tree_edge (BLOCK_SUPERCONTEXT (expr));
1309 357579 : DFS_follow_tree_edge (BLOCK_ABSTRACT_ORIGIN (expr));
1310 :
1311 : /* Do not follow BLOCK_NONLOCALIZED_VARS. We cannot handle debug
1312 : information for early inlined BLOCKs so drop it on the floor instead
1313 : of ICEing in dwarf2out.cc. */
1314 :
1315 : /* BLOCK_FRAGMENT_ORIGIN and BLOCK_FRAGMENT_CHAIN is not live at LTO
1316 : streaming time. */
1317 :
1318 : /* Do not output BLOCK_SUBBLOCKS. Instead on streaming-in this
1319 : list is re-constructed from BLOCK_SUPERCONTEXT. */
1320 : }
1321 :
1322 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1323 : {
1324 : unsigned i;
1325 : tree t;
1326 :
1327 : /* Note that the number of BINFO slots has already been emitted in
1328 : EXPR's header (see streamer_write_tree_header) because this length
1329 : is needed to build the empty BINFO node on the reader side. */
1330 20429 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr), i, t)
1331 10842 : DFS_follow_tree_edge (t);
1332 9587 : DFS_follow_tree_edge (BINFO_OFFSET (expr));
1333 9587 : DFS_follow_tree_edge (BINFO_VTABLE (expr));
1334 :
1335 : /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX,
1336 : BINFO_BASE_ACCESSES and BINFO_VPTR_INDEX; these are used
1337 : by C++ FE only. */
1338 : }
1339 :
1340 7232015 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1341 : {
1342 : unsigned i;
1343 : tree index, value;
1344 :
1345 773424 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr), i, index, value)
1346 : {
1347 534520 : DFS_follow_tree_edge (index);
1348 534520 : DFS_follow_tree_edge (value);
1349 : }
1350 : }
1351 :
1352 7232015 : if (code == RAW_DATA_CST)
1353 21 : DFS_follow_tree_edge (RAW_DATA_OWNER (expr));
1354 :
1355 7232015 : if (code == OMP_CLAUSE)
1356 : {
1357 : int i;
1358 635 : for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (expr)]; i++)
1359 406 : DFS_follow_tree_edge (OMP_CLAUSE_OPERAND (expr, i));
1360 229 : DFS_follow_tree_edge (OMP_CLAUSE_CHAIN (expr));
1361 : }
1362 :
1363 : #undef DFS_follow_tree_edge
1364 7232015 : }
1365 :
1366 : /* Return a hash value for the tree T.
1367 : CACHE holds hash values of trees outside current SCC. MAP, if non-NULL,
1368 : may hold hash values if trees inside current SCC. */
1369 :
1370 : static hashval_t
1371 2844340 : hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, tree t)
1372 : {
1373 2844340 : inchash::hash hstate;
1374 :
1375 : #define visit(SIBLING) \
1376 : do { \
1377 : unsigned ix; \
1378 : if (!SIBLING) \
1379 : hstate.add_int (0); \
1380 : else if (streamer_tree_cache_lookup (cache, SIBLING, &ix)) \
1381 : hstate.add_int (streamer_tree_cache_get_hash (cache, ix)); \
1382 : else if (map) \
1383 : hstate.add_int (*map->get (SIBLING)); \
1384 : else \
1385 : hstate.add_int (1); \
1386 : } while (0)
1387 :
1388 : /* Hash TS_BASE. */
1389 2844340 : enum tree_code code = TREE_CODE (t);
1390 2844340 : hstate.add_int (code);
1391 2844340 : if (!TYPE_P (t))
1392 : {
1393 2375404 : hstate.add_flag (TREE_SIDE_EFFECTS (t));
1394 2375404 : hstate.add_flag (TREE_CONSTANT (t));
1395 2375404 : hstate.add_flag (TREE_READONLY (t));
1396 2375404 : hstate.add_flag (TREE_PUBLIC (t));
1397 : }
1398 2844340 : hstate.add_flag (TREE_ADDRESSABLE (t));
1399 2844340 : hstate.add_flag (TREE_THIS_VOLATILE (t));
1400 2844340 : if (DECL_P (t))
1401 689721 : hstate.add_flag (DECL_UNSIGNED (t));
1402 2154619 : else if (TYPE_P (t))
1403 468936 : hstate.add_flag (TYPE_UNSIGNED (t));
1404 2844340 : if (TYPE_P (t))
1405 468936 : hstate.add_flag (TYPE_ARTIFICIAL (t));
1406 : else
1407 2375404 : hstate.add_flag (TREE_NO_WARNING (t));
1408 2844340 : hstate.add_flag (TREE_NOTHROW (t));
1409 2844340 : hstate.add_flag (TREE_STATIC (t));
1410 2844340 : hstate.add_flag (TREE_PROTECTED (t));
1411 2844340 : hstate.add_flag (TREE_DEPRECATED (t));
1412 2844340 : if (code != TREE_BINFO)
1413 2837996 : hstate.add_flag (TREE_PRIVATE (t));
1414 2844340 : if (TYPE_P (t))
1415 : {
1416 468936 : hstate.add_flag (AGGREGATE_TYPE_P (t)
1417 468936 : ? TYPE_REVERSE_STORAGE_ORDER (t) : TYPE_SATURATING (t));
1418 468936 : hstate.add_flag (TYPE_ADDR_SPACE (t));
1419 : }
1420 2375404 : else if (code == SSA_NAME)
1421 0 : hstate.add_flag (SSA_NAME_IS_DEFAULT_DEF (t));
1422 2844340 : hstate.commit_flag ();
1423 :
1424 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
1425 191953 : hstate.add_wide_int (wi::to_widest (t));
1426 :
1427 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
1428 : {
1429 1714 : REAL_VALUE_TYPE r = TREE_REAL_CST (t);
1430 1714 : hstate.add_flag (r.cl);
1431 1714 : hstate.add_flag (r.sign);
1432 1714 : hstate.add_flag (r.signalling);
1433 1714 : hstate.add_flag (r.canonical);
1434 1714 : hstate.commit_flag ();
1435 1714 : hstate.add_int (r.uexp);
1436 1714 : hstate.add (r.sig, sizeof (r.sig));
1437 : }
1438 :
1439 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
1440 : {
1441 0 : FIXED_VALUE_TYPE f = TREE_FIXED_CST (t);
1442 0 : hstate.add_int (f.mode);
1443 0 : hstate.add_int (f.data.low);
1444 0 : hstate.add_int (f.data.high);
1445 : }
1446 :
1447 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1448 : {
1449 : /* Similar to TYPE_MODE, avoid streaming out host-specific DECL_MODE
1450 : for aggregate type with offloading enabled, and while streaming-in
1451 : recompute appropriate DECL_MODE for accelerator. */
1452 689721 : if (lto_stream_offload_p
1453 0 : && (VAR_P (t)
1454 0 : || TREE_CODE (t) == PARM_DECL
1455 0 : || TREE_CODE (t) == FIELD_DECL)
1456 689721 : && AGGREGATE_TYPE_P (TREE_TYPE (t)))
1457 0 : hstate.add_hwi (VOIDmode);
1458 : else
1459 689721 : hstate.add_hwi (DECL_MODE (t));
1460 689721 : hstate.add_flag (DECL_NONLOCAL (t));
1461 689721 : hstate.add_flag (DECL_VIRTUAL_P (t));
1462 689721 : hstate.add_flag (DECL_IGNORED_P (t));
1463 689721 : hstate.add_flag (DECL_ABSTRACT_P (t));
1464 689721 : hstate.add_flag (DECL_ARTIFICIAL (t));
1465 689721 : hstate.add_flag (DECL_USER_ALIGN (t));
1466 689721 : hstate.add_flag (DECL_PRESERVE_P (t));
1467 689721 : hstate.add_flag (DECL_EXTERNAL (t));
1468 689721 : hstate.add_flag (DECL_NOT_GIMPLE_REG_P (t));
1469 689721 : hstate.commit_flag ();
1470 689721 : hstate.add_int (DECL_ALIGN (t));
1471 689721 : if (code == LABEL_DECL)
1472 : {
1473 0 : hstate.add_int (EH_LANDING_PAD_NR (t));
1474 0 : hstate.add_int (LABEL_DECL_UID (t));
1475 : }
1476 689721 : else if (code == FIELD_DECL)
1477 : {
1478 83029 : hstate.add_flag (DECL_PACKED (t));
1479 83029 : hstate.add_flag (DECL_NONADDRESSABLE_P (t));
1480 83029 : hstate.add_flag (DECL_PADDING_P (t));
1481 83029 : if (DECL_BIT_FIELD (t))
1482 5072 : hstate.add_flag (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (t));
1483 : else
1484 159773 : hstate.add_flag (DECL_FIELD_ABI_IGNORED (t));
1485 83029 : hstate.add_int (DECL_OFFSET_ALIGN (t));
1486 : }
1487 606692 : else if (code == VAR_DECL)
1488 : {
1489 235992 : hstate.add_flag (DECL_HAS_DEBUG_EXPR_P (t));
1490 235992 : hstate.add_flag (DECL_NONLOCAL_FRAME (t));
1491 : }
1492 689721 : if (code == RESULT_DECL
1493 689721 : || code == PARM_DECL
1494 : || code == VAR_DECL)
1495 : {
1496 236004 : hstate.add_flag (DECL_BY_REFERENCE (t));
1497 236004 : if (code == VAR_DECL
1498 236004 : || code == PARM_DECL)
1499 236004 : hstate.add_flag (DECL_HAS_VALUE_EXPR_P (t));
1500 : }
1501 689721 : hstate.commit_flag ();
1502 : }
1503 :
1504 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1505 606688 : hstate.add_int (DECL_REGISTER (t));
1506 :
1507 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1508 : {
1509 606676 : hstate.add_flag (DECL_COMMON (t));
1510 606676 : hstate.add_flag (DECL_DLLIMPORT_P (t));
1511 606676 : hstate.add_flag (DECL_WEAK (t));
1512 606676 : hstate.add_flag (DECL_SEEN_IN_BIND_EXPR_P (t));
1513 606676 : hstate.add_flag (DECL_COMDAT (t));
1514 606676 : hstate.add_flag (DECL_VISIBILITY_SPECIFIED (t));
1515 606676 : hstate.add_int (DECL_VISIBILITY (t));
1516 606676 : if (code == VAR_DECL)
1517 : {
1518 : /* DECL_IN_TEXT_SECTION is set during final asm output only. */
1519 235992 : hstate.add_flag (DECL_HARD_REGISTER (t));
1520 235992 : hstate.add_flag (DECL_IN_CONSTANT_POOL (t));
1521 : }
1522 606676 : if (TREE_CODE (t) == FUNCTION_DECL)
1523 : {
1524 347578 : hstate.add_flag (DECL_FINAL_P (t));
1525 347578 : hstate.add_flag (DECL_CXX_CONSTRUCTOR_P (t));
1526 347578 : hstate.add_flag (DECL_CXX_DESTRUCTOR_P (t));
1527 : }
1528 606676 : hstate.commit_flag ();
1529 : }
1530 :
1531 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1532 : {
1533 347578 : hstate.add_int (DECL_BUILT_IN_CLASS (t));
1534 347578 : hstate.add_flag (DECL_STATIC_CONSTRUCTOR (t));
1535 347578 : hstate.add_flag (DECL_STATIC_DESTRUCTOR (t));
1536 347578 : hstate.add_int ((unsigned)FUNCTION_DECL_DECL_TYPE (t));
1537 347578 : hstate.add_flag (DECL_UNINLINABLE (t));
1538 347578 : hstate.add_flag (DECL_POSSIBLY_INLINED (t));
1539 347578 : hstate.add_flag (DECL_IS_NOVOPS (t));
1540 347578 : hstate.add_flag (DECL_IS_RETURNS_TWICE (t));
1541 347578 : hstate.add_flag (DECL_IS_MALLOC (t));
1542 347578 : hstate.add_flag (DECL_DECLARED_INLINE_P (t));
1543 347578 : hstate.add_flag (DECL_STATIC_CHAIN (t));
1544 347578 : hstate.add_flag (DECL_NO_INLINE_WARNING_P (t));
1545 347578 : hstate.add_flag (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (t));
1546 347578 : hstate.add_flag (DECL_NO_LIMIT_STACK (t));
1547 347578 : hstate.add_flag (DECL_DISREGARD_INLINE_LIMITS (t));
1548 347578 : hstate.add_flag (DECL_PURE_P (t));
1549 347578 : hstate.add_flag (DECL_LOOPING_CONST_OR_PURE_P (t));
1550 347578 : hstate.commit_flag ();
1551 347578 : if (DECL_BUILT_IN_CLASS (t) != NOT_BUILT_IN)
1552 22792 : hstate.add_int (DECL_UNCHECKED_FUNCTION_CODE (t));
1553 : }
1554 :
1555 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1556 : {
1557 : /* For offloading, avoid streaming out TYPE_MODE for aggregate type since
1558 : it may be host-specific. For eg, aarch64 uses OImode for ARRAY_TYPE
1559 : whose size is 256-bits, which is not representable on accelerator.
1560 : Instead stream out VOIDmode, and while streaming-in, recompute
1561 : appropriate TYPE_MODE for accelerator. */
1562 468936 : if (lto_stream_offload_p
1563 0 : && (AGGREGATE_TYPE_P (t) || VECTOR_TYPE_P (t)))
1564 0 : hstate.add_hwi (VOIDmode);
1565 : /* for VECTOR_TYPE, TYPE_MODE reevaluates the mode using target_flags
1566 : not necessary valid in a global context.
1567 : Use the raw value previously set by layout_type. */
1568 : else
1569 468936 : hstate.add_hwi (TYPE_MODE_RAW (t));
1570 : /* TYPE_NO_FORCE_BLK is private to stor-layout and need
1571 : no streaming. */
1572 468936 : hstate.add_flag (TYPE_PACKED (t));
1573 468936 : hstate.add_flag (TYPE_RESTRICT (t));
1574 468936 : hstate.add_flag (TYPE_USER_ALIGN (t));
1575 468936 : hstate.add_flag (TYPE_READONLY (t));
1576 468936 : if (RECORD_OR_UNION_TYPE_P (t))
1577 : {
1578 72886 : hstate.add_flag (TYPE_TRANSPARENT_AGGR (t));
1579 72886 : hstate.add_flag (TYPE_FINAL_P (t));
1580 72886 : hstate.add_flag (TYPE_CXX_ODR_P (t));
1581 : }
1582 396050 : else if (code == ARRAY_TYPE)
1583 30082 : hstate.add_flag (TYPE_NONALIASED_COMPONENT (t));
1584 468936 : if (code == ARRAY_TYPE || code == INTEGER_TYPE)
1585 76213 : hstate.add_flag (TYPE_STRING_FLAG (t));
1586 468936 : if (AGGREGATE_TYPE_P (t))
1587 102968 : hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
1588 468936 : hstate.commit_flag ();
1589 468936 : hstate.add_int (TYPE_PRECISION_RAW (t));
1590 468936 : hstate.add_int (TYPE_ALIGN (t));
1591 468936 : if (!lto_stream_offload_p)
1592 468936 : hstate.add_int (TYPE_EMPTY_P (t));
1593 : }
1594 :
1595 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
1596 0 : hstate.add (TRANSLATION_UNIT_LANGUAGE (t),
1597 0 : strlen (TRANSLATION_UNIT_LANGUAGE (t)));
1598 :
1599 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION)
1600 : /* We don't stream these when passing things to a different target. */
1601 23433 : && !lto_stream_offload_p)
1602 23433 : hstate.add_hwi (cl_target_option_hash (TREE_TARGET_OPTION (t)));
1603 :
1604 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
1605 23649 : hstate.add_hwi (cl_optimization_hash (TREE_OPTIMIZATION (t)));
1606 :
1607 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1608 891095 : hstate.merge_hash (IDENTIFIER_HASH_VALUE (t));
1609 :
1610 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1611 4420 : hstate.add (TREE_STRING_POINTER (t), TREE_STRING_LENGTH (t));
1612 :
1613 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
1614 : {
1615 2797258 : if (code != IDENTIFIER_NODE)
1616 1906163 : visit (TREE_TYPE (t));
1617 : }
1618 :
1619 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
1620 : {
1621 0 : unsigned int count = vector_cst_encoded_nelts (t);
1622 0 : for (unsigned int i = 0; i < count; ++i)
1623 0 : visit (VECTOR_CST_ENCODED_ELT (t, i));
1624 : }
1625 :
1626 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_POLY_INT_CST))
1627 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1628 0 : visit (POLY_INT_CST_COEFF (t, i));
1629 :
1630 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
1631 : {
1632 0 : visit (TREE_REALPART (t));
1633 0 : visit (TREE_IMAGPART (t));
1634 : }
1635 :
1636 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
1637 : {
1638 : /* Drop names that were created for anonymous entities. */
1639 689721 : if (DECL_NAME (t)
1640 672243 : && TREE_CODE (DECL_NAME (t)) == IDENTIFIER_NODE
1641 1361964 : && IDENTIFIER_ANON_P (DECL_NAME (t)))
1642 : ;
1643 : else
1644 689364 : visit (DECL_NAME (t));
1645 689721 : if (DECL_FILE_SCOPE_P (t))
1646 : ;
1647 : else
1648 113559 : visit (DECL_CONTEXT (t));
1649 : }
1650 :
1651 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1652 : {
1653 689721 : visit (DECL_SIZE (t));
1654 689721 : visit (DECL_SIZE_UNIT (t));
1655 689721 : visit (DECL_ATTRIBUTES (t));
1656 689721 : if ((code == VAR_DECL
1657 689721 : || code == PARM_DECL)
1658 689721 : && DECL_HAS_VALUE_EXPR_P (t))
1659 20 : visit (DECL_VALUE_EXPR (t));
1660 689721 : if (code == VAR_DECL
1661 925713 : && DECL_HAS_DEBUG_EXPR_P (t))
1662 0 : visit (DECL_DEBUG_EXPR (t));
1663 : /* ??? Hash DECL_INITIAL as streamed. Needs the output-block to
1664 : be able to call get_symbol_initial_value. */
1665 : }
1666 :
1667 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1668 : {
1669 606676 : if (DECL_ASSEMBLER_NAME_SET_P (t))
1670 604197 : visit (DECL_ASSEMBLER_NAME (t));
1671 : }
1672 :
1673 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
1674 : {
1675 83029 : visit (DECL_FIELD_OFFSET (t));
1676 83029 : visit (DECL_BIT_FIELD_TYPE (t));
1677 83029 : visit (DECL_BIT_FIELD_REPRESENTATIVE (t));
1678 83029 : visit (DECL_FIELD_BIT_OFFSET (t));
1679 : }
1680 :
1681 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1682 : {
1683 347578 : visit (DECL_FUNCTION_PERSONALITY (t));
1684 347578 : visit (DECL_FUNCTION_SPECIFIC_TARGET (t));
1685 347578 : visit (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t));
1686 : }
1687 :
1688 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1689 : {
1690 468936 : visit (TYPE_SIZE (t));
1691 468936 : visit (TYPE_SIZE_UNIT (t));
1692 468936 : visit (TYPE_ATTRIBUTES (t));
1693 468936 : visit (TYPE_NAME (t));
1694 468936 : visit (TYPE_MAIN_VARIANT (t));
1695 468936 : if (TYPE_FILE_SCOPE_P (t))
1696 : ;
1697 : else
1698 16382 : visit (TYPE_CONTEXT (t));
1699 : }
1700 :
1701 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1702 : {
1703 468936 : if (code == ARRAY_TYPE)
1704 30082 : visit (TYPE_DOMAIN (t));
1705 438854 : else if (RECORD_OR_UNION_TYPE_P (t))
1706 179947 : for (tree f = TYPE_FIELDS (t); f; f = TREE_CHAIN (f))
1707 107061 : visit (f);
1708 365968 : else if (code == FUNCTION_TYPE
1709 365968 : || code == METHOD_TYPE)
1710 117034 : visit (TYPE_ARG_TYPES (t));
1711 468936 : if (!POINTER_TYPE_P (t))
1712 276735 : visit (TYPE_MIN_VALUE_RAW (t));
1713 468936 : visit (TYPE_MAX_VALUE_RAW (t));
1714 : }
1715 :
1716 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1717 : {
1718 534940 : visit (TREE_PURPOSE (t));
1719 534940 : visit (TREE_VALUE (t));
1720 534940 : visit (TREE_CHAIN (t));
1721 : }
1722 :
1723 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1724 0 : for (int i = 0; i < TREE_VEC_LENGTH (t); ++i)
1725 0 : visit (TREE_VEC_ELT (t, i));
1726 :
1727 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_EXP))
1728 : {
1729 7577 : hstate.add_hwi (TREE_OPERAND_LENGTH (t));
1730 18988 : for (int i = 0; i < TREE_OPERAND_LENGTH (t); ++i)
1731 11411 : visit (TREE_OPERAND (t, i));
1732 : }
1733 :
1734 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1735 : {
1736 : unsigned i;
1737 : tree b;
1738 12757 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t), i, b)
1739 6413 : visit (b);
1740 6344 : visit (BINFO_OFFSET (t));
1741 6344 : visit (BINFO_VTABLE (t));
1742 : /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
1743 : BINFO_BASE_ACCESSES and BINFO_VPTR_INDEX; these are used
1744 : by C++ FE only. */
1745 : }
1746 :
1747 2844340 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1748 : {
1749 404 : unsigned i;
1750 404 : tree index, value;
1751 622 : hstate.add_hwi (CONSTRUCTOR_NELTS (t));
1752 1761 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, index, value)
1753 : {
1754 1357 : visit (index);
1755 1357 : visit (value);
1756 : }
1757 : }
1758 :
1759 2844340 : if (code == OMP_CLAUSE)
1760 : {
1761 148 : int i;
1762 148 : HOST_WIDE_INT val;
1763 :
1764 148 : hstate.add_hwi (OMP_CLAUSE_CODE (t));
1765 148 : switch (OMP_CLAUSE_CODE (t))
1766 : {
1767 0 : case OMP_CLAUSE_DEFAULT:
1768 0 : val = OMP_CLAUSE_DEFAULT_KIND (t);
1769 0 : break;
1770 0 : case OMP_CLAUSE_SCHEDULE:
1771 0 : val = OMP_CLAUSE_SCHEDULE_KIND (t);
1772 0 : break;
1773 0 : case OMP_CLAUSE_DEPEND:
1774 0 : val = OMP_CLAUSE_DEPEND_KIND (t);
1775 0 : break;
1776 0 : case OMP_CLAUSE_DOACROSS:
1777 0 : val = OMP_CLAUSE_DOACROSS_KIND (t);
1778 0 : break;
1779 0 : case OMP_CLAUSE_MAP:
1780 0 : val = OMP_CLAUSE_MAP_KIND (t);
1781 0 : break;
1782 0 : case OMP_CLAUSE_PROC_BIND:
1783 0 : val = OMP_CLAUSE_PROC_BIND_KIND (t);
1784 0 : break;
1785 0 : case OMP_CLAUSE_REDUCTION:
1786 0 : case OMP_CLAUSE_TASK_REDUCTION:
1787 0 : case OMP_CLAUSE_IN_REDUCTION:
1788 0 : val = OMP_CLAUSE_REDUCTION_CODE (t);
1789 0 : break;
1790 : default:
1791 : val = 0;
1792 : break;
1793 : }
1794 148 : hstate.add_hwi (val);
1795 400 : for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (t)]; i++)
1796 252 : visit (OMP_CLAUSE_OPERAND (t, i));
1797 148 : visit (OMP_CLAUSE_CHAIN (t));
1798 : }
1799 :
1800 2844340 : return hstate.end ();
1801 :
1802 : #undef visit
1803 : }
1804 :
1805 : /* Compare two SCC entries by their hash value for qsorting them. */
1806 :
1807 : int
1808 1585118 : DFS::scc_entry_compare (const void *p1_, const void *p2_)
1809 : {
1810 1585118 : const scc_entry *p1 = (const scc_entry *) p1_;
1811 1585118 : const scc_entry *p2 = (const scc_entry *) p2_;
1812 1585118 : if (p1->hash < p2->hash)
1813 : return -1;
1814 714273 : else if (p1->hash > p2->hash)
1815 692837 : return 1;
1816 : return 0;
1817 : }
1818 :
1819 : /* Return a hash value for the SCC on the SCC stack from FIRST with SIZE.
1820 : THIS_REF_P and REF_P are as passed to lto_output_tree for FIRST. */
1821 :
1822 : hashval_t
1823 2695098 : DFS::hash_scc (struct output_block *ob, unsigned first, unsigned size,
1824 : bool ref_p, bool this_ref_p)
1825 : {
1826 2695098 : unsigned int last_classes = 0, iterations = 0;
1827 :
1828 : /* Compute hash values for the SCC members. */
1829 5539438 : for (unsigned i = 0; i < size; ++i)
1830 2844340 : sccstack[first+i].hash
1831 5688680 : = hash_tree (ob->writer_cache, NULL, sccstack[first+i].t);
1832 :
1833 2695098 : if (size == 1)
1834 2626988 : return sccstack[first].hash;
1835 :
1836 : /* We aim to get unique hash for every tree within SCC and compute hash value
1837 : of the whole SCC by combining all values together in a stable (entry-point
1838 : independent) order. This guarantees that the same SCC regions within
1839 : different translation units will get the same hash values and therefore
1840 : will be merged at WPA time.
1841 :
1842 : Often the hashes are already unique. In that case we compute the SCC hash
1843 : by combining individual hash values in an increasing order.
1844 :
1845 : If there are duplicates, we seek at least one tree with unique hash (and
1846 : pick one with minimal hash and this property). Then we obtain a stable
1847 : order by DFS walk starting from this unique tree and then use the index
1848 : within this order to make individual hash values unique.
1849 :
1850 : If there is no tree with unique hash, we iteratively propagate the hash
1851 : values across the internal edges of SCC. This usually quickly leads
1852 : to unique hashes. Consider, for example, an SCC containing two pointers
1853 : that are identical except for the types they point to and assume that
1854 : these types are also part of the SCC. The propagation will add the
1855 : points-to type information into their hash values. */
1856 68110 : do
1857 : {
1858 : /* Sort the SCC so we can easily check for uniqueness. */
1859 68110 : qsort (&sccstack[first], size, sizeof (scc_entry), scc_entry_compare);
1860 :
1861 68110 : unsigned int classes = 1;
1862 68110 : int firstunique = -1;
1863 :
1864 : /* Find the tree with lowest unique hash (if it exists) and compute
1865 : the number of equivalence classes. */
1866 68110 : if (sccstack[first].hash != sccstack[first+1].hash)
1867 68107 : firstunique = 0;
1868 217352 : for (unsigned i = 1; i < size; ++i)
1869 149242 : if (sccstack[first+i-1].hash != sccstack[first+i].hash)
1870 : {
1871 147275 : classes++;
1872 147275 : if (firstunique == -1
1873 147275 : && (i == size - 1
1874 3 : || sccstack[first+i+1].hash != sccstack[first+i].hash))
1875 3 : firstunique = i;
1876 : }
1877 :
1878 : /* If we found a tree with unique hash, stop the iteration. */
1879 68110 : if (firstunique != -1
1880 : /* Also terminate if we run out of iterations or if the number of
1881 : equivalence classes is no longer increasing.
1882 : For example a cyclic list of trees that are all equivalent will
1883 : never have unique entry point; we however do not build such SCCs
1884 : in our IL. */
1885 68110 : || classes <= last_classes || iterations > 16)
1886 : {
1887 68110 : hashval_t scc_hash;
1888 :
1889 : /* If some hashes are not unique (CLASSES != SIZE), use the DFS walk
1890 : starting from FIRSTUNIQUE to obtain a stable order. */
1891 68110 : if (classes != size && firstunique != -1)
1892 : {
1893 347 : hash_map <tree, hashval_t> map(size*2);
1894 :
1895 : /* Store hash values into a map, so we can associate them with
1896 : the reordered SCC. */
1897 11644 : for (unsigned i = 0; i < size; ++i)
1898 10950 : map.put (sccstack[first+i].t, sccstack[first+i].hash);
1899 :
1900 347 : DFS again (ob, sccstack[first+firstunique].t, ref_p, this_ref_p,
1901 347 : true);
1902 694 : gcc_assert (again.sccstack.length () == size);
1903 :
1904 347 : memcpy (sccstack.address () + first,
1905 347 : again.sccstack.address (),
1906 : sizeof (scc_entry) * size);
1907 :
1908 : /* Update hash values of individual members by hashing in the
1909 : index within the stable order. This ensures uniqueness.
1910 : Also compute the SCC hash by mixing in all hash values in
1911 : the stable order we obtained. */
1912 347 : sccstack[first].hash = *map.get (sccstack[first].t);
1913 347 : scc_hash = sccstack[first].hash;
1914 10950 : for (unsigned i = 1; i < size; ++i)
1915 : {
1916 31809 : sccstack[first+i].hash
1917 10603 : = iterative_hash_hashval_t (i,
1918 10603 : *map.get (sccstack[first+i].t));
1919 10603 : scc_hash
1920 10603 : = iterative_hash_hashval_t (scc_hash,
1921 10603 : sccstack[first+i].hash);
1922 : }
1923 347 : }
1924 : /* If we got a unique hash value for each tree, then sort already
1925 : ensured entry-point independent order. Only compute the final
1926 : SCC hash.
1927 :
1928 : If we failed to find the unique entry point, we go by the same
1929 : route. We will eventually introduce unwanted hash conflicts. */
1930 : else
1931 : {
1932 : scc_hash = sccstack[first].hash;
1933 206402 : for (unsigned i = 1; i < size; ++i)
1934 138639 : scc_hash
1935 138639 : = iterative_hash_hashval_t (scc_hash, sccstack[first+i].hash);
1936 :
1937 : /* We cannot 100% guarantee that the hash won't conflict so as
1938 : to make it impossible to find a unique hash. This however
1939 : should be an extremely rare case. ICE for now so possible
1940 : issues are found and evaluated. */
1941 67763 : gcc_checking_assert (classes == size);
1942 : }
1943 :
1944 : /* To avoid conflicts across SCCs, iteratively hash the whole SCC
1945 : hash into the hash of each element. */
1946 285462 : for (unsigned i = 0; i < size; ++i)
1947 434704 : sccstack[first+i].hash
1948 217352 : = iterative_hash_hashval_t (sccstack[first+i].hash, scc_hash);
1949 68110 : return scc_hash;
1950 : }
1951 :
1952 0 : last_classes = classes;
1953 0 : iterations++;
1954 :
1955 : /* We failed to identify the entry point; propagate hash values across
1956 : the edges. */
1957 0 : hash_map <tree, hashval_t> map(size*2);
1958 :
1959 0 : for (unsigned i = 0; i < size; ++i)
1960 0 : map.put (sccstack[first+i].t, sccstack[first+i].hash);
1961 :
1962 0 : for (unsigned i = 0; i < size; i++)
1963 0 : sccstack[first+i].hash
1964 0 : = hash_tree (ob->writer_cache, &map, sccstack[first+i].t);
1965 0 : }
1966 : while (true);
1967 : }
1968 :
1969 : /* DFS walk EXPR and stream SCCs of tree bodies if they are not
1970 : already in the streamer cache. Main routine called for
1971 : each visit of EXPR. */
1972 :
1973 : void
1974 36574211 : DFS::DFS_write_tree (struct output_block *ob, sccs *from_state,
1975 : tree expr, bool ref_p, bool this_ref_p)
1976 : {
1977 : /* Handle special cases. */
1978 36574211 : if (expr == NULL_TREE)
1979 26639555 : return;
1980 :
1981 : /* Do not DFS walk into indexable trees. */
1982 23878362 : if (this_ref_p && tree_is_indexable (expr))
1983 : return;
1984 :
1985 : /* Check if we already streamed EXPR. */
1986 17418183 : if (streamer_tree_cache_lookup (ob->writer_cache, expr, NULL))
1987 : {
1988 : /* Reference to a local tree makes entry also local. We always process
1989 : top of stack entry, so set max to number of entries in stack - 1. */
1990 7483527 : if (ob->local_trees
1991 7483527 : && ob->local_trees->contains (expr))
1992 18250 : max_local_entry = sccstack.length () - 1;
1993 : return;
1994 : }
1995 :
1996 9934656 : worklist w;
1997 9934656 : w.expr = expr;
1998 9934656 : w.from_state = from_state;
1999 9934656 : w.cstate = NULL;
2000 9934656 : w.ref_p = ref_p;
2001 9934656 : w.this_ref_p = this_ref_p;
2002 9934656 : worklist_vec.safe_push (w);
2003 : }
2004 :
2005 :
2006 : /* Emit the physical representation of tree node EXPR to output block OB.
2007 : If THIS_REF_P is true, the leaves of EXPR are emitted as references via
2008 : lto_output_tree_ref. REF_P is used for streaming siblings of EXPR. */
2009 :
2010 : void
2011 12978691 : lto_output_tree (struct output_block *ob, tree expr,
2012 : bool ref_p, bool this_ref_p)
2013 : {
2014 12978691 : unsigned ix;
2015 12978691 : bool existed_p;
2016 12978691 : unsigned int size = ob->main_stream->total_size;
2017 : /* This is the first time we see EXPR, write all reachable
2018 : trees to OB. */
2019 12978691 : static bool in_dfs_walk;
2020 :
2021 12978691 : if (expr == NULL_TREE)
2022 : {
2023 2862093 : streamer_write_record_start (ob, LTO_null);
2024 10875753 : return;
2025 : }
2026 :
2027 10116598 : if (this_ref_p && tree_is_indexable (expr))
2028 : {
2029 5151567 : enum LTO_tags tag;
2030 5151567 : unsigned ix;
2031 :
2032 5151567 : lto_indexable_tree_ref (ob, expr, &tag, &ix);
2033 5151567 : streamer_write_record_start (ob, tag);
2034 5151567 : streamer_write_uhwi (ob, ix);
2035 5151567 : return;
2036 : }
2037 :
2038 4965031 : existed_p = streamer_tree_cache_lookup (ob->writer_cache, expr, &ix);
2039 4965031 : if (existed_p)
2040 : {
2041 1886543 : if (streamer_dump_file)
2042 : {
2043 96 : if (in_dfs_walk)
2044 8 : print_node_brief (streamer_dump_file, " Streaming ref to ",
2045 : expr, 4);
2046 : else
2047 88 : print_node_brief (streamer_dump_file, " Streaming ref to ",
2048 : expr, 4);
2049 96 : fprintf (streamer_dump_file, "\n");
2050 : }
2051 : /* If a node has already been streamed out, make sure that
2052 : we don't write it more than once. Otherwise, the reader
2053 : will instantiate two different nodes for the same object. */
2054 1886543 : streamer_write_record_start (ob, LTO_tree_pickle_reference);
2055 1886543 : streamer_write_uhwi (ob, ix);
2056 1886543 : lto_stats.num_pickle_refs_output++;
2057 : }
2058 : else
2059 : {
2060 : /* Protect against recursion which means disconnect between
2061 : what tree edges we walk in the DFS walk and what edges
2062 : we stream out. */
2063 3078488 : gcc_assert (!in_dfs_walk);
2064 :
2065 3078488 : if (streamer_dump_file)
2066 : {
2067 172 : print_node_brief (streamer_dump_file, " Streaming tree ",
2068 : expr, 4);
2069 172 : fprintf (streamer_dump_file, "\n");
2070 : }
2071 :
2072 : /* Start the DFS walk. */
2073 : /* Save ob state ... */
2074 : /* let's see ... */
2075 3078488 : in_dfs_walk = true;
2076 3078488 : DFS (ob, expr, ref_p, this_ref_p, false);
2077 :
2078 : /* Finally append a reference to the tree we were writing. */
2079 3078488 : existed_p = streamer_tree_cache_lookup (ob->writer_cache, expr, &ix);
2080 :
2081 : /* DFS walk above possibly skipped streaming EXPR itself to let us inline
2082 : it. */
2083 3078488 : if (!existed_p)
2084 2128830 : lto_output_tree_1 (ob, expr, 0, ref_p, this_ref_p);
2085 949658 : else if (this_ref_p)
2086 : {
2087 10 : if (streamer_dump_file)
2088 : {
2089 0 : print_node_brief (streamer_dump_file,
2090 : " Streaming final ref to ",
2091 : expr, 4);
2092 0 : fprintf (streamer_dump_file, "\n");
2093 : }
2094 10 : streamer_write_record_start (ob, LTO_tree_pickle_reference);
2095 10 : streamer_write_uhwi (ob, ix);
2096 : }
2097 3078488 : in_dfs_walk = false;
2098 3078488 : lto_stats.num_pickle_refs_output++;
2099 : }
2100 4965031 : if (streamer_dump_file && !in_dfs_walk)
2101 260 : fprintf (streamer_dump_file, " %u bytes\n",
2102 260 : ob->main_stream->total_size - size);
2103 : }
2104 :
2105 :
2106 : /* Output to OB a list of try/catch handlers starting with FIRST. */
2107 :
2108 : static void
2109 312 : output_eh_try_list (struct output_block *ob, eh_catch first)
2110 : {
2111 312 : eh_catch n;
2112 :
2113 712 : for (n = first; n; n = n->next_catch)
2114 : {
2115 400 : streamer_write_record_start (ob, LTO_eh_catch);
2116 400 : stream_write_tree (ob, n->type_list, true);
2117 400 : stream_write_tree (ob, n->filter_list, true);
2118 400 : stream_write_tree (ob, n->label, true);
2119 : }
2120 :
2121 312 : streamer_write_record_start (ob, LTO_null);
2122 312 : }
2123 :
2124 :
2125 : /* Output EH region R in function FN to OB. CURR_RN is the slot index
2126 : that is being emitted in FN->EH->REGION_ARRAY. This is used to
2127 : detect EH region sharing. */
2128 :
2129 : static void
2130 18529 : output_eh_region (struct output_block *ob, eh_region r)
2131 : {
2132 18529 : enum LTO_tags tag;
2133 :
2134 18529 : if (r == NULL)
2135 : {
2136 7830 : streamer_write_record_start (ob, LTO_null);
2137 7830 : return;
2138 : }
2139 :
2140 10699 : if (r->type == ERT_CLEANUP)
2141 : tag = LTO_ert_cleanup;
2142 : else if (r->type == ERT_TRY)
2143 : tag = LTO_ert_try;
2144 : else if (r->type == ERT_ALLOWED_EXCEPTIONS)
2145 : tag = LTO_ert_allowed_exceptions;
2146 : else if (r->type == ERT_MUST_NOT_THROW)
2147 : tag = LTO_ert_must_not_throw;
2148 : else
2149 0 : gcc_unreachable ();
2150 :
2151 10699 : streamer_write_record_start (ob, tag);
2152 10699 : streamer_write_hwi (ob, r->index);
2153 :
2154 10699 : if (r->outer)
2155 3190 : streamer_write_hwi (ob, r->outer->index);
2156 : else
2157 7509 : streamer_write_zero (ob);
2158 :
2159 10699 : if (r->inner)
2160 1876 : streamer_write_hwi (ob, r->inner->index);
2161 : else
2162 8823 : streamer_write_zero (ob);
2163 :
2164 10699 : if (r->next_peer)
2165 4552 : streamer_write_hwi (ob, r->next_peer->index);
2166 : else
2167 6147 : streamer_write_zero (ob);
2168 :
2169 10699 : if (r->type == ERT_TRY)
2170 : {
2171 312 : output_eh_try_list (ob, r->u.eh_try.first_catch);
2172 : }
2173 10387 : else if (r->type == ERT_ALLOWED_EXCEPTIONS)
2174 : {
2175 324 : stream_write_tree (ob, r->u.allowed.type_list, true);
2176 324 : stream_write_tree (ob, r->u.allowed.label, true);
2177 324 : streamer_write_uhwi (ob, r->u.allowed.filter);
2178 : }
2179 10063 : else if (r->type == ERT_MUST_NOT_THROW)
2180 : {
2181 5334 : stream_write_tree (ob, r->u.must_not_throw.failure_decl, true);
2182 5334 : bitpack_d bp = bitpack_create (ob->main_stream);
2183 5334 : stream_output_location (ob, &bp, r->u.must_not_throw.failure_loc);
2184 5334 : streamer_write_bitpack (&bp);
2185 : }
2186 :
2187 10699 : if (r->landing_pads)
2188 3263 : streamer_write_hwi (ob, r->landing_pads->index);
2189 : else
2190 7436 : streamer_write_zero (ob);
2191 : }
2192 :
2193 :
2194 : /* Output landing pad LP to OB. */
2195 :
2196 : static void
2197 8500 : output_eh_lp (struct output_block *ob, eh_landing_pad lp)
2198 : {
2199 8500 : if (lp == NULL)
2200 : {
2201 5188 : streamer_write_record_start (ob, LTO_null);
2202 5188 : return;
2203 : }
2204 :
2205 3312 : streamer_write_record_start (ob, LTO_eh_landing_pad);
2206 3312 : streamer_write_hwi (ob, lp->index);
2207 3312 : if (lp->next_lp)
2208 49 : streamer_write_hwi (ob, lp->next_lp->index);
2209 : else
2210 3263 : streamer_write_zero (ob);
2211 :
2212 3312 : if (lp->region)
2213 3312 : streamer_write_hwi (ob, lp->region->index);
2214 : else
2215 0 : streamer_write_zero (ob);
2216 :
2217 3312 : stream_write_tree (ob, lp->post_landing_pad, true);
2218 : }
2219 :
2220 :
2221 : /* Output the existing eh_table to OB. */
2222 :
2223 : static void
2224 110229 : output_eh_regions (struct output_block *ob, struct function *fn)
2225 : {
2226 110229 : if (fn->eh && fn->eh->region_tree)
2227 : {
2228 4271 : unsigned i;
2229 4271 : eh_region eh;
2230 4271 : eh_landing_pad lp;
2231 4271 : tree ttype;
2232 :
2233 4271 : streamer_write_record_start (ob, LTO_eh_table);
2234 :
2235 : /* Emit the index of the root of the EH region tree. */
2236 4271 : streamer_write_hwi (ob, fn->eh->region_tree->index);
2237 :
2238 : /* Emit all the EH regions in the region array. */
2239 4271 : streamer_write_hwi (ob, vec_safe_length (fn->eh->region_array));
2240 27071 : FOR_EACH_VEC_SAFE_ELT (fn->eh->region_array, i, eh)
2241 18529 : output_eh_region (ob, eh);
2242 :
2243 : /* Emit all landing pads. */
2244 4271 : streamer_write_hwi (ob, vec_safe_length (fn->eh->lp_array));
2245 17042 : FOR_EACH_VEC_SAFE_ELT (fn->eh->lp_array, i, lp)
2246 8500 : output_eh_lp (ob, lp);
2247 :
2248 : /* Emit all the runtime type data. */
2249 4271 : streamer_write_hwi (ob, vec_safe_length (fn->eh->ttype_data));
2250 8542 : FOR_EACH_VEC_SAFE_ELT (fn->eh->ttype_data, i, ttype)
2251 0 : stream_write_tree (ob, ttype, true);
2252 :
2253 : /* Emit the table of action chains. */
2254 4271 : if (targetm.arm_eabi_unwinder)
2255 : {
2256 0 : tree t;
2257 0 : streamer_write_hwi (ob, vec_safe_length (fn->eh->ehspec_data.arm_eabi));
2258 0 : FOR_EACH_VEC_SAFE_ELT (fn->eh->ehspec_data.arm_eabi, i, t)
2259 0 : stream_write_tree (ob, t, true);
2260 : }
2261 : else
2262 : {
2263 4271 : uchar c;
2264 4271 : streamer_write_hwi (ob, vec_safe_length (fn->eh->ehspec_data.other));
2265 8542 : FOR_EACH_VEC_SAFE_ELT (fn->eh->ehspec_data.other, i, c)
2266 0 : streamer_write_char_stream (ob->main_stream, c);
2267 : }
2268 : }
2269 :
2270 : /* The LTO_null either terminates the record or indicates that there
2271 : are no eh_records at all. */
2272 110229 : streamer_write_record_start (ob, LTO_null);
2273 110229 : }
2274 :
2275 :
2276 : /* Output all of the active ssa names to the ssa_names stream. */
2277 :
2278 : static void
2279 110229 : output_ssa_names (struct output_block *ob, struct function *fn)
2280 : {
2281 110229 : unsigned int i, len;
2282 :
2283 110229 : len = vec_safe_length (SSANAMES (fn));
2284 110229 : streamer_write_uhwi (ob, len);
2285 :
2286 1893858 : for (i = 1; i < len; i++)
2287 : {
2288 1673400 : tree ptr = (*SSANAMES (fn))[i];
2289 :
2290 2307106 : if (ptr == NULL_TREE
2291 1666794 : || SSA_NAME_IN_FREE_LIST (ptr)
2292 1666794 : || virtual_operand_p (ptr)
2293 : /* Simply skip unreleased SSA names. */
2294 2716002 : || (! SSA_NAME_IS_DEFAULT_DEF (ptr)
2295 932402 : && (! SSA_NAME_DEF_STMT (ptr)
2296 932402 : || ! gimple_bb (SSA_NAME_DEF_STMT (ptr)))))
2297 633706 : continue;
2298 :
2299 1039694 : streamer_write_uhwi (ob, i);
2300 1039694 : streamer_write_char_stream (ob->main_stream,
2301 1039694 : SSA_NAME_IS_DEFAULT_DEF (ptr));
2302 1039694 : if (SSA_NAME_VAR (ptr))
2303 306669 : stream_write_tree (ob, SSA_NAME_VAR (ptr), true);
2304 : else
2305 : /* ??? This drops SSA_NAME_IDENTIFIER on the floor. */
2306 733025 : stream_write_tree (ob, TREE_TYPE (ptr), true);
2307 : }
2308 :
2309 110229 : streamer_write_zero (ob);
2310 110229 : }
2311 :
2312 :
2313 :
2314 : /* Output the cfg. */
2315 :
2316 : static void
2317 110229 : output_cfg (struct output_block *ob, struct function *fn)
2318 : {
2319 110229 : struct lto_output_stream *tmp_stream = ob->main_stream;
2320 110229 : basic_block bb;
2321 :
2322 110229 : ob->main_stream = ob->cfg_stream;
2323 :
2324 110229 : streamer_write_enum (ob->main_stream, profile_status_d, PROFILE_LAST,
2325 : profile_status_for_fn (fn));
2326 :
2327 : /* Output the number of the highest basic block. */
2328 110229 : streamer_write_uhwi (ob, last_basic_block_for_fn (fn));
2329 :
2330 1036358 : FOR_ALL_BB_FN (bb, fn)
2331 : {
2332 926129 : edge_iterator ei;
2333 926129 : edge e;
2334 :
2335 926129 : streamer_write_hwi (ob, bb->index);
2336 :
2337 : /* Output the predecessors and the edge flags. We output
2338 : predecessors instead of successors so PHI argument order
2339 : is preserved when we reconstruct the CFG greedily in
2340 : input_cfg. */
2341 1741856 : streamer_write_uhwi (ob, EDGE_COUNT (bb->preds));
2342 1976968 : FOR_EACH_EDGE (e, ei, bb->preds)
2343 : {
2344 1050839 : bitpack_d bp = bitpack_create (ob->main_stream);
2345 1050839 : bp_pack_var_len_unsigned (&bp, e->src->index);
2346 1050839 : bp_pack_var_len_unsigned (&bp, e->flags);
2347 1050839 : stream_output_location_and_block (ob, &bp, e->goto_locus);
2348 1050839 : e->probability.stream_out (ob);
2349 : }
2350 : }
2351 :
2352 110229 : streamer_write_hwi (ob, -1);
2353 :
2354 110229 : bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
2355 926129 : while (bb->next_bb)
2356 : {
2357 815900 : streamer_write_hwi (ob, bb->next_bb->index);
2358 815900 : bb = bb->next_bb;
2359 : }
2360 :
2361 110229 : streamer_write_hwi (ob, -1);
2362 :
2363 : /* Output the number of loops. */
2364 110229 : streamer_write_uhwi (ob, number_of_loops (fn));
2365 :
2366 : /* Output each loop, skipping the tree root which has number zero. */
2367 481509 : for (unsigned i = 1; i < number_of_loops (fn); ++i)
2368 : {
2369 75411 : class loop *loop = get_loop (fn, i);
2370 :
2371 : /* Write the index of the loop header. That's enough to rebuild
2372 : the loop tree on the reader side. Stream -1 for an unused
2373 : loop entry. */
2374 75411 : if (!loop)
2375 : {
2376 25272 : streamer_write_hwi (ob, -1);
2377 25272 : continue;
2378 : }
2379 : else
2380 50139 : streamer_write_hwi (ob, loop->header->index);
2381 :
2382 : /* Write everything copy_loop_info copies. */
2383 50139 : streamer_write_enum (ob->main_stream,
2384 : loop_estimation, EST_LAST, loop->estimate_state);
2385 50139 : streamer_write_hwi (ob, loop->any_upper_bound);
2386 50139 : if (loop->any_upper_bound)
2387 : {
2388 41012 : widest_int w = widest_int::from (loop->nb_iterations_upper_bound,
2389 41012 : SIGNED);
2390 41012 : streamer_write_widest_int (ob, w);
2391 41012 : }
2392 50139 : streamer_write_hwi (ob, loop->any_likely_upper_bound);
2393 50139 : if (loop->any_likely_upper_bound)
2394 : {
2395 41012 : widest_int w
2396 41012 : = widest_int::from (loop->nb_iterations_likely_upper_bound,
2397 41012 : SIGNED);
2398 41012 : streamer_write_widest_int (ob, w);
2399 41012 : }
2400 50139 : streamer_write_hwi (ob, loop->any_estimate);
2401 50139 : if (loop->any_estimate)
2402 : {
2403 33545 : widest_int w = widest_int::from (loop->nb_iterations_estimate,
2404 33545 : SIGNED);
2405 33545 : streamer_write_widest_int (ob, w);
2406 33545 : }
2407 :
2408 : /* Write OMP SIMD related info. */
2409 50139 : streamer_write_hwi (ob, loop->safelen);
2410 50139 : streamer_write_hwi (ob, loop->unroll);
2411 50139 : streamer_write_hwi (ob, loop->owned_clique);
2412 50139 : streamer_write_hwi (ob, loop->dont_vectorize);
2413 50139 : streamer_write_hwi (ob, loop->force_vectorize);
2414 50139 : streamer_write_hwi (ob, loop->finite_p);
2415 50139 : streamer_write_hwi (ob, loop->can_be_parallel);
2416 50139 : stream_write_tree (ob, loop->simduid, true);
2417 : }
2418 :
2419 110229 : ob->main_stream = tmp_stream;
2420 110229 : }
2421 :
2422 : /* Create the header in the file using OB. If the section type is for
2423 : a function, set FN to the decl for that function. */
2424 :
2425 : void
2426 260558 : produce_symbol_asm (struct output_block *ob, tree fn, int output_order)
2427 : {
2428 260558 : enum lto_section_type section_type = ob->section_type;
2429 260558 : struct lto_function_header header;
2430 260558 : char *section_name;
2431 :
2432 260558 : if (section_type == LTO_section_function_body)
2433 : {
2434 121655 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn));
2435 121655 : section_name = lto_get_section_name (section_type, name,
2436 : output_order, NULL);
2437 : }
2438 : else
2439 138903 : section_name = lto_get_section_name (section_type, NULL, 0, NULL);
2440 :
2441 260558 : lto_begin_section (section_name, !flag_wpa);
2442 260558 : free (section_name);
2443 :
2444 : /* The entire header is stream computed here. */
2445 260558 : memset (&header, 0, sizeof (struct lto_function_header));
2446 :
2447 260558 : if (section_type == LTO_section_function_body)
2448 121655 : header.cfg_size = ob->cfg_stream->total_size;
2449 260558 : header.main_size = ob->main_stream->total_size;
2450 260558 : header.string_size = ob->string_stream->total_size;
2451 260558 : lto_write_data (&header, sizeof header);
2452 :
2453 : /* Put all of the gimple and the string table out the asm file as a
2454 : block of text. */
2455 260558 : if (section_type == LTO_section_function_body)
2456 121655 : lto_write_stream (ob->cfg_stream);
2457 260558 : lto_write_stream (ob->main_stream);
2458 260558 : lto_write_stream (ob->string_stream);
2459 :
2460 260558 : lto_end_section ();
2461 260558 : }
2462 :
2463 : /* Wrapper for unused arguments. */
2464 :
2465 : void
2466 138903 : produce_asm (struct output_block *ob)
2467 : {
2468 138903 : produce_symbol_asm (ob, NULL, -1);
2469 138903 : }
2470 :
2471 :
2472 : /* Output the base body of struct function FN using output block OB. */
2473 :
2474 : static void
2475 110229 : output_struct_function_base (struct output_block *ob, struct function *fn)
2476 : {
2477 110229 : struct bitpack_d bp;
2478 110229 : unsigned i;
2479 110229 : tree t;
2480 :
2481 : /* Output the static chain and non-local goto save area. */
2482 110229 : stream_write_tree (ob, fn->static_chain_decl, true);
2483 110229 : stream_write_tree (ob, fn->nonlocal_goto_save_area, true);
2484 :
2485 : /* Output all the local variables in the function. */
2486 110229 : streamer_write_hwi (ob, vec_safe_length (fn->local_decls));
2487 390328 : FOR_EACH_VEC_SAFE_ELT (fn->local_decls, i, t)
2488 169870 : stream_write_tree (ob, t, true);
2489 :
2490 : /* Output current IL state of the function. */
2491 110229 : streamer_write_uhwi (ob, fn->curr_properties);
2492 :
2493 : /* Write all the attributes for FN. */
2494 110229 : bp = bitpack_create (ob->main_stream);
2495 110229 : bp_pack_value (&bp, fn->is_thunk, 1);
2496 110229 : bp_pack_value (&bp, fn->has_local_explicit_reg_vars, 1);
2497 110229 : bp_pack_value (&bp, fn->returns_pcc_struct, 1);
2498 110229 : bp_pack_value (&bp, fn->returns_struct, 1);
2499 110229 : bp_pack_value (&bp, fn->can_throw_non_call_exceptions, 1);
2500 110229 : bp_pack_value (&bp, fn->can_delete_dead_exceptions, 1);
2501 110229 : bp_pack_value (&bp, fn->always_inline_functions_inlined, 1);
2502 110229 : bp_pack_value (&bp, fn->after_inlining, 1);
2503 110229 : bp_pack_value (&bp, fn->stdarg, 1);
2504 110229 : bp_pack_value (&bp, fn->has_nonlocal_label, 1);
2505 110229 : bp_pack_value (&bp, fn->has_forced_label_in_static, 1);
2506 110229 : bp_pack_value (&bp, fn->calls_alloca, 1);
2507 110229 : bp_pack_value (&bp, fn->calls_setjmp, 1);
2508 110229 : bp_pack_value (&bp, fn->calls_eh_return, 1);
2509 110229 : bp_pack_value (&bp, fn->has_force_vectorize_loops, 1);
2510 110229 : bp_pack_value (&bp, fn->has_simduid_loops, 1);
2511 110229 : bp_pack_value (&bp, fn->has_musttail, 1);
2512 110229 : bp_pack_value (&bp, fn->has_unroll, 1);
2513 110229 : bp_pack_value (&bp, fn->assume_function, 1);
2514 110229 : bp_pack_value (&bp, fn->va_list_fpr_size, 8);
2515 110229 : bp_pack_value (&bp, fn->va_list_gpr_size, 8);
2516 110229 : bp_pack_value (&bp, fn->last_clique, sizeof (short) * 8);
2517 :
2518 : /* Output the function start and end loci. */
2519 110229 : stream_output_location (ob, &bp, fn->function_start_locus);
2520 110229 : stream_output_location (ob, &bp, fn->function_end_locus);
2521 :
2522 : /* Save the instance discriminator if present. */
2523 110229 : int *instance_number_p = NULL;
2524 110229 : if (decl_to_instance_map)
2525 0 : instance_number_p = decl_to_instance_map->get (fn->decl);
2526 110229 : bp_pack_value (&bp, !!instance_number_p, 1);
2527 110229 : if (instance_number_p)
2528 0 : bp_pack_value (&bp, *instance_number_p, sizeof (int) * CHAR_BIT);
2529 :
2530 110229 : streamer_write_bitpack (&bp);
2531 110229 : }
2532 :
2533 :
2534 : /* Collect all leaf BLOCKs beyond ROOT into LEAFS. */
2535 :
2536 : static void
2537 250035 : collect_block_tree_leafs (tree root, vec<tree> &leafs)
2538 : {
2539 468395 : for (root = BLOCK_SUBBLOCKS (root); root; root = BLOCK_CHAIN (root))
2540 218360 : if (! BLOCK_SUBBLOCKS (root))
2541 78554 : leafs.safe_push (root);
2542 : else
2543 139806 : collect_block_tree_leafs (root, leafs);
2544 250035 : }
2545 :
2546 : /* This performs function body modifications that are needed for streaming
2547 : to work. */
2548 :
2549 : void
2550 110219 : lto_prepare_function_for_streaming (struct cgraph_node *node)
2551 : {
2552 110219 : struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
2553 110219 : basic_block bb;
2554 :
2555 220438 : if (number_of_loops (fn))
2556 : {
2557 110219 : push_cfun (fn);
2558 110219 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
2559 110219 : loop_optimizer_finalize ();
2560 110219 : pop_cfun ();
2561 : }
2562 : /* We will renumber the statements. The code that does this uses
2563 : the same ordering that we use for serializing them so we can use
2564 : the same code on the other end and not have to write out the
2565 : statement numbers. We do not assign UIDs to PHIs here because
2566 : virtual PHIs get re-computed on-the-fly which would make numbers
2567 : inconsistent. */
2568 110219 : set_gimple_stmt_max_uid (fn, 0);
2569 1036318 : FOR_ALL_BB_FN (bb, fn)
2570 : {
2571 1087158 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2572 161059 : gsi_next (&gsi))
2573 : {
2574 161059 : gphi *stmt = gsi.phi ();
2575 :
2576 : /* Virtual PHIs are not going to be streamed. */
2577 322118 : if (!virtual_operand_p (gimple_phi_result (stmt)))
2578 93391 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2579 : }
2580 3583370 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
2581 1731172 : gsi_next (&gsi))
2582 : {
2583 1731172 : gimple *stmt = gsi_stmt (gsi);
2584 1731172 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2585 : }
2586 : }
2587 : /* To avoid keeping duplicate gimple IDs in the statements, renumber
2588 : virtual phis now. */
2589 1036318 : FOR_ALL_BB_FN (bb, fn)
2590 : {
2591 1087158 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2592 161059 : gsi_next (&gsi))
2593 : {
2594 161059 : gphi *stmt = gsi.phi ();
2595 389786 : if (virtual_operand_p (gimple_phi_result (stmt)))
2596 67668 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2597 : }
2598 : }
2599 :
2600 110219 : }
2601 :
2602 : /* Emit the chain of tree nodes starting at T. OB is the output block
2603 : to write to. REF_P is true if chain elements should be emitted
2604 : as references. */
2605 :
2606 : static void
2607 110383 : streamer_write_chain (struct output_block *ob, tree t, bool ref_p)
2608 : {
2609 433074 : while (t)
2610 : {
2611 : /* We avoid outputting external vars or functions by reference
2612 : to the global decls section as we do not want to have them
2613 : enter decl merging. We should not need to do this anymore because
2614 : free_lang_data removes them from block scopes. */
2615 322691 : gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
2616 322691 : stream_write_tree (ob, t, ref_p);
2617 :
2618 322691 : t = TREE_CHAIN (t);
2619 : }
2620 :
2621 : /* Write a sentinel to terminate the chain. */
2622 110383 : stream_write_tree (ob, NULL_TREE, ref_p);
2623 110383 : }
2624 :
2625 : /* Output the body of function NODE->DECL. */
2626 :
2627 : static void
2628 110383 : output_function (struct cgraph_node *node, int output_order)
2629 : {
2630 110383 : tree function;
2631 110383 : struct function *fn;
2632 110383 : basic_block bb;
2633 110383 : struct output_block *ob;
2634 :
2635 110383 : if (streamer_dump_file)
2636 8 : fprintf (streamer_dump_file, "\nStreaming body of %s\n",
2637 : node->dump_name ());
2638 :
2639 110383 : function = node->decl;
2640 110383 : fn = DECL_STRUCT_FUNCTION (function);
2641 110383 : ob = create_output_block (LTO_section_function_body);
2642 :
2643 110383 : ob->symbol = node;
2644 :
2645 110383 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
2646 :
2647 : /* Make string 0 be a NULL string. */
2648 110383 : streamer_write_char_stream (ob->string_stream, 0);
2649 :
2650 110383 : streamer_write_record_start (ob, LTO_function);
2651 :
2652 : /* Output decls for parameters and args. */
2653 110383 : stream_write_tree (ob, DECL_RESULT (function), true);
2654 110383 : streamer_write_chain (ob, DECL_ARGUMENTS (function), true);
2655 :
2656 : /* Output debug args if available. */
2657 110383 : vec<tree, va_gc> **debugargs = decl_debug_args_lookup (function);
2658 110383 : if (! debugargs)
2659 110354 : streamer_write_uhwi (ob, 0);
2660 : else
2661 : {
2662 29 : streamer_write_uhwi (ob, (*debugargs)->length ());
2663 132 : for (unsigned i = 0; i < (*debugargs)->length (); ++i)
2664 74 : stream_write_tree (ob, (**debugargs)[i], true);
2665 : }
2666 :
2667 : /* Output DECL_INITIAL for the function, which contains the tree of
2668 : lexical scopes. */
2669 110383 : stream_write_tree (ob, DECL_INITIAL (function), true);
2670 : /* As we do not recurse into BLOCK_SUBBLOCKS but only BLOCK_SUPERCONTEXT
2671 : collect block tree leafs and stream those. */
2672 110383 : auto_vec<tree> block_tree_leafs;
2673 110383 : if (DECL_INITIAL (function) && DECL_INITIAL (function) != error_mark_node)
2674 110229 : collect_block_tree_leafs (DECL_INITIAL (function), block_tree_leafs);
2675 110383 : streamer_write_uhwi (ob, block_tree_leafs.length ());
2676 299320 : for (unsigned i = 0; i < block_tree_leafs.length (); ++i)
2677 78554 : stream_write_tree (ob, block_tree_leafs[i], true);
2678 :
2679 : /* We also stream abstract functions where we stream only stuff needed for
2680 : debug info. */
2681 110383 : if (gimple_has_body_p (function))
2682 : {
2683 110229 : streamer_write_uhwi (ob, 1);
2684 110229 : output_struct_function_base (ob, fn);
2685 :
2686 110229 : output_cfg (ob, fn);
2687 :
2688 : /* Output all the SSA names used in the function. */
2689 110229 : output_ssa_names (ob, fn);
2690 :
2691 : /* Output any exception handling regions. */
2692 110229 : output_eh_regions (ob, fn);
2693 :
2694 : /* Output the code for the function. */
2695 1036358 : FOR_ALL_BB_FN (bb, fn)
2696 926129 : output_bb (ob, bb, fn);
2697 :
2698 : /* The terminator for this function. */
2699 110229 : streamer_write_record_start (ob, LTO_null);
2700 : }
2701 : else
2702 154 : streamer_write_uhwi (ob, 0);
2703 :
2704 : /* Create a section to hold the pickled output of this function. */
2705 110383 : produce_symbol_asm (ob, function, output_order);
2706 :
2707 110383 : destroy_output_block (ob);
2708 110383 : if (streamer_dump_file)
2709 8 : fprintf (streamer_dump_file, "Finished streaming %s\n",
2710 : node->dump_name ());
2711 110383 : }
2712 :
2713 : /* Output the body of function NODE->DECL. */
2714 :
2715 : static void
2716 11272 : output_constructor (struct varpool_node *node, int output_order)
2717 : {
2718 11272 : tree var = node->decl;
2719 11272 : struct output_block *ob;
2720 :
2721 11272 : if (streamer_dump_file)
2722 4 : fprintf (streamer_dump_file, "\nStreaming constructor of %s\n",
2723 : node->dump_name ());
2724 :
2725 11272 : timevar_push (TV_IPA_LTO_CTORS_OUT);
2726 11272 : ob = create_output_block (LTO_section_function_body);
2727 :
2728 11272 : ob->symbol = node;
2729 :
2730 : /* Make string 0 be a NULL string. */
2731 11272 : streamer_write_char_stream (ob->string_stream, 0);
2732 :
2733 : /* Output DECL_INITIAL for the function, which contains the tree of
2734 : lexical scopes. */
2735 11272 : stream_write_tree (ob, DECL_INITIAL (var), true);
2736 :
2737 : /* Create a section to hold the pickled output of this function. */
2738 11272 : produce_symbol_asm (ob, var, output_order);
2739 :
2740 11272 : destroy_output_block (ob);
2741 11272 : if (streamer_dump_file)
2742 4 : fprintf (streamer_dump_file, "Finished streaming %s\n",
2743 : node->dump_name ());
2744 11272 : timevar_pop (TV_IPA_LTO_CTORS_OUT);
2745 11272 : }
2746 :
2747 :
2748 : /* Emit toplevel asms. */
2749 :
2750 : void
2751 32481 : lto_output_toplevel_asms (lto_symtab_encoder_t encoder)
2752 : {
2753 32481 : struct output_block *ob;
2754 32481 : char *section_name;
2755 32481 : struct lto_simple_header_with_strings header;
2756 :
2757 32481 : unsigned asm_count = 0;
2758 1493009 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
2759 1428288 : if (is_a <asm_node*> (lto_symtab_encoder_deref (encoder, i)))
2760 156 : asm_count++;
2761 :
2762 32481 : if (!asm_count)
2763 32366 : return;
2764 :
2765 115 : ob = create_output_block (LTO_section_asm);
2766 :
2767 : /* Stream the length. */
2768 115 : streamer_write_uhwi (ob, asm_count);
2769 26173 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
2770 : {
2771 12914 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
2772 12914 : asm_node *anode = dyn_cast <asm_node*> (tnode);
2773 12914 : if (!anode)
2774 12758 : continue;
2775 :
2776 156 : int output_order = *encoder->order_remap->get (anode->order);
2777 156 : stream_write_tree (ob, anode->asm_str, true);
2778 156 : streamer_write_hwi (ob, output_order);
2779 : }
2780 :
2781 115 : section_name = lto_get_section_name (LTO_section_asm, NULL, 0, NULL);
2782 115 : lto_begin_section (section_name, !flag_wpa);
2783 115 : free (section_name);
2784 :
2785 : /* The entire header stream is computed here. */
2786 115 : memset (&header, 0, sizeof (header));
2787 :
2788 115 : header.main_size = ob->main_stream->total_size;
2789 115 : header.string_size = ob->string_stream->total_size;
2790 115 : lto_write_data (&header, sizeof header);
2791 :
2792 : /* Put all of the gimple and the string table out the asm file as a
2793 : block of text. */
2794 115 : lto_write_stream (ob->main_stream);
2795 115 : lto_write_stream (ob->string_stream);
2796 :
2797 115 : lto_end_section ();
2798 :
2799 115 : destroy_output_block (ob);
2800 : }
2801 :
2802 :
2803 : /* Copy the function body or variable constructor of NODE without deserializing. */
2804 :
2805 : static void
2806 35423 : copy_function_or_variable (struct symtab_node *node, int output_order)
2807 : {
2808 35423 : tree function = node->decl;
2809 35423 : struct lto_file_decl_data *file_data = node->lto_file_data;
2810 35423 : const char *data;
2811 35423 : size_t len;
2812 35423 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
2813 35423 : char *section_name =
2814 35423 : lto_get_section_name (LTO_section_function_body, name, output_order, NULL);
2815 35423 : size_t i, j;
2816 35423 : struct lto_in_decl_state *in_state;
2817 35423 : struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
2818 :
2819 35423 : if (streamer_dump_file)
2820 0 : fprintf (streamer_dump_file, "Copying section for %s\n", name);
2821 35423 : lto_begin_section (section_name, false);
2822 35423 : free (section_name);
2823 :
2824 : /* We may have renamed the declaration, e.g., a static function. */
2825 35423 : name = lto_get_decl_name_mapping (file_data, name);
2826 :
2827 70846 : data = lto_get_raw_section_data (file_data, LTO_section_function_body,
2828 35423 : name, node->order - file_data->order_base,
2829 : &len);
2830 35423 : gcc_assert (data);
2831 :
2832 : /* Do a bit copy of the function body. */
2833 35423 : lto_write_raw_data (data, len);
2834 :
2835 : /* Copy decls. */
2836 35423 : in_state =
2837 35423 : lto_get_function_in_decl_state (node->lto_file_data, function);
2838 35423 : out_state->compressed = in_state->compressed;
2839 35423 : gcc_assert (in_state);
2840 :
2841 70846 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
2842 : {
2843 35423 : size_t n = vec_safe_length (in_state->streams[i]);
2844 35423 : vec<tree, va_gc> *trees = in_state->streams[i];
2845 35423 : struct lto_tree_ref_encoder *encoder = &(out_state->streams[i]);
2846 :
2847 : /* The out state must have the same indices and the in state.
2848 : So just copy the vector. All the encoders in the in state
2849 : must be empty where we reach here. */
2850 35423 : gcc_assert (lto_tree_ref_encoder_size (encoder) == 0);
2851 35423 : encoder->trees.reserve_exact (n);
2852 536521 : for (j = 0; j < n; j++)
2853 465675 : encoder->trees.safe_push ((*trees)[j]);
2854 : }
2855 :
2856 35423 : lto_free_raw_section_data (file_data, LTO_section_function_body, name,
2857 : data, len);
2858 35423 : lto_end_section ();
2859 :
2860 : /* Make sure the reader knows which linemap section to use. */
2861 35423 : out_state->linemap_id = lto_linemap_output_id (in_state->linemap_id,
2862 : file_data);
2863 35423 : }
2864 :
2865 : /* Wrap symbol references in *TP inside a type-preserving MEM_REF. */
2866 :
2867 : static tree
2868 795675 : wrap_refs (tree *tp, int *ws, void *)
2869 : {
2870 795675 : tree t = *tp;
2871 795675 : if (handled_component_p (t)
2872 178 : && VAR_P (TREE_OPERAND (t, 0))
2873 121 : && TREE_PUBLIC (TREE_OPERAND (t, 0)))
2874 : {
2875 82 : tree decl = TREE_OPERAND (t, 0);
2876 82 : tree ptrtype = build_pointer_type (TREE_TYPE (decl));
2877 82 : TREE_OPERAND (t, 0) = build2 (MEM_REF, TREE_TYPE (decl),
2878 : build1 (ADDR_EXPR, ptrtype, decl),
2879 : build_int_cst (ptrtype, 0));
2880 82 : TREE_THIS_VOLATILE (TREE_OPERAND (t, 0)) = TREE_THIS_VOLATILE (decl);
2881 82 : *ws = 0;
2882 : }
2883 795593 : else if (TREE_CODE (t) == CONSTRUCTOR)
2884 : ;
2885 577612 : else if (!EXPR_P (t))
2886 337595 : *ws = 0;
2887 795675 : return NULL_TREE;
2888 : }
2889 :
2890 : /* Remove functions that are no longer used from offload_funcs, and mark the
2891 : remaining ones with DECL_PRESERVE_P. */
2892 :
2893 : static void
2894 32481 : prune_offload_funcs (void)
2895 : {
2896 32481 : if (!offload_funcs)
2897 32481 : return;
2898 :
2899 0 : unsigned ix, ix2;
2900 0 : tree *elem_ptr;
2901 0 : VEC_ORDERED_REMOVE_IF (*offload_funcs, ix, ix2, elem_ptr,
2902 0 : cgraph_node::get (*elem_ptr) == NULL);
2903 :
2904 0 : tree fn_decl;
2905 0 : FOR_EACH_VEC_ELT (*offload_funcs, ix, fn_decl)
2906 0 : DECL_PRESERVE_P (fn_decl) = 1;
2907 : }
2908 :
2909 : /* Produce LTO section that contains global information
2910 : about LTO bytecode. */
2911 :
2912 : static void
2913 40628 : produce_lto_section ()
2914 : {
2915 : /* Stream LTO meta section. */
2916 40628 : output_block *ob = create_output_block (LTO_section_lto);
2917 :
2918 40628 : char * section_name = lto_get_section_name (LTO_section_lto, NULL, 0, NULL);
2919 40628 : lto_begin_section (section_name, false);
2920 40628 : free (section_name);
2921 :
2922 : #ifdef HAVE_ZSTD_H
2923 40628 : lto_compression compression = ZSTD;
2924 : #else
2925 : lto_compression compression = ZLIB;
2926 : #endif
2927 :
2928 40628 : bool slim_object = flag_generate_lto && !flag_fat_lto_objects;
2929 40628 : lto_section s
2930 40628 : = { LTO_major_version, LTO_minor_version, slim_object, 0, 0 };
2931 40628 : s.set_compression (compression);
2932 40628 : lto_write_data (&s, sizeof s);
2933 40628 : lto_end_section ();
2934 40628 : destroy_output_block (ob);
2935 40628 : }
2936 :
2937 : /* If we have copied a function, we need to make sure the linemap it refers to
2938 : is also streamed out. */
2939 :
2940 : static void
2941 8971 : copy_linemap_section (lto_file_decl_data *file_data, unsigned order)
2942 : {
2943 8971 : const auto in_section_name
2944 8971 : = lto_get_section_name (LTO_section_linemap, nullptr, order, file_data);
2945 8971 : const auto out_section_name
2946 17942 : = lto_get_section_name (LTO_section_linemap, nullptr,
2947 8971 : lto_linemap_output_id (order, file_data), nullptr);
2948 :
2949 8971 : if (streamer_dump_file)
2950 0 : fprintf (streamer_dump_file, "Copying linemap section from %s to %s\n",
2951 : in_section_name, out_section_name);
2952 :
2953 8971 : size_t len;
2954 8971 : const auto data = lto_get_raw_section_data (file_data, LTO_section_linemap,
2955 : nullptr, order, &len);
2956 8971 : gcc_assert (data);
2957 8971 : lto_begin_section (out_section_name, false);
2958 8971 : free (in_section_name);
2959 8971 : free (out_section_name);
2960 8971 : lto_write_raw_data (data, len);
2961 8971 : lto_free_raw_section_data (file_data, LTO_section_linemap,
2962 : nullptr, data, len);
2963 8971 : lto_end_section ();
2964 8971 : }
2965 :
2966 : static void
2967 8969 : copy_linemap_sections (lto_file_decl_data *file_data)
2968 : {
2969 17940 : for (unsigned i = 0; i != file_data->num_linemap_sections; ++i)
2970 8971 : copy_linemap_section (file_data, i);
2971 8969 : }
2972 :
2973 : /* Copy all the linemaps we read into an object file so LTRANS can find them
2974 : later. */
2975 :
2976 : void
2977 8183 : lto_copy_linemaps ()
2978 : {
2979 8183 : timevar_push (TV_IPA_LTO_LINEMAP_COPY);
2980 8183 : lto_streamer_init ();
2981 8183 : lto_push_out_decl_state (nullptr);
2982 :
2983 : /* In WPA, we write these out to a standalone file; give it an LTO header
2984 : section. */
2985 8183 : if (flag_wpa)
2986 8147 : produce_lto_section ();
2987 :
2988 17152 : for (auto file_data = lto_get_file_decl_data (); *file_data; ++file_data)
2989 8969 : copy_linemap_sections (*file_data);
2990 :
2991 8183 : lto_pop_out_decl_state ();
2992 8183 : timevar_pop (TV_IPA_LTO_LINEMAP_COPY);
2993 8183 : }
2994 :
2995 : /* Compare symbols to get them sorted by filename (to optimize streaming) */
2996 :
2997 : static int
2998 3404529 : cmp_symbol_files (const void *pn1, const void *pn2, void *id_map_)
2999 : {
3000 3404529 : const symtab_node *n1 = *(const symtab_node * const *)pn1;
3001 3404529 : const symtab_node *n2 = *(const symtab_node * const *)pn2;
3002 3404529 : hash_map<lto_file_decl_data *, int> *id_map
3003 : = (hash_map<lto_file_decl_data *, int> *)id_map_;
3004 :
3005 3404529 : int file_order1 = n1->lto_file_data ? n1->lto_file_data->order : -1;
3006 3404529 : int file_order2 = n2->lto_file_data ? n2->lto_file_data->order : -1;
3007 :
3008 : /* Order files same way as they appeared in the command line to reduce
3009 : seeking while copying sections. */
3010 3404529 : if (file_order1 != file_order2)
3011 10295 : return file_order1 - file_order2;
3012 :
3013 : /* Order within static library. */
3014 3394234 : if (n1->lto_file_data && n1->lto_file_data->id != n2->lto_file_data->id)
3015 0 : return *id_map->get (n1->lto_file_data) - *id_map->get (n2->lto_file_data);
3016 :
3017 : /* And finally order by the definition order. */
3018 3394234 : return n1->order - n2->order;
3019 : }
3020 :
3021 : /* Compare ints, callback for qsort. */
3022 :
3023 : static int
3024 31935391 : cmp_int (const void *a, const void *b)
3025 : {
3026 31935391 : int ia = *(int const*) a;
3027 31935391 : int ib = *(int const*) b;
3028 31935391 : return ia - ib;
3029 : }
3030 :
3031 : /* Create order mapping independent on symbols outside of the partition.
3032 : Results in stable order values for incremental LTO.
3033 :
3034 : Remapping is not done in place, because symbols can be used
3035 : by multiple partitions. */
3036 :
3037 : static void
3038 32481 : create_order_remap (lto_symtab_encoder_t encoder)
3039 : {
3040 32481 : auto_vec<int> orders;
3041 32481 : unsigned i;
3042 32481 : encoder->order_remap = new hash_map<int_hash<int, -1, -2>, int>;
3043 32481 : unsigned n_nodes = lto_symtab_encoder_size (encoder);
3044 :
3045 746625 : for (i = 0; i < n_nodes; i++)
3046 714144 : orders.safe_push (lto_symtab_encoder_deref (encoder, i)->order);
3047 :
3048 32481 : orders.qsort (cmp_int);
3049 32481 : int ord = 0;
3050 32481 : int last_order = -1;
3051 746625 : for (i = 0; i < orders.length (); i++)
3052 : {
3053 714144 : int order = orders[i];
3054 714144 : if (order != last_order)
3055 : {
3056 690760 : last_order = order;
3057 690760 : encoder->order_remap->put (order, ord);
3058 690760 : ord++;
3059 : }
3060 : }
3061 32481 : }
3062 :
3063 : /* When WPA writes out its outputs, there are two different ways a location
3064 : may be streamed out: either streamed freshly, e.g. when trees are
3065 : streamed out in the decls section, or else copied verbatim from the input
3066 : files. In the former case, we need to remember how a location_t was
3067 : originally referenced in the input data, so we can stream it out the same
3068 : way; otherwise it would be necessary to stream out a new linemap section
3069 : just for WPA-generated locations, which would a) be wasteful given that
3070 : all locations originated from one of the linemap sections that already
3071 : exists and b) inhibit incremental LTO since a change to one partition
3072 : would affect the linemap for all of them. */
3073 :
3074 21236 : void lto_register_linemap_for_output (size_t map_idx, unsigned linemap_id)
3075 : {
3076 21236 : loc_output.register_map_id (map_idx, linemap_id);
3077 21236 : }
3078 :
3079 : /* Main entry point from the pass manager. */
3080 :
3081 : void
3082 32481 : lto_output (void)
3083 : {
3084 32481 : struct lto_out_decl_state *decl_state;
3085 32481 : bitmap output = NULL;
3086 32481 : bitmap_obstack output_obstack;
3087 32481 : unsigned int i, n_nodes;
3088 32481 : lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder;
3089 32481 : auto_vec<symtab_node *> symbols_to_copy;
3090 :
3091 32481 : create_order_remap (encoder);
3092 :
3093 32481 : prune_offload_funcs ();
3094 :
3095 32481 : if (flag_checking)
3096 : {
3097 32475 : bitmap_obstack_initialize (&output_obstack);
3098 32475 : output = BITMAP_ALLOC (&output_obstack);
3099 : }
3100 :
3101 : /* Initialize the streamer. */
3102 32481 : lto_streamer_init ();
3103 :
3104 32481 : produce_lto_section ();
3105 :
3106 32481 : n_nodes = lto_symtab_encoder_size (encoder);
3107 : /* Prepare vector of functions to output and then sort it to optimize
3108 : section copying. */
3109 746625 : for (i = 0; i < n_nodes; i++)
3110 : {
3111 714144 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
3112 714144 : symtab_node *node = dyn_cast <symtab_node *> (tnode);
3113 713988 : if (!node || node->alias)
3114 12981 : continue;
3115 :
3116 701163 : if (cgraph_node *node = dyn_cast <cgraph_node *> (tnode))
3117 : {
3118 413842 : if (lto_symtab_encoder_encode_body_p (encoder, node)
3119 413842 : && !node->clone_of)
3120 141160 : symbols_to_copy.safe_push (node);
3121 : }
3122 1001465 : else if (varpool_node *node = dyn_cast <varpool_node *> (tnode))
3123 : {
3124 : /* Wrap symbol references inside the ctor in a type
3125 : preserving MEM_REF. */
3126 287321 : tree ctor = DECL_INITIAL (node->decl);
3127 287321 : if (ctor && !in_lto_p)
3128 19694 : walk_tree (&ctor, wrap_refs, NULL, NULL);
3129 287321 : if (get_symbol_initial_value (encoder, node->decl) == error_mark_node
3130 287321 : && lto_symtab_encoder_encode_initializer_p (encoder, node))
3131 15918 : symbols_to_copy.safe_push (node);
3132 : }
3133 : }
3134 : /* Map the section hash to an order it appears in symbols_to_copy
3135 : since we want to sort same ID symbols next to each other but need
3136 : to avoid making overall order depend on the actual hash value. */
3137 32481 : int order = 0;
3138 32481 : hash_map<lto_file_decl_data *, int> id_map;
3139 222040 : for (i = 0; i < symbols_to_copy.length (); ++i)
3140 : {
3141 157078 : symtab_node *snode = symbols_to_copy[i];
3142 157078 : if (snode->lto_file_data)
3143 : {
3144 41074 : bool existed_p = false;
3145 41074 : int &ord = id_map.get_or_insert (snode->lto_file_data, &existed_p);
3146 41074 : if (!existed_p)
3147 9051 : ord = order++;
3148 : }
3149 : }
3150 32481 : symbols_to_copy.sort (cmp_symbol_files, (void *)&id_map);
3151 189559 : for (i = 0; i < symbols_to_copy.length (); i++)
3152 : {
3153 157078 : symtab_node *snode = symbols_to_copy[i];
3154 157078 : cgraph_node *cnode;
3155 157078 : varpool_node *vnode;
3156 :
3157 157078 : int output_order = *encoder->order_remap->get (snode->order);
3158 :
3159 157078 : if (flag_checking)
3160 157076 : gcc_assert (bitmap_set_bit (output, DECL_UID (snode->decl)));
3161 :
3162 157078 : decl_state = lto_new_out_decl_state ();
3163 157078 : lto_push_out_decl_state (decl_state);
3164 :
3165 157078 : if ((cnode = dyn_cast <cgraph_node *> (snode))
3166 141160 : && (gimple_has_body_p (cnode->decl)
3167 30931 : || (!flag_wpa
3168 301 : && flag_incremental_link != INCREMENTAL_LINK_LTO)
3169 : /* Thunks have no body but they may be synthesized
3170 : at WPA time. */
3171 30777 : || DECL_ARGUMENTS (cnode->decl)))
3172 110383 : output_function (cnode, output_order);
3173 46695 : else if ((vnode = dyn_cast <varpool_node *> (snode))
3174 15918 : && (DECL_INITIAL (vnode->decl) != error_mark_node
3175 4646 : || (!flag_wpa
3176 42 : && flag_incremental_link != INCREMENTAL_LINK_LTO)))
3177 11272 : output_constructor (vnode, output_order);
3178 : else
3179 35423 : copy_function_or_variable (snode, output_order);
3180 157078 : gcc_assert (lto_get_out_decl_state () == decl_state);
3181 157078 : lto_pop_out_decl_state ();
3182 157078 : lto_record_function_out_decl_state (snode->decl, decl_state);
3183 : }
3184 :
3185 : /* Emit the callgraph after emitting function bodies. This needs to
3186 : be done now to make sure that all the statements in every function
3187 : have been renumbered so that edges can be associated with call
3188 : statements using the statement UIDs. */
3189 32481 : output_symtab ();
3190 :
3191 32481 : if (lto_get_out_decl_state ()->output_offload_tables_p)
3192 8147 : output_offload_tables ();
3193 :
3194 32481 : if (flag_checking)
3195 : {
3196 32475 : BITMAP_FREE (output);
3197 32475 : bitmap_obstack_release (&output_obstack);
3198 : }
3199 32481 : }
3200 :
3201 : /* Write each node in encoded by ENCODER to OB, as well as those reachable
3202 : from it and required for correct representation of its semantics.
3203 : Each node in ENCODER must be a global declaration or a type. A node
3204 : is written only once, even if it appears multiple times in the
3205 : vector. Certain transitively-reachable nodes, such as those
3206 : representing expressions, may be duplicated, but such nodes
3207 : must not appear in ENCODER itself. */
3208 :
3209 : static void
3210 189559 : write_global_stream (struct output_block *ob,
3211 : struct lto_tree_ref_encoder *encoder)
3212 : {
3213 189559 : tree t;
3214 189559 : size_t index;
3215 189559 : const size_t size = lto_tree_ref_encoder_size (encoder);
3216 :
3217 2890771 : for (index = 0; index < size; index++)
3218 : {
3219 2701212 : t = lto_tree_ref_encoder_get_tree (encoder, index);
3220 2701212 : if (streamer_dump_file)
3221 : {
3222 176 : fprintf (streamer_dump_file, " %i:", (int)index);
3223 176 : print_node_brief (streamer_dump_file, "", t, 4);
3224 176 : fprintf (streamer_dump_file, "\n");
3225 : }
3226 2701212 : if (!streamer_tree_cache_lookup (ob->writer_cache, t, NULL))
3227 949648 : stream_write_tree (ob, t, false);
3228 : }
3229 189559 : }
3230 :
3231 :
3232 : /* Write a sequence of indices into the globals vector corresponding
3233 : to the trees in ENCODER. These are used by the reader to map the
3234 : indices used to refer to global entities within function bodies to
3235 : their referents. */
3236 :
3237 : static void
3238 189559 : write_global_references (struct output_block *ob,
3239 : struct lto_tree_ref_encoder *encoder)
3240 : {
3241 189559 : tree t;
3242 189559 : uint32_t index;
3243 189559 : const uint32_t size = lto_tree_ref_encoder_size (encoder);
3244 :
3245 : /* Write size and slot indexes as 32-bit unsigned numbers. */
3246 189559 : uint32_t *data = XNEWVEC (uint32_t, size + 1);
3247 189559 : data[0] = size;
3248 :
3249 2890771 : for (index = 0; index < size; index++)
3250 : {
3251 2701212 : unsigned slot_num;
3252 :
3253 2701212 : t = lto_tree_ref_encoder_get_tree (encoder, index);
3254 2701212 : streamer_tree_cache_lookup (ob->writer_cache, t, &slot_num);
3255 2701212 : gcc_assert (slot_num != (unsigned)-1);
3256 2701212 : data[index + 1] = slot_num;
3257 : }
3258 :
3259 189559 : lto_write_data (data, sizeof (int32_t) * (size + 1));
3260 189559 : free (data);
3261 189559 : }
3262 :
3263 :
3264 : /* Write all the streams in an lto_out_decl_state STATE using
3265 : output block OB and output stream OUT_STREAM. */
3266 :
3267 : void
3268 189559 : lto_output_decl_state_streams (struct output_block *ob,
3269 : struct lto_out_decl_state *state)
3270 : {
3271 189559 : int i;
3272 :
3273 379118 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3274 189559 : write_global_stream (ob, &state->streams[i]);
3275 189559 : }
3276 :
3277 :
3278 : /* Write all the references in an lto_out_decl_state STATE using
3279 : output block OB and output stream OUT_STREAM. */
3280 :
3281 : void
3282 189559 : lto_output_decl_state_refs (struct output_block *ob,
3283 : struct lto_out_decl_state *state)
3284 : {
3285 189559 : unsigned i;
3286 189559 : uint32_t ref, lm_order;
3287 189559 : tree decl;
3288 :
3289 : /* Write reference to FUNCTION_DECL. If there is not function,
3290 : write reference to void_type_node. */
3291 189559 : decl = (state->fn_decl) ? state->fn_decl : void_type_node;
3292 189559 : streamer_tree_cache_lookup (ob->writer_cache, decl, &ref);
3293 189559 : gcc_assert (ref != (uint32_t)-1);
3294 189559 : ref = ref * 2 + (state->compressed ? 1 : 0);
3295 189559 : lto_write_data (&ref, sizeof (uint32_t));
3296 189559 : if (state->fn_decl)
3297 : {
3298 157078 : lm_order = state->linemap_id;
3299 157078 : lto_write_data (&lm_order, sizeof (lm_order));
3300 : }
3301 379118 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3302 189559 : write_global_references (ob, &state->streams[i]);
3303 189559 : }
3304 :
3305 :
3306 : /* Return the written size of STATE. */
3307 :
3308 : static size_t
3309 189559 : lto_out_decl_state_written_size (struct lto_out_decl_state *state)
3310 : {
3311 189559 : int i;
3312 189559 : size_t size;
3313 :
3314 189559 : size = sizeof (int32_t); /* fn_ref. */
3315 189559 : if (state->fn_decl)
3316 157078 : size += sizeof (int32_t); /* linemap_id. */
3317 379118 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3318 : {
3319 189559 : size += sizeof (int32_t); /* vector size. */
3320 189559 : size += (lto_tree_ref_encoder_size (&state->streams[i])
3321 189559 : * sizeof (int32_t));
3322 : }
3323 189559 : return size;
3324 : }
3325 :
3326 :
3327 : /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
3328 : so far. */
3329 :
3330 : static void
3331 546569 : write_symbol (struct streamer_tree_cache_d *cache,
3332 : tree t, hash_set<const char *> *seen, bool alias)
3333 : {
3334 546569 : const char *name;
3335 546569 : enum gcc_plugin_symbol_kind kind;
3336 546569 : enum gcc_plugin_symbol_visibility visibility = GCCPV_DEFAULT;
3337 546569 : unsigned slot_num;
3338 546569 : uint64_t size;
3339 546569 : const char *comdat;
3340 546569 : unsigned char c;
3341 :
3342 546569 : gcc_assert (VAR_OR_FUNCTION_DECL_P (t));
3343 :
3344 546569 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
3345 :
3346 : /* This behaves like assemble_name_raw in varasm.cc, performing the
3347 : same name manipulations that ASM_OUTPUT_LABELREF does. */
3348 546569 : name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
3349 :
3350 546569 : if (seen->add (name))
3351 769 : return;
3352 :
3353 545800 : streamer_tree_cache_lookup (cache, t, &slot_num);
3354 545800 : gcc_assert (slot_num != (unsigned)-1);
3355 :
3356 545800 : if (DECL_EXTERNAL (t))
3357 : {
3358 215788 : if (DECL_WEAK (t))
3359 : kind = GCCPK_WEAKUNDEF;
3360 : else
3361 215750 : kind = GCCPK_UNDEF;
3362 : }
3363 : else
3364 : {
3365 330012 : if (DECL_WEAK (t))
3366 : kind = GCCPK_WEAKDEF;
3367 317868 : else if (DECL_COMMON (t))
3368 : kind = GCCPK_COMMON;
3369 : else
3370 317807 : kind = GCCPK_DEF;
3371 :
3372 : /* When something is defined, it should have node attached. */
3373 330012 : gcc_assert (alias || !VAR_P (t) || varpool_node::get (t)->definition);
3374 330012 : gcc_assert (alias || TREE_CODE (t) != FUNCTION_DECL
3375 : || (cgraph_node::get (t)
3376 : && cgraph_node::get (t)->definition));
3377 : }
3378 :
3379 : /* Imitate what default_elf_asm_output_external do.
3380 : When symbol is external, we need to output it with DEFAULT visibility
3381 : when compiling with -fvisibility=default, while with HIDDEN visibility
3382 : when symbol has attribute (visibility("hidden")) specified.
3383 : targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
3384 : right. */
3385 :
3386 545800 : if (DECL_EXTERNAL (t)
3387 545800 : && !targetm.binds_local_p (t))
3388 : visibility = GCCPV_DEFAULT;
3389 : else
3390 330066 : switch (DECL_VISIBILITY (t))
3391 : {
3392 : case VISIBILITY_DEFAULT:
3393 : visibility = GCCPV_DEFAULT;
3394 : break;
3395 : case VISIBILITY_PROTECTED:
3396 545800 : visibility = GCCPV_PROTECTED;
3397 : break;
3398 : case VISIBILITY_HIDDEN:
3399 : visibility = GCCPV_HIDDEN;
3400 : break;
3401 : case VISIBILITY_INTERNAL:
3402 : visibility = GCCPV_INTERNAL;
3403 : break;
3404 : }
3405 :
3406 545800 : if (kind == GCCPK_COMMON
3407 61 : && DECL_SIZE_UNIT (t)
3408 545861 : && TREE_CODE (DECL_SIZE_UNIT (t)) == INTEGER_CST)
3409 61 : size = TREE_INT_CST_LOW (DECL_SIZE_UNIT (t));
3410 : else
3411 545739 : size = 0;
3412 :
3413 545800 : if (DECL_ONE_ONLY (t))
3414 12107 : comdat = IDENTIFIER_POINTER (decl_comdat_group_id (t));
3415 : else
3416 : comdat = "";
3417 :
3418 545800 : lto_write_data (name, strlen (name) + 1);
3419 545800 : lto_write_data (comdat, strlen (comdat) + 1);
3420 545800 : c = (unsigned char) kind;
3421 545800 : lto_write_data (&c, 1);
3422 545800 : c = (unsigned char) visibility;
3423 545800 : lto_write_data (&c, 1);
3424 545800 : lto_write_data (&size, 8);
3425 545800 : lto_write_data (&slot_num, 4);
3426 : }
3427 :
3428 : /* Write extension information for symbols (symbol type, section flags). */
3429 :
3430 : static void
3431 546569 : write_symbol_extension_info (tree t)
3432 : {
3433 546569 : unsigned char c;
3434 546569 : c = ((unsigned char) TREE_CODE (t) == VAR_DECL
3435 : ? GCCST_VARIABLE : GCCST_FUNCTION);
3436 546569 : lto_write_data (&c, 1);
3437 546569 : unsigned char section_kind = 0;
3438 546569 : if (VAR_P (t))
3439 : {
3440 234911 : section *s = get_variable_section (t, false);
3441 234911 : if (s->common.flags & SECTION_BSS)
3442 224840 : section_kind |= GCCSSK_BSS;
3443 : }
3444 546569 : lto_write_data (§ion_kind, 1);
3445 546569 : }
3446 :
3447 : /* Write an IL symbol table to OB.
3448 : SET and VSET are cgraph/varpool node sets we are outputting. */
3449 :
3450 : static unsigned int
3451 23943 : produce_symtab (struct output_block *ob)
3452 : {
3453 23943 : unsigned int streamed_symbols = 0;
3454 23943 : struct streamer_tree_cache_d *cache = ob->writer_cache;
3455 23943 : char *section_name = lto_get_section_name (LTO_section_symtab, NULL, 0, NULL);
3456 23943 : lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
3457 23943 : lto_symtab_encoder_iterator lsei;
3458 :
3459 23943 : lto_begin_section (section_name, false);
3460 23943 : free (section_name);
3461 :
3462 23943 : hash_set<const char *> seen;
3463 :
3464 : /* Write the symbol table.
3465 : First write everything defined and then all declarations.
3466 : This is necessary to handle cases where we have duplicated symbols. */
3467 23943 : for (lsei = lsei_start (encoder);
3468 627669 : !lsei_end_p (lsei); lsei_next (&lsei))
3469 : {
3470 603726 : toplevel_node *tnode = lsei_node (lsei);
3471 603726 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3472 603726 : if (!node)
3473 84 : continue;
3474 :
3475 603642 : if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3476 273630 : continue;
3477 330012 : write_symbol (cache, node->decl, &seen, false);
3478 330012 : ++streamed_symbols;
3479 : }
3480 23943 : for (lsei = lsei_start (encoder);
3481 627669 : !lsei_end_p (lsei); lsei_next (&lsei))
3482 : {
3483 603726 : toplevel_node *tnode = lsei_node (lsei);
3484 603726 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3485 603726 : if (!node)
3486 84 : continue;
3487 :
3488 603642 : if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3489 387085 : continue;
3490 216557 : write_symbol (cache, node->decl, &seen, false);
3491 216557 : ++streamed_symbols;
3492 : }
3493 :
3494 23943 : lto_end_section ();
3495 :
3496 23943 : return streamed_symbols;
3497 23943 : }
3498 :
3499 : /* Symtab extension version. */
3500 : #define LTO_SYMTAB_EXTENSION_VERSION 1
3501 :
3502 : /* Write an IL symbol table extension to OB.
3503 : SET and VSET are cgraph/varpool node sets we are outputting. */
3504 :
3505 : static void
3506 23943 : produce_symtab_extension (struct output_block *ob,
3507 : unsigned int previous_streamed_symbols)
3508 : {
3509 23943 : unsigned int streamed_symbols = 0;
3510 23943 : char *section_name = lto_get_section_name (LTO_section_symtab_extension,
3511 : NULL, 0, NULL);
3512 23943 : lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
3513 23943 : lto_symtab_encoder_iterator lsei;
3514 :
3515 23943 : lto_begin_section (section_name, false);
3516 23943 : free (section_name);
3517 :
3518 23943 : unsigned char version = LTO_SYMTAB_EXTENSION_VERSION;
3519 23943 : lto_write_data (&version, 1);
3520 :
3521 : /* Write the symbol table.
3522 : First write everything defined and then all declarations.
3523 : This is necessary to handle cases where we have duplicated symbols. */
3524 23943 : for (lsei = lsei_start (encoder);
3525 627669 : !lsei_end_p (lsei); lsei_next (&lsei))
3526 : {
3527 603726 : toplevel_node *tnode = lsei_node (lsei);
3528 603726 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3529 603726 : if (!node)
3530 84 : continue;
3531 :
3532 603642 : if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3533 273630 : continue;
3534 330012 : write_symbol_extension_info (node->decl);
3535 330012 : ++streamed_symbols;
3536 : }
3537 23943 : for (lsei = lsei_start (encoder);
3538 627669 : !lsei_end_p (lsei); lsei_next (&lsei))
3539 : {
3540 603726 : toplevel_node *tnode = lsei_node (lsei);
3541 603726 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3542 603726 : if (!node)
3543 84 : continue;
3544 :
3545 603642 : if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3546 387085 : continue;
3547 216557 : write_symbol_extension_info (node->decl);
3548 216557 : ++streamed_symbols;
3549 : }
3550 :
3551 23943 : gcc_assert (previous_streamed_symbols == streamed_symbols);
3552 23943 : lto_end_section ();
3553 23943 : }
3554 :
3555 :
3556 : /* Init the streamer_mode_table for output, where we collect info on what
3557 : machine_mode values have been streamed. */
3558 : void
3559 32481 : lto_output_init_mode_table (void)
3560 : {
3561 32481 : memset (streamer_mode_table, '\0', MAX_MACHINE_MODE);
3562 32481 : }
3563 :
3564 :
3565 : /* Write the mode table. */
3566 : static void
3567 0 : lto_write_mode_table (void)
3568 : {
3569 0 : struct output_block *ob;
3570 0 : ob = create_output_block (LTO_section_mode_table);
3571 0 : bitpack_d bp = bitpack_create (ob->main_stream);
3572 :
3573 0 : if (lto_stream_offload_p)
3574 0 : bp_pack_value (&bp, NUM_POLY_INT_COEFFS, MAX_NUM_POLY_INT_COEFFS_BITS);
3575 :
3576 : /* Ensure that for GET_MODE_INNER (m) != m we have
3577 : also the inner mode marked. */
3578 0 : for (int i = 0; i < (int) MAX_MACHINE_MODE; i++)
3579 0 : if (streamer_mode_table[i])
3580 : {
3581 0 : machine_mode m = (machine_mode) i;
3582 0 : machine_mode inner_m = GET_MODE_INNER (m);
3583 0 : if (inner_m != m)
3584 0 : streamer_mode_table[(int) inner_m] = 1;
3585 : }
3586 :
3587 : /* Pack the mode_bits value within 5 bits (up to 31) in the beginning. */
3588 0 : unsigned mode_bits = ceil_log2 (MAX_MACHINE_MODE);
3589 0 : bp_pack_value (&bp, mode_bits, 5);
3590 :
3591 : /* First stream modes that have GET_MODE_INNER (m) == m,
3592 : so that we can refer to them afterwards. */
3593 0 : for (int pass = 0; pass < 2; pass++)
3594 0 : for (int i = 0; i < (int) MAX_MACHINE_MODE; i++)
3595 0 : if (streamer_mode_table[i] && i != (int) VOIDmode && i != (int) BLKmode)
3596 : {
3597 0 : machine_mode m = (machine_mode) i;
3598 0 : if ((GET_MODE_INNER (m) == m) ^ (pass == 0))
3599 0 : continue;
3600 0 : bp_pack_value (&bp, m, mode_bits);
3601 0 : bp_pack_enum (&bp, mode_class, MAX_MODE_CLASS, GET_MODE_CLASS (m));
3602 0 : bp_pack_poly_value (&bp, GET_MODE_SIZE (m), 16);
3603 0 : bp_pack_poly_value (&bp, GET_MODE_PRECISION (m), 16);
3604 0 : bp_pack_value (&bp, GET_MODE_INNER (m), mode_bits);
3605 0 : bp_pack_poly_value (&bp, GET_MODE_NUNITS (m), 16);
3606 0 : switch (GET_MODE_CLASS (m))
3607 : {
3608 0 : case MODE_FRACT:
3609 0 : case MODE_UFRACT:
3610 0 : case MODE_ACCUM:
3611 0 : case MODE_UACCUM:
3612 0 : bp_pack_value (&bp, GET_MODE_IBIT (m), 8);
3613 0 : bp_pack_value (&bp, GET_MODE_FBIT (m), 8);
3614 0 : break;
3615 0 : case MODE_FLOAT:
3616 0 : case MODE_DECIMAL_FLOAT:
3617 0 : bp_pack_string (ob, &bp, REAL_MODE_FORMAT (m)->name, true);
3618 0 : break;
3619 : default:
3620 : break;
3621 : }
3622 0 : bp_pack_string (ob, &bp, GET_MODE_NAME (m), true);
3623 : }
3624 0 : bp_pack_value (&bp, VOIDmode, mode_bits);
3625 :
3626 0 : streamer_write_bitpack (&bp);
3627 :
3628 0 : char *section_name
3629 0 : = lto_get_section_name (LTO_section_mode_table, NULL, 0, NULL);
3630 0 : lto_begin_section (section_name, !flag_wpa);
3631 0 : free (section_name);
3632 :
3633 : /* The entire header stream is computed here. */
3634 0 : struct lto_simple_header_with_strings header;
3635 0 : memset (&header, 0, sizeof (header));
3636 :
3637 0 : header.main_size = ob->main_stream->total_size;
3638 0 : header.string_size = ob->string_stream->total_size;
3639 0 : lto_write_data (&header, sizeof header);
3640 :
3641 : /* Put all of the gimple and the string table out the asm file as a
3642 : block of text. */
3643 0 : lto_write_stream (ob->main_stream);
3644 0 : lto_write_stream (ob->string_stream);
3645 :
3646 0 : lto_end_section ();
3647 0 : destroy_output_block (ob);
3648 0 : }
3649 :
3650 :
3651 : /* This pass is run after all of the functions are serialized and all
3652 : of the IPA passes have written their serialized forms. This pass
3653 : causes the vector of all of the global decls and types used from
3654 : this file to be written in to a section that can then be read in to
3655 : recover these on other side. */
3656 :
3657 : void
3658 32481 : produce_asm_for_decls (void)
3659 : {
3660 32481 : struct lto_out_decl_state *out_state;
3661 32481 : struct lto_out_decl_state *fn_out_state;
3662 32481 : struct lto_decl_header header;
3663 32481 : char *section_name;
3664 32481 : struct output_block *ob;
3665 32481 : unsigned idx, num_fns;
3666 32481 : size_t decl_state_size;
3667 32481 : int32_t num_decl_states;
3668 :
3669 32481 : ob = create_output_block (LTO_section_decls);
3670 :
3671 32481 : memset (&header, 0, sizeof (struct lto_decl_header));
3672 :
3673 32481 : section_name = lto_get_section_name (LTO_section_decls, NULL, 0, NULL);
3674 32481 : lto_begin_section (section_name, !flag_wpa);
3675 32481 : free (section_name);
3676 :
3677 : /* Make string 0 be a NULL string. */
3678 32481 : streamer_write_char_stream (ob->string_stream, 0);
3679 :
3680 32481 : gcc_assert (!alias_pairs);
3681 :
3682 : /* Get rid of the global decl state hash tables to save some memory. */
3683 32481 : out_state = lto_get_out_decl_state ();
3684 97443 : for (int i = 0; i < LTO_N_DECL_STREAMS; i++)
3685 32481 : if (out_state->streams[i].tree_hash_table)
3686 : {
3687 32481 : delete out_state->streams[i].tree_hash_table;
3688 32481 : out_state->streams[i].tree_hash_table = NULL;
3689 : }
3690 :
3691 : /* Write the global symbols. */
3692 32481 : if (streamer_dump_file)
3693 4 : fprintf (streamer_dump_file, "Outputting global stream\n");
3694 32481 : lto_output_decl_state_streams (ob, out_state);
3695 32481 : num_fns = lto_function_decl_states.length ();
3696 189559 : for (idx = 0; idx < num_fns; idx++)
3697 : {
3698 157078 : fn_out_state =
3699 157078 : lto_function_decl_states[idx];
3700 157078 : if (streamer_dump_file)
3701 24 : fprintf (streamer_dump_file, "Outputting stream for %s\n",
3702 12 : IDENTIFIER_POINTER
3703 : (DECL_ASSEMBLER_NAME (fn_out_state->fn_decl)));
3704 157078 : lto_output_decl_state_streams (ob, fn_out_state);
3705 : }
3706 :
3707 : /* Currently not used. This field would allow us to preallocate
3708 : the globals vector, so that it need not be resized as it is extended. */
3709 32481 : header.num_nodes = -1;
3710 :
3711 : /* Compute the total size of all decl out states. */
3712 32481 : decl_state_size = sizeof (int32_t);
3713 32481 : decl_state_size += lto_out_decl_state_written_size (out_state);
3714 189559 : for (idx = 0; idx < num_fns; idx++)
3715 : {
3716 157078 : fn_out_state =
3717 157078 : lto_function_decl_states[idx];
3718 157078 : decl_state_size += lto_out_decl_state_written_size (fn_out_state);
3719 : }
3720 32481 : header.decl_state_size = decl_state_size;
3721 :
3722 32481 : header.main_size = ob->main_stream->total_size;
3723 32481 : header.string_size = ob->string_stream->total_size;
3724 :
3725 32481 : lto_write_data (&header, sizeof header);
3726 :
3727 : /* Write the main out-decl state, followed by out-decl states of
3728 : functions. */
3729 32481 : num_decl_states = num_fns + 1;
3730 32481 : lto_write_data (&num_decl_states, sizeof (num_decl_states));
3731 32481 : lto_output_decl_state_refs (ob, out_state);
3732 222040 : for (idx = 0; idx < num_fns; idx++)
3733 : {
3734 157078 : fn_out_state = lto_function_decl_states[idx];
3735 157078 : lto_output_decl_state_refs (ob, fn_out_state);
3736 : }
3737 :
3738 32481 : lto_write_stream (ob->main_stream);
3739 32481 : lto_write_stream (ob->string_stream);
3740 :
3741 32481 : lto_end_section ();
3742 :
3743 : /* Write the symbol table. It is used by linker to determine dependencies
3744 : and thus we can skip it for WPA. */
3745 32481 : if (!flag_wpa)
3746 : {
3747 23943 : unsigned int streamed_symbols = produce_symtab (ob);
3748 23943 : produce_symtab_extension (ob, streamed_symbols);
3749 : }
3750 :
3751 : /* Write command line opts. */
3752 32481 : lto_write_options ();
3753 :
3754 : /* Deallocate memory and clean up. */
3755 222040 : for (idx = 0; idx < num_fns; idx++)
3756 : {
3757 157078 : fn_out_state =
3758 157078 : lto_function_decl_states[idx];
3759 157078 : lto_delete_out_decl_state (fn_out_state);
3760 : }
3761 32481 : lto_symtab_encoder_delete (ob->decl_state->symtab_node_encoder);
3762 32481 : lto_function_decl_states.release ();
3763 32481 : destroy_output_block (ob);
3764 32481 : if (lto_stream_offload_p)
3765 0 : lto_write_mode_table ();
3766 :
3767 : /* Copy or write the linemap section(s) as needed. For incremental LTO, we
3768 : copy them into the output file now. For WPA, we will copy them into a
3769 : dedicated file later. Otherwise, we create a new one from scratch and
3770 : output it now. */
3771 32481 : if (flag_incremental_link == INCREMENTAL_LINK_LTO)
3772 36 : lto_copy_linemaps ();
3773 32445 : else if (!flag_wpa)
3774 : {
3775 23907 : gcc_checking_assert (!in_lto_p);
3776 23907 : loc_output.produce_linemap_section ();
3777 : }
3778 32481 : }
|