OSDN Git Service

* ChangeLog: Additional fixes for AVX2 ChangeLog entry.
[pf3gnuchains/gcc-fork.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 static void
35 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                                      TREE_STRING_POINTER (string),
41                                      TREE_STRING_LENGTH (string),
42                                      true);
43 }
44
45
46 /* Output the identifier ID to the string
47    table in OB.  Then put the index onto the INDEX_STREAM.  */
48
49 static void
50 write_identifier (struct output_block *ob,
51                    struct lto_output_stream *index_stream,
52                    tree id)
53 {
54   streamer_write_string_with_length (ob, index_stream,
55                                      IDENTIFIER_POINTER (id),
56                                      IDENTIFIER_LENGTH (id),
57                                      true);
58 }
59
60
61 /* Pack all the non-pointer fields of the TS_BASE structure of
62    expression EXPR into bitpack BP.  */
63
64 static void
65 pack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
66 {
67   bp_pack_value (bp, TREE_CODE (expr), 16);
68   if (!TYPE_P (expr))
69     {
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);
73
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);
78     }
79   else
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);
83   if (DECL_P (expr))
84     bp_pack_value (bp, DECL_UNSIGNED (expr), 1);
85   else if (TYPE_P (expr))
86     bp_pack_value (bp, TYPE_UNSIGNED (expr), 1);
87   else
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);
91   if (TYPE_P (expr))
92     bp_pack_value (bp, TYPE_ARTIFICIAL (expr), 1);
93   else
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);
101   if (TYPE_P (expr))
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);
105   else
106     bp_pack_value (bp, 0, 1);
107 }
108
109
110 /* Pack all the non-pointer fields of the TS_REAL_CST structure of
111    expression EXPR into bitpack BP.  */
112
113 static void
114 pack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
115 {
116   unsigned i;
117   REAL_VALUE_TYPE r;
118
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);
128 }
129
130
131 /* Pack all the non-pointer fields of the TS_FIXED_CST structure of
132    expression EXPR into bitpack BP.  */
133
134 static void
135 pack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
136 {
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);
141 }
142
143
144 /* Pack all the non-pointer fields of the TS_DECL_COMMON structure
145    of expression EXPR into bitpack BP.  */
146
147 static void
148 pack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
149 {
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));
162
163   if (TREE_CODE (expr) == LABEL_DECL)
164     {
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));
170     }
171
172   if (TREE_CODE (expr) == FIELD_DECL)
173     {
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);
177     }
178
179   if (TREE_CODE (expr) == RESULT_DECL
180       || TREE_CODE (expr) == PARM_DECL
181       || TREE_CODE (expr) == VAR_DECL)
182     {
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);
188     }
189 }
190
191
192 /* Pack all the non-pointer fields of the TS_DECL_WRTL structure
193    of expression EXPR into bitpack BP.  */
194
195 static void
196 pack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
197 {
198   bp_pack_value (bp, DECL_REGISTER (expr), 1);
199 }
200
201
202 /* Pack all the non-pointer fields of the TS_DECL_WITH_VIS structure
203    of expression EXPR into bitpack BP.  */
204
205 static void
206 pack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
207 {
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);
216
217   if (TREE_CODE (expr) == VAR_DECL)
218     {
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);
223     }
224
225   if (VAR_OR_FUNCTION_DECL_P (expr))
226     bp_pack_var_len_unsigned (bp, DECL_INIT_PRIORITY (expr));
227 }
228
229
230 /* Pack all the non-pointer fields of the TS_FUNCTION_DECL structure
231    of expression EXPR into bitpack BP.  */
232
233 static void
234 pack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
235 {
236   /* For normal/md builtins we only write the class and code, so they
237      should never be handled here.  */
238   gcc_assert (!streamer_handle_as_builtin_p (expr));
239
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));
262 }
263
264
265 /* Pack all the non-pointer fields of the TS_TYPE_COMMON structure
266    of expression EXPR into bitpack BP.  */
267
268 static void
269 pack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
270 {
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);
285 }
286
287
288 /* Pack all the non-pointer fields of the TS_BLOCK structure
289    of expression EXPR into bitpack BP.  */
290
291 static void
292 pack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
293 {
294   bp_pack_value (bp, BLOCK_ABSTRACT (expr), 1);
295   /* BLOCK_NUMBER is recomputed.  */
296 }
297
298 /* Pack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL structure
299    of expression EXPR into bitpack BP.  */
300
301 static void
302 pack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
303 {
304 }
305
306
307 /* Pack all the bitfields in EXPR into a bit pack.  */
308
309 void
310 streamer_pack_tree_bitfields (struct bitpack_d *bp, tree expr)
311 {
312   enum tree_code code;
313
314   code = TREE_CODE (expr);
315
316   /* Note that all these functions are highly sensitive to changes in
317      the types and sizes of each of the fields being packed.  */
318   pack_ts_base_value_fields (bp, expr);
319
320   if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
321     pack_ts_real_cst_value_fields (bp, expr);
322
323   if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
324     pack_ts_fixed_cst_value_fields (bp, expr);
325
326   if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
327     pack_ts_decl_common_value_fields (bp, expr);
328
329   if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
330     pack_ts_decl_wrtl_value_fields (bp, expr);
331
332   if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
333     pack_ts_decl_with_vis_value_fields (bp, expr);
334
335   if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
336     pack_ts_function_decl_value_fields (bp, expr);
337
338   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
339     pack_ts_type_common_value_fields (bp, expr);
340
341   if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
342     pack_ts_block_value_fields (bp, expr);
343
344   if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
345     pack_ts_translation_unit_decl_value_fields (bp, expr);
346 }
347
348
349 /* Write the code and class of builtin EXPR to output block OB.  IX is
350    the index into the streamer cache where EXPR is stored.*/
351
352 void
353 streamer_write_builtin (struct output_block *ob, tree expr)
354 {
355   gcc_assert (streamer_handle_as_builtin_p (expr));
356
357   if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
358       && !targetm.builtin_decl)
359     sorry ("tree bytecode streams do not support machine specific builtin "
360            "functions on this target");
361
362   streamer_write_record_start (ob, LTO_builtin_decl);
363   streamer_write_enum (ob->main_stream, built_in_class, BUILT_IN_LAST,
364                        DECL_BUILT_IN_CLASS (expr));
365   streamer_write_uhwi (ob, DECL_FUNCTION_CODE (expr));
366
367   if (DECL_ASSEMBLER_NAME_SET_P (expr))
368     {
369       /* When the assembler name of a builtin gets a user name,
370          the new name is always prefixed with '*' by
371          set_builtin_user_assembler_name.  So, to prevent the
372          reader side from adding a second '*', we omit it here.  */
373       const char *str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr));
374       if (strlen (str) > 1 && str[0] == '*')
375         streamer_write_string (ob, ob->main_stream, &str[1], true);
376       else
377         streamer_write_string (ob, ob->main_stream, NULL, true);
378     }
379   else
380     streamer_write_string (ob, ob->main_stream, NULL, true);
381 }
382
383
384 /* Emit the chain of tree nodes starting at T.  OB is the output block
385    to write to.  REF_P is true if chain elements should be emitted
386    as references.  */
387
388 void
389 streamer_write_chain (struct output_block *ob, tree t, bool ref_p)
390 {
391   int i, count;
392
393   count = list_length (t);
394   streamer_write_hwi (ob, count);
395   for (i = 0; i < count; i++)
396     {
397       tree saved_chain;
398
399       /* Clear TREE_CHAIN to avoid blindly recursing into the rest
400          of the list.  */
401       saved_chain = TREE_CHAIN (t);
402       TREE_CHAIN (t) = NULL_TREE;
403
404       stream_write_tree (ob, t, ref_p);
405
406       TREE_CHAIN (t) = saved_chain;
407       t = TREE_CHAIN (t);
408     }
409 }
410
411
412 /* Write all pointer fields in the TS_COMMON structure of EXPR to output
413    block OB.  If REF_P is true, write a reference to EXPR's pointer
414    fields.  */
415
416 static void
417 write_ts_common_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
418 {
419   if (TREE_CODE (expr) != IDENTIFIER_NODE)
420     stream_write_tree (ob, TREE_TYPE (expr), ref_p);
421 }
422
423
424 /* Write all pointer fields in the TS_VECTOR structure of EXPR to output
425    block OB.  If REF_P is true, write a reference to EXPR's pointer
426    fields.  */
427
428 static void
429 write_ts_vector_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
430 {
431   streamer_write_chain (ob, TREE_VECTOR_CST_ELTS (expr), ref_p);
432 }
433
434
435 /* Write all pointer fields in the TS_COMPLEX structure of EXPR to output
436    block OB.  If REF_P is true, write a reference to EXPR's pointer
437    fields.  */
438
439 static void
440 write_ts_complex_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
441 {
442   stream_write_tree (ob, TREE_REALPART (expr), ref_p);
443   stream_write_tree (ob, TREE_IMAGPART (expr), ref_p);
444 }
445
446
447 /* Write all pointer fields in the TS_DECL_MINIMAL structure of EXPR
448    to output block OB.  If REF_P is true, write a reference to EXPR's
449    pointer fields.  */
450
451 static void
452 write_ts_decl_minimal_tree_pointers (struct output_block *ob, tree expr,
453                                      bool ref_p)
454 {
455   stream_write_tree (ob, DECL_NAME (expr), ref_p);
456   stream_write_tree (ob, DECL_CONTEXT (expr), ref_p);
457   lto_output_location (ob, DECL_SOURCE_LOCATION (expr));
458 }
459
460
461 /* Write all pointer fields in the TS_DECL_COMMON structure of EXPR to
462    output block OB.  If REF_P is true, write a reference to EXPR's
463    pointer fields.  */
464
465 static void
466 write_ts_decl_common_tree_pointers (struct output_block *ob, tree expr,
467                                     bool ref_p)
468 {
469   stream_write_tree (ob, DECL_SIZE (expr), ref_p);
470   stream_write_tree (ob, DECL_SIZE_UNIT (expr), ref_p);
471
472   /* Note, DECL_INITIAL is not handled here.  Since DECL_INITIAL needs
473      special handling in LTO, it must be handled by streamer hooks.  */
474
475   stream_write_tree (ob, DECL_ATTRIBUTES (expr), ref_p);
476
477   /* Do not stream DECL_ABSTRACT_ORIGIN.  We cannot handle debug information
478      for early inlining so drop it on the floor instead of ICEing in
479      dwarf2out.c.  */
480
481   if (TREE_CODE (expr) == PARM_DECL)
482     streamer_write_chain (ob, TREE_CHAIN (expr), ref_p);
483
484   if ((TREE_CODE (expr) == VAR_DECL
485        || TREE_CODE (expr) == PARM_DECL)
486       && DECL_HAS_VALUE_EXPR_P (expr))
487     stream_write_tree (ob, DECL_VALUE_EXPR (expr), ref_p);
488
489   if (TREE_CODE (expr) == VAR_DECL)
490     stream_write_tree (ob, DECL_DEBUG_EXPR (expr), ref_p);
491 }
492
493
494 /* Write all pointer fields in the TS_DECL_NON_COMMON structure of
495    EXPR to output block OB.  If REF_P is true, write a reference to EXPR's
496    pointer fields.  */
497
498 static void
499 write_ts_decl_non_common_tree_pointers (struct output_block *ob, tree expr,
500                                         bool ref_p)
501 {
502   if (TREE_CODE (expr) == FUNCTION_DECL)
503     {
504       stream_write_tree (ob, DECL_ARGUMENTS (expr), ref_p);
505       stream_write_tree (ob, DECL_RESULT (expr), ref_p);
506     }
507   stream_write_tree (ob, DECL_VINDEX (expr), ref_p);
508 }
509
510
511 /* Write all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
512    to output block OB.  If REF_P is true, write a reference to EXPR's
513    pointer fields.  */
514
515 static void
516 write_ts_decl_with_vis_tree_pointers (struct output_block *ob, tree expr,
517                                       bool ref_p)
518 {
519   /* Make sure we don't inadvertently set the assembler name.  */
520   if (DECL_ASSEMBLER_NAME_SET_P (expr))
521     stream_write_tree (ob, DECL_ASSEMBLER_NAME (expr), ref_p);
522   else
523     stream_write_tree (ob, NULL_TREE, false);
524
525   stream_write_tree (ob, DECL_SECTION_NAME (expr), ref_p);
526   stream_write_tree (ob, DECL_COMDAT_GROUP (expr), ref_p);
527 }
528
529
530 /* Write all pointer fields in the TS_FIELD_DECL structure of EXPR to
531    output block OB.  If REF_P is true, write a reference to EXPR's
532    pointer fields.  */
533
534 static void
535 write_ts_field_decl_tree_pointers (struct output_block *ob, tree expr,
536                                    bool ref_p)
537 {
538   stream_write_tree (ob, DECL_FIELD_OFFSET (expr), ref_p);
539   stream_write_tree (ob, DECL_BIT_FIELD_TYPE (expr), ref_p);
540   stream_write_tree (ob, DECL_QUALIFIER (expr), ref_p);
541   stream_write_tree (ob, DECL_FIELD_BIT_OFFSET (expr), ref_p);
542   stream_write_tree (ob, DECL_FCONTEXT (expr), ref_p);
543   streamer_write_chain (ob, TREE_CHAIN (expr), ref_p);
544 }
545
546
547 /* Write all pointer fields in the TS_FUNCTION_DECL structure of EXPR
548    to output block OB.  If REF_P is true, write a reference to EXPR's
549    pointer fields.  */
550
551 static void
552 write_ts_function_decl_tree_pointers (struct output_block *ob, tree expr,
553                                       bool ref_p)
554 {
555   /* DECL_STRUCT_FUNCTION is handled by lto_output_function.  FIXME lto,
556      maybe it should be handled here?  */
557   stream_write_tree (ob, DECL_FUNCTION_PERSONALITY (expr), ref_p);
558   stream_write_tree (ob, DECL_FUNCTION_SPECIFIC_TARGET (expr), ref_p);
559   stream_write_tree (ob, DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr), ref_p);
560 }
561
562
563 /* Write all pointer fields in the TS_TYPE_COMMON structure of EXPR to
564    output block OB.  If REF_P is true, write a reference to EXPR's
565    pointer fields.  */
566
567 static void
568 write_ts_type_common_tree_pointers (struct output_block *ob, tree expr,
569                                     bool ref_p)
570 {
571   stream_write_tree (ob, TYPE_SIZE (expr), ref_p);
572   stream_write_tree (ob, TYPE_SIZE_UNIT (expr), ref_p);
573   stream_write_tree (ob, TYPE_ATTRIBUTES (expr), ref_p);
574   stream_write_tree (ob, TYPE_NAME (expr), ref_p);
575   /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO.  They will be
576      reconstructed during fixup.  */
577   /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
578      during fixup.  */
579   stream_write_tree (ob, TYPE_MAIN_VARIANT (expr), ref_p);
580   stream_write_tree (ob, TYPE_CONTEXT (expr), ref_p);
581   /* TYPE_CANONICAL is re-computed during type merging, so no need
582      to stream it here.  */
583   stream_write_tree (ob, TYPE_STUB_DECL (expr), ref_p);
584 }
585
586 /* Write all pointer fields in the TS_TYPE_NON_COMMON structure of EXPR
587    to 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_non_common_tree_pointers (struct output_block *ob, tree expr,
592                                         bool ref_p)
593 {
594   if (TREE_CODE (expr) == ENUMERAL_TYPE)
595     stream_write_tree (ob, TYPE_VALUES (expr), ref_p);
596   else if (TREE_CODE (expr) == ARRAY_TYPE)
597     stream_write_tree (ob, TYPE_DOMAIN (expr), ref_p);
598   else if (RECORD_OR_UNION_TYPE_P (expr))
599     stream_write_tree (ob, TYPE_FIELDS (expr), ref_p);
600   else if (TREE_CODE (expr) == FUNCTION_TYPE
601            || TREE_CODE (expr) == METHOD_TYPE)
602     stream_write_tree (ob, TYPE_ARG_TYPES (expr), ref_p);
603
604   if (!POINTER_TYPE_P (expr))
605     stream_write_tree (ob, TYPE_MINVAL (expr), ref_p);
606   stream_write_tree (ob, TYPE_MAXVAL (expr), ref_p);
607   if (RECORD_OR_UNION_TYPE_P (expr))
608     stream_write_tree (ob, TYPE_BINFO (expr), ref_p);
609 }
610
611
612 /* Write all pointer fields in the TS_LIST structure of EXPR to output
613    block OB.  If REF_P is true, write a reference to EXPR's pointer
614    fields.  */
615
616 static void
617 write_ts_list_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
618 {
619   stream_write_tree (ob, TREE_PURPOSE (expr), ref_p);
620   stream_write_tree (ob, TREE_VALUE (expr), ref_p);
621   streamer_write_chain (ob, TREE_CHAIN (expr), ref_p);
622 }
623
624
625 /* Write all pointer fields in the TS_VEC structure of EXPR to output
626    block OB.  If REF_P is true, write a reference to EXPR's pointer
627    fields.  */
628
629 static void
630 write_ts_vec_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
631 {
632   int i;
633
634   /* Note that the number of slots for EXPR has already been emitted
635      in EXPR's header (see streamer_write_tree_header).  */
636   for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
637     stream_write_tree (ob, TREE_VEC_ELT (expr, i), ref_p);
638 }
639
640
641 /* Write all pointer fields in the TS_EXP structure of EXPR to output
642    block OB.  If REF_P is true, write a reference to EXPR's pointer
643    fields.  */
644
645 static void
646 write_ts_exp_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
647 {
648   int i;
649
650   streamer_write_hwi (ob, TREE_OPERAND_LENGTH (expr));
651   for (i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
652     stream_write_tree (ob, TREE_OPERAND (expr, i), ref_p);
653   lto_output_location (ob, EXPR_LOCATION (expr));
654   stream_write_tree (ob, TREE_BLOCK (expr), ref_p);
655 }
656
657
658 /* Write all pointer fields in the TS_BLOCK structure of EXPR to output
659    block OB.  If REF_P is true, write a reference to EXPR's pointer
660    fields.  */
661
662 static void
663 write_ts_block_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
664 {
665   /* Do not stream BLOCK_SOURCE_LOCATION.  We cannot handle debug information
666      for early inlining so drop it on the floor instead of ICEing in
667      dwarf2out.c.  */
668   streamer_write_chain (ob, BLOCK_VARS (expr), ref_p);
669
670   /* Do not stream BLOCK_NONLOCALIZED_VARS.  We cannot handle debug information
671      for early inlining so drop it on the floor instead of ICEing in
672      dwarf2out.c.  */
673
674   stream_write_tree (ob, BLOCK_SUPERCONTEXT (expr), ref_p);
675   /* Do not stream BLOCK_ABSTRACT_ORIGIN.  We cannot handle debug information
676      for early inlining so drop it on the floor instead of ICEing in
677      dwarf2out.c.  */
678   stream_write_tree (ob, BLOCK_FRAGMENT_ORIGIN (expr), ref_p);
679   stream_write_tree (ob, BLOCK_FRAGMENT_CHAIN (expr), ref_p);
680   /* Do not output BLOCK_SUBBLOCKS.  Instead on streaming-in this
681      list is re-constructed from BLOCK_SUPERCONTEXT.  */
682 }
683
684
685 /* Write all pointer fields in the TS_BINFO structure of EXPR to output
686    block OB.  If REF_P is true, write a reference to EXPR's pointer
687    fields.  */
688
689 static void
690 write_ts_binfo_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
691 {
692   unsigned i;
693   tree t;
694
695   /* Note that the number of BINFO slots has already been emitted in
696      EXPR's header (see streamer_write_tree_header) because this length
697      is needed to build the empty BINFO node on the reader side.  */
698   FOR_EACH_VEC_ELT (tree, BINFO_BASE_BINFOS (expr), i, t)
699     stream_write_tree (ob, t, ref_p);
700   stream_write_tree (ob, NULL_TREE, false);
701
702   stream_write_tree (ob, BINFO_OFFSET (expr), ref_p);
703   stream_write_tree (ob, BINFO_VTABLE (expr), ref_p);
704   /* BINFO_VIRTUALS is used to drive type based devirtualizatoin.  It often links
705      together large portions of programs making it harder to partition.  Becuase
706      devirtualization is interesting before inlining, only, there is no real
707      need to ship it into ltrans partition.  */
708   stream_write_tree (ob, flag_wpa ? NULL : BINFO_VIRTUALS (expr), ref_p);
709   stream_write_tree (ob, BINFO_VPTR_FIELD (expr), ref_p);
710
711   streamer_write_uhwi (ob, VEC_length (tree, BINFO_BASE_ACCESSES (expr)));
712   FOR_EACH_VEC_ELT (tree, BINFO_BASE_ACCESSES (expr), i, t)
713     stream_write_tree (ob, t, ref_p);
714
715   stream_write_tree (ob, BINFO_INHERITANCE_CHAIN (expr), ref_p);
716   stream_write_tree (ob, BINFO_SUBVTT_INDEX (expr), ref_p);
717   stream_write_tree (ob, BINFO_VPTR_INDEX (expr), ref_p);
718 }
719
720
721 /* Write all pointer fields in the TS_CONSTRUCTOR structure of EXPR to
722    output block OB.  If REF_P is true, write a reference to EXPR's
723    pointer fields.  */
724
725 static void
726 write_ts_constructor_tree_pointers (struct output_block *ob, tree expr,
727                                     bool ref_p)
728 {
729   unsigned i;
730   tree index, value;
731
732   streamer_write_uhwi (ob, CONSTRUCTOR_NELTS (expr));
733   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr), i, index, value)
734     {
735       stream_write_tree (ob, index, ref_p);
736       stream_write_tree (ob, value, ref_p);
737     }
738 }
739
740 /* Write a TS_TARGET_OPTION tree in EXPR to OB.  */
741
742 static void
743 write_ts_target_option (struct output_block *ob, tree expr)
744 {
745   struct cl_target_option *t = TREE_TARGET_OPTION (expr);
746   struct bitpack_d bp;
747   unsigned i, len;
748
749   /* The cl_target_option is target specific and generated by the options
750      awk script, so we just recreate a byte-by-byte copy here. */
751
752   bp = bitpack_create (ob->main_stream);
753   len = sizeof (struct cl_target_option);
754   for (i = 0; i < len; i++)
755     bp_pack_value (&bp, ((unsigned char *)t)[i], 8);
756   /* Catch struct size mismatches between reader and writer. */
757   bp_pack_value (&bp, 0x12345678, 32);
758   streamer_write_bitpack (&bp);
759 }
760
761 /* Write a TS_TRANSLATION_UNIT_DECL tree in EXPR to OB.  */
762
763 static void
764 write_ts_translation_unit_decl_tree_pointers (struct output_block *ob,
765                                               tree expr)
766 {
767   streamer_write_string (ob, ob->main_stream,
768                          TRANSLATION_UNIT_LANGUAGE (expr), true);
769 }
770
771 /* Write all pointer fields in EXPR to output block OB.  If REF_P is true,
772    the leaves of EXPR are emitted as references.  */
773
774 void
775 streamer_write_tree_body (struct output_block *ob, tree expr, bool ref_p)
776 {
777   enum tree_code code;
778
779   code = TREE_CODE (expr);
780
781   if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
782     write_ts_common_tree_pointers (ob, expr, ref_p);
783
784   if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
785     write_ts_vector_tree_pointers (ob, expr, ref_p);
786
787   if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
788     write_ts_complex_tree_pointers (ob, expr, ref_p);
789
790   if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
791     write_ts_decl_minimal_tree_pointers (ob, expr, ref_p);
792
793   if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
794     write_ts_decl_common_tree_pointers (ob, expr, ref_p);
795
796   if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
797     write_ts_decl_non_common_tree_pointers (ob, expr, ref_p);
798
799   if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
800     write_ts_decl_with_vis_tree_pointers (ob, expr, ref_p);
801
802   if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
803     write_ts_field_decl_tree_pointers (ob, expr, ref_p);
804
805   if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
806     write_ts_function_decl_tree_pointers (ob, expr, ref_p);
807
808   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
809     write_ts_type_common_tree_pointers (ob, expr, ref_p);
810
811   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
812     write_ts_type_non_common_tree_pointers (ob, expr, ref_p);
813
814   if (CODE_CONTAINS_STRUCT (code, TS_LIST))
815     write_ts_list_tree_pointers (ob, expr, ref_p);
816
817   if (CODE_CONTAINS_STRUCT (code, TS_VEC))
818     write_ts_vec_tree_pointers (ob, expr, ref_p);
819
820   if (CODE_CONTAINS_STRUCT (code, TS_EXP))
821     write_ts_exp_tree_pointers (ob, expr, ref_p);
822
823   if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
824     write_ts_block_tree_pointers (ob, expr, ref_p);
825
826   if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
827     write_ts_binfo_tree_pointers (ob, expr, ref_p);
828
829   if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
830     write_ts_constructor_tree_pointers (ob, expr, ref_p);
831
832   if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
833     write_ts_target_option (ob, expr);
834
835   if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
836     write_ts_translation_unit_decl_tree_pointers (ob, expr);
837 }
838
839
840 /* Emit header information for tree EXPR to output block OB.  The header
841    contains everything needed to instantiate an empty skeleton for
842    EXPR on the reading side.  IX is the index into the streamer cache
843    where EXPR is stored.  */
844
845 void
846 streamer_write_tree_header (struct output_block *ob, tree expr)
847 {
848   enum LTO_tags tag;
849   enum tree_code code;
850
851   /* We should not see any tree nodes not handled by the streamer.  */
852   code = TREE_CODE (expr);
853
854   /* The header of a tree node consists of its tag, the size of
855      the node, and any other information needed to instantiate
856      EXPR on the reading side (such as the number of slots in
857      variable sized nodes).  */
858   tag = lto_tree_code_to_tag (code);
859   streamer_write_record_start (ob, tag);
860
861   /* The following will cause bootstrap miscomparisons.  Enable with care.  */
862 #ifdef LTO_STREAMER_DEBUG
863   /* This is used mainly for debugging purposes.  When the reader
864      and the writer do not agree on a streamed node, the pointer
865      value for EXPR can be used to track down the differences in
866      the debugger.  */
867   gcc_assert ((HOST_WIDEST_INT) (intptr_t) expr == (intptr_t) expr);
868   streamer_write_hwi (ob, (HOST_WIDEST_INT) (intptr_t) expr);
869 #endif
870
871   /* The text in strings and identifiers are completely emitted in
872      the header.  */
873   if (CODE_CONTAINS_STRUCT (code, TS_STRING))
874     write_string_cst (ob, ob->main_stream, expr);
875   else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
876     write_identifier (ob, ob->main_stream, expr);
877   else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
878     streamer_write_hwi (ob, TREE_VEC_LENGTH (expr));
879   else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
880     streamer_write_uhwi (ob, BINFO_N_BASE_BINFOS (expr));
881   else if (TREE_CODE (expr) == CALL_EXPR)
882     streamer_write_uhwi (ob, call_expr_nargs (expr));
883 }
884
885
886 /* Emit the integer constant CST to output block OB.  If REF_P is true,
887    CST's type will be emitted as a reference.  */
888
889 void
890 streamer_write_integer_cst (struct output_block *ob, tree cst, bool ref_p)
891 {
892   streamer_write_record_start (ob, lto_tree_code_to_tag (INTEGER_CST));
893   stream_write_tree (ob, TREE_TYPE (cst), ref_p);
894   streamer_write_char_stream (ob->main_stream, TREE_OVERFLOW_P (cst));
895   streamer_write_uhwi (ob, TREE_INT_CST_LOW (cst));
896   streamer_write_uhwi (ob, TREE_INT_CST_HIGH (cst));
897 }