[lto] Factor predicate out of set_asm_name

Diego Novillo dnovillo@google.com
Wed Dec 31 15:14:00 GMT 2008


I cleaned up the predicate we use to check which decls should get
an asm name and pulled it out in a new function.

I also added an additional check for FUNCTION_DECLs.  If the
function had its address taken, it also need its asm name set.
This fixes one additional test in check-gcc.

Tested on x86_64.



	* tree.c (need_assembler_name_p): Factor out of ...
	(set_asm_name): ... here.

Index: tree.c
===================================================================
--- tree.c	(revision 142954)
+++ tree.c	(working copy)
@@ -3993,28 +3993,58 @@ reset_type_lang_specific (void **slot, v
 }
 
 
+
+/* Return true if DECL may need an assembler name to be set.  */
+
+static inline bool
+need_assembler_name_p (tree decl)
+{
+  /* Only FUNCTION_DECLs and VAR_DECLs are considered.  */
+  if (TREE_CODE (decl) != FUNCTION_DECL
+      && TREE_CODE (decl) != VAR_DECL)
+    return false;
+
+  /* If DECL is ignored or already has its assembler name set, it does
+     not need a new one.  */
+  if (DECL_IGNORED_P (decl)
+      || !HAS_DECL_ASSEMBLER_NAME_P (decl)
+      || DECL_ASSEMBLER_NAME_SET_P (decl))
+    return false;
+
+  /* For VAR_DECLs, we are only interested in static, public and external
+     declarations.  */
+  if (TREE_CODE (decl) == VAR_DECL
+      && !TREE_STATIC (decl)
+      && !TREE_PUBLIC (decl)
+      && !DECL_EXTERNAL (decl))
+    return false;
+
+  /* For FUNCTION_DECLs, we only are interested in addressable and used
+     functions.  */
+  if (TREE_CODE (decl) == FUNCTION_DECL
+      && !TREE_USED (decl)
+      && !TREE_ADDRESSABLE (decl))
+    return false;
+
+  return true;
+}
+
+
 /* Helper function of free_lang_specifics.
    Set the assembler name for nodes that may need one.  */
 
 static int
 set_asm_name (void **slot, void *unused ATTRIBUTE_UNUSED)
 {
-  tree decl = *(tree*) slot;
-  if (HAS_DECL_ASSEMBLER_NAME_P (decl)
-      && (TREE_CODE (decl) == FUNCTION_DECL
-          || TREE_CODE (decl) == VAR_DECL)
-      && !DECL_ASSEMBLER_NAME_SET_P (decl)
-      && !DECL_IGNORED_P (decl)
-      && (TREE_CODE (decl) != VAR_DECL
-	  || TREE_STATIC (decl)
-	  || TREE_PUBLIC (decl)
-	  || DECL_EXTERNAL (decl))
-      && (TREE_CODE (decl) != FUNCTION_DECL
-	  || TREE_USED (decl)))
+  tree decl = *((tree *) slot);
+
+  if (need_assembler_name_p (decl))
     lang_hooks.set_decl_assembler_name (decl);
+
   return 1;
 }
 
+
 /* Helper function of free_lang_specifics. */
 
 static int



More information about the Gcc-patches mailing list