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