Line data Source code
1 : /* Read the GIMPLE representation from 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 "cfghooks.h"
32 : #include "tree-pass.h"
33 : #include "ssa.h"
34 : #include "gimple-streamer.h"
35 : #include "toplev.h"
36 : #include "gimple-iterator.h"
37 : #include "tree-cfg.h"
38 : #include "tree-into-ssa.h"
39 : #include "tree-dfa.h"
40 : #include "tree-ssa.h"
41 : #include "except.h"
42 : #include "cgraph.h"
43 : #include "cfgloop.h"
44 : #include "debug.h"
45 : #include "alloc-pool.h"
46 :
47 : /* Allocator used to hold string slot entries for line map streaming. */
48 : static struct object_allocator<struct string_slot> *string_slot_allocator;
49 :
50 : /* The table to hold the file names. */
51 : static hash_table<string_slot_hasher> *file_name_hash_table;
52 :
53 : /* The table to hold the relative pathname prefixes. */
54 :
55 : /* This obstack holds file names used in locators. Line map datastructures
56 : points here and thus it needs to be kept allocated as long as linemaps
57 : exists. */
58 : static struct obstack file_name_obstack;
59 :
60 : /* Map a pair of nul terminated strings where the first one can be
61 : pointer compared, but the second can't, to another string. */
62 : struct string_pair_map
63 : {
64 : const char *str1;
65 : const char *str2;
66 : const char *str3;
67 : hashval_t hash;
68 : bool prefix;
69 : };
70 :
71 : /* Allocator used to hold string pair map entries for line map streaming. */
72 : static struct object_allocator<struct string_pair_map>
73 : *string_pair_map_allocator;
74 :
75 : struct string_pair_map_hasher : nofree_ptr_hash <string_pair_map>
76 : {
77 : static inline hashval_t hash (const string_pair_map *);
78 : static inline bool equal (const string_pair_map *, const string_pair_map *);
79 : };
80 :
81 : inline hashval_t
82 0 : string_pair_map_hasher::hash (const string_pair_map *spm)
83 : {
84 0 : return spm->hash;
85 : }
86 :
87 : inline bool
88 0 : string_pair_map_hasher::equal (const string_pair_map *spm1,
89 : const string_pair_map *spm2)
90 : {
91 0 : return (spm1->hash == spm2->hash
92 0 : && spm1->str1 == spm2->str1
93 0 : && spm1->prefix == spm2->prefix
94 0 : && strcmp (spm1->str2, spm2->str2) == 0);
95 : }
96 :
97 : /* The table to hold the pairs of pathnames and corresponding
98 : resulting pathname. Used for both mapping of get_src_pwd ()
99 : and recorded source working directory to relative path prefix
100 : from current working directory to the recorded one, and for
101 : mapping of that relative path prefix and some relative path
102 : to those concatenated. */
103 : static hash_table<string_pair_map_hasher> *path_name_pair_hash_table;
104 :
105 :
106 : /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
107 : number of valid tag values to check. */
108 :
109 : void
110 1446135 : lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
111 : {
112 1446135 : va_list ap;
113 1446135 : int i;
114 :
115 1446135 : va_start (ap, ntags);
116 2887150 : for (i = 0; i < ntags; i++)
117 2887150 : if ((unsigned) actual == va_arg (ap, unsigned))
118 : {
119 1446135 : va_end (ap);
120 1446135 : return;
121 : }
122 :
123 0 : va_end (ap);
124 0 : internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
125 : }
126 :
127 :
128 : /* Read LENGTH bytes from STREAM to ADDR. */
129 :
130 : void
131 0 : lto_input_data_block (class lto_input_block *ib, void *addr, size_t length)
132 : {
133 0 : size_t i;
134 0 : unsigned char *const buffer = (unsigned char *) addr;
135 :
136 0 : for (i = 0; i < length; i++)
137 0 : buffer[i] = streamer_read_uchar (ib);
138 0 : }
139 :
140 : /* Compute the relative path to get to DATA_WD (absolute directory name)
141 : from CWD (another absolute directory name). E.g. for
142 : DATA_WD of "/tmp/foo/bar" and CWD of "/tmp/baz/qux" return
143 : "../../foo/bar". Returned string should be freed by the caller.
144 : Return NULL if absolute file name needs to be used. */
145 :
146 : static char *
147 0 : relative_path_prefix (const char *data_wd, const char *cwd)
148 : {
149 0 : const char *d = data_wd;
150 0 : const char *c = cwd;
151 : #ifdef HAVE_DOS_BASED_FILE_SYSTEM
152 : if (d[1] == ':')
153 : {
154 : if (!IS_DIR_SEPARATOR (d[2]))
155 : return NULL;
156 : if (c[0] == d[0] && c[1] == ':' && IS_DIR_SEPARATOR (c[2]))
157 : {
158 : c += 3;
159 : d += 3;
160 : }
161 : else
162 : return NULL;
163 : }
164 : else if (c[1] == ':')
165 : return NULL;
166 : #endif
167 : do
168 : {
169 0 : while (IS_DIR_SEPARATOR (*d))
170 0 : d++;
171 0 : while (IS_DIR_SEPARATOR (*c))
172 0 : c++;
173 : size_t i;
174 0 : for (i = 0; c[i] && !IS_DIR_SEPARATOR (c[i]) && c[i] == d[i]; i++)
175 : ;
176 0 : if ((c[i] == '\0' || IS_DIR_SEPARATOR (c[i]))
177 0 : && (d[i] == '\0' || IS_DIR_SEPARATOR (d[i])))
178 : {
179 0 : c += i;
180 0 : d += i;
181 0 : if (*c == '\0' || *d == '\0')
182 : break;
183 : }
184 : else
185 : break;
186 : }
187 : while (1);
188 0 : size_t num_up = 0;
189 : do
190 : {
191 0 : while (IS_DIR_SEPARATOR (*c))
192 0 : c++;
193 0 : if (*c == '\0')
194 : break;
195 0 : num_up++;
196 0 : while (*c && !IS_DIR_SEPARATOR (*c))
197 0 : c++;
198 : }
199 : while (1);
200 0 : while (IS_DIR_SEPARATOR (*d))
201 0 : d++;
202 0 : size_t len = strlen (d);
203 0 : if (len == 0 && num_up == 0)
204 0 : return xstrdup (".");
205 0 : char *ret = XNEWVEC (char, num_up * 3 + len + 1);
206 0 : char *p = ret;
207 0 : for (; num_up; num_up--)
208 : {
209 0 : const char dir_up[3] = { '.', '.', DIR_SEPARATOR };
210 0 : memcpy (p, dir_up, 3);
211 0 : p += 3;
212 : }
213 0 : memcpy (p, d, len + 1);
214 0 : return ret;
215 : }
216 :
217 : /* Look up DATA_WD in hash table of relative prefixes. If found,
218 : return relative path from CWD to DATA_WD from the hash table,
219 : otherwise create it. */
220 :
221 : static const char *
222 0 : canon_relative_path_prefix (const char *data_wd, const char *cwd)
223 : {
224 0 : if (!IS_ABSOLUTE_PATH (data_wd) || !IS_ABSOLUTE_PATH (cwd))
225 : return NULL;
226 :
227 0 : if (!path_name_pair_hash_table)
228 : {
229 0 : path_name_pair_hash_table
230 0 : = new hash_table<string_pair_map_hasher> (37);
231 0 : string_pair_map_allocator
232 0 : = new object_allocator <struct string_pair_map>
233 0 : ("line map string pair map hash");
234 : }
235 :
236 0 : inchash::hash h;
237 0 : h.add_ptr (cwd);
238 0 : h.merge_hash (htab_hash_string (data_wd));
239 0 : h.add_int (true);
240 :
241 0 : string_pair_map s_slot;
242 0 : s_slot.str1 = cwd;
243 0 : s_slot.str2 = data_wd;
244 0 : s_slot.str3 = NULL;
245 0 : s_slot.hash = h.end ();
246 0 : s_slot.prefix = true;
247 :
248 0 : string_pair_map **slot
249 0 : = path_name_pair_hash_table->find_slot (&s_slot, INSERT);
250 0 : if (*slot == NULL)
251 : {
252 : /* Compute relative path from cwd directory to data_wd directory.
253 : E.g. if cwd is /tmp/foo/bar and data_wd is /tmp/baz/qux ,
254 : it will return ../../baz/qux . */
255 0 : char *relative_path = relative_path_prefix (data_wd, cwd);
256 0 : const char *relative = relative_path ? relative_path : data_wd;
257 0 : size_t relative_len = strlen (relative);
258 0 : gcc_assert (relative_len);
259 :
260 0 : size_t data_wd_len = strlen (data_wd);
261 0 : bool add_separator = false;
262 0 : if (!IS_DIR_SEPARATOR (relative[relative_len - 1]))
263 0 : add_separator = true;
264 :
265 0 : size_t len = relative_len + 1 + data_wd_len + 1 + add_separator;
266 :
267 0 : char *saved_string = XOBNEWVEC (&file_name_obstack, char, len);
268 0 : struct string_pair_map *new_slot
269 0 : = string_pair_map_allocator->allocate ();
270 0 : memcpy (saved_string, data_wd, data_wd_len + 1);
271 0 : memcpy (saved_string + data_wd_len + 1, relative, relative_len);
272 0 : if (add_separator)
273 0 : saved_string[len - 2] = DIR_SEPARATOR;
274 0 : saved_string[len - 1] = '\0';
275 0 : new_slot->str1 = cwd;
276 0 : new_slot->str2 = saved_string;
277 0 : new_slot->str3 = saved_string + data_wd_len + 1;
278 0 : if (relative_len == 1 && relative[0] == '.')
279 0 : new_slot->str3 = NULL;
280 0 : new_slot->hash = s_slot.hash;
281 0 : new_slot->prefix = true;
282 0 : *slot = new_slot;
283 0 : free (relative_path);
284 0 : return new_slot->str3;
285 : }
286 : else
287 : {
288 0 : string_pair_map *old_slot = *slot;
289 0 : return old_slot->str3;
290 : }
291 : }
292 :
293 : /* Look up the pair of RELATIVE_PREFIX and STRING strings in a hash table.
294 : If found, return the concatenation of those from the hash table,
295 : otherwise concatenate them. */
296 :
297 : static const char *
298 0 : canon_relative_file_name (const char *relative_prefix, const char *string)
299 : {
300 0 : inchash::hash h;
301 0 : h.add_ptr (relative_prefix);
302 0 : h.merge_hash (htab_hash_string (string));
303 :
304 0 : string_pair_map s_slot;
305 0 : s_slot.str1 = relative_prefix;
306 0 : s_slot.str2 = string;
307 0 : s_slot.str3 = NULL;
308 0 : s_slot.hash = h.end ();
309 0 : s_slot.prefix = false;
310 :
311 0 : string_pair_map **slot
312 0 : = path_name_pair_hash_table->find_slot (&s_slot, INSERT);
313 0 : if (*slot == NULL)
314 : {
315 0 : size_t relative_prefix_len = strlen (relative_prefix);
316 0 : size_t string_len = strlen (string);
317 0 : size_t len = relative_prefix_len + string_len + 1;
318 :
319 0 : char *saved_string = XOBNEWVEC (&file_name_obstack, char, len);
320 0 : struct string_pair_map *new_slot
321 0 : = string_pair_map_allocator->allocate ();
322 0 : memcpy (saved_string, relative_prefix, relative_prefix_len);
323 0 : memcpy (saved_string + relative_prefix_len, string, string_len + 1);
324 0 : new_slot->str1 = relative_prefix;
325 0 : new_slot->str2 = saved_string + relative_prefix_len;
326 0 : new_slot->str3 = saved_string;
327 0 : new_slot->hash = s_slot.hash;
328 0 : new_slot->prefix = false;
329 0 : *slot = new_slot;
330 0 : return new_slot->str3;
331 : }
332 : else
333 : {
334 0 : string_pair_map *old_slot = *slot;
335 0 : return old_slot->str3;
336 : }
337 : }
338 :
339 : /* Lookup STRING in file_name_hash_table. If found, return the existing
340 : string, otherwise insert STRING as the canonical version.
341 : If STRING is a relative pathname and RELATIVE_PREFIX is non-NULL, use
342 : canon_relative_file_name instead. */
343 :
344 : static const char *
345 52542 : canon_file_name (const char *relative_prefix, const char *string)
346 : {
347 52542 : if (relative_prefix && !IS_ABSOLUTE_PATH (string))
348 0 : return canon_relative_file_name (relative_prefix, string);
349 :
350 52542 : string_slot **slot;
351 52542 : struct string_slot s_slot;
352 52542 : size_t len = strlen (string);
353 :
354 52542 : s_slot.s = string;
355 52542 : s_slot.len = len;
356 :
357 52542 : slot = file_name_hash_table->find_slot (&s_slot, INSERT);
358 52542 : if (*slot == NULL)
359 : {
360 48327 : char *saved_string;
361 48327 : struct string_slot *new_slot;
362 :
363 48327 : saved_string = XOBNEWVEC (&file_name_obstack, char, len + 1);
364 48327 : new_slot = string_slot_allocator->allocate ();
365 48327 : memcpy (saved_string, string, len + 1);
366 48327 : new_slot->s = saved_string;
367 48327 : new_slot->len = len;
368 48327 : *slot = new_slot;
369 48327 : return saved_string;
370 : }
371 : else
372 : {
373 4215 : struct string_slot *old_slot = *slot;
374 4215 : return old_slot->s;
375 : }
376 : }
377 :
378 : /* Given a map index and offset from the streamed data, convert it to a
379 : location_t in the global line map. */
380 :
381 : static location_t
382 3093121 : get_location_from_idx (size_t map_idx, location_t offset,
383 : const lto_loc_map *loc_map)
384 : {
385 3093121 : if (!map_idx)
386 : return offset;
387 3093121 : gcc_checking_assert (loc_map);
388 3093121 : --map_idx;
389 3093121 : gcc_assert (map_idx < loc_map->nmaps);
390 3093121 : const auto map = LINEMAPS_ORDINARY_MAP_AT (line_table, loc_map->map[map_idx]);
391 3093121 : const location_t res = map->start_location + offset;
392 3093121 : gcc_checking_assert (res < (map == LINEMAPS_LAST_ORDINARY_MAP (line_table)
393 : ? line_table->highest_location + 1
394 : : map[1].start_location));
395 : return res;
396 : }
397 :
398 : /* Pointer to currently alive instance of lto_location_cache. */
399 :
400 : lto_location_cache *lto_location_cache::current_cache;
401 :
402 : /* Apply all changes in location cache. Add locations into linemap and patch
403 : trees. */
404 :
405 : bool
406 639003 : lto_location_cache::apply_location_cache ()
407 : {
408 639003 : if (loc_cache.is_empty ())
409 : return true;
410 :
411 2027662 : for (const auto &cloc: loc_cache)
412 : {
413 1744519 : const location_t loc = cloc.loc;
414 1744519 : const auto range = source_range::from_location (loc);
415 1744519 : *cloc.dest = line_table->get_or_create_combined_loc (loc, range,
416 1744519 : cloc.block,
417 1744519 : cloc.discr);
418 : }
419 566286 : current_cloc = loc_cache[loc_cache.length () - 1];
420 283143 : current_loc = *current_cloc.dest;
421 283143 : loc_cache.truncate (0);
422 283143 : accepted_length = 0;
423 283143 : return true;
424 : }
425 :
426 : /* Tree merging did not succeed; mark all changes in the cache as accepted. */
427 :
428 : void
429 1915747 : lto_location_cache::accept_location_cache ()
430 : {
431 1915747 : gcc_assert (current_cache == this);
432 1915747 : accepted_length = loc_cache.length ();
433 1915747 : }
434 :
435 : /* Tree merging did succeed; throw away recent changes. */
436 :
437 : void
438 148908 : lto_location_cache::revert_location_cache ()
439 : {
440 148908 : loc_cache.truncate (accepted_length);
441 148908 : }
442 :
443 : /* Bitpack packing is more efficient for small values since every 4th bit is a
444 : continuation bit, so it helps to pack values as the delta from the previous
445 : if they can get large. */
446 : template<typename Int>
447 : static Int
448 6110972 : bp_unpack_delta (bitpack_d *bp, Int &prev)
449 : {
450 6110972 : const bool decrease = bp_unpack_value (bp, 1);
451 6110972 : const Int delta = bp_unpack_var_len_unsigned (bp);
452 6110972 : return prev = (decrease ? prev - delta : prev + delta);
453 : }
454 :
455 : /* Read the linemap section of order LINEMAP_ID from FILE_DATA and create an
456 : lto_loc_map object that can be used to find which ordinary map in the
457 : global line_table corresponds to a given streamed-out map index. Always
458 : either returns a non-NULL pointer, or calls fatal_error(). */
459 :
460 : static lto_loc_map *
461 23113 : create_loc_map (lto_file_decl_data *file_data, unsigned linemap_id)
462 : {
463 23113 : timevar_push (TV_IPA_LTO_LINEMAP_IN);
464 :
465 23113 : size_t len;
466 23113 : const auto data = lto_get_section_data (file_data, LTO_section_linemap,
467 : nullptr, linemap_id, &len, true);
468 23113 : if (!data)
469 0 : fatal_error (UNKNOWN_LOCATION,
470 : "linemap section #%u not found in file %qs",
471 : linemap_id, file_data->file_name);
472 :
473 23113 : const auto header = (const lto_simple_header_with_strings *) data;
474 23113 : const char *const main_begin = data + sizeof (*header);
475 23113 : const auto data_in
476 46226 : = lto_data_in_create (file_data, main_begin + header->main_size,
477 23113 : header->string_size, vNULL, false);
478 23113 : lto_input_block ib (main_begin, header->main_size, file_data);
479 23113 : bitpack_d bp = streamer_read_bitpack (&ib);
480 :
481 : /* Create the location map object. */
482 23113 : const size_t nmaps = bp_unpack_var_len_unsigned (&bp);
483 23113 : size_t loc_map_sz = sizeof (lto_loc_map);
484 23113 : if (nmaps > 1)
485 5639 : loc_map_sz += (nmaps - 1) * sizeof (size_t);
486 23113 : const auto loc_map = (lto_loc_map *) ggc_internal_alloc (loc_map_sz);
487 23113 : loc_map->nmaps = nmaps;
488 :
489 : /* Read the line map data. */
490 23113 : const char *stream_relative_path_prefix = nullptr;
491 23113 : const char *stream_file = nullptr;
492 23113 : size_t cur_map_idx = 0;
493 23113 : linenum_type cur_line = 0;
494 75655 : for (size_t i = 0; i != nmaps; ++i)
495 : {
496 52542 : const size_t map_idx = bp_unpack_delta (&bp, cur_map_idx);
497 52542 : gcc_assert (map_idx && map_idx <= nmaps);
498 52542 : const line_map_uint_t num_lines = bp_unpack_var_len_unsigned (&bp);
499 52542 : const bool sysp = bp_unpack_value (&bp, 1);
500 52542 : const unsigned int column_bits = bp_unpack_value (&bp, 8);
501 52542 : const linenum_type to_line = bp_unpack_delta (&bp, cur_line);
502 52542 : const bool file_change = bp_unpack_value (&bp, 1);
503 52542 : if (file_change)
504 : {
505 52542 : const bool pwd_change = bp_unpack_value (&bp, 1);
506 52542 : if (pwd_change)
507 : {
508 2826 : const char *pwd = bp_unpack_string (data_in, &bp);
509 2826 : const char *src_pwd = get_src_pwd ();
510 2826 : stream_relative_path_prefix
511 2826 : = strcmp (pwd, src_pwd) == 0 ? nullptr
512 0 : : canon_relative_path_prefix (pwd, src_pwd);
513 : }
514 52542 : stream_file = canon_file_name (stream_relative_path_prefix,
515 : bp_unpack_string (data_in, &bp));
516 : }
517 52542 : gcc_assert (stream_file);
518 52542 : const auto map
519 52542 : = linemap_add_raw_map (line_table,
520 52542 : line_table->depth ? LC_RENAME : LC_ENTER,
521 52542 : line_table->highest_location + 1, sysp,
522 : column_bits, 0, stream_file, to_line, num_lines);
523 52542 : if (!map)
524 0 : fatal_error (UNKNOWN_LOCATION,
525 : "Ran out of locations while reading linemap section #%u",
526 : linemap_id);
527 52542 : loc_map->map[map_idx - 1] = map - line_table->info_ordinary.maps;
528 52542 : if (flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
529 : {
530 21236 : const auto out_id = lto_linemap_output_id (linemap_id, file_data);
531 21236 : lto_register_linemap_for_output (map_idx, out_id);
532 : }
533 : }
534 :
535 : /* Process the diagnostics classification history. */
536 23113 : auto &chist = global_dc->get_classification_history ();
537 23113 : const int pop_offset = chist.length ();
538 23113 : using DK = diagnostics::kind;
539 113290 : for (size_t i = 0, nc = bp_unpack_var_len_unsigned (&bp); i != nc; ++i)
540 : {
541 90177 : const size_t map_idx = bp_unpack_var_len_unsigned (&bp);
542 90177 : const location_t offset = bp_unpack_var_len_unsigned (&bp);
543 90177 : const location_t loc = get_location_from_idx (map_idx, offset, loc_map);
544 90177 : const int option = bp_unpack_var_len_int (&bp);
545 90177 : const auto kind = bp_unpack_enum (&bp, diagnostics::kind,
546 : DK::tot_num_diagnostic_kinds);
547 90177 : if (kind == DK::pop)
548 : {
549 46458 : diagnostics::option_classifier::classification_change_t c = {};
550 46458 : c.location = loc;
551 46458 : c.option = option + pop_offset;
552 46458 : c.kind = kind;
553 46458 : chist.safe_push (c);
554 : }
555 : else
556 43719 : global_dc->classify_diagnostic (option, kind, loc);
557 : }
558 : /* Make sure we reset back to the baseline. */
559 23113 : {
560 23113 : diagnostics::option_classifier::classification_change_t c = {};
561 23113 : c.location = line_table->highest_location;
562 23113 : c.kind = DK::pop;
563 23113 : chist.safe_push (c);
564 : }
565 :
566 23113 : lto_data_in_delete (data_in);
567 23113 : lto_free_section_data (file_data, LTO_section_linemap, nullptr,
568 : data, len, true);
569 :
570 23113 : timevar_pop (TV_IPA_LTO_LINEMAP_IN);
571 23113 : return loc_map;
572 : }
573 :
574 : /* Return the location map with given ID, reading it from the LTO object if
575 : necessary. */
576 :
577 : static const lto_loc_map *
578 109858 : get_loc_map (lto_file_decl_data *file_data, unsigned linemap_id)
579 : {
580 : /* During LTRANS, the location maps are stored in a different object. */
581 155613 : while (file_data->loc_map_decl_data)
582 : file_data = file_data->loc_map_decl_data;
583 :
584 109858 : if (vec_safe_length (file_data->loc_maps) <= linemap_id)
585 22882 : vec_safe_grow_cleared (file_data->loc_maps, linemap_id + 1);
586 109858 : auto &res = (*file_data->loc_maps)[linemap_id];
587 109858 : if (!res)
588 23113 : res = create_loc_map (file_data, linemap_id);
589 109858 : return res;
590 : }
591 :
592 :
593 : /* Read a location bitpack from bit pack BP and either update *LOC directly or
594 : add it to the location cache. It is necessary to call apply_location_cache
595 : to guarantee that *LOC has been updated. */
596 :
597 : void
598 5109242 : lto_location_cache::input_location_and_block (location_t *dest,
599 : struct bitpack_d *bp,
600 : class lto_input_block *ib,
601 : class data_in *data_in)
602 : {
603 5109242 : gcc_checking_assert (decl_data);
604 :
605 5109242 : location_t loc;
606 5109242 : unsigned this_discr;
607 5109242 : const bool is_reserved = bp_unpack_value (bp, 1);
608 5109242 : if (is_reserved)
609 : {
610 2106298 : loc = bp_unpack_int_in_range (bp, "loc", 0, RESERVED_LOCATION_COUNT - 1);
611 2106298 : this_discr = 0;
612 : }
613 : else
614 : {
615 3002944 : const bool linemap_change = bp_unpack_value (bp, 1);
616 3002944 : if (linemap_change)
617 : {
618 109858 : const unsigned linemap_id = bp_unpack_var_len_unsigned (bp);
619 109858 : cur_loc_map = get_loc_map (decl_data, linemap_id + linemap_offset);
620 : }
621 3002944 : const auto prev_idx = stream_map_idx;
622 3002944 : bp_unpack_delta (bp, stream_map_idx);
623 3002944 : bp_unpack_delta (bp, stream_loc_offset);
624 3002944 : if (stream_map_idx != prev_idx)
625 : /* The hash code is only there for the benefit of -flto-incremental;
626 : we don't need to do anything with it here. */
627 187289 : bp_unpack_var_len_unsigned (bp);
628 :
629 3002944 : loc = get_location_from_idx (stream_map_idx, stream_loc_offset,
630 : cur_loc_map);
631 3002944 : if (bp_unpack_value (bp, 1))
632 1140747 : stream_discr = bp_unpack_var_len_unsigned (bp);
633 3002944 : this_discr = stream_discr;
634 : }
635 :
636 5109242 : tree this_block = NULL_TREE;
637 5109242 : if (ib)
638 : {
639 2505522 : if (bp_unpack_value (bp, 1))
640 525883 : stream_block = stream_read_tree (ib, data_in);
641 2505522 : this_block = stream_block;
642 : }
643 :
644 : /* If this location can be ordinary rather than ad-hoc, then there is no more
645 : overhead associated with it, so we may as well finalize it now. */
646 5109242 : if (!(this_discr || this_block))
647 : {
648 3341891 : *dest = loc;
649 3364723 : return;
650 : }
651 :
652 : /* This optimization saves location cache operations during gimple
653 : streaming. */
654 1767351 : if (loc == current_cloc.loc
655 191949 : && this_block == current_cloc.block
656 107994 : && this_discr == current_cloc.discr)
657 : {
658 22832 : *dest = current_loc;
659 22832 : return;
660 : }
661 :
662 : /* Keep value RESERVED_LOCATION_COUNT in *dest so linemap lookups will ICE on
663 : it if we erroneously try to use the location before it is ready. */
664 1744519 : *dest = RESERVED_LOCATION_COUNT;
665 :
666 : /* This location needs to be ad-hoc; remember the details for now and create
667 : the ad-hoc location later once we know we need it. */
668 1744519 : cached_location entry = {};
669 1744519 : entry.dest = dest;
670 1744519 : entry.loc = loc;
671 1744519 : entry.block = this_block;
672 1744519 : entry.discr = this_discr;
673 1744519 : loc_cache.safe_push (entry);
674 : }
675 :
676 : void
677 2603720 : lto_location_cache::input_location (location_t *dest, struct bitpack_d *bp,
678 : class data_in *data_in)
679 : {
680 2603720 : return input_location_and_block (dest, bp, NULL, data_in);
681 : }
682 :
683 : void
684 2603720 : lto_input_location (location_t *loc, struct bitpack_d *bp,
685 : class data_in *data_in)
686 : {
687 2603720 : data_in->location_cache.input_location (loc, bp, data_in);
688 2603720 : }
689 :
690 : /* Read a reference to a tree node from DATA_IN using input block IB.
691 : TAG is the expected node that should be found in IB, if TAG belongs
692 : to one of the indexable trees, expect to read a reference index to
693 : be looked up in one of the symbol tables, otherwise read the physical
694 : representation of the tree using stream_read_tree. FN is the
695 : function scope for the read tree. */
696 :
697 : tree
698 4145404 : lto_input_tree_ref (class lto_input_block *ib, class data_in *data_in,
699 : struct function *fn, enum LTO_tags tag)
700 : {
701 4145404 : unsigned HOST_WIDE_INT ix_u;
702 4145404 : tree result = NULL_TREE;
703 :
704 4145404 : if (tag == LTO_ssa_name_ref)
705 : {
706 1643240 : ix_u = streamer_read_uhwi (ib);
707 1643240 : result = (*SSANAMES (fn))[ix_u];
708 : }
709 : else
710 : {
711 2502164 : gcc_checking_assert (tag == LTO_global_stream_ref);
712 2502164 : ix_u = streamer_read_uhwi (ib);
713 2502164 : result = (*data_in->file_data->current_decl_state
714 2502164 : ->streams[LTO_DECL_STREAM])[ix_u];
715 : }
716 :
717 4145404 : gcc_assert (result);
718 :
719 4145404 : return result;
720 : }
721 :
722 : /* Read VAR_DECL reference to DATA from IB. */
723 :
724 : tree
725 75625 : lto_input_var_decl_ref (lto_input_block *ib, lto_file_decl_data *file_data)
726 : {
727 75625 : unsigned int ix_u = streamer_read_uhwi (ib);
728 75625 : tree result = (*file_data->current_decl_state
729 75625 : ->streams[LTO_DECL_STREAM])[ix_u];
730 75625 : gcc_assert (VAR_P (result));
731 75625 : return result;
732 : }
733 :
734 : /* Read VAR_DECL reference to DATA from IB. */
735 :
736 : tree
737 200414 : lto_input_fn_decl_ref (lto_input_block *ib, lto_file_decl_data *file_data)
738 : {
739 200414 : unsigned int ix_u = streamer_read_uhwi (ib);
740 200414 : tree result = (*file_data->current_decl_state
741 200414 : ->streams[LTO_DECL_STREAM])[ix_u];
742 200414 : gcc_assert (TREE_CODE (result) == FUNCTION_DECL);
743 200414 : return result;
744 : }
745 :
746 :
747 : /* Read and return a double-linked list of catch handlers from input
748 : block IB, using descriptors in DATA_IN. */
749 :
750 : static struct eh_catch_d *
751 212 : lto_input_eh_catch_list (class lto_input_block *ib, class data_in *data_in,
752 : eh_catch *last_p)
753 : {
754 212 : eh_catch first;
755 212 : enum LTO_tags tag;
756 :
757 212 : *last_p = first = NULL;
758 212 : tag = streamer_read_record_start (ib);
759 452 : while (tag)
760 : {
761 240 : tree list;
762 240 : eh_catch n;
763 :
764 240 : lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
765 :
766 : /* Read the catch node. */
767 240 : n = ggc_cleared_alloc<eh_catch_d> ();
768 240 : n->type_list = stream_read_tree (ib, data_in);
769 240 : n->filter_list = stream_read_tree (ib, data_in);
770 240 : n->label = stream_read_tree (ib, data_in);
771 :
772 : /* Register all the types in N->FILTER_LIST. */
773 240 : for (list = n->filter_list; list; list = TREE_CHAIN (list))
774 0 : add_type_for_runtime (TREE_VALUE (list));
775 :
776 : /* Chain N to the end of the list. */
777 240 : if (*last_p)
778 44 : (*last_p)->next_catch = n;
779 240 : n->prev_catch = *last_p;
780 240 : *last_p = n;
781 :
782 : /* Set the head of the list the first time through the loop. */
783 240 : if (first == NULL)
784 196 : first = n;
785 :
786 240 : tag = streamer_read_record_start (ib);
787 : }
788 :
789 212 : return first;
790 : }
791 :
792 :
793 : /* Read and return EH region IX from input block IB, using descriptors
794 : in DATA_IN. */
795 :
796 : static eh_region
797 15662 : input_eh_region (class lto_input_block *ib, class data_in *data_in, int ix)
798 : {
799 15662 : enum LTO_tags tag;
800 15662 : eh_region r;
801 :
802 : /* Read the region header. */
803 15662 : tag = streamer_read_record_start (ib);
804 15662 : if (tag == LTO_null)
805 : return NULL;
806 :
807 9552 : r = ggc_cleared_alloc<eh_region_d> ();
808 9552 : r->index = streamer_read_hwi (ib);
809 :
810 9552 : gcc_assert (r->index == ix);
811 :
812 : /* Read all the region pointers as region numbers. We'll fix up
813 : the pointers once the whole array has been read. */
814 9552 : r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib);
815 9552 : r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib);
816 9552 : r->next_peer = (eh_region) (intptr_t) streamer_read_hwi (ib);
817 :
818 9552 : switch (tag)
819 : {
820 4004 : case LTO_ert_cleanup:
821 4004 : r->type = ERT_CLEANUP;
822 4004 : break;
823 :
824 212 : case LTO_ert_try:
825 212 : {
826 212 : struct eh_catch_d *last_catch;
827 212 : r->type = ERT_TRY;
828 212 : r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
829 : &last_catch);
830 212 : r->u.eh_try.last_catch = last_catch;
831 212 : break;
832 : }
833 :
834 321 : case LTO_ert_allowed_exceptions:
835 321 : {
836 321 : tree l;
837 :
838 321 : r->type = ERT_ALLOWED_EXCEPTIONS;
839 321 : r->u.allowed.type_list = stream_read_tree (ib, data_in);
840 321 : r->u.allowed.label = stream_read_tree (ib, data_in);
841 321 : r->u.allowed.filter = streamer_read_uhwi (ib);
842 :
843 323 : for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
844 2 : add_type_for_runtime (TREE_VALUE (l));
845 : }
846 : break;
847 :
848 5015 : case LTO_ert_must_not_throw:
849 5015 : {
850 5015 : r->type = ERT_MUST_NOT_THROW;
851 5015 : r->u.must_not_throw.failure_decl = stream_read_tree (ib, data_in);
852 5015 : bitpack_d bp = streamer_read_bitpack (ib);
853 5015 : stream_input_location (&r->u.must_not_throw.failure_loc,
854 : &bp, data_in);
855 : }
856 5015 : break;
857 :
858 0 : default:
859 0 : gcc_unreachable ();
860 : }
861 :
862 9552 : r->landing_pads = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
863 :
864 9552 : return r;
865 : }
866 :
867 :
868 : /* Read and return EH landing pad IX from input block IB, using descriptors
869 : in DATA_IN. */
870 :
871 : static eh_landing_pad
872 6868 : input_eh_lp (class lto_input_block *ib, class data_in *data_in, int ix)
873 : {
874 6868 : enum LTO_tags tag;
875 6868 : eh_landing_pad lp;
876 :
877 : /* Read the landing pad header. */
878 6868 : tag = streamer_read_record_start (ib);
879 6868 : if (tag == LTO_null)
880 : return NULL;
881 :
882 2572 : lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
883 :
884 2572 : lp = ggc_cleared_alloc<eh_landing_pad_d> ();
885 2572 : lp->index = streamer_read_hwi (ib);
886 2572 : gcc_assert (lp->index == ix);
887 2572 : lp->next_lp = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
888 2572 : lp->region = (eh_region) (intptr_t) streamer_read_hwi (ib);
889 2572 : lp->post_landing_pad = stream_read_tree (ib, data_in);
890 :
891 2572 : return lp;
892 : }
893 :
894 :
895 : /* After reading the EH regions, pointers to peer and children regions
896 : are region numbers. This converts all these region numbers into
897 : real pointers into the rematerialized regions for FN. ROOT_REGION
898 : is the region number for the root EH region in FN. */
899 :
900 : static void
901 3689 : fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
902 : {
903 3689 : unsigned i;
904 3689 : vec<eh_region, va_gc> *eh_array = fn->eh->region_array;
905 3689 : vec<eh_landing_pad, va_gc> *lp_array = fn->eh->lp_array;
906 3689 : eh_region r;
907 3689 : eh_landing_pad lp;
908 :
909 3689 : gcc_assert (eh_array && lp_array);
910 :
911 3689 : gcc_assert (root_region >= 0);
912 3689 : fn->eh->region_tree = (*eh_array)[root_region];
913 :
914 : #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)]
915 : #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)]
916 :
917 : /* Convert all the index numbers stored in pointer fields into
918 : pointers to the corresponding slots in the EH region array. */
919 19351 : FOR_EACH_VEC_ELT (*eh_array, i, r)
920 : {
921 : /* The array may contain NULL regions. */
922 15662 : if (r == NULL)
923 6110 : continue;
924 :
925 9552 : gcc_assert (i == (unsigned) r->index);
926 9552 : FIXUP_EH_REGION (r->outer);
927 9552 : FIXUP_EH_REGION (r->inner);
928 9552 : FIXUP_EH_REGION (r->next_peer);
929 9552 : FIXUP_EH_LP (r->landing_pads);
930 : }
931 :
932 : /* Convert all the index numbers stored in pointer fields into
933 : pointers to the corresponding slots in the EH landing pad array. */
934 10557 : FOR_EACH_VEC_ELT (*lp_array, i, lp)
935 : {
936 : /* The array may contain NULL landing pads. */
937 6868 : if (lp == NULL)
938 4296 : continue;
939 :
940 2572 : gcc_assert (i == (unsigned) lp->index);
941 2572 : FIXUP_EH_LP (lp->next_lp);
942 2572 : FIXUP_EH_REGION (lp->region);
943 : }
944 :
945 : #undef FIXUP_EH_REGION
946 : #undef FIXUP_EH_LP
947 3689 : }
948 :
949 :
950 : /* Initialize EH support. */
951 :
952 : void
953 43507 : lto_init_eh (void)
954 : {
955 43507 : static bool eh_initialized_p = false;
956 :
957 43507 : if (eh_initialized_p)
958 : return;
959 :
960 : /* Contrary to most other FEs, we only initialize EH support when at
961 : least one of the files in the set contains exception regions in
962 : it. Since this happens much later than the call to init_eh in
963 : lang_dependent_init, we have to set flag_exceptions and call
964 : init_eh again to initialize the EH tables. */
965 3769 : flag_exceptions = 1;
966 3769 : init_eh ();
967 :
968 3769 : eh_initialized_p = true;
969 : }
970 :
971 :
972 : /* Read the exception table for FN from IB using the data descriptors
973 : in DATA_IN. */
974 :
975 : static void
976 85823 : input_eh_regions (class lto_input_block *ib, class data_in *data_in,
977 : struct function *fn)
978 : {
979 85823 : HOST_WIDE_INT i, root_region, len;
980 85823 : enum LTO_tags tag;
981 :
982 85823 : tag = streamer_read_record_start (ib);
983 85823 : if (tag == LTO_null)
984 : return;
985 :
986 3689 : lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
987 :
988 3689 : gcc_assert (fn->eh);
989 :
990 3689 : root_region = streamer_read_hwi (ib);
991 3689 : gcc_assert (root_region == (int) root_region);
992 :
993 : /* Read the EH region array. */
994 3689 : len = streamer_read_hwi (ib);
995 3689 : gcc_assert (len == (int) len);
996 3689 : if (len > 0)
997 : {
998 3689 : vec_safe_grow_cleared (fn->eh->region_array, len, true);
999 23040 : for (i = 0; i < len; i++)
1000 : {
1001 15662 : eh_region r = input_eh_region (ib, data_in, i);
1002 15662 : (*fn->eh->region_array)[i] = r;
1003 : }
1004 : }
1005 :
1006 : /* Read the landing pads. */
1007 3689 : len = streamer_read_hwi (ib);
1008 3689 : gcc_assert (len == (int) len);
1009 3689 : if (len > 0)
1010 : {
1011 3689 : vec_safe_grow_cleared (fn->eh->lp_array, len, true);
1012 14246 : for (i = 0; i < len; i++)
1013 : {
1014 6868 : eh_landing_pad lp = input_eh_lp (ib, data_in, i);
1015 6868 : (*fn->eh->lp_array)[i] = lp;
1016 : }
1017 : }
1018 :
1019 : /* Read the runtime type data. */
1020 3689 : len = streamer_read_hwi (ib);
1021 3689 : gcc_assert (len == (int) len);
1022 3689 : if (len > 0)
1023 : {
1024 0 : vec_safe_grow_cleared (fn->eh->ttype_data, len, true);
1025 0 : for (i = 0; i < len; i++)
1026 : {
1027 0 : tree ttype = stream_read_tree (ib, data_in);
1028 0 : (*fn->eh->ttype_data)[i] = ttype;
1029 : }
1030 : }
1031 :
1032 : /* Read the table of action chains. */
1033 3689 : len = streamer_read_hwi (ib);
1034 3689 : gcc_assert (len == (int) len);
1035 3689 : if (len > 0)
1036 : {
1037 0 : if (targetm.arm_eabi_unwinder)
1038 : {
1039 0 : vec_safe_grow_cleared (fn->eh->ehspec_data.arm_eabi, len, true);
1040 0 : for (i = 0; i < len; i++)
1041 : {
1042 0 : tree t = stream_read_tree (ib, data_in);
1043 0 : (*fn->eh->ehspec_data.arm_eabi)[i] = t;
1044 : }
1045 : }
1046 : else
1047 : {
1048 0 : vec_safe_grow_cleared (fn->eh->ehspec_data.other, len, true);
1049 0 : for (i = 0; i < len; i++)
1050 : {
1051 0 : uchar c = streamer_read_uchar (ib);
1052 0 : (*fn->eh->ehspec_data.other)[i] = c;
1053 : }
1054 : }
1055 : }
1056 :
1057 : /* Reconstruct the EH region tree by fixing up the peer/children
1058 : pointers. */
1059 3689 : fixup_eh_region_pointers (fn, root_region);
1060 :
1061 3689 : tag = streamer_read_record_start (ib);
1062 3689 : lto_tag_check_range (tag, LTO_null, LTO_null);
1063 : }
1064 :
1065 :
1066 : /* Make a new basic block with index INDEX in function FN. */
1067 :
1068 : static basic_block
1069 590389 : make_new_block (struct function *fn, unsigned int index)
1070 : {
1071 590389 : basic_block bb = alloc_block ();
1072 590389 : bb->index = index;
1073 590389 : SET_BASIC_BLOCK_FOR_FN (fn, index, bb);
1074 590389 : n_basic_blocks_for_fn (fn)++;
1075 590389 : return bb;
1076 : }
1077 :
1078 :
1079 : /* Read the CFG for function FN from input block IB. */
1080 :
1081 : static void
1082 85823 : input_cfg (class lto_input_block *ib, class data_in *data_in,
1083 : struct function *fn)
1084 : {
1085 85823 : unsigned int bb_count;
1086 85823 : basic_block p_bb;
1087 85823 : unsigned int i;
1088 85823 : int index;
1089 85823 : bool full_profile = false;
1090 :
1091 85823 : init_empty_tree_cfg_for_function (fn);
1092 :
1093 85823 : profile_status_for_fn (fn) = streamer_read_enum (ib, profile_status_d,
1094 : PROFILE_LAST);
1095 :
1096 85823 : bb_count = streamer_read_uhwi (ib);
1097 :
1098 85823 : last_basic_block_for_fn (fn) = bb_count;
1099 85823 : if (bb_count > basic_block_info_for_fn (fn)->length ())
1100 2245 : vec_safe_grow_cleared (basic_block_info_for_fn (fn), bb_count, true);
1101 :
1102 85823 : if (bb_count > label_to_block_map_for_fn (fn)->length ())
1103 2245 : vec_safe_grow_cleared (label_to_block_map_for_fn (fn), bb_count, true);
1104 :
1105 85823 : index = streamer_read_hwi (ib);
1106 847858 : while (index != -1)
1107 : {
1108 762035 : basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
1109 762035 : unsigned int edge_count;
1110 :
1111 762035 : if (bb == NULL)
1112 550783 : bb = make_new_block (fn, index);
1113 :
1114 762035 : edge_count = streamer_read_uhwi (ib);
1115 762035 : vec_safe_reserve (bb->preds, edge_count);
1116 :
1117 : /* Connect up the CFG. */
1118 2398546 : for (i = 0; i < edge_count; i++)
1119 : {
1120 874476 : bitpack_d bp = streamer_read_bitpack (ib);
1121 874476 : unsigned int src_index = bp_unpack_var_len_unsigned (&bp);
1122 874476 : unsigned int edge_flags = bp_unpack_var_len_unsigned (&bp);
1123 874476 : basic_block src = BASIC_BLOCK_FOR_FN (fn, src_index);
1124 :
1125 874476 : if (src == NULL)
1126 39606 : src = make_new_block (fn, src_index);
1127 :
1128 874476 : edge e = make_edge (src, bb, edge_flags);
1129 874476 : data_in->location_cache.input_location_and_block (&e->goto_locus,
1130 : &bp, ib, data_in);
1131 874476 : e->probability = profile_probability::stream_in (ib);
1132 874476 : if (!e->probability.initialized_p ())
1133 874476 : full_profile = false;
1134 : }
1135 :
1136 762035 : index = streamer_read_hwi (ib);
1137 : }
1138 :
1139 85823 : p_bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
1140 85823 : index = streamer_read_hwi (ib);
1141 762035 : while (index != -1)
1142 : {
1143 676212 : basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
1144 676212 : bb->prev_bb = p_bb;
1145 676212 : p_bb->next_bb = bb;
1146 676212 : p_bb = bb;
1147 676212 : index = streamer_read_hwi (ib);
1148 : }
1149 :
1150 : /* ??? The cfgloop interface is tied to cfun. */
1151 85823 : gcc_assert (cfun == fn);
1152 :
1153 : /* Input the loop tree. */
1154 85823 : unsigned n_loops = streamer_read_uhwi (ib);
1155 85823 : if (n_loops == 0)
1156 : return;
1157 :
1158 85823 : struct loops *loops = ggc_cleared_alloc<struct loops> ();
1159 85823 : init_loops_structure (fn, loops, n_loops);
1160 85823 : set_loops_for_fn (fn, loops);
1161 :
1162 : /* Input each loop and associate it with its loop header so
1163 : flow_loops_find can rebuild the loop tree. */
1164 231481 : for (unsigned i = 1; i < n_loops; ++i)
1165 : {
1166 59835 : int header_index = streamer_read_hwi (ib);
1167 59835 : if (header_index == -1)
1168 : {
1169 21388 : loops->larray->quick_push (NULL);
1170 21388 : continue;
1171 : }
1172 :
1173 38447 : class loop *loop = alloc_loop ();
1174 38447 : loop->header = BASIC_BLOCK_FOR_FN (fn, header_index);
1175 38447 : loop->header->loop_father = loop;
1176 :
1177 : /* Read everything copy_loop_info copies. */
1178 38447 : loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST);
1179 38447 : loop->any_upper_bound = streamer_read_hwi (ib);
1180 38447 : if (loop->any_upper_bound)
1181 33373 : loop->nb_iterations_upper_bound
1182 33373 : = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
1183 38447 : loop->any_likely_upper_bound = streamer_read_hwi (ib);
1184 38447 : if (loop->any_likely_upper_bound)
1185 33373 : loop->nb_iterations_likely_upper_bound
1186 33373 : = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
1187 38447 : loop->any_estimate = streamer_read_hwi (ib);
1188 38447 : if (loop->any_estimate)
1189 27575 : loop->nb_iterations_estimate
1190 27575 : = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
1191 :
1192 : /* Read OMP SIMD related info. */
1193 38447 : loop->safelen = streamer_read_hwi (ib);
1194 38447 : loop->unroll = streamer_read_hwi (ib);
1195 38447 : loop->owned_clique = streamer_read_hwi (ib);
1196 38447 : loop->dont_vectorize = streamer_read_hwi (ib);
1197 38447 : loop->force_vectorize = streamer_read_hwi (ib);
1198 38447 : loop->finite_p = streamer_read_hwi (ib);
1199 38447 : loop->can_be_parallel = streamer_read_hwi (ib);
1200 38447 : loop->simduid = stream_read_tree (ib, data_in);
1201 :
1202 38447 : place_new_loop (fn, loop);
1203 :
1204 : /* flow_loops_find doesn't like loops not in the tree, hook them
1205 : all as siblings of the tree root temporarily. */
1206 38447 : flow_loop_tree_node_add (loops->tree_root, loop);
1207 : }
1208 :
1209 : /* Rebuild the loop tree. */
1210 85823 : flow_loops_find (loops);
1211 85823 : cfun->cfg->full_profile = full_profile;
1212 : }
1213 :
1214 :
1215 : /* Read the SSA names array for function FN from DATA_IN using input
1216 : block IB. */
1217 :
1218 : static void
1219 85823 : input_ssa_names (class lto_input_block *ib, class data_in *data_in,
1220 : struct function *fn)
1221 : {
1222 85823 : unsigned int i, size;
1223 :
1224 85823 : size = streamer_read_uhwi (ib);
1225 85823 : init_tree_ssa (fn, size);
1226 85823 : cfun->gimple_df->in_ssa_p = true;
1227 85823 : init_ssa_operands (fn);
1228 :
1229 85823 : i = streamer_read_uhwi (ib);
1230 928301 : while (i)
1231 : {
1232 : tree ssa_name, name;
1233 : bool is_default_def;
1234 :
1235 : /* Skip over the elements that had been freed. */
1236 1129171 : while (SSANAMES (fn)->length () < i)
1237 286693 : SSANAMES (fn)->quick_push (NULL_TREE);
1238 :
1239 842478 : is_default_def = (streamer_read_uchar (ib) != 0);
1240 842478 : name = stream_read_tree (ib, data_in);
1241 842478 : ssa_name = make_ssa_name_fn (fn, name, NULL);
1242 :
1243 842478 : if (is_default_def)
1244 : {
1245 86800 : set_ssa_default_def (cfun, SSA_NAME_VAR (ssa_name), ssa_name);
1246 86800 : SSA_NAME_DEF_STMT (ssa_name) = gimple_build_nop ();
1247 : }
1248 :
1249 842478 : i = streamer_read_uhwi (ib);
1250 : }
1251 85823 : }
1252 :
1253 :
1254 : /* Go through all NODE edges and fixup call_stmt pointers
1255 : so they point to STMTS. */
1256 :
1257 : static void
1258 112212 : fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple **stmts,
1259 : struct function *fn)
1260 : {
1261 : #define STMT_UID_NOT_IN_RANGE(uid) \
1262 : (gimple_stmt_max_uid (fn) < uid || uid == 0)
1263 :
1264 112212 : struct cgraph_edge *cedge;
1265 112212 : struct ipa_ref *ref = NULL;
1266 112212 : unsigned int i;
1267 :
1268 484902 : for (cedge = node->callees; cedge; cedge = cedge->next_callee)
1269 : {
1270 372690 : if (STMT_UID_NOT_IN_RANGE (cedge->lto_stmt_uid))
1271 0 : fatal_error (input_location,
1272 : "Cgraph edge statement index out of range");
1273 372690 : cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
1274 372690 : cedge->lto_stmt_uid = 0;
1275 372690 : if (!cedge->call_stmt)
1276 : fatal_error (input_location,
1277 : "Cgraph edge statement index not found");
1278 : }
1279 113932 : for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
1280 : {
1281 1720 : if (STMT_UID_NOT_IN_RANGE (cedge->lto_stmt_uid))
1282 0 : fatal_error (input_location,
1283 : "Cgraph edge statement index out of range");
1284 1720 : cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
1285 1720 : cedge->lto_stmt_uid = 0;
1286 1720 : if (!cedge->call_stmt)
1287 : fatal_error (input_location, "Cgraph edge statement index not found");
1288 : }
1289 372378 : for (i = 0; node->iterate_reference (i, ref); i++)
1290 260166 : if (ref->lto_stmt_uid)
1291 : {
1292 254774 : if (STMT_UID_NOT_IN_RANGE (ref->lto_stmt_uid))
1293 0 : fatal_error (input_location,
1294 : "Reference statement index out of range");
1295 254774 : ref->stmt = stmts[ref->lto_stmt_uid - 1];
1296 254774 : ref->lto_stmt_uid = 0;
1297 254774 : if (!ref->stmt)
1298 0 : fatal_error (input_location, "Reference statement index not found");
1299 : }
1300 112212 : }
1301 :
1302 :
1303 : /* Fixup call_stmt pointers in NODE and all clones. */
1304 :
1305 : static void
1306 85823 : fixup_call_stmt_edges (struct cgraph_node *orig, gimple **stmts)
1307 : {
1308 85823 : struct cgraph_node *node;
1309 85823 : struct function *fn;
1310 :
1311 86051 : while (orig->clone_of)
1312 : orig = orig->clone_of;
1313 85823 : fn = DECL_STRUCT_FUNCTION (orig->decl);
1314 :
1315 85823 : if (!orig->thunk)
1316 85823 : fixup_call_stmt_edges_1 (orig, stmts, fn);
1317 85823 : if (orig->clones)
1318 31442 : for (node = orig->clones; node != orig;)
1319 : {
1320 26391 : if (!node->thunk)
1321 26389 : fixup_call_stmt_edges_1 (node, stmts, fn);
1322 26391 : if (node->clones)
1323 : node = node->clones;
1324 23866 : else if (node->next_sibling_clone)
1325 : node = node->next_sibling_clone;
1326 : else
1327 : {
1328 13283 : while (node != orig && !node->next_sibling_clone)
1329 7576 : node = node->clone_of;
1330 5707 : if (node != orig)
1331 656 : node = node->next_sibling_clone;
1332 : }
1333 : }
1334 85823 : }
1335 :
1336 :
1337 : /* Input the base body of struct function FN from DATA_IN
1338 : using input block IB. */
1339 :
1340 : static void
1341 85823 : input_struct_function_base (struct function *fn, class data_in *data_in,
1342 : class lto_input_block *ib)
1343 : {
1344 85823 : struct bitpack_d bp;
1345 85823 : int len;
1346 :
1347 : /* Read the static chain and non-local goto save area. */
1348 85823 : fn->static_chain_decl = stream_read_tree (ib, data_in);
1349 85823 : fn->nonlocal_goto_save_area = stream_read_tree (ib, data_in);
1350 :
1351 : /* Read all the local symbols. */
1352 85823 : len = streamer_read_hwi (ib);
1353 85823 : if (len > 0)
1354 : {
1355 23169 : int i;
1356 23169 : vec_safe_grow_cleared (fn->local_decls, len, true);
1357 187512 : for (i = 0; i < len; i++)
1358 : {
1359 141174 : tree t = stream_read_tree (ib, data_in);
1360 141174 : (*fn->local_decls)[i] = t;
1361 : }
1362 : }
1363 :
1364 : /* Input the current IL state of the function. */
1365 85823 : fn->curr_properties = streamer_read_uhwi (ib);
1366 :
1367 : /* Read all the attributes for FN. */
1368 85823 : bp = streamer_read_bitpack (ib);
1369 85823 : fn->is_thunk = bp_unpack_value (&bp, 1);
1370 85823 : fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
1371 85823 : fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
1372 85823 : fn->returns_struct = bp_unpack_value (&bp, 1);
1373 85823 : fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
1374 85823 : fn->can_delete_dead_exceptions = bp_unpack_value (&bp, 1);
1375 85823 : fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
1376 85823 : fn->after_inlining = bp_unpack_value (&bp, 1);
1377 85823 : fn->stdarg = bp_unpack_value (&bp, 1);
1378 85823 : fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
1379 85823 : fn->has_forced_label_in_static = bp_unpack_value (&bp, 1);
1380 85823 : fn->calls_alloca = bp_unpack_value (&bp, 1);
1381 85823 : fn->calls_setjmp = bp_unpack_value (&bp, 1);
1382 85823 : fn->calls_eh_return = bp_unpack_value (&bp, 1);
1383 85823 : fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1);
1384 85823 : fn->has_simduid_loops = bp_unpack_value (&bp, 1);
1385 85823 : fn->has_musttail = bp_unpack_value (&bp, 1);
1386 85823 : fn->has_unroll = bp_unpack_value (&bp, 1);
1387 85823 : fn->assume_function = bp_unpack_value (&bp, 1);
1388 85823 : fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
1389 85823 : fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
1390 85823 : fn->last_clique = bp_unpack_value (&bp, sizeof (short) * 8);
1391 :
1392 : /* Input the function start and end loci. */
1393 85823 : stream_input_location (&fn->function_start_locus, &bp, data_in);
1394 85823 : stream_input_location (&fn->function_end_locus, &bp, data_in);
1395 :
1396 : /* Restore the instance discriminators if present. */
1397 85823 : int instance_number = bp_unpack_value (&bp, 1);
1398 85823 : if (instance_number)
1399 : {
1400 0 : instance_number = bp_unpack_value (&bp, sizeof (int) * CHAR_BIT);
1401 0 : maybe_create_decl_to_instance_map ()->put (fn->decl, instance_number);
1402 : }
1403 85823 : }
1404 :
1405 : /* Read a chain of tree nodes from input block IB. DATA_IN contains
1406 : tables and descriptors for the file being read. */
1407 :
1408 : static tree
1409 85898 : streamer_read_chain (class lto_input_block *ib, class data_in *data_in)
1410 : {
1411 85898 : tree first, prev, curr;
1412 :
1413 : /* The chain is written as NULL terminated list of trees. */
1414 85898 : first = prev = NULL_TREE;
1415 177243 : do
1416 : {
1417 177243 : curr = stream_read_tree (ib, data_in);
1418 177243 : if (prev)
1419 91345 : TREE_CHAIN (prev) = curr;
1420 : else
1421 : first = curr;
1422 :
1423 177243 : prev = curr;
1424 : }
1425 177243 : while (curr);
1426 :
1427 85898 : return first;
1428 : }
1429 :
1430 : /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1431 :
1432 : static void
1433 85898 : input_function (tree fn_decl, class data_in *data_in,
1434 : class lto_input_block *ib, class lto_input_block *ib_cfg,
1435 : cgraph_node *node)
1436 : {
1437 85898 : struct function *fn;
1438 85898 : enum LTO_tags tag;
1439 85898 : gimple **stmts;
1440 85898 : basic_block bb;
1441 :
1442 85898 : tag = streamer_read_record_start (ib);
1443 85898 : lto_tag_check (tag, LTO_function);
1444 :
1445 : /* Read decls for parameters and args. */
1446 85898 : DECL_RESULT (fn_decl) = stream_read_tree (ib, data_in);
1447 85898 : DECL_ARGUMENTS (fn_decl) = streamer_read_chain (ib, data_in);
1448 :
1449 : /* Read debug args if available. */
1450 85898 : unsigned n_debugargs = streamer_read_uhwi (ib);
1451 85898 : if (n_debugargs)
1452 : {
1453 23 : vec<tree, va_gc> **debugargs = decl_debug_args_insert (fn_decl);
1454 23 : vec_safe_grow (*debugargs, n_debugargs, true);
1455 108 : for (unsigned i = 0; i < n_debugargs; ++i)
1456 62 : (**debugargs)[i] = stream_read_tree (ib, data_in);
1457 : }
1458 :
1459 : /* Read the tree of lexical scopes for the function. */
1460 85898 : DECL_INITIAL (fn_decl) = stream_read_tree (ib, data_in);
1461 85898 : unsigned block_leaf_count = streamer_read_uhwi (ib);
1462 149014 : while (block_leaf_count--)
1463 63116 : stream_read_tree (ib, data_in);
1464 :
1465 85898 : if (!streamer_read_uhwi (ib))
1466 : return;
1467 :
1468 85823 : push_struct_function (fn_decl);
1469 85823 : fn = DECL_STRUCT_FUNCTION (fn_decl);
1470 :
1471 85823 : gimple_register_cfg_hooks ();
1472 :
1473 85823 : input_struct_function_base (fn, data_in, ib);
1474 85823 : input_cfg (ib_cfg, data_in, fn);
1475 :
1476 : /* Read all the SSA names. */
1477 85823 : input_ssa_names (ib, data_in, fn);
1478 :
1479 : /* Read the exception handling regions in the function. */
1480 85823 : input_eh_regions (ib, data_in, fn);
1481 :
1482 85823 : gcc_assert (DECL_INITIAL (fn_decl));
1483 85823 : DECL_SAVED_TREE (fn_decl) = NULL_TREE;
1484 :
1485 : /* Read all the basic blocks. */
1486 85823 : tag = streamer_read_record_start (ib);
1487 847858 : while (tag)
1488 : {
1489 762035 : input_bb (ib, tag, data_in, fn,
1490 : node->count_materialization_scale);
1491 762035 : tag = streamer_read_record_start (ib);
1492 : }
1493 :
1494 : /* Finalize gimple_location/gimple_block of stmts and phis. */
1495 85823 : data_in->location_cache.apply_location_cache ();
1496 :
1497 : /* Fix up the call statements that are mentioned in the callgraph
1498 : edges. */
1499 85823 : set_gimple_stmt_max_uid (cfun, 0);
1500 847858 : FOR_ALL_BB_FN (bb, cfun)
1501 : {
1502 762035 : gimple_stmt_iterator gsi;
1503 833653 : for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1504 : {
1505 71618 : gimple *stmt = gsi_stmt (gsi);
1506 71618 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1507 : }
1508 2970205 : for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1509 : {
1510 1446135 : gimple *stmt = gsi_stmt (gsi);
1511 1446135 : gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1512 : }
1513 : }
1514 85823 : stmts = (gimple **) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple *));
1515 847858 : FOR_ALL_BB_FN (bb, cfun)
1516 : {
1517 762035 : gimple_stmt_iterator bsi = gsi_start_phis (bb);
1518 833653 : while (!gsi_end_p (bsi))
1519 : {
1520 71618 : gimple *stmt = gsi_stmt (bsi);
1521 71618 : gsi_next (&bsi);
1522 71618 : stmts[gimple_uid (stmt)] = stmt;
1523 : }
1524 762035 : bsi = gsi_start_bb (bb);
1525 2208170 : while (!gsi_end_p (bsi))
1526 : {
1527 1446135 : gimple *stmt = gsi_stmt (bsi);
1528 1446135 : bool remove = false;
1529 : /* If we're recompiling LTO objects with debug stmts but
1530 : we're not supposed to have debug stmts, remove them now.
1531 : We can't remove them earlier because this would cause uid
1532 : mismatches in fixups, but we can do it at this point, as
1533 : long as debug stmts don't require fixups.
1534 : Similarly remove all IFN_*SAN_* internal calls */
1535 1446135 : if (!flag_wpa)
1536 : {
1537 1353391 : if (is_gimple_debug (stmt)
1538 1353391 : && (gimple_debug_nonbind_marker_p (stmt)
1539 8160 : ? !MAY_HAVE_DEBUG_MARKER_STMTS
1540 6035 : : !MAY_HAVE_DEBUG_BIND_STMTS))
1541 : remove = true;
1542 : /* In case the linemap overflows locations can be dropped
1543 : to zero. Thus do not keep nonsensical inline entry markers
1544 : we'd later ICE on. */
1545 1353391 : tree block;
1546 1353391 : if (gimple_debug_inline_entry_p (stmt)
1547 14195 : && (((block = gimple_block (stmt))
1548 990 : && !inlined_function_outer_scope_p (block))
1549 990 : || !debug_inline_points))
1550 : remove = true;
1551 1353391 : if (is_gimple_call (stmt)
1552 1353391 : && gimple_call_internal_p (stmt))
1553 : {
1554 21611 : bool replace = false;
1555 21611 : switch (gimple_call_internal_fn (stmt))
1556 : {
1557 252 : case IFN_UBSAN_NULL:
1558 252 : if ((flag_sanitize
1559 252 : & (SANITIZE_NULL | SANITIZE_ALIGNMENT)) == 0)
1560 : replace = true;
1561 : break;
1562 235 : case IFN_UBSAN_BOUNDS:
1563 235 : if ((flag_sanitize & SANITIZE_BOUNDS) == 0)
1564 : replace = true;
1565 : break;
1566 0 : case IFN_UBSAN_VPTR:
1567 0 : if ((flag_sanitize & SANITIZE_VPTR) == 0)
1568 : replace = true;
1569 : break;
1570 178 : case IFN_UBSAN_OBJECT_SIZE:
1571 178 : if ((flag_sanitize & SANITIZE_OBJECT_SIZE) == 0)
1572 : replace = true;
1573 : break;
1574 166 : case IFN_UBSAN_PTR:
1575 166 : if ((flag_sanitize & SANITIZE_POINTER_OVERFLOW) == 0)
1576 : replace = true;
1577 : break;
1578 934 : case IFN_ASAN_MARK:
1579 934 : if ((flag_sanitize & SANITIZE_ADDRESS) == 0)
1580 : replace = true;
1581 : break;
1582 0 : case IFN_TSAN_FUNC_EXIT:
1583 0 : if ((flag_sanitize & SANITIZE_THREAD) == 0)
1584 : replace = true;
1585 : break;
1586 : default:
1587 : break;
1588 : }
1589 : if (replace)
1590 : {
1591 2 : gimple_call_set_internal_fn (as_a <gcall *> (stmt),
1592 : IFN_NOP);
1593 2 : update_stmt (stmt);
1594 : }
1595 : }
1596 : }
1597 1353391 : if (remove)
1598 : {
1599 4 : gimple_stmt_iterator gsi = bsi;
1600 4 : gsi_next (&bsi);
1601 4 : unlink_stmt_vdef (stmt);
1602 4 : release_defs (stmt);
1603 4 : gsi_remove (&gsi, true);
1604 : }
1605 : else
1606 : {
1607 1446131 : gsi_next (&bsi);
1608 1446131 : stmts[gimple_uid (stmt)] = stmt;
1609 :
1610 : /* Remember that the input function has begin stmt
1611 : markers, so that we know to expect them when emitting
1612 : debug info. */
1613 1446131 : if (!cfun->debug_nonbind_markers
1614 2868906 : && gimple_debug_nonbind_marker_p (stmt))
1615 1375 : cfun->debug_nonbind_markers = true;
1616 : }
1617 : }
1618 : }
1619 :
1620 : /* Set the gimple body to the statement sequence in the entry
1621 : basic block. FIXME lto, this is fairly hacky. The existence
1622 : of a gimple body is used by the cgraph routines, but we should
1623 : really use the presence of the CFG. */
1624 85823 : {
1625 85823 : edge_iterator ei = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
1626 171646 : gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
1627 : }
1628 :
1629 85823 : update_max_bb_count ();
1630 85823 : fixup_call_stmt_edges (node, stmts);
1631 85823 : execute_all_ipa_stmt_fixups (node, stmts);
1632 :
1633 85823 : free_dominance_info (CDI_DOMINATORS);
1634 85823 : free_dominance_info (CDI_POST_DOMINATORS);
1635 85823 : free (stmts);
1636 85823 : pop_cfun ();
1637 : }
1638 :
1639 : /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1640 :
1641 : static void
1642 7945 : input_constructor (tree var, class data_in *data_in,
1643 : class lto_input_block *ib)
1644 : {
1645 7945 : DECL_INITIAL (var) = stream_read_tree (ib, data_in);
1646 7945 : }
1647 :
1648 :
1649 : /* Read the body from DATA for function NODE and fill it in.
1650 : FILE_DATA are the global decls and types. SECTION_TYPE is either
1651 : LTO_section_function_body or LTO_section_static_initializer. If
1652 : section type is LTO_section_function_body, FN must be the decl for
1653 : that function. */
1654 :
1655 : static void
1656 93843 : lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symtab_node *node,
1657 : const char *data, enum lto_section_type section_type)
1658 : {
1659 93843 : const struct lto_function_header *header;
1660 93843 : class data_in *data_in;
1661 93843 : int cfg_offset;
1662 93843 : int main_offset;
1663 93843 : int string_offset;
1664 93843 : tree fn_decl = node->decl;
1665 :
1666 93843 : header = (const struct lto_function_header *) data;
1667 93843 : if (TREE_CODE (node->decl) == FUNCTION_DECL)
1668 : {
1669 85898 : cfg_offset = sizeof (struct lto_function_header);
1670 85898 : main_offset = cfg_offset + header->cfg_size;
1671 85898 : string_offset = main_offset + header->main_size;
1672 : }
1673 : else
1674 : {
1675 7945 : main_offset = sizeof (struct lto_function_header);
1676 7945 : string_offset = main_offset + header->main_size;
1677 : }
1678 :
1679 93843 : data_in = lto_data_in_create (file_data, data + string_offset,
1680 93843 : header->string_size, vNULL);
1681 :
1682 93843 : if (section_type == LTO_section_function_body)
1683 : {
1684 93843 : struct lto_in_decl_state *decl_state;
1685 93843 : unsigned from;
1686 :
1687 93843 : gcc_checking_assert (node);
1688 :
1689 : /* Use the function's decl state. */
1690 93843 : decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
1691 93843 : gcc_assert (decl_state);
1692 93843 : file_data->current_decl_state = decl_state;
1693 93843 : data_in->location_cache.set_linemap_offset (decl_state->linemap_id);
1694 :
1695 : /* Set up the struct function. */
1696 93843 : from = data_in->reader_cache->nodes.length ();
1697 93843 : lto_input_block ib_main (data + main_offset, header->main_size,
1698 93843 : file_data);
1699 93843 : if (TREE_CODE (node->decl) == FUNCTION_DECL)
1700 : {
1701 85898 : lto_input_block ib_cfg (data + cfg_offset, header->cfg_size,
1702 85898 : file_data);
1703 85898 : input_function (fn_decl, data_in, &ib_main, &ib_cfg,
1704 : dyn_cast <cgraph_node *>(node));
1705 : }
1706 : else
1707 7945 : input_constructor (fn_decl, data_in, &ib_main);
1708 93843 : data_in->location_cache.apply_location_cache ();
1709 : /* And fixup types we streamed locally. */
1710 93843 : {
1711 93843 : struct streamer_tree_cache_d *cache = data_in->reader_cache;
1712 93843 : unsigned len = cache->nodes.length ();
1713 93843 : unsigned i;
1714 3008932 : for (i = len; i-- > from;)
1715 : {
1716 2915089 : tree t = streamer_tree_cache_get_tree (cache, i);
1717 2915089 : if (t == NULL_TREE)
1718 0 : continue;
1719 :
1720 2915089 : if (TYPE_P (t))
1721 : {
1722 1734 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
1723 1734 : if (type_with_alias_set_p (t)
1724 1734 : && canonical_type_used_p (t))
1725 570 : TYPE_CANONICAL (t) = TYPE_MAIN_VARIANT (t);
1726 1734 : if (TYPE_MAIN_VARIANT (t) != t)
1727 : {
1728 129 : gcc_assert (TYPE_NEXT_VARIANT (t) == NULL_TREE);
1729 258 : TYPE_NEXT_VARIANT (t)
1730 129 : = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t));
1731 129 : TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t)) = t;
1732 : }
1733 : }
1734 : }
1735 : }
1736 :
1737 : /* Restore decl state */
1738 93843 : file_data->current_decl_state = file_data->global_decl_state;
1739 : }
1740 :
1741 93843 : lto_data_in_delete (data_in);
1742 93843 : }
1743 :
1744 :
1745 : /* Read the body of NODE using DATA. FILE_DATA holds the global
1746 : decls and types. */
1747 :
1748 : void
1749 85898 : lto_input_function_body (struct lto_file_decl_data *file_data,
1750 : struct cgraph_node *node, const char *data)
1751 : {
1752 85898 : lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
1753 85898 : }
1754 :
1755 : /* Read the body of NODE using DATA. FILE_DATA holds the global
1756 : decls and types. */
1757 :
1758 : void
1759 7945 : lto_input_variable_constructor (struct lto_file_decl_data *file_data,
1760 : struct varpool_node *node, const char *data)
1761 : {
1762 7945 : lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
1763 7945 : }
1764 :
1765 :
1766 : /* Queue of acummulated decl -> DIE mappings. Similar to locations those
1767 : are only applied to prevailing tree nodes during tree merging. */
1768 : vec<dref_entry> dref_queue;
1769 :
1770 : /* Read the physical representation of a tree node EXPR from
1771 : input block IB using the per-file context in DATA_IN. */
1772 :
1773 : static void
1774 4532642 : lto_read_tree_1 (class lto_input_block *ib, class data_in *data_in, tree expr)
1775 : {
1776 : /* Read all the bitfield values in EXPR. Note that for LTO, we
1777 : only write language-independent bitfields, so no more unpacking is
1778 : needed. */
1779 4532642 : streamer_read_tree_bitfields (ib, data_in, expr);
1780 :
1781 : /* Read all the pointer fields in EXPR. */
1782 4532642 : streamer_read_tree_body (ib, data_in, expr);
1783 :
1784 : /* Read any LTO-specific data not read by the tree streamer. Do not use
1785 : stream_read_tree here since that flushes the dref_queue in mids of
1786 : SCC reading. */
1787 4532642 : if (DECL_P (expr)
1788 762312 : && TREE_CODE (expr) != FUNCTION_DECL
1789 552057 : && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
1790 1057906 : DECL_INITIAL (expr)
1791 1057906 : = lto_input_tree_1 (ib, data_in, streamer_read_record_start (ib), 0);
1792 :
1793 : /* Stream references to early generated DIEs. Keep in sync with the
1794 : trees handled in dwarf2out_register_external_die. */
1795 4532642 : if ((DECL_P (expr)
1796 : && TREE_CODE (expr) != FIELD_DECL
1797 : && TREE_CODE (expr) != DEBUG_EXPR_DECL
1798 : && TREE_CODE (expr) != TYPE_DECL)
1799 3869522 : || TREE_CODE (expr) == BLOCK)
1800 : {
1801 950804 : const char *str = streamer_read_string (data_in, ib);
1802 950804 : if (str)
1803 : {
1804 44467 : unsigned HOST_WIDE_INT off = streamer_read_uhwi (ib);
1805 44467 : dref_entry e = { expr, str, off };
1806 44467 : dref_queue.safe_push (e);
1807 : }
1808 : /* When there's no early DIE to refer to but dwarf2out set up
1809 : things in a way to expect that fixup. This tends to happen
1810 : with -g1, see for example PR113488. */
1811 906337 : else if (DECL_P (expr) && DECL_ABSTRACT_ORIGIN (expr) == expr)
1812 0 : DECL_ABSTRACT_ORIGIN (expr) = NULL_TREE;
1813 : }
1814 :
1815 : #ifdef ACCEL_COMPILER
1816 : if ((VAR_P (expr)
1817 : || TREE_CODE (expr) == PARM_DECL
1818 : || TREE_CODE (expr) == FIELD_DECL)
1819 : && DECL_MODE (expr) == VOIDmode)
1820 : {
1821 : tree type = TREE_TYPE (expr);
1822 : if (AGGREGATE_TYPE_P (type))
1823 : SET_DECL_MODE (expr, TYPE_MODE (type));
1824 : else if (VECTOR_TYPE_P (type))
1825 : SET_DECL_MODE (expr, TYPE_MODE_RAW (type));
1826 : }
1827 :
1828 : if (VECTOR_TYPE_P (expr) && TYPE_MODE (expr) == VOIDmode)
1829 : {
1830 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (expr);
1831 : tree innertype = TREE_TYPE (expr);
1832 : machine_mode vmode
1833 : = mode_for_vector (SCALAR_TYPE_MODE (innertype), nunits).else_blk ();
1834 : SET_TYPE_MODE (expr, vmode);
1835 : }
1836 : #endif
1837 4532642 : }
1838 :
1839 : /* Read the physical representation of a tree node with tag TAG from
1840 : input block IB using the per-file context in DATA_IN. */
1841 :
1842 : static tree
1843 4340166 : lto_read_tree (class lto_input_block *ib, class data_in *data_in,
1844 : enum LTO_tags tag, hashval_t hash)
1845 : {
1846 : /* Instantiate a new tree node. */
1847 4340166 : tree result = streamer_alloc_tree (ib, data_in, tag);
1848 :
1849 : /* Enter RESULT in the reader cache. This will make RESULT
1850 : available so that circular references in the rest of the tree
1851 : structure can be resolved in subsequent calls to stream_read_tree. */
1852 4340166 : streamer_tree_cache_append (data_in->reader_cache, result, hash);
1853 :
1854 4340166 : lto_read_tree_1 (ib, data_in, result);
1855 :
1856 4340166 : return result;
1857 : }
1858 :
1859 :
1860 : /* Populate the reader cache with trees materialized from the SCC
1861 : following in the IB, DATA_IN stream.
1862 : If SHARED_SCC is true we input LTO_tree_scc. */
1863 :
1864 : hashval_t
1865 2183496 : lto_input_scc (class lto_input_block *ib, class data_in *data_in,
1866 : unsigned *len, unsigned *entry_len, bool shared_scc)
1867 : {
1868 2183496 : unsigned size = streamer_read_uhwi (ib);
1869 2183496 : hashval_t scc_hash = 0;
1870 2183496 : unsigned scc_entry_len = 1;
1871 :
1872 2183496 : if (shared_scc)
1873 : {
1874 773997 : if (size & 1)
1875 0 : scc_entry_len = streamer_read_uhwi (ib);
1876 773997 : size /= 2;
1877 773997 : scc_hash = streamer_read_uhwi (ib);
1878 : }
1879 :
1880 2183496 : if (size == 1)
1881 : {
1882 2134811 : enum LTO_tags tag = streamer_read_record_start (ib);
1883 2134811 : lto_input_tree_1 (ib, data_in, tag, scc_hash);
1884 : }
1885 : else
1886 : {
1887 48685 : unsigned int first = data_in->reader_cache->nodes.length ();
1888 48685 : tree result;
1889 :
1890 : /* Materialize size trees by reading their headers. */
1891 241161 : for (unsigned i = 0; i < size; ++i)
1892 : {
1893 192476 : enum LTO_tags tag = streamer_read_record_start (ib);
1894 192476 : if (tag == LTO_null
1895 192476 : || tag == LTO_global_stream_ref
1896 192476 : || tag == LTO_tree_pickle_reference
1897 192476 : || tag == LTO_integer_cst
1898 : || tag == LTO_tree_scc
1899 192476 : || tag == LTO_trees)
1900 0 : gcc_unreachable ();
1901 :
1902 192476 : result = streamer_alloc_tree (ib, data_in, tag);
1903 192476 : streamer_tree_cache_append (data_in->reader_cache, result, 0);
1904 : }
1905 :
1906 : /* Read the tree bitpacks and references. */
1907 241161 : for (unsigned i = 0; i < size; ++i)
1908 : {
1909 192476 : result = streamer_tree_cache_get_tree (data_in->reader_cache,
1910 : first + i);
1911 192476 : lto_read_tree_1 (ib, data_in, result);
1912 : }
1913 : }
1914 :
1915 2183496 : *len = size;
1916 2183496 : *entry_len = scc_entry_len;
1917 2183496 : return scc_hash;
1918 : }
1919 :
1920 : /* Read reference to tree from IB and DATA_IN.
1921 : This is used for streaming tree bodies where we know that
1922 : the tree is already in cache or is indexable and
1923 : must be matched with stream_write_tree_ref. */
1924 :
1925 : tree
1926 20380352 : stream_read_tree_ref (lto_input_block *ib, data_in *data_in)
1927 : {
1928 20380352 : int ix = streamer_read_hwi (ib);
1929 20380352 : if (!ix)
1930 : return NULL_TREE;
1931 12546403 : if (ix > 0)
1932 9528501 : return streamer_tree_cache_get_tree (data_in->reader_cache, ix - 1);
1933 :
1934 3017902 : ix = -ix - 1;
1935 3017902 : int id = ix & 1;
1936 3017902 : ix /= 2;
1937 :
1938 3017902 : tree ret;
1939 3017902 : if (!id)
1940 2853786 : ret = (*data_in->file_data->current_decl_state
1941 2853786 : ->streams[LTO_DECL_STREAM])[ix];
1942 : else
1943 164116 : ret = (*SSANAMES (cfun))[ix];
1944 : return ret;
1945 : }
1946 :
1947 : /* Read a tree from input block IB using the per-file context in
1948 : DATA_IN. This context is used, for example, to resolve references
1949 : to previously read nodes. */
1950 :
1951 : tree
1952 13042607 : lto_input_tree_1 (class lto_input_block *ib, class data_in *data_in,
1953 : enum LTO_tags tag, hashval_t hash)
1954 : {
1955 13042607 : tree result;
1956 :
1957 13042607 : gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
1958 :
1959 13042607 : if (tag == LTO_null)
1960 : result = NULL_TREE;
1961 : else if (tag == LTO_global_stream_ref || tag == LTO_ssa_name_ref)
1962 : {
1963 : /* If TAG is a reference to an indexable tree, the next value
1964 : in IB is the index into the table where we expect to find
1965 : that tree. */
1966 4145404 : result = lto_input_tree_ref (ib, data_in, cfun, tag);
1967 : }
1968 : else if (tag == LTO_tree_pickle_reference)
1969 : {
1970 : /* If TAG is a reference to a previously read tree, look it up in
1971 : the reader cache. */
1972 1614850 : result = streamer_get_pickled_tree (ib, data_in);
1973 : }
1974 : else if (tag == LTO_integer_cst)
1975 : {
1976 : /* For shared integer constants in singletons we can use the
1977 : existing tree integer constant merging code. */
1978 720422 : tree type = stream_read_tree_ref (ib, data_in);
1979 720422 : unsigned HOST_WIDE_INT len = streamer_read_uhwi (ib);
1980 720422 : unsigned HOST_WIDE_INT i;
1981 720422 : HOST_WIDE_INT abuf[WIDE_INT_MAX_INL_ELTS], *a = abuf;
1982 :
1983 720422 : if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
1984 8 : a = XALLOCAVEC (HOST_WIDE_INT, len);
1985 1446506 : for (i = 0; i < len; i++)
1986 726084 : a[i] = streamer_read_hwi (ib);
1987 720422 : gcc_assert (TYPE_PRECISION (type) <= WIDE_INT_MAX_PRECISION);
1988 720422 : result
1989 720422 : = wide_int_to_tree (type,
1990 720422 : wide_int::from_array (a, len,
1991 720422 : TYPE_PRECISION (type)));
1992 720422 : streamer_tree_cache_append (data_in->reader_cache, result, hash);
1993 : }
1994 : else if (tag == LTO_tree_scc || tag == LTO_trees)
1995 0 : gcc_unreachable ();
1996 : else
1997 : {
1998 : /* Otherwise, materialize a new node from IB. */
1999 4340166 : result = lto_read_tree (ib, data_in, tag, hash);
2000 : }
2001 :
2002 13042607 : return result;
2003 : }
2004 :
2005 : tree
2006 9104099 : lto_input_tree (class lto_input_block *ib, class data_in *data_in)
2007 : {
2008 9104099 : enum LTO_tags tag;
2009 :
2010 : /* Input pickled trees needed to stream in the reference. */
2011 10497848 : while ((tag = streamer_read_record_start (ib)) == LTO_trees)
2012 : {
2013 1393749 : unsigned len, entry_len;
2014 1393749 : lto_input_scc (ib, data_in, &len, &entry_len, false);
2015 :
2016 : /* Register DECLs with the debuginfo machinery. */
2017 2909031 : while (!dref_queue.is_empty ())
2018 : {
2019 10947 : dref_entry e = dref_queue.pop ();
2020 10947 : debug_hooks->register_external_die (e.decl, e.sym, e.off);
2021 : }
2022 : }
2023 9104099 : tree t = lto_input_tree_1 (ib, data_in, tag, 0);
2024 :
2025 9104099 : if (!dref_queue.is_empty ())
2026 : {
2027 9429 : dref_entry e = dref_queue.pop ();
2028 9429 : debug_hooks->register_external_die (e.decl, e.sym, e.off);
2029 9429 : gcc_checking_assert (dref_queue.is_empty ());
2030 : }
2031 9104099 : return t;
2032 : }
2033 :
2034 :
2035 : /* Input toplevel asms. */
2036 :
2037 : void
2038 22434 : lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base)
2039 : {
2040 22434 : size_t len;
2041 22434 : const char *data
2042 22434 : = lto_get_summary_section_data (file_data, LTO_section_asm, &len);
2043 22434 : const struct lto_simple_header_with_strings *header
2044 : = (const struct lto_simple_header_with_strings *) data;
2045 22434 : int string_offset;
2046 22434 : class data_in *data_in;
2047 :
2048 22434 : if (! data)
2049 22323 : return;
2050 :
2051 111 : string_offset = sizeof (*header) + header->main_size;
2052 :
2053 111 : lto_input_block ib (data + sizeof (*header), header->main_size,
2054 111 : file_data);
2055 :
2056 111 : data_in = lto_data_in_create (file_data, data + string_offset,
2057 111 : header->string_size, vNULL);
2058 :
2059 111 : unsigned asm_count = streamer_read_uhwi (&ib);
2060 263 : for (unsigned i = 0; i < asm_count; i++)
2061 : {
2062 152 : tree str = stream_read_tree (&ib, data_in);
2063 152 : asm_node *node = symtab->finalize_toplevel_asm (str);
2064 152 : node->order = streamer_read_hwi (&ib) + order_base;
2065 152 : node->lto_file_data = file_data;
2066 152 : if (node->order >= symtab->order)
2067 0 : symtab->order = node->order + 1;
2068 : }
2069 :
2070 111 : lto_data_in_delete (data_in);
2071 :
2072 111 : lto_free_section_data (file_data, LTO_section_asm, NULL, data, len);
2073 : }
2074 :
2075 :
2076 : /* Input mode table. */
2077 :
2078 : void
2079 0 : lto_input_mode_table (struct lto_file_decl_data *file_data)
2080 : {
2081 0 : size_t len;
2082 0 : const char *data
2083 0 : = lto_get_summary_section_data (file_data, LTO_section_mode_table, &len);
2084 0 : if (! data)
2085 0 : internal_error ("cannot read LTO mode table from %s",
2086 : file_data->file_name);
2087 :
2088 0 : const struct lto_simple_header_with_strings *header
2089 : = (const struct lto_simple_header_with_strings *) data;
2090 0 : int string_offset;
2091 0 : class data_in *data_in;
2092 0 : string_offset = sizeof (*header) + header->main_size;
2093 :
2094 0 : lto_input_block ib (data + sizeof (*header), header->main_size, NULL);
2095 0 : data_in = lto_data_in_create (file_data, data + string_offset,
2096 0 : header->string_size, vNULL);
2097 0 : bitpack_d bp = streamer_read_bitpack (&ib);
2098 :
2099 : #ifdef ACCEL_COMPILER
2100 : host_num_poly_int_coeffs
2101 : = bp_unpack_value (&bp, MAX_NUM_POLY_INT_COEFFS_BITS);
2102 : #endif
2103 :
2104 0 : unsigned mode_bits = bp_unpack_value (&bp, 5);
2105 0 : unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << mode_bits);
2106 :
2107 0 : file_data->mode_table = table;
2108 0 : file_data->mode_bits = mode_bits;
2109 :
2110 0 : table[VOIDmode] = VOIDmode;
2111 0 : table[BLKmode] = BLKmode;
2112 0 : unsigned int m;
2113 0 : while ((m = bp_unpack_value (&bp, mode_bits)) != VOIDmode)
2114 : {
2115 0 : enum mode_class mclass
2116 0 : = bp_unpack_enum (&bp, mode_class, MAX_MODE_CLASS);
2117 0 : poly_uint16 size = bp_unpack_poly_value (&bp, 16);
2118 0 : poly_uint16 prec = bp_unpack_poly_value (&bp, 16);
2119 0 : machine_mode inner = (machine_mode) bp_unpack_value (&bp, mode_bits);
2120 0 : poly_uint16 nunits = bp_unpack_poly_value (&bp, 16);
2121 0 : unsigned int ibit = 0, fbit = 0;
2122 0 : unsigned int real_fmt_len = 0;
2123 0 : const char *real_fmt_name = NULL;
2124 0 : switch (mclass)
2125 : {
2126 0 : case MODE_FRACT:
2127 0 : case MODE_UFRACT:
2128 0 : case MODE_ACCUM:
2129 0 : case MODE_UACCUM:
2130 0 : ibit = bp_unpack_value (&bp, 8);
2131 0 : fbit = bp_unpack_value (&bp, 8);
2132 0 : break;
2133 0 : case MODE_FLOAT:
2134 0 : case MODE_DECIMAL_FLOAT:
2135 0 : real_fmt_name = bp_unpack_indexed_string (data_in, &bp,
2136 : &real_fmt_len);
2137 0 : break;
2138 : default:
2139 : break;
2140 : }
2141 : /* First search just the GET_CLASS_NARROWEST_MODE to wider modes,
2142 : if not found, fallback to all modes. When found, pass is 3 (2 + 1),
2143 : when not found, pass is 2 ('< 2' check + 1). */
2144 0 : int pass;
2145 0 : for (pass = 0; pass < 2; pass++)
2146 0 : for (machine_mode mr = pass ? VOIDmode
2147 0 : : GET_CLASS_NARROWEST_MODE (mclass);
2148 0 : pass ? mr < MAX_MACHINE_MODE : mr != VOIDmode;
2149 0 : pass ? mr = (machine_mode) (mr + 1)
2150 0 : : mr = GET_MODE_WIDER_MODE (mr).else_void ())
2151 0 : if (GET_MODE_CLASS (mr) != mclass
2152 0 : || maybe_ne (GET_MODE_SIZE (mr), size)
2153 0 : || maybe_ne (GET_MODE_PRECISION (mr), prec)
2154 0 : || (inner == m
2155 0 : ? GET_MODE_INNER (mr) != mr
2156 0 : : GET_MODE_INNER (mr) != table[(int) inner])
2157 0 : || GET_MODE_IBIT (mr) != ibit
2158 0 : || GET_MODE_FBIT (mr) != fbit
2159 0 : || maybe_ne (GET_MODE_NUNITS (mr), nunits))
2160 0 : continue;
2161 0 : else if ((mclass == MODE_FLOAT || mclass == MODE_DECIMAL_FLOAT)
2162 0 : && strcmp (REAL_MODE_FORMAT (mr)->name, real_fmt_name) != 0)
2163 0 : continue;
2164 : else
2165 : {
2166 : /* Found. */
2167 0 : table[m] = mr;
2168 0 : pass = 2; /* Will be 3 after the outer loop. */
2169 : #ifdef ACCEL_COMPILER
2170 : /* A mode used by the host code - and generally supported by the
2171 : offloading-target compiler might not actually be available,
2172 : depending e.g. on -march or other other commandline options.
2173 : Hence, check again and, if failing, diagnose it below. */
2174 : if (scalar_mode::includes_p (mr)
2175 : && !targetm.scalar_mode_supported_p (
2176 : scalar_mode::from_int (mr)))
2177 : pass = 1; /* Such that pass == 2 after the outer loop. */
2178 : #endif
2179 0 : break;
2180 : }
2181 0 : unsigned int mname_len;
2182 0 : const char *mname = bp_unpack_indexed_string (data_in, &bp, &mname_len);
2183 0 : if (pass == 2)
2184 : {
2185 0 : switch (mclass)
2186 : {
2187 0 : case MODE_VECTOR_BOOL:
2188 0 : case MODE_VECTOR_INT:
2189 0 : case MODE_VECTOR_FLOAT:
2190 0 : case MODE_VECTOR_FRACT:
2191 0 : case MODE_VECTOR_UFRACT:
2192 0 : case MODE_VECTOR_ACCUM:
2193 0 : case MODE_VECTOR_UACCUM:
2194 : /* Vector modes are recomputed on accel side and shouldn't have
2195 : been streamed-out from host. */
2196 0 : gcc_unreachable ();
2197 : /* FALLTHRU */
2198 0 : default:
2199 : /* This is only used for offloading-target compilations and
2200 : is a user-facing error. Give a better error message for
2201 : the common modes; see also mode-classes.def. */
2202 0 : if (mclass == MODE_FLOAT)
2203 0 : fatal_error (UNKNOWN_LOCATION,
2204 : "%s - %u-bit-precision floating-point numbers "
2205 : "unsupported (mode %qs)", TARGET_MACHINE,
2206 0 : prec.to_constant (), mname);
2207 0 : else if (mclass == MODE_DECIMAL_FLOAT)
2208 0 : fatal_error (UNKNOWN_LOCATION,
2209 : "%s - %u-bit-precision decimal floating-point "
2210 : "numbers unsupported (mode %qs)", TARGET_MACHINE,
2211 0 : prec.to_constant (), mname);
2212 0 : else if (mclass == MODE_COMPLEX_FLOAT)
2213 0 : fatal_error (UNKNOWN_LOCATION,
2214 : "%s - %u-bit-precision complex floating-point "
2215 : "numbers unsupported (mode %qs)", TARGET_MACHINE,
2216 0 : prec.to_constant (), mname);
2217 0 : else if (mclass == MODE_INT)
2218 0 : fatal_error (UNKNOWN_LOCATION,
2219 : "%s - %u-bit integer numbers unsupported (mode "
2220 0 : "%qs)", TARGET_MACHINE, prec.to_constant (), mname);
2221 : else
2222 0 : fatal_error (UNKNOWN_LOCATION, "%s - unsupported mode %qs",
2223 : TARGET_MACHINE, mname);
2224 0 : break;
2225 : }
2226 : }
2227 : }
2228 0 : lto_data_in_delete (data_in);
2229 :
2230 0 : lto_free_section_data (file_data, LTO_section_mode_table, NULL, data, len);
2231 0 : }
2232 :
2233 :
2234 : /* Initialization for the LTO reader. */
2235 :
2236 : void
2237 21320 : lto_reader_init (void)
2238 : {
2239 21320 : lto_streamer_init ();
2240 21320 : file_name_hash_table
2241 21320 : = new hash_table<string_slot_hasher> (37);
2242 42640 : string_slot_allocator = new object_allocator <struct string_slot>
2243 21320 : ("line map file name hash");
2244 21320 : gcc_obstack_init (&file_name_obstack);
2245 21320 : }
2246 :
2247 : /* Free hash table used to stream in location file names. */
2248 :
2249 : void
2250 8147 : lto_free_file_name_hash (void)
2251 : {
2252 8147 : delete file_name_hash_table;
2253 8147 : file_name_hash_table = NULL;
2254 16294 : delete string_slot_allocator;
2255 8147 : string_slot_allocator = NULL;
2256 8147 : delete path_name_pair_hash_table;
2257 8147 : path_name_pair_hash_table = NULL;
2258 8147 : delete string_pair_map_allocator;
2259 8147 : string_pair_map_allocator = NULL;
2260 : /* file_name_obstack must stay allocated since it is referred to by
2261 : line map table. */
2262 8147 : }
2263 :
2264 :
2265 : /* Create a new data_in object for FILE_DATA. STRINGS is the string
2266 : table to use with LEN strings. RESOLUTIONS is the vector of linker
2267 : resolutions (NULL if not using a linker plugin). */
2268 :
2269 : class data_in *
2270 229727 : lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
2271 : unsigned len,
2272 : vec<ld_plugin_symbol_resolution_t> resolutions,
2273 : bool need_location_cache)
2274 : {
2275 229727 : const auto d = new data_in{need_location_cache ? file_data : nullptr};
2276 229727 : d->file_data = file_data;
2277 229727 : d->strings = strings;
2278 229727 : d->strings_len = len;
2279 229727 : d->globals_resolution = resolutions;
2280 229727 : d->reader_cache = streamer_tree_cache_create (false, false, true);
2281 229727 : return d;
2282 : }
2283 :
2284 :
2285 : /* Remove DATA_IN. */
2286 :
2287 : void
2288 229727 : lto_data_in_delete (class data_in *data_in)
2289 : {
2290 229727 : data_in->globals_resolution.release ();
2291 229727 : streamer_tree_cache_delete (data_in->reader_cache);
2292 229727 : delete data_in;
2293 229727 : }
|