Line data Source code
1 : /* Classes for representing locations within the program.
2 : Copyright (C) 2019-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it
8 : under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3, or (at your option)
10 : any later version.
11 :
12 : GCC is distributed in the hope that it will be useful, but
13 : WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along 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"
25 : #include "analyzer/call-string.h"
26 : #include "analyzer/supergraph.h"
27 :
28 : namespace ana {
29 :
30 : class format
31 : {
32 : public:
33 3577 : format (bool newlines) : m_newlines (newlines) {}
34 :
35 3577 : void spacer (pretty_printer *pp) const
36 : {
37 3577 : if (m_newlines)
38 651 : pp_newline (pp);
39 : else
40 2926 : pp_space (pp);
41 3577 : }
42 :
43 : bool m_newlines;
44 : };
45 :
46 : /* A class for representing a location within the program, including
47 : interprocedural information.
48 :
49 : This represents a fine-grained location within the supergraph (or
50 : within one of its nodes), along with a call string giving the
51 : interprocedural context. */
52 :
53 : class program_point
54 : {
55 : public:
56 366924 : program_point (const supernode *snode,
57 : const call_string &call_string)
58 382653 : : m_snode (snode),
59 22071 : m_call_string (&call_string)
60 : {
61 : }
62 :
63 : void print (pretty_printer *pp, const format &f) const;
64 : void dump () const;
65 : void print_source_line (pretty_printer *pp) const;
66 :
67 : std::unique_ptr<json::object> to_json () const;
68 :
69 : hashval_t hash () const;
70 10374727 : bool operator== (const program_point &other) const
71 : {
72 10374727 : return (m_snode == other.m_snode
73 10374727 : && m_call_string == other.m_call_string);
74 : }
75 : bool operator!= (const program_point &other) const
76 : {
77 : return !(*this == other);
78 : }
79 :
80 : /* Accessors. */
81 :
82 7961219 : const supernode *get_supernode () const
83 : {
84 7828500 : return m_snode;
85 : }
86 3188239 : const call_string &get_call_string () const { return *m_call_string; }
87 :
88 2178091 : function *get_function () const
89 : {
90 2009924 : return m_snode ? m_snode->get_function () : nullptr;
91 : }
92 : function *get_function_at_depth (unsigned depth) const;
93 38406 : tree get_fndecl () const
94 : {
95 69386 : function *fn = get_function ();
96 38528 : return fn ? fn->decl : nullptr;
97 : }
98 382663 : location_t get_location () const
99 : {
100 382553 : return m_snode ? m_snode->get_location () : UNKNOWN_LOCATION;
101 : }
102 :
103 : /* Get the number of frames we expect at this program point.
104 : This will be one more than the length of the call_string
105 : (which stores the parent callsites), apart from the origin
106 : node, which doesn't have any frames. */
107 964746 : int get_stack_depth () const
108 : {
109 932453 : if (m_snode == nullptr)
110 : // Origin
111 : return 0;
112 1173521 : return get_call_string ().length () + 1;
113 : }
114 :
115 749545 : bool state_merge_at_p () const
116 : {
117 749545 : if (m_snode)
118 742825 : return m_snode->m_state_merger_node;
119 : return false;
120 : }
121 :
122 : /* Factory functions for making various kinds of program_point. */
123 : static program_point origin (const region_model_manager &mgr);
124 : static program_point from_function_entry (const region_model_manager &mgr,
125 : const supergraph &sg,
126 : const function &fun);
127 :
128 : void pop_from_call_stack ();
129 : void validate () const;
130 :
131 : static bool effectively_intraprocedural_p (const program_point &point_a,
132 : const program_point &point_b);
133 :
134 : private:
135 : const supernode *m_snode;
136 : const call_string *m_call_string;
137 : };
138 :
139 : } // namespace ana
140 :
141 : #endif /* GCC_ANALYZER_PROGRAM_POINT_H */
|