1 /* Routines for reading PPH data.
2 Copyright (C) 2011 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@google.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
25 #include "langhooks.h"
26 #include "tree-iterator.h"
27 #include "tree-pretty-print.h"
28 #include "lto-streamer.h"
29 #include "pph-streamer.h"
31 #include "tree-pass.h"
33 #include "cppbuiltin.h"
35 /* Wrapper for memory allocation calls that should have their results
36 registered in the PPH streamer cache. DATA is the pointer returned
37 by the memory allocation call in ALLOC_EXPR. IX is the cache slot
38 in STREAM where the newly allocated DATA should be registered at. */
39 #define ALLOC_AND_REGISTER(STREAM, IX, DATA, ALLOC_EXPR) \
41 (DATA) = (ALLOC_EXPR); \
42 pph_stream_register_shared_data (STREAM, DATA, IX); \
45 /* Callback for unpacking value fields in ASTs. BP is the bitpack
46 we are unpacking from. EXPR is the tree to unpack. */
49 pph_stream_unpack_value_fields (struct bitpack_d
*bp
, tree expr
)
53 TYPE_LANG_FLAG_0 (expr
) = bp_unpack_value (bp
, 1);
54 TYPE_LANG_FLAG_1 (expr
) = bp_unpack_value (bp
, 1);
55 TYPE_LANG_FLAG_2 (expr
) = bp_unpack_value (bp
, 1);
56 TYPE_LANG_FLAG_3 (expr
) = bp_unpack_value (bp
, 1);
57 TYPE_LANG_FLAG_4 (expr
) = bp_unpack_value (bp
, 1);
58 TYPE_LANG_FLAG_5 (expr
) = bp_unpack_value (bp
, 1);
59 TYPE_LANG_FLAG_6 (expr
) = bp_unpack_value (bp
, 1);
61 else if (DECL_P (expr
))
63 DECL_LANG_FLAG_0 (expr
) = bp_unpack_value (bp
, 1);
64 DECL_LANG_FLAG_1 (expr
) = bp_unpack_value (bp
, 1);
65 DECL_LANG_FLAG_2 (expr
) = bp_unpack_value (bp
, 1);
66 DECL_LANG_FLAG_3 (expr
) = bp_unpack_value (bp
, 1);
67 DECL_LANG_FLAG_4 (expr
) = bp_unpack_value (bp
, 1);
68 DECL_LANG_FLAG_5 (expr
) = bp_unpack_value (bp
, 1);
69 DECL_LANG_FLAG_6 (expr
) = bp_unpack_value (bp
, 1);
70 DECL_LANG_FLAG_7 (expr
) = bp_unpack_value (bp
, 1);
71 DECL_LANG_FLAG_8 (expr
) = bp_unpack_value (bp
, 1);
74 TREE_LANG_FLAG_0 (expr
) = bp_unpack_value (bp
, 1);
75 TREE_LANG_FLAG_1 (expr
) = bp_unpack_value (bp
, 1);
76 TREE_LANG_FLAG_2 (expr
) = bp_unpack_value (bp
, 1);
77 TREE_LANG_FLAG_3 (expr
) = bp_unpack_value (bp
, 1);
78 TREE_LANG_FLAG_4 (expr
) = bp_unpack_value (bp
, 1);
79 TREE_LANG_FLAG_5 (expr
) = bp_unpack_value (bp
, 1);
80 TREE_LANG_FLAG_6 (expr
) = bp_unpack_value (bp
, 1);
84 /* Get the section with name NAME and type SECTION_TYPE from FILE_DATA.
85 Return a pointer to the start of the section contents and store
86 the length of the section in *LEN_P.
88 FIXME pph, this does not currently handle multiple sections. It
89 assumes that the file has exactly one section. */
92 pph_get_section_data (struct lto_file_decl_data
*file_data
,
93 enum lto_section_type section_type ATTRIBUTE_UNUSED
,
94 const char *name ATTRIBUTE_UNUSED
,
97 /* FIXME pph - Stop abusing lto_file_decl_data fields. */
98 const pph_stream
*stream
= (const pph_stream
*) file_data
->file_name
;
99 *len
= stream
->file_size
- sizeof (pph_file_header
);
100 return (const char *) stream
->file_data
+ sizeof (pph_file_header
);
104 /* Free the section data from FILE_DATA of SECTION_TYPE and NAME that
105 starts at OFFSET and has LEN bytes. */
108 pph_free_section_data (struct lto_file_decl_data
*file_data
,
109 enum lto_section_type section_type ATTRIBUTE_UNUSED
,
110 const char *name ATTRIBUTE_UNUSED
,
111 const char *offset ATTRIBUTE_UNUSED
,
112 size_t len ATTRIBUTE_UNUSED
)
114 /* FIXME pph - Stop abusing lto_file_decl_data fields. */
115 const pph_stream
*stream
= (const pph_stream
*) file_data
->file_name
;
116 free (stream
->file_data
);
120 /* Read into memory the contents of the file in STREAM. Initialize
121 internal tables and data structures needed to re-construct the
125 pph_stream_init_read (pph_stream
*stream
)
128 size_t i
, bytes_read
, strtab_size
, body_size
;
130 pph_file_header
*header
;
131 const char *strtab
, *body
;
135 /* Read STREAM->NAME into the memory buffer STREAM->FILE_DATA.
136 FIXME pph, we are reading the whole file at once. This seems
138 retcode
= fstat (fileno (stream
->file
), &st
);
139 gcc_assert (retcode
== 0);
140 stream
->file_size
= (size_t) st
.st_size
;
141 stream
->file_data
= XCNEWVEC (char, stream
->file_size
);
142 bytes_read
= fread (stream
->file_data
, 1, stream
->file_size
, stream
->file
);
143 gcc_assert (bytes_read
== stream
->file_size
);
145 /* Set LTO callbacks to read the PPH file. */
146 stream
->pph_sections
= XCNEWVEC (struct lto_file_decl_data
*,
148 for (i
= 0; i
< PPH_NUM_SECTIONS
; i
++)
150 stream
->pph_sections
[i
] = XCNEW (struct lto_file_decl_data
);
151 /* FIXME pph - Stop abusing fields in lto_file_decl_data. */
152 stream
->pph_sections
[i
]->file_name
= (const char *) stream
;
155 lto_set_in_hooks (stream
->pph_sections
, pph_get_section_data
,
156 pph_free_section_data
);
158 header
= (pph_file_header
*) stream
->file_data
;
159 strtab
= (const char *) header
+ sizeof (pph_file_header
);
160 strtab_size
= header
->strtab_size
;
161 body
= strtab
+ strtab_size
;
162 gcc_assert (stream
->file_size
>= strtab_size
+ sizeof (pph_file_header
));
163 body_size
= stream
->file_size
- strtab_size
- sizeof (pph_file_header
);
165 /* Create an input block structure pointing right after the string
167 stream
->ib
= XCNEW (struct lto_input_block
);
168 LTO_INIT_INPUT_BLOCK_PTR (stream
->ib
, body
, 0, body_size
);
169 stream
->data_in
= lto_data_in_create (stream
->pph_sections
[0], strtab
,
172 /* Associate STREAM with STREAM->DATA_IN so we can recover it from
173 the streamer hooks. */
174 stream
->data_in
->sdata
= (void *) stream
;
178 /* Read and return a record marker from STREAM. When a PPH_RECORD_START
179 marker is read, the next word read is an index into the streamer
180 cache where the rematerialized data structure should be stored.
181 When the writer stored this data structure for the first time, it
182 added it to its own streamer cache at slot number *CACHE_IX.
184 This way, if the same data structure was written a second time to
185 the stream, instead of writing the whole structure again, only the
186 index *CACHE_IX is written as a PPH_RECORD_SHARED record.
188 Therefore, when reading a PPH_RECORD_START marker, *CACHE_IX will
189 contain the slot number where the materialized data should be
190 cached at. When reading a PPH_RECORD_SHARED marker, *CACHE_IX will
191 contain the slot number the reader can find the previously
192 materialized structure. */
194 static inline enum pph_record_marker
195 pph_start_record (pph_stream
*stream
, unsigned *cache_ix
)
197 enum pph_record_marker marker
;
199 marker
= (enum pph_record_marker
) pph_input_uchar (stream
);
201 /* For PPH_RECORD_START and PPH_RECORD_SHARED markers, read the
202 streamer cache slot where we should store or find the
203 rematerialized data structure (see description above). */
204 if (marker
== PPH_RECORD_START
|| marker
== PPH_RECORD_SHARED
)
205 *cache_ix
= pph_input_uint (stream
);
207 gcc_assert (marker
== PPH_RECORD_END
);
213 /* Return a shared pointer from the streamer cache in STREAM. This is
214 called when pph_start_record returns PPH_RECORD_SHARED. It means
215 that the data structure we are about to read has been instantiated
216 before and is present in the streamer cache. */
219 pph_stream_read_shared_data (pph_stream
*stream
, unsigned ix
)
221 return pph_stream_cache_get (stream
, ix
);
225 /* Register DATA in STREAM's cache slot IX. This is called when a
226 potentially shared data structure is first read from STREAM.
227 Subsequent reads of this data structure will get the index from the
228 table cache where this data was saved. */
231 pph_stream_register_shared_data (pph_stream
*stream
, void *data
, unsigned ix
)
233 pph_stream_cache_insert_at (stream
, data
, ix
);
237 /* Read all fields in lang_decl_base instance LDB from STREAM. */
240 pph_stream_read_ld_base (pph_stream
*stream
, struct lang_decl_base
*ldb
)
244 bp
= pph_input_bitpack (stream
);
245 ldb
->selector
= bp_unpack_value (&bp
, 16);
246 ldb
->language
= (enum languages
) bp_unpack_value (&bp
, 4);
247 ldb
->use_template
= bp_unpack_value (&bp
, 2);
248 ldb
->not_really_extern
= bp_unpack_value (&bp
, 1);
249 ldb
->initialized_in_class
= bp_unpack_value (&bp
, 1);
250 ldb
->repo_available_p
= bp_unpack_value (&bp
, 1);
251 ldb
->threadprivate_or_deleted_p
= bp_unpack_value (&bp
, 1);
252 ldb
->anticipated_p
= bp_unpack_value (&bp
, 1);
253 ldb
->friend_attr
= bp_unpack_value (&bp
, 1);
254 ldb
->template_conv_p
= bp_unpack_value (&bp
, 1);
255 ldb
->odr_used
= bp_unpack_value (&bp
, 1);
256 ldb
->u2sel
= bp_unpack_value (&bp
, 1);
260 /* Read all the fields in lang_decl_min instance LDM from STREAM. */
263 pph_stream_read_ld_min (pph_stream
*stream
, struct lang_decl_min
*ldm
)
265 ldm
->template_info
= pph_input_tree (stream
);
266 if (ldm
->base
.u2sel
== 0)
267 ldm
->u2
.access
= pph_input_tree (stream
);
268 else if (ldm
->base
.u2sel
== 1)
269 ldm
->u2
.discriminator
= pph_input_uint (stream
);
275 /* Read and return a gc VEC of trees from STREAM. */
278 pph_stream_read_tree_vec (pph_stream
*stream
)
283 num
= pph_input_uint (stream
);
285 for (i
= 0; i
< num
; i
++)
287 tree t
= pph_input_tree (stream
);
288 VEC_safe_push (tree
, gc
, v
, t
);
295 /* Read and return a gc VEC of qualified_typedef_usage_t from STREAM. */
297 static VEC(qualified_typedef_usage_t
,gc
) *
298 pph_stream_read_qual_use_vec (pph_stream
*stream
)
301 VEC(qualified_typedef_usage_t
,gc
) *v
;
303 num
= pph_input_uint (stream
);
305 for (i
= 0; i
< num
; i
++)
307 qualified_typedef_usage_t q
;
308 q
.typedef_decl
= pph_input_tree (stream
);
309 q
.context
= pph_input_tree (stream
);
310 /* FIXME pph: also read location. */
311 VEC_safe_push (qualified_typedef_usage_t
, gc
, v
, &q
);
318 /* Forward declaration to break cyclic dependencies. */
319 static struct cp_binding_level
*pph_stream_read_binding_level (pph_stream
*);
321 /* Helper for pph_stream_read_cxx_binding. Read and return a cxx_binding
322 instance from STREAM. */
325 pph_stream_read_cxx_binding_1 (pph_stream
*stream
)
330 enum pph_record_marker marker
;
333 marker
= pph_start_record (stream
, &ix
);
334 if (marker
== PPH_RECORD_END
)
336 else if (marker
== PPH_RECORD_SHARED
)
337 return (cxx_binding
*) pph_stream_read_shared_data (stream
, ix
);
339 value
= pph_input_tree (stream
);
340 type
= pph_input_tree (stream
);
341 cb
= cxx_binding_make (value
, type
);
342 cb
->scope
= pph_stream_read_binding_level (stream
);
343 bp
= pph_input_bitpack (stream
);
344 cb
->value_is_inherited
= bp_unpack_value (&bp
, 1);
345 cb
->is_local
= bp_unpack_value (&bp
, 1);
347 pph_stream_register_shared_data (stream
, cb
, ix
);
353 /* Read and return an instance of cxx_binding from STREAM. */
356 pph_stream_read_cxx_binding (pph_stream
*stream
)
358 unsigned i
, num_bindings
;
359 cxx_binding
*curr
, *cb
;
361 /* Read the list of previous bindings. */
362 num_bindings
= pph_input_uint (stream
);
363 for (curr
= NULL
, i
= 0; i
< num_bindings
; i
++)
365 cxx_binding
*prev
= pph_stream_read_cxx_binding_1 (stream
);
367 curr
->previous
= prev
;
371 /* Read the current binding at the end. Note that we do not need
372 to call pph_stream_register_shared_data as it is already done
373 by pph_stream_read_cxx_binding_1. */
374 cb
= pph_stream_read_cxx_binding_1 (stream
);
382 /* Read all the fields of cp_class_binding instance CB to OB. */
384 static cp_class_binding
*
385 pph_stream_read_class_binding (pph_stream
*stream
)
387 cp_class_binding
*cb
;
388 enum pph_record_marker marker
;
391 marker
= pph_start_record (stream
, &ix
);
392 if (marker
== PPH_RECORD_END
)
394 else if (marker
== PPH_RECORD_SHARED
)
395 return (cp_class_binding
*) pph_stream_read_shared_data (stream
, ix
);
397 cb
= ggc_alloc_cleared_cp_class_binding ();
398 memcpy (&cb
->base
, pph_stream_read_cxx_binding (stream
),
399 sizeof (cxx_binding
));
400 cb
->identifier
= pph_input_tree (stream
);
402 pph_stream_register_shared_data (stream
, cb
, ix
);
408 /* Read and return an instance of cp_label_binding from STREAM. */
410 static cp_label_binding
*
411 pph_stream_read_label_binding (pph_stream
*stream
)
413 cp_label_binding
*lb
;
414 enum pph_record_marker marker
;
417 marker
= pph_start_record (stream
, &ix
);
418 if (marker
== PPH_RECORD_END
)
420 else if (marker
== PPH_RECORD_SHARED
)
421 return (cp_label_binding
*) pph_stream_read_shared_data (stream
, ix
);
423 lb
= ggc_alloc_cleared_cp_label_binding ();
424 lb
->label
= pph_input_tree (stream
);
425 lb
->prev_value
= pph_input_tree (stream
);
427 pph_stream_register_shared_data (stream
, lb
, ix
);
433 /* Read and return an instance of cp_binding_level from STREAM. */
435 static struct cp_binding_level
*
436 pph_stream_read_binding_level (pph_stream
*stream
)
439 cp_label_binding
*sl
;
440 struct cp_binding_level
*bl
;
442 enum pph_record_marker marker
;
444 marker
= pph_start_record (stream
, &ix
);
445 if (marker
== PPH_RECORD_END
)
447 else if (marker
== PPH_RECORD_SHARED
)
448 return (struct cp_binding_level
*) pph_stream_read_shared_data (stream
, ix
);
450 ALLOC_AND_REGISTER (stream
, ix
, bl
, ggc_alloc_cleared_cp_binding_level ());
452 bl
->names
= pph_input_chain (stream
);
453 bl
->names_size
= pph_input_uint (stream
);
454 bl
->namespaces
= pph_input_chain (stream
);
456 bl
->static_decls
= pph_stream_read_tree_vec (stream
);
458 bl
->usings
= pph_input_chain (stream
);
459 bl
->using_directives
= pph_input_chain (stream
);
461 num
= pph_input_uint (stream
);
462 bl
->class_shadowed
= NULL
;
463 for (i
= 0; i
< num
; i
++)
465 cp_class_binding
*cb
= pph_stream_read_class_binding (stream
);
466 VEC_safe_push (cp_class_binding
, gc
, bl
->class_shadowed
, cb
);
469 bl
->type_shadowed
= pph_input_tree (stream
);
471 num
= pph_input_uint (stream
);
472 bl
->shadowed_labels
= NULL
;
473 for (i
= 0; VEC_iterate (cp_label_binding
, bl
->shadowed_labels
, i
, sl
); i
++)
475 cp_label_binding
*sl
= pph_stream_read_label_binding (stream
);
476 VEC_safe_push (cp_label_binding
, gc
, bl
->shadowed_labels
, sl
);
479 bl
->blocks
= pph_input_chain (stream
);
480 bl
->this_entity
= pph_input_tree (stream
);
481 bl
->level_chain
= pph_stream_read_binding_level (stream
);
482 bl
->dead_vars_from_for
= pph_stream_read_tree_vec (stream
);
483 bl
->statement_list
= pph_input_chain (stream
);
484 bl
->binding_depth
= pph_input_uint (stream
);
486 bp
= pph_input_bitpack (stream
);
487 bl
->kind
= (enum scope_kind
) bp_unpack_value (&bp
, 4);
488 bl
->keep
= bp_unpack_value (&bp
, 1);
489 bl
->more_cleanups_ok
= bp_unpack_value (&bp
, 1);
490 bl
->have_cleanups
= bp_unpack_value (&bp
, 1);
496 /* Read and return an instance of struct c_language_function from STREAM. */
498 static struct c_language_function
*
499 pph_stream_read_c_language_function (pph_stream
*stream
)
501 struct c_language_function
*clf
;
502 enum pph_record_marker marker
;
505 marker
= pph_start_record (stream
, &ix
);
506 if (marker
== PPH_RECORD_END
)
508 else if (marker
== PPH_RECORD_SHARED
)
509 return (struct c_language_function
*) pph_stream_read_shared_data (stream
,
512 ALLOC_AND_REGISTER (stream
, ix
, clf
,
513 ggc_alloc_cleared_c_language_function ());
514 clf
->x_stmt_tree
.x_cur_stmt_list
= pph_input_tree (stream
);
515 clf
->x_stmt_tree
.stmts_are_full_exprs_p
= pph_input_uint (stream
);
521 /* Read and return an instance of struct language_function from STREAM. */
523 static struct language_function
*
524 pph_stream_read_language_function (pph_stream
*stream
)
527 struct language_function
*lf
;
528 enum pph_record_marker marker
;
531 marker
= pph_start_record (stream
, &ix
);
532 if (marker
== PPH_RECORD_END
)
534 else if (marker
== PPH_RECORD_SHARED
)
535 return (struct language_function
*) pph_stream_read_shared_data (stream
,
538 ALLOC_AND_REGISTER (stream
, ix
, lf
, ggc_alloc_cleared_language_function ());
539 memcpy (&lf
->base
, pph_stream_read_c_language_function (stream
),
540 sizeof (struct c_language_function
));
541 lf
->x_cdtor_label
= pph_input_tree (stream
);
542 lf
->x_current_class_ptr
= pph_input_tree (stream
);
543 lf
->x_current_class_ref
= pph_input_tree (stream
);
544 lf
->x_eh_spec_block
= pph_input_tree (stream
);
545 lf
->x_in_charge_parm
= pph_input_tree (stream
);
546 lf
->x_vtt_parm
= pph_input_tree (stream
);
547 lf
->x_return_value
= pph_input_tree (stream
);
548 bp
= pph_input_bitpack (stream
);
549 lf
->x_returns_value
= bp_unpack_value (&bp
, 1);
550 lf
->x_returns_null
= bp_unpack_value (&bp
, 1);
551 lf
->x_returns_abnormally
= bp_unpack_value (&bp
, 1);
552 lf
->x_in_function_try_handler
= bp_unpack_value (&bp
, 1);
553 lf
->x_in_base_initializer
= bp_unpack_value (&bp
, 1);
554 lf
->can_throw
= bp_unpack_value (&bp
, 1);
556 /* FIXME pph. We are not reading lf->x_named_labels. */
558 lf
->bindings
= pph_stream_read_binding_level (stream
);
559 lf
->x_local_names
= pph_stream_read_tree_vec (stream
);
561 /* FIXME pph. We are not reading lf->extern_decl_map. */
567 /* Read all the fields of lang_decl_fn instance LDF from STREAM. */
570 pph_stream_read_ld_fn (pph_stream
*stream
, struct lang_decl_fn
*ldf
)
574 bp
= pph_input_bitpack (stream
);
575 ldf
->operator_code
= (enum tree_code
) bp_unpack_value (&bp
, 16);
576 ldf
->global_ctor_p
= bp_unpack_value (&bp
, 1);
577 ldf
->global_dtor_p
= bp_unpack_value (&bp
, 1);
578 ldf
->constructor_attr
= bp_unpack_value (&bp
, 1);
579 ldf
->destructor_attr
= bp_unpack_value (&bp
, 1);
580 ldf
->assignment_operator_p
= bp_unpack_value (&bp
, 1);
581 ldf
->static_function
= bp_unpack_value (&bp
, 1);
582 ldf
->pure_virtual
= bp_unpack_value (&bp
, 1);
583 ldf
->defaulted_p
= bp_unpack_value (&bp
, 1);
584 ldf
->has_in_charge_parm_p
= bp_unpack_value (&bp
, 1);
585 ldf
->has_vtt_parm_p
= bp_unpack_value (&bp
, 1);
586 ldf
->pending_inline_p
= bp_unpack_value (&bp
, 1);
587 ldf
->nonconverting
= bp_unpack_value (&bp
, 1);
588 ldf
->thunk_p
= bp_unpack_value (&bp
, 1);
589 ldf
->this_thunk_p
= bp_unpack_value (&bp
, 1);
590 ldf
->hidden_friend_p
= bp_unpack_value (&bp
, 1);
592 ldf
->befriending_classes
= pph_input_tree (stream
);
593 ldf
->context
= pph_input_tree (stream
);
595 if (ldf
->thunk_p
== 0)
596 ldf
->u5
.cloned_function
= pph_input_tree (stream
);
597 else if (ldf
->thunk_p
== 1)
598 ldf
->u5
.fixed_offset
= pph_input_uint (stream
);
602 if (ldf
->pending_inline_p
== 1)
603 ldf
->u
.pending_inline_info
= pth_load_token_cache (stream
);
604 else if (ldf
->pending_inline_p
== 0)
605 ldf
->u
.saved_language_function
= pph_stream_read_language_function (stream
);
609 /* Read all the fields of lang_decl_ns instance LDNS from STREAM. */
612 pph_stream_read_ld_ns (pph_stream
*stream
, struct lang_decl_ns
*ldns
)
614 ldns
->level
= pph_stream_read_binding_level (stream
);
618 /* Read all the fields of lang_decl_parm instance LDP from STREAM. */
621 pph_stream_read_ld_parm (pph_stream
*stream
, struct lang_decl_parm
*ldp
)
623 ldp
->level
= pph_input_uint (stream
);
624 ldp
->index
= pph_input_uint (stream
);
628 /* Read language specific data in DECL from STREAM. */
631 pph_stream_read_lang_specific (pph_stream
*stream
, tree decl
)
633 struct lang_decl
*ld
;
634 struct lang_decl_base
*ldb
;
635 enum pph_record_marker marker
;
638 marker
= pph_start_record (stream
, &ix
);
639 if (marker
== PPH_RECORD_END
)
642 /* Since lang_decl is embedded in every decl, LD cannot
644 gcc_assert (marker
!= PPH_RECORD_SHARED
);
646 /* Allocate a lang_decl structure for DECL. */
647 retrofit_lang_decl (decl
);
649 ld
= DECL_LANG_SPECIFIC (decl
);
652 /* Read all the fields in lang_decl_base. */
653 pph_stream_read_ld_base (stream
, ldb
);
655 if (ldb
->selector
== 0)
657 /* Read all the fields in lang_decl_min. */
658 pph_stream_read_ld_min (stream
, &ld
->u
.min
);
660 else if (ldb
->selector
== 1)
662 /* Read all the fields in lang_decl_fn. */
663 pph_stream_read_ld_fn (stream
, &ld
->u
.fn
);
665 else if (ldb
->selector
== 2)
667 /* Read all the fields in lang_decl_ns. */
668 pph_stream_read_ld_ns (stream
, &ld
->u
.ns
);
670 else if (ldb
->selector
== 3)
672 /* Read all the fields in lang_decl_parm. */
673 pph_stream_read_ld_parm (stream
, &ld
->u
.parm
);
680 /* Allocate a tree node with code CODE. IB and DATA_IN are used to
681 read more data from the stream, if needed to build this node.
682 Return NULL if we did not want to handle this node. In that case,
683 the caller will call make_node to allocate this tree. */
686 pph_stream_alloc_tree (enum tree_code code
,
687 struct lto_input_block
*ib ATTRIBUTE_UNUSED
,
688 struct data_in
*data_in
)
690 pph_stream
*stream
= (pph_stream
*) data_in
->sdata
;
692 if (code
== CALL_EXPR
)
694 unsigned nargs
= pph_input_uint (stream
);
695 return build_vl_exp (CALL_EXPR
, nargs
+ 3);
702 /* Read all the fields in lang_type_header instance LTH from STREAM. */
705 pph_stream_read_lang_type_header (pph_stream
*stream
,
706 struct lang_type_header
*lth
)
710 bp
= pph_input_bitpack (stream
);
711 lth
->is_lang_type_class
= bp_unpack_value (&bp
, 1);
712 lth
->has_type_conversion
= bp_unpack_value (&bp
, 1);
713 lth
->has_copy_ctor
= bp_unpack_value (&bp
, 1);
714 lth
->has_default_ctor
= bp_unpack_value (&bp
, 1);
715 lth
->const_needs_init
= bp_unpack_value (&bp
, 1);
716 lth
->ref_needs_init
= bp_unpack_value (&bp
, 1);
717 lth
->has_const_copy_assign
= bp_unpack_value (&bp
, 1);
721 /* Read the vector V of tree_pair_s instances from STREAM. */
723 static VEC(tree_pair_s
,gc
) *
724 pph_stream_read_tree_pair_vec (pph_stream
*stream
)
727 VEC(tree_pair_s
,gc
) *v
;
729 num
= pph_input_uint (stream
);
730 for (i
= 0, v
= NULL
; i
< num
; i
++)
733 p
.purpose
= pph_input_tree (stream
);
734 p
.value
= pph_input_tree (stream
);
735 VEC_safe_push (tree_pair_s
, gc
, v
, &p
);
742 /* Read a struct sorted_fields_type instance SFT to STREAM. REF_P is
743 true if the tree nodes should be written as references. */
745 static struct sorted_fields_type
*
746 pph_stream_read_sorted_fields_type (pph_stream
*stream
)
748 unsigned i
, num_fields
;
749 struct sorted_fields_type
*v
;
750 enum pph_record_marker marker
;
753 marker
= pph_start_record (stream
, &ix
);
754 if (marker
== PPH_RECORD_END
)
756 else if (marker
== PPH_RECORD_SHARED
)
757 return (struct sorted_fields_type
*) pph_stream_read_shared_data (stream
,
760 num_fields
= pph_input_uint (stream
);
761 ALLOC_AND_REGISTER (stream
, ix
, v
, sorted_fields_type_new (num_fields
));
762 for (i
= 0; i
< num_fields
; i
++)
763 v
->elts
[i
] = pph_input_tree (stream
);
769 /* Read all the fields in lang_type_class instance LTC to STREAM.
770 REF_P is true if all the trees in the structure should be written
774 pph_stream_read_lang_type_class (pph_stream
*stream
,
775 struct lang_type_class
*ltc
)
778 enum pph_record_marker marker
;
781 ltc
->align
= pph_input_uchar (stream
);
783 bp
= pph_input_bitpack (stream
);
784 ltc
->has_mutable
= bp_unpack_value (&bp
, 1);
785 ltc
->com_interface
= bp_unpack_value (&bp
, 1);
786 ltc
->non_pod_class
= bp_unpack_value (&bp
, 1);
787 ltc
->nearly_empty_p
= bp_unpack_value (&bp
, 1);
788 ltc
->user_align
= bp_unpack_value (&bp
, 1);
789 ltc
->has_copy_assign
= bp_unpack_value (&bp
, 1);
790 ltc
->has_new
= bp_unpack_value (&bp
, 1);
791 ltc
->has_array_new
= bp_unpack_value (&bp
, 1);
792 ltc
->gets_delete
= bp_unpack_value (&bp
, 2);
793 ltc
->interface_only
= bp_unpack_value (&bp
, 1);
794 ltc
->interface_unknown
= bp_unpack_value (&bp
, 1);
795 ltc
->contains_empty_class_p
= bp_unpack_value (&bp
, 1);
796 ltc
->anon_aggr
= bp_unpack_value (&bp
, 1);
797 ltc
->non_zero_init
= bp_unpack_value (&bp
, 1);
798 ltc
->empty_p
= bp_unpack_value (&bp
, 1);
799 ltc
->vec_new_uses_cookie
= bp_unpack_value (&bp
, 1);
800 ltc
->declared_class
= bp_unpack_value (&bp
, 1);
801 ltc
->diamond_shaped
= bp_unpack_value (&bp
, 1);
802 ltc
->repeated_base
= bp_unpack_value (&bp
, 1);
803 ltc
->being_defined
= bp_unpack_value (&bp
, 1);
804 ltc
->java_interface
= bp_unpack_value (&bp
, 1);
805 ltc
->debug_requested
= bp_unpack_value (&bp
, 1);
806 ltc
->fields_readonly
= bp_unpack_value (&bp
, 1);
807 ltc
->use_template
= bp_unpack_value (&bp
, 2);
808 ltc
->ptrmemfunc_flag
= bp_unpack_value (&bp
, 1);
809 ltc
->was_anonymous
= bp_unpack_value (&bp
, 1);
810 ltc
->lazy_default_ctor
= bp_unpack_value (&bp
, 1);
811 ltc
->lazy_copy_ctor
= bp_unpack_value (&bp
, 1);
812 ltc
->lazy_copy_assign
= bp_unpack_value (&bp
, 1);
813 ltc
->lazy_destructor
= bp_unpack_value (&bp
, 1);
814 ltc
->has_const_copy_ctor
= bp_unpack_value (&bp
, 1);
815 ltc
->has_complex_copy_ctor
= bp_unpack_value (&bp
, 1);
816 ltc
->has_complex_copy_assign
= bp_unpack_value (&bp
, 1);
817 ltc
->non_aggregate
= bp_unpack_value (&bp
, 1);
818 ltc
->has_complex_dflt
= bp_unpack_value (&bp
, 1);
819 ltc
->has_list_ctor
= bp_unpack_value (&bp
, 1);
820 ltc
->non_std_layout
= bp_unpack_value (&bp
, 1);
821 ltc
->is_literal
= bp_unpack_value (&bp
, 1);
822 ltc
->lazy_move_ctor
= bp_unpack_value (&bp
, 1);
823 ltc
->lazy_move_assign
= bp_unpack_value (&bp
, 1);
824 ltc
->has_complex_move_ctor
= bp_unpack_value (&bp
, 1);
825 ltc
->has_complex_move_assign
= bp_unpack_value (&bp
, 1);
826 ltc
->has_constexpr_ctor
= bp_unpack_value (&bp
, 1);
828 ltc
->primary_base
= pph_input_tree (stream
);
829 ltc
->vcall_indices
= pph_stream_read_tree_pair_vec (stream
);
830 ltc
->vtables
= pph_input_tree (stream
);
831 ltc
->typeinfo_var
= pph_input_tree (stream
);
832 ltc
->vbases
= pph_stream_read_tree_vec (stream
);
834 marker
= pph_start_record (stream
, &ix
);
835 if (marker
== PPH_RECORD_START
)
837 ltc
->nested_udts
= pph_stream_read_binding_table (stream
);
838 pph_stream_register_shared_data (stream
, ltc
->nested_udts
, ix
);
840 else if (marker
== PPH_RECORD_SHARED
)
841 ltc
->nested_udts
= (binding_table
) pph_stream_read_shared_data (stream
, ix
);
843 ltc
->as_base
= pph_input_tree (stream
);
844 ltc
->pure_virtuals
= pph_stream_read_tree_vec (stream
);
845 ltc
->friend_classes
= pph_input_tree (stream
);
846 ltc
->methods
= pph_stream_read_tree_vec (stream
);
847 ltc
->key_method
= pph_input_tree (stream
);
848 ltc
->decl_list
= pph_input_tree (stream
);
849 ltc
->template_info
= pph_input_tree (stream
);
850 ltc
->befriending_classes
= pph_input_tree (stream
);
851 ltc
->objc_info
= pph_input_tree (stream
);
852 ltc
->sorted_fields
= pph_stream_read_sorted_fields_type (stream
);
853 ltc
->lambda_expr
= pph_input_tree (stream
);
857 /* Read all fields of struct lang_type_ptrmem instance LTP from STREAM. */
860 pph_stream_read_lang_type_ptrmem (pph_stream
*stream
,
861 struct lang_type_ptrmem
*ltp
)
863 ltp
->record
= pph_input_tree (stream
);
867 /* Read all the fields in struct lang_type from STREAM. */
869 static struct lang_type
*
870 pph_stream_read_lang_type (pph_stream
*stream
)
872 struct lang_type
*lt
;
873 enum pph_record_marker marker
;
876 marker
= pph_start_record (stream
, &ix
);
877 if (marker
== PPH_RECORD_END
)
879 else if (marker
== PPH_RECORD_SHARED
)
880 return (struct lang_type
*) pph_stream_read_shared_data (stream
, ix
);
882 ALLOC_AND_REGISTER (stream
, ix
, lt
,
883 ggc_alloc_cleared_lang_type (sizeof (struct lang_type
)));
885 pph_stream_read_lang_type_header (stream
, <
->u
.h
);
886 if (lt
->u
.h
.is_lang_type_class
)
887 pph_stream_read_lang_type_class (stream
, <
->u
.c
);
889 pph_stream_read_lang_type_ptrmem (stream
, <
->u
.ptrmem
);
895 /* Callback for reading ASTs from a stream. This reads all the fields
896 that are not processed by default by the common tree pickler.
897 IB, DATA_IN are as in lto_read_tree. EXPR is the partially materialized
901 pph_stream_read_tree (struct lto_input_block
*ib ATTRIBUTE_UNUSED
,
902 struct data_in
*data_in
, tree expr
)
904 pph_stream
*stream
= (pph_stream
*) data_in
->sdata
;
906 switch (TREE_CODE (expr
))
908 /* TREES NEEDING EXTRA WORK */
910 /* tcc_declaration */
912 case DEBUG_EXPR_DECL
:
916 DECL_INITIAL (expr
) = pph_input_tree (stream
);
925 /* FIXME pph: Should we merge DECL_INITIAL into lang_specific? */
926 DECL_INITIAL (expr
) = pph_input_tree (stream
);
927 pph_stream_read_lang_specific (stream
, expr
);
931 DECL_INITIAL (expr
) = pph_input_tree (stream
);
932 pph_stream_read_lang_specific (stream
, expr
);
933 DECL_SAVED_TREE (expr
) = pph_input_tree (stream
);
937 DECL_INITIAL (expr
) = pph_input_tree (stream
);
938 pph_stream_read_lang_specific (stream
, expr
);
939 DECL_ORIGINAL_TYPE (expr
) = pph_input_tree (stream
);
943 DECL_INITIAL (expr
) = pph_input_tree (stream
);
944 pph_stream_read_lang_specific (stream
, expr
);
945 DECL_TEMPLATE_RESULT (expr
) = pph_input_tree (stream
);
946 DECL_TEMPLATE_PARMS (expr
) = pph_input_tree (stream
);
947 DECL_CONTEXT (expr
) = pph_input_tree (stream
);
956 case FIXED_POINT_TYPE
:
968 TYPE_LANG_SPECIFIC (expr
) = pph_stream_read_lang_type (stream
);
971 case QUAL_UNION_TYPE
:
974 TYPE_LANG_SPECIFIC (expr
) = pph_stream_read_lang_type (stream
);
975 TYPE_BINFO (expr
) = pph_input_tree (stream
);
978 case BOUND_TEMPLATE_TEMPLATE_PARM
:
980 case TEMPLATE_TEMPLATE_PARM
:
981 case TEMPLATE_TYPE_PARM
:
984 TYPE_LANG_SPECIFIC (expr
) = pph_stream_read_lang_type (stream
);
985 TYPE_CACHED_VALUES (expr
) = pph_input_tree (stream
);
986 /* Note that we are using TYPED_CACHED_VALUES for it access to
987 the generic .values field of types. */
994 HOST_WIDE_INT i
, num_trees
= pph_input_uint (stream
);
995 for (i
= 0; i
< num_trees
; i
++)
997 tree stmt
= pph_input_tree (stream
);
998 append_to_statement_list (stmt
, &expr
);
1003 /* tcc_expression */
1013 /* tcc_exceptional */
1016 OVL_FUNCTION (expr
) = pph_input_tree (stream
);
1019 case IDENTIFIER_NODE
:
1021 struct lang_identifier
*id
= LANG_IDENTIFIER_CAST (expr
);
1022 id
->namespace_bindings
= pph_stream_read_cxx_binding (stream
);
1023 id
->bindings
= pph_stream_read_cxx_binding (stream
);
1024 id
->class_template_info
= pph_input_tree (stream
);
1025 id
->label_value
= pph_input_tree (stream
);
1030 BASELINK_BINFO (expr
) = pph_input_tree (stream
);
1031 BASELINK_FUNCTIONS (expr
) = pph_input_tree (stream
);
1032 BASELINK_ACCESS_BINFO (expr
) = pph_input_tree (stream
);
1036 TI_TYPEDEFS_NEEDING_ACCESS_CHECKING (expr
)
1037 = pph_stream_read_qual_use_vec (stream
);
1040 case TEMPLATE_PARM_INDEX
:
1042 template_parm_index
*p
= TEMPLATE_PARM_INDEX_CAST (expr
);
1043 p
->index
= pph_input_uint (stream
);
1044 p
->level
= pph_input_uint (stream
);
1045 p
->orig_level
= pph_input_uint (stream
);
1046 p
->num_siblings
= pph_input_uint (stream
);
1047 p
->decl
= pph_input_tree (stream
);
1048 /* FIXME pph: Is TEMPLATE_PARM_PARAMETER_PACK using TREE_LANG_FLAG_0
1053 /* TREES ALREADY HANDLED */
1055 /* tcc_declaration */
1057 case TRANSLATION_UNIT_DECL
:
1059 /* tcc_exceptional */
1067 /* TREES UNIMPLEMENTED */
1069 /* tcc_declaration */
1073 case TYPE_ARGUMENT_PACK
:
1074 case TYPE_PACK_EXPANSION
:
1075 case UNBOUND_CLASS_TEMPLATE
:
1086 case RANGE_FOR_STMT
:
1093 /* tcc_expression */
1098 case VEC_DELETE_EXPR
:
1102 case EMPTY_CLASS_EXPR
:
1103 case TEMPLATE_ID_EXPR
:
1104 case PSEUDO_DTOR_EXPR
:
1108 case NON_DEPENDENT_EXPR
:
1109 case CTOR_INITIALIZER
:
1110 case MUST_NOT_THROW_EXPR
:
1117 case AT_ENCODE_EXPR
:
1119 case NONTYPE_ARGUMENT_PACK
:
1120 case EXPR_PACK_EXPANSION
:
1125 case REINTERPRET_CAST_EXPR
:
1126 case CONST_CAST_EXPR
:
1127 case STATIC_CAST_EXPR
:
1128 case DYNAMIC_CAST_EXPR
:
1130 case UNARY_PLUS_EXPR
:
1144 case AGGR_INIT_EXPR
:
1146 /* tcc_exceptional */
1150 case ARGUMENT_PACK_SELECT
:
1154 if (flag_pph_untree
)
1155 fprintf (pph_logfile
, "PPH: unimplemented tree node %s\n",
1156 tree_code_name
[TREE_CODE (expr
)]);
1159 /* TREES UNRECOGNIZED */
1162 if (flag_pph_untree
)
1163 fprintf (pph_logfile
, "PPH: unrecognized tree node %s\n",
1164 tree_code_name
[TREE_CODE (expr
)]);