isl_schedule.c: extract out isl_band_alloc
[platform/upstream/isl.git] / isl_band.c
index 4a0bf4e..b6624cf 100644 (file)
 
 #include <isl_band_private.h>
 #include <isl_schedule_private.h>
+#include <isl_list_private.h>
 
 isl_ctx *isl_band_get_ctx(__isl_keep isl_band *band)
 {
-       return band ? isl_union_map_get_ctx(band->map) : NULL;
+       return band ? isl_union_pw_multi_aff_get_ctx(band->pma) : NULL;
+}
+
+__isl_give isl_band *isl_band_alloc(isl_ctx *ctx)
+{
+       isl_band *band;
+
+       band = isl_calloc_type(ctx, isl_band);
+       if (!band)
+               return NULL;
+
+       band->ref = 1;
+
+       return band;
 }
 
 /* We not only increment the reference count of the band,
@@ -45,9 +59,9 @@ void *isl_band_free(__isl_take isl_band *band)
        if (--band->ref > 0)
                return isl_schedule_free(band->schedule);
 
-       isl_union_map_free(band->map);
+       isl_union_pw_multi_aff_free(band->pma);
        isl_band_list_free(band->children);
-       free(band->parallel);
+       free(band->zero);
        free(band);
 
        return NULL;
@@ -69,7 +83,7 @@ __isl_give isl_band_list *isl_band_get_children(
        if (!band->children)
                isl_die(isl_band_get_ctx(band), isl_error_invalid,
                        "band has no children", return NULL);
-       return isl_band_list_copy(band->children);
+       return isl_band_list_dup(band->children);
 }
 
 int isl_band_n_member(__isl_keep isl_band *band)
@@ -77,10 +91,10 @@ int isl_band_n_member(__isl_keep isl_band *band)
        return band ? band->n : 0;
 }
 
-/* Is the given scheduling dimension parallel within the band and
+/* Is the given scheduling dimension zero distance within the band and
  * with respect to the proximity dependences.
  */
-int isl_band_member_is_parallel(__isl_keep isl_band *band, int pos)
+int isl_band_member_is_zero_distance(__isl_keep isl_band *band, int pos)
 {
        if (!band)
                return -1;
@@ -89,7 +103,7 @@ int isl_band_member_is_parallel(__isl_keep isl_band *band, int pos)
                isl_die(isl_band_get_ctx(band), isl_error_invalid,
                        "invalid member position", return -1);
 
-       return band->parallel[pos];
+       return band->zero[pos];
 }
 
 /* Return the schedule that leads up to this band.
@@ -97,21 +111,34 @@ int isl_band_member_is_parallel(__isl_keep isl_band *band, int pos)
 __isl_give isl_union_map *isl_band_get_prefix_schedule(
        __isl_keep isl_band *band)
 {
-       isl_union_map *prefix;
+       isl_union_set *domain;
+       isl_union_pw_multi_aff *prefix;
        isl_band *a;
 
        if (!band)
                return NULL;
 
-       prefix = isl_union_map_copy(band->map);
-       prefix = isl_union_map_from_domain(isl_union_map_domain(prefix));
+       prefix = isl_union_pw_multi_aff_copy(band->pma);
+       domain = isl_union_pw_multi_aff_domain(prefix);
+       prefix = isl_union_pw_multi_aff_from_domain(domain);
 
        for (a = band->parent; a; a = a->parent) {
-               isl_union_map *partial = isl_union_map_copy(a->map);
-               prefix = isl_union_map_flat_range_product(partial, prefix);
+               isl_union_pw_multi_aff *partial;
+
+               partial = isl_union_pw_multi_aff_copy(a->pma);
+               prefix = isl_union_pw_multi_aff_flat_range_product(partial,
+                                                                  prefix);
        }
 
-       return prefix;
+       return isl_union_map_from_union_pw_multi_aff(prefix);
+}
+
+/* Return the schedule of the band in isolation.
+ */
+__isl_give isl_union_pw_multi_aff *
+isl_band_get_partial_schedule_union_pw_multi_aff(__isl_keep isl_band *band)
+{
+       return band ? isl_union_pw_multi_aff_copy(band->pma) : NULL;
 }
 
 /* Return the schedule of the band in isolation.
@@ -119,49 +146,105 @@ __isl_give isl_union_map *isl_band_get_prefix_schedule(
 __isl_give isl_union_map *isl_band_get_partial_schedule(
        __isl_keep isl_band *band)
 {
-       return band ? isl_union_map_copy(band->map) : NULL;
+       isl_union_pw_multi_aff *sched;
+
+       sched = isl_band_get_partial_schedule_union_pw_multi_aff(band);
+       return isl_union_map_from_union_pw_multi_aff(sched);
+}
+
+__isl_give isl_union_pw_multi_aff *
+isl_band_get_suffix_schedule_union_pw_multi_aff(__isl_keep isl_band *band);
+
+/* Return the schedule for the given band list.
+ * For each band in the list, the schedule is composed of the partial
+ * and suffix schedules of that band.
+ */
+__isl_give isl_union_pw_multi_aff *
+isl_band_list_get_suffix_schedule_union_pw_multi_aff(
+       __isl_keep isl_band_list *list)
+{
+       isl_ctx *ctx;
+       int i, n;
+       isl_space *space;
+       isl_union_pw_multi_aff *suffix;
+
+       if (!list)
+               return NULL;
+
+       ctx = isl_band_list_get_ctx(list);
+       space = isl_space_alloc(ctx, 0, 0, 0);
+       suffix = isl_union_pw_multi_aff_empty(space);
+       n = isl_band_list_n_band(list);
+       for (i = 0; i < n; ++i) {
+               isl_band *el;
+               isl_union_pw_multi_aff *partial;
+               isl_union_pw_multi_aff *suffix_i;
+
+               el = isl_band_list_get_band(list, i);
+               partial = isl_band_get_partial_schedule_union_pw_multi_aff(el);
+               suffix_i = isl_band_get_suffix_schedule_union_pw_multi_aff(el);
+               suffix_i = isl_union_pw_multi_aff_flat_range_product(
+                               partial, suffix_i);
+               suffix = isl_union_pw_multi_aff_add(suffix, suffix_i);
+
+               isl_band_free(el);
+       }
+
+       return suffix;
+}
+
+/* Return the schedule for the given band list.
+ * For each band in the list, the schedule is composed of the partial
+ * and suffix schedules of that band.
+ */
+__isl_give isl_union_map *isl_band_list_get_suffix_schedule(
+       __isl_keep isl_band_list *list)
+{
+       isl_union_pw_multi_aff *suffix;
+
+       suffix = isl_band_list_get_suffix_schedule_union_pw_multi_aff(list);
+       return isl_union_map_from_union_pw_multi_aff(suffix);
 }
 
 /* Return the schedule for the forest underneath the given band.
  */
-__isl_give isl_union_map *isl_band_get_suffix_schedule(
-       __isl_keep isl_band *band)
+__isl_give isl_union_pw_multi_aff *
+isl_band_get_suffix_schedule_union_pw_multi_aff(__isl_keep isl_band *band)
 {
-       isl_union_map *suffix;
+       isl_union_pw_multi_aff *suffix;
 
        if (!band)
                return NULL;
 
        if (!isl_band_has_children(band)) {
-               suffix = isl_union_map_copy(band->map);
-               suffix = isl_union_map_from_domain(isl_union_map_domain(suffix));
+               isl_union_set *domain;
+
+               suffix = isl_union_pw_multi_aff_copy(band->pma);
+               domain = isl_union_pw_multi_aff_domain(suffix);
+               suffix = isl_union_pw_multi_aff_from_domain(domain);
        } else {
-               int i, n;
-               isl_band_list *children;
-
-               suffix = isl_union_map_empty(isl_union_map_get_dim(band->map));
-               children = isl_band_get_children(band);
-               n = isl_band_list_n_band(children);
-               for (i = 0; i < n; ++i) {
-                       isl_band *child;
-                       isl_union_map *partial_i;
-                       isl_union_map *suffix_i;
-
-                       child = isl_band_list_get_band(children, i);
-                       partial_i = isl_band_get_partial_schedule(child);
-                       suffix_i = isl_band_get_suffix_schedule(child);
-                       suffix_i = isl_union_map_flat_range_product(partial_i,
-                                                                   suffix_i);
-                       suffix = isl_union_map_union(suffix, suffix_i);
-
-                       isl_band_free(child);
-               }
-               isl_band_list_free(children);
+               isl_band_list *list;
+
+               list = isl_band_get_children(band);
+               suffix =
+                   isl_band_list_get_suffix_schedule_union_pw_multi_aff(list);
+               isl_band_list_free(list);
        }
 
        return suffix;
 }
 
+/* Return the schedule for the forest underneath the given band.
+ */
+__isl_give isl_union_map *isl_band_get_suffix_schedule(
+       __isl_keep isl_band *band)
+{
+       isl_union_pw_multi_aff *suffix;
+
+       suffix = isl_band_get_suffix_schedule_union_pw_multi_aff(band);
+       return isl_union_map_from_union_pw_multi_aff(suffix);
+}
+
 __isl_give isl_printer *isl_printer_print_band(__isl_take isl_printer *p,
        __isl_keep isl_band *band)
 {
@@ -185,17 +268,3 @@ __isl_give isl_printer *isl_printer_print_band(__isl_take isl_printer *p,
 
        return p;
 }
-
-void isl_band_dump(__isl_keep isl_band *band)
-{
-       isl_printer *printer;
-
-       if (!band)
-               return;
-
-       printer = isl_printer_to_file(isl_band_get_ctx(band), stderr);
-       printer = isl_printer_print_band(printer, band);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}