tree-dfa.c (renumber_gimple_stmt_uids): Also number PHIs.
[gcc.git] / gcc / lto-streamer-in.c
1 /* Read the GIMPLE representation from a file stream.
2
3 Copyright 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 Re-implemented by Diego Novillo <dnovillo@google.com>
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "toplev.h"
28 #include "tree.h"
29 #include "expr.h"
30 #include "flags.h"
31 #include "params.h"
32 #include "input.h"
33 #include "hashtab.h"
34 #include "basic-block.h"
35 #include "tree-flow.h"
36 #include "tree-pass.h"
37 #include "cgraph.h"
38 #include "function.h"
39 #include "ggc.h"
40 #include "diagnostic.h"
41 #include "libfuncs.h"
42 #include "except.h"
43 #include "debug.h"
44 #include "vec.h"
45 #include "timevar.h"
46 #include "output.h"
47 #include "ipa-utils.h"
48 #include "lto-streamer.h"
49 #include "tree-pass.h"
50
51 /* Data structure used to hash file names in the source_location field. */
52 struct string_slot
53 {
54 const char *s;
55 unsigned int slot_num;
56 };
57
58 /* The table to hold the file names. */
59 static htab_t file_name_hash_table;
60
61
62 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
63 number of valid tag values to check. */
64
65 static void
66 lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
67 {
68 va_list ap;
69 int i;
70
71 va_start (ap, ntags);
72 for (i = 0; i < ntags; i++)
73 if ((unsigned) actual == va_arg (ap, unsigned))
74 {
75 va_end (ap);
76 return;
77 }
78
79 va_end (ap);
80 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
81 }
82
83
84 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
85
86 static void
87 lto_tag_check_range (enum LTO_tags actual, enum LTO_tags tag1,
88 enum LTO_tags tag2)
89 {
90 if (actual < tag1 || actual > tag2)
91 internal_error ("bytecode stream: tag %s is not in the expected range "
92 "[%s, %s]",
93 lto_tag_name (actual),
94 lto_tag_name (tag1),
95 lto_tag_name (tag2));
96 }
97
98
99 /* Check that tag ACTUAL == EXPECTED. */
100
101 static void
102 lto_tag_check (enum LTO_tags actual, enum LTO_tags expected)
103 {
104 if (actual != expected)
105 internal_error ("bytecode stream: expected tag %s instead of %s",
106 lto_tag_name (expected), lto_tag_name (actual));
107 }
108
109
110 /* Return a hash code for P. */
111
112 static hashval_t
113 hash_string_slot_node (const void *p)
114 {
115 const struct string_slot *ds = (const struct string_slot *) p;
116 return (hashval_t) htab_hash_string (ds->s);
117 }
118
119
120 /* Returns nonzero if P1 and P2 are equal. */
121
122 static int
123 eq_string_slot_node (const void *p1, const void *p2)
124 {
125 const struct string_slot *ds1 = (const struct string_slot *) p1;
126 const struct string_slot *ds2 = (const struct string_slot *) p2;
127 return strcmp (ds1->s, ds2->s) == 0;
128 }
129
130
131 /* Read a string from the string table in DATA_IN using input block
132 IB. Write the length to RLEN. */
133
134 static const char *
135 input_string_internal (struct data_in *data_in, struct lto_input_block *ib,
136 unsigned int *rlen)
137 {
138 struct lto_input_block str_tab;
139 unsigned int len;
140 unsigned int loc;
141 const char *result;
142
143 /* Read the location of the string from IB. */
144 loc = lto_input_uleb128 (ib);
145
146 /* Get the string stored at location LOC in DATA_IN->STRINGS. */
147 LTO_INIT_INPUT_BLOCK (str_tab, data_in->strings, loc, data_in->strings_len);
148 len = lto_input_uleb128 (&str_tab);
149 *rlen = len;
150
151 if (str_tab.p + len > data_in->strings_len)
152 internal_error ("bytecode stream: string too long for the string table");
153
154 result = (const char *)(data_in->strings + str_tab.p);
155
156 return result;
157 }
158
159
160 /* Read a STRING_CST from the string table in DATA_IN using input
161 block IB. */
162
163 static tree
164 input_string_cst (struct data_in *data_in, struct lto_input_block *ib)
165 {
166 unsigned int len;
167 const char * ptr;
168 unsigned int is_null;
169
170 is_null = lto_input_uleb128 (ib);
171 if (is_null)
172 return NULL;
173
174 ptr = input_string_internal (data_in, ib, &len);
175 return build_string (len, ptr);
176 }
177
178
179 /* Read an IDENTIFIER from the string table in DATA_IN using input
180 block IB. */
181
182 static tree
183 input_identifier (struct data_in *data_in, struct lto_input_block *ib)
184 {
185 unsigned int len;
186 const char *ptr;
187 unsigned int is_null;
188
189 is_null = lto_input_uleb128 (ib);
190 if (is_null)
191 return NULL;
192
193 ptr = input_string_internal (data_in, ib, &len);
194 return get_identifier_with_length (ptr, len);
195 }
196
197
198 /* Read LENGTH bytes from STREAM to ADDR. */
199
200 void
201 lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length)
202 {
203 size_t i;
204 unsigned char *const buffer = (unsigned char *const) addr;
205
206 for (i = 0; i < length; i++)
207 buffer[i] = lto_input_1_unsigned (ib);
208 }
209
210
211 /* Read a NULL terminated string from the string table in DATA_IN. */
212
213 const char *
214 lto_input_string (struct data_in *data_in, struct lto_input_block *ib)
215 {
216 unsigned int len;
217 const char *ptr;
218 unsigned int is_null;
219
220 is_null = lto_input_uleb128 (ib);
221 if (is_null)
222 return NULL;
223
224 ptr = input_string_internal (data_in, ib, &len);
225 if (ptr[len - 1] != '\0')
226 internal_error ("bytecode stream: found non-null terminated string");
227
228 return ptr;
229 }
230
231
232 /* Return the next tag in the input block IB. */
233
234 static enum LTO_tags
235 input_record_start (struct lto_input_block *ib)
236 {
237 enum LTO_tags tag = (enum LTO_tags) lto_input_uleb128 (ib);
238 return tag;
239 }
240
241
242 /* Lookup STRING in file_name_hash_table. If found, return the existing
243 string, otherwise insert STRING as the canonical version. */
244
245 static const char *
246 canon_file_name (const char *string)
247 {
248 void **slot;
249 struct string_slot s_slot;
250 s_slot.s = string;
251
252 slot = htab_find_slot (file_name_hash_table, &s_slot, INSERT);
253 if (*slot == NULL)
254 {
255 size_t len;
256 char *saved_string;
257 struct string_slot *new_slot;
258
259 len = strlen (string);
260 saved_string = (char *) xmalloc (len + 1);
261 new_slot = XCNEW (struct string_slot);
262 strcpy (saved_string, string);
263 new_slot->s = saved_string;
264 *slot = new_slot;
265 return saved_string;
266 }
267 else
268 {
269 struct string_slot *old_slot = (struct string_slot *) *slot;
270 return old_slot->s;
271 }
272 }
273
274
275 /* Clear the line info stored in DATA_IN. */
276
277 static void
278 clear_line_info (struct data_in *data_in)
279 {
280 if (data_in->current_file)
281 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
282 data_in->current_file = NULL;
283 data_in->current_line = 0;
284 data_in->current_col = 0;
285 }
286
287
288 /* Read a location from input block IB. */
289
290 static location_t
291 lto_input_location (struct lto_input_block *ib, struct data_in *data_in)
292 {
293 expanded_location xloc;
294
295 xloc.file = lto_input_string (data_in, ib);
296 if (xloc.file == NULL)
297 return UNKNOWN_LOCATION;
298
299 xloc.file = canon_file_name (xloc.file);
300 xloc.line = lto_input_sleb128 (ib);
301 xloc.column = lto_input_sleb128 (ib);
302 xloc.sysp = lto_input_sleb128 (ib);
303
304 if (data_in->current_file != xloc.file)
305 {
306 if (data_in->current_file)
307 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
308
309 linemap_add (line_table, LC_ENTER, xloc.sysp, xloc.file, xloc.line);
310 }
311 else if (data_in->current_line != xloc.line)
312 linemap_line_start (line_table, xloc.line, xloc.column);
313
314 data_in->current_file = xloc.file;
315 data_in->current_line = xloc.line;
316 data_in->current_col = xloc.column;
317
318 return linemap_position_for_column (line_table, xloc.column);
319 }
320
321
322 /* Read a reference to a tree node from DATA_IN using input block IB.
323 TAG is the expected node that should be found in IB, if TAG belongs
324 to one of the indexable trees, expect to read a reference index to
325 be looked up in one of the symbol tables, otherwise read the pysical
326 representation of the tree using lto_input_tree. FN is the
327 function scope for the read tree. */
328
329 static tree
330 lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in,
331 struct function *fn, enum LTO_tags tag)
332 {
333 unsigned HOST_WIDE_INT ix_u;
334 tree result = NULL_TREE;
335
336 lto_tag_check_range (tag, LTO_field_decl_ref, LTO_global_decl_ref);
337
338 switch (tag)
339 {
340 case LTO_type_ref:
341 ix_u = lto_input_uleb128 (ib);
342 result = lto_file_decl_data_get_type (data_in->file_data, ix_u);
343 break;
344
345 case LTO_ssa_name_ref:
346 ix_u = lto_input_uleb128 (ib);
347 result = VEC_index (tree, SSANAMES (fn), ix_u);
348 break;
349
350 case LTO_field_decl_ref:
351 ix_u = lto_input_uleb128 (ib);
352 result = lto_file_decl_data_get_field_decl (data_in->file_data, ix_u);
353 break;
354
355 case LTO_function_decl_ref:
356 ix_u = lto_input_uleb128 (ib);
357 result = lto_file_decl_data_get_fn_decl (data_in->file_data, ix_u);
358 break;
359
360 case LTO_type_decl_ref:
361 ix_u = lto_input_uleb128 (ib);
362 result = lto_file_decl_data_get_type_decl (data_in->file_data, ix_u);
363 break;
364
365 case LTO_namespace_decl_ref:
366 ix_u = lto_input_uleb128 (ib);
367 result = lto_file_decl_data_get_namespace_decl (data_in->file_data, ix_u);
368 break;
369
370 case LTO_global_decl_ref:
371 case LTO_result_decl_ref:
372 case LTO_const_decl_ref:
373 case LTO_imported_decl_ref:
374 case LTO_label_decl_ref:
375 case LTO_translation_unit_decl_ref:
376 ix_u = lto_input_uleb128 (ib);
377 result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u);
378 break;
379
380 default:
381 gcc_unreachable ();
382 }
383
384 gcc_assert (result);
385
386 return result;
387 }
388
389
390 /* Read and return a double-linked list of catch handlers from input
391 block IB, using descriptors in DATA_IN. */
392
393 static struct eh_catch_d *
394 lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in,
395 eh_catch *last_p)
396 {
397 eh_catch first;
398 enum LTO_tags tag;
399
400 *last_p = first = NULL;
401 tag = input_record_start (ib);
402 while (tag)
403 {
404 tree list;
405 eh_catch n;
406
407 lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
408
409 /* Read the catch node. */
410 n = ggc_alloc_cleared_eh_catch_d ();
411 n->type_list = lto_input_tree (ib, data_in);
412 n->filter_list = lto_input_tree (ib, data_in);
413 n->label = lto_input_tree (ib, data_in);
414
415 /* Register all the types in N->FILTER_LIST. */
416 for (list = n->filter_list; list; list = TREE_CHAIN (list))
417 add_type_for_runtime (TREE_VALUE (list));
418
419 /* Chain N to the end of the list. */
420 if (*last_p)
421 (*last_p)->next_catch = n;
422 n->prev_catch = *last_p;
423 *last_p = n;
424
425 /* Set the head of the list the first time through the loop. */
426 if (first == NULL)
427 first = n;
428
429 tag = input_record_start (ib);
430 }
431
432 return first;
433 }
434
435
436 /* Read and return EH region IX from input block IB, using descriptors
437 in DATA_IN. */
438
439 static eh_region
440 input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
441 {
442 enum LTO_tags tag;
443 eh_region r;
444
445 /* Read the region header. */
446 tag = input_record_start (ib);
447 if (tag == LTO_null)
448 return NULL;
449
450 r = ggc_alloc_cleared_eh_region_d ();
451 r->index = lto_input_sleb128 (ib);
452
453 gcc_assert (r->index == ix);
454
455 /* Read all the region pointers as region numbers. We'll fix up
456 the pointers once the whole array has been read. */
457 r->outer = (eh_region) (intptr_t) lto_input_sleb128 (ib);
458 r->inner = (eh_region) (intptr_t) lto_input_sleb128 (ib);
459 r->next_peer = (eh_region) (intptr_t) lto_input_sleb128 (ib);
460
461 switch (tag)
462 {
463 case LTO_ert_cleanup:
464 r->type = ERT_CLEANUP;
465 break;
466
467 case LTO_ert_try:
468 {
469 struct eh_catch_d *last_catch;
470 r->type = ERT_TRY;
471 r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
472 &last_catch);
473 r->u.eh_try.last_catch = last_catch;
474 break;
475 }
476
477 case LTO_ert_allowed_exceptions:
478 {
479 tree l;
480
481 r->type = ERT_ALLOWED_EXCEPTIONS;
482 r->u.allowed.type_list = lto_input_tree (ib, data_in);
483 r->u.allowed.label = lto_input_tree (ib, data_in);
484 r->u.allowed.filter = lto_input_uleb128 (ib);
485
486 for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
487 add_type_for_runtime (TREE_VALUE (l));
488 }
489 break;
490
491 case LTO_ert_must_not_throw:
492 r->type = ERT_MUST_NOT_THROW;
493 r->u.must_not_throw.failure_decl = lto_input_tree (ib, data_in);
494 r->u.must_not_throw.failure_loc = lto_input_location (ib, data_in);
495 break;
496
497 default:
498 gcc_unreachable ();
499 }
500
501 r->landing_pads = (eh_landing_pad) (intptr_t) lto_input_sleb128 (ib);
502
503 return r;
504 }
505
506
507 /* Read and return EH landing pad IX from input block IB, using descriptors
508 in DATA_IN. */
509
510 static eh_landing_pad
511 input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix)
512 {
513 enum LTO_tags tag;
514 eh_landing_pad lp;
515
516 /* Read the landing pad header. */
517 tag = input_record_start (ib);
518 if (tag == LTO_null)
519 return NULL;
520
521 lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
522
523 lp = ggc_alloc_cleared_eh_landing_pad_d ();
524 lp->index = lto_input_sleb128 (ib);
525 gcc_assert (lp->index == ix);
526 lp->next_lp = (eh_landing_pad) (intptr_t) lto_input_sleb128 (ib);
527 lp->region = (eh_region) (intptr_t) lto_input_sleb128 (ib);
528 lp->post_landing_pad = lto_input_tree (ib, data_in);
529
530 return lp;
531 }
532
533
534 /* After reading the EH regions, pointers to peer and children regions
535 are region numbers. This converts all these region numbers into
536 real pointers into the rematerialized regions for FN. ROOT_REGION
537 is the region number for the root EH region in FN. */
538
539 static void
540 fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
541 {
542 unsigned i;
543 VEC(eh_region,gc) *eh_array = fn->eh->region_array;
544 VEC(eh_landing_pad,gc) *lp_array = fn->eh->lp_array;
545 eh_region r;
546 eh_landing_pad lp;
547
548 gcc_assert (eh_array && lp_array);
549
550 gcc_assert (root_region >= 0);
551 fn->eh->region_tree = VEC_index (eh_region, eh_array, root_region);
552
553 #define FIXUP_EH_REGION(r) (r) = VEC_index (eh_region, eh_array, \
554 (HOST_WIDE_INT) (intptr_t) (r))
555 #define FIXUP_EH_LP(p) (p) = VEC_index (eh_landing_pad, lp_array, \
556 (HOST_WIDE_INT) (intptr_t) (p))
557
558 /* Convert all the index numbers stored in pointer fields into
559 pointers to the corresponding slots in the EH region array. */
560 FOR_EACH_VEC_ELT (eh_region, eh_array, i, r)
561 {
562 /* The array may contain NULL regions. */
563 if (r == NULL)
564 continue;
565
566 gcc_assert (i == (unsigned) r->index);
567 FIXUP_EH_REGION (r->outer);
568 FIXUP_EH_REGION (r->inner);
569 FIXUP_EH_REGION (r->next_peer);
570 FIXUP_EH_LP (r->landing_pads);
571 }
572
573 /* Convert all the index numbers stored in pointer fields into
574 pointers to the corresponding slots in the EH landing pad array. */
575 FOR_EACH_VEC_ELT (eh_landing_pad, lp_array, i, lp)
576 {
577 /* The array may contain NULL landing pads. */
578 if (lp == NULL)
579 continue;
580
581 gcc_assert (i == (unsigned) lp->index);
582 FIXUP_EH_LP (lp->next_lp);
583 FIXUP_EH_REGION (lp->region);
584 }
585
586 #undef FIXUP_EH_REGION
587 #undef FIXUP_EH_LP
588 }
589
590
591 /* Initialize EH support. */
592
593 static void
594 lto_init_eh (void)
595 {
596 static bool eh_initialized_p = false;
597
598 if (eh_initialized_p)
599 return;
600
601 /* Contrary to most other FEs, we only initialize EH support when at
602 least one of the files in the set contains exception regions in
603 it. Since this happens much later than the call to init_eh in
604 lang_dependent_init, we have to set flag_exceptions and call
605 init_eh again to initialize the EH tables. */
606 flag_exceptions = 1;
607 init_eh ();
608
609 /* Initialize dwarf2 tables. Since dwarf2out_do_frame() returns
610 true only when exceptions are enabled, this initialization is
611 never done during lang_dependent_init. */
612 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
613 if (dwarf2out_do_frame ())
614 dwarf2out_frame_init ();
615 #endif
616
617 eh_initialized_p = true;
618 }
619
620
621 /* Read the exception table for FN from IB using the data descriptors
622 in DATA_IN. */
623
624 static void
625 input_eh_regions (struct lto_input_block *ib, struct data_in *data_in,
626 struct function *fn)
627 {
628 HOST_WIDE_INT i, root_region, len;
629 enum LTO_tags tag;
630
631 tag = input_record_start (ib);
632 if (tag == LTO_null)
633 return;
634
635 lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
636
637 /* If the file contains EH regions, then it was compiled with
638 -fexceptions. In that case, initialize the backend EH
639 machinery. */
640 lto_init_eh ();
641
642 gcc_assert (fn->eh);
643
644 root_region = lto_input_sleb128 (ib);
645 gcc_assert (root_region == (int) root_region);
646
647 /* Read the EH region array. */
648 len = lto_input_sleb128 (ib);
649 gcc_assert (len == (int) len);
650 if (len > 0)
651 {
652 VEC_safe_grow (eh_region, gc, fn->eh->region_array, len);
653 for (i = 0; i < len; i++)
654 {
655 eh_region r = input_eh_region (ib, data_in, i);
656 VEC_replace (eh_region, fn->eh->region_array, i, r);
657 }
658 }
659
660 /* Read the landing pads. */
661 len = lto_input_sleb128 (ib);
662 gcc_assert (len == (int) len);
663 if (len > 0)
664 {
665 VEC_safe_grow (eh_landing_pad, gc, fn->eh->lp_array, len);
666 for (i = 0; i < len; i++)
667 {
668 eh_landing_pad lp = input_eh_lp (ib, data_in, i);
669 VEC_replace (eh_landing_pad, fn->eh->lp_array, i, lp);
670 }
671 }
672
673 /* Read the runtime type data. */
674 len = lto_input_sleb128 (ib);
675 gcc_assert (len == (int) len);
676 if (len > 0)
677 {
678 VEC_safe_grow (tree, gc, fn->eh->ttype_data, len);
679 for (i = 0; i < len; i++)
680 {
681 tree ttype = lto_input_tree (ib, data_in);
682 VEC_replace (tree, fn->eh->ttype_data, i, ttype);
683 }
684 }
685
686 /* Read the table of action chains. */
687 len = lto_input_sleb128 (ib);
688 gcc_assert (len == (int) len);
689 if (len > 0)
690 {
691 if (targetm.arm_eabi_unwinder)
692 {
693 VEC_safe_grow (tree, gc, fn->eh->ehspec_data.arm_eabi, len);
694 for (i = 0; i < len; i++)
695 {
696 tree t = lto_input_tree (ib, data_in);
697 VEC_replace (tree, fn->eh->ehspec_data.arm_eabi, i, t);
698 }
699 }
700 else
701 {
702 VEC_safe_grow (uchar, gc, fn->eh->ehspec_data.other, len);
703 for (i = 0; i < len; i++)
704 {
705 uchar c = lto_input_1_unsigned (ib);
706 VEC_replace (uchar, fn->eh->ehspec_data.other, i, c);
707 }
708 }
709 }
710
711 /* Reconstruct the EH region tree by fixing up the peer/children
712 pointers. */
713 fixup_eh_region_pointers (fn, root_region);
714
715 tag = input_record_start (ib);
716 lto_tag_check_range (tag, LTO_null, LTO_null);
717 }
718
719
720 /* Make a new basic block with index INDEX in function FN. */
721
722 static basic_block
723 make_new_block (struct function *fn, unsigned int index)
724 {
725 basic_block bb = alloc_block ();
726 bb->index = index;
727 SET_BASIC_BLOCK_FOR_FUNCTION (fn, index, bb);
728 bb->il.gimple = ggc_alloc_cleared_gimple_bb_info ();
729 n_basic_blocks_for_function (fn)++;
730 bb->flags = 0;
731 set_bb_seq (bb, gimple_seq_alloc ());
732 return bb;
733 }
734
735
736 /* Read the CFG for function FN from input block IB. */
737
738 static void
739 input_cfg (struct lto_input_block *ib, struct function *fn,
740 int count_materialization_scale)
741 {
742 unsigned int bb_count;
743 basic_block p_bb;
744 unsigned int i;
745 int index;
746
747 init_empty_tree_cfg_for_function (fn);
748 init_ssa_operands ();
749
750 profile_status_for_function (fn) =
751 (enum profile_status_d) lto_input_uleb128 (ib);
752
753 bb_count = lto_input_uleb128 (ib);
754
755 last_basic_block_for_function (fn) = bb_count;
756 if (bb_count > VEC_length (basic_block, basic_block_info_for_function (fn)))
757 VEC_safe_grow_cleared (basic_block, gc,
758 basic_block_info_for_function (fn), bb_count);
759
760 if (bb_count > VEC_length (basic_block, label_to_block_map_for_function (fn)))
761 VEC_safe_grow_cleared (basic_block, gc,
762 label_to_block_map_for_function (fn), bb_count);
763
764 index = lto_input_sleb128 (ib);
765 while (index != -1)
766 {
767 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
768 unsigned int edge_count;
769
770 if (bb == NULL)
771 bb = make_new_block (fn, index);
772
773 edge_count = lto_input_uleb128 (ib);
774
775 /* Connect up the CFG. */
776 for (i = 0; i < edge_count; i++)
777 {
778 unsigned int dest_index;
779 unsigned int edge_flags;
780 basic_block dest;
781 int probability;
782 gcov_type count;
783 edge e;
784
785 dest_index = lto_input_uleb128 (ib);
786 probability = (int) lto_input_sleb128 (ib);
787 count = ((gcov_type) lto_input_sleb128 (ib) * count_materialization_scale
788 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
789 edge_flags = lto_input_uleb128 (ib);
790
791 dest = BASIC_BLOCK_FOR_FUNCTION (fn, dest_index);
792
793 if (dest == NULL)
794 dest = make_new_block (fn, dest_index);
795
796 e = make_edge (bb, dest, edge_flags);
797 e->probability = probability;
798 e->count = count;
799 }
800
801 index = lto_input_sleb128 (ib);
802 }
803
804 p_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(fn);
805 index = lto_input_sleb128 (ib);
806 while (index != -1)
807 {
808 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
809 bb->prev_bb = p_bb;
810 p_bb->next_bb = bb;
811 p_bb = bb;
812 index = lto_input_sleb128 (ib);
813 }
814 }
815
816
817 /* Read a PHI function for basic block BB in function FN. DATA_IN is
818 the file being read. IB is the input block to use for reading. */
819
820 static gimple
821 input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
822 struct function *fn)
823 {
824 unsigned HOST_WIDE_INT ix;
825 tree phi_result;
826 int i, len;
827 gimple result;
828
829 ix = lto_input_uleb128 (ib);
830 phi_result = VEC_index (tree, SSANAMES (fn), ix);
831 len = EDGE_COUNT (bb->preds);
832 result = create_phi_node (phi_result, bb);
833 SSA_NAME_DEF_STMT (phi_result) = result;
834
835 /* We have to go through a lookup process here because the preds in the
836 reconstructed graph are generally in a different order than they
837 were in the original program. */
838 for (i = 0; i < len; i++)
839 {
840 tree def = lto_input_tree (ib, data_in);
841 int src_index = lto_input_uleb128 (ib);
842 location_t arg_loc = lto_input_location (ib, data_in);
843 basic_block sbb = BASIC_BLOCK_FOR_FUNCTION (fn, src_index);
844
845 edge e = NULL;
846 int j;
847
848 for (j = 0; j < len; j++)
849 if (EDGE_PRED (bb, j)->src == sbb)
850 {
851 e = EDGE_PRED (bb, j);
852 break;
853 }
854
855 add_phi_arg (result, def, e, arg_loc);
856 }
857
858 return result;
859 }
860
861
862 /* Read the SSA names array for function FN from DATA_IN using input
863 block IB. */
864
865 static void
866 input_ssa_names (struct lto_input_block *ib, struct data_in *data_in,
867 struct function *fn)
868 {
869 unsigned int i, size;
870
871 size = lto_input_uleb128 (ib);
872 init_ssanames (fn, size);
873
874 i = lto_input_uleb128 (ib);
875 while (i)
876 {
877 tree ssa_name, name;
878 bool is_default_def;
879
880 /* Skip over the elements that had been freed. */
881 while (VEC_length (tree, SSANAMES (fn)) < i)
882 VEC_quick_push (tree, SSANAMES (fn), NULL_TREE);
883
884 is_default_def = (lto_input_1_unsigned (ib) != 0);
885 name = lto_input_tree (ib, data_in);
886 ssa_name = make_ssa_name_fn (fn, name, gimple_build_nop ());
887
888 if (is_default_def)
889 set_default_def (SSA_NAME_VAR (ssa_name), ssa_name);
890
891 i = lto_input_uleb128 (ib);
892 }
893 }
894
895 /* Read a statement with tag TAG in function FN from block IB using
896 descriptors in DATA_IN. */
897
898 static gimple
899 input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
900 struct function *fn, enum LTO_tags tag)
901 {
902 gimple stmt;
903 enum gimple_code code;
904 unsigned HOST_WIDE_INT num_ops;
905 size_t i;
906 struct bitpack_d bp;
907
908 code = lto_tag_to_gimple_code (tag);
909
910 /* Read the tuple header. */
911 bp = lto_input_bitpack (ib);
912 num_ops = bp_unpack_value (&bp, sizeof (unsigned) * 8);
913 stmt = gimple_alloc (code, num_ops);
914 stmt->gsbase.no_warning = bp_unpack_value (&bp, 1);
915 if (is_gimple_assign (stmt))
916 stmt->gsbase.nontemporal_move = bp_unpack_value (&bp, 1);
917 stmt->gsbase.has_volatile_ops = bp_unpack_value (&bp, 1);
918 stmt->gsbase.subcode = bp_unpack_value (&bp, 16);
919
920 /* Read location information. */
921 gimple_set_location (stmt, lto_input_location (ib, data_in));
922
923 /* Read lexical block reference. */
924 gimple_set_block (stmt, lto_input_tree (ib, data_in));
925
926 /* Read in all the operands. */
927 switch (code)
928 {
929 case GIMPLE_RESX:
930 gimple_resx_set_region (stmt, lto_input_sleb128 (ib));
931 break;
932
933 case GIMPLE_EH_MUST_NOT_THROW:
934 gimple_eh_must_not_throw_set_fndecl (stmt, lto_input_tree (ib, data_in));
935 break;
936
937 case GIMPLE_EH_DISPATCH:
938 gimple_eh_dispatch_set_region (stmt, lto_input_sleb128 (ib));
939 break;
940
941 case GIMPLE_ASM:
942 {
943 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
944 tree str;
945 stmt->gimple_asm.ni = lto_input_uleb128 (ib);
946 stmt->gimple_asm.no = lto_input_uleb128 (ib);
947 stmt->gimple_asm.nc = lto_input_uleb128 (ib);
948 stmt->gimple_asm.nl = lto_input_uleb128 (ib);
949 str = input_string_cst (data_in, ib);
950 stmt->gimple_asm.string = TREE_STRING_POINTER (str);
951 }
952 /* Fallthru */
953
954 case GIMPLE_ASSIGN:
955 case GIMPLE_CALL:
956 case GIMPLE_RETURN:
957 case GIMPLE_SWITCH:
958 case GIMPLE_LABEL:
959 case GIMPLE_COND:
960 case GIMPLE_GOTO:
961 case GIMPLE_DEBUG:
962 for (i = 0; i < num_ops; i++)
963 {
964 tree op = lto_input_tree (ib, data_in);
965 gimple_set_op (stmt, i, op);
966 if (!op)
967 continue;
968
969 /* Fixup FIELD_DECLs in COMPONENT_REFs, they are not handled
970 by decl merging. */
971 if (TREE_CODE (op) == ADDR_EXPR)
972 op = TREE_OPERAND (op, 0);
973 while (handled_component_p (op))
974 {
975 if (TREE_CODE (op) == COMPONENT_REF)
976 {
977 tree field, type, tem;
978 tree closest_match = NULL_TREE;
979 field = TREE_OPERAND (op, 1);
980 type = DECL_CONTEXT (field);
981 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
982 {
983 if (tem == field)
984 break;
985 if (DECL_NONADDRESSABLE_P (tem)
986 == DECL_NONADDRESSABLE_P (field)
987 && gimple_compare_field_offset (tem, field))
988 {
989 if (types_compatible_p (TREE_TYPE (tem),
990 TREE_TYPE (field)))
991 break;
992 else
993 closest_match = tem;
994 }
995 }
996 /* In case of type mismatches across units we can fail
997 to unify some types and thus not find a proper
998 field-decl here. */
999 if (tem == NULL_TREE)
1000 {
1001 /* Thus, emit a ODR violation warning. */
1002 if (warning_at (gimple_location (stmt), 0,
1003 "use of type %<%E%> with two mismatching "
1004 "declarations at field %<%E%>",
1005 type, TREE_OPERAND (op, 1)))
1006 {
1007 if (TYPE_FIELDS (type))
1008 inform (DECL_SOURCE_LOCATION (TYPE_FIELDS (type)),
1009 "original type declared here");
1010 inform (DECL_SOURCE_LOCATION (TREE_OPERAND (op, 1)),
1011 "field in mismatching type declared here");
1012 if (TYPE_NAME (TREE_TYPE (field))
1013 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
1014 == TYPE_DECL))
1015 inform (DECL_SOURCE_LOCATION
1016 (TYPE_NAME (TREE_TYPE (field))),
1017 "type of field declared here");
1018 if (closest_match
1019 && TYPE_NAME (TREE_TYPE (closest_match))
1020 && (TREE_CODE (TYPE_NAME
1021 (TREE_TYPE (closest_match))) == TYPE_DECL))
1022 inform (DECL_SOURCE_LOCATION
1023 (TYPE_NAME (TREE_TYPE (closest_match))),
1024 "type of mismatching field declared here");
1025 }
1026 /* And finally fixup the types. */
1027 TREE_OPERAND (op, 0)
1028 = build1 (VIEW_CONVERT_EXPR, type,
1029 TREE_OPERAND (op, 0));
1030 }
1031 else
1032 TREE_OPERAND (op, 1) = tem;
1033 }
1034
1035 op = TREE_OPERAND (op, 0);
1036 }
1037 }
1038 break;
1039
1040 case GIMPLE_NOP:
1041 case GIMPLE_PREDICT:
1042 break;
1043
1044 default:
1045 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
1046 lto_tag_name (tag));
1047 }
1048
1049 /* Update the properties of symbols, SSA names and labels associated
1050 with STMT. */
1051 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1052 {
1053 tree lhs = gimple_get_lhs (stmt);
1054 if (lhs && TREE_CODE (lhs) == SSA_NAME)
1055 SSA_NAME_DEF_STMT (lhs) = stmt;
1056 }
1057 else if (code == GIMPLE_LABEL)
1058 gcc_assert (emit_label_in_global_context_p (gimple_label_label (stmt))
1059 || DECL_CONTEXT (gimple_label_label (stmt)) == fn->decl);
1060 else if (code == GIMPLE_ASM)
1061 {
1062 unsigned i;
1063
1064 for (i = 0; i < gimple_asm_noutputs (stmt); i++)
1065 {
1066 tree op = TREE_VALUE (gimple_asm_output_op (stmt, i));
1067 if (TREE_CODE (op) == SSA_NAME)
1068 SSA_NAME_DEF_STMT (op) = stmt;
1069 }
1070 }
1071
1072 /* Reset alias information. */
1073 if (code == GIMPLE_CALL)
1074 gimple_call_reset_alias_info (stmt);
1075
1076 /* Mark the statement modified so its operand vectors can be filled in. */
1077 gimple_set_modified (stmt, true);
1078
1079 return stmt;
1080 }
1081
1082
1083 /* Read a basic block with tag TAG from DATA_IN using input block IB.
1084 FN is the function being processed. */
1085
1086 static void
1087 input_bb (struct lto_input_block *ib, enum LTO_tags tag,
1088 struct data_in *data_in, struct function *fn,
1089 int count_materialization_scale)
1090 {
1091 unsigned int index;
1092 basic_block bb;
1093 gimple_stmt_iterator bsi;
1094
1095 /* This routine assumes that CFUN is set to FN, as it needs to call
1096 basic GIMPLE routines that use CFUN. */
1097 gcc_assert (cfun == fn);
1098
1099 index = lto_input_uleb128 (ib);
1100 bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
1101
1102 bb->count = (lto_input_sleb128 (ib) * count_materialization_scale
1103 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
1104 bb->loop_depth = lto_input_sleb128 (ib);
1105 bb->frequency = lto_input_sleb128 (ib);
1106 bb->flags = lto_input_sleb128 (ib);
1107
1108 /* LTO_bb1 has statements. LTO_bb0 does not. */
1109 if (tag == LTO_bb0)
1110 return;
1111
1112 bsi = gsi_start_bb (bb);
1113 tag = input_record_start (ib);
1114 while (tag)
1115 {
1116 gimple stmt = input_gimple_stmt (ib, data_in, fn, tag);
1117 if (!is_gimple_debug (stmt))
1118 find_referenced_vars_in (stmt);
1119 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
1120
1121 /* After the statement, expect a 0 delimiter or the EH region
1122 that the previous statement belongs to. */
1123 tag = input_record_start (ib);
1124 lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
1125
1126 if (tag == LTO_eh_region)
1127 {
1128 HOST_WIDE_INT region = lto_input_sleb128 (ib);
1129 gcc_assert (region == (int) region);
1130 add_stmt_to_eh_lp (stmt, region);
1131 }
1132
1133 tag = input_record_start (ib);
1134 }
1135
1136 tag = input_record_start (ib);
1137 while (tag)
1138 {
1139 gimple phi = input_phi (ib, bb, data_in, fn);
1140 find_referenced_vars_in (phi);
1141 tag = input_record_start (ib);
1142 }
1143 }
1144
1145 /* Go through all NODE edges and fixup call_stmt pointers
1146 so they point to STMTS. */
1147
1148 static void
1149 fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple *stmts)
1150 {
1151 struct cgraph_edge *cedge;
1152 for (cedge = node->callees; cedge; cedge = cedge->next_callee)
1153 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
1154 for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
1155 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
1156 }
1157
1158 /* Fixup call_stmt pointers in NODE and all clones. */
1159
1160 static void
1161 fixup_call_stmt_edges (struct cgraph_node *orig, gimple *stmts)
1162 {
1163 struct cgraph_node *node;
1164
1165 while (orig->clone_of)
1166 orig = orig->clone_of;
1167
1168 fixup_call_stmt_edges_1 (orig, stmts);
1169 if (orig->clones)
1170 for (node = orig->clones; node != orig;)
1171 {
1172 fixup_call_stmt_edges_1 (node, stmts);
1173 if (node->clones)
1174 node = node->clones;
1175 else if (node->next_sibling_clone)
1176 node = node->next_sibling_clone;
1177 else
1178 {
1179 while (node != orig && !node->next_sibling_clone)
1180 node = node->clone_of;
1181 if (node != orig)
1182 node = node->next_sibling_clone;
1183 }
1184 }
1185 }
1186
1187 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1188
1189 static void
1190 input_function (tree fn_decl, struct data_in *data_in,
1191 struct lto_input_block *ib)
1192 {
1193 struct function *fn;
1194 enum LTO_tags tag;
1195 gimple *stmts;
1196 basic_block bb;
1197 struct bitpack_d bp;
1198 struct cgraph_node *node;
1199 tree args, narg, oarg;
1200 int len;
1201
1202 fn = DECL_STRUCT_FUNCTION (fn_decl);
1203 tag = input_record_start (ib);
1204 clear_line_info (data_in);
1205
1206 gimple_register_cfg_hooks ();
1207 lto_tag_check (tag, LTO_function);
1208
1209 /* Read all the attributes for FN. */
1210 bp = lto_input_bitpack (ib);
1211 fn->is_thunk = bp_unpack_value (&bp, 1);
1212 fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
1213 fn->after_tree_profile = bp_unpack_value (&bp, 1);
1214 fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
1215 fn->returns_struct = bp_unpack_value (&bp, 1);
1216 fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
1217 fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
1218 fn->after_inlining = bp_unpack_value (&bp, 1);
1219 fn->dont_save_pending_sizes_p = bp_unpack_value (&bp, 1);
1220 fn->stdarg = bp_unpack_value (&bp, 1);
1221 fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
1222 fn->calls_alloca = bp_unpack_value (&bp, 1);
1223 fn->calls_setjmp = bp_unpack_value (&bp, 1);
1224 fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
1225 fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
1226
1227 /* Input the function start and end loci. */
1228 fn->function_start_locus = lto_input_location (ib, data_in);
1229 fn->function_end_locus = lto_input_location (ib, data_in);
1230
1231 /* Input the current IL state of the function. */
1232 fn->curr_properties = lto_input_uleb128 (ib);
1233
1234 /* Read the static chain and non-local goto save area. */
1235 fn->static_chain_decl = lto_input_tree (ib, data_in);
1236 fn->nonlocal_goto_save_area = lto_input_tree (ib, data_in);
1237
1238 /* Read all the local symbols. */
1239 len = lto_input_sleb128 (ib);
1240 if (len > 0)
1241 {
1242 int i;
1243 VEC_safe_grow (tree, gc, fn->local_decls, len);
1244 for (i = 0; i < len; i++)
1245 {
1246 tree t = lto_input_tree (ib, data_in);
1247 VEC_replace (tree, fn->local_decls, i, t);
1248 }
1249 }
1250
1251 /* Read all function arguments. We need to re-map them here to the
1252 arguments of the merged function declaration. */
1253 args = lto_input_tree (ib, data_in);
1254 for (oarg = args, narg = DECL_ARGUMENTS (fn_decl);
1255 oarg && narg;
1256 oarg = TREE_CHAIN (oarg), narg = TREE_CHAIN (narg))
1257 {
1258 int ix;
1259 bool res;
1260 res = lto_streamer_cache_lookup (data_in->reader_cache, oarg, &ix);
1261 gcc_assert (res);
1262 /* Replace the argument in the streamer cache. */
1263 lto_streamer_cache_insert_at (data_in->reader_cache, narg, ix);
1264 }
1265 gcc_assert (!oarg && !narg);
1266
1267 /* Read all the SSA names. */
1268 input_ssa_names (ib, data_in, fn);
1269
1270 /* Read the exception handling regions in the function. */
1271 input_eh_regions (ib, data_in, fn);
1272
1273 /* Read the tree of lexical scopes for the function. */
1274 DECL_INITIAL (fn_decl) = lto_input_tree (ib, data_in);
1275 gcc_assert (DECL_INITIAL (fn_decl));
1276 DECL_SAVED_TREE (fn_decl) = NULL_TREE;
1277 node = cgraph_node (fn_decl);
1278
1279 /* Read all the basic blocks. */
1280 tag = input_record_start (ib);
1281 while (tag)
1282 {
1283 input_bb (ib, tag, data_in, fn,
1284 node->count_materialization_scale);
1285 tag = input_record_start (ib);
1286 }
1287
1288 /* Fix up the call statements that are mentioned in the callgraph
1289 edges. */
1290 set_gimple_stmt_max_uid (cfun, 0);
1291 FOR_ALL_BB (bb)
1292 {
1293 gimple_stmt_iterator gsi;
1294 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1295 {
1296 gimple stmt = gsi_stmt (gsi);
1297 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1298 }
1299 }
1300 stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple));
1301 FOR_ALL_BB (bb)
1302 {
1303 gimple_stmt_iterator bsi = gsi_start_bb (bb);
1304 while (!gsi_end_p (bsi))
1305 {
1306 gimple stmt = gsi_stmt (bsi);
1307 /* If we're recompiling LTO objects with debug stmts but
1308 we're not supposed to have debug stmts, remove them now.
1309 We can't remove them earlier because this would cause uid
1310 mismatches in fixups, but we can do it at this point, as
1311 long as debug stmts don't require fixups. */
1312 if (!MAY_HAVE_DEBUG_STMTS && is_gimple_debug (stmt))
1313 {
1314 gimple_stmt_iterator gsi = bsi;
1315 gsi_next (&bsi);
1316 gsi_remove (&gsi, true);
1317 }
1318 else
1319 {
1320 gsi_next (&bsi);
1321 stmts[gimple_uid (stmt)] = stmt;
1322 }
1323 }
1324 }
1325
1326 /* Set the gimple body to the statement sequence in the entry
1327 basic block. FIXME lto, this is fairly hacky. The existence
1328 of a gimple body is used by the cgraph routines, but we should
1329 really use the presence of the CFG. */
1330 {
1331 edge_iterator ei = ei_start (ENTRY_BLOCK_PTR->succs);
1332 gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
1333 }
1334
1335 fixup_call_stmt_edges (node, stmts);
1336 execute_all_ipa_stmt_fixups (node, stmts);
1337
1338 update_ssa (TODO_update_ssa_only_virtuals);
1339 free_dominance_info (CDI_DOMINATORS);
1340 free_dominance_info (CDI_POST_DOMINATORS);
1341 free (stmts);
1342 }
1343
1344
1345 /* Read initializer expressions for public statics. DATA_IN is the
1346 file being read. IB is the input block used for reading. */
1347
1348 static void
1349 input_alias_pairs (struct lto_input_block *ib, struct data_in *data_in)
1350 {
1351 tree var;
1352
1353 clear_line_info (data_in);
1354
1355 /* Skip over all the unreferenced globals. */
1356 do
1357 var = lto_input_tree (ib, data_in);
1358 while (var);
1359
1360 var = lto_input_tree (ib, data_in);
1361 while (var)
1362 {
1363 const char *orig_name, *new_name;
1364 alias_pair *p;
1365
1366 p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
1367 p->decl = var;
1368 p->target = lto_input_tree (ib, data_in);
1369
1370 /* If the target is a static object, we may have registered a
1371 new name for it to avoid clashes between statics coming from
1372 different files. In that case, use the new name. */
1373 orig_name = IDENTIFIER_POINTER (p->target);
1374 new_name = lto_get_decl_name_mapping (data_in->file_data, orig_name);
1375 if (strcmp (orig_name, new_name) != 0)
1376 p->target = get_identifier (new_name);
1377
1378 var = lto_input_tree (ib, data_in);
1379 }
1380 }
1381
1382
1383 /* Read the body from DATA for function FN_DECL and fill it in.
1384 FILE_DATA are the global decls and types. SECTION_TYPE is either
1385 LTO_section_function_body or LTO_section_static_initializer. If
1386 section type is LTO_section_function_body, FN must be the decl for
1387 that function. */
1388
1389 static void
1390 lto_read_body (struct lto_file_decl_data *file_data, tree fn_decl,
1391 const char *data, enum lto_section_type section_type)
1392 {
1393 const struct lto_function_header *header;
1394 struct data_in *data_in;
1395 int32_t cfg_offset;
1396 int32_t main_offset;
1397 int32_t string_offset;
1398 struct lto_input_block ib_cfg;
1399 struct lto_input_block ib_main;
1400
1401 header = (const struct lto_function_header *) data;
1402 cfg_offset = sizeof (struct lto_function_header);
1403 main_offset = cfg_offset + header->cfg_size;
1404 string_offset = main_offset + header->main_size;
1405
1406 LTO_INIT_INPUT_BLOCK (ib_cfg,
1407 data + cfg_offset,
1408 0,
1409 header->cfg_size);
1410
1411 LTO_INIT_INPUT_BLOCK (ib_main,
1412 data + main_offset,
1413 0,
1414 header->main_size);
1415
1416 data_in = lto_data_in_create (file_data, data + string_offset,
1417 header->string_size, NULL);
1418
1419 /* Make sure the file was generated by the exact same compiler. */
1420 lto_check_version (header->lto_header.major_version,
1421 header->lto_header.minor_version);
1422
1423 if (section_type == LTO_section_function_body)
1424 {
1425 struct function *fn = DECL_STRUCT_FUNCTION (fn_decl);
1426 struct lto_in_decl_state *decl_state;
1427 struct cgraph_node *node = cgraph_node (fn_decl);
1428
1429 push_cfun (fn);
1430 init_tree_ssa (fn);
1431
1432 /* Use the function's decl state. */
1433 decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
1434 gcc_assert (decl_state);
1435 file_data->current_decl_state = decl_state;
1436
1437 input_cfg (&ib_cfg, fn, node->count_materialization_scale);
1438
1439 /* Set up the struct function. */
1440 input_function (fn_decl, data_in, &ib_main);
1441
1442 /* We should now be in SSA. */
1443 cfun->gimple_df->in_ssa_p = true;
1444
1445 /* Restore decl state */
1446 file_data->current_decl_state = file_data->global_decl_state;
1447
1448 pop_cfun ();
1449 }
1450 else
1451 {
1452 input_alias_pairs (&ib_main, data_in);
1453 }
1454
1455 clear_line_info (data_in);
1456 lto_data_in_delete (data_in);
1457 }
1458
1459
1460 /* Read the body of FN_DECL using DATA. FILE_DATA holds the global
1461 decls and types. */
1462
1463 void
1464 lto_input_function_body (struct lto_file_decl_data *file_data,
1465 tree fn_decl, const char *data)
1466 {
1467 current_function_decl = fn_decl;
1468 lto_read_body (file_data, fn_decl, data, LTO_section_function_body);
1469 }
1470
1471
1472 /* Read in VAR_DECL using DATA. FILE_DATA holds the global decls and
1473 types. */
1474
1475 void
1476 lto_input_constructors_and_inits (struct lto_file_decl_data *file_data,
1477 const char *data)
1478 {
1479 lto_read_body (file_data, NULL, data, LTO_section_static_initializer);
1480 }
1481
1482
1483 /* Return the resolution for the decl with index INDEX from DATA_IN. */
1484
1485 static enum ld_plugin_symbol_resolution
1486 get_resolution (struct data_in *data_in, unsigned index)
1487 {
1488 if (data_in->globals_resolution)
1489 {
1490 ld_plugin_symbol_resolution_t ret;
1491 /* We can have references to not emitted functions in
1492 DECL_FUNCTION_PERSONALITY at least. So we can and have
1493 to indeed return LDPR_UNKNOWN in some cases. */
1494 if (VEC_length (ld_plugin_symbol_resolution_t,
1495 data_in->globals_resolution) <= index)
1496 return LDPR_UNKNOWN;
1497 ret = VEC_index (ld_plugin_symbol_resolution_t,
1498 data_in->globals_resolution,
1499 index);
1500 return ret;
1501 }
1502 else
1503 /* Delay resolution finding until decl merging. */
1504 return LDPR_UNKNOWN;
1505 }
1506
1507
1508 /* Unpack all the non-pointer fields of the TS_BASE structure of
1509 expression EXPR from bitpack BP. */
1510
1511 static void
1512 unpack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
1513 {
1514 /* Note that the code for EXPR has already been unpacked to create EXPR in
1515 lto_materialize_tree. */
1516 if (!TYPE_P (expr))
1517 {
1518 TREE_SIDE_EFFECTS (expr) = (unsigned) bp_unpack_value (bp, 1);
1519 TREE_CONSTANT (expr) = (unsigned) bp_unpack_value (bp, 1);
1520 TREE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1521
1522 /* TREE_PUBLIC is used on types to indicate that the type
1523 has a TYPE_CACHED_VALUES vector. This is not streamed out,
1524 so we skip it here. */
1525 TREE_PUBLIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1526 }
1527 else
1528 bp_unpack_value (bp, 4);
1529 TREE_ADDRESSABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1530 TREE_THIS_VOLATILE (expr) = (unsigned) bp_unpack_value (bp, 1);
1531 if (DECL_P (expr))
1532 DECL_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1533 else if (TYPE_P (expr))
1534 TYPE_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1535 else
1536 bp_unpack_value (bp, 1);
1537 TREE_ASM_WRITTEN (expr) = (unsigned) bp_unpack_value (bp, 1);
1538 TREE_NO_WARNING (expr) = (unsigned) bp_unpack_value (bp, 1);
1539 TREE_USED (expr) = (unsigned) bp_unpack_value (bp, 1);
1540 TREE_NOTHROW (expr) = (unsigned) bp_unpack_value (bp, 1);
1541 TREE_STATIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1542 TREE_PRIVATE (expr) = (unsigned) bp_unpack_value (bp, 1);
1543 TREE_PROTECTED (expr) = (unsigned) bp_unpack_value (bp, 1);
1544 TREE_DEPRECATED (expr) = (unsigned) bp_unpack_value (bp, 1);
1545 if (TYPE_P (expr))
1546 TYPE_SATURATING (expr) = (unsigned) bp_unpack_value (bp, 1);
1547 else if (TREE_CODE (expr) == SSA_NAME)
1548 SSA_NAME_IS_DEFAULT_DEF (expr) = (unsigned) bp_unpack_value (bp, 1);
1549 else
1550 bp_unpack_value (bp, 1);
1551 }
1552
1553
1554 /* Unpack all the non-pointer fields of the TS_REAL_CST structure of
1555 expression EXPR from bitpack BP. */
1556
1557 static void
1558 unpack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
1559 {
1560 unsigned i;
1561 REAL_VALUE_TYPE r;
1562 REAL_VALUE_TYPE *rp;
1563
1564 r.cl = (unsigned) bp_unpack_value (bp, 2);
1565 r.decimal = (unsigned) bp_unpack_value (bp, 1);
1566 r.sign = (unsigned) bp_unpack_value (bp, 1);
1567 r.signalling = (unsigned) bp_unpack_value (bp, 1);
1568 r.canonical = (unsigned) bp_unpack_value (bp, 1);
1569 r.uexp = (unsigned) bp_unpack_value (bp, EXP_BITS);
1570 for (i = 0; i < SIGSZ; i++)
1571 r.sig[i] = (unsigned long) bp_unpack_value (bp, HOST_BITS_PER_LONG);
1572
1573 rp = ggc_alloc_real_value ();
1574 memcpy (rp, &r, sizeof (REAL_VALUE_TYPE));
1575 TREE_REAL_CST_PTR (expr) = rp;
1576 }
1577
1578
1579 /* Unpack all the non-pointer fields of the TS_FIXED_CST structure of
1580 expression EXPR from bitpack BP. */
1581
1582 static void
1583 unpack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
1584 {
1585 struct fixed_value fv;
1586
1587 fv.data.low = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1588 fv.data.high = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1589 fv.mode = (enum machine_mode) bp_unpack_value (bp, HOST_BITS_PER_INT);
1590 TREE_FIXED_CST (expr) = fv;
1591 }
1592
1593
1594 /* Unpack all the non-pointer fields of the TS_DECL_COMMON structure
1595 of expression EXPR from bitpack BP. */
1596
1597 static void
1598 unpack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
1599 {
1600 DECL_MODE (expr) = (enum machine_mode) bp_unpack_value (bp, 8);
1601 DECL_NONLOCAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1602 DECL_VIRTUAL_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1603 DECL_IGNORED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1604 DECL_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1605 DECL_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1606 DECL_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1607 DECL_PRESERVE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1608 DECL_DEBUG_EXPR_IS_FROM (expr) = (unsigned) bp_unpack_value (bp, 1);
1609 DECL_EXTERNAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1610 DECL_GIMPLE_REG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1611 DECL_ALIGN (expr) = (unsigned) bp_unpack_value (bp, HOST_BITS_PER_INT);
1612
1613 if (TREE_CODE (expr) == LABEL_DECL)
1614 {
1615 DECL_ERROR_ISSUED (expr) = (unsigned) bp_unpack_value (bp, 1);
1616 EH_LANDING_PAD_NR (expr) = (int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1617
1618 /* Always assume an initial value of -1 for LABEL_DECL_UID to
1619 force gimple_set_bb to recreate label_to_block_map. */
1620 LABEL_DECL_UID (expr) = -1;
1621 }
1622
1623 if (TREE_CODE (expr) == FIELD_DECL)
1624 {
1625 unsigned HOST_WIDE_INT off_align;
1626 DECL_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1627 DECL_NONADDRESSABLE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1628 off_align = (unsigned HOST_WIDE_INT) bp_unpack_value (bp, 8);
1629 SET_DECL_OFFSET_ALIGN (expr, off_align);
1630 }
1631
1632 if (TREE_CODE (expr) == RESULT_DECL
1633 || TREE_CODE (expr) == PARM_DECL
1634 || TREE_CODE (expr) == VAR_DECL)
1635 {
1636 DECL_BY_REFERENCE (expr) = (unsigned) bp_unpack_value (bp, 1);
1637 if (TREE_CODE (expr) == VAR_DECL
1638 || TREE_CODE (expr) == PARM_DECL)
1639 DECL_HAS_VALUE_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1640 DECL_RESTRICTED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1641 }
1642 }
1643
1644
1645 /* Unpack all the non-pointer fields of the TS_DECL_WRTL structure
1646 of expression EXPR from bitpack BP. */
1647
1648 static void
1649 unpack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
1650 {
1651 DECL_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1652 }
1653
1654
1655 /* Unpack all the non-pointer fields of the TS_DECL_WITH_VIS structure
1656 of expression EXPR from bitpack BP. */
1657
1658 static void
1659 unpack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
1660 {
1661 DECL_DEFER_OUTPUT (expr) = (unsigned) bp_unpack_value (bp, 1);
1662 DECL_COMMON (expr) = (unsigned) bp_unpack_value (bp, 1);
1663 DECL_DLLIMPORT_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1664 DECL_WEAK (expr) = (unsigned) bp_unpack_value (bp, 1);
1665 DECL_SEEN_IN_BIND_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1666 DECL_COMDAT (expr) = (unsigned) bp_unpack_value (bp, 1);
1667 DECL_VISIBILITY (expr) = (enum symbol_visibility) bp_unpack_value (bp, 2);
1668 DECL_VISIBILITY_SPECIFIED (expr) = (unsigned) bp_unpack_value (bp, 1);
1669
1670 if (TREE_CODE (expr) == VAR_DECL)
1671 {
1672 DECL_HARD_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1673 DECL_IN_TEXT_SECTION (expr) = (unsigned) bp_unpack_value (bp, 1);
1674 DECL_IN_CONSTANT_POOL (expr) = (unsigned) bp_unpack_value (bp, 1);
1675 DECL_TLS_MODEL (expr) = (enum tls_model) bp_unpack_value (bp, 3);
1676 }
1677
1678 if (VAR_OR_FUNCTION_DECL_P (expr))
1679 {
1680 priority_type p;
1681 p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1682 SET_DECL_INIT_PRIORITY (expr, p);
1683 }
1684 }
1685
1686
1687 /* Unpack all the non-pointer fields of the TS_FUNCTION_DECL structure
1688 of expression EXPR from bitpack BP. */
1689
1690 static void
1691 unpack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
1692 {
1693 DECL_FUNCTION_CODE (expr) = (enum built_in_function) bp_unpack_value (bp, 11);
1694 DECL_BUILT_IN_CLASS (expr) = (enum built_in_class) bp_unpack_value (bp, 2);
1695 DECL_STATIC_CONSTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1696 DECL_STATIC_DESTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1697 DECL_UNINLINABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1698 DECL_POSSIBLY_INLINED (expr) = (unsigned) bp_unpack_value (bp, 1);
1699 DECL_IS_NOVOPS (expr) = (unsigned) bp_unpack_value (bp, 1);
1700 DECL_IS_RETURNS_TWICE (expr) = (unsigned) bp_unpack_value (bp, 1);
1701 DECL_IS_MALLOC (expr) = (unsigned) bp_unpack_value (bp, 1);
1702 DECL_IS_OPERATOR_NEW (expr) = (unsigned) bp_unpack_value (bp, 1);
1703 DECL_DECLARED_INLINE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1704 DECL_STATIC_CHAIN (expr) = (unsigned) bp_unpack_value (bp, 1);
1705 DECL_NO_INLINE_WARNING_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1706 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr)
1707 = (unsigned) bp_unpack_value (bp, 1);
1708 DECL_NO_LIMIT_STACK (expr) = (unsigned) bp_unpack_value (bp, 1);
1709 DECL_DISREGARD_INLINE_LIMITS (expr) = (unsigned) bp_unpack_value (bp, 1);
1710 DECL_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1711 DECL_LOOPING_CONST_OR_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1712 if (DECL_STATIC_DESTRUCTOR (expr))
1713 {
1714 priority_type p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1715 SET_DECL_FINI_PRIORITY (expr, p);
1716 }
1717 }
1718
1719
1720 /* Unpack all the non-pointer fields of the TS_TYPE structure
1721 of expression EXPR from bitpack BP. */
1722
1723 static void
1724 unpack_ts_type_value_fields (struct bitpack_d *bp, tree expr)
1725 {
1726 enum machine_mode mode;
1727
1728 TYPE_PRECISION (expr) = (unsigned) bp_unpack_value (bp, 10);
1729 mode = (enum machine_mode) bp_unpack_value (bp, 8);
1730 SET_TYPE_MODE (expr, mode);
1731 TYPE_STRING_FLAG (expr) = (unsigned) bp_unpack_value (bp, 1);
1732 TYPE_NO_FORCE_BLK (expr) = (unsigned) bp_unpack_value (bp, 1);
1733 TYPE_NEEDS_CONSTRUCTING (expr) = (unsigned) bp_unpack_value (bp, 1);
1734 if (RECORD_OR_UNION_TYPE_P (expr))
1735 TYPE_TRANSPARENT_AGGR (expr) = (unsigned) bp_unpack_value (bp, 1);
1736 TYPE_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1737 TYPE_RESTRICT (expr) = (unsigned) bp_unpack_value (bp, 1);
1738 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr)
1739 = (unsigned) bp_unpack_value (bp, 2);
1740 TYPE_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1741 TYPE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1742 TYPE_ALIGN (expr) = (unsigned) bp_unpack_value (bp, HOST_BITS_PER_INT);
1743 TYPE_ALIAS_SET (expr) = bp_unpack_value (bp, HOST_BITS_PER_INT);
1744 }
1745
1746
1747 /* Unpack all the non-pointer fields of the TS_BLOCK structure
1748 of expression EXPR from bitpack BP. */
1749
1750 static void
1751 unpack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
1752 {
1753 BLOCK_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1754 BLOCK_NUMBER (expr) = (unsigned) bp_unpack_value (bp, 31);
1755 }
1756
1757 /* Unpack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL
1758 structure of expression EXPR from bitpack BP. */
1759
1760 static void
1761 unpack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1762 {
1763 }
1764
1765 /* Unpack all the non-pointer fields in EXPR into a bit pack. */
1766
1767 static void
1768 unpack_value_fields (struct bitpack_d *bp, tree expr)
1769 {
1770 enum tree_code code;
1771
1772 code = TREE_CODE (expr);
1773
1774 /* Note that all these functions are highly sensitive to changes in
1775 the types and sizes of each of the fields being packed. */
1776 unpack_ts_base_value_fields (bp, expr);
1777
1778 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
1779 unpack_ts_real_cst_value_fields (bp, expr);
1780
1781 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
1782 unpack_ts_fixed_cst_value_fields (bp, expr);
1783
1784 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1785 unpack_ts_decl_common_value_fields (bp, expr);
1786
1787 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1788 unpack_ts_decl_wrtl_value_fields (bp, expr);
1789
1790 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1791 unpack_ts_decl_with_vis_value_fields (bp, expr);
1792
1793 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1794 unpack_ts_function_decl_value_fields (bp, expr);
1795
1796 if (CODE_CONTAINS_STRUCT (code, TS_TYPE))
1797 unpack_ts_type_value_fields (bp, expr);
1798
1799 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1800 unpack_ts_block_value_fields (bp, expr);
1801
1802 if (CODE_CONTAINS_STRUCT (code, TS_SSA_NAME))
1803 {
1804 /* We only stream the version number of SSA names. */
1805 gcc_unreachable ();
1806 }
1807
1808 if (CODE_CONTAINS_STRUCT (code, TS_STATEMENT_LIST))
1809 {
1810 /* This is only used by GENERIC. */
1811 gcc_unreachable ();
1812 }
1813
1814 if (CODE_CONTAINS_STRUCT (code, TS_OMP_CLAUSE))
1815 {
1816 /* This is only used by High GIMPLE. */
1817 gcc_unreachable ();
1818 }
1819
1820 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
1821 unpack_ts_translation_unit_decl_value_fields (bp, expr);
1822 }
1823
1824
1825 /* Materialize a new tree from input block IB using descriptors in
1826 DATA_IN. The code for the new tree should match TAG. Store in
1827 *IX_P the index into the reader cache where the new tree is stored. */
1828
1829 static tree
1830 lto_materialize_tree (struct lto_input_block *ib, struct data_in *data_in,
1831 enum LTO_tags tag, int *ix_p)
1832 {
1833 struct bitpack_d bp;
1834 enum tree_code code;
1835 tree result;
1836 #ifdef LTO_STREAMER_DEBUG
1837 HOST_WIDEST_INT orig_address_in_writer;
1838 #endif
1839 HOST_WIDE_INT ix;
1840
1841 result = NULL_TREE;
1842
1843 /* Read the header of the node we are about to create. */
1844 ix = lto_input_sleb128 (ib);
1845 gcc_assert ((int) ix == ix);
1846 *ix_p = (int) ix;
1847
1848 #ifdef LTO_STREAMER_DEBUG
1849 /* Read the word representing the memory address for the tree
1850 as it was written by the writer. This is useful when
1851 debugging differences between the writer and reader. */
1852 orig_address_in_writer = lto_input_sleb128 (ib);
1853 gcc_assert ((intptr_t) orig_address_in_writer == orig_address_in_writer);
1854 #endif
1855
1856 code = lto_tag_to_tree_code (tag);
1857
1858 /* We should never see an SSA_NAME tree. Only the version numbers of
1859 SSA names are ever written out. See input_ssa_names. */
1860 gcc_assert (code != SSA_NAME);
1861
1862 /* Instantiate a new tree using the header data. */
1863 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1864 result = input_string_cst (data_in, ib);
1865 else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1866 result = input_identifier (data_in, ib);
1867 else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1868 {
1869 HOST_WIDE_INT len = lto_input_sleb128 (ib);
1870 result = make_tree_vec (len);
1871 }
1872 else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1873 {
1874 unsigned HOST_WIDE_INT len = lto_input_uleb128 (ib);
1875 result = make_tree_binfo (len);
1876 }
1877 else
1878 {
1879 /* All other nodes can be materialized with a raw make_node
1880 call. */
1881 result = make_node (code);
1882 }
1883
1884 #ifdef LTO_STREAMER_DEBUG
1885 /* Store the original address of the tree as seen by the writer
1886 in RESULT's aux field. This is useful when debugging streaming
1887 problems. This way, a debugging session can be started on
1888 both writer and reader with a breakpoint using this address
1889 value in both. */
1890 lto_orig_address_map (result, (intptr_t) orig_address_in_writer);
1891 #endif
1892
1893 /* Read the bitpack of non-pointer values from IB. */
1894 bp = lto_input_bitpack (ib);
1895
1896 /* The first word in BP contains the code of the tree that we
1897 are about to read. */
1898 code = (enum tree_code) bp_unpack_value (&bp, 16);
1899 lto_tag_check (lto_tree_code_to_tag (code), tag);
1900
1901 /* Unpack all the value fields from BP. */
1902 unpack_value_fields (&bp, result);
1903
1904 /* Enter RESULT in the reader cache. This will make RESULT
1905 available so that circular references in the rest of the tree
1906 structure can be resolved in subsequent calls to lto_input_tree. */
1907 lto_streamer_cache_insert_at (data_in->reader_cache, result, ix);
1908
1909 return result;
1910 }
1911
1912
1913 /* Read a chain of tree nodes from input block IB. DATA_IN contains
1914 tables and descriptors for the file being read. */
1915
1916 static tree
1917 lto_input_chain (struct lto_input_block *ib, struct data_in *data_in)
1918 {
1919 int i, count;
1920 tree first, prev, curr;
1921
1922 first = prev = NULL_TREE;
1923 count = lto_input_sleb128 (ib);
1924 for (i = 0; i < count; i++)
1925 {
1926 curr = lto_input_tree (ib, data_in);
1927 if (prev)
1928 TREE_CHAIN (prev) = curr;
1929 else
1930 first = curr;
1931
1932 TREE_CHAIN (curr) = NULL_TREE;
1933 prev = curr;
1934 }
1935
1936 return first;
1937 }
1938
1939
1940 /* Read all pointer fields in the TS_COMMON structure of EXPR from input
1941 block IB. DATA_IN contains tables and descriptors for the
1942 file being read. */
1943
1944
1945 static void
1946 lto_input_ts_common_tree_pointers (struct lto_input_block *ib,
1947 struct data_in *data_in, tree expr)
1948 {
1949 if (TREE_CODE (expr) != IDENTIFIER_NODE)
1950 TREE_TYPE (expr) = lto_input_tree (ib, data_in);
1951 }
1952
1953
1954 /* Read all pointer fields in the TS_VECTOR structure of EXPR from input
1955 block IB. DATA_IN contains tables and descriptors for the
1956 file being read. */
1957
1958 static void
1959 lto_input_ts_vector_tree_pointers (struct lto_input_block *ib,
1960 struct data_in *data_in, tree expr)
1961 {
1962 TREE_VECTOR_CST_ELTS (expr) = lto_input_chain (ib, data_in);
1963 }
1964
1965
1966 /* Read all pointer fields in the TS_COMPLEX structure of EXPR from input
1967 block IB. DATA_IN contains tables and descriptors for the
1968 file being read. */
1969
1970 static void
1971 lto_input_ts_complex_tree_pointers (struct lto_input_block *ib,
1972 struct data_in *data_in, tree expr)
1973 {
1974 TREE_REALPART (expr) = lto_input_tree (ib, data_in);
1975 TREE_IMAGPART (expr) = lto_input_tree (ib, data_in);
1976 }
1977
1978
1979 /* Read all pointer fields in the TS_DECL_MINIMAL structure of EXPR
1980 from input block IB. DATA_IN contains tables and descriptors for the
1981 file being read. */
1982
1983 static void
1984 lto_input_ts_decl_minimal_tree_pointers (struct lto_input_block *ib,
1985 struct data_in *data_in, tree expr)
1986 {
1987 DECL_NAME (expr) = lto_input_tree (ib, data_in);
1988 DECL_CONTEXT (expr) = lto_input_tree (ib, data_in);
1989 DECL_SOURCE_LOCATION (expr) = lto_input_location (ib, data_in);
1990 }
1991
1992
1993 /* Read all pointer fields in the TS_DECL_COMMON structure of EXPR from
1994 input block IB. DATA_IN contains tables and descriptors for the
1995 file being read. */
1996
1997 static void
1998 lto_input_ts_decl_common_tree_pointers (struct lto_input_block *ib,
1999 struct data_in *data_in, tree expr)
2000 {
2001 DECL_SIZE (expr) = lto_input_tree (ib, data_in);
2002 DECL_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
2003
2004 if (TREE_CODE (expr) != FUNCTION_DECL
2005 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
2006 DECL_INITIAL (expr) = lto_input_tree (ib, data_in);
2007
2008 DECL_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2009 /* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
2010 for early inlining so drop it on the floor instead of ICEing in
2011 dwarf2out.c. */
2012
2013 if (TREE_CODE (expr) == PARM_DECL)
2014 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2015
2016 if ((TREE_CODE (expr) == VAR_DECL
2017 || TREE_CODE (expr) == PARM_DECL)
2018 && DECL_HAS_VALUE_EXPR_P (expr))
2019 SET_DECL_VALUE_EXPR (expr, lto_input_tree (ib, data_in));
2020
2021 if (TREE_CODE (expr) == VAR_DECL)
2022 {
2023 tree dexpr = lto_input_tree (ib, data_in);
2024 if (dexpr)
2025 SET_DECL_DEBUG_EXPR (expr, dexpr);
2026 }
2027 }
2028
2029
2030 /* Read all pointer fields in the TS_DECL_NON_COMMON structure of
2031 EXPR from input block IB. DATA_IN contains tables and descriptors for the
2032 file being read. */
2033
2034 static void
2035 lto_input_ts_decl_non_common_tree_pointers (struct lto_input_block *ib,
2036 struct data_in *data_in, tree expr)
2037 {
2038 if (TREE_CODE (expr) == FUNCTION_DECL)
2039 {
2040 DECL_ARGUMENTS (expr) = lto_input_tree (ib, data_in);
2041 DECL_RESULT (expr) = lto_input_tree (ib, data_in);
2042 }
2043 DECL_VINDEX (expr) = lto_input_tree (ib, data_in);
2044 }
2045
2046
2047 /* Read all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
2048 from input block IB. DATA_IN contains tables and descriptors for the
2049 file being read. */
2050
2051 static void
2052 lto_input_ts_decl_with_vis_tree_pointers (struct lto_input_block *ib,
2053 struct data_in *data_in, tree expr)
2054 {
2055 tree id;
2056
2057 id = lto_input_tree (ib, data_in);
2058 if (id)
2059 {
2060 gcc_assert (TREE_CODE (id) == IDENTIFIER_NODE);
2061 SET_DECL_ASSEMBLER_NAME (expr, id);
2062 }
2063
2064 DECL_SECTION_NAME (expr) = lto_input_tree (ib, data_in);
2065 DECL_COMDAT_GROUP (expr) = lto_input_tree (ib, data_in);
2066 }
2067
2068
2069 /* Read all pointer fields in the TS_FIELD_DECL structure of EXPR from
2070 input block IB. DATA_IN contains tables and descriptors for the
2071 file being read. */
2072
2073 static void
2074 lto_input_ts_field_decl_tree_pointers (struct lto_input_block *ib,
2075 struct data_in *data_in, tree expr)
2076 {
2077 DECL_FIELD_OFFSET (expr) = lto_input_tree (ib, data_in);
2078 DECL_BIT_FIELD_TYPE (expr) = lto_input_tree (ib, data_in);
2079 DECL_QUALIFIER (expr) = lto_input_tree (ib, data_in);
2080 DECL_FIELD_BIT_OFFSET (expr) = lto_input_tree (ib, data_in);
2081 DECL_FCONTEXT (expr) = lto_input_tree (ib, data_in);
2082 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2083 }
2084
2085
2086 /* Read all pointer fields in the TS_FUNCTION_DECL structure of EXPR
2087 from input block IB. DATA_IN contains tables and descriptors for the
2088 file being read. */
2089
2090 static void
2091 lto_input_ts_function_decl_tree_pointers (struct lto_input_block *ib,
2092 struct data_in *data_in, tree expr)
2093 {
2094 /* DECL_STRUCT_FUNCTION is handled by lto_input_function. FIXME lto,
2095 maybe it should be handled here? */
2096 DECL_FUNCTION_PERSONALITY (expr) = lto_input_tree (ib, data_in);
2097 DECL_FUNCTION_SPECIFIC_TARGET (expr) = lto_input_tree (ib, data_in);
2098 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr) = lto_input_tree (ib, data_in);
2099
2100 /* If the file contains a function with an EH personality set,
2101 then it was compiled with -fexceptions. In that case, initialize
2102 the backend EH machinery. */
2103 if (DECL_FUNCTION_PERSONALITY (expr))
2104 lto_init_eh ();
2105 }
2106
2107
2108 /* Read all pointer fields in the TS_TYPE structure of EXPR from input
2109 block IB. DATA_IN contains tables and descriptors for the
2110 file being read. */
2111
2112 static void
2113 lto_input_ts_type_tree_pointers (struct lto_input_block *ib,
2114 struct data_in *data_in, tree expr)
2115 {
2116 if (TREE_CODE (expr) == ENUMERAL_TYPE)
2117 TYPE_VALUES (expr) = lto_input_tree (ib, data_in);
2118 else if (TREE_CODE (expr) == ARRAY_TYPE)
2119 TYPE_DOMAIN (expr) = lto_input_tree (ib, data_in);
2120 else if (RECORD_OR_UNION_TYPE_P (expr))
2121 TYPE_FIELDS (expr) = lto_input_tree (ib, data_in);
2122 else if (TREE_CODE (expr) == FUNCTION_TYPE
2123 || TREE_CODE (expr) == METHOD_TYPE)
2124 TYPE_ARG_TYPES (expr) = lto_input_tree (ib, data_in);
2125
2126 TYPE_SIZE (expr) = lto_input_tree (ib, data_in);
2127 TYPE_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
2128 TYPE_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2129 TYPE_NAME (expr) = lto_input_tree (ib, data_in);
2130 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO nor
2131 TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. */
2132 if (!POINTER_TYPE_P (expr))
2133 TYPE_MINVAL (expr) = lto_input_tree (ib, data_in);
2134 TYPE_MAXVAL (expr) = lto_input_tree (ib, data_in);
2135 TYPE_MAIN_VARIANT (expr) = lto_input_tree (ib, data_in);
2136 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
2137 during fixup. */
2138 if (RECORD_OR_UNION_TYPE_P (expr))
2139 TYPE_BINFO (expr) = lto_input_tree (ib, data_in);
2140 TYPE_CONTEXT (expr) = lto_input_tree (ib, data_in);
2141 /* TYPE_CANONICAL gets re-computed during type merging. */
2142 TYPE_CANONICAL (expr) = NULL_TREE;
2143 TYPE_STUB_DECL (expr) = lto_input_tree (ib, data_in);
2144 }
2145
2146
2147 /* Read all pointer fields in the TS_LIST structure of EXPR from input
2148 block IB. DATA_IN contains tables and descriptors for the
2149 file being read. */
2150
2151 static void
2152 lto_input_ts_list_tree_pointers (struct lto_input_block *ib,
2153 struct data_in *data_in, tree expr)
2154 {
2155 TREE_PURPOSE (expr) = lto_input_tree (ib, data_in);
2156 TREE_VALUE (expr) = lto_input_tree (ib, data_in);
2157 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2158 }
2159
2160
2161 /* Read all pointer fields in the TS_VEC structure of EXPR from input
2162 block IB. DATA_IN contains tables and descriptors for the
2163 file being read. */
2164
2165 static void
2166 lto_input_ts_vec_tree_pointers (struct lto_input_block *ib,
2167 struct data_in *data_in, tree expr)
2168 {
2169 int i;
2170
2171 /* Note that TREE_VEC_LENGTH was read by lto_materialize_tree to
2172 instantiate EXPR. */
2173 for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
2174 TREE_VEC_ELT (expr, i) = lto_input_tree (ib, data_in);
2175 }
2176
2177
2178 /* Read all pointer fields in the TS_EXP structure of EXPR from input
2179 block IB. DATA_IN contains tables and descriptors for the
2180 file being read. */
2181
2182
2183 static void
2184 lto_input_ts_exp_tree_pointers (struct lto_input_block *ib,
2185 struct data_in *data_in, tree expr)
2186 {
2187 int i, length;
2188 location_t loc;
2189
2190 length = lto_input_sleb128 (ib);
2191 gcc_assert (length == TREE_OPERAND_LENGTH (expr));
2192
2193 for (i = 0; i < length; i++)
2194 TREE_OPERAND (expr, i) = lto_input_tree (ib, data_in);
2195
2196 loc = lto_input_location (ib, data_in);
2197 SET_EXPR_LOCATION (expr, loc);
2198 TREE_BLOCK (expr) = lto_input_tree (ib, data_in);
2199 }
2200
2201
2202 /* Read all pointer fields in the TS_BLOCK structure of EXPR from input
2203 block IB. DATA_IN contains tables and descriptors for the
2204 file being read. */
2205
2206 static void
2207 lto_input_ts_block_tree_pointers (struct lto_input_block *ib,
2208 struct data_in *data_in, tree expr)
2209 {
2210 /* Do not stream BLOCK_SOURCE_LOCATION. We cannot handle debug information
2211 for early inlining so drop it on the floor instead of ICEing in
2212 dwarf2out.c. */
2213 BLOCK_VARS (expr) = lto_input_chain (ib, data_in);
2214
2215 /* Do not stream BLOCK_NONLOCALIZED_VARS. We cannot handle debug information
2216 for early inlining so drop it on the floor instead of ICEing in
2217 dwarf2out.c. */
2218
2219 BLOCK_SUPERCONTEXT (expr) = lto_input_tree (ib, data_in);
2220 /* Do not stream BLOCK_ABSTRACT_ORIGIN. We cannot handle debug information
2221 for early inlining so drop it on the floor instead of ICEing in
2222 dwarf2out.c. */
2223 BLOCK_FRAGMENT_ORIGIN (expr) = lto_input_tree (ib, data_in);
2224 BLOCK_FRAGMENT_CHAIN (expr) = lto_input_tree (ib, data_in);
2225 /* We re-compute BLOCK_SUBBLOCKS of our parent here instead
2226 of streaming it. For non-BLOCK BLOCK_SUPERCONTEXTs we still
2227 stream the child relationship explicitly. */
2228 if (BLOCK_SUPERCONTEXT (expr)
2229 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == BLOCK)
2230 {
2231 BLOCK_CHAIN (expr) = BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr));
2232 BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr)) = expr;
2233 }
2234 /* The global block is rooted at the TU decl. Hook it here to
2235 avoid the need to stream in this block during WPA time. */
2236 else if (BLOCK_SUPERCONTEXT (expr)
2237 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == TRANSLATION_UNIT_DECL)
2238 DECL_INITIAL (BLOCK_SUPERCONTEXT (expr)) = expr;
2239 /* The function-level block is connected at the time we read in
2240 function bodies for the same reason. */
2241 }
2242
2243
2244 /* Read all pointer fields in the TS_BINFO structure of EXPR from input
2245 block IB. DATA_IN contains tables and descriptors for the
2246 file being read. */
2247
2248 static void
2249 lto_input_ts_binfo_tree_pointers (struct lto_input_block *ib,
2250 struct data_in *data_in, tree expr)
2251 {
2252 unsigned i, len;
2253 tree t;
2254
2255 /* Note that the number of slots in EXPR was read in
2256 lto_materialize_tree when instantiating EXPR. However, the
2257 vector is empty so we cannot rely on VEC_length to know how many
2258 elements to read. So, this list is emitted as a 0-terminated
2259 list on the writer side. */
2260 do
2261 {
2262 t = lto_input_tree (ib, data_in);
2263 if (t)
2264 VEC_quick_push (tree, BINFO_BASE_BINFOS (expr), t);
2265 }
2266 while (t);
2267
2268 BINFO_OFFSET (expr) = lto_input_tree (ib, data_in);
2269 BINFO_VTABLE (expr) = lto_input_tree (ib, data_in);
2270 BINFO_VIRTUALS (expr) = lto_input_tree (ib, data_in);
2271 BINFO_VPTR_FIELD (expr) = lto_input_tree (ib, data_in);
2272
2273 len = lto_input_uleb128 (ib);
2274 if (len > 0)
2275 {
2276 VEC_reserve_exact (tree, gc, BINFO_BASE_ACCESSES (expr), len);
2277 for (i = 0; i < len; i++)
2278 {
2279 tree a = lto_input_tree (ib, data_in);
2280 VEC_quick_push (tree, BINFO_BASE_ACCESSES (expr), a);
2281 }
2282 }
2283
2284 BINFO_INHERITANCE_CHAIN (expr) = lto_input_tree (ib, data_in);
2285 BINFO_SUBVTT_INDEX (expr) = lto_input_tree (ib, data_in);
2286 BINFO_VPTR_INDEX (expr) = lto_input_tree (ib, data_in);
2287 }
2288
2289
2290 /* Read all pointer fields in the TS_CONSTRUCTOR structure of EXPR from
2291 input block IB. DATA_IN contains tables and descriptors for the
2292 file being read. */
2293
2294 static void
2295 lto_input_ts_constructor_tree_pointers (struct lto_input_block *ib,
2296 struct data_in *data_in, tree expr)
2297 {
2298 unsigned i, len;
2299
2300 len = lto_input_uleb128 (ib);
2301 for (i = 0; i < len; i++)
2302 {
2303 tree index, value;
2304
2305 index = lto_input_tree (ib, data_in);
2306 value = lto_input_tree (ib, data_in);
2307 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (expr), index, value);
2308 }
2309 }
2310
2311
2312 /* Input a TS_TARGET_OPTION tree from IB into EXPR. */
2313
2314 static void
2315 lto_input_ts_target_option (struct lto_input_block *ib, tree expr)
2316 {
2317 unsigned i, len;
2318 struct bitpack_d bp;
2319 struct cl_target_option *t = TREE_TARGET_OPTION (expr);
2320
2321 bp = lto_input_bitpack (ib);
2322 len = sizeof (struct cl_target_option);
2323 for (i = 0; i < len; i++)
2324 ((unsigned char *)t)[i] = bp_unpack_value (&bp, 8);
2325 if (bp_unpack_value (&bp, 32) != 0x12345678)
2326 fatal_error ("cl_target_option size mismatch in LTO reader and writer");
2327 }
2328
2329 /* Input a TS_TRANSLATION_UNIT_DECL tree from IB and DATA_IN into EXPR. */
2330
2331 static void
2332 lto_input_ts_translation_unit_decl_tree_pointers (struct lto_input_block *ib,
2333 struct data_in *data_in,
2334 tree expr)
2335 {
2336 TRANSLATION_UNIT_LANGUAGE (expr) = xstrdup (lto_input_string (data_in, ib));
2337 VEC_safe_push (tree, gc, all_translation_units, expr);
2338 }
2339
2340 /* Helper for lto_input_tree. Read all pointer fields in EXPR from
2341 input block IB. DATA_IN contains tables and descriptors for the
2342 file being read. */
2343
2344 static void
2345 lto_input_tree_pointers (struct lto_input_block *ib, struct data_in *data_in,
2346 tree expr)
2347 {
2348 enum tree_code code;
2349
2350 code = TREE_CODE (expr);
2351
2352 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
2353 lto_input_ts_common_tree_pointers (ib, data_in, expr);
2354
2355 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
2356 lto_input_ts_vector_tree_pointers (ib, data_in, expr);
2357
2358 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
2359 lto_input_ts_complex_tree_pointers (ib, data_in, expr);
2360
2361 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
2362 lto_input_ts_decl_minimal_tree_pointers (ib, data_in, expr);
2363
2364 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
2365 lto_input_ts_decl_common_tree_pointers (ib, data_in, expr);
2366
2367 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
2368 lto_input_ts_decl_non_common_tree_pointers (ib, data_in, expr);
2369
2370 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
2371 lto_input_ts_decl_with_vis_tree_pointers (ib, data_in, expr);
2372
2373 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
2374 lto_input_ts_field_decl_tree_pointers (ib, data_in, expr);
2375
2376 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
2377 lto_input_ts_function_decl_tree_pointers (ib, data_in, expr);
2378
2379 if (CODE_CONTAINS_STRUCT (code, TS_TYPE))
2380 lto_input_ts_type_tree_pointers (ib, data_in, expr);
2381
2382 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
2383 lto_input_ts_list_tree_pointers (ib, data_in, expr);
2384
2385 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
2386 lto_input_ts_vec_tree_pointers (ib, data_in, expr);
2387
2388 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
2389 lto_input_ts_exp_tree_pointers (ib, data_in, expr);
2390
2391 if (CODE_CONTAINS_STRUCT (code, TS_SSA_NAME))
2392 {
2393 /* We only stream the version number of SSA names. */
2394 gcc_unreachable ();
2395 }
2396
2397 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
2398 lto_input_ts_block_tree_pointers (ib, data_in, expr);
2399
2400 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
2401 lto_input_ts_binfo_tree_pointers (ib, data_in, expr);
2402
2403 if (CODE_CONTAINS_STRUCT (code, TS_STATEMENT_LIST))
2404 {
2405 /* This should only appear in GENERIC. */
2406 gcc_unreachable ();
2407 }
2408
2409 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
2410 lto_input_ts_constructor_tree_pointers (ib, data_in, expr);
2411
2412 if (CODE_CONTAINS_STRUCT (code, TS_OMP_CLAUSE))
2413 {
2414 /* This should only appear in High GIMPLE. */
2415 gcc_unreachable ();
2416 }
2417
2418 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
2419 {
2420 sorry ("optimization options not supported yet");
2421 }
2422
2423 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
2424 lto_input_ts_target_option (ib, expr);
2425
2426 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
2427 lto_input_ts_translation_unit_decl_tree_pointers (ib, data_in, expr);
2428 }
2429
2430
2431 /* Register DECL with the global symbol table and change its
2432 name if necessary to avoid name clashes for static globals across
2433 different files. */
2434
2435 static void
2436 lto_register_var_decl_in_symtab (struct data_in *data_in, tree decl)
2437 {
2438 tree context;
2439
2440 /* Variable has file scope, not local. Need to ensure static variables
2441 between different files don't clash unexpectedly. */
2442 if (!TREE_PUBLIC (decl)
2443 && !((context = decl_function_context (decl))
2444 && auto_var_in_fn_p (decl, context)))
2445 {
2446 /* ??? We normally pre-mangle names before we serialize them
2447 out. Here, in lto1, we do not know the language, and
2448 thus cannot do the mangling again. Instead, we just
2449 append a suffix to the mangled name. The resulting name,
2450 however, is not a properly-formed mangled name, and will
2451 confuse any attempt to unmangle it. */
2452 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2453 char *label;
2454
2455 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
2456 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
2457 rest_of_decl_compilation (decl, 1, 0);
2458
2459 VEC_safe_push (tree, gc, lto_global_var_decls, decl);
2460 }
2461
2462 /* If this variable has already been declared, queue the
2463 declaration for merging. */
2464 if (TREE_PUBLIC (decl))
2465 {
2466 int ix;
2467 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
2468 gcc_unreachable ();
2469 lto_symtab_register_decl (decl, get_resolution (data_in, ix),
2470 data_in->file_data);
2471 }
2472 }
2473
2474
2475
2476 /* Register DECL with the global symbol table and change its
2477 name if necessary to avoid name clashes for static globals across
2478 different files. DATA_IN contains descriptors and tables for the
2479 file being read. */
2480
2481 static void
2482 lto_register_function_decl_in_symtab (struct data_in *data_in, tree decl)
2483 {
2484 /* Need to ensure static entities between different files
2485 don't clash unexpectedly. */
2486 if (!TREE_PUBLIC (decl))
2487 {
2488 /* We must not use the DECL_ASSEMBLER_NAME macro here, as it
2489 may set the assembler name where it was previously empty. */
2490 tree old_assembler_name = decl->decl_with_vis.assembler_name;
2491
2492 /* FIXME lto: We normally pre-mangle names before we serialize
2493 them out. Here, in lto1, we do not know the language, and
2494 thus cannot do the mangling again. Instead, we just append a
2495 suffix to the mangled name. The resulting name, however, is
2496 not a properly-formed mangled name, and will confuse any
2497 attempt to unmangle it. */
2498 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2499 char *label;
2500
2501 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
2502 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
2503
2504 /* We may arrive here with the old assembler name not set
2505 if the function body is not needed, e.g., it has been
2506 inlined away and does not appear in the cgraph. */
2507 if (old_assembler_name)
2508 {
2509 tree new_assembler_name = DECL_ASSEMBLER_NAME (decl);
2510
2511 /* Make the original assembler name available for later use.
2512 We may have used it to indicate the section within its
2513 object file where the function body may be found.
2514 FIXME lto: Find a better way to maintain the function decl
2515 to body section mapping so we don't need this hack. */
2516 lto_record_renamed_decl (data_in->file_data,
2517 IDENTIFIER_POINTER (old_assembler_name),
2518 IDENTIFIER_POINTER (new_assembler_name));
2519
2520 /* Also register the reverse mapping so that we can find the
2521 new name given to an existing assembler name (used when
2522 restoring alias pairs in input_constructors_or_inits. */
2523 lto_record_renamed_decl (data_in->file_data,
2524 IDENTIFIER_POINTER (new_assembler_name),
2525 IDENTIFIER_POINTER (old_assembler_name));
2526 }
2527 }
2528
2529 /* If this variable has already been declared, queue the
2530 declaration for merging. */
2531 if (TREE_PUBLIC (decl) && !DECL_ABSTRACT (decl))
2532 {
2533 int ix;
2534 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
2535 gcc_unreachable ();
2536 lto_symtab_register_decl (decl, get_resolution (data_in, ix),
2537 data_in->file_data);
2538 }
2539 }
2540
2541
2542 /* Read an index IX from input block IB and return the tree node at
2543 DATA_IN->FILE_DATA->GLOBALS_INDEX[IX]. */
2544
2545 static tree
2546 lto_get_pickled_tree (struct lto_input_block *ib, struct data_in *data_in)
2547 {
2548 HOST_WIDE_INT ix;
2549 tree result;
2550 enum LTO_tags expected_tag;
2551 unsigned HOST_WIDE_INT orig_offset;
2552
2553 ix = lto_input_sleb128 (ib);
2554 expected_tag = (enum LTO_tags) lto_input_uleb128 (ib);
2555
2556 orig_offset = lto_input_uleb128 (ib);
2557 gcc_assert (orig_offset == (unsigned) orig_offset);
2558
2559 result = lto_streamer_cache_get (data_in->reader_cache, ix);
2560 if (result == NULL_TREE)
2561 {
2562 /* We have not yet read the cache slot IX. Go to the offset
2563 in the stream where the physical tree node is, and materialize
2564 it from there. */
2565 struct lto_input_block fwd_ib;
2566
2567 /* If we are trying to go back in the stream, something is wrong.
2568 We should've read the node at the earlier position already. */
2569 if (ib->p >= orig_offset)
2570 internal_error ("bytecode stream: tried to jump backwards in the "
2571 "stream");
2572
2573 LTO_INIT_INPUT_BLOCK (fwd_ib, ib->data, orig_offset, ib->len);
2574 result = lto_input_tree (&fwd_ib, data_in);
2575 }
2576
2577 gcc_assert (result
2578 && TREE_CODE (result) == lto_tag_to_tree_code (expected_tag));
2579
2580 return result;
2581 }
2582
2583
2584 /* Read a code and class from input block IB and return the
2585 corresponding builtin. DATA_IN is as in lto_input_tree. */
2586
2587 static tree
2588 lto_get_builtin_tree (struct lto_input_block *ib, struct data_in *data_in)
2589 {
2590 enum built_in_class fclass;
2591 enum built_in_function fcode;
2592 const char *asmname;
2593 tree result;
2594 int ix;
2595
2596 fclass = (enum built_in_class) lto_input_uleb128 (ib);
2597 gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
2598
2599 fcode = (enum built_in_function) lto_input_uleb128 (ib);
2600
2601 ix = lto_input_sleb128 (ib);
2602 gcc_assert (ix == (int) ix);
2603
2604 if (fclass == BUILT_IN_NORMAL)
2605 {
2606 gcc_assert (fcode < END_BUILTINS);
2607 result = built_in_decls[fcode];
2608 gcc_assert (result);
2609 }
2610 else if (fclass == BUILT_IN_MD)
2611 {
2612 result = targetm.builtin_decl (fcode, true);
2613 if (!result || result == error_mark_node)
2614 fatal_error ("target specific builtin not available");
2615 }
2616 else
2617 gcc_unreachable ();
2618
2619 asmname = lto_input_string (data_in, ib);
2620 if (asmname)
2621 set_builtin_user_assembler_name (result, asmname);
2622
2623 lto_streamer_cache_insert_at (data_in->reader_cache, result, ix);
2624
2625 return result;
2626 }
2627
2628
2629 /* Read the physical representation of a tree node with tag TAG from
2630 input block IB using the per-file context in DATA_IN. */
2631
2632 static tree
2633 lto_read_tree (struct lto_input_block *ib, struct data_in *data_in,
2634 enum LTO_tags tag)
2635 {
2636 tree result;
2637 int ix;
2638
2639 result = lto_materialize_tree (ib, data_in, tag, &ix);
2640
2641 /* Read all the pointer fields in RESULT. */
2642 lto_input_tree_pointers (ib, data_in, result);
2643
2644 /* We should never try to instantiate an MD or NORMAL builtin here. */
2645 if (TREE_CODE (result) == FUNCTION_DECL)
2646 gcc_assert (!lto_stream_as_builtin_p (result));
2647
2648 if (TREE_CODE (result) == VAR_DECL)
2649 lto_register_var_decl_in_symtab (data_in, result);
2650 else if (TREE_CODE (result) == FUNCTION_DECL && !DECL_BUILT_IN (result))
2651 lto_register_function_decl_in_symtab (data_in, result);
2652
2653 /* end_marker = */ lto_input_1_unsigned (ib);
2654
2655 #ifdef LTO_STREAMER_DEBUG
2656 /* Remove the mapping to RESULT's original address set by
2657 lto_materialize_tree. */
2658 lto_orig_address_remove (result);
2659 #endif
2660
2661 return result;
2662 }
2663
2664
2665 /* Read and INTEGER_CST node from input block IB using the per-file
2666 context in DATA_IN. */
2667
2668 static tree
2669 lto_input_integer_cst (struct lto_input_block *ib, struct data_in *data_in)
2670 {
2671 tree result, type;
2672 HOST_WIDE_INT low, high;
2673 bool overflow_p;
2674
2675 type = lto_input_tree (ib, data_in);
2676 overflow_p = (lto_input_1_unsigned (ib) != 0);
2677 low = lto_input_uleb128 (ib);
2678 high = lto_input_uleb128 (ib);
2679 result = build_int_cst_wide (type, low, high);
2680
2681 /* If the original constant had overflown, build a replica of RESULT to
2682 avoid modifying the shared constant returned by build_int_cst_wide. */
2683 if (overflow_p)
2684 {
2685 result = copy_node (result);
2686 TREE_OVERFLOW (result) = 1;
2687 }
2688
2689 return result;
2690 }
2691
2692
2693 /* Read a tree from input block IB using the per-file context in
2694 DATA_IN. This context is used, for example, to resolve references
2695 to previously read nodes. */
2696
2697 tree
2698 lto_input_tree (struct lto_input_block *ib, struct data_in *data_in)
2699 {
2700 enum LTO_tags tag;
2701 tree result;
2702
2703 tag = input_record_start (ib);
2704 gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
2705
2706 if (tag == LTO_null)
2707 result = NULL_TREE;
2708 else if (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
2709 {
2710 /* If TAG is a reference to an indexable tree, the next value
2711 in IB is the index into the table where we expect to find
2712 that tree. */
2713 result = lto_input_tree_ref (ib, data_in, cfun, tag);
2714 }
2715 else if (tag == LTO_tree_pickle_reference)
2716 {
2717 /* If TAG is a reference to a previously read tree, look it up in
2718 the reader cache. */
2719 result = lto_get_pickled_tree (ib, data_in);
2720 }
2721 else if (tag == LTO_builtin_decl)
2722 {
2723 /* If we are going to read a built-in function, all we need is
2724 the code and class. */
2725 result = lto_get_builtin_tree (ib, data_in);
2726 }
2727 else if (tag == lto_tree_code_to_tag (INTEGER_CST))
2728 {
2729 /* For integer constants we only need the type and its hi/low
2730 words. */
2731 result = lto_input_integer_cst (ib, data_in);
2732 }
2733 else
2734 {
2735 /* Otherwise, materialize a new node from IB. */
2736 result = lto_read_tree (ib, data_in, tag);
2737 }
2738
2739 return result;
2740 }
2741
2742
2743 /* Initialization for the LTO reader. */
2744
2745 void
2746 lto_init_reader (void)
2747 {
2748 lto_streamer_init ();
2749
2750 memset (&lto_stats, 0, sizeof (lto_stats));
2751 bitmap_obstack_initialize (NULL);
2752
2753 file_name_hash_table = htab_create (37, hash_string_slot_node,
2754 eq_string_slot_node, free);
2755
2756 gimple_register_cfg_hooks ();
2757 }
2758
2759
2760 /* Create a new data_in object for FILE_DATA. STRINGS is the string
2761 table to use with LEN strings. RESOLUTIONS is the vector of linker
2762 resolutions (NULL if not using a linker plugin). */
2763
2764 struct data_in *
2765 lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
2766 unsigned len,
2767 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
2768 {
2769 struct data_in *data_in = XCNEW (struct data_in);
2770 data_in->file_data = file_data;
2771 data_in->strings = strings;
2772 data_in->strings_len = len;
2773 data_in->globals_resolution = resolutions;
2774 data_in->reader_cache = lto_streamer_cache_create ();
2775
2776 return data_in;
2777 }
2778
2779
2780 /* Remove DATA_IN. */
2781
2782 void
2783 lto_data_in_delete (struct data_in *data_in)
2784 {
2785 VEC_free (ld_plugin_symbol_resolution_t, heap, data_in->globals_resolution);
2786 lto_streamer_cache_delete (data_in->reader_cache);
2787 free (data_in->labels);
2788 free (data_in);
2789 }