1*e4b17023SJohn Marino /* Data structures and functions for streaming trees.
2*e4b17023SJohn Marino
3*e4b17023SJohn Marino Copyright 2011 Free Software Foundation, Inc.
4*e4b17023SJohn Marino Contributed by Diego Novillo <dnovillo@google.com>
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11*e4b17023SJohn Marino version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16*e4b17023SJohn Marino for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino #ifndef GCC_TREE_STREAMER_H
23*e4b17023SJohn Marino #define GCC_TREE_STREAMER_H
24*e4b17023SJohn Marino
25*e4b17023SJohn Marino #include "tree.h"
26*e4b17023SJohn Marino #include "streamer-hooks.h"
27*e4b17023SJohn Marino #include "lto-streamer.h"
28*e4b17023SJohn Marino
29*e4b17023SJohn Marino /* Cache of pickled nodes. Used to avoid writing the same node more
30*e4b17023SJohn Marino than once. The first time a tree node is streamed out, it is
31*e4b17023SJohn Marino entered in this cache. Subsequent references to the same node are
32*e4b17023SJohn Marino resolved by looking it up in this cache.
33*e4b17023SJohn Marino
34*e4b17023SJohn Marino This is used in two ways:
35*e4b17023SJohn Marino
36*e4b17023SJohn Marino - On the writing side, the first time T is added to STREAMER_CACHE,
37*e4b17023SJohn Marino a new reference index is created for T and T is emitted on the
38*e4b17023SJohn Marino stream. If T needs to be emitted again to the stream, instead of
39*e4b17023SJohn Marino pickling it again, the reference index is emitted.
40*e4b17023SJohn Marino
41*e4b17023SJohn Marino - On the reading side, the first time T is read from the stream, it
42*e4b17023SJohn Marino is reconstructed in memory and a new reference index created for
43*e4b17023SJohn Marino T. The reconstructed T is inserted in some array so that when
44*e4b17023SJohn Marino the reference index for T is found in the input stream, it can be
45*e4b17023SJohn Marino used to look up into the array to get the reconstructed T. */
46*e4b17023SJohn Marino struct streamer_tree_cache_d
47*e4b17023SJohn Marino {
48*e4b17023SJohn Marino /* The mapping between tree nodes and slots into the nodes array. */
49*e4b17023SJohn Marino struct pointer_map_t *node_map;
50*e4b17023SJohn Marino
51*e4b17023SJohn Marino /* The nodes pickled so far. */
52*e4b17023SJohn Marino VEC(tree,heap) *nodes;
53*e4b17023SJohn Marino };
54*e4b17023SJohn Marino
55*e4b17023SJohn Marino /* Return true if tree node EXPR should be streamed as a builtin. For
56*e4b17023SJohn Marino these nodes, we just emit the class and function code. */
57*e4b17023SJohn Marino static inline bool
streamer_handle_as_builtin_p(tree expr)58*e4b17023SJohn Marino streamer_handle_as_builtin_p (tree expr)
59*e4b17023SJohn Marino {
60*e4b17023SJohn Marino return (TREE_CODE (expr) == FUNCTION_DECL
61*e4b17023SJohn Marino && DECL_IS_BUILTIN (expr)
62*e4b17023SJohn Marino && (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL
63*e4b17023SJohn Marino || DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD));
64*e4b17023SJohn Marino }
65*e4b17023SJohn Marino
66*e4b17023SJohn Marino /* In tree-streamer-in.c. */
67*e4b17023SJohn Marino tree streamer_read_string_cst (struct data_in *, struct lto_input_block *);
68*e4b17023SJohn Marino tree streamer_read_chain (struct lto_input_block *, struct data_in *);
69*e4b17023SJohn Marino tree streamer_alloc_tree (struct lto_input_block *, struct data_in *,
70*e4b17023SJohn Marino enum LTO_tags);
71*e4b17023SJohn Marino void streamer_read_tree_body (struct lto_input_block *, struct data_in *, tree);
72*e4b17023SJohn Marino tree streamer_get_pickled_tree (struct lto_input_block *, struct data_in *);
73*e4b17023SJohn Marino tree streamer_get_builtin_tree (struct lto_input_block *, struct data_in *);
74*e4b17023SJohn Marino tree streamer_read_integer_cst (struct lto_input_block *, struct data_in *);
75*e4b17023SJohn Marino struct bitpack_d streamer_read_tree_bitfields (struct lto_input_block *, tree);
76*e4b17023SJohn Marino
77*e4b17023SJohn Marino /* In tree-streamer-out.c. */
78*e4b17023SJohn Marino void streamer_write_string_cst (struct output_block *,
79*e4b17023SJohn Marino struct lto_output_stream *, tree);
80*e4b17023SJohn Marino void streamer_write_chain (struct output_block *, tree, bool);
81*e4b17023SJohn Marino void streamer_write_tree_header (struct output_block *, tree);
82*e4b17023SJohn Marino void streamer_pack_tree_bitfields (struct bitpack_d *, tree);
83*e4b17023SJohn Marino void streamer_write_tree_body (struct output_block *, tree, bool);
84*e4b17023SJohn Marino void streamer_write_integer_cst (struct output_block *, tree, bool);
85*e4b17023SJohn Marino void streamer_write_builtin (struct output_block *, tree);
86*e4b17023SJohn Marino
87*e4b17023SJohn Marino /* In tree-streamer.c. */
88*e4b17023SJohn Marino void streamer_check_handled_ts_structures (void);
89*e4b17023SJohn Marino bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree,
90*e4b17023SJohn Marino unsigned *);
91*e4b17023SJohn Marino bool streamer_tree_cache_insert_at (struct streamer_tree_cache_d *, tree,
92*e4b17023SJohn Marino unsigned);
93*e4b17023SJohn Marino void streamer_tree_cache_append (struct streamer_tree_cache_d *, tree);
94*e4b17023SJohn Marino bool streamer_tree_cache_lookup (struct streamer_tree_cache_d *, tree,
95*e4b17023SJohn Marino unsigned *);
96*e4b17023SJohn Marino tree streamer_tree_cache_get (struct streamer_tree_cache_d *, unsigned);
97*e4b17023SJohn Marino struct streamer_tree_cache_d *streamer_tree_cache_create (void);
98*e4b17023SJohn Marino void streamer_tree_cache_delete (struct streamer_tree_cache_d *);
99*e4b17023SJohn Marino
100*e4b17023SJohn Marino #endif /* GCC_TREE_STREAMER_H */
101