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 350942 : 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 350942 : ob->current_block = void_node;
64 350942 : ob->current_discr = UINT_MAX;
65 350942 : ob->current_map_idx = 0;
66 350942 : ob->current_loc_offset = 0;
67 350942 : 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 350942 : create_output_block (enum lto_section_type section_type)
76 : {
77 350942 : struct output_block *ob = XCNEW (struct output_block);
78 350942 : 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 350942 : ob->section_type = section_type;
83 350942 : 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 350942 : if (!flag_wpa && section_type == LTO_section_decls)
87 23417 : ob->local_trees = new (hash_set <tree>);
88 350942 : ob->main_stream = XCNEW (struct lto_output_stream);
89 350942 : ob->string_stream = XCNEW (struct lto_output_stream);
90 350942 : ob->writer_cache = streamer_tree_cache_create (!flag_wpa, true, false);
91 :
92 350942 : if (section_type == LTO_section_function_body)
93 120310 : ob->cfg_stream = XCNEW (struct lto_output_stream);
94 :
95 350942 : clear_line_info (ob);
96 :
97 350942 : ob->string_hash_table = new hash_table<string_slot_hasher> (37);
98 350942 : gcc_obstack_init (&ob->obstack);
99 :
100 350942 : return ob;
101 : }
102 :
103 :
104 : /* Destroy the output block OB. */
105 :
106 : void
107 350942 : destroy_output_block (struct output_block *ob)
108 : {
109 350942 : enum lto_section_type section_type = ob->section_type;
110 :
111 350942 : delete ob->string_hash_table;
112 350942 : ob->string_hash_table = NULL;
113 374359 : delete ob->local_trees;
114 :
115 350942 : free (ob->main_stream);
116 350942 : free (ob->string_stream);
117 350942 : if (section_type == LTO_section_function_body)
118 120310 : free (ob->cfg_stream);
119 :
120 350942 : streamer_tree_cache_delete (ob->writer_cache);
121 350942 : obstack_free (&ob->obstack, NULL);
122 :
123 350942 : free (ob);
124 350942 : }
125 :
126 :
127 : /* Wrapper around variably_modified_type_p avoiding type modification
128 : during WPA streaming. */
129 :
130 : bool
131 14469743 : lto_variably_modified_type_p (tree type)
132 : {
133 14469743 : return (in_lto_p
134 14469743 : ? TYPE_LANG_FLAG_0 (TYPE_MAIN_VARIANT (type))
135 14165564 : : 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 36080659 : 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 34967145 : if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
151 36414559 : && DECL_CONTEXT (t))
152 1447414 : 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 34633245 : else if (TREE_CODE (t) == IMPORTED_DECL)
156 0 : gcc_unreachable ();
157 34633245 : else if (TREE_CODE (t) == LABEL_DECL)
158 81500 : return FORCED_LABEL (t) || DECL_NONLOCAL (t);
159 1677610 : 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 35448340 : && decl_function_context (t))
164 : return false;
165 33665037 : 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 33663103 : else if (TYPE_P (t)
172 33663103 : && lto_variably_modified_type_p (t))
173 : return false;
174 33651228 : else if (TREE_CODE (t) == FIELD_DECL
175 33651228 : && lto_variably_modified_type_p (DECL_CONTEXT (t)))
176 : return false;
177 : else
178 33650797 : 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 62769 : compute_map_hash (const line_map_ordinary *map)
190 : {
191 62769 : inchash::hash h;
192 62769 : h.add_int (map->sysp);
193 62769 : h.add_int (map->m_column_and_range_bits - map->m_range_bits);
194 62769 : h.add_int (map->to_line);
195 62769 : h.add_object (map->included_from);
196 62769 : h.add (map->to_file, strlen (map->to_file));
197 62769 : 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 20768 : void register_map_id (size_t map_idx, unsigned linemap_id)
220 : {
221 33646 : gcc_checking_assert (LINEMAPS_ORDINARY_USED (line_table)
222 : == orig_map_ids.length () + 1);
223 20768 : const auto map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
224 20768 : const hashval_t hash = compute_map_hash (map);
225 20768 : orig_map_ids.safe_push (map_id_t{map_idx, linemap_id, hash});
226 20768 : }
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 6979476 : location_output::record_location (location_t loc)
243 : {
244 : /* Strip away any macro expansion data or embedded range information. */
245 6979476 : loc = linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
246 : nullptr);
247 6979476 : loc = get_pure_location (loc);
248 6979476 : location_id_t loc_id = {};
249 6979476 : if (loc < RESERVED_LOCATION_COUNT)
250 : {
251 : /* IDX 0 is for reserved locations. */
252 2432732 : loc_id.offset = loc;
253 2432732 : return loc_id;
254 : }
255 :
256 4546744 : const auto map = linemap_check_ordinary (linemap_lookup (line_table, loc));
257 :
258 4546744 : 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 389158 : gcc_checking_assert (orig_map_ids.length ()
263 : == LINEMAPS_ORDINARY_USED (line_table));
264 194579 : gcc_checking_assert (!map->m_range_bits);
265 194579 : loc_id.map_id = orig_map_ids[map - line_table->info_ordinary.maps];
266 194579 : loc_id.offset = loc - map->start_location;
267 194579 : return loc_id;
268 : }
269 :
270 : /* Represent each location_t as the offset from the map start,
271 : without any range bits. */
272 4352165 : map_data &md = map_data_map.get_or_insert (map);
273 4352165 : if (!md.idx)
274 : {
275 42001 : md.idx = map_data_map.elements ();
276 42001 : md.hash = compute_map_hash (map);
277 : }
278 4352165 : md.highest_location = MAX (md.highest_location, loc);
279 4352165 : loc_id.map_id.idx = md.idx;
280 4352165 : loc_id.map_id.hash = md.hash;
281 4352165 : loc_id.offset = (loc - map->start_location) >> map->m_range_bits;
282 4352165 : 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 8920934 : bp_pack_delta (bitpack_d *bp, Int val, Int &prev)
291 : {
292 8920934 : const bool decrease = (val < prev);
293 8920934 : bp_pack_value (bp, decrease, 1);
294 8920934 : bp_pack_var_len_unsigned (bp, decrease ? prev - val : val - prev);
295 8920934 : prev = val;
296 8920934 : }
297 :
298 : void
299 23382 : location_output::produce_linemap_section ()
300 : {
301 23382 : timevar_push (TV_IPA_LTO_LINEMAP_OUT);
302 :
303 23382 : const auto ob = create_output_block (LTO_section_linemap);
304 23382 : 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 23382 : const auto &chist = global_dc->get_classification_history ();
311 90237 : for (auto &c : chist)
312 64139 : record_location (c.location);
313 :
314 : /* Sort the maps in the order they need to be inserted later. */
315 23382 : const size_t nmaps = map_data_map.elements ();
316 23382 : using KV = std::pair<const line_map_ordinary *, map_data>;
317 65383 : const std::unique_ptr<KV[]> sorted_maps{new KV[nmaps]};
318 23382 : size_t map_i = 0;
319 65383 : for (auto iter = map_data_map.begin (), end = map_data_map.end ();
320 65383 : iter != end; ++iter)
321 42001 : sorted_maps[map_i++] = *iter;
322 23382 : 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 23382 : bp_pack_var_len_unsigned (&bp, nmaps);
334 23382 : const char *current_file = nullptr;
335 23382 : bool emit_pwd = true;
336 23382 : size_t prev_idx = 0;
337 23382 : linenum_type prev_line = 0;
338 65383 : for (map_i = 0; map_i != nmaps; ++map_i)
339 : {
340 42001 : const auto map = sorted_maps[map_i].first;
341 42001 : const map_data &md = sorted_maps[map_i].second;
342 42001 : bp_pack_delta (&bp, md.idx, prev_idx);
343 42001 : const auto num_lines
344 42001 : = 1 + ((md.highest_location - map->start_location)
345 42001 : >> map->m_column_and_range_bits);
346 42001 : bp_pack_var_len_unsigned (&bp, num_lines);
347 42001 : bp_pack_value (&bp, map->sysp != 0, 1);
348 42001 : bp_pack_value (&bp, map->m_column_and_range_bits - map->m_range_bits, 8);
349 42001 : bp_pack_delta (&bp, map->to_line, prev_line);
350 42001 : const bool file_change = (map->to_file != current_file);
351 42001 : bp_pack_value (&bp, file_change, 1);
352 42001 : if (file_change)
353 : {
354 42001 : bool stream_pwd = false;
355 42001 : const char *remapped = remap_debug_filename (map->to_file);
356 42001 : if (emit_pwd && remapped && !IS_ABSOLUTE_PATH (remapped))
357 : {
358 1755 : stream_pwd = true;
359 1755 : emit_pwd = false;
360 : }
361 42001 : bp_pack_value (&bp, stream_pwd, 1);
362 42001 : if (stream_pwd)
363 1755 : bp_pack_string (ob, &bp, get_src_pwd (), true);
364 42001 : bp_pack_string (ob, &bp, remapped, true);
365 : }
366 : }
367 :
368 : /* Output the diagnostics classification history. */
369 24740 : bp_pack_var_len_unsigned (&bp, chist.length ());
370 90237 : for (auto &c : chist)
371 : {
372 64139 : const location_id_t loc_id = record_location (c.location);
373 64139 : bp_pack_var_len_unsigned (&bp, loc_id.map_id.idx);
374 64139 : bp_pack_var_len_unsigned (&bp, loc_id.offset);
375 64139 : bp_pack_var_len_int (&bp, c.option);
376 64139 : using DK = diagnostics::kind;
377 64139 : bp_pack_enum (&bp, DK, DK::tot_num_diagnostic_kinds, c.kind);
378 : }
379 :
380 : /* Finalize the section. */
381 23382 : streamer_write_bitpack (&bp);
382 23382 : {
383 23382 : const auto section_name
384 23382 : = lto_get_section_name (LTO_section_linemap, nullptr, 0, nullptr);
385 23382 : lto_begin_section (section_name, true);
386 23382 : free (section_name);
387 : }
388 :
389 23382 : lto_simple_header_with_strings header = {};
390 23382 : header.main_size = ob->main_stream->total_size;
391 23382 : header.string_size = ob->string_stream->total_size;
392 23382 : lto_write_data (&header, sizeof header);
393 23382 : lto_write_stream (ob->main_stream);
394 23382 : lto_write_stream (ob->string_stream);
395 23382 : lto_end_section ();
396 23382 : destroy_output_block (ob);
397 :
398 23382 : timevar_pop (TV_IPA_LTO_LINEMAP_OUT);
399 23382 : }
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 6851198 : lto_output_location_1 (struct output_block *ob, struct bitpack_d *bp,
410 : location_t loc, bool block_p)
411 : {
412 6851198 : const auto loc_id = loc_output.record_location (loc);
413 6851198 : if (!loc_id.map_id.idx)
414 : {
415 2432732 : bp_pack_value (bp, true, 1);
416 2432732 : bp_pack_int_in_range (bp, 0, RESERVED_LOCATION_COUNT - 1, loc_id.offset);
417 : }
418 : else
419 : {
420 4418466 : bp_pack_value (bp, false, 1);
421 4418466 : if (loc_id.map_id.linemap_id == ob->current_linemap_id)
422 4275893 : bp_pack_value (bp, false, 1);
423 : else
424 : {
425 142573 : bp_pack_value (bp, true, 1);
426 142573 : bp_pack_var_len_unsigned (bp, loc_id.map_id.linemap_id);
427 142573 : ob->current_linemap_id = loc_id.map_id.linemap_id;
428 : }
429 4418466 : const bool is_new_map = (loc_id.map_id.idx != ob->current_map_idx);
430 4418466 : bp_pack_delta (bp, loc_id.map_id.idx, ob->current_map_idx);
431 4418466 : bp_pack_delta (bp, loc_id.offset, ob->current_loc_offset);
432 4418466 : if (is_new_map)
433 225172 : bp_pack_var_len_unsigned (bp, loc_id.map_id.hash);
434 4418466 : const unsigned discr = get_discriminator_from_loc (loc);
435 4418466 : bp_pack_value (bp, ob->current_discr != discr, 1);
436 4418466 : if (ob->current_discr != discr)
437 : {
438 1323125 : bp_pack_var_len_unsigned (bp, discr);
439 1323125 : ob->current_discr = discr;
440 : }
441 : }
442 :
443 6851198 : if (block_p)
444 : {
445 2984095 : tree block = LOCATION_BLOCK (loc);
446 2984095 : bp_pack_value (bp, ob->current_block != block, 1);
447 2984095 : streamer_write_bitpack (bp);
448 2984095 : if (ob->current_block != block)
449 : {
450 651065 : lto_output_tree (ob, block, true, true);
451 651065 : ob->current_block = block;
452 : }
453 : }
454 6851198 : }
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 3867103 : lto_output_location (struct output_block *ob, struct bitpack_d *bp,
462 : location_t loc)
463 : {
464 3867103 : lto_output_location_1 (ob, bp, loc, false);
465 3867103 : }
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 2984095 : lto_output_location_and_block (struct output_block *ob, struct bitpack_d *bp,
474 : location_t loc)
475 : {
476 2984095 : lto_output_location_1 (ob, bp, loc, true);
477 2984095 : }
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 8047279 : lto_get_index (struct lto_tree_ref_encoder *encoder, tree t)
488 : {
489 8047279 : bool existed_p;
490 :
491 8047279 : unsigned int &index
492 8047279 : = encoder->tree_hash_table->get_or_insert (t, &existed_p);
493 8047279 : if (!existed_p)
494 : {
495 2221451 : index = encoder->trees.length ();
496 2221451 : 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 2221451 : encoder->trees.safe_push (t);
503 : }
504 :
505 8047279 : 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 9563663 : lto_indexable_tree_ref (struct output_block *ob, tree expr,
515 : enum LTO_tags *tag, unsigned *index)
516 : {
517 9563663 : gcc_checking_assert (tree_is_indexable (expr));
518 :
519 9563663 : if (TREE_CODE (expr) == SSA_NAME)
520 : {
521 2230868 : *tag = LTO_ssa_name_ref;
522 2230868 : *index = SSA_NAME_VERSION (expr);
523 : }
524 : else
525 : {
526 7332795 : *tag = LTO_global_stream_ref;
527 7332795 : *index = lto_get_index (&ob->decl_state->streams[LTO_DECL_STREAM], expr);
528 : }
529 9563663 : }
530 :
531 :
532 : /* Output a static or extern var DECL to OBS. */
533 :
534 : void
535 290544 : lto_output_var_decl_ref (struct lto_out_decl_state *decl_state,
536 : struct lto_output_stream * obs, tree decl)
537 : {
538 290544 : gcc_checking_assert (VAR_P (decl));
539 290544 : streamer_write_uhwi_stream
540 290544 : (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM],
541 : decl));
542 290544 : }
543 :
544 :
545 : /* Output a static or extern var DECL to OBS. */
546 :
547 : void
548 423940 : lto_output_fn_decl_ref (struct lto_out_decl_state *decl_state,
549 : struct lto_output_stream * obs, tree decl)
550 : {
551 423940 : gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
552 423940 : streamer_write_uhwi_stream
553 423940 : (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM], decl));
554 423940 : }
555 :
556 : /* Return true if EXPR is a tree node that can be written to disk. */
557 :
558 : static inline bool
559 7169803 : lto_is_streamable (tree expr)
560 : {
561 7169803 : 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 7169803 : return !is_lang_specific (expr)
566 7169803 : && code != SSA_NAME
567 7169803 : && code != LANG_TYPE
568 : && code != MODIFY_EXPR
569 7169803 : && code != INIT_EXPR
570 7169803 : && code != TARGET_EXPR
571 7169803 : && code != BIND_EXPR
572 7169803 : && code != WITH_CLEANUP_EXPR
573 7169803 : && code != STATEMENT_LIST
574 7169803 : && (code == CASE_LABEL_EXPR
575 7169803 : || code == DECL_EXPR
576 7161772 : || code == ASM_EXPR
577 7161732 : || 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 102166 : subtract_estimated_size (tree *tp, int *ws, void *data)
589 : {
590 102166 : long *sum = (long *)data;
591 102166 : 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 102166 : if (TREE_CODE (*tp) == STRING_CST)
600 7893 : *sum -= TREE_STRING_LENGTH (*tp) + 8;
601 : else
602 : {
603 : /* Identifiers are also variable length but should not appear
604 : naked in constructor. */
605 94273 : 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 94273 : *sum -= 16;
609 : }
610 102166 : if (*sum < 0)
611 33443 : 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 2452456 : get_symbol_initial_value (lto_symtab_encoder_t encoder, tree expr)
620 : {
621 2452456 : 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 2452456 : tree initial = DECL_INITIAL (expr);
627 2452456 : if (VAR_P (expr)
628 1218754 : && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
629 864016 : && !DECL_IN_CONSTANT_POOL (expr)
630 3316340 : && initial)
631 : {
632 86576 : varpool_node *vnode;
633 : /* Extra section needs about 30 bytes; do not produce it for simple
634 : scalar values. */
635 86576 : if (!(vnode = varpool_node::get (expr))
636 86576 : || !lto_symtab_encoder_encode_initializer_p (encoder, vnode))
637 3289 : initial = error_mark_node;
638 86576 : if (initial != error_mark_node)
639 : {
640 69569 : long max_size = 30;
641 69569 : if (walk_tree (&initial, subtract_estimated_size, (void *)&max_size,
642 : NULL))
643 33443 : initial = error_mark_node;
644 : }
645 : }
646 :
647 2452456 : 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 32513325 : stream_write_tree_ref (struct output_block *ob, tree t)
658 : {
659 32513325 : if (!t)
660 12418738 : streamer_write_zero (ob);
661 : else
662 : {
663 20094587 : unsigned int ix;
664 20094587 : bool existed_p = streamer_tree_cache_lookup (ob->writer_cache, t, &ix);
665 20094587 : if (existed_p)
666 15609992 : streamer_write_hwi (ob, ix + 1);
667 : else
668 : {
669 4484595 : enum LTO_tags tag;
670 4484595 : unsigned ix;
671 4484595 : int id = 0;
672 :
673 4484595 : lto_indexable_tree_ref (ob, t, &tag, &ix);
674 4484595 : if (tag == LTO_ssa_name_ref)
675 : id = 1;
676 : else
677 4275569 : gcc_checking_assert (tag == LTO_global_stream_ref);
678 4484595 : streamer_write_hwi (ob, -(int)(ix * 2 + id + 1));
679 : }
680 : }
681 32513325 : }
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 7169803 : lto_write_tree_1 (struct output_block *ob, tree expr, bool ref_p)
692 : {
693 7169803 : 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 7169803 : streamer_write_tree_bitfields (ob, expr);
704 :
705 : /* Write all the pointer fields in EXPR. */
706 7169803 : streamer_write_tree_body (ob, expr);
707 :
708 : /* Write any LTO-specific data to OB. */
709 7169803 : if (DECL_P (expr)
710 1550992 : && TREE_CODE (expr) != FUNCTION_DECL
711 1113185 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
712 : {
713 : /* Handle DECL_INITIAL for symbols. */
714 1081040 : tree initial = get_symbol_initial_value
715 1081040 : (ob->decl_state->symtab_node_encoder, expr);
716 1081040 : 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 7169803 : if ((DECL_P (expr)
722 : && TREE_CODE (expr) != FIELD_DECL
723 : && TREE_CODE (expr) != DEBUG_EXPR_DECL
724 : && TREE_CODE (expr) != TYPE_DECL)
725 5759796 : || TREE_CODE (expr) == BLOCK)
726 : {
727 1765071 : const char *sym;
728 1765071 : unsigned HOST_WIDE_INT off;
729 1765071 : if (debug_info_level > DINFO_LEVEL_NONE
730 1765071 : && debug_hooks->die_ref_for_decl (expr, &sym, &off))
731 : {
732 49506 : streamer_write_string (ob, ob->main_stream, sym, true);
733 49506 : streamer_write_uhwi (ob, off);
734 : }
735 : else
736 1715565 : streamer_write_string (ob, ob->main_stream, NULL, true);
737 : }
738 7169803 : }
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 6888538 : lto_write_tree (struct output_block *ob, tree expr, bool ref_p)
747 : {
748 6888538 : 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 6888538 : streamer_write_tree_header (ob, expr);
755 :
756 6888538 : lto_write_tree_1 (ob, expr, ref_p);
757 6888538 : }
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 7966056 : lto_output_tree_1 (struct output_block *ob, tree expr, hashval_t hash,
765 : bool ref_p, bool this_ref_p)
766 : {
767 7966056 : unsigned ix;
768 :
769 7966056 : gcc_checking_assert (expr != NULL_TREE
770 : && !(this_ref_p && tree_is_indexable (expr)));
771 :
772 7966056 : bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
773 : expr, hash, &ix);
774 7966056 : gcc_assert (!exists_p);
775 7966056 : if (TREE_CODE (expr) == INTEGER_CST
776 7966056 : && !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 1077518 : 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 6888538 : lto_write_tree (ob, expr, ref_p);
788 : }
789 7966056 : }
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 2909827 : local_tree_p (tree t)
850 : {
851 2909827 : switch (TREE_CODE (t))
852 : {
853 : case LABEL_DECL:
854 : return true;
855 1674 : case NAMESPACE_DECL:
856 1674 : return !DECL_NAME (t);
857 623038 : case VAR_DECL:
858 623038 : case FUNCTION_DECL:
859 623038 : return !TREE_PUBLIC (t) && !DECL_EXTERNAL (t);
860 75450 : case RECORD_TYPE:
861 75450 : case UNION_TYPE:
862 75450 : case ENUMERAL_TYPE:
863 : /* Anonymous namespace types are local.
864 : Only work hard for main variants;
865 : variant types will inherit locality. */
866 75450 : return TYPE_MAIN_VARIANT (t) == t
867 60271 : && odr_type_p (t) && type_with_linkage_p (t)
868 96127 : && 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 3024381 : DFS::DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p,
881 3024381 : bool single_p)
882 : {
883 3024381 : unsigned int next_dfs_num = 1;
884 :
885 3024381 : max_local_entry = -1;
886 3024381 : gcc_obstack_init (&sccstate_obstack);
887 3024381 : DFS_write_tree (ob, NULL, expr, ref_p, this_ref_p);
888 22023317 : while (!worklist_vec.is_empty ())
889 : {
890 18055106 : worklist &w = worklist_vec.last ();
891 18055106 : expr = w.expr;
892 18055106 : sccs *from_state = w.from_state;
893 18055106 : sccs *cstate = w.cstate;
894 18055106 : ref_p = w.ref_p;
895 18055106 : this_ref_p = w.this_ref_p;
896 18055106 : if (cstate == NULL)
897 : {
898 9796835 : sccs **slot = &sccstate.get_or_insert (expr);
899 9796835 : cstate = *slot;
900 9796835 : if (cstate)
901 : {
902 1538564 : gcc_checking_assert (from_state);
903 1538564 : if (cstate->dfsnum < from_state->dfsnum)
904 196396 : from_state->low = MIN (cstate->dfsnum, from_state->low);
905 1538564 : worklist_vec.pop ();
906 1538564 : continue;
907 : }
908 :
909 8258271 : scc_entry e = { expr, 0 };
910 : /* Not yet visited. DFS recurse and push it onto the stack. */
911 8258271 : *slot = cstate = XOBNEW (&sccstate_obstack, struct sccs);
912 8258271 : if (ob->local_trees && local_tree_p (expr))
913 87656 : max_local_entry = sccstack.length ();
914 8258271 : sccstack.safe_push (e);
915 8258271 : cstate->dfsnum = next_dfs_num++;
916 8258271 : cstate->low = cstate->dfsnum;
917 8258271 : w.cstate = cstate;
918 :
919 8258271 : if (TREE_CODE (expr) == INTEGER_CST
920 8258271 : && !TREE_OVERFLOW (expr))
921 1123334 : DFS_write_tree (ob, cstate, TREE_TYPE (expr), ref_p, ref_p);
922 : else
923 : {
924 7134937 : DFS_write_tree_body (ob, expr, cstate, ref_p);
925 :
926 : /* Walk any LTO-specific edges. */
927 7134937 : if (DECL_P (expr)
928 1554702 : && TREE_CODE (expr) != FUNCTION_DECL
929 1116895 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
930 : {
931 : /* Handle DECL_INITIAL for symbols. */
932 1084750 : tree initial
933 1084750 : = get_symbol_initial_value (ob->decl_state->symtab_node_encoder,
934 : expr);
935 1084750 : DFS_write_tree (ob, cstate, initial, ref_p, ref_p);
936 : }
937 : }
938 8258271 : continue;
939 8258271 : }
940 :
941 : /* See if we found an SCC. */
942 8258271 : if (cstate->low == cstate->dfsnum)
943 : {
944 8050180 : unsigned first, size;
945 8050180 : 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 8050180 : if (single_p)
950 : {
951 347 : worklist_vec.pop ();
952 347 : continue;
953 : }
954 :
955 : /* Pop the SCC and compute its size. */
956 16099666 : first = sccstack.length ();
957 8247321 : do
958 : {
959 8247321 : x = sccstack[--first].t;
960 : }
961 8247321 : while (x != expr);
962 8049833 : size = sccstack.length () - first;
963 :
964 : /* No need to compute hashes for LTRANS units, we don't perform
965 : any merging there. */
966 8049833 : hashval_t scc_hash = 0;
967 8049833 : unsigned scc_entry_len = 0;
968 21449621 : bool local_to_unit = !ob->local_trees
969 8049833 : || max_local_entry >= (int)first;
970 :
971 : /* Remember that trees are local so info gets propagated to other
972 : SCCs. */
973 5349955 : if (local_to_unit && ob->local_trees)
974 : {
975 97800 : for (unsigned i = 0; i < size; ++i)
976 50384 : 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 8049833 : if (size == 1
984 8049833 : && TREE_CODE (sccstack[first].t) == TRANSLATION_UNIT_DECL)
985 : local_to_unit = true;
986 :
987 8017688 : if (!local_to_unit)
988 : {
989 2676675 : 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 2676675 : unsigned entry_start = 0;
993 2676675 : scc_entry_len = size + 1;
994 5501965 : for (unsigned i = 0; i < size;)
995 : {
996 2825290 : unsigned from = i;
997 2825290 : for (i = i + 1; i < size
998 2825290 : && (sccstack[first + i].hash
999 148615 : == sccstack[first + from].hash); ++i)
1000 : ;
1001 2825290 : if (i - from < scc_entry_len)
1002 : {
1003 2676675 : scc_entry_len = i - from;
1004 2676675 : entry_start = from;
1005 : }
1006 : }
1007 5353350 : for (unsigned i = 0; i < scc_entry_len; ++i)
1008 2676675 : std::swap (sccstack[first + i],
1009 2676675 : 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 2676675 : gcc_checking_assert (scc_entry_len == 1);
1017 : }
1018 :
1019 8049833 : worklist_vec.pop ();
1020 :
1021 8049833 : unsigned int prev_size = ob->main_stream->total_size;
1022 :
1023 : /* Only global decl sections are considered by tree merging. */
1024 8049833 : 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 4559178 : if (worklist_vec.is_empty () && first == 0 && size == 1)
1029 : return;
1030 2478627 : if (streamer_dump_file)
1031 : {
1032 140 : fprintf (streamer_dump_file,
1033 : " Start of LTO_trees of size %i\n", size);
1034 : }
1035 2478627 : streamer_write_record_start (ob, LTO_trees);
1036 2478627 : streamer_write_uhwi (ob, size);
1037 : }
1038 : /* Write LTO_tree_scc if tree merging is going to be performed. */
1039 3490655 : 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 3490655 : && (size != 1
1045 2608864 : || (TREE_CODE (sccstack[first].t) != IDENTIFIER_NODE
1046 1723040 : && (TREE_CODE (sccstack[first].t) != INTEGER_CST
1047 157974 : || TREE_OVERFLOW (sccstack[first].t)))))
1048 :
1049 : {
1050 1632879 : gcc_checking_assert (ob->section_type == LTO_section_decls);
1051 1632879 : if (streamer_dump_file)
1052 : {
1053 172 : fprintf (streamer_dump_file,
1054 : " Start of LTO_tree_scc of size %i\n", size);
1055 : }
1056 1632879 : 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 1632879 : streamer_write_uhwi (ob, size * 2 + (scc_entry_len != 1));
1061 1632879 : if (scc_entry_len != 1)
1062 0 : streamer_write_uhwi (ob, scc_entry_len);
1063 1632879 : streamer_write_uhwi (ob, scc_hash);
1064 : }
1065 : /* Non-trivial SCCs must be packed to trees blocks so forward
1066 : references work correctly. */
1067 1857776 : else if (size != 1)
1068 : {
1069 15830 : if (streamer_dump_file)
1070 : {
1071 0 : fprintf (streamer_dump_file,
1072 : " Start of LTO_trees of size %i\n", size);
1073 : }
1074 15830 : streamer_write_record_start (ob, LTO_trees);
1075 15830 : streamer_write_uhwi (ob, size);
1076 : }
1077 1841946 : 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 5969282 : if (size == 1)
1087 5885505 : 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 365042 : for (unsigned i = 0; i < size; ++i)
1093 : {
1094 281265 : hashval_t hash = sccstack[first+i].hash;
1095 281265 : tree t = sccstack[first+i].t;
1096 281265 : bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
1097 : t, hash, NULL);
1098 281265 : gcc_assert (!exists_p);
1099 :
1100 281265 : 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 281265 : streamer_write_tree_header (ob, t);
1108 : }
1109 :
1110 : /* Write the bitpacks and tree references. */
1111 365042 : for (unsigned i = 0; i < size; ++i)
1112 281265 : lto_write_tree_1 (ob, sccstack[first+i].t, ref_p);
1113 : }
1114 5969282 : 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 5969282 : sccstack.truncate (first);
1120 5969282 : if ((int)first <= max_local_entry)
1121 47416 : max_local_entry = first - 1;
1122 :
1123 5969282 : if (from_state)
1124 5025799 : from_state->low = MIN (from_state->low, cstate->low);
1125 5969282 : continue;
1126 5969282 : }
1127 :
1128 208091 : gcc_checking_assert (from_state);
1129 208091 : from_state->low = MIN (from_state->low, cstate->low);
1130 208091 : if (cstate->dfsnum < from_state->dfsnum)
1131 0 : from_state->low = MIN (cstate->dfsnum, from_state->low);
1132 208091 : worklist_vec.pop ();
1133 : }
1134 : }
1135 :
1136 3024381 : DFS::~DFS ()
1137 : {
1138 3024381 : obstack_free (&sccstate_obstack, NULL);
1139 3024381 : }
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 7134937 : 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 7134937 : enum tree_code code;
1152 :
1153 7134937 : code = TREE_CODE (expr);
1154 :
1155 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
1156 : {
1157 6717178 : if (TREE_CODE (expr) != IDENTIFIER_NODE)
1158 5207221 : DFS_follow_tree_edge (TREE_TYPE (expr));
1159 : }
1160 :
1161 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
1162 : {
1163 5980 : unsigned int count = vector_cst_encoded_nelts (expr);
1164 31737 : for (unsigned int i = 0; i < count; ++i)
1165 19777 : DFS_follow_tree_edge (VECTOR_CST_ENCODED_ELT (expr, i));
1166 : }
1167 :
1168 7134937 : 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 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
1173 : {
1174 8011 : DFS_follow_tree_edge (TREE_REALPART (expr));
1175 8011 : DFS_follow_tree_edge (TREE_IMAGPART (expr));
1176 : }
1177 :
1178 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
1179 : {
1180 : /* Drop names that were created for anonymous entities. */
1181 1554702 : if (DECL_NAME (expr)
1182 1368870 : && TREE_CODE (DECL_NAME (expr)) == IDENTIFIER_NODE
1183 2923572 : && IDENTIFIER_ANON_P (DECL_NAME (expr)))
1184 : ;
1185 : else
1186 1554089 : DFS_follow_tree_edge (DECL_NAME (expr));
1187 1554702 : if (TREE_CODE (expr) != TRANSLATION_UNIT_DECL
1188 1554702 : && ! DECL_CONTEXT (expr))
1189 15598 : DFS_follow_tree_edge ((*all_translation_units)[0]);
1190 : else
1191 1539104 : DFS_follow_tree_edge (DECL_CONTEXT (expr));
1192 : }
1193 :
1194 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1195 : {
1196 1554702 : DFS_follow_tree_edge (DECL_SIZE (expr));
1197 1554702 : 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 1554702 : 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 1554702 : gcc_assert (DECL_ABSTRACT_ORIGIN (expr) != error_mark_node);
1208 1554702 : DFS_follow_tree_edge (DECL_ABSTRACT_ORIGIN (expr));
1209 :
1210 1554702 : if ((VAR_P (expr)
1211 1554702 : || TREE_CODE (expr) == PARM_DECL)
1212 1554702 : && DECL_HAS_VALUE_EXPR_P (expr))
1213 6632 : DFS_follow_tree_edge (DECL_VALUE_EXPR (expr));
1214 1554702 : if (VAR_P (expr)
1215 1554702 : && DECL_HAS_DEBUG_EXPR_P (expr))
1216 1702 : DFS_follow_tree_edge (DECL_DEBUG_EXPR (expr));
1217 : }
1218 :
1219 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1220 : {
1221 : /* Make sure we don't inadvertently set the assembler name. */
1222 934845 : if (DECL_ASSEMBLER_NAME_SET_P (expr))
1223 753933 : DFS_follow_tree_edge (DECL_ASSEMBLER_NAME (expr));
1224 : }
1225 :
1226 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
1227 : {
1228 115490 : DFS_follow_tree_edge (DECL_FIELD_OFFSET (expr));
1229 115490 : DFS_follow_tree_edge (DECL_BIT_FIELD_TYPE (expr));
1230 115490 : DFS_follow_tree_edge (DECL_BIT_FIELD_REPRESENTATIVE (expr));
1231 115490 : DFS_follow_tree_edge (DECL_FIELD_BIT_OFFSET (expr));
1232 115490 : gcc_checking_assert (!DECL_FCONTEXT (expr));
1233 : }
1234 :
1235 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1236 : {
1237 437807 : gcc_checking_assert (DECL_VINDEX (expr) == NULL);
1238 437807 : DFS_follow_tree_edge (DECL_FUNCTION_PERSONALITY (expr));
1239 437807 : DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_TARGET (expr));
1240 437807 : DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr));
1241 : }
1242 :
1243 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1244 : {
1245 668560 : DFS_follow_tree_edge (TYPE_SIZE (expr));
1246 668560 : DFS_follow_tree_edge (TYPE_SIZE_UNIT (expr));
1247 668560 : DFS_follow_tree_edge (TYPE_ATTRIBUTES (expr));
1248 668560 : 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 668560 : DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr));
1254 668560 : 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 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1263 : {
1264 668560 : if (TREE_CODE (expr) == ARRAY_TYPE)
1265 47063 : DFS_follow_tree_edge (TYPE_DOMAIN (expr));
1266 621497 : else if (RECORD_OR_UNION_TYPE_P (expr))
1267 249367 : for (tree t = TYPE_FIELDS (expr); t; t = TREE_CHAIN (t))
1268 152977 : DFS_follow_tree_edge (t);
1269 525107 : else if (FUNC_OR_METHOD_TYPE_P (expr))
1270 177528 : DFS_follow_tree_edge (TYPE_ARG_TYPES (expr));
1271 :
1272 668560 : if (!POINTER_TYPE_P (expr))
1273 404637 : DFS_follow_tree_edge (TYPE_MIN_VALUE_RAW (expr));
1274 668560 : DFS_follow_tree_edge (TYPE_MAX_VALUE_RAW (expr));
1275 : }
1276 :
1277 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1278 : {
1279 690759 : DFS_follow_tree_edge (TREE_PURPOSE (expr));
1280 690759 : DFS_follow_tree_edge (TREE_VALUE (expr));
1281 690759 : DFS_follow_tree_edge (TREE_CHAIN (expr));
1282 : }
1283 :
1284 7134937 : 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 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_EXP))
1291 : {
1292 4225823 : for (int i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
1293 2486442 : DFS_follow_tree_edge (TREE_OPERAND (expr, i));
1294 1739381 : DFS_follow_tree_edge (TREE_BLOCK (expr));
1295 : }
1296 :
1297 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1298 : {
1299 502682 : 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 147618 : gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
1305 147618 : DFS_follow_tree_edge (t);
1306 : }
1307 :
1308 355064 : DFS_follow_tree_edge (BLOCK_SUPERCONTEXT (expr));
1309 355064 : 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 7134937 : 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 7134937 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1341 : {
1342 : unsigned i;
1343 : tree index, value;
1344 :
1345 771319 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr), i, index, value)
1346 : {
1347 533026 : DFS_follow_tree_edge (index);
1348 533026 : DFS_follow_tree_edge (value);
1349 : }
1350 : }
1351 :
1352 7134937 : if (code == RAW_DATA_CST)
1353 21 : DFS_follow_tree_edge (RAW_DATA_OWNER (expr));
1354 :
1355 7134937 : if (code == OMP_CLAUSE)
1356 : {
1357 : int i;
1358 600 : for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (expr)]; i++)
1359 384 : DFS_follow_tree_edge (OMP_CLAUSE_OPERAND (expr, i));
1360 216 : DFS_follow_tree_edge (OMP_CLAUSE_CHAIN (expr));
1361 : }
1362 :
1363 : #undef DFS_follow_tree_edge
1364 7134937 : }
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 2825290 : hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, tree t)
1372 : {
1373 2825290 : 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 2825290 : enum tree_code code = TREE_CODE (t);
1390 2825290 : hstate.add_int (code);
1391 2825290 : if (!TYPE_P (t))
1392 : {
1393 2360893 : hstate.add_flag (TREE_SIDE_EFFECTS (t));
1394 2360893 : hstate.add_flag (TREE_CONSTANT (t));
1395 2360893 : hstate.add_flag (TREE_READONLY (t));
1396 2360893 : hstate.add_flag (TREE_PUBLIC (t));
1397 : }
1398 2825290 : hstate.add_flag (TREE_ADDRESSABLE (t));
1399 2825290 : hstate.add_flag (TREE_THIS_VOLATILE (t));
1400 2825290 : if (DECL_P (t))
1401 687950 : hstate.add_flag (DECL_UNSIGNED (t));
1402 2137340 : else if (TYPE_P (t))
1403 464397 : hstate.add_flag (TYPE_UNSIGNED (t));
1404 2825290 : if (TYPE_P (t))
1405 464397 : hstate.add_flag (TYPE_ARTIFICIAL (t));
1406 : else
1407 2360893 : hstate.add_flag (TREE_NO_WARNING (t));
1408 2825290 : hstate.add_flag (TREE_NOTHROW (t));
1409 2825290 : hstate.add_flag (TREE_STATIC (t));
1410 2825290 : hstate.add_flag (TREE_PROTECTED (t));
1411 2825290 : hstate.add_flag (TREE_DEPRECATED (t));
1412 2825290 : if (code != TREE_BINFO)
1413 2818946 : hstate.add_flag (TREE_PRIVATE (t));
1414 2825290 : if (TYPE_P (t))
1415 : {
1416 464397 : hstate.add_flag (AGGREGATE_TYPE_P (t)
1417 464397 : ? TYPE_REVERSE_STORAGE_ORDER (t) : TYPE_SATURATING (t));
1418 464397 : hstate.add_flag (TYPE_ADDR_SPACE (t));
1419 : }
1420 2360893 : else if (code == SSA_NAME)
1421 0 : hstate.add_flag (SSA_NAME_IS_DEFAULT_DEF (t));
1422 2825290 : hstate.commit_flag ();
1423 :
1424 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
1425 189638 : hstate.add_wide_int (wi::to_widest (t));
1426 :
1427 2825290 : 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 2825290 : 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 2825290 : 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 687950 : 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 687950 : && AGGREGATE_TYPE_P (TREE_TYPE (t)))
1457 0 : hstate.add_hwi (VOIDmode);
1458 : else
1459 687950 : hstate.add_hwi (DECL_MODE (t));
1460 687950 : hstate.add_flag (DECL_NONLOCAL (t));
1461 687950 : hstate.add_flag (DECL_VIRTUAL_P (t));
1462 687950 : hstate.add_flag (DECL_IGNORED_P (t));
1463 687950 : hstate.add_flag (DECL_ABSTRACT_P (t));
1464 687950 : hstate.add_flag (DECL_ARTIFICIAL (t));
1465 687950 : hstate.add_flag (DECL_USER_ALIGN (t));
1466 687950 : hstate.add_flag (DECL_PRESERVE_P (t));
1467 687950 : hstate.add_flag (DECL_EXTERNAL (t));
1468 687950 : hstate.add_flag (DECL_NOT_GIMPLE_REG_P (t));
1469 687950 : hstate.commit_flag ();
1470 687950 : hstate.add_int (DECL_ALIGN (t));
1471 687950 : 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 687950 : else if (code == FIELD_DECL)
1477 : {
1478 82831 : hstate.add_flag (DECL_PACKED (t));
1479 82831 : hstate.add_flag (DECL_NONADDRESSABLE_P (t));
1480 82831 : hstate.add_flag (DECL_PADDING_P (t));
1481 82831 : if (DECL_BIT_FIELD (t))
1482 5038 : hstate.add_flag (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (t));
1483 : else
1484 159411 : hstate.add_flag (DECL_FIELD_ABI_IGNORED (t));
1485 82831 : hstate.add_int (DECL_OFFSET_ALIGN (t));
1486 : }
1487 605119 : else if (code == VAR_DECL)
1488 : {
1489 235755 : hstate.add_flag (DECL_HAS_DEBUG_EXPR_P (t));
1490 235755 : hstate.add_flag (DECL_NONLOCAL_FRAME (t));
1491 : }
1492 687950 : if (code == RESULT_DECL
1493 687950 : || code == PARM_DECL
1494 : || code == VAR_DECL)
1495 : {
1496 235767 : hstate.add_flag (DECL_BY_REFERENCE (t));
1497 235767 : if (code == VAR_DECL
1498 235767 : || code == PARM_DECL)
1499 235767 : hstate.add_flag (DECL_HAS_VALUE_EXPR_P (t));
1500 : }
1501 687950 : hstate.commit_flag ();
1502 : }
1503 :
1504 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1505 605115 : hstate.add_int (DECL_REGISTER (t));
1506 :
1507 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1508 : {
1509 605103 : hstate.add_flag (DECL_COMMON (t));
1510 605103 : hstate.add_flag (DECL_DLLIMPORT_P (t));
1511 605103 : hstate.add_flag (DECL_WEAK (t));
1512 605103 : hstate.add_flag (DECL_SEEN_IN_BIND_EXPR_P (t));
1513 605103 : hstate.add_flag (DECL_COMDAT (t));
1514 605103 : hstate.add_flag (DECL_VISIBILITY_SPECIFIED (t));
1515 605103 : hstate.add_int (DECL_VISIBILITY (t));
1516 605103 : if (code == VAR_DECL)
1517 : {
1518 : /* DECL_IN_TEXT_SECTION is set during final asm output only. */
1519 235755 : hstate.add_flag (DECL_HARD_REGISTER (t));
1520 235755 : hstate.add_flag (DECL_IN_CONSTANT_POOL (t));
1521 : }
1522 605103 : if (TREE_CODE (t) == FUNCTION_DECL)
1523 : {
1524 346278 : hstate.add_flag (DECL_FINAL_P (t));
1525 346278 : hstate.add_flag (DECL_CXX_CONSTRUCTOR_P (t));
1526 346278 : hstate.add_flag (DECL_CXX_DESTRUCTOR_P (t));
1527 : }
1528 605103 : hstate.commit_flag ();
1529 : }
1530 :
1531 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1532 : {
1533 346278 : hstate.add_int (DECL_BUILT_IN_CLASS (t));
1534 346278 : hstate.add_flag (DECL_STATIC_CONSTRUCTOR (t));
1535 346278 : hstate.add_flag (DECL_STATIC_DESTRUCTOR (t));
1536 346278 : hstate.add_int ((unsigned)FUNCTION_DECL_DECL_TYPE (t));
1537 346278 : hstate.add_flag (DECL_UNINLINABLE (t));
1538 346278 : hstate.add_flag (DECL_POSSIBLY_INLINED (t));
1539 346278 : hstate.add_flag (DECL_IS_NOVOPS (t));
1540 346278 : hstate.add_flag (DECL_IS_RETURNS_TWICE (t));
1541 346278 : hstate.add_flag (DECL_IS_MALLOC (t));
1542 346278 : hstate.add_flag (DECL_DECLARED_INLINE_P (t));
1543 346278 : hstate.add_flag (DECL_STATIC_CHAIN (t));
1544 346278 : hstate.add_flag (DECL_NO_INLINE_WARNING_P (t));
1545 346278 : hstate.add_flag (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (t));
1546 346278 : hstate.add_flag (DECL_NO_LIMIT_STACK (t));
1547 346278 : hstate.add_flag (DECL_DISREGARD_INLINE_LIMITS (t));
1548 346278 : hstate.add_flag (DECL_PURE_P (t));
1549 346278 : hstate.add_flag (DECL_LOOPING_CONST_OR_PURE_P (t));
1550 346278 : hstate.commit_flag ();
1551 346278 : if (DECL_BUILT_IN_CLASS (t) != NOT_BUILT_IN)
1552 22516 : hstate.add_int (DECL_UNCHECKED_FUNCTION_CODE (t));
1553 : }
1554 :
1555 2825290 : 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 464397 : 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 464397 : hstate.add_hwi (TYPE_MODE_RAW (t));
1570 : /* TYPE_NO_FORCE_BLK is private to stor-layout and need
1571 : no streaming. */
1572 464397 : hstate.add_flag (TYPE_PACKED (t));
1573 464397 : hstate.add_flag (TYPE_RESTRICT (t));
1574 464397 : hstate.add_flag (TYPE_USER_ALIGN (t));
1575 464397 : hstate.add_flag (TYPE_READONLY (t));
1576 464397 : if (RECORD_OR_UNION_TYPE_P (t))
1577 : {
1578 72657 : hstate.add_flag (TYPE_TRANSPARENT_AGGR (t));
1579 72657 : hstate.add_flag (TYPE_FINAL_P (t));
1580 72657 : hstate.add_flag (TYPE_CXX_ODR_P (t));
1581 : }
1582 391740 : else if (code == ARRAY_TYPE)
1583 29654 : hstate.add_flag (TYPE_NONALIASED_COMPONENT (t));
1584 464397 : if (code == ARRAY_TYPE || code == INTEGER_TYPE)
1585 75289 : hstate.add_flag (TYPE_STRING_FLAG (t));
1586 464397 : if (AGGREGATE_TYPE_P (t))
1587 102311 : hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
1588 464397 : hstate.commit_flag ();
1589 464397 : hstate.add_int (TYPE_PRECISION_RAW (t));
1590 464397 : hstate.add_int (TYPE_ALIGN (t));
1591 464397 : if (!lto_stream_offload_p)
1592 464397 : hstate.add_int (TYPE_EMPTY_P (t));
1593 : }
1594 :
1595 2825290 : 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 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION)
1600 : /* We don't stream these when passing things to a different target. */
1601 22913 : && !lto_stream_offload_p)
1602 22913 : hstate.add_hwi (cl_target_option_hash (TREE_TARGET_OPTION (t)));
1603 :
1604 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
1605 23129 : hstate.add_hwi (cl_optimization_hash (TREE_OPTIMIZATION (t)));
1606 :
1607 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1608 885824 : hstate.merge_hash (IDENTIFIER_HASH_VALUE (t));
1609 :
1610 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1611 4395 : hstate.add (TREE_STRING_POINTER (t), TREE_STRING_LENGTH (t));
1612 :
1613 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
1614 : {
1615 2779248 : if (code != IDENTIFIER_NODE)
1616 1893424 : visit (TREE_TYPE (t));
1617 : }
1618 :
1619 2825290 : 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 2825290 : 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 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
1631 : {
1632 0 : visit (TREE_REALPART (t));
1633 0 : visit (TREE_IMAGPART (t));
1634 : }
1635 :
1636 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
1637 : {
1638 : /* Drop names that were created for anonymous entities. */
1639 687950 : if (DECL_NAME (t)
1640 670478 : && TREE_CODE (DECL_NAME (t)) == IDENTIFIER_NODE
1641 1358428 : && IDENTIFIER_ANON_P (DECL_NAME (t)))
1642 : ;
1643 : else
1644 687593 : visit (DECL_NAME (t));
1645 687950 : if (DECL_FILE_SCOPE_P (t))
1646 : ;
1647 : else
1648 113355 : visit (DECL_CONTEXT (t));
1649 : }
1650 :
1651 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1652 : {
1653 687950 : visit (DECL_SIZE (t));
1654 687950 : visit (DECL_SIZE_UNIT (t));
1655 687950 : visit (DECL_ATTRIBUTES (t));
1656 687950 : if ((code == VAR_DECL
1657 687950 : || code == PARM_DECL)
1658 687950 : && DECL_HAS_VALUE_EXPR_P (t))
1659 20 : visit (DECL_VALUE_EXPR (t));
1660 687950 : if (code == VAR_DECL
1661 923705 : && 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 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1668 : {
1669 605103 : if (DECL_ASSEMBLER_NAME_SET_P (t))
1670 602636 : visit (DECL_ASSEMBLER_NAME (t));
1671 : }
1672 :
1673 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
1674 : {
1675 82831 : visit (DECL_FIELD_OFFSET (t));
1676 82831 : visit (DECL_BIT_FIELD_TYPE (t));
1677 82831 : visit (DECL_BIT_FIELD_REPRESENTATIVE (t));
1678 82831 : visit (DECL_FIELD_BIT_OFFSET (t));
1679 : }
1680 :
1681 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1682 : {
1683 346278 : visit (DECL_FUNCTION_PERSONALITY (t));
1684 346278 : visit (DECL_FUNCTION_SPECIFIC_TARGET (t));
1685 346278 : visit (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t));
1686 : }
1687 :
1688 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1689 : {
1690 464397 : visit (TYPE_SIZE (t));
1691 464397 : visit (TYPE_SIZE_UNIT (t));
1692 464397 : visit (TYPE_ATTRIBUTES (t));
1693 464397 : visit (TYPE_NAME (t));
1694 464397 : visit (TYPE_MAIN_VARIANT (t));
1695 464397 : if (TYPE_FILE_SCOPE_P (t))
1696 : ;
1697 : else
1698 16357 : visit (TYPE_CONTEXT (t));
1699 : }
1700 :
1701 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1702 : {
1703 464397 : if (code == ARRAY_TYPE)
1704 29654 : visit (TYPE_DOMAIN (t));
1705 434743 : else if (RECORD_OR_UNION_TYPE_P (t))
1706 179398 : for (tree f = TYPE_FIELDS (t); f; f = TREE_CHAIN (f))
1707 106741 : visit (f);
1708 362086 : else if (code == FUNCTION_TYPE
1709 362086 : || code == METHOD_TYPE)
1710 115610 : visit (TYPE_ARG_TYPES (t));
1711 464397 : if (!POINTER_TYPE_P (t))
1712 273777 : visit (TYPE_MIN_VALUE_RAW (t));
1713 464397 : visit (TYPE_MAX_VALUE_RAW (t));
1714 : }
1715 :
1716 2825290 : if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1717 : {
1718 530864 : visit (TREE_PURPOSE (t));
1719 530864 : visit (TREE_VALUE (t));
1720 530864 : visit (TREE_CHAIN (t));
1721 : }
1722 :
1723 2825290 : 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 2825290 : 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 2825290 : 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 2825290 : 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 2825290 : if (code == OMP_CLAUSE)
1760 : {
1761 135 : int i;
1762 135 : HOST_WIDE_INT val;
1763 :
1764 135 : hstate.add_hwi (OMP_CLAUSE_CODE (t));
1765 135 : 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 135 : hstate.add_hwi (val);
1795 365 : for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (t)]; i++)
1796 230 : visit (OMP_CLAUSE_OPERAND (t, i));
1797 135 : visit (OMP_CLAUSE_CHAIN (t));
1798 : }
1799 :
1800 2825290 : 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 1581460 : DFS::scc_entry_compare (const void *p1_, const void *p2_)
1809 : {
1810 1581460 : const scc_entry *p1 = (const scc_entry *) p1_;
1811 1581460 : const scc_entry *p2 = (const scc_entry *) p2_;
1812 1581460 : if (p1->hash < p2->hash)
1813 : return -1;
1814 712813 : else if (p1->hash > p2->hash)
1815 691377 : 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 2676675 : DFS::hash_scc (struct output_block *ob, unsigned first, unsigned size,
1824 : bool ref_p, bool this_ref_p)
1825 : {
1826 2676675 : unsigned int last_classes = 0, iterations = 0;
1827 :
1828 : /* Compute hash values for the SCC members. */
1829 5501965 : for (unsigned i = 0; i < size; ++i)
1830 2825290 : sccstack[first+i].hash
1831 5650580 : = hash_tree (ob->writer_cache, NULL, sccstack[first+i].t);
1832 :
1833 2676675 : if (size == 1)
1834 2608864 : 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 67811 : do
1857 : {
1858 : /* Sort the SCC so we can easily check for uniqueness. */
1859 67811 : qsort (&sccstack[first], size, sizeof (scc_entry), scc_entry_compare);
1860 :
1861 67811 : unsigned int classes = 1;
1862 67811 : int firstunique = -1;
1863 :
1864 : /* Find the tree with lowest unique hash (if it exists) and compute
1865 : the number of equivalence classes. */
1866 67811 : if (sccstack[first].hash != sccstack[first+1].hash)
1867 67808 : firstunique = 0;
1868 216426 : for (unsigned i = 1; i < size; ++i)
1869 148615 : if (sccstack[first+i-1].hash != sccstack[first+i].hash)
1870 : {
1871 146648 : classes++;
1872 146648 : if (firstunique == -1
1873 146648 : && (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 67811 : 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 67811 : || classes <= last_classes || iterations > 16)
1886 : {
1887 67811 : 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 67811 : 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 205476 : for (unsigned i = 1; i < size; ++i)
1934 138012 : scc_hash
1935 138012 : = 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 67464 : 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 284237 : for (unsigned i = 0; i < size; ++i)
1947 432852 : sccstack[first+i].hash
1948 216426 : = iterative_hash_hashval_t (sccstack[first+i].hash, scc_hash);
1949 67811 : 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 36055400 : 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 36055400 : if (expr == NULL_TREE)
1979 26258565 : return;
1980 :
1981 : /* Do not DFS walk into indexable trees. */
1982 23539266 : if (this_ref_p && tree_is_indexable (expr))
1983 : return;
1984 :
1985 : /* Check if we already streamed EXPR. */
1986 17200471 : 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 7403636 : if (ob->local_trees
1991 7403636 : && ob->local_trees->contains (expr))
1992 18218 : max_local_entry = sccstack.length () - 1;
1993 : return;
1994 : }
1995 :
1996 9796835 : worklist w;
1997 9796835 : w.expr = expr;
1998 9796835 : w.from_state = from_state;
1999 9796835 : w.cstate = NULL;
2000 9796835 : w.ref_p = ref_p;
2001 9796835 : w.this_ref_p = this_ref_p;
2002 9796835 : 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 12814466 : lto_output_tree (struct output_block *ob, tree expr,
2012 : bool ref_p, bool this_ref_p)
2013 : {
2014 12814466 : unsigned ix;
2015 12814466 : bool existed_p;
2016 12814466 : 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 12814466 : static bool in_dfs_walk;
2020 :
2021 12814466 : if (expr == NULL_TREE)
2022 : {
2023 2840979 : streamer_write_record_start (ob, LTO_null);
2024 10761026 : return;
2025 : }
2026 :
2027 9973487 : if (this_ref_p && tree_is_indexable (expr))
2028 : {
2029 5079068 : enum LTO_tags tag;
2030 5079068 : unsigned ix;
2031 :
2032 5079068 : lto_indexable_tree_ref (ob, expr, &tag, &ix);
2033 5079068 : streamer_write_record_start (ob, tag);
2034 5079068 : streamer_write_uhwi (ob, ix);
2035 5079068 : return;
2036 : }
2037 :
2038 4894419 : existed_p = streamer_tree_cache_lookup (ob->writer_cache, expr, &ix);
2039 4894419 : if (existed_p)
2040 : {
2041 1870385 : 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 1870385 : streamer_write_record_start (ob, LTO_tree_pickle_reference);
2055 1870385 : streamer_write_uhwi (ob, ix);
2056 1870385 : 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 3024034 : gcc_assert (!in_dfs_walk);
2064 :
2065 3024034 : 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 3024034 : in_dfs_walk = true;
2076 3024034 : DFS (ob, expr, ref_p, this_ref_p, false);
2077 :
2078 : /* Finally append a reference to the tree we were writing. */
2079 3024034 : 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 3024034 : if (!existed_p)
2084 2080551 : lto_output_tree_1 (ob, expr, 0, ref_p, this_ref_p);
2085 943483 : 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 3024034 : in_dfs_walk = false;
2098 3024034 : lto_stats.num_pickle_refs_output++;
2099 : }
2100 4894419 : 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 311 : output_eh_try_list (struct output_block *ob, eh_catch first)
2110 : {
2111 311 : eh_catch n;
2112 :
2113 710 : for (n = first; n; n = n->next_catch)
2114 : {
2115 399 : streamer_write_record_start (ob, LTO_eh_catch);
2116 399 : stream_write_tree (ob, n->type_list, true);
2117 399 : stream_write_tree (ob, n->filter_list, true);
2118 399 : stream_write_tree (ob, n->label, true);
2119 : }
2120 :
2121 311 : streamer_write_record_start (ob, LTO_null);
2122 311 : }
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 18510 : output_eh_region (struct output_block *ob, eh_region r)
2131 : {
2132 18510 : enum LTO_tags tag;
2133 :
2134 18510 : if (r == NULL)
2135 : {
2136 7824 : streamer_write_record_start (ob, LTO_null);
2137 7824 : return;
2138 : }
2139 :
2140 10686 : 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 10686 : streamer_write_record_start (ob, tag);
2152 10686 : streamer_write_hwi (ob, r->index);
2153 :
2154 10686 : if (r->outer)
2155 3190 : streamer_write_hwi (ob, r->outer->index);
2156 : else
2157 7496 : streamer_write_zero (ob);
2158 :
2159 10686 : if (r->inner)
2160 1876 : streamer_write_hwi (ob, r->inner->index);
2161 : else
2162 8810 : streamer_write_zero (ob);
2163 :
2164 10686 : if (r->next_peer)
2165 4539 : streamer_write_hwi (ob, r->next_peer->index);
2166 : else
2167 6147 : streamer_write_zero (ob);
2168 :
2169 10686 : if (r->type == ERT_TRY)
2170 : {
2171 311 : output_eh_try_list (ob, r->u.eh_try.first_catch);
2172 : }
2173 10375 : 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 10051 : else if (r->type == ERT_MUST_NOT_THROW)
2180 : {
2181 5325 : stream_write_tree (ob, r->u.must_not_throw.failure_decl, true);
2182 5325 : bitpack_d bp = bitpack_create (ob->main_stream);
2183 5325 : stream_output_location (ob, &bp, r->u.must_not_throw.failure_loc);
2184 5325 : streamer_write_bitpack (&bp);
2185 : }
2186 :
2187 10686 : if (r->landing_pads)
2188 3259 : streamer_write_hwi (ob, r->landing_pads->index);
2189 : else
2190 7427 : streamer_write_zero (ob);
2191 : }
2192 :
2193 :
2194 : /* Output landing pad LP to OB. */
2195 :
2196 : static void
2197 8493 : output_eh_lp (struct output_block *ob, eh_landing_pad lp)
2198 : {
2199 8493 : if (lp == NULL)
2200 : {
2201 5185 : streamer_write_record_start (ob, LTO_null);
2202 5185 : return;
2203 : }
2204 :
2205 3308 : streamer_write_record_start (ob, LTO_eh_landing_pad);
2206 3308 : streamer_write_hwi (ob, lp->index);
2207 3308 : if (lp->next_lp)
2208 49 : streamer_write_hwi (ob, lp->next_lp->index);
2209 : else
2210 3259 : streamer_write_zero (ob);
2211 :
2212 3308 : if (lp->region)
2213 3308 : streamer_write_hwi (ob, lp->region->index);
2214 : else
2215 0 : streamer_write_zero (ob);
2216 :
2217 3308 : 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 109044 : output_eh_regions (struct output_block *ob, struct function *fn)
2225 : {
2226 109044 : 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 27052 : FOR_EACH_VEC_SAFE_ELT (fn->eh->region_array, i, eh)
2241 18510 : 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 17035 : FOR_EACH_VEC_SAFE_ELT (fn->eh->lp_array, i, lp)
2246 8493 : 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 109044 : streamer_write_record_start (ob, LTO_null);
2273 109044 : }
2274 :
2275 :
2276 : /* Output all of the active ssa names to the ssa_names stream. */
2277 :
2278 : static void
2279 109044 : output_ssa_names (struct output_block *ob, struct function *fn)
2280 : {
2281 109044 : unsigned int i, len;
2282 :
2283 109044 : len = vec_safe_length (SSANAMES (fn));
2284 109044 : streamer_write_uhwi (ob, len);
2285 :
2286 1860529 : for (i = 1; i < len; i++)
2287 : {
2288 1642441 : tree ptr = (*SSANAMES (fn))[i];
2289 :
2290 2254280 : if (ptr == NULL_TREE
2291 1635871 : || SSA_NAME_IN_FREE_LIST (ptr)
2292 1635871 : || virtual_operand_p (ptr)
2293 : /* Simply skip unreleased SSA names. */
2294 2675951 : || (! SSA_NAME_IS_DEFAULT_DEF (ptr)
2295 924501 : && (! SSA_NAME_DEF_STMT (ptr)
2296 924501 : || ! gimple_bb (SSA_NAME_DEF_STMT (ptr)))))
2297 611839 : continue;
2298 :
2299 1030602 : streamer_write_uhwi (ob, i);
2300 1030602 : streamer_write_char_stream (ob->main_stream,
2301 1030602 : SSA_NAME_IS_DEFAULT_DEF (ptr));
2302 1030602 : if (SSA_NAME_VAR (ptr))
2303 302947 : stream_write_tree (ob, SSA_NAME_VAR (ptr), true);
2304 : else
2305 : /* ??? This drops SSA_NAME_IDENTIFIER on the floor. */
2306 727655 : stream_write_tree (ob, TREE_TYPE (ptr), true);
2307 : }
2308 :
2309 109044 : streamer_write_zero (ob);
2310 109044 : }
2311 :
2312 :
2313 :
2314 : /* Output the cfg. */
2315 :
2316 : static void
2317 109044 : output_cfg (struct output_block *ob, struct function *fn)
2318 : {
2319 109044 : struct lto_output_stream *tmp_stream = ob->main_stream;
2320 109044 : basic_block bb;
2321 :
2322 109044 : ob->main_stream = ob->cfg_stream;
2323 :
2324 109044 : 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 109044 : streamer_write_uhwi (ob, last_basic_block_for_fn (fn));
2329 :
2330 1027081 : FOR_ALL_BB_FN (bb, fn)
2331 : {
2332 918037 : edge_iterator ei;
2333 918037 : edge e;
2334 :
2335 918037 : 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 1726857 : streamer_write_uhwi (ob, EDGE_COUNT (bb->preds));
2342 1959991 : FOR_EACH_EDGE (e, ei, bb->preds)
2343 : {
2344 1041954 : bitpack_d bp = bitpack_create (ob->main_stream);
2345 1041954 : bp_pack_var_len_unsigned (&bp, e->src->index);
2346 1041954 : bp_pack_var_len_unsigned (&bp, e->flags);
2347 1041954 : stream_output_location_and_block (ob, &bp, e->goto_locus);
2348 1041954 : e->probability.stream_out (ob);
2349 : }
2350 : }
2351 :
2352 109044 : streamer_write_hwi (ob, -1);
2353 :
2354 109044 : bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
2355 918037 : while (bb->next_bb)
2356 : {
2357 808993 : streamer_write_hwi (ob, bb->next_bb->index);
2358 808993 : bb = bb->next_bb;
2359 : }
2360 :
2361 109044 : streamer_write_hwi (ob, -1);
2362 :
2363 : /* Output the number of loops. */
2364 109044 : streamer_write_uhwi (ob, number_of_loops (fn));
2365 :
2366 : /* Output each loop, skipping the tree root which has number zero. */
2367 476918 : for (unsigned i = 1; i < number_of_loops (fn); ++i)
2368 : {
2369 74893 : 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 74893 : if (!loop)
2375 : {
2376 25316 : streamer_write_hwi (ob, -1);
2377 25316 : continue;
2378 : }
2379 : else
2380 49577 : streamer_write_hwi (ob, loop->header->index);
2381 :
2382 : /* Write everything copy_loop_info copies. */
2383 49577 : streamer_write_enum (ob->main_stream,
2384 : loop_estimation, EST_LAST, loop->estimate_state);
2385 49577 : streamer_write_hwi (ob, loop->any_upper_bound);
2386 49577 : if (loop->any_upper_bound)
2387 : {
2388 40540 : widest_int w = widest_int::from (loop->nb_iterations_upper_bound,
2389 40540 : SIGNED);
2390 40540 : streamer_write_widest_int (ob, w);
2391 40540 : }
2392 49577 : streamer_write_hwi (ob, loop->any_likely_upper_bound);
2393 49577 : if (loop->any_likely_upper_bound)
2394 : {
2395 40540 : widest_int w
2396 40540 : = widest_int::from (loop->nb_iterations_likely_upper_bound,
2397 40540 : SIGNED);
2398 40540 : streamer_write_widest_int (ob, w);
2399 40540 : }
2400 49577 : streamer_write_hwi (ob, loop->any_estimate);
2401 49577 : if (loop->any_estimate)
2402 : {
2403 33361 : widest_int w = widest_int::from (loop->nb_iterations_estimate,
2404 33361 : SIGNED);
2405 33361 : streamer_write_widest_int (ob, w);
2406 33361 : }
2407 :
2408 : /* Write OMP SIMD related info. */
2409 49577 : streamer_write_hwi (ob, loop->safelen);
2410 49577 : streamer_write_hwi (ob, loop->unroll);
2411 49577 : streamer_write_hwi (ob, loop->owned_clique);
2412 49577 : streamer_write_hwi (ob, loop->dont_vectorize);
2413 49577 : streamer_write_hwi (ob, loop->force_vectorize);
2414 49577 : streamer_write_hwi (ob, loop->finite_p);
2415 49577 : streamer_write_hwi (ob, loop->can_be_parallel);
2416 49577 : stream_write_tree (ob, loop->simduid, true);
2417 : }
2418 :
2419 109044 : ob->main_stream = tmp_stream;
2420 109044 : }
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 256255 : produce_symbol_asm (struct output_block *ob, tree fn, int output_order)
2427 : {
2428 256255 : enum lto_section_type section_type = ob->section_type;
2429 256255 : struct lto_function_header header;
2430 256255 : char *section_name;
2431 :
2432 256255 : if (section_type == LTO_section_function_body)
2433 : {
2434 120310 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn));
2435 120310 : section_name = lto_get_section_name (section_type, name,
2436 : output_order, NULL);
2437 : }
2438 : else
2439 135945 : section_name = lto_get_section_name (section_type, NULL, 0, NULL);
2440 :
2441 256255 : lto_begin_section (section_name, !flag_wpa);
2442 256255 : free (section_name);
2443 :
2444 : /* The entire header is stream computed here. */
2445 256255 : memset (&header, 0, sizeof (struct lto_function_header));
2446 :
2447 256255 : if (section_type == LTO_section_function_body)
2448 120310 : header.cfg_size = ob->cfg_stream->total_size;
2449 256255 : header.main_size = ob->main_stream->total_size;
2450 256255 : header.string_size = ob->string_stream->total_size;
2451 256255 : 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 256255 : if (section_type == LTO_section_function_body)
2456 120310 : lto_write_stream (ob->cfg_stream);
2457 256255 : lto_write_stream (ob->main_stream);
2458 256255 : lto_write_stream (ob->string_stream);
2459 :
2460 256255 : lto_end_section ();
2461 256255 : }
2462 :
2463 : /* Wrapper for unused arguments. */
2464 :
2465 : void
2466 135945 : produce_asm (struct output_block *ob)
2467 : {
2468 135945 : produce_symbol_asm (ob, NULL, -1);
2469 135945 : }
2470 :
2471 :
2472 : /* Output the base body of struct function FN using output block OB. */
2473 :
2474 : static void
2475 109044 : output_struct_function_base (struct output_block *ob, struct function *fn)
2476 : {
2477 109044 : struct bitpack_d bp;
2478 109044 : unsigned i;
2479 109044 : tree t;
2480 :
2481 : /* Output the static chain and non-local goto save area. */
2482 109044 : stream_write_tree (ob, fn->static_chain_decl, true);
2483 109044 : stream_write_tree (ob, fn->nonlocal_goto_save_area, true);
2484 :
2485 : /* Output all the local variables in the function. */
2486 109044 : streamer_write_hwi (ob, vec_safe_length (fn->local_decls));
2487 385932 : FOR_EACH_VEC_SAFE_ELT (fn->local_decls, i, t)
2488 167844 : stream_write_tree (ob, t, true);
2489 :
2490 : /* Output current IL state of the function. */
2491 109044 : streamer_write_uhwi (ob, fn->curr_properties);
2492 :
2493 : /* Write all the attributes for FN. */
2494 109044 : bp = bitpack_create (ob->main_stream);
2495 109044 : bp_pack_value (&bp, fn->is_thunk, 1);
2496 109044 : bp_pack_value (&bp, fn->has_local_explicit_reg_vars, 1);
2497 109044 : bp_pack_value (&bp, fn->returns_pcc_struct, 1);
2498 109044 : bp_pack_value (&bp, fn->returns_struct, 1);
2499 109044 : bp_pack_value (&bp, fn->can_throw_non_call_exceptions, 1);
2500 109044 : bp_pack_value (&bp, fn->can_delete_dead_exceptions, 1);
2501 109044 : bp_pack_value (&bp, fn->always_inline_functions_inlined, 1);
2502 109044 : bp_pack_value (&bp, fn->after_inlining, 1);
2503 109044 : bp_pack_value (&bp, fn->stdarg, 1);
2504 109044 : bp_pack_value (&bp, fn->has_nonlocal_label, 1);
2505 109044 : bp_pack_value (&bp, fn->has_forced_label_in_static, 1);
2506 109044 : bp_pack_value (&bp, fn->calls_alloca, 1);
2507 109044 : bp_pack_value (&bp, fn->calls_setjmp, 1);
2508 109044 : bp_pack_value (&bp, fn->calls_eh_return, 1);
2509 109044 : bp_pack_value (&bp, fn->has_force_vectorize_loops, 1);
2510 109044 : bp_pack_value (&bp, fn->has_simduid_loops, 1);
2511 109044 : bp_pack_value (&bp, fn->has_musttail, 1);
2512 109044 : bp_pack_value (&bp, fn->has_unroll, 1);
2513 109044 : bp_pack_value (&bp, fn->assume_function, 1);
2514 109044 : bp_pack_value (&bp, fn->va_list_fpr_size, 8);
2515 109044 : bp_pack_value (&bp, fn->va_list_gpr_size, 8);
2516 109044 : bp_pack_value (&bp, fn->last_clique, sizeof (short) * 8);
2517 :
2518 : /* Output the function start and end loci. */
2519 109044 : stream_output_location (ob, &bp, fn->function_start_locus);
2520 109044 : stream_output_location (ob, &bp, fn->function_end_locus);
2521 :
2522 : /* Save the instance discriminator if present. */
2523 109044 : int *instance_number_p = NULL;
2524 109044 : if (decl_to_instance_map)
2525 0 : instance_number_p = decl_to_instance_map->get (fn->decl);
2526 109044 : bp_pack_value (&bp, !!instance_number_p, 1);
2527 109044 : if (instance_number_p)
2528 0 : bp_pack_value (&bp, *instance_number_p, sizeof (int) * CHAR_BIT);
2529 :
2530 109044 : streamer_write_bitpack (&bp);
2531 109044 : }
2532 :
2533 :
2534 : /* Collect all leaf BLOCKs beyond ROOT into LEAFS. */
2535 :
2536 : static void
2537 248378 : collect_block_tree_leafs (tree root, vec<tree> &leafs)
2538 : {
2539 465606 : for (root = BLOCK_SUBBLOCKS (root); root; root = BLOCK_CHAIN (root))
2540 217228 : if (! BLOCK_SUBBLOCKS (root))
2541 77894 : leafs.safe_push (root);
2542 : else
2543 139334 : collect_block_tree_leafs (root, leafs);
2544 248378 : }
2545 :
2546 : /* This performs function body modifications that are needed for streaming
2547 : to work. */
2548 :
2549 : void
2550 109034 : lto_prepare_function_for_streaming (struct cgraph_node *node)
2551 : {
2552 109034 : struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
2553 109034 : basic_block bb;
2554 :
2555 218068 : if (number_of_loops (fn))
2556 : {
2557 109034 : push_cfun (fn);
2558 109034 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
2559 109034 : loop_optimizer_finalize ();
2560 109034 : 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 109034 : set_gimple_stmt_max_uid (fn, 0);
2569 1027041 : FOR_ALL_BB_FN (bb, fn)
2570 : {
2571 1077316 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2572 159309 : gsi_next (&gsi))
2573 : {
2574 159309 : gphi *stmt = gsi.phi ();
2575 :
2576 : /* Virtual PHIs are not going to be streamed. */
2577 318618 : if (!virtual_operand_p (gimple_phi_result (stmt)))
2578 92376 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2579 : }
2580 3537086 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
2581 1701072 : gsi_next (&gsi))
2582 : {
2583 1701072 : gimple *stmt = gsi_stmt (gsi);
2584 1701072 : 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 1027041 : FOR_ALL_BB_FN (bb, fn)
2590 : {
2591 1077316 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2592 159309 : gsi_next (&gsi))
2593 : {
2594 159309 : gphi *stmt = gsi.phi ();
2595 385551 : if (virtual_operand_p (gimple_phi_result (stmt)))
2596 66933 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2597 : }
2598 : }
2599 :
2600 109034 : }
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 109198 : streamer_write_chain (struct output_block *ob, tree t, bool ref_p)
2608 : {
2609 430702 : 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 321504 : gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
2616 321504 : stream_write_tree (ob, t, ref_p);
2617 :
2618 321504 : t = TREE_CHAIN (t);
2619 : }
2620 :
2621 : /* Write a sentinel to terminate the chain. */
2622 109198 : stream_write_tree (ob, NULL_TREE, ref_p);
2623 109198 : }
2624 :
2625 : /* Output the body of function NODE->DECL. */
2626 :
2627 : static void
2628 109198 : output_function (struct cgraph_node *node, int output_order)
2629 : {
2630 109198 : tree function;
2631 109198 : struct function *fn;
2632 109198 : basic_block bb;
2633 109198 : struct output_block *ob;
2634 :
2635 109198 : if (streamer_dump_file)
2636 8 : fprintf (streamer_dump_file, "\nStreaming body of %s\n",
2637 : node->dump_name ());
2638 :
2639 109198 : function = node->decl;
2640 109198 : fn = DECL_STRUCT_FUNCTION (function);
2641 109198 : ob = create_output_block (LTO_section_function_body);
2642 :
2643 109198 : ob->symbol = node;
2644 :
2645 109198 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
2646 :
2647 : /* Make string 0 be a NULL string. */
2648 109198 : streamer_write_char_stream (ob->string_stream, 0);
2649 :
2650 109198 : streamer_write_record_start (ob, LTO_function);
2651 :
2652 : /* Output decls for parameters and args. */
2653 109198 : stream_write_tree (ob, DECL_RESULT (function), true);
2654 109198 : streamer_write_chain (ob, DECL_ARGUMENTS (function), true);
2655 :
2656 : /* Output debug args if available. */
2657 109198 : vec<tree, va_gc> **debugargs = decl_debug_args_lookup (function);
2658 109198 : if (! debugargs)
2659 109169 : 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 109198 : 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 109198 : auto_vec<tree> block_tree_leafs;
2673 109198 : if (DECL_INITIAL (function) && DECL_INITIAL (function) != error_mark_node)
2674 109044 : collect_block_tree_leafs (DECL_INITIAL (function), block_tree_leafs);
2675 109198 : streamer_write_uhwi (ob, block_tree_leafs.length ());
2676 296290 : for (unsigned i = 0; i < block_tree_leafs.length (); ++i)
2677 77894 : 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 109198 : if (gimple_has_body_p (function))
2682 : {
2683 109044 : streamer_write_uhwi (ob, 1);
2684 109044 : output_struct_function_base (ob, fn);
2685 :
2686 109044 : output_cfg (ob, fn);
2687 :
2688 : /* Output all the SSA names used in the function. */
2689 109044 : output_ssa_names (ob, fn);
2690 :
2691 : /* Output any exception handling regions. */
2692 109044 : output_eh_regions (ob, fn);
2693 :
2694 : /* Output the code for the function. */
2695 1027081 : FOR_ALL_BB_FN (bb, fn)
2696 918037 : output_bb (ob, bb, fn);
2697 :
2698 : /* The terminator for this function. */
2699 109044 : 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 109198 : produce_symbol_asm (ob, function, output_order);
2706 :
2707 109198 : destroy_output_block (ob);
2708 109198 : if (streamer_dump_file)
2709 8 : fprintf (streamer_dump_file, "Finished streaming %s\n",
2710 : node->dump_name ());
2711 109198 : }
2712 :
2713 : /* Output the body of function NODE->DECL. */
2714 :
2715 : static void
2716 11112 : output_constructor (struct varpool_node *node, int output_order)
2717 : {
2718 11112 : tree var = node->decl;
2719 11112 : struct output_block *ob;
2720 :
2721 11112 : if (streamer_dump_file)
2722 4 : fprintf (streamer_dump_file, "\nStreaming constructor of %s\n",
2723 : node->dump_name ());
2724 :
2725 11112 : timevar_push (TV_IPA_LTO_CTORS_OUT);
2726 11112 : ob = create_output_block (LTO_section_function_body);
2727 :
2728 11112 : ob->symbol = node;
2729 :
2730 : /* Make string 0 be a NULL string. */
2731 11112 : 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 11112 : stream_write_tree (ob, DECL_INITIAL (var), true);
2736 :
2737 : /* Create a section to hold the pickled output of this function. */
2738 11112 : produce_symbol_asm (ob, var, output_order);
2739 :
2740 11112 : destroy_output_block (ob);
2741 11112 : if (streamer_dump_file)
2742 4 : fprintf (streamer_dump_file, "Finished streaming %s\n",
2743 : node->dump_name ());
2744 11112 : timevar_pop (TV_IPA_LTO_CTORS_OUT);
2745 11112 : }
2746 :
2747 :
2748 : /* Emit toplevel asms. */
2749 :
2750 : void
2751 31664 : lto_output_toplevel_asms (lto_symtab_encoder_t encoder)
2752 : {
2753 31664 : struct output_block *ob;
2754 31664 : char *section_name;
2755 31664 : struct lto_simple_header_with_strings header;
2756 :
2757 31664 : unsigned asm_count = 0;
2758 1485193 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
2759 1422100 : if (is_a <asm_node*> (lto_symtab_encoder_deref (encoder, i)))
2760 156 : asm_count++;
2761 :
2762 31664 : if (!asm_count)
2763 31549 : 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 26185 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
2770 : {
2771 12920 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
2772 12920 : asm_node *anode = dyn_cast <asm_node*> (tnode);
2773 12920 : if (!anode)
2774 12764 : 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 34738 : copy_function_or_variable (struct symtab_node *node, int output_order)
2807 : {
2808 34738 : tree function = node->decl;
2809 34738 : struct lto_file_decl_data *file_data = node->lto_file_data;
2810 34738 : const char *data;
2811 34738 : size_t len;
2812 34738 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
2813 34738 : char *section_name =
2814 34738 : lto_get_section_name (LTO_section_function_body, name, output_order, NULL);
2815 34738 : size_t i, j;
2816 34738 : struct lto_in_decl_state *in_state;
2817 34738 : struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
2818 :
2819 34738 : if (streamer_dump_file)
2820 0 : fprintf (streamer_dump_file, "Copying section for %s\n", name);
2821 34738 : lto_begin_section (section_name, false);
2822 34738 : free (section_name);
2823 :
2824 : /* We may have renamed the declaration, e.g., a static function. */
2825 34738 : name = lto_get_decl_name_mapping (file_data, name);
2826 :
2827 69476 : data = lto_get_raw_section_data (file_data, LTO_section_function_body,
2828 34738 : name, node->order - file_data->order_base,
2829 : &len);
2830 34738 : gcc_assert (data);
2831 :
2832 : /* Do a bit copy of the function body. */
2833 34738 : lto_write_raw_data (data, len);
2834 :
2835 : /* Copy decls. */
2836 34738 : in_state =
2837 34738 : lto_get_function_in_decl_state (node->lto_file_data, function);
2838 34738 : out_state->compressed = in_state->compressed;
2839 34738 : gcc_assert (in_state);
2840 :
2841 69476 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
2842 : {
2843 34738 : size_t n = vec_safe_length (in_state->streams[i]);
2844 34738 : vec<tree, va_gc> *trees = in_state->streams[i];
2845 34738 : 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 34738 : gcc_assert (lto_tree_ref_encoder_size (encoder) == 0);
2851 34738 : encoder->trees.reserve_exact (n);
2852 530192 : for (j = 0; j < n; j++)
2853 460716 : encoder->trees.safe_push ((*trees)[j]);
2854 : }
2855 :
2856 34738 : lto_free_raw_section_data (file_data, LTO_section_function_body, name,
2857 : data, len);
2858 34738 : lto_end_section ();
2859 :
2860 : /* Make sure the reader knows which linemap section to use. */
2861 34738 : out_state->linemap_id = lto_linemap_output_id (in_state->linemap_id,
2862 : file_data);
2863 34738 : }
2864 :
2865 : /* Wrap symbol references in *TP inside a type-preserving MEM_REF. */
2866 :
2867 : static tree
2868 793991 : wrap_refs (tree *tp, int *ws, void *)
2869 : {
2870 793991 : tree t = *tp;
2871 793991 : 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 793909 : else if (TREE_CODE (t) == CONSTRUCTOR)
2884 : ;
2885 576134 : else if (!EXPR_P (t))
2886 336145 : *ws = 0;
2887 793991 : 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 31664 : prune_offload_funcs (void)
2895 : {
2896 31664 : if (!offload_funcs)
2897 31664 : 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 39526 : produce_lto_section ()
2914 : {
2915 : /* Stream LTO meta section. */
2916 39526 : output_block *ob = create_output_block (LTO_section_lto);
2917 :
2918 39526 : char * section_name = lto_get_section_name (LTO_section_lto, NULL, 0, NULL);
2919 39526 : lto_begin_section (section_name, false);
2920 39526 : free (section_name);
2921 :
2922 : #ifdef HAVE_ZSTD_H
2923 39526 : lto_compression compression = ZSTD;
2924 : #else
2925 : lto_compression compression = ZLIB;
2926 : #endif
2927 :
2928 39526 : bool slim_object = flag_generate_lto && !flag_fat_lto_objects;
2929 39526 : lto_section s
2930 39526 : = { LTO_major_version, LTO_minor_version, slim_object, 0, 0 };
2931 39526 : s.set_compression (compression);
2932 39526 : lto_write_data (&s, sizeof s);
2933 39526 : lto_end_section ();
2934 39526 : destroy_output_block (ob);
2935 39526 : }
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 8669 : copy_linemap_section (lto_file_decl_data *file_data, unsigned order)
2942 : {
2943 8669 : const auto in_section_name
2944 8669 : = lto_get_section_name (LTO_section_linemap, nullptr, order, file_data);
2945 8669 : const auto out_section_name
2946 17338 : = lto_get_section_name (LTO_section_linemap, nullptr,
2947 8669 : lto_linemap_output_id (order, file_data), nullptr);
2948 :
2949 8669 : 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 8669 : size_t len;
2954 8669 : const auto data = lto_get_raw_section_data (file_data, LTO_section_linemap,
2955 : nullptr, order, &len);
2956 8669 : gcc_assert (data);
2957 8669 : lto_begin_section (out_section_name, false);
2958 8669 : free (in_section_name);
2959 8669 : free (out_section_name);
2960 8669 : lto_write_raw_data (data, len);
2961 8669 : lto_free_raw_section_data (file_data, LTO_section_linemap,
2962 : nullptr, data, len);
2963 8669 : lto_end_section ();
2964 8669 : }
2965 :
2966 : static void
2967 8667 : copy_linemap_sections (lto_file_decl_data *file_data)
2968 : {
2969 17336 : for (unsigned i = 0; i != file_data->num_linemap_sections; ++i)
2970 8669 : copy_linemap_section (file_data, i);
2971 8667 : }
2972 :
2973 : /* Copy all the linemaps we read into an object file so LTRANS can find them
2974 : later. */
2975 :
2976 : void
2977 7897 : lto_copy_linemaps ()
2978 : {
2979 7897 : timevar_push (TV_IPA_LTO_LINEMAP_COPY);
2980 7897 : lto_streamer_init ();
2981 7897 : 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 7897 : if (flag_wpa)
2986 7862 : produce_lto_section ();
2987 :
2988 16564 : for (auto file_data = lto_get_file_decl_data (); *file_data; ++file_data)
2989 8667 : copy_linemap_sections (*file_data);
2990 :
2991 7897 : lto_pop_out_decl_state ();
2992 7897 : timevar_pop (TV_IPA_LTO_LINEMAP_COPY);
2993 7897 : }
2994 :
2995 : /* Compare symbols to get them sorted by filename (to optimize streaming) */
2996 :
2997 : static int
2998 3384691 : cmp_symbol_files (const void *pn1, const void *pn2, void *id_map_)
2999 : {
3000 3384691 : const symtab_node *n1 = *(const symtab_node * const *)pn1;
3001 3384691 : const symtab_node *n2 = *(const symtab_node * const *)pn2;
3002 3384691 : hash_map<lto_file_decl_data *, int> *id_map
3003 : = (hash_map<lto_file_decl_data *, int> *)id_map_;
3004 :
3005 3384691 : int file_order1 = n1->lto_file_data ? n1->lto_file_data->order : -1;
3006 3384691 : 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 3384691 : if (file_order1 != file_order2)
3011 10237 : return file_order1 - file_order2;
3012 :
3013 : /* Order within static library. */
3014 3374454 : 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 3374454 : return n1->order - n2->order;
3019 : }
3020 :
3021 : /* Compare ints, callback for qsort. */
3022 :
3023 : static int
3024 31898119 : cmp_int (const void *a, const void *b)
3025 : {
3026 31898119 : int ia = *(int const*) a;
3027 31898119 : int ib = *(int const*) b;
3028 31898119 : 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 31664 : create_order_remap (lto_symtab_encoder_t encoder)
3039 : {
3040 31664 : auto_vec<int> orders;
3041 31664 : unsigned i;
3042 31664 : encoder->order_remap = new hash_map<int_hash<int, -1, -2>, int>;
3043 31664 : unsigned n_nodes = lto_symtab_encoder_size (encoder);
3044 :
3045 742714 : for (i = 0; i < n_nodes; i++)
3046 711050 : orders.safe_push (lto_symtab_encoder_deref (encoder, i)->order);
3047 :
3048 31664 : orders.qsort (cmp_int);
3049 31664 : int ord = 0;
3050 31664 : int last_order = -1;
3051 742714 : for (i = 0; i < orders.length (); i++)
3052 : {
3053 711050 : int order = orders[i];
3054 711050 : if (order != last_order)
3055 : {
3056 687735 : last_order = order;
3057 687735 : encoder->order_remap->put (order, ord);
3058 687735 : ord++;
3059 : }
3060 : }
3061 31664 : }
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 20768 : void lto_register_linemap_for_output (size_t map_idx, unsigned linemap_id)
3075 : {
3076 20768 : loc_output.register_map_id (map_idx, linemap_id);
3077 20768 : }
3078 :
3079 : /* Main entry point from the pass manager. */
3080 :
3081 : void
3082 31664 : lto_output (void)
3083 : {
3084 31664 : struct lto_out_decl_state *decl_state;
3085 31664 : bitmap output = NULL;
3086 31664 : bitmap_obstack output_obstack;
3087 31664 : unsigned int i, n_nodes;
3088 31664 : lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder;
3089 31664 : auto_vec<symtab_node *> symbols_to_copy;
3090 :
3091 31664 : create_order_remap (encoder);
3092 :
3093 31664 : prune_offload_funcs ();
3094 :
3095 31664 : if (flag_checking)
3096 : {
3097 31658 : bitmap_obstack_initialize (&output_obstack);
3098 31658 : output = BITMAP_ALLOC (&output_obstack);
3099 : }
3100 :
3101 : /* Initialize the streamer. */
3102 31664 : lto_streamer_init ();
3103 :
3104 31664 : produce_lto_section ();
3105 :
3106 31664 : n_nodes = lto_symtab_encoder_size (encoder);
3107 : /* Prepare vector of functions to output and then sort it to optimize
3108 : section copying. */
3109 742714 : for (i = 0; i < n_nodes; i++)
3110 : {
3111 711050 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
3112 711050 : symtab_node *node = dyn_cast <symtab_node *> (tnode);
3113 710894 : if (!node || node->alias)
3114 12981 : continue;
3115 :
3116 698069 : if (cgraph_node *node = dyn_cast <cgraph_node *> (tnode))
3117 : {
3118 411403 : if (lto_symtab_encoder_encode_body_p (encoder, node)
3119 411403 : && !node->clone_of)
3120 139364 : symbols_to_copy.safe_push (node);
3121 : }
3122 997716 : 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 286666 : tree ctor = DECL_INITIAL (node->decl);
3127 286666 : if (ctor && !in_lto_p)
3128 19498 : walk_tree (&ctor, wrap_refs, NULL, NULL);
3129 286666 : if (get_symbol_initial_value (encoder, node->decl) == error_mark_node
3130 286666 : && lto_symtab_encoder_encode_initializer_p (encoder, node))
3131 15684 : 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 31664 : int order = 0;
3138 31664 : hash_map<lto_file_decl_data *, int> id_map;
3139 218376 : for (i = 0; i < symbols_to_copy.length (); ++i)
3140 : {
3141 155048 : symtab_node *snode = symbols_to_copy[i];
3142 155048 : if (snode->lto_file_data)
3143 : {
3144 40357 : bool existed_p = false;
3145 40357 : int &ord = id_map.get_or_insert (snode->lto_file_data, &existed_p);
3146 40357 : if (!existed_p)
3147 8746 : ord = order++;
3148 : }
3149 : }
3150 31664 : symbols_to_copy.sort (cmp_symbol_files, (void *)&id_map);
3151 186712 : for (i = 0; i < symbols_to_copy.length (); i++)
3152 : {
3153 155048 : symtab_node *snode = symbols_to_copy[i];
3154 155048 : cgraph_node *cnode;
3155 155048 : varpool_node *vnode;
3156 :
3157 155048 : int output_order = *encoder->order_remap->get (snode->order);
3158 :
3159 155048 : if (flag_checking)
3160 155046 : gcc_assert (bitmap_set_bit (output, DECL_UID (snode->decl)));
3161 :
3162 155048 : decl_state = lto_new_out_decl_state ();
3163 155048 : lto_push_out_decl_state (decl_state);
3164 :
3165 155048 : if ((cnode = dyn_cast <cgraph_node *> (snode))
3166 139364 : && (gimple_has_body_p (cnode->decl)
3167 30320 : || (!flag_wpa
3168 300 : && flag_incremental_link != INCREMENTAL_LINK_LTO)
3169 : /* Thunks have no body but they may be synthesized
3170 : at WPA time. */
3171 30166 : || DECL_ARGUMENTS (cnode->decl)))
3172 109198 : output_function (cnode, output_order);
3173 45850 : else if ((vnode = dyn_cast <varpool_node *> (snode))
3174 15684 : && (DECL_INITIAL (vnode->decl) != error_mark_node
3175 4572 : || (!flag_wpa
3176 42 : && flag_incremental_link != INCREMENTAL_LINK_LTO)))
3177 11112 : output_constructor (vnode, output_order);
3178 : else
3179 34738 : copy_function_or_variable (snode, output_order);
3180 155048 : gcc_assert (lto_get_out_decl_state () == decl_state);
3181 155048 : lto_pop_out_decl_state ();
3182 155048 : 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 31664 : output_symtab ();
3190 :
3191 31664 : if (lto_get_out_decl_state ()->output_offload_tables_p)
3192 7862 : output_offload_tables ();
3193 :
3194 31664 : if (flag_checking)
3195 : {
3196 31658 : BITMAP_FREE (output);
3197 31658 : bitmap_obstack_release (&output_obstack);
3198 : }
3199 31664 : }
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 186712 : write_global_stream (struct output_block *ob,
3211 : struct lto_tree_ref_encoder *encoder)
3212 : {
3213 186712 : tree t;
3214 186712 : size_t index;
3215 186712 : const size_t size = lto_tree_ref_encoder_size (encoder);
3216 :
3217 2868879 : for (index = 0; index < size; index++)
3218 : {
3219 2682167 : t = lto_tree_ref_encoder_get_tree (encoder, index);
3220 2682167 : 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 2682167 : if (!streamer_tree_cache_lookup (ob->writer_cache, t, NULL))
3227 943473 : stream_write_tree (ob, t, false);
3228 : }
3229 186712 : }
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 186712 : write_global_references (struct output_block *ob,
3239 : struct lto_tree_ref_encoder *encoder)
3240 : {
3241 186712 : tree t;
3242 186712 : uint32_t index;
3243 186712 : const uint32_t size = lto_tree_ref_encoder_size (encoder);
3244 :
3245 : /* Write size and slot indexes as 32-bit unsigned numbers. */
3246 186712 : uint32_t *data = XNEWVEC (uint32_t, size + 1);
3247 186712 : data[0] = size;
3248 :
3249 2868879 : for (index = 0; index < size; index++)
3250 : {
3251 2682167 : unsigned slot_num;
3252 :
3253 2682167 : t = lto_tree_ref_encoder_get_tree (encoder, index);
3254 2682167 : streamer_tree_cache_lookup (ob->writer_cache, t, &slot_num);
3255 2682167 : gcc_assert (slot_num != (unsigned)-1);
3256 2682167 : data[index + 1] = slot_num;
3257 : }
3258 :
3259 186712 : lto_write_data (data, sizeof (int32_t) * (size + 1));
3260 186712 : free (data);
3261 186712 : }
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 186712 : lto_output_decl_state_streams (struct output_block *ob,
3269 : struct lto_out_decl_state *state)
3270 : {
3271 186712 : int i;
3272 :
3273 373424 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3274 186712 : write_global_stream (ob, &state->streams[i]);
3275 186712 : }
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 186712 : lto_output_decl_state_refs (struct output_block *ob,
3283 : struct lto_out_decl_state *state)
3284 : {
3285 186712 : unsigned i;
3286 186712 : uint32_t ref, lm_order;
3287 186712 : tree decl;
3288 :
3289 : /* Write reference to FUNCTION_DECL. If there is not function,
3290 : write reference to void_type_node. */
3291 186712 : decl = (state->fn_decl) ? state->fn_decl : void_type_node;
3292 186712 : streamer_tree_cache_lookup (ob->writer_cache, decl, &ref);
3293 186712 : gcc_assert (ref != (uint32_t)-1);
3294 186712 : ref = ref * 2 + (state->compressed ? 1 : 0);
3295 186712 : lto_write_data (&ref, sizeof (uint32_t));
3296 186712 : if (state->fn_decl)
3297 : {
3298 155048 : lm_order = state->linemap_id;
3299 155048 : lto_write_data (&lm_order, sizeof (lm_order));
3300 : }
3301 373424 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3302 186712 : write_global_references (ob, &state->streams[i]);
3303 186712 : }
3304 :
3305 :
3306 : /* Return the written size of STATE. */
3307 :
3308 : static size_t
3309 186712 : lto_out_decl_state_written_size (struct lto_out_decl_state *state)
3310 : {
3311 186712 : int i;
3312 186712 : size_t size;
3313 :
3314 186712 : size = sizeof (int32_t); /* fn_ref. */
3315 186712 : if (state->fn_decl)
3316 155048 : size += sizeof (int32_t); /* linemap_id. */
3317 373424 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3318 : {
3319 186712 : size += sizeof (int32_t); /* vector size. */
3320 186712 : size += (lto_tree_ref_encoder_size (&state->streams[i])
3321 186712 : * sizeof (int32_t));
3322 : }
3323 186712 : 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 545317 : write_symbol (struct streamer_tree_cache_d *cache,
3332 : tree t, hash_set<const char *> *seen, bool alias)
3333 : {
3334 545317 : const char *name;
3335 545317 : enum gcc_plugin_symbol_kind kind;
3336 545317 : enum gcc_plugin_symbol_visibility visibility = GCCPV_DEFAULT;
3337 545317 : unsigned slot_num;
3338 545317 : uint64_t size;
3339 545317 : const char *comdat;
3340 545317 : unsigned char c;
3341 :
3342 545317 : gcc_assert (VAR_OR_FUNCTION_DECL_P (t));
3343 :
3344 545317 : 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 545317 : name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
3349 :
3350 545317 : if (seen->add (name))
3351 769 : return;
3352 :
3353 544548 : streamer_tree_cache_lookup (cache, t, &slot_num);
3354 544548 : gcc_assert (slot_num != (unsigned)-1);
3355 :
3356 544548 : if (DECL_EXTERNAL (t))
3357 : {
3358 215666 : if (DECL_WEAK (t))
3359 : kind = GCCPK_WEAKUNDEF;
3360 : else
3361 215628 : kind = GCCPK_UNDEF;
3362 : }
3363 : else
3364 : {
3365 328882 : if (DECL_WEAK (t))
3366 : kind = GCCPK_WEAKDEF;
3367 316740 : else if (DECL_COMMON (t))
3368 : kind = GCCPK_COMMON;
3369 : else
3370 316679 : kind = GCCPK_DEF;
3371 :
3372 : /* When something is defined, it should have node attached. */
3373 328882 : gcc_assert (alias || !VAR_P (t) || varpool_node::get (t)->definition);
3374 328882 : 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 544548 : if (DECL_EXTERNAL (t)
3387 544548 : && !targetm.binds_local_p (t))
3388 : visibility = GCCPV_DEFAULT;
3389 : else
3390 328936 : switch (DECL_VISIBILITY (t))
3391 : {
3392 : case VISIBILITY_DEFAULT:
3393 : visibility = GCCPV_DEFAULT;
3394 : break;
3395 : case VISIBILITY_PROTECTED:
3396 544548 : 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 544548 : if (kind == GCCPK_COMMON
3407 61 : && DECL_SIZE_UNIT (t)
3408 544609 : && TREE_CODE (DECL_SIZE_UNIT (t)) == INTEGER_CST)
3409 61 : size = TREE_INT_CST_LOW (DECL_SIZE_UNIT (t));
3410 : else
3411 544487 : size = 0;
3412 :
3413 544548 : if (DECL_ONE_ONLY (t))
3414 12105 : comdat = IDENTIFIER_POINTER (decl_comdat_group_id (t));
3415 : else
3416 : comdat = "";
3417 :
3418 544548 : lto_write_data (name, strlen (name) + 1);
3419 544548 : lto_write_data (comdat, strlen (comdat) + 1);
3420 544548 : c = (unsigned char) kind;
3421 544548 : lto_write_data (&c, 1);
3422 544548 : c = (unsigned char) visibility;
3423 544548 : lto_write_data (&c, 1);
3424 544548 : lto_write_data (&size, 8);
3425 544548 : lto_write_data (&slot_num, 4);
3426 : }
3427 :
3428 : /* Write extension information for symbols (symbol type, section flags). */
3429 :
3430 : static void
3431 545317 : write_symbol_extension_info (tree t)
3432 : {
3433 545317 : unsigned char c;
3434 545317 : c = ((unsigned char) TREE_CODE (t) == VAR_DECL
3435 : ? GCCST_VARIABLE : GCCST_FUNCTION);
3436 545317 : lto_write_data (&c, 1);
3437 545317 : unsigned char section_kind = 0;
3438 545317 : if (VAR_P (t))
3439 : {
3440 234674 : section *s = get_variable_section (t, false);
3441 234674 : if (s->common.flags & SECTION_BSS)
3442 224619 : section_kind |= GCCSSK_BSS;
3443 : }
3444 545317 : lto_write_data (§ion_kind, 1);
3445 545317 : }
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 23417 : produce_symtab (struct output_block *ob)
3452 : {
3453 23417 : unsigned int streamed_symbols = 0;
3454 23417 : struct streamer_tree_cache_d *cache = ob->writer_cache;
3455 23417 : char *section_name = lto_get_section_name (LTO_section_symtab, NULL, 0, NULL);
3456 23417 : lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
3457 23417 : lto_symtab_encoder_iterator lsei;
3458 :
3459 23417 : lto_begin_section (section_name, false);
3460 23417 : free (section_name);
3461 :
3462 23417 : 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 23417 : for (lsei = lsei_start (encoder);
3468 625181 : !lsei_end_p (lsei); lsei_next (&lsei))
3469 : {
3470 601764 : toplevel_node *tnode = lsei_node (lsei);
3471 601764 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3472 601764 : if (!node)
3473 84 : continue;
3474 :
3475 601680 : if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3476 272798 : continue;
3477 328882 : write_symbol (cache, node->decl, &seen, false);
3478 328882 : ++streamed_symbols;
3479 : }
3480 23417 : for (lsei = lsei_start (encoder);
3481 625181 : !lsei_end_p (lsei); lsei_next (&lsei))
3482 : {
3483 601764 : toplevel_node *tnode = lsei_node (lsei);
3484 601764 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3485 601764 : if (!node)
3486 84 : continue;
3487 :
3488 601680 : if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3489 385245 : continue;
3490 216435 : write_symbol (cache, node->decl, &seen, false);
3491 216435 : ++streamed_symbols;
3492 : }
3493 :
3494 23417 : lto_end_section ();
3495 :
3496 23417 : return streamed_symbols;
3497 23417 : }
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 23417 : produce_symtab_extension (struct output_block *ob,
3507 : unsigned int previous_streamed_symbols)
3508 : {
3509 23417 : unsigned int streamed_symbols = 0;
3510 23417 : char *section_name = lto_get_section_name (LTO_section_symtab_extension,
3511 : NULL, 0, NULL);
3512 23417 : lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
3513 23417 : lto_symtab_encoder_iterator lsei;
3514 :
3515 23417 : lto_begin_section (section_name, false);
3516 23417 : free (section_name);
3517 :
3518 23417 : unsigned char version = LTO_SYMTAB_EXTENSION_VERSION;
3519 23417 : 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 23417 : for (lsei = lsei_start (encoder);
3525 625181 : !lsei_end_p (lsei); lsei_next (&lsei))
3526 : {
3527 601764 : toplevel_node *tnode = lsei_node (lsei);
3528 601764 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3529 601764 : if (!node)
3530 84 : continue;
3531 :
3532 601680 : if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3533 272798 : continue;
3534 328882 : write_symbol_extension_info (node->decl);
3535 328882 : ++streamed_symbols;
3536 : }
3537 23417 : for (lsei = lsei_start (encoder);
3538 625181 : !lsei_end_p (lsei); lsei_next (&lsei))
3539 : {
3540 601764 : toplevel_node *tnode = lsei_node (lsei);
3541 601764 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3542 601764 : if (!node)
3543 84 : continue;
3544 :
3545 601680 : if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3546 385245 : continue;
3547 216435 : write_symbol_extension_info (node->decl);
3548 216435 : ++streamed_symbols;
3549 : }
3550 :
3551 23417 : gcc_assert (previous_streamed_symbols == streamed_symbols);
3552 23417 : lto_end_section ();
3553 23417 : }
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 31664 : lto_output_init_mode_table (void)
3560 : {
3561 31664 : memset (streamer_mode_table, '\0', MAX_MACHINE_MODE);
3562 31664 : }
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 31664 : produce_asm_for_decls (void)
3659 : {
3660 31664 : struct lto_out_decl_state *out_state;
3661 31664 : struct lto_out_decl_state *fn_out_state;
3662 31664 : struct lto_decl_header header;
3663 31664 : char *section_name;
3664 31664 : struct output_block *ob;
3665 31664 : unsigned idx, num_fns;
3666 31664 : size_t decl_state_size;
3667 31664 : int32_t num_decl_states;
3668 :
3669 31664 : ob = create_output_block (LTO_section_decls);
3670 :
3671 31664 : memset (&header, 0, sizeof (struct lto_decl_header));
3672 :
3673 31664 : section_name = lto_get_section_name (LTO_section_decls, NULL, 0, NULL);
3674 31664 : lto_begin_section (section_name, !flag_wpa);
3675 31664 : free (section_name);
3676 :
3677 : /* Make string 0 be a NULL string. */
3678 31664 : streamer_write_char_stream (ob->string_stream, 0);
3679 :
3680 31664 : gcc_assert (!alias_pairs);
3681 :
3682 : /* Get rid of the global decl state hash tables to save some memory. */
3683 31664 : out_state = lto_get_out_decl_state ();
3684 94992 : for (int i = 0; i < LTO_N_DECL_STREAMS; i++)
3685 31664 : if (out_state->streams[i].tree_hash_table)
3686 : {
3687 31664 : delete out_state->streams[i].tree_hash_table;
3688 31664 : out_state->streams[i].tree_hash_table = NULL;
3689 : }
3690 :
3691 : /* Write the global symbols. */
3692 31664 : if (streamer_dump_file)
3693 4 : fprintf (streamer_dump_file, "Outputting global stream\n");
3694 31664 : lto_output_decl_state_streams (ob, out_state);
3695 31664 : num_fns = lto_function_decl_states.length ();
3696 186712 : for (idx = 0; idx < num_fns; idx++)
3697 : {
3698 155048 : fn_out_state =
3699 155048 : lto_function_decl_states[idx];
3700 155048 : 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 155048 : 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 31664 : header.num_nodes = -1;
3710 :
3711 : /* Compute the total size of all decl out states. */
3712 31664 : decl_state_size = sizeof (int32_t);
3713 31664 : decl_state_size += lto_out_decl_state_written_size (out_state);
3714 186712 : for (idx = 0; idx < num_fns; idx++)
3715 : {
3716 155048 : fn_out_state =
3717 155048 : lto_function_decl_states[idx];
3718 155048 : decl_state_size += lto_out_decl_state_written_size (fn_out_state);
3719 : }
3720 31664 : header.decl_state_size = decl_state_size;
3721 :
3722 31664 : header.main_size = ob->main_stream->total_size;
3723 31664 : header.string_size = ob->string_stream->total_size;
3724 :
3725 31664 : lto_write_data (&header, sizeof header);
3726 :
3727 : /* Write the main out-decl state, followed by out-decl states of
3728 : functions. */
3729 31664 : num_decl_states = num_fns + 1;
3730 31664 : lto_write_data (&num_decl_states, sizeof (num_decl_states));
3731 31664 : lto_output_decl_state_refs (ob, out_state);
3732 218376 : for (idx = 0; idx < num_fns; idx++)
3733 : {
3734 155048 : fn_out_state = lto_function_decl_states[idx];
3735 155048 : lto_output_decl_state_refs (ob, fn_out_state);
3736 : }
3737 :
3738 31664 : lto_write_stream (ob->main_stream);
3739 31664 : lto_write_stream (ob->string_stream);
3740 :
3741 31664 : 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 31664 : if (!flag_wpa)
3746 : {
3747 23417 : unsigned int streamed_symbols = produce_symtab (ob);
3748 23417 : produce_symtab_extension (ob, streamed_symbols);
3749 : }
3750 :
3751 : /* Write command line opts. */
3752 31664 : lto_write_options ();
3753 :
3754 : /* Deallocate memory and clean up. */
3755 218376 : for (idx = 0; idx < num_fns; idx++)
3756 : {
3757 155048 : fn_out_state =
3758 155048 : lto_function_decl_states[idx];
3759 155048 : lto_delete_out_decl_state (fn_out_state);
3760 : }
3761 31664 : lto_symtab_encoder_delete (ob->decl_state->symtab_node_encoder);
3762 31664 : lto_function_decl_states.release ();
3763 31664 : destroy_output_block (ob);
3764 31664 : 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 31664 : if (flag_incremental_link == INCREMENTAL_LINK_LTO)
3772 35 : lto_copy_linemaps ();
3773 31629 : else if (!flag_wpa)
3774 : {
3775 23382 : gcc_checking_assert (!in_lto_p);
3776 23382 : loc_output.produce_linemap_section ();
3777 : }
3778 31664 : }
|