1 /* Routines for emitting trees to a file stream.
3 Copyright 2011 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
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
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/>. */
24 #include "coretypes.h"
25 #include "diagnostic.h"
27 #include "tree-streamer.h"
28 #include "data-streamer.h"
29 #include "streamer-hooks.h"
31 /* Output the STRING constant to the string
32 table in OB. Then put the index onto the INDEX_STREAM. */
35 output_string_cst (struct output_block *ob,
36 struct lto_output_stream *index_stream,
39 lto_output_string_with_length (ob, index_stream,
40 TREE_STRING_POINTER (string),
41 TREE_STRING_LENGTH (string),
46 /* Output the identifier ID to the string
47 table in OB. Then put the index onto the INDEX_STREAM. */
50 output_identifier (struct output_block *ob,
51 struct lto_output_stream *index_stream,
54 lto_output_string_with_length (ob, index_stream,
55 IDENTIFIER_POINTER (id),
56 IDENTIFIER_LENGTH (id),
61 /* Pack all the non-pointer fields of the TS_BASE structure of
62 expression EXPR into bitpack BP. */
65 pack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
67 bp_pack_value (bp, TREE_CODE (expr), 16);
70 bp_pack_value (bp, TREE_SIDE_EFFECTS (expr), 1);
71 bp_pack_value (bp, TREE_CONSTANT (expr), 1);
72 bp_pack_value (bp, TREE_READONLY (expr), 1);
74 /* TREE_PUBLIC is used on types to indicate that the type
75 has a TYPE_CACHED_VALUES vector. This is not streamed out,
76 so we skip it here. */
77 bp_pack_value (bp, TREE_PUBLIC (expr), 1);
80 bp_pack_value (bp, 0, 4);
81 bp_pack_value (bp, TREE_ADDRESSABLE (expr), 1);
82 bp_pack_value (bp, TREE_THIS_VOLATILE (expr), 1);
84 bp_pack_value (bp, DECL_UNSIGNED (expr), 1);
85 else if (TYPE_P (expr))
86 bp_pack_value (bp, TYPE_UNSIGNED (expr), 1);
88 bp_pack_value (bp, 0, 1);
89 /* We write debug info two times, do not confuse the second one. */
90 bp_pack_value (bp, TYPE_P (expr) ? 0 : TREE_ASM_WRITTEN (expr), 1);
92 bp_pack_value (bp, TYPE_ARTIFICIAL (expr), 1);
94 bp_pack_value (bp, TREE_NO_WARNING (expr), 1);
95 bp_pack_value (bp, TREE_USED (expr), 1);
96 bp_pack_value (bp, TREE_NOTHROW (expr), 1);
97 bp_pack_value (bp, TREE_STATIC (expr), 1);
98 bp_pack_value (bp, TREE_PRIVATE (expr), 1);
99 bp_pack_value (bp, TREE_PROTECTED (expr), 1);
100 bp_pack_value (bp, TREE_DEPRECATED (expr), 1);
102 bp_pack_value (bp, TYPE_SATURATING (expr), 1);
103 else if (TREE_CODE (expr) == SSA_NAME)
104 bp_pack_value (bp, SSA_NAME_IS_DEFAULT_DEF (expr), 1);
106 bp_pack_value (bp, 0, 1);
110 /* Pack all the non-pointer fields of the TS_REAL_CST structure of
111 expression EXPR into bitpack BP. */
114 pack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
119 r = TREE_REAL_CST (expr);
120 bp_pack_value (bp, r.cl, 2);
121 bp_pack_value (bp, r.decimal, 1);
122 bp_pack_value (bp, r.sign, 1);
123 bp_pack_value (bp, r.signalling, 1);
124 bp_pack_value (bp, r.canonical, 1);
125 bp_pack_value (bp, r.uexp, EXP_BITS);
126 for (i = 0; i < SIGSZ; i++)
127 bp_pack_value (bp, r.sig[i], HOST_BITS_PER_LONG);
131 /* Pack all the non-pointer fields of the TS_FIXED_CST structure of
132 expression EXPR into bitpack BP. */
135 pack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
137 struct fixed_value fv = TREE_FIXED_CST (expr);
138 bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, fv.mode);
139 bp_pack_var_len_int (bp, fv.data.low);
140 bp_pack_var_len_int (bp, fv.data.high);
144 /* Pack all the non-pointer fields of the TS_DECL_COMMON structure
145 of expression EXPR into bitpack BP. */
148 pack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
150 bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, DECL_MODE (expr));
151 bp_pack_value (bp, DECL_NONLOCAL (expr), 1);
152 bp_pack_value (bp, DECL_VIRTUAL_P (expr), 1);
153 bp_pack_value (bp, DECL_IGNORED_P (expr), 1);
154 bp_pack_value (bp, DECL_ABSTRACT (expr), 1);
155 bp_pack_value (bp, DECL_ARTIFICIAL (expr), 1);
156 bp_pack_value (bp, DECL_USER_ALIGN (expr), 1);
157 bp_pack_value (bp, DECL_PRESERVE_P (expr), 1);
158 bp_pack_value (bp, DECL_DEBUG_EXPR_IS_FROM (expr), 1);
159 bp_pack_value (bp, DECL_EXTERNAL (expr), 1);
160 bp_pack_value (bp, DECL_GIMPLE_REG_P (expr), 1);
161 bp_pack_var_len_unsigned (bp, DECL_ALIGN (expr));
163 if (TREE_CODE (expr) == LABEL_DECL)
165 /* Note that we do not write LABEL_DECL_UID. The reader will
166 always assume an initial value of -1 so that the
167 label_to_block_map is recreated by gimple_set_bb. */
168 bp_pack_value (bp, DECL_ERROR_ISSUED (expr), 1);
169 bp_pack_var_len_unsigned (bp, EH_LANDING_PAD_NR (expr));
172 if (TREE_CODE (expr) == FIELD_DECL)
174 bp_pack_value (bp, DECL_PACKED (expr), 1);
175 bp_pack_value (bp, DECL_NONADDRESSABLE_P (expr), 1);
176 bp_pack_value (bp, expr->decl_common.off_align, 8);
179 if (TREE_CODE (expr) == RESULT_DECL
180 || TREE_CODE (expr) == PARM_DECL
181 || TREE_CODE (expr) == VAR_DECL)
183 bp_pack_value (bp, DECL_BY_REFERENCE (expr), 1);
184 if (TREE_CODE (expr) == VAR_DECL
185 || TREE_CODE (expr) == PARM_DECL)
186 bp_pack_value (bp, DECL_HAS_VALUE_EXPR_P (expr), 1);
187 bp_pack_value (bp, DECL_RESTRICTED_P (expr), 1);
192 /* Pack all the non-pointer fields of the TS_DECL_WRTL structure
193 of expression EXPR into bitpack BP. */
196 pack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
198 bp_pack_value (bp, DECL_REGISTER (expr), 1);
202 /* Pack all the non-pointer fields of the TS_DECL_WITH_VIS structure
203 of expression EXPR into bitpack BP. */
206 pack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
208 bp_pack_value (bp, DECL_DEFER_OUTPUT (expr), 1);
209 bp_pack_value (bp, DECL_COMMON (expr), 1);
210 bp_pack_value (bp, DECL_DLLIMPORT_P (expr), 1);
211 bp_pack_value (bp, DECL_WEAK (expr), 1);
212 bp_pack_value (bp, DECL_SEEN_IN_BIND_EXPR_P (expr), 1);
213 bp_pack_value (bp, DECL_COMDAT (expr), 1);
214 bp_pack_value (bp, DECL_VISIBILITY (expr), 2);
215 bp_pack_value (bp, DECL_VISIBILITY_SPECIFIED (expr), 1);
217 if (TREE_CODE (expr) == VAR_DECL)
219 bp_pack_value (bp, DECL_HARD_REGISTER (expr), 1);
220 bp_pack_value (bp, DECL_IN_TEXT_SECTION (expr), 1);
221 bp_pack_value (bp, DECL_IN_CONSTANT_POOL (expr), 1);
222 bp_pack_value (bp, DECL_TLS_MODEL (expr), 3);
225 if (VAR_OR_FUNCTION_DECL_P (expr))
226 bp_pack_var_len_unsigned (bp, DECL_INIT_PRIORITY (expr));
230 /* Pack all the non-pointer fields of the TS_FUNCTION_DECL structure
231 of expression EXPR into bitpack BP. */
234 pack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
236 /* For normal/md builtins we only write the class and code, so they
237 should never be handled here. */
238 gcc_assert (!lto_stream_as_builtin_p (expr));
240 bp_pack_enum (bp, built_in_class, BUILT_IN_LAST,
241 DECL_BUILT_IN_CLASS (expr));
242 bp_pack_value (bp, DECL_STATIC_CONSTRUCTOR (expr), 1);
243 bp_pack_value (bp, DECL_STATIC_DESTRUCTOR (expr), 1);
244 bp_pack_value (bp, DECL_UNINLINABLE (expr), 1);
245 bp_pack_value (bp, DECL_POSSIBLY_INLINED (expr), 1);
246 bp_pack_value (bp, DECL_IS_NOVOPS (expr), 1);
247 bp_pack_value (bp, DECL_IS_RETURNS_TWICE (expr), 1);
248 bp_pack_value (bp, DECL_IS_MALLOC (expr), 1);
249 bp_pack_value (bp, DECL_IS_OPERATOR_NEW (expr), 1);
250 bp_pack_value (bp, DECL_DECLARED_INLINE_P (expr), 1);
251 bp_pack_value (bp, DECL_STATIC_CHAIN (expr), 1);
252 bp_pack_value (bp, DECL_NO_INLINE_WARNING_P (expr), 1);
253 bp_pack_value (bp, DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr), 1);
254 bp_pack_value (bp, DECL_NO_LIMIT_STACK (expr), 1);
255 bp_pack_value (bp, DECL_DISREGARD_INLINE_LIMITS (expr), 1);
256 bp_pack_value (bp, DECL_PURE_P (expr), 1);
257 bp_pack_value (bp, DECL_LOOPING_CONST_OR_PURE_P (expr), 1);
258 if (DECL_BUILT_IN_CLASS (expr) != NOT_BUILT_IN)
259 bp_pack_value (bp, DECL_FUNCTION_CODE (expr), 11);
260 if (DECL_STATIC_DESTRUCTOR (expr))
261 bp_pack_var_len_unsigned (bp, DECL_FINI_PRIORITY (expr));
265 /* Pack all the non-pointer fields of the TS_TYPE_COMMON structure
266 of expression EXPR into bitpack BP. */
269 pack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
271 bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, TYPE_MODE (expr));
272 bp_pack_value (bp, TYPE_STRING_FLAG (expr), 1);
273 bp_pack_value (bp, TYPE_NO_FORCE_BLK (expr), 1);
274 bp_pack_value (bp, TYPE_NEEDS_CONSTRUCTING (expr), 1);
275 if (RECORD_OR_UNION_TYPE_P (expr))
276 bp_pack_value (bp, TYPE_TRANSPARENT_AGGR (expr), 1);
277 bp_pack_value (bp, TYPE_PACKED (expr), 1);
278 bp_pack_value (bp, TYPE_RESTRICT (expr), 1);
279 bp_pack_value (bp, TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr), 2);
280 bp_pack_value (bp, TYPE_USER_ALIGN (expr), 1);
281 bp_pack_value (bp, TYPE_READONLY (expr), 1);
282 bp_pack_var_len_unsigned (bp, TYPE_PRECISION (expr));
283 bp_pack_var_len_unsigned (bp, TYPE_ALIGN (expr));
284 bp_pack_var_len_int (bp, TYPE_ALIAS_SET (expr) == 0 ? 0 : -1);
288 /* Pack all the non-pointer fields of the TS_BLOCK structure
289 of expression EXPR into bitpack BP. */
292 pack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
294 bp_pack_value (bp, BLOCK_ABSTRACT (expr), 1);
295 /* BLOCK_NUMBER is recomputed. */
298 /* Pack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL structure
299 of expression EXPR into bitpack BP. */
302 pack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
306 /* Pack all the non-pointer fields in EXPR into a bit pack. */
309 pack_value_fields (struct bitpack_d *bp, tree expr)
313 code = TREE_CODE (expr);
315 /* Note that all these functions are highly sensitive to changes in
316 the types and sizes of each of the fields being packed. */
317 pack_ts_base_value_fields (bp, expr);
319 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
320 pack_ts_real_cst_value_fields (bp, expr);
322 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
323 pack_ts_fixed_cst_value_fields (bp, expr);
325 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
326 pack_ts_decl_common_value_fields (bp, expr);
328 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
329 pack_ts_decl_wrtl_value_fields (bp, expr);
331 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
332 pack_ts_decl_with_vis_value_fields (bp, expr);
334 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
335 pack_ts_function_decl_value_fields (bp, expr);
337 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
338 pack_ts_type_common_value_fields (bp, expr);
340 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
341 pack_ts_block_value_fields (bp, expr);
343 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
344 pack_ts_translation_unit_decl_value_fields (bp, expr);
346 if (streamer_hooks.pack_value_fields)
347 streamer_hooks.pack_value_fields (bp, expr);
351 /* If REF_P is true, emit a reference to EXPR in output block OB,
352 otherwise emit the physical representation of EXPR in OB. */
355 lto_output_tree_or_ref (struct output_block *ob, tree expr, bool ref_p)
358 lto_output_tree_ref (ob, expr);
360 lto_output_tree (ob, expr, false);
364 /* Write the code and class of builtin EXPR to output block OB. IX is
365 the index into the streamer cache where EXPR is stored.*/
368 lto_output_builtin_tree (struct output_block *ob, tree expr)
370 gcc_assert (lto_stream_as_builtin_p (expr));
372 if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
373 && !targetm.builtin_decl)
374 sorry ("gimple bytecode streams do not support machine specific builtin "
375 "functions on this target");
377 output_record_start (ob, LTO_builtin_decl);
378 lto_output_enum (ob->main_stream, built_in_class, BUILT_IN_LAST,
379 DECL_BUILT_IN_CLASS (expr));
380 output_uleb128 (ob, DECL_FUNCTION_CODE (expr));
382 if (DECL_ASSEMBLER_NAME_SET_P (expr))
384 /* When the assembler name of a builtin gets a user name,
385 the new name is always prefixed with '*' by
386 set_builtin_user_assembler_name. So, to prevent the
387 reader side from adding a second '*', we omit it here. */
388 const char *str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr));
389 if (strlen (str) > 1 && str[0] == '*')
390 lto_output_string (ob, ob->main_stream, &str[1], true);
392 lto_output_string (ob, ob->main_stream, NULL, true);
395 lto_output_string (ob, ob->main_stream, NULL, true);
399 /* GIMPLE hook for writing GIMPLE-specific parts of trees. OB, EXPR
400 and REF_P are as in lto_write_tree. */
403 lto_streamer_write_tree (struct output_block *ob, tree expr, bool ref_p)
406 && TREE_CODE (expr) != FUNCTION_DECL
407 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
409 /* Handle DECL_INITIAL for symbols. */
410 tree initial = DECL_INITIAL (expr);
411 if (TREE_CODE (expr) == VAR_DECL
412 && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
415 lto_varpool_encoder_t varpool_encoder;
416 struct varpool_node *vnode;
418 varpool_encoder = ob->decl_state->varpool_node_encoder;
419 vnode = varpool_get_node (expr);
421 initial = error_mark_node;
422 else if (!lto_varpool_encoder_encode_initializer_p (varpool_encoder,
427 lto_output_tree_or_ref (ob, initial, ref_p);
432 /* Emit the chain of tree nodes starting at T. OB is the output block
433 to write to. REF_P is true if chain elements should be emitted
437 lto_output_chain (struct output_block *ob, tree t, bool ref_p)
441 count = list_length (t);
442 output_sleb128 (ob, count);
443 for (i = 0; i < count; i++)
447 /* Clear TREE_CHAIN to avoid blindly recursing into the rest
449 saved_chain = TREE_CHAIN (t);
450 TREE_CHAIN (t) = NULL_TREE;
452 lto_output_tree_or_ref (ob, t, ref_p);
454 TREE_CHAIN (t) = saved_chain;
460 /* Write all pointer fields in the TS_COMMON structure of EXPR to output
461 block OB. If REF_P is true, write a reference to EXPR's pointer
465 lto_output_ts_common_tree_pointers (struct output_block *ob, tree expr,
468 if (TREE_CODE (expr) != IDENTIFIER_NODE)
469 lto_output_tree_or_ref (ob, TREE_TYPE (expr), ref_p);
473 /* Write all pointer fields in the TS_VECTOR structure of EXPR to output
474 block OB. If REF_P is true, write a reference to EXPR's pointer
478 lto_output_ts_vector_tree_pointers (struct output_block *ob, tree expr,
481 lto_output_chain (ob, TREE_VECTOR_CST_ELTS (expr), ref_p);
485 /* Write all pointer fields in the TS_COMPLEX structure of EXPR to output
486 block OB. If REF_P is true, write a reference to EXPR's pointer
490 lto_output_ts_complex_tree_pointers (struct output_block *ob, tree expr,
493 lto_output_tree_or_ref (ob, TREE_REALPART (expr), ref_p);
494 lto_output_tree_or_ref (ob, TREE_IMAGPART (expr), ref_p);
498 /* Write all pointer fields in the TS_DECL_MINIMAL structure of EXPR
499 to output block OB. If REF_P is true, write a reference to EXPR's
503 lto_output_ts_decl_minimal_tree_pointers (struct output_block *ob, tree expr,
506 lto_output_tree_or_ref (ob, DECL_NAME (expr), ref_p);
507 lto_output_tree_or_ref (ob, DECL_CONTEXT (expr), ref_p);
508 lto_output_location (ob, DECL_SOURCE_LOCATION (expr));
512 /* Write all pointer fields in the TS_DECL_COMMON structure of EXPR to
513 output block OB. If REF_P is true, write a reference to EXPR's
517 lto_output_ts_decl_common_tree_pointers (struct output_block *ob, tree expr,
520 lto_output_tree_or_ref (ob, DECL_SIZE (expr), ref_p);
521 lto_output_tree_or_ref (ob, DECL_SIZE_UNIT (expr), ref_p);
523 /* Note, DECL_INITIAL is not handled here. Since DECL_INITIAL needs
524 special handling in LTO, it must be handled by streamer hooks. */
526 lto_output_tree_or_ref (ob, DECL_ATTRIBUTES (expr), ref_p);
528 /* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
529 for early inlining so drop it on the floor instead of ICEing in
532 if (TREE_CODE (expr) == PARM_DECL)
533 lto_output_chain (ob, TREE_CHAIN (expr), ref_p);
535 if ((TREE_CODE (expr) == VAR_DECL
536 || TREE_CODE (expr) == PARM_DECL)
537 && DECL_HAS_VALUE_EXPR_P (expr))
538 lto_output_tree_or_ref (ob, DECL_VALUE_EXPR (expr), ref_p);
540 if (TREE_CODE (expr) == VAR_DECL)
541 lto_output_tree_or_ref (ob, DECL_DEBUG_EXPR (expr), ref_p);
545 /* Write all pointer fields in the TS_DECL_NON_COMMON structure of
546 EXPR to output block OB. If REF_P is true, write a reference to EXPR's
550 lto_output_ts_decl_non_common_tree_pointers (struct output_block *ob,
551 tree expr, bool ref_p)
553 if (TREE_CODE (expr) == FUNCTION_DECL)
555 lto_output_tree_or_ref (ob, DECL_ARGUMENTS (expr), ref_p);
556 lto_output_tree_or_ref (ob, DECL_RESULT (expr), ref_p);
558 lto_output_tree_or_ref (ob, DECL_VINDEX (expr), ref_p);
562 /* Write all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
563 to output block OB. If REF_P is true, write a reference to EXPR's
567 lto_output_ts_decl_with_vis_tree_pointers (struct output_block *ob, tree expr,
570 /* Make sure we don't inadvertently set the assembler name. */
571 if (DECL_ASSEMBLER_NAME_SET_P (expr))
572 lto_output_tree_or_ref (ob, DECL_ASSEMBLER_NAME (expr), ref_p);
574 output_record_start (ob, LTO_null);
576 lto_output_tree_or_ref (ob, DECL_SECTION_NAME (expr), ref_p);
577 lto_output_tree_or_ref (ob, DECL_COMDAT_GROUP (expr), ref_p);
581 /* Write all pointer fields in the TS_FIELD_DECL structure of EXPR to
582 output block OB. If REF_P is true, write a reference to EXPR's
586 lto_output_ts_field_decl_tree_pointers (struct output_block *ob, tree expr,
589 lto_output_tree_or_ref (ob, DECL_FIELD_OFFSET (expr), ref_p);
590 lto_output_tree_or_ref (ob, DECL_BIT_FIELD_TYPE (expr), ref_p);
591 lto_output_tree_or_ref (ob, DECL_QUALIFIER (expr), ref_p);
592 lto_output_tree_or_ref (ob, DECL_FIELD_BIT_OFFSET (expr), ref_p);
593 lto_output_tree_or_ref (ob, DECL_FCONTEXT (expr), ref_p);
594 lto_output_chain (ob, TREE_CHAIN (expr), ref_p);
598 /* Write all pointer fields in the TS_FUNCTION_DECL structure of EXPR
599 to output block OB. If REF_P is true, write a reference to EXPR's
603 lto_output_ts_function_decl_tree_pointers (struct output_block *ob, tree expr,
606 /* DECL_STRUCT_FUNCTION is handled by lto_output_function. FIXME lto,
607 maybe it should be handled here? */
608 lto_output_tree_or_ref (ob, DECL_FUNCTION_PERSONALITY (expr), ref_p);
609 lto_output_tree_or_ref (ob, DECL_FUNCTION_SPECIFIC_TARGET (expr), ref_p);
610 lto_output_tree_or_ref (ob, DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr),
615 /* Write all pointer fields in the TS_TYPE_COMMON structure of EXPR to
616 output block OB. If REF_P is true, write a reference to EXPR's
620 lto_output_ts_type_common_tree_pointers (struct output_block *ob, tree expr,
623 lto_output_tree_or_ref (ob, TYPE_SIZE (expr), ref_p);
624 lto_output_tree_or_ref (ob, TYPE_SIZE_UNIT (expr), ref_p);
625 lto_output_tree_or_ref (ob, TYPE_ATTRIBUTES (expr), ref_p);
626 lto_output_tree_or_ref (ob, TYPE_NAME (expr), ref_p);
627 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO. They will be
628 reconstructed during fixup. */
629 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
631 lto_output_tree_or_ref (ob, TYPE_MAIN_VARIANT (expr), ref_p);
632 lto_output_tree_or_ref (ob, TYPE_CONTEXT (expr), ref_p);
633 /* TYPE_CANONICAL is re-computed during type merging, so no need
634 to stream it here. */
635 lto_output_tree_or_ref (ob, TYPE_STUB_DECL (expr), ref_p);
638 /* Write all pointer fields in the TS_TYPE_NON_COMMON structure of EXPR
639 to output block OB. If REF_P is true, write a reference to EXPR's
643 lto_output_ts_type_non_common_tree_pointers (struct output_block *ob,
644 tree expr, bool ref_p)
646 if (TREE_CODE (expr) == ENUMERAL_TYPE)
647 lto_output_tree_or_ref (ob, TYPE_VALUES (expr), ref_p);
648 else if (TREE_CODE (expr) == ARRAY_TYPE)
649 lto_output_tree_or_ref (ob, TYPE_DOMAIN (expr), ref_p);
650 else if (RECORD_OR_UNION_TYPE_P (expr))
651 lto_output_tree_or_ref (ob, TYPE_FIELDS (expr), ref_p);
652 else if (TREE_CODE (expr) == FUNCTION_TYPE
653 || TREE_CODE (expr) == METHOD_TYPE)
654 lto_output_tree_or_ref (ob, TYPE_ARG_TYPES (expr), ref_p);
656 if (!POINTER_TYPE_P (expr))
657 lto_output_tree_or_ref (ob, TYPE_MINVAL (expr), ref_p);
658 lto_output_tree_or_ref (ob, TYPE_MAXVAL (expr), ref_p);
659 if (RECORD_OR_UNION_TYPE_P (expr))
660 lto_output_tree_or_ref (ob, TYPE_BINFO (expr), ref_p);
664 /* Write all pointer fields in the TS_LIST structure of EXPR to output
665 block OB. If REF_P is true, write a reference to EXPR's pointer
669 lto_output_ts_list_tree_pointers (struct output_block *ob, tree expr,
672 lto_output_tree_or_ref (ob, TREE_PURPOSE (expr), ref_p);
673 lto_output_tree_or_ref (ob, TREE_VALUE (expr), ref_p);
674 lto_output_chain (ob, TREE_CHAIN (expr), ref_p);
678 /* Write all pointer fields in the TS_VEC structure of EXPR to output
679 block OB. If REF_P is true, write a reference to EXPR's pointer
683 lto_output_ts_vec_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
687 /* Note that the number of slots for EXPR has already been emitted
688 in EXPR's header (see lto_output_tree_header). */
689 for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
690 lto_output_tree_or_ref (ob, TREE_VEC_ELT (expr, i), ref_p);
694 /* Write all pointer fields in the TS_EXP structure of EXPR to output
695 block OB. If REF_P is true, write a reference to EXPR's pointer
699 lto_output_ts_exp_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
703 output_sleb128 (ob, TREE_OPERAND_LENGTH (expr));
704 for (i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
705 lto_output_tree_or_ref (ob, TREE_OPERAND (expr, i), ref_p);
706 lto_output_location (ob, EXPR_LOCATION (expr));
707 lto_output_tree_or_ref (ob, TREE_BLOCK (expr), ref_p);
711 /* Write all pointer fields in the TS_BLOCK structure of EXPR to output
712 block OB. If REF_P is true, write a reference to EXPR's pointer
716 lto_output_ts_block_tree_pointers (struct output_block *ob, tree expr,
719 /* Do not stream BLOCK_SOURCE_LOCATION. We cannot handle debug information
720 for early inlining so drop it on the floor instead of ICEing in
722 lto_output_chain (ob, BLOCK_VARS (expr), ref_p);
724 /* Do not stream BLOCK_NONLOCALIZED_VARS. We cannot handle debug information
725 for early inlining so drop it on the floor instead of ICEing in
728 lto_output_tree_or_ref (ob, BLOCK_SUPERCONTEXT (expr), ref_p);
729 /* Do not stream BLOCK_ABSTRACT_ORIGIN. We cannot handle debug information
730 for early inlining so drop it on the floor instead of ICEing in
732 lto_output_tree_or_ref (ob, BLOCK_FRAGMENT_ORIGIN (expr), ref_p);
733 lto_output_tree_or_ref (ob, BLOCK_FRAGMENT_CHAIN (expr), ref_p);
734 /* Do not output BLOCK_SUBBLOCKS. Instead on streaming-in this
735 list is re-constructed from BLOCK_SUPERCONTEXT. */
739 /* Write all pointer fields in the TS_BINFO structure of EXPR to output
740 block OB. If REF_P is true, write a reference to EXPR's pointer
744 lto_output_ts_binfo_tree_pointers (struct output_block *ob, tree expr,
750 /* Note that the number of BINFO slots has already been emitted in
751 EXPR's header (see lto_output_tree_header) because this length
752 is needed to build the empty BINFO node on the reader side. */
753 FOR_EACH_VEC_ELT (tree, BINFO_BASE_BINFOS (expr), i, t)
754 lto_output_tree_or_ref (ob, t, ref_p);
755 output_record_start (ob, LTO_null);
757 lto_output_tree_or_ref (ob, BINFO_OFFSET (expr), ref_p);
758 lto_output_tree_or_ref (ob, BINFO_VTABLE (expr), ref_p);
759 /* BINFO_VIRTUALS is used to drive type based devirtualizatoin. It often links
760 together large portions of programs making it harder to partition. Becuase
761 devirtualization is interesting before inlining, only, there is no real
762 need to ship it into ltrans partition. */
763 lto_output_tree_or_ref (ob, flag_wpa ? NULL : BINFO_VIRTUALS (expr), ref_p);
764 lto_output_tree_or_ref (ob, BINFO_VPTR_FIELD (expr), ref_p);
766 output_uleb128 (ob, VEC_length (tree, BINFO_BASE_ACCESSES (expr)));
767 FOR_EACH_VEC_ELT (tree, BINFO_BASE_ACCESSES (expr), i, t)
768 lto_output_tree_or_ref (ob, t, ref_p);
770 lto_output_tree_or_ref (ob, BINFO_INHERITANCE_CHAIN (expr), ref_p);
771 lto_output_tree_or_ref (ob, BINFO_SUBVTT_INDEX (expr), ref_p);
772 lto_output_tree_or_ref (ob, BINFO_VPTR_INDEX (expr), ref_p);
776 /* Write all pointer fields in the TS_CONSTRUCTOR structure of EXPR to
777 output block OB. If REF_P is true, write a reference to EXPR's
781 lto_output_ts_constructor_tree_pointers (struct output_block *ob, tree expr,
787 output_uleb128 (ob, CONSTRUCTOR_NELTS (expr));
788 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr), i, index, value)
790 lto_output_tree_or_ref (ob, index, ref_p);
791 lto_output_tree_or_ref (ob, value, ref_p);
795 /* Write a TS_TARGET_OPTION tree in EXPR to OB. */
798 lto_output_ts_target_option (struct output_block *ob, tree expr)
800 struct cl_target_option *t = TREE_TARGET_OPTION (expr);
804 /* The cl_target_option is target specific and generated by the options
805 awk script, so we just recreate a byte-by-byte copy here. */
807 bp = bitpack_create (ob->main_stream);
808 len = sizeof (struct cl_target_option);
809 for (i = 0; i < len; i++)
810 bp_pack_value (&bp, ((unsigned char *)t)[i], 8);
811 /* Catch struct size mismatches between reader and writer. */
812 bp_pack_value (&bp, 0x12345678, 32);
813 lto_output_bitpack (&bp);
816 /* Write a TS_TRANSLATION_UNIT_DECL tree in EXPR to OB. */
819 lto_output_ts_translation_unit_decl_tree_pointers (struct output_block *ob,
822 lto_output_string (ob, ob->main_stream,
823 TRANSLATION_UNIT_LANGUAGE (expr), true);
826 /* Helper for lto_output_tree. Write all pointer fields in EXPR to output
827 block OB. If REF_P is true, the leaves of EXPR are emitted as
831 lto_output_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
835 code = TREE_CODE (expr);
837 if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
838 lto_output_ts_common_tree_pointers (ob, expr, ref_p);
840 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
841 lto_output_ts_vector_tree_pointers (ob, expr, ref_p);
843 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
844 lto_output_ts_complex_tree_pointers (ob, expr, ref_p);
846 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
847 lto_output_ts_decl_minimal_tree_pointers (ob, expr, ref_p);
849 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
850 lto_output_ts_decl_common_tree_pointers (ob, expr, ref_p);
852 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
853 lto_output_ts_decl_non_common_tree_pointers (ob, expr, ref_p);
855 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
856 lto_output_ts_decl_with_vis_tree_pointers (ob, expr, ref_p);
858 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
859 lto_output_ts_field_decl_tree_pointers (ob, expr, ref_p);
861 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
862 lto_output_ts_function_decl_tree_pointers (ob, expr, ref_p);
864 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
865 lto_output_ts_type_common_tree_pointers (ob, expr, ref_p);
867 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
868 lto_output_ts_type_non_common_tree_pointers (ob, expr, ref_p);
870 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
871 lto_output_ts_list_tree_pointers (ob, expr, ref_p);
873 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
874 lto_output_ts_vec_tree_pointers (ob, expr, ref_p);
876 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
877 lto_output_ts_exp_tree_pointers (ob, expr, ref_p);
879 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
880 lto_output_ts_block_tree_pointers (ob, expr, ref_p);
882 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
883 lto_output_ts_binfo_tree_pointers (ob, expr, ref_p);
885 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
886 lto_output_ts_constructor_tree_pointers (ob, expr, ref_p);
888 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
889 lto_output_ts_target_option (ob, expr);
891 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
892 lto_output_ts_translation_unit_decl_tree_pointers (ob, expr);
896 /* Emit header information for tree EXPR to output block OB. The header
897 contains everything needed to instantiate an empty skeleton for
898 EXPR on the reading side. IX is the index into the streamer cache
899 where EXPR is stored. REF_P is as in lto_output_tree. */
902 lto_output_tree_header (struct output_block *ob, tree expr)
907 /* We should not see any tree nodes not handled by the streamer. */
908 code = TREE_CODE (expr);
909 if (!streamer_hooks.is_streamable (expr))
910 internal_error ("tree code %qs is not supported in %s streams",
911 tree_code_name[code], streamer_hooks.name);
913 /* The header of a tree node consists of its tag, the size of
914 the node, and any other information needed to instantiate
915 EXPR on the reading side (such as the number of slots in
916 variable sized nodes). */
917 tag = lto_tree_code_to_tag (code);
918 output_record_start (ob, tag);
920 /* The following will cause bootstrap miscomparisons. Enable with care. */
921 #ifdef LTO_STREAMER_DEBUG
922 /* This is used mainly for debugging purposes. When the reader
923 and the writer do not agree on a streamed node, the pointer
924 value for EXPR can be used to track down the differences in
926 gcc_assert ((HOST_WIDEST_INT) (intptr_t) expr == (intptr_t) expr);
927 output_sleb128 (ob, (HOST_WIDEST_INT) (intptr_t) expr);
930 /* The text in strings and identifiers are completely emitted in
932 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
933 output_string_cst (ob, ob->main_stream, expr);
934 else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
935 output_identifier (ob, ob->main_stream, expr);
936 else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
937 output_sleb128 (ob, TREE_VEC_LENGTH (expr));
938 else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
939 output_uleb128 (ob, BINFO_N_BASE_BINFOS (expr));
941 /* Allow the streamer to write any streamer-specific information
942 needed to instantiate the node when reading. */
943 if (streamer_hooks.output_tree_header)
944 streamer_hooks.output_tree_header (ob, expr);
948 /* Emit the integer constant CST to output block OB. If REF_P is true,
949 CST's type will be emitted as a reference. */
952 lto_output_integer_cst (struct output_block *ob, tree cst, bool ref_p)
954 output_record_start (ob, lto_tree_code_to_tag (INTEGER_CST));
955 lto_output_tree_or_ref (ob, TREE_TYPE (cst), ref_p);
956 lto_output_1_stream (ob->main_stream, TREE_OVERFLOW_P (cst));
957 output_uleb128 (ob, TREE_INT_CST_LOW (cst));
958 output_uleb128 (ob, TREE_INT_CST_HIGH (cst));
962 /* Write a physical representation of tree node EXPR to output block
963 OB. If REF_P is true, the leaves of EXPR are emitted as references
964 via lto_output_tree_ref. IX is the index into the streamer cache
965 where EXPR is stored. */
968 lto_write_tree (struct output_block *ob, tree expr, bool ref_p)
972 /* Write the header, containing everything needed to materialize
973 EXPR on the reading side. */
974 lto_output_tree_header (ob, expr);
976 /* Pack all the non-pointer fields in EXPR into a bitpack and write
977 the resulting bitpack. */
978 bp = bitpack_create (ob->main_stream);
979 pack_value_fields (&bp, expr);
980 lto_output_bitpack (&bp);
982 /* Write all the pointer fields in EXPR. */
983 lto_output_tree_pointers (ob, expr, ref_p);
985 /* Call back into the streaming module to see if it needs to write
986 anything that was not written by the common streamer. */
987 if (streamer_hooks.write_tree)
988 streamer_hooks.write_tree (ob, expr, ref_p);
990 /* Mark the end of EXPR. */
995 /* Emit the physical representation of tree node EXPR to output block
996 OB. If REF_P is true, the leaves of EXPR are emitted as references
997 via lto_output_tree_ref. */
1000 lto_output_tree (struct output_block *ob, tree expr, bool ref_p)
1005 if (expr == NULL_TREE)
1007 output_record_start (ob, LTO_null);
1011 /* INTEGER_CST nodes are special because they need their original type
1012 to be materialized by the reader (to implement TYPE_CACHED_VALUES). */
1013 if (TREE_CODE (expr) == INTEGER_CST)
1015 lto_output_integer_cst (ob, expr, ref_p);
1019 existed_p = lto_streamer_cache_insert (ob->writer_cache, expr, &ix);
1022 /* If a node has already been streamed out, make sure that
1023 we don't write it more than once. Otherwise, the reader
1024 will instantiate two different nodes for the same object. */
1025 output_record_start (ob, LTO_tree_pickle_reference);
1026 output_uleb128 (ob, ix);
1027 lto_output_enum (ob->main_stream, LTO_tags, LTO_NUM_TAGS,
1028 lto_tree_code_to_tag (TREE_CODE (expr)));
1030 else if (lto_stream_as_builtin_p (expr))
1032 /* MD and NORMAL builtins do not need to be written out
1033 completely as they are always instantiated by the
1034 compiler on startup. The only builtins that need to
1035 be written out are BUILT_IN_FRONTEND. For all other
1036 builtins, we simply write the class and code. */
1037 lto_output_builtin_tree (ob, expr);
1041 /* This is the first time we see EXPR, write its fields
1043 lto_write_tree (ob, expr, ref_p);