1 /* A class to encapsulate decisions about how the analysis should happen.
2 Copyright (C) 2019-2021 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/>. */
23 #include "coretypes.h"
28 #include "ipa-utils.h"
31 #include "analyzer/analyzer.h"
32 #include "diagnostic-core.h"
33 #include "analyzer/analyzer-logging.h"
34 #include "analyzer/analysis-plan.h"
35 #include "ordered-hash-map.h"
40 #include "basic-block.h"
42 #include "gimple-iterator.h"
44 #include "analyzer/supergraph.h"
48 /* class analysis_plan. */
50 /* analysis_plan's ctor. */
52 analysis_plan::analysis_plan (const supergraph
&sg
, logger
*logger
)
53 : log_user (logger
), m_sg (sg
),
54 m_cgraph_node_postorder (XCNEWVEC (struct cgraph_node
*,
55 symtab
->cgraph_count
)),
56 m_index_by_uid (symtab
->cgraph_max_uid
)
59 auto_timevar
time (TV_ANALYZER_PLAN
);
61 m_num_cgraph_nodes
= ipa_reverse_postorder (m_cgraph_node_postorder
);
62 gcc_assert (m_num_cgraph_nodes
== symtab
->cgraph_count
);
63 if (get_logger_file ())
64 ipa_print_order (get_logger_file (),
65 "analysis_plan", m_cgraph_node_postorder
,
68 /* Populate m_index_by_uid. */
69 for (int i
= 0; i
< symtab
->cgraph_max_uid
; i
++)
70 m_index_by_uid
.quick_push (-1);
71 for (int i
= 0; i
< m_num_cgraph_nodes
; i
++)
73 gcc_assert (m_cgraph_node_postorder
[i
]->get_uid ()
74 < symtab
->cgraph_max_uid
);
75 m_index_by_uid
[m_cgraph_node_postorder
[i
]->get_uid ()] = i
;
79 /* analysis_plan's dtor. */
81 analysis_plan::~analysis_plan ()
83 free (m_cgraph_node_postorder
);
86 /* Comparator for use by the exploded_graph's worklist, to order FUN_A
87 and FUN_B so that functions that are to be summarized are visited
88 before the summary is needed (based on a sort of the callgraph). */
91 analysis_plan::cmp_function (function
*fun_a
, function
*fun_b
) const
93 cgraph_node
*node_a
= cgraph_node::get (fun_a
->decl
);
94 cgraph_node
*node_b
= cgraph_node::get (fun_b
->decl
);
96 int idx_a
= m_index_by_uid
[node_a
->get_uid ()];
97 int idx_b
= m_index_by_uid
[node_b
->get_uid ()];
102 /* Return true if the call EDGE should be analyzed using a call summary.
103 Return false if it should be analyzed using a full call and return. */
106 analysis_plan::use_summary_p (const cgraph_edge
*edge
) const
108 /* Don't use call summaries if -fno-analyzer-call-summaries. */
109 if (!flag_analyzer_call_summaries
)
112 /* Don't use call summaries if there is no callgraph edge */
113 if (!edge
|| !edge
->callee
)
116 /* TODO: don't count callsites each time. */
117 int num_call_sites
= 0;
118 const cgraph_node
*callee
= edge
->callee
;
119 for (cgraph_edge
*edge
= callee
->callers
; edge
; edge
= edge
->next_caller
)
122 /* Don't use a call summary if there's only one call site. */
123 if (num_call_sites
<= 1)
126 /* Require the callee to be sufficiently complex to be worth
129 = const_cast <cgraph_node
*> (callee
)->ultimate_alias_target ()->get_fun ();
130 /* TODO(stage1): can ultimate_alias_target be made const? */
132 if ((int)m_sg
.get_num_snodes (fun
)
133 < param_analyzer_min_snodes_for_call_summary
)
139 #endif /* #if ENABLE_ANALYZER */