New unroll and jam option in Graphite.
[gcc.git] / gcc / graphite-isl-ast-to-gimple.c
index 46ccbf4fd05e481efcfd80180c552553e2a87cd8..bbf30550e94ac1c01a32e3996450a35667a870e3 100644 (file)
@@ -831,6 +831,92 @@ extend_schedule (__isl_take isl_map *schedule, int nb_schedule_dims)
   return schedule;
 }
 
+/* Set the separation_class option for unroll and jam. */
+
+static __isl_give isl_union_map *
+generate_luj_sepclass_opt (scop_p scop, __isl_take isl_union_set *domain, 
+                       int dim, int cl)
+{
+  isl_map  *map;
+  isl_space *space, *space_sep;
+  isl_ctx *ctx;
+  isl_union_map *mapu;
+  int nsched = get_max_schedule_dimensions (scop);
+  ctx = scop->ctx;
+  space_sep = isl_space_alloc (ctx, 0, 1, 1);
+  space_sep = isl_space_wrap (space_sep);
+  space_sep = isl_space_set_tuple_name (space_sep, isl_dim_set,
+                                       "separation_class");
+  space = isl_set_get_space (scop->context);
+  space_sep = isl_space_align_params (space_sep, isl_space_copy(space));
+  space = isl_space_map_from_domain_and_range (space, space_sep);
+  space = isl_space_add_dims (space,isl_dim_in, nsched);
+  map = isl_map_universe (space);
+  isl_map_fix_si (map,isl_dim_out,0,dim);
+  isl_map_fix_si (map,isl_dim_out,1,cl);
+
+  mapu = isl_union_map_intersect_domain (isl_union_map_from_map (map), 
+                                        domain);
+  return (mapu);
+}
+
+/* Compute the separation class for loop unroll and jam.  */
+
+static __isl_give isl_union_set *
+generate_luj_sepclass (scop_p scop)
+{
+  int i;
+  poly_bb_p pbb;
+  isl_union_set *domain_isl;
+
+  domain_isl = isl_union_set_empty (isl_set_get_space (scop->context));
+
+  FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb)
+    {
+      isl_set *bb_domain;
+      isl_set *bb_domain_s;
+
+      if (pbb->map_sepclass == NULL)
+       continue;
+
+      if (isl_set_is_empty (pbb->domain))
+       continue;
+
+      bb_domain = isl_set_copy (pbb->domain);
+      bb_domain_s = isl_set_apply (bb_domain, pbb->map_sepclass);
+      pbb->map_sepclass = NULL;
+
+      domain_isl =
+       isl_union_set_union (domain_isl, isl_union_set_from_set (bb_domain_s));
+    }
+
+  return domain_isl;
+}
+
+/* Set the AST built options for loop unroll and jam. */
+static __isl_give isl_union_map *
+generate_luj_options (scop_p scop)
+{
+  isl_union_set *domain_isl;
+  isl_union_map *options_isl_ss;
+  isl_union_map *options_isl =
+    isl_union_map_empty (isl_set_get_space (scop->context));
+  int dim = get_max_schedule_dimensions (scop) - 1;
+  int dim1 = dim - PARAM_VALUE (PARAM_LOOP_UNROLL_JAM_DEPTH);
+
+  if (!flag_loop_unroll_jam)
+    return options_isl;
+
+  domain_isl = generate_luj_sepclass (scop);
+
+  options_isl_ss = generate_luj_sepclass_opt (scop, domain_isl, dim1, 0);
+  options_isl = isl_union_map_union (options_isl, options_isl_ss);
+
+  return options_isl;
+}
+
 /* Generates a schedule, which specifies an order used to
    visit elements in a domain.  */
 
@@ -879,11 +965,13 @@ ast_build_before_for (__isl_keep isl_ast_build *build, void *user)
 }
 
 /* Set the separate option for all dimensions.
-   This helps to reduce control overhead.  */
+   This helps to reduce control overhead.
+   Set the options for unroll and jam.  */
 
 static __isl_give isl_ast_build *
 set_options (__isl_take isl_ast_build *control,
-            __isl_keep isl_union_map *schedule)
+            __isl_keep isl_union_map *schedule,
+            __isl_take isl_union_map *opt_luj)
 {
   isl_ctx *ctx = isl_union_map_get_ctx (schedule);
   isl_space *range_space = isl_space_set_alloc (ctx, 0, 1);
@@ -894,6 +982,9 @@ set_options (__isl_take isl_ast_build *control,
   isl_union_set *domain = isl_union_map_range (isl_union_map_copy (schedule));
   domain = isl_union_set_universe (domain);
   isl_union_map *options = isl_union_map_from_domain_and_range (domain, range);
+
+  options = isl_union_map_union (options, opt_luj);
+
   return isl_ast_build_set_options (control, options);
 }
 
@@ -907,9 +998,14 @@ scop_to_isl_ast (scop_p scop, ivs_params &ip)
   isl_options_set_ast_build_atomic_upper_bound (scop->ctx, true);
 
   add_parameters_to_ivs_params (scop, ip);
+
+  isl_union_map *options_luj = generate_luj_options (scop);
+
   isl_union_map *schedule_isl = generate_isl_schedule (scop);
   isl_ast_build *context_isl = generate_isl_context (scop);
-  context_isl = set_options (context_isl, schedule_isl);
+
+  context_isl = set_options (context_isl, schedule_isl, options_luj);
+
   isl_union_map *dependences = NULL;
   if (flag_loop_parallelize_all)
   {