diff mbox

[2/5] Dump each scop in a separate file.

Message ID 1282069224-21268-3-git-send-email-sebpop@gmail.com
State New
Headers show

Commit Message

Sebastian Pop Aug. 17, 2010, 6:20 p.m. UTC
2010-08-17  Riyadh Baghdadi <baghdadi.mr@gmail.com>

	* graphite-poly.c (init_graphite_out_file): New.
	(init_graphite_in_file): New.
	(apply_poly_transforms): Updated to enable reading and writing of
	multiple scop files.
	* toplev.c (init_asm_output): Remove graphite in/out file initialization.
---
 gcc/ChangeLog.graphite |    8 +++++
 gcc/graphite-poly.c    |   68 ++++++++++++++++++++++++++++++++++++++++++++++-
 gcc/toplev.c           |   35 +-----------------------
 3 files changed, 76 insertions(+), 35 deletions(-)
diff mbox

Patch

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index da76ef8..ccc8b9c 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,3 +1,11 @@ 
+2010-08-17  Riyadh Baghdadi <baghdadi.mr@gmail.com>
+
+	* graphite-poly.c (init_graphite_out_file): New.
+	(init_graphite_in_file): New.
+	(apply_poly_transforms): Updated to enable reading and writing of
+	multiple scop files.
+	* toplev.c (init_asm_output): Remove graphite in/out file initialization.
+
 2010-08-17  Tobias Grosser  <grosser@fim.uni-passau.de>
 
 	* graphite-scop-detection.c (graphite_can_represent_scev): Remove
diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index 8f08251..fc69e7c 100644
--- a/gcc/graphite-poly.c
+++ b/gcc/graphite-poly.c
@@ -683,17 +683,77 @@  graphite_read_scop_file (FILE *file, scop_p scop)
   return transform_done;
 }
 
+/* Initialize and return a file that will be used to write a scop.  SCOP_NUMBER
+   is a sequential number (identifier) used to differentiate scop files.
+   Examples of the generated file names: dump_base_name.0.graphite,
+   dump_base_name.1.graphite, dump_base_name.2.graphite, etc.  */
+
+static FILE *
+init_graphite_out_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, ".graphite");
+  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;
+}
+
+/* Open and return a file used for scop reading.  SCOP_NUMBER is a sequential
+   number (identifier) used to differentiate scop files.  Examples of the
+   generated file names: dump_base_name.0.graphite, dump_base_name.1.graphite,
+   dump_base_name.2.graphite, etc.  */
+
+static FILE *
+init_graphite_in_file (int scop_number)
+{
+  FILE *graphite_in_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, ".graphite");
+  graphite_in_file = fopen (dumpname, "r+b");
+
+  if (graphite_in_file == 0)
+    fatal_error ("can%'t open %s for reading: %m", dumpname);
+
+  free (dumpname);
+
+  return graphite_in_file;
+}
+
 /* Apply graphite transformations to all the basic blocks of SCOP.  */
 
 bool
 apply_poly_transforms (scop_p scop)
 {
   bool transform_done = false;
+  FILE *graphite_file;
+  static size_t file_scop_number = 0;
 
   if (flag_graphite_read)
     {
-      transform_done |= graphite_read_scop_file (graphite_in_file, scop);
+      graphite_file = init_graphite_in_file (file_scop_number);
+      transform_done |= graphite_read_scop_file (graphite_file, scop);
       gcc_assert (graphite_legal_transform (scop));
+      file_scop_number++;
     }
 
   /* Generate code even if we did not apply any real transformation.
@@ -719,7 +779,11 @@  apply_poly_transforms (scop_p scop)
     }
 
   if (flag_graphite_write)
-    print_scop (graphite_out_file, scop, 1);
+    {
+      graphite_file = init_graphite_out_file (file_scop_number);
+      print_scop (graphite_file, scop, 1);
+      file_scop_number++;
+    }
 
   return transform_done;
 }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 587c955..4f3f7fc 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -385,8 +385,6 @@  static const param_info lang_independent_params[] = {
    and debugging dumps.  */
 
 FILE *asm_out_file;
-FILE *graphite_out_file;
-FILE *graphite_in_file;
 FILE *aux_info_file;
 FILE *dump_file = NULL;
 const char *dump_file_name;
@@ -1454,37 +1452,8 @@  init_asm_output (const char *name)
 	fatal_error ("can%'t open %s for writing: %m", asm_file_name);
     }
 
-  if (flag_graphite_read)
-    {
-      int len = strlen (dump_base_name);
-      char *dumpname = XNEWVEC (char, len + 10);
-
-      gcc_assert (!flag_graphite_write);
-
-      memcpy (dumpname, dump_base_name, len + 1);
-      strip_off_ending (dumpname, len);
-      strcat (dumpname, ".graphite");
-      graphite_in_file = fopen (dumpname, "r+b");
-      if (graphite_in_file == 0)
-	fatal_error ("can%'t open %s for writing: %m", dumpname);
-      free (dumpname);
-    }
-
-  if (flag_graphite_write)
-    {
-      int len = strlen (dump_base_name);
-      char *dumpname = XNEWVEC (char, len + 10);
-
-      gcc_assert (!flag_graphite_read);
-
-      memcpy (dumpname, dump_base_name, len + 1);
-      strip_off_ending (dumpname, len);
-      strcat (dumpname, ".graphite");
-      graphite_out_file = fopen (dumpname, "w+b");
-      if (graphite_out_file == 0)
-	fatal_error ("can%'t open %s for writing: %m", dumpname);
-      free (dumpname);
-    }
+  if (flag_graphite_read && flag_graphite_write)
+    fatal_error ("cannot read and write the Graphite representation at the same time");
 
   if (!flag_syntax_only)
     {