]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/tree-streamer-out.c
Add TREE_INT_CST_OFFSET_NUNITS.
[thirdparty/gcc.git] / gcc / tree-streamer-out.c
1 /* Routines for emitting trees to a file stream.
2
3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@google.com>
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "diagnostic.h"
27 #include "tree.h"
28 #include "stor-layout.h"
29 #include "gimple.h"
30 #include "tree-streamer.h"
31 #include "data-streamer.h"
32 #include "streamer-hooks.h"
33
34 /* Output the STRING constant to the string
35 table in OB. Then put the index onto the INDEX_STREAM. */
36
37 void
38 streamer_write_string_cst (struct output_block *ob,
39 struct lto_output_stream *index_stream,
40 tree string)
41 {
42 streamer_write_string_with_length (ob, index_stream,
43 string ? TREE_STRING_POINTER (string)
44 : NULL,
45 string ? TREE_STRING_LENGTH (string) : 0,
46 true);
47 }
48
49
50 /* Output the identifier ID to the string
51 table in OB. Then put the index onto the INDEX_STREAM. */
52
53 static void
54 write_identifier (struct output_block *ob,
55 struct lto_output_stream *index_stream,
56 tree id)
57 {
58 streamer_write_string_with_length (ob, index_stream,
59 IDENTIFIER_POINTER (id),
60 IDENTIFIER_LENGTH (id),
61 true);
62 }
63
64
65 /* Pack all the non-pointer fields of the TS_BASE structure of
66 expression EXPR into bitpack BP. */
67
68 static void
69 pack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
70 {
71 bp_pack_value (bp, TREE_CODE (expr), 16);
72 if (!TYPE_P (expr))
73 {
74 bp_pack_value (bp, TREE_SIDE_EFFECTS (expr), 1);
75 bp_pack_value (bp, TREE_CONSTANT (expr), 1);
76 bp_pack_value (bp, TREE_READONLY (expr), 1);
77
78 /* TREE_PUBLIC is used on types to indicate that the type
79 has a TYPE_CACHED_VALUES vector. This is not streamed out,
80 so we skip it here. */
81 bp_pack_value (bp, TREE_PUBLIC (expr), 1);
82 }
83 else
84 bp_pack_value (bp, 0, 4);
85 bp_pack_value (bp, TREE_ADDRESSABLE (expr), 1);
86 bp_pack_value (bp, TREE_THIS_VOLATILE (expr), 1);
87 if (DECL_P (expr))
88 bp_pack_value (bp, DECL_UNSIGNED (expr), 1);
89 else if (TYPE_P (expr))
90 bp_pack_value (bp, TYPE_UNSIGNED (expr), 1);
91 else
92 bp_pack_value (bp, 0, 1);
93 /* We write debug info two times, do not confuse the second one.
94 The only relevant TREE_ASM_WRITTEN use is on SSA names. */
95 bp_pack_value (bp, (TREE_CODE (expr) != SSA_NAME
96 ? 0 : TREE_ASM_WRITTEN (expr)), 1);
97 if (TYPE_P (expr))
98 bp_pack_value (bp, TYPE_ARTIFICIAL (expr), 1);
99 else
100 bp_pack_value (bp, TREE_NO_WARNING (expr), 1);
101 bp_pack_value (bp, TREE_NOTHROW (expr), 1);
102 bp_pack_value (bp, TREE_STATIC (expr), 1);
103 if (TREE_CODE (expr) != TREE_BINFO)
104 bp_pack_value (bp, TREE_PRIVATE (expr), 1);
105 bp_pack_value (bp, TREE_PROTECTED (expr), 1);
106 bp_pack_value (bp, TREE_DEPRECATED (expr), 1);
107 if (TYPE_P (expr))
108 {
109 bp_pack_value (bp, TYPE_SATURATING (expr), 1);
110 bp_pack_value (bp, TYPE_ADDR_SPACE (expr), 8);
111 }
112 else if (TREE_CODE (expr) == SSA_NAME)
113 bp_pack_value (bp, SSA_NAME_IS_DEFAULT_DEF (expr), 1);
114 else
115 bp_pack_value (bp, 0, 1);
116 }
117
118
119 /* Pack all the non-pointer fields of the TS_INTEGER_CST structure of
120 expression EXPR into bitpack BP. */
121
122 static void
123 pack_ts_int_cst_value_fields (struct bitpack_d *bp, tree expr)
124 {
125 int i;
126 /* Note that the number of elements has already been written out in
127 streamer_write_tree_header. */
128 for (i = 0; i < TREE_INT_CST_EXT_NUNITS (expr); i++)
129 bp_pack_var_len_int (bp, TREE_INT_CST_ELT (expr, i));
130 }
131
132
133 /* Pack all the non-pointer fields of the TS_REAL_CST structure of
134 expression EXPR into bitpack BP. */
135
136 static void
137 pack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
138 {
139 unsigned i;
140 REAL_VALUE_TYPE r;
141
142 r = TREE_REAL_CST (expr);
143 bp_pack_value (bp, r.cl, 2);
144 bp_pack_value (bp, r.decimal, 1);
145 bp_pack_value (bp, r.sign, 1);
146 bp_pack_value (bp, r.signalling, 1);
147 bp_pack_value (bp, r.canonical, 1);
148 bp_pack_value (bp, r.uexp, EXP_BITS);
149 for (i = 0; i < SIGSZ; i++)
150 bp_pack_value (bp, r.sig[i], HOST_BITS_PER_LONG);
151 }
152
153
154 /* Pack all the non-pointer fields of the TS_FIXED_CST structure of
155 expression EXPR into bitpack BP. */
156
157 static void
158 pack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
159 {
160 struct fixed_value fv = TREE_FIXED_CST (expr);
161 bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, fv.mode);
162 bp_pack_var_len_int (bp, fv.data.low);
163 bp_pack_var_len_int (bp, fv.data.high);
164 }
165
166 /* Pack all the non-pointer fields of the TS_DECL_COMMON structure
167 of expression EXPR into bitpack BP. */
168
169 static void
170 pack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
171 {
172 bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, DECL_MODE (expr));
173 bp_pack_value (bp, DECL_NONLOCAL (expr), 1);
174 bp_pack_value (bp, DECL_VIRTUAL_P (expr), 1);
175 bp_pack_value (bp, DECL_IGNORED_P (expr), 1);
176 bp_pack_value (bp, DECL_ABSTRACT (expr), 1);
177 bp_pack_value (bp, DECL_ARTIFICIAL (expr), 1);
178 bp_pack_value (bp, DECL_USER_ALIGN (expr), 1);
179 bp_pack_value (bp, DECL_PRESERVE_P (expr), 1);
180 bp_pack_value (bp, DECL_EXTERNAL (expr), 1);
181 bp_pack_value (bp, DECL_GIMPLE_REG_P (expr), 1);
182 bp_pack_var_len_unsigned (bp, DECL_ALIGN (expr));
183
184 if (TREE_CODE (expr) == LABEL_DECL)
185 {
186 /* Note that we do not write LABEL_DECL_UID. The reader will
187 always assume an initial value of -1 so that the
188 label_to_block_map is recreated by gimple_set_bb. */
189 bp_pack_var_len_unsigned (bp, EH_LANDING_PAD_NR (expr));
190 }
191
192 if (TREE_CODE (expr) == FIELD_DECL)
193 {
194 bp_pack_value (bp, DECL_PACKED (expr), 1);
195 bp_pack_value (bp, DECL_NONADDRESSABLE_P (expr), 1);
196 bp_pack_value (bp, expr->decl_common.off_align, 8);
197 }
198
199 if (TREE_CODE (expr) == VAR_DECL)
200 {
201 bp_pack_value (bp, DECL_HAS_DEBUG_EXPR_P (expr), 1);
202 bp_pack_value (bp, DECL_NONLOCAL_FRAME (expr), 1);
203 }
204
205 if (TREE_CODE (expr) == RESULT_DECL
206 || TREE_CODE (expr) == PARM_DECL
207 || TREE_CODE (expr) == VAR_DECL)
208 {
209 bp_pack_value (bp, DECL_BY_REFERENCE (expr), 1);
210 if (TREE_CODE (expr) == VAR_DECL
211 || TREE_CODE (expr) == PARM_DECL)
212 bp_pack_value (bp, DECL_HAS_VALUE_EXPR_P (expr), 1);
213 }
214 }
215
216
217 /* Pack all the non-pointer fields of the TS_DECL_WRTL structure
218 of expression EXPR into bitpack BP. */
219
220 static void
221 pack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
222 {
223 bp_pack_value (bp, DECL_REGISTER (expr), 1);
224 }
225
226
227 /* Pack all the non-pointer fields of the TS_DECL_WITH_VIS structure
228 of expression EXPR into bitpack BP. */
229
230 static void
231 pack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
232 {
233 bp_pack_value (bp, DECL_COMMON (expr), 1);
234 bp_pack_value (bp, DECL_DLLIMPORT_P (expr), 1);
235 bp_pack_value (bp, DECL_WEAK (expr), 1);
236 bp_pack_value (bp, DECL_SEEN_IN_BIND_EXPR_P (expr), 1);
237 bp_pack_value (bp, DECL_COMDAT (expr), 1);
238 bp_pack_value (bp, DECL_VISIBILITY (expr), 2);
239 bp_pack_value (bp, DECL_VISIBILITY_SPECIFIED (expr), 1);
240
241 if (TREE_CODE (expr) == VAR_DECL)
242 {
243 bp_pack_value (bp, DECL_HARD_REGISTER (expr), 1);
244 /* DECL_IN_TEXT_SECTION is set during final asm output only. */
245 bp_pack_value (bp, DECL_IN_CONSTANT_POOL (expr), 1);
246 bp_pack_value (bp, DECL_TLS_MODEL (expr), 3);
247 }
248
249 if (TREE_CODE (expr) == FUNCTION_DECL)
250 {
251 bp_pack_value (bp, DECL_FINAL_P (expr), 1);
252 bp_pack_value (bp, DECL_CXX_CONSTRUCTOR_P (expr), 1);
253 bp_pack_value (bp, DECL_CXX_DESTRUCTOR_P (expr), 1);
254 }
255 if (VAR_OR_FUNCTION_DECL_P (expr))
256 bp_pack_var_len_unsigned (bp, DECL_INIT_PRIORITY (expr));
257 }
258
259
260 /* Pack all the non-pointer fields of the TS_FUNCTION_DECL structure
261 of expression EXPR into bitpack BP. */
262
263 static void
264 pack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
265 {
266 /* For normal/md builtins we only write the class and code, so they
267 should never be handled here. */
268 gcc_assert (!streamer_handle_as_builtin_p (expr));
269
270 bp_pack_enum (bp, built_in_class, BUILT_IN_LAST,
271 DECL_BUILT_IN_CLASS (expr));
272 bp_pack_value (bp, DECL_STATIC_CONSTRUCTOR (expr), 1);
273 bp_pack_value (bp, DECL_STATIC_DESTRUCTOR (expr), 1);
274 bp_pack_value (bp, DECL_UNINLINABLE (expr), 1);
275 bp_pack_value (bp, DECL_POSSIBLY_INLINED (expr), 1);
276 bp_pack_value (bp, DECL_IS_NOVOPS (expr), 1);
277 bp_pack_value (bp, DECL_IS_RETURNS_TWICE (expr), 1);
278 bp_pack_value (bp, DECL_IS_MALLOC (expr), 1);
279 bp_pack_value (bp, DECL_IS_OPERATOR_NEW (expr), 1);
280 bp_pack_value (bp, DECL_DECLARED_INLINE_P (expr), 1);
281 bp_pack_value (bp, DECL_STATIC_CHAIN (expr), 1);
282 bp_pack_value (bp, DECL_NO_INLINE_WARNING_P (expr), 1);
283 bp_pack_value (bp, DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr), 1);
284 bp_pack_value (bp, DECL_NO_LIMIT_STACK (expr), 1);
285 bp_pack_value (bp, DECL_DISREGARD_INLINE_LIMITS (expr), 1);
286 bp_pack_value (bp, DECL_PURE_P (expr), 1);
287 bp_pack_value (bp, DECL_LOOPING_CONST_OR_PURE_P (expr), 1);
288 if (DECL_BUILT_IN_CLASS (expr) != NOT_BUILT_IN)
289 bp_pack_value (bp, DECL_FUNCTION_CODE (expr), 11);
290 if (DECL_STATIC_DESTRUCTOR (expr))
291 bp_pack_var_len_unsigned (bp, DECL_FINI_PRIORITY (expr));
292 }
293
294
295 /* Pack all the non-pointer fields of the TS_TYPE_COMMON structure
296 of expression EXPR into bitpack BP. */
297
298 static void
299 pack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
300 {
301 bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, TYPE_MODE (expr));
302 bp_pack_value (bp, TYPE_STRING_FLAG (expr), 1);
303 bp_pack_value (bp, TYPE_NO_FORCE_BLK (expr), 1);
304 bp_pack_value (bp, TYPE_NEEDS_CONSTRUCTING (expr), 1);
305 if (RECORD_OR_UNION_TYPE_P (expr))
306 {
307 bp_pack_value (bp, TYPE_TRANSPARENT_AGGR (expr), 1);
308 bp_pack_value (bp, TYPE_FINAL_P (expr), 1);
309 }
310 else if (TREE_CODE (expr) == ARRAY_TYPE)
311 bp_pack_value (bp, TYPE_NONALIASED_COMPONENT (expr), 1);
312 bp_pack_value (bp, TYPE_PACKED (expr), 1);
313 bp_pack_value (bp, TYPE_RESTRICT (expr), 1);
314 bp_pack_value (bp, TYPE_USER_ALIGN (expr), 1);
315 bp_pack_value (bp, TYPE_READONLY (expr), 1);
316 bp_pack_var_len_unsigned (bp, TYPE_PRECISION (expr));
317 bp_pack_var_len_unsigned (bp, TYPE_ALIGN (expr));
318 /* Make sure to preserve the fact whether the frontend would assign
319 alias-set zero to this type. */
320 bp_pack_var_len_int (bp, (TYPE_ALIAS_SET (expr) == 0
321 || (!in_lto_p
322 && get_alias_set (expr) == 0)) ? 0 : -1);
323 }
324
325
326 /* Pack all the non-pointer fields of the TS_BLOCK structure
327 of expression EXPR into bitpack BP. */
328
329 static void
330 pack_ts_block_value_fields (struct output_block *ob,
331 struct bitpack_d *bp, tree expr)
332 {
333 bp_pack_value (bp, BLOCK_ABSTRACT (expr), 1);
334 /* BLOCK_NUMBER is recomputed. */
335 /* Stream BLOCK_SOURCE_LOCATION for the limited cases we can handle - those
336 that represent inlined function scopes.
337 For the rest them on the floor instead of ICEing in dwarf2out.c. */
338 if (inlined_function_outer_scope_p (expr))
339 stream_output_location (ob, bp, BLOCK_SOURCE_LOCATION (expr));
340 else
341 stream_output_location (ob, bp, UNKNOWN_LOCATION);
342 }
343
344 /* Pack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL structure
345 of expression EXPR into bitpack BP. */
346
347 static void
348 pack_ts_translation_unit_decl_value_fields (struct output_block *ob,
349 struct bitpack_d *bp, tree expr)
350 {
351 bp_pack_string (ob, bp, TRANSLATION_UNIT_LANGUAGE (expr), true);
352 }
353
354 /* Pack a TS_TARGET_OPTION tree in EXPR to BP. */
355
356 static void
357 pack_ts_target_option (struct bitpack_d *bp, tree expr)
358 {
359 struct cl_target_option *t = TREE_TARGET_OPTION (expr);
360 unsigned i, len;
361
362 /* The cl_target_option is target specific and generated by the options
363 awk script, so we just recreate a byte-by-byte copy here. */
364
365 len = sizeof (struct cl_target_option);
366 for (i = 0; i < len; i++)
367 bp_pack_value (bp, ((unsigned char *)t)[i], 8);
368 /* Catch struct size mismatches between reader and writer. */
369 bp_pack_value (bp, 0x12345678, 32);
370 }
371
372 /* Pack a TS_OPTIMIZATION tree in EXPR to BP. */
373
374 static void
375 pack_ts_optimization (struct bitpack_d *bp, tree expr)
376 {
377 struct cl_optimization *t = TREE_OPTIMIZATION (expr);
378 unsigned i, len;
379
380 /* The cl_optimization is generated by the options
381 awk script, so we just recreate a byte-by-byte copy here. */
382
383 len = sizeof (struct cl_optimization);
384 for (i = 0; i < len; i++)
385 bp_pack_value (bp, ((unsigned char *)t)[i], 8);
386 /* Catch struct size mismatches between reader and writer. */
387 bp_pack_value (bp, 0x12345678, 32);
388 }
389
390
391 /* Pack all the bitfields in EXPR into a bit pack. */
392
393 void
394 streamer_pack_tree_bitfields (struct output_block *ob,
395 struct bitpack_d *bp, tree expr)
396 {
397 enum tree_code code;
398
399 code = TREE_CODE (expr);
400
401 /* Note that all these functions are highly sensitive to changes in
402 the types and sizes of each of the fields being packed. */
403 pack_ts_base_value_fields (bp, expr);
404
405 if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
406 pack_ts_int_cst_value_fields (bp, expr);
407
408 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
409 pack_ts_real_cst_value_fields (bp, expr);
410
411 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
412 pack_ts_fixed_cst_value_fields (bp, expr);
413
414 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
415 stream_output_location (ob, bp, DECL_SOURCE_LOCATION (expr));
416
417 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
418 pack_ts_decl_common_value_fields (bp, expr);
419
420 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
421 pack_ts_decl_wrtl_value_fields (bp, expr);
422
423 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
424 pack_ts_decl_with_vis_value_fields (bp, expr);
425
426 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
427 pack_ts_function_decl_value_fields (bp, expr);
428
429 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
430 pack_ts_type_common_value_fields (bp, expr);
431
432 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
433 stream_output_location (ob, bp, EXPR_LOCATION (expr));
434
435 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
436 pack_ts_block_value_fields (ob, bp, expr);
437
438 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
439 pack_ts_translation_unit_decl_value_fields (ob, bp, expr);
440
441 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
442 pack_ts_target_option (bp, expr);
443
444 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
445 pack_ts_optimization (bp, expr);
446
447 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
448 bp_pack_var_len_unsigned (bp, vec_safe_length (BINFO_BASE_ACCESSES (expr)));
449
450 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
451 bp_pack_var_len_unsigned (bp, CONSTRUCTOR_NELTS (expr));
452 }
453
454
455 /* Write the code and class of builtin EXPR to output block OB. IX is
456 the index into the streamer cache where EXPR is stored.*/
457
458 void
459 streamer_write_builtin (struct output_block *ob, tree expr)
460 {
461 gcc_assert (streamer_handle_as_builtin_p (expr));
462
463 if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
464 && !targetm.builtin_decl)
465 sorry ("tree bytecode streams do not support machine specific builtin "
466 "functions on this target");
467
468 streamer_write_record_start (ob, LTO_builtin_decl);
469 streamer_write_enum (ob->main_stream, built_in_class, BUILT_IN_LAST,
470 DECL_BUILT_IN_CLASS (expr));
471 streamer_write_uhwi (ob, DECL_FUNCTION_CODE (expr));
472
473 if (DECL_ASSEMBLER_NAME_SET_P (expr))
474 {
475 /* When the assembler name of a builtin gets a user name,
476 the new name is always prefixed with '*' by
477 set_builtin_user_assembler_name. So, to prevent the
478 reader side from adding a second '*', we omit it here. */
479 const char *str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr));
480 if (strlen (str) > 1 && str[0] == '*')
481 streamer_write_string (ob, ob->main_stream, &str[1], true);
482 else
483 streamer_write_string (ob, ob->main_stream, NULL, true);
484 }
485 else
486 streamer_write_string (ob, ob->main_stream, NULL, true);
487 }
488
489
490 /* Emit the chain of tree nodes starting at T. OB is the output block
491 to write to. REF_P is true if chain elements should be emitted
492 as references. */
493
494 void
495 streamer_write_chain (struct output_block *ob, tree t, bool ref_p)
496 {
497 while (t)
498 {
499 tree saved_chain;
500
501 /* Clear TREE_CHAIN to avoid blindly recursing into the rest
502 of the list. */
503 saved_chain = TREE_CHAIN (t);
504 TREE_CHAIN (t) = NULL_TREE;
505
506 /* We avoid outputting external vars or functions by reference
507 to the global decls section as we do not want to have them
508 enter decl merging. This is, of course, only for the call
509 for streaming BLOCK_VARS, but other callers are safe. */
510 /* ??? FIXME wrt SCC streaming. Drop these for now. */
511 if (VAR_OR_FUNCTION_DECL_P (t)
512 && DECL_EXTERNAL (t))
513 ; /* stream_write_tree_shallow_non_ref (ob, t, ref_p); */
514 else
515 stream_write_tree (ob, t, ref_p);
516
517 TREE_CHAIN (t) = saved_chain;
518 t = TREE_CHAIN (t);
519 }
520
521 /* Write a sentinel to terminate the chain. */
522 stream_write_tree (ob, NULL_TREE, ref_p);
523 }
524
525
526 /* Write all pointer fields in the TS_COMMON structure of EXPR to output
527 block OB. If REF_P is true, write a reference to EXPR's pointer
528 fields. */
529
530 static void
531 write_ts_common_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
532 {
533 if (TREE_CODE (expr) != IDENTIFIER_NODE)
534 stream_write_tree (ob, TREE_TYPE (expr), ref_p);
535 }
536
537
538 /* Write all pointer fields in the TS_VECTOR structure of EXPR to output
539 block OB. If REF_P is true, write a reference to EXPR's pointer
540 fields. */
541
542 static void
543 write_ts_vector_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
544 {
545 unsigned i;
546 /* Note that the number of elements for EXPR has already been emitted
547 in EXPR's header (see streamer_write_tree_header). */
548 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
549 stream_write_tree (ob, VECTOR_CST_ELT (expr, i), ref_p);
550 }
551
552
553 /* Write all pointer fields in the TS_COMPLEX structure of EXPR to output
554 block OB. If REF_P is true, write a reference to EXPR's pointer
555 fields. */
556
557 static void
558 write_ts_complex_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
559 {
560 stream_write_tree (ob, TREE_REALPART (expr), ref_p);
561 stream_write_tree (ob, TREE_IMAGPART (expr), ref_p);
562 }
563
564
565 /* Write all pointer fields in the TS_DECL_MINIMAL structure of EXPR
566 to output block OB. If REF_P is true, write a reference to EXPR's
567 pointer fields. */
568
569 static void
570 write_ts_decl_minimal_tree_pointers (struct output_block *ob, tree expr,
571 bool ref_p)
572 {
573 /* Drop names that were created for anonymous entities. */
574 if (DECL_NAME (expr)
575 && TREE_CODE (DECL_NAME (expr)) == IDENTIFIER_NODE
576 && ANON_AGGRNAME_P (DECL_NAME (expr)))
577 stream_write_tree (ob, NULL_TREE, ref_p);
578 else
579 stream_write_tree (ob, DECL_NAME (expr), ref_p);
580 stream_write_tree (ob, DECL_CONTEXT (expr), ref_p);
581 }
582
583
584 /* Write all pointer fields in the TS_DECL_COMMON structure of EXPR to
585 output block OB. If REF_P is true, write a reference to EXPR's
586 pointer fields. */
587
588 static void
589 write_ts_decl_common_tree_pointers (struct output_block *ob, tree expr,
590 bool ref_p)
591 {
592 stream_write_tree (ob, DECL_SIZE (expr), ref_p);
593 stream_write_tree (ob, DECL_SIZE_UNIT (expr), ref_p);
594
595 /* Note, DECL_INITIAL is not handled here. Since DECL_INITIAL needs
596 special handling in LTO, it must be handled by streamer hooks. */
597
598 stream_write_tree (ob, DECL_ATTRIBUTES (expr), ref_p);
599
600 /* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
601 for early inlining so drop it on the floor instead of ICEing in
602 dwarf2out.c. */
603
604 if ((TREE_CODE (expr) == VAR_DECL
605 || TREE_CODE (expr) == PARM_DECL)
606 && DECL_HAS_VALUE_EXPR_P (expr))
607 stream_write_tree (ob, DECL_VALUE_EXPR (expr), ref_p);
608
609 if (TREE_CODE (expr) == VAR_DECL)
610 stream_write_tree (ob, DECL_DEBUG_EXPR (expr), ref_p);
611 }
612
613
614 /* Write all pointer fields in the TS_DECL_NON_COMMON structure of
615 EXPR to output block OB. If REF_P is true, write a reference to EXPR's
616 pointer fields. */
617
618 static void
619 write_ts_decl_non_common_tree_pointers (struct output_block *ob, tree expr,
620 bool ref_p)
621 {
622 if (TREE_CODE (expr) == TYPE_DECL)
623 stream_write_tree (ob, DECL_ORIGINAL_TYPE (expr), ref_p);
624 stream_write_tree (ob, DECL_VINDEX (expr), ref_p);
625 }
626
627
628 /* Write all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
629 to output block OB. If REF_P is true, write a reference to EXPR's
630 pointer fields. */
631
632 static void
633 write_ts_decl_with_vis_tree_pointers (struct output_block *ob, tree expr,
634 bool ref_p)
635 {
636 /* Make sure we don't inadvertently set the assembler name. */
637 if (DECL_ASSEMBLER_NAME_SET_P (expr))
638 stream_write_tree (ob, DECL_ASSEMBLER_NAME (expr), ref_p);
639 else
640 stream_write_tree (ob, NULL_TREE, false);
641
642 stream_write_tree (ob, DECL_SECTION_NAME (expr), ref_p);
643 stream_write_tree (ob, DECL_COMDAT_GROUP (expr), ref_p);
644 }
645
646
647 /* Write all pointer fields in the TS_FIELD_DECL structure of EXPR to
648 output block OB. If REF_P is true, write a reference to EXPR's
649 pointer fields. */
650
651 static void
652 write_ts_field_decl_tree_pointers (struct output_block *ob, tree expr,
653 bool ref_p)
654 {
655 stream_write_tree (ob, DECL_FIELD_OFFSET (expr), ref_p);
656 stream_write_tree (ob, DECL_BIT_FIELD_TYPE (expr), ref_p);
657 stream_write_tree (ob, DECL_BIT_FIELD_REPRESENTATIVE (expr), ref_p);
658 stream_write_tree (ob, DECL_FIELD_BIT_OFFSET (expr), ref_p);
659 stream_write_tree (ob, DECL_FCONTEXT (expr), ref_p);
660 }
661
662
663 /* Write all pointer fields in the TS_FUNCTION_DECL structure of EXPR
664 to output block OB. If REF_P is true, write a reference to EXPR's
665 pointer fields. */
666
667 static void
668 write_ts_function_decl_tree_pointers (struct output_block *ob, tree expr,
669 bool ref_p)
670 {
671 /* DECL_STRUCT_FUNCTION is handled by lto_output_function. FIXME lto,
672 maybe it should be handled here? */
673 stream_write_tree (ob, DECL_FUNCTION_PERSONALITY (expr), ref_p);
674 stream_write_tree (ob, DECL_FUNCTION_SPECIFIC_TARGET (expr), ref_p);
675 stream_write_tree (ob, DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr), ref_p);
676 }
677
678
679 /* Write all pointer fields in the TS_TYPE_COMMON structure of EXPR to
680 output block OB. If REF_P is true, write a reference to EXPR's
681 pointer fields. */
682
683 static void
684 write_ts_type_common_tree_pointers (struct output_block *ob, tree expr,
685 bool ref_p)
686 {
687 stream_write_tree (ob, TYPE_SIZE (expr), ref_p);
688 stream_write_tree (ob, TYPE_SIZE_UNIT (expr), ref_p);
689 stream_write_tree (ob, TYPE_ATTRIBUTES (expr), ref_p);
690 stream_write_tree (ob, TYPE_NAME (expr), ref_p);
691 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO. They will be
692 reconstructed during fixup. */
693 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
694 during fixup. */
695 stream_write_tree (ob, TYPE_MAIN_VARIANT (expr), ref_p);
696 stream_write_tree (ob, TYPE_CONTEXT (expr), ref_p);
697 /* TYPE_CANONICAL is re-computed during type merging, so no need
698 to stream it here. */
699 stream_write_tree (ob, TYPE_STUB_DECL (expr), ref_p);
700 }
701
702 /* Write all pointer fields in the TS_TYPE_NON_COMMON structure of EXPR
703 to output block OB. If REF_P is true, write a reference to EXPR's
704 pointer fields. */
705
706 static void
707 write_ts_type_non_common_tree_pointers (struct output_block *ob, tree expr,
708 bool ref_p)
709 {
710 if (TREE_CODE (expr) == ENUMERAL_TYPE)
711 stream_write_tree (ob, TYPE_VALUES (expr), ref_p);
712 else if (TREE_CODE (expr) == ARRAY_TYPE)
713 stream_write_tree (ob, TYPE_DOMAIN (expr), ref_p);
714 else if (RECORD_OR_UNION_TYPE_P (expr))
715 streamer_write_chain (ob, TYPE_FIELDS (expr), ref_p);
716 else if (TREE_CODE (expr) == FUNCTION_TYPE
717 || TREE_CODE (expr) == METHOD_TYPE)
718 stream_write_tree (ob, TYPE_ARG_TYPES (expr), ref_p);
719
720 if (!POINTER_TYPE_P (expr))
721 stream_write_tree (ob, TYPE_MINVAL (expr), ref_p);
722 stream_write_tree (ob, TYPE_MAXVAL (expr), ref_p);
723 if (RECORD_OR_UNION_TYPE_P (expr))
724 stream_write_tree (ob, TYPE_BINFO (expr), ref_p);
725 }
726
727
728 /* Write all pointer fields in the TS_LIST structure of EXPR to output
729 block OB. If REF_P is true, write a reference to EXPR's pointer
730 fields. */
731
732 static void
733 write_ts_list_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
734 {
735 stream_write_tree (ob, TREE_PURPOSE (expr), ref_p);
736 stream_write_tree (ob, TREE_VALUE (expr), ref_p);
737 stream_write_tree (ob, TREE_CHAIN (expr), ref_p);
738 }
739
740
741 /* Write all pointer fields in the TS_VEC structure of EXPR to output
742 block OB. If REF_P is true, write a reference to EXPR's pointer
743 fields. */
744
745 static void
746 write_ts_vec_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
747 {
748 int i;
749
750 /* Note that the number of slots for EXPR has already been emitted
751 in EXPR's header (see streamer_write_tree_header). */
752 for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
753 stream_write_tree (ob, TREE_VEC_ELT (expr, i), ref_p);
754 }
755
756
757 /* Write all pointer fields in the TS_EXP structure of EXPR to output
758 block OB. If REF_P is true, write a reference to EXPR's pointer
759 fields. */
760
761 static void
762 write_ts_exp_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
763 {
764 int i;
765
766 for (i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
767 stream_write_tree (ob, TREE_OPERAND (expr, i), ref_p);
768 stream_write_tree (ob, TREE_BLOCK (expr), ref_p);
769 }
770
771
772 /* Write all pointer fields in the TS_BLOCK structure of EXPR to output
773 block OB. If REF_P is true, write a reference to EXPR's pointer
774 fields. */
775
776 static void
777 write_ts_block_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
778 {
779 streamer_write_chain (ob, BLOCK_VARS (expr), ref_p);
780
781 stream_write_tree (ob, BLOCK_SUPERCONTEXT (expr), ref_p);
782
783 /* Stream BLOCK_ABSTRACT_ORIGIN for the limited cases we can handle - those
784 that represent inlined function scopes.
785 For the rest them on the floor instead of ICEing in dwarf2out.c. */
786 if (inlined_function_outer_scope_p (expr))
787 {
788 tree ultimate_origin = block_ultimate_origin (expr);
789 stream_write_tree (ob, ultimate_origin, ref_p);
790 }
791 else
792 stream_write_tree (ob, NULL_TREE, ref_p);
793 /* Do not stream BLOCK_NONLOCALIZED_VARS. We cannot handle debug information
794 for early inlined BLOCKs so drop it on the floor instead of ICEing in
795 dwarf2out.c. */
796
797 /* BLOCK_FRAGMENT_ORIGIN and BLOCK_FRAGMENT_CHAIN is not live at LTO
798 streaming time. */
799
800 /* Do not output BLOCK_SUBBLOCKS. Instead on streaming-in this
801 list is re-constructed from BLOCK_SUPERCONTEXT. */
802 }
803
804
805 /* Write all pointer fields in the TS_BINFO structure of EXPR to output
806 block OB. If REF_P is true, write a reference to EXPR's pointer
807 fields. */
808
809 static void
810 write_ts_binfo_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
811 {
812 unsigned i;
813 tree t;
814
815 /* Note that the number of BINFO slots has already been emitted in
816 EXPR's header (see streamer_write_tree_header) because this length
817 is needed to build the empty BINFO node on the reader side. */
818 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr), i, t)
819 stream_write_tree (ob, t, ref_p);
820 stream_write_tree (ob, NULL_TREE, false);
821
822 stream_write_tree (ob, BINFO_OFFSET (expr), ref_p);
823 stream_write_tree (ob, BINFO_VTABLE (expr), ref_p);
824 stream_write_tree (ob, BINFO_VPTR_FIELD (expr), ref_p);
825
826 /* The number of BINFO_BASE_ACCESSES has already been emitted in
827 EXPR's bitfield section. */
828 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_ACCESSES (expr), i, t)
829 stream_write_tree (ob, t, ref_p);
830
831 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
832 and BINFO_VPTR_INDEX; these are used by C++ FE only. */
833 }
834
835
836 /* Write all pointer fields in the TS_CONSTRUCTOR structure of EXPR to
837 output block OB. If REF_P is true, write a reference to EXPR's
838 pointer fields. */
839
840 static void
841 write_ts_constructor_tree_pointers (struct output_block *ob, tree expr,
842 bool ref_p)
843 {
844 unsigned i;
845 tree index, value;
846
847 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr), i, index, value)
848 {
849 stream_write_tree (ob, index, ref_p);
850 stream_write_tree (ob, value, ref_p);
851 }
852 }
853
854 /* Write all pointer fields in EXPR to output block OB. If REF_P is true,
855 the leaves of EXPR are emitted as references. */
856
857 void
858 streamer_write_tree_body (struct output_block *ob, tree expr, bool ref_p)
859 {
860 enum tree_code code;
861
862 lto_stats.num_tree_bodies_output++;
863
864 code = TREE_CODE (expr);
865
866 if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
867 write_ts_common_tree_pointers (ob, expr, ref_p);
868
869 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
870 write_ts_vector_tree_pointers (ob, expr, ref_p);
871
872 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
873 write_ts_complex_tree_pointers (ob, expr, ref_p);
874
875 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
876 write_ts_decl_minimal_tree_pointers (ob, expr, ref_p);
877
878 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
879 write_ts_decl_common_tree_pointers (ob, expr, ref_p);
880
881 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
882 write_ts_decl_non_common_tree_pointers (ob, expr, ref_p);
883
884 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
885 write_ts_decl_with_vis_tree_pointers (ob, expr, ref_p);
886
887 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
888 write_ts_field_decl_tree_pointers (ob, expr, ref_p);
889
890 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
891 write_ts_function_decl_tree_pointers (ob, expr, ref_p);
892
893 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
894 write_ts_type_common_tree_pointers (ob, expr, ref_p);
895
896 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
897 write_ts_type_non_common_tree_pointers (ob, expr, ref_p);
898
899 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
900 write_ts_list_tree_pointers (ob, expr, ref_p);
901
902 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
903 write_ts_vec_tree_pointers (ob, expr, ref_p);
904
905 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
906 write_ts_exp_tree_pointers (ob, expr, ref_p);
907
908 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
909 write_ts_block_tree_pointers (ob, expr, ref_p);
910
911 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
912 write_ts_binfo_tree_pointers (ob, expr, ref_p);
913
914 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
915 write_ts_constructor_tree_pointers (ob, expr, ref_p);
916 }
917
918
919 /* Emit header information for tree EXPR to output block OB. The header
920 contains everything needed to instantiate an empty skeleton for
921 EXPR on the reading side. IX is the index into the streamer cache
922 where EXPR is stored. */
923
924 void
925 streamer_write_tree_header (struct output_block *ob, tree expr)
926 {
927 enum LTO_tags tag;
928 enum tree_code code;
929
930 /* We should not see any tree nodes not handled by the streamer. */
931 code = TREE_CODE (expr);
932
933 /* The header of a tree node consists of its tag, the size of
934 the node, and any other information needed to instantiate
935 EXPR on the reading side (such as the number of slots in
936 variable sized nodes). */
937 tag = lto_tree_code_to_tag (code);
938 streamer_write_record_start (ob, tag);
939
940 /* The following will cause bootstrap miscomparisons. Enable with care. */
941 #ifdef LTO_STREAMER_DEBUG
942 /* This is used mainly for debugging purposes. When the reader
943 and the writer do not agree on a streamed node, the pointer
944 value for EXPR can be used to track down the differences in
945 the debugger. */
946 gcc_assert ((HOST_WIDEST_INT) (intptr_t) expr == (intptr_t) expr);
947 streamer_write_hwi (ob, (HOST_WIDEST_INT) (intptr_t) expr);
948 #endif
949
950 /* The text in strings and identifiers are completely emitted in
951 the header. */
952 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
953 streamer_write_string_cst (ob, ob->main_stream, expr);
954 else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
955 write_identifier (ob, ob->main_stream, expr);
956 else if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
957 streamer_write_hwi (ob, VECTOR_CST_NELTS (expr));
958 else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
959 streamer_write_hwi (ob, TREE_VEC_LENGTH (expr));
960 else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
961 streamer_write_uhwi (ob, BINFO_N_BASE_BINFOS (expr));
962 else if (TREE_CODE (expr) == CALL_EXPR)
963 streamer_write_uhwi (ob, call_expr_nargs (expr));
964 else if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
965 {
966 gcc_checking_assert (TREE_INT_CST_NUNITS (expr));
967 streamer_write_uhwi (ob, TREE_INT_CST_NUNITS (expr));
968 streamer_write_uhwi (ob, TREE_INT_CST_EXT_NUNITS (expr));
969 }
970 }
971
972
973 /* Emit the integer constant CST to output block OB. If REF_P is true,
974 CST's type will be emitted as a reference. */
975
976 void
977 streamer_write_integer_cst (struct output_block *ob, tree cst, bool ref_p)
978 {
979 int i;
980 int len = TREE_INT_CST_NUNITS (cst);
981 gcc_assert (!TREE_OVERFLOW (cst));
982 streamer_write_record_start (ob, LTO_integer_cst);
983 stream_write_tree (ob, TREE_TYPE (cst), ref_p);
984 /* We're effectively streaming a non-sign-extended wide_int here,
985 so there's no need to stream TREE_INT_CST_EXT_NUNITS or any
986 array members beyond LEN. We'll recreate the tree from the
987 wide_int and the type. */
988 streamer_write_uhwi (ob, len);
989 for (i = 0; i < len; i++)
990 streamer_write_hwi (ob, TREE_INT_CST_ELT (cst, i));
991 }