]>
Commit | Line | Data |
---|---|---|
7bfefa9d | 1 | /* Read the GIMPLE representation from a file stream. |
2 | ||
d353bf18 | 3 | Copyright (C) 2009-2015 Free Software Foundation, Inc. |
7bfefa9d | 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 "tm.h" | |
27 | #include "toplev.h" | |
b20a8bb4 | 28 | #include "alias.h" |
29 | #include "symtab.h" | |
7bfefa9d | 30 | #include "tree.h" |
b20a8bb4 | 31 | #include "fold-const.h" |
9ed99284 | 32 | #include "stringpool.h" |
d53441c8 | 33 | #include "hard-reg-set.h" |
34 | #include "function.h" | |
35 | #include "rtl.h" | |
7bfefa9d | 36 | #include "flags.h" |
d53441c8 | 37 | #include "insn-config.h" |
38 | #include "expmed.h" | |
39 | #include "dojump.h" | |
40 | #include "explow.h" | |
41 | #include "calls.h" | |
42 | #include "emit-rtl.h" | |
43 | #include "varasm.h" | |
44 | #include "stmt.h" | |
45 | #include "expr.h" | |
7bfefa9d | 46 | #include "params.h" |
94ea8568 | 47 | #include "predict.h" |
94ea8568 | 48 | #include "dominance.h" |
49 | #include "cfg.h" | |
7bfefa9d | 50 | #include "basic-block.h" |
bc61cadb | 51 | #include "tree-ssa-alias.h" |
52 | #include "internal-fn.h" | |
53 | #include "gimple-expr.h" | |
073c1fd5 | 54 | #include "gimple.h" |
dcf1a1ec | 55 | #include "gimple-iterator.h" |
073c1fd5 | 56 | #include "gimple-ssa.h" |
57 | #include "tree-cfg.h" | |
58 | #include "tree-ssanames.h" | |
59 | #include "tree-into-ssa.h" | |
60 | #include "tree-dfa.h" | |
69ee5dbb | 61 | #include "tree-ssa.h" |
7bfefa9d | 62 | #include "tree-pass.h" |
7bfefa9d | 63 | #include "diagnostic.h" |
7bfefa9d | 64 | #include "except.h" |
65 | #include "debug.h" | |
1140c305 | 66 | #include "plugin-api.h" |
67 | #include "ipa-ref.h" | |
68 | #include "cgraph.h" | |
7bfefa9d | 69 | #include "ipa-utils.h" |
2541503d | 70 | #include "data-streamer.h" |
71 | #include "gimple-streamer.h" | |
7bfefa9d | 72 | #include "lto-streamer.h" |
2541503d | 73 | #include "tree-streamer.h" |
c59bc102 | 74 | #include "streamer-hooks.h" |
7a569539 | 75 | #include "cfgloop.h" |
76 | ||
7bfefa9d | 77 | |
d9dd21a8 | 78 | struct freeing_string_slot_hasher : string_slot_hasher |
79 | { | |
80 | static inline void remove (value_type *); | |
81 | }; | |
82 | ||
83 | inline void | |
84 | freeing_string_slot_hasher::remove (value_type *v) | |
85 | { | |
86 | free (v); | |
87 | } | |
88 | ||
7bfefa9d | 89 | /* The table to hold the file names. */ |
c1f445d2 | 90 | static hash_table<freeing_string_slot_hasher> *file_name_hash_table; |
7bfefa9d | 91 | |
92 | ||
93 | /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the | |
94 | number of valid tag values to check. */ | |
95 | ||
2541503d | 96 | void |
7bfefa9d | 97 | lto_tag_check_set (enum LTO_tags actual, int ntags, ...) |
98 | { | |
99 | va_list ap; | |
100 | int i; | |
101 | ||
102 | va_start (ap, ntags); | |
103 | for (i = 0; i < ntags; i++) | |
104 | if ((unsigned) actual == va_arg (ap, unsigned)) | |
105 | { | |
106 | va_end (ap); | |
107 | return; | |
108 | } | |
109 | ||
110 | va_end (ap); | |
111 | internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual)); | |
112 | } | |
113 | ||
114 | ||
284cc480 | 115 | /* Read LENGTH bytes from STREAM to ADDR. */ |
116 | ||
117 | void | |
118 | lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length) | |
119 | { | |
120 | size_t i; | |
121 | unsigned char *const buffer = (unsigned char *const) addr; | |
122 | ||
123 | for (i = 0; i < length; i++) | |
7f385784 | 124 | buffer[i] = streamer_read_uchar (ib); |
284cc480 | 125 | } |
126 | ||
127 | ||
7bfefa9d | 128 | /* Lookup STRING in file_name_hash_table. If found, return the existing |
129 | string, otherwise insert STRING as the canonical version. */ | |
130 | ||
131 | static const char * | |
132 | canon_file_name (const char *string) | |
133 | { | |
d9dd21a8 | 134 | string_slot **slot; |
7bfefa9d | 135 | struct string_slot s_slot; |
c56fba00 | 136 | size_t len = strlen (string); |
137 | ||
7bfefa9d | 138 | s_slot.s = string; |
c56fba00 | 139 | s_slot.len = len; |
7bfefa9d | 140 | |
c1f445d2 | 141 | slot = file_name_hash_table->find_slot (&s_slot, INSERT); |
7bfefa9d | 142 | if (*slot == NULL) |
143 | { | |
7bfefa9d | 144 | char *saved_string; |
145 | struct string_slot *new_slot; | |
146 | ||
7bfefa9d | 147 | saved_string = (char *) xmalloc (len + 1); |
148 | new_slot = XCNEW (struct string_slot); | |
c56fba00 | 149 | memcpy (saved_string, string, len + 1); |
7bfefa9d | 150 | new_slot->s = saved_string; |
c56fba00 | 151 | new_slot->len = len; |
7bfefa9d | 152 | *slot = new_slot; |
153 | return saved_string; | |
154 | } | |
155 | else | |
156 | { | |
d9dd21a8 | 157 | struct string_slot *old_slot = *slot; |
7bfefa9d | 158 | return old_slot->s; |
159 | } | |
160 | } | |
161 | ||
da6f3259 | 162 | /* Pointer to currently alive instance of lto_location_cache. */ |
7bfefa9d | 163 | |
da6f3259 | 164 | lto_location_cache *lto_location_cache::current_cache; |
7bfefa9d | 165 | |
da6f3259 | 166 | /* Sort locations in source order. Start with file from last application. */ |
167 | ||
168 | int | |
169 | lto_location_cache::cmp_loc (const void *pa, const void *pb) | |
170 | { | |
171 | const cached_location *a = ((const cached_location *)pa); | |
172 | const cached_location *b = ((const cached_location *)pb); | |
173 | const char *current_file = current_cache->current_file; | |
174 | int current_line = current_cache->current_line; | |
175 | ||
176 | if (a->file == current_file && b->file != current_file) | |
177 | return -1; | |
178 | if (a->file != current_file && b->file == current_file) | |
179 | return 1; | |
180 | if (a->file == current_file && b->file == current_file) | |
181 | { | |
182 | if (a->line == current_line && b->line != current_line) | |
183 | return -1; | |
184 | if (a->line != current_line && b->line == current_line) | |
185 | return 1; | |
186 | } | |
187 | if (a->file != b->file) | |
188 | return strcmp (a->file, b->file); | |
189 | if (a->line != b->line) | |
190 | return a->line - b->line; | |
191 | return a->col - b->col; | |
192 | } | |
193 | ||
194 | /* Apply all changes in location cache. Add locations into linemap and patch | |
195 | trees. */ | |
196 | ||
197 | bool | |
198 | lto_location_cache::apply_location_cache () | |
199 | { | |
200 | static const char *prev_file; | |
201 | if (!loc_cache.length ()) | |
202 | return false; | |
203 | if (loc_cache.length () > 1) | |
204 | loc_cache.qsort (cmp_loc); | |
205 | ||
206 | for (unsigned int i = 0; i < loc_cache.length (); i++) | |
207 | { | |
208 | struct cached_location loc = loc_cache[i]; | |
209 | ||
210 | if (current_file != loc.file) | |
211 | linemap_add (line_table, prev_file ? LC_RENAME : LC_ENTER, | |
212 | false, loc.file, loc.line); | |
213 | else if (current_line != loc.line) | |
214 | { | |
215 | int max = loc.col; | |
216 | ||
217 | for (unsigned int j = i + 1; j < loc_cache.length (); j++) | |
218 | if (loc.file != loc_cache[j].file | |
219 | || loc.line != loc_cache[j].line) | |
220 | break; | |
221 | else if (max < loc_cache[j].col) | |
222 | max = loc_cache[j].col; | |
223 | linemap_line_start (line_table, loc.line, max + 1); | |
224 | } | |
225 | gcc_assert (*loc.loc == BUILTINS_LOCATION + 1); | |
226 | if (current_file == loc.file && current_line == loc.line | |
227 | && current_col == loc.col) | |
228 | *loc.loc = current_loc; | |
229 | else | |
230 | current_loc = *loc.loc = linemap_position_for_column (line_table, | |
231 | loc.col); | |
232 | current_line = loc.line; | |
233 | prev_file = current_file = loc.file; | |
234 | current_col = loc.col; | |
235 | } | |
236 | loc_cache.truncate (0); | |
237 | accepted_length = 0; | |
238 | return true; | |
239 | } | |
240 | ||
241 | /* Tree merging did not suceed; mark all changes in the cache as accepted. */ | |
242 | ||
243 | void | |
244 | lto_location_cache::accept_location_cache () | |
245 | { | |
246 | gcc_assert (current_cache == this); | |
247 | accepted_length = loc_cache.length (); | |
248 | } | |
249 | ||
250 | /* Tree merging did suceed; throw away recent changes. */ | |
251 | ||
252 | void | |
253 | lto_location_cache::revert_location_cache () | |
254 | { | |
255 | loc_cache.truncate (accepted_length); | |
256 | } | |
257 | ||
258 | /* Read a location bitpack from input block IB and either update *LOC directly | |
259 | or add it to the location cache. | |
260 | It is neccesary to call apply_location_cache to get *LOC updated. */ | |
261 | ||
262 | void | |
263 | lto_location_cache::input_location (location_t *loc, struct bitpack_d *bp, | |
264 | struct data_in *data_in) | |
7bfefa9d | 265 | { |
da6f3259 | 266 | static const char *stream_file; |
267 | static int stream_line; | |
268 | static int stream_col; | |
a12c2487 | 269 | bool file_change, line_change, column_change; |
da6f3259 | 270 | |
271 | gcc_assert (current_cache == this); | |
7bfefa9d | 272 | |
43f418e7 | 273 | *loc = bp_unpack_int_in_range (bp, "location", 0, RESERVED_LOCATION_COUNT); |
274 | ||
275 | if (*loc < RESERVED_LOCATION_COUNT) | |
276 | return; | |
277 | ||
278 | /* Keep value RESERVED_LOCATION_COUNT in *loc as linemap lookups will | |
279 | ICE on it. */ | |
7bfefa9d | 280 | |
a12c2487 | 281 | file_change = bp_unpack_value (bp, 1); |
ab3c0986 | 282 | line_change = bp_unpack_value (bp, 1); |
283 | column_change = bp_unpack_value (bp, 1); | |
284 | ||
a12c2487 | 285 | if (file_change) |
da6f3259 | 286 | stream_file = canon_file_name (bp_unpack_string (data_in, bp)); |
a12c2487 | 287 | |
a12c2487 | 288 | if (line_change) |
da6f3259 | 289 | stream_line = bp_unpack_var_len_unsigned (bp); |
7bfefa9d | 290 | |
a12c2487 | 291 | if (column_change) |
da6f3259 | 292 | stream_col = bp_unpack_var_len_unsigned (bp); |
a12c2487 | 293 | |
da6f3259 | 294 | /* This optimization saves location cache operations druing gimple |
295 | streaming. */ | |
296 | ||
297 | if (current_file == stream_file && current_line == stream_line | |
298 | && current_col == stream_col) | |
cb0ae7a9 | 299 | { |
da6f3259 | 300 | *loc = current_loc; |
301 | return; | |
cb0ae7a9 | 302 | } |
a12c2487 | 303 | |
da6f3259 | 304 | struct cached_location entry = {stream_file, loc, stream_line, stream_col}; |
305 | loc_cache.safe_push (entry); | |
306 | } | |
307 | ||
308 | /* Read a location bitpack from input block IB and either update *LOC directly | |
309 | or add it to the location cache. | |
310 | It is neccesary to call apply_location_cache to get *LOC updated. */ | |
311 | ||
312 | void | |
313 | lto_input_location (location_t *loc, struct bitpack_d *bp, | |
314 | struct data_in *data_in) | |
315 | { | |
316 | data_in->location_cache.input_location (loc, bp, data_in); | |
a12c2487 | 317 | } |
318 | ||
da6f3259 | 319 | /* Read location and return it instead of going through location caching. |
320 | This should be used only when the resulting location is not going to be | |
321 | discarded. */ | |
322 | ||
323 | location_t | |
324 | stream_input_location_now (struct bitpack_d *bp, struct data_in *data_in) | |
325 | { | |
326 | location_t loc; | |
327 | stream_input_location (&loc, bp, data_in); | |
328 | data_in->location_cache.apply_location_cache (); | |
329 | return loc; | |
330 | } | |
cb0ae7a9 | 331 | |
7bfefa9d | 332 | /* Read a reference to a tree node from DATA_IN using input block IB. |
333 | TAG is the expected node that should be found in IB, if TAG belongs | |
334 | to one of the indexable trees, expect to read a reference index to | |
335 | be looked up in one of the symbol tables, otherwise read the pysical | |
515cf651 | 336 | representation of the tree using stream_read_tree. FN is the |
7bfefa9d | 337 | function scope for the read tree. */ |
338 | ||
2541503d | 339 | tree |
48e1416a | 340 | lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in, |
7bfefa9d | 341 | struct function *fn, enum LTO_tags tag) |
342 | { | |
343 | unsigned HOST_WIDE_INT ix_u; | |
344 | tree result = NULL_TREE; | |
345 | ||
c40a5c1b | 346 | lto_tag_check_range (tag, LTO_field_decl_ref, LTO_namelist_decl_ref); |
7bfefa9d | 347 | |
348 | switch (tag) | |
349 | { | |
350 | case LTO_type_ref: | |
7f385784 | 351 | ix_u = streamer_read_uhwi (ib); |
7bfefa9d | 352 | result = lto_file_decl_data_get_type (data_in->file_data, ix_u); |
353 | break; | |
354 | ||
355 | case LTO_ssa_name_ref: | |
7f385784 | 356 | ix_u = streamer_read_uhwi (ib); |
f1f41a6c | 357 | result = (*SSANAMES (fn))[ix_u]; |
7bfefa9d | 358 | break; |
359 | ||
360 | case LTO_field_decl_ref: | |
7f385784 | 361 | ix_u = streamer_read_uhwi (ib); |
7bfefa9d | 362 | result = lto_file_decl_data_get_field_decl (data_in->file_data, ix_u); |
363 | break; | |
364 | ||
365 | case LTO_function_decl_ref: | |
7f385784 | 366 | ix_u = streamer_read_uhwi (ib); |
7bfefa9d | 367 | result = lto_file_decl_data_get_fn_decl (data_in->file_data, ix_u); |
368 | break; | |
369 | ||
370 | case LTO_type_decl_ref: | |
7f385784 | 371 | ix_u = streamer_read_uhwi (ib); |
7bfefa9d | 372 | result = lto_file_decl_data_get_type_decl (data_in->file_data, ix_u); |
373 | break; | |
374 | ||
375 | case LTO_namespace_decl_ref: | |
7f385784 | 376 | ix_u = streamer_read_uhwi (ib); |
7bfefa9d | 377 | result = lto_file_decl_data_get_namespace_decl (data_in->file_data, ix_u); |
378 | break; | |
379 | ||
380 | case LTO_global_decl_ref: | |
381 | case LTO_result_decl_ref: | |
382 | case LTO_const_decl_ref: | |
383 | case LTO_imported_decl_ref: | |
384 | case LTO_label_decl_ref: | |
23bdc9ca | 385 | case LTO_translation_unit_decl_ref: |
6541e9a1 | 386 | case LTO_namelist_decl_ref: |
7f385784 | 387 | ix_u = streamer_read_uhwi (ib); |
7bfefa9d | 388 | result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u); |
7bfefa9d | 389 | break; |
390 | ||
391 | default: | |
392 | gcc_unreachable (); | |
393 | } | |
394 | ||
395 | gcc_assert (result); | |
396 | ||
397 | return result; | |
398 | } | |
399 | ||
400 | ||
401 | /* Read and return a double-linked list of catch handlers from input | |
402 | block IB, using descriptors in DATA_IN. */ | |
403 | ||
404 | static struct eh_catch_d * | |
405 | lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in, | |
406 | eh_catch *last_p) | |
407 | { | |
408 | eh_catch first; | |
409 | enum LTO_tags tag; | |
410 | ||
411 | *last_p = first = NULL; | |
7f385784 | 412 | tag = streamer_read_record_start (ib); |
7bfefa9d | 413 | while (tag) |
414 | { | |
415 | tree list; | |
416 | eh_catch n; | |
417 | ||
418 | lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch); | |
419 | ||
420 | /* Read the catch node. */ | |
25a27413 | 421 | n = ggc_cleared_alloc<eh_catch_d> (); |
515cf651 | 422 | n->type_list = stream_read_tree (ib, data_in); |
423 | n->filter_list = stream_read_tree (ib, data_in); | |
424 | n->label = stream_read_tree (ib, data_in); | |
7bfefa9d | 425 | |
426 | /* Register all the types in N->FILTER_LIST. */ | |
427 | for (list = n->filter_list; list; list = TREE_CHAIN (list)) | |
428 | add_type_for_runtime (TREE_VALUE (list)); | |
429 | ||
430 | /* Chain N to the end of the list. */ | |
431 | if (*last_p) | |
432 | (*last_p)->next_catch = n; | |
433 | n->prev_catch = *last_p; | |
434 | *last_p = n; | |
435 | ||
436 | /* Set the head of the list the first time through the loop. */ | |
437 | if (first == NULL) | |
438 | first = n; | |
439 | ||
7f385784 | 440 | tag = streamer_read_record_start (ib); |
7bfefa9d | 441 | } |
442 | ||
443 | return first; | |
444 | } | |
445 | ||
446 | ||
447 | /* Read and return EH region IX from input block IB, using descriptors | |
448 | in DATA_IN. */ | |
449 | ||
450 | static eh_region | |
451 | input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix) | |
452 | { | |
453 | enum LTO_tags tag; | |
454 | eh_region r; | |
455 | ||
456 | /* Read the region header. */ | |
7f385784 | 457 | tag = streamer_read_record_start (ib); |
7bfefa9d | 458 | if (tag == LTO_null) |
459 | return NULL; | |
460 | ||
25a27413 | 461 | r = ggc_cleared_alloc<eh_region_d> (); |
7f385784 | 462 | r->index = streamer_read_hwi (ib); |
7bfefa9d | 463 | |
464 | gcc_assert (r->index == ix); | |
465 | ||
466 | /* Read all the region pointers as region numbers. We'll fix up | |
467 | the pointers once the whole array has been read. */ | |
7f385784 | 468 | r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib); |
469 | r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib); | |
470 | r->next_peer = (eh_region) (intptr_t) streamer_read_hwi (ib); | |
7bfefa9d | 471 | |
472 | switch (tag) | |
473 | { | |
474 | case LTO_ert_cleanup: | |
475 | r->type = ERT_CLEANUP; | |
476 | break; | |
477 | ||
478 | case LTO_ert_try: | |
479 | { | |
480 | struct eh_catch_d *last_catch; | |
481 | r->type = ERT_TRY; | |
482 | r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in, | |
483 | &last_catch); | |
484 | r->u.eh_try.last_catch = last_catch; | |
485 | break; | |
486 | } | |
487 | ||
488 | case LTO_ert_allowed_exceptions: | |
489 | { | |
490 | tree l; | |
491 | ||
492 | r->type = ERT_ALLOWED_EXCEPTIONS; | |
515cf651 | 493 | r->u.allowed.type_list = stream_read_tree (ib, data_in); |
494 | r->u.allowed.label = stream_read_tree (ib, data_in); | |
7f385784 | 495 | r->u.allowed.filter = streamer_read_uhwi (ib); |
7bfefa9d | 496 | |
497 | for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l)) | |
498 | add_type_for_runtime (TREE_VALUE (l)); | |
499 | } | |
500 | break; | |
501 | ||
502 | case LTO_ert_must_not_throw: | |
ec180527 | 503 | { |
504 | r->type = ERT_MUST_NOT_THROW; | |
505 | r->u.must_not_throw.failure_decl = stream_read_tree (ib, data_in); | |
506 | bitpack_d bp = streamer_read_bitpack (ib); | |
507 | r->u.must_not_throw.failure_loc | |
da6f3259 | 508 | = stream_input_location_now (&bp, data_in); |
ec180527 | 509 | } |
7bfefa9d | 510 | break; |
511 | ||
512 | default: | |
513 | gcc_unreachable (); | |
514 | } | |
515 | ||
7f385784 | 516 | r->landing_pads = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib); |
7bfefa9d | 517 | |
518 | return r; | |
519 | } | |
520 | ||
521 | ||
522 | /* Read and return EH landing pad IX from input block IB, using descriptors | |
523 | in DATA_IN. */ | |
524 | ||
525 | static eh_landing_pad | |
526 | input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix) | |
527 | { | |
528 | enum LTO_tags tag; | |
529 | eh_landing_pad lp; | |
530 | ||
531 | /* Read the landing pad header. */ | |
7f385784 | 532 | tag = streamer_read_record_start (ib); |
7bfefa9d | 533 | if (tag == LTO_null) |
534 | return NULL; | |
535 | ||
536 | lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad); | |
537 | ||
25a27413 | 538 | lp = ggc_cleared_alloc<eh_landing_pad_d> (); |
7f385784 | 539 | lp->index = streamer_read_hwi (ib); |
7bfefa9d | 540 | gcc_assert (lp->index == ix); |
7f385784 | 541 | lp->next_lp = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib); |
542 | lp->region = (eh_region) (intptr_t) streamer_read_hwi (ib); | |
515cf651 | 543 | lp->post_landing_pad = stream_read_tree (ib, data_in); |
7bfefa9d | 544 | |
545 | return lp; | |
546 | } | |
547 | ||
548 | ||
549 | /* After reading the EH regions, pointers to peer and children regions | |
550 | are region numbers. This converts all these region numbers into | |
551 | real pointers into the rematerialized regions for FN. ROOT_REGION | |
552 | is the region number for the root EH region in FN. */ | |
553 | ||
554 | static void | |
555 | fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region) | |
556 | { | |
557 | unsigned i; | |
f1f41a6c | 558 | vec<eh_region, va_gc> *eh_array = fn->eh->region_array; |
559 | vec<eh_landing_pad, va_gc> *lp_array = fn->eh->lp_array; | |
7bfefa9d | 560 | eh_region r; |
561 | eh_landing_pad lp; | |
562 | ||
563 | gcc_assert (eh_array && lp_array); | |
564 | ||
565 | gcc_assert (root_region >= 0); | |
f1f41a6c | 566 | fn->eh->region_tree = (*eh_array)[root_region]; |
7bfefa9d | 567 | |
f1f41a6c | 568 | #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)] |
569 | #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)] | |
7bfefa9d | 570 | |
571 | /* Convert all the index numbers stored in pointer fields into | |
572 | pointers to the corresponding slots in the EH region array. */ | |
f1f41a6c | 573 | FOR_EACH_VEC_ELT (*eh_array, i, r) |
7bfefa9d | 574 | { |
575 | /* The array may contain NULL regions. */ | |
576 | if (r == NULL) | |
577 | continue; | |
578 | ||
579 | gcc_assert (i == (unsigned) r->index); | |
580 | FIXUP_EH_REGION (r->outer); | |
581 | FIXUP_EH_REGION (r->inner); | |
582 | FIXUP_EH_REGION (r->next_peer); | |
583 | FIXUP_EH_LP (r->landing_pads); | |
584 | } | |
585 | ||
586 | /* Convert all the index numbers stored in pointer fields into | |
587 | pointers to the corresponding slots in the EH landing pad array. */ | |
f1f41a6c | 588 | FOR_EACH_VEC_ELT (*lp_array, i, lp) |
7bfefa9d | 589 | { |
590 | /* The array may contain NULL landing pads. */ | |
591 | if (lp == NULL) | |
592 | continue; | |
593 | ||
594 | gcc_assert (i == (unsigned) lp->index); | |
595 | FIXUP_EH_LP (lp->next_lp); | |
596 | FIXUP_EH_REGION (lp->region); | |
597 | } | |
598 | ||
599 | #undef FIXUP_EH_REGION | |
600 | #undef FIXUP_EH_LP | |
601 | } | |
602 | ||
603 | ||
604 | /* Initialize EH support. */ | |
605 | ||
2541503d | 606 | void |
7bfefa9d | 607 | lto_init_eh (void) |
608 | { | |
eecdda7c | 609 | static bool eh_initialized_p = false; |
610 | ||
611 | if (eh_initialized_p) | |
612 | return; | |
613 | ||
7bfefa9d | 614 | /* Contrary to most other FEs, we only initialize EH support when at |
615 | least one of the files in the set contains exception regions in | |
616 | it. Since this happens much later than the call to init_eh in | |
617 | lang_dependent_init, we have to set flag_exceptions and call | |
618 | init_eh again to initialize the EH tables. */ | |
619 | flag_exceptions = 1; | |
620 | init_eh (); | |
621 | ||
eecdda7c | 622 | eh_initialized_p = true; |
7bfefa9d | 623 | } |
624 | ||
625 | ||
626 | /* Read the exception table for FN from IB using the data descriptors | |
627 | in DATA_IN. */ | |
628 | ||
629 | static void | |
630 | input_eh_regions (struct lto_input_block *ib, struct data_in *data_in, | |
631 | struct function *fn) | |
632 | { | |
633 | HOST_WIDE_INT i, root_region, len; | |
634 | enum LTO_tags tag; | |
48e1416a | 635 | |
7f385784 | 636 | tag = streamer_read_record_start (ib); |
7bfefa9d | 637 | if (tag == LTO_null) |
638 | return; | |
639 | ||
640 | lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table); | |
641 | ||
642 | /* If the file contains EH regions, then it was compiled with | |
643 | -fexceptions. In that case, initialize the backend EH | |
644 | machinery. */ | |
eecdda7c | 645 | lto_init_eh (); |
7bfefa9d | 646 | |
647 | gcc_assert (fn->eh); | |
648 | ||
7f385784 | 649 | root_region = streamer_read_hwi (ib); |
7bfefa9d | 650 | gcc_assert (root_region == (int) root_region); |
651 | ||
652 | /* Read the EH region array. */ | |
7f385784 | 653 | len = streamer_read_hwi (ib); |
7bfefa9d | 654 | gcc_assert (len == (int) len); |
655 | if (len > 0) | |
656 | { | |
f1f41a6c | 657 | vec_safe_grow_cleared (fn->eh->region_array, len); |
7bfefa9d | 658 | for (i = 0; i < len; i++) |
659 | { | |
660 | eh_region r = input_eh_region (ib, data_in, i); | |
f1f41a6c | 661 | (*fn->eh->region_array)[i] = r; |
7bfefa9d | 662 | } |
663 | } | |
664 | ||
665 | /* Read the landing pads. */ | |
7f385784 | 666 | len = streamer_read_hwi (ib); |
7bfefa9d | 667 | gcc_assert (len == (int) len); |
668 | if (len > 0) | |
669 | { | |
f1f41a6c | 670 | vec_safe_grow_cleared (fn->eh->lp_array, len); |
7bfefa9d | 671 | for (i = 0; i < len; i++) |
672 | { | |
673 | eh_landing_pad lp = input_eh_lp (ib, data_in, i); | |
f1f41a6c | 674 | (*fn->eh->lp_array)[i] = lp; |
7bfefa9d | 675 | } |
676 | } | |
677 | ||
678 | /* Read the runtime type data. */ | |
7f385784 | 679 | len = streamer_read_hwi (ib); |
7bfefa9d | 680 | gcc_assert (len == (int) len); |
681 | if (len > 0) | |
682 | { | |
f1f41a6c | 683 | vec_safe_grow_cleared (fn->eh->ttype_data, len); |
7bfefa9d | 684 | for (i = 0; i < len; i++) |
685 | { | |
515cf651 | 686 | tree ttype = stream_read_tree (ib, data_in); |
f1f41a6c | 687 | (*fn->eh->ttype_data)[i] = ttype; |
7bfefa9d | 688 | } |
689 | } | |
690 | ||
691 | /* Read the table of action chains. */ | |
7f385784 | 692 | len = streamer_read_hwi (ib); |
7bfefa9d | 693 | gcc_assert (len == (int) len); |
694 | if (len > 0) | |
695 | { | |
696 | if (targetm.arm_eabi_unwinder) | |
697 | { | |
f1f41a6c | 698 | vec_safe_grow_cleared (fn->eh->ehspec_data.arm_eabi, len); |
7bfefa9d | 699 | for (i = 0; i < len; i++) |
700 | { | |
515cf651 | 701 | tree t = stream_read_tree (ib, data_in); |
f1f41a6c | 702 | (*fn->eh->ehspec_data.arm_eabi)[i] = t; |
7bfefa9d | 703 | } |
704 | } | |
705 | else | |
706 | { | |
f1f41a6c | 707 | vec_safe_grow_cleared (fn->eh->ehspec_data.other, len); |
7bfefa9d | 708 | for (i = 0; i < len; i++) |
709 | { | |
7f385784 | 710 | uchar c = streamer_read_uchar (ib); |
f1f41a6c | 711 | (*fn->eh->ehspec_data.other)[i] = c; |
7bfefa9d | 712 | } |
713 | } | |
714 | } | |
715 | ||
716 | /* Reconstruct the EH region tree by fixing up the peer/children | |
717 | pointers. */ | |
718 | fixup_eh_region_pointers (fn, root_region); | |
719 | ||
7f385784 | 720 | tag = streamer_read_record_start (ib); |
7bfefa9d | 721 | lto_tag_check_range (tag, LTO_null, LTO_null); |
722 | } | |
723 | ||
724 | ||
725 | /* Make a new basic block with index INDEX in function FN. */ | |
726 | ||
727 | static basic_block | |
728 | make_new_block (struct function *fn, unsigned int index) | |
729 | { | |
730 | basic_block bb = alloc_block (); | |
731 | bb->index = index; | |
98e6ab47 | 732 | SET_BASIC_BLOCK_FOR_FN (fn, index, bb); |
a28770e1 | 733 | n_basic_blocks_for_fn (fn)++; |
7bfefa9d | 734 | return bb; |
735 | } | |
736 | ||
737 | ||
8b3716ff | 738 | /* Read a wide-int. */ |
739 | ||
740 | static widest_int | |
741 | streamer_read_wi (struct lto_input_block *ib) | |
742 | { | |
743 | HOST_WIDE_INT a[WIDE_INT_MAX_ELTS]; | |
744 | int i; | |
745 | int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib); | |
746 | int len = streamer_read_uhwi (ib); | |
747 | for (i = 0; i < len; i++) | |
748 | a[i] = streamer_read_hwi (ib); | |
749 | return widest_int::from_array (a, len); | |
750 | } | |
751 | ||
752 | ||
7bfefa9d | 753 | /* Read the CFG for function FN from input block IB. */ |
754 | ||
48e1416a | 755 | static void |
9978ce6d | 756 | input_cfg (struct lto_input_block *ib, struct data_in *data_in, |
757 | struct function *fn, | |
c470c5a9 | 758 | int count_materialization_scale) |
7bfefa9d | 759 | { |
760 | unsigned int bb_count; | |
761 | basic_block p_bb; | |
762 | unsigned int i; | |
763 | int index; | |
764 | ||
765 | init_empty_tree_cfg_for_function (fn); | |
5084b2e4 | 766 | init_ssa_operands (fn); |
7bfefa9d | 767 | |
3bedbae3 | 768 | profile_status_for_fn (fn) = streamer_read_enum (ib, profile_status_d, |
769 | PROFILE_LAST); | |
7bfefa9d | 770 | |
7f385784 | 771 | bb_count = streamer_read_uhwi (ib); |
7bfefa9d | 772 | |
776b0663 | 773 | last_basic_block_for_fn (fn) = bb_count; |
98e6ab47 | 774 | if (bb_count > basic_block_info_for_fn (fn)->length ()) |
775 | vec_safe_grow_cleared (basic_block_info_for_fn (fn), bb_count); | |
7bfefa9d | 776 | |
dbd64d47 | 777 | if (bb_count > label_to_block_map_for_fn (fn)->length ()) |
778 | vec_safe_grow_cleared (label_to_block_map_for_fn (fn), bb_count); | |
7bfefa9d | 779 | |
7f385784 | 780 | index = streamer_read_hwi (ib); |
7bfefa9d | 781 | while (index != -1) |
782 | { | |
98e6ab47 | 783 | basic_block bb = BASIC_BLOCK_FOR_FN (fn, index); |
7bfefa9d | 784 | unsigned int edge_count; |
785 | ||
786 | if (bb == NULL) | |
787 | bb = make_new_block (fn, index); | |
788 | ||
7f385784 | 789 | edge_count = streamer_read_uhwi (ib); |
7bfefa9d | 790 | |
791 | /* Connect up the CFG. */ | |
792 | for (i = 0; i < edge_count; i++) | |
793 | { | |
794 | unsigned int dest_index; | |
795 | unsigned int edge_flags; | |
796 | basic_block dest; | |
797 | int probability; | |
798 | gcov_type count; | |
799 | edge e; | |
800 | ||
7f385784 | 801 | dest_index = streamer_read_uhwi (ib); |
802 | probability = (int) streamer_read_hwi (ib); | |
e2bc4ec8 | 803 | count = apply_scale ((gcov_type) streamer_read_gcov_count (ib), |
804 | count_materialization_scale); | |
7f385784 | 805 | edge_flags = streamer_read_uhwi (ib); |
7bfefa9d | 806 | |
98e6ab47 | 807 | dest = BASIC_BLOCK_FOR_FN (fn, dest_index); |
7bfefa9d | 808 | |
48e1416a | 809 | if (dest == NULL) |
7bfefa9d | 810 | dest = make_new_block (fn, dest_index); |
811 | ||
812 | e = make_edge (bb, dest, edge_flags); | |
813 | e->probability = probability; | |
814 | e->count = count; | |
815 | } | |
816 | ||
7f385784 | 817 | index = streamer_read_hwi (ib); |
7bfefa9d | 818 | } |
819 | ||
34154e27 | 820 | p_bb = ENTRY_BLOCK_PTR_FOR_FN (fn); |
7f385784 | 821 | index = streamer_read_hwi (ib); |
7bfefa9d | 822 | while (index != -1) |
823 | { | |
98e6ab47 | 824 | basic_block bb = BASIC_BLOCK_FOR_FN (fn, index); |
7bfefa9d | 825 | bb->prev_bb = p_bb; |
826 | p_bb->next_bb = bb; | |
827 | p_bb = bb; | |
7f385784 | 828 | index = streamer_read_hwi (ib); |
7bfefa9d | 829 | } |
7a569539 | 830 | |
831 | /* ??? The cfgloop interface is tied to cfun. */ | |
832 | gcc_assert (cfun == fn); | |
833 | ||
834 | /* Input the loop tree. */ | |
835 | unsigned n_loops = streamer_read_uhwi (ib); | |
836 | if (n_loops == 0) | |
837 | return; | |
838 | ||
25a27413 | 839 | struct loops *loops = ggc_cleared_alloc<struct loops> (); |
7a569539 | 840 | init_loops_structure (fn, loops, n_loops); |
41f75a99 | 841 | set_loops_for_fn (fn, loops); |
7a569539 | 842 | |
843 | /* Input each loop and associate it with its loop header so | |
844 | flow_loops_find can rebuild the loop tree. */ | |
845 | for (unsigned i = 1; i < n_loops; ++i) | |
846 | { | |
847 | int header_index = streamer_read_hwi (ib); | |
848 | if (header_index == -1) | |
849 | { | |
850 | loops->larray->quick_push (NULL); | |
851 | continue; | |
852 | } | |
853 | ||
854 | struct loop *loop = alloc_loop (); | |
98e6ab47 | 855 | loop->header = BASIC_BLOCK_FOR_FN (fn, header_index); |
7a569539 | 856 | loop->header->loop_father = loop; |
857 | ||
858 | /* Read everything copy_loop_info copies. */ | |
859 | loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST); | |
860 | loop->any_upper_bound = streamer_read_hwi (ib); | |
861 | if (loop->any_upper_bound) | |
8b3716ff | 862 | loop->nb_iterations_upper_bound = streamer_read_wi (ib); |
7a569539 | 863 | loop->any_estimate = streamer_read_hwi (ib); |
864 | if (loop->any_estimate) | |
8b3716ff | 865 | loop->nb_iterations_estimate = streamer_read_wi (ib); |
7a569539 | 866 | |
9978ce6d | 867 | /* Read OMP SIMD related info. */ |
868 | loop->safelen = streamer_read_hwi (ib); | |
eb71996d | 869 | loop->dont_vectorize = streamer_read_hwi (ib); |
4c73695b | 870 | loop->force_vectorize = streamer_read_hwi (ib); |
9978ce6d | 871 | loop->simduid = stream_read_tree (ib, data_in); |
872 | ||
41f75a99 | 873 | place_new_loop (fn, loop); |
7a569539 | 874 | |
875 | /* flow_loops_find doesn't like loops not in the tree, hook them | |
876 | all as siblings of the tree root temporarily. */ | |
877 | flow_loop_tree_node_add (loops->tree_root, loop); | |
878 | } | |
879 | ||
880 | /* Rebuild the loop tree. */ | |
41f75a99 | 881 | flow_loops_find (loops); |
7bfefa9d | 882 | } |
883 | ||
884 | ||
7bfefa9d | 885 | /* Read the SSA names array for function FN from DATA_IN using input |
886 | block IB. */ | |
887 | ||
888 | static void | |
889 | input_ssa_names (struct lto_input_block *ib, struct data_in *data_in, | |
890 | struct function *fn) | |
891 | { | |
892 | unsigned int i, size; | |
893 | ||
7f385784 | 894 | size = streamer_read_uhwi (ib); |
7bfefa9d | 895 | init_ssanames (fn, size); |
896 | ||
7f385784 | 897 | i = streamer_read_uhwi (ib); |
7bfefa9d | 898 | while (i) |
899 | { | |
900 | tree ssa_name, name; | |
901 | bool is_default_def; | |
902 | ||
903 | /* Skip over the elements that had been freed. */ | |
f1f41a6c | 904 | while (SSANAMES (fn)->length () < i) |
905 | SSANAMES (fn)->quick_push (NULL_TREE); | |
7bfefa9d | 906 | |
7f385784 | 907 | is_default_def = (streamer_read_uchar (ib) != 0); |
515cf651 | 908 | name = stream_read_tree (ib, data_in); |
7bfefa9d | 909 | ssa_name = make_ssa_name_fn (fn, name, gimple_build_nop ()); |
910 | ||
911 | if (is_default_def) | |
c6dfe037 | 912 | set_ssa_default_def (cfun, SSA_NAME_VAR (ssa_name), ssa_name); |
7bfefa9d | 913 | |
7f385784 | 914 | i = streamer_read_uhwi (ib); |
48e1416a | 915 | } |
7bfefa9d | 916 | } |
917 | ||
7bfefa9d | 918 | |
919 | /* Go through all NODE edges and fixup call_stmt pointers | |
920 | so they point to STMTS. */ | |
921 | ||
922 | static void | |
4d044066 | 923 | fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple *stmts, |
924 | struct function *fn) | |
7bfefa9d | 925 | { |
926 | struct cgraph_edge *cedge; | |
51ce5652 | 927 | struct ipa_ref *ref = NULL; |
4d044066 | 928 | unsigned int i; |
929 | ||
7bfefa9d | 930 | for (cedge = node->callees; cedge; cedge = cedge->next_callee) |
4d044066 | 931 | { |
932 | if (gimple_stmt_max_uid (fn) < cedge->lto_stmt_uid) | |
c05be867 | 933 | fatal_error (input_location, |
934 | "Cgraph edge statement index out of range"); | |
1a91d914 | 935 | cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]); |
4d044066 | 936 | if (!cedge->call_stmt) |
c05be867 | 937 | fatal_error (input_location, |
938 | "Cgraph edge statement index not found"); | |
4d044066 | 939 | } |
799c8711 | 940 | for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee) |
4d044066 | 941 | { |
942 | if (gimple_stmt_max_uid (fn) < cedge->lto_stmt_uid) | |
c05be867 | 943 | fatal_error (input_location, |
944 | "Cgraph edge statement index out of range"); | |
1a91d914 | 945 | cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]); |
4d044066 | 946 | if (!cedge->call_stmt) |
c05be867 | 947 | fatal_error (input_location, "Cgraph edge statement index not found"); |
4d044066 | 948 | } |
51ce5652 | 949 | for (i = 0; node->iterate_reference (i, ref); i++) |
4d044066 | 950 | if (ref->lto_stmt_uid) |
951 | { | |
952 | if (gimple_stmt_max_uid (fn) < ref->lto_stmt_uid) | |
c05be867 | 953 | fatal_error (input_location, |
954 | "Reference statement index out of range"); | |
4d044066 | 955 | ref->stmt = stmts[ref->lto_stmt_uid - 1]; |
956 | if (!ref->stmt) | |
c05be867 | 957 | fatal_error (input_location, "Reference statement index not found"); |
4d044066 | 958 | } |
7bfefa9d | 959 | } |
960 | ||
4d044066 | 961 | |
7bfefa9d | 962 | /* Fixup call_stmt pointers in NODE and all clones. */ |
963 | ||
964 | static void | |
965 | fixup_call_stmt_edges (struct cgraph_node *orig, gimple *stmts) | |
966 | { | |
967 | struct cgraph_node *node; | |
4d044066 | 968 | struct function *fn; |
7bfefa9d | 969 | |
970 | while (orig->clone_of) | |
971 | orig = orig->clone_of; | |
02774f2d | 972 | fn = DECL_STRUCT_FUNCTION (orig->decl); |
7bfefa9d | 973 | |
4d044066 | 974 | fixup_call_stmt_edges_1 (orig, stmts, fn); |
7bfefa9d | 975 | if (orig->clones) |
976 | for (node = orig->clones; node != orig;) | |
977 | { | |
4d044066 | 978 | fixup_call_stmt_edges_1 (node, stmts, fn); |
7bfefa9d | 979 | if (node->clones) |
980 | node = node->clones; | |
981 | else if (node->next_sibling_clone) | |
982 | node = node->next_sibling_clone; | |
983 | else | |
984 | { | |
985 | while (node != orig && !node->next_sibling_clone) | |
986 | node = node->clone_of; | |
987 | if (node != orig) | |
988 | node = node->next_sibling_clone; | |
989 | } | |
990 | } | |
991 | } | |
992 | ||
e4fc8eb2 | 993 | |
994 | /* Input the base body of struct function FN from DATA_IN | |
995 | using input block IB. */ | |
7bfefa9d | 996 | |
997 | static void | |
e4fc8eb2 | 998 | input_struct_function_base (struct function *fn, struct data_in *data_in, |
999 | struct lto_input_block *ib) | |
7bfefa9d | 1000 | { |
30baba90 | 1001 | struct bitpack_d bp; |
2ab2ce89 | 1002 | int len; |
7bfefa9d | 1003 | |
e4fc8eb2 | 1004 | /* Read the static chain and non-local goto save area. */ |
1005 | fn->static_chain_decl = stream_read_tree (ib, data_in); | |
1006 | fn->nonlocal_goto_save_area = stream_read_tree (ib, data_in); | |
7bfefa9d | 1007 | |
e4fc8eb2 | 1008 | /* Read all the local symbols. */ |
1009 | len = streamer_read_hwi (ib); | |
1010 | if (len > 0) | |
1011 | { | |
1012 | int i; | |
f1f41a6c | 1013 | vec_safe_grow_cleared (fn->local_decls, len); |
e4fc8eb2 | 1014 | for (i = 0; i < len; i++) |
1015 | { | |
1016 | tree t = stream_read_tree (ib, data_in); | |
f1f41a6c | 1017 | (*fn->local_decls)[i] = t; |
e4fc8eb2 | 1018 | } |
1019 | } | |
1020 | ||
e4fc8eb2 | 1021 | /* Input the current IL state of the function. */ |
1022 | fn->curr_properties = streamer_read_uhwi (ib); | |
7bfefa9d | 1023 | |
1024 | /* Read all the attributes for FN. */ | |
7f385784 | 1025 | bp = streamer_read_bitpack (ib); |
30baba90 | 1026 | fn->is_thunk = bp_unpack_value (&bp, 1); |
1027 | fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1); | |
30baba90 | 1028 | fn->returns_pcc_struct = bp_unpack_value (&bp, 1); |
1029 | fn->returns_struct = bp_unpack_value (&bp, 1); | |
1030 | fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1); | |
bc0dfc8d | 1031 | fn->can_delete_dead_exceptions = bp_unpack_value (&bp, 1); |
30baba90 | 1032 | fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1); |
1033 | fn->after_inlining = bp_unpack_value (&bp, 1); | |
30baba90 | 1034 | fn->stdarg = bp_unpack_value (&bp, 1); |
1035 | fn->has_nonlocal_label = bp_unpack_value (&bp, 1); | |
1036 | fn->calls_alloca = bp_unpack_value (&bp, 1); | |
1037 | fn->calls_setjmp = bp_unpack_value (&bp, 1); | |
4c73695b | 1038 | fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1); |
9978ce6d | 1039 | fn->has_simduid_loops = bp_unpack_value (&bp, 1); |
30baba90 | 1040 | fn->va_list_fpr_size = bp_unpack_value (&bp, 8); |
1041 | fn->va_list_gpr_size = bp_unpack_value (&bp, 8); | |
e70d82fd | 1042 | fn->last_clique = bp_unpack_value (&bp, sizeof (short) * 8); |
ec180527 | 1043 | |
1044 | /* Input the function start and end loci. */ | |
da6f3259 | 1045 | fn->function_start_locus = stream_input_location_now (&bp, data_in); |
1046 | fn->function_end_locus = stream_input_location_now (&bp, data_in); | |
e4fc8eb2 | 1047 | } |
7bfefa9d | 1048 | |
115697e0 | 1049 | |
e4fc8eb2 | 1050 | /* Read the body of function FN_DECL from DATA_IN using input block IB. */ |
7b76dcb9 | 1051 | |
e4fc8eb2 | 1052 | static void |
1053 | input_function (tree fn_decl, struct data_in *data_in, | |
4df870fd | 1054 | struct lto_input_block *ib, struct lto_input_block *ib_cfg) |
e4fc8eb2 | 1055 | { |
1056 | struct function *fn; | |
1057 | enum LTO_tags tag; | |
1058 | gimple *stmts; | |
1059 | basic_block bb; | |
1060 | struct cgraph_node *node; | |
7bfefa9d | 1061 | |
e4fc8eb2 | 1062 | tag = streamer_read_record_start (ib); |
4df870fd | 1063 | lto_tag_check (tag, LTO_function); |
1064 | ||
1065 | /* Read decls for parameters and args. */ | |
1066 | DECL_RESULT (fn_decl) = stream_read_tree (ib, data_in); | |
1067 | DECL_ARGUMENTS (fn_decl) = streamer_read_chain (ib, data_in); | |
1068 | ||
1069 | /* Read the tree of lexical scopes for the function. */ | |
1070 | DECL_INITIAL (fn_decl) = stream_read_tree (ib, data_in); | |
1071 | ||
1072 | if (!streamer_read_uhwi (ib)) | |
1073 | return; | |
1074 | ||
1075 | push_struct_function (fn_decl); | |
1076 | fn = DECL_STRUCT_FUNCTION (fn_decl); | |
1077 | init_tree_ssa (fn); | |
1078 | /* We input IL in SSA form. */ | |
1079 | cfun->gimple_df->in_ssa_p = true; | |
e4fc8eb2 | 1080 | |
1081 | gimple_register_cfg_hooks (); | |
e4fc8eb2 | 1082 | |
415d1b9a | 1083 | node = cgraph_node::get (fn_decl); |
5037630b | 1084 | if (!node) |
415d1b9a | 1085 | node = cgraph_node::create (fn_decl); |
e4fc8eb2 | 1086 | input_struct_function_base (fn, data_in, ib); |
9978ce6d | 1087 | input_cfg (ib_cfg, data_in, fn, node->count_materialization_scale); |
7bfefa9d | 1088 | |
1089 | /* Read all the SSA names. */ | |
1090 | input_ssa_names (ib, data_in, fn); | |
1091 | ||
1092 | /* Read the exception handling regions in the function. */ | |
1093 | input_eh_regions (ib, data_in, fn); | |
1094 | ||
7bfefa9d | 1095 | gcc_assert (DECL_INITIAL (fn_decl)); |
1096 | DECL_SAVED_TREE (fn_decl) = NULL_TREE; | |
1097 | ||
7bfefa9d | 1098 | /* Read all the basic blocks. */ |
7f385784 | 1099 | tag = streamer_read_record_start (ib); |
7bfefa9d | 1100 | while (tag) |
1101 | { | |
c470c5a9 | 1102 | input_bb (ib, tag, data_in, fn, |
1103 | node->count_materialization_scale); | |
7f385784 | 1104 | tag = streamer_read_record_start (ib); |
7bfefa9d | 1105 | } |
1106 | ||
1107 | /* Fix up the call statements that are mentioned in the callgraph | |
1108 | edges. */ | |
d55c4ba8 | 1109 | set_gimple_stmt_max_uid (cfun, 0); |
ed7d889a | 1110 | FOR_ALL_BB_FN (bb, cfun) |
d55c4ba8 | 1111 | { |
1112 | gimple_stmt_iterator gsi; | |
62732f86 | 1113 | for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
1114 | { | |
1115 | gimple stmt = gsi_stmt (gsi); | |
1116 | gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun)); | |
1117 | } | |
d55c4ba8 | 1118 | for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
1119 | { | |
1120 | gimple stmt = gsi_stmt (gsi); | |
1121 | gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun)); | |
1122 | } | |
1123 | } | |
7bfefa9d | 1124 | stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple)); |
ed7d889a | 1125 | FOR_ALL_BB_FN (bb, cfun) |
7bfefa9d | 1126 | { |
62732f86 | 1127 | gimple_stmt_iterator bsi = gsi_start_phis (bb); |
1128 | while (!gsi_end_p (bsi)) | |
1129 | { | |
1130 | gimple stmt = gsi_stmt (bsi); | |
1131 | gsi_next (&bsi); | |
1132 | stmts[gimple_uid (stmt)] = stmt; | |
1133 | } | |
1134 | bsi = gsi_start_bb (bb); | |
a33da2f4 | 1135 | while (!gsi_end_p (bsi)) |
7bfefa9d | 1136 | { |
1137 | gimple stmt = gsi_stmt (bsi); | |
a33da2f4 | 1138 | /* If we're recompiling LTO objects with debug stmts but |
1139 | we're not supposed to have debug stmts, remove them now. | |
1140 | We can't remove them earlier because this would cause uid | |
1141 | mismatches in fixups, but we can do it at this point, as | |
1142 | long as debug stmts don't require fixups. */ | |
1df9b23b | 1143 | if (!MAY_HAVE_DEBUG_STMTS && !flag_wpa && is_gimple_debug (stmt)) |
a33da2f4 | 1144 | { |
1145 | gimple_stmt_iterator gsi = bsi; | |
1146 | gsi_next (&bsi); | |
1147 | gsi_remove (&gsi, true); | |
1148 | } | |
1149 | else | |
1150 | { | |
1151 | gsi_next (&bsi); | |
1152 | stmts[gimple_uid (stmt)] = stmt; | |
1153 | } | |
7bfefa9d | 1154 | } |
1155 | } | |
1156 | ||
1157 | /* Set the gimple body to the statement sequence in the entry | |
1158 | basic block. FIXME lto, this is fairly hacky. The existence | |
1159 | of a gimple body is used by the cgraph routines, but we should | |
1160 | really use the presence of the CFG. */ | |
1161 | { | |
34154e27 | 1162 | edge_iterator ei = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs); |
7bfefa9d | 1163 | gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest)); |
1164 | } | |
1165 | ||
90464c8b | 1166 | fixup_call_stmt_edges (node, stmts); |
1167 | execute_all_ipa_stmt_fixups (node, stmts); | |
7bfefa9d | 1168 | |
48e1416a | 1169 | update_ssa (TODO_update_ssa_only_virtuals); |
8867b500 | 1170 | free_dominance_info (CDI_DOMINATORS); |
1171 | free_dominance_info (CDI_POST_DOMINATORS); | |
7bfefa9d | 1172 | free (stmts); |
bb251465 | 1173 | pop_cfun (); |
7bfefa9d | 1174 | } |
1175 | ||
afb0d513 | 1176 | /* Read the body of function FN_DECL from DATA_IN using input block IB. */ |
1177 | ||
1178 | static void | |
1179 | input_constructor (tree var, struct data_in *data_in, | |
1180 | struct lto_input_block *ib) | |
1181 | { | |
1182 | DECL_INITIAL (var) = stream_read_tree (ib, data_in); | |
1183 | } | |
1184 | ||
7bfefa9d | 1185 | |
7e4b741c | 1186 | /* Read the body from DATA for function NODE and fill it in. |
7bfefa9d | 1187 | FILE_DATA are the global decls and types. SECTION_TYPE is either |
1188 | LTO_section_function_body or LTO_section_static_initializer. If | |
1189 | section type is LTO_section_function_body, FN must be the decl for | |
1190 | that function. */ | |
1191 | ||
48e1416a | 1192 | static void |
afb0d513 | 1193 | lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symtab_node *node, |
1194 | const char *data, enum lto_section_type section_type) | |
7bfefa9d | 1195 | { |
1196 | const struct lto_function_header *header; | |
1197 | struct data_in *data_in; | |
949e5786 | 1198 | int cfg_offset; |
1199 | int main_offset; | |
1200 | int string_offset; | |
02774f2d | 1201 | tree fn_decl = node->decl; |
7bfefa9d | 1202 | |
1203 | header = (const struct lto_function_header *) data; | |
afb0d513 | 1204 | if (TREE_CODE (node->decl) == FUNCTION_DECL) |
1205 | { | |
1206 | cfg_offset = sizeof (struct lto_function_header); | |
1207 | main_offset = cfg_offset + header->cfg_size; | |
1208 | string_offset = main_offset + header->main_size; | |
afb0d513 | 1209 | } |
1210 | else | |
1211 | { | |
1212 | main_offset = sizeof (struct lto_function_header); | |
1213 | string_offset = main_offset + header->main_size; | |
afb0d513 | 1214 | } |
48e1416a | 1215 | |
7bfefa9d | 1216 | data_in = lto_data_in_create (file_data, data + string_offset, |
1e094109 | 1217 | header->string_size, vNULL); |
7bfefa9d | 1218 | |
7bfefa9d | 1219 | if (section_type == LTO_section_function_body) |
1220 | { | |
7bfefa9d | 1221 | struct lto_in_decl_state *decl_state; |
4c42fa78 | 1222 | unsigned from; |
7bfefa9d | 1223 | |
53f79206 | 1224 | gcc_checking_assert (node); |
5aabc5f2 | 1225 | |
7bfefa9d | 1226 | /* Use the function's decl state. */ |
1227 | decl_state = lto_get_function_in_decl_state (file_data, fn_decl); | |
1228 | gcc_assert (decl_state); | |
1229 | file_data->current_decl_state = decl_state; | |
1230 | ||
7bfefa9d | 1231 | |
1232 | /* Set up the struct function. */ | |
f1f41a6c | 1233 | from = data_in->reader_cache->nodes.length (); |
2e971afd | 1234 | lto_input_block ib_main (data + main_offset, header->main_size, |
1235 | file_data->mode_table); | |
afb0d513 | 1236 | if (TREE_CODE (node->decl) == FUNCTION_DECL) |
472ca566 | 1237 | { |
2e971afd | 1238 | lto_input_block ib_cfg (data + cfg_offset, header->cfg_size, |
1239 | file_data->mode_table); | |
472ca566 | 1240 | input_function (fn_decl, data_in, &ib_main, &ib_cfg); |
1241 | } | |
afb0d513 | 1242 | else |
1243 | input_constructor (fn_decl, data_in, &ib_main); | |
da6f3259 | 1244 | data_in->location_cache.apply_location_cache (); |
4c42fa78 | 1245 | /* And fixup types we streamed locally. */ |
1246 | { | |
1247 | struct streamer_tree_cache_d *cache = data_in->reader_cache; | |
f1f41a6c | 1248 | unsigned len = cache->nodes.length (); |
4c42fa78 | 1249 | unsigned i; |
1250 | for (i = len; i-- > from;) | |
1251 | { | |
8ceff600 | 1252 | tree t = streamer_tree_cache_get_tree (cache, i); |
4c42fa78 | 1253 | if (t == NULL_TREE) |
1254 | continue; | |
1255 | ||
1256 | if (TYPE_P (t)) | |
1257 | { | |
1258 | gcc_assert (TYPE_CANONICAL (t) == NULL_TREE); | |
1259 | TYPE_CANONICAL (t) = TYPE_MAIN_VARIANT (t); | |
1260 | if (TYPE_MAIN_VARIANT (t) != t) | |
1261 | { | |
1262 | gcc_assert (TYPE_NEXT_VARIANT (t) == NULL_TREE); | |
1263 | TYPE_NEXT_VARIANT (t) | |
1264 | = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t)); | |
1265 | TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t)) = t; | |
1266 | } | |
1267 | } | |
1268 | } | |
1269 | } | |
7bfefa9d | 1270 | |
7bfefa9d | 1271 | /* Restore decl state */ |
1272 | file_data->current_decl_state = file_data->global_decl_state; | |
7bfefa9d | 1273 | } |
7bfefa9d | 1274 | |
7bfefa9d | 1275 | lto_data_in_delete (data_in); |
1276 | } | |
1277 | ||
1278 | ||
7e4b741c | 1279 | /* Read the body of NODE using DATA. FILE_DATA holds the global |
7bfefa9d | 1280 | decls and types. */ |
1281 | ||
48e1416a | 1282 | void |
7bfefa9d | 1283 | lto_input_function_body (struct lto_file_decl_data *file_data, |
7e4b741c | 1284 | struct cgraph_node *node, const char *data) |
7bfefa9d | 1285 | { |
afb0d513 | 1286 | lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body); |
1287 | } | |
1288 | ||
1289 | /* Read the body of NODE using DATA. FILE_DATA holds the global | |
1290 | decls and types. */ | |
1291 | ||
1292 | void | |
1293 | lto_input_variable_constructor (struct lto_file_decl_data *file_data, | |
1294 | struct varpool_node *node, const char *data) | |
1295 | { | |
1296 | lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body); | |
7bfefa9d | 1297 | } |
1298 | ||
1299 | ||
8ceff600 | 1300 | /* Read the physical representation of a tree node EXPR from |
1301 | input block IB using the per-file context in DATA_IN. */ | |
1302 | ||
1303 | static void | |
1304 | lto_read_tree_1 (struct lto_input_block *ib, struct data_in *data_in, tree expr) | |
1305 | { | |
1306 | /* Read all the bitfield values in EXPR. Note that for LTO, we | |
1307 | only write language-independent bitfields, so no more unpacking is | |
1308 | needed. */ | |
1309 | streamer_read_tree_bitfields (ib, data_in, expr); | |
1310 | ||
1311 | /* Read all the pointer fields in EXPR. */ | |
1312 | streamer_read_tree_body (ib, data_in, expr); | |
1313 | ||
1314 | /* Read any LTO-specific data not read by the tree streamer. */ | |
1315 | if (DECL_P (expr) | |
1316 | && TREE_CODE (expr) != FUNCTION_DECL | |
1317 | && TREE_CODE (expr) != TRANSLATION_UNIT_DECL) | |
1318 | DECL_INITIAL (expr) = stream_read_tree (ib, data_in); | |
1319 | ||
1320 | /* We should never try to instantiate an MD or NORMAL builtin here. */ | |
1321 | if (TREE_CODE (expr) == FUNCTION_DECL) | |
1322 | gcc_assert (!streamer_handle_as_builtin_p (expr)); | |
1323 | ||
1324 | #ifdef LTO_STREAMER_DEBUG | |
1325 | /* Remove the mapping to RESULT's original address set by | |
1326 | streamer_alloc_tree. */ | |
1327 | lto_orig_address_remove (expr); | |
1328 | #endif | |
1329 | } | |
1330 | ||
515cf651 | 1331 | /* Read the physical representation of a tree node with tag TAG from |
1332 | input block IB using the per-file context in DATA_IN. */ | |
7bfefa9d | 1333 | |
515cf651 | 1334 | static tree |
1335 | lto_read_tree (struct lto_input_block *ib, struct data_in *data_in, | |
8ceff600 | 1336 | enum LTO_tags tag, hashval_t hash) |
a0605d65 | 1337 | { |
515cf651 | 1338 | /* Instantiate a new tree node. */ |
7f385784 | 1339 | tree result = streamer_alloc_tree (ib, data_in, tag); |
515cf651 | 1340 | |
1341 | /* Enter RESULT in the reader cache. This will make RESULT | |
1342 | available so that circular references in the rest of the tree | |
1343 | structure can be resolved in subsequent calls to stream_read_tree. */ | |
8ceff600 | 1344 | streamer_tree_cache_append (data_in->reader_cache, result, hash); |
515cf651 | 1345 | |
8ceff600 | 1346 | lto_read_tree_1 (ib, data_in, result); |
515cf651 | 1347 | |
8ceff600 | 1348 | /* end_marker = */ streamer_read_uchar (ib); |
515cf651 | 1349 | |
8ceff600 | 1350 | return result; |
1351 | } | |
515cf651 | 1352 | |
515cf651 | 1353 | |
8ceff600 | 1354 | /* Populate the reader cache with trees materialized from the SCC |
1355 | following in the IB, DATA_IN stream. */ | |
515cf651 | 1356 | |
8ceff600 | 1357 | hashval_t |
1358 | lto_input_scc (struct lto_input_block *ib, struct data_in *data_in, | |
1359 | unsigned *len, unsigned *entry_len) | |
1360 | { | |
1361 | /* A blob of unnamed tree nodes, fill the cache from it and | |
1362 | recurse. */ | |
1363 | unsigned size = streamer_read_uhwi (ib); | |
1364 | hashval_t scc_hash = streamer_read_uhwi (ib); | |
1365 | unsigned scc_entry_len = 1; | |
515cf651 | 1366 | |
8ceff600 | 1367 | if (size == 1) |
1368 | { | |
1369 | enum LTO_tags tag = streamer_read_record_start (ib); | |
1370 | lto_input_tree_1 (ib, data_in, tag, scc_hash); | |
1371 | } | |
1372 | else | |
1373 | { | |
1374 | unsigned int first = data_in->reader_cache->nodes.length (); | |
1375 | tree result; | |
1376 | ||
1377 | scc_entry_len = streamer_read_uhwi (ib); | |
1378 | ||
1379 | /* Materialize size trees by reading their headers. */ | |
1380 | for (unsigned i = 0; i < size; ++i) | |
1381 | { | |
1382 | enum LTO_tags tag = streamer_read_record_start (ib); | |
1383 | if (tag == LTO_null | |
1384 | || (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref) | |
1385 | || tag == LTO_tree_pickle_reference | |
1386 | || tag == LTO_builtin_decl | |
1387 | || tag == LTO_integer_cst | |
1388 | || tag == LTO_tree_scc) | |
1389 | gcc_unreachable (); | |
1390 | ||
1391 | result = streamer_alloc_tree (ib, data_in, tag); | |
1392 | streamer_tree_cache_append (data_in->reader_cache, result, 0); | |
1393 | } | |
1394 | ||
1395 | /* Read the tree bitpacks and references. */ | |
1396 | for (unsigned i = 0; i < size; ++i) | |
1397 | { | |
1398 | result = streamer_tree_cache_get_tree (data_in->reader_cache, | |
1399 | first + i); | |
1400 | lto_read_tree_1 (ib, data_in, result); | |
1401 | /* end_marker = */ streamer_read_uchar (ib); | |
1402 | } | |
1403 | } | |
1404 | ||
1405 | *len = size; | |
1406 | *entry_len = scc_entry_len; | |
1407 | return scc_hash; | |
515cf651 | 1408 | } |
1409 | ||
1410 | ||
1411 | /* Read a tree from input block IB using the per-file context in | |
1412 | DATA_IN. This context is used, for example, to resolve references | |
1413 | to previously read nodes. */ | |
1414 | ||
1415 | tree | |
8ceff600 | 1416 | lto_input_tree_1 (struct lto_input_block *ib, struct data_in *data_in, |
1417 | enum LTO_tags tag, hashval_t hash) | |
515cf651 | 1418 | { |
515cf651 | 1419 | tree result; |
1420 | ||
515cf651 | 1421 | gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS); |
1422 | ||
1423 | if (tag == LTO_null) | |
1424 | result = NULL_TREE; | |
c40a5c1b | 1425 | else if (tag >= LTO_field_decl_ref && tag <= LTO_namelist_decl_ref) |
515cf651 | 1426 | { |
1427 | /* If TAG is a reference to an indexable tree, the next value | |
1428 | in IB is the index into the table where we expect to find | |
1429 | that tree. */ | |
1430 | result = lto_input_tree_ref (ib, data_in, cfun, tag); | |
1431 | } | |
1432 | else if (tag == LTO_tree_pickle_reference) | |
1433 | { | |
1434 | /* If TAG is a reference to a previously read tree, look it up in | |
1435 | the reader cache. */ | |
7f385784 | 1436 | result = streamer_get_pickled_tree (ib, data_in); |
515cf651 | 1437 | } |
1438 | else if (tag == LTO_builtin_decl) | |
1439 | { | |
1440 | /* If we are going to read a built-in function, all we need is | |
1441 | the code and class. */ | |
7f385784 | 1442 | result = streamer_get_builtin_tree (ib, data_in); |
515cf651 | 1443 | } |
42603940 | 1444 | else if (tag == LTO_integer_cst) |
515cf651 | 1445 | { |
e913b5cd | 1446 | /* For shared integer constants in singletons we can use the |
1447 | existing tree integer constant merging code. */ | |
8ceff600 | 1448 | tree type = stream_read_tree (ib, data_in); |
e913b5cd | 1449 | unsigned HOST_WIDE_INT len = streamer_read_uhwi (ib); |
1450 | unsigned HOST_WIDE_INT i; | |
ddb1be65 | 1451 | HOST_WIDE_INT a[WIDE_INT_MAX_ELTS]; |
e913b5cd | 1452 | |
1453 | for (i = 0; i < len; i++) | |
1454 | a[i] = streamer_read_hwi (ib); | |
a12aa4cc | 1455 | gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT); |
e913b5cd | 1456 | result = wide_int_to_tree (type, wide_int::from_array |
05363b4a | 1457 | (a, len, TYPE_PRECISION (type))); |
8ceff600 | 1458 | streamer_tree_cache_append (data_in->reader_cache, result, hash); |
1459 | } | |
1460 | else if (tag == LTO_tree_scc) | |
5510bd70 | 1461 | gcc_unreachable (); |
515cf651 | 1462 | else |
1463 | { | |
1464 | /* Otherwise, materialize a new node from IB. */ | |
8ceff600 | 1465 | result = lto_read_tree (ib, data_in, tag, hash); |
515cf651 | 1466 | } |
1467 | ||
1468 | return result; | |
a0605d65 | 1469 | } |
1470 | ||
8ceff600 | 1471 | tree |
1472 | lto_input_tree (struct lto_input_block *ib, struct data_in *data_in) | |
1473 | { | |
5510bd70 | 1474 | enum LTO_tags tag; |
1475 | ||
1476 | /* Input and skip SCCs. */ | |
1477 | while ((tag = streamer_read_record_start (ib)) == LTO_tree_scc) | |
1478 | { | |
1479 | unsigned len, entry_len; | |
1480 | lto_input_scc (ib, data_in, &len, &entry_len); | |
1481 | } | |
1482 | return lto_input_tree_1 (ib, data_in, tag, 0); | |
8ceff600 | 1483 | } |
1484 | ||
a0605d65 | 1485 | |
65d1b157 | 1486 | /* Input toplevel asms. */ |
1487 | ||
1488 | void | |
f1007c72 | 1489 | lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base) |
65d1b157 | 1490 | { |
1491 | size_t len; | |
1492 | const char *data = lto_get_section_data (file_data, LTO_section_asm, | |
1493 | NULL, &len); | |
472ca566 | 1494 | const struct lto_simple_header_with_strings *header |
1495 | = (const struct lto_simple_header_with_strings *) data; | |
949e5786 | 1496 | int string_offset; |
65d1b157 | 1497 | struct data_in *data_in; |
65d1b157 | 1498 | tree str; |
1499 | ||
1500 | if (! data) | |
1501 | return; | |
1502 | ||
1503 | string_offset = sizeof (*header) + header->main_size; | |
1504 | ||
2e971afd | 1505 | lto_input_block ib (data + sizeof (*header), header->main_size, |
1506 | file_data->mode_table); | |
65d1b157 | 1507 | |
1508 | data_in = lto_data_in_create (file_data, data + string_offset, | |
1e094109 | 1509 | header->string_size, vNULL); |
65d1b157 | 1510 | |
65d1b157 | 1511 | while ((str = streamer_read_string_cst (data_in, &ib))) |
f1007c72 | 1512 | { |
35ee1c66 | 1513 | asm_node *node = symtab->finalize_toplevel_asm (str); |
f1007c72 | 1514 | node->order = streamer_read_hwi (&ib) + order_base; |
35ee1c66 | 1515 | if (node->order >= symtab->order) |
1516 | symtab->order = node->order + 1; | |
f1007c72 | 1517 | } |
65d1b157 | 1518 | |
65d1b157 | 1519 | lto_data_in_delete (data_in); |
1520 | ||
1521 | lto_free_section_data (file_data, LTO_section_asm, NULL, data, len); | |
1522 | } | |
1523 | ||
1524 | ||
2e971afd | 1525 | /* Input mode table. */ |
1526 | ||
1527 | void | |
1528 | lto_input_mode_table (struct lto_file_decl_data *file_data) | |
1529 | { | |
1530 | size_t len; | |
1531 | const char *data = lto_get_section_data (file_data, LTO_section_mode_table, | |
1532 | NULL, &len); | |
1533 | if (! data) | |
1534 | { | |
1535 | internal_error ("cannot read LTO mode table from %s", | |
1536 | file_data->file_name); | |
1537 | return; | |
1538 | } | |
1539 | ||
1540 | unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << 8); | |
1541 | file_data->mode_table = table; | |
1542 | const struct lto_simple_header_with_strings *header | |
1543 | = (const struct lto_simple_header_with_strings *) data; | |
1544 | int string_offset; | |
1545 | struct data_in *data_in; | |
1546 | string_offset = sizeof (*header) + header->main_size; | |
1547 | ||
1548 | lto_input_block ib (data + sizeof (*header), header->main_size, NULL); | |
1549 | data_in = lto_data_in_create (file_data, data + string_offset, | |
1550 | header->string_size, vNULL); | |
1551 | bitpack_d bp = streamer_read_bitpack (&ib); | |
1552 | ||
1553 | table[VOIDmode] = VOIDmode; | |
1554 | table[BLKmode] = BLKmode; | |
1555 | unsigned int m; | |
1556 | while ((m = bp_unpack_value (&bp, 8)) != VOIDmode) | |
1557 | { | |
1558 | enum mode_class mclass | |
1559 | = bp_unpack_enum (&bp, mode_class, MAX_MODE_CLASS); | |
1560 | unsigned int size = bp_unpack_value (&bp, 8); | |
1561 | unsigned int prec = bp_unpack_value (&bp, 16); | |
1562 | machine_mode inner = (machine_mode) table[bp_unpack_value (&bp, 8)]; | |
1563 | unsigned int nunits = bp_unpack_value (&bp, 8); | |
1564 | unsigned int ibit = 0, fbit = 0; | |
1565 | unsigned int real_fmt_len = 0; | |
1566 | const char *real_fmt_name = NULL; | |
1567 | switch (mclass) | |
1568 | { | |
1569 | case MODE_FRACT: | |
1570 | case MODE_UFRACT: | |
1571 | case MODE_ACCUM: | |
1572 | case MODE_UACCUM: | |
1573 | ibit = bp_unpack_value (&bp, 8); | |
1574 | fbit = bp_unpack_value (&bp, 8); | |
1575 | break; | |
1576 | case MODE_FLOAT: | |
1577 | case MODE_DECIMAL_FLOAT: | |
1578 | real_fmt_name = bp_unpack_indexed_string (data_in, &bp, | |
1579 | &real_fmt_len); | |
1580 | break; | |
1581 | default: | |
1582 | break; | |
1583 | } | |
1584 | /* First search just the GET_CLASS_NARROWEST_MODE to wider modes, | |
1585 | if not found, fallback to all modes. */ | |
1586 | int pass; | |
1587 | for (pass = 0; pass < 2; pass++) | |
1588 | for (machine_mode mr = pass ? VOIDmode | |
1589 | : GET_CLASS_NARROWEST_MODE (mclass); | |
1590 | pass ? mr < MAX_MACHINE_MODE : mr != VOIDmode; | |
1591 | pass ? mr = (machine_mode) (m + 1) | |
1592 | : mr = GET_MODE_WIDER_MODE (mr)) | |
1593 | if (GET_MODE_CLASS (mr) != mclass | |
1594 | || GET_MODE_SIZE (mr) != size | |
1595 | || GET_MODE_PRECISION (mr) != prec | |
1596 | || GET_MODE_INNER (mr) != inner | |
1597 | || GET_MODE_IBIT (mr) != ibit | |
1598 | || GET_MODE_FBIT (mr) != fbit | |
1599 | || GET_MODE_NUNITS (mr) != nunits) | |
1600 | continue; | |
1601 | else if ((mclass == MODE_FLOAT || mclass == MODE_DECIMAL_FLOAT) | |
1602 | && strcmp (REAL_MODE_FORMAT (mr)->name, real_fmt_name) != 0) | |
1603 | continue; | |
1604 | else | |
1605 | { | |
1606 | table[m] = mr; | |
1607 | pass = 2; | |
1608 | break; | |
1609 | } | |
1610 | unsigned int mname_len; | |
1611 | const char *mname = bp_unpack_indexed_string (data_in, &bp, &mname_len); | |
1612 | if (pass == 2) | |
1613 | { | |
1614 | switch (mclass) | |
1615 | { | |
1616 | case MODE_VECTOR_INT: | |
1617 | case MODE_VECTOR_FLOAT: | |
1618 | case MODE_VECTOR_FRACT: | |
1619 | case MODE_VECTOR_UFRACT: | |
1620 | case MODE_VECTOR_ACCUM: | |
1621 | case MODE_VECTOR_UACCUM: | |
1622 | /* For unsupported vector modes just use BLKmode, | |
1623 | if the scalar mode is supported. */ | |
1624 | if (inner != VOIDmode) | |
1625 | { | |
1626 | table[m] = BLKmode; | |
1627 | break; | |
1628 | } | |
1629 | /* FALLTHRU */ | |
1630 | default: | |
1631 | fatal_error (UNKNOWN_LOCATION, "unsupported mode %s\n", mname); | |
1632 | break; | |
1633 | } | |
1634 | } | |
1635 | } | |
1636 | lto_data_in_delete (data_in); | |
1637 | ||
1638 | lto_free_section_data (file_data, LTO_section_mode_table, NULL, data, len); | |
1639 | } | |
1640 | ||
1641 | ||
7bfefa9d | 1642 | /* Initialization for the LTO reader. */ |
1643 | ||
1644 | void | |
a0605d65 | 1645 | lto_reader_init (void) |
7bfefa9d | 1646 | { |
1647 | lto_streamer_init (); | |
c1f445d2 | 1648 | file_name_hash_table |
1649 | = new hash_table<freeing_string_slot_hasher> (37); | |
7bfefa9d | 1650 | } |
1651 | ||
1652 | ||
1653 | /* Create a new data_in object for FILE_DATA. STRINGS is the string | |
1654 | table to use with LEN strings. RESOLUTIONS is the vector of linker | |
1655 | resolutions (NULL if not using a linker plugin). */ | |
1656 | ||
1657 | struct data_in * | |
1658 | lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings, | |
1659 | unsigned len, | |
f1f41a6c | 1660 | vec<ld_plugin_symbol_resolution_t> resolutions) |
7bfefa9d | 1661 | { |
da6f3259 | 1662 | struct data_in *data_in = new (struct data_in); |
7bfefa9d | 1663 | data_in->file_data = file_data; |
1664 | data_in->strings = strings; | |
1665 | data_in->strings_len = len; | |
1666 | data_in->globals_resolution = resolutions; | |
b1e946ea | 1667 | data_in->reader_cache = streamer_tree_cache_create (false, false, true); |
7bfefa9d | 1668 | return data_in; |
1669 | } | |
1670 | ||
1671 | ||
1672 | /* Remove DATA_IN. */ | |
1673 | ||
1674 | void | |
1675 | lto_data_in_delete (struct data_in *data_in) | |
1676 | { | |
f1f41a6c | 1677 | data_in->globals_resolution.release (); |
7f385784 | 1678 | streamer_tree_cache_delete (data_in->reader_cache); |
da6f3259 | 1679 | delete data_in; |
7bfefa9d | 1680 | } |