OSDN Git Service

* lib/gcc-simulate-thread.exp (simulate-thread): Improve error message.
[pf3gnuchains/gcc-fork.git] / gcc / graphite-poly.c
index 96a0a70..db5b0cb 100644 (file)
@@ -21,35 +21,19 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "ggc.h"
-#include "tree.h"
-#include "rtl.h"
-#include "output.h"
-#include "basic-block.h"
-#include "diagnostic.h"
-#include "tree-pretty-print.h"
-#include "gimple-pretty-print.h"
+#include "diagnostic-core.h"
 #include "tree-flow.h"
-#include "toplev.h"
 #include "tree-dump.h"
-#include "timevar.h"
+#include "gimple-pretty-print.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 "params.h"
+#include "sese.h"
 
 #ifdef HAVE_cloog
 #include "ppl_c.h"
-#include "sese.h"
 #include "graphite-ppl.h"
-#include "graphite.h"
 #include "graphite-poly.h"
 #include "graphite-dependences.h"
 #include "graphite-cloog-util.h"
@@ -606,7 +590,7 @@ graphite_read_scop_file (FILE *file, scop_p scop)
 
   if (strcmp (tmp, "SCoP 1"))
     {
-      error ("The file is not in OpenScop format.\n");
+      error ("the file is not in OpenScop format");
       return false;
     }
 
@@ -617,7 +601,7 @@ graphite_read_scop_file (FILE *file, scop_p scop)
 
   if (strcmp (language, "Gimple"))
     {
-      error ("The language is not recognized\n");
+      error ("the language is not recognized");
       return false;
     }
 
@@ -628,8 +612,8 @@ graphite_read_scop_file (FILE *file, scop_p scop)
 
   if ((size_t) params != scop->nb_params)
     {
-      error ("Parameters number in the scop file is different from the"
-            " internal scop parameter number.");
+      error ("parameters number in the scop file is different from the"
+            " internal scop parameter number");
       return false;
     }
 
@@ -641,8 +625,8 @@ graphite_read_scop_file (FILE *file, scop_p scop)
 
   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.");
+      error ("number of statements in the OpenScop file does not match"
+            " the graphite internal statements number");
       return false;
     }
 
@@ -753,7 +737,15 @@ apply_poly_transforms (scop_p 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));
+
+      /* We cannot check for the legality of the transform here: there
+        are cases where graphite_legal_transform cannot determine the
+        dependence at compile time.  For an example, see the
+        explanation of why http://gcc.gnu.org/PR45450 is invalid.  */
+      if (0 && !graphite_legal_transform (scop))
+       fatal_error ("the graphite file read for scop %d does not contain a legal transform",
+                    (int) file_scop_number);
+
       file_scop_number++;
     }
 
@@ -773,12 +765,15 @@ apply_poly_transforms (scop_p scop)
   else
     {
       if (flag_loop_strip_mine)
-       transform_done |= scop_do_strip_mine (scop);
+       transform_done |= scop_do_strip_mine (scop, 0);
 
       if (flag_loop_interchange)
        transform_done |= scop_do_interchange (scop);
     }
 
+  if (flag_loop_flatten)
+    transform_done |= flatten_all_loops (scop);
+
   /* This feature is only enabled in the Graphite branch.  */
   if (0)
     {
@@ -822,15 +817,16 @@ pbb_remove_duplicate_pdrs (poly_bb_p pbb)
 {
   int i, j;
   poly_dr_p pdr1, pdr2;
-  unsigned n = VEC_length (poly_dr_p, PBB_DRS (pbb));
-  VEC (poly_dr_p, heap) *collapsed = VEC_alloc (poly_dr_p, heap, n);
 
   FOR_EACH_VEC_ELT (poly_dr_p, PBB_DRS (pbb), i, pdr1)
-    FOR_EACH_VEC_ELT (poly_dr_p, collapsed, j, pdr2)
-      if (!can_collapse_pdrs (pdr1, pdr2))
-       VEC_quick_push (poly_dr_p, collapsed, pdr1);
+    for (j = i + 1; VEC_iterate (poly_dr_p, PBB_DRS (pbb), j, pdr2); j++)
+      if (can_collapse_pdrs (pdr1, pdr2))
+       {
+         PDR_NB_REFS (pdr1) += PDR_NB_REFS (pdr2);
+         free_poly_dr (pdr2);
+         VEC_ordered_remove (poly_dr_p, PBB_DRS (pbb), j);
+       }
 
-  VEC_free (poly_dr_p, heap, collapsed);
   PBB_PDR_DUPLICATES_REMOVED (pbb) = true;
 }
 
@@ -868,8 +864,8 @@ free_poly_dr (poly_dr_p pdr)
 
 /* Create a new polyhedral black box.  */
 
-void
-new_poly_bb (scop_p scop, void *black_box, bool reduction)
+poly_bb_p
+new_poly_bb (scop_p scop, void *black_box)
 {
   poly_bb_p pbb = XNEW (struct poly_bb);
 
@@ -880,9 +876,11 @@ new_poly_bb (scop_p scop, void *black_box, bool reduction)
   PBB_SAVED (pbb) = NULL;
   PBB_ORIGINAL (pbb) = NULL;
   PBB_DRS (pbb) = VEC_alloc (poly_dr_p, heap, 3);
-  PBB_IS_REDUCTION (pbb) = reduction;
+  PBB_IS_REDUCTION (pbb) = false;
   PBB_PDR_DUPLICATES_REMOVED (pbb) = false;
-  VEC_safe_push (poly_bb_p, heap, SCOP_BBS (scop), pbb);
+  GBB_PBB ((gimple_bb_p) black_box) = pbb;
+
+  return pbb;
 }
 
 /* Free polyhedral black box.  */
@@ -1249,13 +1247,16 @@ print_pbb_body (FILE *file, poly_bb_p pbb, int verbosity,
     fprintf (file, "# Body (\n");
 
   if (!statement_body_provided)
-  {
-    if (verbosity > 0)
-      fprintf (file, "# Statement body is not provided\n");
+    {
+      if (verbosity > 0)
+       fprintf (file, "# Statement body is not provided\n");
 
-   fprintf (file, "0\n");
-   return;
-  }
+      fprintf (file, "0\n");
+
+      if (verbosity > 1)
+       fprintf (file, "#)\n");
+      return;
+    }
 
   if (verbosity > 0)
     fprintf (file, "# Statement body is provided\n");
@@ -1394,12 +1395,14 @@ print_scop_context (FILE *file, scop_p scop, int verbosity)
     fprintf (file, "# )\n");
 }
 
-/* Print to FILE the SCOP header: context, parameters, and statements
-   number.  */
+/* Print to FILE the SCOP, at some VERBOSITY level.  */
 
-static void
-print_scop_header (FILE *file, scop_p scop, int verbosity)
+void
+print_scop (FILE *file, scop_p scop, int verbosity)
 {
+  int i;
+  poly_bb_p pbb;
+
   fprintf (file, "SCoP 1\n#(\n");
   fprintf (file, "# Language\nGimple\n");
   openscop_print_scop_context (file, scop, verbosity);
@@ -1409,17 +1412,6 @@ print_scop_header (FILE *file, scop_p scop, int verbosity)
     fprintf (file, "# Number of statements\n");
 
   fprintf (file, "%d\n",VEC_length (poly_bb_p, SCOP_BBS (scop)));
-}
-
-/* Print to FILE the SCOP, at some VERBOSITY level.  */
-
-void
-print_scop (FILE *file, scop_p scop, int verbosity)
-{
-  int i;
-  poly_bb_p pbb;
-
-  print_scop_header (file, scop, verbosity);
 
   FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
     print_pbb (file, pbb, verbosity);
@@ -1627,72 +1619,120 @@ psct_scattering_dim_for_loop_depth (poly_bb_p pbb, graphite_dim_t loop_depth)
   gcc_unreachable ();
 }
 
-/* Returns the number of iterations NITER of the loop around PBB at
-   depth LOOP_DEPTH.  */
-
-void
-pbb_number_of_iterations (poly_bb_p pbb,
-                         graphite_dim_t loop_depth,
-                         mpz_t niter)
-{
-  ppl_Linear_Expression_t le;
-  ppl_dimension_type dim;
-
-  ppl_Pointset_Powerset_C_Polyhedron_space_dimension (PBB_DOMAIN (pbb), &dim);
-  ppl_new_Linear_Expression_with_dimension (&le, dim);
-  ppl_set_coef (le, pbb_iterator_dim (pbb, loop_depth), 1);
-  mpz_set_si (niter, -1);
-  ppl_max_for_le_pointset (PBB_DOMAIN (pbb), le, niter);
-  ppl_delete_Linear_Expression (le);
-}
-
-/* Returns the number of iterations NITER of the loop around PBB at
+/* Returns the number of iterations RES of the loop around PBB at
    time(scattering) dimension TIME_DEPTH.  */
 
 void
 pbb_number_of_iterations_at_time (poly_bb_p pbb,
                                  graphite_dim_t time_depth,
-                                 mpz_t niter)
+                                 mpz_t res)
 {
-  ppl_Pointset_Powerset_C_Polyhedron_t ext_domain, sctr;
+  ppl_Pointset_Powerset_C_Polyhedron_t domain, sctr_lb, sctr_ub;
+  ppl_dimension_type domain_dim, sctr_dim;
+  graphite_dim_t dim_iter_domain = pbb_dim_iter_domain (pbb);
   ppl_Linear_Expression_t le;
-  ppl_dimension_type dim;
+  mpz_t lb, ub, diff, one;
+  int i;
 
-  /* Takes together domain and scattering polyhedrons, and composes
-     them into the bigger polyhedron that has the following format:
+  ppl_Polyhedron_space_dimension (PBB_TRANSFORMED_SCATTERING (pbb), &sctr_dim);
 
-     t0..t_{n-1} | l0..l_{nlcl-1} | i0..i_{niter-1} | g0..g_{nparm-1}
+  ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
+    (&domain, PBB_DOMAIN (pbb));
 
-     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_Pointset_Powerset_C_Polyhedron_space_dimension (domain, &domain_dim);
 
-  ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sctr,
-      PBB_TRANSFORMED_SCATTERING (pbb));
+  mpz_init (diff);
+  mpz_init (lb);
+  mpz_init (ub);
+  mpz_init (one);
+  mpz_set_si (one, 1);
 
-  /* 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));
+  /* Compute the upper bound on the original iteration domain and add
+     that upper bound to the scattering.  */
+  ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron
+    (&sctr_ub, PBB_TRANSFORMED_SCATTERING (pbb));
+  for (i = 0; i < (int) dim_iter_domain; i++)
+    {
+      ppl_Linear_Expression_t eq;
+      ppl_Constraint_t pc;
+      ppl_Constraint_System_t cs;
+      ppl_Polyhedron_t ph;
+      ppl_Pointset_Powerset_C_Polyhedron_t pph;
+
+      ppl_new_Linear_Expression_with_dimension (&le, domain_dim);
+      ppl_set_coef (le, i, 1);
+      ppl_min_for_le_pointset (domain, le, lb);
+      ppl_max_for_le_pointset (domain, le, ub);
+      mpz_sub (diff, ub, lb);
+      mpz_add (diff, diff, one);
+
+      ppl_new_Linear_Expression_with_dimension (&eq, sctr_dim);
+      ppl_set_coef (eq, psct_iterator_dim (pbb, i), -1);
+      ppl_set_inhomogeneous_gmp (eq, diff);
+
+      ppl_new_Constraint (&pc, eq, PPL_CONSTRAINT_TYPE_EQUAL);
+      ppl_new_Constraint_System_from_Constraint (&cs, pc);
+      ppl_new_C_Polyhedron_from_Constraint_System (&ph, cs);
+      ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&pph, ph);
+      ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr_ub, pph);
+
+      ppl_delete_Linear_Expression (le);
+      ppl_delete_Linear_Expression (eq);
+      ppl_delete_Polyhedron (ph);
+      ppl_delete_Pointset_Powerset_C_Polyhedron (pph);
+      ppl_delete_Constraint (pc);
+      ppl_delete_Constraint_System (cs);
+    }
 
-  /* Add to sctr the extended domain.  */
-  ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr, ext_domain);
+  /* Compute the lower bound on the original iteration domain and add
+     it to the scattering.  */
+  ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron
+    (&sctr_lb, PBB_TRANSFORMED_SCATTERING (pbb));
+  for (i = 0; i < (int) dim_iter_domain; i++)
+    {
+      ppl_Linear_Expression_t eq;
+      ppl_Constraint_t pc;
+      ppl_Constraint_System_t cs;
+      ppl_Polyhedron_t ph;
+      ppl_Pointset_Powerset_C_Polyhedron_t pph;
+
+      ppl_new_Linear_Expression_with_dimension (&le, domain_dim);
+      ppl_set_coef (le, i, 1);
+      ppl_min_for_le_pointset (domain, le, lb);
+
+      ppl_new_Linear_Expression_with_dimension (&eq, sctr_dim);
+      ppl_set_coef (eq, psct_iterator_dim (pbb, i), -1);
+      ppl_set_inhomogeneous_gmp (eq, lb);
+
+      ppl_new_Constraint (&pc, eq, PPL_CONSTRAINT_TYPE_EQUAL);
+      ppl_new_Constraint_System_from_Constraint (&cs, pc);
+      ppl_new_C_Polyhedron_from_Constraint_System (&ph, cs);
+      ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&pph, ph);
+      ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr_lb, pph);
+
+      ppl_delete_Linear_Expression (le);
+      ppl_delete_Linear_Expression (eq);
+      ppl_delete_Polyhedron (ph);
+      ppl_delete_Pointset_Powerset_C_Polyhedron (pph);
+      ppl_delete_Constraint (pc);
+      ppl_delete_Constraint_System (cs);
+    }
 
   /* Extract the number of iterations.  */
-  ppl_Pointset_Powerset_C_Polyhedron_space_dimension (sctr, &dim);
-  ppl_new_Linear_Expression_with_dimension (&le, dim);
+  ppl_new_Linear_Expression_with_dimension (&le, sctr_dim);
   ppl_set_coef (le, time_depth, 1);
-  mpz_set_si (niter, -1);
-  ppl_max_for_le_pointset (sctr, le, niter);
+  ppl_min_for_le_pointset (sctr_lb, le, lb);
+  ppl_max_for_le_pointset (sctr_ub, le, ub);
+  mpz_sub (res, ub, lb);
 
+  mpz_clear (one);
+  mpz_clear (diff);
+  mpz_clear (lb);
+  mpz_clear (ub);
   ppl_delete_Linear_Expression (le);
-  ppl_delete_Pointset_Powerset_C_Polyhedron (sctr);
-  ppl_delete_Pointset_Powerset_C_Polyhedron (ext_domain);
+  ppl_delete_Pointset_Powerset_C_Polyhedron (sctr_ub);
+  ppl_delete_Pointset_Powerset_C_Polyhedron (sctr_lb);
+  ppl_delete_Pointset_Powerset_C_Polyhedron (domain);
 }
 
 /* Translates LOOP to LST.  */
@@ -1872,5 +1912,23 @@ dot_lst (lst_p lst)
 #endif
 }
 
+/* Computes a checksum for the code generated by CLooG for SCOP.  */
+
+DEBUG_FUNCTION void
+cloog_checksum (scop_p scop ATTRIBUTE_UNUSED)
+{
+  /* When debugging, enable the following code.  This cannot be used
+     in production compilers because it calls "system".  */
+#if 0
+  FILE *stream = fopen ("/tmp/scop.cloog", "w");
+  gcc_assert (stream);
+  print_cloog (stream, scop, 0);
+  fclose (stream);
+
+  fputs ("\n", stdout);
+  system ("cloog -compilable 1 /tmp/scop.cloog > /tmp/scop.c ; gcc -O0 -g /tmp/scop.c -lm -o /tmp/scop; /tmp/scop | md5sum ");
+#endif
+}
+
 #endif