Branch data Line data Source code
1 : : /* Measuring the complexity of svalues/regions.
2 : : Copyright (C) 2020-2025 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 "analyzer/common.h"
22 : :
23 : : #include "options.h"
24 : : #include "cgraph.h"
25 : : #include "cfg.h"
26 : : #include "digraph.h"
27 : :
28 : : #include "analyzer/analyzer-logging.h"
29 : : #include "analyzer/call-string.h"
30 : : #include "analyzer/program-point.h"
31 : : #include "analyzer/store.h"
32 : : #include "analyzer/complexity.h"
33 : : #include "analyzer/svalue.h"
34 : : #include "analyzer/region.h"
35 : :
36 : : #if ENABLE_ANALYZER
37 : :
38 : : namespace ana {
39 : :
40 : : /* struct complexity. */
41 : :
42 : : /* Get complexity for a new node that references REG
43 : : (the complexity of REG, plus one for the new node). */
44 : :
45 : 276067 : complexity::complexity (const region *reg)
46 : 276067 : : m_num_nodes (reg->get_complexity ().m_num_nodes + 1),
47 : 276067 : m_max_depth (reg->get_complexity ().m_max_depth + 1)
48 : : {
49 : 276067 : }
50 : :
51 : : /* Get complexity for a new node that references SVAL.
52 : : (the complexity of SVAL, plus one for the new node). */
53 : :
54 : 29497 : complexity::complexity (const svalue *sval)
55 : 29497 : : m_num_nodes (sval->get_complexity ().m_num_nodes + 1),
56 : 29497 : m_max_depth (sval->get_complexity ().m_max_depth + 1)
57 : : {
58 : 29497 : }
59 : :
60 : : /* Get complexity for a new node that references nodes with complexity
61 : : C1 and C2. */
62 : :
63 : : complexity
64 : 45600 : complexity::from_pair (const complexity &c1, const complexity &c2)
65 : : {
66 : 91200 : return complexity (c1.m_num_nodes + c2.m_num_nodes + 1,
67 : 45600 : MAX (c1.m_max_depth, c2.m_max_depth) + 1);
68 : : }
69 : :
70 : : /* Get complexity for a new node that references the svalues in VEC. */
71 : :
72 : : complexity
73 : 447 : complexity::from_vec_svalue (const vec<const svalue *> &vec)
74 : : {
75 : 447 : unsigned num_nodes = 0;
76 : 447 : unsigned max_depth = 0;
77 : 1786 : for (auto iter_sval : vec)
78 : : {
79 : 551 : const complexity &iter_c = iter_sval->get_complexity ();
80 : 551 : num_nodes += iter_c.m_num_nodes;
81 : 551 : max_depth = MAX (max_depth, iter_c.m_max_depth);
82 : : }
83 : 447 : return complexity (num_nodes + 1, max_depth + 1);
84 : : }
85 : :
86 : : } // namespace ana
87 : :
88 : : #endif /* #if ENABLE_ANALYZER */
|