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
24#include "svalue.h"
25#include "region.h"
27
28namespace ana {
29
30/* A class responsible for owning and consolidating region and svalue
31 instances.
32 region and svalue instances are immutable as far as clients are
33 concerned, so they are provided as "const" ptrs. */
34
36{
37public:
39 logger *logger = nullptr);
41
42 unsigned
44
45 /* call_string consolidation. */
47 {
49 }
50
51 /* svalue consolidation. */
55 const svalue *get_or_create_null_ptr (tree pointer_type);
58 tree type);
60 tree type);
62 bool check_poisoned = true);
63 const svalue *get_ptr_svalue (tree ptr_type, const region *pointee);
66 const svalue *arg);
69 enum tree_code op,
70 const svalue *arg0, const svalue *arg1);
72 const symbolic::bit_vector &bv);
73 template <typename ConcreteValueType>
78 const supernode *snode,
79 const svalue *base_svalue,
80 const svalue *iter_svalue);
82 const region *id_reg,
83 const conjured_purge &p,
84 unsigned idx = 0);
85 const svalue *
87 const gasm *asm_stmt,
88 unsigned output_idx,
89 const vec<const svalue *> &inputs);
90 const svalue *
92 const char *asm_string,
93 unsigned output_idx,
94 unsigned num_outputs,
95 const vec<const svalue *> &inputs);
96 const svalue *
98 tree fndecl,
99 const vec<const svalue *> &inputs);
100
101 /* Dynamically-allocated svalue instances.
102 The number of these within the analysis can grow arbitrarily.
103 They are still owned by the manager. */
105
106 /* region consolidation. */
107 const root_region *get_root_region () const { return &m_root_region; }
108
109 const memory_space_region *
110 get_stack_region () const { return &m_stack_region; }
111
112 const memory_space_region *
113 get_heap_region () const { return &m_heap_region; }
114
115 const memory_space_region *
116 get_code_region () const { return &m_code_region; }
117
118 const memory_space_region *
120
121 const errno_region *get_errno_region () const { return &m_errno_region; }
125 const region *get_field_region (const region *parent, tree field);
126 const region *get_element_region (const region *parent,
127 tree element_type,
128 const svalue *index);
129 const region *get_offset_region (const region *parent,
130 tree type,
131 const svalue *byte_offset);
132 const region *get_sized_region (const region *parent,
133 tree type,
134 const svalue *byte_size_sval);
135 const region *get_cast_region (const region *original_region,
136 tree type);
137 const frame_region *get_frame_region (const frame_region *calling_frame,
138 const function &fun);
139 const region *get_symbolic_region (const svalue *sval);
141 const region *get_bit_range (const region *parent, tree type,
142 const concrete_bit_range &bits);
144 unsigned idx);
145
147
148 const region *
150 tree t,
151 const dump_location_t &loc);
152
155 {
156 return m_node_mgr;
157 }
158
160
165
166 /* Dynamically-allocated region instances.
167 The number of these within the analysis can grow arbitrarily.
168 They are still owned by the manager. */
169 const region *
172
173 void log_stats (logger *logger, bool show_objs) const;
174
177
178 logger *get_logger () const { return m_logger; }
179
181
183 const svalue *arg0, const svalue *arg1);
184
185private:
186 bool too_complex_p (const complexity &c) const;
188
189 const svalue *
191 const binop_svalue *binop);
193 const svalue *arg);
195 const symbolic::bit_vector &bv);
197 const vec<const svalue *> &inputs);
198
199 const region *
201 tree type,
202 const svalue *byte_size_sval);
203 const region *
205
208
210
214
215 /* svalue consolidation. */
216 typedef std::map<constant_svalue::key_t, constant_svalue *> constants_map_t;
218
219 typedef std::map<tree, unknown_svalue *> unknowns_map_t;
222
223 typedef std::map<poisoned_svalue::key_t,
226
227 typedef std::map<setjmp_svalue::key_t,
230
231 typedef std::map<const region *, initial_svalue *> initial_values_map_t;
233
234 typedef std::map<pointer_svalue::key_t, pointer_svalue *> pointer_values_map_t;
236
237 typedef std::map<unaryop_svalue::key_t,
240
241 typedef std::map<binop_svalue::key_t, binop_svalue *> binop_values_map_t;
243
244 typedef std::map<svalue_from_bit_vector::key_t,
247
248 typedef std::map<const svalue *,
251
252 typedef std::map<widening_svalue::key_t,
255
256 typedef std::map<asm_output_svalue::key_t,
259
260 typedef std::map<const_fn_result_svalue::key_t,
263
265
266 /* "Dynamically-allocated" svalue instances.
267 The number of these within the analysis can grow arbitrarily.
268 They are still owned by the manager. */
270
271 /* Maximum complexity of svalues that weren't rejected. */
273
274 /* region consolidation. */
275
277 typedef std::map<tree, function_region *> fndecls_map_t;
278 typedef fndecls_map_t::iterator fndecls_iterator_t;
280
281 typedef std::map<tree, label_region *> labels_map_t;
282 typedef labels_map_t::iterator labels_iterator_t;
284
286 typedef std::map<tree, decl_region *> globals_map_t;
287 typedef globals_map_t::iterator globals_iterator_t;
289
292
300
301 typedef std::map<tree, string_region *> string_map_t;
303
306
308
310
311 /* "Dynamically-allocated" region instances.
312 The number of these within the analysis can grow arbitrarily.
313 They are still owned by the manager. */
315};
316
317} // namespace ana
318
319#endif /* GCC_ANALYZER_REGION_MODEL_MANAGER_H */
Definition svalue.h:1166
Definition svalue.h:741
Definition constraint-manager.h:178
Definition call-string.h:44
Definition symbolic-nodes.h:585
Definition svalue.h:1297
Definition region.h:776
Definition region.h:1666
Definition region.h:406
Definition region.h:558
Definition known-function-manager.h:41
Definition region.h:607
Definition analyzer-logging.h:36
Definition region.h:351
Definition svalue.h:421
Definition region-model.h:840
const svalue * maybe_fold_svalue_from_bit_vector(tree type, const symbolic::bit_vector &bv)
initial_values_map_t m_initial_values_map
Definition region-model-manager.h:232
const memory_space_region * get_code_region() const
Definition region-model-manager.h:116
memory_space_region m_thread_local_region
Definition region-model-manager.h:290
known_function_manager m_known_fn_mgr
Definition region-model-manager.h:309
std::map< asm_output_svalue::key_t, asm_output_svalue * > asm_output_values_map_t
Definition region-model-manager.h:257
const memory_space_region * get_globals_region() const
Definition region-model-manager.h:119
const function_region * get_region_for_fndecl(tree fndecl)
const svalue * get_or_create_cast(tree type, const svalue *arg)
const svalue * get_svalue_from_scalar(tree type, const symbolic::scalar< ConcreteValueType > &scalar)
asm_output_values_map_t m_asm_output_values_map
Definition region-model-manager.h:258
bool reject_if_too_complex(svalue *sval)
globals_map_t::iterator globals_iterator_t
Definition region-model-manager.h:287
const region * get_field_region(const region *parent, tree field)
consolidation_map< offset_region > m_offset_regions
Definition region-model-manager.h:295
const svalue * maybe_fold_unaryop(tree type, enum tree_code op, const svalue *arg)
errno_region m_errno_region
Definition region-model-manager.h:291
memory_space_region m_heap_region
Definition region-model-manager.h:213
const svalue * get_or_create_int_cst(tree type, const poly_wide_int_ref &cst)
const region * get_bit_range(const region *parent, tree type, const concrete_bit_range &bits)
consolidation_map< var_arg_region > m_var_arg_regions
Definition region-model-manager.h:305
memory_space_region m_globals_region
Definition region-model-manager.h:285
std::map< const_fn_result_svalue::key_t, const_fn_result_svalue * > const_fn_result_values_map_t
Definition region-model-manager.h:261
auto_delete_vec< svalue > m_managed_dynamic_svalues
Definition region-model-manager.h:269
const svalue * create_unique_svalue(tree type)
pointer_values_map_t m_pointer_values_map
Definition region-model-manager.h:235
const svalue * get_svalue_from_bit_vector(tree type, const symbolic::bit_vector &bv)
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:264
labels_map_t::iterator labels_iterator_t
Definition region-model-manager.h:282
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:219
bounded_ranges_manager * m_range_mgr
Definition region-model-manager.h:307
const region * get_element_region(const region *parent, tree element_type, const svalue *index)
std::map< binop_svalue::key_t, binop_svalue * > binop_values_map_t
Definition region-model-manager.h:241
setjmp_values_map_t m_setjmp_values_map
Definition region-model-manager.h:229
consolidation_map< frame_region > m_frame_regions
Definition region-model-manager.h:298
const errno_region * get_errno_region() const
Definition region-model-manager.h:121
const_fn_result_values_map_t m_const_fn_result_values_map
Definition region-model-manager.h:262
consolidation_map< symbolic_region > m_symbolic_regions
Definition region-model-manager.h:299
const region * get_symbolic_region(const svalue *sval)
region_model_manager(symbolic::node_manager &node_mgr, logger *logger=nullptr)
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:281
std::map< setjmp_svalue::key_t, setjmp_svalue * > setjmp_values_map_t
Definition region-model-manager.h:228
bool too_complex_p(const complexity &c) const
consolidation_map< cast_region > m_cast_regions
Definition region-model-manager.h:297
const svalue * get_ptr_svalue(tree ptr_type, const region *pointee)
fndecls_map_t m_fndecls_map
Definition region-model-manager.h:279
std::map< tree, function_region * > fndecls_map_t
Definition region-model-manager.h:277
std::map< svalue_from_bit_vector::key_t, svalue_from_bit_vector * > bit_vector_to_svalue_map_t
Definition region-model-manager.h:245
const unknown_svalue * m_unknown_NULL
Definition region-model-manager.h:221
unaryop_values_map_t m_unaryop_values_map
Definition region-model-manager.h:239
const memory_space_region * get_stack_region() const
Definition region-model-manager.h:110
std::map< poisoned_svalue::key_t, poisoned_svalue * > poisoned_values_map_t
Definition region-model-manager.h:224
widening_values_map_t m_widening_values_map
Definition region-model-manager.h:254
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:216
bounded_ranges_manager * get_range_manager() const
Definition region-model-manager.h:159
void log_stats(logger *logger, bool show_objs) const
binop_values_map_t m_binop_values_map
Definition region-model-manager.h:242
symbolic::node_manager & get_node_manager() const
Definition region-model-manager.h:154
globals_map_t m_globals_map
Definition region-model-manager.h:288
constants_map_t m_constants_map
Definition region-model-manager.h:217
const region * get_or_create_region_for_heap_alloc(const bitmap &base_regs_in_use)
string_map_t m_string_map
Definition region-model-manager.h:302
poisoned_values_map_t m_poisoned_values_map
Definition region-model-manager.h:225
const svalue * get_or_create_constant_svalue(tree cst_expr)
consolidation_map< sized_region > m_sized_regions
Definition region-model-manager.h:296
const call_string m_empty_call_string
Definition region-model-manager.h:209
const region * maybe_fold_sized_region_to_initial_field(const region *parent, tree type, const svalue *byte_size_sval)
logger * get_logger() const
Definition region-model-manager.h:178
symbolic::node_manager & m_node_mgr
Definition region-model-manager.h:206
void end_checking_feasibility(void)
Definition region-model-manager.h:176
const string_region * get_region_for_string(tree string_cst)
const root_region * get_root_region() const
Definition region-model-manager.h:107
const svalue * get_or_create_constant_svalue(tree type, tree cst_expr)
root_region m_root_region
Definition region-model-manager.h:211
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:293
memory_space_region m_stack_region
Definition region-model-manager.h:212
memory_space_region m_code_region
Definition region-model-manager.h:276
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:304
const label_region * get_region_for_label(tree label)
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)
const svalue * get_ptr_svalue(tree ptr_type, symbolic::pointer ptr)
fndecls_map_t::iterator fndecls_iterator_t
Definition region-model-manager.h:278
consolidation_map< element_region > m_element_regions
Definition region-model-manager.h:294
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:249
void begin_checking_feasibility(void)
Definition region-model-manager.h:175
unknowns_map_t m_unknowns_map
Definition region-model-manager.h:220
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:46
auto_delete_vec< region > m_managed_dynamic_regions
Definition region-model-manager.h:314
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:161
std::map< widening_svalue::key_t, widening_svalue * > widening_values_map_t
Definition region-model-manager.h:253
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 memory_space_region * get_heap_region() const
Definition region-model-manager.h:113
const svalue * get_or_create_unmergeable(const svalue *arg)
const region * get_sized_region(const region *parent, tree type, const svalue *byte_size_sval)
std::map< tree, string_region * > string_map_t
Definition region-model-manager.h:301
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:238
logger * m_logger
Definition region-model-manager.h:207
unmergeable_values_map_t m_unmergeable_values_map
Definition region-model-manager.h:250
const region * get_unknown_symbolic_region(tree region_type)
unsigned alloc_node_id()
Definition region-model-manager.h:43
std::map< const region *, initial_svalue * > initial_values_map_t
Definition region-model-manager.h:231
const svalue * get_or_create_unknown_svalue(tree type)
void dump_untracked_regions() const
const region * maybe_fold_symbolic_region(const svalue *sval)
const svalue * maybe_invert_comparison_in_unaryop(tree type, const binop_svalue *binop)
std::map< tree, decl_region * > globals_map_t
Definition region-model-manager.h:286
const region * get_cast_region(const region *original_region, tree type)
complexity m_max_complexity
Definition region-model-manager.h:272
const svalue * get_or_create_unaryop(tree type, enum tree_code op, const svalue *arg)
bit_vector_to_svalue_map_t m_bit_vector_to_svalue_map
Definition region-model-manager.h:246
std::map< pointer_svalue::key_t, pointer_svalue * > pointer_values_map_t
Definition region-model-manager.h:234
labels_map_t m_labels_map
Definition region-model-manager.h:283
Definition region.h:154
Definition region.h:653
Definition svalue.h:524
Definition region.h:1419
Definition supergraph.h:227
Definition svalue.h:840
Definition svalue.h:82
Definition symbolic-bit-vectors.h:107
Definition symbolic-nodes.h:48
unsigned alloc_node_id()
Definition symbolic-nodes.h:56
Definition symbolic-pointers.h:33
Definition symbolic-scalars.h:67
Definition type.h:29
Definition svalue.h:658
Definition svalue.h:386
Definition svalue.h:947
Definition region.h:1576
Definition svalue.h:1058
Definition vec.h:1813
Definition common.h:659
Definition dumpfile.h:446
Definition genmatch.cc:1627
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
concrete::range< integer_with_unit< units::bit > > concrete_bit_range
Definition concrete-ranges.h:117
poison_kind
Definition common.h:521
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:1174
Definition complexity.h:31
Definition svalue.h:1305
Definition svalue.h:425
Definition svalue.h:496
Definition svalue.h:528
Definition svalue.h:843
Definition svalue.h:662
Definition svalue.h:1062
Definition function.h:249
Definition gimple.h:553
Definition gimple.h:225
Definition vec.h:450