Patchwork LTO partitioning reorg 3/n - remove some hacks and handle vars/functions more regularly

login
register
mail settings
Submitter Jan Hubicka
Date Sept. 10, 2012, 8:39 a.m.
Message ID <20120910083910.GA8913@kam.mff.cuni.cz>
Download mbox | patch
Permalink /patch/182823/
State New
Headers show

Comments

Jan Hubicka - Sept. 10, 2012, 8:39 a.m.
Hi,
this patch makes variable and cgraph handling more alike so code can be shared
in future. The basic idea is to categorize symbols into three categories:

 1) external symbols that goes only into boundary if they are used.
 2) partitioned symbols that goes into one partition based on decision
    of particular paritioning alg.
 3) non-partitioned symbols (COMDATs that are not keyed by C++ ABI and not used
    by object files, weakrefs, constat pool).
    Those symbols are output only if used and are duplicated into
    every partition using them.

1) is easy to identify by DECL_EXTERNAL_P, for 2) we have partition_symbol_p
and 3) is the case where first two tests fails.

I will cleanup the APIs in the followup.  The purpose of this patch is to
remove hacks that has cummulated in the code over as it envolved and I believe
they are not needed (or rather was fixing symptoms rather than bugs).  One was
handling of COMDAT where I managed to convince myself that I need to ship it
into every partition even if it is keyed by C++ ABI. This should not be true.

Second is somewhat convoluted handling of aliases. This come from a time when
we made no difference in between aliases and weakrefs but we had the
non-same-body alias path still around.

I tested the patch by bootstrapping/regtested x86_64-linux and also by compiling
mozilla/Qt/webkit with LTO.
Comitted.

Honza

	* lto-cgraph.c (compute_ltrans_boundary): Do not care about aliases.
	* lto-partition.c (partition_symbol_p): Forward declare.
	(add_references_to_partition): Reimplement using partition_symbol_p.
	(add_aliases_to_partition): Break out from add_references_to_partition;
	reimplement using partition_symbol_p.
	(add_cgraph_node_to_partition_1): Handle callees using partition_symbol_p;
	add sanity checks.
	(add_varpool_node_to_partition): Use add_aliases_to_partition.
	(partition_varpool_node_p): Do not special case aliases.

Patch

Index: lto-cgraph.c
===================================================================
--- lto-cgraph.c	(revision 191113)
+++ lto-cgraph.c	(working copy)
@@ -730,8 +730,6 @@  compute_ltrans_boundary (lto_symtab_enco
 	      lto_set_symtab_encoder_encode_initializer (encoder, vnode);
 	      add_references (encoder, &vnode->symbol.ref_list);
 	    }
-	  else if (vnode->alias || vnode->alias_of)
-	    add_references (encoder, &vnode->symbol.ref_list);
        }
     }
 
Index: lto/lto-partition.c
===================================================================
--- lto/lto-partition.c	(revision 191113)
+++ lto/lto-partition.c	(working copy)
@@ -35,6 +35,7 @@  VEC(ltrans_partition, heap) *ltrans_part
 
 static void add_cgraph_node_to_partition (ltrans_partition part, struct cgraph_node *node);
 static void add_varpool_node_to_partition (ltrans_partition part, struct varpool_node *vnode);
+static bool partition_symbol_p (symtab_node node);
 
 /* Create new partition with name NAME.  */
 static ltrans_partition
@@ -62,8 +63,8 @@  free_ltrans_partitions (void)
   VEC_free (ltrans_partition, heap, ltrans_partitions);
 }
 
-/* See all references that go to comdat objects and bring them into partition too.
-   Also see all aliases of the newly added entry and bring them, too.  */
+/* Add all referenced symbols referenced by REFS that are not external and not
+   partitioned into PART.  */
 static void
 add_references_to_partition (ltrans_partition part, struct ipa_ref_list *refs)
 {
@@ -71,46 +72,38 @@  add_references_to_partition (ltrans_part
   struct ipa_ref *ref;
   for (i = 0; ipa_ref_list_reference_iterate (refs, i, ref); i++)
     {
-      if (symtab_function_p (ref->referred)
-	  && (DECL_COMDAT (cgraph_function_node (ipa_ref_node (ref),
-			   NULL)->symbol.decl)
-	      || (ref->use == IPA_REF_ALIAS
-		  && lookup_attribute
-		       ("weakref", DECL_ATTRIBUTES (ref->referred->symbol.decl))))
-	  && !lto_symtab_encoder_in_partition_p (part->encoder, ref->referred))
+      if (DECL_EXTERNAL (ref->referred->symbol.decl)
+	  || partition_symbol_p (ref->referred)
+	  || lto_symtab_encoder_in_partition_p (part->encoder, ref->referred))
+	continue;
+      if (symtab_function_p (ref->referred))
 	add_cgraph_node_to_partition (part, ipa_ref_node (ref));
       else
-        if (symtab_variable_p (ref->referred)
-	    && (DECL_COMDAT (ref->referred->symbol.decl)
-		|| DECL_EXTERNAL (ref->referred->symbol.decl)
-	        || (ref->use == IPA_REF_ALIAS
-		    && lookup_attribute
-		         ("weakref",
-			  DECL_ATTRIBUTES (ref->referred->symbol.decl))))
-	    && !lto_symtab_encoder_in_partition_p (part->encoder, ref->referred))
-	  add_varpool_node_to_partition (part, ipa_ref_varpool_node (ref));
+	add_varpool_node_to_partition (part, ipa_ref_varpool_node (ref));
     }
+}
+
+/* Look for all (nonweakref) aliases in REFS and add them into PART. */
+static void
+add_aliases_to_partition (ltrans_partition part, struct ipa_ref_list *refs)
+{
+  int i;
+  struct ipa_ref *ref;
+
   for (i = 0; ipa_ref_list_referring_iterate (refs, i, ref); i++)
-    {
-      if (symtab_function_p (ref->referring)
-	  && ref->use == IPA_REF_ALIAS
-	  && !lto_symtab_encoder_in_partition_p (part->encoder,
-						 ref->referring)
-	  && !lookup_attribute ("weakref",
-				DECL_ATTRIBUTES
-				  (ref->referring->symbol.decl)))
-	add_cgraph_node_to_partition (part, ipa_ref_referring_node (ref));
-      else
-        if (symtab_variable_p (ref->referring)
-	    && ref->use == IPA_REF_ALIAS
-	    && !lto_symtab_encoder_in_partition_p (part->encoder,
-						   ref->referring)
-	    && !lookup_attribute ("weakref",
-				  DECL_ATTRIBUTES
-				    (ref->referring->symbol.decl)))
+    if (ref->use == IPA_REF_ALIAS
+	&& !lto_symtab_encoder_in_partition_p (part->encoder,
+					       ref->referring)
+	&& !lookup_attribute ("weakref",
+			      DECL_ATTRIBUTES
+				(ref->referring->symbol.decl)))
+      {
+	if (symtab_function_p (ref->referring))
+	  add_cgraph_node_to_partition (part, ipa_ref_referring_node (ref));
+	else
 	  add_varpool_node_to_partition (part,
 					 ipa_ref_referring_varpool_node (ref));
-    }
+      }
 }
 
 /* Worker for add_cgraph_node_to_partition.  */
@@ -129,6 +122,8 @@  add_cgraph_node_to_partition_1 (struct c
       return false;
     }
 
+  gcc_assert (!lto_symtab_encoder_in_partition_p (part->encoder, (symtab_node) node));
+
   if (node->symbol.aux)
     {
       node->symbol.in_other_partition = 1;
@@ -157,12 +152,10 @@  add_cgraph_node_to_partition (ltrans_par
 
   part->insns += inline_summary (node)->self_size;
 
-
-  lto_set_symtab_encoder_in_partition (part->encoder, (symtab_node) node);
-
   for (e = node->callees; e; e = e->next_callee)
     if ((!e->inline_failed
-	 || DECL_COMDAT (cgraph_function_node (e->callee, NULL)->symbol.decl)))
+         || (!DECL_EXTERNAL (e->callee->symbol.decl)
+	     && !partition_symbol_p ((symtab_node) e->callee))))
       add_cgraph_node_to_partition (part, e->callee);
 
   /* The only way to assemble non-weakref alias is to add the aliased object into
@@ -211,6 +204,7 @@  add_varpool_node_to_partition (ltrans_pa
     add_varpool_node_to_partition (part, v);
 
   add_references_to_partition (part, &vnode->symbol.ref_list);
+  add_aliases_to_partition (part, &vnode->symbol.ref_list);
 
   if (vnode->symbol.same_comdat_group
       && !lto_symtab_encoder_in_partition_p (part->encoder,
@@ -266,7 +260,7 @@  partition_cgraph_node_p (struct cgraph_n
 static bool
 partition_varpool_node_p (struct varpool_node *vnode)
 {
-  if (vnode->alias || !vnode->analyzed)
+  if (!vnode->analyzed)
     return false;
   /* Constant pool and comdat are always only in partitions they are needed.  */
   if (DECL_IN_CONSTANT_POOL (vnode->symbol.decl)