This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] ditch rebuild_ssa_for_lto


I'd like to check in the patch below on the LTO branch.  However, it is
mildly controversial, intent-wise, so I'm going to hold off for a couple
of days to let people comment on the approach.  I will note up front
that this patch makes forward progress on the testsuite--the only
problems appear to be when we have virtual operands in statements; the
virtual operands do not get reconstituted on the reading side.  I don't
know how hard this is to fix...

A bit of explanation first: when dumping function bodies for LTO, we
dump out things in SSA form.  Except that we don't dump out *everything*
associated with ssa form.  We dump out enough that we can read things
back in and then run the CFG through a referenced-vars pass and a
rebuild-ssa-for-lto pass, which takes care of reconstituting all the
little bits that we didn't serialize.

This generally works well.  It runs into problems, however, because the
SSA rebuilding process starts from scratch and handing SSA to the SSA
building process does not work so well sometimes (e.g. when you have two
differently-versioned instances of a variable with overlapping live
ranges).  It also seems silly to build something so close to SSA form
and then go through and rebuild the whole thing.

So this patch attempts to do away with all that.  During reading, we add
referenced variables when appropriate and we let normal statement
updating take care of rebuilding the necessary pieces.  The
referenced-vars pass goes away, rebuild_ssa_for_lto can become a no-op,
and we get a generally cleaner codebase.  I haven't removed the two
passes from the pass list yet, though.

I do realize that at least DannyB has voiced objections to this approach
and I realize DannyB has much more experience with the Tree-SSA code
than I do.  However, I think the general approach (not entirely
rebuilding SSA form) is sound, even if the particular tack I have taken
may not be.  (I think we could at least get away with ditching the
referenced-vars pass.)  Hence the posting for comments before actually
committing the patch.

The patch also contains some generally useful bits that I will commit at
some point, like the setting of TREE_THIS_VOLATILE on decls and the use
of {push,pop}_cfun.

-Nathan

gcc/
	* tree-into-ssa.c (rebuild_ssa_for_lto): Remove rebuilding code.
	(pass_rebuild_ssa_for_lto): Add TODO_verify_all.

gcc/lto/
	* lto.c (lto_read_variable_formal_parameter_constant_DIE): Set
	TREE_THIS_VOLATILE if the associated type is a volatile type.
	(lto_materialize_function): Remove call to init_ssa_operands.
	* lto-read.c (input_expr_operand): Add SSA_NAME_VAR as a referenced
	variable when reading an SSA_NAME.  Do the same when reading a
	RESULT_DECL, a RETURN_EXPR, or an MTAG.
	(input_cfg): Call init_ssa_operands.
	(input_ssa_names): Set the default def of an SSA_NAME if necessary.
	Move call to init_tree_ssa...
	(lto_read_body): ...here.  Use push_cfun and pop_cfun.  Call
	add_referenced_var on any variables referenced from the body of the
	function.  Inform the rest of the compiler we are in SSA form.

Index: gcc/tree-into-ssa.c
===================================================================
--- gcc/tree-into-ssa.c	(revision 130517)
+++ gcc/tree-into-ssa.c	(working copy)
@@ -3369,26 +3369,7 @@ done:
 static unsigned int
 rebuild_ssa_for_lto (void)
 {
-  block_stmt_iterator bsi;
-  basic_block bb;
-  referenced_var_iterator rvi;
-  tree var;
-
-  init_ssa_operands ();
-  FOR_EACH_BB (bb)
-    for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
-      update_stmt_if_modified (bsi_stmt (bsi));
-
-  FOR_EACH_REFERENCED_VAR (var, rvi)
-    {
-      if (dump_file)
-	print_node (dump_file, "\nmarking symbol for renaming ", var, 0);
-      mark_sym_for_renaming (var);
-    }
-
-  update_ssa (TODO_update_ssa);
   return 1;
-
 }
 
 
@@ -3406,7 +3387,7 @@ struct tree_opt_pass pass_rebuild_ssa_fo
   0,					/* properties_destroyed */
   0,					/* todo_flags_start */
   TODO_dump_func
-    | TODO_verify_ssa
+    | TODO_verify_all
     | TODO_remove_unused_locals,	/* todo_flags_finish */
   0					/* letter */
 };
Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c	(revision 130545)
+++ gcc/lto/lto.c	(working copy)
@@ -2094,6 +2094,8 @@ lto_read_variable_formal_parameter_const
 
 	  if (TYPE_QUALS (type) & TYPE_QUAL_CONST)
 	    TREE_READONLY (decl) = 1;
+	  if (TYPE_QUALS (type) & TYPE_QUAL_VOLATILE)
+	    TREE_THIS_VOLATILE (decl) = 1;
 
 	  if (!TREE_PUBLIC (decl))
 	    {
@@ -2426,8 +2428,6 @@ lto_materialize_function (lto_info_fd *f
 	 useless work while reading in LTO files--building SSA operands
 	 once while reading and then rebuilding again during
 	 rebuild_ssa_for_lto.  */
-      init_ssa_operands ();
-
       cgraph_finalize_function (decl, /*nested=*/false);
     }
 }
Index: gcc/lto/lto-read.c
===================================================================
--- gcc/lto/lto-read.c	(revision 130517)
+++ gcc/lto/lto-read.c	(working copy)
@@ -735,6 +735,7 @@ input_expr_operand (struct input_block *
 
     case SSA_NAME:
       result = VEC_index (tree, SSANAMES (fn), input_uleb128 (ib));
+      add_referenced_var (SSA_NAME_VAR (result));
       break;
 
     case CONST_DECL:
@@ -834,6 +835,7 @@ input_expr_operand (struct input_block *
 
     case RESULT_DECL:
       result = build0 (code, type);
+      add_referenced_var (result);
       break;
 
     case COMPONENT_REF:
@@ -960,7 +962,10 @@ input_expr_operand (struct input_block *
             if (tag)
               op0 = input_expr_operand (ib, data_in, fn, tag);
             else
-              op0 = DECL_RESULT (current_function_decl);
+	      {
+		op0 = DECL_RESULT (current_function_decl);
+		add_referenced_var (op0);
+	      }
 
             result = build1 (code, type, op0);
 
@@ -1161,6 +1166,8 @@ input_expr_operand (struct input_block *
 
       recompute_tree_invariant_for_addr_expr (result);
     }
+  else if (MTAG_P (result))
+    add_referenced_var (result);
   return result;
 }
 
@@ -1430,6 +1437,7 @@ input_cfg (struct input_block *ib, struc
   int index;
 
   init_flow (fn);
+  init_ssa_operands ();
 
   LTO_DEBUG_TOKEN ("lastbb");
   bb_count = input_uleb128 (ib);
@@ -1565,7 +1573,6 @@ input_ssa_names (struct input_block *ib,
   unsigned int i;
   int size = input_uleb128 (ib);
 
-  init_tree_ssa (fn);
   init_ssanames (fn, size);
   i = input_uleb128 (ib);
 
@@ -1584,6 +1591,8 @@ input_ssa_names (struct input_block *ib,
 
       flags = input_tree_flags (ib, 0, true);
       process_tree_flags (ssa_name, flags);
+      if (SSA_NAME_IS_DEFAULT_DEF (ssa_name))
+	set_default_def (SSA_NAME_VAR (ssa_name), ssa_name);
       i = input_uleb128 (ib);
     } 
 }
@@ -1889,7 +1898,8 @@ lto_read_body (lto_info_fd *fd,
   if (in_function)
     {
       struct function *fn = DECL_STRUCT_FUNCTION (t);
-      cfun = fn;
+      push_cfun (fn);
+      init_tree_ssa (fn);
       data_in.num_named_labels = header->num_named_labels;
 
 #ifdef LTO_STREAM_DEBUGGING
@@ -1918,11 +1928,27 @@ lto_read_body (lto_info_fd *fd,
 #endif
       input_cfg (&ib_cfg, fn);
 
+      /* Ensure that all our variables have annotations attached to them
+	 so building SSA doesn't choke.  */
+      {
+	int i;
+
+	for (i = 0; i < header->num_var_decls; i++)
+	  add_referenced_var (data_in.var_decls[i]);
+	for (i =0; i < header->num_local_decls; i++)
+	  add_referenced_var (data_in.local_decls[i]);
+      }
+
 #ifdef LTO_STREAM_DEBUGGING
       lto_debug_context.current_data = &debug_main;
 #endif
       /* Set up the struct function.  */
       input_function (t, &data_in, &ib_main);
+
+      /* We should now be in SSA.  */
+      cfun->gimple_df->in_ssa_p = true;
+
+      pop_cfun ();
     }
   else 
     {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]