jit: document union types
[official-gcc.git] / gcc / lto-streamer-in.c
blob66298ec54a4282035633f7d6df80d9a87fe52020
1 /* Read the GIMPLE representation from a file stream.
3 Copyright (C) 2009-2015 Free Software Foundation, Inc.
4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 Re-implemented by Diego Novillo <dnovillo@google.com>
7 This file is part of GCC.
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.
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.
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/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "toplev.h"
28 #include "alias.h"
29 #include "symtab.h"
30 #include "tree.h"
31 #include "fold-const.h"
32 #include "stringpool.h"
33 #include "hard-reg-set.h"
34 #include "function.h"
35 #include "rtl.h"
36 #include "flags.h"
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"
46 #include "params.h"
47 #include "predict.h"
48 #include "dominance.h"
49 #include "cfg.h"
50 #include "basic-block.h"
51 #include "tree-ssa-alias.h"
52 #include "internal-fn.h"
53 #include "gimple-expr.h"
54 #include "gimple.h"
55 #include "gimple-iterator.h"
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"
61 #include "tree-ssa.h"
62 #include "tree-pass.h"
63 #include "diagnostic.h"
64 #include "except.h"
65 #include "debug.h"
66 #include "cgraph.h"
67 #include "ipa-utils.h"
68 #include "data-streamer.h"
69 #include "gimple-streamer.h"
70 #include "lto-streamer.h"
71 #include "tree-streamer.h"
72 #include "streamer-hooks.h"
73 #include "cfgloop.h"
76 struct freeing_string_slot_hasher : string_slot_hasher
78 static inline void remove (value_type *);
81 inline void
82 freeing_string_slot_hasher::remove (value_type *v)
84 free (v);
87 /* The table to hold the file names. */
88 static hash_table<freeing_string_slot_hasher> *file_name_hash_table;
91 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
92 number of valid tag values to check. */
94 void
95 lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
97 va_list ap;
98 int i;
100 va_start (ap, ntags);
101 for (i = 0; i < ntags; i++)
102 if ((unsigned) actual == va_arg (ap, unsigned))
104 va_end (ap);
105 return;
108 va_end (ap);
109 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
113 /* Read LENGTH bytes from STREAM to ADDR. */
115 void
116 lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length)
118 size_t i;
119 unsigned char *const buffer = (unsigned char *const) addr;
121 for (i = 0; i < length; i++)
122 buffer[i] = streamer_read_uchar (ib);
126 /* Lookup STRING in file_name_hash_table. If found, return the existing
127 string, otherwise insert STRING as the canonical version. */
129 static const char *
130 canon_file_name (const char *string)
132 string_slot **slot;
133 struct string_slot s_slot;
134 size_t len = strlen (string);
136 s_slot.s = string;
137 s_slot.len = len;
139 slot = file_name_hash_table->find_slot (&s_slot, INSERT);
140 if (*slot == NULL)
142 char *saved_string;
143 struct string_slot *new_slot;
145 saved_string = (char *) xmalloc (len + 1);
146 new_slot = XCNEW (struct string_slot);
147 memcpy (saved_string, string, len + 1);
148 new_slot->s = saved_string;
149 new_slot->len = len;
150 *slot = new_slot;
151 return saved_string;
153 else
155 struct string_slot *old_slot = *slot;
156 return old_slot->s;
160 /* Pointer to currently alive instance of lto_location_cache. */
162 lto_location_cache *lto_location_cache::current_cache;
164 /* Sort locations in source order. Start with file from last application. */
167 lto_location_cache::cmp_loc (const void *pa, const void *pb)
169 const cached_location *a = ((const cached_location *)pa);
170 const cached_location *b = ((const cached_location *)pb);
171 const char *current_file = current_cache->current_file;
172 int current_line = current_cache->current_line;
174 if (a->file == current_file && b->file != current_file)
175 return -1;
176 if (a->file != current_file && b->file == current_file)
177 return 1;
178 if (a->file == current_file && b->file == current_file)
180 if (a->line == current_line && b->line != current_line)
181 return -1;
182 if (a->line != current_line && b->line == current_line)
183 return 1;
185 if (a->file != b->file)
186 return strcmp (a->file, b->file);
187 if (a->line != b->line)
188 return a->line - b->line;
189 return a->col - b->col;
192 /* Apply all changes in location cache. Add locations into linemap and patch
193 trees. */
195 bool
196 lto_location_cache::apply_location_cache ()
198 static const char *prev_file;
199 if (!loc_cache.length ())
200 return false;
201 if (loc_cache.length () > 1)
202 loc_cache.qsort (cmp_loc);
204 for (unsigned int i = 0; i < loc_cache.length (); i++)
206 struct cached_location loc = loc_cache[i];
208 if (current_file != loc.file)
209 linemap_add (line_table, prev_file ? LC_RENAME : LC_ENTER,
210 false, loc.file, loc.line);
211 else if (current_line != loc.line)
213 int max = loc.col;
215 for (unsigned int j = i + 1; j < loc_cache.length (); j++)
216 if (loc.file != loc_cache[j].file
217 || loc.line != loc_cache[j].line)
218 break;
219 else if (max < loc_cache[j].col)
220 max = loc_cache[j].col;
221 linemap_line_start (line_table, loc.line, max + 1);
223 gcc_assert (*loc.loc == BUILTINS_LOCATION + 1);
224 if (current_file == loc.file && current_line == loc.line
225 && current_col == loc.col)
226 *loc.loc = current_loc;
227 else
228 current_loc = *loc.loc = linemap_position_for_column (line_table,
229 loc.col);
230 current_line = loc.line;
231 prev_file = current_file = loc.file;
232 current_col = loc.col;
234 loc_cache.truncate (0);
235 accepted_length = 0;
236 return true;
239 /* Tree merging did not suceed; mark all changes in the cache as accepted. */
241 void
242 lto_location_cache::accept_location_cache ()
244 gcc_assert (current_cache == this);
245 accepted_length = loc_cache.length ();
248 /* Tree merging did suceed; throw away recent changes. */
250 void
251 lto_location_cache::revert_location_cache ()
253 loc_cache.truncate (accepted_length);
256 /* Read a location bitpack from input block IB and either update *LOC directly
257 or add it to the location cache.
258 It is neccesary to call apply_location_cache to get *LOC updated. */
260 void
261 lto_location_cache::input_location (location_t *loc, struct bitpack_d *bp,
262 struct data_in *data_in)
264 static const char *stream_file;
265 static int stream_line;
266 static int stream_col;
267 bool file_change, line_change, column_change;
269 gcc_assert (current_cache == this);
271 *loc = bp_unpack_int_in_range (bp, "location", 0, RESERVED_LOCATION_COUNT);
273 if (*loc < RESERVED_LOCATION_COUNT)
274 return;
276 /* Keep value RESERVED_LOCATION_COUNT in *loc as linemap lookups will
277 ICE on it. */
279 file_change = bp_unpack_value (bp, 1);
280 line_change = bp_unpack_value (bp, 1);
281 column_change = bp_unpack_value (bp, 1);
283 if (file_change)
284 stream_file = canon_file_name (bp_unpack_string (data_in, bp));
286 if (line_change)
287 stream_line = bp_unpack_var_len_unsigned (bp);
289 if (column_change)
290 stream_col = bp_unpack_var_len_unsigned (bp);
292 /* This optimization saves location cache operations druing gimple
293 streaming. */
295 if (current_file == stream_file && current_line == stream_line
296 && current_col == stream_col)
298 *loc = current_loc;
299 return;
302 struct cached_location entry = {stream_file, loc, stream_line, stream_col};
303 loc_cache.safe_push (entry);
306 /* Read a location bitpack from input block IB and either update *LOC directly
307 or add it to the location cache.
308 It is neccesary to call apply_location_cache to get *LOC updated. */
310 void
311 lto_input_location (location_t *loc, struct bitpack_d *bp,
312 struct data_in *data_in)
314 data_in->location_cache.input_location (loc, bp, data_in);
317 /* Read location and return it instead of going through location caching.
318 This should be used only when the resulting location is not going to be
319 discarded. */
321 location_t
322 stream_input_location_now (struct bitpack_d *bp, struct data_in *data_in)
324 location_t loc;
325 stream_input_location (&loc, bp, data_in);
326 data_in->location_cache.apply_location_cache ();
327 return loc;
330 /* Read a reference to a tree node from DATA_IN using input block IB.
331 TAG is the expected node that should be found in IB, if TAG belongs
332 to one of the indexable trees, expect to read a reference index to
333 be looked up in one of the symbol tables, otherwise read the pysical
334 representation of the tree using stream_read_tree. FN is the
335 function scope for the read tree. */
337 tree
338 lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in,
339 struct function *fn, enum LTO_tags tag)
341 unsigned HOST_WIDE_INT ix_u;
342 tree result = NULL_TREE;
344 lto_tag_check_range (tag, LTO_field_decl_ref, LTO_namelist_decl_ref);
346 switch (tag)
348 case LTO_type_ref:
349 ix_u = streamer_read_uhwi (ib);
350 result = lto_file_decl_data_get_type (data_in->file_data, ix_u);
351 break;
353 case LTO_ssa_name_ref:
354 ix_u = streamer_read_uhwi (ib);
355 result = (*SSANAMES (fn))[ix_u];
356 break;
358 case LTO_field_decl_ref:
359 ix_u = streamer_read_uhwi (ib);
360 result = lto_file_decl_data_get_field_decl (data_in->file_data, ix_u);
361 break;
363 case LTO_function_decl_ref:
364 ix_u = streamer_read_uhwi (ib);
365 result = lto_file_decl_data_get_fn_decl (data_in->file_data, ix_u);
366 break;
368 case LTO_type_decl_ref:
369 ix_u = streamer_read_uhwi (ib);
370 result = lto_file_decl_data_get_type_decl (data_in->file_data, ix_u);
371 break;
373 case LTO_namespace_decl_ref:
374 ix_u = streamer_read_uhwi (ib);
375 result = lto_file_decl_data_get_namespace_decl (data_in->file_data, ix_u);
376 break;
378 case LTO_global_decl_ref:
379 case LTO_result_decl_ref:
380 case LTO_const_decl_ref:
381 case LTO_imported_decl_ref:
382 case LTO_label_decl_ref:
383 case LTO_translation_unit_decl_ref:
384 case LTO_namelist_decl_ref:
385 ix_u = streamer_read_uhwi (ib);
386 result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u);
387 break;
389 default:
390 gcc_unreachable ();
393 gcc_assert (result);
395 return result;
399 /* Read and return a double-linked list of catch handlers from input
400 block IB, using descriptors in DATA_IN. */
402 static struct eh_catch_d *
403 lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in,
404 eh_catch *last_p)
406 eh_catch first;
407 enum LTO_tags tag;
409 *last_p = first = NULL;
410 tag = streamer_read_record_start (ib);
411 while (tag)
413 tree list;
414 eh_catch n;
416 lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
418 /* Read the catch node. */
419 n = ggc_cleared_alloc<eh_catch_d> ();
420 n->type_list = stream_read_tree (ib, data_in);
421 n->filter_list = stream_read_tree (ib, data_in);
422 n->label = stream_read_tree (ib, data_in);
424 /* Register all the types in N->FILTER_LIST. */
425 for (list = n->filter_list; list; list = TREE_CHAIN (list))
426 add_type_for_runtime (TREE_VALUE (list));
428 /* Chain N to the end of the list. */
429 if (*last_p)
430 (*last_p)->next_catch = n;
431 n->prev_catch = *last_p;
432 *last_p = n;
434 /* Set the head of the list the first time through the loop. */
435 if (first == NULL)
436 first = n;
438 tag = streamer_read_record_start (ib);
441 return first;
445 /* Read and return EH region IX from input block IB, using descriptors
446 in DATA_IN. */
448 static eh_region
449 input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
451 enum LTO_tags tag;
452 eh_region r;
454 /* Read the region header. */
455 tag = streamer_read_record_start (ib);
456 if (tag == LTO_null)
457 return NULL;
459 r = ggc_cleared_alloc<eh_region_d> ();
460 r->index = streamer_read_hwi (ib);
462 gcc_assert (r->index == ix);
464 /* Read all the region pointers as region numbers. We'll fix up
465 the pointers once the whole array has been read. */
466 r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib);
467 r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib);
468 r->next_peer = (eh_region) (intptr_t) streamer_read_hwi (ib);
470 switch (tag)
472 case LTO_ert_cleanup:
473 r->type = ERT_CLEANUP;
474 break;
476 case LTO_ert_try:
478 struct eh_catch_d *last_catch;
479 r->type = ERT_TRY;
480 r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
481 &last_catch);
482 r->u.eh_try.last_catch = last_catch;
483 break;
486 case LTO_ert_allowed_exceptions:
488 tree l;
490 r->type = ERT_ALLOWED_EXCEPTIONS;
491 r->u.allowed.type_list = stream_read_tree (ib, data_in);
492 r->u.allowed.label = stream_read_tree (ib, data_in);
493 r->u.allowed.filter = streamer_read_uhwi (ib);
495 for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
496 add_type_for_runtime (TREE_VALUE (l));
498 break;
500 case LTO_ert_must_not_throw:
502 r->type = ERT_MUST_NOT_THROW;
503 r->u.must_not_throw.failure_decl = stream_read_tree (ib, data_in);
504 bitpack_d bp = streamer_read_bitpack (ib);
505 r->u.must_not_throw.failure_loc
506 = stream_input_location_now (&bp, data_in);
508 break;
510 default:
511 gcc_unreachable ();
514 r->landing_pads = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
516 return r;
520 /* Read and return EH landing pad IX from input block IB, using descriptors
521 in DATA_IN. */
523 static eh_landing_pad
524 input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix)
526 enum LTO_tags tag;
527 eh_landing_pad lp;
529 /* Read the landing pad header. */
530 tag = streamer_read_record_start (ib);
531 if (tag == LTO_null)
532 return NULL;
534 lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
536 lp = ggc_cleared_alloc<eh_landing_pad_d> ();
537 lp->index = streamer_read_hwi (ib);
538 gcc_assert (lp->index == ix);
539 lp->next_lp = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
540 lp->region = (eh_region) (intptr_t) streamer_read_hwi (ib);
541 lp->post_landing_pad = stream_read_tree (ib, data_in);
543 return lp;
547 /* After reading the EH regions, pointers to peer and children regions
548 are region numbers. This converts all these region numbers into
549 real pointers into the rematerialized regions for FN. ROOT_REGION
550 is the region number for the root EH region in FN. */
552 static void
553 fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
555 unsigned i;
556 vec<eh_region, va_gc> *eh_array = fn->eh->region_array;
557 vec<eh_landing_pad, va_gc> *lp_array = fn->eh->lp_array;
558 eh_region r;
559 eh_landing_pad lp;
561 gcc_assert (eh_array && lp_array);
563 gcc_assert (root_region >= 0);
564 fn->eh->region_tree = (*eh_array)[root_region];
566 #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)]
567 #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)]
569 /* Convert all the index numbers stored in pointer fields into
570 pointers to the corresponding slots in the EH region array. */
571 FOR_EACH_VEC_ELT (*eh_array, i, r)
573 /* The array may contain NULL regions. */
574 if (r == NULL)
575 continue;
577 gcc_assert (i == (unsigned) r->index);
578 FIXUP_EH_REGION (r->outer);
579 FIXUP_EH_REGION (r->inner);
580 FIXUP_EH_REGION (r->next_peer);
581 FIXUP_EH_LP (r->landing_pads);
584 /* Convert all the index numbers stored in pointer fields into
585 pointers to the corresponding slots in the EH landing pad array. */
586 FOR_EACH_VEC_ELT (*lp_array, i, lp)
588 /* The array may contain NULL landing pads. */
589 if (lp == NULL)
590 continue;
592 gcc_assert (i == (unsigned) lp->index);
593 FIXUP_EH_LP (lp->next_lp);
594 FIXUP_EH_REGION (lp->region);
597 #undef FIXUP_EH_REGION
598 #undef FIXUP_EH_LP
602 /* Initialize EH support. */
604 void
605 lto_init_eh (void)
607 static bool eh_initialized_p = false;
609 if (eh_initialized_p)
610 return;
612 /* Contrary to most other FEs, we only initialize EH support when at
613 least one of the files in the set contains exception regions in
614 it. Since this happens much later than the call to init_eh in
615 lang_dependent_init, we have to set flag_exceptions and call
616 init_eh again to initialize the EH tables. */
617 flag_exceptions = 1;
618 init_eh ();
620 eh_initialized_p = true;
624 /* Read the exception table for FN from IB using the data descriptors
625 in DATA_IN. */
627 static void
628 input_eh_regions (struct lto_input_block *ib, struct data_in *data_in,
629 struct function *fn)
631 HOST_WIDE_INT i, root_region, len;
632 enum LTO_tags tag;
634 tag = streamer_read_record_start (ib);
635 if (tag == LTO_null)
636 return;
638 lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
640 /* If the file contains EH regions, then it was compiled with
641 -fexceptions. In that case, initialize the backend EH
642 machinery. */
643 lto_init_eh ();
645 gcc_assert (fn->eh);
647 root_region = streamer_read_hwi (ib);
648 gcc_assert (root_region == (int) root_region);
650 /* Read the EH region array. */
651 len = streamer_read_hwi (ib);
652 gcc_assert (len == (int) len);
653 if (len > 0)
655 vec_safe_grow_cleared (fn->eh->region_array, len);
656 for (i = 0; i < len; i++)
658 eh_region r = input_eh_region (ib, data_in, i);
659 (*fn->eh->region_array)[i] = r;
663 /* Read the landing pads. */
664 len = streamer_read_hwi (ib);
665 gcc_assert (len == (int) len);
666 if (len > 0)
668 vec_safe_grow_cleared (fn->eh->lp_array, len);
669 for (i = 0; i < len; i++)
671 eh_landing_pad lp = input_eh_lp (ib, data_in, i);
672 (*fn->eh->lp_array)[i] = lp;
676 /* Read the runtime type data. */
677 len = streamer_read_hwi (ib);
678 gcc_assert (len == (int) len);
679 if (len > 0)
681 vec_safe_grow_cleared (fn->eh->ttype_data, len);
682 for (i = 0; i < len; i++)
684 tree ttype = stream_read_tree (ib, data_in);
685 (*fn->eh->ttype_data)[i] = ttype;
689 /* Read the table of action chains. */
690 len = streamer_read_hwi (ib);
691 gcc_assert (len == (int) len);
692 if (len > 0)
694 if (targetm.arm_eabi_unwinder)
696 vec_safe_grow_cleared (fn->eh->ehspec_data.arm_eabi, len);
697 for (i = 0; i < len; i++)
699 tree t = stream_read_tree (ib, data_in);
700 (*fn->eh->ehspec_data.arm_eabi)[i] = t;
703 else
705 vec_safe_grow_cleared (fn->eh->ehspec_data.other, len);
706 for (i = 0; i < len; i++)
708 uchar c = streamer_read_uchar (ib);
709 (*fn->eh->ehspec_data.other)[i] = c;
714 /* Reconstruct the EH region tree by fixing up the peer/children
715 pointers. */
716 fixup_eh_region_pointers (fn, root_region);
718 tag = streamer_read_record_start (ib);
719 lto_tag_check_range (tag, LTO_null, LTO_null);
723 /* Make a new basic block with index INDEX in function FN. */
725 static basic_block
726 make_new_block (struct function *fn, unsigned int index)
728 basic_block bb = alloc_block ();
729 bb->index = index;
730 SET_BASIC_BLOCK_FOR_FN (fn, index, bb);
731 n_basic_blocks_for_fn (fn)++;
732 return bb;
736 /* Read a wide-int. */
738 static widest_int
739 streamer_read_wi (struct lto_input_block *ib)
741 HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
742 int i;
743 int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
744 int len = streamer_read_uhwi (ib);
745 for (i = 0; i < len; i++)
746 a[i] = streamer_read_hwi (ib);
747 return widest_int::from_array (a, len);
751 /* Read the CFG for function FN from input block IB. */
753 static void
754 input_cfg (struct lto_input_block *ib, struct data_in *data_in,
755 struct function *fn,
756 int count_materialization_scale)
758 unsigned int bb_count;
759 basic_block p_bb;
760 unsigned int i;
761 int index;
763 init_empty_tree_cfg_for_function (fn);
764 init_ssa_operands (fn);
766 profile_status_for_fn (fn) = streamer_read_enum (ib, profile_status_d,
767 PROFILE_LAST);
769 bb_count = streamer_read_uhwi (ib);
771 last_basic_block_for_fn (fn) = bb_count;
772 if (bb_count > basic_block_info_for_fn (fn)->length ())
773 vec_safe_grow_cleared (basic_block_info_for_fn (fn), bb_count);
775 if (bb_count > label_to_block_map_for_fn (fn)->length ())
776 vec_safe_grow_cleared (label_to_block_map_for_fn (fn), bb_count);
778 index = streamer_read_hwi (ib);
779 while (index != -1)
781 basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
782 unsigned int edge_count;
784 if (bb == NULL)
785 bb = make_new_block (fn, index);
787 edge_count = streamer_read_uhwi (ib);
789 /* Connect up the CFG. */
790 for (i = 0; i < edge_count; i++)
792 unsigned int dest_index;
793 unsigned int edge_flags;
794 basic_block dest;
795 int probability;
796 gcov_type count;
797 edge e;
799 dest_index = streamer_read_uhwi (ib);
800 probability = (int) streamer_read_hwi (ib);
801 count = apply_scale ((gcov_type) streamer_read_gcov_count (ib),
802 count_materialization_scale);
803 edge_flags = streamer_read_uhwi (ib);
805 dest = BASIC_BLOCK_FOR_FN (fn, dest_index);
807 if (dest == NULL)
808 dest = make_new_block (fn, dest_index);
810 e = make_edge (bb, dest, edge_flags);
811 e->probability = probability;
812 e->count = count;
815 index = streamer_read_hwi (ib);
818 p_bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
819 index = streamer_read_hwi (ib);
820 while (index != -1)
822 basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
823 bb->prev_bb = p_bb;
824 p_bb->next_bb = bb;
825 p_bb = bb;
826 index = streamer_read_hwi (ib);
829 /* ??? The cfgloop interface is tied to cfun. */
830 gcc_assert (cfun == fn);
832 /* Input the loop tree. */
833 unsigned n_loops = streamer_read_uhwi (ib);
834 if (n_loops == 0)
835 return;
837 struct loops *loops = ggc_cleared_alloc<struct loops> ();
838 init_loops_structure (fn, loops, n_loops);
839 set_loops_for_fn (fn, loops);
841 /* Input each loop and associate it with its loop header so
842 flow_loops_find can rebuild the loop tree. */
843 for (unsigned i = 1; i < n_loops; ++i)
845 int header_index = streamer_read_hwi (ib);
846 if (header_index == -1)
848 loops->larray->quick_push (NULL);
849 continue;
852 struct loop *loop = alloc_loop ();
853 loop->header = BASIC_BLOCK_FOR_FN (fn, header_index);
854 loop->header->loop_father = loop;
856 /* Read everything copy_loop_info copies. */
857 loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST);
858 loop->any_upper_bound = streamer_read_hwi (ib);
859 if (loop->any_upper_bound)
860 loop->nb_iterations_upper_bound = streamer_read_wi (ib);
861 loop->any_estimate = streamer_read_hwi (ib);
862 if (loop->any_estimate)
863 loop->nb_iterations_estimate = streamer_read_wi (ib);
865 /* Read OMP SIMD related info. */
866 loop->safelen = streamer_read_hwi (ib);
867 loop->dont_vectorize = streamer_read_hwi (ib);
868 loop->force_vectorize = streamer_read_hwi (ib);
869 loop->simduid = stream_read_tree (ib, data_in);
871 place_new_loop (fn, loop);
873 /* flow_loops_find doesn't like loops not in the tree, hook them
874 all as siblings of the tree root temporarily. */
875 flow_loop_tree_node_add (loops->tree_root, loop);
878 /* Rebuild the loop tree. */
879 flow_loops_find (loops);
883 /* Read the SSA names array for function FN from DATA_IN using input
884 block IB. */
886 static void
887 input_ssa_names (struct lto_input_block *ib, struct data_in *data_in,
888 struct function *fn)
890 unsigned int i, size;
892 size = streamer_read_uhwi (ib);
893 init_ssanames (fn, size);
895 i = streamer_read_uhwi (ib);
896 while (i)
898 tree ssa_name, name;
899 bool is_default_def;
901 /* Skip over the elements that had been freed. */
902 while (SSANAMES (fn)->length () < i)
903 SSANAMES (fn)->quick_push (NULL_TREE);
905 is_default_def = (streamer_read_uchar (ib) != 0);
906 name = stream_read_tree (ib, data_in);
907 ssa_name = make_ssa_name_fn (fn, name, gimple_build_nop ());
909 if (is_default_def)
910 set_ssa_default_def (cfun, SSA_NAME_VAR (ssa_name), ssa_name);
912 i = streamer_read_uhwi (ib);
917 /* Go through all NODE edges and fixup call_stmt pointers
918 so they point to STMTS. */
920 static void
921 fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple *stmts,
922 struct function *fn)
924 struct cgraph_edge *cedge;
925 struct ipa_ref *ref = NULL;
926 unsigned int i;
928 for (cedge = node->callees; cedge; cedge = cedge->next_callee)
930 if (gimple_stmt_max_uid (fn) < cedge->lto_stmt_uid)
931 fatal_error (input_location,
932 "Cgraph edge statement index out of range");
933 cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
934 if (!cedge->call_stmt)
935 fatal_error (input_location,
936 "Cgraph edge statement index not found");
938 for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
940 if (gimple_stmt_max_uid (fn) < cedge->lto_stmt_uid)
941 fatal_error (input_location,
942 "Cgraph edge statement index out of range");
943 cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
944 if (!cedge->call_stmt)
945 fatal_error (input_location, "Cgraph edge statement index not found");
947 for (i = 0; node->iterate_reference (i, ref); i++)
948 if (ref->lto_stmt_uid)
950 if (gimple_stmt_max_uid (fn) < ref->lto_stmt_uid)
951 fatal_error (input_location,
952 "Reference statement index out of range");
953 ref->stmt = stmts[ref->lto_stmt_uid - 1];
954 if (!ref->stmt)
955 fatal_error (input_location, "Reference statement index not found");
960 /* Fixup call_stmt pointers in NODE and all clones. */
962 static void
963 fixup_call_stmt_edges (struct cgraph_node *orig, gimple *stmts)
965 struct cgraph_node *node;
966 struct function *fn;
968 while (orig->clone_of)
969 orig = orig->clone_of;
970 fn = DECL_STRUCT_FUNCTION (orig->decl);
972 fixup_call_stmt_edges_1 (orig, stmts, fn);
973 if (orig->clones)
974 for (node = orig->clones; node != orig;)
976 fixup_call_stmt_edges_1 (node, stmts, fn);
977 if (node->clones)
978 node = node->clones;
979 else if (node->next_sibling_clone)
980 node = node->next_sibling_clone;
981 else
983 while (node != orig && !node->next_sibling_clone)
984 node = node->clone_of;
985 if (node != orig)
986 node = node->next_sibling_clone;
992 /* Input the base body of struct function FN from DATA_IN
993 using input block IB. */
995 static void
996 input_struct_function_base (struct function *fn, struct data_in *data_in,
997 struct lto_input_block *ib)
999 struct bitpack_d bp;
1000 int len;
1002 /* Read the static chain and non-local goto save area. */
1003 fn->static_chain_decl = stream_read_tree (ib, data_in);
1004 fn->nonlocal_goto_save_area = stream_read_tree (ib, data_in);
1006 /* Read all the local symbols. */
1007 len = streamer_read_hwi (ib);
1008 if (len > 0)
1010 int i;
1011 vec_safe_grow_cleared (fn->local_decls, len);
1012 for (i = 0; i < len; i++)
1014 tree t = stream_read_tree (ib, data_in);
1015 (*fn->local_decls)[i] = t;
1019 /* Input the current IL state of the function. */
1020 fn->curr_properties = streamer_read_uhwi (ib);
1022 /* Read all the attributes for FN. */
1023 bp = streamer_read_bitpack (ib);
1024 fn->is_thunk = bp_unpack_value (&bp, 1);
1025 fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
1026 fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
1027 fn->returns_struct = bp_unpack_value (&bp, 1);
1028 fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
1029 fn->can_delete_dead_exceptions = bp_unpack_value (&bp, 1);
1030 fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
1031 fn->after_inlining = bp_unpack_value (&bp, 1);
1032 fn->stdarg = bp_unpack_value (&bp, 1);
1033 fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
1034 fn->calls_alloca = bp_unpack_value (&bp, 1);
1035 fn->calls_setjmp = bp_unpack_value (&bp, 1);
1036 fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1);
1037 fn->has_simduid_loops = bp_unpack_value (&bp, 1);
1038 fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
1039 fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
1040 fn->last_clique = bp_unpack_value (&bp, sizeof (short) * 8);
1042 /* Input the function start and end loci. */
1043 fn->function_start_locus = stream_input_location_now (&bp, data_in);
1044 fn->function_end_locus = stream_input_location_now (&bp, data_in);
1048 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1050 static void
1051 input_function (tree fn_decl, struct data_in *data_in,
1052 struct lto_input_block *ib, struct lto_input_block *ib_cfg)
1054 struct function *fn;
1055 enum LTO_tags tag;
1056 gimple *stmts;
1057 basic_block bb;
1058 struct cgraph_node *node;
1060 tag = streamer_read_record_start (ib);
1061 lto_tag_check (tag, LTO_function);
1063 /* Read decls for parameters and args. */
1064 DECL_RESULT (fn_decl) = stream_read_tree (ib, data_in);
1065 DECL_ARGUMENTS (fn_decl) = streamer_read_chain (ib, data_in);
1067 /* Read the tree of lexical scopes for the function. */
1068 DECL_INITIAL (fn_decl) = stream_read_tree (ib, data_in);
1070 if (!streamer_read_uhwi (ib))
1071 return;
1073 push_struct_function (fn_decl);
1074 fn = DECL_STRUCT_FUNCTION (fn_decl);
1075 init_tree_ssa (fn);
1076 /* We input IL in SSA form. */
1077 cfun->gimple_df->in_ssa_p = true;
1079 gimple_register_cfg_hooks ();
1081 node = cgraph_node::get (fn_decl);
1082 if (!node)
1083 node = cgraph_node::create (fn_decl);
1084 input_struct_function_base (fn, data_in, ib);
1085 input_cfg (ib_cfg, data_in, fn, node->count_materialization_scale);
1087 /* Read all the SSA names. */
1088 input_ssa_names (ib, data_in, fn);
1090 /* Read the exception handling regions in the function. */
1091 input_eh_regions (ib, data_in, fn);
1093 gcc_assert (DECL_INITIAL (fn_decl));
1094 DECL_SAVED_TREE (fn_decl) = NULL_TREE;
1096 /* Read all the basic blocks. */
1097 tag = streamer_read_record_start (ib);
1098 while (tag)
1100 input_bb (ib, tag, data_in, fn,
1101 node->count_materialization_scale);
1102 tag = streamer_read_record_start (ib);
1105 /* Fix up the call statements that are mentioned in the callgraph
1106 edges. */
1107 set_gimple_stmt_max_uid (cfun, 0);
1108 FOR_ALL_BB_FN (bb, cfun)
1110 gimple_stmt_iterator gsi;
1111 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1113 gimple stmt = gsi_stmt (gsi);
1114 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1116 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1118 gimple stmt = gsi_stmt (gsi);
1119 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1122 stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple));
1123 FOR_ALL_BB_FN (bb, cfun)
1125 gimple_stmt_iterator bsi = gsi_start_phis (bb);
1126 while (!gsi_end_p (bsi))
1128 gimple stmt = gsi_stmt (bsi);
1129 gsi_next (&bsi);
1130 stmts[gimple_uid (stmt)] = stmt;
1132 bsi = gsi_start_bb (bb);
1133 while (!gsi_end_p (bsi))
1135 gimple stmt = gsi_stmt (bsi);
1136 /* If we're recompiling LTO objects with debug stmts but
1137 we're not supposed to have debug stmts, remove them now.
1138 We can't remove them earlier because this would cause uid
1139 mismatches in fixups, but we can do it at this point, as
1140 long as debug stmts don't require fixups. */
1141 if (!MAY_HAVE_DEBUG_STMTS && !flag_wpa && is_gimple_debug (stmt))
1143 gimple_stmt_iterator gsi = bsi;
1144 gsi_next (&bsi);
1145 gsi_remove (&gsi, true);
1147 else
1149 gsi_next (&bsi);
1150 stmts[gimple_uid (stmt)] = stmt;
1155 /* Set the gimple body to the statement sequence in the entry
1156 basic block. FIXME lto, this is fairly hacky. The existence
1157 of a gimple body is used by the cgraph routines, but we should
1158 really use the presence of the CFG. */
1160 edge_iterator ei = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
1161 gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
1164 fixup_call_stmt_edges (node, stmts);
1165 execute_all_ipa_stmt_fixups (node, stmts);
1167 update_ssa (TODO_update_ssa_only_virtuals);
1168 free_dominance_info (CDI_DOMINATORS);
1169 free_dominance_info (CDI_POST_DOMINATORS);
1170 free (stmts);
1171 pop_cfun ();
1174 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1176 static void
1177 input_constructor (tree var, struct data_in *data_in,
1178 struct lto_input_block *ib)
1180 DECL_INITIAL (var) = stream_read_tree (ib, data_in);
1184 /* Read the body from DATA for function NODE and fill it in.
1185 FILE_DATA are the global decls and types. SECTION_TYPE is either
1186 LTO_section_function_body or LTO_section_static_initializer. If
1187 section type is LTO_section_function_body, FN must be the decl for
1188 that function. */
1190 static void
1191 lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symtab_node *node,
1192 const char *data, enum lto_section_type section_type)
1194 const struct lto_function_header *header;
1195 struct data_in *data_in;
1196 int cfg_offset;
1197 int main_offset;
1198 int string_offset;
1199 tree fn_decl = node->decl;
1201 header = (const struct lto_function_header *) data;
1202 if (TREE_CODE (node->decl) == FUNCTION_DECL)
1204 cfg_offset = sizeof (struct lto_function_header);
1205 main_offset = cfg_offset + header->cfg_size;
1206 string_offset = main_offset + header->main_size;
1208 else
1210 main_offset = sizeof (struct lto_function_header);
1211 string_offset = main_offset + header->main_size;
1214 data_in = lto_data_in_create (file_data, data + string_offset,
1215 header->string_size, vNULL);
1217 if (section_type == LTO_section_function_body)
1219 struct lto_in_decl_state *decl_state;
1220 unsigned from;
1222 gcc_checking_assert (node);
1224 /* Use the function's decl state. */
1225 decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
1226 gcc_assert (decl_state);
1227 file_data->current_decl_state = decl_state;
1230 /* Set up the struct function. */
1231 from = data_in->reader_cache->nodes.length ();
1232 lto_input_block ib_main (data + main_offset, header->main_size,
1233 file_data->mode_table);
1234 if (TREE_CODE (node->decl) == FUNCTION_DECL)
1236 lto_input_block ib_cfg (data + cfg_offset, header->cfg_size,
1237 file_data->mode_table);
1238 input_function (fn_decl, data_in, &ib_main, &ib_cfg);
1240 else
1241 input_constructor (fn_decl, data_in, &ib_main);
1242 data_in->location_cache.apply_location_cache ();
1243 /* And fixup types we streamed locally. */
1245 struct streamer_tree_cache_d *cache = data_in->reader_cache;
1246 unsigned len = cache->nodes.length ();
1247 unsigned i;
1248 for (i = len; i-- > from;)
1250 tree t = streamer_tree_cache_get_tree (cache, i);
1251 if (t == NULL_TREE)
1252 continue;
1254 if (TYPE_P (t))
1256 gcc_assert (TYPE_CANONICAL (t) == NULL_TREE);
1257 TYPE_CANONICAL (t) = TYPE_MAIN_VARIANT (t);
1258 if (TYPE_MAIN_VARIANT (t) != t)
1260 gcc_assert (TYPE_NEXT_VARIANT (t) == NULL_TREE);
1261 TYPE_NEXT_VARIANT (t)
1262 = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t));
1263 TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t)) = t;
1269 /* Restore decl state */
1270 file_data->current_decl_state = file_data->global_decl_state;
1273 lto_data_in_delete (data_in);
1277 /* Read the body of NODE using DATA. FILE_DATA holds the global
1278 decls and types. */
1280 void
1281 lto_input_function_body (struct lto_file_decl_data *file_data,
1282 struct cgraph_node *node, const char *data)
1284 lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
1287 /* Read the body of NODE using DATA. FILE_DATA holds the global
1288 decls and types. */
1290 void
1291 lto_input_variable_constructor (struct lto_file_decl_data *file_data,
1292 struct varpool_node *node, const char *data)
1294 lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
1298 /* Read the physical representation of a tree node EXPR from
1299 input block IB using the per-file context in DATA_IN. */
1301 static void
1302 lto_read_tree_1 (struct lto_input_block *ib, struct data_in *data_in, tree expr)
1304 /* Read all the bitfield values in EXPR. Note that for LTO, we
1305 only write language-independent bitfields, so no more unpacking is
1306 needed. */
1307 streamer_read_tree_bitfields (ib, data_in, expr);
1309 /* Read all the pointer fields in EXPR. */
1310 streamer_read_tree_body (ib, data_in, expr);
1312 /* Read any LTO-specific data not read by the tree streamer. */
1313 if (DECL_P (expr)
1314 && TREE_CODE (expr) != FUNCTION_DECL
1315 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
1316 DECL_INITIAL (expr) = stream_read_tree (ib, data_in);
1318 /* We should never try to instantiate an MD or NORMAL builtin here. */
1319 if (TREE_CODE (expr) == FUNCTION_DECL)
1320 gcc_assert (!streamer_handle_as_builtin_p (expr));
1322 #ifdef LTO_STREAMER_DEBUG
1323 /* Remove the mapping to RESULT's original address set by
1324 streamer_alloc_tree. */
1325 lto_orig_address_remove (expr);
1326 #endif
1329 /* Read the physical representation of a tree node with tag TAG from
1330 input block IB using the per-file context in DATA_IN. */
1332 static tree
1333 lto_read_tree (struct lto_input_block *ib, struct data_in *data_in,
1334 enum LTO_tags tag, hashval_t hash)
1336 /* Instantiate a new tree node. */
1337 tree result = streamer_alloc_tree (ib, data_in, tag);
1339 /* Enter RESULT in the reader cache. This will make RESULT
1340 available so that circular references in the rest of the tree
1341 structure can be resolved in subsequent calls to stream_read_tree. */
1342 streamer_tree_cache_append (data_in->reader_cache, result, hash);
1344 lto_read_tree_1 (ib, data_in, result);
1346 /* end_marker = */ streamer_read_uchar (ib);
1348 return result;
1352 /* Populate the reader cache with trees materialized from the SCC
1353 following in the IB, DATA_IN stream. */
1355 hashval_t
1356 lto_input_scc (struct lto_input_block *ib, struct data_in *data_in,
1357 unsigned *len, unsigned *entry_len)
1359 /* A blob of unnamed tree nodes, fill the cache from it and
1360 recurse. */
1361 unsigned size = streamer_read_uhwi (ib);
1362 hashval_t scc_hash = streamer_read_uhwi (ib);
1363 unsigned scc_entry_len = 1;
1365 if (size == 1)
1367 enum LTO_tags tag = streamer_read_record_start (ib);
1368 lto_input_tree_1 (ib, data_in, tag, scc_hash);
1370 else
1372 unsigned int first = data_in->reader_cache->nodes.length ();
1373 tree result;
1375 scc_entry_len = streamer_read_uhwi (ib);
1377 /* Materialize size trees by reading their headers. */
1378 for (unsigned i = 0; i < size; ++i)
1380 enum LTO_tags tag = streamer_read_record_start (ib);
1381 if (tag == LTO_null
1382 || (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
1383 || tag == LTO_tree_pickle_reference
1384 || tag == LTO_builtin_decl
1385 || tag == LTO_integer_cst
1386 || tag == LTO_tree_scc)
1387 gcc_unreachable ();
1389 result = streamer_alloc_tree (ib, data_in, tag);
1390 streamer_tree_cache_append (data_in->reader_cache, result, 0);
1393 /* Read the tree bitpacks and references. */
1394 for (unsigned i = 0; i < size; ++i)
1396 result = streamer_tree_cache_get_tree (data_in->reader_cache,
1397 first + i);
1398 lto_read_tree_1 (ib, data_in, result);
1399 /* end_marker = */ streamer_read_uchar (ib);
1403 *len = size;
1404 *entry_len = scc_entry_len;
1405 return scc_hash;
1409 /* Read a tree from input block IB using the per-file context in
1410 DATA_IN. This context is used, for example, to resolve references
1411 to previously read nodes. */
1413 tree
1414 lto_input_tree_1 (struct lto_input_block *ib, struct data_in *data_in,
1415 enum LTO_tags tag, hashval_t hash)
1417 tree result;
1419 gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
1421 if (tag == LTO_null)
1422 result = NULL_TREE;
1423 else if (tag >= LTO_field_decl_ref && tag <= LTO_namelist_decl_ref)
1425 /* If TAG is a reference to an indexable tree, the next value
1426 in IB is the index into the table where we expect to find
1427 that tree. */
1428 result = lto_input_tree_ref (ib, data_in, cfun, tag);
1430 else if (tag == LTO_tree_pickle_reference)
1432 /* If TAG is a reference to a previously read tree, look it up in
1433 the reader cache. */
1434 result = streamer_get_pickled_tree (ib, data_in);
1436 else if (tag == LTO_builtin_decl)
1438 /* If we are going to read a built-in function, all we need is
1439 the code and class. */
1440 result = streamer_get_builtin_tree (ib, data_in);
1442 else if (tag == LTO_integer_cst)
1444 /* For shared integer constants in singletons we can use the
1445 existing tree integer constant merging code. */
1446 tree type = stream_read_tree (ib, data_in);
1447 unsigned HOST_WIDE_INT len = streamer_read_uhwi (ib);
1448 unsigned HOST_WIDE_INT i;
1449 HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
1451 for (i = 0; i < len; i++)
1452 a[i] = streamer_read_hwi (ib);
1453 gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
1454 result = wide_int_to_tree (type, wide_int::from_array
1455 (a, len, TYPE_PRECISION (type)));
1456 streamer_tree_cache_append (data_in->reader_cache, result, hash);
1458 else if (tag == LTO_tree_scc)
1459 gcc_unreachable ();
1460 else
1462 /* Otherwise, materialize a new node from IB. */
1463 result = lto_read_tree (ib, data_in, tag, hash);
1466 return result;
1469 tree
1470 lto_input_tree (struct lto_input_block *ib, struct data_in *data_in)
1472 enum LTO_tags tag;
1474 /* Input and skip SCCs. */
1475 while ((tag = streamer_read_record_start (ib)) == LTO_tree_scc)
1477 unsigned len, entry_len;
1478 lto_input_scc (ib, data_in, &len, &entry_len);
1480 return lto_input_tree_1 (ib, data_in, tag, 0);
1484 /* Input toplevel asms. */
1486 void
1487 lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base)
1489 size_t len;
1490 const char *data = lto_get_section_data (file_data, LTO_section_asm,
1491 NULL, &len);
1492 const struct lto_simple_header_with_strings *header
1493 = (const struct lto_simple_header_with_strings *) data;
1494 int string_offset;
1495 struct data_in *data_in;
1496 tree str;
1498 if (! data)
1499 return;
1501 string_offset = sizeof (*header) + header->main_size;
1503 lto_input_block ib (data + sizeof (*header), header->main_size,
1504 file_data->mode_table);
1506 data_in = lto_data_in_create (file_data, data + string_offset,
1507 header->string_size, vNULL);
1509 while ((str = streamer_read_string_cst (data_in, &ib)))
1511 asm_node *node = symtab->finalize_toplevel_asm (str);
1512 node->order = streamer_read_hwi (&ib) + order_base;
1513 if (node->order >= symtab->order)
1514 symtab->order = node->order + 1;
1517 lto_data_in_delete (data_in);
1519 lto_free_section_data (file_data, LTO_section_asm, NULL, data, len);
1523 /* Input mode table. */
1525 void
1526 lto_input_mode_table (struct lto_file_decl_data *file_data)
1528 size_t len;
1529 const char *data = lto_get_section_data (file_data, LTO_section_mode_table,
1530 NULL, &len);
1531 if (! data)
1533 internal_error ("cannot read LTO mode table from %s",
1534 file_data->file_name);
1535 return;
1538 unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << 8);
1539 file_data->mode_table = table;
1540 const struct lto_simple_header_with_strings *header
1541 = (const struct lto_simple_header_with_strings *) data;
1542 int string_offset;
1543 struct data_in *data_in;
1544 string_offset = sizeof (*header) + header->main_size;
1546 lto_input_block ib (data + sizeof (*header), header->main_size, NULL);
1547 data_in = lto_data_in_create (file_data, data + string_offset,
1548 header->string_size, vNULL);
1549 bitpack_d bp = streamer_read_bitpack (&ib);
1551 table[VOIDmode] = VOIDmode;
1552 table[BLKmode] = BLKmode;
1553 unsigned int m;
1554 while ((m = bp_unpack_value (&bp, 8)) != VOIDmode)
1556 enum mode_class mclass
1557 = bp_unpack_enum (&bp, mode_class, MAX_MODE_CLASS);
1558 unsigned int size = bp_unpack_value (&bp, 8);
1559 unsigned int prec = bp_unpack_value (&bp, 16);
1560 machine_mode inner = (machine_mode) table[bp_unpack_value (&bp, 8)];
1561 unsigned int nunits = bp_unpack_value (&bp, 8);
1562 unsigned int ibit = 0, fbit = 0;
1563 unsigned int real_fmt_len = 0;
1564 const char *real_fmt_name = NULL;
1565 switch (mclass)
1567 case MODE_FRACT:
1568 case MODE_UFRACT:
1569 case MODE_ACCUM:
1570 case MODE_UACCUM:
1571 ibit = bp_unpack_value (&bp, 8);
1572 fbit = bp_unpack_value (&bp, 8);
1573 break;
1574 case MODE_FLOAT:
1575 case MODE_DECIMAL_FLOAT:
1576 real_fmt_name = bp_unpack_indexed_string (data_in, &bp,
1577 &real_fmt_len);
1578 break;
1579 default:
1580 break;
1582 /* First search just the GET_CLASS_NARROWEST_MODE to wider modes,
1583 if not found, fallback to all modes. */
1584 int pass;
1585 for (pass = 0; pass < 2; pass++)
1586 for (machine_mode mr = pass ? VOIDmode
1587 : GET_CLASS_NARROWEST_MODE (mclass);
1588 pass ? mr < MAX_MACHINE_MODE : mr != VOIDmode;
1589 pass ? mr = (machine_mode) (m + 1)
1590 : mr = GET_MODE_WIDER_MODE (mr))
1591 if (GET_MODE_CLASS (mr) != mclass
1592 || GET_MODE_SIZE (mr) != size
1593 || GET_MODE_PRECISION (mr) != prec
1594 || GET_MODE_INNER (mr) != inner
1595 || GET_MODE_IBIT (mr) != ibit
1596 || GET_MODE_FBIT (mr) != fbit
1597 || GET_MODE_NUNITS (mr) != nunits)
1598 continue;
1599 else if ((mclass == MODE_FLOAT || mclass == MODE_DECIMAL_FLOAT)
1600 && strcmp (REAL_MODE_FORMAT (mr)->name, real_fmt_name) != 0)
1601 continue;
1602 else
1604 table[m] = mr;
1605 pass = 2;
1606 break;
1608 unsigned int mname_len;
1609 const char *mname = bp_unpack_indexed_string (data_in, &bp, &mname_len);
1610 if (pass == 2)
1612 switch (mclass)
1614 case MODE_VECTOR_INT:
1615 case MODE_VECTOR_FLOAT:
1616 case MODE_VECTOR_FRACT:
1617 case MODE_VECTOR_UFRACT:
1618 case MODE_VECTOR_ACCUM:
1619 case MODE_VECTOR_UACCUM:
1620 /* For unsupported vector modes just use BLKmode,
1621 if the scalar mode is supported. */
1622 if (inner != VOIDmode)
1624 table[m] = BLKmode;
1625 break;
1627 /* FALLTHRU */
1628 default:
1629 fatal_error (UNKNOWN_LOCATION, "unsupported mode %s\n", mname);
1630 break;
1634 lto_data_in_delete (data_in);
1636 lto_free_section_data (file_data, LTO_section_mode_table, NULL, data, len);
1640 /* Initialization for the LTO reader. */
1642 void
1643 lto_reader_init (void)
1645 lto_streamer_init ();
1646 file_name_hash_table
1647 = new hash_table<freeing_string_slot_hasher> (37);
1651 /* Create a new data_in object for FILE_DATA. STRINGS is the string
1652 table to use with LEN strings. RESOLUTIONS is the vector of linker
1653 resolutions (NULL if not using a linker plugin). */
1655 struct data_in *
1656 lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
1657 unsigned len,
1658 vec<ld_plugin_symbol_resolution_t> resolutions)
1660 struct data_in *data_in = new (struct data_in);
1661 data_in->file_data = file_data;
1662 data_in->strings = strings;
1663 data_in->strings_len = len;
1664 data_in->globals_resolution = resolutions;
1665 data_in->reader_cache = streamer_tree_cache_create (false, false, true);
1666 return data_in;
1670 /* Remove DATA_IN. */
1672 void
1673 lto_data_in_delete (struct data_in *data_in)
1675 data_in->globals_resolution.release ();
1676 streamer_tree_cache_delete (data_in->reader_cache);
1677 delete data_in;