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