diff gcc/graphite-clast-to-gimple.c @ 14:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children
line wrap: on
line diff
--- a/gcc/graphite-clast-to-gimple.c	Tue May 25 18:58:51 2010 +0900
+++ b/gcc/graphite-clast-to-gimple.c	Tue Mar 22 17:18:12 2011 +0900
@@ -21,37 +21,24 @@
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "ggc.h"
-#include "tree.h"
-#include "rtl.h"
-#include "basic-block.h"
-#include "diagnostic.h"
+#include "diagnostic-core.h"
 #include "tree-flow.h"
-#include "toplev.h"
 #include "tree-dump.h"
-#include "timevar.h"
 #include "cfgloop.h"
 #include "tree-chrec.h"
 #include "tree-data-ref.h"
 #include "tree-scalar-evolution.h"
-#include "tree-pass.h"
-#include "domwalk.h"
-#include "value-prof.h"
-#include "pointer-set.h"
-#include "gimple.h"
-#include "langhooks.h"
 #include "sese.h"
 
 #ifdef HAVE_cloog
 #include "cloog/cloog.h"
 #include "ppl_c.h"
+#include "graphite-cloog-util.h"
 #include "graphite-ppl.h"
-#include "graphite.h"
 #include "graphite-poly.h"
-#include "graphite-scop-detection.h"
 #include "graphite-clast-to-gimple.h"
 #include "graphite-dependences.h"
+#include "graphite-cloog-compat.h"
 
 /* This flag is set when an error occurred during the translation of
    CLAST to Gimple.  */
@@ -65,7 +52,6 @@
 #ifdef ENABLE_CHECKING
   verify_loop_structure ();
   verify_dominators (CDI_DOMINATORS);
-  verify_dominators (CDI_POST_DOMINATORS);
   verify_loop_closed_ssa (true);
 #endif
 }
@@ -95,12 +81,18 @@
    SCATTERING_DIMENSIONS vector.  */
 
 static inline int
-clast_name_to_index (const char *name, htab_t index_table)
+clast_name_to_index (clast_name_p name, htab_t index_table)
 {
   struct clast_name_index tmp;
   PTR *slot;
 
+#ifdef CLOOG_ORG
+  gcc_assert (name->type == clast_expr_name);
+  tmp.name = ((const struct clast_name*) name)->name;
+#else
   tmp.name = name;
+#endif
+
   slot = htab_find_slot (index_table, &tmp, NO_INSERT);
 
   if (slot && *slot)
@@ -129,32 +121,6 @@
     }
 }
 
-/* Print to stderr the element ELT.  */
-
-static inline void
-debug_clast_name_index (clast_name_index_p elt)
-{
-  fprintf (stderr, "(index = %d, name = %s)\n", elt->index, elt->name);
-}
-
-/* Helper function for debug_rename_map.  */
-
-static inline int
-debug_clast_name_indexes_1 (void **slot, void *s ATTRIBUTE_UNUSED)
-{
-  struct clast_name_index *entry = (struct clast_name_index *) *slot;
-  debug_clast_name_index (entry);
-  return 1;
-}
-
-/* Print to stderr all the elements of MAP.  */
-
-void
-debug_clast_name_indexes (htab_t map)
-{
-  htab_traverse (map, debug_clast_name_indexes_1, NULL);
-}
-
 /* Computes a hash function for database element ELT.  */
 
 static inline hashval_t
@@ -174,20 +140,6 @@
   return (elt1->name == elt2->name);
 }
 
-
-/* For a given loop DEPTH in the loop nest of the original black box
-   PBB, return the old induction variable associated to that loop.  */
-
-static inline tree
-pbb_to_depth_to_oldiv (poly_bb_p pbb, int depth)
-{
-  gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
-  sese region = SCOP_REGION (PBB_SCOP (pbb));
-  loop_p loop = gbb_loop_at_index (gbb, region, depth);
-
-  return loop->single_iv;
-}
-
 /* For a given scattering dimension, return the new induction variable
    associated to it.  */
 
@@ -203,7 +155,7 @@
    Cloog representation.  */
 
 static tree
-clast_name_to_gcc (const char *name, sese region, VEC (tree, heap) *newivs,
+clast_name_to_gcc (clast_name_p name, sese region, VEC (tree, heap) *newivs,
 		   htab_t newivs_index, htab_t params_index)
 {
   int index;
@@ -233,19 +185,29 @@
   int p2 = TYPE_PRECISION (type2);
   int precision;
   tree type;
+  enum machine_mode mode;
 
   if (p1 > p2)
     precision = TYPE_UNSIGNED (type1) ? p1 * 2 : p1;
   else
     precision = TYPE_UNSIGNED (type2) ? p2 * 2 : p2;
 
-  type = lang_hooks.types.type_for_size (precision, false);
+  if (precision > BITS_PER_WORD)
+    {
+      gloog_error = true;
+      return integer_type_node;
+    }
+
+  mode = smallest_mode_for_size (precision, MODE_INT);
+  precision = GET_MODE_PRECISION (mode);
+  type = build_nonstandard_integer_type (precision, false);
 
   if (!type)
     {
       gloog_error = true;
       return integer_type_node;
     }
+
   return type;
 }
 
@@ -305,7 +267,7 @@
 {
   switch (e->type)
     {
-    case expr_term:
+    case clast_expr_term:
       {
 	struct clast_term *t = (struct clast_term *) e;
 
@@ -357,7 +319,7 @@
 	  return gmp_cst_to_tree (type, t->val);
       }
 
-    case expr_red:
+    case clast_expr_red:
       {
         struct clast_reduction *r = (struct clast_reduction *) e;
 
@@ -384,7 +346,7 @@
         break;
       }
 
-    case expr_bin:
+    case clast_expr_bin:
       {
 	struct clast_binary *b = (struct clast_binary *) e;
 	struct clast_expr *lhs = (struct clast_expr *) b->LHS;
@@ -426,26 +388,26 @@
   mpz_t x, y, two;
   int precision;
 
-  value_init (x);
-  value_init (y);
-  value_init (two);
-  value_set_si (x, 2);
-  value_assign (y, val);
-  value_set_si (two, 2);
+  mpz_init (x);
+  mpz_init (y);
+  mpz_init (two);
+  mpz_set_si (x, 2);
+  mpz_set (y, val);
+  mpz_set_si (two, 2);
   precision = 1;
 
-  if (value_neg_p (y))
-    value_oppose (y, y);
+  if (mpz_sgn (y) < 0)
+    mpz_neg (y, y);
 
-  while (value_gt (y, x))
+  while (mpz_cmp (y, x) >= 0)
     {
-      value_multiply (x, x, two);
+      mpz_mul (x, x, two);
       precision++;
     }
 
-  value_clear (x);
-  value_clear (y);
-  value_clear (two);
+  mpz_clear (x);
+  mpz_clear (y);
+  mpz_clear (two);
 
   return precision;
 }
@@ -459,38 +421,51 @@
   mpz_t diff;
   int precision;
 
-  gcc_assert (value_le (low, up));
+  gcc_assert (mpz_cmp (low, up) <= 0);
 
-  value_init (diff);
-  value_subtract (diff, up, low);
+  mpz_init (diff);
+  mpz_sub (diff, up, low);
   precision = precision_for_value (diff);
-  value_clear (diff);
+  mpz_clear (diff);
 
   return precision;
 }
 
-/* Return a type that could represent the integer value VAL, or
-   otherwise return NULL_TREE.  */
+/* Return a type that could represent the integer value VAL.  */
 
 static tree
-gcc_type_for_interval (mpz_t low, mpz_t up, tree old_type)
+gcc_type_for_interval (mpz_t low, mpz_t up)
 {
   bool unsigned_p = true;
   int precision, prec_up, prec_int;
   tree type;
-
-  gcc_assert (value_le (low, up));
+  enum machine_mode mode;
 
-  /* Preserve the signedness of the old IV.  */
-  if ((old_type && !TYPE_UNSIGNED (old_type))
-      || value_neg_p (low))
-    unsigned_p = false;
+  gcc_assert (mpz_cmp (low, up) <= 0);
 
   prec_up = precision_for_value (up);
   prec_int = precision_for_interval (low, up);
-  precision = prec_up > prec_int ? prec_up : prec_int;
+  precision = MAX (prec_up, prec_int);
+
+  if (precision > BITS_PER_WORD)
+    {
+      gloog_error = true;
+      return integer_type_node;
+    }
+
+  if (mpz_sgn (low) <= 0)
+    unsigned_p = false;
 
-  type = lang_hooks.types.type_for_size (precision, unsigned_p);
+  else if (precision < BITS_PER_WORD)
+    {
+      unsigned_p = false;
+      precision++;
+    }
+
+  mode = smallest_mode_for_size (precision, MODE_INT);
+  precision = GET_MODE_PRECISION (mode);
+  type = build_nonstandard_integer_type (precision, unsigned_p);
+
   if (!type)
     {
       gloog_error = true;
@@ -506,7 +481,7 @@
 static tree
 gcc_type_for_value (mpz_t val)
 {
-  return gcc_type_for_interval (val, val, NULL_TREE);
+  return gcc_type_for_interval (val, val);
 }
 
 /* Return the type for the clast_term T used in STMT.  */
@@ -516,7 +491,7 @@
 			 sese region, VEC (tree, heap) *newivs,
 			 htab_t newivs_index, htab_t params_index)
 {
-  gcc_assert (t->expr.type == expr_term);
+  gcc_assert (t->expr.type == clast_expr_term);
 
   if (!t->var)
     return gcc_type_for_value (t->val);
@@ -588,15 +563,15 @@
 {
   switch (e->type)
     {
-    case expr_term:
+    case clast_expr_term:
       return gcc_type_for_clast_term ((struct clast_term *) e, region,
 				      newivs, newivs_index, params_index);
 
-    case expr_red:
+    case clast_expr_red:
       return gcc_type_for_clast_red ((struct clast_reduction *) e, region,
 				     newivs, newivs_index, params_index);
 
-    case expr_bin:
+    case clast_expr_bin:
       return gcc_type_for_clast_bin ((struct clast_binary *) e, region,
 				     newivs, newivs_index, params_index);
 
@@ -713,27 +688,8 @@
 
   ppl_max_for_le_pointset (ps, le, up);
   ppl_min_for_le_pointset (ps, le, low);
-}
-
-/* Compute the type for the induction variable at LEVEL for the
-   statement PBB, based on the transformed schedule of PBB.  OLD_TYPE
-   is the type of the old induction variable for that loop.  */
-
-static tree
-compute_type_for_level_1 (poly_bb_p pbb, int level, tree old_type)
-{
-  mpz_t low, up;
-  tree type;
-
-  value_init (low);
-  value_init (up);
-
-  compute_bounds_for_level (pbb, level, low, up);
-  type = gcc_type_for_interval (low, up, old_type);
-
-  value_clear (low);
-  value_clear (up);
-  return type;
+  ppl_delete_Linear_Expression (le);
+  ppl_delete_Pointset_Powerset_C_Polyhedron (ps);
 }
 
 /* Compute the type for the induction variable at LEVEL for the
@@ -742,24 +698,18 @@
 static tree
 compute_type_for_level (poly_bb_p pbb, int level)
 {
-  tree oldiv = pbb_to_depth_to_oldiv (pbb, level);
-  tree type = TREE_TYPE (oldiv);
+  mpz_t low, up;
+  tree type;
 
-  if (type && POINTER_TYPE_P (type))
-    {
-#ifdef ENABLE_CHECKING
-      tree ctype = compute_type_for_level_1 (pbb, level, type);
+  mpz_init (low);
+  mpz_init (up);
 
-      /* In the case of a pointer type, check that after the loop
-	 transform, the lower and the upper bounds of the type fit the
-	 oldiv pointer type.  */
-      gcc_assert (TYPE_PRECISION (type) >= TYPE_PRECISION (ctype)
-		  && integer_zerop (lower_bound_in_type (ctype, ctype)));
-#endif
-      return type;
-    }
+  compute_bounds_for_level (pbb, level, low, up);
+  type = gcc_type_for_interval (low, up);
 
-  return compute_type_for_level_1 (pbb, level, type);
+  mpz_clear (low);
+  mpz_clear (up);
+  return type;
 }
 
 /* Walks a CLAST and returns the first statement in the body of a
@@ -839,55 +789,36 @@
   return loop;
 }
 
-/* Inserts in MAP a tuple (OLD_NAME, NEW_NAME) for the induction
-   variables of the loops around GBB in SESE.  */
+/* Inserts in iv_map a tuple (OLD_LOOP->num, NEW_NAME) for the
+   induction variables of the loops around GBB in SESE.  */
 
 static void
-build_iv_mapping (htab_t map, sese region,
+build_iv_mapping (VEC (tree, heap) *iv_map, sese region,
 		  VEC (tree, heap) *newivs, htab_t newivs_index,
 		  struct clast_user_stmt *user_stmt,
 		  htab_t params_index)
 {
   struct clast_stmt *t;
-  int index = 0;
+  int depth = 0;
   CloogStatement *cs = user_stmt->statement;
   poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (cs);
+  gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
 
-  for (t = user_stmt->substitutions; t; t = t->next, index++)
+  for (t = user_stmt->substitutions; t; t = t->next, depth++)
     {
       struct clast_expr *expr = (struct clast_expr *)
        ((struct clast_assignment *)t)->RHS;
       tree type = gcc_type_for_clast_expr (expr, region, newivs,
 					   newivs_index, params_index);
-      tree old_name = pbb_to_depth_to_oldiv (pbb, index);
-      tree e = clast_to_gcc_expression (type, expr, region, newivs,
-					newivs_index, params_index);
-      set_rename (map, old_name, e);
+      tree new_name = clast_to_gcc_expression (type, expr, region, newivs,
+					       newivs_index, params_index);
+      loop_p old_loop = gbb_loop_at_index (gbb, region, depth);
+
+      VEC_replace (tree, iv_map, old_loop->num, new_name);
     }
 }
 
-/* Helper function for htab_traverse.  */
-
-static int
-copy_renames (void **slot, void *s)
-{
-  struct rename_map_elt_s *entry = (struct rename_map_elt_s *) *slot;
-  htab_t res = (htab_t) s;
-  tree old_name = entry->old_name;
-  tree expr = entry->expr;
-  struct rename_map_elt_s tmp;
-  PTR *x;
-
-  tmp.old_name = old_name;
-  x = htab_find_slot (res, &tmp, INSERT);
-
-  if (x && !*x)
-    *x = new_rename_map_elt (old_name, expr);
-
-  return 1;
-}
-
-/* Construct bb_pbb_def with BB and PBB. */
+/* Construct bb_pbb_def with BB and PBB.  */
 
 static bb_pbb_def *
 new_bb_pbb_def (basic_block bb, poly_bb_p pbb)
@@ -970,38 +901,39 @@
   return false;
 }
 
-static edge
-translate_clast (sese, loop_p, struct clast_stmt *, edge, htab_t,
-		 VEC (tree, heap) **, htab_t, htab_t, int, htab_t);
-
 /* Translates a clast user statement STMT to gimple.
 
    - REGION is the sese region we used to generate the scop.
    - NEXT_E is the edge where new generated code should be attached.
    - CONTEXT_LOOP is the loop in which the generated code will be placed
-   - RENAME_MAP contains a set of tuples of new names associated to
-     the original variables names.
    - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
    - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
      the sese region.  */
 static edge
 translate_clast_user (sese region, struct clast_user_stmt *stmt, edge next_e,
-		      htab_t rename_map, VEC (tree, heap) **newivs,
+		      VEC (tree, heap) **newivs,
 		      htab_t newivs_index, htab_t bb_pbb_mapping,
 		      htab_t params_index)
 {
-  gimple_bb_p gbb;
+  int i, nb_loops;
   basic_block new_bb;
   poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (stmt->statement);
-  gbb = PBB_BLACK_BOX (pbb);
+  gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
+  VEC (tree, heap) *iv_map;
 
   if (GBB_BB (gbb) == ENTRY_BLOCK_PTR)
     return next_e;
 
-  build_iv_mapping (rename_map, region, *newivs, newivs_index, stmt,
-		    params_index);
+  nb_loops = number_of_loops ();
+  iv_map = VEC_alloc (tree, heap, nb_loops);
+  for (i = 0; i < nb_loops; i++)
+    VEC_quick_push (tree, iv_map, NULL_TREE);
+
+  build_iv_mapping (iv_map, region, *newivs, newivs_index, stmt, params_index);
   next_e = copy_bb_and_scalar_dependences (GBB_BB (gbb), region,
-					   next_e, rename_map);
+					   next_e, iv_map);
+  VEC_free (tree, heap, iv_map);
+
   new_bb = next_e->src;
   mark_bb_with_pbb (pbb, new_bb, bb_pbb_mapping);
   update_ssa (TODO_update_ssa);
@@ -1011,6 +943,7 @@
 
 /* Creates a new if region protecting the loop to be executed, if the execution
    count is zero (lb > ub).  */
+
 static edge
 graphite_create_new_loop_guard (sese region, edge entry_edge,
 				struct clast_for *stmt,
@@ -1028,48 +961,45 @@
 				     newivs_index, params_index);
   tree ub = clast_to_gcc_expression (type, stmt->UB, region, newivs,
 				     newivs_index, params_index);
-  tree ub_one;
-
-  /* Adding +1 and using LT_EXPR helps with loop latches that have a
-     loop iteration count of "PARAMETER - 1".  For PARAMETER == 0 this becomes
-     2^{32|64}, and the condition lb <= ub is true, even if we do not want this.
-     However lb < ub + 1 is false, as expected.  */
-  tree one;
-  mpz_t gmp_one;
-  
-  mpz_init (gmp_one);
-  mpz_set_si (gmp_one, 1);
-  one = gmp_cst_to_tree (type, gmp_one);
-  mpz_clear (gmp_one);
-
-  ub_one = fold_build2 (POINTER_TYPE_P (type) ? POINTER_PLUS_EXPR : PLUS_EXPR,
-			type, ub, one);
-
-  /* When ub + 1 wraps around, use lb <= ub.  */
-  if (integer_zerop (ub_one))
+  /* When ub is simply a constant or a parameter, use lb <= ub.  */
+  if (TREE_CODE (ub) == INTEGER_CST || TREE_CODE (ub) == SSA_NAME)
     cond_expr = fold_build2 (LE_EXPR, boolean_type_node, lb, ub);
   else
-    cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub_one);
+    {
+      tree one = (POINTER_TYPE_P (type)
+		  ? size_one_node
+		  : fold_convert (type, integer_one_node));
+      /* Adding +1 and using LT_EXPR helps with loop latches that have a
+	 loop iteration count of "PARAMETER - 1".  For PARAMETER == 0 this becomes
+	 2^k-1 due to integer overflow, and the condition lb <= ub is true,
+	 even if we do not want this.  However lb < ub + 1 is false, as
+	 expected.  */
+      tree ub_one = fold_build2 (POINTER_TYPE_P (type) ? POINTER_PLUS_EXPR
+				 : PLUS_EXPR, type, ub, one);
+
+      cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub_one);
+    }
 
   exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr);
 
   return exit_edge;
 }
 
+static edge
+translate_clast (sese, loop_p, struct clast_stmt *, edge,
+		 VEC (tree, heap) **, htab_t, htab_t, int, htab_t);
 
 /* Create the loop for a clast for statement.
 
    - REGION is the sese region we used to generate the scop.
    - NEXT_E is the edge where new generated code should be attached.
-   - RENAME_MAP contains a set of tuples of new names associated to
-     the original variables names.
    - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
    - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
      the sese region.  */
 static edge
 translate_clast_for_loop (sese region, loop_p context_loop,
 			  struct clast_for *stmt, edge next_e,
-			  htab_t rename_map, VEC (tree, heap) **newivs,
+			  VEC (tree, heap) **newivs,
 			  htab_t newivs_index, htab_t bb_pbb_mapping,
 			  int level, htab_t params_index)
 {
@@ -1085,16 +1015,12 @@
   last_e = single_succ_edge (split_edge (last_e));
 
   /* Translate the body of the loop.  */
-  next_e = translate_clast (region, loop, stmt->body, to_body, rename_map,
+  next_e = translate_clast (region, loop, stmt->body, to_body,
 			    newivs, newivs_index, bb_pbb_mapping, level + 1,
 			    params_index);
   redirect_edge_succ_nodup (next_e, after);
   set_immediate_dominator (CDI_DOMINATORS, next_e->dest, next_e->src);
 
-   /* Remove from rename_map all the tuples containing variables
-      defined in loop's body.  */
-  insert_loop_close_phis (rename_map, loop);
-
   if (flag_loop_parallelize_all
       && !dependency_in_loop_p (loop, bb_pbb_mapping,
  				get_scattering_level (level)))
@@ -1109,39 +1035,22 @@
 
    - REGION is the sese region we used to generate the scop.
    - NEXT_E is the edge where new generated code should be attached.
-   - RENAME_MAP contains a set of tuples of new names associated to
-     the original variables names.
    - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
    - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
      the sese region.  */
 static edge
 translate_clast_for (sese region, loop_p context_loop, struct clast_for *stmt,
-		     edge next_e, htab_t rename_map, VEC (tree, heap) **newivs,
+		     edge next_e, VEC (tree, heap) **newivs,
 		     htab_t newivs_index, htab_t bb_pbb_mapping, int level,
 		     htab_t params_index)
 {
   edge last_e = graphite_create_new_loop_guard (region, next_e, stmt, *newivs,
 						newivs_index, params_index);
-
   edge true_e = get_true_edge_from_guard_bb (next_e->dest);
-  edge false_e = get_false_edge_from_guard_bb (next_e->dest);
-  edge exit_true_e = single_succ_edge (true_e->dest);
-  edge exit_false_e = single_succ_edge (false_e->dest);
-
-  htab_t before_guard = htab_create (10, rename_map_elt_info,
-				     eq_rename_map_elts, free);
-  htab_traverse (rename_map, copy_renames, before_guard);
 
-  next_e = translate_clast_for_loop (region, context_loop, stmt, true_e,
-				     rename_map, newivs,
-				     newivs_index, bb_pbb_mapping, level,
-				     params_index);
-
-  insert_guard_phis (last_e->src, exit_true_e, exit_false_e,
-		     before_guard, rename_map);
-
-  htab_delete (before_guard);
-
+  translate_clast_for_loop (region, context_loop, stmt, true_e, newivs,
+			    newivs_index, bb_pbb_mapping, level,
+			    params_index);
   return last_e;
 }
 
@@ -1150,39 +1059,23 @@
    - REGION is the sese region we used to generate the scop.
    - NEXT_E is the edge where new generated code should be attached.
    - CONTEXT_LOOP is the loop in which the generated code will be placed
-   - RENAME_MAP contains a set of tuples of new names associated to
-     the original variables names.
    - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
    - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
      the sese region.  */
 static edge
 translate_clast_guard (sese region, loop_p context_loop,
 		       struct clast_guard *stmt, edge next_e,
-		       htab_t rename_map, VEC (tree, heap) **newivs,
+		       VEC (tree, heap) **newivs,
 		       htab_t newivs_index, htab_t bb_pbb_mapping, int level,
 		       htab_t params_index)
 {
   edge last_e = graphite_create_new_guard (region, next_e, stmt, *newivs,
 					   newivs_index, params_index);
-
   edge true_e = get_true_edge_from_guard_bb (next_e->dest);
-  edge false_e = get_false_edge_from_guard_bb (next_e->dest);
-  edge exit_true_e = single_succ_edge (true_e->dest);
-  edge exit_false_e = single_succ_edge (false_e->dest);
-
-  htab_t before_guard = htab_create (10, rename_map_elt_info,
-				     eq_rename_map_elts, free);
-  htab_traverse (rename_map, copy_renames, before_guard);
 
-  next_e = translate_clast (region, context_loop, stmt->then, true_e,
-			    rename_map, newivs, newivs_index, bb_pbb_mapping,
-			    level, params_index);
-
-  insert_guard_phis (last_e->src, exit_true_e, exit_false_e,
-		     before_guard, rename_map);
-
-  htab_delete (before_guard);
-
+  translate_clast (region, context_loop, stmt->then, true_e,
+		   newivs, newivs_index, bb_pbb_mapping,
+		   level, params_index);
   return last_e;
 }
 
@@ -1191,12 +1084,10 @@
 
    - NEXT_E is the edge where new generated code should be attached.
    - CONTEXT_LOOP is the loop in which the generated code will be placed
-   - RENAME_MAP contains a set of tuples of new names associated to
-     the original variables names.
    - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.  */
 static edge
 translate_clast (sese region, loop_p context_loop, struct clast_stmt *stmt,
-		 edge next_e, htab_t rename_map, VEC (tree, heap) **newivs,
+		 edge next_e, VEC (tree, heap) **newivs,
 		 htab_t newivs_index, htab_t bb_pbb_mapping, int level,
 		 htab_t params_index)
 {
@@ -1208,25 +1099,25 @@
 
   else if (CLAST_STMT_IS_A (stmt, stmt_user))
     next_e = translate_clast_user (region, (struct clast_user_stmt *) stmt,
-				   next_e, rename_map, newivs, newivs_index,
+				   next_e, newivs, newivs_index,
 				   bb_pbb_mapping, params_index);
 
   else if (CLAST_STMT_IS_A (stmt, stmt_for))
     next_e = translate_clast_for (region, context_loop,
 				  (struct clast_for *) stmt, next_e,
-				  rename_map, newivs, newivs_index,
+				  newivs, newivs_index,
 				  bb_pbb_mapping, level, params_index);
 
   else if (CLAST_STMT_IS_A (stmt, stmt_guard))
     next_e = translate_clast_guard (region, context_loop,
 				    (struct clast_guard *) stmt, next_e,
-				    rename_map, newivs, newivs_index,
+				    newivs, newivs_index,
 				    bb_pbb_mapping, level, params_index);
 
   else if (CLAST_STMT_IS_A (stmt, stmt_block))
     next_e = translate_clast (region, context_loop,
 			      ((struct clast_block *) stmt)->body,
-			      next_e, rename_map, newivs, newivs_index,
+			      next_e, newivs, newivs_index,
 			      bb_pbb_mapping, level, params_index);
   else
     gcc_unreachable();
@@ -1235,21 +1126,21 @@
   graphite_verify ();
 
   return translate_clast (region, context_loop, stmt->next, next_e,
-			  rename_map, newivs, newivs_index,
+			  newivs, newivs_index,
 			  bb_pbb_mapping, level, params_index);
 }
 
 /* Free the SCATTERING domain list.  */
 
 static void
-free_scattering (CloogDomainList *scattering)
+free_scattering (CloogScatteringList *scattering)
 {
   while (scattering)
     {
-      CloogDomain *dom = cloog_domain (scattering);
-      CloogDomainList *next = cloog_next_domain (scattering);
+      CloogScattering *dom = cloog_scattering (scattering);
+      CloogScatteringList *next = cloog_next_scattering (scattering);
 
-      cloog_domain_free (dom);
+      cloog_scattering_free (dom);
       free (scattering);
       scattering = next;
     }
@@ -1316,31 +1207,59 @@
 			      scattering);
 }
 
+/* Initialize a CLooG input file.  */
+
+static FILE *
+init_cloog_input_file (int scop_number)
+{
+  FILE *graphite_out_file;
+  int len = strlen (dump_base_name);
+  char *dumpname = XNEWVEC (char, len + 25);
+  char *s_scop_number = XNEWVEC (char, 15);
+
+  memcpy (dumpname, dump_base_name, len + 1);
+  strip_off_ending (dumpname, len);
+  sprintf (s_scop_number, ".%d", scop_number);
+  strcat (dumpname, s_scop_number);
+  strcat (dumpname, ".cloog");
+  graphite_out_file = fopen (dumpname, "w+b");
+
+  if (graphite_out_file == 0)
+    fatal_error ("can%'t open %s for writing: %m", dumpname);
+
+  free (dumpname);
+
+  return graphite_out_file;
+}
+
 /* Build cloog program for SCoP.  */
 
 static void
-build_cloog_prog (scop_p scop, CloogProgram *prog)
+build_cloog_prog (scop_p scop, CloogProgram *prog,
+                  CloogOptions *options)
 {
   int i;
   int max_nb_loops = scop_max_loop_depth (scop);
   poly_bb_p pbb;
   CloogLoop *loop_list = NULL;
   CloogBlockList *block_list = NULL;
-  CloogDomainList *scattering = NULL;
+  CloogScatteringList *scattering = NULL;
   int nbs = 2 * max_nb_loops + 1;
   int *scaldims;
 
   cloog_program_set_context
-    (prog, new_Cloog_Domain_from_ppl_Pointset_Powerset (SCOP_CONTEXT (scop)));
+    (prog, new_Cloog_Domain_from_ppl_Pointset_Powerset (SCOP_CONTEXT (scop),
+      scop_nb_params (scop), cloog_state));
   nbs = unify_scattering_dimensions (scop);
   scaldims = (int *) xmalloc (nbs * (sizeof (int)));
   cloog_program_set_nb_scattdims (prog, nbs);
   initialize_cloog_names (scop, prog);
 
-  for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
+  FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
     {
       CloogStatement *stmt;
       CloogBlock *block;
+      CloogDomain *dom;
 
       /* Dead code elimination: when the domain of a PBB is empty,
 	 don't generate code for the PBB.  */
@@ -1348,17 +1267,18 @@
 	continue;
 
       /* Build the new statement and its block.  */
-      stmt = cloog_statement_alloc (pbb_index (pbb));
+      stmt = cloog_statement_alloc (cloog_state, pbb_index (pbb));
+      dom = new_Cloog_Domain_from_ppl_Pointset_Powerset (PBB_DOMAIN (pbb),
+                                                         scop_nb_params (scop),
+                                                         cloog_state);
       block = cloog_block_alloc (stmt, 0, NULL, pbb_dim_iter_domain (pbb));
       cloog_statement_set_usr (stmt, pbb);
 
       /* Build loop list.  */
       {
-        CloogLoop *new_loop_list = cloog_loop_malloc ();
+        CloogLoop *new_loop_list = cloog_loop_malloc (cloog_state);
         cloog_loop_set_next (new_loop_list, loop_list);
-        cloog_loop_set_domain
-	  (new_loop_list,
-	   new_Cloog_Domain_from_ppl_Pointset_Powerset (PBB_DOMAIN (pbb)));
+        cloog_loop_set_domain (new_loop_list, dom);
         cloog_loop_set_block (new_loop_list, block);
         loop_list = new_loop_list;
       }
@@ -1375,16 +1295,18 @@
       /* Build scattering list.  */
       {
         /* XXX: Replace with cloog_domain_list_alloc(), when available.  */
-        CloogDomainList *new_scattering
-	  = (CloogDomainList *) xmalloc (sizeof (CloogDomainList));
+        CloogScatteringList *new_scattering
+	  = (CloogScatteringList *) xmalloc (sizeof (CloogScatteringList));
         ppl_Polyhedron_t scat;
-	CloogDomain *dom;
+	CloogScattering *dom;
 
 	scat = PBB_TRANSFORMED_SCATTERING (pbb);
-	dom = new_Cloog_Domain_from_ppl_Polyhedron (scat);
+        dom = new_Cloog_Scattering_from_ppl_Polyhedron
+          (scat, scop_nb_params (scop), pbb_nb_scattering_transform (pbb),
+           cloog_state);
 
-        cloog_set_next_domain (new_scattering, scattering);
-        cloog_set_domain (new_scattering, dom);
+        cloog_set_next_scattering (new_scattering, scattering);
+        cloog_set_scattering (new_scattering, dom);
         scattering = new_scattering;
       }
     }
@@ -1398,10 +1320,21 @@
   cloog_program_set_scaldims (prog, scaldims);
 
   /* Extract scalar dimensions to simplify the code generation problem.  */
-  cloog_program_extract_scalars (prog, scattering);
+  cloog_program_extract_scalars (prog, scattering, options);
+
+  /* Dump a .cloog input file, if requested.  This feature is only
+     enabled in the Graphite branch.  */
+  if (0)
+    {
+      static size_t file_scop_number = 0;
+      FILE *cloog_file = init_cloog_input_file (file_scop_number);
+
+      cloog_program_dump_cloog (cloog_file, prog, scattering);
+      ++file_scop_number;
+    }
 
   /* Apply scattering.  */
-  cloog_program_scatter (prog, scattering);
+  cloog_program_scatter (prog, scattering, options);
   free_scattering (scattering);
 
   /* Iterators corresponding to scalar dimensions have to be extracted.  */
@@ -1429,7 +1362,7 @@
 static CloogOptions *
 set_cloog_options (void)
 {
-  CloogOptions *options = cloog_options_malloc ();
+  CloogOptions *options = cloog_options_malloc (cloog_state);
 
   /* Change cloog output language to C.  If we do use FORTRAN instead, cloog
      will stop e.g. with "ERROR: unbounded loops not allowed in FORTRAN.", if
@@ -1442,9 +1375,14 @@
      GLooG.  */
   options->esp = 1;
 
+#ifdef CLOOG_ORG
+  /* Silence CLooG to avoid failing tests due to debug output to stderr.  */
+  options->quiet = 1;
+#else
   /* Enable C pretty-printing mode: normalizes the substitution
      equations for statements.  */
   options->cpp = 1;
+#endif
 
   /* Allow cloog to build strides with a stride width different to one.
      This example has stride = 4:
@@ -1475,13 +1413,13 @@
 {
   CloogOptions *options = set_cloog_options ();
 
-  pprint (file, stmt, 0, options);
+  clast_pprint (file, stmt, 0, options);
   cloog_options_free (options);
 }
 
 /* Prints STMT to STDERR.  */
 
-void
+DEBUG_FUNCTION void
 debug_clast_stmt (struct clast_stmt *stmt)
 {
   print_clast_stmt (stderr, stmt);
@@ -1499,7 +1437,7 @@
 
   /* Connect new cloog prog generation to graphite.  */
   pc.prog = cloog_program_malloc ();
-  build_cloog_prog (scop, pc.prog);
+  build_cloog_prog (scop, pc.prog, options);
   pc.prog = cloog_program_generate (pc.prog, options);
   pc.stmt = cloog_clast_create (pc.prog, options);
 
@@ -1513,6 +1451,7 @@
 print_generated_program (FILE *file, scop_p scop)
 {
   CloogOptions *options = set_cloog_options ();
+
   cloog_prog_clast pc = scop_to_clast (scop);
 
   fprintf (file, "       (prog: \n");
@@ -1520,7 +1459,7 @@
   fprintf (file, "       )\n");
 
   fprintf (file, "       (clast: \n");
-  pprint (file, pc.stmt, 0, options);
+  clast_pprint (file, pc.stmt, 0, options);
   fprintf (file, "       )\n");
 
   cloog_options_free (options);
@@ -1530,7 +1469,7 @@
 
 /* Prints to STDERR the code generated by CLooG for SCOP.  */
 
-void
+DEBUG_FUNCTION void
 debug_generated_program (scop_p scop)
 {
   print_generated_program (stderr, scop);
@@ -1556,15 +1495,14 @@
 */
 
 bool
-gloog (scop_p scop, VEC (scop_p, heap) *scops, htab_t bb_pbb_mapping)
+gloog (scop_p scop, htab_t bb_pbb_mapping)
 {
   VEC (tree, heap) *newivs = VEC_alloc (tree, heap, 10);
   loop_p context_loop;
   sese region = SCOP_REGION (scop);
   ifsese if_region = NULL;
-  htab_t rename_map, newivs_index, params_index;
+  htab_t newivs_index, params_index;
   cloog_prog_clast pc;
-  int i;
 
   timevar_push (TV_GRAPHITE_CODE_GEN);
   gloog_error = false;
@@ -1590,7 +1528,6 @@
   graphite_verify ();
 
   context_loop = SESE_ENTRY (region)->src->loop_father;
-  rename_map = htab_create (10, rename_map_elt_info, eq_rename_map_elts, free);
   newivs_index = htab_create (10, clast_name_index_elt_info,
 			      eq_clast_name_indexes, free);
   params_index = htab_create (10, clast_name_index_elt_info,
@@ -1600,19 +1537,10 @@
 
   translate_clast (region, context_loop, pc.stmt,
 		   if_region->true_region->entry,
-		   rename_map, &newivs, newivs_index,
+		   &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);
-
-  for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++)
-    rename_sese_parameters (rename_map, SCOP_REGION (scop));
-
+  scev_reset ();
   recompute_all_dominators ();
   graphite_verify ();
 
@@ -1623,7 +1551,6 @@
   free (if_region->region);
   free (if_region);
 
-  htab_delete (rename_map);
   htab_delete (newivs_index);
   htab_delete (params_index);
   VEC_free (tree, heap, newivs);
@@ -1647,5 +1574,4 @@
 
   return !gloog_error;
 }
-
 #endif