diff mbox

[graphite] Remove sese_adjust_liveout_phis

Message ID AANLkTink94yQ-xUGo7bVKd0Tsw_QmPmE--3J82GLkSPV@mail.gmail.com
State New
Headers show

Commit Message

Sebastian Pop June 12, 2010, 7:53 a.m. UTC
Hi,

with the attached patches we no longer need to use the rename_map to
substitute the arguments of the phi nodes created after the code
generated by Graphite.  I committed these patches to the graphite
branch, and I will commit them to trunk once they pass the usual
graphite branch tests.

The aim is to replace the rename_map with the map that CLooG exposes
for each user statement: associating to a loop level an expression.
The expand_* functions will be replaced by the code generation from a
chrec that is obtained from the original scev by chrec_applying the
loop level -> expression map on each varying loop.  This will then
allow us to remove the call to the IV canonicalization from Graphite.

Sebastian
diff mbox

Patch

From e1e77ccc827024af17e5afc9baf5d8f044815052 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Fri, 11 Jun 2010 19:58:39 -0500
Subject: [PATCH 4/4] Also rewrite out of SSA scalar dependences going outside the SCoP region.

2010-06-12  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite-clast-to-gimple.c (gloog): Remove call to
	sese_adjust_liveout_phis.
	* graphite-sese-to-poly.c (scev_analyzable_p): When scev returns an
	SSA_NAME, allow it to be handled by rewrite_cross_bb_scalar_deps.
	(rewrite_cross_bb_scalar_deps): Handle GIMPLE_PHI nodes: call
	rewrite_phi_out_of_ssa.
	* sese.c (get_vdef_before_sese): Removed.
	(sese_adjust_vphi): Removed.
	(sese_adjust_liveout_phis): Removed.
	* sese.h (sese_adjust_liveout_phis): Removed.
---
 gcc/ChangeLog.graphite         |   13 +++
 gcc/graphite-clast-to-gimple.c |    4 -
 gcc/graphite-sese-to-poly.c    |   13 ++-
 gcc/sese.c                     |  159 ----------------------------------------
 gcc/sese.h                     |    1 -
 5 files changed, 22 insertions(+), 168 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index 888a77d..d703048 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,18 @@ 
 2010-06-12  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-clast-to-gimple.c (gloog): Remove call to
+	sese_adjust_liveout_phis.
+	* graphite-sese-to-poly.c (scev_analyzable_p): When scev returns an
+	SSA_NAME, allow it to be handled by rewrite_cross_bb_scalar_deps.
+	(rewrite_cross_bb_scalar_deps): Handle GIMPLE_PHI nodes: call
+	rewrite_phi_out_of_ssa.
+	* sese.c (get_vdef_before_sese): Removed.
+	(sese_adjust_vphi): Removed.
+	(sese_adjust_liveout_phis): Removed.
+	* sese.h (sese_adjust_liveout_phis): Removed.
+
+2010-06-12  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* graphite-sese-to-poly.c (insert_out_of_ssa_copy): Pass an extra
 	argument for the place after which to insert the out of SSA copy.
 	(rewrite_close_phi_out_of_ssa): Update calls to insert_out_of_ssa_copy.
diff --git a/gcc/graphite-clast-to-gimple.c b/gcc/graphite-clast-to-gimple.c
index a363f5d..01adba0 100644
--- a/gcc/graphite-clast-to-gimple.c
+++ b/gcc/graphite-clast-to-gimple.c
@@ -1578,10 +1578,6 @@  gloog (scop_p scop, VEC (scop_p, heap) *scops, htab_t bb_pbb_mapping)
 		   rename_map, &newivs, newivs_index,
 		   bb_pbb_mapping, 1, params_index);
   graphite_verify ();
-  sese_adjust_liveout_phis (region, rename_map,
-			    if_region->region->exit->src,
-			    if_region->false_region->exit,
-			    if_region->true_region->exit);
   scev_reset_htab ();
   rename_nb_iterations (rename_map);
 
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 7bb7bb8..57967e5 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2325,7 +2325,8 @@  scev_analyzable_p (tree def, sese region)
   loop_p loop = loop_containing_stmt (stmt);
   tree scev = scalar_evolution_in_region (region, loop, def);
 
-  return !chrec_contains_undetermined (scev);
+  return !chrec_contains_undetermined (scev)
+    && TREE_CODE (scev) != SSA_NAME;
 }
 
 /* Rewrite the scalar dependence of DEF used in USE_STMT with a memory
@@ -2379,9 +2380,13 @@  rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi)
   def_bb = gimple_bb (stmt);
 
   FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
-    if (def_bb != gimple_bb (use_stmt)
-	&& gimple_code (use_stmt) != GIMPLE_PHI
-	&& !is_gimple_debug (use_stmt))
+    if (gimple_code (use_stmt) == GIMPLE_PHI)
+      {
+	gimple_stmt_iterator si = gsi_for_stmt (use_stmt);
+	rewrite_phi_out_of_ssa (&si);
+      }
+    else if (def_bb != gimple_bb (use_stmt)
+	     && !is_gimple_debug (use_stmt))
       {
 	if (!zero_dim_array)
 	  {
diff --git a/gcc/sese.c b/gcc/sese.c
index 7e9bd91..051599e 100644
--- a/gcc/sese.c
+++ b/gcc/sese.c
@@ -394,100 +394,6 @@  sese_insert_phis_for_liveouts (sese region, basic_block bb,
   update_ssa (TODO_update_ssa);
 }
 
-/* Get the definition of NAME before the SESE.  Keep track of the
-   basic blocks that have been VISITED in a bitmap.  */
-
-static tree
-get_vdef_before_sese (sese region, tree name, sbitmap visited)
-{
-  unsigned i;
-  gimple stmt = SSA_NAME_DEF_STMT (name);
-  basic_block def_bb = gimple_bb (stmt);
-
-  if (!def_bb || !bb_in_sese_p (def_bb, region))
-    return name;
-
-  if (TEST_BIT (visited, def_bb->index))
-    return NULL_TREE;
-
-  SET_BIT (visited, def_bb->index);
-
-  switch (gimple_code (stmt))
-    {
-    case GIMPLE_PHI:
-      for (i = 0; i < gimple_phi_num_args (stmt); i++)
-	{
-	  tree arg = gimple_phi_arg_def (stmt, i);
-	  tree res;
-
-	  if (gimple_bb (SSA_NAME_DEF_STMT (arg))
-	      && def_bb->index == gimple_bb (SSA_NAME_DEF_STMT (arg))->index)
-	    continue;
-
-	  res = get_vdef_before_sese (region, arg, visited);
-	  if (res)
-	    return res;
-	}
-      return NULL_TREE;
-
-    case GIMPLE_ASSIGN:
-    case GIMPLE_CALL:
-      {
-	use_operand_p use_p = gimple_vuse_op (stmt);
-	tree use = USE_FROM_PTR (use_p);
-
-	if (def_bb->index == gimple_bb (SSA_NAME_DEF_STMT (use))->index)
-	  RESET_BIT (visited, def_bb->index);
-
-	return get_vdef_before_sese (region, use, visited);
-      }
-
-    default:
-      return NULL_TREE;
-    }
-}
-
-/* Adjust a virtual phi node PHI that is placed at the end of the
-   generated code for SCOP:
-
-   | if (1)
-   |   generated code from REGION;
-   | else
-   |   REGION;
-
-   The FALSE_E edge comes from the original code, TRUE_E edge comes
-   from the code generated for the SCOP.  */
-
-static void
-sese_adjust_vphi (sese region, gimple phi, edge true_e)
-{
-  unsigned i;
-
-  gcc_assert (gimple_phi_num_args (phi) == 2);
-
-  for (i = 0; i < gimple_phi_num_args (phi); i++)
-    if (gimple_phi_arg_edge (phi, i) == true_e)
-      {
-	tree true_arg, false_arg, before_scop_arg;
-	sbitmap visited;
-
-	true_arg = gimple_phi_arg_def (phi, i);
-	if (!SSA_NAME_IS_DEFAULT_DEF (true_arg))
-	  return;
-
-	false_arg = gimple_phi_arg_def (phi, i == 0 ? 1 : 0);
-	if (SSA_NAME_IS_DEFAULT_DEF (false_arg))
-	  return;
-
-	visited = sbitmap_alloc (last_basic_block);
-	sbitmap_zero (visited);
-	before_scop_arg = get_vdef_before_sese (region, false_arg, visited);
-	gcc_assert (before_scop_arg != NULL_TREE);
-	SET_PHI_ARG_DEF (phi, i, before_scop_arg);
-	sbitmap_free (visited);
-      }
-}
-
 /* Returns the expression associated to OLD_NAME in MAP.  */
 
 static tree
@@ -585,71 +491,6 @@  rename_sese_parameters (htab_t rename_map, sese region)
 		 rename_variables_in_expr (rename_map, p));
 }
 
-/* Adjusts the phi nodes in the block BB for variables defined in
-   SCOP_REGION and used outside the SCOP_REGION.  The code generation
-   moves SCOP_REGION in the else clause of an "if (1)" and generates
-   code in the then clause:
-
-   | if (1)
-   |   generated code from REGION;
-   | else
-   |   REGION;
-
-   To adjust the phi nodes after the condition, the RENAME_MAP is
-   used.  */
-
-void
-sese_adjust_liveout_phis (sese region, htab_t rename_map, basic_block bb,
-			  edge false_e, edge true_e)
-{
-  gimple_stmt_iterator si;
-
-  for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
-    {
-      unsigned i;
-      unsigned false_i = 0;
-      gimple phi = gsi_stmt (si);
-      tree res = gimple_phi_result (phi);
-
-      if (!is_gimple_reg (res))
-	{
-	  sese_adjust_vphi (region, phi, true_e);
-	  continue;
-	}
-
-      for (i = 0; i < gimple_phi_num_args (phi); i++)
-	if (gimple_phi_arg_edge (phi, i) == false_e)
-	  {
-	    false_i = i;
-	    break;
-	  }
-
-      for (i = 0; i < gimple_phi_num_args (phi); i++)
-	if (gimple_phi_arg_edge (phi, i) == true_e)
-	  {
-	    tree old_name = gimple_phi_arg_def (phi, false_i);
-	    tree expr = get_rename (rename_map, old_name);
-	    gimple_seq stmts;
-
-	    gcc_assert (old_name != expr);
-
-	    if (TREE_CODE (expr) != SSA_NAME
-		&& is_gimple_reg (old_name))
-	      {
-		tree type = TREE_TYPE (old_name);
-		tree var = create_tmp_var (type, "var");
-
-		expr = build2 (MODIFY_EXPR, type, var, expr);
-		expr = force_gimple_operand (expr, &stmts, true, NULL);
-		gsi_insert_seq_on_edge_immediate (true_e, stmts);
-	      }
-
-	    SET_PHI_ARG_DEF (phi, i, expr);
-	    set_rename (rename_map, old_name, res);
-	  }
-    }
-}
-
 /* Rename the SSA_NAMEs used in STMT and that appear in MAP.  */
 
 static void
diff --git a/gcc/sese.h b/gcc/sese.h
index 2b05ca8..4b2e5c2 100644
--- a/gcc/sese.h
+++ b/gcc/sese.h
@@ -55,7 +55,6 @@  typedef struct sese_s
 extern sese new_sese (edge, edge);
 extern void free_sese (sese);
 extern void sese_insert_phis_for_liveouts (sese, basic_block, edge, edge);
-extern void sese_adjust_liveout_phis (sese, htab_t, basic_block, edge, edge);
 extern void build_sese_loop_nests (sese);
 extern edge copy_bb_and_scalar_dependences (basic_block, sese, edge, htab_t);
 extern struct loop *outermost_loop_in_sese (sese, basic_block);
-- 
1.7.0.4