[PATCH] Remove redundant cgraph_node_for_decl function

Jakub Jelinek jakub@redhat.com
Wed Nov 18 17:38:00 GMT 2009


Hi!

When working on same_body alias cgraph support, I've noticed
that cgraph_node_for_decl does the same thing as cgraph_get_node.
This patch removes the former and does a tiny optimization in the latter,
inspired by cgraph_node_for_decl implementation - if cgraph_hash
is NULL, we don't need to create the hash table only to find out decl
is not there.

Ok for trunk if it passes bootstrap/regtest?

2009-11-18  Jakub Jelinek  <jakub@redhat.com>

	* tree.c (need_assembler_name_p): Use cgraph_get_node instead
	of cgraph_node_for_decl.
	* cgraph.h (cgraph_node_for_decl): Remove prototype.
	* cgraph.c (cgraph_node_for_decl): Remove.
	(cgraph_get_node): Just return NULL if !cgraph_hash.

--- gcc/tree.c.jj	2009-11-09 13:30:10.000000000 +0100
+++ gcc/tree.c	2009-11-18 18:13:13.000000000 +0100
@@ -4289,7 +4289,7 @@ need_assembler_name_p (tree decl)
 	return false;
 
       /* Functions represented in the callgraph need an assembler name.  */
-      if (cgraph_node_for_decl (decl) != NULL)
+      if (cgraph_get_node (decl) != NULL)
 	return true;
 
       /* Unused and not public functions don't need an assembler name.  */
--- gcc/cgraph.h.jj	2009-11-18 15:48:55.000000000 +0100
+++ gcc/cgraph.h	2009-11-18 18:12:40.000000000 +0100
@@ -425,7 +425,6 @@ struct cgraph_node *cgraph_node (tree);
 bool cgraph_same_body_alias (tree, tree);
 void cgraph_remove_same_body_alias (struct cgraph_node *);
 struct cgraph_node *cgraph_node_for_asm (tree);
-struct cgraph_node *cgraph_node_for_decl (tree);
 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
--- gcc/cgraph.c.jj	2009-11-18 15:48:55.000000000 +0100
+++ gcc/cgraph.c	2009-11-18 18:12:24.000000000 +0100
@@ -406,36 +406,6 @@ hash_node (const void *p)
 }
 
 
-/* Return the cgraph node associated with function DECL.  If none
-   exists, return NULL.  */
-
-struct cgraph_node *
-cgraph_node_for_decl (tree decl)
-{
-  struct cgraph_node *node;
-  void **slot;
-
-  gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
-
-  node = NULL;
-  if (cgraph_hash)
-    {
-      struct cgraph_node key;
-
-      key.decl = decl;
-      slot = htab_find_slot (cgraph_hash, &key, NO_INSERT);
-      if (slot && *slot)
-	{
-	  node = (struct cgraph_node *) *slot;
-	  if (node->same_body_alias)
-	    node = node->same_body;
-	}
-    }
-
-  return node;
-}
-
-
 /* Returns nonzero if P1 and P2 are equal.  */
 
 static int
@@ -594,7 +564,7 @@ cgraph_get_node (tree decl)
   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
 
   if (!cgraph_hash)
-    cgraph_hash = htab_create_ggc (10, hash_node, eq_node, NULL);
+    return NULL;
 
   key.decl = decl;
 

	Jakub



More information about the Gcc-patches mailing list