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