OSDN Git Service

* ada/gcc-interface/Make-lang.in, alias.c, attribs.c, auto-inc-dec.c,
[pf3gnuchains/gcc-fork.git] / gcc / graphite-poly.c
index 659839d..86ef485 100644 (file)
@@ -1,5 +1,5 @@
 /* Graphite polyhedral representation.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
    Contributed by Sebastian Pop <sebastian.pop@amd.com> and
    Tobias Grosser <grosser@fim.uni-passau.de>.
 
@@ -135,102 +135,145 @@ unify_scattering_dimensions (scop_p scop)
   return max_scattering;
 }
 
-/* Prints to FILE the scattering function of PBB.  */
+/* Prints to FILE the scattering function of PBB, at some VERBOSITY
+   level.  */
 
-void
-print_scattering_function (FILE *file, poly_bb_p pbb)
+static void
+print_scattering_function_1 (FILE *file, poly_bb_p pbb, int verbosity)
 {
   graphite_dim_t i;
 
-  if (!PBB_TRANSFORMED (pbb))
-    return;
+  if (verbosity > 0)
+    {
+      fprintf (file, "# scattering bb_%d (\n", pbb_index (pbb));
+      fprintf (file, "#  eq");
 
-  fprintf (file, "scattering bb_%d (\n", pbb_index (pbb));
-  fprintf (file, "#  eq");
+      for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
+       fprintf (file, "     s%d", (int) i);
 
-  for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
-    fprintf (file, "     s%d", (int) i);
+      for (i = 0; i < pbb_nb_local_vars (pbb); i++)
+       fprintf (file, "    lv%d", (int) i);
 
-  for (i = 0; i < pbb_nb_local_vars (pbb); i++)
-    fprintf (file, "    lv%d", (int) i);
+      for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
+       fprintf (file, "     i%d", (int) i);
 
-  for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
-    fprintf (file, "     i%d", (int) i);
+      for (i = 0; i < pbb_nb_params (pbb); i++)
+       fprintf (file, "     p%d", (int) i);
 
-  for (i = 0; i < pbb_nb_params (pbb); i++)
-    fprintf (file, "     p%d", (int) i);
+      fprintf (file, "    cst\n");
+    }
 
-  fprintf (file, "    cst\n");
+  /* Number of disjunct components.  Remove this when
+     PBB_TRANSFORMED_SCATTERING will be a pointset_powerset.  */
+  fprintf (file, "1\n");
+  ppl_print_polyhedron_matrix (file, PBB_TRANSFORMED_SCATTERING (pbb)
+                              ? PBB_TRANSFORMED_SCATTERING (pbb)
+                              : PBB_ORIGINAL_SCATTERING (pbb));
+
+  if (verbosity > 0)
+    fprintf (file, "#)\n");
+}
+
+/* Prints to FILE the scattering function of PBB, at some VERBOSITY
+   level.  */
+
+void
+print_scattering_function (FILE *file, poly_bb_p pbb, int verbosity)
+{
+  if (!PBB_TRANSFORMED (pbb))
+    return;
+
+  if (PBB_TRANSFORMED_SCATTERING (pbb)
+      || PBB_ORIGINAL_SCATTERING (pbb))
+    {
+      if (verbosity > 0)
+       fprintf (file, "# Scattering function is provided\n");
+
+      fprintf (file, "1\n");
+    }
+  else
+    {
+      if (verbosity > 0)
+       fprintf (file, "# Scattering function is not provided\n");
 
-  ppl_print_polyhedron_matrix (file, PBB_TRANSFORMED_SCATTERING (pbb));
+      fprintf (file, "0\n");
+      return;
+    }
 
-  fprintf (file, ")\n");
+  print_scattering_function_1 (file, pbb, verbosity);
 }
 
-/* Prints to FILE the iteration domain of PBB.  */
+/* Prints to FILE the iteration domain of PBB, at some VERBOSITY
+   level.  */
 
 void
-print_iteration_domain (FILE *file, poly_bb_p pbb)
+print_iteration_domain (FILE *file, poly_bb_p pbb, int verbosity)
 {
-  print_pbb_domain (file, pbb);
+  print_pbb_domain (file, pbb, verbosity);
 }
 
 /* Prints to FILE the scattering functions of every PBB of SCOP.  */
 
 void
-print_scattering_functions (FILE *file, scop_p scop)
+print_scattering_functions (FILE *file, scop_p scop, int verbosity)
 {
   int i;
   poly_bb_p pbb;
 
   for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
-    print_scattering_function (file, pbb);
+    print_scattering_function (file, pbb, verbosity);
 }
 
-/* Prints to FILE the iteration domains of every PBB of SCOP.  */
+/* Prints to FILE the iteration domains of every PBB of SCOP, at some
+   VERBOSITY level.  */
 
 void
-print_iteration_domains (FILE *file, scop_p scop)
+print_iteration_domains (FILE *file, scop_p scop, int verbosity)
 {
   int i;
   poly_bb_p pbb;
 
   for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
-    print_iteration_domain (file, pbb);
+    print_iteration_domain (file, pbb, verbosity);
 }
 
-/* Prints to STDERR the scattering function of PBB.  */
+/* Prints to STDERR the scattering function of PBB, at some VERBOSITY
+   level.  */
 
 void
-debug_scattering_function (poly_bb_p pbb)
+debug_scattering_function (poly_bb_p pbb, int verbosity)
 {
-  print_scattering_function (stderr, pbb);
+  print_scattering_function (stderr, pbb, verbosity);
 }
 
-/* Prints to STDERR the iteration domain of PBB.  */
+/* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
+   level.  */
 
 void
-debug_iteration_domain (poly_bb_p pbb)
+debug_iteration_domain (poly_bb_p pbb, int verbosity)
 {
-  print_iteration_domain (stderr, pbb);
+  print_iteration_domain (stderr, pbb, verbosity);
 }
 
-/* Prints to STDERR the scattering functions of every PBB of SCOP.  */
+/* Prints to STDERR the scattering functions of every PBB of SCOP, at
+   some VERBOSITY level.  */
 
 void
-debug_scattering_functions (scop_p scop)
+debug_scattering_functions (scop_p scop, int verbosity)
 {
-  print_scattering_functions (stderr, scop);
+  print_scattering_functions (stderr, scop, verbosity);
 }
 
-/* Prints to STDERR the iteration domains of every PBB of SCOP.  */
+/* Prints to STDERR the iteration domains of every PBB of SCOP, at
+   some VERBOSITY level.  */
 
 void
-debug_iteration_domains (scop_p scop)
+debug_iteration_domains (scop_p scop, int verbosity)
 {
-  print_iteration_domains (stderr, scop);
+  print_iteration_domains (stderr, scop, verbosity);
 }
 
+
 /* Apply graphite transformations to all the basic blocks of SCOP.  */
 
 bool
@@ -250,10 +293,7 @@ apply_poly_transforms (scop_p scop)
     transform_done = true;
 
   if (flag_loop_block)
-    {
-      transform_done |= scop_do_strip_mine (scop);
-      transform_done |= scop_do_interchange (scop);
-    }
+    transform_done |= scop_do_block (scop);
   else
     {
       if (flag_loop_strip_mine)
@@ -305,6 +345,9 @@ pbb_remove_duplicate_pdrs (poly_bb_p pbb)
     for (j = 0; VEC_iterate (poly_dr_p, collapsed, j, pdr2); j++)
       if (!can_collapse_pdrs (pdr1, pdr2))
        VEC_quick_push (poly_dr_p, collapsed, pdr1);
+
+  VEC_free (poly_dr_p, heap, collapsed);
+  PBB_PDR_DUPLICATES_REMOVED (pbb) = true;
 }
 
 /* Create a new polyhedral data reference and add it to PBB.  It is
@@ -354,6 +397,7 @@ new_poly_bb (scop_p scop, void *black_box, bool reduction)
   PBB_ORIGINAL (pbb) = NULL;
   PBB_DRS (pbb) = VEC_alloc (poly_dr_p, heap, 3);
   PBB_IS_REDUCTION (pbb) = reduction;
+  PBB_PDR_DUPLICATES_REMOVED (pbb) = false;
   VEC_safe_push (poly_bb_p, heap, SCOP_BBS (scop), pbb);
 }
 
@@ -405,47 +449,59 @@ print_pdr_access_layout (FILE *file, poly_dr_p pdr)
   fprintf (file, "    cst\n");
 }
 
-/* Prints to FILE the polyhedral data reference PDR.  */
+/* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
+   level.  */
 
 void
-print_pdr (FILE *file, poly_dr_p pdr)
+print_pdr (FILE *file, poly_dr_p pdr, int verbosity)
 {
-  fprintf (file, "pdr_%d (", PDR_ID (pdr));
-
-  switch (PDR_TYPE (pdr))
+  if (verbosity > 1)
     {
-    case PDR_READ:
-      fprintf (file, "read \n");
-      break;
+      fprintf (file, "# pdr_%d (", PDR_ID (pdr));
+
+      switch (PDR_TYPE (pdr))
+       {
+       case PDR_READ:
+         fprintf (file, "read \n");
+         break;
 
-    case PDR_WRITE:
-      fprintf (file, "write \n");
-      break;
+       case PDR_WRITE:
+         fprintf (file, "write \n");
+         break;
 
-    case PDR_MAY_WRITE:
-      fprintf (file, "may_write \n");
-      break;
+       case PDR_MAY_WRITE:
+         fprintf (file, "may_write \n");
+         break;
 
-    default:
-      gcc_unreachable ();
+       default:
+         gcc_unreachable ();
+       }
+
+      dump_data_reference (file, (data_reference_p) PDR_CDR (pdr));
     }
 
-  dump_data_reference (file, (data_reference_p) PDR_CDR (pdr));
+  if (verbosity > 0)
+    {
+      fprintf (file, "# data accesses (\n");
+      print_pdr_access_layout (file, pdr);
+    }
 
-  fprintf (file, "data accesses (\n");
-  print_pdr_access_layout (file, pdr);
   ppl_print_powerset_matrix (file, PDR_ACCESSES (pdr));
-  fprintf (file, ")\n");
 
-  fprintf (file, ")\n");
+  if (verbosity > 0)
+    fprintf (file, "#)\n");
+
+  if (verbosity > 1)
+    fprintf (file, "#)\n");
 }
 
-/* Prints to STDERR the polyhedral data reference PDR.  */
+/* Prints to STDERR the polyhedral data reference PDR, at some
+   VERBOSITY level.  */
 
 void
-debug_pdr (poly_dr_p pdr)
+debug_pdr (poly_dr_p pdr, int verbosity)
 {
-  print_pdr (stderr, pdr);
+  print_pdr (stderr, pdr, verbosity);
 }
 
 /* Creates a new SCOP containing REGION.  */
@@ -460,6 +516,11 @@ new_scop (void *region)
   SCOP_BBS (scop) = VEC_alloc (poly_bb_p, heap, 3);
   SCOP_ORIGINAL_PDDRS (scop) = htab_create (10, hash_poly_ddr_p,
                                            eq_poly_ddr_p, free_poly_ddr);
+  SCOP_ORIGINAL_SCHEDULE (scop) = NULL;
+  SCOP_TRANSFORMED_SCHEDULE (scop) = NULL;
+  SCOP_SAVED_SCHEDULE (scop) = NULL;
+  POLY_SCOP_P (scop) = false;
+
   return scop;
 }
 
@@ -480,13 +541,16 @@ free_scop (scop_p scop)
     ppl_delete_Pointset_Powerset_C_Polyhedron (SCOP_CONTEXT (scop));
 
   htab_delete (SCOP_ORIGINAL_PDDRS (scop));
+  free_lst (SCOP_ORIGINAL_SCHEDULE (scop));
+  free_lst (SCOP_TRANSFORMED_SCHEDULE (scop));
+  free_lst (SCOP_SAVED_SCHEDULE (scop));
   XDELETE (scop);
 }
 
-/* Print to FILE the domain of PBB.  */
+/* Print to FILE the domain of PBB, at some VERBOSITY level.  */
 
 void
-print_pbb_domain (FILE *file, poly_bb_p pbb)
+print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity)
 {
   graphite_dim_t i;
   gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
@@ -494,21 +558,27 @@ print_pbb_domain (FILE *file, poly_bb_p pbb)
   if (!PBB_DOMAIN (pbb))
     return;
 
-  fprintf (file, "domains bb_%d (\n", GBB_BB (gbb)->index);
-  fprintf (file, "#  eq");
+  if (verbosity > 0)
+    {
+      fprintf (file, "# Iteration domain of bb_%d (\n", GBB_BB (gbb)->index);
+      fprintf (file, "#  eq");
 
-  for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
-    fprintf (file, "     i%d", (int) i);
+      for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
+       fprintf (file, "     i%d", (int) i);
 
-  for (i = 0; i < pbb_nb_params (pbb); i++)
-    fprintf (file, "     p%d", (int) i);
+      for (i = 0; i < pbb_nb_params (pbb); i++)
+       fprintf (file, "     p%d", (int) i);
 
-  fprintf (file, "    cst\n");
+      fprintf (file, "    cst\n");
+    }
 
   if (PBB_DOMAIN (pbb))
     ppl_print_powerset_matrix (file, PBB_DOMAIN (pbb));
+  else
+    fprintf (file, "0\n");
 
-  fprintf (file, ")\n");
+  if (verbosity > 0)
+    fprintf (file, "#)\n");
 }
 
 /* Dump the cases of a graphite basic block GBB on FILE.  */
@@ -527,12 +597,15 @@ dump_gbb_cases (FILE *file, gimple_bb_p gbb)
   if (VEC_empty (gimple, cases))
     return;
 
-  fprintf (file, "cases bb_%d (", GBB_BB (gbb)->index);
+  fprintf (file, "# cases bb_%d (\n", GBB_BB (gbb)->index);
 
   for (i = 0; VEC_iterate (gimple, cases, i, stmt); i++)
-    print_gimple_stmt (file, stmt, 0, 0);
+    {
+      fprintf (file, "# ");
+      print_gimple_stmt (file, stmt, 0, 0);
+    }
 
-  fprintf (file, ")\n");
+  fprintf (file, "#)\n");
 }
 
 /* Dump conditions of a graphite basic block GBB on FILE.  */
@@ -551,150 +624,364 @@ dump_gbb_conditions (FILE *file, gimple_bb_p gbb)
   if (VEC_empty (gimple, conditions))
     return;
 
-  fprintf (file, "conditions bb_%d (", GBB_BB (gbb)->index);
+  fprintf (file, "# conditions bb_%d (\n", GBB_BB (gbb)->index);
 
   for (i = 0; VEC_iterate (gimple, conditions, i, stmt); i++)
-    print_gimple_stmt (file, stmt, 0, 0);
+    {
+      fprintf (file, "# ");
+      print_gimple_stmt (file, stmt, 0, 0);
+    }
 
-  fprintf (file, ")\n");
+  fprintf (file, "#)\n");
 }
 
-/* Print to FILE all the data references of PBB.  */
+/* Print to FILE all the data references of PBB, at some VERBOSITY
+   level.  */
 
 void
-print_pdrs (FILE *file, poly_bb_p pbb)
+print_pdrs (FILE *file, poly_bb_p pbb, int verbosity)
 {
   int i;
   poly_dr_p pdr;
+  int nb_reads = 0;
+  int nb_writes = 0;
+
+  if (VEC_length (poly_dr_p, PBB_DRS (pbb)) == 0)
+    {
+      if (verbosity > 0)
+       fprintf (file, "# Access informations are not provided\n");\
+      fprintf (file, "0\n");
+      return;
+    }
+
+  if (verbosity > 1)
+    fprintf (file, "# Data references (\n");
+
+  if (verbosity > 0)
+    fprintf (file, "# Access informations are provided\n");
+  fprintf (file, "1\n");
 
   for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
-    print_pdr (file, pdr);
+    if (PDR_TYPE (pdr) == PDR_READ)
+      nb_reads++;
+    else
+      nb_writes++;
+
+  if (verbosity > 1)
+    fprintf (file, "# Read data references (\n");
+
+  if (verbosity > 0)
+    fprintf (file, "# Read access informations\n");
+  fprintf (file, "%d\n", nb_reads);
+
+  for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
+    if (PDR_TYPE (pdr) == PDR_READ)
+      print_pdr (file, pdr, verbosity);
+
+  if (verbosity > 1)
+    fprintf (file, "#)\n");
+
+  if (verbosity > 1)
+    fprintf (file, "# Write data references (\n");
+
+  if (verbosity > 0)
+    fprintf (file, "# Write access informations\n");
+  fprintf (file, "%d\n", nb_writes);
+
+  for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
+    if (PDR_TYPE (pdr) != PDR_READ)
+      print_pdr (file, pdr, verbosity);
+
+  if (verbosity > 1)
+    fprintf (file, "#)\n");
+
+  if (verbosity > 1)
+    fprintf (file, "#)\n");
 }
 
 /* Print to STDERR all the data references of PBB.  */
 
 void
-debug_pdrs (poly_bb_p pbb)
+debug_pdrs (poly_bb_p pbb, int verbosity)
 {
-  print_pdrs (stderr, pbb);
+  print_pdrs (stderr, pbb, verbosity);
 }
 
-/* Print to FILE the domain and scattering function of PBB.  */
+/* Print to FILE the body of PBB, at some VERBOSITY level.  */
+
+static void
+print_pbb_body (FILE *file, poly_bb_p pbb, int verbosity)
+{
+  if (verbosity > 1)
+    fprintf (file, "# Body (\n");
+
+  if (verbosity > 0)
+    fprintf (file, "# Statement body is provided\n");
+  fprintf (file, "1\n");
+
+  if (verbosity > 0)
+    fprintf (file, "# Original iterator names\n# Iterator names are not provided yet.\n");
+
+  if (verbosity > 0)
+    fprintf (file, "# Statement body\n");
+
+  fprintf (file, "{\n");
+  dump_bb (pbb_bb (pbb), file, 0);
+  fprintf (file, "}\n");
+
+  if (verbosity > 1)
+    fprintf (file, "#)\n");
+}
+
+/* Print to FILE the domain and scattering function of PBB, at some
+   VERBOSITY level.  */
 
 void
-print_pbb (FILE *file, poly_bb_p pbb)
+print_pbb (FILE *file, poly_bb_p pbb, int verbosity)
 {
-  fprintf (file, "pbb_%d (\n", pbb_index (pbb));
-  dump_gbb_conditions (file, PBB_BLACK_BOX (pbb));
-  dump_gbb_cases (file, PBB_BLACK_BOX (pbb));
-  print_pdrs (file, pbb);
-  print_pbb_domain (file, pbb);
-  print_scattering_function (file, pbb);
-  fprintf (file, ")\n");
+  if (verbosity > 1)
+    {
+      fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
+      dump_gbb_conditions (file, PBB_BLACK_BOX (pbb));
+      dump_gbb_cases (file, PBB_BLACK_BOX (pbb));
+    }
+
+  print_pbb_domain (file, pbb, verbosity);
+  print_scattering_function (file, pbb, verbosity);
+  print_pdrs (file, pbb, verbosity);
+  print_pbb_body (file, pbb, verbosity);
+
+  if (verbosity > 1)
+    fprintf (file, "#)\n");
 }
 
-/* Print to FILE the parameters of SCOP.  */
+/* Print to FILE the parameters of SCOP, at some VERBOSITY level.  */
 
 void
-print_scop_params (FILE *file, scop_p scop)
+print_scop_params (FILE *file, scop_p scop, int verbosity)
 {
   int i;
   tree t;
 
-  fprintf (file, "parameters (\n");
+  if (verbosity > 1)
+    fprintf (file, "# parameters (\n");
+
+  if (VEC_length (tree, SESE_PARAMS (SCOP_REGION (scop))))
+    {
+      if (verbosity > 0)
+       fprintf (file, "# Parameter names are provided\n");
+
+      fprintf (file, "1\n");
+
+      if (verbosity > 0)
+       fprintf (file, "# Parameter names\n");
+    }
+  else
+    {
+      if (verbosity > 0)
+       fprintf (file, "# Parameter names are not provided\n");
+      fprintf (file, "0\n");
+    }
+
   for (i = 0; VEC_iterate (tree, SESE_PARAMS (SCOP_REGION (scop)), i, t); i++)
     {
-      fprintf (file, "p_%d -> ", i);
       print_generic_expr (file, t, 0);
-      fprintf (file, "\n");
+      fprintf (file, " ");
     }
-  fprintf (file, ")\n");
+
+  fprintf (file, "\n");
+
+  if (verbosity > 1)
+    fprintf (file, "#)\n");
 }
 
-/* Print to FILE the context of SCoP.  */
+/* Print to FILE the context of SCoP, at some VERBOSITY level.  */
+
 void
-print_scop_context (FILE *file, scop_p scop)
+print_scop_context (FILE *file, scop_p scop, int verbosity)
 {
   graphite_dim_t i;
 
-  fprintf (file, "context (\n");
-  fprintf (file, "#  eq");
+  if (verbosity > 0)
+    {
+      fprintf (file, "# Context (\n");
+      fprintf (file, "#  eq");
 
-  for (i = 0; i < scop_nb_params (scop); i++)
-    fprintf (file, "     p%d", (int) i);
+      for (i = 0; i < scop_nb_params (scop); i++)
+       fprintf (file, "     p%d", (int) i);
 
-  fprintf (file, "    cst\n");
+      fprintf (file, "    cst\n");
+    }
 
   if (SCOP_CONTEXT (scop))
     ppl_print_powerset_matrix (file, SCOP_CONTEXT (scop));
+  else
+    fprintf (file, "0 %d\n", (int) scop_nb_params (scop) + 2);
 
-  fprintf (file, ")\n");
+  if (verbosity > 0)
+    fprintf (file, "# )\n");
 }
 
-/* Print to FILE the SCOP.  */
+/* Print to FILE the SCOP, at some VERBOSITY level.  */
 
 void
-print_scop (FILE *file, scop_p scop)
+print_scop (FILE *file, scop_p scop, int verbosity)
 {
   int i;
   poly_bb_p pbb;
 
-  fprintf (file, "scop (\n");
-  print_scop_params (file, scop);
-  print_scop_context (file, scop);
+  fprintf (file, "SCoP #(\n");
+  fprintf (file, "# Language\nGimple\n");
+  print_scop_context (file, scop, verbosity);
+  print_scop_params (file, scop, verbosity);
+
+  if (verbosity > 0)
+    fprintf (file, "# Number of statements\n");
+
+  fprintf (file, "%d\n",VEC_length (poly_bb_p, SCOP_BBS (scop)));
 
   for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
-    print_pbb (file, pbb);
+    print_pbb (file, pbb, verbosity);
 
-  fprintf (file, ")\n");
+  if (verbosity > 1)
+    {
+      fprintf (file, "# original_lst (\n");
+      print_lst (file, SCOP_ORIGINAL_SCHEDULE (scop), 0);
+      fprintf (file, "\n#)\n");
 
-  fprintf (file, "original_lst (\n");
-  print_lst (file, SCOP_ORIGINAL_SCHEDULE (scop), 0);
-  fprintf (file, ")\n");
+      fprintf (file, "# transformed_lst (\n");
+      print_lst (file, SCOP_TRANSFORMED_SCHEDULE (scop), 0);
+      fprintf (file, "\n#)\n");
+    }
 
-  fprintf (file, "transformed_lst (\n");
-  print_lst (file, SCOP_TRANSFORMED_SCHEDULE (scop), 0);
-  fprintf (file, ")\n");
+  fprintf (file, "#)\n");
 }
 
-/* Print to STDERR the domain of PBB.  */
+/* Print to FILE the input file that CLooG would expect as input, at
+   some VERBOSITY level.  */
 
 void
-debug_pbb_domain (poly_bb_p pbb)
+print_cloog (FILE *file, scop_p scop, int verbosity)
 {
-  print_pbb_domain (stderr, pbb);
+  int i;
+  poly_bb_p pbb;
+
+  fprintf (file, "# SCoP (generated by GCC/Graphite\n");
+  if (verbosity > 0)
+    fprintf (file, "# CLooG output language\n");
+  fprintf (file, "c\n");
+
+  print_scop_context (file, scop, verbosity);
+  print_scop_params (file, scop, verbosity);
+
+  if (verbosity > 0)
+    fprintf (file, "# Number of statements\n");
+
+  fprintf (file, "%d\n", VEC_length (poly_bb_p, SCOP_BBS (scop)));
+
+  for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
+    {
+      if (verbosity > 1)
+       fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
+
+      print_pbb_domain (file, pbb, verbosity);
+      fprintf (file, "0 0 0");
+
+      if (verbosity > 0)
+       fprintf (file, "# For future CLooG options.\n");
+      else
+       fprintf (file, "\n");
+
+      if (verbosity > 1)
+       fprintf (file, "#)\n");
+    }
+
+  fprintf (file, "0");
+  if (verbosity > 0)
+    fprintf (file, "# Don't set the iterator names.\n");
+  else
+    fprintf (file, "\n");
+
+  if (verbosity > 0)
+    fprintf (file, "# Number of scattering functions\n");
+
+  fprintf (file, "%d\n", VEC_length (poly_bb_p, SCOP_BBS (scop)));
+  unify_scattering_dimensions (scop);
+
+  for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
+    {
+      if (!PBB_TRANSFORMED (pbb)
+         || !(PBB_TRANSFORMED_SCATTERING (pbb)
+              || PBB_ORIGINAL_SCATTERING (pbb)))
+       continue;
+
+      if (verbosity > 1)
+       fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
+
+      print_scattering_function_1 (file, pbb, verbosity);
+
+      if (verbosity > 1)
+       fprintf (file, "#)\n");
+    }
+
+  fprintf (file, "0");
+  if (verbosity > 0)
+    fprintf (file, "# Don't set the scattering dimension names.\n");
+  else
+    fprintf (file, "\n");
+
+  fprintf (file, "#)\n");
 }
 
-/* Print to FILE the domain and scattering function of PBB.  */
+/* Print to STDERR the domain of PBB, at some VERBOSITY level.  */
 
 void
-debug_pbb (poly_bb_p pbb)
+debug_pbb_domain (poly_bb_p pbb, int verbosity)
 {
-  print_pbb (stderr, pbb);
+  print_pbb_domain (stderr, pbb, verbosity);
 }
 
-/* Print to STDERR the context of SCOP.  */
+/* Print to FILE the domain and scattering function of PBB, at some
+   VERBOSITY level.  */
 
 void
-debug_scop_context (scop_p scop)
+debug_pbb (poly_bb_p pbb, int verbosity)
 {
-  print_scop_context (stderr, scop);
+  print_pbb (stderr, pbb, verbosity);
 }
 
-/* Print to STDERR the SCOP.  */
+/* Print to STDERR the context of SCOP, at some VERBOSITY level.  */
 
 void
-debug_scop (scop_p scop)
+debug_scop_context (scop_p scop, int verbosity)
 {
-  print_scop (stderr, scop);
+  print_scop_context (stderr, scop, verbosity);
 }
 
-/* Print to STDERR the parameters of SCOP.  */
+/* Print to STDERR the SCOP, at some VERBOSITY level.  */
 
 void
-debug_scop_params (scop_p scop)
+debug_scop (scop_p scop, int verbosity)
 {
-  print_scop_params (stderr, scop);
+  print_scop (stderr, scop, verbosity);
+}
+
+/* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
+   level.  */
+
+void
+debug_cloog (scop_p scop, int verbosity)
+{
+  print_cloog (stderr, scop, verbosity);
+}
+
+/* Print to STDERR the parameters of SCOP, at some VERBOSITY
+   level.  */
+
+void
+debug_scop_params (scop_p scop, int verbosity)
+{
+  print_scop_params (stderr, scop, verbosity);
 }
 
 
@@ -790,28 +1077,36 @@ pbb_number_of_iterations_at_time (poly_bb_p pbb,
   ppl_Linear_Expression_t le;
   ppl_dimension_type dim;
 
-  value_set_si (niter, -1);
-
   /* Takes together domain and scattering polyhedrons, and composes
      them into the bigger polyhedron that has the following format:
-     t0..t_{n-1} | l0..l_{nlcl-1} | i0..i_{niter-1} | g0..g_{nparm-1}.
-     t0..t_{n-1} are time dimensions (scattering dimensions)
-     l0..l_{nclc-1} are local variables in scatterin function
-     i0..i_{niter-1} are original iteration variables
-     g0..g_{nparam-1} are global parameters.  */
 
+     t0..t_{n-1} | l0..l_{nlcl-1} | i0..i_{niter-1} | g0..g_{nparm-1}
+
+     where
+     | t0..t_{n-1} are time dimensions (scattering dimensions)
+     | l0..l_{nclc-1} are local variables in scattering function
+     | i0..i_{niter-1} are original iteration variables
+     | g0..g_{nparam-1} are global parameters.  */
+
+  ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sctr,
+      PBB_TRANSFORMED_SCATTERING (pbb));
+
+  /* Extend the iteration domain with the scattering dimensions:
+     0..0 | 0..0 | i0..i_{niter-1} | g0..g_{nparm-1}.   */
   ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
     (&ext_domain, PBB_DOMAIN (pbb));
   ppl_insert_dimensions_pointset (ext_domain, 0,
                                   pbb_nb_scattering_transform (pbb)
                                   + pbb_nb_local_vars (pbb));
-  ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sctr,
-      PBB_TRANSFORMED_SCATTERING (pbb));
+
+  /* Add to sctr the extended domain.  */
   ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr, ext_domain);
 
+  /* Extract the number of iterations.  */
   ppl_Pointset_Powerset_C_Polyhedron_space_dimension (sctr, &dim);
   ppl_new_Linear_Expression_with_dimension (&le, dim);
   ppl_set_coef (le, time_depth, 1);
+  value_set_si (niter, -1);
   ppl_max_for_le_pointset (sctr, le, niter);
 
   ppl_delete_Linear_Expression (le);
@@ -834,22 +1129,19 @@ loop_to_lst (loop_p loop, VEC (poly_bb_p, heap) *bbs, int *i)
 
       if (bb->loop_father == loop)
        stmt = new_lst_stmt (pbb);
-      else
+      else if (flow_bb_inside_loop_p (loop, bb))
        {
-         if (flow_bb_inside_loop_p (loop, bb))
-           stmt = loop_to_lst (loop->inner, bbs, i);
-         else
-           {
-             loop_p next = loop;
+         loop_p next = loop->inner;
 
-             while ((next = next->next)
-                    && !flow_bb_inside_loop_p (next, bb));
+         while (next && !flow_bb_inside_loop_p (next, bb))
+           next = next->next;
 
-             if (!next)
-               return new_lst_loop (seq);
-
-             stmt = loop_to_lst (next, bbs, i);
-           }
+         stmt = loop_to_lst (next, bbs, i);
+       }
+      else
+       {
+         (*i)--;
+         return new_lst_loop (seq);
        }
 
       VEC_safe_push (lst_p, heap, seq, stmt);
@@ -864,12 +1156,41 @@ loop_to_lst (loop_p loop, VEC (poly_bb_p, heap) *bbs, int *i)
 void
 scop_to_lst (scop_p scop)
 {
-  poly_bb_p pbb = VEC_index (poly_bb_p, SCOP_BBS (scop), 0);
-  loop_p loop = outermost_loop_in_sese (SCOP_REGION (scop), GBB_BB (PBB_BLACK_BOX (pbb)));
-  int i = 0;
+  lst_p res;
+  int i, n = VEC_length (poly_bb_p, SCOP_BBS (scop));
+  VEC (lst_p, heap) *seq = VEC_alloc (lst_p, heap, 5);
+  sese region = SCOP_REGION (scop);
 
-  SCOP_ORIGINAL_SCHEDULE (scop) = loop_to_lst (loop, SCOP_BBS (scop), &i);
-  SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (SCOP_ORIGINAL_SCHEDULE (scop));
+  for (i = 0; i < n; i++)
+    {
+      poly_bb_p pbb = VEC_index (poly_bb_p, SCOP_BBS (scop), i);
+      loop_p loop = outermost_loop_in_sese (region, GBB_BB (PBB_BLACK_BOX (pbb)));
+
+      if (loop_in_sese_p (loop, region))
+       res = loop_to_lst (loop, SCOP_BBS (scop), &i);
+      else
+       res = new_lst_stmt (pbb);
+
+      VEC_safe_push (lst_p, heap, seq, res);
+    }
+
+  res = new_lst_loop (seq);
+  SCOP_ORIGINAL_SCHEDULE (scop) = res;
+  SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (res);
+}
+
+/* Print to FILE on a new line COLUMN white spaces.  */
+
+static void
+lst_indent_to (FILE *file, int column)
+{
+  int i;
+
+  if (column > 0)
+    fprintf (file, "\n#");
+
+  for (i = 0; i < column; i++)
+    fprintf (file, " ");
 }
 
 /* Print LST to FILE with INDENT spaces of indentation.  */
@@ -880,14 +1201,17 @@ print_lst (FILE *file, lst_p lst, int indent)
   if (!lst)
     return;
 
-  indent_to (file, indent);
+  lst_indent_to (file, indent);
 
   if (LST_LOOP_P (lst))
     {
       int i;
       lst_p l;
 
-      fprintf (file, "%d (loop", lst_dewey_number (lst));
+      if (LST_LOOP_FATHER (lst))
+       fprintf (file, "%d (loop", lst_dewey_number (lst));
+      else
+       fprintf (file, "#(root");
 
       for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
        print_lst (file, l, indent + 2);