public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: gcc-patches@gcc.gnu.org
Subject: Cgraph alias reorg 20/14 (inliner and same comdat groups)
Date: Mon, 13 Jun 2011 15:30:00 -0000	[thread overview]
Message-ID: <20110613131633.GA11750@kam.mff.cuni.cz> (raw)

Hi,
this patch makes inliner to handle removal of offline copies of functions in
the same comdat groups.  Since aliases are now functions and a lot of comdat
functions do have aliases, we end up having a lot more comdat groups than before.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

	* ipa-inline-transform.c (can_remove_node_now_p_1): Break out from...
	(can_remove_node_now_p): ... here; handle same comdat groups.
	(clone_inlined_nodes): Update use of can_remove_node_now_p add TODO.
	(inline_call): Update use of can_remove_node_now_p.
Index: ipa-inline-transform.c
===================================================================
--- ipa-inline-transform.c	(revision 174970)
+++ ipa-inline-transform.c	(working copy)
@@ -83,7 +83,7 @@ update_noncloned_frequencies (struct cgr
    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
@@ -98,15 +98,34 @@ can_remove_node_now_p (struct cgraph_nod
 	  && (!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.
@@ -128,8 +147,15 @@ clone_inlined_nodes (struct cgraph_edge 
 	  /* 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 +226,7 @@ inline_call (struct cgraph_edge *e, bool
       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);

                 reply	other threads:[~2011-06-13 13:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110613131633.GA11750@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).