GCC Middle and Back End API Reference
region-model-manager.h
Go to the documentation of this file.
1/* Consolidation of svalues and regions.
2 Copyright (C) 2020-2026 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_ANALYZER_REGION_MODEL_MANAGER_H
22#define GCC_ANALYZER_REGION_MODEL_MANAGER_H
23
24namespace ana {
25
26/* A class responsible for owning and consolidating region and svalue
27 instances.
28 region and svalue instances are immutable as far as clients are
29 concerned, so they are provided as "const" ptrs. */
30
32{
33public:
36
37 unsigned get_num_symbols () const { return m_next_symbol_id; }
38 unsigned alloc_symbol_id () { return m_next_symbol_id++; }
39
40 /* call_string consolidation. */
42 {
44 }
45
46 /* svalue consolidation. */
50 const svalue *get_or_create_null_ptr (tree pointer_type);
53 tree type);
55 tree type);
57 bool check_poisoned = true);
58 const svalue *get_ptr_svalue (tree ptr_type, const region *pointee);
60 const svalue *arg);
63 enum tree_code op,
64 const svalue *arg0, const svalue *arg1);
66 const svalue *parent_svalue,
67 const region *subregion);
69 const svalue *outer_size,
70 const svalue *inner_svalue);
72 const bit_range &bits,
73 const svalue *inner_svalue);
76 const supernode *snode,
77 const svalue *base_svalue,
78 const svalue *iter_svalue);
82 const concrete_binding_map &map);
84 const region *id_reg,
85 const conjured_purge &p,
86 unsigned idx = 0);
87 const svalue *
89 const gasm *asm_stmt,
90 unsigned output_idx,
91 const vec<const svalue *> &inputs);
92 const svalue *
94 const char *asm_string,
95 unsigned output_idx,
96 unsigned num_outputs,
97 const vec<const svalue *> &inputs);
98 const svalue *
100 tree fndecl,
101 const vec<const svalue *> &inputs);
102
104 tree byte_offset_cst);
106 tree byte_offset_cst);
108 tree byte_offset_cst);
109
110 /* Dynamically-allocated svalue instances.
111 The number of these within the analysis can grow arbitrarily.
112 They are still owned by the manager. */
114
115 /* region consolidation. */
116 const root_region *get_root_region () const { return &m_root_region; }
117 const stack_region * get_stack_region () const { return &m_stack_region; }
118 const heap_region *get_heap_region () const { return &m_heap_region; }
119 const code_region *get_code_region () const { return &m_code_region; }
121 {
122 return &m_globals_region;
123 }
124 const errno_region *get_errno_region () const { return &m_errno_region; }
128 const region *get_field_region (const region *parent, tree field);
129 const region *get_element_region (const region *parent,
130 tree element_type,
131 const svalue *index);
132 const region *get_offset_region (const region *parent,
133 tree type,
134 const svalue *byte_offset);
135 const region *get_sized_region (const region *parent,
136 tree type,
137 const svalue *byte_size_sval);
138 const region *get_cast_region (const region *original_region,
139 tree type);
140 const frame_region *get_frame_region (const frame_region *calling_frame,
141 const function &fun);
142 const region *get_symbolic_region (const svalue *sval);
144 const region *get_bit_range (const region *parent, tree type,
145 const bit_range &bits);
147 unsigned idx);
148
150
151 const region *
153 tree t,
154 const dump_location_t &loc);
155
158
163
164 /* Dynamically-allocated region instances.
165 The number of these within the analysis can grow arbitrarily.
166 They are still owned by the manager. */
167 const region *
170
171 void log_stats (logger *logger, bool show_objs) const;
172
175
176 logger *get_logger () const { return m_logger; }
177
179
181 const svalue *arg0, const svalue *arg1);
182private:
183 bool too_complex_p (const complexity &c) const;
185
186 const svalue *
188 const binop_svalue *binop);
190 const svalue *arg);
192 const svalue *parent_svalue,
193 const region *subregion);
195 const svalue *outer_size,
196 const svalue *inner_svalue);
198 const bit_range &bits,
199 const svalue *inner_svalue);
201 const compound_svalue *compound_sval,
202 tree cst, const svalue *arg1);
204 const vec<const svalue *> &inputs);
205
207
209
211
215
216 /* svalue consolidation. */
217 typedef std::map<constant_svalue::key_t, constant_svalue *> constants_map_t;
219
220 typedef std::map<tree, unknown_svalue *> unknowns_map_t;
223
224 typedef std::map<poisoned_svalue::key_t,
227
228 typedef std::map<setjmp_svalue::key_t,
231
232 typedef std::map<const region *, initial_svalue *> initial_values_map_t;
234
235 typedef std::map<region_svalue::key_t, region_svalue *> pointer_values_map_t;
237
238 typedef std::map<unaryop_svalue::key_t,
241
242 typedef std::map<binop_svalue::key_t, binop_svalue *> binop_values_map_t;
244
245 typedef std::map<sub_svalue::key_t, sub_svalue *> sub_values_map_t;
247
248 typedef std::map<repeated_svalue::key_t,
251
252 typedef std::map<bits_within_svalue::key_t,
255
256 typedef std::map<const svalue *,
259
260 typedef std::map<widening_svalue::key_t,
263
264 typedef std::map<compound_svalue::key_t,
267
268 typedef std::map<conjured_svalue::key_t,
271
272 typedef std::map<asm_output_svalue::key_t,
275
276 typedef std::map<const_fn_result_svalue::key_t,
279
281
282 /* "Dynamically-allocated" svalue instances.
283 The number of these within the analysis can grow arbitrarily.
284 They are still owned by the manager. */
286
287 /* Maximum complexity of svalues that weren't rejected. */
289
290 /* region consolidation. */
291
293 typedef std::map<tree, function_region *> fndecls_map_t;
294 typedef fndecls_map_t::iterator fndecls_iterator_t;
296
297 typedef std::map<tree, label_region *> labels_map_t;
298 typedef labels_map_t::iterator labels_iterator_t;
300
302 typedef std::map<tree, decl_region *> globals_map_t;
303 typedef globals_map_t::iterator globals_iterator_t;
305
308
316
317 typedef std::map<tree, string_region *> string_map_t;
319
322
324
326
328
329 /* "Dynamically-allocated" region instances.
330 The number of these within the analysis can grow arbitrarily.
331 They are still owned by the manager. */
333};
334
335} // namespace ana
336
337#endif /* GCC_ANALYZER_REGION_MODEL_MANAGER_H */
Definition svalue.h:1430
Definition svalue.h:726
Definition svalue.h:954
Definition constraint-manager.h:178
Definition call-string.h:41
Definition region.h:454
Definition svalue.h:1235
Definition store.h:524
Definition svalue.h:1321
Definition svalue.h:1352
Definition svalue.h:1550
Definition region.h:743
Definition region.h:1489
Definition region.h:320
Definition region.h:482
Definition region.h:426
Definition region.h:584
Definition known-function-manager.h:41
Definition region.h:521
Definition analyzer-logging.h:36
Definition svalue.h:432
Definition region-model.h:754
initial_values_map_t m_initial_values_map
Definition region-model-manager.h:233
known_function_manager m_known_fn_mgr
Definition region-model-manager.h:327
std::map< asm_output_svalue::key_t, asm_output_svalue * > asm_output_values_map_t
Definition region-model-manager.h:273
const function_region * get_region_for_fndecl(tree fndecl)
const svalue * get_or_create_cast(tree type, const svalue *arg)
asm_output_values_map_t m_asm_output_values_map
Definition region-model-manager.h:274
bool reject_if_too_complex(svalue *sval)
globals_map_t::iterator globals_iterator_t
Definition region-model-manager.h:303
const region * get_field_region(const region *parent, tree field)
consolidation_map< offset_region > m_offset_regions
Definition region-model-manager.h:311
const svalue * maybe_fold_unaryop(tree type, enum tree_code op, const svalue *arg)
errno_region m_errno_region
Definition region-model-manager.h:307
const svalue * get_or_create_int_cst(tree type, const poly_wide_int_ref &cst)
const code_region * get_code_region() const
Definition region-model-manager.h:119
consolidation_map< var_arg_region > m_var_arg_regions
Definition region-model-manager.h:321
const svalue * get_or_create_bits_within(tree type, const bit_range &bits, const svalue *inner_svalue)
std::map< compound_svalue::key_t, compound_svalue * > compound_values_map_t
Definition region-model-manager.h:265
std::map< const_fn_result_svalue::key_t, const_fn_result_svalue * > const_fn_result_values_map_t
Definition region-model-manager.h:277
auto_delete_vec< svalue > m_managed_dynamic_svalues
Definition region-model-manager.h:285
const svalue * create_unique_svalue(tree type)
const svalue * maybe_fold_bits_within_svalue(tree type, const bit_range &bits, const svalue *inner_svalue)
pointer_values_map_t m_pointer_values_map
Definition region-model-manager.h:236
const region * create_region_for_alloca(const frame_region *frame)
const svalue * get_or_create_widening_svalue(tree type, const supernode *snode, const svalue *base_svalue, const svalue *iter_svalue)
bool m_checking_feasibility
Definition region-model-manager.h:280
labels_map_t::iterator labels_iterator_t
Definition region-model-manager.h:298
const svalue * get_or_create_initial_value(const region *reg, bool check_poisoned=true)
const svalue * get_or_create_binop(tree type, enum tree_code op, const svalue *arg0, const svalue *arg1)
std::map< tree, unknown_svalue * > unknowns_map_t
Definition region-model-manager.h:220
const svalue * maybe_get_char_from_string_cst(tree string_cst, tree byte_offset_cst)
bounded_ranges_manager * m_range_mgr
Definition region-model-manager.h:325
code_region m_code_region
Definition region-model-manager.h:292
const region * get_element_region(const region *parent, tree element_type, const svalue *index)
std::map< region_svalue::key_t, region_svalue * > pointer_values_map_t
Definition region-model-manager.h:235
const svalue * get_or_create_compound_svalue(tree type, const concrete_binding_map &map)
std::map< binop_svalue::key_t, binop_svalue * > binop_values_map_t
Definition region-model-manager.h:242
compound_values_map_t m_compound_values_map
Definition region-model-manager.h:266
setjmp_values_map_t m_setjmp_values_map
Definition region-model-manager.h:230
consolidation_map< frame_region > m_frame_regions
Definition region-model-manager.h:314
const errno_region * get_errno_region() const
Definition region-model-manager.h:124
const_fn_result_values_map_t m_const_fn_result_values_map
Definition region-model-manager.h:278
const region * get_bit_range(const region *parent, tree type, const bit_range &bits)
std::map< repeated_svalue::key_t, repeated_svalue * > repeated_values_map_t
Definition region-model-manager.h:249
consolidation_map< symbolic_region > m_symbolic_regions
Definition region-model-manager.h:315
const region * get_symbolic_region(const svalue *sval)
const svalue * maybe_fold_asm_output_svalue(tree type, const vec< const svalue * > &inputs)
std::map< tree, label_region * > labels_map_t
Definition region-model-manager.h:297
std::map< setjmp_svalue::key_t, setjmp_svalue * > setjmp_values_map_t
Definition region-model-manager.h:229
bool too_complex_p(const complexity &c) const
consolidation_map< cast_region > m_cast_regions
Definition region-model-manager.h:313
const svalue * get_ptr_svalue(tree ptr_type, const region *pointee)
fndecls_map_t m_fndecls_map
Definition region-model-manager.h:295
std::map< tree, function_region * > fndecls_map_t
Definition region-model-manager.h:293
sub_values_map_t m_sub_values_map
Definition region-model-manager.h:246
const unknown_svalue * m_unknown_NULL
Definition region-model-manager.h:222
unaryop_values_map_t m_unaryop_values_map
Definition region-model-manager.h:240
unsigned m_next_symbol_id
Definition region-model-manager.h:208
conjured_values_map_t m_conjured_values_map
Definition region-model-manager.h:270
const svalue * maybe_get_char_from_raw_data_cst(tree raw_data_cst, tree byte_offset_cst)
std::map< poisoned_svalue::key_t, poisoned_svalue * > poisoned_values_map_t
Definition region-model-manager.h:225
widening_values_map_t m_widening_values_map
Definition region-model-manager.h:262
const heap_region * get_heap_region() const
Definition region-model-manager.h:118
const region * get_region_for_unexpected_tree_code(region_model_context *ctxt, tree t, const dump_location_t &loc)
std::map< constant_svalue::key_t, constant_svalue * > constants_map_t
Definition region-model-manager.h:217
bounded_ranges_manager * get_range_manager() const
Definition region-model-manager.h:157
void log_stats(logger *logger, bool show_objs) const
const svalue * get_or_create_compound_svalue(tree type, concrete_binding_map &&map)
binop_values_map_t m_binop_values_map
Definition region-model-manager.h:243
globals_map_t m_globals_map
Definition region-model-manager.h:304
constants_map_t m_constants_map
Definition region-model-manager.h:218
const globals_region * get_globals_region() const
Definition region-model-manager.h:120
const region * get_or_create_region_for_heap_alloc(const bitmap &base_regs_in_use)
std::map< conjured_svalue::key_t, conjured_svalue * > conjured_values_map_t
Definition region-model-manager.h:269
string_map_t m_string_map
Definition region-model-manager.h:318
poisoned_values_map_t m_poisoned_values_map
Definition region-model-manager.h:226
const svalue * get_or_create_constant_svalue(tree cst_expr)
store_manager * get_store_manager()
Definition region-model-manager.h:156
consolidation_map< sized_region > m_sized_regions
Definition region-model-manager.h:312
const call_string m_empty_call_string
Definition region-model-manager.h:210
bits_within_values_map_t m_bits_within_values_map
Definition region-model-manager.h:254
logger * get_logger() const
Definition region-model-manager.h:176
const svalue * maybe_fold_repeated_svalue(tree type, const svalue *outer_size, const svalue *inner_svalue)
void end_checking_feasibility(void)
Definition region-model-manager.h:174
const stack_region * get_stack_region() const
Definition region-model-manager.h:117
region_model_manager(logger *logger=nullptr)
const string_region * get_region_for_string(tree string_cst)
const root_region * get_root_region() const
Definition region-model-manager.h:116
const svalue * get_or_create_constant_svalue(tree type, tree cst_expr)
root_region m_root_region
Definition region-model-manager.h:212
std::map< bits_within_svalue::key_t, bits_within_svalue * > bits_within_values_map_t
Definition region-model-manager.h:253
const svalue * get_or_create_setjmp_svalue(const setjmp_record &r, tree type)
consolidation_map< field_region > m_field_regions
Definition region-model-manager.h:309
const svalue * maybe_fold_binop(tree type, enum tree_code op, const svalue *arg0, const svalue *arg1)
consolidation_map< bit_range_region > m_bit_range_regions
Definition region-model-manager.h:320
const label_region * get_region_for_label(tree label)
heap_region m_heap_region
Definition region-model-manager.h:214
const svalue * get_or_create_const_fn_result_svalue(tree type, tree fndecl, const vec< const svalue * > &inputs)
const region * get_offset_region(const region *parent, tree type, const svalue *byte_offset)
const frame_region * get_frame_region(const frame_region *calling_frame, const function &fun)
fndecls_map_t::iterator fndecls_iterator_t
Definition region-model-manager.h:294
consolidation_map< element_region > m_element_regions
Definition region-model-manager.h:310
repeated_values_map_t m_repeated_values_map
Definition region-model-manager.h:250
store_manager m_store_mgr
Definition region-model-manager.h:323
const svalue * get_or_create_poisoned_svalue(enum poison_kind kind, tree type)
std::map< const svalue *, unmergeable_svalue * > unmergeable_values_map_t
Definition region-model-manager.h:257
void begin_checking_feasibility(void)
Definition region-model-manager.h:173
unknowns_map_t m_unknowns_map
Definition region-model-manager.h:221
const svalue * get_or_create_null_ptr(tree pointer_type)
const decl_region * get_region_for_global(tree expr)
const call_string & get_empty_call_string() const
Definition region-model-manager.h:41
globals_region m_globals_region
Definition region-model-manager.h:301
auto_delete_vec< region > m_managed_dynamic_regions
Definition region-model-manager.h:332
const svalue * get_or_create_asm_output_svalue(tree type, const gasm *asm_stmt, unsigned output_idx, const vec< const svalue * > &inputs)
known_function_manager * get_known_function_manager()
Definition region-model-manager.h:159
std::map< widening_svalue::key_t, widening_svalue * > widening_values_map_t
Definition region-model-manager.h:261
const svalue * get_or_create_asm_output_svalue(tree type, const char *asm_string, unsigned output_idx, unsigned num_outputs, const vec< const svalue * > &inputs)
const svalue * maybe_undo_optimize_bit_field_compare(tree type, const compound_svalue *compound_sval, tree cst, const svalue *arg1)
const svalue * get_or_create_unmergeable(const svalue *arg)
const svalue * maybe_fold_sub_svalue(tree type, const svalue *parent_svalue, const region *subregion)
const region * get_sized_region(const region *parent, tree type, const svalue *byte_size_sval)
stack_region m_stack_region
Definition region-model-manager.h:213
std::map< tree, string_region * > string_map_t
Definition region-model-manager.h:317
const svalue * get_or_create_conjured_svalue(tree type, const gimple *stmt, const region *id_reg, const conjured_purge &p, unsigned idx=0)
const var_arg_region * get_var_arg_region(const frame_region *parent, unsigned idx)
std::map< unaryop_svalue::key_t, unaryop_svalue * > unaryop_values_map_t
Definition region-model-manager.h:239
logger * m_logger
Definition region-model-manager.h:206
unmergeable_values_map_t m_unmergeable_values_map
Definition region-model-manager.h:258
const svalue * maybe_get_char_from_cst(tree data_cst, tree byte_offset_cst)
std::map< sub_svalue::key_t, sub_svalue * > sub_values_map_t
Definition region-model-manager.h:245
const region * get_unknown_symbolic_region(tree region_type)
std::map< const region *, initial_svalue * > initial_values_map_t
Definition region-model-manager.h:232
thread_local_region m_thread_local_region
Definition region-model-manager.h:306
const svalue * get_or_create_unknown_svalue(tree type)
void dump_untracked_regions() const
const svalue * get_or_create_repeated_svalue(tree type, const svalue *outer_size, const svalue *inner_svalue)
unsigned alloc_symbol_id()
Definition region-model-manager.h:38
const svalue * maybe_invert_comparison_in_unaryop(tree type, const binop_svalue *binop)
unsigned get_num_symbols() const
Definition region-model-manager.h:37
const svalue * get_or_create_sub_svalue(tree type, const svalue *parent_svalue, const region *subregion)
std::map< tree, decl_region * > globals_map_t
Definition region-model-manager.h:302
const region * get_cast_region(const region *original_region, tree type)
complexity m_max_complexity
Definition region-model-manager.h:288
const svalue * get_or_create_unaryop(tree type, enum tree_code op, const svalue *arg)
labels_map_t m_labels_map
Definition region-model-manager.h:299
Definition region.h:127
Definition svalue.h:877
Definition region.h:639
Definition svalue.h:534
Definition region.h:556
Definition store.h:1045
Definition region.h:1277
Definition supergraph.h:227
Definition svalue.h:92
Definition region.h:611
Definition svalue.h:650
Definition svalue.h:380
Definition svalue.h:1038
Definition region.h:1407
Definition svalue.h:1133
Definition vec.h:1813
Definition common.h:624
Definition dumpfile.h:446
Definition genmatch.cc:1625
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
tree_code
Definition genmatch.cc:1011
Definition access-diagram.h:30
poison_kind
Definition svalue.h:412
poly_int< NUM_POLY_INT_COEFFS, wide_int_ref > poly_wide_int_ref
Definition poly-int-types.h:28
poly_int< N, C > r
Definition poly-int.h:774
Definition svalue.h:1438
Definition store.h:234
Definition svalue.h:958
Definition complexity.h:31
Definition svalue.h:1244
Definition svalue.h:1356
Definition svalue.h:1558
Definition svalue.h:436
Definition svalue.h:881
Definition svalue.h:506
Definition svalue.h:538
Definition svalue.h:654
Definition svalue.h:1137
Definition function.h:249
Definition gimple.h:552
Definition gimple.h:224
Definition gengtype.h:252
Definition vec.h:450