Patchwork [2/3] Do not rewrite out of SSA scalar dependences crossing the limits of the scop.

login
register
mail settings
Submitter Sebastian Pop
Date Nov. 22, 2010, 11:18 p.m.
Message ID <1290467900-14995-2-git-send-email-sebpop@gmail.com>
Download mbox | patch
Permalink /patch/72612/
State New
Headers show

Comments

Sebastian Pop - Nov. 22, 2010, 11:18 p.m.
Committed to the graphite branch.

2010-11-22  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite-sese-to-poly.c (handle_scalar_deps_crossing_scop_limits):
	New.
	(rewrite_cross_bb_scalar_deps): Pass in the scop.  Call
	handle_scalar_deps_crossing_scop_limits.
	(rewrite_cross_bb_scalar_deps_out_of_ssa): Create an empty BB
	after the scop.  Update call to rewrite_cross_bb_scalar_deps.
---
 gcc/ChangeLog.graphite      |    9 +++++++
 gcc/graphite-sese-to-poly.c |   54 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 2 deletions(-)

Patch

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index e5df72e..5ccbc63 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,14 @@ 
 2010-11-22  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-sese-to-poly.c (handle_scalar_deps_crossing_scop_limits):
+	New.
+	(rewrite_cross_bb_scalar_deps): Pass in the scop.  Call
+	handle_scalar_deps_crossing_scop_limits.
+	(rewrite_cross_bb_scalar_deps_out_of_ssa): Create an empty BB
+	after the scop.  Update call to rewrite_cross_bb_scalar_deps.
+
+2010-11-22  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* sese.c (rename_uses): Call recompute_tree_invariant_for_addr_expr
 	when replacing a constant in an ADDR_EXPR.
 
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 77930d5..eec46dc 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2426,13 +2426,57 @@  rewrite_cross_bb_scalar_dependence (tree zero_dim_array, tree def, gimple use_st
   update_stmt (use_stmt);
 }
 
+/* For every definition DEF in the SCOP that is used outside the scop,
+   insert a closing-scop definition in the basic block just after this
+   SCOP.  */
+
+static void
+handle_scalar_deps_crossing_scop_limits (scop_p scop, tree def, gimple stmt)
+{
+  tree var = create_tmp_reg (TREE_TYPE (def), NULL);
+  tree new_name = make_ssa_name (var, stmt);
+  bool needs_copy = false;
+  use_operand_p use_p;
+  imm_use_iterator imm_iter;
+  gimple use_stmt;
+  sese region = SCOP_REGION (scop);
+
+  FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
+    {
+      if (!bb_in_sese_p (gimple_bb (use_stmt), region))
+	{
+	  FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+	    {
+	      SET_USE (use_p, new_name);
+	    }
+	  update_stmt (use_stmt);
+	  needs_copy = true;
+	}
+    }
+
+  /* Insert in the empty BB just after the scop a use of DEF such
+     that the rewrite of cross_bb_scalar_dependences won't insert
+     arrays everywhere else.  */
+  if (needs_copy)
+    {
+      gimple assign = gimple_build_assign (new_name, def);
+      gimple_stmt_iterator psi = gsi_after_labels (SESE_EXIT (region)->dest);
+
+      add_referenced_var (var);
+      SSA_NAME_DEF_STMT (new_name) = assign;
+      update_stmt (assign);
+      gsi_insert_before (&psi, assign, GSI_SAME_STMT);
+    }
+}
+
 /* Rewrite the scalar dependences crossing the boundary of the BB
    containing STMT with an array.  Return true when something has been
    changed.  */
 
 static bool
-rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi)
+rewrite_cross_bb_scalar_deps (scop_p scop, gimple_stmt_iterator *gsi)
 {
+  sese region = SCOP_REGION (scop);
   gimple stmt = gsi_stmt (*gsi);
   imm_use_iterator imm_iter;
   tree def;
@@ -2473,6 +2517,8 @@  rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi)
 
   def_bb = gimple_bb (stmt);
 
+  handle_scalar_deps_crossing_scop_limits (scop, def, stmt);
+
   FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
     if (gimple_code (use_stmt) == GIMPLE_PHI
 	&& (res = true))
@@ -2512,14 +2558,18 @@  void
 rewrite_cross_bb_scalar_deps_out_of_ssa (scop_p scop)
 {
   basic_block bb;
+  basic_block exit;
   gimple_stmt_iterator psi;
   sese region = SCOP_REGION (scop);
   bool changed = false;
 
+  /* Create an extra empty BB after the scop.  */
+  exit = split_edge (SESE_EXIT (region));
+
   FOR_EACH_BB (bb)
     if (bb_in_sese_p (bb, region))
       for (psi = gsi_start_bb (bb); !gsi_end_p (psi); gsi_next (&psi))
-	changed |= rewrite_cross_bb_scalar_deps (region, &psi);
+	changed |= rewrite_cross_bb_scalar_deps (scop, &psi);
 
   if (changed)
     {