]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Enable graphite to read an OpenScop file.
authorRiyadh Baghdadi <baghdadi.mr@gmail.com>
Thu, 30 Sep 2010 21:17:12 +0000 (21:17 +0000)
committerSebastian Pop <spop@gcc.gnu.org>
Thu, 30 Sep 2010 21:17:12 +0000 (21:17 +0000)
2010-08-12  Riyadh Baghdadi <baghdadi.mr@gmail.com>

* graphite-cloog-util.c (openscop_read_cloog_matrix): New.
(openscop_read_polyhedron_matrix): New.
* graphite-cloog-util.h (openscop_read_polyhedron_matrix): Declared.
(openscop_read_N_int): Same.
* graphite-poly.c (openscop_read_N_int): New.
(openscop_read_one_int): New.
(openscop_read_N_string): New.
(openscop_read_one_string): New.
(openscop_read_powerset_matrix): New.
(graphite_read_transforms): Remove.
(graphite_read_scatt): New.
(graphite_read_scop_file): New.
(apply_poly_transforms): Updated to call graphite_read_scop_file.

From-SVN: r164778

gcc/ChangeLog
gcc/ChangeLog.graphite
gcc/graphite-cloog-util.c
gcc/graphite-cloog-util.h
gcc/graphite-poly.c

index 9daa730f7210d3534639e85fde63c6de60028309..77302872e1cedbc664bf8163b70cfbacd23c6003 100644 (file)
@@ -1,3 +1,19 @@
+2010-09-30  Riyadh Baghdadi <baghdadi.mr@gmail.com>
+
+       * graphite-cloog-util.c (openscop_read_cloog_matrix): New.
+       (openscop_read_polyhedron_matrix): New.
+       * graphite-cloog-util.h (openscop_read_polyhedron_matrix): Declared.
+       (openscop_read_N_int): Same.
+       * graphite-poly.c (openscop_read_N_int): New.
+       (openscop_read_one_int): New.
+       (openscop_read_N_string): New.
+       (openscop_read_one_string): New.
+       (openscop_read_powerset_matrix): New.
+       (graphite_read_transforms): Remove.
+       (graphite_read_scatt): New.
+       (graphite_read_scop_file): New.
+       (apply_poly_transforms): Updated to call graphite_read_scop_file.
+
 2010-09-30  Andreas Simbuerger  <simbuerg@fim.uni-passau.de>
 
        * graphite-poly.c: Change include order.
index 11cf83f59df41d7bea69288056e931add0b685e8..6c56686842a3bec9574c8611d0309743f8b34336 100644 (file)
@@ -1,3 +1,19 @@
+2010-08-12  Riyadh Baghdadi <baghdadi.mr@gmail.com>
+
+       * graphite-cloog-util.c (openscop_read_cloog_matrix): New.
+       (openscop_read_polyhedron_matrix): New.
+       * graphite-cloog-util.h (openscop_read_polyhedron_matrix): Declared.
+       (openscop_read_N_int): Same.
+       * graphite-poly.c (openscop_read_N_int): New.
+       (openscop_read_one_int): New.
+       (openscop_read_N_string): New.
+       (openscop_read_one_string): New.
+       (openscop_read_powerset_matrix): New.
+       (graphite_read_transforms): Remove.
+       (graphite_read_scatt): New.
+       (graphite_read_scop_file): New.
+       (apply_poly_transforms): Updated to call graphite_read_scop_file.
+
 2010-08-11  Andreas Simbuerger  <simbuerg@fim.uni-passau.de>
 
        * graphite-poly.c: Change include order.
index 949e8d470315ae69360bbe31c1acc8571a5a4eda..40c6fbc004f2cbc6aff11cf0630de30daa9c60bd 100644 (file)
@@ -339,4 +339,69 @@ openscop_print_polyhedron_matrix (FILE *file, ppl_const_Polyhedron_t ph,
   cloog_matrix_free (mat);
 }
 
+/* Read from FILE a matrix in OpenScop format.  OUTPUT is the number of
+   output dimensions, INPUT is the number of input dimensions, LOCALS
+   is the number of existentially quantified variables and PARAMS is the
+   number of parameters.  */
+
+static CloogMatrix *
+openscop_read_cloog_matrix (FILE *file, int *output, int *input, int *locals,
+                           int *params)
+{
+  int nb_rows, nb_cols, i, j;
+  CloogMatrix *mat;
+  int *openscop_matrix_header, *matrix_line;
+
+  openscop_matrix_header = openscop_read_N_int (file, 6);
+
+  nb_rows = openscop_matrix_header[0];
+  nb_cols = openscop_matrix_header[1];
+  *output = openscop_matrix_header[2];
+  *input = openscop_matrix_header[3];
+  *locals = openscop_matrix_header[4];
+  *params = openscop_matrix_header[5];
+
+  free (openscop_matrix_header);
+
+  if (nb_rows == 0 || nb_cols == 0)
+    return NULL;
+
+  mat = cloog_matrix_alloc (nb_rows, nb_cols);
+  mat->NbRows = nb_rows;
+  mat->NbColumns = nb_cols;
+
+  for (i = 0; i < nb_rows; i++)
+    {
+      matrix_line = openscop_read_N_int (file, nb_cols);
+
+      for (j = 0; j < nb_cols; j++)
+        mpz_set_si (mat->p[i][j], matrix_line[j]);
+    }
+
+  return mat;
+}
+
+/* Read from FILE the polyhedron PH in OpenScop format.  OUTPUT is the number
+   of output dimensions, INPUT is the number of input dimensions, LOCALS is
+   the number of existentially quantified variables and PARAMS is the number
+   of parameters.  */
+
+void
+openscop_read_polyhedron_matrix (FILE *file, ppl_Polyhedron_t *ph,
+                                int *output, int *input, int *locals,
+                                int *params)
+{
+  CloogMatrix *mat;
+
+  mat = openscop_read_cloog_matrix (file, output, input, locals, params);
+
+  if (!mat)
+    *ph = NULL;
+  else
+    {
+      new_C_Polyhedron_from_Cloog_Matrix (ph, mat);
+      cloog_matrix_free (mat);
+    }
+}
+
 #endif
index 62e2f94dd8214a5df1ea502c606ecfc0aab7dc50..9686e7cd465f7fbc8d6ede7ed6d990a0b80afb82 100644 (file)
@@ -34,5 +34,9 @@ CloogDomain * new_Cloog_Domain_from_ppl_Pointset_Powerset
 void new_C_Polyhedron_from_Cloog_Matrix (ppl_Polyhedron_t *, CloogMatrix *);
 void openscop_print_polyhedron_matrix (FILE *, ppl_const_Polyhedron_t, int,
                                       int, int, int);
+void openscop_read_polyhedron_matrix (FILE *, ppl_Polyhedron_t *, int *, int *,
+                                    int *, int *);
+
+extern int *openscop_read_N_int (FILE *, int);
 
 #endif /* GRAPHITE_CLOOG_UTIL_H */
index 2e5345d41affab00f7815dd44038b2122e5edbf7..eb4d61fe841c5c5c892670178e97c02b4d1881bb 100644 (file)
@@ -54,6 +54,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "graphite-dependences.h"
 #include "graphite-cloog-util.h"
 
+#define OPENSCOP_MAX_STRING 256
+
 /* Return the maximal loop depth in SCOP.  */
 
 int
@@ -434,6 +436,252 @@ debug_iteration_domains (scop_p scop, int verbosity)
   print_iteration_domains (stderr, scop, verbosity);
 }
 
+/* Read N integer from FILE.  */
+
+int *
+openscop_read_N_int (FILE *file, int N)
+{
+  char s[OPENSCOP_MAX_STRING];
+  char *str;
+  int i, *res = (int *) xmalloc (OPENSCOP_MAX_STRING * sizeof (int));
+
+  /* Skip blank and commented lines.  */
+  while (fgets (s, sizeof s, file) == (char *) 0
+        || s[0] == '#'
+        || ISSPACE (s[0]))
+    ;
+
+  str = s;
+
+  for (i = 0; i < N; i++)
+    {
+      sscanf (str, "%d", &res[i]);
+
+      /* Jump the integer that was read.  */
+      while ((*str) && !ISSPACE (*str) && (*str != '#'))
+       str++;
+
+      /* Jump spaces.  */
+      while ((*str) && ISSPACE (*str) && (*str != '#'))
+       str++;
+    }
+
+  return res;
+}
+
+/* Read one integer from FILE.  */
+
+static int
+openscop_read_one_int (FILE *file)
+{
+  int *x = openscop_read_N_int (file, 1);
+  int res = *x;
+
+  free (x);
+  return res;
+}
+
+/* Read N string from FILE.  */
+
+static char *
+openscop_read_N_string (FILE *file, int N)
+{
+  int count, i;
+  char str[OPENSCOP_MAX_STRING];
+  char *tmp = (char *) xmalloc (sizeof (char) * OPENSCOP_MAX_STRING);
+  char *s = NULL;
+
+  /* Skip blank and commented lines.  */
+  while (fgets (str, sizeof str, file) == (char *) 0
+        || str[0] == '#'
+        || ISSPACE (str[0]))
+    ;
+
+  s = str;
+  count = 0;
+
+  for (i = 0; i < N; i++)
+    {
+      /* Read the first word.  */
+      for (; (*s) && (!ISSPACE (*s)) && (*s != '#'); ++count)
+        tmp[count] = *(s++);
+
+      tmp[count] = ' ';
+      count++;
+
+      /* Jump spaces.  */
+      while ((*s) && ISSPACE (*s) && (*s != '#'))
+       s++;
+    }
+
+  tmp[count-1] = '\0';
+
+  return tmp;
+}
+
+/* Read one string from FILE.  */
+
+static char *
+openscop_read_one_string (FILE *file)
+{
+  return openscop_read_N_string (file, 1);
+}
+
+/* Read from FILE the powerset PS in its OpenScop matrix form.  OUTPUT is the
+   number of output dimensions, INPUT is the number of input dimensions,
+   LOCALS is the number of existentially quantified variables and PARAMS is
+   the number of parameters.  */
+
+static void
+openscop_read_powerset_matrix (FILE *file,
+                              ppl_Pointset_Powerset_C_Polyhedron_t *ps,
+                              int *output, int *input, int *locals,
+                              int *params)
+{
+  int nb_disjuncts, i;
+
+  nb_disjuncts = openscop_read_one_int (file);
+
+  for (i = 0; i < nb_disjuncts; i++)
+    {
+      ppl_Polyhedron_t ph;
+
+      openscop_read_polyhedron_matrix (file, &ph, output, input, locals,
+                                      params);
+      if (!ph)
+        *ps = NULL;
+      else if (i == 0)
+        ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (ps, ph);
+      else
+        ppl_Pointset_Powerset_C_Polyhedron_add_disjunct (*ps, ph);
+    }
+}
+
+/* Read a scattering function from FILE and save it to PBB.  Return whether
+   the scattering function was provided or not.  */
+
+static bool
+graphite_read_scatt (FILE *file, poly_bb_p pbb)
+{
+  bool scattering_provided = false;
+  int output, input, locals, params;
+  ppl_Polyhedron_t newp;
+
+  if (openscop_read_one_int (file) > 0)
+    {
+      /* Read number of disjunct components.  */
+      openscop_read_one_int (file);
+
+      /* Read scattering function.  */
+      openscop_read_polyhedron_matrix (file, &newp, &output, &input,
+                                      &locals, &params);
+      store_scattering (PBB_SCOP (pbb));
+      PBB_TRANSFORMED (pbb) = poly_scattering_new ();
+      PBB_TRANSFORMED_SCATTERING (pbb) = newp;
+      PBB_NB_LOCAL_VARIABLES (pbb) = locals;
+
+      /* New scattering dimension.  */
+      PBB_NB_SCATTERING_TRANSFORM (pbb) = output;
+
+      scattering_provided = true;
+    }
+
+  return scattering_provided;
+}
+
+/* Read a scop file.  Return true if the scop is transformed.  */
+
+static bool
+graphite_read_scop_file (FILE *file, scop_p scop)
+{
+  char *tmp, *language;
+  size_t i, j, nb_statements, nbr, nbw;
+  int input, output, locals, params;
+  ppl_Pointset_Powerset_C_Polyhedron_t ps;
+  poly_bb_p pbb;
+  bool transform_done;
+
+  /* Ensure that the file is in OpenScop format.  */
+  tmp = openscop_read_N_string (file, 2);
+
+  if (strcmp (tmp, "SCoP 1"))
+    {
+      error ("The file is not in OpenScop format.\n");
+      return false;
+    }
+
+  free (tmp);
+
+  /* Read the language.  */
+  language = openscop_read_one_string (file);
+
+  if (strcmp (language, "Gimple"))
+    {
+      error ("The language is not recognized\n");
+      return false;
+    }
+
+  free (language);
+
+  /* Read the context but do not use it.  */
+  openscop_read_powerset_matrix (file, &ps, &input, &output, &locals, &params);
+
+  if ((size_t) params != scop->nb_params)
+    {
+      error ("Parameters number in the scop file is different from the"
+            " internal scop parameter number.");
+      return false;
+    }
+
+  /* Read parameter names if provided.  */
+  if (openscop_read_one_int (file))
+    openscop_read_N_string (file, scop->nb_params);
+
+  nb_statements = openscop_read_one_int (file);
+
+  if (nb_statements != VEC_length (poly_bb_p, SCOP_BBS (scop)))
+    {
+      error ("Number of statements in the OpenScop file does not match"
+            " the graphite internal statements number.");
+      return false;
+    }
+
+  for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
+    {
+      /* Read iteration domain.  */
+      openscop_read_powerset_matrix (file, &ps, &input, &output, &locals,
+                                    &params);
+
+      /* Read scattering.  */
+      transform_done = graphite_read_scatt (file, pbb);
+
+      /* Scattering names.  */
+      openscop_read_one_int (file);
+
+      /* Read access functions.  */
+      if (openscop_read_one_int (file) > 0)
+       {
+         nbr = openscop_read_one_int (file);
+
+         /* Read access functions.  */
+         for (j = 0; j < nbr; j++)
+           openscop_read_powerset_matrix (file, &ps, &input, &output, &locals,
+                                          &params);
+
+         nbw = openscop_read_one_int (file);
+
+         /* Write access functions.  */
+         for (j = 0; j < nbw; j++)
+           openscop_read_powerset_matrix (file, &ps, &input, &output, &locals,
+                                          &params);
+       }
+
+      /* Statement body.  */
+      openscop_read_one_int (file);
+    }
+
+  return transform_done;
+}
 
 /* Apply graphite transformations to all the basic blocks of SCOP.  */
 
@@ -442,6 +690,13 @@ apply_poly_transforms (scop_p scop)
 {
   bool transform_done = false;
 
+  /* This feature is only enabled in the Graphite branch.  */
+  if (0)
+    {
+      transform_done |= graphite_read_scop_file (dump_file, scop);
+      gcc_assert (graphite_legal_transform (scop));
+    }
+
   /* Generate code even if we did not apply any real transformation.
      This also allows to check the performance for the identity
      transformation: GIMPLE -> GRAPHITE -> GIMPLE
@@ -464,6 +719,10 @@ apply_poly_transforms (scop_p scop)
        transform_done |= scop_do_interchange (scop);
     }
 
+  /* This feature is only enabled in the Graphite branch.  */
+  if (0)
+    print_scop (dump_file, scop, 1);
+
   return transform_done;
 }