| 1 |
/* Data structures and functions for streaming trees. |
| 2 |
|
| 3 |
Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Diego Novillo <[email protected]> |
| 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 |
#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 |
|
| 46 |
struct streamer_tree_cache_d |
| 47 |
{ |
| 48 |
/* The mapping between tree nodes and slots into the nodes array. */ |
| 49 |
hash_map<tree, unsigned> *node_map; |
| 50 |
|
| 51 |
/* The nodes pickled so far. */ |
| 52 |
vec<tree> nodes; |
| 53 |
/* The node hashes (if available). */ |
| 54 |
vec<hashval_t> hashes; |
| 55 |
|
| 56 |
/* Next index to assign. */ |
| 57 |
unsigned next_idx; |
| 58 |
}; |
| 59 |
|
| 60 |
/* In tree-streamer-in.cc. */ |
| 61 |
tree streamer_read_string_cst (class data_in *, class lto_input_block *); |
| 62 |
tree streamer_alloc_tree (class lto_input_block *, class data_in *, |
| 63 |
enum LTO_tags); |
| 64 |
void streamer_read_tree_body (class lto_input_block *, class data_in *, tree); |
| 65 |
tree streamer_get_pickled_tree (class lto_input_block *, class data_in *); |
| 66 |
void streamer_read_tree_bitfields (class lto_input_block *, |
| 67 |
class data_in *, tree); |
| 68 |
|
| 69 |
/* In tree-streamer-out.cc. */ |
| 70 |
void streamer_write_string_cst (struct output_block *, |
| 71 |
struct lto_output_stream *, tree); |
| 72 |
void streamer_write_tree_header (struct output_block *, tree); |
| 73 |
void streamer_write_tree_bitfields (struct output_block *, tree); |
| 74 |
void streamer_write_tree_body (struct output_block *, tree); |
| 75 |
void streamer_write_integer_cst (struct output_block *, tree); |
| 76 |
|
| 77 |
/* In tree-streamer.cc. */ |
| 78 |
extern unsigned char streamer_mode_table[MAX_MACHINE_MODE]; |
| 79 |
void streamer_check_handled_ts_structures (void); |
| 80 |
bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree, |
| 81 |
hashval_t, unsigned *); |
| 82 |
void streamer_tree_cache_replace_tree (struct streamer_tree_cache_d *, tree, |
| 83 |
unsigned); |
| 84 |
void streamer_tree_cache_append (struct streamer_tree_cache_d *, tree, |
| 85 |
hashval_t); |
| 86 |
bool streamer_tree_cache_lookup (struct streamer_tree_cache_d *, tree, |
| 87 |
unsigned *); |
| 88 |
struct streamer_tree_cache_d *streamer_tree_cache_create (bool, bool, bool); |
| 89 |
void streamer_tree_cache_delete (struct streamer_tree_cache_d *); |
| 90 |
|
| 91 |
/* Return the tree node at slot IX in CACHE. */ |
| 92 |
|
| 93 |
inline tree |
| 94 |
streamer_tree_cache_get_tree (struct streamer_tree_cache_d *cache, unsigned ix) |
| 95 |
{ |
| 96 |
return cache->nodes[ix]; |
| 97 |
} |
| 98 |
|
| 99 |
/* Return the tree hash value at slot IX in CACHE. */ |
| 100 |
|
| 101 |
inline hashval_t |
| 102 |
streamer_tree_cache_get_hash (struct streamer_tree_cache_d *cache, unsigned ix) |
| 103 |
{ |
| 104 |
return cache->hashes[ix]; |
| 105 |
} |
| 106 |
|
| 107 |
inline void |
| 108 |
bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode) |
| 109 |
{ |
| 110 |
streamer_mode_table[mode] = 1; |
| 111 |
int last = 1 << ceil_log2 (MAX_MACHINE_MODE); |
| 112 |
bp_pack_enum (bp, machine_mode, last, mode); |
| 113 |
} |
| 114 |
|
| 115 |
inline machine_mode |
| 116 |
bp_unpack_machine_mode (struct bitpack_d *bp) |
| 117 |
{ |
| 118 |
lto_input_block *ib = (class lto_input_block *) bp->stream; |
| 119 |
int last = 1 << ib->file_data->mode_bits; |
| 120 |
unsigned ix = bp_unpack_enum (bp, machine_mode, last); |
| 121 |
if (ib->file_data->mode_table) |
| 122 |
return (machine_mode) ib->file_data->mode_table[ix]; |
| 123 |
else |
| 124 |
return (machine_mode) ix; |
| 125 |
} |
| 126 |
|
| 127 |
#endif /* GCC_TREE_STREAMER_H */ |