OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ipa-inline-transform.c
index e10e28e..ce1bc6e 100644 (file)
@@ -83,7 +83,7 @@ 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
@@ -95,18 +95,35 @@ can_remove_node_now_p (struct cgraph_node *node)
             those only after all devirtualizable virtual calls are processed.
             Lacking may edges in callgraph we just preserve them post
             inlining.  */
-         && (!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
+         && !DECL_VIRTUAL_P (node->decl)
          /* 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 ((next->callers && next->callers != e)
+       || !can_remove_node_now_p_1 (next))
+      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.
@@ -128,8 +145,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))
            {
@@ -200,7 +224,7 @@ inline_call (struct cgraph_edge *e, bool update_original,
       while (alias && alias != callee)
        {
          if (!alias->callers
-             && can_remove_node_now_p (alias))
+             && can_remove_node_now_p (alias, e))
            {
              next_alias = cgraph_alias_aliased_node (alias);
              cgraph_remove_node (alias);
@@ -222,7 +246,9 @@ inline_call (struct cgraph_edge *e, bool update_original,
     *overall_size += new_size - old_size;
   ncalls_inlined++;
 
-  if (flag_indirect_inlining && optimize)
+  /* This must happen after inline_merge_summary that rely on jump
+     functions of callee to not be updated.  */
+  if (optimize)
     return ipa_propagate_indirect_call_infos (curr, new_edges);
   else
     return false;
@@ -296,7 +322,7 @@ save_inline_function_body (struct cgraph_node *node)
 
   /* Copy the OLD_VERSION_NODE function tree to the new version.  */
   tree_function_versioning (node->decl, first_clone->decl, NULL, true, NULL,
-                           NULL, NULL);
+                           false, NULL, NULL);
 
   /* The function will be short lived and removed after we inline all the clones,
      but make it internal so we won't confuse ourself.  */
@@ -322,8 +348,7 @@ inline_transform (struct cgraph_node *node)
 {
   unsigned int todo = 0;
   struct cgraph_edge *e;
-  bool inline_p = false;
-
   /* FIXME: Currently the pass manager is adding inline transform more than
      once to some clones.  This needs revisiting after WPA cleanups.  */
   if (cfun->after_inlining)
@@ -335,21 +360,20 @@ inline_transform (struct cgraph_node *node)
     save_inline_function_body (node);
 
   for (e = node->callees; e; e = e->next_callee)
-    {
-      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;
-    }
+    cgraph_redirect_edge_call_stmt_to_callee (e);
+
+  timevar_push (TV_INTEGRATION);
+  if (node->callees)
+    todo = optimize_inline_calls (current_function_decl);
+  timevar_pop (TV_INTEGRATION);
 
-  if (inline_p)
-    {
-      timevar_push (TV_INTEGRATION);
-      todo = optimize_inline_calls (current_function_decl);
-      timevar_pop (TV_INTEGRATION);
-    }
   cfun->always_inline_functions_inlined = true;
   cfun->after_inlining = true;
-  return todo | execute_fixup_cfg ();
+  todo |= execute_fixup_cfg ();
+
+  if (!(todo & TODO_update_ssa_any))
+    /* Redirecting edges might lead to a need for vops to be recomputed.  */
+    todo |= TODO_update_ssa_only_virtuals;
+
+  return todo;
 }