[obvious] Fix typos above expand_cond_expr_using_cmove
[official-gcc.git] / gcc / lto-streamer-in.c
blobb9cdd0040507504939db0f7582fafed39431fcf7
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 "backend.h"
27 #include "tree.h"
28 #include "gimple.h"
29 #include "rtl.h"
30 #include "ssa.h"
31 #include "toplev.h"
32 #include "alias.h"
33 #include "fold-const.h"
34 #include "flags.h"
35 #include "insn-config.h"
36 #include "expmed.h"
37 #include "dojump.h"
38 #include "explow.h"
39 #include "calls.h"
40 #include "emit-rtl.h"
41 #include "varasm.h"
42 #include "stmt.h"
43 #include "expr.h"
44 #include "params.h"
45 #include "internal-fn.h"
46 #include "gimple-iterator.h"
47 #include "tree-cfg.h"
48 #include "tree-into-ssa.h"
49 #include "tree-dfa.h"
50 #include "tree-ssa.h"
51 #include "tree-pass.h"
52 #include "diagnostic.h"
53 #include "except.h"
54 #include "debug.h"
55 #include "cgraph.h"
56 #include "ipa-utils.h"
57 #include "target.h"
58 #include "data-streamer.h"
59 #include "gimple-streamer.h"
60 #include "lto-streamer.h"
61 #include "tree-streamer.h"
62 #include "streamer-hooks.h"
63 #include "cfgloop.h"
66 struct freeing_string_slot_hasher : string_slot_hasher
68 static inline void remove (value_type *);
71 inline void
72 freeing_string_slot_hasher::remove (value_type *v)
74 free (v);
77 /* The table to hold the file names. */
78 static hash_table<freeing_string_slot_hasher> *file_name_hash_table;
81 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
82 number of valid tag values to check. */
84 void
85 lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
87 va_list ap;
88 int i;
90 va_start (ap, ntags);
91 for (i = 0; i < ntags; i++)
92 if ((unsigned) actual == va_arg (ap, unsigned))
94 va_end (ap);
95 return;
98 va_end (ap);
99 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
103 /* Read LENGTH bytes from STREAM to ADDR. */
105 void
106 lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length)
108 size_t i;
109 unsigned char *const buffer = (unsigned char *const) addr;
111 for (i = 0; i < length; i++)
112 buffer[i] = streamer_read_uchar (ib);
116 /* Lookup STRING in file_name_hash_table. If found, return the existing
117 string, otherwise insert STRING as the canonical version. */
119 static const char *
120 canon_file_name (const char *string)
122 string_slot **slot;
123 struct string_slot s_slot;
124 size_t len = strlen (string);
126 s_slot.s = string;
127 s_slot.len = len;
129 slot = file_name_hash_table->find_slot (&s_slot, INSERT);
130 if (*slot == NULL)
132 char *saved_string;
133 struct string_slot *new_slot;
135 saved_string = (char *) xmalloc (len + 1);
136 new_slot = XCNEW (struct string_slot);
137 memcpy (saved_string, string, len + 1);
138 new_slot->s = saved_string;
139 new_slot->len = len;
140 *slot = new_slot;
141 return saved_string;
143 else
145 struct string_slot *old_slot = *slot;
146 return old_slot->s;
150 /* Pointer to currently alive instance of lto_location_cache. */
152 lto_location_cache *lto_location_cache::current_cache;
154 /* Sort locations in source order. Start with file from last application. */
157 lto_location_cache::cmp_loc (const void *pa, const void *pb)
159 const cached_location *a = ((const cached_location *)pa);
160 const cached_location *b = ((const cached_location *)pb);
161 const char *current_file = current_cache->current_file;
162 int current_line = current_cache->current_line;
164 if (a->file == current_file && b->file != current_file)
165 return -1;
166 if (a->file != current_file && b->file == current_file)
167 return 1;
168 if (a->file == current_file && b->file == current_file)
170 if (a->line == current_line && b->line != current_line)
171 return -1;
172 if (a->line != current_line && b->line == current_line)
173 return 1;
175 if (a->file != b->file)
176 return strcmp (a->file, b->file);
177 if (a->line != b->line)
178 return a->line - b->line;
179 return a->col - b->col;
182 /* Apply all changes in location cache. Add locations into linemap and patch
183 trees. */
185 bool
186 lto_location_cache::apply_location_cache ()
188 static const char *prev_file;
189 if (!loc_cache.length ())
190 return false;
191 if (loc_cache.length () > 1)
192 loc_cache.qsort (cmp_loc);
194 for (unsigned int i = 0; i < loc_cache.length (); i++)
196 struct cached_location loc = loc_cache[i];
198 if (current_file != loc.file)
199 linemap_add (line_table, prev_file ? LC_RENAME : LC_ENTER,
200 false, loc.file, loc.line);
201 else if (current_line != loc.line)
203 int max = loc.col;
205 for (unsigned int j = i + 1; j < loc_cache.length (); j++)
206 if (loc.file != loc_cache[j].file
207 || loc.line != loc_cache[j].line)
208 break;
209 else if (max < loc_cache[j].col)
210 max = loc_cache[j].col;
211 linemap_line_start (line_table, loc.line, max + 1);
213 gcc_assert (*loc.loc == BUILTINS_LOCATION + 1);
214 if (current_file == loc.file && current_line == loc.line
215 && current_col == loc.col)
216 *loc.loc = current_loc;
217 else
218 current_loc = *loc.loc = linemap_position_for_column (line_table,
219 loc.col);
220 current_line = loc.line;
221 prev_file = current_file = loc.file;
222 current_col = loc.col;
224 loc_cache.truncate (0);
225 accepted_length = 0;
226 return true;
229 /* Tree merging did not suceed; mark all changes in the cache as accepted. */
231 void
232 lto_location_cache::accept_location_cache ()
234 gcc_assert (current_cache == this);
235 accepted_length = loc_cache.length ();
238 /* Tree merging did suceed; throw away recent changes. */
240 void
241 lto_location_cache::revert_location_cache ()
243 loc_cache.truncate (accepted_length);
246 /* Read a location bitpack from input block IB and either update *LOC directly
247 or add it to the location cache.
248 It is neccesary to call apply_location_cache to get *LOC updated. */
250 void
251 lto_location_cache::input_location (location_t *loc, struct bitpack_d *bp,
252 struct data_in *data_in)
254 static const char *stream_file;
255 static int stream_line;
256 static int stream_col;
257 bool file_change, line_change, column_change;
259 gcc_assert (current_cache == this);
261 *loc = bp_unpack_int_in_range (bp, "location", 0, RESERVED_LOCATION_COUNT);
263 if (*loc < RESERVED_LOCATION_COUNT)
264 return;
266 /* Keep value RESERVED_LOCATION_COUNT in *loc as linemap lookups will
267 ICE on it. */
269 file_change = bp_unpack_value (bp, 1);
270 line_change = bp_unpack_value (bp, 1);
271 column_change = bp_unpack_value (bp, 1);
273 if (file_change)
274 stream_file = canon_file_name (bp_unpack_string (data_in, bp));
276 if (line_change)
277 stream_line = bp_unpack_var_len_unsigned (bp);
279 if (column_change)
280 stream_col = bp_unpack_var_len_unsigned (bp);
282 /* This optimization saves location cache operations druing gimple
283 streaming. */
285 if (current_file == stream_file && current_line == stream_line
286 && current_col == stream_col)
288 *loc = current_loc;
289 return;
292 struct cached_location entry = {stream_file, loc, stream_line, stream_col};
293 loc_cache.safe_push (entry);
296 /* Read a location bitpack from input block IB and either update *LOC directly
297 or add it to the location cache.
298 It is neccesary to call apply_location_cache to get *LOC updated. */
300 void
301 lto_input_location (location_t *loc, struct bitpack_d *bp,
302 struct data_in *data_in)
304 data_in->location_cache.input_location (loc, bp, data_in);
307 /* Read location and return it instead of going through location caching.
308 This should be used only when the resulting location is not going to be
309 discarded. */
311 location_t
312 stream_input_location_now (struct bitpack_d *bp, struct data_in *data_in)
314 location_t loc;
315 stream_input_location (&loc, bp, data_in);
316 data_in->location_cache.apply_location_cache ();
317 return loc;
320 /* Read a reference to a tree node from DATA_IN using input block IB.
321 TAG is the expected node that should be found in IB, if TAG belongs
322 to one of the indexable trees, expect to read a reference index to
323 be looked up in one of the symbol tables, otherwise read the pysical
324 representation of the tree using stream_read_tree. FN is the
325 function scope for the read tree. */
327 tree
328 lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in,
329 struct function *fn, enum LTO_tags tag)
331 unsigned HOST_WIDE_INT ix_u;
332 tree result = NULL_TREE;
334 lto_tag_check_range (tag, LTO_field_decl_ref, LTO_namelist_decl_ref);
336 switch (tag)
338 case LTO_type_ref:
339 ix_u = streamer_read_uhwi (ib);
340 result = lto_file_decl_data_get_type (data_in->file_data, ix_u);
341 break;
343 case LTO_ssa_name_ref:
344 ix_u = streamer_read_uhwi (ib);
345 result = (*SSANAMES (fn))[ix_u];
346 break;
348 case LTO_field_decl_ref:
349 ix_u = streamer_read_uhwi (ib);
350 result = lto_file_decl_data_get_field_decl (data_in->file_data, ix_u);
351 break;
353 case LTO_function_decl_ref:
354 ix_u = streamer_read_uhwi (ib);
355 result = lto_file_decl_data_get_fn_decl (data_in->file_data, ix_u);
356 break;
358 case LTO_type_decl_ref:
359 ix_u = streamer_read_uhwi (ib);
360 result = lto_file_decl_data_get_type_decl (data_in->file_data, ix_u);
361 break;
363 case LTO_namespace_decl_ref:
364 ix_u = streamer_read_uhwi (ib);
365 result = lto_file_decl_data_get_namespace_decl (data_in->file_data, ix_u);
366 break;
368 case LTO_global_decl_ref:
369 case LTO_result_decl_ref:
370 case LTO_const_decl_ref:
371 case LTO_imported_decl_ref:
372 case LTO_label_decl_ref:
373 case LTO_translation_unit_decl_ref:
374 case LTO_namelist_decl_ref:
375 ix_u = streamer_read_uhwi (ib);
376 result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u);
377 break;
379 default:
380 gcc_unreachable ();
383 gcc_assert (result);
385 return result;
389 /* Read and return a double-linked list of catch handlers from input
390 block IB, using descriptors in DATA_IN. */
392 static struct eh_catch_d *
393 lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in,
394 eh_catch *last_p)
396 eh_catch first;
397 enum LTO_tags tag;
399 *last_p = first = NULL;
400 tag = streamer_read_record_start (ib);
401 while (tag)
403 tree list;
404 eh_catch n;
406 lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
408 /* Read the catch node. */
409 n = ggc_cleared_alloc<eh_catch_d> ();
410 n->type_list = stream_read_tree (ib, data_in);
411 n->filter_list = stream_read_tree (ib, data_in);
412 n->label = stream_read_tree (ib, data_in);
414 /* Register all the types in N->FILTER_LIST. */
415 for (list = n->filter_list; list; list = TREE_CHAIN (list))
416 add_type_for_runtime (TREE_VALUE (list));
418 /* Chain N to the end of the list. */
419 if (*last_p)
420 (*last_p)->next_catch = n;
421 n->prev_catch = *last_p;
422 *last_p = n;
424 /* Set the head of the list the first time through the loop. */
425 if (first == NULL)
426 first = n;
428 tag = streamer_read_record_start (ib);
431 return first;
435 /* Read and return EH region IX from input block IB, using descriptors
436 in DATA_IN. */
438 static eh_region
439 input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
441 enum LTO_tags tag;
442 eh_region r;
444 /* Read the region header. */
445 tag = streamer_read_record_start (ib);
446 if (tag == LTO_null)
447 return NULL;
449 r = ggc_cleared_alloc<eh_region_d> ();
450 r->index = streamer_read_hwi (ib);
452 gcc_assert (r->index == ix);
454 /* Read all the region pointers as region numbers. We'll fix up
455 the pointers once the whole array has been read. */
456 r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib);
457 r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib);
458 r->next_peer = (eh_region) (intptr_t) streamer_read_hwi (ib);
460 switch (tag)
462 case LTO_ert_cleanup:
463 r->type = ERT_CLEANUP;
464 break;
466 case LTO_ert_try:
468 struct eh_catch_d *last_catch;
469 r->type = ERT_TRY;
470 r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
471 &last_catch);
472 r->u.eh_try.last_catch = last_catch;
473 break;
476 case LTO_ert_allowed_exceptions:
478 tree l;
480 r->type = ERT_ALLOWED_EXCEPTIONS;
481 r->u.allowed.type_list = stream_read_tree (ib, data_in);
482 r->u.allowed.label = stream_read_tree (ib, data_in);
483 r->u.allowed.filter = streamer_read_uhwi (ib);
485 for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
486 add_type_for_runtime (TREE_VALUE (l));
488 break;
490 case LTO_ert_must_not_throw:
492 r->type = ERT_MUST_NOT_THROW;
493 r->u.must_not_throw.failure_decl = stream_read_tree (ib, data_in);
494 bitpack_d bp = streamer_read_bitpack (ib);
495 r->u.must_not_throw.failure_loc
496 = stream_input_location_now (&bp, data_in);
498 break;
500 default:
501 gcc_unreachable ();
504 r->landing_pads = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
506 return r;
510 /* Read and return EH landing pad IX from input block IB, using descriptors
511 in DATA_IN. */
513 static eh_landing_pad
514 input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix)
516 enum LTO_tags tag;
517 eh_landing_pad lp;
519 /* Read the landing pad header. */
520 tag = streamer_read_record_start (ib);
521 if (tag == LTO_null)
522 return NULL;
524 lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
526 lp = ggc_cleared_alloc<eh_landing_pad_d> ();
527 lp->index = streamer_read_hwi (ib);
528 gcc_assert (lp->index == ix);
529 lp->next_lp = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
530 lp->region = (eh_region) (intptr_t) streamer_read_hwi (ib);
531 lp->post_landing_pad = stream_read_tree (ib, data_in);
533 return lp;
537 /* After reading the EH regions, pointers to peer and children regions
538 are region numbers. This converts all these region numbers into
539 real pointers into the rematerialized regions for FN. ROOT_REGION
540 is the region number for the root EH region in FN. */
542 static void
543 fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
545 unsigned i;
546 vec<eh_region, va_gc> *eh_array = fn->eh->region_array;
547 vec<eh_landing_pad, va_gc> *lp_array = fn->eh->lp_array;
548 eh_region r;
549 eh_landing_pad lp;
551 gcc_assert (eh_array && lp_array);
553 gcc_assert (root_region >= 0);
554 fn->eh->region_tree = (*eh_array)[root_region];
556 #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)]
557 #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)]
559 /* Convert all the index numbers stored in pointer fields into
560 pointers to the corresponding slots in the EH region array. */
561 FOR_EACH_VEC_ELT (*eh_array, i, r)
563 /* The array may contain NULL regions. */
564 if (r == NULL)
565 continue;
567 gcc_assert (i == (unsigned) r->index);
568 FIXUP_EH_REGION (r->outer);
569 FIXUP_EH_REGION (r->inner);
570 FIXUP_EH_REGION (r->next_peer);
571 FIXUP_EH_LP (r->landing_pads);
574 /* Convert all the index numbers stored in pointer fields into
575 pointers to the corresponding slots in the EH landing pad array. */
576 FOR_EACH_VEC_ELT (*lp_array, i, lp)
578 /* The array may contain NULL landing pads. */
579 if (lp == NULL)
580 continue;
582 gcc_assert (i == (unsigned) lp->index);
583 FIXUP_EH_LP (lp->next_lp);
584 FIXUP_EH_REGION (lp->region);
587 #undef FIXUP_EH_REGION
588 #undef FIXUP_EH_LP
592 /* Initialize EH support. */
594 void
595 lto_init_eh (void)
597 static bool eh_initialized_p = false;
599 if (eh_initialized_p)
600 return;
602 /* Contrary to most other FEs, we only initialize EH support when at
603 least one of the files in the set contains exception regions in
604 it. Since this happens much later than the call to init_eh in
605 lang_dependent_init, we have to set flag_exceptions and call
606 init_eh again to initialize the EH tables. */
607 flag_exceptions = 1;
608 init_eh ();
610 eh_initialized_p = true;
614 /* Read the exception table for FN from IB using the data descriptors
615 in DATA_IN. */
617 static void
618 input_eh_regions (struct lto_input_block *ib, struct data_in *data_in,
619 struct function *fn)
621 HOST_WIDE_INT i, root_region, len;
622 enum LTO_tags tag;
624 tag = streamer_read_record_start (ib);
625 if (tag == LTO_null)
626 return;
628 lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
630 /* If the file contains EH regions, then it was compiled with
631 -fexceptions. In that case, initialize the backend EH
632 machinery. */
633 lto_init_eh ();
635 gcc_assert (fn->eh);
637 root_region = streamer_read_hwi (ib);
638 gcc_assert (root_region == (int) root_region);
640 /* Read the EH region array. */
641 len = streamer_read_hwi (ib);
642 gcc_assert (len == (int) len);
643 if (len > 0)
645 vec_safe_grow_cleared (fn->eh->region_array, len);
646 for (i = 0; i < len; i++)
648 eh_region r = input_eh_region (ib, data_in, i);
649 (*fn->eh->region_array)[i] = r;
653 /* Read the landing pads. */
654 len = streamer_read_hwi (ib);
655 gcc_assert (len == (int) len);
656 if (len > 0)
658 vec_safe_grow_cleared (fn->eh->lp_array, len);
659 for (i = 0; i < len; i++)
661 eh_landing_pad lp = input_eh_lp (ib, data_in, i);
662 (*fn->eh->lp_array)[i] = lp;
666 /* Read the runtime type data. */
667 len = streamer_read_hwi (ib);
668 gcc_assert (len == (int) len);
669 if (len > 0)
671 vec_safe_grow_cleared (fn->eh->ttype_data, len);
672 for (i = 0; i < len; i++)
674 tree ttype = stream_read_tree (ib, data_in);
675 (*fn->eh->ttype_data)[i] = ttype;
679 /* Read the table of action chains. */
680 len = streamer_read_hwi (ib);
681 gcc_assert (len == (int) len);
682 if (len > 0)
684 if (targetm.arm_eabi_unwinder)
686 vec_safe_grow_cleared (fn->eh->ehspec_data.arm_eabi, len);
687 for (i = 0; i < len; i++)
689 tree t = stream_read_tree (ib, data_in);
690 (*fn->eh->ehspec_data.arm_eabi)[i] = t;
693 else
695 vec_safe_grow_cleared (fn->eh->ehspec_data.other, len);
696 for (i = 0; i < len; i++)
698 uchar c = streamer_read_uchar (ib);
699 (*fn->eh->ehspec_data.other)[i] = c;
704 /* Reconstruct the EH region tree by fixing up the peer/children
705 pointers. */
706 fixup_eh_region_pointers (fn, root_region);
708 tag = streamer_read_record_start (ib);
709 lto_tag_check_range (tag, LTO_null, LTO_null);
713 /* Make a new basic block with index INDEX in function FN. */
715 static basic_block
716 make_new_block (struct function *fn, unsigned int index)
718 basic_block bb = alloc_block ();
719 bb->index = index;
720 SET_BASIC_BLOCK_FOR_FN (fn, index, bb);
721 n_basic_blocks_for_fn (fn)++;
722 return bb;
726 /* Read a wide-int. */
728 static widest_int
729 streamer_read_wi (struct lto_input_block *ib)
731 HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
732 int i;
733 int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
734 int len = streamer_read_uhwi (ib);
735 for (i = 0; i < len; i++)
736 a[i] = streamer_read_hwi (ib);
737 return widest_int::from_array (a, len);
741 /* Read the CFG for function FN from input block IB. */
743 static void
744 input_cfg (struct lto_input_block *ib, struct data_in *data_in,
745 struct function *fn,
746 int count_materialization_scale)
748 unsigned int bb_count;
749 basic_block p_bb;
750 unsigned int i;
751 int index;
753 init_empty_tree_cfg_for_function (fn);
754 init_ssa_operands (fn);
756 profile_status_for_fn (fn) = streamer_read_enum (ib, profile_status_d,
757 PROFILE_LAST);
759 bb_count = streamer_read_uhwi (ib);
761 last_basic_block_for_fn (fn) = bb_count;
762 if (bb_count > basic_block_info_for_fn (fn)->length ())
763 vec_safe_grow_cleared (basic_block_info_for_fn (fn), bb_count);
765 if (bb_count > label_to_block_map_for_fn (fn)->length ())
766 vec_safe_grow_cleared (label_to_block_map_for_fn (fn), bb_count);
768 index = streamer_read_hwi (ib);
769 while (index != -1)
771 basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
772 unsigned int edge_count;
774 if (bb == NULL)
775 bb = make_new_block (fn, index);
777 edge_count = streamer_read_uhwi (ib);
779 /* Connect up the CFG. */
780 for (i = 0; i < edge_count; i++)
782 unsigned int dest_index;
783 unsigned int edge_flags;
784 basic_block dest;
785 int probability;
786 gcov_type count;
787 edge e;
789 dest_index = streamer_read_uhwi (ib);
790 probability = (int) streamer_read_hwi (ib);
791 count = apply_scale ((gcov_type) streamer_read_gcov_count (ib),
792 count_materialization_scale);
793 edge_flags = streamer_read_uhwi (ib);
795 dest = BASIC_BLOCK_FOR_FN (fn, dest_index);
797 if (dest == NULL)
798 dest = make_new_block (fn, dest_index);
800 e = make_edge (bb, dest, edge_flags);
801 e->probability = probability;
802 e->count = count;
805 index = streamer_read_hwi (ib);
808 p_bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
809 index = streamer_read_hwi (ib);
810 while (index != -1)
812 basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
813 bb->prev_bb = p_bb;
814 p_bb->next_bb = bb;
815 p_bb = bb;
816 index = streamer_read_hwi (ib);
819 /* ??? The cfgloop interface is tied to cfun. */
820 gcc_assert (cfun == fn);
822 /* Input the loop tree. */
823 unsigned n_loops = streamer_read_uhwi (ib);
824 if (n_loops == 0)
825 return;
827 struct loops *loops = ggc_cleared_alloc<struct loops> ();
828 init_loops_structure (fn, loops, n_loops);
829 set_loops_for_fn (fn, loops);
831 /* Input each loop and associate it with its loop header so
832 flow_loops_find can rebuild the loop tree. */
833 for (unsigned i = 1; i < n_loops; ++i)
835 int header_index = streamer_read_hwi (ib);
836 if (header_index == -1)
838 loops->larray->quick_push (NULL);
839 continue;
842 struct loop *loop = alloc_loop ();
843 loop->header = BASIC_BLOCK_FOR_FN (fn, header_index);
844 loop->header->loop_father = loop;
846 /* Read everything copy_loop_info copies. */
847 loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST);
848 loop->any_upper_bound = streamer_read_hwi (ib);
849 if (loop->any_upper_bound)
850 loop->nb_iterations_upper_bound = streamer_read_wi (ib);
851 loop->any_estimate = streamer_read_hwi (ib);
852 if (loop->any_estimate)
853 loop->nb_iterations_estimate = streamer_read_wi (ib);
855 /* Read OMP SIMD related info. */
856 loop->safelen = streamer_read_hwi (ib);
857 loop->dont_vectorize = streamer_read_hwi (ib);
858 loop->force_vectorize = streamer_read_hwi (ib);
859 loop->simduid = stream_read_tree (ib, data_in);
861 place_new_loop (fn, loop);
863 /* flow_loops_find doesn't like loops not in the tree, hook them
864 all as siblings of the tree root temporarily. */
865 flow_loop_tree_node_add (loops->tree_root, loop);
868 /* Rebuild the loop tree. */
869 flow_loops_find (loops);
873 /* Read the SSA names array for function FN from DATA_IN using input
874 block IB. */
876 static void
877 input_ssa_names (struct lto_input_block *ib, struct data_in *data_in,
878 struct function *fn)
880 unsigned int i, size;
882 size = streamer_read_uhwi (ib);
883 init_ssanames (fn, size);
885 i = streamer_read_uhwi (ib);
886 while (i)
888 tree ssa_name, name;
889 bool is_default_def;
891 /* Skip over the elements that had been freed. */
892 while (SSANAMES (fn)->length () < i)
893 SSANAMES (fn)->quick_push (NULL_TREE);
895 is_default_def = (streamer_read_uchar (ib) != 0);
896 name = stream_read_tree (ib, data_in);
897 ssa_name = make_ssa_name_fn (fn, name, gimple_build_nop ());
899 if (is_default_def)
900 set_ssa_default_def (cfun, SSA_NAME_VAR (ssa_name), ssa_name);
902 i = streamer_read_uhwi (ib);
907 /* Go through all NODE edges and fixup call_stmt pointers
908 so they point to STMTS. */
910 static void
911 fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple *stmts,
912 struct function *fn)
914 struct cgraph_edge *cedge;
915 struct ipa_ref *ref = NULL;
916 unsigned int i;
918 for (cedge = node->callees; cedge; cedge = cedge->next_callee)
920 if (gimple_stmt_max_uid (fn) < cedge->lto_stmt_uid)
921 fatal_error (input_location,
922 "Cgraph edge statement index out of range");
923 cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
924 if (!cedge->call_stmt)
925 fatal_error (input_location,
926 "Cgraph edge statement index not found");
928 for (cedge = node->indirect_calls; 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, "Cgraph edge statement index not found");
937 for (i = 0; node->iterate_reference (i, ref); i++)
938 if (ref->lto_stmt_uid)
940 if (gimple_stmt_max_uid (fn) < ref->lto_stmt_uid)
941 fatal_error (input_location,
942 "Reference statement index out of range");
943 ref->stmt = stmts[ref->lto_stmt_uid - 1];
944 if (!ref->stmt)
945 fatal_error (input_location, "Reference statement index not found");
950 /* Fixup call_stmt pointers in NODE and all clones. */
952 static void
953 fixup_call_stmt_edges (struct cgraph_node *orig, gimple *stmts)
955 struct cgraph_node *node;
956 struct function *fn;
958 while (orig->clone_of)
959 orig = orig->clone_of;
960 fn = DECL_STRUCT_FUNCTION (orig->decl);
962 fixup_call_stmt_edges_1 (orig, stmts, fn);
963 if (orig->clones)
964 for (node = orig->clones; node != orig;)
966 fixup_call_stmt_edges_1 (node, stmts, fn);
967 if (node->clones)
968 node = node->clones;
969 else if (node->next_sibling_clone)
970 node = node->next_sibling_clone;
971 else
973 while (node != orig && !node->next_sibling_clone)
974 node = node->clone_of;
975 if (node != orig)
976 node = node->next_sibling_clone;
982 /* Input the base body of struct function FN from DATA_IN
983 using input block IB. */
985 static void
986 input_struct_function_base (struct function *fn, struct data_in *data_in,
987 struct lto_input_block *ib)
989 struct bitpack_d bp;
990 int len;
992 /* Read the static chain and non-local goto save area. */
993 fn->static_chain_decl = stream_read_tree (ib, data_in);
994 fn->nonlocal_goto_save_area = stream_read_tree (ib, data_in);
996 /* Read all the local symbols. */
997 len = streamer_read_hwi (ib);
998 if (len > 0)
1000 int i;
1001 vec_safe_grow_cleared (fn->local_decls, len);
1002 for (i = 0; i < len; i++)
1004 tree t = stream_read_tree (ib, data_in);
1005 (*fn->local_decls)[i] = t;
1009 /* Input the current IL state of the function. */
1010 fn->curr_properties = streamer_read_uhwi (ib);
1012 /* Read all the attributes for FN. */
1013 bp = streamer_read_bitpack (ib);
1014 fn->is_thunk = bp_unpack_value (&bp, 1);
1015 fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
1016 fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
1017 fn->returns_struct = bp_unpack_value (&bp, 1);
1018 fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
1019 fn->can_delete_dead_exceptions = bp_unpack_value (&bp, 1);
1020 fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
1021 fn->after_inlining = bp_unpack_value (&bp, 1);
1022 fn->stdarg = bp_unpack_value (&bp, 1);
1023 fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
1024 fn->calls_alloca = bp_unpack_value (&bp, 1);
1025 fn->calls_setjmp = bp_unpack_value (&bp, 1);
1026 fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1);
1027 fn->has_simduid_loops = bp_unpack_value (&bp, 1);
1028 fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
1029 fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
1030 fn->last_clique = bp_unpack_value (&bp, sizeof (short) * 8);
1032 /* Input the function start and end loci. */
1033 fn->function_start_locus = stream_input_location_now (&bp, data_in);
1034 fn->function_end_locus = stream_input_location_now (&bp, data_in);
1038 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1040 static void
1041 input_function (tree fn_decl, struct data_in *data_in,
1042 struct lto_input_block *ib, struct lto_input_block *ib_cfg)
1044 struct function *fn;
1045 enum LTO_tags tag;
1046 gimple *stmts;
1047 basic_block bb;
1048 struct cgraph_node *node;
1050 tag = streamer_read_record_start (ib);
1051 lto_tag_check (tag, LTO_function);
1053 /* Read decls for parameters and args. */
1054 DECL_RESULT (fn_decl) = stream_read_tree (ib, data_in);
1055 DECL_ARGUMENTS (fn_decl) = streamer_read_chain (ib, data_in);
1057 /* Read the tree of lexical scopes for the function. */
1058 DECL_INITIAL (fn_decl) = stream_read_tree (ib, data_in);
1060 if (!streamer_read_uhwi (ib))
1061 return;
1063 push_struct_function (fn_decl);
1064 fn = DECL_STRUCT_FUNCTION (fn_decl);
1065 init_tree_ssa (fn);
1066 /* We input IL in SSA form. */
1067 cfun->gimple_df->in_ssa_p = true;
1069 gimple_register_cfg_hooks ();
1071 node = cgraph_node::get (fn_decl);
1072 if (!node)
1073 node = cgraph_node::create (fn_decl);
1074 input_struct_function_base (fn, data_in, ib);
1075 input_cfg (ib_cfg, data_in, fn, node->count_materialization_scale);
1077 /* Read all the SSA names. */
1078 input_ssa_names (ib, data_in, fn);
1080 /* Read the exception handling regions in the function. */
1081 input_eh_regions (ib, data_in, fn);
1083 gcc_assert (DECL_INITIAL (fn_decl));
1084 DECL_SAVED_TREE (fn_decl) = NULL_TREE;
1086 /* Read all the basic blocks. */
1087 tag = streamer_read_record_start (ib);
1088 while (tag)
1090 input_bb (ib, tag, data_in, fn,
1091 node->count_materialization_scale);
1092 tag = streamer_read_record_start (ib);
1095 /* Fix up the call statements that are mentioned in the callgraph
1096 edges. */
1097 set_gimple_stmt_max_uid (cfun, 0);
1098 FOR_ALL_BB_FN (bb, cfun)
1100 gimple_stmt_iterator gsi;
1101 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1103 gimple stmt = gsi_stmt (gsi);
1104 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1106 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1108 gimple stmt = gsi_stmt (gsi);
1109 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1112 stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple));
1113 FOR_ALL_BB_FN (bb, cfun)
1115 gimple_stmt_iterator bsi = gsi_start_phis (bb);
1116 while (!gsi_end_p (bsi))
1118 gimple stmt = gsi_stmt (bsi);
1119 gsi_next (&bsi);
1120 stmts[gimple_uid (stmt)] = stmt;
1122 bsi = gsi_start_bb (bb);
1123 while (!gsi_end_p (bsi))
1125 gimple stmt = gsi_stmt (bsi);
1126 /* If we're recompiling LTO objects with debug stmts but
1127 we're not supposed to have debug stmts, remove them now.
1128 We can't remove them earlier because this would cause uid
1129 mismatches in fixups, but we can do it at this point, as
1130 long as debug stmts don't require fixups. */
1131 if (!MAY_HAVE_DEBUG_STMTS && !flag_wpa && is_gimple_debug (stmt))
1133 gimple_stmt_iterator gsi = bsi;
1134 gsi_next (&bsi);
1135 gsi_remove (&gsi, true);
1137 else
1139 gsi_next (&bsi);
1140 stmts[gimple_uid (stmt)] = stmt;
1145 /* Set the gimple body to the statement sequence in the entry
1146 basic block. FIXME lto, this is fairly hacky. The existence
1147 of a gimple body is used by the cgraph routines, but we should
1148 really use the presence of the CFG. */
1150 edge_iterator ei = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
1151 gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
1154 fixup_call_stmt_edges (node, stmts);
1155 execute_all_ipa_stmt_fixups (node, stmts);
1157 update_ssa (TODO_update_ssa_only_virtuals);
1158 free_dominance_info (CDI_DOMINATORS);
1159 free_dominance_info (CDI_POST_DOMINATORS);
1160 free (stmts);
1161 pop_cfun ();
1164 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1166 static void
1167 input_constructor (tree var, struct data_in *data_in,
1168 struct lto_input_block *ib)
1170 DECL_INITIAL (var) = stream_read_tree (ib, data_in);
1174 /* Read the body from DATA for function NODE and fill it in.
1175 FILE_DATA are the global decls and types. SECTION_TYPE is either
1176 LTO_section_function_body or LTO_section_static_initializer. If
1177 section type is LTO_section_function_body, FN must be the decl for
1178 that function. */
1180 static void
1181 lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symtab_node *node,
1182 const char *data, enum lto_section_type section_type)
1184 const struct lto_function_header *header;
1185 struct data_in *data_in;
1186 int cfg_offset;
1187 int main_offset;
1188 int string_offset;
1189 tree fn_decl = node->decl;
1191 header = (const struct lto_function_header *) data;
1192 if (TREE_CODE (node->decl) == FUNCTION_DECL)
1194 cfg_offset = sizeof (struct lto_function_header);
1195 main_offset = cfg_offset + header->cfg_size;
1196 string_offset = main_offset + header->main_size;
1198 else
1200 main_offset = sizeof (struct lto_function_header);
1201 string_offset = main_offset + header->main_size;
1204 data_in = lto_data_in_create (file_data, data + string_offset,
1205 header->string_size, vNULL);
1207 if (section_type == LTO_section_function_body)
1209 struct lto_in_decl_state *decl_state;
1210 unsigned from;
1212 gcc_checking_assert (node);
1214 /* Use the function's decl state. */
1215 decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
1216 gcc_assert (decl_state);
1217 file_data->current_decl_state = decl_state;
1220 /* Set up the struct function. */
1221 from = data_in->reader_cache->nodes.length ();
1222 lto_input_block ib_main (data + main_offset, header->main_size,
1223 file_data->mode_table);
1224 if (TREE_CODE (node->decl) == FUNCTION_DECL)
1226 lto_input_block ib_cfg (data + cfg_offset, header->cfg_size,
1227 file_data->mode_table);
1228 input_function (fn_decl, data_in, &ib_main, &ib_cfg);
1230 else
1231 input_constructor (fn_decl, data_in, &ib_main);
1232 data_in->location_cache.apply_location_cache ();
1233 /* And fixup types we streamed locally. */
1235 struct streamer_tree_cache_d *cache = data_in->reader_cache;
1236 unsigned len = cache->nodes.length ();
1237 unsigned i;
1238 for (i = len; i-- > from;)
1240 tree t = streamer_tree_cache_get_tree (cache, i);
1241 if (t == NULL_TREE)
1242 continue;
1244 if (TYPE_P (t))
1246 gcc_assert (TYPE_CANONICAL (t) == NULL_TREE);
1247 TYPE_CANONICAL (t) = TYPE_MAIN_VARIANT (t);
1248 if (TYPE_MAIN_VARIANT (t) != t)
1250 gcc_assert (TYPE_NEXT_VARIANT (t) == NULL_TREE);
1251 TYPE_NEXT_VARIANT (t)
1252 = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t));
1253 TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t)) = t;
1259 /* Restore decl state */
1260 file_data->current_decl_state = file_data->global_decl_state;
1263 lto_data_in_delete (data_in);
1267 /* Read the body of NODE using DATA. FILE_DATA holds the global
1268 decls and types. */
1270 void
1271 lto_input_function_body (struct lto_file_decl_data *file_data,
1272 struct cgraph_node *node, const char *data)
1274 lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
1277 /* Read the body of NODE using DATA. FILE_DATA holds the global
1278 decls and types. */
1280 void
1281 lto_input_variable_constructor (struct lto_file_decl_data *file_data,
1282 struct varpool_node *node, const char *data)
1284 lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
1288 /* Read the physical representation of a tree node EXPR from
1289 input block IB using the per-file context in DATA_IN. */
1291 static void
1292 lto_read_tree_1 (struct lto_input_block *ib, struct data_in *data_in, tree expr)
1294 /* Read all the bitfield values in EXPR. Note that for LTO, we
1295 only write language-independent bitfields, so no more unpacking is
1296 needed. */
1297 streamer_read_tree_bitfields (ib, data_in, expr);
1299 /* Read all the pointer fields in EXPR. */
1300 streamer_read_tree_body (ib, data_in, expr);
1302 /* Read any LTO-specific data not read by the tree streamer. */
1303 if (DECL_P (expr)
1304 && TREE_CODE (expr) != FUNCTION_DECL
1305 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
1306 DECL_INITIAL (expr) = stream_read_tree (ib, data_in);
1308 /* We should never try to instantiate an MD or NORMAL builtin here. */
1309 if (TREE_CODE (expr) == FUNCTION_DECL)
1310 gcc_assert (!streamer_handle_as_builtin_p (expr));
1312 #ifdef LTO_STREAMER_DEBUG
1313 /* Remove the mapping to RESULT's original address set by
1314 streamer_alloc_tree. */
1315 lto_orig_address_remove (expr);
1316 #endif
1319 /* Read the physical representation of a tree node with tag TAG from
1320 input block IB using the per-file context in DATA_IN. */
1322 static tree
1323 lto_read_tree (struct lto_input_block *ib, struct data_in *data_in,
1324 enum LTO_tags tag, hashval_t hash)
1326 /* Instantiate a new tree node. */
1327 tree result = streamer_alloc_tree (ib, data_in, tag);
1329 /* Enter RESULT in the reader cache. This will make RESULT
1330 available so that circular references in the rest of the tree
1331 structure can be resolved in subsequent calls to stream_read_tree. */
1332 streamer_tree_cache_append (data_in->reader_cache, result, hash);
1334 lto_read_tree_1 (ib, data_in, result);
1336 /* end_marker = */ streamer_read_uchar (ib);
1338 return result;
1342 /* Populate the reader cache with trees materialized from the SCC
1343 following in the IB, DATA_IN stream. */
1345 hashval_t
1346 lto_input_scc (struct lto_input_block *ib, struct data_in *data_in,
1347 unsigned *len, unsigned *entry_len)
1349 /* A blob of unnamed tree nodes, fill the cache from it and
1350 recurse. */
1351 unsigned size = streamer_read_uhwi (ib);
1352 hashval_t scc_hash = streamer_read_uhwi (ib);
1353 unsigned scc_entry_len = 1;
1355 if (size == 1)
1357 enum LTO_tags tag = streamer_read_record_start (ib);
1358 lto_input_tree_1 (ib, data_in, tag, scc_hash);
1360 else
1362 unsigned int first = data_in->reader_cache->nodes.length ();
1363 tree result;
1365 scc_entry_len = streamer_read_uhwi (ib);
1367 /* Materialize size trees by reading their headers. */
1368 for (unsigned i = 0; i < size; ++i)
1370 enum LTO_tags tag = streamer_read_record_start (ib);
1371 if (tag == LTO_null
1372 || (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
1373 || tag == LTO_tree_pickle_reference
1374 || tag == LTO_builtin_decl
1375 || tag == LTO_integer_cst
1376 || tag == LTO_tree_scc)
1377 gcc_unreachable ();
1379 result = streamer_alloc_tree (ib, data_in, tag);
1380 streamer_tree_cache_append (data_in->reader_cache, result, 0);
1383 /* Read the tree bitpacks and references. */
1384 for (unsigned i = 0; i < size; ++i)
1386 result = streamer_tree_cache_get_tree (data_in->reader_cache,
1387 first + i);
1388 lto_read_tree_1 (ib, data_in, result);
1389 /* end_marker = */ streamer_read_uchar (ib);
1393 *len = size;
1394 *entry_len = scc_entry_len;
1395 return scc_hash;
1399 /* Read a tree from input block IB using the per-file context in
1400 DATA_IN. This context is used, for example, to resolve references
1401 to previously read nodes. */
1403 tree
1404 lto_input_tree_1 (struct lto_input_block *ib, struct data_in *data_in,
1405 enum LTO_tags tag, hashval_t hash)
1407 tree result;
1409 gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
1411 if (tag == LTO_null)
1412 result = NULL_TREE;
1413 else if (tag >= LTO_field_decl_ref && tag <= LTO_namelist_decl_ref)
1415 /* If TAG is a reference to an indexable tree, the next value
1416 in IB is the index into the table where we expect to find
1417 that tree. */
1418 result = lto_input_tree_ref (ib, data_in, cfun, tag);
1420 else if (tag == LTO_tree_pickle_reference)
1422 /* If TAG is a reference to a previously read tree, look it up in
1423 the reader cache. */
1424 result = streamer_get_pickled_tree (ib, data_in);
1426 else if (tag == LTO_builtin_decl)
1428 /* If we are going to read a built-in function, all we need is
1429 the code and class. */
1430 result = streamer_get_builtin_tree (ib, data_in);
1432 else if (tag == LTO_integer_cst)
1434 /* For shared integer constants in singletons we can use the
1435 existing tree integer constant merging code. */
1436 tree type = stream_read_tree (ib, data_in);
1437 unsigned HOST_WIDE_INT len = streamer_read_uhwi (ib);
1438 unsigned HOST_WIDE_INT i;
1439 HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
1441 for (i = 0; i < len; i++)
1442 a[i] = streamer_read_hwi (ib);
1443 gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
1444 result = wide_int_to_tree (type, wide_int::from_array
1445 (a, len, TYPE_PRECISION (type)));
1446 streamer_tree_cache_append (data_in->reader_cache, result, hash);
1448 else if (tag == LTO_tree_scc)
1449 gcc_unreachable ();
1450 else
1452 /* Otherwise, materialize a new node from IB. */
1453 result = lto_read_tree (ib, data_in, tag, hash);
1456 return result;
1459 tree
1460 lto_input_tree (struct lto_input_block *ib, struct data_in *data_in)
1462 enum LTO_tags tag;
1464 /* Input and skip SCCs. */
1465 while ((tag = streamer_read_record_start (ib)) == LTO_tree_scc)
1467 unsigned len, entry_len;
1468 lto_input_scc (ib, data_in, &len, &entry_len);
1470 return lto_input_tree_1 (ib, data_in, tag, 0);
1474 /* Input toplevel asms. */
1476 void
1477 lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base)
1479 size_t len;
1480 const char *data = lto_get_section_data (file_data, LTO_section_asm,
1481 NULL, &len);
1482 const struct lto_simple_header_with_strings *header
1483 = (const struct lto_simple_header_with_strings *) data;
1484 int string_offset;
1485 struct data_in *data_in;
1486 tree str;
1488 if (! data)
1489 return;
1491 string_offset = sizeof (*header) + header->main_size;
1493 lto_input_block ib (data + sizeof (*header), header->main_size,
1494 file_data->mode_table);
1496 data_in = lto_data_in_create (file_data, data + string_offset,
1497 header->string_size, vNULL);
1499 while ((str = streamer_read_string_cst (data_in, &ib)))
1501 asm_node *node = symtab->finalize_toplevel_asm (str);
1502 node->order = streamer_read_hwi (&ib) + order_base;
1503 if (node->order >= symtab->order)
1504 symtab->order = node->order + 1;
1507 lto_data_in_delete (data_in);
1509 lto_free_section_data (file_data, LTO_section_asm, NULL, data, len);
1513 /* Input mode table. */
1515 void
1516 lto_input_mode_table (struct lto_file_decl_data *file_data)
1518 size_t len;
1519 const char *data = lto_get_section_data (file_data, LTO_section_mode_table,
1520 NULL, &len);
1521 if (! data)
1523 internal_error ("cannot read LTO mode table from %s",
1524 file_data->file_name);
1525 return;
1528 unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << 8);
1529 file_data->mode_table = table;
1530 const struct lto_simple_header_with_strings *header
1531 = (const struct lto_simple_header_with_strings *) data;
1532 int string_offset;
1533 struct data_in *data_in;
1534 string_offset = sizeof (*header) + header->main_size;
1536 lto_input_block ib (data + sizeof (*header), header->main_size, NULL);
1537 data_in = lto_data_in_create (file_data, data + string_offset,
1538 header->string_size, vNULL);
1539 bitpack_d bp = streamer_read_bitpack (&ib);
1541 table[VOIDmode] = VOIDmode;
1542 table[BLKmode] = BLKmode;
1543 unsigned int m;
1544 while ((m = bp_unpack_value (&bp, 8)) != VOIDmode)
1546 enum mode_class mclass
1547 = bp_unpack_enum (&bp, mode_class, MAX_MODE_CLASS);
1548 unsigned int size = bp_unpack_value (&bp, 8);
1549 unsigned int prec = bp_unpack_value (&bp, 16);
1550 machine_mode inner = (machine_mode) table[bp_unpack_value (&bp, 8)];
1551 unsigned int nunits = bp_unpack_value (&bp, 8);
1552 unsigned int ibit = 0, fbit = 0;
1553 unsigned int real_fmt_len = 0;
1554 const char *real_fmt_name = NULL;
1555 switch (mclass)
1557 case MODE_FRACT:
1558 case MODE_UFRACT:
1559 case MODE_ACCUM:
1560 case MODE_UACCUM:
1561 ibit = bp_unpack_value (&bp, 8);
1562 fbit = bp_unpack_value (&bp, 8);
1563 break;
1564 case MODE_FLOAT:
1565 case MODE_DECIMAL_FLOAT:
1566 real_fmt_name = bp_unpack_indexed_string (data_in, &bp,
1567 &real_fmt_len);
1568 break;
1569 default:
1570 break;
1572 /* First search just the GET_CLASS_NARROWEST_MODE to wider modes,
1573 if not found, fallback to all modes. */
1574 int pass;
1575 for (pass = 0; pass < 2; pass++)
1576 for (machine_mode mr = pass ? VOIDmode
1577 : GET_CLASS_NARROWEST_MODE (mclass);
1578 pass ? mr < MAX_MACHINE_MODE : mr != VOIDmode;
1579 pass ? mr = (machine_mode) (m + 1)
1580 : mr = GET_MODE_WIDER_MODE (mr))
1581 if (GET_MODE_CLASS (mr) != mclass
1582 || GET_MODE_SIZE (mr) != size
1583 || GET_MODE_PRECISION (mr) != prec
1584 || GET_MODE_INNER (mr) != inner
1585 || GET_MODE_IBIT (mr) != ibit
1586 || GET_MODE_FBIT (mr) != fbit
1587 || GET_MODE_NUNITS (mr) != nunits)
1588 continue;
1589 else if ((mclass == MODE_FLOAT || mclass == MODE_DECIMAL_FLOAT)
1590 && strcmp (REAL_MODE_FORMAT (mr)->name, real_fmt_name) != 0)
1591 continue;
1592 else
1594 table[m] = mr;
1595 pass = 2;
1596 break;
1598 unsigned int mname_len;
1599 const char *mname = bp_unpack_indexed_string (data_in, &bp, &mname_len);
1600 if (pass == 2)
1602 switch (mclass)
1604 case MODE_VECTOR_INT:
1605 case MODE_VECTOR_FLOAT:
1606 case MODE_VECTOR_FRACT:
1607 case MODE_VECTOR_UFRACT:
1608 case MODE_VECTOR_ACCUM:
1609 case MODE_VECTOR_UACCUM:
1610 /* For unsupported vector modes just use BLKmode,
1611 if the scalar mode is supported. */
1612 if (inner != VOIDmode)
1614 table[m] = BLKmode;
1615 break;
1617 /* FALLTHRU */
1618 default:
1619 fatal_error (UNKNOWN_LOCATION, "unsupported mode %s\n", mname);
1620 break;
1624 lto_data_in_delete (data_in);
1626 lto_free_section_data (file_data, LTO_section_mode_table, NULL, data, len);
1630 /* Initialization for the LTO reader. */
1632 void
1633 lto_reader_init (void)
1635 lto_streamer_init ();
1636 file_name_hash_table
1637 = new hash_table<freeing_string_slot_hasher> (37);
1641 /* Create a new data_in object for FILE_DATA. STRINGS is the string
1642 table to use with LEN strings. RESOLUTIONS is the vector of linker
1643 resolutions (NULL if not using a linker plugin). */
1645 struct data_in *
1646 lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
1647 unsigned len,
1648 vec<ld_plugin_symbol_resolution_t> resolutions)
1650 struct data_in *data_in = new (struct data_in);
1651 data_in->file_data = file_data;
1652 data_in->strings = strings;
1653 data_in->strings_len = len;
1654 data_in->globals_resolution = resolutions;
1655 data_in->reader_cache = streamer_tree_cache_create (false, false, true);
1656 return data_in;
1660 /* Remove DATA_IN. */
1662 void
1663 lto_data_in_delete (struct data_in *data_in)
1665 data_in->globals_resolution.release ();
1666 streamer_tree_cache_delete (data_in->reader_cache);
1667 delete data_in;