Mercurial > hg > CbC > CbC_gcc
annotate gcc/ipa-inline.c @ 138:fc828634a951
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 08 Nov 2018 14:17:14 +0900 |
parents | d34655255c78 |
children | 351920fa3827 |
rev | line source |
---|---|
0 | 1 /* Inlining decision heuristics. |
131 | 2 Copyright (C) 2003-2018 Free Software Foundation, Inc. |
0 | 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 /* Inlining decision heuristics | |
22 | |
111 | 23 The implementation of inliner is organized as follows: |
0 | 24 |
25 inlining heuristics limits | |
26 | |
111 | 27 can_inline_edge_p allow to check that particular inlining is allowed |
28 by the limits specified by user (allowed function growth, growth and so | |
29 on). | |
30 | |
31 Functions are inlined when it is obvious the result is profitable (such | |
32 as functions called once or when inlining reduce code size). | |
33 In addition to that we perform inlining of small functions and recursive | |
34 inlining. | |
0 | 35 |
36 inlining heuristics | |
37 | |
111 | 38 The inliner itself is split into two passes: |
39 | |
40 pass_early_inlining | |
0 | 41 |
111 | 42 Simple local inlining pass inlining callees into current function. |
43 This pass makes no use of whole unit analysis and thus it can do only | |
44 very simple decisions based on local properties. | |
0 | 45 |
111 | 46 The strength of the pass is that it is run in topological order |
47 (reverse postorder) on the callgraph. Functions are converted into SSA | |
48 form just before this pass and optimized subsequently. As a result, the | |
49 callees of the function seen by the early inliner was already optimized | |
50 and results of early inlining adds a lot of optimization opportunities | |
51 for the local optimization. | |
0 | 52 |
111 | 53 The pass handle the obvious inlining decisions within the compilation |
54 unit - inlining auto inline functions, inlining for size and | |
55 flattening. | |
0 | 56 |
111 | 57 main strength of the pass is the ability to eliminate abstraction |
58 penalty in C++ code (via combination of inlining and early | |
59 optimization) and thus improve quality of analysis done by real IPA | |
60 optimizers. | |
0 | 61 |
111 | 62 Because of lack of whole unit knowledge, the pass can not really make |
63 good code size/performance tradeoffs. It however does very simple | |
64 speculative inlining allowing code size to grow by | |
65 EARLY_INLINING_INSNS when callee is leaf function. In this case the | |
66 optimizations performed later are very likely to eliminate the cost. | |
0 | 67 |
111 | 68 pass_ipa_inline |
0 | 69 |
111 | 70 This is the real inliner able to handle inlining with whole program |
71 knowledge. It performs following steps: | |
72 | |
73 1) inlining of small functions. This is implemented by greedy | |
74 algorithm ordering all inlinable cgraph edges by their badness and | |
75 inlining them in this order as long as inline limits allows doing so. | |
0 | 76 |
111 | 77 This heuristics is not very good on inlining recursive calls. Recursive |
78 calls can be inlined with results similar to loop unrolling. To do so, | |
79 special purpose recursive inliner is executed on function when | |
80 recursive edge is met as viable candidate. | |
0 | 81 |
111 | 82 2) Unreachable functions are removed from callgraph. Inlining leads |
83 to devirtualization and other modification of callgraph so functions | |
84 may become unreachable during the process. Also functions declared as | |
85 extern inline or virtual functions are removed, since after inlining | |
86 we no longer need the offline bodies. | |
0 | 87 |
111 | 88 3) Functions called once and not exported from the unit are inlined. |
89 This should almost always lead to reduction of code size by eliminating | |
90 the need for offline copy of the function. */ | |
0 | 91 |
92 #include "config.h" | |
93 #include "system.h" | |
94 #include "coretypes.h" | |
111 | 95 #include "backend.h" |
96 #include "target.h" | |
97 #include "rtl.h" | |
0 | 98 #include "tree.h" |
111 | 99 #include "gimple.h" |
100 #include "alloc-pool.h" | |
101 #include "tree-pass.h" | |
102 #include "gimple-ssa.h" | |
103 #include "cgraph.h" | |
104 #include "lto-streamer.h" | |
105 #include "trans-mem.h" | |
106 #include "calls.h" | |
0 | 107 #include "tree-inline.h" |
108 #include "params.h" | |
111 | 109 #include "profile.h" |
110 #include "symbol-summary.h" | |
111 #include "tree-vrp.h" | |
0 | 112 #include "ipa-prop.h" |
111 | 113 #include "ipa-fnsummary.h" |
114 #include "ipa-inline.h" | |
115 #include "ipa-utils.h" | |
116 #include "sreal.h" | |
117 #include "auto-profile.h" | |
118 #include "builtins.h" | |
119 #include "fibonacci_heap.h" | |
120 #include "stringpool.h" | |
121 #include "attribs.h" | |
122 #include "asan.h" | |
122 | 123 #include "c/cbc-tree.h" |
0 | 124 |
111 | 125 typedef fibonacci_heap <sreal, cgraph_edge> edge_heap_t; |
126 typedef fibonacci_node <sreal, cgraph_edge> edge_heap_node_t; | |
0 | 127 |
128 /* Statistics we collect about inlining algorithm. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
129 static int overall_size; |
111 | 130 static profile_count max_count; |
131 static profile_count spec_rem; | |
0 | 132 |
111 | 133 /* Return false when inlining edge E would lead to violating |
134 limits on function unit growth or stack usage growth. | |
0 | 135 |
111 | 136 The relative function body growth limit is present generally |
137 to avoid problems with non-linear behavior of the compiler. | |
138 To allow inlining huge functions into tiny wrapper, the limit | |
139 is always based on the bigger of the two functions considered. | |
0 | 140 |
111 | 141 For stack growth limits we always base the growth in stack usage |
142 of the callers. We want to prevent applications from segfaulting | |
143 on stack overflow when functions with huge stack frames gets | |
144 inlined. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
145 |
111 | 146 static bool |
147 caller_growth_limits (struct cgraph_edge *e) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
148 { |
111 | 149 struct cgraph_node *to = e->caller; |
150 struct cgraph_node *what = e->callee->ultimate_alias_target (); | |
151 int newsize; | |
152 int limit = 0; | |
153 HOST_WIDE_INT stack_size_limit = 0, inlined_stack; | |
131 | 154 ipa_fn_summary *info, *what_info; |
155 ipa_fn_summary *outer_info = ipa_fn_summaries->get (to); | |
0 | 156 |
111 | 157 /* Look for function e->caller is inlined to. While doing |
158 so work out the largest function body on the way. As | |
159 described above, we want to base our function growth | |
160 limits based on that. Not on the self size of the | |
161 outer function, not on the self size of inline code | |
162 we immediately inline to. This is the most relaxed | |
163 interpretation of the rule "do not grow large functions | |
164 too much in order to prevent compiler from exploding". */ | |
165 while (true) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
166 { |
111 | 167 info = ipa_fn_summaries->get (to); |
168 if (limit < info->self_size) | |
169 limit = info->self_size; | |
170 if (stack_size_limit < info->estimated_self_stack_size) | |
171 stack_size_limit = info->estimated_self_stack_size; | |
172 if (to->global.inlined_to) | |
173 to = to->callers->caller; | |
0 | 174 else |
111 | 175 break; |
0 | 176 } |
177 | |
111 | 178 what_info = ipa_fn_summaries->get (what); |
0 | 179 |
111 | 180 if (limit < what_info->self_size) |
181 limit = what_info->self_size; | |
0 | 182 |
183 limit += limit * PARAM_VALUE (PARAM_LARGE_FUNCTION_GROWTH) / 100; | |
184 | |
185 /* Check the size after inlining against the function limits. But allow | |
186 the function to shrink if it went over the limits by forced inlining. */ | |
111 | 187 newsize = estimate_size_after_inlining (to, e); |
188 if (newsize >= info->size | |
0 | 189 && newsize > PARAM_VALUE (PARAM_LARGE_FUNCTION_INSNS) |
190 && newsize > limit) | |
191 { | |
111 | 192 e->inline_failed = CIF_LARGE_FUNCTION_GROWTH_LIMIT; |
0 | 193 return false; |
194 } | |
195 | |
111 | 196 if (!what_info->estimated_stack_size) |
197 return true; | |
0 | 198 |
111 | 199 /* FIXME: Stack size limit often prevents inlining in Fortran programs |
200 due to large i/o datastructures used by the Fortran front-end. | |
201 We ought to ignore this limit when we know that the edge is executed | |
202 on every invocation of the caller (i.e. its call statement dominates | |
203 exit block). We do not track this information, yet. */ | |
204 stack_size_limit += ((gcov_type)stack_size_limit | |
205 * PARAM_VALUE (PARAM_STACK_FRAME_GROWTH) / 100); | |
0 | 206 |
111 | 207 inlined_stack = (outer_info->stack_frame_offset |
208 + outer_info->estimated_self_stack_size | |
209 + what_info->estimated_stack_size); | |
210 /* Check new stack consumption with stack consumption at the place | |
211 stack is used. */ | |
212 if (inlined_stack > stack_size_limit | |
213 /* If function already has large stack usage from sibling | |
214 inline call, we can inline, too. | |
215 This bit overoptimistically assume that we are good at stack | |
216 packing. */ | |
217 && inlined_stack > info->estimated_stack_size | |
0 | 218 && inlined_stack > PARAM_VALUE (PARAM_LARGE_STACK_FRAME)) |
219 { | |
111 | 220 e->inline_failed = CIF_LARGE_STACK_FRAME_GROWTH_LIMIT; |
0 | 221 return false; |
222 } | |
223 return true; | |
224 } | |
225 | |
111 | 226 /* Dump info about why inlining has failed. */ |
227 | |
228 static void | |
229 report_inline_failed_reason (struct cgraph_edge *e) | |
230 { | |
231 if (dump_file) | |
232 { | |
233 fprintf (dump_file, " not inlinable: %s -> %s, %s\n", | |
234 e->caller->dump_name (), | |
235 e->callee->dump_name (), | |
236 cgraph_inline_failed_string (e->inline_failed)); | |
237 if ((e->inline_failed == CIF_TARGET_OPTION_MISMATCH | |
238 || e->inline_failed == CIF_OPTIMIZATION_MISMATCH) | |
239 && e->caller->lto_file_data | |
240 && e->callee->ultimate_alias_target ()->lto_file_data) | |
241 { | |
242 fprintf (dump_file, " LTO objects: %s, %s\n", | |
243 e->caller->lto_file_data->file_name, | |
244 e->callee->ultimate_alias_target ()->lto_file_data->file_name); | |
245 } | |
246 if (e->inline_failed == CIF_TARGET_OPTION_MISMATCH) | |
247 cl_target_option_print_diff | |
248 (dump_file, 2, target_opts_for_fn (e->caller->decl), | |
249 target_opts_for_fn (e->callee->ultimate_alias_target ()->decl)); | |
250 if (e->inline_failed == CIF_OPTIMIZATION_MISMATCH) | |
251 cl_optimization_print_diff | |
252 (dump_file, 2, opts_for_fn (e->caller->decl), | |
253 opts_for_fn (e->callee->ultimate_alias_target ()->decl)); | |
254 } | |
255 } | |
256 | |
257 /* Decide whether sanitizer-related attributes allow inlining. */ | |
0 | 258 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
259 static bool |
111 | 260 sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee) |
0 | 261 { |
111 | 262 if (!caller || !callee) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
263 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
264 |
131 | 265 return ((sanitize_flags_p (SANITIZE_ADDRESS, caller) |
266 == sanitize_flags_p (SANITIZE_ADDRESS, callee)) | |
267 && (sanitize_flags_p (SANITIZE_POINTER_COMPARE, caller) | |
268 == sanitize_flags_p (SANITIZE_POINTER_COMPARE, callee)) | |
269 && (sanitize_flags_p (SANITIZE_POINTER_SUBTRACT, caller) | |
270 == sanitize_flags_p (SANITIZE_POINTER_SUBTRACT, callee))); | |
111 | 271 } |
272 | |
273 /* Used for flags where it is safe to inline when caller's value is | |
274 grater than callee's. */ | |
275 #define check_maybe_up(flag) \ | |
276 (opts_for_fn (caller->decl)->x_##flag \ | |
277 != opts_for_fn (callee->decl)->x_##flag \ | |
278 && (!always_inline \ | |
279 || opts_for_fn (caller->decl)->x_##flag \ | |
280 < opts_for_fn (callee->decl)->x_##flag)) | |
281 /* Used for flags where it is safe to inline when caller's value is | |
282 smaller than callee's. */ | |
283 #define check_maybe_down(flag) \ | |
284 (opts_for_fn (caller->decl)->x_##flag \ | |
285 != opts_for_fn (callee->decl)->x_##flag \ | |
286 && (!always_inline \ | |
287 || opts_for_fn (caller->decl)->x_##flag \ | |
288 > opts_for_fn (callee->decl)->x_##flag)) | |
289 /* Used for flags where exact match is needed for correctness. */ | |
290 #define check_match(flag) \ | |
291 (opts_for_fn (caller->decl)->x_##flag \ | |
292 != opts_for_fn (callee->decl)->x_##flag) | |
293 | |
131 | 294 /* Decide if we can inline the edge and possibly update |
111 | 295 inline_failed reason. |
296 We check whether inlining is possible at all and whether | |
297 caller growth limits allow doing so. | |
298 | |
131 | 299 if REPORT is true, output reason to the dump file. */ |
111 | 300 |
301 static bool | |
302 can_inline_edge_p (struct cgraph_edge *e, bool report, | |
131 | 303 bool early = false) |
111 | 304 { |
305 gcc_checking_assert (e->inline_failed); | |
306 | |
307 if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR) | |
0 | 308 { |
111 | 309 if (report) |
310 report_inline_failed_reason (e); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
311 return false; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
312 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
313 |
111 | 314 bool inlinable = true; |
315 enum availability avail; | |
316 cgraph_node *caller = e->caller->global.inlined_to | |
317 ? e->caller->global.inlined_to : e->caller; | |
318 cgraph_node *callee = e->callee->ultimate_alias_target (&avail, caller); | |
0 | 319 |
111 | 320 if (!callee->definition) |
321 { | |
322 e->inline_failed = CIF_BODY_NOT_AVAILABLE; | |
323 inlinable = false; | |
324 } | |
131 | 325 if (!early && (!opt_for_fn (callee->decl, optimize) |
326 || !opt_for_fn (caller->decl, optimize))) | |
111 | 327 { |
328 e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED; | |
329 inlinable = false; | |
330 } | |
331 else if (callee->calls_comdat_local) | |
332 { | |
333 e->inline_failed = CIF_USES_COMDAT_LOCAL; | |
334 inlinable = false; | |
335 } | |
336 else if (avail <= AVAIL_INTERPOSABLE) | |
337 { | |
338 e->inline_failed = CIF_OVERWRITABLE; | |
339 inlinable = false; | |
340 } | |
341 /* All edges with call_stmt_cannot_inline_p should have inline_failed | |
342 initialized to one of FINAL_ERROR reasons. */ | |
343 else if (e->call_stmt_cannot_inline_p) | |
344 gcc_unreachable (); | |
345 /* Don't inline if the functions have different EH personalities. */ | |
346 else if (DECL_FUNCTION_PERSONALITY (caller->decl) | |
347 && DECL_FUNCTION_PERSONALITY (callee->decl) | |
348 && (DECL_FUNCTION_PERSONALITY (caller->decl) | |
349 != DECL_FUNCTION_PERSONALITY (callee->decl))) | |
350 { | |
351 e->inline_failed = CIF_EH_PERSONALITY; | |
352 inlinable = false; | |
353 } | |
354 /* TM pure functions should not be inlined into non-TM_pure | |
355 functions. */ | |
356 else if (is_tm_pure (callee->decl) && !is_tm_pure (caller->decl)) | |
357 { | |
358 e->inline_failed = CIF_UNSPECIFIED; | |
359 inlinable = false; | |
360 } | |
361 /* Check compatibility of target optimization options. */ | |
362 else if (!targetm.target_option.can_inline_p (caller->decl, | |
363 callee->decl)) | |
364 { | |
365 e->inline_failed = CIF_TARGET_OPTION_MISMATCH; | |
366 inlinable = false; | |
367 } | |
131 | 368 else if (ipa_fn_summaries->get (callee) == NULL |
369 || !ipa_fn_summaries->get (callee)->inlinable) | |
111 | 370 { |
371 e->inline_failed = CIF_FUNCTION_NOT_INLINABLE; | |
372 inlinable = false; | |
373 } | |
374 /* Don't inline a function with mismatched sanitization attributes. */ | |
375 else if (!sanitize_attrs_match_for_inline_p (caller->decl, callee->decl)) | |
0 | 376 { |
111 | 377 e->inline_failed = CIF_ATTRIBUTE_MISMATCH; |
378 inlinable = false; | |
379 } | |
131 | 380 if (!inlinable && report) |
381 report_inline_failed_reason (e); | |
382 return inlinable; | |
383 } | |
384 | |
385 /* Decide if we can inline the edge and possibly update | |
386 inline_failed reason. | |
387 We check whether inlining is possible at all and whether | |
388 caller growth limits allow doing so. | |
389 | |
390 if REPORT is true, output reason to the dump file. | |
391 | |
392 if DISREGARD_LIMITS is true, ignore size limits. */ | |
393 | |
394 static bool | |
395 can_inline_edge_by_limits_p (struct cgraph_edge *e, bool report, | |
396 bool disregard_limits = false, bool early = false) | |
397 { | |
398 gcc_checking_assert (e->inline_failed); | |
399 | |
400 if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR) | |
401 { | |
402 if (report) | |
403 report_inline_failed_reason (e); | |
404 return false; | |
405 } | |
406 | |
407 bool inlinable = true; | |
408 enum availability avail; | |
409 cgraph_node *caller = e->caller->global.inlined_to | |
410 ? e->caller->global.inlined_to : e->caller; | |
411 cgraph_node *callee = e->callee->ultimate_alias_target (&avail, caller); | |
412 tree caller_tree = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (caller->decl); | |
413 tree callee_tree | |
414 = callee ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (callee->decl) : NULL; | |
111 | 415 /* Check if caller growth allows the inlining. */ |
131 | 416 if (!DECL_DISREGARD_INLINE_LIMITS (callee->decl) |
417 && !disregard_limits | |
418 && !lookup_attribute ("flatten", | |
419 DECL_ATTRIBUTES (caller->decl)) | |
420 && !caller_growth_limits (e)) | |
111 | 421 inlinable = false; |
422 /* Don't inline a function with a higher optimization level than the | |
423 caller. FIXME: this is really just tip of iceberg of handling | |
424 optimization attribute. */ | |
425 else if (caller_tree != callee_tree) | |
426 { | |
427 bool always_inline = | |
428 (DECL_DISREGARD_INLINE_LIMITS (callee->decl) | |
429 && lookup_attribute ("always_inline", | |
430 DECL_ATTRIBUTES (callee->decl))); | |
431 ipa_fn_summary *caller_info = ipa_fn_summaries->get (caller); | |
432 ipa_fn_summary *callee_info = ipa_fn_summaries->get (callee); | |
433 | |
131 | 434 /* Until GCC 4.9 we did not check the semantics-altering flags |
435 below and inlined across optimization boundaries. | |
436 Enabling checks below breaks several packages by refusing | |
111 | 437 to inline library always_inline functions. See PR65873. |
438 Disable the check for early inlining for now until better solution | |
439 is found. */ | |
440 if (always_inline && early) | |
441 ; | |
442 /* There are some options that change IL semantics which means | |
443 we cannot inline in these cases for correctness reason. | |
444 Not even for always_inline declared functions. */ | |
445 else if (check_match (flag_wrapv) | |
446 || check_match (flag_trapv) | |
447 || check_match (flag_pcc_struct_return) | |
448 /* When caller or callee does FP math, be sure FP codegen flags | |
449 compatible. */ | |
450 || ((caller_info->fp_expressions && callee_info->fp_expressions) | |
451 && (check_maybe_up (flag_rounding_math) | |
452 || check_maybe_up (flag_trapping_math) | |
453 || check_maybe_down (flag_unsafe_math_optimizations) | |
454 || check_maybe_down (flag_finite_math_only) | |
455 || check_maybe_up (flag_signaling_nans) | |
456 || check_maybe_down (flag_cx_limited_range) | |
457 || check_maybe_up (flag_signed_zeros) | |
458 || check_maybe_down (flag_associative_math) | |
459 || check_maybe_down (flag_reciprocal_math) | |
460 || check_maybe_down (flag_fp_int_builtin_inexact) | |
461 /* Strictly speaking only when the callee contains function | |
462 calls that may end up setting errno. */ | |
463 || check_maybe_up (flag_errno_math))) | |
464 /* We do not want to make code compiled with exceptions to be | |
465 brought into a non-EH function unless we know that the callee | |
466 does not throw. | |
467 This is tracked by DECL_FUNCTION_PERSONALITY. */ | |
468 || (check_maybe_up (flag_non_call_exceptions) | |
469 && DECL_FUNCTION_PERSONALITY (callee->decl)) | |
470 || (check_maybe_up (flag_exceptions) | |
471 && DECL_FUNCTION_PERSONALITY (callee->decl)) | |
472 /* When devirtualization is diabled for callee, it is not safe | |
473 to inline it as we possibly mangled the type info. | |
474 Allow early inlining of always inlines. */ | |
475 || (!early && check_maybe_down (flag_devirtualize))) | |
0 | 476 { |
111 | 477 e->inline_failed = CIF_OPTIMIZATION_MISMATCH; |
478 inlinable = false; | |
479 } | |
480 /* gcc.dg/pr43564.c. Apply user-forced inline even at -O0. */ | |
481 else if (always_inline) | |
482 ; | |
483 /* When user added an attribute to the callee honor it. */ | |
484 else if (lookup_attribute ("optimize", DECL_ATTRIBUTES (callee->decl)) | |
485 && opts_for_fn (caller->decl) != opts_for_fn (callee->decl)) | |
486 { | |
487 e->inline_failed = CIF_OPTIMIZATION_MISMATCH; | |
488 inlinable = false; | |
489 } | |
490 /* If explicit optimize attribute are not used, the mismatch is caused | |
491 by different command line options used to build different units. | |
492 Do not care about COMDAT functions - those are intended to be | |
493 optimized with the optimization flags of module they are used in. | |
494 Also do not care about mixing up size/speed optimization when | |
495 DECL_DISREGARD_INLINE_LIMITS is set. */ | |
496 else if ((callee->merged_comdat | |
497 && !lookup_attribute ("optimize", | |
498 DECL_ATTRIBUTES (caller->decl))) | |
499 || DECL_DISREGARD_INLINE_LIMITS (callee->decl)) | |
500 ; | |
501 /* If mismatch is caused by merging two LTO units with different | |
502 optimizationflags we want to be bit nicer. However never inline | |
503 if one of functions is not optimized at all. */ | |
504 else if (!opt_for_fn (callee->decl, optimize) | |
505 || !opt_for_fn (caller->decl, optimize)) | |
506 { | |
507 e->inline_failed = CIF_OPTIMIZATION_MISMATCH; | |
508 inlinable = false; | |
509 } | |
510 /* If callee is optimized for size and caller is not, allow inlining if | |
511 code shrinks or we are in MAX_INLINE_INSNS_SINGLE limit and callee | |
512 is inline (and thus likely an unified comdat). This will allow caller | |
513 to run faster. */ | |
514 else if (opt_for_fn (callee->decl, optimize_size) | |
515 > opt_for_fn (caller->decl, optimize_size)) | |
516 { | |
517 int growth = estimate_edge_growth (e); | |
518 if (growth > 0 | |
519 && (!DECL_DECLARED_INLINE_P (callee->decl) | |
520 && growth >= MAX (MAX_INLINE_INSNS_SINGLE, | |
521 MAX_INLINE_INSNS_AUTO))) | |
522 { | |
523 e->inline_failed = CIF_OPTIMIZATION_MISMATCH; | |
524 inlinable = false; | |
525 } | |
526 } | |
527 /* If callee is more aggressively optimized for performance than caller, | |
528 we generally want to inline only cheap (runtime wise) functions. */ | |
529 else if (opt_for_fn (callee->decl, optimize_size) | |
530 < opt_for_fn (caller->decl, optimize_size) | |
531 || (opt_for_fn (callee->decl, optimize) | |
532 > opt_for_fn (caller->decl, optimize))) | |
533 { | |
534 if (estimate_edge_time (e) | |
535 >= 20 + ipa_call_summaries->get (e)->call_stmt_time) | |
536 { | |
537 e->inline_failed = CIF_OPTIMIZATION_MISMATCH; | |
538 inlinable = false; | |
539 } | |
0 | 540 } |
111 | 541 |
542 } | |
543 | |
544 if (!inlinable && report) | |
545 report_inline_failed_reason (e); | |
546 return inlinable; | |
547 } | |
548 | |
549 | |
550 /* Return true if the edge E is inlinable during early inlining. */ | |
551 | |
552 static bool | |
553 can_early_inline_edge_p (struct cgraph_edge *e) | |
554 { | |
555 struct cgraph_node *callee = e->callee->ultimate_alias_target (); | |
556 /* Early inliner might get called at WPA stage when IPA pass adds new | |
557 function. In this case we can not really do any of early inlining | |
558 because function bodies are missing. */ | |
559 if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR) | |
560 return false; | |
561 if (!gimple_has_body_p (callee->decl)) | |
562 { | |
563 e->inline_failed = CIF_BODY_NOT_AVAILABLE; | |
564 return false; | |
565 } | |
566 /* In early inliner some of callees may not be in SSA form yet | |
567 (i.e. the callgraph is cyclic and we did not process | |
568 the callee by early inliner, yet). We don't have CIF code for this | |
569 case; later we will re-do the decision in the real inliner. */ | |
570 if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (e->caller->decl)) | |
571 || !gimple_in_ssa_p (DECL_STRUCT_FUNCTION (callee->decl))) | |
572 { | |
573 if (dump_file) | |
574 fprintf (dump_file, " edge not inlinable: not in SSA form\n"); | |
575 return false; | |
576 } | |
131 | 577 if (!can_inline_edge_p (e, true, true) |
578 || !can_inline_edge_by_limits_p (e, true, false, true)) | |
111 | 579 return false; |
580 return true; | |
581 } | |
582 | |
583 | |
584 /* Return number of calls in N. Ignore cheap builtins. */ | |
585 | |
586 static int | |
587 num_calls (struct cgraph_node *n) | |
588 { | |
589 struct cgraph_edge *e; | |
590 int num = 0; | |
591 | |
592 for (e = n->callees; e; e = e->next_callee) | |
593 if (!is_inexpensive_builtin (e->callee->decl)) | |
594 num++; | |
595 return num; | |
596 } | |
597 | |
598 | |
599 /* Return true if we are interested in inlining small function. */ | |
600 | |
601 static bool | |
602 want_early_inline_function_p (struct cgraph_edge *e) | |
603 { | |
604 bool want_inline = true; | |
605 struct cgraph_node *callee = e->callee->ultimate_alias_target (); | |
606 | |
607 if (DECL_DISREGARD_INLINE_LIMITS (callee->decl)) | |
608 ; | |
609 /* For AutoFDO, we need to make sure that before profile summary, all | |
610 hot paths' IR look exactly the same as profiled binary. As a result, | |
611 in einliner, we will disregard size limit and inline those callsites | |
612 that are: | |
613 * inlined in the profiled binary, and | |
614 * the cloned callee has enough samples to be considered "hot". */ | |
615 else if (flag_auto_profile && afdo_callsite_hot_enough_for_early_inline (e)) | |
616 ; | |
617 else if (!DECL_DECLARED_INLINE_P (callee->decl) | |
618 && !opt_for_fn (e->caller->decl, flag_inline_small_functions)) | |
619 { | |
620 e->inline_failed = CIF_FUNCTION_NOT_INLINE_CANDIDATE; | |
621 report_inline_failed_reason (e); | |
622 want_inline = false; | |
0 | 623 } |
624 else | |
625 { | |
111 | 626 int growth = estimate_edge_growth (e); |
627 int n; | |
628 | |
629 if (growth <= 0) | |
630 ; | |
631 else if (!e->maybe_hot_p () | |
632 && growth > 0) | |
633 { | |
634 if (dump_file) | |
635 fprintf (dump_file, " will not early inline: %s->%s, " | |
636 "call is cold and code would grow by %i\n", | |
637 e->caller->dump_name (), | |
638 callee->dump_name (), | |
639 growth); | |
640 want_inline = false; | |
641 } | |
642 else if (growth > PARAM_VALUE (PARAM_EARLY_INLINING_INSNS)) | |
0 | 643 { |
111 | 644 if (dump_file) |
645 fprintf (dump_file, " will not early inline: %s->%s, " | |
646 "growth %i exceeds --param early-inlining-insns\n", | |
647 e->caller->dump_name (), | |
648 callee->dump_name (), | |
649 growth); | |
650 want_inline = false; | |
651 } | |
652 else if ((n = num_calls (callee)) != 0 | |
653 && growth * (n + 1) > PARAM_VALUE (PARAM_EARLY_INLINING_INSNS)) | |
654 { | |
655 if (dump_file) | |
656 fprintf (dump_file, " will not early inline: %s->%s, " | |
657 "growth %i exceeds --param early-inlining-insns " | |
658 "divided by number of calls\n", | |
659 e->caller->dump_name (), | |
660 callee->dump_name (), | |
661 growth); | |
662 want_inline = false; | |
0 | 663 } |
664 } | |
111 | 665 return want_inline; |
666 } | |
0 | 667 |
111 | 668 /* Compute time of the edge->caller + edge->callee execution when inlining |
669 does not happen. */ | |
670 | |
671 inline sreal | |
672 compute_uninlined_call_time (struct cgraph_edge *edge, | |
673 sreal uninlined_call_time) | |
674 { | |
675 cgraph_node *caller = (edge->caller->global.inlined_to | |
676 ? edge->caller->global.inlined_to | |
677 : edge->caller); | |
678 | |
131 | 679 sreal freq = edge->sreal_frequency (); |
680 if (freq > 0) | |
681 uninlined_call_time *= freq; | |
111 | 682 else |
683 uninlined_call_time = uninlined_call_time >> 11; | |
684 | |
685 sreal caller_time = ipa_fn_summaries->get (caller)->time; | |
686 return uninlined_call_time + caller_time; | |
687 } | |
688 | |
689 /* Same as compute_uinlined_call_time but compute time when inlining | |
690 does happen. */ | |
691 | |
692 inline sreal | |
693 compute_inlined_call_time (struct cgraph_edge *edge, | |
694 sreal time) | |
695 { | |
696 cgraph_node *caller = (edge->caller->global.inlined_to | |
697 ? edge->caller->global.inlined_to | |
698 : edge->caller); | |
699 sreal caller_time = ipa_fn_summaries->get (caller)->time; | |
700 | |
131 | 701 sreal freq = edge->sreal_frequency (); |
702 if (freq > 0) | |
703 time *= freq; | |
111 | 704 else |
705 time = time >> 11; | |
706 | |
707 /* This calculation should match one in ipa-inline-analysis.c | |
708 (estimate_edge_size_and_time). */ | |
131 | 709 time -= (sreal)ipa_call_summaries->get (edge)->call_stmt_time * freq; |
111 | 710 time += caller_time; |
711 if (time <= 0) | |
712 time = ((sreal) 1) >> 8; | |
713 gcc_checking_assert (time >= 0); | |
714 return time; | |
715 } | |
716 | |
717 /* Return true if the speedup for inlining E is bigger than | |
718 PARAM_MAX_INLINE_MIN_SPEEDUP. */ | |
719 | |
720 static bool | |
721 big_speedup_p (struct cgraph_edge *e) | |
722 { | |
723 sreal unspec_time; | |
724 sreal spec_time = estimate_edge_time (e, &unspec_time); | |
725 sreal time = compute_uninlined_call_time (e, unspec_time); | |
726 sreal inlined_time = compute_inlined_call_time (e, spec_time); | |
727 | |
131 | 728 if ((time - inlined_time) * 100 |
729 > (sreal) (time * PARAM_VALUE (PARAM_INLINE_MIN_SPEEDUP))) | |
111 | 730 return true; |
731 return false; | |
0 | 732 } |
733 | |
111 | 734 /* Return true if we are interested in inlining small function. |
735 When REPORT is true, report reason to dump file. */ | |
736 | |
737 static bool | |
738 want_inline_small_function_p (struct cgraph_edge *e, bool report) | |
739 { | |
740 bool want_inline = true; | |
741 struct cgraph_node *callee = e->callee->ultimate_alias_target (); | |
742 | |
131 | 743 /* Allow this function to be called before can_inline_edge_p, |
744 since it's usually cheaper. */ | |
745 if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR) | |
746 want_inline = false; | |
747 else if (DECL_DISREGARD_INLINE_LIMITS (callee->decl)) | |
111 | 748 ; |
749 else if (!DECL_DECLARED_INLINE_P (callee->decl) | |
750 && !opt_for_fn (e->caller->decl, flag_inline_small_functions)) | |
751 { | |
752 e->inline_failed = CIF_FUNCTION_NOT_INLINE_CANDIDATE; | |
753 want_inline = false; | |
754 } | |
755 /* Do fast and conservative check if the function can be good | |
756 inline candidate. At the moment we allow inline hints to | |
757 promote non-inline functions to inline and we increase | |
758 MAX_INLINE_INSNS_SINGLE 16-fold for inline functions. */ | |
759 else if ((!DECL_DECLARED_INLINE_P (callee->decl) | |
131 | 760 && (!e->count.ipa ().initialized_p () || !e->maybe_hot_p ())) |
111 | 761 && ipa_fn_summaries->get (callee)->min_size |
762 - ipa_call_summaries->get (e)->call_stmt_size | |
763 > MAX (MAX_INLINE_INSNS_SINGLE, MAX_INLINE_INSNS_AUTO)) | |
764 { | |
765 e->inline_failed = CIF_MAX_INLINE_INSNS_AUTO_LIMIT; | |
766 want_inline = false; | |
767 } | |
768 else if ((DECL_DECLARED_INLINE_P (callee->decl) | |
131 | 769 || e->count.ipa ().nonzero_p ()) |
111 | 770 && ipa_fn_summaries->get (callee)->min_size |
771 - ipa_call_summaries->get (e)->call_stmt_size | |
772 > 16 * MAX_INLINE_INSNS_SINGLE) | |
773 { | |
774 e->inline_failed = (DECL_DECLARED_INLINE_P (callee->decl) | |
775 ? CIF_MAX_INLINE_INSNS_SINGLE_LIMIT | |
776 : CIF_MAX_INLINE_INSNS_AUTO_LIMIT); | |
777 want_inline = false; | |
778 } | |
779 else | |
780 { | |
781 int growth = estimate_edge_growth (e); | |
782 ipa_hints hints = estimate_edge_hints (e); | |
783 bool big_speedup = big_speedup_p (e); | |
0 | 784 |
111 | 785 if (growth <= 0) |
786 ; | |
787 /* Apply MAX_INLINE_INSNS_SINGLE limit. Do not do so when | |
788 hints suggests that inlining given function is very profitable. */ | |
789 else if (DECL_DECLARED_INLINE_P (callee->decl) | |
790 && growth >= MAX_INLINE_INSNS_SINGLE | |
791 && ((!big_speedup | |
792 && !(hints & (INLINE_HINT_indirect_call | |
793 | INLINE_HINT_known_hot | |
794 | INLINE_HINT_loop_iterations | |
795 | INLINE_HINT_array_index | |
796 | INLINE_HINT_loop_stride))) | |
797 || growth >= MAX_INLINE_INSNS_SINGLE * 16)) | |
798 { | |
799 e->inline_failed = CIF_MAX_INLINE_INSNS_SINGLE_LIMIT; | |
800 want_inline = false; | |
801 } | |
802 else if (!DECL_DECLARED_INLINE_P (callee->decl) | |
803 && !opt_for_fn (e->caller->decl, flag_inline_functions)) | |
804 { | |
805 /* growth_likely_positive is expensive, always test it last. */ | |
806 if (growth >= MAX_INLINE_INSNS_SINGLE | |
807 || growth_likely_positive (callee, growth)) | |
808 { | |
809 e->inline_failed = CIF_NOT_DECLARED_INLINED; | |
810 want_inline = false; | |
811 } | |
812 } | |
813 /* Apply MAX_INLINE_INSNS_AUTO limit for functions not declared inline | |
814 Upgrade it to MAX_INLINE_INSNS_SINGLE when hints suggests that | |
815 inlining given function is very profitable. */ | |
816 else if (!DECL_DECLARED_INLINE_P (callee->decl) | |
817 && !big_speedup | |
818 && !(hints & INLINE_HINT_known_hot) | |
819 && growth >= ((hints & (INLINE_HINT_indirect_call | |
820 | INLINE_HINT_loop_iterations | |
821 | INLINE_HINT_array_index | |
822 | INLINE_HINT_loop_stride)) | |
823 ? MAX (MAX_INLINE_INSNS_AUTO, | |
824 MAX_INLINE_INSNS_SINGLE) | |
825 : MAX_INLINE_INSNS_AUTO)) | |
826 { | |
827 /* growth_likely_positive is expensive, always test it last. */ | |
828 if (growth >= MAX_INLINE_INSNS_SINGLE | |
829 || growth_likely_positive (callee, growth)) | |
830 { | |
831 e->inline_failed = CIF_MAX_INLINE_INSNS_AUTO_LIMIT; | |
832 want_inline = false; | |
833 } | |
834 } | |
835 /* If call is cold, do not inline when function body would grow. */ | |
836 else if (!e->maybe_hot_p () | |
837 && (growth >= MAX_INLINE_INSNS_SINGLE | |
838 || growth_likely_positive (callee, growth))) | |
839 { | |
840 e->inline_failed = CIF_UNLIKELY_CALL; | |
841 want_inline = false; | |
842 } | |
843 } | |
844 if (!want_inline && report) | |
845 report_inline_failed_reason (e); | |
846 return want_inline; | |
847 } | |
848 | |
849 /* EDGE is self recursive edge. | |
850 We hand two cases - when function A is inlining into itself | |
851 or when function A is being inlined into another inliner copy of function | |
852 A within function B. | |
853 | |
854 In first case OUTER_NODE points to the toplevel copy of A, while | |
855 in the second case OUTER_NODE points to the outermost copy of A in B. | |
856 | |
857 In both cases we want to be extra selective since | |
858 inlining the call will just introduce new recursive calls to appear. */ | |
859 | |
860 static bool | |
861 want_inline_self_recursive_call_p (struct cgraph_edge *edge, | |
862 struct cgraph_node *outer_node, | |
863 bool peeling, | |
864 int depth) | |
0 | 865 { |
111 | 866 char const *reason = NULL; |
867 bool want_inline = true; | |
131 | 868 sreal caller_freq = 1; |
111 | 869 int max_depth = PARAM_VALUE (PARAM_MAX_INLINE_RECURSIVE_DEPTH_AUTO); |
870 | |
871 if (DECL_DECLARED_INLINE_P (edge->caller->decl)) | |
872 max_depth = PARAM_VALUE (PARAM_MAX_INLINE_RECURSIVE_DEPTH); | |
873 | |
874 if (!edge->maybe_hot_p ()) | |
875 { | |
876 reason = "recursive call is cold"; | |
877 want_inline = false; | |
878 } | |
879 else if (depth > max_depth) | |
880 { | |
881 reason = "--param max-inline-recursive-depth exceeded."; | |
882 want_inline = false; | |
883 } | |
131 | 884 else if (outer_node->global.inlined_to |
885 && (caller_freq = outer_node->callers->sreal_frequency ()) == 0) | |
111 | 886 { |
131 | 887 reason = "caller frequency is 0"; |
111 | 888 want_inline = false; |
889 } | |
890 | |
891 if (!want_inline) | |
892 ; | |
131 | 893 /* Inlining of self recursive function into copy of itself within other |
894 function is transformation similar to loop peeling. | |
111 | 895 |
896 Peeling is profitable if we can inline enough copies to make probability | |
897 of actual call to the self recursive function very small. Be sure that | |
898 the probability of recursion is small. | |
899 | |
900 We ensure that the frequency of recursing is at most 1 - (1/max_depth). | |
131 | 901 This way the expected number of recursion is at most max_depth. */ |
111 | 902 else if (peeling) |
903 { | |
131 | 904 sreal max_prob = (sreal)1 - ((sreal)1 / (sreal)max_depth); |
111 | 905 int i; |
906 for (i = 1; i < depth; i++) | |
131 | 907 max_prob = max_prob * max_prob; |
908 if (edge->sreal_frequency () >= max_prob * caller_freq) | |
111 | 909 { |
910 reason = "frequency of recursive call is too large"; | |
911 want_inline = false; | |
912 } | |
913 } | |
131 | 914 /* Recursive inlining, i.e. equivalent of unrolling, is profitable if |
915 recursion depth is large. We reduce function call overhead and increase | |
916 chances that things fit in hardware return predictor. | |
111 | 917 |
918 Recursive inlining might however increase cost of stack frame setup | |
919 actually slowing down functions whose recursion tree is wide rather than | |
920 deep. | |
921 | |
922 Deciding reliably on when to do recursive inlining without profile feedback | |
923 is tricky. For now we disable recursive inlining when probability of self | |
924 recursion is low. | |
925 | |
131 | 926 Recursive inlining of self recursive call within loop also results in |
927 large loop depths that generally optimize badly. We may want to throttle | |
928 down inlining in those cases. In particular this seems to happen in one | |
929 of libstdc++ rb tree methods. */ | |
0 | 930 else |
111 | 931 { |
131 | 932 if (edge->sreal_frequency () * 100 |
933 <= caller_freq | |
934 * PARAM_VALUE (PARAM_MIN_INLINE_RECURSIVE_PROBABILITY)) | |
111 | 935 { |
936 reason = "frequency of recursive call is too small"; | |
937 want_inline = false; | |
938 } | |
939 } | |
940 if (!want_inline && dump_file) | |
941 fprintf (dump_file, " not inlining recursively: %s\n", reason); | |
942 return want_inline; | |
943 } | |
944 | |
945 /* Return true when NODE has uninlinable caller; | |
946 set HAS_HOT_CALL if it has hot call. | |
947 Worker for cgraph_for_node_and_aliases. */ | |
948 | |
949 static bool | |
950 check_callers (struct cgraph_node *node, void *has_hot_call) | |
951 { | |
952 struct cgraph_edge *e; | |
953 for (e = node->callers; e; e = e->next_caller) | |
954 { | |
955 if (!opt_for_fn (e->caller->decl, flag_inline_functions_called_once) | |
956 || !opt_for_fn (e->caller->decl, optimize)) | |
957 return true; | |
958 if (!can_inline_edge_p (e, true)) | |
959 return true; | |
960 if (e->recursive_p ()) | |
961 return true; | |
131 | 962 if (!can_inline_edge_by_limits_p (e, true)) |
963 return true; | |
111 | 964 if (!(*(bool *)has_hot_call) && e->maybe_hot_p ()) |
965 *(bool *)has_hot_call = true; | |
966 } | |
967 return false; | |
968 } | |
969 | |
970 /* If NODE has a caller, return true. */ | |
971 | |
972 static bool | |
973 has_caller_p (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED) | |
974 { | |
975 if (node->callers) | |
976 return true; | |
977 return false; | |
978 } | |
979 | |
980 /* Decide if inlining NODE would reduce unit size by eliminating | |
981 the offline copy of function. | |
982 When COLD is true the cold calls are considered, too. */ | |
983 | |
984 static bool | |
985 want_inline_function_to_all_callers_p (struct cgraph_node *node, bool cold) | |
986 { | |
987 bool has_hot_call = false; | |
988 | |
989 /* Aliases gets inlined along with the function they alias. */ | |
990 if (node->alias) | |
991 return false; | |
992 /* Already inlined? */ | |
993 if (node->global.inlined_to) | |
994 return false; | |
995 /* Does it have callers? */ | |
996 if (!node->call_for_symbol_and_aliases (has_caller_p, NULL, true)) | |
997 return false; | |
998 /* Inlining into all callers would increase size? */ | |
999 if (estimate_growth (node) > 0) | |
1000 return false; | |
1001 /* All inlines must be possible. */ | |
1002 if (node->call_for_symbol_and_aliases (check_callers, &has_hot_call, | |
1003 true)) | |
1004 return false; | |
1005 if (!cold && !has_hot_call) | |
1006 return false; | |
1007 return true; | |
0 | 1008 } |
1009 | |
1010 /* A cost model driving the inlining heuristics in a way so the edges with | |
1011 smallest badness are inlined first. After each inlining is performed | |
1012 the costs of all caller edges of nodes affected are recomputed so the | |
1013 metrics may accurately depend on values such as number of inlinable callers | |
1014 of the function or function body size. */ | |
1015 | |
111 | 1016 static sreal |
1017 edge_badness (struct cgraph_edge *edge, bool dump) | |
0 | 1018 { |
111 | 1019 sreal badness; |
1020 int growth; | |
1021 sreal edge_time, unspec_edge_time; | |
1022 struct cgraph_node *callee = edge->callee->ultimate_alias_target (); | |
1023 struct ipa_fn_summary *callee_info = ipa_fn_summaries->get (callee); | |
1024 ipa_hints hints; | |
1025 cgraph_node *caller = (edge->caller->global.inlined_to | |
1026 ? edge->caller->global.inlined_to | |
1027 : edge->caller); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1028 |
111 | 1029 growth = estimate_edge_growth (edge); |
1030 edge_time = estimate_edge_time (edge, &unspec_edge_time); | |
1031 hints = estimate_edge_hints (edge); | |
1032 gcc_checking_assert (edge_time >= 0); | |
131 | 1033 /* Check that inlined time is better, but tolerate some roundoff issues. |
1034 FIXME: When callee profile drops to 0 we account calls more. This | |
1035 should be fixed by never doing that. */ | |
1036 gcc_checking_assert ((edge_time * 100 | |
1037 - callee_info->time * 101).to_int () <= 0 | |
1038 || callee->count.ipa ().initialized_p ()); | |
111 | 1039 gcc_checking_assert (growth <= callee_info->size); |
0 | 1040 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1041 if (dump) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1042 { |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1043 fprintf (dump_file, " Badness calculation for %s -> %s\n", |
111 | 1044 edge->caller->dump_name (), |
1045 edge->callee->dump_name ()); | |
1046 fprintf (dump_file, " size growth %i, time %f unspec %f ", | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1047 growth, |
111 | 1048 edge_time.to_double (), |
1049 unspec_edge_time.to_double ()); | |
1050 ipa_dump_hints (dump_file, hints); | |
1051 if (big_speedup_p (edge)) | |
1052 fprintf (dump_file, " big_speedup"); | |
1053 fprintf (dump_file, "\n"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1054 } |
0 | 1055 |
1056 /* Always prefer inlining saving code size. */ | |
1057 if (growth <= 0) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1058 { |
111 | 1059 badness = (sreal) (-SREAL_MIN_SIG + growth) << (SREAL_MAX_EXP / 256); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1060 if (dump) |
111 | 1061 fprintf (dump_file, " %f: Growth %d <= 0\n", badness.to_double (), |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1062 growth); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1063 } |
111 | 1064 /* Inlining into EXTERNAL functions is not going to change anything unless |
1065 they are themselves inlined. */ | |
1066 else if (DECL_EXTERNAL (caller->decl)) | |
1067 { | |
1068 if (dump) | |
1069 fprintf (dump_file, " max: function is external\n"); | |
1070 return sreal::max (); | |
1071 } | |
1072 /* When profile is available. Compute badness as: | |
1073 | |
1074 time_saved * caller_count | |
1075 goodness = ------------------------------------------------- | |
1076 growth_of_caller * overall_growth * combined_size | |
0 | 1077 |
111 | 1078 badness = - goodness |
1079 | |
1080 Again use negative value to make calls with profile appear hotter | |
1081 then calls without. | |
1082 */ | |
1083 else if (opt_for_fn (caller->decl, flag_guess_branch_prob) | |
131 | 1084 || caller->count.ipa ().nonzero_p ()) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1085 { |
111 | 1086 sreal numerator, denominator; |
1087 int overall_growth; | |
1088 sreal inlined_time = compute_inlined_call_time (edge, edge_time); | |
1089 | |
1090 numerator = (compute_uninlined_call_time (edge, unspec_edge_time) | |
1091 - inlined_time); | |
131 | 1092 if (numerator <= 0) |
111 | 1093 numerator = ((sreal) 1 >> 8); |
131 | 1094 if (caller->count.ipa ().nonzero_p ()) |
1095 numerator *= caller->count.ipa ().to_gcov_type (); | |
1096 else if (caller->count.ipa ().initialized_p ()) | |
111 | 1097 numerator = numerator >> 11; |
1098 denominator = growth; | |
1099 | |
1100 overall_growth = callee_info->growth; | |
1101 | |
1102 /* Look for inliner wrappers of the form: | |
1103 | |
1104 inline_caller () | |
1105 { | |
1106 do_fast_job... | |
1107 if (need_more_work) | |
1108 noninline_callee (); | |
1109 } | |
1110 Withhout panilizing this case, we usually inline noninline_callee | |
1111 into the inline_caller because overall_growth is small preventing | |
1112 further inlining of inline_caller. | |
1113 | |
1114 Penalize only callgraph edges to functions with small overall | |
1115 growth ... | |
1116 */ | |
1117 if (growth > overall_growth | |
1118 /* ... and having only one caller which is not inlined ... */ | |
1119 && callee_info->single_caller | |
1120 && !edge->caller->global.inlined_to | |
1121 /* ... and edges executed only conditionally ... */ | |
131 | 1122 && edge->sreal_frequency () < 1 |
111 | 1123 /* ... consider case where callee is not inline but caller is ... */ |
1124 && ((!DECL_DECLARED_INLINE_P (edge->callee->decl) | |
1125 && DECL_DECLARED_INLINE_P (caller->decl)) | |
1126 /* ... or when early optimizers decided to split and edge | |
1127 frequency still indicates splitting is a win ... */ | |
1128 || (callee->split_part && !caller->split_part | |
131 | 1129 && edge->sreal_frequency () * 100 |
1130 < PARAM_VALUE | |
1131 (PARAM_PARTIAL_INLINING_ENTRY_PROBABILITY) | |
111 | 1132 /* ... and do not overwrite user specified hints. */ |
1133 && (!DECL_DECLARED_INLINE_P (edge->callee->decl) | |
1134 || DECL_DECLARED_INLINE_P (caller->decl))))) | |
1135 { | |
131 | 1136 ipa_fn_summary *caller_info = ipa_fn_summaries->get (caller); |
111 | 1137 int caller_growth = caller_info->growth; |
1138 | |
1139 /* Only apply the penalty when caller looks like inline candidate, | |
1140 and it is not called once and. */ | |
1141 if (!caller_info->single_caller && overall_growth < caller_growth | |
1142 && caller_info->inlinable | |
1143 && caller_info->size | |
1144 < (DECL_DECLARED_INLINE_P (caller->decl) | |
1145 ? MAX_INLINE_INSNS_SINGLE : MAX_INLINE_INSNS_AUTO)) | |
1146 { | |
1147 if (dump) | |
1148 fprintf (dump_file, | |
1149 " Wrapper penalty. Increasing growth %i to %i\n", | |
1150 overall_growth, caller_growth); | |
1151 overall_growth = caller_growth; | |
1152 } | |
1153 } | |
1154 if (overall_growth > 0) | |
1155 { | |
1156 /* Strongly preffer functions with few callers that can be inlined | |
1157 fully. The square root here leads to smaller binaries at average. | |
1158 Watch however for extreme cases and return to linear function | |
1159 when growth is large. */ | |
1160 if (overall_growth < 256) | |
1161 overall_growth *= overall_growth; | |
1162 else | |
1163 overall_growth += 256 * 256 - 256; | |
1164 denominator *= overall_growth; | |
1165 } | |
1166 denominator *= inlined_time; | |
1167 | |
1168 badness = - numerator / denominator; | |
1169 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1170 if (dump) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1171 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1172 fprintf (dump_file, |
111 | 1173 " %f: guessed profile. frequency %f, count %" PRId64 |
1174 " caller count %" PRId64 | |
1175 " time w/o inlining %f, time with inlining %f" | |
1176 " overall growth %i (current) %i (original)" | |
1177 " %i (compensated)\n", | |
1178 badness.to_double (), | |
131 | 1179 edge->sreal_frequency ().to_double (), |
1180 edge->count.ipa ().initialized_p () ? edge->count.ipa ().to_gcov_type () : -1, | |
1181 caller->count.ipa ().initialized_p () ? caller->count.ipa ().to_gcov_type () : -1, | |
111 | 1182 compute_uninlined_call_time (edge, |
1183 unspec_edge_time).to_double (), | |
131 | 1184 inlined_time.to_double (), |
111 | 1185 estimate_growth (callee), |
1186 callee_info->growth, overall_growth); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1187 } |
0 | 1188 } |
1189 /* When function local profile is not available or it does not give | |
1190 useful information (ie frequency is zero), base the cost on | |
1191 loop nest and overall size growth, so we optimize for overall number | |
1192 of functions fully inlined in program. */ | |
1193 else | |
1194 { | |
111 | 1195 int nest = MIN (ipa_call_summaries->get (edge)->loop_depth, 8); |
1196 badness = growth; | |
0 | 1197 |
1198 /* Decrease badness if call is nested. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1199 if (badness > 0) |
111 | 1200 badness = badness >> nest; |
0 | 1201 else |
111 | 1202 badness = badness << nest; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1203 if (dump) |
111 | 1204 fprintf (dump_file, " %f: no profile. nest %i\n", |
1205 badness.to_double (), nest); | |
0 | 1206 } |
111 | 1207 gcc_checking_assert (badness != 0); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1208 |
111 | 1209 if (edge->recursive_p ()) |
1210 badness = badness.shift (badness > 0 ? 4 : -4); | |
1211 if ((hints & (INLINE_HINT_indirect_call | |
1212 | INLINE_HINT_loop_iterations | |
1213 | INLINE_HINT_array_index | |
1214 | INLINE_HINT_loop_stride)) | |
1215 || callee_info->growth <= 0) | |
1216 badness = badness.shift (badness > 0 ? -2 : 2); | |
1217 if (hints & (INLINE_HINT_same_scc)) | |
1218 badness = badness.shift (badness > 0 ? 3 : -3); | |
1219 else if (hints & (INLINE_HINT_in_scc)) | |
1220 badness = badness.shift (badness > 0 ? 2 : -2); | |
1221 else if (hints & (INLINE_HINT_cross_module)) | |
1222 badness = badness.shift (badness > 0 ? 1 : -1); | |
1223 if (DECL_DISREGARD_INLINE_LIMITS (callee->decl)) | |
1224 badness = badness.shift (badness > 0 ? -4 : 4); | |
1225 else if ((hints & INLINE_HINT_declared_inline)) | |
1226 badness = badness.shift (badness > 0 ? -3 : 3); | |
1227 if (dump) | |
1228 fprintf (dump_file, " Adjusted by hints %f\n", badness.to_double ()); | |
1229 return badness; | |
0 | 1230 } |
1231 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1232 /* Recompute badness of EDGE and update its key in HEAP if needed. */ |
111 | 1233 static inline void |
1234 update_edge_key (edge_heap_t *heap, struct cgraph_edge *edge) | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1235 { |
111 | 1236 sreal badness = edge_badness (edge, false); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1237 if (edge->aux) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1238 { |
111 | 1239 edge_heap_node_t *n = (edge_heap_node_t *) edge->aux; |
1240 gcc_checking_assert (n->get_data () == edge); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1241 |
111 | 1242 /* fibonacci_heap::replace_key does busy updating of the |
1243 heap that is unnecesarily expensive. | |
1244 We do lazy increases: after extracting minimum if the key | |
1245 turns out to be out of date, it is re-inserted into heap | |
1246 with correct value. */ | |
1247 if (badness < n->get_key ()) | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1248 { |
111 | 1249 if (dump_file && (dump_flags & TDF_DETAILS)) |
1250 { | |
1251 fprintf (dump_file, | |
1252 " decreasing badness %s -> %s, %f to %f\n", | |
1253 edge->caller->dump_name (), | |
1254 edge->callee->dump_name (), | |
1255 n->get_key ().to_double (), | |
1256 badness.to_double ()); | |
1257 } | |
1258 heap->decrease_key (n, badness); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1259 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1260 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1261 else |
111 | 1262 { |
1263 if (dump_file && (dump_flags & TDF_DETAILS)) | |
1264 { | |
1265 fprintf (dump_file, | |
1266 " enqueuing call %s -> %s, badness %f\n", | |
1267 edge->caller->dump_name (), | |
1268 edge->callee->dump_name (), | |
1269 badness.to_double ()); | |
1270 } | |
1271 edge->aux = heap->insert (badness, edge); | |
1272 } | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1273 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1274 |
111 | 1275 |
1276 /* NODE was inlined. | |
1277 All caller edges needs to be resetted because | |
1278 size estimates change. Similarly callees needs reset | |
1279 because better context may be known. */ | |
0 | 1280 |
1281 static void | |
111 | 1282 reset_edge_caches (struct cgraph_node *node) |
0 | 1283 { |
1284 struct cgraph_edge *edge; | |
111 | 1285 struct cgraph_edge *e = node->callees; |
1286 struct cgraph_node *where = node; | |
1287 struct ipa_ref *ref; | |
0 | 1288 |
111 | 1289 if (where->global.inlined_to) |
1290 where = where->global.inlined_to; | |
0 | 1291 |
131 | 1292 if (edge_growth_cache != NULL) |
1293 for (edge = where->callers; edge; edge = edge->next_caller) | |
1294 if (edge->inline_failed) | |
1295 edge_growth_cache->remove (edge); | |
0 | 1296 |
111 | 1297 FOR_EACH_ALIAS (where, ref) |
1298 reset_edge_caches (dyn_cast <cgraph_node *> (ref->referring)); | |
0 | 1299 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1300 if (!e) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1301 return; |
111 | 1302 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1303 while (true) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1304 if (!e->inline_failed && e->callee->callees) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1305 e = e->callee->callees; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1306 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1307 { |
131 | 1308 if (edge_growth_cache != NULL && e->inline_failed) |
1309 edge_growth_cache->remove (e); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1310 if (e->next_callee) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1311 e = e->next_callee; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1312 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1313 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1314 do |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1315 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1316 if (e->caller == node) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1317 return; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1318 e = e->caller->callers; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1319 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1320 while (!e->next_callee); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1321 e = e->next_callee; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1322 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1323 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1324 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1325 |
111 | 1326 /* Recompute HEAP nodes for each of caller of NODE. |
1327 UPDATED_NODES track nodes we already visited, to avoid redundant work. | |
1328 When CHECK_INLINABLITY_FOR is set, re-check for specified edge that | |
1329 it is inlinable. Otherwise check all edges. */ | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1330 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1331 static void |
111 | 1332 update_caller_keys (edge_heap_t *heap, struct cgraph_node *node, |
1333 bitmap updated_nodes, | |
1334 struct cgraph_edge *check_inlinablity_for) | |
1335 { | |
1336 struct cgraph_edge *edge; | |
1337 struct ipa_ref *ref; | |
1338 | |
1339 if ((!node->alias && !ipa_fn_summaries->get (node)->inlinable) | |
1340 || node->global.inlined_to) | |
1341 return; | |
131 | 1342 if (!bitmap_set_bit (updated_nodes, node->get_uid ())) |
111 | 1343 return; |
1344 | |
1345 FOR_EACH_ALIAS (node, ref) | |
1346 { | |
1347 struct cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring); | |
1348 update_caller_keys (heap, alias, updated_nodes, check_inlinablity_for); | |
1349 } | |
1350 | |
1351 for (edge = node->callers; edge; edge = edge->next_caller) | |
1352 if (edge->inline_failed) | |
1353 { | |
1354 if (!check_inlinablity_for | |
1355 || check_inlinablity_for == edge) | |
1356 { | |
1357 if (can_inline_edge_p (edge, false) | |
131 | 1358 && want_inline_small_function_p (edge, false) |
1359 && can_inline_edge_by_limits_p (edge, false)) | |
111 | 1360 update_edge_key (heap, edge); |
1361 else if (edge->aux) | |
1362 { | |
1363 report_inline_failed_reason (edge); | |
1364 heap->delete_node ((edge_heap_node_t *) edge->aux); | |
1365 edge->aux = NULL; | |
1366 } | |
1367 } | |
1368 else if (edge->aux) | |
1369 update_edge_key (heap, edge); | |
1370 } | |
1371 } | |
1372 | |
1373 /* Recompute HEAP nodes for each uninlined call in NODE. | |
1374 This is used when we know that edge badnesses are going only to increase | |
1375 (we introduced new call site) and thus all we need is to insert newly | |
1376 created edges into heap. */ | |
1377 | |
1378 static void | |
1379 update_callee_keys (edge_heap_t *heap, struct cgraph_node *node, | |
1380 bitmap updated_nodes) | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1381 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1382 struct cgraph_edge *e = node->callees; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1383 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1384 if (!e) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1385 return; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1386 while (true) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1387 if (!e->inline_failed && e->callee->callees) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1388 e = e->callee->callees; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1389 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1390 { |
111 | 1391 enum availability avail; |
1392 struct cgraph_node *callee; | |
1393 /* We do not reset callee growth cache here. Since we added a new call, | |
1394 growth chould have just increased and consequentely badness metric | |
1395 don't need updating. */ | |
1396 if (e->inline_failed | |
1397 && (callee = e->callee->ultimate_alias_target (&avail, e->caller)) | |
131 | 1398 && ipa_fn_summaries->get (callee) != NULL |
111 | 1399 && ipa_fn_summaries->get (callee)->inlinable |
1400 && avail >= AVAIL_AVAILABLE | |
131 | 1401 && !bitmap_bit_p (updated_nodes, callee->get_uid ())) |
111 | 1402 { |
1403 if (can_inline_edge_p (e, false) | |
131 | 1404 && want_inline_small_function_p (e, false) |
1405 && can_inline_edge_by_limits_p (e, false)) | |
111 | 1406 update_edge_key (heap, e); |
1407 else if (e->aux) | |
1408 { | |
1409 report_inline_failed_reason (e); | |
1410 heap->delete_node ((edge_heap_node_t *) e->aux); | |
1411 e->aux = NULL; | |
1412 } | |
1413 } | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1414 if (e->next_callee) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1415 e = e->next_callee; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1416 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1417 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1418 do |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1419 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1420 if (e->caller == node) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1421 return; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1422 e = e->caller->callers; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1423 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1424 while (!e->next_callee); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1425 e = e->next_callee; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1426 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1427 } |
0 | 1428 } |
1429 | |
1430 /* Enqueue all recursive calls from NODE into priority queue depending on | |
1431 how likely we want to recursively inline the call. */ | |
1432 | |
1433 static void | |
1434 lookup_recursive_calls (struct cgraph_node *node, struct cgraph_node *where, | |
111 | 1435 edge_heap_t *heap) |
0 | 1436 { |
1437 struct cgraph_edge *e; | |
111 | 1438 enum availability avail; |
1439 | |
0 | 1440 for (e = where->callees; e; e = e->next_callee) |
111 | 1441 if (e->callee == node |
1442 || (e->callee->ultimate_alias_target (&avail, e->caller) == node | |
1443 && avail > AVAIL_INTERPOSABLE)) | |
131 | 1444 heap->insert (-e->sreal_frequency (), e); |
0 | 1445 for (e = where->callees; e; e = e->next_callee) |
1446 if (!e->inline_failed) | |
1447 lookup_recursive_calls (node, e->callee, heap); | |
1448 } | |
1449 | |
1450 /* Decide on recursive inlining: in the case function has recursive calls, | |
1451 inline until body size reaches given argument. If any new indirect edges | |
1452 are discovered in the process, add them to *NEW_EDGES, unless NEW_EDGES | |
1453 is NULL. */ | |
1454 | |
1455 static bool | |
111 | 1456 recursive_inlining (struct cgraph_edge *edge, |
1457 vec<cgraph_edge *> *new_edges) | |
0 | 1458 { |
1459 int limit = PARAM_VALUE (PARAM_MAX_INLINE_INSNS_RECURSIVE_AUTO); | |
111 | 1460 edge_heap_t heap (sreal::min ()); |
1461 struct cgraph_node *node; | |
0 | 1462 struct cgraph_edge *e; |
111 | 1463 struct cgraph_node *master_clone = NULL, *next; |
0 | 1464 int depth = 0; |
1465 int n = 0; | |
1466 | |
111 | 1467 node = edge->caller; |
1468 if (node->global.inlined_to) | |
1469 node = node->global.inlined_to; | |
0 | 1470 |
1471 if (DECL_DECLARED_INLINE_P (node->decl)) | |
111 | 1472 limit = PARAM_VALUE (PARAM_MAX_INLINE_INSNS_RECURSIVE); |
0 | 1473 |
1474 /* Make sure that function is small enough to be considered for inlining. */ | |
111 | 1475 if (estimate_size_after_inlining (node, edge) >= limit) |
0 | 1476 return false; |
111 | 1477 lookup_recursive_calls (node, node, &heap); |
1478 if (heap.empty ()) | |
1479 return false; | |
0 | 1480 |
1481 if (dump_file) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1482 fprintf (dump_file, |
0 | 1483 " Performing recursive inlining on %s\n", |
111 | 1484 node->name ()); |
0 | 1485 |
1486 /* Do the inlining and update list of recursive call during process. */ | |
111 | 1487 while (!heap.empty ()) |
0 | 1488 { |
111 | 1489 struct cgraph_edge *curr = heap.extract_min (); |
1490 struct cgraph_node *cnode, *dest = curr->callee; | |
1491 | |
131 | 1492 if (!can_inline_edge_p (curr, true) |
1493 || can_inline_edge_by_limits_p (curr, true)) | |
111 | 1494 continue; |
1495 | |
1496 /* MASTER_CLONE is produced in the case we already started modified | |
1497 the function. Be sure to redirect edge to the original body before | |
1498 estimating growths otherwise we will be seeing growths after inlining | |
1499 the already modified body. */ | |
1500 if (master_clone) | |
1501 { | |
1502 curr->redirect_callee (master_clone); | |
131 | 1503 if (edge_growth_cache != NULL) |
1504 edge_growth_cache->remove (curr); | |
111 | 1505 } |
1506 | |
1507 if (estimate_size_after_inlining (node, curr) > limit) | |
1508 { | |
1509 curr->redirect_callee (dest); | |
131 | 1510 if (edge_growth_cache != NULL) |
1511 edge_growth_cache->remove (curr); | |
111 | 1512 break; |
1513 } | |
0 | 1514 |
1515 depth = 1; | |
1516 for (cnode = curr->caller; | |
1517 cnode->global.inlined_to; cnode = cnode->callers->caller) | |
111 | 1518 if (node->decl |
1519 == curr->callee->ultimate_alias_target ()->decl) | |
1520 depth++; | |
0 | 1521 |
111 | 1522 if (!want_inline_self_recursive_call_p (curr, node, false, depth)) |
0 | 1523 { |
111 | 1524 curr->redirect_callee (dest); |
131 | 1525 if (edge_growth_cache != NULL) |
1526 edge_growth_cache->remove (curr); | |
111 | 1527 continue; |
0 | 1528 } |
1529 | |
1530 if (dump_file) | |
1531 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1532 fprintf (dump_file, |
0 | 1533 " Inlining call of depth %i", depth); |
131 | 1534 if (node->count.nonzero_p ()) |
0 | 1535 { |
1536 fprintf (dump_file, " called approx. %.2f times per call", | |
111 | 1537 (double)curr->count.to_gcov_type () |
1538 / node->count.to_gcov_type ()); | |
0 | 1539 } |
1540 fprintf (dump_file, "\n"); | |
1541 } | |
111 | 1542 if (!master_clone) |
1543 { | |
1544 /* We need original clone to copy around. */ | |
1545 master_clone = node->create_clone (node->decl, node->count, | |
131 | 1546 false, vNULL, true, NULL, NULL); |
111 | 1547 for (e = master_clone->callees; e; e = e->next_callee) |
1548 if (!e->inline_failed) | |
131 | 1549 clone_inlined_nodes (e, true, false, NULL); |
111 | 1550 curr->redirect_callee (master_clone); |
131 | 1551 if (edge_growth_cache != NULL) |
1552 edge_growth_cache->remove (curr); | |
111 | 1553 } |
1554 | |
1555 inline_call (curr, false, new_edges, &overall_size, true); | |
1556 lookup_recursive_calls (node, curr->callee, &heap); | |
0 | 1557 n++; |
1558 } | |
111 | 1559 |
1560 if (!heap.empty () && dump_file) | |
0 | 1561 fprintf (dump_file, " Recursive inlining growth limit met.\n"); |
1562 | |
111 | 1563 if (!master_clone) |
1564 return false; | |
1565 | |
0 | 1566 if (dump_file) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1567 fprintf (dump_file, |
111 | 1568 "\n Inlined %i times, " |
1569 "body grown from size %i to %i, time %f to %f\n", n, | |
1570 ipa_fn_summaries->get (master_clone)->size, | |
1571 ipa_fn_summaries->get (node)->size, | |
1572 ipa_fn_summaries->get (master_clone)->time.to_double (), | |
1573 ipa_fn_summaries->get (node)->time.to_double ()); | |
0 | 1574 |
1575 /* Remove master clone we used for inlining. We rely that clones inlined | |
1576 into master clone gets queued just before master clone so we don't | |
1577 need recursion. */ | |
111 | 1578 for (node = symtab->first_function (); node != master_clone; |
0 | 1579 node = next) |
1580 { | |
111 | 1581 next = symtab->next_function (node); |
0 | 1582 if (node->global.inlined_to == master_clone) |
111 | 1583 node->remove (); |
0 | 1584 } |
111 | 1585 master_clone->remove (); |
1586 return true; | |
0 | 1587 } |
1588 | |
1589 | |
1590 /* Given whole compilation unit estimate of INSNS, compute how large we can | |
1591 allow the unit to grow. */ | |
111 | 1592 |
0 | 1593 static int |
1594 compute_max_insns (int insns) | |
1595 { | |
1596 int max_insns = insns; | |
1597 if (max_insns < PARAM_VALUE (PARAM_LARGE_UNIT_INSNS)) | |
1598 max_insns = PARAM_VALUE (PARAM_LARGE_UNIT_INSNS); | |
1599 | |
111 | 1600 return ((int64_t) max_insns |
0 | 1601 * (100 + PARAM_VALUE (PARAM_INLINE_UNIT_GROWTH)) / 100); |
1602 } | |
1603 | |
111 | 1604 |
0 | 1605 /* Compute badness of all edges in NEW_EDGES and add them to the HEAP. */ |
111 | 1606 |
0 | 1607 static void |
111 | 1608 add_new_edges_to_heap (edge_heap_t *heap, vec<cgraph_edge *> new_edges) |
0 | 1609 { |
111 | 1610 while (new_edges.length () > 0) |
0 | 1611 { |
111 | 1612 struct cgraph_edge *edge = new_edges.pop (); |
0 | 1613 |
1614 gcc_assert (!edge->aux); | |
111 | 1615 if (edge->inline_failed |
1616 && can_inline_edge_p (edge, true) | |
131 | 1617 && want_inline_small_function_p (edge, true) |
1618 && can_inline_edge_by_limits_p (edge, true)) | |
111 | 1619 edge->aux = heap->insert (edge_badness (edge, false), edge); |
1620 } | |
1621 } | |
1622 | |
1623 /* Remove EDGE from the fibheap. */ | |
1624 | |
1625 static void | |
1626 heap_edge_removal_hook (struct cgraph_edge *e, void *data) | |
1627 { | |
1628 if (e->aux) | |
1629 { | |
1630 ((edge_heap_t *)data)->delete_node ((edge_heap_node_t *)e->aux); | |
1631 e->aux = NULL; | |
0 | 1632 } |
1633 } | |
1634 | |
111 | 1635 /* Return true if speculation of edge E seems useful. |
1636 If ANTICIPATE_INLINING is true, be conservative and hope that E | |
1637 may get inlined. */ | |
1638 | |
1639 bool | |
1640 speculation_useful_p (struct cgraph_edge *e, bool anticipate_inlining) | |
1641 { | |
1642 enum availability avail; | |
1643 struct cgraph_node *target = e->callee->ultimate_alias_target (&avail, | |
1644 e->caller); | |
1645 struct cgraph_edge *direct, *indirect; | |
1646 struct ipa_ref *ref; | |
1647 | |
1648 gcc_assert (e->speculative && !e->indirect_unknown_callee); | |
1649 | |
1650 if (!e->maybe_hot_p ()) | |
1651 return false; | |
1652 | |
1653 /* See if IP optimizations found something potentially useful about the | |
1654 function. For now we look only for CONST/PURE flags. Almost everything | |
1655 else we propagate is useless. */ | |
1656 if (avail >= AVAIL_AVAILABLE) | |
1657 { | |
1658 int ecf_flags = flags_from_decl_or_type (target->decl); | |
1659 if (ecf_flags & ECF_CONST) | |
1660 { | |
1661 e->speculative_call_info (direct, indirect, ref); | |
1662 if (!(indirect->indirect_info->ecf_flags & ECF_CONST)) | |
1663 return true; | |
1664 } | |
1665 else if (ecf_flags & ECF_PURE) | |
1666 { | |
1667 e->speculative_call_info (direct, indirect, ref); | |
1668 if (!(indirect->indirect_info->ecf_flags & ECF_PURE)) | |
1669 return true; | |
1670 } | |
1671 } | |
1672 /* If we did not managed to inline the function nor redirect | |
1673 to an ipa-cp clone (that are seen by having local flag set), | |
1674 it is probably pointless to inline it unless hardware is missing | |
1675 indirect call predictor. */ | |
1676 if (!anticipate_inlining && e->inline_failed && !target->local.local) | |
1677 return false; | |
1678 /* For overwritable targets there is not much to do. */ | |
131 | 1679 if (e->inline_failed |
1680 && (!can_inline_edge_p (e, false) | |
1681 || !can_inline_edge_by_limits_p (e, false, true))) | |
111 | 1682 return false; |
1683 /* OK, speculation seems interesting. */ | |
1684 return true; | |
1685 } | |
1686 | |
1687 /* We know that EDGE is not going to be inlined. | |
1688 See if we can remove speculation. */ | |
1689 | |
1690 static void | |
1691 resolve_noninline_speculation (edge_heap_t *edge_heap, struct cgraph_edge *edge) | |
1692 { | |
1693 if (edge->speculative && !speculation_useful_p (edge, false)) | |
1694 { | |
1695 struct cgraph_node *node = edge->caller; | |
1696 struct cgraph_node *where = node->global.inlined_to | |
1697 ? node->global.inlined_to : node; | |
1698 auto_bitmap updated_nodes; | |
1699 | |
131 | 1700 if (edge->count.ipa ().initialized_p ()) |
1701 spec_rem += edge->count.ipa (); | |
111 | 1702 edge->resolve_speculation (); |
1703 reset_edge_caches (where); | |
1704 ipa_update_overall_fn_summary (where); | |
1705 update_caller_keys (edge_heap, where, | |
1706 updated_nodes, NULL); | |
1707 update_callee_keys (edge_heap, where, | |
1708 updated_nodes); | |
1709 } | |
1710 } | |
1711 | |
1712 /* Return true if NODE should be accounted for overall size estimate. | |
1713 Skip all nodes optimized for size so we can measure the growth of hot | |
1714 part of program no matter of the padding. */ | |
1715 | |
1716 bool | |
1717 inline_account_function_p (struct cgraph_node *node) | |
1718 { | |
1719 return (!DECL_EXTERNAL (node->decl) | |
1720 && !opt_for_fn (node->decl, optimize_size) | |
1721 && node->frequency != NODE_FREQUENCY_UNLIKELY_EXECUTED); | |
1722 } | |
1723 | |
1724 /* Count number of callers of NODE and store it into DATA (that | |
1725 points to int. Worker for cgraph_for_node_and_aliases. */ | |
1726 | |
1727 static bool | |
1728 sum_callers (struct cgraph_node *node, void *data) | |
1729 { | |
1730 struct cgraph_edge *e; | |
1731 int *num_calls = (int *)data; | |
1732 | |
1733 for (e = node->callers; e; e = e->next_caller) | |
1734 (*num_calls)++; | |
1735 return false; | |
1736 } | |
0 | 1737 |
1738 /* We use greedy algorithm for inlining of small functions: | |
111 | 1739 All inline candidates are put into prioritized heap ordered in |
1740 increasing badness. | |
0 | 1741 |
111 | 1742 The inlining of small functions is bounded by unit growth parameters. */ |
0 | 1743 |
1744 static void | |
111 | 1745 inline_small_functions (void) |
0 | 1746 { |
1747 struct cgraph_node *node; | |
1748 struct cgraph_edge *edge; | |
111 | 1749 edge_heap_t edge_heap (sreal::min ()); |
1750 auto_bitmap updated_nodes; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1751 int min_size, max_size; |
111 | 1752 auto_vec<cgraph_edge *> new_indirect_edges; |
1753 int initial_size = 0; | |
1754 struct cgraph_node **order = XCNEWVEC (cgraph_node *, symtab->cgraph_count); | |
1755 struct cgraph_edge_hook_list *edge_removal_hook_holder; | |
1756 new_indirect_edges.create (8); | |
1757 | |
1758 edge_removal_hook_holder | |
1759 = symtab->add_edge_removal_hook (&heap_edge_removal_hook, &edge_heap); | |
1760 | |
1761 /* Compute overall unit size and other global parameters used by badness | |
1762 metrics. */ | |
1763 | |
1764 max_count = profile_count::uninitialized (); | |
1765 ipa_reduced_postorder (order, true, true, NULL); | |
1766 free (order); | |
1767 | |
1768 FOR_EACH_DEFINED_FUNCTION (node) | |
1769 if (!node->global.inlined_to) | |
1770 { | |
1771 if (!node->alias && node->analyzed | |
1772 && (node->has_gimple_body_p () || node->thunk.thunk_p) | |
1773 && opt_for_fn (node->decl, optimize)) | |
1774 { | |
1775 struct ipa_fn_summary *info = ipa_fn_summaries->get (node); | |
1776 struct ipa_dfs_info *dfs = (struct ipa_dfs_info *) node->aux; | |
0 | 1777 |
111 | 1778 /* Do not account external functions, they will be optimized out |
1779 if not inlined. Also only count the non-cold portion of program. */ | |
1780 if (inline_account_function_p (node)) | |
1781 initial_size += info->size; | |
1782 info->growth = estimate_growth (node); | |
1783 | |
1784 int num_calls = 0; | |
1785 node->call_for_symbol_and_aliases (sum_callers, &num_calls, | |
1786 true); | |
1787 if (num_calls == 1) | |
1788 info->single_caller = true; | |
1789 if (dfs && dfs->next_cycle) | |
1790 { | |
1791 struct cgraph_node *n2; | |
1792 int id = dfs->scc_no + 1; | |
1793 for (n2 = node; n2; | |
131 | 1794 n2 = ((struct ipa_dfs_info *) n2->aux)->next_cycle) |
111 | 1795 if (opt_for_fn (n2->decl, optimize)) |
1796 { | |
131 | 1797 ipa_fn_summary *info2 = ipa_fn_summaries->get (n2); |
111 | 1798 if (info2->scc_no) |
1799 break; | |
1800 info2->scc_no = id; | |
1801 } | |
1802 } | |
1803 } | |
1804 | |
1805 for (edge = node->callers; edge; edge = edge->next_caller) | |
131 | 1806 max_count = max_count.max (edge->count.ipa ()); |
111 | 1807 } |
1808 ipa_free_postorder_info (); | |
131 | 1809 edge_growth_cache |
1810 = new call_summary<edge_growth_cache_entry *> (symtab, false); | |
0 | 1811 |
1812 if (dump_file) | |
111 | 1813 fprintf (dump_file, |
1814 "\nDeciding on inlining of small functions. Starting with size %i.\n", | |
1815 initial_size); | |
0 | 1816 |
111 | 1817 overall_size = initial_size; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1818 max_size = compute_max_insns (overall_size); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1819 min_size = overall_size; |
0 | 1820 |
111 | 1821 /* Populate the heap with all edges we might inline. */ |
1822 | |
1823 FOR_EACH_DEFINED_FUNCTION (node) | |
1824 { | |
1825 bool update = false; | |
1826 struct cgraph_edge *next = NULL; | |
1827 bool has_speculative = false; | |
1828 | |
1829 if (!opt_for_fn (node->decl, optimize)) | |
1830 continue; | |
1831 | |
1832 if (dump_file) | |
1833 fprintf (dump_file, "Enqueueing calls in %s.\n", node->dump_name ()); | |
1834 | |
1835 for (edge = node->callees; edge; edge = next) | |
1836 { | |
1837 next = edge->next_callee; | |
1838 if (edge->inline_failed | |
1839 && !edge->aux | |
1840 && can_inline_edge_p (edge, true) | |
1841 && want_inline_small_function_p (edge, true) | |
131 | 1842 && can_inline_edge_by_limits_p (edge, true) |
111 | 1843 && edge->inline_failed) |
1844 { | |
1845 gcc_assert (!edge->aux); | |
1846 update_edge_key (&edge_heap, edge); | |
1847 } | |
1848 if (edge->speculative) | |
1849 has_speculative = true; | |
1850 } | |
1851 if (has_speculative) | |
1852 for (edge = node->callees; edge; edge = next) | |
1853 if (edge->speculative && !speculation_useful_p (edge, | |
1854 edge->aux != NULL)) | |
1855 { | |
1856 edge->resolve_speculation (); | |
1857 update = true; | |
1858 } | |
1859 if (update) | |
1860 { | |
1861 struct cgraph_node *where = node->global.inlined_to | |
1862 ? node->global.inlined_to : node; | |
1863 ipa_update_overall_fn_summary (where); | |
1864 reset_edge_caches (where); | |
1865 update_caller_keys (&edge_heap, where, | |
1866 updated_nodes, NULL); | |
1867 update_callee_keys (&edge_heap, where, | |
1868 updated_nodes); | |
1869 bitmap_clear (updated_nodes); | |
1870 } | |
1871 } | |
1872 | |
1873 gcc_assert (in_lto_p | |
1874 || !(max_count > 0) | |
1875 || (profile_info && flag_branch_probabilities)); | |
1876 | |
1877 while (!edge_heap.empty ()) | |
0 | 1878 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1879 int old_size = overall_size; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1880 struct cgraph_node *where, *callee; |
111 | 1881 sreal badness = edge_heap.min_key (); |
1882 sreal current_badness; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1883 int growth; |
0 | 1884 |
111 | 1885 edge = edge_heap.extract_min (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1886 gcc_assert (edge->aux); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1887 edge->aux = NULL; |
111 | 1888 if (!edge->inline_failed || !edge->callee->analyzed) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1889 continue; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1890 |
111 | 1891 #if CHECKING_P |
131 | 1892 /* Be sure that caches are maintained consistent. |
1893 This check is affected by scaling roundoff errors when compiling for | |
1894 IPA this we skip it in that case. */ | |
1895 if (!edge->callee->count.ipa_p () | |
1896 && (!max_count.initialized_p () || !max_count.nonzero_p ())) | |
1897 { | |
1898 sreal cached_badness = edge_badness (edge, false); | |
1899 | |
1900 int old_size_est = estimate_edge_size (edge); | |
1901 sreal old_time_est = estimate_edge_time (edge); | |
1902 int old_hints_est = estimate_edge_hints (edge); | |
111 | 1903 |
131 | 1904 if (edge_growth_cache != NULL) |
1905 edge_growth_cache->remove (edge); | |
1906 gcc_assert (old_size_est == estimate_edge_size (edge)); | |
1907 gcc_assert (old_time_est == estimate_edge_time (edge)); | |
1908 /* FIXME: | |
111 | 1909 |
131 | 1910 gcc_assert (old_hints_est == estimate_edge_hints (edge)); |
111 | 1911 |
131 | 1912 fails with profile feedback because some hints depends on |
1913 maybe_hot_edge_p predicate and because callee gets inlined to other | |
1914 calls, the edge may become cold. | |
1915 This ought to be fixed by computing relative probabilities | |
1916 for given invocation but that will be better done once whole | |
1917 code is converted to sreals. Disable for now and revert to "wrong" | |
1918 value so enable/disable checking paths agree. */ | |
1919 edge_growth_cache->get (edge)->hints = old_hints_est + 1; | |
1920 | |
1921 /* When updating the edge costs, we only decrease badness in the keys. | |
1922 Increases of badness are handled lazilly; when we see key with out | |
1923 of date value on it, we re-insert it now. */ | |
1924 current_badness = edge_badness (edge, false); | |
1925 gcc_assert (cached_badness == current_badness); | |
1926 gcc_assert (current_badness >= badness); | |
1927 } | |
1928 else | |
1929 current_badness = edge_badness (edge, false); | |
111 | 1930 #else |
1931 current_badness = edge_badness (edge, false); | |
1932 #endif | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1933 if (current_badness != badness) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1934 { |
111 | 1935 if (edge_heap.min () && current_badness > edge_heap.min_key ()) |
1936 { | |
1937 edge->aux = edge_heap.insert (current_badness, edge); | |
1938 continue; | |
1939 } | |
1940 else | |
1941 badness = current_badness; | |
1942 } | |
1943 | |
131 | 1944 if (!can_inline_edge_p (edge, true) |
1945 || !can_inline_edge_by_limits_p (edge, true)) | |
111 | 1946 { |
1947 resolve_noninline_speculation (&edge_heap, edge); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1948 continue; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1949 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1950 |
111 | 1951 callee = edge->callee->ultimate_alias_target (); |
1952 growth = estimate_edge_growth (edge); | |
0 | 1953 if (dump_file) |
1954 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1955 fprintf (dump_file, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1956 "\nConsidering %s with %i size\n", |
111 | 1957 callee->dump_name (), |
1958 ipa_fn_summaries->get (callee)->size); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1959 fprintf (dump_file, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1960 " to be inlined into %s in %s:%i\n" |
111 | 1961 " Estimated badness is %f, frequency %.2f.\n", |
1962 edge->caller->dump_name (), | |
1963 edge->call_stmt | |
1964 && (LOCATION_LOCUS (gimple_location ((const gimple *) | |
1965 edge->call_stmt)) | |
1966 > BUILTINS_LOCATION) | |
1967 ? gimple_filename ((const gimple *) edge->call_stmt) | |
1968 : "unknown", | |
1969 edge->call_stmt | |
1970 ? gimple_lineno ((const gimple *) edge->call_stmt) | |
1971 : -1, | |
1972 badness.to_double (), | |
131 | 1973 edge->sreal_frequency ().to_double ()); |
1974 if (edge->count.ipa ().initialized_p ()) | |
111 | 1975 { |
1976 fprintf (dump_file, " Called "); | |
131 | 1977 edge->count.ipa ().dump (dump_file); |
1978 fprintf (dump_file, " times\n"); | |
111 | 1979 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1980 if (dump_flags & TDF_DETAILS) |
111 | 1981 edge_badness (edge, true); |
0 | 1982 } |
1983 | |
111 | 1984 if (overall_size + growth > max_size |
1985 && !DECL_DISREGARD_INLINE_LIMITS (callee->decl)) | |
0 | 1986 { |
111 | 1987 edge->inline_failed = CIF_INLINE_UNIT_GROWTH_LIMIT; |
1988 report_inline_failed_reason (edge); | |
1989 resolve_noninline_speculation (&edge_heap, edge); | |
1990 continue; | |
0 | 1991 } |
1992 | |
111 | 1993 if (!want_inline_small_function_p (edge, true)) |
0 | 1994 { |
111 | 1995 resolve_noninline_speculation (&edge_heap, edge); |
0 | 1996 continue; |
1997 } | |
111 | 1998 |
1999 /* Heuristics for inlining small functions work poorly for | |
2000 recursive calls where we do effects similar to loop unrolling. | |
2001 When inlining such edge seems profitable, leave decision on | |
2002 specific inliner. */ | |
2003 if (edge->recursive_p ()) | |
0 | 2004 { |
2005 where = edge->caller; | |
2006 if (where->global.inlined_to) | |
2007 where = where->global.inlined_to; | |
111 | 2008 if (!recursive_inlining (edge, |
2009 opt_for_fn (edge->caller->decl, | |
2010 flag_indirect_inlining) | |
2011 ? &new_indirect_edges : NULL)) | |
2012 { | |
2013 edge->inline_failed = CIF_RECURSIVE_INLINING; | |
2014 resolve_noninline_speculation (&edge_heap, edge); | |
2015 continue; | |
2016 } | |
2017 reset_edge_caches (where); | |
2018 /* Recursive inliner inlines all recursive calls of the function | |
2019 at once. Consequently we need to update all callee keys. */ | |
2020 if (opt_for_fn (edge->caller->decl, flag_indirect_inlining)) | |
2021 add_new_edges_to_heap (&edge_heap, new_indirect_edges); | |
2022 update_callee_keys (&edge_heap, where, updated_nodes); | |
2023 bitmap_clear (updated_nodes); | |
0 | 2024 } |
2025 else | |
2026 { | |
111 | 2027 struct cgraph_node *outer_node = NULL; |
2028 int depth = 0; | |
2029 | |
2030 /* Consider the case where self recursive function A is inlined | |
2031 into B. This is desired optimization in some cases, since it | |
2032 leads to effect similar of loop peeling and we might completely | |
2033 optimize out the recursive call. However we must be extra | |
2034 selective. */ | |
2035 | |
2036 where = edge->caller; | |
2037 while (where->global.inlined_to) | |
0 | 2038 { |
111 | 2039 if (where->decl == callee->decl) |
2040 outer_node = where, depth++; | |
2041 where = where->callers->caller; | |
2042 } | |
2043 if (outer_node | |
2044 && !want_inline_self_recursive_call_p (edge, outer_node, | |
2045 true, depth)) | |
2046 { | |
2047 edge->inline_failed | |
2048 = (DECL_DISREGARD_INLINE_LIMITS (edge->callee->decl) | |
2049 ? CIF_RECURSIVE_INLINING : CIF_UNSPECIFIED); | |
2050 resolve_noninline_speculation (&edge_heap, edge); | |
0 | 2051 continue; |
2052 } | |
111 | 2053 else if (depth && dump_file) |
2054 fprintf (dump_file, " Peeling recursion with depth %i\n", depth); | |
0 | 2055 |
111 | 2056 gcc_checking_assert (!callee->global.inlined_to); |
2057 inline_call (edge, true, &new_indirect_edges, &overall_size, true); | |
2058 add_new_edges_to_heap (&edge_heap, new_indirect_edges); | |
2059 | |
2060 reset_edge_caches (edge->callee); | |
2061 | |
2062 update_callee_keys (&edge_heap, where, updated_nodes); | |
0 | 2063 } |
2064 where = edge->caller; | |
2065 if (where->global.inlined_to) | |
2066 where = where->global.inlined_to; | |
2067 | |
2068 /* Our profitability metric can depend on local properties | |
2069 such as number of inlinable calls and size of the function body. | |
2070 After inlining these properties might change for the function we | |
2071 inlined into (since it's body size changed) and for the functions | |
2072 called by function we inlined (since number of it inlinable callers | |
2073 might change). */ | |
111 | 2074 update_caller_keys (&edge_heap, where, updated_nodes, NULL); |
2075 /* Offline copy count has possibly changed, recompute if profile is | |
2076 available. */ | |
131 | 2077 struct cgraph_node *n = cgraph_node::get (edge->callee->decl); |
2078 if (n != edge->callee && n->analyzed && n->count.ipa ().initialized_p ()) | |
2079 update_callee_keys (&edge_heap, n, updated_nodes); | |
0 | 2080 bitmap_clear (updated_nodes); |
2081 | |
2082 if (dump_file) | |
2083 { | |
131 | 2084 ipa_fn_summary *s = ipa_fn_summaries->get (edge->caller); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2085 fprintf (dump_file, |
111 | 2086 " Inlined %s into %s which now has time %f and size %i, " |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2087 "net change of %+i.\n", |
111 | 2088 xstrdup_for_dump (edge->callee->name ()), |
2089 xstrdup_for_dump (edge->caller->name ()), | |
131 | 2090 s->time.to_double (), |
2091 s->size, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2092 overall_size - old_size); |
0 | 2093 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2094 if (min_size > overall_size) |
0 | 2095 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2096 min_size = overall_size; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2097 max_size = compute_max_insns (min_size); |
0 | 2098 |
2099 if (dump_file) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2100 fprintf (dump_file, "New minimal size reached: %i\n", min_size); |
0 | 2101 } |
2102 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2103 |
111 | 2104 free_growth_caches (); |
2105 if (dump_file) | |
2106 fprintf (dump_file, | |
2107 "Unit growth for small function inlining: %i->%i (%i%%)\n", | |
2108 initial_size, overall_size, | |
2109 initial_size ? overall_size * 100 / (initial_size) - 100: 0); | |
2110 symtab->remove_edge_removal_hook (edge_removal_hook_holder); | |
0 | 2111 } |
2112 | |
111 | 2113 /* Flatten NODE. Performed both during early inlining and |
2114 at IPA inlining time. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2115 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2116 static void |
111 | 2117 flatten_function (struct cgraph_node *node, bool early) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2118 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2119 struct cgraph_edge *e; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2120 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2121 /* We shouldn't be called recursively when we are being processed. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2122 gcc_assert (node->aux == NULL); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2123 |
111 | 2124 node->aux = (void *) node; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2125 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2126 for (e = node->callees; e; e = e->next_callee) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2127 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2128 struct cgraph_node *orig_callee; |
111 | 2129 struct cgraph_node *callee = e->callee->ultimate_alias_target (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2130 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2131 /* We've hit cycle? It is time to give up. */ |
111 | 2132 if (callee->aux) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2133 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2134 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2135 fprintf (dump_file, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2136 "Not inlining %s into %s to avoid cycle.\n", |
111 | 2137 xstrdup_for_dump (callee->name ()), |
2138 xstrdup_for_dump (e->caller->name ())); | |
131 | 2139 if (cgraph_inline_failed_type (e->inline_failed) != CIF_FINAL_ERROR) |
2140 e->inline_failed = CIF_RECURSIVE_INLINING; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2141 continue; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2142 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2143 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2144 /* When the edge is already inlined, we just need to recurse into |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2145 it in order to fully flatten the leaves. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2146 if (!e->inline_failed) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2147 { |
111 | 2148 flatten_function (callee, early); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2149 continue; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2150 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2151 |
111 | 2152 /* Flatten attribute needs to be processed during late inlining. For |
2153 extra code quality we however do flattening during early optimization, | |
2154 too. */ | |
2155 if (!early | |
2156 ? !can_inline_edge_p (e, true) | |
131 | 2157 && !can_inline_edge_by_limits_p (e, true) |
111 | 2158 : !can_early_inline_edge_p (e)) |
2159 continue; | |
2160 | |
2161 if (e->recursive_p ()) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2162 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2163 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2164 fprintf (dump_file, "Not inlining: recursive call.\n"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2165 continue; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2166 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2167 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2168 if (gimple_in_ssa_p (DECL_STRUCT_FUNCTION (node->decl)) |
111 | 2169 != gimple_in_ssa_p (DECL_STRUCT_FUNCTION (callee->decl))) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2170 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2171 if (dump_file) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2172 fprintf (dump_file, "Not inlining: SSA form does not match.\n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2173 continue; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2174 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2175 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2176 /* Inline the edge and flatten the inline clone. Avoid |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2177 recursing through the original node if the node was cloned. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2178 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2179 fprintf (dump_file, " Inlining %s into %s.\n", |
111 | 2180 xstrdup_for_dump (callee->name ()), |
2181 xstrdup_for_dump (e->caller->name ())); | |
2182 orig_callee = callee; | |
2183 inline_call (e, true, NULL, NULL, false); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2184 if (e->callee != orig_callee) |
111 | 2185 orig_callee->aux = (void *) node; |
2186 flatten_function (e->callee, early); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2187 if (e->callee != orig_callee) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2188 orig_callee->aux = NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2189 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2190 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2191 node->aux = NULL; |
111 | 2192 if (!node->global.inlined_to) |
2193 ipa_update_overall_fn_summary (node); | |
2194 } | |
2195 | |
2196 /* Inline NODE to all callers. Worker for cgraph_for_node_and_aliases. | |
2197 DATA points to number of calls originally found so we avoid infinite | |
2198 recursion. */ | |
2199 | |
2200 static bool | |
2201 inline_to_all_callers_1 (struct cgraph_node *node, void *data, | |
2202 hash_set<cgraph_node *> *callers) | |
2203 { | |
2204 int *num_calls = (int *)data; | |
2205 bool callee_removed = false; | |
123 | 2206 #ifndef noCbC |
124 | 2207 bool tail_call_f = false; |
2208 if (node->callees) { | |
2209 if (node->callees->call_stmt) { | |
2210 if (node->callees->call_stmt->vdef) | |
2211 tail_call_f = gimple_call_tail_p (as_a <gcall *> (node->callees->call_stmt->vdef->ssa_name.def_stmt)); | |
2212 } | |
2213 } | |
2214 while (node->callers && !node->global.inlined_to && !tail_call_f) | |
123 | 2215 { |
2216 #else | |
111 | 2217 while (node->callers && !node->global.inlined_to) |
2218 { | |
123 | 2219 #endif |
111 | 2220 struct cgraph_node *caller = node->callers->caller; |
2221 | |
2222 if (!can_inline_edge_p (node->callers, true) | |
131 | 2223 || !can_inline_edge_by_limits_p (node->callers, true) |
111 | 2224 || node->callers->recursive_p ()) |
2225 { | |
2226 if (dump_file) | |
2227 fprintf (dump_file, "Uninlinable call found; giving up.\n"); | |
2228 *num_calls = 0; | |
2229 return false; | |
2230 } | |
2231 | |
2232 if (dump_file) | |
2233 { | |
131 | 2234 cgraph_node *ultimate = node->ultimate_alias_target (); |
111 | 2235 fprintf (dump_file, |
2236 "\nInlining %s size %i.\n", | |
131 | 2237 ultimate->name (), |
2238 ipa_fn_summaries->get (ultimate)->size); | |
111 | 2239 fprintf (dump_file, |
2240 " Called once from %s %i insns.\n", | |
2241 node->callers->caller->name (), | |
2242 ipa_fn_summaries->get (node->callers->caller)->size); | |
2243 } | |
2244 /* Remember which callers we inlined to, delaying updating the | |
2245 overall summary. */ | |
2246 callers->add (node->callers->caller); | |
2247 inline_call (node->callers, true, NULL, NULL, false, &callee_removed); | |
2248 if (dump_file) | |
2249 fprintf (dump_file, | |
2250 " Inlined into %s which now has %i size\n", | |
2251 caller->name (), | |
2252 ipa_fn_summaries->get (caller)->size); | |
2253 if (!(*num_calls)--) | |
2254 { | |
2255 if (dump_file) | |
2256 fprintf (dump_file, "New calls found; giving up.\n"); | |
2257 return callee_removed; | |
2258 } | |
2259 if (callee_removed) | |
2260 return true; | |
2261 } | |
2262 return false; | |
2263 } | |
2264 | |
2265 /* Wrapper around inline_to_all_callers_1 doing delayed overall summary | |
2266 update. */ | |
2267 | |
2268 static bool | |
2269 inline_to_all_callers (struct cgraph_node *node, void *data) | |
2270 { | |
2271 hash_set<cgraph_node *> callers; | |
2272 bool res = inline_to_all_callers_1 (node, data, &callers); | |
2273 /* Perform the delayed update of the overall summary of all callers | |
2274 processed. This avoids quadratic behavior in the cases where | |
2275 we have a lot of calls to the same function. */ | |
2276 for (hash_set<cgraph_node *>::iterator i = callers.begin (); | |
2277 i != callers.end (); ++i) | |
2278 ipa_update_overall_fn_summary (*i); | |
2279 return res; | |
2280 } | |
2281 | |
2282 /* Output overall time estimate. */ | |
2283 static void | |
2284 dump_overall_stats (void) | |
2285 { | |
2286 sreal sum_weighted = 0, sum = 0; | |
2287 struct cgraph_node *node; | |
2288 | |
2289 FOR_EACH_DEFINED_FUNCTION (node) | |
2290 if (!node->global.inlined_to | |
2291 && !node->alias) | |
2292 { | |
131 | 2293 ipa_fn_summary *s = ipa_fn_summaries->get (node); |
2294 if (s != NULL) | |
2295 { | |
2296 sum += s->time; | |
2297 if (node->count.ipa ().initialized_p ()) | |
2298 sum_weighted += s->time * node->count.ipa ().to_gcov_type (); | |
2299 } | |
111 | 2300 } |
2301 fprintf (dump_file, "Overall time estimate: " | |
2302 "%f weighted by profile: " | |
2303 "%f\n", sum.to_double (), sum_weighted.to_double ()); | |
2304 } | |
2305 | |
2306 /* Output some useful stats about inlining. */ | |
2307 | |
2308 static void | |
2309 dump_inline_stats (void) | |
2310 { | |
2311 int64_t inlined_cnt = 0, inlined_indir_cnt = 0; | |
2312 int64_t inlined_virt_cnt = 0, inlined_virt_indir_cnt = 0; | |
2313 int64_t noninlined_cnt = 0, noninlined_indir_cnt = 0; | |
2314 int64_t noninlined_virt_cnt = 0, noninlined_virt_indir_cnt = 0; | |
2315 int64_t inlined_speculative = 0, inlined_speculative_ply = 0; | |
2316 int64_t indirect_poly_cnt = 0, indirect_cnt = 0; | |
131 | 2317 int64_t reason[CIF_N_REASONS][2]; |
2318 sreal reason_freq[CIF_N_REASONS]; | |
111 | 2319 int i; |
2320 struct cgraph_node *node; | |
2321 | |
2322 memset (reason, 0, sizeof (reason)); | |
131 | 2323 for (i=0; i < CIF_N_REASONS; i++) |
2324 reason_freq[i] = 0; | |
111 | 2325 FOR_EACH_DEFINED_FUNCTION (node) |
2326 { | |
2327 struct cgraph_edge *e; | |
2328 for (e = node->callees; e; e = e->next_callee) | |
2329 { | |
2330 if (e->inline_failed) | |
2331 { | |
131 | 2332 if (e->count.ipa ().initialized_p ()) |
2333 reason[(int) e->inline_failed][0] += e->count.ipa ().to_gcov_type (); | |
2334 reason_freq[(int) e->inline_failed] += e->sreal_frequency (); | |
2335 reason[(int) e->inline_failed][1] ++; | |
111 | 2336 if (DECL_VIRTUAL_P (e->callee->decl) |
131 | 2337 && e->count.ipa ().initialized_p ()) |
111 | 2338 { |
2339 if (e->indirect_inlining_edge) | |
131 | 2340 noninlined_virt_indir_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2341 else |
131 | 2342 noninlined_virt_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2343 } |
131 | 2344 else if (e->count.ipa ().initialized_p ()) |
111 | 2345 { |
2346 if (e->indirect_inlining_edge) | |
131 | 2347 noninlined_indir_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2348 else |
131 | 2349 noninlined_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2350 } |
2351 } | |
131 | 2352 else if (e->count.ipa ().initialized_p ()) |
111 | 2353 { |
2354 if (e->speculative) | |
2355 { | |
2356 if (DECL_VIRTUAL_P (e->callee->decl)) | |
131 | 2357 inlined_speculative_ply += e->count.ipa ().to_gcov_type (); |
111 | 2358 else |
131 | 2359 inlined_speculative += e->count.ipa ().to_gcov_type (); |
111 | 2360 } |
2361 else if (DECL_VIRTUAL_P (e->callee->decl)) | |
2362 { | |
2363 if (e->indirect_inlining_edge) | |
131 | 2364 inlined_virt_indir_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2365 else |
131 | 2366 inlined_virt_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2367 } |
2368 else | |
2369 { | |
2370 if (e->indirect_inlining_edge) | |
131 | 2371 inlined_indir_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2372 else |
131 | 2373 inlined_cnt += e->count.ipa ().to_gcov_type (); |
111 | 2374 } |
2375 } | |
2376 } | |
2377 for (e = node->indirect_calls; e; e = e->next_callee) | |
2378 if (e->indirect_info->polymorphic | |
131 | 2379 & e->count.ipa ().initialized_p ()) |
2380 indirect_poly_cnt += e->count.ipa ().to_gcov_type (); | |
2381 else if (e->count.ipa ().initialized_p ()) | |
2382 indirect_cnt += e->count.ipa ().to_gcov_type (); | |
111 | 2383 } |
2384 if (max_count.initialized_p ()) | |
2385 { | |
2386 fprintf (dump_file, | |
2387 "Inlined %" PRId64 " + speculative " | |
2388 "%" PRId64 " + speculative polymorphic " | |
2389 "%" PRId64 " + previously indirect " | |
2390 "%" PRId64 " + virtual " | |
2391 "%" PRId64 " + virtual and previously indirect " | |
2392 "%" PRId64 "\n" "Not inlined " | |
2393 "%" PRId64 " + previously indirect " | |
2394 "%" PRId64 " + virtual " | |
2395 "%" PRId64 " + virtual and previously indirect " | |
2396 "%" PRId64 " + stil indirect " | |
2397 "%" PRId64 " + still indirect polymorphic " | |
2398 "%" PRId64 "\n", inlined_cnt, | |
2399 inlined_speculative, inlined_speculative_ply, | |
2400 inlined_indir_cnt, inlined_virt_cnt, inlined_virt_indir_cnt, | |
2401 noninlined_cnt, noninlined_indir_cnt, noninlined_virt_cnt, | |
2402 noninlined_virt_indir_cnt, indirect_cnt, indirect_poly_cnt); | |
2403 fprintf (dump_file, "Removed speculations "); | |
2404 spec_rem.dump (dump_file); | |
2405 fprintf (dump_file, "\n"); | |
2406 } | |
2407 dump_overall_stats (); | |
2408 fprintf (dump_file, "\nWhy inlining failed?\n"); | |
2409 for (i = 0; i < CIF_N_REASONS; i++) | |
131 | 2410 if (reason[i][1]) |
2411 fprintf (dump_file, "%-50s: %8i calls, %8f freq, %" PRId64" count\n", | |
111 | 2412 cgraph_inline_failed_string ((cgraph_inline_failed_t) i), |
131 | 2413 (int) reason[i][1], reason_freq[i].to_double (), reason[i][0]); |
2414 } | |
2415 | |
2416 /* Called when node is removed. */ | |
2417 | |
2418 static void | |
2419 flatten_remove_node_hook (struct cgraph_node *node, void *data) | |
2420 { | |
2421 if (lookup_attribute ("flatten", DECL_ATTRIBUTES (node->decl)) == NULL) | |
2422 return; | |
2423 | |
2424 hash_set<struct cgraph_node *> *removed | |
2425 = (hash_set<struct cgraph_node *> *) data; | |
2426 removed->add (node); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2427 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2428 |
0 | 2429 /* Decide on the inlining. We do so in the topological order to avoid |
2430 expenses on updating data structures. */ | |
2431 | |
2432 static unsigned int | |
111 | 2433 ipa_inline (void) |
0 | 2434 { |
2435 struct cgraph_node *node; | |
2436 int nnodes; | |
111 | 2437 struct cgraph_node **order; |
131 | 2438 int i, j; |
111 | 2439 int cold; |
2440 bool remove_functions = false; | |
0 | 2441 |
111 | 2442 order = XCNEWVEC (struct cgraph_node *, symtab->cgraph_count); |
0 | 2443 |
2444 if (dump_file) | |
111 | 2445 ipa_dump_fn_summaries (dump_file); |
2446 | |
2447 nnodes = ipa_reverse_postorder (order); | |
131 | 2448 spec_rem = profile_count::zero (); |
111 | 2449 |
2450 FOR_EACH_FUNCTION (node) | |
2451 { | |
2452 node->aux = 0; | |
0 | 2453 |
111 | 2454 /* Recompute the default reasons for inlining because they may have |
2455 changed during merging. */ | |
2456 if (in_lto_p) | |
2457 { | |
2458 for (cgraph_edge *e = node->callees; e; e = e->next_callee) | |
2459 { | |
2460 gcc_assert (e->inline_failed); | |
2461 initialize_inline_failed (e); | |
2462 } | |
2463 for (cgraph_edge *e = node->indirect_calls; e; e = e->next_callee) | |
2464 initialize_inline_failed (e); | |
2465 } | |
2466 } | |
0 | 2467 |
2468 if (dump_file) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2469 fprintf (dump_file, "\nFlattening functions:\n"); |
0 | 2470 |
131 | 2471 /* First shrink order array, so that it only contains nodes with |
2472 flatten attribute. */ | |
2473 for (i = nnodes - 1, j = i; i >= 0; i--) | |
2474 { | |
2475 node = order[i]; | |
2476 if (lookup_attribute ("flatten", | |
2477 DECL_ATTRIBUTES (node->decl)) != NULL) | |
2478 order[j--] = order[i]; | |
2479 } | |
2480 | |
2481 /* After the above loop, order[j + 1] ... order[nnodes - 1] contain | |
2482 nodes with flatten attribute. If there is more than one such | |
2483 node, we need to register a node removal hook, as flatten_function | |
2484 could remove other nodes with flatten attribute. See PR82801. */ | |
2485 struct cgraph_node_hook_list *node_removal_hook_holder = NULL; | |
2486 hash_set<struct cgraph_node *> *flatten_removed_nodes = NULL; | |
2487 if (j < nnodes - 2) | |
2488 { | |
2489 flatten_removed_nodes = new hash_set<struct cgraph_node *>; | |
2490 node_removal_hook_holder | |
2491 = symtab->add_cgraph_removal_hook (&flatten_remove_node_hook, | |
2492 flatten_removed_nodes); | |
2493 } | |
2494 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2495 /* In the first pass handle functions to be flattened. Do this with |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2496 a priority so none of our later choices will make this impossible. */ |
131 | 2497 for (i = nnodes - 1; i > j; i--) |
0 | 2498 { |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2499 node = order[i]; |
131 | 2500 if (flatten_removed_nodes |
2501 && flatten_removed_nodes->contains (node)) | |
2502 continue; | |
0 | 2503 |
111 | 2504 /* Handle nodes to be flattened. |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2505 Ideally when processing callees we stop inlining at the |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2506 entry of cycles, possibly cloning that entry point and |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2507 try to flatten itself turning it into a self-recursive |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2508 function. */ |
131 | 2509 if (dump_file) |
2510 fprintf (dump_file, "Flattening %s\n", node->name ()); | |
2511 flatten_function (node, false); | |
0 | 2512 } |
131 | 2513 |
2514 if (j < nnodes - 2) | |
2515 { | |
2516 symtab->remove_cgraph_removal_hook (node_removal_hook_holder); | |
2517 delete flatten_removed_nodes; | |
2518 } | |
2519 free (order); | |
2520 | |
111 | 2521 if (dump_file) |
2522 dump_overall_stats (); | |
0 | 2523 |
111 | 2524 inline_small_functions (); |
0 | 2525 |
111 | 2526 gcc_assert (symtab->state == IPA_SSA); |
2527 symtab->state = IPA_SSA_AFTER_INLINING; | |
2528 /* Do first after-inlining removal. We want to remove all "stale" extern | |
2529 inline functions and virtual functions so we really know what is called | |
2530 once. */ | |
2531 symtab->remove_unreachable_nodes (dump_file); | |
0 | 2532 |
111 | 2533 /* Inline functions with a property that after inlining into all callers the |
2534 code size will shrink because the out-of-line copy is eliminated. | |
2535 We do this regardless on the callee size as long as function growth limits | |
2536 are met. */ | |
2537 if (dump_file) | |
2538 fprintf (dump_file, | |
2539 "\nDeciding on functions to be inlined into all callers and " | |
2540 "removing useless speculations:\n"); | |
0 | 2541 |
111 | 2542 /* Inlining one function called once has good chance of preventing |
2543 inlining other function into the same callee. Ideally we should | |
2544 work in priority order, but probably inlining hot functions first | |
2545 is good cut without the extra pain of maintaining the queue. | |
2546 | |
2547 ??? this is not really fitting the bill perfectly: inlining function | |
2548 into callee often leads to better optimization of callee due to | |
2549 increased context for optimization. | |
2550 For example if main() function calls a function that outputs help | |
2551 and then function that does the main optmization, we should inline | |
2552 the second with priority even if both calls are cold by themselves. | |
2553 | |
2554 We probably want to implement new predicate replacing our use of | |
2555 maybe_hot_edge interpreted as maybe_hot_edge || callee is known | |
2556 to be hot. */ | |
2557 for (cold = 0; cold <= 1; cold ++) | |
2558 { | |
2559 FOR_EACH_DEFINED_FUNCTION (node) | |
2560 { | |
2561 struct cgraph_edge *edge, *next; | |
2562 bool update=false; | |
2563 | |
2564 if (!opt_for_fn (node->decl, optimize) | |
2565 || !opt_for_fn (node->decl, flag_inline_functions_called_once)) | |
2566 continue; | |
2567 | |
2568 for (edge = node->callees; edge; edge = next) | |
0 | 2569 { |
111 | 2570 next = edge->next_callee; |
2571 if (edge->speculative && !speculation_useful_p (edge, false)) | |
0 | 2572 { |
131 | 2573 if (edge->count.ipa ().initialized_p ()) |
2574 spec_rem += edge->count.ipa (); | |
111 | 2575 edge->resolve_speculation (); |
2576 update = true; | |
2577 remove_functions = true; | |
0 | 2578 } |
111 | 2579 } |
2580 if (update) | |
2581 { | |
2582 struct cgraph_node *where = node->global.inlined_to | |
2583 ? node->global.inlined_to : node; | |
2584 reset_edge_caches (where); | |
2585 ipa_update_overall_fn_summary (where); | |
2586 } | |
2587 if (want_inline_function_to_all_callers_p (node, cold)) | |
2588 { | |
2589 int num_calls = 0; | |
2590 node->call_for_symbol_and_aliases (sum_callers, &num_calls, | |
2591 true); | |
2592 while (node->call_for_symbol_and_aliases | |
2593 (inline_to_all_callers, &num_calls, true)) | |
2594 ; | |
2595 remove_functions = true; | |
0 | 2596 } |
2597 } | |
2598 } | |
2599 | |
2600 /* Free ipa-prop structures if they are no longer needed. */ | |
111 | 2601 ipa_free_all_structures_after_iinln (); |
2602 | |
2603 if (dump_file) | |
2604 { | |
2605 fprintf (dump_file, | |
2606 "\nInlined %i calls, eliminated %i functions\n\n", | |
2607 ncalls_inlined, nfunctions_inlined); | |
2608 dump_inline_stats (); | |
2609 } | |
0 | 2610 |
2611 if (dump_file) | |
111 | 2612 ipa_dump_fn_summaries (dump_file); |
2613 return remove_functions ? TODO_remove_functions : 0; | |
0 | 2614 } |
2615 | |
111 | 2616 /* Inline always-inline function calls in NODE. */ |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2617 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2618 static bool |
111 | 2619 inline_always_inline_functions (struct cgraph_node *node) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2620 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2621 struct cgraph_edge *e; |
111 | 2622 bool inlined = false; |
2623 | |
2624 for (e = node->callees; e; e = e->next_callee) | |
2625 { | |
2626 struct cgraph_node *callee = e->callee->ultimate_alias_target (); | |
2627 if (!DECL_DISREGARD_INLINE_LIMITS (callee->decl)) | |
2628 continue; | |
2629 | |
2630 if (e->recursive_p ()) | |
2631 { | |
2632 if (dump_file) | |
2633 fprintf (dump_file, " Not inlining recursive call to %s.\n", | |
2634 e->callee->name ()); | |
2635 e->inline_failed = CIF_RECURSIVE_INLINING; | |
2636 continue; | |
2637 } | |
2638 | |
2639 if (!can_early_inline_edge_p (e)) | |
2640 { | |
2641 /* Set inlined to true if the callee is marked "always_inline" but | |
2642 is not inlinable. This will allow flagging an error later in | |
2643 expand_call_inline in tree-inline.c. */ | |
2644 if (lookup_attribute ("always_inline", | |
2645 DECL_ATTRIBUTES (callee->decl)) != NULL) | |
2646 inlined = true; | |
2647 continue; | |
2648 } | |
2649 | |
2650 if (dump_file) | |
2651 fprintf (dump_file, " Inlining %s into %s (always_inline).\n", | |
2652 xstrdup_for_dump (e->callee->name ()), | |
2653 xstrdup_for_dump (e->caller->name ())); | |
2654 inline_call (e, true, NULL, NULL, false); | |
2655 inlined = true; | |
2656 } | |
2657 if (inlined) | |
2658 ipa_update_overall_fn_summary (node); | |
2659 | |
2660 return inlined; | |
0 | 2661 } |
2662 | |
2663 /* Decide on the inlining. We do so in the topological order to avoid | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2664 expenses on updating data structures. */ |
0 | 2665 |
2666 static bool | |
111 | 2667 early_inline_small_functions (struct cgraph_node *node) |
0 | 2668 { |
2669 struct cgraph_edge *e; | |
2670 bool inlined = false; | |
111 | 2671 |
2672 for (e = node->callees; e; e = e->next_callee) | |
2673 { | |
2674 struct cgraph_node *callee = e->callee->ultimate_alias_target (); | |
131 | 2675 |
2676 /* We can enounter not-yet-analyzed function during | |
2677 early inlining on callgraphs with strongly | |
2678 connected components. */ | |
2679 ipa_fn_summary *s = ipa_fn_summaries->get (callee); | |
2680 if (s == NULL || !s->inlinable || !e->inline_failed) | |
111 | 2681 continue; |
0 | 2682 |
111 | 2683 /* Do not consider functions not declared inline. */ |
2684 if (!DECL_DECLARED_INLINE_P (callee->decl) | |
2685 && !opt_for_fn (node->decl, flag_inline_small_functions) | |
2686 && !opt_for_fn (node->decl, flag_inline_functions)) | |
2687 continue; | |
2688 | |
2689 if (dump_file) | |
2690 fprintf (dump_file, "Considering inline candidate %s.\n", | |
2691 callee->name ()); | |
0 | 2692 |
111 | 2693 if (!can_early_inline_edge_p (e)) |
2694 continue; | |
2695 | |
2696 if (e->recursive_p ()) | |
2697 { | |
2698 if (dump_file) | |
2699 fprintf (dump_file, " Not inlining: recursive call.\n"); | |
2700 continue; | |
2701 } | |
2702 | |
2703 if (!want_early_inline_function_p (e)) | |
2704 continue; | |
2705 | |
0 | 2706 if (dump_file) |
111 | 2707 fprintf (dump_file, " Inlining %s into %s.\n", |
2708 xstrdup_for_dump (callee->name ()), | |
2709 xstrdup_for_dump (e->caller->name ())); | |
2710 inline_call (e, true, NULL, NULL, false); | |
2711 inlined = true; | |
0 | 2712 } |
2713 | |
111 | 2714 if (inlined) |
2715 ipa_update_overall_fn_summary (node); | |
0 | 2716 |
2717 return inlined; | |
2718 } | |
2719 | |
111 | 2720 unsigned int |
2721 early_inliner (function *fun) | |
0 | 2722 { |
111 | 2723 struct cgraph_node *node = cgraph_node::get (current_function_decl); |
2724 struct cgraph_edge *edge; | |
0 | 2725 unsigned int todo = 0; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2726 int iterations = 0; |
111 | 2727 bool inlined = false; |
0 | 2728 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2729 if (seen_error ()) |
0 | 2730 return 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2731 |
111 | 2732 /* Do nothing if datastructures for ipa-inliner are already computed. This |
2733 happens when some pass decides to construct new function and | |
2734 cgraph_add_new_function calls lowering passes and early optimization on | |
2735 it. This may confuse ourself when early inliner decide to inline call to | |
2736 function clone, because function clones don't have parameter list in | |
2737 ipa-prop matching their signature. */ | |
2738 if (ipa_node_params_sum) | |
2739 return 0; | |
2740 | |
2741 if (flag_checking) | |
2742 node->verify (); | |
2743 node->remove_all_references (); | |
2744 | |
2745 /* Even when not optimizing or not inlining inline always-inline | |
2746 functions. */ | |
2747 inlined = inline_always_inline_functions (node); | |
2748 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2749 if (!optimize |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2750 || flag_no_inline |
111 | 2751 || !flag_early_inlining |
2752 /* Never inline regular functions into always-inline functions | |
2753 during incremental inlining. This sucks as functions calling | |
2754 always inline functions will get less optimized, but at the | |
2755 same time inlining of functions calling always inline | |
2756 function into an always inline function might introduce | |
2757 cycles of edges to be always inlined in the callgraph. | |
2758 | |
2759 We might want to be smarter and just avoid this type of inlining. */ | |
2760 || (DECL_DISREGARD_INLINE_LIMITS (node->decl) | |
2761 && lookup_attribute ("always_inline", | |
2762 DECL_ATTRIBUTES (node->decl)))) | |
2763 ; | |
2764 else if (lookup_attribute ("flatten", | |
2765 DECL_ATTRIBUTES (node->decl)) != NULL) | |
0 | 2766 { |
111 | 2767 /* When the function is marked to be flattened, recursively inline |
2768 all calls in it. */ | |
2769 if (dump_file) | |
2770 fprintf (dump_file, | |
2771 "Flattening %s\n", node->name ()); | |
2772 flatten_function (node, true); | |
2773 inlined = true; | |
0 | 2774 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2775 else |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2776 { |
111 | 2777 /* If some always_inline functions was inlined, apply the changes. |
2778 This way we will not account always inline into growth limits and | |
2779 moreover we will inline calls from always inlines that we skipped | |
2780 previously because of conditional above. */ | |
2781 if (inlined) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2782 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2783 timevar_push (TV_INTEGRATION); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2784 todo |= optimize_inline_calls (current_function_decl); |
111 | 2785 /* optimize_inline_calls call above might have introduced new |
2786 statements that don't have inline parameters computed. */ | |
2787 for (edge = node->callees; edge; edge = edge->next_callee) | |
2788 { | |
131 | 2789 /* We can enounter not-yet-analyzed function during |
2790 early inlining on callgraphs with strongly | |
2791 connected components. */ | |
2792 ipa_call_summary *es = ipa_call_summaries->get_create (edge); | |
111 | 2793 es->call_stmt_size |
2794 = estimate_num_insns (edge->call_stmt, &eni_size_weights); | |
2795 es->call_stmt_time | |
2796 = estimate_num_insns (edge->call_stmt, &eni_time_weights); | |
2797 } | |
2798 ipa_update_overall_fn_summary (node); | |
2799 inlined = false; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2800 timevar_pop (TV_INTEGRATION); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2801 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2802 /* We iterate incremental inlining to get trivial cases of indirect |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2803 inlining. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2804 while (iterations < PARAM_VALUE (PARAM_EARLY_INLINER_MAX_ITERATIONS) |
111 | 2805 && early_inline_small_functions (node)) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2806 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2807 timevar_push (TV_INTEGRATION); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2808 todo |= optimize_inline_calls (current_function_decl); |
111 | 2809 |
2810 /* Technically we ought to recompute inline parameters so the new | |
2811 iteration of early inliner works as expected. We however have | |
2812 values approximately right and thus we only need to update edge | |
2813 info that might be cleared out for newly discovered edges. */ | |
2814 for (edge = node->callees; edge; edge = edge->next_callee) | |
2815 { | |
2816 /* We have no summary for new bound store calls yet. */ | |
131 | 2817 ipa_call_summary *es = ipa_call_summaries->get_create (edge); |
111 | 2818 es->call_stmt_size |
2819 = estimate_num_insns (edge->call_stmt, &eni_size_weights); | |
2820 es->call_stmt_time | |
2821 = estimate_num_insns (edge->call_stmt, &eni_time_weights); | |
2822 | |
2823 if (edge->callee->decl | |
2824 && !gimple_check_call_matching_types ( | |
2825 edge->call_stmt, edge->callee->decl, false)) | |
2826 { | |
2827 edge->inline_failed = CIF_MISMATCHED_ARGUMENTS; | |
2828 edge->call_stmt_cannot_inline_p = true; | |
2829 } | |
2830 } | |
2831 if (iterations < PARAM_VALUE (PARAM_EARLY_INLINER_MAX_ITERATIONS) - 1) | |
2832 ipa_update_overall_fn_summary (node); | |
2833 timevar_pop (TV_INTEGRATION); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2834 iterations++; |
111 | 2835 inlined = false; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2836 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2837 if (dump_file) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2838 fprintf (dump_file, "Iterations: %i\n", iterations); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2839 } |
0 | 2840 |
111 | 2841 if (inlined) |
2842 { | |
2843 timevar_push (TV_INTEGRATION); | |
2844 todo |= optimize_inline_calls (current_function_decl); | |
2845 timevar_pop (TV_INTEGRATION); | |
2846 } | |
2847 | |
2848 fun->always_inline_functions_inlined = true; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2849 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2850 return todo; |
0 | 2851 } |
2852 | |
111 | 2853 /* Do inlining of small functions. Doing so early helps profiling and other |
2854 passes to be somewhat more effective and avoids some code duplication in | |
2855 later real inlining pass for testcases with very many function calls. */ | |
2856 | |
2857 namespace { | |
2858 | |
2859 const pass_data pass_data_early_inline = | |
0 | 2860 { |
111 | 2861 GIMPLE_PASS, /* type */ |
2862 "einline", /* name */ | |
2863 OPTGROUP_INLINE, /* optinfo_flags */ | |
2864 TV_EARLY_INLINING, /* tv_id */ | |
2865 PROP_ssa, /* properties_required */ | |
2866 0, /* properties_provided */ | |
2867 0, /* properties_destroyed */ | |
2868 0, /* todo_flags_start */ | |
2869 0, /* todo_flags_finish */ | |
0 | 2870 }; |
2871 | |
111 | 2872 class pass_early_inline : public gimple_opt_pass |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2873 { |
111 | 2874 public: |
2875 pass_early_inline (gcc::context *ctxt) | |
2876 : gimple_opt_pass (pass_data_early_inline, ctxt) | |
2877 {} | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2878 |
111 | 2879 /* opt_pass methods: */ |
2880 virtual unsigned int execute (function *); | |
2881 | |
2882 }; // class pass_early_inline | |
2883 | |
2884 unsigned int | |
2885 pass_early_inline::execute (function *fun) | |
2886 { | |
2887 return early_inliner (fun); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2888 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2889 |
111 | 2890 } // anon namespace |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2891 |
111 | 2892 gimple_opt_pass * |
2893 make_pass_early_inline (gcc::context *ctxt) | |
0 | 2894 { |
111 | 2895 return new pass_early_inline (ctxt); |
0 | 2896 } |
2897 | |
111 | 2898 namespace { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2899 |
111 | 2900 const pass_data pass_data_ipa_inline = |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2901 { |
111 | 2902 IPA_PASS, /* type */ |
2903 "inline", /* name */ | |
2904 OPTGROUP_INLINE, /* optinfo_flags */ | |
2905 TV_IPA_INLINING, /* tv_id */ | |
2906 0, /* properties_required */ | |
2907 0, /* properties_provided */ | |
2908 0, /* properties_destroyed */ | |
2909 0, /* todo_flags_start */ | |
2910 ( TODO_dump_symtab ), /* todo_flags_finish */ | |
0 | 2911 }; |
2912 | |
111 | 2913 class pass_ipa_inline : public ipa_opt_pass_d |
2914 { | |
2915 public: | |
2916 pass_ipa_inline (gcc::context *ctxt) | |
2917 : ipa_opt_pass_d (pass_data_ipa_inline, ctxt, | |
2918 NULL, /* generate_summary */ | |
2919 NULL, /* write_summary */ | |
2920 NULL, /* read_summary */ | |
2921 NULL, /* write_optimization_summary */ | |
2922 NULL, /* read_optimization_summary */ | |
2923 NULL, /* stmt_fixup */ | |
2924 0, /* function_transform_todo_flags_start */ | |
2925 inline_transform, /* function_transform */ | |
2926 NULL) /* variable_transform */ | |
2927 {} | |
0 | 2928 |
111 | 2929 /* opt_pass methods: */ |
2930 virtual unsigned int execute (function *) { return ipa_inline (); } | |
2931 | |
2932 }; // class pass_ipa_inline | |
2933 | |
2934 } // anon namespace | |
2935 | |
2936 ipa_opt_pass_d * | |
2937 make_pass_ipa_inline (gcc::context *ctxt) | |
2938 { | |
2939 return new pass_ipa_inline (ctxt); | |
2940 } |