1*38fd1498Szrj /* Data structures and functions for streaming trees.
2*38fd1498Szrj
3*38fd1498Szrj Copyright (C) 2011-2018 Free Software Foundation, Inc.
4*38fd1498Szrj Contributed by Diego Novillo <dnovillo@google.com>
5*38fd1498Szrj
6*38fd1498Szrj This file is part of GCC.
7*38fd1498Szrj
8*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
9*38fd1498Szrj the terms of the GNU General Public License as published by the Free
10*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
11*38fd1498Szrj version.
12*38fd1498Szrj
13*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16*38fd1498Szrj for more details.
17*38fd1498Szrj
18*38fd1498Szrj You should have received a copy of the GNU General Public License
19*38fd1498Szrj along with GCC; see the file COPYING3. If not see
20*38fd1498Szrj <http://www.gnu.org/licenses/>. */
21*38fd1498Szrj
22*38fd1498Szrj #ifndef GCC_TREE_STREAMER_H
23*38fd1498Szrj #define GCC_TREE_STREAMER_H
24*38fd1498Szrj
25*38fd1498Szrj #include "streamer-hooks.h"
26*38fd1498Szrj #include "data-streamer.h"
27*38fd1498Szrj
28*38fd1498Szrj /* Cache of pickled nodes. Used to avoid writing the same node more
29*38fd1498Szrj than once. The first time a tree node is streamed out, it is
30*38fd1498Szrj entered in this cache. Subsequent references to the same node are
31*38fd1498Szrj resolved by looking it up in this cache.
32*38fd1498Szrj
33*38fd1498Szrj This is used in two ways:
34*38fd1498Szrj
35*38fd1498Szrj - On the writing side, the first time T is added to STREAMER_CACHE,
36*38fd1498Szrj a new reference index is created for T and T is emitted on the
37*38fd1498Szrj stream. If T needs to be emitted again to the stream, instead of
38*38fd1498Szrj pickling it again, the reference index is emitted.
39*38fd1498Szrj
40*38fd1498Szrj - On the reading side, the first time T is read from the stream, it
41*38fd1498Szrj is reconstructed in memory and a new reference index created for
42*38fd1498Szrj T. The reconstructed T is inserted in some array so that when
43*38fd1498Szrj the reference index for T is found in the input stream, it can be
44*38fd1498Szrj used to look up into the array to get the reconstructed T. */
45*38fd1498Szrj
46*38fd1498Szrj struct streamer_tree_cache_d
47*38fd1498Szrj {
48*38fd1498Szrj /* The mapping between tree nodes and slots into the nodes array. */
49*38fd1498Szrj hash_map<tree, unsigned> *node_map;
50*38fd1498Szrj
51*38fd1498Szrj /* The nodes pickled so far. */
52*38fd1498Szrj vec<tree> nodes;
53*38fd1498Szrj /* The node hashes (if available). */
54*38fd1498Szrj vec<hashval_t> hashes;
55*38fd1498Szrj
56*38fd1498Szrj /* Next index to assign. */
57*38fd1498Szrj unsigned next_idx;
58*38fd1498Szrj };
59*38fd1498Szrj
60*38fd1498Szrj /* In tree-streamer-in.c. */
61*38fd1498Szrj tree streamer_read_string_cst (struct data_in *, struct lto_input_block *);
62*38fd1498Szrj tree streamer_read_chain (struct lto_input_block *, struct data_in *);
63*38fd1498Szrj tree streamer_alloc_tree (struct lto_input_block *, struct data_in *,
64*38fd1498Szrj enum LTO_tags);
65*38fd1498Szrj void streamer_read_tree_body (struct lto_input_block *, struct data_in *, tree);
66*38fd1498Szrj tree streamer_get_pickled_tree (struct lto_input_block *, struct data_in *);
67*38fd1498Szrj void streamer_read_tree_bitfields (struct lto_input_block *,
68*38fd1498Szrj struct data_in *, tree);
69*38fd1498Szrj
70*38fd1498Szrj /* In tree-streamer-out.c. */
71*38fd1498Szrj void streamer_write_string_cst (struct output_block *,
72*38fd1498Szrj struct lto_output_stream *, tree);
73*38fd1498Szrj void streamer_write_chain (struct output_block *, tree, bool);
74*38fd1498Szrj void streamer_write_tree_header (struct output_block *, tree);
75*38fd1498Szrj void streamer_write_tree_bitfields (struct output_block *, tree);
76*38fd1498Szrj void streamer_write_tree_body (struct output_block *, tree, bool);
77*38fd1498Szrj void streamer_write_integer_cst (struct output_block *, tree, bool);
78*38fd1498Szrj
79*38fd1498Szrj /* In tree-streamer.c. */
80*38fd1498Szrj extern unsigned char streamer_mode_table[1 << 8];
81*38fd1498Szrj void streamer_check_handled_ts_structures (void);
82*38fd1498Szrj bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree,
83*38fd1498Szrj hashval_t, unsigned *);
84*38fd1498Szrj void streamer_tree_cache_replace_tree (struct streamer_tree_cache_d *, tree,
85*38fd1498Szrj unsigned);
86*38fd1498Szrj void streamer_tree_cache_append (struct streamer_tree_cache_d *, tree,
87*38fd1498Szrj hashval_t);
88*38fd1498Szrj bool streamer_tree_cache_lookup (struct streamer_tree_cache_d *, tree,
89*38fd1498Szrj unsigned *);
90*38fd1498Szrj struct streamer_tree_cache_d *streamer_tree_cache_create (bool, bool, bool);
91*38fd1498Szrj void streamer_tree_cache_delete (struct streamer_tree_cache_d *);
92*38fd1498Szrj
93*38fd1498Szrj /* Return the tree node at slot IX in CACHE. */
94*38fd1498Szrj
95*38fd1498Szrj static inline tree
streamer_tree_cache_get_tree(struct streamer_tree_cache_d * cache,unsigned ix)96*38fd1498Szrj streamer_tree_cache_get_tree (struct streamer_tree_cache_d *cache, unsigned ix)
97*38fd1498Szrj {
98*38fd1498Szrj return cache->nodes[ix];
99*38fd1498Szrj }
100*38fd1498Szrj
101*38fd1498Szrj /* Return the tree hash value at slot IX in CACHE. */
102*38fd1498Szrj
103*38fd1498Szrj static inline hashval_t
streamer_tree_cache_get_hash(struct streamer_tree_cache_d * cache,unsigned ix)104*38fd1498Szrj streamer_tree_cache_get_hash (struct streamer_tree_cache_d *cache, unsigned ix)
105*38fd1498Szrj {
106*38fd1498Szrj return cache->hashes[ix];
107*38fd1498Szrj }
108*38fd1498Szrj
109*38fd1498Szrj static inline void
bp_pack_machine_mode(struct bitpack_d * bp,machine_mode mode)110*38fd1498Szrj bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode)
111*38fd1498Szrj {
112*38fd1498Szrj streamer_mode_table[mode] = 1;
113*38fd1498Szrj bp_pack_enum (bp, machine_mode, 1 << 8, mode);
114*38fd1498Szrj }
115*38fd1498Szrj
116*38fd1498Szrj static inline machine_mode
bp_unpack_machine_mode(struct bitpack_d * bp)117*38fd1498Szrj bp_unpack_machine_mode (struct bitpack_d *bp)
118*38fd1498Szrj {
119*38fd1498Szrj return (machine_mode)
120*38fd1498Szrj ((struct lto_input_block *)
121*38fd1498Szrj bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, 1 << 8)];
122*38fd1498Szrj }
123*38fd1498Szrj
124*38fd1498Szrj #endif /* GCC_TREE_STREAMER_H */
125