GCC Middle and Back End API Reference
tree-streamer.h
Go to the documentation of this file.
1/* Data structures and functions for streaming trees.
2
3 Copyright (C) 2011-2026 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@google.com>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_TREE_STREAMER_H
23#define GCC_TREE_STREAMER_H
24
25#include "streamer-hooks.h"
26#include "data-streamer.h"
27
28/* Cache of pickled nodes. Used to avoid writing the same node more
29 than once. The first time a tree node is streamed out, it is
30 entered in this cache. Subsequent references to the same node are
31 resolved by looking it up in this cache.
32
33 This is used in two ways:
34
35 - On the writing side, the first time T is added to STREAMER_CACHE,
36 a new reference index is created for T and T is emitted on the
37 stream. If T needs to be emitted again to the stream, instead of
38 pickling it again, the reference index is emitted.
39
40 - On the reading side, the first time T is read from the stream, it
41 is reconstructed in memory and a new reference index created for
42 T. The reconstructed T is inserted in some array so that when
43 the reference index for T is found in the input stream, it can be
44 used to look up into the array to get the reconstructed T. */
45
47{
48 /* The mapping between tree nodes and slots into the nodes array. */
50
51 /* The nodes pickled so far. */
53 /* The node hashes (if available). */
55
56 /* Next index to assign. */
57 unsigned next_idx;
58};
59
60/* In tree-streamer-in.cc. */
63 enum LTO_tags);
65 int *);
68 class data_in *, tree);
69
70/* In tree-streamer-out.cc. */
72 struct lto_output_stream *, tree);
77
78/* In tree-streamer.cc. */
79extern unsigned char streamer_mode_table[MAX_MACHINE_MODE];
82 hashval_t, unsigned *);
84 unsigned);
86 hashval_t);
88 unsigned *);
89struct streamer_tree_cache_d *streamer_tree_cache_create (bool, bool, bool);
91
92/* Return the tree node at slot IX in CACHE. */
93
94inline tree
96{
97 return cache->nodes[ix];
98}
99
100/* Return the tree hash value at slot IX in CACHE. */
101
102inline hashval_t
104{
105 return cache->hashes[ix];
106}
107
108inline void
109bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode)
110{
111 streamer_mode_table[mode] = 1;
112 int last = 1 << ceil_log2 (MAX_MACHINE_MODE);
113 bp_pack_enum (bp, machine_mode, last, mode);
114}
115
116inline machine_mode
118{
119 lto_input_block *ib = (class lto_input_block *) bp->stream;
120 int last = 1 << ib->file_data->mode_bits;
121 unsigned ix = bp_unpack_enum (bp, machine_mode, last);
122 if (ib->file_data->mode_table)
123 return (machine_mode) ib->file_data->mode_table[ix];
124 else
125 return (machine_mode) ix;
126}
127
128#endif /* GCC_TREE_STREAMER_H */
Definition lto-streamer.h:844
Definition hash-map.h:40
Definition lto-streamer.h:349
const lto_file_decl_data * file_data
Definition lto-streamer.h:361
union tree_node * tree
Definition coretypes.h:97
#define bp_unpack_enum(bp, enum_name, enum_last)
Definition data-streamer.h:375
#define bp_pack_enum(bp, enum_name, enum_last, val)
Definition data-streamer.h:370
int ceil_log2(unsigned HOST_WIDE_INT x)
Definition hwint.cc:73
LTO_tags
Definition lto-streamer.h:134
Definition data-streamer.h:35
void * stream
Definition data-streamer.h:43
unsigned mode_bits
Definition lto-streamer.h:685
const unsigned char * mode_table
Definition lto-streamer.h:676
Definition lto-streamer.h:717
Definition lto-streamer.h:793
Definition tree-streamer.h:47
hash_map< tree, unsigned > * node_map
Definition tree-streamer.h:49
unsigned next_idx
Definition tree-streamer.h:57
vec< hashval_t > hashes
Definition tree-streamer.h:54
vec< tree > nodes
Definition tree-streamer.h:52
Definition vec.h:450
tree streamer_read_string_cst(class data_in *data_in, class lto_input_block *ib)
Definition tree-streamer-in.cc:45
tree streamer_alloc_tree(class lto_input_block *ib, class data_in *data_in, enum LTO_tags tag)
Definition tree-streamer-in.cc:595
tree streamer_get_pickled_tree(class lto_input_block *ib, class data_in *data_in)
Definition tree-streamer-in.cc:1184
void streamer_read_tree_body(class lto_input_block *ib, class data_in *data_in, tree expr, int *origin_ref)
Definition tree-streamer-in.cc:1111
void streamer_read_tree_bitfields(class lto_input_block *ib, class data_in *data_in, tree expr)
Definition tree-streamer-in.cc:501
void streamer_write_string_cst(struct output_block *ob, struct lto_output_stream *index_stream, tree string)
Definition tree-streamer-out.cc:41
void streamer_write_tree_body(struct output_block *ob, tree expr)
Definition tree-streamer-out.cc:928
void streamer_write_integer_cst(struct output_block *ob, tree cst)
Definition tree-streamer-out.cc:1090
void streamer_write_tree_header(struct output_block *ob, tree expr)
Definition tree-streamer-out.cc:1004
void streamer_write_tree_bitfields(struct output_block *ob, tree expr)
Definition tree-streamer-out.cc:463
void streamer_tree_cache_append(struct streamer_tree_cache_d *cache, tree t, hashval_t hash)
Definition tree-streamer.cc:210
bool streamer_tree_cache_insert(struct streamer_tree_cache_d *cache, tree t, hashval_t hash, unsigned *ix_p)
Definition tree-streamer.cc:184
bool streamer_tree_cache_lookup(struct streamer_tree_cache_d *cache, tree t, unsigned *ix_p)
Definition tree-streamer.cc:225
struct streamer_tree_cache_d * streamer_tree_cache_create(bool with_hashes, bool with_map, bool with_vec)
Definition tree-streamer.cc:400
void streamer_tree_cache_replace_tree(struct streamer_tree_cache_d *cache, tree t, unsigned ix)
Definition tree-streamer.cc:194
void streamer_check_handled_ts_structures(void)
Definition tree-streamer.cc:45
void streamer_tree_cache_delete(struct streamer_tree_cache_d *c)
Definition tree-streamer.cc:426
unsigned char streamer_mode_table[MAX_MACHINE_MODE]
Definition tree-streamer.cc:38
void bp_pack_machine_mode(struct bitpack_d *bp, machine_mode mode)
Definition tree-streamer.h:109
machine_mode bp_unpack_machine_mode(struct bitpack_d *bp)
Definition tree-streamer.h:117
tree streamer_tree_cache_get_tree(struct streamer_tree_cache_d *cache, unsigned ix)
Definition tree-streamer.h:95
hashval_t streamer_tree_cache_get_hash(struct streamer_tree_cache_d *cache, unsigned ix)
Definition tree-streamer.h:103