ipa-fnsummary.h revision 1.1.1.2 1 1.1 mrg /* IPA function body analysis.
2 1.1.1.2 mrg Copyright (C) 2003-2019 Free Software Foundation, Inc.
3 1.1 mrg Contributed by Jan Hubicka
4 1.1 mrg
5 1.1 mrg This file is part of GCC.
6 1.1 mrg
7 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
8 1.1 mrg the terms of the GNU General Public License as published by the Free
9 1.1 mrg Software Foundation; either version 3, or (at your option) any later
10 1.1 mrg version.
11 1.1 mrg
12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 1.1 mrg for more details.
16 1.1 mrg
17 1.1 mrg You should have received a copy of the GNU General Public License
18 1.1 mrg along with GCC; see the file COPYING3. If not see
19 1.1 mrg <http://www.gnu.org/licenses/>. */
20 1.1 mrg
21 1.1 mrg #ifndef GCC_IPA_SUMMARY_H
22 1.1 mrg #define GCC_IPA_SUMMARY_H
23 1.1 mrg
24 1.1 mrg #include "sreal.h"
25 1.1 mrg #include "ipa-predicate.h"
26 1.1 mrg
27 1.1 mrg
28 1.1 mrg /* Hints are reasons why IPA heuristics should preffer specializing given
29 1.1 mrg function. They are represtented as bitmap of the following values. */
30 1.1 mrg enum ipa_hints_vals {
31 1.1 mrg /* When specialization turns indirect call into a direct call,
32 1.1 mrg it is good idea to do so. */
33 1.1 mrg INLINE_HINT_indirect_call = 1,
34 1.1 mrg /* Inlining may make loop iterations or loop stride known. It is good idea
35 1.1 mrg to do so because it enables loop optimizatoins. */
36 1.1 mrg INLINE_HINT_loop_iterations = 2,
37 1.1 mrg INLINE_HINT_loop_stride = 4,
38 1.1 mrg /* Inlining within same strongly connected component of callgraph is often
39 1.1 mrg a loss due to increased stack frame usage and prologue setup costs. */
40 1.1 mrg INLINE_HINT_same_scc = 8,
41 1.1 mrg /* Inlining functions in strongly connected component is not such a great
42 1.1 mrg win. */
43 1.1 mrg INLINE_HINT_in_scc = 16,
44 1.1 mrg /* If function is declared inline by user, it may be good idea to inline
45 1.1 mrg it. Set by simple_edge_hints in ipa-inline-analysis.c. */
46 1.1 mrg INLINE_HINT_declared_inline = 32,
47 1.1 mrg /* Programs are usually still organized for non-LTO compilation and thus
48 1.1 mrg if functions are in different modules, inlining may not be so important.
49 1.1 mrg Set by simple_edge_hints in ipa-inline-analysis.c. */
50 1.1 mrg INLINE_HINT_cross_module = 64,
51 1.1 mrg /* If array indexes of loads/stores become known there may be room for
52 1.1 mrg further optimization. */
53 1.1 mrg INLINE_HINT_array_index = 128,
54 1.1 mrg /* We know that the callee is hot by profile. */
55 1.1 mrg INLINE_HINT_known_hot = 256
56 1.1 mrg };
57 1.1 mrg
58 1.1 mrg typedef int ipa_hints;
59 1.1 mrg
60 1.1 mrg /* Simple description of whether a memory load or a condition refers to a load
61 1.1 mrg from an aggregate and if so, how and where from in the aggregate.
62 1.1 mrg Individual fields have the same meaning like fields with the same name in
63 1.1 mrg struct condition. */
64 1.1 mrg
65 1.1 mrg struct agg_position_info
66 1.1 mrg {
67 1.1 mrg HOST_WIDE_INT offset;
68 1.1 mrg bool agg_contents;
69 1.1 mrg bool by_ref;
70 1.1 mrg };
71 1.1 mrg
72 1.1 mrg /* Representation of function body size and time depending on the call
73 1.1 mrg context. We keep simple array of record, every containing of predicate
74 1.1 mrg and time/size to account. */
75 1.1 mrg struct GTY(()) size_time_entry
76 1.1 mrg {
77 1.1 mrg /* Predicate for code to be executed. */
78 1.1 mrg predicate exec_predicate;
79 1.1 mrg /* Predicate for value to be constant and optimized out in a specialized copy.
80 1.1 mrg When deciding on specialization this makes it possible to see how much
81 1.1 mrg the executed code paths will simplify. */
82 1.1 mrg predicate nonconst_predicate;
83 1.1 mrg int size;
84 1.1 mrg sreal GTY((skip)) time;
85 1.1 mrg };
86 1.1 mrg
87 1.1 mrg /* Function inlining information. */
88 1.1 mrg struct GTY(()) ipa_fn_summary
89 1.1 mrg {
90 1.1.1.2 mrg /* Keep all field empty so summary dumping works during its computation.
91 1.1.1.2 mrg This is useful for debugging. */
92 1.1.1.2 mrg ipa_fn_summary ()
93 1.1.1.2 mrg : estimated_self_stack_size (0), self_size (0), min_size (0),
94 1.1.1.2 mrg inlinable (false), single_caller (false),
95 1.1.1.2 mrg fp_expressions (false), estimated_stack_size (false),
96 1.1.1.2 mrg stack_frame_offset (false), time (0), size (0), conds (NULL),
97 1.1.1.2 mrg size_time_table (NULL), loop_iterations (NULL), loop_stride (NULL),
98 1.1.1.2 mrg array_index (NULL), growth (0), scc_no (0)
99 1.1.1.2 mrg {
100 1.1.1.2 mrg }
101 1.1.1.2 mrg
102 1.1.1.2 mrg /* Copy constructor. */
103 1.1.1.2 mrg ipa_fn_summary (const ipa_fn_summary &s)
104 1.1.1.2 mrg : estimated_self_stack_size (s.estimated_self_stack_size),
105 1.1.1.2 mrg self_size (s.self_size), min_size (s.min_size),
106 1.1.1.2 mrg inlinable (s.inlinable), single_caller (s.single_caller),
107 1.1.1.2 mrg fp_expressions (s.fp_expressions),
108 1.1.1.2 mrg estimated_stack_size (s.estimated_stack_size),
109 1.1.1.2 mrg stack_frame_offset (s.stack_frame_offset), time (s.time), size (s.size),
110 1.1.1.2 mrg conds (s.conds), size_time_table (s.size_time_table),
111 1.1.1.2 mrg loop_iterations (s.loop_iterations), loop_stride (s.loop_stride),
112 1.1.1.2 mrg array_index (s.array_index), growth (s.growth), scc_no (s.scc_no)
113 1.1.1.2 mrg {}
114 1.1.1.2 mrg
115 1.1.1.2 mrg /* Default constructor. */
116 1.1.1.2 mrg ~ipa_fn_summary ();
117 1.1.1.2 mrg
118 1.1 mrg /* Information about the function body itself. */
119 1.1 mrg
120 1.1 mrg /* Estimated stack frame consumption by the function. */
121 1.1 mrg HOST_WIDE_INT estimated_self_stack_size;
122 1.1 mrg /* Size of the function body. */
123 1.1 mrg int self_size;
124 1.1 mrg /* Minimal size increase after inlining. */
125 1.1 mrg int min_size;
126 1.1 mrg
127 1.1 mrg /* False when there something makes inlining impossible (such as va_arg). */
128 1.1 mrg unsigned inlinable : 1;
129 1.1 mrg /* True wen there is only one caller of the function before small function
130 1.1 mrg inlining. */
131 1.1 mrg unsigned int single_caller : 1;
132 1.1 mrg /* True if function contains any floating point expressions. */
133 1.1 mrg unsigned int fp_expressions : 1;
134 1.1 mrg
135 1.1 mrg /* Information about function that will result after applying all the
136 1.1 mrg inline decisions present in the callgraph. Generally kept up to
137 1.1 mrg date only for functions that are not inline clones. */
138 1.1 mrg
139 1.1 mrg /* Estimated stack frame consumption by the function. */
140 1.1 mrg HOST_WIDE_INT estimated_stack_size;
141 1.1 mrg /* Expected offset of the stack frame of function. */
142 1.1 mrg HOST_WIDE_INT stack_frame_offset;
143 1.1 mrg /* Estimated size of the function after inlining. */
144 1.1 mrg sreal GTY((skip)) time;
145 1.1 mrg int size;
146 1.1 mrg
147 1.1 mrg /* Conditional size/time information. The summaries are being
148 1.1 mrg merged during inlining. */
149 1.1 mrg conditions conds;
150 1.1 mrg vec<size_time_entry, va_gc> *size_time_table;
151 1.1 mrg
152 1.1 mrg /* Predicate on when some loop in the function becomes to have known
153 1.1 mrg bounds. */
154 1.1 mrg predicate * GTY((skip)) loop_iterations;
155 1.1 mrg /* Predicate on when some loop in the function becomes to have known
156 1.1 mrg stride. */
157 1.1 mrg predicate * GTY((skip)) loop_stride;
158 1.1 mrg /* Predicate on when some array indexes become constants. */
159 1.1 mrg predicate * GTY((skip)) array_index;
160 1.1 mrg /* Estimated growth for inlining all copies of the function before start
161 1.1 mrg of small functions inlining.
162 1.1 mrg This value will get out of date as the callers are duplicated, but
163 1.1 mrg using up-to-date value in the badness metric mean a lot of extra
164 1.1 mrg expenses. */
165 1.1 mrg int growth;
166 1.1 mrg /* Number of SCC on the beginning of inlining process. */
167 1.1 mrg int scc_no;
168 1.1 mrg
169 1.1 mrg /* Record time and size under given predicates. */
170 1.1 mrg void account_size_time (int, sreal, const predicate &, const predicate &);
171 1.1 mrg
172 1.1 mrg /* We keep values scaled up, so fractional sizes can be accounted. */
173 1.1 mrg static const int size_scale = 2;
174 1.1 mrg };
175 1.1 mrg
176 1.1.1.2 mrg class GTY((user)) ipa_fn_summary_t:
177 1.1.1.2 mrg public fast_function_summary <ipa_fn_summary *, va_gc>
178 1.1 mrg {
179 1.1 mrg public:
180 1.1.1.2 mrg ipa_fn_summary_t (symbol_table *symtab):
181 1.1.1.2 mrg fast_function_summary <ipa_fn_summary *, va_gc> (symtab) {}
182 1.1 mrg
183 1.1 mrg static ipa_fn_summary_t *create_ggc (symbol_table *symtab)
184 1.1 mrg {
185 1.1 mrg struct ipa_fn_summary_t *summary = new (ggc_alloc <ipa_fn_summary_t> ())
186 1.1.1.2 mrg ipa_fn_summary_t (symtab);
187 1.1 mrg summary->disable_insertion_hook ();
188 1.1 mrg return summary;
189 1.1 mrg }
190 1.1 mrg
191 1.1.1.2 mrg /* Remove ipa_fn_summary for all callees of NODE. */
192 1.1.1.2 mrg void remove_callees (cgraph_node *node);
193 1.1 mrg
194 1.1 mrg virtual void insert (cgraph_node *, ipa_fn_summary *);
195 1.1.1.2 mrg virtual void remove (cgraph_node *node, ipa_fn_summary *)
196 1.1.1.2 mrg {
197 1.1.1.2 mrg remove_callees (node);
198 1.1.1.2 mrg }
199 1.1.1.2 mrg
200 1.1 mrg virtual void duplicate (cgraph_node *src, cgraph_node *dst,
201 1.1 mrg ipa_fn_summary *src_data, ipa_fn_summary *dst_data);
202 1.1 mrg };
203 1.1 mrg
204 1.1.1.2 mrg extern GTY(()) fast_function_summary <ipa_fn_summary *, va_gc>
205 1.1.1.2 mrg *ipa_fn_summaries;
206 1.1 mrg
207 1.1 mrg /* Information kept about callgraph edges. */
208 1.1 mrg struct ipa_call_summary
209 1.1 mrg {
210 1.1.1.2 mrg /* Keep all field empty so summary dumping works during its computation.
211 1.1.1.2 mrg This is useful for debugging. */
212 1.1.1.2 mrg ipa_call_summary ()
213 1.1.1.2 mrg : predicate (NULL), param (vNULL), call_stmt_size (0), call_stmt_time (0),
214 1.1.1.2 mrg loop_depth (0), is_return_callee_uncaptured (false)
215 1.1.1.2 mrg {
216 1.1.1.2 mrg }
217 1.1.1.2 mrg
218 1.1.1.2 mrg /* Copy constructor. */
219 1.1.1.2 mrg ipa_call_summary (const ipa_call_summary &s):
220 1.1.1.2 mrg predicate (s.predicate), param (s.param), call_stmt_size (s.call_stmt_size),
221 1.1.1.2 mrg call_stmt_time (s.call_stmt_time), loop_depth (s.loop_depth),
222 1.1.1.2 mrg is_return_callee_uncaptured (s.is_return_callee_uncaptured)
223 1.1.1.2 mrg {
224 1.1.1.2 mrg }
225 1.1.1.2 mrg
226 1.1.1.2 mrg /* Default destructor. */
227 1.1.1.2 mrg ~ipa_call_summary ();
228 1.1.1.2 mrg
229 1.1 mrg class predicate *predicate;
230 1.1 mrg /* Vector indexed by parameters. */
231 1.1 mrg vec<inline_param_summary> param;
232 1.1 mrg /* Estimated size and time of the call statement. */
233 1.1 mrg int call_stmt_size;
234 1.1 mrg int call_stmt_time;
235 1.1 mrg /* Depth of loop nest, 0 means no nesting. */
236 1.1 mrg unsigned int loop_depth;
237 1.1 mrg /* Indicates whether the caller returns the value of it's callee. */
238 1.1 mrg bool is_return_callee_uncaptured;
239 1.1 mrg };
240 1.1 mrg
241 1.1.1.2 mrg class ipa_call_summary_t: public fast_call_summary <ipa_call_summary *, va_heap>
242 1.1 mrg {
243 1.1 mrg public:
244 1.1.1.2 mrg ipa_call_summary_t (symbol_table *symtab):
245 1.1.1.2 mrg fast_call_summary <ipa_call_summary *, va_heap> (symtab) {}
246 1.1 mrg
247 1.1 mrg /* Hook that is called by summary when an edge is duplicated. */
248 1.1 mrg virtual void duplicate (cgraph_edge *src, cgraph_edge *dst,
249 1.1 mrg ipa_call_summary *src_data,
250 1.1 mrg ipa_call_summary *dst_data);
251 1.1 mrg };
252 1.1 mrg
253 1.1.1.2 mrg extern fast_call_summary <ipa_call_summary *, va_heap> *ipa_call_summaries;
254 1.1 mrg
255 1.1 mrg /* In ipa-fnsummary.c */
256 1.1 mrg void ipa_debug_fn_summary (struct cgraph_node *);
257 1.1 mrg void ipa_dump_fn_summaries (FILE *f);
258 1.1 mrg void ipa_dump_fn_summary (FILE *f, struct cgraph_node *node);
259 1.1 mrg void ipa_dump_hints (FILE *f, ipa_hints);
260 1.1 mrg void ipa_free_fn_summary (void);
261 1.1 mrg void inline_analyze_function (struct cgraph_node *node);
262 1.1 mrg void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
263 1.1 mrg vec<tree>,
264 1.1 mrg vec<ipa_polymorphic_call_context>,
265 1.1 mrg vec<ipa_agg_jump_function_p>,
266 1.1 mrg int *, sreal *, sreal *,
267 1.1 mrg ipa_hints *);
268 1.1 mrg void ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge);
269 1.1 mrg void ipa_update_overall_fn_summary (struct cgraph_node *node);
270 1.1 mrg void compute_fn_summary (struct cgraph_node *, bool);
271 1.1 mrg
272 1.1 mrg
273 1.1 mrg void evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
274 1.1 mrg clause_t *clause_ptr,
275 1.1 mrg clause_t *nonspec_clause_ptr,
276 1.1 mrg vec<tree> *known_vals_ptr,
277 1.1 mrg vec<ipa_polymorphic_call_context>
278 1.1 mrg *known_contexts_ptr,
279 1.1 mrg vec<ipa_agg_jump_function_p> *);
280 1.1 mrg void estimate_node_size_and_time (struct cgraph_node *node,
281 1.1 mrg clause_t possible_truths,
282 1.1 mrg clause_t nonspec_possible_truths,
283 1.1 mrg vec<tree> known_vals,
284 1.1 mrg vec<ipa_polymorphic_call_context>,
285 1.1 mrg vec<ipa_agg_jump_function_p> known_aggs,
286 1.1 mrg int *ret_size, int *ret_min_size,
287 1.1 mrg sreal *ret_time,
288 1.1 mrg sreal *ret_nonspecialized_time,
289 1.1 mrg ipa_hints *ret_hints,
290 1.1 mrg vec<inline_param_summary>
291 1.1 mrg inline_param_summary);
292 1.1 mrg
293 1.1 mrg void ipa_fnsummary_c_finalize (void);
294 1.1 mrg
295 1.1 mrg #endif /* GCC_IPA_FNSUMMARY_H */
296