diff mbox

[3/4,graphite] add tiling on schedule trees

Message ID 1450460511-18925-3-git-send-email-s.pop@samsung.com
State New
Headers show

Commit Message

Sebastian Pop Dec. 18, 2015, 5:41 p.m. UTC
---
 gcc/graphite-optimize-isl.c | 96 ++++++++++++++++++++++++++++++++++++++++-----
 gcc/graphite-poly.c         | 19 +++++++++
 gcc/graphite.h              |  2 +
 gcc/params.def              |  2 +-
 4 files changed, 108 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
index 7c3bfcf..9d185c6 100644
--- a/gcc/graphite-optimize-isl.c
+++ b/gcc/graphite-optimize-isl.c
@@ -48,6 +48,71 @@  optimize_isl (scop_p scop ATTRIBUTE_UNUSED)
 }
 #else
 
+static isl_schedule_node *
+tile_node (__isl_take isl_schedule_node *node)
+{
+  isl_ctx *ctx = isl_schedule_node_get_ctx (node);
+  isl_space *space = isl_schedule_node_band_get_space (node);
+  unsigned dims = isl_space_dim (space, isl_dim_set);
+  isl_multi_val *sizes = isl_multi_val_zero (space);
+
+  for (unsigned i = 0; i < dims; i++)
+    {
+      isl_val *tile_size = isl_val_int_from_si
+	(ctx, PARAM_VALUE (PARAM_LOOP_BLOCK_TILE_SIZE));
+      sizes = isl_multi_val_set_val (sizes, i, tile_size);
+    }
+
+  isl_id *id1 = isl_id_alloc (ctx, "tile", NULL);
+  node = isl_schedule_node_insert_mark
+    (node, id1);
+  node = isl_schedule_node_child (node, 0);
+  node = isl_schedule_node_band_tile (node, sizes);
+  node = isl_schedule_node_child (node, 0);
+  isl_id *id2 = isl_id_alloc (ctx, "point", NULL);
+  node = isl_schedule_node_insert_mark
+    (node, id2);
+
+  return isl_schedule_node_child (node, 0);
+}
+
+static bool is_tileable_node (__isl_keep isl_schedule_node *node)
+{
+  if (isl_schedule_node_get_type (node) != isl_schedule_node_band)
+    return false;
+
+  if (isl_schedule_node_n_children (node) != 1)
+    return false;
+
+  if (!isl_schedule_node_band_get_permutable (node))
+    return false;
+
+  isl_space *space = isl_schedule_node_band_get_space (node);
+  unsigned dims = isl_space_dim (space, isl_dim_set);
+  isl_space_free (space);
+
+  if (dims <= 1)
+    return false;
+
+  isl_schedule_node *child = isl_schedule_node_get_child (node, 0);
+  enum isl_schedule_node_type type = isl_schedule_node_get_type (child);
+  isl_schedule_node_free (child);
+
+  if (type != isl_schedule_node_leaf)
+    return false;
+
+  return true;
+}
+
+static isl_schedule_node *
+optimize_node (__isl_take isl_schedule_node *node, void *user ATTRIBUTE_UNUSED)
+{
+  if (is_tileable_node (node))
+    return tile_node (node);
+
+  return node;
+}
+
 static isl_union_set *
 scop_get_domains (scop_p scop)
 {
@@ -62,8 +127,6 @@  scop_get_domains (scop_p scop)
   return res;
 }
 
-static const int CONSTANT_BOUND = 20;
-
 /* Compute the schedule for SCOP based on its parameters, domain and set of
    constraints.  Then apply the schedule to SCOP.  */
 
@@ -85,15 +148,13 @@  optimize_isl (scop_p scop)
   isl_union_map *validity = isl_union_map_copy (scop->dependence);
   isl_union_map *proximity = isl_union_map_copy (validity);
 
-  isl_options_set_schedule_max_constant_term (scop->isl_context, CONSTANT_BOUND);
-  isl_options_set_schedule_maximize_band_depth (scop->isl_context, 1);
-  isl_options_set_schedule_serialize_sccs (scop->isl_context, 0);
+  isl_options_set_schedule_serialize_sccs (scop->isl_context, 1);
   isl_options_set_schedule_maximize_band_depth (scop->isl_context, 1);
   isl_options_set_schedule_max_constant_term (scop->isl_context, 20);
   isl_options_set_schedule_max_coefficient (scop->isl_context, 20);
   isl_options_set_tile_scale_tile_loops (scop->isl_context, 0);
-  isl_options_set_coalesce_bounded_wrapping (scop->isl_context, 1);
-  isl_options_set_ast_build_exploit_nested_bounds (scop->isl_context, 1);
+  //isl_options_set_coalesce_bounded_wrapping (scop->isl_context, 1);
+  //isl_options_set_ast_build_exploit_nested_bounds (scop->isl_context, 1);
   isl_options_set_ast_build_atomic_upper_bound (scop->isl_context, 1);
 
   /* FIXME: the use of isl_union_set_compute_schedule is discouraged in isl
@@ -114,9 +175,24 @@  optimize_isl (scop_p scop)
       return false;
     }
 
-  /* Attach the schedule to scop so that it can be used in code generation.
-     schedule freeing will occur in code generation.  */
-  scop->schedule = schedule;
+  if (dump_file)
+    {
+      fprintf (dump_file, "schedule before tiling:\n");
+      print_isl_schedule (dump_file, schedule);
+    }
+
+  isl_schedule_node *root = isl_schedule_get_root (schedule);
+  root = isl_schedule_node_map_descendant_bottom_up (root, optimize_node, NULL);
+  scop->schedule = isl_schedule_node_get_schedule (root);
+
+  if (dump_file)
+    {
+      fprintf (dump_file, "schedule after tiling:\n");
+      print_isl_schedule (dump_file, scop->schedule);
+    }
+
+  isl_schedule_free (schedule);
+  isl_schedule_node_free (root);
   return true;
 }
 #endif /* HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS */
diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index ff451b8..73356f2 100644
--- a/gcc/graphite-poly.c
+++ b/gcc/graphite-poly.c
@@ -541,6 +541,7 @@  void
 print_isl_set (FILE *f, isl_set *set)
 {
   isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
+  p = isl_printer_set_yaml_style (p, ISL_YAML_STYLE_BLOCK);
   p = isl_printer_print_set (p, set);
   p = isl_printer_print_str (p, "\n");
   isl_printer_free (p);
@@ -556,6 +557,7 @@  void
 print_isl_map (FILE *f, isl_map *map)
 {
   isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
+  p = isl_printer_set_yaml_style (p, ISL_YAML_STYLE_BLOCK);
   p = isl_printer_print_map (p, map);
   p = isl_printer_print_str (p, "\n");
   isl_printer_free (p);
@@ -571,6 +573,7 @@  void
 print_isl_union_map (FILE *f, isl_union_map *map)
 {
   isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
+  p = isl_printer_set_yaml_style (p, ISL_YAML_STYLE_BLOCK);
   p = isl_printer_print_union_map (p, map);
   p = isl_printer_print_str (p, "\n");
   isl_printer_free (p);
@@ -613,6 +616,22 @@  debug_isl_constraint (isl_constraint *c)
   print_isl_constraint (stderr, c);
 }
 
+void
+print_isl_schedule (FILE *f, isl_schedule *s)
+{
+  isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
+  p = isl_printer_set_yaml_style (p, ISL_YAML_STYLE_BLOCK);
+  p = isl_printer_print_schedule (p, s);
+  p = isl_printer_print_str (p, "\n");
+  isl_printer_free (p);
+}
+
+DEBUG_FUNCTION void
+debug_isl_schedule (isl_schedule *s)
+{
+  print_isl_schedule (stderr, s);
+}
+
 /* Returns the number of iterations RES of the loop around PBB at
    time(scattering) dimension TIME_DEPTH.  */
 
diff --git a/gcc/graphite.h b/gcc/graphite.h
index 83f8191..2e07a89 100644
--- a/gcc/graphite.h
+++ b/gcc/graphite.h
@@ -317,6 +317,8 @@  extern void print_isl_map (FILE *, isl_map *);
 extern void print_isl_union_map (FILE *, isl_union_map *);
 extern void print_isl_aff (FILE *, isl_aff *);
 extern void print_isl_constraint (FILE *, isl_constraint *);
+extern void print_isl_schedule (FILE *, isl_schedule *);
+extern void debug_isl_schedule (isl_schedule *);
 extern void debug_isl_set (isl_set *);
 extern void debug_isl_map (isl_map *);
 extern void debug_isl_union_map (isl_union_map *);
diff --git a/gcc/params.def b/gcc/params.def
index 9b82164..98081b9 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -833,7 +833,7 @@  DEFPARAM (PARAM_SWITCH_CONVERSION_BRANCH_RATIO,
 DEFPARAM (PARAM_LOOP_BLOCK_TILE_SIZE,
 	  "loop-block-tile-size",
 	  "size of tiles for loop blocking.",
-	  51, 0, 0)
+	  32, 0, 0)
 
 /* Maximal number of parameters that we allow in a SCoP.  */