diff options
Diffstat (limited to 'gcc/ipa-inline-transform.c')
-rw-r--r-- | gcc/ipa-inline-transform.c | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c index c5f32a34b76..2e1375437d5 100644 --- a/gcc/ipa-inline-transform.c +++ b/gcc/ipa-inline-transform.c @@ -45,6 +45,7 @@ along with GCC; see the file COPYING3. If not see #include "ipa-prop.h" #include "ipa-inline.h" #include "tree-inline.h" +#include "tree-pass.h" int ncalls_inlined; int nfunctions_inlined; @@ -82,12 +83,13 @@ update_noncloned_frequencies (struct cgraph_node *node, copy of function was removed. */ static bool -can_remove_node_now_p (struct cgraph_node *node) +can_remove_node_now_p_1 (struct cgraph_node *node) { /* FIXME: When address is taken of DECL_EXTERNAL function we still can remove its offline copy, but we would need to keep unanalyzed node in the callgraph so references can point to it. */ return (!node->address_taken + && !ipa_ref_has_aliases_p (&node->ref_list) && cgraph_can_remove_if_no_direct_calls_p (node) /* Inlining might enable more devirtualizing, so we want to remove those only after all devirtualizable virtual calls are processed. @@ -96,15 +98,34 @@ can_remove_node_now_p (struct cgraph_node *node) && (!DECL_VIRTUAL_P (node->decl) || (!DECL_COMDAT (node->decl) && !DECL_EXTERNAL (node->decl))) - /* Don't reuse if more than one function shares a comdat group. - If the other function(s) are needed, we need to emit even - this function out of line. */ - && !node->same_comdat_group /* During early inlining some unanalyzed cgraph nodes might be in the callgraph and they might reffer the function in question. */ && !cgraph_new_nodes); } +/* We are going to eliminate last direct call to NODE (or alias of it) via edge E. + Verify that the NODE can be removed from unit and if it is contained in comdat + group that the whole comdat group is removable. */ + +static bool +can_remove_node_now_p (struct cgraph_node *node, struct cgraph_edge *e) +{ + struct cgraph_node *next; + if (!can_remove_node_now_p_1 (node)) + return false; + + /* When we see same comdat group, we need to be sure that all + items can be removed. */ + if (!node->same_comdat_group) + return true; + for (next = node->same_comdat_group; + next != node; next = next->same_comdat_group) + if (node->callers && node->callers != e + && !can_remove_node_now_p_1 (node)) + return false; + return true; +} + /* E is expected to be an edge being inlined. Clone destination node of the edge and redirect it to the new clone. @@ -126,8 +147,15 @@ clone_inlined_nodes (struct cgraph_edge *e, bool duplicate, /* Recursive inlining never wants the master clone to be overwritten. */ && update_original - && can_remove_node_now_p (e->callee)) + && can_remove_node_now_p (e->callee, e)) { + /* TODO: When callee is in a comdat group, we could remove all of it, + including all inline clones inlined into it. That would however + need small function inlining to register edge removal hook to + maintain the priority queue. + + For now we keep the ohter functions in the group in program until + cgraph_remove_unreachable_functions gets rid of them. */ gcc_assert (!e->callee->global.inlined_to); if (e->callee->analyzed && !DECL_EXTERNAL (e->callee->decl)) { @@ -192,7 +220,22 @@ inline_call (struct cgraph_edge *e, bool update_original, /* If aliases are involved, redirect edge to the actual destination and possibly remove the aliases. */ if (e->callee != callee) - cgraph_redirect_edge_callee (e, callee); + { + struct cgraph_node *alias = e->callee, *next_alias; + cgraph_redirect_edge_callee (e, callee); + while (alias && alias != callee) + { + if (!alias->callers + && can_remove_node_now_p (alias, e)) + { + next_alias = cgraph_alias_aliased_node (alias); + cgraph_remove_node (alias); + alias = next_alias; + } + else + break; + } + } clone_inlined_nodes (e, true, update_original, overall_size); @@ -322,6 +365,8 @@ inline_transform (struct cgraph_node *node) cgraph_redirect_edge_call_stmt_to_callee (e); if (!e->inline_failed || warn_inline) inline_p = true; + /* Redirecting edges might lead to a need for vops to be recomputed. */ + todo |= TODO_update_ssa_only_virtuals; } if (inline_p) |