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