gcc/ChangeLog
[official-gcc.git] / gcc / tree-streamer-in.c
blobb5ead0f9eb7219e2ea2d894565a2d93afac0244d
1 /* Routines for reading trees from a file stream.
3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@google.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "diagnostic.h"
26 #include "tree.h"
27 #include "tree-flow.h"
28 #include "tree-streamer.h"
29 #include "data-streamer.h"
30 #include "streamer-hooks.h"
31 #include "lto-streamer.h"
33 /* Read a STRING_CST from the string table in DATA_IN using input
34 block IB. */
36 tree
37 streamer_read_string_cst (struct data_in *data_in, struct lto_input_block *ib)
39 unsigned int len;
40 const char * ptr;
42 ptr = streamer_read_indexed_string (data_in, ib, &len);
43 if (!ptr)
44 return NULL;
45 return build_string (len, ptr);
49 /* Read an IDENTIFIER from the string table in DATA_IN using input
50 block IB. */
52 static tree
53 input_identifier (struct data_in *data_in, struct lto_input_block *ib)
55 unsigned int len;
56 const char *ptr;
58 ptr = streamer_read_indexed_string (data_in, ib, &len);
59 if (!ptr)
60 return NULL;
61 return get_identifier_with_length (ptr, len);
65 /* Read a chain of tree nodes from input block IB. DATA_IN contains
66 tables and descriptors for the file being read. */
68 tree
69 streamer_read_chain (struct lto_input_block *ib, struct data_in *data_in)
71 tree first, prev, curr;
73 /* The chain is written as NULL terminated list of trees. */
74 first = prev = NULL_TREE;
77 curr = stream_read_tree (ib, data_in);
78 if (prev)
79 TREE_CHAIN (prev) = curr;
80 else
81 first = curr;
83 prev = curr;
85 while (curr);
87 return first;
91 /* Unpack all the non-pointer fields of the TS_BASE structure of
92 expression EXPR from bitpack BP. */
94 static void
95 unpack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
97 /* Note that the code for EXPR has already been unpacked to create EXPR in
98 streamer_alloc_tree. */
99 if (!TYPE_P (expr))
101 TREE_SIDE_EFFECTS (expr) = (unsigned) bp_unpack_value (bp, 1);
102 TREE_CONSTANT (expr) = (unsigned) bp_unpack_value (bp, 1);
103 TREE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
105 /* TREE_PUBLIC is used on types to indicate that the type
106 has a TYPE_CACHED_VALUES vector. This is not streamed out,
107 so we skip it here. */
108 TREE_PUBLIC (expr) = (unsigned) bp_unpack_value (bp, 1);
110 else
111 bp_unpack_value (bp, 4);
112 TREE_ADDRESSABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
113 TREE_THIS_VOLATILE (expr) = (unsigned) bp_unpack_value (bp, 1);
114 if (DECL_P (expr))
115 DECL_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
116 else if (TYPE_P (expr))
117 TYPE_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
118 else
119 bp_unpack_value (bp, 1);
120 TREE_ASM_WRITTEN (expr) = (unsigned) bp_unpack_value (bp, 1);
121 if (TYPE_P (expr))
122 TYPE_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1);
123 else
124 TREE_NO_WARNING (expr) = (unsigned) bp_unpack_value (bp, 1);
125 TREE_USED (expr) = (unsigned) bp_unpack_value (bp, 1);
126 TREE_NOTHROW (expr) = (unsigned) bp_unpack_value (bp, 1);
127 TREE_STATIC (expr) = (unsigned) bp_unpack_value (bp, 1);
128 TREE_PRIVATE (expr) = (unsigned) bp_unpack_value (bp, 1);
129 TREE_PROTECTED (expr) = (unsigned) bp_unpack_value (bp, 1);
130 TREE_DEPRECATED (expr) = (unsigned) bp_unpack_value (bp, 1);
131 if (TYPE_P (expr))
133 TYPE_SATURATING (expr) = (unsigned) bp_unpack_value (bp, 1);
134 TYPE_ADDR_SPACE (expr) = (unsigned) bp_unpack_value (bp, 8);
136 else if (TREE_CODE (expr) == SSA_NAME)
137 SSA_NAME_IS_DEFAULT_DEF (expr) = (unsigned) bp_unpack_value (bp, 1);
138 else
139 bp_unpack_value (bp, 1);
143 /* Unpack all the non-pointer fields of the TS_INT_CST structure of
144 expression EXPR from bitpack BP. */
146 static void
147 unpack_ts_int_cst_value_fields (struct bitpack_d *bp, tree expr)
149 TREE_INT_CST_LOW (expr) = bp_unpack_var_len_unsigned (bp);
150 TREE_INT_CST_HIGH (expr) = bp_unpack_var_len_int (bp);
154 /* Unpack all the non-pointer fields of the TS_REAL_CST structure of
155 expression EXPR from bitpack BP. */
157 static void
158 unpack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
160 unsigned i;
161 REAL_VALUE_TYPE r;
162 REAL_VALUE_TYPE *rp;
164 r.cl = (unsigned) bp_unpack_value (bp, 2);
165 r.decimal = (unsigned) bp_unpack_value (bp, 1);
166 r.sign = (unsigned) bp_unpack_value (bp, 1);
167 r.signalling = (unsigned) bp_unpack_value (bp, 1);
168 r.canonical = (unsigned) bp_unpack_value (bp, 1);
169 r.uexp = (unsigned) bp_unpack_value (bp, EXP_BITS);
170 for (i = 0; i < SIGSZ; i++)
171 r.sig[i] = (unsigned long) bp_unpack_value (bp, HOST_BITS_PER_LONG);
173 rp = ggc_alloc_real_value ();
174 memcpy (rp, &r, sizeof (REAL_VALUE_TYPE));
175 TREE_REAL_CST_PTR (expr) = rp;
179 /* Unpack all the non-pointer fields of the TS_FIXED_CST structure of
180 expression EXPR from bitpack BP. */
182 static void
183 unpack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
185 FIXED_VALUE_TYPE *fp = ggc_alloc_fixed_value ();
186 fp->mode = bp_unpack_enum (bp, machine_mode, MAX_MACHINE_MODE);
187 fp->data.low = bp_unpack_var_len_int (bp);
188 fp->data.high = bp_unpack_var_len_int (bp);
189 TREE_FIXED_CST_PTR (expr) = fp;
192 /* Unpack all the non-pointer fields of the TS_DECL_COMMON structure
193 of expression EXPR from bitpack BP. */
195 static void
196 unpack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
198 DECL_MODE (expr) = bp_unpack_enum (bp, machine_mode, MAX_MACHINE_MODE);
199 DECL_NONLOCAL (expr) = (unsigned) bp_unpack_value (bp, 1);
200 DECL_VIRTUAL_P (expr) = (unsigned) bp_unpack_value (bp, 1);
201 DECL_IGNORED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
202 DECL_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
203 DECL_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1);
204 DECL_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
205 DECL_PRESERVE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
206 DECL_EXTERNAL (expr) = (unsigned) bp_unpack_value (bp, 1);
207 DECL_GIMPLE_REG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
208 DECL_ALIGN (expr) = (unsigned) bp_unpack_var_len_unsigned (bp);
210 if (TREE_CODE (expr) == LABEL_DECL)
212 DECL_ERROR_ISSUED (expr) = (unsigned) bp_unpack_value (bp, 1);
213 EH_LANDING_PAD_NR (expr) = (int) bp_unpack_var_len_unsigned (bp);
215 /* Always assume an initial value of -1 for LABEL_DECL_UID to
216 force gimple_set_bb to recreate label_to_block_map. */
217 LABEL_DECL_UID (expr) = -1;
220 if (TREE_CODE (expr) == FIELD_DECL)
222 DECL_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
223 DECL_NONADDRESSABLE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
224 expr->decl_common.off_align = bp_unpack_value (bp, 8);
227 if (TREE_CODE (expr) == VAR_DECL)
229 DECL_HAS_DEBUG_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
230 DECL_NONLOCAL_FRAME (expr) = (unsigned) bp_unpack_value (bp, 1);
233 if (TREE_CODE (expr) == RESULT_DECL
234 || TREE_CODE (expr) == PARM_DECL
235 || TREE_CODE (expr) == VAR_DECL)
237 DECL_BY_REFERENCE (expr) = (unsigned) bp_unpack_value (bp, 1);
238 if (TREE_CODE (expr) == VAR_DECL
239 || TREE_CODE (expr) == PARM_DECL)
240 DECL_HAS_VALUE_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
245 /* Unpack all the non-pointer fields of the TS_DECL_WRTL structure
246 of expression EXPR from bitpack BP. */
248 static void
249 unpack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
251 DECL_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
255 /* Unpack all the non-pointer fields of the TS_DECL_WITH_VIS structure
256 of expression EXPR from bitpack BP. */
258 static void
259 unpack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
261 DECL_DEFER_OUTPUT (expr) = (unsigned) bp_unpack_value (bp, 1);
262 DECL_COMMON (expr) = (unsigned) bp_unpack_value (bp, 1);
263 DECL_DLLIMPORT_P (expr) = (unsigned) bp_unpack_value (bp, 1);
264 DECL_WEAK (expr) = (unsigned) bp_unpack_value (bp, 1);
265 DECL_SEEN_IN_BIND_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
266 DECL_COMDAT (expr) = (unsigned) bp_unpack_value (bp, 1);
267 DECL_VISIBILITY (expr) = (enum symbol_visibility) bp_unpack_value (bp, 2);
268 DECL_VISIBILITY_SPECIFIED (expr) = (unsigned) bp_unpack_value (bp, 1);
270 if (TREE_CODE (expr) == VAR_DECL)
272 DECL_HARD_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
273 DECL_IN_TEXT_SECTION (expr) = (unsigned) bp_unpack_value (bp, 1);
274 DECL_IN_CONSTANT_POOL (expr) = (unsigned) bp_unpack_value (bp, 1);
275 DECL_TLS_MODEL (expr) = (enum tls_model) bp_unpack_value (bp, 3);
278 if (VAR_OR_FUNCTION_DECL_P (expr))
280 priority_type p;
281 p = (priority_type) bp_unpack_var_len_unsigned (bp);
282 SET_DECL_INIT_PRIORITY (expr, p);
287 /* Unpack all the non-pointer fields of the TS_FUNCTION_DECL structure
288 of expression EXPR from bitpack BP. */
290 static void
291 unpack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
293 DECL_BUILT_IN_CLASS (expr) = bp_unpack_enum (bp, built_in_class,
294 BUILT_IN_LAST);
295 DECL_STATIC_CONSTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
296 DECL_STATIC_DESTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
297 DECL_UNINLINABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
298 DECL_POSSIBLY_INLINED (expr) = (unsigned) bp_unpack_value (bp, 1);
299 DECL_IS_NOVOPS (expr) = (unsigned) bp_unpack_value (bp, 1);
300 DECL_IS_RETURNS_TWICE (expr) = (unsigned) bp_unpack_value (bp, 1);
301 DECL_IS_MALLOC (expr) = (unsigned) bp_unpack_value (bp, 1);
302 DECL_IS_OPERATOR_NEW (expr) = (unsigned) bp_unpack_value (bp, 1);
303 DECL_DECLARED_INLINE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
304 DECL_STATIC_CHAIN (expr) = (unsigned) bp_unpack_value (bp, 1);
305 DECL_NO_INLINE_WARNING_P (expr) = (unsigned) bp_unpack_value (bp, 1);
306 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr)
307 = (unsigned) bp_unpack_value (bp, 1);
308 DECL_NO_LIMIT_STACK (expr) = (unsigned) bp_unpack_value (bp, 1);
309 DECL_DISREGARD_INLINE_LIMITS (expr) = (unsigned) bp_unpack_value (bp, 1);
310 DECL_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
311 DECL_LOOPING_CONST_OR_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
312 if (DECL_BUILT_IN_CLASS (expr) != NOT_BUILT_IN)
314 DECL_FUNCTION_CODE (expr) = (enum built_in_function) bp_unpack_value (bp,
315 11);
316 if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL
317 && DECL_FUNCTION_CODE (expr) >= END_BUILTINS)
318 fatal_error ("machine independent builtin code out of range");
319 else if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD)
321 tree result = targetm.builtin_decl (DECL_FUNCTION_CODE (expr), true);
322 if (!result || result == error_mark_node)
323 fatal_error ("target specific builtin not available");
326 if (DECL_STATIC_DESTRUCTOR (expr))
328 priority_type p;
329 p = (priority_type) bp_unpack_var_len_unsigned (bp);
330 SET_DECL_FINI_PRIORITY (expr, p);
335 /* Unpack all the non-pointer fields of the TS_TYPE_COMMON structure
336 of expression EXPR from bitpack BP. */
338 static void
339 unpack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
341 enum machine_mode mode;
343 mode = bp_unpack_enum (bp, machine_mode, MAX_MACHINE_MODE);
344 SET_TYPE_MODE (expr, mode);
345 TYPE_STRING_FLAG (expr) = (unsigned) bp_unpack_value (bp, 1);
346 TYPE_NO_FORCE_BLK (expr) = (unsigned) bp_unpack_value (bp, 1);
347 TYPE_NEEDS_CONSTRUCTING (expr) = (unsigned) bp_unpack_value (bp, 1);
348 if (RECORD_OR_UNION_TYPE_P (expr))
349 TYPE_TRANSPARENT_AGGR (expr) = (unsigned) bp_unpack_value (bp, 1);
350 else if (TREE_CODE (expr) == ARRAY_TYPE)
351 TYPE_NONALIASED_COMPONENT (expr) = (unsigned) bp_unpack_value (bp, 1);
352 TYPE_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
353 TYPE_RESTRICT (expr) = (unsigned) bp_unpack_value (bp, 1);
354 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr)
355 = (unsigned) bp_unpack_value (bp, 2);
356 TYPE_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
357 TYPE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
358 TYPE_PRECISION (expr) = bp_unpack_var_len_unsigned (bp);
359 TYPE_ALIGN (expr) = bp_unpack_var_len_unsigned (bp);
360 TYPE_ALIAS_SET (expr) = bp_unpack_var_len_int (bp);
364 /* Unpack all the non-pointer fields of the TS_BLOCK structure
365 of expression EXPR from bitpack BP. */
367 static void
368 unpack_ts_block_value_fields (struct data_in *data_in,
369 struct bitpack_d *bp, tree expr)
371 BLOCK_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
372 /* BLOCK_NUMBER is recomputed. */
373 BLOCK_SOURCE_LOCATION (expr) = stream_input_location (bp, data_in);
376 /* Unpack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL
377 structure of expression EXPR from bitpack BP. */
379 static void
380 unpack_ts_translation_unit_decl_value_fields (struct data_in *data_in,
381 struct bitpack_d *bp, tree expr)
383 TRANSLATION_UNIT_LANGUAGE (expr) = xstrdup (bp_unpack_string (data_in, bp));
384 vec_safe_push (all_translation_units, expr);
387 /* Unpack a TS_TARGET_OPTION tree from BP into EXPR. */
389 static void
390 unpack_ts_target_option (struct bitpack_d *bp, tree expr)
392 unsigned i, len;
393 struct cl_target_option *t = TREE_TARGET_OPTION (expr);
395 len = sizeof (struct cl_target_option);
396 for (i = 0; i < len; i++)
397 ((unsigned char *)t)[i] = bp_unpack_value (bp, 8);
398 if (bp_unpack_value (bp, 32) != 0x12345678)
399 fatal_error ("cl_target_option size mismatch in LTO reader and writer");
402 /* Unpack a TS_OPTIMIZATION tree from BP into EXPR. */
404 static void
405 unpack_ts_optimization (struct bitpack_d *bp, tree expr)
407 unsigned i, len;
408 struct cl_optimization *t = TREE_OPTIMIZATION (expr);
410 len = sizeof (struct cl_optimization);
411 for (i = 0; i < len; i++)
412 ((unsigned char *)t)[i] = bp_unpack_value (bp, 8);
413 if (bp_unpack_value (bp, 32) != 0x12345678)
414 fatal_error ("cl_optimization size mismatch in LTO reader and writer");
418 /* Unpack all the non-pointer fields in EXPR into a bit pack. */
420 static void
421 unpack_value_fields (struct data_in *data_in, struct bitpack_d *bp, tree expr)
423 enum tree_code code;
425 code = TREE_CODE (expr);
427 /* Note that all these functions are highly sensitive to changes in
428 the types and sizes of each of the fields being packed. */
429 unpack_ts_base_value_fields (bp, expr);
431 if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
432 unpack_ts_int_cst_value_fields (bp, expr);
434 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
435 unpack_ts_real_cst_value_fields (bp, expr);
437 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
438 unpack_ts_fixed_cst_value_fields (bp, expr);
440 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
441 DECL_SOURCE_LOCATION (expr) = stream_input_location (bp, data_in);
443 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
444 unpack_ts_decl_common_value_fields (bp, expr);
446 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
447 unpack_ts_decl_wrtl_value_fields (bp, expr);
449 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
450 unpack_ts_decl_with_vis_value_fields (bp, expr);
452 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
453 unpack_ts_function_decl_value_fields (bp, expr);
455 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
456 unpack_ts_type_common_value_fields (bp, expr);
458 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
459 SET_EXPR_LOCATION (expr, stream_input_location (bp, data_in));
461 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
462 unpack_ts_block_value_fields (data_in, bp, expr);
464 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
465 unpack_ts_translation_unit_decl_value_fields (data_in, bp, expr);
467 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
468 unpack_ts_target_option (bp, expr);
470 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
471 unpack_ts_optimization (bp, expr);
473 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
475 unsigned HOST_WIDE_INT length = bp_unpack_var_len_unsigned (bp);
476 if (length > 0)
477 vec_safe_grow (BINFO_BASE_ACCESSES (expr), length);
480 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
482 unsigned HOST_WIDE_INT length = bp_unpack_var_len_unsigned (bp);
483 if (length > 0)
484 vec_safe_grow (CONSTRUCTOR_ELTS (expr), length);
489 /* Read all the language-independent bitfield values for EXPR from IB.
490 Return the partially unpacked bitpack so the caller can unpack any other
491 bitfield values that the writer may have written. */
493 struct bitpack_d
494 streamer_read_tree_bitfields (struct lto_input_block *ib,
495 struct data_in *data_in, tree expr)
497 enum tree_code code;
498 struct bitpack_d bp;
500 /* Read the bitpack of non-pointer values from IB. */
501 bp = streamer_read_bitpack (ib);
503 /* The first word in BP contains the code of the tree that we
504 are about to read. */
505 code = (enum tree_code) bp_unpack_value (&bp, 16);
506 lto_tag_check (lto_tree_code_to_tag (code),
507 lto_tree_code_to_tag (TREE_CODE (expr)));
509 /* Unpack all the value fields from BP. */
510 unpack_value_fields (data_in, &bp, expr);
512 return bp;
516 /* Materialize a new tree from input block IB using descriptors in
517 DATA_IN. The code for the new tree should match TAG. Store in
518 *IX_P the index into the reader cache where the new tree is stored. */
520 tree
521 streamer_alloc_tree (struct lto_input_block *ib, struct data_in *data_in,
522 enum LTO_tags tag)
524 enum tree_code code;
525 tree result;
526 #ifdef LTO_STREAMER_DEBUG
527 HOST_WIDEST_INT orig_address_in_writer;
528 #endif
530 result = NULL_TREE;
532 #ifdef LTO_STREAMER_DEBUG
533 /* Read the word representing the memory address for the tree
534 as it was written by the writer. This is useful when
535 debugging differences between the writer and reader. */
536 orig_address_in_writer = streamer_read_hwi (ib);
537 gcc_assert ((intptr_t) orig_address_in_writer == orig_address_in_writer);
538 #endif
540 code = lto_tag_to_tree_code (tag);
542 /* We should never see an SSA_NAME tree. Only the version numbers of
543 SSA names are ever written out. See input_ssa_names. */
544 gcc_assert (code != SSA_NAME);
546 /* Instantiate a new tree using the header data. */
547 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
548 result = streamer_read_string_cst (data_in, ib);
549 else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
550 result = input_identifier (data_in, ib);
551 else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
553 HOST_WIDE_INT len = streamer_read_hwi (ib);
554 result = make_tree_vec (len);
556 else if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
558 HOST_WIDE_INT len = streamer_read_hwi (ib);
559 result = make_vector (len);
561 else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
563 unsigned HOST_WIDE_INT len = streamer_read_uhwi (ib);
564 result = make_tree_binfo (len);
566 else if (code == CALL_EXPR)
568 unsigned HOST_WIDE_INT nargs = streamer_read_uhwi (ib);
569 return build_vl_exp (CALL_EXPR, nargs + 3);
571 else
573 /* For all other nodes, materialize the tree with a raw
574 make_node call. */
575 result = make_node (code);
578 #ifdef LTO_STREAMER_DEBUG
579 /* Store the original address of the tree as seen by the writer
580 in RESULT's aux field. This is useful when debugging streaming
581 problems. This way, a debugging session can be started on
582 both writer and reader with a breakpoint using this address
583 value in both. */
584 lto_orig_address_map (result, (intptr_t) orig_address_in_writer);
585 #endif
587 return result;
591 /* Read all pointer fields in the TS_COMMON structure of EXPR from input
592 block IB. DATA_IN contains tables and descriptors for the
593 file being read. */
596 static void
597 lto_input_ts_common_tree_pointers (struct lto_input_block *ib,
598 struct data_in *data_in, tree expr)
600 if (TREE_CODE (expr) != IDENTIFIER_NODE)
601 TREE_TYPE (expr) = stream_read_tree (ib, data_in);
605 /* Read all pointer fields in the TS_VECTOR structure of EXPR from input
606 block IB. DATA_IN contains tables and descriptors for the
607 file being read. */
609 static void
610 lto_input_ts_vector_tree_pointers (struct lto_input_block *ib,
611 struct data_in *data_in, tree expr)
613 unsigned i;
614 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
615 VECTOR_CST_ELT (expr, i) = stream_read_tree (ib, data_in);
619 /* Read all pointer fields in the TS_COMPLEX structure of EXPR from input
620 block IB. DATA_IN contains tables and descriptors for the
621 file being read. */
623 static void
624 lto_input_ts_complex_tree_pointers (struct lto_input_block *ib,
625 struct data_in *data_in, tree expr)
627 TREE_REALPART (expr) = stream_read_tree (ib, data_in);
628 TREE_IMAGPART (expr) = stream_read_tree (ib, data_in);
632 /* Read all pointer fields in the TS_DECL_MINIMAL structure of EXPR
633 from input block IB. DATA_IN contains tables and descriptors for the
634 file being read. */
636 static void
637 lto_input_ts_decl_minimal_tree_pointers (struct lto_input_block *ib,
638 struct data_in *data_in, tree expr)
640 DECL_NAME (expr) = stream_read_tree (ib, data_in);
641 DECL_CONTEXT (expr) = stream_read_tree (ib, data_in);
645 /* Read all pointer fields in the TS_DECL_COMMON structure of EXPR from
646 input block IB. DATA_IN contains tables and descriptors for the
647 file being read. */
649 static void
650 lto_input_ts_decl_common_tree_pointers (struct lto_input_block *ib,
651 struct data_in *data_in, tree expr)
653 DECL_SIZE (expr) = stream_read_tree (ib, data_in);
654 DECL_SIZE_UNIT (expr) = stream_read_tree (ib, data_in);
655 DECL_ATTRIBUTES (expr) = stream_read_tree (ib, data_in);
657 /* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
658 for early inlining so drop it on the floor instead of ICEing in
659 dwarf2out.c. */
661 if ((TREE_CODE (expr) == VAR_DECL
662 || TREE_CODE (expr) == PARM_DECL)
663 && DECL_HAS_VALUE_EXPR_P (expr))
664 SET_DECL_VALUE_EXPR (expr, stream_read_tree (ib, data_in));
666 if (TREE_CODE (expr) == VAR_DECL)
668 tree dexpr = stream_read_tree (ib, data_in);
669 if (dexpr)
670 SET_DECL_DEBUG_EXPR (expr, dexpr);
675 /* Read all pointer fields in the TS_DECL_NON_COMMON structure of
676 EXPR from input block IB. DATA_IN contains tables and descriptors for the
677 file being read. */
679 static void
680 lto_input_ts_decl_non_common_tree_pointers (struct lto_input_block *ib,
681 struct data_in *data_in, tree expr)
683 if (TREE_CODE (expr) == FUNCTION_DECL)
685 DECL_ARGUMENTS (expr) = streamer_read_chain (ib, data_in);
686 DECL_RESULT (expr) = stream_read_tree (ib, data_in);
688 else if (TREE_CODE (expr) == TYPE_DECL)
689 DECL_ORIGINAL_TYPE (expr) = stream_read_tree (ib, data_in);
690 DECL_VINDEX (expr) = stream_read_tree (ib, data_in);
694 /* Read all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
695 from input block IB. DATA_IN contains tables and descriptors for the
696 file being read. */
698 static void
699 lto_input_ts_decl_with_vis_tree_pointers (struct lto_input_block *ib,
700 struct data_in *data_in, tree expr)
702 tree id;
704 id = stream_read_tree (ib, data_in);
705 if (id)
707 gcc_assert (TREE_CODE (id) == IDENTIFIER_NODE);
708 SET_DECL_ASSEMBLER_NAME (expr, id);
711 DECL_SECTION_NAME (expr) = stream_read_tree (ib, data_in);
712 DECL_COMDAT_GROUP (expr) = stream_read_tree (ib, data_in);
716 /* Read all pointer fields in the TS_FIELD_DECL structure of EXPR from
717 input block IB. DATA_IN contains tables and descriptors for the
718 file being read. */
720 static void
721 lto_input_ts_field_decl_tree_pointers (struct lto_input_block *ib,
722 struct data_in *data_in, tree expr)
724 DECL_FIELD_OFFSET (expr) = stream_read_tree (ib, data_in);
725 DECL_BIT_FIELD_TYPE (expr) = stream_read_tree (ib, data_in);
726 DECL_BIT_FIELD_REPRESENTATIVE (expr) = stream_read_tree (ib, data_in);
727 DECL_FIELD_BIT_OFFSET (expr) = stream_read_tree (ib, data_in);
728 DECL_FCONTEXT (expr) = stream_read_tree (ib, data_in);
732 /* Read all pointer fields in the TS_FUNCTION_DECL structure of EXPR
733 from input block IB. DATA_IN contains tables and descriptors for the
734 file being read. */
736 static void
737 lto_input_ts_function_decl_tree_pointers (struct lto_input_block *ib,
738 struct data_in *data_in, tree expr)
740 /* DECL_STRUCT_FUNCTION is handled by lto_input_function. FIXME lto,
741 maybe it should be handled here? */
742 DECL_FUNCTION_PERSONALITY (expr) = stream_read_tree (ib, data_in);
743 DECL_FUNCTION_SPECIFIC_TARGET (expr) = stream_read_tree (ib, data_in);
744 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr) = stream_read_tree (ib, data_in);
746 /* If the file contains a function with an EH personality set,
747 then it was compiled with -fexceptions. In that case, initialize
748 the backend EH machinery. */
749 if (DECL_FUNCTION_PERSONALITY (expr))
750 lto_init_eh ();
754 /* Read all pointer fields in the TS_TYPE_COMMON structure of EXPR from
755 input block IB. DATA_IN contains tables and descriptors for the file
756 being read. */
758 static void
759 lto_input_ts_type_common_tree_pointers (struct lto_input_block *ib,
760 struct data_in *data_in, tree expr)
762 TYPE_SIZE (expr) = stream_read_tree (ib, data_in);
763 TYPE_SIZE_UNIT (expr) = stream_read_tree (ib, data_in);
764 TYPE_ATTRIBUTES (expr) = stream_read_tree (ib, data_in);
765 TYPE_NAME (expr) = stream_read_tree (ib, data_in);
766 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO. They will be
767 reconstructed during fixup. */
768 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
769 during fixup. */
770 TYPE_MAIN_VARIANT (expr) = stream_read_tree (ib, data_in);
771 TYPE_CONTEXT (expr) = stream_read_tree (ib, data_in);
772 /* TYPE_CANONICAL gets re-computed during type merging. */
773 TYPE_CANONICAL (expr) = NULL_TREE;
774 TYPE_STUB_DECL (expr) = stream_read_tree (ib, data_in);
777 /* Read all pointer fields in the TS_TYPE_NON_COMMON structure of EXPR
778 from input block IB. DATA_IN contains tables and descriptors for the
779 file being read. */
781 static void
782 lto_input_ts_type_non_common_tree_pointers (struct lto_input_block *ib,
783 struct data_in *data_in,
784 tree expr)
786 if (TREE_CODE (expr) == ENUMERAL_TYPE)
787 TYPE_VALUES (expr) = stream_read_tree (ib, data_in);
788 else if (TREE_CODE (expr) == ARRAY_TYPE)
789 TYPE_DOMAIN (expr) = stream_read_tree (ib, data_in);
790 else if (RECORD_OR_UNION_TYPE_P (expr))
791 TYPE_FIELDS (expr) = streamer_read_chain (ib, data_in);
792 else if (TREE_CODE (expr) == FUNCTION_TYPE
793 || TREE_CODE (expr) == METHOD_TYPE)
794 TYPE_ARG_TYPES (expr) = stream_read_tree (ib, data_in);
796 if (!POINTER_TYPE_P (expr))
797 TYPE_MINVAL (expr) = stream_read_tree (ib, data_in);
798 TYPE_MAXVAL (expr) = stream_read_tree (ib, data_in);
799 if (RECORD_OR_UNION_TYPE_P (expr))
800 TYPE_BINFO (expr) = stream_read_tree (ib, data_in);
804 /* Read all pointer fields in the TS_LIST structure of EXPR from input
805 block IB. DATA_IN contains tables and descriptors for the
806 file being read. */
808 static void
809 lto_input_ts_list_tree_pointers (struct lto_input_block *ib,
810 struct data_in *data_in, tree expr)
812 TREE_PURPOSE (expr) = stream_read_tree (ib, data_in);
813 TREE_VALUE (expr) = stream_read_tree (ib, data_in);
814 TREE_CHAIN (expr) = streamer_read_chain (ib, data_in);
818 /* Read all pointer fields in the TS_VEC structure of EXPR from input
819 block IB. DATA_IN contains tables and descriptors for the
820 file being read. */
822 static void
823 lto_input_ts_vec_tree_pointers (struct lto_input_block *ib,
824 struct data_in *data_in, tree expr)
826 int i;
828 /* Note that TREE_VEC_LENGTH was read by streamer_alloc_tree to
829 instantiate EXPR. */
830 for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
831 TREE_VEC_ELT (expr, i) = stream_read_tree (ib, data_in);
835 /* Read all pointer fields in the TS_EXP structure of EXPR from input
836 block IB. DATA_IN contains tables and descriptors for the
837 file being read. */
840 static void
841 lto_input_ts_exp_tree_pointers (struct lto_input_block *ib,
842 struct data_in *data_in, tree expr)
844 int i;
846 for (i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
847 TREE_OPERAND (expr, i) = stream_read_tree (ib, data_in);
849 TREE_SET_BLOCK (expr, stream_read_tree (ib, data_in));
853 /* Read all pointer fields in the TS_BLOCK structure of EXPR from input
854 block IB. DATA_IN contains tables and descriptors for the
855 file being read. */
857 static void
858 lto_input_ts_block_tree_pointers (struct lto_input_block *ib,
859 struct data_in *data_in, tree expr)
861 BLOCK_VARS (expr) = streamer_read_chain (ib, data_in);
863 BLOCK_SUPERCONTEXT (expr) = stream_read_tree (ib, data_in);
865 /* Stream BLOCK_ABSTRACT_ORIGIN and BLOCK_SOURCE_LOCATION for
866 the limited cases we can handle - those that represent inlined
867 function scopes. For the rest them on the floor instead of ICEing in
868 dwarf2out.c. */
869 BLOCK_ABSTRACT_ORIGIN (expr) = stream_read_tree (ib, data_in);
870 /* Do not stream BLOCK_NONLOCALIZED_VARS. We cannot handle debug information
871 for early inlined BLOCKs so drop it on the floor instead of ICEing in
872 dwarf2out.c. */
874 /* BLOCK_FRAGMENT_ORIGIN and BLOCK_FRAGMENT_CHAIN is not live at LTO
875 streaming time. */
877 /* We re-compute BLOCK_SUBBLOCKS of our parent here instead
878 of streaming it. For non-BLOCK BLOCK_SUPERCONTEXTs we still
879 stream the child relationship explicitly. */
880 if (BLOCK_SUPERCONTEXT (expr)
881 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == BLOCK)
883 BLOCK_CHAIN (expr) = BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr));
884 BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr)) = expr;
887 /* The global block is rooted at the TU decl. Hook it here to
888 avoid the need to stream in this block during WPA time. */
889 else if (BLOCK_SUPERCONTEXT (expr)
890 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == TRANSLATION_UNIT_DECL)
891 DECL_INITIAL (BLOCK_SUPERCONTEXT (expr)) = expr;
893 /* The function-level block is connected at the time we read in
894 function bodies for the same reason. */
898 /* Read all pointer fields in the TS_BINFO structure of EXPR from input
899 block IB. DATA_IN contains tables and descriptors for the
900 file being read. */
902 static void
903 lto_input_ts_binfo_tree_pointers (struct lto_input_block *ib,
904 struct data_in *data_in, tree expr)
906 unsigned i;
907 tree t;
909 /* Note that the number of slots in EXPR was read in
910 streamer_alloc_tree when instantiating EXPR. However, the
911 vector is empty so we cannot rely on vec::length to know how many
912 elements to read. So, this list is emitted as a 0-terminated
913 list on the writer side. */
916 t = stream_read_tree (ib, data_in);
917 if (t)
918 BINFO_BASE_BINFOS (expr)->quick_push (t);
920 while (t);
922 BINFO_OFFSET (expr) = stream_read_tree (ib, data_in);
923 BINFO_VTABLE (expr) = stream_read_tree (ib, data_in);
924 BINFO_VPTR_FIELD (expr) = stream_read_tree (ib, data_in);
926 /* The vector of BINFO_BASE_ACCESSES is pre-allocated during
927 unpacking the bitfield section. */
928 for (i = 0; i < vec_safe_length (BINFO_BASE_ACCESSES (expr)); i++)
930 tree a = stream_read_tree (ib, data_in);
931 (*BINFO_BASE_ACCESSES (expr))[i] = a;
934 BINFO_INHERITANCE_CHAIN (expr) = stream_read_tree (ib, data_in);
935 BINFO_SUBVTT_INDEX (expr) = stream_read_tree (ib, data_in);
936 BINFO_VPTR_INDEX (expr) = stream_read_tree (ib, data_in);
940 /* Read all pointer fields in the TS_CONSTRUCTOR structure of EXPR from
941 input block IB. DATA_IN contains tables and descriptors for the
942 file being read. */
944 static void
945 lto_input_ts_constructor_tree_pointers (struct lto_input_block *ib,
946 struct data_in *data_in, tree expr)
948 unsigned i;
950 for (i = 0; i < CONSTRUCTOR_NELTS (expr); i++)
952 constructor_elt e;
953 e.index = stream_read_tree (ib, data_in);
954 e.value = stream_read_tree (ib, data_in);
955 (*CONSTRUCTOR_ELTS (expr))[i] = e;
960 /* Read all pointer fields in EXPR from input block IB. DATA_IN
961 contains tables and descriptors for the file being read. */
963 void
964 streamer_read_tree_body (struct lto_input_block *ib, struct data_in *data_in,
965 tree expr)
967 enum tree_code code;
969 code = TREE_CODE (expr);
971 if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
972 lto_input_ts_common_tree_pointers (ib, data_in, expr);
974 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
975 lto_input_ts_vector_tree_pointers (ib, data_in, expr);
977 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
978 lto_input_ts_complex_tree_pointers (ib, data_in, expr);
980 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
981 lto_input_ts_decl_minimal_tree_pointers (ib, data_in, expr);
983 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
984 lto_input_ts_decl_common_tree_pointers (ib, data_in, expr);
986 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
987 lto_input_ts_decl_non_common_tree_pointers (ib, data_in, expr);
989 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
990 lto_input_ts_decl_with_vis_tree_pointers (ib, data_in, expr);
992 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
993 lto_input_ts_field_decl_tree_pointers (ib, data_in, expr);
995 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
996 lto_input_ts_function_decl_tree_pointers (ib, data_in, expr);
998 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
999 lto_input_ts_type_common_tree_pointers (ib, data_in, expr);
1001 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1002 lto_input_ts_type_non_common_tree_pointers (ib, data_in, expr);
1004 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1005 lto_input_ts_list_tree_pointers (ib, data_in, expr);
1007 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1008 lto_input_ts_vec_tree_pointers (ib, data_in, expr);
1010 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
1011 lto_input_ts_exp_tree_pointers (ib, data_in, expr);
1013 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1014 lto_input_ts_block_tree_pointers (ib, data_in, expr);
1016 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1017 lto_input_ts_binfo_tree_pointers (ib, data_in, expr);
1019 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1020 lto_input_ts_constructor_tree_pointers (ib, data_in, expr);
1024 /* Read and INTEGER_CST node from input block IB using the per-file
1025 context in DATA_IN. */
1027 tree
1028 streamer_read_integer_cst (struct lto_input_block *ib, struct data_in *data_in)
1030 tree type = stream_read_tree (ib, data_in);
1031 unsigned HOST_WIDE_INT low = streamer_read_uhwi (ib);
1032 HOST_WIDE_INT high = streamer_read_hwi (ib);
1033 return build_int_cst_wide (type, low, high);
1037 /* Read an index IX from input block IB and return the tree node at
1038 DATA_IN->FILE_DATA->GLOBALS_INDEX[IX]. */
1040 tree
1041 streamer_get_pickled_tree (struct lto_input_block *ib, struct data_in *data_in)
1043 unsigned HOST_WIDE_INT ix;
1044 tree result;
1045 enum LTO_tags expected_tag;
1047 ix = streamer_read_uhwi (ib);
1048 expected_tag = streamer_read_enum (ib, LTO_tags, LTO_NUM_TAGS);
1050 result = streamer_tree_cache_get (data_in->reader_cache, ix);
1051 gcc_assert (result
1052 && TREE_CODE (result) == lto_tag_to_tree_code (expected_tag));
1054 return result;
1058 /* Read a code and class from input block IB and return the
1059 corresponding builtin. DATA_IN is as in stream_read_tree. */
1061 tree
1062 streamer_get_builtin_tree (struct lto_input_block *ib, struct data_in *data_in)
1064 enum built_in_class fclass;
1065 enum built_in_function fcode;
1066 const char *asmname;
1067 tree result;
1069 fclass = streamer_read_enum (ib, built_in_class, BUILT_IN_LAST);
1070 gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
1072 fcode = (enum built_in_function) streamer_read_uhwi (ib);
1074 if (fclass == BUILT_IN_NORMAL)
1076 if (fcode >= END_BUILTINS)
1077 fatal_error ("machine independent builtin code out of range");
1078 result = builtin_decl_explicit (fcode);
1079 gcc_assert (result);
1081 else if (fclass == BUILT_IN_MD)
1083 result = targetm.builtin_decl (fcode, true);
1084 if (!result || result == error_mark_node)
1085 fatal_error ("target specific builtin not available");
1087 else
1088 gcc_unreachable ();
1090 asmname = streamer_read_string (data_in, ib);
1091 if (asmname)
1092 set_builtin_user_assembler_name (result, asmname);
1094 streamer_tree_cache_append (data_in->reader_cache, result);
1096 return result;