Patchwork [13/20] add pbb->schedule

login
register
mail settings
Submitter Sebastian Pop
Date Aug. 15, 2011, 7:12 a.m.
Message ID <1313392379-1525-13-git-send-email-sebpop@gmail.com>
Download mbox | patch
Permalink /patch/110000/
State New
Headers show

Comments

Sebastian Pop - Aug. 15, 2011, 7:12 a.m.
---
 gcc/graphite-poly.c         |    6 ++++
 gcc/graphite-poly.h         |    6 ++++
 gcc/graphite-sese-to-poly.c |   55 ++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 64 insertions(+), 3 deletions(-)

Patch

diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index ce0649b..3d81372 100644
--- a/gcc/graphite-poly.c
+++ b/gcc/graphite-poly.c
@@ -881,6 +881,9 @@  new_poly_bb (scop_p scop, void *black_box)
 
   PBB_DOMAIN (pbb) = NULL;
   pbb->domain = NULL;
+  pbb->schedule = NULL;
+  pbb->transformed = NULL;
+  pbb->saved = NULL;
   PBB_SCOP (pbb) = scop;
   pbb_set_black_box (pbb, black_box);
   PBB_TRANSFORMED (pbb) = NULL;
@@ -906,6 +909,9 @@  free_poly_bb (poly_bb_p pbb)
     ppl_delete_Pointset_Powerset_C_Polyhedron (PBB_DOMAIN (pbb));
 
   isl_set_free (pbb->domain);
+  isl_map_free (pbb->schedule);
+  isl_map_free (pbb->transformed);
+  isl_map_free (pbb->saved);
 
   if (PBB_TRANSFORMED (pbb))
     poly_scattering_free (PBB_TRANSFORMED (pbb));
diff --git a/gcc/graphite-poly.h b/gcc/graphite-poly.h
index 3483ef0..b6e5277 100644
--- a/gcc/graphite-poly.h
+++ b/gcc/graphite-poly.h
@@ -1521,6 +1521,9 @@  store_scattering_pbb (poly_bb_p pbb)
     poly_scattering_free (PBB_SAVED (pbb));
 
   PBB_SAVED (pbb) = poly_scattering_copy (PBB_TRANSFORMED (pbb));
+
+  isl_map_free (pbb->saved);
+  pbb->saved = isl_map_copy (pbb->transformed);
 }
 
 /* Stores the SCOP_TRANSFORMED_SCHEDULE to SCOP_SAVED_SCHEDULE.  */
@@ -1568,6 +1571,9 @@  restore_scattering_pbb (poly_bb_p pbb)
 
   poly_scattering_free (PBB_TRANSFORMED (pbb));
   PBB_TRANSFORMED (pbb) = poly_scattering_copy (PBB_SAVED (pbb));
+
+  isl_map_free (pbb->transformed);
+  pbb->transformed = isl_map_copy (pbb->saved);
 }
 
 /* Restores the scattering for all the pbbs in the SCOP.  */
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 20bcf1f..9407a8d 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -407,6 +407,16 @@  build_scop_bbs (scop_p scop)
   sbitmap_free (visited);
 }
 
+/* Return an ISL identifier for the polyhedral basic block PBB.  */
+
+static isl_id *
+isl_id_for_pbb (scop_p s, poly_bb_p pbb)
+{
+  char name[50];
+  snprintf (name, sizeof (name), "S_%d", pbb_index (pbb));
+  return isl_id_alloc (s->ctx, name, pbb);
+}
+
 /* Converts the STATIC_SCHEDULE of PBB into a scattering polyhedron.
    We generate SCATTERING_DIMENSIONS scattering dimensions.
 
@@ -441,7 +451,8 @@  build_scop_bbs (scop_p scop)
    | 0   0   1   0   0   0   0   0  -5  = 0  */
 
 static void
-build_pbb_scattering_polyhedrons (ppl_Linear_Expression_t static_schedule,
+build_pbb_scattering_polyhedrons (isl_aff *static_sched,
+				  ppl_Linear_Expression_t static_schedule,
 				  poly_bb_p pbb, int scattering_dimensions)
 {
   int i;
@@ -452,9 +463,11 @@  build_pbb_scattering_polyhedrons (ppl_Linear_Expression_t static_schedule,
   ppl_Coefficient_t c;
   ppl_dimension_type dim = scattering_dimensions + nb_iterators + nb_params;
   mpz_t v;
+  isl_int val;
 
   gcc_assert (scattering_dimensions >= used_scattering_dimensions);
 
+  isl_int_init (val);
   mpz_init (v);
   ppl_new_Coefficient (&c);
   PBB_TRANSFORMED (pbb) = poly_scattering_new ();
@@ -463,6 +476,15 @@  build_pbb_scattering_polyhedrons (ppl_Linear_Expression_t static_schedule,
 
   PBB_NB_SCATTERING_TRANSFORM (pbb) = scattering_dimensions;
 
+  {
+    isl_dim *dc = isl_set_get_dim (pbb->domain);
+    isl_dim *dm = isl_dim_add (isl_dim_from_domain (dc),
+			       isl_dim_out, scattering_dimensions);
+    pbb->schedule = isl_map_universe (dm);
+    pbb->schedule = isl_map_set_tuple_id (pbb->schedule, isl_dim_in,
+					  isl_id_for_pbb (scop, pbb));
+  }
+
   for (i = 0; i < scattering_dimensions; i++)
     {
       ppl_Constraint_t cstr;
@@ -481,6 +503,20 @@  build_pbb_scattering_polyhedrons (ppl_Linear_Expression_t static_schedule,
 	  mpz_neg (v, v);
 	  ppl_assign_Coefficient_from_mpz_t (c, v);
 	  ppl_Linear_Expression_add_to_inhomogeneous (expr, c);
+
+	  {
+	    isl_constraint *c = isl_equality_alloc
+	      (isl_map_get_dim (pbb->schedule));
+
+	    if (0 != isl_aff_get_coefficient (static_sched, isl_dim_set,
+					      i / 2, &val))
+	      gcc_unreachable ();
+
+	    isl_int_neg (val, val);
+	    c = isl_constraint_set_constant (c, val);
+	    c = isl_constraint_set_coefficient_si (c, isl_dim_out, i, 1);
+	    pbb->schedule = isl_map_add_constraint (pbb->schedule, c);
+	  }
 	}
 
       /* Iterations of this loop.  */
@@ -492,6 +528,10 @@  build_pbb_scattering_polyhedrons (ppl_Linear_Expression_t static_schedule,
 	  ppl_assign_Coefficient_from_mpz_t (c, v);
 	  ppl_Linear_Expression_add_to_coefficient
 	    (expr, scattering_dimensions + loop, c);
+
+	  loop = (i + 1) / 2;
+	  pbb->schedule = isl_map_equate (pbb->schedule, isl_dim_in, loop,
+					  isl_dim_out, i);
 	}
 
       ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_EQUAL);
@@ -500,10 +540,12 @@  build_pbb_scattering_polyhedrons (ppl_Linear_Expression_t static_schedule,
       ppl_delete_Constraint (cstr);
     }
 
+  isl_int_clear (val);
   mpz_clear (v);
   ppl_delete_Coefficient (c);
 
   PBB_ORIGINAL (pbb) = poly_scattering_copy (PBB_TRANSFORMED (pbb));
+  pbb->transformed = isl_map_copy (pbb->schedule);
 }
 
 /* Build for BB the static schedule.
@@ -551,6 +593,8 @@  build_scop_scattering (scop_p scop)
   ppl_Linear_Expression_t static_schedule;
   ppl_Coefficient_t c;
   mpz_t v;
+  isl_dim *dc = isl_set_get_dim (scop->context);
+  isl_aff *static_sched = isl_aff_zero (isl_local_space_from_dim (dc));
 
   mpz_init (v);
   ppl_new_Coefficient (&c);
@@ -564,6 +608,8 @@  build_scop_scattering (scop_p scop)
   ppl_assign_Coefficient_from_mpz_t (c, v);
   ppl_Linear_Expression_add_to_coefficient (static_schedule, 0, c);
 
+  static_sched = isl_aff_add_coefficient_si (static_sched, isl_dim_set, 0, -1);
+
   FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
     {
       gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
@@ -587,11 +633,14 @@  build_scop_scattering (scop_p scop)
       ppl_assign_Linear_Expression_from_Linear_Expression (static_schedule,
 							   common);
 
-      build_pbb_scattering_polyhedrons (common, pbb, nb_scat_dims);
-
+      static_sched = isl_aff_add_coefficient_si (static_sched, isl_dim_set,
+						 prefix, 1);
+      build_pbb_scattering_polyhedrons (static_sched, common, pbb,
+					nb_scat_dims);
       ppl_delete_Linear_Expression (common);
     }
 
+  isl_aff_free (static_sched);
   mpz_clear (v);
   ppl_delete_Coefficient (c);
   ppl_delete_Linear_Expression (static_schedule);