aix: Fix _STDC_FORMAT_MACROS in inttypes.h [PR97044]
[official-gcc.git] / gcc / ipa-inline-transform.c
blobaf2c2856aaac7bbb11a4a1968aad4e1a5e8d4c3d
1 /* Callgraph transformations to handle inlining
2 Copyright (C) 2003-2020 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"
50 #include "ipa-utils.h"
51 #include "ipa-modref-tree.h"
52 #include "ipa-modref.h"
54 int ncalls_inlined;
55 int nfunctions_inlined;
57 /* Scale counts of NODE edges by NUM/DEN. */
59 static void
60 update_noncloned_counts (struct cgraph_node *node,
61 profile_count num, profile_count den)
63 struct cgraph_edge *e;
65 profile_count::adjust_for_ipa_scaling (&num, &den);
67 for (e = node->callees; e; e = e->next_callee)
69 if (!e->inline_failed)
70 update_noncloned_counts (e->callee, num, den);
71 e->count = e->count.apply_scale (num, den);
73 for (e = node->indirect_calls; e; e = e->next_callee)
74 e->count = e->count.apply_scale (num, den);
75 node->count = node->count.apply_scale (num, den);
78 /* We removed or are going to remove the last call to NODE.
79 Return true if we can and want proactively remove the NODE now.
80 This is important to do, since we want inliner to know when offline
81 copy of function was removed. */
83 static bool
84 can_remove_node_now_p_1 (struct cgraph_node *node, struct cgraph_edge *e)
86 ipa_ref *ref;
88 FOR_EACH_ALIAS (node, ref)
90 cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
91 if ((alias->callers && alias->callers != e)
92 || !can_remove_node_now_p_1 (alias, e))
93 return false;
95 /* FIXME: When address is taken of DECL_EXTERNAL function we still
96 can remove its offline copy, but we would need to keep unanalyzed node in
97 the callgraph so references can point to it.
99 Also for comdat group we can ignore references inside a group as we
100 want to prove the group as a whole to be dead. */
101 return (!node->address_taken
102 && node->can_remove_if_no_direct_calls_and_refs_p ()
103 /* Inlining might enable more devirtualizing, so we want to remove
104 those only after all devirtualizable virtual calls are processed.
105 Lacking may edges in callgraph we just preserve them post
106 inlining. */
107 && (!DECL_VIRTUAL_P (node->decl)
108 || !opt_for_fn (node->decl, flag_devirtualize))
109 /* During early inlining some unanalyzed cgraph nodes might be in the
110 callgraph and they might refer the function in question. */
111 && !cgraph_new_nodes.exists ());
114 /* We are going to eliminate last direct call to NODE (or alias of it) via edge E.
115 Verify that the NODE can be removed from unit and if it is contained in comdat
116 group that the whole comdat group is removable. */
118 static bool
119 can_remove_node_now_p (struct cgraph_node *node, struct cgraph_edge *e)
121 struct cgraph_node *next;
122 if (!can_remove_node_now_p_1 (node, e))
123 return false;
125 /* When we see same comdat group, we need to be sure that all
126 items can be removed. */
127 if (!node->same_comdat_group || !node->externally_visible)
128 return true;
129 for (next = dyn_cast<cgraph_node *> (node->same_comdat_group);
130 next != node; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
132 if (next->alias)
133 continue;
134 if ((next->callers && next->callers != e)
135 || !can_remove_node_now_p_1 (next, e))
136 return false;
138 return true;
141 /* Return true if NODE is a master clone with non-inline clones. */
143 static bool
144 master_clone_with_noninline_clones_p (struct cgraph_node *node)
146 if (node->clone_of)
147 return false;
149 for (struct cgraph_node *n = node->clones; n; n = n->next_sibling_clone)
150 if (n->decl != node->decl)
151 return true;
153 return false;
156 /* E is expected to be an edge being inlined. Clone destination node of
157 the edge and redirect it to the new clone.
158 DUPLICATE is used for bookkeeping on whether we are actually creating new
159 clones or re-using node originally representing out-of-line function call.
160 By default the offline copy is removed, when it appears dead after inlining.
161 UPDATE_ORIGINAL prevents this transformation.
162 If OVERALL_SIZE is non-NULL, the size is updated to reflect the
163 transformation. */
165 void
166 clone_inlined_nodes (struct cgraph_edge *e, bool duplicate,
167 bool update_original, int *overall_size)
169 struct cgraph_node *inlining_into;
170 struct cgraph_edge *next;
172 if (e->caller->inlined_to)
173 inlining_into = e->caller->inlined_to;
174 else
175 inlining_into = e->caller;
177 if (duplicate)
179 /* We may eliminate the need for out-of-line copy to be output.
180 In that case just go ahead and re-use it. This is not just an
181 memory optimization. Making offline copy of function disappear
182 from the program will improve future decisions on inlining. */
183 if (!e->callee->callers->next_caller
184 /* Recursive inlining never wants the master clone to
185 be overwritten. */
186 && update_original
187 && can_remove_node_now_p (e->callee, e)
188 /* We cannot overwrite a master clone with non-inline clones
189 until after these clones are materialized. */
190 && !master_clone_with_noninline_clones_p (e->callee))
192 /* TODO: When callee is in a comdat group, we could remove all of it,
193 including all inline clones inlined into it. That would however
194 need small function inlining to register edge removal hook to
195 maintain the priority queue.
197 For now we keep the other functions in the group in program until
198 cgraph_remove_unreachable_functions gets rid of them. */
199 gcc_assert (!e->callee->inlined_to);
200 e->callee->remove_from_same_comdat_group ();
201 if (e->callee->definition
202 && inline_account_function_p (e->callee))
204 gcc_assert (!e->callee->alias);
205 if (overall_size)
206 *overall_size -= ipa_size_summaries->get (e->callee)->size;
207 nfunctions_inlined++;
209 duplicate = false;
210 e->callee->externally_visible = false;
211 update_noncloned_counts (e->callee, e->count, e->callee->count);
213 dump_callgraph_transformation (e->callee, inlining_into,
214 "inlining to");
216 else
218 struct cgraph_node *n;
220 n = e->callee->create_clone (e->callee->decl,
221 e->count,
222 update_original, vNULL, true,
223 inlining_into,
224 NULL);
225 n->used_as_abstract_origin = e->callee->used_as_abstract_origin;
226 e->redirect_callee (n);
229 else
230 e->callee->remove_from_same_comdat_group ();
232 e->callee->inlined_to = inlining_into;
234 /* Recursively clone all bodies. */
235 for (e = e->callee->callees; e; e = next)
237 next = e->next_callee;
238 if (!e->inline_failed)
239 clone_inlined_nodes (e, duplicate, update_original, overall_size);
243 /* Check all speculations in N and if any seem useless, resolve them. When a
244 first edge is resolved, pop all edges from NEW_EDGES and insert them to
245 EDGE_SET. Then remove each resolved edge from EDGE_SET, if it is there. */
247 static bool
248 check_speculations_1 (cgraph_node *n, vec<cgraph_edge *> *new_edges,
249 hash_set <cgraph_edge *> *edge_set)
251 bool speculation_removed = false;
252 cgraph_edge *next;
254 for (cgraph_edge *e = n->callees; e; e = next)
256 next = e->next_callee;
257 if (e->speculative && !speculation_useful_p (e, true))
259 while (new_edges && !new_edges->is_empty ())
260 edge_set->add (new_edges->pop ());
261 edge_set->remove (e);
263 cgraph_edge::resolve_speculation (e, NULL);
264 speculation_removed = true;
266 else if (!e->inline_failed)
267 speculation_removed |= check_speculations_1 (e->callee, new_edges,
268 edge_set);
270 return speculation_removed;
273 /* Push E to NEW_EDGES. Called from hash_set traverse method, which
274 unfortunately means this function has to have external linkage, otherwise
275 the code will not compile with gcc 4.8. */
277 bool
278 push_all_edges_in_set_to_vec (cgraph_edge * const &e,
279 vec<cgraph_edge *> *new_edges)
281 new_edges->safe_push (e);
282 return true;
285 /* Check all speculations in N and if any seem useless, resolve them and remove
286 them from NEW_EDGES. */
288 static bool
289 check_speculations (cgraph_node *n, vec<cgraph_edge *> *new_edges)
291 hash_set <cgraph_edge *> edge_set;
292 bool res = check_speculations_1 (n, new_edges, &edge_set);
293 if (!edge_set.is_empty ())
294 edge_set.traverse <vec<cgraph_edge *> *,
295 push_all_edges_in_set_to_vec> (new_edges);
296 return res;
299 /* Mark all call graph edges coming out of NODE and all nodes that have been
300 inlined to it as in_polymorphic_cdtor. */
302 static void
303 mark_all_inlined_calls_cdtor (cgraph_node *node)
305 for (cgraph_edge *cs = node->callees; cs; cs = cs->next_callee)
307 cs->in_polymorphic_cdtor = true;
308 if (!cs->inline_failed)
309 mark_all_inlined_calls_cdtor (cs->callee);
311 for (cgraph_edge *cs = node->indirect_calls; cs; cs = cs->next_callee)
312 cs->in_polymorphic_cdtor = true;
316 /* Mark edge E as inlined and update callgraph accordingly. UPDATE_ORIGINAL
317 specify whether profile of original function should be updated. If any new
318 indirect edges are discovered in the process, add them to NEW_EDGES, unless
319 it is NULL. If UPDATE_OVERALL_SUMMARY is false, do not bother to recompute overall
320 size of caller after inlining. Caller is required to eventually do it via
321 ipa_update_overall_fn_summary.
322 If callee_removed is non-NULL, set it to true if we removed callee node.
324 Return true iff any new callgraph edges were discovered as a
325 result of inlining. */
327 bool
328 inline_call (struct cgraph_edge *e, bool update_original,
329 vec<cgraph_edge *> *new_edges,
330 int *overall_size, bool update_overall_summary,
331 bool *callee_removed)
333 int old_size = 0, new_size = 0;
334 struct cgraph_node *to = NULL;
335 struct cgraph_edge *curr = e;
336 bool comdat_local = e->callee->comdat_local_p ();
337 struct cgraph_node *callee = e->callee->ultimate_alias_target ();
338 bool new_edges_found = false;
340 int estimated_growth = 0;
341 if (! update_overall_summary)
342 estimated_growth = estimate_edge_growth (e);
343 /* This is used only for assert bellow. */
344 #if 0
345 bool predicated = inline_edge_summary (e)->predicate != NULL;
346 #endif
348 /* Don't inline inlined edges. */
349 gcc_assert (e->inline_failed);
350 /* Don't even think of inlining inline clone. */
351 gcc_assert (!callee->inlined_to);
353 to = e->caller;
354 if (to->inlined_to)
355 to = to->inlined_to;
356 if (to->thunk.thunk_p)
358 struct cgraph_node *target = to->callees->callee;
359 thunk_expansion = true;
360 symtab->call_cgraph_removal_hooks (to);
361 if (in_lto_p)
362 to->get_untransformed_body ();
363 to->expand_thunk (false, true);
364 /* When thunk is instrumented we may have multiple callees. */
365 for (e = to->callees; e && e->callee != target; e = e->next_callee)
367 symtab->call_cgraph_insertion_hooks (to);
368 thunk_expansion = false;
369 gcc_assert (e);
373 e->inline_failed = CIF_OK;
374 DECL_POSSIBLY_INLINED (callee->decl) = true;
376 if (DECL_FUNCTION_PERSONALITY (callee->decl))
377 DECL_FUNCTION_PERSONALITY (to->decl)
378 = DECL_FUNCTION_PERSONALITY (callee->decl);
380 bool reload_optimization_node = false;
381 if (!opt_for_fn (callee->decl, flag_strict_aliasing)
382 && opt_for_fn (to->decl, flag_strict_aliasing))
384 struct gcc_options opts = global_options;
385 struct gcc_options opts_set = global_options_set;
387 cl_optimization_restore (&opts, &opts_set, opts_for_fn (to->decl));
388 opts.x_flag_strict_aliasing = false;
389 if (dump_file)
390 fprintf (dump_file, "Dropping flag_strict_aliasing on %s\n",
391 to->dump_name ());
392 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
393 = build_optimization_node (&opts, &opts_set);
394 reload_optimization_node = true;
397 ipa_fn_summary *caller_info = ipa_fn_summaries->get (to);
398 ipa_fn_summary *callee_info = ipa_fn_summaries->get (callee);
399 if (!caller_info->fp_expressions && callee_info->fp_expressions)
401 caller_info->fp_expressions = true;
402 if (opt_for_fn (callee->decl, flag_rounding_math)
403 != opt_for_fn (to->decl, flag_rounding_math)
404 || opt_for_fn (callee->decl, flag_trapping_math)
405 != opt_for_fn (to->decl, flag_trapping_math)
406 || opt_for_fn (callee->decl, flag_unsafe_math_optimizations)
407 != opt_for_fn (to->decl, flag_unsafe_math_optimizations)
408 || opt_for_fn (callee->decl, flag_finite_math_only)
409 != opt_for_fn (to->decl, flag_finite_math_only)
410 || opt_for_fn (callee->decl, flag_signaling_nans)
411 != opt_for_fn (to->decl, flag_signaling_nans)
412 || opt_for_fn (callee->decl, flag_cx_limited_range)
413 != opt_for_fn (to->decl, flag_cx_limited_range)
414 || opt_for_fn (callee->decl, flag_signed_zeros)
415 != opt_for_fn (to->decl, flag_signed_zeros)
416 || opt_for_fn (callee->decl, flag_associative_math)
417 != opt_for_fn (to->decl, flag_associative_math)
418 || opt_for_fn (callee->decl, flag_reciprocal_math)
419 != opt_for_fn (to->decl, flag_reciprocal_math)
420 || opt_for_fn (callee->decl, flag_fp_int_builtin_inexact)
421 != opt_for_fn (to->decl, flag_fp_int_builtin_inexact)
422 || opt_for_fn (callee->decl, flag_errno_math)
423 != opt_for_fn (to->decl, flag_errno_math))
425 struct gcc_options opts = global_options;
426 struct gcc_options opts_set = global_options_set;
428 cl_optimization_restore (&opts, &opts_set, opts_for_fn (to->decl));
429 opts.x_flag_rounding_math
430 = opt_for_fn (callee->decl, flag_rounding_math);
431 opts.x_flag_trapping_math
432 = opt_for_fn (callee->decl, flag_trapping_math);
433 opts.x_flag_unsafe_math_optimizations
434 = opt_for_fn (callee->decl, flag_unsafe_math_optimizations);
435 opts.x_flag_finite_math_only
436 = opt_for_fn (callee->decl, flag_finite_math_only);
437 opts.x_flag_signaling_nans
438 = opt_for_fn (callee->decl, flag_signaling_nans);
439 opts.x_flag_cx_limited_range
440 = opt_for_fn (callee->decl, flag_cx_limited_range);
441 opts.x_flag_signed_zeros
442 = opt_for_fn (callee->decl, flag_signed_zeros);
443 opts.x_flag_associative_math
444 = opt_for_fn (callee->decl, flag_associative_math);
445 opts.x_flag_reciprocal_math
446 = opt_for_fn (callee->decl, flag_reciprocal_math);
447 opts.x_flag_fp_int_builtin_inexact
448 = opt_for_fn (callee->decl, flag_fp_int_builtin_inexact);
449 opts.x_flag_errno_math
450 = opt_for_fn (callee->decl, flag_errno_math);
451 if (dump_file)
452 fprintf (dump_file, "Copying FP flags from %s to %s\n",
453 callee->dump_name (), to->dump_name ());
454 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
455 = build_optimization_node (&opts, &opts_set);
456 reload_optimization_node = true;
460 /* Reload global optimization flags. */
461 if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun)
462 set_cfun (cfun, true);
464 /* If aliases are involved, redirect edge to the actual destination and
465 possibly remove the aliases. */
466 if (e->callee != callee)
468 struct cgraph_node *alias = e->callee, *next_alias;
469 e->redirect_callee (callee);
470 while (alias && alias != callee)
472 if (!alias->callers
473 && can_remove_node_now_p (alias,
474 !e->next_caller && !e->prev_caller ? e : NULL))
476 next_alias = alias->get_alias_target ();
477 alias->remove ();
478 if (callee_removed)
479 *callee_removed = true;
480 alias = next_alias;
482 else
483 break;
487 clone_inlined_nodes (e, true, update_original, overall_size);
489 gcc_assert (curr->callee->inlined_to == to);
491 old_size = ipa_size_summaries->get (to)->size;
492 ipa_merge_modref_summary_after_inlining (e);
493 ipa_merge_fn_summary_after_inlining (e);
494 if (e->in_polymorphic_cdtor)
495 mark_all_inlined_calls_cdtor (e->callee);
496 if (opt_for_fn (e->caller->decl, optimize))
497 new_edges_found = ipa_propagate_indirect_call_infos (curr, new_edges);
498 bool removed_p = check_speculations (e->callee, new_edges);
499 if (update_overall_summary)
500 ipa_update_overall_fn_summary (to, new_edges_found || removed_p);
501 else
502 /* Update self size by the estimate so overall function growth limits
503 work for further inlining into this function. Before inlining
504 the function we inlined to again we expect the caller to update
505 the overall summary. */
506 ipa_size_summaries->get (to)->size += estimated_growth;
507 new_size = ipa_size_summaries->get (to)->size;
509 if (callee->calls_comdat_local)
510 to->calls_comdat_local = true;
511 else if (to->calls_comdat_local && comdat_local)
512 to->calls_comdat_local = to->check_calls_comdat_local_p ();
514 /* FIXME: This assert suffers from roundoff errors, disable it for GCC 5
515 and revisit it after conversion to sreals in GCC 6.
516 See PR 65654. */
517 #if 0
518 /* Verify that estimated growth match real growth. Allow off-by-one
519 error due to ipa_fn_summary::size_scale roudoff errors. */
520 gcc_assert (!update_overall_summary || !overall_size || new_edges_found
521 || abs (estimated_growth - (new_size - old_size)) <= 1
522 || speculation_removed
523 /* FIXME: a hack. Edges with false predicate are accounted
524 wrong, we should remove them from callgraph. */
525 || predicated);
526 #endif
528 /* Account the change of overall unit size; external functions will be
529 removed and are thus not accounted. */
530 if (overall_size && inline_account_function_p (to))
531 *overall_size += new_size - old_size;
532 ncalls_inlined++;
534 /* This must happen after ipa_merge_fn_summary_after_inlining that rely on jump
535 functions of callee to not be updated. */
536 return new_edges_found;
539 /* For each node that was made the holder of function body by
540 save_inline_function_body, this summary contains pointer to the previous
541 holder of the body. */
543 function_summary <tree *> *ipa_saved_clone_sources;
545 /* Copy function body of NODE and redirect all inline clones to it.
546 This is done before inline plan is applied to NODE when there are
547 still some inline clones if it.
549 This is necessary because inline decisions are not really transitive
550 and the other inline clones may have different bodies. */
552 static struct cgraph_node *
553 save_inline_function_body (struct cgraph_node *node)
555 struct cgraph_node *first_clone, *n;
557 if (dump_file)
558 fprintf (dump_file, "\nSaving body of %s for later reuse\n",
559 node->dump_name ());
561 gcc_assert (node == cgraph_node::get (node->decl));
563 /* first_clone will be turned into real function. */
564 first_clone = node->clones;
566 /* Arrange first clone to not be thunk as those do not have bodies. */
567 if (first_clone->thunk.thunk_p)
569 while (first_clone->thunk.thunk_p)
570 first_clone = first_clone->next_sibling_clone;
571 first_clone->prev_sibling_clone->next_sibling_clone
572 = first_clone->next_sibling_clone;
573 if (first_clone->next_sibling_clone)
574 first_clone->next_sibling_clone->prev_sibling_clone
575 = first_clone->prev_sibling_clone;
576 first_clone->next_sibling_clone = node->clones;
577 first_clone->prev_sibling_clone = NULL;
578 node->clones->prev_sibling_clone = first_clone;
579 node->clones = first_clone;
581 first_clone->decl = copy_node (node->decl);
582 first_clone->decl->decl_with_vis.symtab_node = first_clone;
583 gcc_assert (first_clone == cgraph_node::get (first_clone->decl));
585 /* Now reshape the clone tree, so all other clones descends from
586 first_clone. */
587 if (first_clone->next_sibling_clone)
589 for (n = first_clone->next_sibling_clone; n->next_sibling_clone;
590 n = n->next_sibling_clone)
591 n->clone_of = first_clone;
592 n->clone_of = first_clone;
593 n->next_sibling_clone = first_clone->clones;
594 if (first_clone->clones)
595 first_clone->clones->prev_sibling_clone = n;
596 first_clone->clones = first_clone->next_sibling_clone;
597 first_clone->next_sibling_clone->prev_sibling_clone = NULL;
598 first_clone->next_sibling_clone = NULL;
599 gcc_assert (!first_clone->prev_sibling_clone);
602 tree prev_body_holder = node->decl;
603 if (!ipa_saved_clone_sources)
604 ipa_saved_clone_sources = new function_summary <tree *> (symtab);
605 else
607 tree *p = ipa_saved_clone_sources->get (node);
608 if (p)
610 prev_body_holder = *p;
611 gcc_assert (prev_body_holder);
614 *ipa_saved_clone_sources->get_create (first_clone) = prev_body_holder;
615 first_clone->former_clone_of
616 = node->former_clone_of ? node->former_clone_of : node->decl;
617 first_clone->clone_of = NULL;
619 /* Now node in question has no clones. */
620 node->clones = NULL;
622 /* Inline clones share decl with the function they are cloned
623 from. Walk the whole clone tree and redirect them all to the
624 new decl. */
625 if (first_clone->clones)
626 for (n = first_clone->clones; n != first_clone;)
628 gcc_assert (n->decl == node->decl);
629 n->decl = first_clone->decl;
630 if (n->clones)
631 n = n->clones;
632 else if (n->next_sibling_clone)
633 n = n->next_sibling_clone;
634 else
636 while (n != first_clone && !n->next_sibling_clone)
637 n = n->clone_of;
638 if (n != first_clone)
639 n = n->next_sibling_clone;
643 /* Copy the OLD_VERSION_NODE function tree to the new version. */
644 tree_function_versioning (node->decl, first_clone->decl,
645 NULL, NULL, true, NULL, NULL);
647 /* The function will be short lived and removed after we inline all the clones,
648 but make it internal so we won't confuse ourself. */
649 DECL_EXTERNAL (first_clone->decl) = 0;
650 TREE_PUBLIC (first_clone->decl) = 0;
651 DECL_COMDAT (first_clone->decl) = 0;
652 first_clone->ipa_transforms_to_apply.release ();
654 /* When doing recursive inlining, the clone may become unnecessary.
655 This is possible i.e. in the case when the recursive function is proved to be
656 non-throwing and the recursion happens only in the EH landing pad.
657 We cannot remove the clone until we are done with saving the body.
658 Remove it now. */
659 if (!first_clone->callers)
661 first_clone->remove_symbol_and_inline_clones ();
662 first_clone = NULL;
664 else if (flag_checking)
665 first_clone->verify ();
667 return first_clone;
670 /* Return true when function body of DECL still needs to be kept around
671 for later re-use. */
672 static bool
673 preserve_function_body_p (struct cgraph_node *node)
675 gcc_assert (symtab->global_info_ready);
676 gcc_assert (!node->alias && !node->thunk.thunk_p);
678 /* Look if there is any non-thunk clone around. */
679 for (node = node->clones; node; node = node->next_sibling_clone)
680 if (!node->thunk.thunk_p)
681 return true;
682 return false;
685 /* Apply inline plan to function. */
687 unsigned int
688 inline_transform (struct cgraph_node *node)
690 unsigned int todo = 0;
691 struct cgraph_edge *e, *next;
692 bool has_inline = false;
694 /* FIXME: Currently the pass manager is adding inline transform more than
695 once to some clones. This needs revisiting after WPA cleanups. */
696 if (cfun->after_inlining)
697 return 0;
699 /* We might need the body of this function so that we can expand
700 it inline somewhere else. */
701 if (preserve_function_body_p (node))
702 save_inline_function_body (node);
704 profile_count num = node->count;
705 profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
706 bool scale = num.initialized_p () && !(num == den);
707 if (scale)
709 profile_count::adjust_for_ipa_scaling (&num, &den);
710 if (dump_file)
712 fprintf (dump_file, "Applying count scale ");
713 num.dump (dump_file);
714 fprintf (dump_file, "/");
715 den.dump (dump_file);
716 fprintf (dump_file, "\n");
719 basic_block bb;
720 cfun->cfg->count_max = profile_count::uninitialized ();
721 FOR_ALL_BB_FN (bb, cfun)
723 bb->count = bb->count.apply_scale (num, den);
724 cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
726 ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
729 for (e = node->callees; e; e = next)
731 if (!e->inline_failed)
732 has_inline = true;
733 next = e->next_callee;
734 cgraph_edge::redirect_call_stmt_to_callee (e);
736 node->remove_all_references ();
738 timevar_push (TV_INTEGRATION);
739 if (node->callees && (opt_for_fn (node->decl, optimize) || has_inline))
741 todo = optimize_inline_calls (current_function_decl);
743 timevar_pop (TV_INTEGRATION);
745 cfun->always_inline_functions_inlined = true;
746 cfun->after_inlining = true;
747 todo |= execute_fixup_cfg ();
749 if (!(todo & TODO_update_ssa_any))
750 /* Redirecting edges might lead to a need for vops to be recomputed. */
751 todo |= TODO_update_ssa_only_virtuals;
753 return todo;