annotate gcc/ipa-inline.c @ 120:f93fa5091070

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