GCC Middle and Back End API Reference
program-point.h
Go to the documentation of this file.
1/* Classes for representing locations within the program.
2 Copyright (C) 2019-2024 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_PROGRAM_POINT_H
22#define GCC_ANALYZER_PROGRAM_POINT_H
23
24#include "pretty-print.h"
26
27namespace ana {
28
29class exploded_graph;
30
31/* An enum for distinguishing the various kinds of program_point. */
32
34 /* A "fake" node which has edges to all entrypoints. */
36
40
41 /* Special values used for hash_map: */
44
46};
47
48extern const char *point_kind_to_string (enum point_kind pk);
49
50class format
51{
52public:
54
55 void spacer (pretty_printer *pp) const
56 {
57 if (m_newlines)
58 pp_newline (pp);
59 else
60 pp_space (pp);
61 }
62
64};
65
66/* A class for representing a location within the program, without
67 interprocedural information.
68
69 This represents a fine-grained location within the supergraph (or
70 within one of its nodes). */
71
73{
74public:
76 const superedge *from_edge,
77 unsigned stmt_idx,
78 enum point_kind kind);
79
80 void print (pretty_printer *pp, const format &f) const;
82 void dump () const;
83
84 hashval_t hash () const;
85 bool operator== (const function_point &other) const
86 {
87 return (m_supernode == other.m_supernode
88 && m_from_edge == other.m_from_edge
89 && m_stmt_idx == other.m_stmt_idx
90 && m_kind == other.m_kind);
91 }
92
93 /* Accessors. */
94
95 const supernode *get_supernode () const { return m_supernode; }
97 const gimple *get_stmt () const;
99 enum point_kind get_kind () const { return m_kind; }
100 const superedge *get_from_edge () const
101 {
102 return m_from_edge;
103 }
104 unsigned get_stmt_idx () const
105 {
107 return m_stmt_idx;
108 }
109
110 bool final_stmt_p () const;
111
112 /* Factory functions for making various kinds of program_point. */
113
115 const function &fun);
116
118 const superedge *from_edge);
119
121 unsigned stmt_idx)
122 {
124 }
125
130
131 /* Support for hash_map. */
132
134 {
135 return function_point (NULL, NULL, 0, PK_EMPTY);
136 }
138 {
139 return function_point (NULL, NULL, 0, PK_DELETED);
140 }
141
143 const function_point &point_b);
145 const function_point &point_b);
146 static int cmp (const function_point &point_a,
147 const function_point &point_b);
148 static int cmp_ptr (const void *p1, const void *p2);
149
150 /* For before_stmt, go to next stmt. */
151 void next_stmt ();
152
154
155 private:
157
158 /* For PK_BEFORE_SUPERNODE, and only for CFG edges. */
160
161 /* Only for PK_BEFORE_STMT. */
162 unsigned m_stmt_idx;
163
165};
166
167/* A class for representing a location within the program, including
168 interprocedural information.
169
170 This represents a fine-grained location within the supergraph (or
171 within one of its nodes), along with a call string giving the
172 interprocedural context. */
173
175{
176public:
183
184 void print (pretty_printer *pp, const format &f) const;
185 void dump () const;
186
188
189 hashval_t hash () const;
190 bool operator== (const program_point &other) const
191 {
192 return (m_function_point == other.m_function_point
193 && m_call_string == other.m_call_string);
194 }
195 bool operator!= (const program_point &other) const
196 {
197 return !(*this == other);
198 }
199
200 /* Accessors. */
201
203 const call_string &get_call_string () const { return *m_call_string; }
204
205 const supernode *get_supernode () const
206 {
208 }
210 {
212 }
213 function *get_function_at_depth (unsigned depth) const;
215 {
217 return get_function ()->decl;
218 }
219 const gimple *get_stmt () const
220 {
221 return m_function_point.get_stmt ();
222 }
224 {
226 }
227 enum point_kind get_kind () const
228 {
229 return m_function_point.get_kind ();
230 }
231 const superedge *get_from_edge () const
232 {
234 }
235 unsigned get_stmt_idx () const
236 {
238 }
239
240 /* Get the number of frames we expect at this program point.
241 This will be one more than the length of the call_string
242 (which stores the parent callsites), apart from the origin
243 node, which doesn't have any frames. */
244 int get_stack_depth () const
245 {
246 if (get_kind () == PK_ORIGIN)
247 return 0;
248 return get_call_string ().length () + 1;
249 }
250
251 /* Factory functions for making various kinds of program_point. */
254 const supergraph &sg,
255 const function &fun);
256
265
273
280
281 /* Support for hash_map. */
282
284 {
286 }
288 {
290 }
291
292 bool on_edge (exploded_graph &eg, const superedge *succ);
293 void push_to_call_stack (const supernode *caller, const supernode *callee);
295 void validate () const;
296
297 /* For before_stmt, go to next stmt. */
299
301
303 const program_point &point_b);
304
305 private:
311
314};
315
316} // namespace ana
317
318#endif /* GCC_ANALYZER_PROGRAM_POINT_H */
Definition call-string.h:48
unsigned length() const
Definition call-string.h:97
Definition exploded-graph.h:791
Definition program-point.h:51
void spacer(pretty_printer *pp) const
Definition program-point.h:55
format(bool newlines)
Definition program-point.h:53
bool m_newlines
Definition program-point.h:63
Definition program-point.h:73
function * get_function() const
location_t get_location() const
static function_point after_supernode(const supernode *supernode)
Definition program-point.h:126
const supernode * m_supernode
Definition program-point.h:156
static function_point before_stmt(const supernode *supernode, unsigned stmt_idx)
Definition program-point.h:120
const superedge * get_from_edge() const
Definition program-point.h:100
void print(pretty_printer *pp, const format &f) const
bool operator==(const function_point &other) const
Definition program-point.h:85
const gimple * get_stmt() const
function_point(const supernode *supernode, const superedge *from_edge, unsigned stmt_idx, enum point_kind kind)
void dump() const
const superedge * m_from_edge
Definition program-point.h:159
static int cmp_ptr(const void *p1, const void *p2)
function_point get_next() const
static int cmp_within_supernode_1(const function_point &point_a, const function_point &point_b)
static function_point before_supernode(const supernode *supernode, const superedge *from_edge)
unsigned get_stmt_idx() const
Definition program-point.h:104
unsigned m_stmt_idx
Definition program-point.h:162
enum point_kind m_kind
Definition program-point.h:164
static function_point empty()
Definition program-point.h:133
static int cmp(const function_point &point_a, const function_point &point_b)
const supernode * get_supernode() const
Definition program-point.h:95
enum point_kind get_kind() const
Definition program-point.h:99
static function_point from_function_entry(const supergraph &sg, const function &fun)
hashval_t hash() const
void print_source_line(pretty_printer *pp) const
static function_point deleted()
Definition program-point.h:137
static int cmp_within_supernode(const function_point &point_a, const function_point &point_b)
bool final_stmt_p() const
Definition program-point.h:175
location_t get_location() const
Definition program-point.h:223
void push_to_call_stack(const supernode *caller, const supernode *callee)
function * get_function() const
Definition program-point.h:209
bool operator!=(const program_point &other) const
Definition program-point.h:195
void print(pretty_printer *pp, const format &f) const
static program_point before_stmt(const supernode *supernode, unsigned stmt_idx, const call_string &call_string)
Definition program-point.h:266
bool on_edge(exploded_graph &eg, const superedge *succ)
program_point get_next() const
bool operator==(const program_point &other) const
Definition program-point.h:190
static program_point empty()
Definition program-point.h:283
static program_point deleted()
Definition program-point.h:287
const supernode * get_supernode() const
Definition program-point.h:205
static program_point from_function_entry(const region_model_manager &mgr, const supergraph &sg, const function &fun)
void dump() const
int get_stack_depth() const
Definition program-point.h:244
const call_string & get_call_string() const
Definition program-point.h:203
function_point m_function_point
Definition program-point.h:312
function * get_function_at_depth(unsigned depth) const
void pop_from_call_stack()
enum point_kind get_kind() const
Definition program-point.h:227
const function_point & get_function_point() const
Definition program-point.h:202
static program_point after_supernode(const supernode *supernode, const call_string &call_string)
Definition program-point.h:274
static bool effectively_intraprocedural_p(const program_point &point_a, const program_point &point_b)
void validate() const
static program_point before_supernode(const supernode *supernode, const superedge *from_edge, const call_string &call_string)
Definition program-point.h:257
json::object * to_json() const
const superedge * get_from_edge() const
Definition program-point.h:231
static program_point origin(const region_model_manager &mgr)
unsigned get_stmt_idx() const
Definition program-point.h:235
program_point(const function_point &fn_point)
Definition program-point.h:306
void next_stmt()
Definition program-point.h:298
program_point(const function_point &fn_point, const call_string &call_string)
Definition program-point.h:177
tree get_fndecl() const
Definition program-point.h:214
hashval_t hash() const
const gimple * get_stmt() const
Definition program-point.h:219
const call_string * m_call_string
Definition program-point.h:313
Definition region-model-manager.h:32
Definition supergraph.h:314
Definition supergraph.h:109
Definition supergraph.h:235
Definition json.h:95
Definition pretty-print.h:244
union tree_node * tree
Definition coretypes.h:97
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
Definition access-diagram.h:30
const char * point_kind_to_string(enum point_kind pk)
point_kind
Definition program-point.h:33
@ PK_AFTER_SUPERNODE
Definition program-point.h:39
@ PK_EMPTY
Definition program-point.h:42
@ NUM_POINT_KINDS
Definition program-point.h:45
@ PK_DELETED
Definition program-point.h:43
@ PK_BEFORE_STMT
Definition program-point.h:38
@ PK_BEFORE_SUPERNODE
Definition program-point.h:37
@ PK_ORIGIN
Definition program-point.h:35
void pp_newline(pretty_printer *pp)
Definition pretty-print.cc:2208
#define pp_space(PP)
Definition pretty-print.h:316
Definition function.h:249
tree decl
Definition function.h:280
Definition gimple.h:225
#define NULL
Definition system.h:50
#define gcc_assert(EXPR)
Definition system.h:821