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