annotate gcc/ipa-inline.c @ 138:fc828634a951

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