1 | /* Measuring the complexity of svalues/regions. |
2 | Copyright (C) 2020-2024 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 | #include "config.h" |
22 | #define INCLUDE_MEMORY |
23 | #include "system.h" |
24 | #include "coretypes.h" |
25 | #include "tree.h" |
26 | #include "diagnostic-core.h" |
27 | #include "gimple-pretty-print.h" |
28 | #include "function.h" |
29 | #include "basic-block.h" |
30 | #include "gimple.h" |
31 | #include "gimple-iterator.h" |
32 | #include "diagnostic-core.h" |
33 | #include "graphviz.h" |
34 | #include "options.h" |
35 | #include "cgraph.h" |
36 | #include "tree-dfa.h" |
37 | #include "stringpool.h" |
38 | #include "convert.h" |
39 | #include "target.h" |
40 | #include "fold-const.h" |
41 | #include "tree-pretty-print.h" |
42 | #include "bitmap.h" |
43 | #include "analyzer/analyzer.h" |
44 | #include "analyzer/analyzer-logging.h" |
45 | #include "options.h" |
46 | #include "cgraph.h" |
47 | #include "cfg.h" |
48 | #include "digraph.h" |
49 | #include "analyzer/call-string.h" |
50 | #include "analyzer/program-point.h" |
51 | #include "analyzer/store.h" |
52 | #include "analyzer/complexity.h" |
53 | #include "analyzer/svalue.h" |
54 | #include "analyzer/region.h" |
55 | |
56 | #if ENABLE_ANALYZER |
57 | |
58 | namespace ana { |
59 | |
60 | /* struct complexity. */ |
61 | |
62 | /* Get complexity for a new node that references REG |
63 | (the complexity of REG, plus one for the new node). */ |
64 | |
65 | complexity::complexity (const region *reg) |
66 | : m_num_nodes (reg->get_complexity ().m_num_nodes + 1), |
67 | m_max_depth (reg->get_complexity ().m_max_depth + 1) |
68 | { |
69 | } |
70 | |
71 | /* Get complexity for a new node that references SVAL. |
72 | (the complexity of SVAL, plus one for the new node). */ |
73 | |
74 | complexity::complexity (const svalue *sval) |
75 | : m_num_nodes (sval->get_complexity ().m_num_nodes + 1), |
76 | m_max_depth (sval->get_complexity ().m_max_depth + 1) |
77 | { |
78 | } |
79 | |
80 | /* Get complexity for a new node that references nodes with complexity |
81 | C1 and C2. */ |
82 | |
83 | complexity |
84 | complexity::from_pair (const complexity &c1, const complexity &c2) |
85 | { |
86 | return complexity (c1.m_num_nodes + c2.m_num_nodes + 1, |
87 | MAX (c1.m_max_depth, c2.m_max_depth) + 1); |
88 | } |
89 | |
90 | /* Get complexity for a new node that references the svalues in VEC. */ |
91 | |
92 | complexity |
93 | complexity::from_vec_svalue (const vec<const svalue *> &vec) |
94 | { |
95 | unsigned num_nodes = 0; |
96 | unsigned max_depth = 0; |
97 | for (auto iter_sval : vec) |
98 | { |
99 | const complexity &iter_c = iter_sval->get_complexity (); |
100 | num_nodes += iter_c.m_num_nodes; |
101 | max_depth = MAX (max_depth, iter_c.m_max_depth); |
102 | } |
103 | return complexity (num_nodes + 1, max_depth + 1); |
104 | } |
105 | |
106 | } // namespace ana |
107 | |
108 | #endif /* #if ENABLE_ANALYZER */ |
109 | |