xref: /netbsd-src/external/gpl3/gcc/dist/gcc/analyzer/complexity.h (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1 /* Measuring the complexity of svalues/regions.
2    Copyright (C) 2020-2022 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_COMPLEXITY_H
22 #define GCC_ANALYZER_COMPLEXITY_H
23 
24 namespace ana {
25 
26 /* A measurement of the complexity of an svalue or region, so that
27    we can impose bounds on the growth of these tree-like structures
28    and thus avoid infinite chains of analysis.  */
29 
30 struct complexity
31 {
complexitycomplexity32   complexity (unsigned num_nodes, unsigned max_depth)
33   : m_num_nodes (num_nodes), m_max_depth (max_depth)
34   {}
35 
36   complexity (const region *reg);
37   complexity (const svalue *sval);
38   static complexity from_pair (const complexity &c1, const complexity &c);
39   static complexity from_vec_svalue (const vec<const svalue *> &vec);
40 
41   /* The total number of svalues and regions in the tree of this
42      entity, including the entity itself.  */
43   unsigned m_num_nodes;
44 
45   /* The maximum depth of the tree of this entity, including the
46      entity itself.  */
47   unsigned m_max_depth;
48 };
49 
50 } // namespace ana
51 
52 #endif /* GCC_ANALYZER_COMPLEXITY_H */
53