1 /* Call stacks at program points.
2 Copyright (C) 2019-2022 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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)
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.
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/>. */
21 #ifndef GCC_ANALYZER_CALL_STRING_H
22 #define GCC_ANALYZER_CALL_STRING_H
29 class return_superedge
;
32 /* A string of return_superedge pointers, representing a call stack
35 This is used to ensure that we generate interprocedurally valid paths
36 i.e. that we return to the same callsite that called us.
38 The class stores returning calls ( which may be represented by a
39 returning superedge ). We do so because this is what we need to compare
45 /* A struct representing an element in the call_string.
47 Each element represents a path from m_callee to m_caller which represents
48 returning from function. */
52 element_t (const supernode
*caller
, const supernode
*callee
)
53 : m_caller (caller
), m_callee (callee
)
57 bool operator== (const element_t
&other
) const;
58 bool operator!= (const element_t
&other
) const;
61 function
*get_caller_function () const;
62 function
*get_callee_function () const;
64 const supernode
*m_caller
;
65 const supernode
*m_callee
;
68 call_string () : m_elements () {}
69 call_string (const call_string
&other
);
70 call_string
& operator= (const call_string
&other
);
72 bool operator== (const call_string
&other
) const;
74 void print (pretty_printer
*pp
) const;
76 json::value
*to_json () const;
78 hashval_t
hash () const;
80 bool empty_p () const { return m_elements
.is_empty (); }
82 void push_call (const supergraph
&sg
,
83 const call_superedge
*sedge
);
85 void push_call (const supernode
*src
,
86 const supernode
*dest
);
90 int calc_recursion_depth () const;
92 static int cmp (const call_string
&a
,
93 const call_string
&b
);
97 const supernode
*get_callee_node () const;
98 const supernode
*get_caller_node () const;
99 unsigned length () const { return m_elements
.length (); }
100 element_t
operator[] (unsigned idx
) const
102 return m_elements
[idx
];
105 void validate () const;
108 auto_vec
<element_t
> m_elements
;
113 #endif /* GCC_ANALYZER_CALL_STRING_H */