annotate gcc/ipa-inline.c @ 124:c3a50d7877e8

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