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