annotate gcc/ipa-inline-analysis.c @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Analysis used by inlining decision heuristics.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Jan Hubicka
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "backend.h"
kono
parents:
diff changeset
25 #include "tree.h"
kono
parents:
diff changeset
26 #include "gimple.h"
kono
parents:
diff changeset
27 #include "alloc-pool.h"
kono
parents:
diff changeset
28 #include "tree-pass.h"
kono
parents:
diff changeset
29 #include "ssa.h"
kono
parents:
diff changeset
30 #include "tree-streamer.h"
kono
parents:
diff changeset
31 #include "cgraph.h"
kono
parents:
diff changeset
32 #include "diagnostic.h"
kono
parents:
diff changeset
33 #include "fold-const.h"
kono
parents:
diff changeset
34 #include "print-tree.h"
kono
parents:
diff changeset
35 #include "tree-inline.h"
kono
parents:
diff changeset
36 #include "gimple-pretty-print.h"
kono
parents:
diff changeset
37 #include "params.h"
kono
parents:
diff changeset
38 #include "cfganal.h"
kono
parents:
diff changeset
39 #include "gimple-iterator.h"
kono
parents:
diff changeset
40 #include "tree-cfg.h"
kono
parents:
diff changeset
41 #include "tree-ssa-loop-niter.h"
kono
parents:
diff changeset
42 #include "tree-ssa-loop.h"
kono
parents:
diff changeset
43 #include "symbol-summary.h"
kono
parents:
diff changeset
44 #include "ipa-prop.h"
kono
parents:
diff changeset
45 #include "ipa-fnsummary.h"
kono
parents:
diff changeset
46 #include "ipa-inline.h"
kono
parents:
diff changeset
47 #include "cfgloop.h"
kono
parents:
diff changeset
48 #include "tree-scalar-evolution.h"
kono
parents:
diff changeset
49 #include "ipa-utils.h"
kono
parents:
diff changeset
50 #include "cfgexpand.h"
kono
parents:
diff changeset
51 #include "gimplify.h"
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 /* Cached node/edge growths. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
54 call_summary<edge_growth_cache_entry *> *edge_growth_cache = NULL;
111
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 /* Give initial reasons why inlining would fail on EDGE. This gets either
kono
parents:
diff changeset
57 nullified or usually overwritten by more precise reasons later. */
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 void
kono
parents:
diff changeset
60 initialize_inline_failed (struct cgraph_edge *e)
kono
parents:
diff changeset
61 {
kono
parents:
diff changeset
62 struct cgraph_node *callee = e->callee;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 if (e->inline_failed && e->inline_failed != CIF_BODY_NOT_AVAILABLE
kono
parents:
diff changeset
65 && cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR)
kono
parents:
diff changeset
66 ;
kono
parents:
diff changeset
67 else if (e->indirect_unknown_callee)
kono
parents:
diff changeset
68 e->inline_failed = CIF_INDIRECT_UNKNOWN_CALL;
kono
parents:
diff changeset
69 else if (!callee->definition)
kono
parents:
diff changeset
70 e->inline_failed = CIF_BODY_NOT_AVAILABLE;
kono
parents:
diff changeset
71 else if (callee->local.redefined_extern_inline)
kono
parents:
diff changeset
72 e->inline_failed = CIF_REDEFINED_EXTERN_INLINE;
kono
parents:
diff changeset
73 else
kono
parents:
diff changeset
74 e->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
kono
parents:
diff changeset
75 gcc_checking_assert (!e->call_stmt_cannot_inline_p
kono
parents:
diff changeset
76 || cgraph_inline_failed_type (e->inline_failed)
kono
parents:
diff changeset
77 == CIF_FINAL_ERROR);
kono
parents:
diff changeset
78 }
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 /* Free growth caches. */
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 void
kono
parents:
diff changeset
84 free_growth_caches (void)
kono
parents:
diff changeset
85 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86 delete edge_growth_cache;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 edge_growth_cache = NULL;
111
kono
parents:
diff changeset
88 }
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 /* Return hints derrived from EDGE. */
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 int
kono
parents:
diff changeset
93 simple_edge_hints (struct cgraph_edge *edge)
kono
parents:
diff changeset
94 {
kono
parents:
diff changeset
95 int hints = 0;
kono
parents:
diff changeset
96 struct cgraph_node *to = (edge->caller->global.inlined_to
kono
parents:
diff changeset
97 ? edge->caller->global.inlined_to : edge->caller);
kono
parents:
diff changeset
98 struct cgraph_node *callee = edge->callee->ultimate_alias_target ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
99 int to_scc_no = ipa_fn_summaries->get (to)->scc_no;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
100 int callee_scc_no = ipa_fn_summaries->get (callee)->scc_no;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
101
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
102 if (to_scc_no && to_scc_no == callee_scc_no && !edge->recursive_p ())
111
kono
parents:
diff changeset
103 hints |= INLINE_HINT_same_scc;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 if (callee->lto_file_data && edge->caller->lto_file_data
kono
parents:
diff changeset
106 && edge->caller->lto_file_data != callee->lto_file_data
kono
parents:
diff changeset
107 && !callee->merged_comdat && !callee->icf_merged)
kono
parents:
diff changeset
108 hints |= INLINE_HINT_cross_module;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 return hints;
kono
parents:
diff changeset
111 }
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 /* Estimate the time cost for the caller when inlining EDGE.
kono
parents:
diff changeset
114 Only to be called via estimate_edge_time, that handles the
kono
parents:
diff changeset
115 caching mechanism.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 When caching, also update the cache entry. Compute both time and
kono
parents:
diff changeset
118 size, since we always need both metrics eventually. */
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 sreal
kono
parents:
diff changeset
121 do_estimate_edge_time (struct cgraph_edge *edge)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 sreal time, nonspec_time;
kono
parents:
diff changeset
124 int size;
kono
parents:
diff changeset
125 ipa_hints hints;
kono
parents:
diff changeset
126 struct cgraph_node *callee;
kono
parents:
diff changeset
127 clause_t clause, nonspec_clause;
kono
parents:
diff changeset
128 vec<tree> known_vals;
kono
parents:
diff changeset
129 vec<ipa_polymorphic_call_context> known_contexts;
kono
parents:
diff changeset
130 vec<ipa_agg_jump_function_p> known_aggs;
kono
parents:
diff changeset
131 struct ipa_call_summary *es = ipa_call_summaries->get (edge);
kono
parents:
diff changeset
132 int min_size;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 callee = edge->callee->ultimate_alias_target ();
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 gcc_checking_assert (edge->inline_failed);
kono
parents:
diff changeset
137 evaluate_properties_for_edge (edge, true,
kono
parents:
diff changeset
138 &clause, &nonspec_clause, &known_vals,
kono
parents:
diff changeset
139 &known_contexts, &known_aggs);
kono
parents:
diff changeset
140 estimate_node_size_and_time (callee, clause, nonspec_clause, known_vals,
kono
parents:
diff changeset
141 known_contexts, known_aggs, &size, &min_size,
kono
parents:
diff changeset
142 &time, &nonspec_time, &hints, es->param);
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 /* When we have profile feedback, we can quite safely identify hot
kono
parents:
diff changeset
145 edges and for those we disable size limits. Don't do that when
kono
parents:
diff changeset
146 probability that caller will call the callee is low however, since it
kono
parents:
diff changeset
147 may hurt optimization of the caller's hot path. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
148 if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
149 && (edge->count.ipa ().apply_scale (2, 1)
111
kono
parents:
diff changeset
150 > (edge->caller->global.inlined_to
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
151 ? edge->caller->global.inlined_to->count.ipa ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
152 : edge->caller->count.ipa ())))
111
kono
parents:
diff changeset
153 hints |= INLINE_HINT_known_hot;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 known_vals.release ();
kono
parents:
diff changeset
156 known_contexts.release ();
kono
parents:
diff changeset
157 known_aggs.release ();
kono
parents:
diff changeset
158 gcc_checking_assert (size >= 0);
kono
parents:
diff changeset
159 gcc_checking_assert (time >= 0);
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 /* When caching, update the cache entry. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
162 if (edge_growth_cache != NULL)
111
kono
parents:
diff changeset
163 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
164 ipa_fn_summaries->get_create (edge->callee)->min_size = min_size;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
165 edge_growth_cache_entry *entry
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
166 = edge_growth_cache->get_create (edge);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167 entry->time = time;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 entry->nonspec_time = nonspec_time;
111
kono
parents:
diff changeset
169
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
170 entry->size = size + (size >= 0);
111
kono
parents:
diff changeset
171 hints |= simple_edge_hints (edge);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
172 entry->hints = hints + 1;
111
kono
parents:
diff changeset
173 }
kono
parents:
diff changeset
174 return time;
kono
parents:
diff changeset
175 }
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 /* Return estimated callee growth after inlining EDGE.
kono
parents:
diff changeset
179 Only to be called via estimate_edge_size. */
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 int
kono
parents:
diff changeset
182 do_estimate_edge_size (struct cgraph_edge *edge)
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 int size;
kono
parents:
diff changeset
185 struct cgraph_node *callee;
kono
parents:
diff changeset
186 clause_t clause, nonspec_clause;
kono
parents:
diff changeset
187 vec<tree> known_vals;
kono
parents:
diff changeset
188 vec<ipa_polymorphic_call_context> known_contexts;
kono
parents:
diff changeset
189 vec<ipa_agg_jump_function_p> known_aggs;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 /* When we do caching, use do_estimate_edge_time to populate the entry. */
kono
parents:
diff changeset
192
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
193 if (edge_growth_cache != NULL)
111
kono
parents:
diff changeset
194 {
kono
parents:
diff changeset
195 do_estimate_edge_time (edge);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
196 size = edge_growth_cache->get (edge)->size;
111
kono
parents:
diff changeset
197 gcc_checking_assert (size);
kono
parents:
diff changeset
198 return size - (size > 0);
kono
parents:
diff changeset
199 }
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 callee = edge->callee->ultimate_alias_target ();
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 /* Early inliner runs without caching, go ahead and do the dirty work. */
kono
parents:
diff changeset
204 gcc_checking_assert (edge->inline_failed);
kono
parents:
diff changeset
205 evaluate_properties_for_edge (edge, true,
kono
parents:
diff changeset
206 &clause, &nonspec_clause,
kono
parents:
diff changeset
207 &known_vals, &known_contexts,
kono
parents:
diff changeset
208 &known_aggs);
kono
parents:
diff changeset
209 estimate_node_size_and_time (callee, clause, nonspec_clause, known_vals,
kono
parents:
diff changeset
210 known_contexts, known_aggs, &size, NULL, NULL,
kono
parents:
diff changeset
211 NULL, NULL, vNULL);
kono
parents:
diff changeset
212 known_vals.release ();
kono
parents:
diff changeset
213 known_contexts.release ();
kono
parents:
diff changeset
214 known_aggs.release ();
kono
parents:
diff changeset
215 return size;
kono
parents:
diff changeset
216 }
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 /* Estimate the growth of the caller when inlining EDGE.
kono
parents:
diff changeset
220 Only to be called via estimate_edge_size. */
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 ipa_hints
kono
parents:
diff changeset
223 do_estimate_edge_hints (struct cgraph_edge *edge)
kono
parents:
diff changeset
224 {
kono
parents:
diff changeset
225 ipa_hints hints;
kono
parents:
diff changeset
226 struct cgraph_node *callee;
kono
parents:
diff changeset
227 clause_t clause, nonspec_clause;
kono
parents:
diff changeset
228 vec<tree> known_vals;
kono
parents:
diff changeset
229 vec<ipa_polymorphic_call_context> known_contexts;
kono
parents:
diff changeset
230 vec<ipa_agg_jump_function_p> known_aggs;
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 /* When we do caching, use do_estimate_edge_time to populate the entry. */
kono
parents:
diff changeset
233
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
234 if (edge_growth_cache != NULL)
111
kono
parents:
diff changeset
235 {
kono
parents:
diff changeset
236 do_estimate_edge_time (edge);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
237 hints = edge_growth_cache->get (edge)->hints;
111
kono
parents:
diff changeset
238 gcc_checking_assert (hints);
kono
parents:
diff changeset
239 return hints - 1;
kono
parents:
diff changeset
240 }
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 callee = edge->callee->ultimate_alias_target ();
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 /* Early inliner runs without caching, go ahead and do the dirty work. */
kono
parents:
diff changeset
245 gcc_checking_assert (edge->inline_failed);
kono
parents:
diff changeset
246 evaluate_properties_for_edge (edge, true,
kono
parents:
diff changeset
247 &clause, &nonspec_clause,
kono
parents:
diff changeset
248 &known_vals, &known_contexts,
kono
parents:
diff changeset
249 &known_aggs);
kono
parents:
diff changeset
250 estimate_node_size_and_time (callee, clause, nonspec_clause, known_vals,
kono
parents:
diff changeset
251 known_contexts, known_aggs, NULL, NULL,
kono
parents:
diff changeset
252 NULL, NULL, &hints, vNULL);
kono
parents:
diff changeset
253 known_vals.release ();
kono
parents:
diff changeset
254 known_contexts.release ();
kono
parents:
diff changeset
255 known_aggs.release ();
kono
parents:
diff changeset
256 hints |= simple_edge_hints (edge);
kono
parents:
diff changeset
257 return hints;
kono
parents:
diff changeset
258 }
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 /* Estimate the size of NODE after inlining EDGE which should be an
kono
parents:
diff changeset
261 edge to either NODE or a call inlined into NODE. */
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 int
kono
parents:
diff changeset
264 estimate_size_after_inlining (struct cgraph_node *node,
kono
parents:
diff changeset
265 struct cgraph_edge *edge)
kono
parents:
diff changeset
266 {
kono
parents:
diff changeset
267 struct ipa_call_summary *es = ipa_call_summaries->get (edge);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
268 ipa_fn_summary *s = ipa_fn_summaries->get (node);
111
kono
parents:
diff changeset
269 if (!es->predicate || *es->predicate != false)
kono
parents:
diff changeset
270 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
271 int size = s->size + estimate_edge_growth (edge);
111
kono
parents:
diff changeset
272 gcc_assert (size >= 0);
kono
parents:
diff changeset
273 return size;
kono
parents:
diff changeset
274 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
275 return s->size;
111
kono
parents:
diff changeset
276 }
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 struct growth_data
kono
parents:
diff changeset
280 {
kono
parents:
diff changeset
281 struct cgraph_node *node;
kono
parents:
diff changeset
282 bool self_recursive;
kono
parents:
diff changeset
283 bool uninlinable;
kono
parents:
diff changeset
284 int growth;
kono
parents:
diff changeset
285 };
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 /* Worker for do_estimate_growth. Collect growth for all callers. */
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 static bool
kono
parents:
diff changeset
291 do_estimate_growth_1 (struct cgraph_node *node, void *data)
kono
parents:
diff changeset
292 {
kono
parents:
diff changeset
293 struct cgraph_edge *e;
kono
parents:
diff changeset
294 struct growth_data *d = (struct growth_data *) data;
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 for (e = node->callers; e; e = e->next_caller)
kono
parents:
diff changeset
297 {
kono
parents:
diff changeset
298 gcc_checking_assert (e->inline_failed);
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR
kono
parents:
diff changeset
301 || !opt_for_fn (e->caller->decl, optimize))
kono
parents:
diff changeset
302 {
kono
parents:
diff changeset
303 d->uninlinable = true;
kono
parents:
diff changeset
304 continue;
kono
parents:
diff changeset
305 }
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 if (e->recursive_p ())
kono
parents:
diff changeset
308 {
kono
parents:
diff changeset
309 d->self_recursive = true;
kono
parents:
diff changeset
310 continue;
kono
parents:
diff changeset
311 }
kono
parents:
diff changeset
312 d->growth += estimate_edge_growth (e);
kono
parents:
diff changeset
313 }
kono
parents:
diff changeset
314 return false;
kono
parents:
diff changeset
315 }
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 /* Estimate the growth caused by inlining NODE into all callees. */
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 int
kono
parents:
diff changeset
321 estimate_growth (struct cgraph_node *node)
kono
parents:
diff changeset
322 {
kono
parents:
diff changeset
323 struct growth_data d = { node, false, false, 0 };
kono
parents:
diff changeset
324 struct ipa_fn_summary *info = ipa_fn_summaries->get (node);
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 node->call_for_symbol_and_aliases (do_estimate_growth_1, &d, true);
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 /* For self recursive functions the growth estimation really should be
kono
parents:
diff changeset
329 infinity. We don't want to return very large values because the growth
kono
parents:
diff changeset
330 plays various roles in badness computation fractions. Be sure to not
kono
parents:
diff changeset
331 return zero or negative growths. */
kono
parents:
diff changeset
332 if (d.self_recursive)
kono
parents:
diff changeset
333 d.growth = d.growth < info->size ? info->size : d.growth;
kono
parents:
diff changeset
334 else if (DECL_EXTERNAL (node->decl) || d.uninlinable)
kono
parents:
diff changeset
335 ;
kono
parents:
diff changeset
336 else
kono
parents:
diff changeset
337 {
kono
parents:
diff changeset
338 if (node->will_be_removed_from_program_if_no_direct_calls_p ())
kono
parents:
diff changeset
339 d.growth -= info->size;
kono
parents:
diff changeset
340 /* COMDAT functions are very often not shared across multiple units
kono
parents:
diff changeset
341 since they come from various template instantiations.
kono
parents:
diff changeset
342 Take this into account. */
kono
parents:
diff changeset
343 else if (DECL_COMDAT (node->decl)
kono
parents:
diff changeset
344 && node->can_remove_if_no_direct_calls_p ())
kono
parents:
diff changeset
345 d.growth -= (info->size
kono
parents:
diff changeset
346 * (100 - PARAM_VALUE (PARAM_COMDAT_SHARING_PROBABILITY))
kono
parents:
diff changeset
347 + 50) / 100;
kono
parents:
diff changeset
348 }
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 return d.growth;
kono
parents:
diff changeset
351 }
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 /* Verify if there are fewer than MAX_CALLERS. */
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 static bool
kono
parents:
diff changeset
356 check_callers (cgraph_node *node, int *max_callers)
kono
parents:
diff changeset
357 {
kono
parents:
diff changeset
358 ipa_ref *ref;
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 if (!node->can_remove_if_no_direct_calls_and_refs_p ())
kono
parents:
diff changeset
361 return true;
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 for (cgraph_edge *e = node->callers; e; e = e->next_caller)
kono
parents:
diff changeset
364 {
kono
parents:
diff changeset
365 (*max_callers)--;
kono
parents:
diff changeset
366 if (!*max_callers
kono
parents:
diff changeset
367 || cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR)
kono
parents:
diff changeset
368 return true;
kono
parents:
diff changeset
369 }
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 FOR_EACH_ALIAS (node, ref)
kono
parents:
diff changeset
372 if (check_callers (dyn_cast <cgraph_node *> (ref->referring), max_callers))
kono
parents:
diff changeset
373 return true;
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 return false;
kono
parents:
diff changeset
376 }
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 /* Make cheap estimation if growth of NODE is likely positive knowing
kono
parents:
diff changeset
380 EDGE_GROWTH of one particular edge.
kono
parents:
diff changeset
381 We assume that most of other edges will have similar growth
kono
parents:
diff changeset
382 and skip computation if there are too many callers. */
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 bool
kono
parents:
diff changeset
385 growth_likely_positive (struct cgraph_node *node,
kono
parents:
diff changeset
386 int edge_growth)
kono
parents:
diff changeset
387 {
kono
parents:
diff changeset
388 int max_callers;
kono
parents:
diff changeset
389 struct cgraph_edge *e;
kono
parents:
diff changeset
390 gcc_checking_assert (edge_growth > 0);
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 /* First quickly check if NODE is removable at all. */
kono
parents:
diff changeset
393 if (DECL_EXTERNAL (node->decl))
kono
parents:
diff changeset
394 return true;
kono
parents:
diff changeset
395 if (!node->can_remove_if_no_direct_calls_and_refs_p ()
kono
parents:
diff changeset
396 || node->address_taken)
kono
parents:
diff changeset
397 return true;
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 max_callers = ipa_fn_summaries->get (node)->size * 4 / edge_growth + 2;
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 for (e = node->callers; e; e = e->next_caller)
kono
parents:
diff changeset
402 {
kono
parents:
diff changeset
403 max_callers--;
kono
parents:
diff changeset
404 if (!max_callers
kono
parents:
diff changeset
405 || cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR)
kono
parents:
diff changeset
406 return true;
kono
parents:
diff changeset
407 }
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 ipa_ref *ref;
kono
parents:
diff changeset
410 FOR_EACH_ALIAS (node, ref)
kono
parents:
diff changeset
411 if (check_callers (dyn_cast <cgraph_node *> (ref->referring), &max_callers))
kono
parents:
diff changeset
412 return true;
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 /* Unlike for functions called once, we play unsafe with
kono
parents:
diff changeset
415 COMDATs. We can allow that since we know functions
kono
parents:
diff changeset
416 in consideration are small (and thus risk is small) and
kono
parents:
diff changeset
417 moreover grow estimates already accounts that COMDAT
kono
parents:
diff changeset
418 functions may or may not disappear when eliminated from
kono
parents:
diff changeset
419 current unit. With good probability making aggressive
kono
parents:
diff changeset
420 choice in all units is going to make overall program
kono
parents:
diff changeset
421 smaller. */
kono
parents:
diff changeset
422 if (DECL_COMDAT (node->decl))
kono
parents:
diff changeset
423 {
kono
parents:
diff changeset
424 if (!node->can_remove_if_no_direct_calls_p ())
kono
parents:
diff changeset
425 return true;
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427 else if (!node->will_be_removed_from_program_if_no_direct_calls_p ())
kono
parents:
diff changeset
428 return true;
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 return estimate_growth (node) > 0;
kono
parents:
diff changeset
431 }