PR tree-optimization/82838
[official-gcc.git] / gcc / ipa-inline-transform.c
blobe367df7df0e5c507f7ebf2bd8da86462cf82b4b4
1 /* Callgraph transformations to handle inlining
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* The inline decisions are stored in callgraph in "inline plan" and
22 applied later.
24 To mark given call inline, use inline_call function.
25 The function marks the edge inlinable and, if necessary, produces
26 virtual clone in the callgraph representing the new copy of callee's
27 function body.
29 The inline plan is applied on given function body by inline_transform. */
31 #include "config.h"
32 #include "system.h"
33 #include "coretypes.h"
34 #include "tm.h"
35 #include "function.h"
36 #include "tree.h"
37 #include "alloc-pool.h"
38 #include "tree-pass.h"
39 #include "cgraph.h"
40 #include "tree-cfg.h"
41 #include "symbol-summary.h"
42 #include "tree-vrp.h"
43 #include "ipa-prop.h"
44 #include "ipa-fnsummary.h"
45 #include "ipa-inline.h"
46 #include "tree-inline.h"
47 #include "function.h"
48 #include "cfg.h"
49 #include "basic-block.h"
51 int ncalls_inlined;
52 int nfunctions_inlined;
54 /* Scale frequency of NODE edges by FREQ_SCALE. */
56 static void
57 update_noncloned_frequencies (struct cgraph_node *node,
58 int freq_scale, profile_count num,
59 profile_count den)
61 struct cgraph_edge *e;
63 /* We always must scale to be sure counters end up compatible.
64 If den is zero, just force it nonzero and hope for reasonable
65 approximation.
66 When num is forced nonzero, also update den, so we do not scale profile
67 to 0. */
68 if (!(num == den)
69 && !(den.force_nonzero () == den))
71 den = den.force_nonzero ();
72 num = num.force_nonzero ();
75 /* We do not want to ignore high loop nest after freq drops to 0. */
76 if (!freq_scale)
77 freq_scale = 1;
78 for (e = node->callees; e; e = e->next_callee)
80 e->frequency = e->frequency * (gcov_type) freq_scale / CGRAPH_FREQ_BASE;
81 if (e->frequency > CGRAPH_FREQ_MAX)
82 e->frequency = CGRAPH_FREQ_MAX;
83 if (!e->inline_failed)
84 update_noncloned_frequencies (e->callee, freq_scale, num, den);
85 e->count = e->count.apply_scale (num, den);
87 for (e = node->indirect_calls; e; e = e->next_callee)
89 e->frequency = e->frequency * (gcov_type) freq_scale / CGRAPH_FREQ_BASE;
90 if (e->frequency > CGRAPH_FREQ_MAX)
91 e->frequency = CGRAPH_FREQ_MAX;
92 e->count = e->count.apply_scale (num, den);
94 node->count = node->count.apply_scale (num, den);
97 /* We removed or are going to remove the last call to NODE.
98 Return true if we can and want proactively remove the NODE now.
99 This is important to do, since we want inliner to know when offline
100 copy of function was removed. */
102 static bool
103 can_remove_node_now_p_1 (struct cgraph_node *node, struct cgraph_edge *e)
105 ipa_ref *ref;
107 FOR_EACH_ALIAS (node, ref)
109 cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
110 if ((alias->callers && alias->callers != e)
111 || !can_remove_node_now_p_1 (alias, e))
112 return false;
114 /* FIXME: When address is taken of DECL_EXTERNAL function we still
115 can remove its offline copy, but we would need to keep unanalyzed node in
116 the callgraph so references can point to it.
118 Also for comdat group we can ignore references inside a group as we
119 want to prove the group as a whole to be dead. */
120 return (!node->address_taken
121 && node->can_remove_if_no_direct_calls_and_refs_p ()
122 /* Inlining might enable more devirtualizing, so we want to remove
123 those only after all devirtualizable virtual calls are processed.
124 Lacking may edges in callgraph we just preserve them post
125 inlining. */
126 && (!DECL_VIRTUAL_P (node->decl)
127 || !opt_for_fn (node->decl, flag_devirtualize))
128 /* During early inlining some unanalyzed cgraph nodes might be in the
129 callgraph and they might reffer the function in question. */
130 && !cgraph_new_nodes.exists ());
133 /* We are going to eliminate last direct call to NODE (or alias of it) via edge E.
134 Verify that the NODE can be removed from unit and if it is contained in comdat
135 group that the whole comdat group is removable. */
137 static bool
138 can_remove_node_now_p (struct cgraph_node *node, struct cgraph_edge *e)
140 struct cgraph_node *next;
141 if (!can_remove_node_now_p_1 (node, e))
142 return false;
144 /* When we see same comdat group, we need to be sure that all
145 items can be removed. */
146 if (!node->same_comdat_group || !node->externally_visible)
147 return true;
148 for (next = dyn_cast<cgraph_node *> (node->same_comdat_group);
149 next != node; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
151 if (next->alias)
152 continue;
153 if ((next->callers && next->callers != e)
154 || !can_remove_node_now_p_1 (next, e))
155 return false;
157 return true;
160 /* Return true if NODE is a master clone with non-inline clones. */
162 static bool
163 master_clone_with_noninline_clones_p (struct cgraph_node *node)
165 if (node->clone_of)
166 return false;
168 for (struct cgraph_node *n = node->clones; n; n = n->next_sibling_clone)
169 if (n->decl != node->decl)
170 return true;
172 return false;
175 /* E is expected to be an edge being inlined. Clone destination node of
176 the edge and redirect it to the new clone.
177 DUPLICATE is used for bookkeeping on whether we are actually creating new
178 clones or re-using node originally representing out-of-line function call.
179 By default the offline copy is removed, when it appears dead after inlining.
180 UPDATE_ORIGINAL prevents this transformation.
181 If OVERALL_SIZE is non-NULL, the size is updated to reflect the
182 transformation.
183 FREQ_SCALE specify the scaling of frequencies of call sites. */
185 void
186 clone_inlined_nodes (struct cgraph_edge *e, bool duplicate,
187 bool update_original, int *overall_size, int freq_scale)
189 struct cgraph_node *inlining_into;
190 struct cgraph_edge *next;
192 if (e->caller->global.inlined_to)
193 inlining_into = e->caller->global.inlined_to;
194 else
195 inlining_into = e->caller;
197 if (duplicate)
199 /* We may eliminate the need for out-of-line copy to be output.
200 In that case just go ahead and re-use it. This is not just an
201 memory optimization. Making offline copy of fuction disappear
202 from the program will improve future decisions on inlining. */
203 if (!e->callee->callers->next_caller
204 /* Recursive inlining never wants the master clone to
205 be overwritten. */
206 && update_original
207 && can_remove_node_now_p (e->callee, e)
208 /* We cannot overwrite a master clone with non-inline clones
209 until after these clones are materialized. */
210 && !master_clone_with_noninline_clones_p (e->callee))
212 /* TODO: When callee is in a comdat group, we could remove all of it,
213 including all inline clones inlined into it. That would however
214 need small function inlining to register edge removal hook to
215 maintain the priority queue.
217 For now we keep the ohter functions in the group in program until
218 cgraph_remove_unreachable_functions gets rid of them. */
219 gcc_assert (!e->callee->global.inlined_to);
220 e->callee->remove_from_same_comdat_group ();
221 if (e->callee->definition
222 && inline_account_function_p (e->callee))
224 gcc_assert (!e->callee->alias);
225 if (overall_size)
226 *overall_size -= ipa_fn_summaries->get (e->callee)->size;
227 nfunctions_inlined++;
229 duplicate = false;
230 e->callee->externally_visible = false;
231 update_noncloned_frequencies (e->callee, e->frequency,
232 e->count, e->callee->count);
234 dump_callgraph_transformation (e->callee, inlining_into,
235 "inlining to");
237 else
239 struct cgraph_node *n;
241 if (freq_scale == -1)
242 freq_scale = e->frequency;
243 n = e->callee->create_clone (e->callee->decl,
244 MIN (e->count, e->callee->count),
245 freq_scale,
246 update_original, vNULL, true,
247 inlining_into,
248 NULL);
249 n->used_as_abstract_origin = e->callee->used_as_abstract_origin;
250 e->redirect_callee (n);
253 else
254 e->callee->remove_from_same_comdat_group ();
256 e->callee->global.inlined_to = inlining_into;
258 /* Recursively clone all bodies. */
259 for (e = e->callee->callees; e; e = next)
261 next = e->next_callee;
262 if (!e->inline_failed)
263 clone_inlined_nodes (e, duplicate, update_original, overall_size, freq_scale);
267 /* Check all speculations in N and resolve them if they seems useless. */
269 static bool
270 check_speculations (cgraph_node *n)
272 bool speculation_removed = false;
273 cgraph_edge *next;
275 for (cgraph_edge *e = n->callees; e; e = next)
277 next = e->next_callee;
278 if (e->speculative && !speculation_useful_p (e, true))
280 e->resolve_speculation (NULL);
281 speculation_removed = true;
283 else if (!e->inline_failed)
284 speculation_removed |= check_speculations (e->callee);
286 return speculation_removed;
289 /* Mark all call graph edges coming out of NODE and all nodes that have been
290 inlined to it as in_polymorphic_cdtor. */
292 static void
293 mark_all_inlined_calls_cdtor (cgraph_node *node)
295 for (cgraph_edge *cs = node->callees; cs; cs = cs->next_callee)
297 cs->in_polymorphic_cdtor = true;
298 if (!cs->inline_failed)
299 mark_all_inlined_calls_cdtor (cs->callee);
301 for (cgraph_edge *cs = node->indirect_calls; cs; cs = cs->next_callee)
302 cs->in_polymorphic_cdtor = true;
306 /* Mark edge E as inlined and update callgraph accordingly. UPDATE_ORIGINAL
307 specify whether profile of original function should be updated. If any new
308 indirect edges are discovered in the process, add them to NEW_EDGES, unless
309 it is NULL. If UPDATE_OVERALL_SUMMARY is false, do not bother to recompute overall
310 size of caller after inlining. Caller is required to eventually do it via
311 ipa_update_overall_fn_summary.
312 If callee_removed is non-NULL, set it to true if we removed callee node.
314 Return true iff any new callgraph edges were discovered as a
315 result of inlining. */
317 bool
318 inline_call (struct cgraph_edge *e, bool update_original,
319 vec<cgraph_edge *> *new_edges,
320 int *overall_size, bool update_overall_summary,
321 bool *callee_removed)
323 int old_size = 0, new_size = 0;
324 struct cgraph_node *to = NULL;
325 struct cgraph_edge *curr = e;
326 struct cgraph_node *callee = e->callee->ultimate_alias_target ();
327 bool new_edges_found = false;
329 int estimated_growth = 0;
330 if (! update_overall_summary)
331 estimated_growth = estimate_edge_growth (e);
332 /* This is used only for assert bellow. */
333 #if 0
334 bool predicated = inline_edge_summary (e)->predicate != NULL;
335 #endif
337 /* Don't inline inlined edges. */
338 gcc_assert (e->inline_failed);
339 /* Don't even think of inlining inline clone. */
340 gcc_assert (!callee->global.inlined_to);
342 to = e->caller;
343 if (to->global.inlined_to)
344 to = to->global.inlined_to;
345 if (to->thunk.thunk_p)
347 struct cgraph_node *target = to->callees->callee;
348 if (in_lto_p)
349 to->get_untransformed_body ();
350 to->expand_thunk (false, true);
351 /* When thunk is instrumented we may have multiple callees. */
352 for (e = to->callees; e && e->callee != target; e = e->next_callee)
354 gcc_assert (e);
358 e->inline_failed = CIF_OK;
359 DECL_POSSIBLY_INLINED (callee->decl) = true;
361 if (DECL_FUNCTION_PERSONALITY (callee->decl))
362 DECL_FUNCTION_PERSONALITY (to->decl)
363 = DECL_FUNCTION_PERSONALITY (callee->decl);
365 bool reload_optimization_node = false;
366 if (!opt_for_fn (callee->decl, flag_strict_aliasing)
367 && opt_for_fn (to->decl, flag_strict_aliasing))
369 struct gcc_options opts = global_options;
371 cl_optimization_restore (&opts, opts_for_fn (to->decl));
372 opts.x_flag_strict_aliasing = false;
373 if (dump_file)
374 fprintf (dump_file, "Dropping flag_strict_aliasing on %s\n",
375 to->dump_name ());
376 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
377 = build_optimization_node (&opts);
378 reload_optimization_node = true;
381 ipa_fn_summary *caller_info = ipa_fn_summaries->get (to);
382 ipa_fn_summary *callee_info = ipa_fn_summaries->get (callee);
383 if (!caller_info->fp_expressions && callee_info->fp_expressions)
385 caller_info->fp_expressions = true;
386 if (opt_for_fn (callee->decl, flag_rounding_math)
387 != opt_for_fn (to->decl, flag_rounding_math)
388 || opt_for_fn (callee->decl, flag_trapping_math)
389 != opt_for_fn (to->decl, flag_trapping_math)
390 || opt_for_fn (callee->decl, flag_unsafe_math_optimizations)
391 != opt_for_fn (to->decl, flag_unsafe_math_optimizations)
392 || opt_for_fn (callee->decl, flag_finite_math_only)
393 != opt_for_fn (to->decl, flag_finite_math_only)
394 || opt_for_fn (callee->decl, flag_signaling_nans)
395 != opt_for_fn (to->decl, flag_signaling_nans)
396 || opt_for_fn (callee->decl, flag_cx_limited_range)
397 != opt_for_fn (to->decl, flag_cx_limited_range)
398 || opt_for_fn (callee->decl, flag_signed_zeros)
399 != opt_for_fn (to->decl, flag_signed_zeros)
400 || opt_for_fn (callee->decl, flag_associative_math)
401 != opt_for_fn (to->decl, flag_associative_math)
402 || opt_for_fn (callee->decl, flag_reciprocal_math)
403 != opt_for_fn (to->decl, flag_reciprocal_math)
404 || opt_for_fn (callee->decl, flag_fp_int_builtin_inexact)
405 != opt_for_fn (to->decl, flag_fp_int_builtin_inexact)
406 || opt_for_fn (callee->decl, flag_errno_math)
407 != opt_for_fn (to->decl, flag_errno_math))
409 struct gcc_options opts = global_options;
411 cl_optimization_restore (&opts, opts_for_fn (to->decl));
412 opts.x_flag_rounding_math
413 = opt_for_fn (callee->decl, flag_rounding_math);
414 opts.x_flag_trapping_math
415 = opt_for_fn (callee->decl, flag_trapping_math);
416 opts.x_flag_unsafe_math_optimizations
417 = opt_for_fn (callee->decl, flag_unsafe_math_optimizations);
418 opts.x_flag_finite_math_only
419 = opt_for_fn (callee->decl, flag_finite_math_only);
420 opts.x_flag_signaling_nans
421 = opt_for_fn (callee->decl, flag_signaling_nans);
422 opts.x_flag_cx_limited_range
423 = opt_for_fn (callee->decl, flag_cx_limited_range);
424 opts.x_flag_signed_zeros
425 = opt_for_fn (callee->decl, flag_signed_zeros);
426 opts.x_flag_associative_math
427 = opt_for_fn (callee->decl, flag_associative_math);
428 opts.x_flag_reciprocal_math
429 = opt_for_fn (callee->decl, flag_reciprocal_math);
430 opts.x_flag_fp_int_builtin_inexact
431 = opt_for_fn (callee->decl, flag_fp_int_builtin_inexact);
432 opts.x_flag_errno_math
433 = opt_for_fn (callee->decl, flag_errno_math);
434 if (dump_file)
435 fprintf (dump_file, "Copying FP flags from %s to %s\n",
436 callee->dump_name (), to->dump_name ());
437 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
438 = build_optimization_node (&opts);
439 reload_optimization_node = true;
443 /* Reload global optimization flags. */
444 if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun)
445 set_cfun (cfun, true);
447 /* If aliases are involved, redirect edge to the actual destination and
448 possibly remove the aliases. */
449 if (e->callee != callee)
451 struct cgraph_node *alias = e->callee, *next_alias;
452 e->redirect_callee (callee);
453 while (alias && alias != callee)
455 if (!alias->callers
456 && can_remove_node_now_p (alias,
457 !e->next_caller && !e->prev_caller ? e : NULL))
459 next_alias = alias->get_alias_target ();
460 alias->remove ();
461 if (callee_removed)
462 *callee_removed = true;
463 alias = next_alias;
465 else
466 break;
470 clone_inlined_nodes (e, true, update_original, overall_size, e->frequency);
472 gcc_assert (curr->callee->global.inlined_to == to);
474 old_size = ipa_fn_summaries->get (to)->size;
475 ipa_merge_fn_summary_after_inlining (e);
476 if (e->in_polymorphic_cdtor)
477 mark_all_inlined_calls_cdtor (e->callee);
478 if (opt_for_fn (e->caller->decl, optimize))
479 new_edges_found = ipa_propagate_indirect_call_infos (curr, new_edges);
480 check_speculations (e->callee);
481 if (update_overall_summary)
482 ipa_update_overall_fn_summary (to);
483 else
484 /* Update self size by the estimate so overall function growth limits
485 work for further inlining into this function. Before inlining
486 the function we inlined to again we expect the caller to update
487 the overall summary. */
488 ipa_fn_summaries->get (to)->size += estimated_growth;
489 new_size = ipa_fn_summaries->get (to)->size;
491 if (callee->calls_comdat_local)
492 to->calls_comdat_local = true;
493 else if (to->calls_comdat_local && callee->comdat_local_p ())
495 struct cgraph_edge *se = to->callees;
496 for (; se; se = se->next_callee)
497 if (se->inline_failed && se->callee->comdat_local_p ())
498 break;
499 if (se == NULL)
500 to->calls_comdat_local = false;
503 /* FIXME: This assert suffers from roundoff errors, disable it for GCC 5
504 and revisit it after conversion to sreals in GCC 6.
505 See PR 65654. */
506 #if 0
507 /* Verify that estimated growth match real growth. Allow off-by-one
508 error due to ipa_fn_summary::size_scale roudoff errors. */
509 gcc_assert (!update_overall_summary || !overall_size || new_edges_found
510 || abs (estimated_growth - (new_size - old_size)) <= 1
511 || speculation_removed
512 /* FIXME: a hack. Edges with false predicate are accounted
513 wrong, we should remove them from callgraph. */
514 || predicated);
515 #endif
517 /* Account the change of overall unit size; external functions will be
518 removed and are thus not accounted. */
519 if (overall_size && inline_account_function_p (to))
520 *overall_size += new_size - old_size;
521 ncalls_inlined++;
523 /* This must happen after ipa_merge_fn_summary_after_inlining that rely on jump
524 functions of callee to not be updated. */
525 return new_edges_found;
529 /* Copy function body of NODE and redirect all inline clones to it.
530 This is done before inline plan is applied to NODE when there are
531 still some inline clones if it.
533 This is necessary because inline decisions are not really transitive
534 and the other inline clones may have different bodies. */
536 static struct cgraph_node *
537 save_inline_function_body (struct cgraph_node *node)
539 struct cgraph_node *first_clone, *n;
541 if (dump_file)
542 fprintf (dump_file, "\nSaving body of %s for later reuse\n",
543 node->name ());
545 gcc_assert (node == cgraph_node::get (node->decl));
547 /* first_clone will be turned into real function. */
548 first_clone = node->clones;
550 /* Arrange first clone to not be thunk as those do not have bodies. */
551 if (first_clone->thunk.thunk_p)
553 while (first_clone->thunk.thunk_p)
554 first_clone = first_clone->next_sibling_clone;
555 first_clone->prev_sibling_clone->next_sibling_clone
556 = first_clone->next_sibling_clone;
557 if (first_clone->next_sibling_clone)
558 first_clone->next_sibling_clone->prev_sibling_clone
559 = first_clone->prev_sibling_clone;
560 first_clone->next_sibling_clone = node->clones;
561 first_clone->prev_sibling_clone = NULL;
562 node->clones->prev_sibling_clone = first_clone;
563 node->clones = first_clone;
565 first_clone->decl = copy_node (node->decl);
566 first_clone->decl->decl_with_vis.symtab_node = first_clone;
567 gcc_assert (first_clone == cgraph_node::get (first_clone->decl));
569 /* Now reshape the clone tree, so all other clones descends from
570 first_clone. */
571 if (first_clone->next_sibling_clone)
573 for (n = first_clone->next_sibling_clone; n->next_sibling_clone;
574 n = n->next_sibling_clone)
575 n->clone_of = first_clone;
576 n->clone_of = first_clone;
577 n->next_sibling_clone = first_clone->clones;
578 if (first_clone->clones)
579 first_clone->clones->prev_sibling_clone = n;
580 first_clone->clones = first_clone->next_sibling_clone;
581 first_clone->next_sibling_clone->prev_sibling_clone = NULL;
582 first_clone->next_sibling_clone = NULL;
583 gcc_assert (!first_clone->prev_sibling_clone);
585 first_clone->clone_of = NULL;
587 /* Now node in question has no clones. */
588 node->clones = NULL;
590 /* Inline clones share decl with the function they are cloned
591 from. Walk the whole clone tree and redirect them all to the
592 new decl. */
593 if (first_clone->clones)
594 for (n = first_clone->clones; n != first_clone;)
596 gcc_assert (n->decl == node->decl);
597 n->decl = first_clone->decl;
598 if (n->clones)
599 n = n->clones;
600 else if (n->next_sibling_clone)
601 n = n->next_sibling_clone;
602 else
604 while (n != first_clone && !n->next_sibling_clone)
605 n = n->clone_of;
606 if (n != first_clone)
607 n = n->next_sibling_clone;
611 /* Copy the OLD_VERSION_NODE function tree to the new version. */
612 tree_function_versioning (node->decl, first_clone->decl,
613 NULL, true, NULL, false,
614 NULL, NULL);
616 /* The function will be short lived and removed after we inline all the clones,
617 but make it internal so we won't confuse ourself. */
618 DECL_EXTERNAL (first_clone->decl) = 0;
619 TREE_PUBLIC (first_clone->decl) = 0;
620 DECL_COMDAT (first_clone->decl) = 0;
621 first_clone->ipa_transforms_to_apply.release ();
623 /* When doing recursive inlining, the clone may become unnecessary.
624 This is possible i.e. in the case when the recursive function is proved to be
625 non-throwing and the recursion happens only in the EH landing pad.
626 We can not remove the clone until we are done with saving the body.
627 Remove it now. */
628 if (!first_clone->callers)
630 first_clone->remove_symbol_and_inline_clones ();
631 first_clone = NULL;
633 else if (flag_checking)
634 first_clone->verify ();
636 return first_clone;
639 /* Return true when function body of DECL still needs to be kept around
640 for later re-use. */
641 static bool
642 preserve_function_body_p (struct cgraph_node *node)
644 gcc_assert (symtab->global_info_ready);
645 gcc_assert (!node->alias && !node->thunk.thunk_p);
647 /* Look if there is any non-thunk clone around. */
648 for (node = node->clones; node; node = node->next_sibling_clone)
649 if (!node->thunk.thunk_p)
650 return true;
651 return false;
654 /* Apply inline plan to function. */
656 unsigned int
657 inline_transform (struct cgraph_node *node)
659 unsigned int todo = 0;
660 struct cgraph_edge *e, *next;
661 bool has_inline = false;
663 /* FIXME: Currently the pass manager is adding inline transform more than
664 once to some clones. This needs revisiting after WPA cleanups. */
665 if (cfun->after_inlining)
666 return 0;
668 /* We might need the body of this function so that we can expand
669 it inline somewhere else. */
670 if (preserve_function_body_p (node))
671 save_inline_function_body (node);
673 for (e = node->callees; e; e = next)
675 if (!e->inline_failed)
676 has_inline = true;
677 next = e->next_callee;
678 e->redirect_call_stmt_to_callee ();
680 node->remove_all_references ();
682 timevar_push (TV_INTEGRATION);
683 if (node->callees && (opt_for_fn (node->decl, optimize) || has_inline))
685 profile_count num = node->count;
686 profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
687 bool scale = num.initialized_p () && den.ipa_p ()
688 && (den.nonzero_p () || num == profile_count::zero ())
689 && !(num == den.ipa ());
690 if (scale)
692 if (dump_file)
694 fprintf (dump_file, "Applying count scale ");
695 num.dump (dump_file);
696 fprintf (dump_file, "/");
697 den.dump (dump_file);
698 fprintf (dump_file, "\n");
701 basic_block bb;
702 FOR_ALL_BB_FN (bb, cfun)
703 if (num == profile_count::zero ())
704 bb->count = bb->count.global0 ();
705 else
706 bb->count = bb->count.apply_scale (num, den);
707 ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
709 todo = optimize_inline_calls (current_function_decl);
711 timevar_pop (TV_INTEGRATION);
713 cfun->always_inline_functions_inlined = true;
714 cfun->after_inlining = true;
715 todo |= execute_fixup_cfg ();
717 if (!(todo & TODO_update_ssa_any))
718 /* Redirecting edges might lead to a need for vops to be recomputed. */
719 todo |= TODO_update_ssa_only_virtuals;
721 return todo;