GCC Middle and Back End API Reference
state-purge.h
Go to the documentation of this file.
1/* Classes for purging state at function_points.
2 Copyright (C) 2019-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_STATE_PURGE_H
22#define GCC_ANALYZER_STATE_PURGE_H
23
24namespace ana {
25
26/* The result of analyzing which decls and SSA names can be purged from state at
27 different points in the program, so that we can simplify program_state
28 objects, in the hope of reducing state-blowup. */
29
31{
32public:
34 typedef ssa_map_t::iterator ssa_iterator;
35
37 typedef decl_map_t::iterator decl_iterator;
38
41 logger *logger);
43
45 {
46 gcc_assert (TREE_CODE (name) == SSA_NAME);
47 if (tree var = SSA_NAME_VAR (name))
48 if (TREE_CODE (var) == VAR_DECL)
50
52 = const_cast <ssa_map_t&> (m_ssa_map).get (name);
53 return **slot;
54 }
55
57 {
58 gcc_assert (TREE_CODE (decl) == VAR_DECL
59 || TREE_CODE (decl) == PARM_DECL
60 || TREE_CODE (decl) == RESULT_DECL);
62 = const_cast <decl_map_t&> (m_decl_map).get (decl))
63 return *slot;
64 else
65 return nullptr;
66 }
67
70
71 const supergraph &get_sg () const { return m_sg; }
72
73 ssa_iterator begin_ssas () const { return m_ssa_map.begin (); }
74 ssa_iterator end_ssas () const { return m_ssa_map.end (); }
75
76 decl_iterator begin_decls () const { return m_decl_map.begin (); }
77 decl_iterator end_decls () const { return m_decl_map.end (); }
78
79 void
80 on_duplicated_node (const supernode &old_snode,
81 const supernode &new_snode);
82
83private:
85
89};
90
91 /* Base class for state_purge_per_ssa_name and state_purge_per_decl. */
92
94{
95public:
96 const function &get_function () const { return m_fun; }
97 tree get_fndecl () const { return m_fun.decl; }
98
99protected:
101
103 : m_fun (fun)
104 {
105 }
106
107private:
109};
110
111/* The part of a state_purge_map relating to a specific SSA name.
112
113 The result of analyzing a given SSA name, recording which
114 function_points need to retain state information about it to handle
115 their successor states, so that we can simplify program_state objects,
116 in the hope of reducing state-blowup. */
117
119{
120public:
122 tree name,
123 const function &fun);
124
125 bool needed_at_supernode_p (const supernode *snode) const;
126
127 void
128 on_duplicated_node (const supernode &old_snode,
129 const supernode &new_snode);
130
131private:
134 logger *logger);
135
138 const state_purge_map &map);
139
142};
143
144/* The part of a state_purge_map relating to a specific decl.
145
146 Analogous to state_purge_per_ssa_name, but for local decls.
147
148 This is more involved than the SSA name case, because we also need
149 to handle pointers and components. */
150
152{
153public:
155 tree decl,
156 const function &fun);
157
158 bool needed_at_supernode_p (const supernode *snode) const;
159
160 void add_needed_at (const supernode &snode);
161 void add_pointed_to_at (const supernode &snode);
164
165 void
166 on_duplicated_node (const supernode &old_snode,
167 const supernode &new_snode);
168
169private:
171 const gimple *use_stmt);
172
175 point_set_t *seen,
176 logger *logger);
177
180 point_set_t *seen,
181 const state_purge_map &map,
182 const region_model &model);
185 point_set_t *seen,
186 const state_purge_map &map);
187
191};
192
193/* Subclass of dot_annotator for use by -fdump-analyzer-state-purge.
194 Annotate the .dot output with state-purge information. */
195
197{
198public:
200
201 void
203 const supernode &n) const final override;
204
205private:
207};
208
209} // namespace ana
210
211#endif /* GCC_ANALYZER_STATE_PURGE_H */
Definition supergraph.h:364
log_user(logger *logger)
Definition analyzer-logging.h:34
Definition region-model-manager.h:32
Definition region-model.h:299
void add_node_annotations(graphviz_out *gv, const supernode &n) const final override
const state_purge_map * m_map
Definition state-purge.h:206
state_purge_annotator(const state_purge_map *map)
Definition state-purge.h:199
Definition state-purge.h:31
state_purge_per_decl & get_or_create_data_for_decl(const function &fun, tree decl)
ssa_iterator end_ssas() const
Definition state-purge.h:74
decl_iterator end_decls() const
Definition state-purge.h:77
const supergraph & m_sg
Definition state-purge.h:86
state_purge_map(const supergraph &sg, region_model_manager *mgr, logger *logger)
ordered_hash_map< tree, state_purge_per_ssa_name * > ssa_map_t
Definition state-purge.h:33
decl_map_t::iterator decl_iterator
Definition state-purge.h:37
ssa_map_t::iterator ssa_iterator
Definition state-purge.h:34
ssa_iterator begin_ssas() const
Definition state-purge.h:73
const state_purge_per_ssa_name & get_data_for_ssa_name(tree name) const
Definition state-purge.h:44
ordered_hash_map< tree, state_purge_per_decl * > decl_map_t
Definition state-purge.h:36
const supergraph & get_sg() const
Definition state-purge.h:71
ssa_map_t m_ssa_map
Definition state-purge.h:87
decl_iterator begin_decls() const
Definition state-purge.h:76
const state_purge_per_decl * get_any_data_for_decl(tree decl) const
Definition state-purge.h:56
DISABLE_COPY_AND_ASSIGN(state_purge_map)
decl_map_t m_decl_map
Definition state-purge.h:88
void on_duplicated_node(const supernode &old_snode, const supernode &new_snode)
Definition state-purge.h:152
bool needed_at_supernode_p(const supernode *snode) const
state_purge_per_decl(const state_purge_map &map, tree decl, const function &fun)
void on_duplicated_node(const supernode &old_snode, const supernode &new_snode)
void process_supernode_backwards(const supernode &snode, auto_vec< const supernode * > *worklist, point_set_t *seen, const state_purge_map &map, const region_model &model)
point_set_t m_snodes_taking_address
Definition state-purge.h:189
void process_worklists(const state_purge_map &map, region_model_manager *mgr)
static const supernode * before_use_stmt(const state_purge_map &map, const gimple *use_stmt)
void process_supernode_forwards(const supernode &snode, auto_vec< const supernode * > *worklist, point_set_t *seen, const state_purge_map &map)
tree m_decl
Definition state-purge.h:190
void add_to_worklist(const supernode &node, auto_vec< const supernode * > *worklist, point_set_t *seen, logger *logger)
void add_needed_at(const supernode &snode)
void add_pointed_to_at(const supernode &snode)
point_set_t m_snodes_needing_decl
Definition state-purge.h:188
Definition state-purge.h:119
state_purge_per_ssa_name(const state_purge_map &map, tree name, const function &fun)
point_set_t m_snodes_needing_name
Definition state-purge.h:140
void add_to_worklist(const supernode &node, auto_vec< const supernode * > *worklist, logger *logger)
void process_supernode(const supernode &node, auto_vec< const supernode * > *worklist, const state_purge_map &map)
void on_duplicated_node(const supernode &old_snode, const supernode &new_snode)
tree m_name
Definition state-purge.h:141
bool needed_at_supernode_p(const supernode *snode) const
const function & get_function() const
Definition state-purge.h:96
state_purge_per_tree(const function &fun)
Definition state-purge.h:102
tree get_fndecl() const
Definition state-purge.h:97
const function & m_fun
Definition state-purge.h:108
hash_set< const supernode * > point_set_t
Definition state-purge.h:100
Definition supergraph.h:105
Definition supergraph.h:224
Definition exploded-graph.h:715
Definition vec.h:1667
Definition graphviz.h:385
Definition hash-set.h:37
Definition ordered-hash-map.h:35
Definition lra-spills.cc:101
union tree_node * tree
Definition coretypes.h:97
static struct string2counter_map map[debug_counter_number_of_counters]
Definition dbgcnt.cc:39
Definition access-diagram.h:30
Definition custom-sarif-properties/state-graphs.h:33
Definition genautomata.cc:499
Definition function.h:249
Definition gimple.h:221
#define gcc_assert(EXPR)
Definition system.h:817
#define SSA_NAME_VAR(NODE)
Definition tree.h:2202
#define VAR_DECL_IS_VIRTUAL_OPERAND(NODE)
Definition tree.h:3433
#define TREE_CODE(NODE)
Definition tree.h:325