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 351867 : 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 351867 : ob->current_block = void_node;
64 351867 : ob->current_discr = UINT_MAX;
65 351867 : ob->current_map_idx = 0;
66 351867 : ob->current_loc_offset = 0;
67 351867 : 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 351867 : create_output_block (enum lto_section_type section_type)
76 : {
77 351867 : struct output_block *ob = XCNEW (struct output_block);
78 351867 : 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 351867 : ob->section_type = section_type;
83 351867 : 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 351867 : if (!flag_wpa && section_type == LTO_section_decls)
87 23539 : ob->local_trees = new (hash_set <tree>);
88 351867 : ob->main_stream = XCNEW (struct lto_output_stream);
89 351867 : ob->string_stream = XCNEW (struct lto_output_stream);
90 351867 : ob->writer_cache = streamer_tree_cache_create (!flag_wpa, true, false);
91 :
92 351867 : if (section_type == LTO_section_function_body)
93 120129 : ob->cfg_stream = XCNEW (struct lto_output_stream);
94 :
95 351867 : clear_line_info (ob);
96 :
97 351867 : ob->string_hash_table = new hash_table<string_slot_hasher> (37);
98 351867 : gcc_obstack_init (&ob->obstack);
99 :
100 351867 : return ob;
101 : }
102 :
103 :
104 : /* Destroy the output block OB. */
105 :
106 : void
107 351867 : destroy_output_block (struct output_block *ob)
108 : {
109 351867 : enum lto_section_type section_type = ob->section_type;
110 :
111 351867 : delete ob->string_hash_table;
112 351867 : ob->string_hash_table = NULL;
113 375406 : delete ob->local_trees;
114 :
115 351867 : free (ob->main_stream);
116 351867 : free (ob->string_stream);
117 351867 : if (section_type == LTO_section_function_body)
118 120129 : free (ob->cfg_stream);
119 :
120 351867 : streamer_tree_cache_delete (ob->writer_cache);
121 351867 : obstack_free (&ob->obstack, NULL);
122 :
123 351867 : free (ob);
124 351867 : }
125 :
126 :
127 : /* Wrapper around variably_modified_type_p avoiding type modification
128 : during WPA streaming. */
129 :
130 : bool
131 14441754 : lto_variably_modified_type_p (tree type)
132 : {
133 14441754 : return (in_lto_p
134 14441754 : ? TYPE_LANG_FLAG_0 (TYPE_MAIN_VARIANT (type))
135 14140845 : : 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 36069009 : 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 34957735 : if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
151 36402459 : && DECL_CONTEXT (t))
152 1444724 : 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 34624285 : else if (TREE_CODE (t) == IMPORTED_DECL)
156 0 : gcc_unreachable ();
157 34624285 : else if (TREE_CODE (t) == LABEL_DECL)
158 81827 : return FORCED_LABEL (t) || DECL_NONLOCAL (t);
159 1673467 : 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 35435880 : && decl_function_context (t))
164 : return false;
165 33658923 : 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 33656989 : else if (TYPE_P (t)
172 33656989 : && lto_variably_modified_type_p (t))
173 : return false;
174 33645385 : else if (TREE_CODE (t) == FIELD_DECL
175 33645385 : && lto_variably_modified_type_p (DECL_CONTEXT (t)))
176 : return false;
177 : else
178 33644954 : 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 63011 : compute_map_hash (const line_map_ordinary *map)
190 : {
191 63011 : inchash::hash h;
192 63011 : h.add_int (map->sysp);
193 63011 : h.add_int (map->m_column_and_range_bits - map->m_range_bits);
194 63011 : h.add_int (map->to_line);
195 63011 : h.add_object (map->included_from);
196 63011 : h.add (map->to_file, strlen (map->to_file));
197 63011 : 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 20889 : void register_map_id (size_t map_idx, unsigned linemap_id)
220 : {
221 33800 : gcc_checking_assert (LINEMAPS_ORDINARY_USED (line_table)
222 : == orig_map_ids.length () + 1);
223 20889 : const auto map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
224 20889 : const hashval_t hash = compute_map_hash (map);
225 20889 : orig_map_ids.safe_push (map_id_t{map_idx, linemap_id, hash});
226 20889 : }
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 6978028 : location_output::record_location (location_t loc)
243 : {
244 : /* Strip away any macro expansion data or embedded range information. */
245 6978028 : loc = linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
246 : nullptr);
247 6978028 : loc = get_pure_location (loc);
248 6978028 : location_id_t loc_id = {};
249 6978028 : if (loc < RESERVED_LOCATION_COUNT)
250 : {
251 : /* IDX 0 is for reserved locations. */
252 2432210 : loc_id.offset = loc;
253 2432210 : return loc_id;
254 : }
255 :
256 4545818 : const auto map = linemap_check_ordinary (linemap_lookup (line_table, loc));
257 :
258 4545818 : 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 385720 : gcc_checking_assert (orig_map_ids.length ()
263 : == LINEMAPS_ORDINARY_USED (line_table));
264 192860 : gcc_checking_assert (!map->m_range_bits);
265 192860 : loc_id.map_id = orig_map_ids[map - line_table->info_ordinary.maps];
266 192860 : loc_id.offset = loc - map->start_location;
267 192860 : return loc_id;
268 : }
269 :
270 : /* Represent each location_t as the offset from the map start,
271 : without any range bits. */
272 4352958 : map_data &md = map_data_map.get_or_insert (map);
273 4352958 : if (!md.idx)
274 : {
275 42122 : md.idx = map_data_map.elements ();
276 42122 : md.hash = compute_map_hash (map);
277 : }
278 4352958 : md.highest_location = MAX (md.highest_location, loc);
279 4352958 : loc_id.map_id.idx = md.idx;
280 4352958 : loc_id.map_id.hash = md.hash;
281 4352958 : loc_id.offset = (loc - map->start_location) >> map->m_range_bits;
282 4352958 : 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 8919028 : bp_pack_delta (bitpack_d *bp, Int val, Int &prev)
291 : {
292 8919028 : const bool decrease = (val < prev);
293 8919028 : bp_pack_value (bp, decrease, 1);
294 8919028 : bp_pack_var_len_unsigned (bp, decrease ? prev - val : val - prev);
295 8919028 : prev = val;
296 8919028 : }
297 :
298 : void
299 23502 : location_output::produce_linemap_section ()
300 : {
301 23502 : timevar_push (TV_IPA_LTO_LINEMAP_OUT);
302 :
303 23502 : const auto ob = create_output_block (LTO_section_linemap);
304 23502 : 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 23502 : const auto &chist = global_dc->get_classification_history ();
311 90423 : for (auto &c : chist)
312 64213 : record_location (c.location);
313 :
314 : /* Sort the maps in the order they need to be inserted later. */
315 23502 : const size_t nmaps = map_data_map.elements ();
316 23502 : using KV = std::pair<const line_map_ordinary *, map_data>;
317 65624 : const std::unique_ptr<KV[]> sorted_maps{new KV[nmaps]};
318 23502 : size_t map_i = 0;
319 65624 : for (auto iter = map_data_map.begin (), end = map_data_map.end ();
320 65624 : iter != end; ++iter)
321 42122 : sorted_maps[map_i++] = *iter;
322 23502 : 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 23502 : bp_pack_var_len_unsigned (&bp, nmaps);
334 23502 : const char *current_file = nullptr;
335 23502 : bool emit_pwd = true;
336 23502 : size_t prev_idx = 0;
337 23502 : linenum_type prev_line = 0;
338 65624 : for (map_i = 0; map_i != nmaps; ++map_i)
339 : {
340 42122 : const auto map = sorted_maps[map_i].first;
341 42122 : const map_data &md = sorted_maps[map_i].second;
342 42122 : bp_pack_delta (&bp, md.idx, prev_idx);
343 42122 : const auto num_lines
344 42122 : = 1 + ((md.highest_location - map->start_location)
345 42122 : >> map->m_column_and_range_bits);
346 42122 : bp_pack_var_len_unsigned (&bp, num_lines);
347 42122 : bp_pack_value (&bp, map->sysp != 0, 1);
348 42122 : bp_pack_value (&bp, map->m_column_and_range_bits - map->m_range_bits, 8);
349 42122 : bp_pack_delta (&bp, map->to_line, prev_line);
350 42122 : const bool file_change = (map->to_file != current_file);
351 42122 : bp_pack_value (&bp, file_change, 1);
352 42122 : if (file_change)
353 : {
354 42122 : bool stream_pwd = false;
355 42122 : const char *remapped = remap_debug_filename (map->to_file);
356 42122 : if (emit_pwd && remapped && !IS_ABSOLUTE_PATH (remapped))
357 : {
358 1947 : stream_pwd = true;
359 1947 : emit_pwd = false;
360 : }
361 42122 : bp_pack_value (&bp, stream_pwd, 1);
362 42122 : if (stream_pwd)
363 1947 : bp_pack_string (ob, &bp, get_src_pwd (), true);
364 42122 : bp_pack_string (ob, &bp, remapped, true);
365 : }
366 : }
367 :
368 : /* Output the diagnostics classification history. */
369 24856 : bp_pack_var_len_unsigned (&bp, chist.length ());
370 90423 : for (auto &c : chist)
371 : {
372 64213 : const location_id_t loc_id = record_location (c.location);
373 64213 : bp_pack_var_len_unsigned (&bp, loc_id.map_id.idx);
374 64213 : bp_pack_var_len_unsigned (&bp, loc_id.offset);
375 64213 : bp_pack_var_len_int (&bp, c.option);
376 64213 : using DK = diagnostics::kind;
377 64213 : bp_pack_enum (&bp, DK, DK::tot_num_diagnostic_kinds, c.kind);
378 : }
379 :
380 : /* Finalize the section. */
381 23502 : streamer_write_bitpack (&bp);
382 23502 : {
383 23502 : const auto section_name
384 23502 : = lto_get_section_name (LTO_section_linemap, nullptr, 0, nullptr);
385 23502 : lto_begin_section (section_name, true);
386 23502 : free (section_name);
387 : }
388 :
389 23502 : lto_simple_header_with_strings header = {};
390 23502 : header.main_size = ob->main_stream->total_size;
391 23502 : header.string_size = ob->string_stream->total_size;
392 23502 : lto_write_data (&header, sizeof header);
393 23502 : lto_write_stream (ob->main_stream);
394 23502 : lto_write_stream (ob->string_stream);
395 23502 : lto_end_section ();
396 23502 : destroy_output_block (ob);
397 :
398 23502 : timevar_pop (TV_IPA_LTO_LINEMAP_OUT);
399 23502 : }
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 6849602 : lto_output_location_1 (struct output_block *ob, struct bitpack_d *bp,
410 : location_t loc, bool block_p)
411 : {
412 6849602 : const auto loc_id = loc_output.record_location (loc);
413 6849602 : if (!loc_id.map_id.idx)
414 : {
415 2432210 : bp_pack_value (bp, true, 1);
416 2432210 : bp_pack_int_in_range (bp, 0, RESERVED_LOCATION_COUNT - 1, loc_id.offset);
417 : }
418 : else
419 : {
420 4417392 : bp_pack_value (bp, false, 1);
421 4417392 : if (loc_id.map_id.linemap_id == ob->current_linemap_id)
422 4274762 : bp_pack_value (bp, false, 1);
423 : else
424 : {
425 142630 : bp_pack_value (bp, true, 1);
426 142630 : bp_pack_var_len_unsigned (bp, loc_id.map_id.linemap_id);
427 142630 : ob->current_linemap_id = loc_id.map_id.linemap_id;
428 : }
429 4417392 : const bool is_new_map = (loc_id.map_id.idx != ob->current_map_idx);
430 4417392 : bp_pack_delta (bp, loc_id.map_id.idx, ob->current_map_idx);
431 4417392 : bp_pack_delta (bp, loc_id.offset, ob->current_loc_offset);
432 4417392 : if (is_new_map)
433 225120 : bp_pack_var_len_unsigned (bp, loc_id.map_id.hash);
434 4417392 : const unsigned discr = get_discriminator_from_loc (loc);
435 4417392 : bp_pack_value (bp, ob->current_discr != discr, 1);
436 4417392 : if (ob->current_discr != discr)
437 : {
438 1327438 : bp_pack_var_len_unsigned (bp, discr);
439 1327438 : ob->current_discr = discr;
440 : }
441 : }
442 :
443 6849602 : if (block_p)
444 : {
445 2988220 : tree block = LOCATION_BLOCK (loc);
446 2988220 : bp_pack_value (bp, ob->current_block != block, 1);
447 2988220 : streamer_write_bitpack (bp);
448 2988220 : if (ob->current_block != block)
449 : {
450 756364 : lto_output_tree (ob, block, true, true);
451 756364 : ob->current_block = block;
452 : }
453 : }
454 6849602 : }
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 3861382 : lto_output_location (struct output_block *ob, struct bitpack_d *bp,
462 : location_t loc)
463 : {
464 3861382 : lto_output_location_1 (ob, bp, loc, false);
465 3861382 : }
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 2988220 : lto_output_location_and_block (struct output_block *ob, struct bitpack_d *bp,
474 : location_t loc)
475 : {
476 2988220 : lto_output_location_1 (ob, bp, loc, true);
477 2988220 : }
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 8033804 : lto_get_index (struct lto_tree_ref_encoder *encoder, tree t)
488 : {
489 8033804 : bool existed_p;
490 :
491 8033804 : unsigned int &index
492 8033804 : = encoder->tree_hash_table->get_or_insert (t, &existed_p);
493 8033804 : if (!existed_p)
494 : {
495 2216981 : index = encoder->trees.length ();
496 2216981 : 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 2216981 : encoder->trees.safe_push (t);
503 : }
504 :
505 8033804 : 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 9547311 : lto_indexable_tree_ref (struct output_block *ob, tree expr,
515 : enum LTO_tags *tag, unsigned *index)
516 : {
517 9547311 : gcc_checking_assert (tree_is_indexable (expr));
518 :
519 9547311 : if (TREE_CODE (expr) == SSA_NAME)
520 : {
521 2227369 : *tag = LTO_ssa_name_ref;
522 2227369 : *index = SSA_NAME_VERSION (expr);
523 : }
524 : else
525 : {
526 7319942 : *tag = LTO_global_stream_ref;
527 7319942 : *index = lto_get_index (&ob->decl_state->streams[LTO_DECL_STREAM], expr);
528 : }
529 9547311 : }
530 :
531 :
532 : /* Output a static or extern var DECL to OBS. */
533 :
534 : void
535 290294 : lto_output_var_decl_ref (struct lto_out_decl_state *decl_state,
536 : struct lto_output_stream * obs, tree decl)
537 : {
538 290294 : gcc_checking_assert (VAR_P (decl));
539 290294 : streamer_write_uhwi_stream
540 290294 : (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM],
541 : decl));
542 290294 : }
543 :
544 :
545 : /* Output a static or extern var DECL to OBS. */
546 :
547 : void
548 423568 : lto_output_fn_decl_ref (struct lto_out_decl_state *decl_state,
549 : struct lto_output_stream * obs, tree decl)
550 : {
551 423568 : gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
552 423568 : streamer_write_uhwi_stream
553 423568 : (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM], decl));
554 423568 : }
555 :
556 : /* Return true if EXPR is a tree node that can be written to disk. */
557 :
558 : static inline bool
559 7156441 : lto_is_streamable (tree expr)
560 : {
561 7156441 : 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 7156441 : return !is_lang_specific (expr)
566 7156441 : && code != SSA_NAME
567 7156441 : && code != LANG_TYPE
568 : && code != MODIFY_EXPR
569 7156441 : && code != INIT_EXPR
570 7156441 : && code != TARGET_EXPR
571 7156441 : && code != BIND_EXPR
572 7156441 : && code != WITH_CLEANUP_EXPR
573 7156441 : && code != STATEMENT_LIST
574 7156441 : && (code == CASE_LABEL_EXPR
575 7156441 : || code == DECL_EXPR
576 7148418 : || code == ASM_EXPR
577 7148378 : || 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 101759 : subtract_estimated_size (tree *tp, int *ws, void *data)
589 : {
590 101759 : long *sum = (long *)data;
591 101759 : 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 101759 : if (TREE_CODE (*tp) == STRING_CST)
600 7767 : *sum -= TREE_STRING_LENGTH (*tp) + 8;
601 : else
602 : {
603 : /* Identifiers are also variable length but should not appear
604 : naked in constructor. */
605 93992 : 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 93992 : *sum -= 16;
609 : }
610 101759 : if (*sum < 0)
611 33346 : 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 2448748 : get_symbol_initial_value (lto_symtab_encoder_t encoder, tree expr)
620 : {
621 2448748 : 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 2448748 : tree initial = DECL_INITIAL (expr);
627 2448748 : if (VAR_P (expr)
628 1216634 : && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
629 863268 : && !DECL_IN_CONSTANT_POOL (expr)
630 3311884 : && initial)
631 : {
632 86269 : varpool_node *vnode;
633 : /* Extra section needs about 30 bytes; do not produce it for simple
634 : scalar values. */
635 86269 : if (!(vnode = varpool_node::get (expr))
636 86269 : || !lto_symtab_encoder_encode_initializer_p (encoder, vnode))
637 3283 : initial = error_mark_node;
638 86269 : if (initial != error_mark_node)
639 : {
640 69322 : long max_size = 30;
641 69322 : if (walk_tree (&initial, subtract_estimated_size, (void *)&max_size,
642 : NULL))
643 33346 : initial = error_mark_node;
644 : }
645 : }
646 :
647 2448748 : 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 32448401 : stream_write_tree_ref (struct output_block *ob, tree t)
658 : {
659 32448401 : if (!t)
660 12394010 : streamer_write_zero (ob);
661 : else
662 : {
663 20054391 : unsigned int ix;
664 20054391 : bool existed_p = streamer_tree_cache_lookup (ob->writer_cache, t, &ix);
665 20054391 : if (existed_p)
666 15577031 : streamer_write_hwi (ob, ix + 1);
667 : else
668 : {
669 4477360 : enum LTO_tags tag;
670 4477360 : unsigned ix;
671 4477360 : int id = 0;
672 :
673 4477360 : lto_indexable_tree_ref (ob, t, &tag, &ix);
674 4477360 : if (tag == LTO_ssa_name_ref)
675 : id = 1;
676 : else
677 4269037 : gcc_checking_assert (tag == LTO_global_stream_ref);
678 4477360 : streamer_write_hwi (ob, -(int)(ix * 2 + id + 1));
679 : }
680 : }
681 32448401 : }
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 7156441 : lto_write_tree_1 (struct output_block *ob, tree expr, bool ref_p)
692 : {
693 7156441 : 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 7156441 : streamer_write_tree_bitfields (ob, expr);
704 :
705 : /* Write all the pointer fields in EXPR. */
706 7156441 : streamer_write_tree_body (ob, expr);
707 :
708 : /* Write any LTO-specific data to OB. */
709 7156441 : if (DECL_P (expr)
710 1548990 : && TREE_CODE (expr) != FUNCTION_DECL
711 1111675 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
712 : {
713 : /* Handle DECL_INITIAL for symbols. */
714 1079322 : tree initial = get_symbol_initial_value
715 1079322 : (ob->decl_state->symtab_node_encoder, expr);
716 1079322 : 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 7156441 : if ((DECL_P (expr)
722 : && TREE_CODE (expr) != FIELD_DECL
723 : && TREE_CODE (expr) != DEBUG_EXPR_DECL
724 : && TREE_CODE (expr) != TYPE_DECL)
725 5748278 : || TREE_CODE (expr) == BLOCK)
726 : {
727 1762404 : const char *sym;
728 1762404 : unsigned HOST_WIDE_INT off;
729 1762404 : if (debug_info_level > DINFO_LEVEL_NONE
730 1762404 : && debug_hooks->die_ref_for_decl (expr, &sym, &off))
731 : {
732 49558 : streamer_write_string (ob, ob->main_stream, sym, true);
733 49558 : streamer_write_uhwi (ob, off);
734 : }
735 : else
736 1712846 : streamer_write_string (ob, ob->main_stream, NULL, true);
737 : }
738 7156441 : }
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 6875909 : lto_write_tree (struct output_block *ob, tree expr, bool ref_p)
747 : {
748 6875909 : 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 6875909 : streamer_write_tree_header (ob, expr);
755 :
756 6875909 : lto_write_tree_1 (ob, expr, ref_p);
757 6875909 : }
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 7950037 : lto_output_tree_1 (struct output_block *ob, tree expr, hashval_t hash,
765 : bool ref_p, bool this_ref_p)
766 : {
767 7950037 : unsigned ix;
768 :
769 7950037 : gcc_checking_assert (expr != NULL_TREE
770 : && !(this_ref_p && tree_is_indexable (expr)));
771 :
772 7950037 : bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
773 : expr, hash, &ix);
774 7950037 : gcc_assert (!exists_p);
775 7950037 : if (TREE_CODE (expr) == INTEGER_CST
776 7950037 : && !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 1074128 : 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 6875909 : lto_write_tree (ob, expr, ref_p);
788 : }
789 7950037 : }
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 2904814 : local_tree_p (tree t)
850 : {
851 2904814 : switch (TREE_CODE (t))
852 : {
853 : case LABEL_DECL:
854 : return true;
855 1672 : case NAMESPACE_DECL:
856 1672 : return !DECL_NAME (t);
857 622575 : case VAR_DECL:
858 622575 : case FUNCTION_DECL:
859 622575 : return !TREE_PUBLIC (t) && !DECL_EXTERNAL (t);
860 75373 : case RECORD_TYPE:
861 75373 : case UNION_TYPE:
862 75373 : case ENUMERAL_TYPE:
863 : /* Anonymous namespace types are local.
864 : Only work hard for main variants;
865 : variant types will inherit locality. */
866 75373 : return TYPE_MAIN_VARIANT (t) == t
867 60217 : && odr_type_p (t) && type_with_linkage_p (t)
868 96016 : && 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 3018728 : DFS::DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p,
881 3018728 : bool single_p)
882 : {
883 3018728 : unsigned int next_dfs_num = 1;
884 :
885 3018728 : max_local_entry = -1;
886 3018728 : gcc_obstack_init (&sccstate_obstack);
887 3018728 : DFS_write_tree (ob, NULL, expr, ref_p, this_ref_p);
888 21979103 : while (!worklist_vec.is_empty ())
889 : {
890 18018345 : worklist &w = worklist_vec.last ();
891 18018345 : expr = w.expr;
892 18018345 : sccs *from_state = w.from_state;
893 18018345 : sccs *cstate = w.cstate;
894 18018345 : ref_p = w.ref_p;
895 18018345 : this_ref_p = w.this_ref_p;
896 18018345 : if (cstate == NULL)
897 : {
898 9776886 : sccs **slot = &sccstate.get_or_insert (expr);
899 9776886 : cstate = *slot;
900 9776886 : if (cstate)
901 : {
902 1535427 : gcc_checking_assert (from_state);
903 1535427 : if (cstate->dfsnum < from_state->dfsnum)
904 195883 : from_state->low = MIN (cstate->dfsnum, from_state->low);
905 1535427 : worklist_vec.pop ();
906 1535427 : continue;
907 : }
908 :
909 8241459 : scc_entry e = { expr, 0 };
910 : /* Not yet visited. DFS recurse and push it onto the stack. */
911 8241459 : *slot = cstate = XOBNEW (&sccstate_obstack, struct sccs);
912 8241459 : if (ob->local_trees && local_tree_p (expr))
913 87272 : max_local_entry = sccstack.length ();
914 8241459 : sccstack.safe_push (e);
915 8241459 : cstate->dfsnum = next_dfs_num++;
916 8241459 : cstate->low = cstate->dfsnum;
917 8241459 : w.cstate = cstate;
918 :
919 8241459 : if (TREE_CODE (expr) == INTEGER_CST
920 8241459 : && !TREE_OVERFLOW (expr))
921 1119650 : DFS_write_tree (ob, cstate, TREE_TYPE (expr), ref_p, ref_p);
922 : else
923 : {
924 7121809 : DFS_write_tree_body (ob, expr, cstate, ref_p);
925 :
926 : /* Walk any LTO-specific edges. */
927 7121809 : if (DECL_P (expr)
928 1552674 : && TREE_CODE (expr) != FUNCTION_DECL
929 1115359 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
930 : {
931 : /* Handle DECL_INITIAL for symbols. */
932 1083006 : tree initial
933 1083006 : = get_symbol_initial_value (ob->decl_state->symtab_node_encoder,
934 : expr);
935 1083006 : DFS_write_tree (ob, cstate, initial, ref_p, ref_p);
936 : }
937 : }
938 8241459 : continue;
939 8241459 : }
940 :
941 : /* See if we found an SCC. */
942 8241459 : if (cstate->low == cstate->dfsnum)
943 : {
944 8033947 : unsigned first, size;
945 8033947 : 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 8033947 : if (single_p)
950 : {
951 343 : worklist_vec.pop ();
952 343 : continue;
953 : }
954 :
955 : /* Pop the SCC and compute its size. */
956 16067208 : first = sccstack.length ();
957 8230569 : do
958 : {
959 8230569 : x = sccstack[--first].t;
960 : }
961 8230569 : while (x != expr);
962 8033604 : size = sccstack.length () - first;
963 :
964 : /* No need to compute hashes for LTRANS units, we don't perform
965 : any merging there. */
966 8033604 : hashval_t scc_hash = 0;
967 8033604 : unsigned scc_entry_len = 0;
968 21405359 : bool local_to_unit = !ob->local_trees
969 8033604 : || max_local_entry >= (int)first;
970 :
971 : /* Remember that trees are local so info gets propagated to other
972 : SCCs. */
973 5338151 : if (local_to_unit && ob->local_trees)
974 : {
975 97406 : for (unsigned i = 0; i < size; ++i)
976 50184 : 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 8033604 : if (size == 1
984 8033604 : && TREE_CODE (sccstack[first].t) == TRANSLATION_UNIT_DECL)
985 : local_to_unit = true;
986 :
987 8001251 : if (!local_to_unit)
988 : {
989 2672128 : 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 2672128 : unsigned entry_start = 0;
993 2672128 : scc_entry_len = size + 1;
994 5492543 : for (unsigned i = 0; i < size;)
995 : {
996 2820415 : unsigned from = i;
997 2820415 : for (i = i + 1; i < size
998 2820415 : && (sccstack[first + i].hash
999 148287 : == sccstack[first + from].hash); ++i)
1000 : ;
1001 2820415 : if (i - from < scc_entry_len)
1002 : {
1003 2672128 : scc_entry_len = i - from;
1004 2672128 : entry_start = from;
1005 : }
1006 : }
1007 5344256 : for (unsigned i = 0; i < scc_entry_len; ++i)
1008 2672128 : std::swap (sccstack[first + i],
1009 2672128 : 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 2672128 : gcc_checking_assert (scc_entry_len == 1);
1017 : }
1018 :
1019 8033604 : worklist_vec.pop ();
1020 :
1021 8033604 : unsigned int prev_size = ob->main_stream->total_size;
1022 :
1023 : /* Only global decl sections are considered by tree merging. */
1024 8033604 : 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 4550230 : if (worklist_vec.is_empty () && first == 0 && size == 1)
1029 : return;
1030 2473532 : if (streamer_dump_file)
1031 : {
1032 140 : fprintf (streamer_dump_file,
1033 : " Start of LTO_trees of size %i\n", size);
1034 : }
1035 2473532 : streamer_write_record_start (ob, LTO_trees);
1036 2473532 : streamer_write_uhwi (ob, size);
1037 : }
1038 : /* Write LTO_tree_scc if tree merging is going to be performed. */
1039 3483374 : 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 3483374 : && (size != 1
1045 2604447 : || (TREE_CODE (sccstack[first].t) != IDENTIFIER_NODE
1046 1719804 : && (TREE_CODE (sccstack[first].t) != INTEGER_CST
1047 157404 : || TREE_OVERFLOW (sccstack[first].t)))))
1048 :
1049 : {
1050 1630083 : gcc_checking_assert (ob->section_type == LTO_section_decls);
1051 1630083 : if (streamer_dump_file)
1052 : {
1053 172 : fprintf (streamer_dump_file,
1054 : " Start of LTO_tree_scc of size %i\n", size);
1055 : }
1056 1630083 : 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 1630083 : streamer_write_uhwi (ob, size * 2 + (scc_entry_len != 1));
1061 1630083 : if (scc_entry_len != 1)
1062 0 : streamer_write_uhwi (ob, scc_entry_len);
1063 1630083 : streamer_write_uhwi (ob, scc_hash);
1064 : }
1065 : /* Non-trivial SCCs must be packed to trees blocks so forward
1066 : references work correctly. */
1067 1853291 : else if (size != 1)
1068 : {
1069 15750 : if (streamer_dump_file)
1070 : {
1071 0 : fprintf (streamer_dump_file,
1072 : " Start of LTO_trees of size %i\n", size);
1073 : }
1074 15750 : streamer_write_record_start (ob, LTO_trees);
1075 15750 : streamer_write_uhwi (ob, size);
1076 : }
1077 1837541 : 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 5956906 : if (size == 1)
1087 5873339 : 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 364099 : for (unsigned i = 0; i < size; ++i)
1093 : {
1094 280532 : hashval_t hash = sccstack[first+i].hash;
1095 280532 : tree t = sccstack[first+i].t;
1096 280532 : bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
1097 : t, hash, NULL);
1098 280532 : gcc_assert (!exists_p);
1099 :
1100 280532 : 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 280532 : streamer_write_tree_header (ob, t);
1108 : }
1109 :
1110 : /* Write the bitpacks and tree references. */
1111 364099 : for (unsigned i = 0; i < size; ++i)
1112 280532 : lto_write_tree_1 (ob, sccstack[first+i].t, ref_p);
1113 : }
1114 5956906 : 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 5956906 : sccstack.truncate (first);
1120 5956906 : if ((int)first <= max_local_entry)
1121 47222 : max_local_entry = first - 1;
1122 :
1123 5956906 : if (from_state)
1124 5015219 : from_state->low = MIN (from_state->low, cstate->low);
1125 5956906 : continue;
1126 5956906 : }
1127 :
1128 207512 : gcc_checking_assert (from_state);
1129 207512 : from_state->low = MIN (from_state->low, cstate->low);
1130 207512 : if (cstate->dfsnum < from_state->dfsnum)
1131 0 : from_state->low = MIN (cstate->dfsnum, from_state->low);
1132 207512 : worklist_vec.pop ();
1133 : }
1134 : }
1135 :
1136 3018728 : DFS::~DFS ()
1137 : {
1138 3018728 : obstack_free (&sccstate_obstack, NULL);
1139 3018728 : }
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 7121809 : 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 7121809 : enum tree_code code;
1152 :
1153 7121809 : code = TREE_CODE (expr);
1154 :
1155 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
1156 : {
1157 6704461 : if (TREE_CODE (expr) != IDENTIFIER_NODE)
1158 5197486 : DFS_follow_tree_edge (TREE_TYPE (expr));
1159 : }
1160 :
1161 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
1162 : {
1163 5948 : unsigned int count = vector_cst_encoded_nelts (expr);
1164 31583 : for (unsigned int i = 0; i < count; ++i)
1165 19687 : DFS_follow_tree_edge (VECTOR_CST_ENCODED_ELT (expr, i));
1166 : }
1167 :
1168 7121809 : 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 7121809 : 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 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
1179 : {
1180 : /* Drop names that were created for anonymous entities. */
1181 1552674 : if (DECL_NAME (expr)
1182 1366866 : && TREE_CODE (DECL_NAME (expr)) == IDENTIFIER_NODE
1183 2919540 : && IDENTIFIER_ANON_P (DECL_NAME (expr)))
1184 : ;
1185 : else
1186 1552061 : DFS_follow_tree_edge (DECL_NAME (expr));
1187 1552674 : if (TREE_CODE (expr) != TRANSLATION_UNIT_DECL
1188 1552674 : && ! DECL_CONTEXT (expr))
1189 15592 : DFS_follow_tree_edge ((*all_translation_units)[0]);
1190 : else
1191 1537082 : DFS_follow_tree_edge (DECL_CONTEXT (expr));
1192 : }
1193 :
1194 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1195 : {
1196 1552674 : DFS_follow_tree_edge (DECL_SIZE (expr));
1197 1552674 : 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 1552674 : 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 1552674 : gcc_assert (DECL_ABSTRACT_ORIGIN (expr) != error_mark_node);
1208 1552674 : DFS_follow_tree_edge (DECL_ABSTRACT_ORIGIN (expr));
1209 :
1210 1552674 : if ((VAR_P (expr)
1211 1552674 : || TREE_CODE (expr) == PARM_DECL)
1212 1552674 : && DECL_HAS_VALUE_EXPR_P (expr))
1213 6632 : DFS_follow_tree_edge (DECL_VALUE_EXPR (expr));
1214 1552674 : if (VAR_P (expr)
1215 1552674 : && DECL_HAS_DEBUG_EXPR_P (expr))
1216 1701 : DFS_follow_tree_edge (DECL_DEBUG_EXPR (expr));
1217 : }
1218 :
1219 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1220 : {
1221 : /* Make sure we don't inadvertently set the assembler name. */
1222 933360 : if (DECL_ASSEMBLER_NAME_SET_P (expr))
1223 753142 : DFS_follow_tree_edge (DECL_ASSEMBLER_NAME (expr));
1224 : }
1225 :
1226 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
1227 : {
1228 115362 : DFS_follow_tree_edge (DECL_FIELD_OFFSET (expr));
1229 115362 : DFS_follow_tree_edge (DECL_BIT_FIELD_TYPE (expr));
1230 115362 : DFS_follow_tree_edge (DECL_BIT_FIELD_REPRESENTATIVE (expr));
1231 115362 : DFS_follow_tree_edge (DECL_FIELD_BIT_OFFSET (expr));
1232 115362 : gcc_checking_assert (!DECL_FCONTEXT (expr));
1233 : }
1234 :
1235 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1236 : {
1237 437315 : gcc_checking_assert (DECL_VINDEX (expr) == NULL);
1238 437315 : DFS_follow_tree_edge (DECL_FUNCTION_PERSONALITY (expr));
1239 437315 : DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_TARGET (expr));
1240 437315 : DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr));
1241 : }
1242 :
1243 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1244 : {
1245 666374 : DFS_follow_tree_edge (TYPE_SIZE (expr));
1246 666374 : DFS_follow_tree_edge (TYPE_SIZE_UNIT (expr));
1247 666374 : DFS_follow_tree_edge (TYPE_ATTRIBUTES (expr));
1248 666374 : 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 666374 : DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr));
1254 666374 : 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 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1263 : {
1264 666374 : if (TREE_CODE (expr) == ARRAY_TYPE)
1265 46809 : DFS_follow_tree_edge (TYPE_DOMAIN (expr));
1266 619565 : else if (RECORD_OR_UNION_TYPE_P (expr))
1267 249042 : for (tree t = TYPE_FIELDS (expr); t; t = TREE_CHAIN (t))
1268 152763 : DFS_follow_tree_edge (t);
1269 523286 : else if (FUNC_OR_METHOD_TYPE_P (expr))
1270 177136 : DFS_follow_tree_edge (TYPE_ARG_TYPES (expr));
1271 :
1272 666374 : if (!POINTER_TYPE_P (expr))
1273 403375 : DFS_follow_tree_edge (TYPE_MIN_VALUE_RAW (expr));
1274 666374 : DFS_follow_tree_edge (TYPE_MAX_VALUE_RAW (expr));
1275 : }
1276 :
1277 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1278 : {
1279 688361 : DFS_follow_tree_edge (TREE_PURPOSE (expr));
1280 688361 : DFS_follow_tree_edge (TREE_VALUE (expr));
1281 688361 : DFS_follow_tree_edge (TREE_CHAIN (expr));
1282 : }
1283 :
1284 7121809 : 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 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_EXP))
1291 : {
1292 4218348 : for (int i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
1293 2481598 : DFS_follow_tree_edge (TREE_OPERAND (expr, i));
1294 1736750 : DFS_follow_tree_edge (TREE_BLOCK (expr));
1295 : }
1296 :
1297 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1298 : {
1299 501128 : 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 146887 : gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
1305 146887 : DFS_follow_tree_edge (t);
1306 : }
1307 :
1308 354241 : DFS_follow_tree_edge (BLOCK_SUPERCONTEXT (expr));
1309 354241 : 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 7121809 : 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 20348 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr), i, t)
1331 10807 : DFS_follow_tree_edge (t);
1332 9541 : DFS_follow_tree_edge (BINFO_OFFSET (expr));
1333 9541 : 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 7121809 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1341 : {
1342 : unsigned i;
1343 : tree index, value;
1344 :
1345 770899 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr), i, index, value)
1346 : {
1347 532759 : DFS_follow_tree_edge (index);
1348 532759 : DFS_follow_tree_edge (value);
1349 : }
1350 : }
1351 :
1352 7121809 : if (code == RAW_DATA_CST)
1353 21 : DFS_follow_tree_edge (RAW_DATA_OWNER (expr));
1354 :
1355 7121809 : if (code == OMP_CLAUSE)
1356 : {
1357 : int i;
1358 494 : for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (expr)]; i++)
1359 280 : DFS_follow_tree_edge (OMP_CLAUSE_OPERAND (expr, i));
1360 214 : DFS_follow_tree_edge (OMP_CLAUSE_CHAIN (expr));
1361 : }
1362 :
1363 : #undef DFS_follow_tree_edge
1364 7121809 : }
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 2820415 : hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, tree t)
1372 : {
1373 2820415 : 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 2820415 : enum tree_code code = TREE_CODE (t);
1390 2820415 : hstate.add_int (code);
1391 2820415 : if (!TYPE_P (t))
1392 : {
1393 2357297 : hstate.add_flag (TREE_SIDE_EFFECTS (t));
1394 2357297 : hstate.add_flag (TREE_CONSTANT (t));
1395 2357297 : hstate.add_flag (TREE_READONLY (t));
1396 2357297 : hstate.add_flag (TREE_PUBLIC (t));
1397 : }
1398 2820415 : hstate.add_flag (TREE_ADDRESSABLE (t));
1399 2820415 : hstate.add_flag (TREE_THIS_VOLATILE (t));
1400 2820415 : if (DECL_P (t))
1401 687573 : hstate.add_flag (DECL_UNSIGNED (t));
1402 2132842 : else if (TYPE_P (t))
1403 463118 : hstate.add_flag (TYPE_UNSIGNED (t));
1404 2820415 : if (TYPE_P (t))
1405 463118 : hstate.add_flag (TYPE_ARTIFICIAL (t));
1406 : else
1407 2357297 : hstate.add_flag (TREE_NO_WARNING (t));
1408 2820415 : hstate.add_flag (TREE_NOTHROW (t));
1409 2820415 : hstate.add_flag (TREE_STATIC (t));
1410 2820415 : hstate.add_flag (TREE_PROTECTED (t));
1411 2820415 : hstate.add_flag (TREE_DEPRECATED (t));
1412 2820415 : if (code != TREE_BINFO)
1413 2814095 : hstate.add_flag (TREE_PRIVATE (t));
1414 2820415 : if (TYPE_P (t))
1415 : {
1416 463118 : hstate.add_flag (AGGREGATE_TYPE_P (t)
1417 463118 : ? TYPE_REVERSE_STORAGE_ORDER (t) : TYPE_SATURATING (t));
1418 463118 : hstate.add_flag (TYPE_ADDR_SPACE (t));
1419 : }
1420 2357297 : else if (code == SSA_NAME)
1421 0 : hstate.add_flag (SSA_NAME_IS_DEFAULT_DEF (t));
1422 2820415 : hstate.commit_flag ();
1423 :
1424 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
1425 188900 : hstate.add_wide_int (wi::to_widest (t));
1426 :
1427 2820415 : 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 2820415 : 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 2820415 : 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 687573 : 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 687573 : && AGGREGATE_TYPE_P (TREE_TYPE (t)))
1457 0 : hstate.add_hwi (VOIDmode);
1458 : else
1459 687573 : hstate.add_hwi (DECL_MODE (t));
1460 687573 : hstate.add_flag (DECL_NONLOCAL (t));
1461 687573 : hstate.add_flag (DECL_VIRTUAL_P (t));
1462 687573 : hstate.add_flag (DECL_IGNORED_P (t));
1463 687573 : hstate.add_flag (DECL_ABSTRACT_P (t));
1464 687573 : hstate.add_flag (DECL_ARTIFICIAL (t));
1465 687573 : hstate.add_flag (DECL_USER_ALIGN (t));
1466 687573 : hstate.add_flag (DECL_PRESERVE_P (t));
1467 687573 : hstate.add_flag (DECL_EXTERNAL (t));
1468 687573 : hstate.add_flag (DECL_NOT_GIMPLE_REG_P (t));
1469 687573 : hstate.commit_flag ();
1470 687573 : hstate.add_int (DECL_ALIGN (t));
1471 687573 : 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 687573 : else if (code == FIELD_DECL)
1477 : {
1478 82761 : hstate.add_flag (DECL_PACKED (t));
1479 82761 : hstate.add_flag (DECL_NONADDRESSABLE_P (t));
1480 82761 : hstate.add_flag (DECL_PADDING_P (t));
1481 82761 : if (DECL_BIT_FIELD (t))
1482 5038 : hstate.add_flag (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (t));
1483 : else
1484 159271 : hstate.add_flag (DECL_FIELD_ABI_IGNORED (t));
1485 82761 : hstate.add_int (DECL_OFFSET_ALIGN (t));
1486 : }
1487 604812 : else if (code == VAR_DECL)
1488 : {
1489 235633 : hstate.add_flag (DECL_HAS_DEBUG_EXPR_P (t));
1490 235633 : hstate.add_flag (DECL_NONLOCAL_FRAME (t));
1491 : }
1492 687573 : if (code == RESULT_DECL
1493 687573 : || code == PARM_DECL
1494 : || code == VAR_DECL)
1495 : {
1496 235645 : hstate.add_flag (DECL_BY_REFERENCE (t));
1497 235645 : if (code == VAR_DECL
1498 235645 : || code == PARM_DECL)
1499 235645 : hstate.add_flag (DECL_HAS_VALUE_EXPR_P (t));
1500 : }
1501 687573 : hstate.commit_flag ();
1502 : }
1503 :
1504 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1505 604808 : hstate.add_int (DECL_REGISTER (t));
1506 :
1507 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1508 : {
1509 604796 : hstate.add_flag (DECL_COMMON (t));
1510 604796 : hstate.add_flag (DECL_DLLIMPORT_P (t));
1511 604796 : hstate.add_flag (DECL_WEAK (t));
1512 604796 : hstate.add_flag (DECL_SEEN_IN_BIND_EXPR_P (t));
1513 604796 : hstate.add_flag (DECL_COMDAT (t));
1514 604796 : hstate.add_flag (DECL_VISIBILITY_SPECIFIED (t));
1515 604796 : hstate.add_int (DECL_VISIBILITY (t));
1516 604796 : if (code == VAR_DECL)
1517 : {
1518 : /* DECL_IN_TEXT_SECTION is set during final asm output only. */
1519 235633 : hstate.add_flag (DECL_HARD_REGISTER (t));
1520 235633 : hstate.add_flag (DECL_IN_CONSTANT_POOL (t));
1521 : }
1522 604796 : if (TREE_CODE (t) == FUNCTION_DECL)
1523 : {
1524 346131 : hstate.add_flag (DECL_FINAL_P (t));
1525 346131 : hstate.add_flag (DECL_CXX_CONSTRUCTOR_P (t));
1526 346131 : hstate.add_flag (DECL_CXX_DESTRUCTOR_P (t));
1527 : }
1528 604796 : hstate.commit_flag ();
1529 : }
1530 :
1531 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1532 : {
1533 346131 : hstate.add_int (DECL_BUILT_IN_CLASS (t));
1534 346131 : hstate.add_flag (DECL_STATIC_CONSTRUCTOR (t));
1535 346131 : hstate.add_flag (DECL_STATIC_DESTRUCTOR (t));
1536 346131 : hstate.add_int ((unsigned)FUNCTION_DECL_DECL_TYPE (t));
1537 346131 : hstate.add_flag (DECL_UNINLINABLE (t));
1538 346131 : hstate.add_flag (DECL_POSSIBLY_INLINED (t));
1539 346131 : hstate.add_flag (DECL_IS_NOVOPS (t));
1540 346131 : hstate.add_flag (DECL_IS_RETURNS_TWICE (t));
1541 346131 : hstate.add_flag (DECL_IS_MALLOC (t));
1542 346131 : hstate.add_flag (DECL_DECLARED_INLINE_P (t));
1543 346131 : hstate.add_flag (DECL_STATIC_CHAIN (t));
1544 346131 : hstate.add_flag (DECL_NO_INLINE_WARNING_P (t));
1545 346131 : hstate.add_flag (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (t));
1546 346131 : hstate.add_flag (DECL_NO_LIMIT_STACK (t));
1547 346131 : hstate.add_flag (DECL_DISREGARD_INLINE_LIMITS (t));
1548 346131 : hstate.add_flag (DECL_PURE_P (t));
1549 346131 : hstate.add_flag (DECL_LOOPING_CONST_OR_PURE_P (t));
1550 346131 : hstate.commit_flag ();
1551 346131 : if (DECL_BUILT_IN_CLASS (t) != NOT_BUILT_IN)
1552 22430 : hstate.add_int (DECL_UNCHECKED_FUNCTION_CODE (t));
1553 : }
1554 :
1555 2820415 : 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 463118 : 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 463118 : hstate.add_hwi (TYPE_MODE_RAW (t));
1570 : /* TYPE_NO_FORCE_BLK is private to stor-layout and need
1571 : no streaming. */
1572 463118 : hstate.add_flag (TYPE_PACKED (t));
1573 463118 : hstate.add_flag (TYPE_RESTRICT (t));
1574 463118 : hstate.add_flag (TYPE_USER_ALIGN (t));
1575 463118 : hstate.add_flag (TYPE_READONLY (t));
1576 463118 : if (RECORD_OR_UNION_TYPE_P (t))
1577 : {
1578 72586 : hstate.add_flag (TYPE_TRANSPARENT_AGGR (t));
1579 72586 : hstate.add_flag (TYPE_FINAL_P (t));
1580 72586 : hstate.add_flag (TYPE_CXX_ODR_P (t));
1581 : }
1582 390532 : else if (code == ARRAY_TYPE)
1583 29512 : hstate.add_flag (TYPE_NONALIASED_COMPONENT (t));
1584 463118 : if (code == ARRAY_TYPE || code == INTEGER_TYPE)
1585 74968 : hstate.add_flag (TYPE_STRING_FLAG (t));
1586 463118 : if (AGGREGATE_TYPE_P (t))
1587 102098 : hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
1588 463118 : hstate.commit_flag ();
1589 463118 : hstate.add_int (TYPE_PRECISION_RAW (t));
1590 463118 : hstate.add_int (TYPE_ALIGN (t));
1591 463118 : if (!lto_stream_offload_p)
1592 463118 : hstate.add_int (TYPE_EMPTY_P (t));
1593 : }
1594 :
1595 2820415 : 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 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION)
1600 : /* We don't stream these when passing things to a different target. */
1601 23035 : && !lto_stream_offload_p)
1602 23035 : hstate.add_hwi (cl_target_option_hash (TREE_TARGET_OPTION (t)));
1603 :
1604 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
1605 23249 : hstate.add_hwi (cl_optimization_hash (TREE_OPTIMIZATION (t)));
1606 :
1607 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1608 884643 : hstate.merge_hash (IDENTIFIER_HASH_VALUE (t));
1609 :
1610 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1611 4355 : hstate.add (TREE_STRING_POINTER (t), TREE_STRING_LENGTH (t));
1612 :
1613 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
1614 : {
1615 2774131 : if (code != IDENTIFIER_NODE)
1616 1889488 : visit (TREE_TYPE (t));
1617 : }
1618 :
1619 2820415 : 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 2820415 : 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 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
1631 : {
1632 0 : visit (TREE_REALPART (t));
1633 0 : visit (TREE_IMAGPART (t));
1634 : }
1635 :
1636 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
1637 : {
1638 : /* Drop names that were created for anonymous entities. */
1639 687573 : if (DECL_NAME (t)
1640 670139 : && TREE_CODE (DECL_NAME (t)) == IDENTIFIER_NODE
1641 1357712 : && IDENTIFIER_ANON_P (DECL_NAME (t)))
1642 : ;
1643 : else
1644 687216 : visit (DECL_NAME (t));
1645 687573 : if (DECL_FILE_SCOPE_P (t))
1646 : ;
1647 : else
1648 113221 : visit (DECL_CONTEXT (t));
1649 : }
1650 :
1651 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1652 : {
1653 687573 : visit (DECL_SIZE (t));
1654 687573 : visit (DECL_SIZE_UNIT (t));
1655 687573 : visit (DECL_ATTRIBUTES (t));
1656 687573 : if ((code == VAR_DECL
1657 687573 : || code == PARM_DECL)
1658 687573 : && DECL_HAS_VALUE_EXPR_P (t))
1659 20 : visit (DECL_VALUE_EXPR (t));
1660 687573 : if (code == VAR_DECL
1661 923206 : && 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 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1668 : {
1669 604796 : if (DECL_ASSEMBLER_NAME_SET_P (t))
1670 602335 : visit (DECL_ASSEMBLER_NAME (t));
1671 : }
1672 :
1673 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
1674 : {
1675 82761 : visit (DECL_FIELD_OFFSET (t));
1676 82761 : visit (DECL_BIT_FIELD_TYPE (t));
1677 82761 : visit (DECL_BIT_FIELD_REPRESENTATIVE (t));
1678 82761 : visit (DECL_FIELD_BIT_OFFSET (t));
1679 : }
1680 :
1681 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1682 : {
1683 346131 : visit (DECL_FUNCTION_PERSONALITY (t));
1684 346131 : visit (DECL_FUNCTION_SPECIFIC_TARGET (t));
1685 346131 : visit (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t));
1686 : }
1687 :
1688 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1689 : {
1690 463118 : visit (TYPE_SIZE (t));
1691 463118 : visit (TYPE_SIZE_UNIT (t));
1692 463118 : visit (TYPE_ATTRIBUTES (t));
1693 463118 : visit (TYPE_NAME (t));
1694 463118 : visit (TYPE_MAIN_VARIANT (t));
1695 463118 : if (TYPE_FILE_SCOPE_P (t))
1696 : ;
1697 : else
1698 16348 : visit (TYPE_CONTEXT (t));
1699 : }
1700 :
1701 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1702 : {
1703 463118 : if (code == ARRAY_TYPE)
1704 29512 : visit (TYPE_DOMAIN (t));
1705 433606 : else if (RECORD_OR_UNION_TYPE_P (t))
1706 179200 : for (tree f = TYPE_FIELDS (t); f; f = TREE_CHAIN (f))
1707 106614 : visit (f);
1708 361020 : else if (code == FUNCTION_TYPE
1709 361020 : || code == METHOD_TYPE)
1710 115382 : visit (TYPE_ARG_TYPES (t));
1711 463118 : if (!POINTER_TYPE_P (t))
1712 273047 : visit (TYPE_MIN_VALUE_RAW (t));
1713 463118 : visit (TYPE_MAX_VALUE_RAW (t));
1714 : }
1715 :
1716 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1717 : {
1718 529434 : visit (TREE_PURPOSE (t));
1719 529434 : visit (TREE_VALUE (t));
1720 529434 : visit (TREE_CHAIN (t));
1721 : }
1722 :
1723 2820415 : 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 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_EXP))
1728 : {
1729 7545 : hstate.add_hwi (TREE_OPERAND_LENGTH (t));
1730 18908 : for (int i = 0; i < TREE_OPERAND_LENGTH (t); ++i)
1731 11363 : visit (TREE_OPERAND (t, i));
1732 : }
1733 :
1734 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1735 : {
1736 : unsigned i;
1737 : tree b;
1738 12719 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t), i, b)
1739 6399 : visit (b);
1740 6320 : visit (BINFO_OFFSET (t));
1741 6320 : 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 2820415 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1748 : {
1749 389 : unsigned i;
1750 389 : tree index, value;
1751 592 : hstate.add_hwi (CONSTRUCTOR_NELTS (t));
1752 1731 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, index, value)
1753 : {
1754 1342 : visit (index);
1755 1342 : visit (value);
1756 : }
1757 : }
1758 :
1759 2820415 : if (code == OMP_CLAUSE)
1760 : {
1761 134 : int i;
1762 134 : HOST_WIDE_INT val;
1763 :
1764 134 : hstate.add_hwi (OMP_CLAUSE_CODE (t));
1765 134 : 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 134 : hstate.add_hwi (val);
1795 302 : for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (t)]; i++)
1796 168 : visit (OMP_CLAUSE_OPERAND (t, i));
1797 134 : visit (OMP_CLAUSE_CHAIN (t));
1798 : }
1799 :
1800 2820415 : 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 1578682 : DFS::scc_entry_compare (const void *p1_, const void *p2_)
1809 : {
1810 1578682 : const scc_entry *p1 = (const scc_entry *) p1_;
1811 1578682 : const scc_entry *p2 = (const scc_entry *) p2_;
1812 1578682 : if (p1->hash < p2->hash)
1813 : return -1;
1814 711698 : else if (p1->hash > p2->hash)
1815 690286 : 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 2672128 : DFS::hash_scc (struct output_block *ob, unsigned first, unsigned size,
1824 : bool ref_p, bool this_ref_p)
1825 : {
1826 2672128 : unsigned int last_classes = 0, iterations = 0;
1827 :
1828 : /* Compute hash values for the SCC members. */
1829 5492543 : for (unsigned i = 0; i < size; ++i)
1830 2820415 : sccstack[first+i].hash
1831 5640830 : = hash_tree (ob->writer_cache, NULL, sccstack[first+i].t);
1832 :
1833 2672128 : if (size == 1)
1834 2604447 : 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 67681 : do
1857 : {
1858 : /* Sort the SCC so we can easily check for uniqueness. */
1859 67681 : qsort (&sccstack[first], size, sizeof (scc_entry), scc_entry_compare);
1860 :
1861 67681 : unsigned int classes = 1;
1862 67681 : int firstunique = -1;
1863 :
1864 : /* Find the tree with lowest unique hash (if it exists) and compute
1865 : the number of equivalence classes. */
1866 67681 : if (sccstack[first].hash != sccstack[first+1].hash)
1867 67678 : firstunique = 0;
1868 215968 : for (unsigned i = 1; i < size; ++i)
1869 148287 : if (sccstack[first+i-1].hash != sccstack[first+i].hash)
1870 : {
1871 146326 : classes++;
1872 146326 : if (firstunique == -1
1873 146326 : && (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 67681 : 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 67681 : || classes <= last_classes || iterations > 16)
1886 : {
1887 67681 : 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 67681 : if (classes != size && firstunique != -1)
1892 : {
1893 343 : 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 11576 : for (unsigned i = 0; i < size; ++i)
1898 10890 : map.put (sccstack[first+i].t, sccstack[first+i].hash);
1899 :
1900 343 : DFS again (ob, sccstack[first+firstunique].t, ref_p, this_ref_p,
1901 343 : true);
1902 686 : gcc_assert (again.sccstack.length () == size);
1903 :
1904 343 : memcpy (sccstack.address () + first,
1905 343 : 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 343 : sccstack[first].hash = *map.get (sccstack[first].t);
1913 343 : scc_hash = sccstack[first].hash;
1914 10890 : for (unsigned i = 1; i < size; ++i)
1915 : {
1916 31641 : sccstack[first+i].hash
1917 10547 : = iterative_hash_hashval_t (i,
1918 10547 : *map.get (sccstack[first+i].t));
1919 10547 : scc_hash
1920 10547 : = iterative_hash_hashval_t (scc_hash,
1921 10547 : sccstack[first+i].hash);
1922 : }
1923 343 : }
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 205078 : for (unsigned i = 1; i < size; ++i)
1934 137740 : scc_hash
1935 137740 : = 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 67338 : 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 283649 : for (unsigned i = 0; i < size; ++i)
1947 431936 : sccstack[first+i].hash
1948 215968 : = iterative_hash_hashval_t (sccstack[first+i].hash, scc_hash);
1949 67681 : 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 35984309 : 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 35984309 : if (expr == NULL_TREE)
1979 26207423 : return;
1980 :
1981 : /* Do not DFS walk into indexable trees. */
1982 23492434 : if (this_ref_p && tree_is_indexable (expr))
1983 : return;
1984 :
1985 : /* Check if we already streamed EXPR. */
1986 17164479 : 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 7387593 : if (ob->local_trees
1991 7387593 : && ob->local_trees->contains (expr))
1992 18218 : max_local_entry = sccstack.length () - 1;
1993 : return;
1994 : }
1995 :
1996 9776886 : worklist w;
1997 9776886 : w.expr = expr;
1998 9776886 : w.from_state = from_state;
1999 9776886 : w.cstate = NULL;
2000 9776886 : w.ref_p = ref_p;
2001 9776886 : w.this_ref_p = this_ref_p;
2002 9776886 : 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 12902742 : lto_output_tree (struct output_block *ob, tree expr,
2012 : bool ref_p, bool this_ref_p)
2013 : {
2014 12902742 : unsigned ix;
2015 12902742 : bool existed_p;
2016 12902742 : 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 12902742 : static bool in_dfs_walk;
2020 :
2021 12902742 : if (expr == NULL_TREE)
2022 : {
2023 2893392 : streamer_write_record_start (ob, LTO_null);
2024 10856735 : return;
2025 : }
2026 :
2027 10009350 : if (this_ref_p && tree_is_indexable (expr))
2028 : {
2029 5069951 : enum LTO_tags tag;
2030 5069951 : unsigned ix;
2031 :
2032 5069951 : lto_indexable_tree_ref (ob, expr, &tag, &ix);
2033 5069951 : streamer_write_record_start (ob, tag);
2034 5069951 : streamer_write_uhwi (ob, ix);
2035 5069951 : return;
2036 : }
2037 :
2038 4939399 : existed_p = streamer_tree_cache_lookup (ob->writer_cache, expr, &ix);
2039 4939399 : if (existed_p)
2040 : {
2041 1921014 : 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 1921014 : streamer_write_record_start (ob, LTO_tree_pickle_reference);
2055 1921014 : streamer_write_uhwi (ob, ix);
2056 1921014 : 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 3018385 : gcc_assert (!in_dfs_walk);
2064 :
2065 3018385 : 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 3018385 : in_dfs_walk = true;
2076 3018385 : DFS (ob, expr, ref_p, this_ref_p, false);
2077 :
2078 : /* Finally append a reference to the tree we were writing. */
2079 3018385 : 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 3018385 : if (!existed_p)
2084 2076698 : lto_output_tree_1 (ob, expr, 0, ref_p, this_ref_p);
2085 941687 : 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 3018385 : in_dfs_walk = false;
2098 3018385 : lto_stats.num_pickle_refs_output++;
2099 : }
2100 4939399 : 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 313 : output_eh_try_list (struct output_block *ob, eh_catch first)
2110 : {
2111 313 : eh_catch n;
2112 :
2113 714 : for (n = first; n; n = n->next_catch)
2114 : {
2115 401 : streamer_write_record_start (ob, LTO_eh_catch);
2116 401 : stream_write_tree (ob, n->type_list, true);
2117 401 : stream_write_tree (ob, n->filter_list, true);
2118 401 : stream_write_tree (ob, n->label, true);
2119 : }
2120 :
2121 313 : streamer_write_record_start (ob, LTO_null);
2122 313 : }
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 18518 : output_eh_region (struct output_block *ob, eh_region r)
2131 : {
2132 18518 : enum LTO_tags tag;
2133 :
2134 18518 : if (r == NULL)
2135 : {
2136 7829 : streamer_write_record_start (ob, LTO_null);
2137 7829 : return;
2138 : }
2139 :
2140 10689 : 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 10689 : streamer_write_record_start (ob, tag);
2152 10689 : streamer_write_hwi (ob, r->index);
2153 :
2154 10689 : if (r->outer)
2155 3190 : streamer_write_hwi (ob, r->outer->index);
2156 : else
2157 7499 : streamer_write_zero (ob);
2158 :
2159 10689 : if (r->inner)
2160 1876 : streamer_write_hwi (ob, r->inner->index);
2161 : else
2162 8813 : streamer_write_zero (ob);
2163 :
2164 10689 : if (r->next_peer)
2165 4541 : streamer_write_hwi (ob, r->next_peer->index);
2166 : else
2167 6148 : streamer_write_zero (ob);
2168 :
2169 10689 : if (r->type == ERT_TRY)
2170 : {
2171 313 : output_eh_try_list (ob, r->u.eh_try.first_catch);
2172 : }
2173 10376 : 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 10052 : else if (r->type == ERT_MUST_NOT_THROW)
2180 : {
2181 5326 : stream_write_tree (ob, r->u.must_not_throw.failure_decl, true);
2182 5326 : bitpack_d bp = bitpack_create (ob->main_stream);
2183 5326 : stream_output_location (ob, &bp, r->u.must_not_throw.failure_loc);
2184 5326 : streamer_write_bitpack (&bp);
2185 : }
2186 :
2187 10689 : if (r->landing_pads)
2188 3261 : streamer_write_hwi (ob, r->landing_pads->index);
2189 : else
2190 7428 : streamer_write_zero (ob);
2191 : }
2192 :
2193 :
2194 : /* Output landing pad LP to OB. */
2195 :
2196 : static void
2197 8498 : output_eh_lp (struct output_block *ob, eh_landing_pad lp)
2198 : {
2199 8498 : if (lp == NULL)
2200 : {
2201 5188 : streamer_write_record_start (ob, LTO_null);
2202 5188 : return;
2203 : }
2204 :
2205 3310 : streamer_write_record_start (ob, LTO_eh_landing_pad);
2206 3310 : streamer_write_hwi (ob, lp->index);
2207 3310 : if (lp->next_lp)
2208 49 : streamer_write_hwi (ob, lp->next_lp->index);
2209 : else
2210 3261 : streamer_write_zero (ob);
2211 :
2212 3310 : if (lp->region)
2213 3310 : streamer_write_hwi (ob, lp->region->index);
2214 : else
2215 0 : streamer_write_zero (ob);
2216 :
2217 3310 : 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 108902 : output_eh_regions (struct output_block *ob, struct function *fn)
2225 : {
2226 108902 : if (fn->eh && fn->eh->region_tree)
2227 : {
2228 4272 : unsigned i;
2229 4272 : eh_region eh;
2230 4272 : eh_landing_pad lp;
2231 4272 : tree ttype;
2232 :
2233 4272 : streamer_write_record_start (ob, LTO_eh_table);
2234 :
2235 : /* Emit the index of the root of the EH region tree. */
2236 4272 : streamer_write_hwi (ob, fn->eh->region_tree->index);
2237 :
2238 : /* Emit all the EH regions in the region array. */
2239 4272 : streamer_write_hwi (ob, vec_safe_length (fn->eh->region_array));
2240 27062 : FOR_EACH_VEC_SAFE_ELT (fn->eh->region_array, i, eh)
2241 18518 : output_eh_region (ob, eh);
2242 :
2243 : /* Emit all landing pads. */
2244 4272 : streamer_write_hwi (ob, vec_safe_length (fn->eh->lp_array));
2245 17042 : FOR_EACH_VEC_SAFE_ELT (fn->eh->lp_array, i, lp)
2246 8498 : output_eh_lp (ob, lp);
2247 :
2248 : /* Emit all the runtime type data. */
2249 4272 : streamer_write_hwi (ob, vec_safe_length (fn->eh->ttype_data));
2250 8544 : 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 4272 : 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 4272 : uchar c;
2264 4272 : streamer_write_hwi (ob, vec_safe_length (fn->eh->ehspec_data.other));
2265 8544 : 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 108902 : streamer_write_record_start (ob, LTO_null);
2273 108902 : }
2274 :
2275 :
2276 : /* Output all of the active ssa names to the ssa_names stream. */
2277 :
2278 : static void
2279 108902 : output_ssa_names (struct output_block *ob, struct function *fn)
2280 : {
2281 108902 : unsigned int i, len;
2282 :
2283 108902 : len = vec_safe_length (SSANAMES (fn));
2284 108902 : streamer_write_uhwi (ob, len);
2285 :
2286 1855757 : for (i = 1; i < len; i++)
2287 : {
2288 1637953 : tree ptr = (*SSANAMES (fn))[i];
2289 :
2290 2248484 : if (ptr == NULL_TREE
2291 1631525 : || SSA_NAME_IN_FREE_LIST (ptr)
2292 1631525 : || virtual_operand_p (ptr)
2293 : /* Simply skip unreleased SSA names. */
2294 2668273 : || (! SSA_NAME_IS_DEFAULT_DEF (ptr)
2295 921881 : && (! SSA_NAME_DEF_STMT (ptr)
2296 921881 : || ! gimple_bb (SSA_NAME_DEF_STMT (ptr)))))
2297 610531 : continue;
2298 :
2299 1027422 : streamer_write_uhwi (ob, i);
2300 1027422 : streamer_write_char_stream (ob->main_stream,
2301 1027422 : SSA_NAME_IS_DEFAULT_DEF (ptr));
2302 1027422 : if (SSA_NAME_VAR (ptr))
2303 301601 : stream_write_tree (ob, SSA_NAME_VAR (ptr), true);
2304 : else
2305 : /* ??? This drops SSA_NAME_IDENTIFIER on the floor. */
2306 725821 : stream_write_tree (ob, TREE_TYPE (ptr), true);
2307 : }
2308 :
2309 108902 : streamer_write_zero (ob);
2310 108902 : }
2311 :
2312 :
2313 :
2314 : /* Output the cfg. */
2315 :
2316 : static void
2317 108902 : output_cfg (struct output_block *ob, struct function *fn)
2318 : {
2319 108902 : struct lto_output_stream *tmp_stream = ob->main_stream;
2320 108902 : basic_block bb;
2321 :
2322 108902 : ob->main_stream = ob->cfg_stream;
2323 :
2324 108902 : 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 108902 : streamer_write_uhwi (ob, last_basic_block_for_fn (fn));
2329 :
2330 1028808 : FOR_ALL_BB_FN (bb, fn)
2331 : {
2332 919906 : edge_iterator ei;
2333 919906 : edge e;
2334 :
2335 919906 : streamer_write_hwi (ob, bb->index);
2336 :
2337 : /* Output the successors and the edge flags. */
2338 1728204 : streamer_write_uhwi (ob, EDGE_COUNT (bb->succs));
2339 1965190 : FOR_EACH_EDGE (e, ei, bb->succs)
2340 : {
2341 1045284 : bitpack_d bp = bitpack_create (ob->main_stream);
2342 1045284 : bp_pack_var_len_unsigned (&bp, e->dest->index);
2343 1045284 : bp_pack_var_len_unsigned (&bp, e->flags);
2344 1045284 : stream_output_location_and_block (ob, &bp, e->goto_locus);
2345 1045284 : e->probability.stream_out (ob);
2346 : }
2347 : }
2348 :
2349 108902 : streamer_write_hwi (ob, -1);
2350 :
2351 108902 : bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
2352 919906 : while (bb->next_bb)
2353 : {
2354 811004 : streamer_write_hwi (ob, bb->next_bb->index);
2355 811004 : bb = bb->next_bb;
2356 : }
2357 :
2358 108902 : streamer_write_hwi (ob, -1);
2359 :
2360 : /* Output the number of loops. */
2361 108902 : streamer_write_uhwi (ob, number_of_loops (fn));
2362 :
2363 : /* Output each loop, skipping the tree root which has number zero. */
2364 476124 : for (unsigned i = 1; i < number_of_loops (fn); ++i)
2365 : {
2366 74709 : class loop *loop = get_loop (fn, i);
2367 :
2368 : /* Write the index of the loop header. That's enough to rebuild
2369 : the loop tree on the reader side. Stream -1 for an unused
2370 : loop entry. */
2371 74709 : if (!loop)
2372 : {
2373 25315 : streamer_write_hwi (ob, -1);
2374 25315 : continue;
2375 : }
2376 : else
2377 49394 : streamer_write_hwi (ob, loop->header->index);
2378 :
2379 : /* Write everything copy_loop_info copies. */
2380 49394 : streamer_write_enum (ob->main_stream,
2381 : loop_estimation, EST_LAST, loop->estimate_state);
2382 49394 : streamer_write_hwi (ob, loop->any_upper_bound);
2383 49394 : if (loop->any_upper_bound)
2384 : {
2385 40373 : widest_int w = widest_int::from (loop->nb_iterations_upper_bound,
2386 40373 : SIGNED);
2387 40373 : streamer_write_widest_int (ob, w);
2388 40373 : }
2389 49394 : streamer_write_hwi (ob, loop->any_likely_upper_bound);
2390 49394 : if (loop->any_likely_upper_bound)
2391 : {
2392 40373 : widest_int w
2393 40373 : = widest_int::from (loop->nb_iterations_likely_upper_bound,
2394 40373 : SIGNED);
2395 40373 : streamer_write_widest_int (ob, w);
2396 40373 : }
2397 49394 : streamer_write_hwi (ob, loop->any_estimate);
2398 49394 : if (loop->any_estimate)
2399 : {
2400 33312 : widest_int w = widest_int::from (loop->nb_iterations_estimate,
2401 33312 : SIGNED);
2402 33312 : streamer_write_widest_int (ob, w);
2403 33312 : }
2404 :
2405 : /* Write OMP SIMD related info. */
2406 49394 : streamer_write_hwi (ob, loop->safelen);
2407 49394 : streamer_write_hwi (ob, loop->unroll);
2408 49394 : streamer_write_hwi (ob, loop->owned_clique);
2409 49394 : streamer_write_hwi (ob, loop->dont_vectorize);
2410 49394 : streamer_write_hwi (ob, loop->force_vectorize);
2411 49394 : streamer_write_hwi (ob, loop->finite_p);
2412 49394 : streamer_write_hwi (ob, loop->can_be_parallel);
2413 49394 : stream_write_tree (ob, loop->simduid, true);
2414 : }
2415 :
2416 108902 : ob->main_stream = tmp_stream;
2417 108902 : }
2418 :
2419 : /* Create the header in the file using OB. If the section type is for
2420 : a function, set FN to the decl for that function. */
2421 :
2422 : void
2423 256558 : produce_symbol_asm (struct output_block *ob, tree fn, int output_order)
2424 : {
2425 256558 : enum lto_section_type section_type = ob->section_type;
2426 256558 : struct lto_function_header header;
2427 256558 : char *section_name;
2428 :
2429 256558 : if (section_type == LTO_section_function_body)
2430 : {
2431 120129 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn));
2432 120129 : section_name = lto_get_section_name (section_type, name,
2433 : output_order, NULL);
2434 : }
2435 : else
2436 136429 : section_name = lto_get_section_name (section_type, NULL, 0, NULL);
2437 :
2438 256558 : lto_begin_section (section_name, !flag_wpa);
2439 256558 : free (section_name);
2440 :
2441 : /* The entire header is stream computed here. */
2442 256558 : memset (&header, 0, sizeof (struct lto_function_header));
2443 :
2444 256558 : if (section_type == LTO_section_function_body)
2445 120129 : header.cfg_size = ob->cfg_stream->total_size;
2446 256558 : header.main_size = ob->main_stream->total_size;
2447 256558 : header.string_size = ob->string_stream->total_size;
2448 256558 : lto_write_data (&header, sizeof header);
2449 :
2450 : /* Put all of the gimple and the string table out the asm file as a
2451 : block of text. */
2452 256558 : if (section_type == LTO_section_function_body)
2453 120129 : lto_write_stream (ob->cfg_stream);
2454 256558 : lto_write_stream (ob->main_stream);
2455 256558 : lto_write_stream (ob->string_stream);
2456 :
2457 256558 : lto_end_section ();
2458 256558 : }
2459 :
2460 : /* Wrapper for unused arguments. */
2461 :
2462 : void
2463 136429 : produce_asm (struct output_block *ob)
2464 : {
2465 136429 : produce_symbol_asm (ob, NULL, -1);
2466 136429 : }
2467 :
2468 :
2469 : /* Output the base body of struct function FN using output block OB. */
2470 :
2471 : static void
2472 108902 : output_struct_function_base (struct output_block *ob, struct function *fn)
2473 : {
2474 108902 : struct bitpack_d bp;
2475 108902 : unsigned i;
2476 108902 : tree t;
2477 :
2478 : /* Output the static chain and non-local goto save area. */
2479 108902 : stream_write_tree (ob, fn->static_chain_decl, true);
2480 108902 : stream_write_tree (ob, fn->nonlocal_goto_save_area, true);
2481 :
2482 : /* Output all the local variables in the function. */
2483 108902 : streamer_write_hwi (ob, vec_safe_length (fn->local_decls));
2484 385133 : FOR_EACH_VEC_SAFE_ELT (fn->local_decls, i, t)
2485 167329 : stream_write_tree (ob, t, true);
2486 :
2487 : /* Output current IL state of the function. */
2488 108902 : streamer_write_uhwi (ob, fn->curr_properties);
2489 :
2490 : /* Write all the attributes for FN. */
2491 108902 : bp = bitpack_create (ob->main_stream);
2492 108902 : bp_pack_value (&bp, fn->is_thunk, 1);
2493 108902 : bp_pack_value (&bp, fn->has_local_explicit_reg_vars, 1);
2494 108902 : bp_pack_value (&bp, fn->returns_pcc_struct, 1);
2495 108902 : bp_pack_value (&bp, fn->returns_struct, 1);
2496 108902 : bp_pack_value (&bp, fn->can_throw_non_call_exceptions, 1);
2497 108902 : bp_pack_value (&bp, fn->can_delete_dead_exceptions, 1);
2498 108902 : bp_pack_value (&bp, fn->always_inline_functions_inlined, 1);
2499 108902 : bp_pack_value (&bp, fn->after_inlining, 1);
2500 108902 : bp_pack_value (&bp, fn->stdarg, 1);
2501 108902 : bp_pack_value (&bp, fn->has_nonlocal_label, 1);
2502 108902 : bp_pack_value (&bp, fn->has_forced_label_in_static, 1);
2503 108902 : bp_pack_value (&bp, fn->calls_alloca, 1);
2504 108902 : bp_pack_value (&bp, fn->calls_setjmp, 1);
2505 108902 : bp_pack_value (&bp, fn->calls_eh_return, 1);
2506 108902 : bp_pack_value (&bp, fn->has_force_vectorize_loops, 1);
2507 108902 : bp_pack_value (&bp, fn->has_simduid_loops, 1);
2508 108902 : bp_pack_value (&bp, fn->has_musttail, 1);
2509 108902 : bp_pack_value (&bp, fn->has_unroll, 1);
2510 108902 : bp_pack_value (&bp, fn->assume_function, 1);
2511 108902 : bp_pack_value (&bp, fn->va_list_fpr_size, 8);
2512 108902 : bp_pack_value (&bp, fn->va_list_gpr_size, 8);
2513 108902 : bp_pack_value (&bp, fn->last_clique, sizeof (short) * 8);
2514 :
2515 : /* Output the function start and end loci. */
2516 108902 : stream_output_location (ob, &bp, fn->function_start_locus);
2517 108902 : stream_output_location (ob, &bp, fn->function_end_locus);
2518 :
2519 : /* Save the instance discriminator if present. */
2520 108902 : int *instance_number_p = NULL;
2521 108902 : if (decl_to_instance_map)
2522 0 : instance_number_p = decl_to_instance_map->get (fn->decl);
2523 108902 : bp_pack_value (&bp, !!instance_number_p, 1);
2524 108902 : if (instance_number_p)
2525 0 : bp_pack_value (&bp, *instance_number_p, sizeof (int) * CHAR_BIT);
2526 :
2527 108902 : streamer_write_bitpack (&bp);
2528 108902 : }
2529 :
2530 :
2531 : /* Collect all leaf BLOCKs beyond ROOT into LEAFS. */
2532 :
2533 : static void
2534 247992 : collect_block_tree_leafs (tree root, vec<tree> &leafs)
2535 : {
2536 464665 : for (root = BLOCK_SUBBLOCKS (root); root; root = BLOCK_CHAIN (root))
2537 216673 : if (! BLOCK_SUBBLOCKS (root))
2538 77583 : leafs.safe_push (root);
2539 : else
2540 139090 : collect_block_tree_leafs (root, leafs);
2541 247992 : }
2542 :
2543 : /* This performs function body modifications that are needed for streaming
2544 : to work. */
2545 :
2546 : void
2547 108892 : lto_prepare_function_for_streaming (struct cgraph_node *node)
2548 : {
2549 108892 : struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
2550 108892 : basic_block bb;
2551 :
2552 217784 : if (number_of_loops (fn))
2553 : {
2554 108892 : push_cfun (fn);
2555 108892 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
2556 108892 : loop_optimizer_finalize ();
2557 108892 : pop_cfun ();
2558 : }
2559 : /* We will renumber the statements. The code that does this uses
2560 : the same ordering that we use for serializing them so we can use
2561 : the same code on the other end and not have to write out the
2562 : statement numbers. We do not assign UIDs to PHIs here because
2563 : virtual PHIs get re-computed on-the-fly which would make numbers
2564 : inconsistent. */
2565 108892 : set_gimple_stmt_max_uid (fn, 0);
2566 1028768 : FOR_ALL_BB_FN (bb, fn)
2567 : {
2568 1078787 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2569 158911 : gsi_next (&gsi))
2570 : {
2571 158911 : gphi *stmt = gsi.phi ();
2572 :
2573 : /* Virtual PHIs are not going to be streamed. */
2574 317822 : if (!virtual_operand_p (gimple_phi_result (stmt)))
2575 92146 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2576 : }
2577 3540455 : for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
2578 1700703 : gsi_next (&gsi))
2579 : {
2580 1700703 : gimple *stmt = gsi_stmt (gsi);
2581 1700703 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2582 : }
2583 : }
2584 : /* To avoid keeping duplicate gimple IDs in the statements, renumber
2585 : virtual phis now. */
2586 1028768 : FOR_ALL_BB_FN (bb, fn)
2587 : {
2588 1078787 : for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2589 158911 : gsi_next (&gsi))
2590 : {
2591 158911 : gphi *stmt = gsi.phi ();
2592 384587 : if (virtual_operand_p (gimple_phi_result (stmt)))
2593 66765 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
2594 : }
2595 : }
2596 :
2597 108892 : }
2598 :
2599 : /* Emit the chain of tree nodes starting at T. OB is the output block
2600 : to write to. REF_P is true if chain elements should be emitted
2601 : as references. */
2602 :
2603 : static void
2604 109048 : streamer_write_chain (struct output_block *ob, tree t, bool ref_p)
2605 : {
2606 430007 : while (t)
2607 : {
2608 : /* We avoid outputting external vars or functions by reference
2609 : to the global decls section as we do not want to have them
2610 : enter decl merging. We should not need to do this anymore because
2611 : free_lang_data removes them from block scopes. */
2612 320959 : gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
2613 320959 : stream_write_tree (ob, t, ref_p);
2614 :
2615 320959 : t = TREE_CHAIN (t);
2616 : }
2617 :
2618 : /* Write a sentinel to terminate the chain. */
2619 109048 : stream_write_tree (ob, NULL_TREE, ref_p);
2620 109048 : }
2621 :
2622 : /* Output the body of function NODE->DECL. */
2623 :
2624 : static void
2625 109048 : output_function (struct cgraph_node *node, int output_order)
2626 : {
2627 109048 : tree function;
2628 109048 : struct function *fn;
2629 109048 : basic_block bb;
2630 109048 : struct output_block *ob;
2631 :
2632 109048 : if (streamer_dump_file)
2633 8 : fprintf (streamer_dump_file, "\nStreaming body of %s\n",
2634 : node->dump_name ());
2635 :
2636 109048 : function = node->decl;
2637 109048 : fn = DECL_STRUCT_FUNCTION (function);
2638 109048 : ob = create_output_block (LTO_section_function_body);
2639 :
2640 109048 : ob->symbol = node;
2641 :
2642 109048 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
2643 :
2644 : /* Make string 0 be a NULL string. */
2645 109048 : streamer_write_char_stream (ob->string_stream, 0);
2646 :
2647 109048 : streamer_write_record_start (ob, LTO_function);
2648 :
2649 : /* Output decls for parameters and args. */
2650 109048 : stream_write_tree (ob, DECL_RESULT (function), true);
2651 109048 : streamer_write_chain (ob, DECL_ARGUMENTS (function), true);
2652 :
2653 : /* Output debug args if available. */
2654 109048 : vec<tree, va_gc> **debugargs = decl_debug_args_lookup (function);
2655 109048 : if (! debugargs)
2656 109019 : streamer_write_uhwi (ob, 0);
2657 : else
2658 : {
2659 29 : streamer_write_uhwi (ob, (*debugargs)->length ());
2660 132 : for (unsigned i = 0; i < (*debugargs)->length (); ++i)
2661 74 : stream_write_tree (ob, (**debugargs)[i], true);
2662 : }
2663 :
2664 : /* Output DECL_INITIAL for the function, which contains the tree of
2665 : lexical scopes. */
2666 109048 : stream_write_tree (ob, DECL_INITIAL (function), true);
2667 : /* As we do not recurse into BLOCK_SUBBLOCKS but only BLOCK_SUPERCONTEXT
2668 : collect block tree leafs and stream those. */
2669 109048 : auto_vec<tree> block_tree_leafs;
2670 109048 : if (DECL_INITIAL (function) && DECL_INITIAL (function) != error_mark_node)
2671 108902 : collect_block_tree_leafs (DECL_INITIAL (function), block_tree_leafs);
2672 109048 : streamer_write_uhwi (ob, block_tree_leafs.length ());
2673 295679 : for (unsigned i = 0; i < block_tree_leafs.length (); ++i)
2674 77583 : stream_write_tree (ob, block_tree_leafs[i], true);
2675 :
2676 : /* We also stream abstract functions where we stream only stuff needed for
2677 : debug info. */
2678 109048 : if (gimple_has_body_p (function))
2679 : {
2680 108902 : streamer_write_uhwi (ob, 1);
2681 108902 : output_struct_function_base (ob, fn);
2682 :
2683 108902 : output_cfg (ob, fn);
2684 :
2685 : /* Output all the SSA names used in the function. */
2686 108902 : output_ssa_names (ob, fn);
2687 :
2688 : /* Output any exception handling regions. */
2689 108902 : output_eh_regions (ob, fn);
2690 :
2691 : /* Output the code for the function. */
2692 1028808 : FOR_ALL_BB_FN (bb, fn)
2693 919906 : output_bb (ob, bb, fn);
2694 :
2695 : /* The terminator for this function. */
2696 108902 : streamer_write_record_start (ob, LTO_null);
2697 : }
2698 : else
2699 146 : streamer_write_uhwi (ob, 0);
2700 :
2701 : /* Create a section to hold the pickled output of this function. */
2702 109048 : produce_symbol_asm (ob, function, output_order);
2703 :
2704 109048 : destroy_output_block (ob);
2705 109048 : if (streamer_dump_file)
2706 8 : fprintf (streamer_dump_file, "Finished streaming %s\n",
2707 : node->dump_name ());
2708 109048 : }
2709 :
2710 : /* Output the body of function NODE->DECL. */
2711 :
2712 : static void
2713 11081 : output_constructor (struct varpool_node *node, int output_order)
2714 : {
2715 11081 : tree var = node->decl;
2716 11081 : struct output_block *ob;
2717 :
2718 11081 : if (streamer_dump_file)
2719 4 : fprintf (streamer_dump_file, "\nStreaming constructor of %s\n",
2720 : node->dump_name ());
2721 :
2722 11081 : timevar_push (TV_IPA_LTO_CTORS_OUT);
2723 11081 : ob = create_output_block (LTO_section_function_body);
2724 :
2725 11081 : ob->symbol = node;
2726 :
2727 : /* Make string 0 be a NULL string. */
2728 11081 : streamer_write_char_stream (ob->string_stream, 0);
2729 :
2730 : /* Output DECL_INITIAL for the function, which contains the tree of
2731 : lexical scopes. */
2732 11081 : stream_write_tree (ob, DECL_INITIAL (var), true);
2733 :
2734 : /* Create a section to hold the pickled output of this function. */
2735 11081 : produce_symbol_asm (ob, var, output_order);
2736 :
2737 11081 : destroy_output_block (ob);
2738 11081 : if (streamer_dump_file)
2739 4 : fprintf (streamer_dump_file, "Finished streaming %s\n",
2740 : node->dump_name ());
2741 11081 : timevar_pop (TV_IPA_LTO_CTORS_OUT);
2742 11081 : }
2743 :
2744 :
2745 : /* Emit toplevel asms. */
2746 :
2747 : void
2748 31872 : lto_output_toplevel_asms (lto_symtab_encoder_t encoder)
2749 : {
2750 31872 : struct output_block *ob;
2751 31872 : char *section_name;
2752 31872 : struct lto_simple_header_with_strings header;
2753 :
2754 31872 : unsigned asm_count = 0;
2755 1484373 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
2756 1420864 : if (is_a <asm_node*> (lto_symtab_encoder_deref (encoder, i)))
2757 156 : asm_count++;
2758 :
2759 31872 : if (!asm_count)
2760 31757 : return;
2761 :
2762 115 : ob = create_output_block (LTO_section_asm);
2763 :
2764 : /* Stream the length. */
2765 115 : streamer_write_uhwi (ob, asm_count);
2766 26177 : for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
2767 : {
2768 12916 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
2769 12916 : asm_node *anode = dyn_cast <asm_node*> (tnode);
2770 12916 : if (!anode)
2771 12760 : continue;
2772 :
2773 156 : int output_order = *encoder->order_remap->get (anode->order);
2774 156 : stream_write_tree (ob, anode->asm_str, true);
2775 156 : streamer_write_hwi (ob, output_order);
2776 : }
2777 :
2778 115 : section_name = lto_get_section_name (LTO_section_asm, NULL, 0, NULL);
2779 115 : lto_begin_section (section_name, !flag_wpa);
2780 115 : free (section_name);
2781 :
2782 : /* The entire header stream is computed here. */
2783 115 : memset (&header, 0, sizeof (header));
2784 :
2785 115 : header.main_size = ob->main_stream->total_size;
2786 115 : header.string_size = ob->string_stream->total_size;
2787 115 : lto_write_data (&header, sizeof header);
2788 :
2789 : /* Put all of the gimple and the string table out the asm file as a
2790 : block of text. */
2791 115 : lto_write_stream (ob->main_stream);
2792 115 : lto_write_stream (ob->string_stream);
2793 :
2794 115 : lto_end_section ();
2795 :
2796 115 : destroy_output_block (ob);
2797 : }
2798 :
2799 :
2800 : /* Copy the function body or variable constructor of NODE without deserializing. */
2801 :
2802 : static void
2803 34679 : copy_function_or_variable (struct symtab_node *node, int output_order)
2804 : {
2805 34679 : tree function = node->decl;
2806 34679 : struct lto_file_decl_data *file_data = node->lto_file_data;
2807 34679 : const char *data;
2808 34679 : size_t len;
2809 34679 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
2810 34679 : char *section_name =
2811 34679 : lto_get_section_name (LTO_section_function_body, name, output_order, NULL);
2812 34679 : size_t i, j;
2813 34679 : struct lto_in_decl_state *in_state;
2814 34679 : struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
2815 :
2816 34679 : if (streamer_dump_file)
2817 0 : fprintf (streamer_dump_file, "Copying section for %s\n", name);
2818 34679 : lto_begin_section (section_name, false);
2819 34679 : free (section_name);
2820 :
2821 : /* We may have renamed the declaration, e.g., a static function. */
2822 34679 : name = lto_get_decl_name_mapping (file_data, name);
2823 :
2824 69358 : data = lto_get_raw_section_data (file_data, LTO_section_function_body,
2825 34679 : name, node->order - file_data->order_base,
2826 : &len);
2827 34679 : gcc_assert (data);
2828 :
2829 : /* Do a bit copy of the function body. */
2830 34679 : lto_write_raw_data (data, len);
2831 :
2832 : /* Copy decls. */
2833 34679 : in_state =
2834 34679 : lto_get_function_in_decl_state (node->lto_file_data, function);
2835 34679 : out_state->compressed = in_state->compressed;
2836 34679 : gcc_assert (in_state);
2837 :
2838 69358 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
2839 : {
2840 34679 : size_t n = vec_safe_length (in_state->streams[i]);
2841 34679 : vec<tree, va_gc> *trees = in_state->streams[i];
2842 34679 : struct lto_tree_ref_encoder *encoder = &(out_state->streams[i]);
2843 :
2844 : /* The out state must have the same indices and the in state.
2845 : So just copy the vector. All the encoders in the in state
2846 : must be empty where we reach here. */
2847 34679 : gcc_assert (lto_tree_ref_encoder_size (encoder) == 0);
2848 34679 : encoder->trees.reserve_exact (n);
2849 528557 : for (j = 0; j < n; j++)
2850 459199 : encoder->trees.safe_push ((*trees)[j]);
2851 : }
2852 :
2853 34679 : lto_free_raw_section_data (file_data, LTO_section_function_body, name,
2854 : data, len);
2855 34679 : lto_end_section ();
2856 :
2857 : /* Make sure the reader knows which linemap section to use. */
2858 34679 : out_state->linemap_id = lto_linemap_output_id (in_state->linemap_id,
2859 : file_data);
2860 34679 : }
2861 :
2862 : /* Wrap symbol references in *TP inside a type-preserving MEM_REF. */
2863 :
2864 : static tree
2865 793456 : wrap_refs (tree *tp, int *ws, void *)
2866 : {
2867 793456 : tree t = *tp;
2868 793456 : if (handled_component_p (t)
2869 178 : && VAR_P (TREE_OPERAND (t, 0))
2870 121 : && TREE_PUBLIC (TREE_OPERAND (t, 0)))
2871 : {
2872 82 : tree decl = TREE_OPERAND (t, 0);
2873 82 : tree ptrtype = build_pointer_type (TREE_TYPE (decl));
2874 82 : TREE_OPERAND (t, 0) = build2 (MEM_REF, TREE_TYPE (decl),
2875 : build1 (ADDR_EXPR, ptrtype, decl),
2876 : build_int_cst (ptrtype, 0));
2877 82 : TREE_THIS_VOLATILE (TREE_OPERAND (t, 0)) = TREE_THIS_VOLATILE (decl);
2878 82 : *ws = 0;
2879 : }
2880 793374 : else if (TREE_CODE (t) == CONSTRUCTOR)
2881 : ;
2882 575668 : else if (!EXPR_P (t))
2883 335855 : *ws = 0;
2884 793456 : return NULL_TREE;
2885 : }
2886 :
2887 : /* Remove functions that are no longer used from offload_funcs, and mark the
2888 : remaining ones with DECL_PRESERVE_P. */
2889 :
2890 : static void
2891 31872 : prune_offload_funcs (void)
2892 : {
2893 31872 : if (!offload_funcs)
2894 31872 : return;
2895 :
2896 0 : unsigned ix, ix2;
2897 0 : tree *elem_ptr;
2898 0 : VEC_ORDERED_REMOVE_IF (*offload_funcs, ix, ix2, elem_ptr,
2899 0 : cgraph_node::get (*elem_ptr) == NULL);
2900 :
2901 0 : tree fn_decl;
2902 0 : FOR_EACH_VEC_ELT (*offload_funcs, ix, fn_decl)
2903 0 : DECL_PRESERVE_P (fn_decl) = 1;
2904 : }
2905 :
2906 : /* Produce LTO section that contains global information
2907 : about LTO bytecode. */
2908 :
2909 : static void
2910 39820 : produce_lto_section ()
2911 : {
2912 : /* Stream LTO meta section. */
2913 39820 : output_block *ob = create_output_block (LTO_section_lto);
2914 :
2915 39820 : char * section_name = lto_get_section_name (LTO_section_lto, NULL, 0, NULL);
2916 39820 : lto_begin_section (section_name, false);
2917 39820 : free (section_name);
2918 :
2919 : #ifdef HAVE_ZSTD_H
2920 39820 : lto_compression compression = ZSTD;
2921 : #else
2922 : lto_compression compression = ZLIB;
2923 : #endif
2924 :
2925 39820 : bool slim_object = flag_generate_lto && !flag_fat_lto_objects;
2926 39820 : lto_section s
2927 39820 : = { LTO_major_version, LTO_minor_version, slim_object, 0, 0 };
2928 39820 : s.set_compression (compression);
2929 39820 : lto_write_data (&s, sizeof s);
2930 39820 : lto_end_section ();
2931 39820 : destroy_output_block (ob);
2932 39820 : }
2933 :
2934 : /* If we have copied a function, we need to make sure the linemap it refers to
2935 : is also streamed out. */
2936 :
2937 : static void
2938 8757 : copy_linemap_section (lto_file_decl_data *file_data, unsigned order)
2939 : {
2940 8757 : const auto in_section_name
2941 8757 : = lto_get_section_name (LTO_section_linemap, nullptr, order, file_data);
2942 8757 : const auto out_section_name
2943 17514 : = lto_get_section_name (LTO_section_linemap, nullptr,
2944 8757 : lto_linemap_output_id (order, file_data), nullptr);
2945 :
2946 8757 : if (streamer_dump_file)
2947 0 : fprintf (streamer_dump_file, "Copying linemap section from %s to %s\n",
2948 : in_section_name, out_section_name);
2949 :
2950 8757 : size_t len;
2951 8757 : const auto data = lto_get_raw_section_data (file_data, LTO_section_linemap,
2952 : nullptr, order, &len);
2953 8757 : gcc_assert (data);
2954 8757 : lto_begin_section (out_section_name, false);
2955 8757 : free (in_section_name);
2956 8757 : free (out_section_name);
2957 8757 : lto_write_raw_data (data, len);
2958 8757 : lto_free_raw_section_data (file_data, LTO_section_linemap,
2959 : nullptr, data, len);
2960 8757 : lto_end_section ();
2961 8757 : }
2962 :
2963 : static void
2964 8755 : copy_linemap_sections (lto_file_decl_data *file_data)
2965 : {
2966 17512 : for (unsigned i = 0; i != file_data->num_linemap_sections; ++i)
2967 8757 : copy_linemap_section (file_data, i);
2968 8755 : }
2969 :
2970 : /* Copy all the linemaps we read into an object file so LTRANS can find them
2971 : later. */
2972 :
2973 : void
2974 7985 : lto_copy_linemaps ()
2975 : {
2976 7985 : timevar_push (TV_IPA_LTO_LINEMAP_COPY);
2977 7985 : lto_streamer_init ();
2978 7985 : lto_push_out_decl_state (nullptr);
2979 :
2980 : /* In WPA, we write these out to a standalone file; give it an LTO header
2981 : section. */
2982 7985 : if (flag_wpa)
2983 7948 : produce_lto_section ();
2984 :
2985 16740 : for (auto file_data = lto_get_file_decl_data (); *file_data; ++file_data)
2986 8755 : copy_linemap_sections (*file_data);
2987 :
2988 7985 : lto_pop_out_decl_state ();
2989 7985 : timevar_pop (TV_IPA_LTO_LINEMAP_COPY);
2990 7985 : }
2991 :
2992 : /* Compare symbols to get them sorted by filename (to optimize streaming) */
2993 :
2994 : static int
2995 3378490 : cmp_symbol_files (const void *pn1, const void *pn2, void *id_map_)
2996 : {
2997 3378490 : const symtab_node *n1 = *(const symtab_node * const *)pn1;
2998 3378490 : const symtab_node *n2 = *(const symtab_node * const *)pn2;
2999 3378490 : hash_map<lto_file_decl_data *, int> *id_map
3000 : = (hash_map<lto_file_decl_data *, int> *)id_map_;
3001 :
3002 3378490 : int file_order1 = n1->lto_file_data ? n1->lto_file_data->order : -1;
3003 3378490 : int file_order2 = n2->lto_file_data ? n2->lto_file_data->order : -1;
3004 :
3005 : /* Order files same way as they appeared in the command line to reduce
3006 : seeking while copying sections. */
3007 3378490 : if (file_order1 != file_order2)
3008 10237 : return file_order1 - file_order2;
3009 :
3010 : /* Order within static library. */
3011 3368253 : if (n1->lto_file_data && n1->lto_file_data->id != n2->lto_file_data->id)
3012 0 : return *id_map->get (n1->lto_file_data) - *id_map->get (n2->lto_file_data);
3013 :
3014 : /* And finally order by the definition order. */
3015 3368253 : return n1->order - n2->order;
3016 : }
3017 :
3018 : /* Compare ints, callback for qsort. */
3019 :
3020 : static int
3021 31883586 : cmp_int (const void *a, const void *b)
3022 : {
3023 31883586 : int ia = *(int const*) a;
3024 31883586 : int ib = *(int const*) b;
3025 31883586 : return ia - ib;
3026 : }
3027 :
3028 : /* Create order mapping independent on symbols outside of the partition.
3029 : Results in stable order values for incremental LTO.
3030 :
3031 : Remapping is not done in place, because symbols can be used
3032 : by multiple partitions. */
3033 :
3034 : static void
3035 31872 : create_order_remap (lto_symtab_encoder_t encoder)
3036 : {
3037 31872 : auto_vec<int> orders;
3038 31872 : unsigned i;
3039 31872 : encoder->order_remap = new hash_map<int_hash<int, -1, -2>, int>;
3040 31872 : unsigned n_nodes = lto_symtab_encoder_size (encoder);
3041 :
3042 742304 : for (i = 0; i < n_nodes; i++)
3043 710432 : orders.safe_push (lto_symtab_encoder_deref (encoder, i)->order);
3044 :
3045 31872 : orders.qsort (cmp_int);
3046 31872 : int ord = 0;
3047 31872 : int last_order = -1;
3048 742304 : for (i = 0; i < orders.length (); i++)
3049 : {
3050 710432 : int order = orders[i];
3051 710432 : if (order != last_order)
3052 : {
3053 687132 : last_order = order;
3054 687132 : encoder->order_remap->put (order, ord);
3055 687132 : ord++;
3056 : }
3057 : }
3058 31872 : }
3059 :
3060 : /* When WPA writes out its outputs, there are two different ways a location
3061 : may be streamed out: either streamed freshly, e.g. when trees are
3062 : streamed out in the decls section, or else copied verbatim from the input
3063 : files. In the former case, we need to remember how a location_t was
3064 : originally referenced in the input data, so we can stream it out the same
3065 : way; otherwise it would be necessary to stream out a new linemap section
3066 : just for WPA-generated locations, which would a) be wasteful given that
3067 : all locations originated from one of the linemap sections that already
3068 : exists and b) inhibit incremental LTO since a change to one partition
3069 : would affect the linemap for all of them. */
3070 :
3071 20889 : void lto_register_linemap_for_output (size_t map_idx, unsigned linemap_id)
3072 : {
3073 20889 : loc_output.register_map_id (map_idx, linemap_id);
3074 20889 : }
3075 :
3076 : /* Main entry point from the pass manager. */
3077 :
3078 : void
3079 31872 : lto_output (void)
3080 : {
3081 31872 : struct lto_out_decl_state *decl_state;
3082 31872 : bitmap output = NULL;
3083 31872 : bitmap_obstack output_obstack;
3084 31872 : unsigned int i, n_nodes;
3085 31872 : lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder;
3086 31872 : auto_vec<symtab_node *> symbols_to_copy;
3087 :
3088 31872 : create_order_remap (encoder);
3089 :
3090 31872 : prune_offload_funcs ();
3091 :
3092 31872 : if (flag_checking)
3093 : {
3094 31866 : bitmap_obstack_initialize (&output_obstack);
3095 31866 : output = BITMAP_ALLOC (&output_obstack);
3096 : }
3097 :
3098 : /* Initialize the streamer. */
3099 31872 : lto_streamer_init ();
3100 :
3101 31872 : produce_lto_section ();
3102 :
3103 31872 : n_nodes = lto_symtab_encoder_size (encoder);
3104 : /* Prepare vector of functions to output and then sort it to optimize
3105 : section copying. */
3106 742304 : for (i = 0; i < n_nodes; i++)
3107 : {
3108 710432 : toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
3109 710432 : symtab_node *node = dyn_cast <symtab_node *> (tnode);
3110 710276 : if (!node || node->alias)
3111 12963 : continue;
3112 :
3113 697469 : if (cgraph_node *node = dyn_cast <cgraph_node *> (tnode))
3114 : {
3115 411049 : if (lto_symtab_encoder_encode_body_p (encoder, node)
3116 411049 : && !node->clone_of)
3117 139173 : symbols_to_copy.safe_push (node);
3118 : }
3119 996852 : else if (varpool_node *node = dyn_cast <varpool_node *> (tnode))
3120 : {
3121 : /* Wrap symbol references inside the ctor in a type
3122 : preserving MEM_REF. */
3123 286420 : tree ctor = DECL_INITIAL (node->decl);
3124 286420 : if (ctor && !in_lto_p)
3125 19432 : walk_tree (&ctor, wrap_refs, NULL, NULL);
3126 286420 : if (get_symbol_initial_value (encoder, node->decl) == error_mark_node
3127 286420 : && lto_symtab_encoder_encode_initializer_p (encoder, node))
3128 15635 : symbols_to_copy.safe_push (node);
3129 : }
3130 : }
3131 : /* Map the section hash to an order it appears in symbols_to_copy
3132 : since we want to sort same ID symbols next to each other but need
3133 : to avoid making overall order depend on the actual hash value. */
3134 31872 : int order = 0;
3135 31872 : hash_map<lto_file_decl_data *, int> id_map;
3136 218552 : for (i = 0; i < symbols_to_copy.length (); ++i)
3137 : {
3138 154808 : symtab_node *snode = symbols_to_copy[i];
3139 154808 : if (snode->lto_file_data)
3140 : {
3141 40276 : bool existed_p = false;
3142 40276 : int &ord = id_map.get_or_insert (snode->lto_file_data, &existed_p);
3143 40276 : if (!existed_p)
3144 8834 : ord = order++;
3145 : }
3146 : }
3147 31872 : symbols_to_copy.sort (cmp_symbol_files, (void *)&id_map);
3148 186680 : for (i = 0; i < symbols_to_copy.length (); i++)
3149 : {
3150 154808 : symtab_node *snode = symbols_to_copy[i];
3151 154808 : cgraph_node *cnode;
3152 154808 : varpool_node *vnode;
3153 :
3154 154808 : int output_order = *encoder->order_remap->get (snode->order);
3155 :
3156 154808 : if (flag_checking)
3157 154806 : gcc_assert (bitmap_set_bit (output, DECL_UID (snode->decl)));
3158 :
3159 154808 : decl_state = lto_new_out_decl_state ();
3160 154808 : lto_push_out_decl_state (decl_state);
3161 :
3162 154808 : if ((cnode = dyn_cast <cgraph_node *> (snode))
3163 139173 : && (gimple_has_body_p (cnode->decl)
3164 30271 : || (!flag_wpa
3165 294 : && flag_incremental_link != INCREMENTAL_LINK_LTO)
3166 : /* Thunks have no body but they may be synthesized
3167 : at WPA time. */
3168 30125 : || DECL_ARGUMENTS (cnode->decl)))
3169 109048 : output_function (cnode, output_order);
3170 45760 : else if ((vnode = dyn_cast <varpool_node *> (snode))
3171 15635 : && (DECL_INITIAL (vnode->decl) != error_mark_node
3172 4554 : || (!flag_wpa
3173 42 : && flag_incremental_link != INCREMENTAL_LINK_LTO)))
3174 11081 : output_constructor (vnode, output_order);
3175 : else
3176 34679 : copy_function_or_variable (snode, output_order);
3177 154808 : gcc_assert (lto_get_out_decl_state () == decl_state);
3178 154808 : lto_pop_out_decl_state ();
3179 154808 : lto_record_function_out_decl_state (snode->decl, decl_state);
3180 : }
3181 :
3182 : /* Emit the callgraph after emitting function bodies. This needs to
3183 : be done now to make sure that all the statements in every function
3184 : have been renumbered so that edges can be associated with call
3185 : statements using the statement UIDs. */
3186 31872 : output_symtab ();
3187 :
3188 31872 : if (lto_get_out_decl_state ()->output_offload_tables_p)
3189 7948 : output_offload_tables ();
3190 :
3191 31872 : if (flag_checking)
3192 : {
3193 31866 : BITMAP_FREE (output);
3194 31866 : bitmap_obstack_release (&output_obstack);
3195 : }
3196 31872 : }
3197 :
3198 : /* Write each node in encoded by ENCODER to OB, as well as those reachable
3199 : from it and required for correct representation of its semantics.
3200 : Each node in ENCODER must be a global declaration or a type. A node
3201 : is written only once, even if it appears multiple times in the
3202 : vector. Certain transitively-reachable nodes, such as those
3203 : representing expressions, may be duplicated, but such nodes
3204 : must not appear in ENCODER itself. */
3205 :
3206 : static void
3207 186680 : write_global_stream (struct output_block *ob,
3208 : struct lto_tree_ref_encoder *encoder)
3209 : {
3210 186680 : tree t;
3211 186680 : size_t index;
3212 186680 : const size_t size = lto_tree_ref_encoder_size (encoder);
3213 :
3214 2862860 : for (index = 0; index < size; index++)
3215 : {
3216 2676180 : t = lto_tree_ref_encoder_get_tree (encoder, index);
3217 2676180 : if (streamer_dump_file)
3218 : {
3219 176 : fprintf (streamer_dump_file, " %i:", (int)index);
3220 176 : print_node_brief (streamer_dump_file, "", t, 4);
3221 176 : fprintf (streamer_dump_file, "\n");
3222 : }
3223 2676180 : if (!streamer_tree_cache_lookup (ob->writer_cache, t, NULL))
3224 941677 : stream_write_tree (ob, t, false);
3225 : }
3226 186680 : }
3227 :
3228 :
3229 : /* Write a sequence of indices into the globals vector corresponding
3230 : to the trees in ENCODER. These are used by the reader to map the
3231 : indices used to refer to global entities within function bodies to
3232 : their referents. */
3233 :
3234 : static void
3235 186680 : write_global_references (struct output_block *ob,
3236 : struct lto_tree_ref_encoder *encoder)
3237 : {
3238 186680 : tree t;
3239 186680 : uint32_t index;
3240 186680 : const uint32_t size = lto_tree_ref_encoder_size (encoder);
3241 :
3242 : /* Write size and slot indexes as 32-bit unsigned numbers. */
3243 186680 : uint32_t *data = XNEWVEC (uint32_t, size + 1);
3244 186680 : data[0] = size;
3245 :
3246 2862860 : for (index = 0; index < size; index++)
3247 : {
3248 2676180 : unsigned slot_num;
3249 :
3250 2676180 : t = lto_tree_ref_encoder_get_tree (encoder, index);
3251 2676180 : streamer_tree_cache_lookup (ob->writer_cache, t, &slot_num);
3252 2676180 : gcc_assert (slot_num != (unsigned)-1);
3253 2676180 : data[index + 1] = slot_num;
3254 : }
3255 :
3256 186680 : lto_write_data (data, sizeof (int32_t) * (size + 1));
3257 186680 : free (data);
3258 186680 : }
3259 :
3260 :
3261 : /* Write all the streams in an lto_out_decl_state STATE using
3262 : output block OB and output stream OUT_STREAM. */
3263 :
3264 : void
3265 186680 : lto_output_decl_state_streams (struct output_block *ob,
3266 : struct lto_out_decl_state *state)
3267 : {
3268 186680 : int i;
3269 :
3270 373360 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3271 186680 : write_global_stream (ob, &state->streams[i]);
3272 186680 : }
3273 :
3274 :
3275 : /* Write all the references in an lto_out_decl_state STATE using
3276 : output block OB and output stream OUT_STREAM. */
3277 :
3278 : void
3279 186680 : lto_output_decl_state_refs (struct output_block *ob,
3280 : struct lto_out_decl_state *state)
3281 : {
3282 186680 : unsigned i;
3283 186680 : uint32_t ref, lm_order;
3284 186680 : tree decl;
3285 :
3286 : /* Write reference to FUNCTION_DECL. If there is not function,
3287 : write reference to void_type_node. */
3288 186680 : decl = (state->fn_decl) ? state->fn_decl : void_type_node;
3289 186680 : streamer_tree_cache_lookup (ob->writer_cache, decl, &ref);
3290 186680 : gcc_assert (ref != (uint32_t)-1);
3291 186680 : ref = ref * 2 + (state->compressed ? 1 : 0);
3292 186680 : lto_write_data (&ref, sizeof (uint32_t));
3293 186680 : if (state->fn_decl)
3294 : {
3295 154808 : lm_order = state->linemap_id;
3296 154808 : lto_write_data (&lm_order, sizeof (lm_order));
3297 : }
3298 373360 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3299 186680 : write_global_references (ob, &state->streams[i]);
3300 186680 : }
3301 :
3302 :
3303 : /* Return the written size of STATE. */
3304 :
3305 : static size_t
3306 186680 : lto_out_decl_state_written_size (struct lto_out_decl_state *state)
3307 : {
3308 186680 : int i;
3309 186680 : size_t size;
3310 :
3311 186680 : size = sizeof (int32_t); /* fn_ref. */
3312 186680 : if (state->fn_decl)
3313 154808 : size += sizeof (int32_t); /* linemap_id. */
3314 373360 : for (i = 0; i < LTO_N_DECL_STREAMS; i++)
3315 : {
3316 186680 : size += sizeof (int32_t); /* vector size. */
3317 186680 : size += (lto_tree_ref_encoder_size (&state->streams[i])
3318 186680 : * sizeof (int32_t));
3319 : }
3320 186680 : return size;
3321 : }
3322 :
3323 :
3324 : /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
3325 : so far. */
3326 :
3327 : static void
3328 545155 : write_symbol (struct streamer_tree_cache_d *cache,
3329 : tree t, hash_set<const char *> *seen, bool alias)
3330 : {
3331 545155 : const char *name;
3332 545155 : enum gcc_plugin_symbol_kind kind;
3333 545155 : enum gcc_plugin_symbol_visibility visibility = GCCPV_DEFAULT;
3334 545155 : unsigned slot_num;
3335 545155 : uint64_t size;
3336 545155 : const char *comdat;
3337 545155 : unsigned char c;
3338 :
3339 545155 : gcc_assert (VAR_OR_FUNCTION_DECL_P (t));
3340 :
3341 545155 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
3342 :
3343 : /* This behaves like assemble_name_raw in varasm.cc, performing the
3344 : same name manipulations that ASM_OUTPUT_LABELREF does. */
3345 545155 : name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
3346 :
3347 545155 : if (seen->add (name))
3348 769 : return;
3349 :
3350 544386 : streamer_tree_cache_lookup (cache, t, &slot_num);
3351 544386 : gcc_assert (slot_num != (unsigned)-1);
3352 :
3353 544386 : if (DECL_EXTERNAL (t))
3354 : {
3355 215650 : if (DECL_WEAK (t))
3356 : kind = GCCPK_WEAKUNDEF;
3357 : else
3358 215612 : kind = GCCPK_UNDEF;
3359 : }
3360 : else
3361 : {
3362 328736 : if (DECL_WEAK (t))
3363 : kind = GCCPK_WEAKDEF;
3364 316674 : else if (DECL_COMMON (t))
3365 : kind = GCCPK_COMMON;
3366 : else
3367 316613 : kind = GCCPK_DEF;
3368 :
3369 : /* When something is defined, it should have node attached. */
3370 328736 : gcc_assert (alias || !VAR_P (t) || varpool_node::get (t)->definition);
3371 328736 : gcc_assert (alias || TREE_CODE (t) != FUNCTION_DECL
3372 : || (cgraph_node::get (t)
3373 : && cgraph_node::get (t)->definition));
3374 : }
3375 :
3376 : /* Imitate what default_elf_asm_output_external do.
3377 : When symbol is external, we need to output it with DEFAULT visibility
3378 : when compiling with -fvisibility=default, while with HIDDEN visibility
3379 : when symbol has attribute (visibility("hidden")) specified.
3380 : targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
3381 : right. */
3382 :
3383 544386 : if (DECL_EXTERNAL (t)
3384 544386 : && !targetm.binds_local_p (t))
3385 : visibility = GCCPV_DEFAULT;
3386 : else
3387 328790 : switch (DECL_VISIBILITY (t))
3388 : {
3389 : case VISIBILITY_DEFAULT:
3390 : visibility = GCCPV_DEFAULT;
3391 : break;
3392 : case VISIBILITY_PROTECTED:
3393 544386 : visibility = GCCPV_PROTECTED;
3394 : break;
3395 : case VISIBILITY_HIDDEN:
3396 : visibility = GCCPV_HIDDEN;
3397 : break;
3398 : case VISIBILITY_INTERNAL:
3399 : visibility = GCCPV_INTERNAL;
3400 : break;
3401 : }
3402 :
3403 544386 : if (kind == GCCPK_COMMON
3404 61 : && DECL_SIZE_UNIT (t)
3405 544447 : && TREE_CODE (DECL_SIZE_UNIT (t)) == INTEGER_CST)
3406 61 : size = TREE_INT_CST_LOW (DECL_SIZE_UNIT (t));
3407 : else
3408 544325 : size = 0;
3409 :
3410 544386 : if (DECL_ONE_ONLY (t))
3411 12025 : comdat = IDENTIFIER_POINTER (decl_comdat_group_id (t));
3412 : else
3413 : comdat = "";
3414 :
3415 544386 : lto_write_data (name, strlen (name) + 1);
3416 544386 : lto_write_data (comdat, strlen (comdat) + 1);
3417 544386 : c = (unsigned char) kind;
3418 544386 : lto_write_data (&c, 1);
3419 544386 : c = (unsigned char) visibility;
3420 544386 : lto_write_data (&c, 1);
3421 544386 : lto_write_data (&size, 8);
3422 544386 : lto_write_data (&slot_num, 4);
3423 : }
3424 :
3425 : /* Write extension information for symbols (symbol type, section flags). */
3426 :
3427 : static void
3428 545155 : write_symbol_extension_info (tree t)
3429 : {
3430 545155 : unsigned char c;
3431 545155 : c = ((unsigned char) TREE_CODE (t) == VAR_DECL
3432 : ? GCCST_VARIABLE : GCCST_FUNCTION);
3433 545155 : lto_write_data (&c, 1);
3434 545155 : unsigned char section_kind = 0;
3435 545155 : if (VAR_P (t))
3436 : {
3437 234554 : section *s = get_variable_section (t, false);
3438 234554 : if (s->common.flags & SECTION_BSS)
3439 224547 : section_kind |= GCCSSK_BSS;
3440 : }
3441 545155 : lto_write_data (§ion_kind, 1);
3442 545155 : }
3443 :
3444 : /* Write an IL symbol table to OB.
3445 : SET and VSET are cgraph/varpool node sets we are outputting. */
3446 :
3447 : static unsigned int
3448 23539 : produce_symtab (struct output_block *ob)
3449 : {
3450 23539 : unsigned int streamed_symbols = 0;
3451 23539 : struct streamer_tree_cache_d *cache = ob->writer_cache;
3452 23539 : char *section_name = lto_get_section_name (LTO_section_symtab, NULL, 0, NULL);
3453 23539 : lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
3454 23539 : lto_symtab_encoder_iterator lsei;
3455 :
3456 23539 : lto_begin_section (section_name, false);
3457 23539 : free (section_name);
3458 :
3459 23539 : hash_set<const char *> seen;
3460 :
3461 : /* Write the symbol table.
3462 : First write everything defined and then all declarations.
3463 : This is necessary to handle cases where we have duplicated symbols. */
3464 23539 : for (lsei = lsei_start (encoder);
3465 624920 : !lsei_end_p (lsei); lsei_next (&lsei))
3466 : {
3467 601381 : toplevel_node *tnode = lsei_node (lsei);
3468 601381 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3469 601381 : if (!node)
3470 84 : continue;
3471 :
3472 601297 : if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3473 272561 : continue;
3474 328736 : write_symbol (cache, node->decl, &seen, false);
3475 328736 : ++streamed_symbols;
3476 : }
3477 23539 : for (lsei = lsei_start (encoder);
3478 624920 : !lsei_end_p (lsei); lsei_next (&lsei))
3479 : {
3480 601381 : toplevel_node *tnode = lsei_node (lsei);
3481 601381 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3482 601381 : if (!node)
3483 84 : continue;
3484 :
3485 601297 : if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3486 384878 : continue;
3487 216419 : write_symbol (cache, node->decl, &seen, false);
3488 216419 : ++streamed_symbols;
3489 : }
3490 :
3491 23539 : lto_end_section ();
3492 :
3493 23539 : return streamed_symbols;
3494 23539 : }
3495 :
3496 : /* Symtab extension version. */
3497 : #define LTO_SYMTAB_EXTENSION_VERSION 1
3498 :
3499 : /* Write an IL symbol table extension to OB.
3500 : SET and VSET are cgraph/varpool node sets we are outputting. */
3501 :
3502 : static void
3503 23539 : produce_symtab_extension (struct output_block *ob,
3504 : unsigned int previous_streamed_symbols)
3505 : {
3506 23539 : unsigned int streamed_symbols = 0;
3507 23539 : char *section_name = lto_get_section_name (LTO_section_symtab_extension,
3508 : NULL, 0, NULL);
3509 23539 : lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
3510 23539 : lto_symtab_encoder_iterator lsei;
3511 :
3512 23539 : lto_begin_section (section_name, false);
3513 23539 : free (section_name);
3514 :
3515 23539 : unsigned char version = LTO_SYMTAB_EXTENSION_VERSION;
3516 23539 : lto_write_data (&version, 1);
3517 :
3518 : /* Write the symbol table.
3519 : First write everything defined and then all declarations.
3520 : This is necessary to handle cases where we have duplicated symbols. */
3521 23539 : for (lsei = lsei_start (encoder);
3522 624920 : !lsei_end_p (lsei); lsei_next (&lsei))
3523 : {
3524 601381 : toplevel_node *tnode = lsei_node (lsei);
3525 601381 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3526 601381 : if (!node)
3527 84 : continue;
3528 :
3529 601297 : if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3530 272561 : continue;
3531 328736 : write_symbol_extension_info (node->decl);
3532 328736 : ++streamed_symbols;
3533 : }
3534 23539 : for (lsei = lsei_start (encoder);
3535 624920 : !lsei_end_p (lsei); lsei_next (&lsei))
3536 : {
3537 601381 : toplevel_node *tnode = lsei_node (lsei);
3538 601381 : symtab_node *node = dyn_cast<symtab_node*> (tnode);
3539 601381 : if (!node)
3540 84 : continue;
3541 :
3542 601297 : if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
3543 384878 : continue;
3544 216419 : write_symbol_extension_info (node->decl);
3545 216419 : ++streamed_symbols;
3546 : }
3547 :
3548 23539 : gcc_assert (previous_streamed_symbols == streamed_symbols);
3549 23539 : lto_end_section ();
3550 23539 : }
3551 :
3552 :
3553 : /* Init the streamer_mode_table for output, where we collect info on what
3554 : machine_mode values have been streamed. */
3555 : void
3556 31872 : lto_output_init_mode_table (void)
3557 : {
3558 31872 : memset (streamer_mode_table, '\0', MAX_MACHINE_MODE);
3559 31872 : }
3560 :
3561 :
3562 : /* Write the mode table. */
3563 : static void
3564 0 : lto_write_mode_table (void)
3565 : {
3566 0 : struct output_block *ob;
3567 0 : ob = create_output_block (LTO_section_mode_table);
3568 0 : bitpack_d bp = bitpack_create (ob->main_stream);
3569 :
3570 0 : if (lto_stream_offload_p)
3571 0 : bp_pack_value (&bp, NUM_POLY_INT_COEFFS, MAX_NUM_POLY_INT_COEFFS_BITS);
3572 :
3573 : /* Ensure that for GET_MODE_INNER (m) != m we have
3574 : also the inner mode marked. */
3575 0 : for (int i = 0; i < (int) MAX_MACHINE_MODE; i++)
3576 0 : if (streamer_mode_table[i])
3577 : {
3578 0 : machine_mode m = (machine_mode) i;
3579 0 : machine_mode inner_m = GET_MODE_INNER (m);
3580 0 : if (inner_m != m)
3581 0 : streamer_mode_table[(int) inner_m] = 1;
3582 : }
3583 :
3584 : /* Pack the mode_bits value within 5 bits (up to 31) in the beginning. */
3585 0 : unsigned mode_bits = ceil_log2 (MAX_MACHINE_MODE);
3586 0 : bp_pack_value (&bp, mode_bits, 5);
3587 :
3588 : /* First stream modes that have GET_MODE_INNER (m) == m,
3589 : so that we can refer to them afterwards. */
3590 0 : for (int pass = 0; pass < 2; pass++)
3591 0 : for (int i = 0; i < (int) MAX_MACHINE_MODE; i++)
3592 0 : if (streamer_mode_table[i] && i != (int) VOIDmode && i != (int) BLKmode)
3593 : {
3594 0 : machine_mode m = (machine_mode) i;
3595 0 : if ((GET_MODE_INNER (m) == m) ^ (pass == 0))
3596 0 : continue;
3597 0 : bp_pack_value (&bp, m, mode_bits);
3598 0 : bp_pack_enum (&bp, mode_class, MAX_MODE_CLASS, GET_MODE_CLASS (m));
3599 0 : bp_pack_poly_value (&bp, GET_MODE_SIZE (m), 16);
3600 0 : bp_pack_poly_value (&bp, GET_MODE_PRECISION (m), 16);
3601 0 : bp_pack_value (&bp, GET_MODE_INNER (m), mode_bits);
3602 0 : bp_pack_poly_value (&bp, GET_MODE_NUNITS (m), 16);
3603 0 : switch (GET_MODE_CLASS (m))
3604 : {
3605 0 : case MODE_FRACT:
3606 0 : case MODE_UFRACT:
3607 0 : case MODE_ACCUM:
3608 0 : case MODE_UACCUM:
3609 0 : bp_pack_value (&bp, GET_MODE_IBIT (m), 8);
3610 0 : bp_pack_value (&bp, GET_MODE_FBIT (m), 8);
3611 0 : break;
3612 0 : case MODE_FLOAT:
3613 0 : case MODE_DECIMAL_FLOAT:
3614 0 : bp_pack_string (ob, &bp, REAL_MODE_FORMAT (m)->name, true);
3615 0 : break;
3616 : default:
3617 : break;
3618 : }
3619 0 : bp_pack_string (ob, &bp, GET_MODE_NAME (m), true);
3620 : }
3621 0 : bp_pack_value (&bp, VOIDmode, mode_bits);
3622 :
3623 0 : streamer_write_bitpack (&bp);
3624 :
3625 0 : char *section_name
3626 0 : = lto_get_section_name (LTO_section_mode_table, NULL, 0, NULL);
3627 0 : lto_begin_section (section_name, !flag_wpa);
3628 0 : free (section_name);
3629 :
3630 : /* The entire header stream is computed here. */
3631 0 : struct lto_simple_header_with_strings header;
3632 0 : memset (&header, 0, sizeof (header));
3633 :
3634 0 : header.main_size = ob->main_stream->total_size;
3635 0 : header.string_size = ob->string_stream->total_size;
3636 0 : lto_write_data (&header, sizeof header);
3637 :
3638 : /* Put all of the gimple and the string table out the asm file as a
3639 : block of text. */
3640 0 : lto_write_stream (ob->main_stream);
3641 0 : lto_write_stream (ob->string_stream);
3642 :
3643 0 : lto_end_section ();
3644 0 : destroy_output_block (ob);
3645 0 : }
3646 :
3647 :
3648 : /* This pass is run after all of the functions are serialized and all
3649 : of the IPA passes have written their serialized forms. This pass
3650 : causes the vector of all of the global decls and types used from
3651 : this file to be written in to a section that can then be read in to
3652 : recover these on other side. */
3653 :
3654 : void
3655 31872 : produce_asm_for_decls (void)
3656 : {
3657 31872 : struct lto_out_decl_state *out_state;
3658 31872 : struct lto_out_decl_state *fn_out_state;
3659 31872 : struct lto_decl_header header;
3660 31872 : char *section_name;
3661 31872 : struct output_block *ob;
3662 31872 : unsigned idx, num_fns;
3663 31872 : size_t decl_state_size;
3664 31872 : int32_t num_decl_states;
3665 :
3666 31872 : ob = create_output_block (LTO_section_decls);
3667 :
3668 31872 : memset (&header, 0, sizeof (struct lto_decl_header));
3669 :
3670 31872 : section_name = lto_get_section_name (LTO_section_decls, NULL, 0, NULL);
3671 31872 : lto_begin_section (section_name, !flag_wpa);
3672 31872 : free (section_name);
3673 :
3674 : /* Make string 0 be a NULL string. */
3675 31872 : streamer_write_char_stream (ob->string_stream, 0);
3676 :
3677 31872 : gcc_assert (!alias_pairs);
3678 :
3679 : /* Get rid of the global decl state hash tables to save some memory. */
3680 31872 : out_state = lto_get_out_decl_state ();
3681 95616 : for (int i = 0; i < LTO_N_DECL_STREAMS; i++)
3682 31872 : if (out_state->streams[i].tree_hash_table)
3683 : {
3684 31872 : delete out_state->streams[i].tree_hash_table;
3685 31872 : out_state->streams[i].tree_hash_table = NULL;
3686 : }
3687 :
3688 : /* Write the global symbols. */
3689 31872 : if (streamer_dump_file)
3690 4 : fprintf (streamer_dump_file, "Outputting global stream\n");
3691 31872 : lto_output_decl_state_streams (ob, out_state);
3692 31872 : num_fns = lto_function_decl_states.length ();
3693 186680 : for (idx = 0; idx < num_fns; idx++)
3694 : {
3695 154808 : fn_out_state =
3696 154808 : lto_function_decl_states[idx];
3697 154808 : if (streamer_dump_file)
3698 24 : fprintf (streamer_dump_file, "Outputting stream for %s\n",
3699 12 : IDENTIFIER_POINTER
3700 : (DECL_ASSEMBLER_NAME (fn_out_state->fn_decl)));
3701 154808 : lto_output_decl_state_streams (ob, fn_out_state);
3702 : }
3703 :
3704 : /* Currently not used. This field would allow us to preallocate
3705 : the globals vector, so that it need not be resized as it is extended. */
3706 31872 : header.num_nodes = -1;
3707 :
3708 : /* Compute the total size of all decl out states. */
3709 31872 : decl_state_size = sizeof (int32_t);
3710 31872 : decl_state_size += lto_out_decl_state_written_size (out_state);
3711 186680 : for (idx = 0; idx < num_fns; idx++)
3712 : {
3713 154808 : fn_out_state =
3714 154808 : lto_function_decl_states[idx];
3715 154808 : decl_state_size += lto_out_decl_state_written_size (fn_out_state);
3716 : }
3717 31872 : header.decl_state_size = decl_state_size;
3718 :
3719 31872 : header.main_size = ob->main_stream->total_size;
3720 31872 : header.string_size = ob->string_stream->total_size;
3721 :
3722 31872 : lto_write_data (&header, sizeof header);
3723 :
3724 : /* Write the main out-decl state, followed by out-decl states of
3725 : functions. */
3726 31872 : num_decl_states = num_fns + 1;
3727 31872 : lto_write_data (&num_decl_states, sizeof (num_decl_states));
3728 31872 : lto_output_decl_state_refs (ob, out_state);
3729 218552 : for (idx = 0; idx < num_fns; idx++)
3730 : {
3731 154808 : fn_out_state = lto_function_decl_states[idx];
3732 154808 : lto_output_decl_state_refs (ob, fn_out_state);
3733 : }
3734 :
3735 31872 : lto_write_stream (ob->main_stream);
3736 31872 : lto_write_stream (ob->string_stream);
3737 :
3738 31872 : lto_end_section ();
3739 :
3740 : /* Write the symbol table. It is used by linker to determine dependencies
3741 : and thus we can skip it for WPA. */
3742 31872 : if (!flag_wpa)
3743 : {
3744 23539 : unsigned int streamed_symbols = produce_symtab (ob);
3745 23539 : produce_symtab_extension (ob, streamed_symbols);
3746 : }
3747 :
3748 : /* Write command line opts. */
3749 31872 : lto_write_options ();
3750 :
3751 : /* Deallocate memory and clean up. */
3752 218552 : for (idx = 0; idx < num_fns; idx++)
3753 : {
3754 154808 : fn_out_state =
3755 154808 : lto_function_decl_states[idx];
3756 154808 : lto_delete_out_decl_state (fn_out_state);
3757 : }
3758 31872 : lto_symtab_encoder_delete (ob->decl_state->symtab_node_encoder);
3759 31872 : lto_function_decl_states.release ();
3760 31872 : destroy_output_block (ob);
3761 31872 : if (lto_stream_offload_p)
3762 0 : lto_write_mode_table ();
3763 :
3764 : /* Copy or write the linemap section(s) as needed. For incremental LTO, we
3765 : copy them into the output file now. For WPA, we will copy them into a
3766 : dedicated file later. Otherwise, we create a new one from scratch and
3767 : output it now. */
3768 31872 : if (flag_incremental_link == INCREMENTAL_LINK_LTO)
3769 37 : lto_copy_linemaps ();
3770 31835 : else if (!flag_wpa)
3771 : {
3772 23502 : gcc_checking_assert (!in_lto_p);
3773 23502 : loc_output.produce_linemap_section ();
3774 : }
3775 31872 : }
|