2 * Copyright 2011 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
11 #include <isl_band_private.h>
12 #include <isl_schedule_private.h>
13 #include <isl_list_private.h>
15 isl_ctx *isl_band_get_ctx(__isl_keep isl_band *band)
17 return band ? isl_union_pw_multi_aff_get_ctx(band->pma) : NULL;
20 /* We not only increment the reference count of the band,
21 * but also that of the schedule that contains this band.
22 * This ensures that the schedule won't disappear while there
23 * is still a reference to the band outside of the schedule.
24 * There is no need to increment the reference count of the parent
25 * band as the parent band is part of the same schedule.
27 __isl_give isl_band *isl_band_copy(__isl_keep isl_band *band)
33 band->schedule->ref++;
37 /* If this is not the last reference to the band (the one from within the
38 * schedule), then we also need to decrement the reference count of the
39 * containing schedule as it was incremented in isl_band_copy.
41 void *isl_band_free(__isl_take isl_band *band)
47 return isl_schedule_free(band->schedule);
49 isl_union_pw_multi_aff_free(band->pma);
50 isl_band_list_free(band->children);
57 int isl_band_has_children(__isl_keep isl_band *band)
62 return band->children != NULL;
65 __isl_give isl_band_list *isl_band_get_children(
66 __isl_keep isl_band *band)
71 isl_die(isl_band_get_ctx(band), isl_error_invalid,
72 "band has no children", return NULL);
73 return isl_band_list_dup(band->children);
76 int isl_band_n_member(__isl_keep isl_band *band)
78 return band ? band->n : 0;
81 /* Is the given scheduling dimension zero distance within the band and
82 * with respect to the proximity dependences.
84 int isl_band_member_is_zero_distance(__isl_keep isl_band *band, int pos)
89 if (pos < 0 || pos >= band->n)
90 isl_die(isl_band_get_ctx(band), isl_error_invalid,
91 "invalid member position", return -1);
93 return band->zero[pos];
96 /* Return the schedule that leads up to this band.
98 __isl_give isl_union_map *isl_band_get_prefix_schedule(
99 __isl_keep isl_band *band)
101 isl_union_set *domain;
102 isl_union_pw_multi_aff *prefix;
108 prefix = isl_union_pw_multi_aff_copy(band->pma);
109 domain = isl_union_pw_multi_aff_domain(prefix);
110 prefix = isl_union_pw_multi_aff_from_domain(domain);
112 for (a = band->parent; a; a = a->parent) {
113 isl_union_pw_multi_aff *partial;
115 partial = isl_union_pw_multi_aff_copy(a->pma);
116 prefix = isl_union_pw_multi_aff_flat_range_product(partial,
120 return isl_union_map_from_union_pw_multi_aff(prefix);
123 /* Return the schedule of the band in isolation.
125 __isl_give isl_union_pw_multi_aff *
126 isl_band_get_partial_schedule_union_pw_multi_aff(__isl_keep isl_band *band)
128 return band ? isl_union_pw_multi_aff_copy(band->pma) : NULL;
131 /* Return the schedule of the band in isolation.
133 __isl_give isl_union_map *isl_band_get_partial_schedule(
134 __isl_keep isl_band *band)
136 isl_union_pw_multi_aff *sched;
138 sched = isl_band_get_partial_schedule_union_pw_multi_aff(band);
139 return isl_union_map_from_union_pw_multi_aff(sched);
142 __isl_give isl_union_pw_multi_aff *
143 isl_band_get_suffix_schedule_union_pw_multi_aff(__isl_keep isl_band *band);
145 /* Return the schedule for the given band list.
146 * For each band in the list, the schedule is composed of the partial
147 * and suffix schedules of that band.
149 __isl_give isl_union_pw_multi_aff *
150 isl_band_list_get_suffix_schedule_union_pw_multi_aff(
151 __isl_keep isl_band_list *list)
156 isl_union_pw_multi_aff *suffix;
161 ctx = isl_band_list_get_ctx(list);
162 space = isl_space_alloc(ctx, 0, 0, 0);
163 suffix = isl_union_pw_multi_aff_empty(space);
164 n = isl_band_list_n_band(list);
165 for (i = 0; i < n; ++i) {
167 isl_union_pw_multi_aff *partial;
168 isl_union_pw_multi_aff *suffix_i;
170 el = isl_band_list_get_band(list, i);
171 partial = isl_band_get_partial_schedule_union_pw_multi_aff(el);
172 suffix_i = isl_band_get_suffix_schedule_union_pw_multi_aff(el);
173 suffix_i = isl_union_pw_multi_aff_flat_range_product(
175 suffix = isl_union_pw_multi_aff_add(suffix, suffix_i);
183 /* Return the schedule for the given band list.
184 * For each band in the list, the schedule is composed of the partial
185 * and suffix schedules of that band.
187 __isl_give isl_union_map *isl_band_list_get_suffix_schedule(
188 __isl_keep isl_band_list *list)
190 isl_union_pw_multi_aff *suffix;
192 suffix = isl_band_list_get_suffix_schedule_union_pw_multi_aff(list);
193 return isl_union_map_from_union_pw_multi_aff(suffix);
196 /* Return the schedule for the forest underneath the given band.
198 __isl_give isl_union_pw_multi_aff *
199 isl_band_get_suffix_schedule_union_pw_multi_aff(__isl_keep isl_band *band)
201 isl_union_pw_multi_aff *suffix;
206 if (!isl_band_has_children(band)) {
207 isl_union_set *domain;
209 suffix = isl_union_pw_multi_aff_copy(band->pma);
210 domain = isl_union_pw_multi_aff_domain(suffix);
211 suffix = isl_union_pw_multi_aff_from_domain(domain);
215 list = isl_band_get_children(band);
217 isl_band_list_get_suffix_schedule_union_pw_multi_aff(list);
218 isl_band_list_free(list);
224 /* Return the schedule for the forest underneath the given band.
226 __isl_give isl_union_map *isl_band_get_suffix_schedule(
227 __isl_keep isl_band *band)
229 isl_union_pw_multi_aff *suffix;
231 suffix = isl_band_get_suffix_schedule_union_pw_multi_aff(band);
232 return isl_union_map_from_union_pw_multi_aff(suffix);
235 __isl_give isl_printer *isl_printer_print_band(__isl_take isl_printer *p,
236 __isl_keep isl_band *band)
238 isl_union_map *prefix, *partial, *suffix;
240 prefix = isl_band_get_prefix_schedule(band);
241 partial = isl_band_get_partial_schedule(band);
242 suffix = isl_band_get_suffix_schedule(band);
244 p = isl_printer_print_str(p, "(");
245 p = isl_printer_print_union_map(p, prefix);
246 p = isl_printer_print_str(p, ",");
247 p = isl_printer_print_union_map(p, partial);
248 p = isl_printer_print_str(p, ",");
249 p = isl_printer_print_union_map(p, suffix);
250 p = isl_printer_print_str(p, ")");
252 isl_union_map_free(prefix);
253 isl_union_map_free(partial);
254 isl_union_map_free(suffix);