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 __isl_give isl_band *isl_band_alloc(isl_ctx *ctx)
24 band = isl_calloc_type(ctx, isl_band);
33 /* We not only increment the reference count of the band,
34 * but also that of the schedule that contains this band.
35 * This ensures that the schedule won't disappear while there
36 * is still a reference to the band outside of the schedule.
37 * There is no need to increment the reference count of the parent
38 * band as the parent band is part of the same schedule.
40 __isl_give isl_band *isl_band_copy(__isl_keep isl_band *band)
46 band->schedule->ref++;
50 /* If this is not the last reference to the band (the one from within the
51 * schedule), then we also need to decrement the reference count of the
52 * containing schedule as it was incremented in isl_band_copy.
54 void *isl_band_free(__isl_take isl_band *band)
60 return isl_schedule_free(band->schedule);
62 isl_union_pw_multi_aff_free(band->pma);
63 isl_band_list_free(band->children);
70 int isl_band_has_children(__isl_keep isl_band *band)
75 return band->children != NULL;
78 __isl_give isl_band_list *isl_band_get_children(
79 __isl_keep isl_band *band)
84 isl_die(isl_band_get_ctx(band), isl_error_invalid,
85 "band has no children", return NULL);
86 return isl_band_list_dup(band->children);
89 int isl_band_n_member(__isl_keep isl_band *band)
91 return band ? band->n : 0;
94 /* Is the given scheduling dimension zero distance within the band and
95 * with respect to the proximity dependences.
97 int isl_band_member_is_zero_distance(__isl_keep isl_band *band, int pos)
102 if (pos < 0 || pos >= band->n)
103 isl_die(isl_band_get_ctx(band), isl_error_invalid,
104 "invalid member position", return -1);
106 return band->zero[pos];
109 /* Return the schedule that leads up to this band.
111 __isl_give isl_union_map *isl_band_get_prefix_schedule(
112 __isl_keep isl_band *band)
114 isl_union_set *domain;
115 isl_union_pw_multi_aff *prefix;
121 prefix = isl_union_pw_multi_aff_copy(band->pma);
122 domain = isl_union_pw_multi_aff_domain(prefix);
123 prefix = isl_union_pw_multi_aff_from_domain(domain);
125 for (a = band->parent; a; a = a->parent) {
126 isl_union_pw_multi_aff *partial;
128 partial = isl_union_pw_multi_aff_copy(a->pma);
129 prefix = isl_union_pw_multi_aff_flat_range_product(partial,
133 return isl_union_map_from_union_pw_multi_aff(prefix);
136 /* Return the schedule of the band in isolation.
138 __isl_give isl_union_pw_multi_aff *
139 isl_band_get_partial_schedule_union_pw_multi_aff(__isl_keep isl_band *band)
141 return band ? isl_union_pw_multi_aff_copy(band->pma) : NULL;
144 /* Return the schedule of the band in isolation.
146 __isl_give isl_union_map *isl_band_get_partial_schedule(
147 __isl_keep isl_band *band)
149 isl_union_pw_multi_aff *sched;
151 sched = isl_band_get_partial_schedule_union_pw_multi_aff(band);
152 return isl_union_map_from_union_pw_multi_aff(sched);
155 __isl_give isl_union_pw_multi_aff *
156 isl_band_get_suffix_schedule_union_pw_multi_aff(__isl_keep isl_band *band);
158 /* Return the schedule for the given band list.
159 * For each band in the list, the schedule is composed of the partial
160 * and suffix schedules of that band.
162 __isl_give isl_union_pw_multi_aff *
163 isl_band_list_get_suffix_schedule_union_pw_multi_aff(
164 __isl_keep isl_band_list *list)
169 isl_union_pw_multi_aff *suffix;
174 ctx = isl_band_list_get_ctx(list);
175 space = isl_space_alloc(ctx, 0, 0, 0);
176 suffix = isl_union_pw_multi_aff_empty(space);
177 n = isl_band_list_n_band(list);
178 for (i = 0; i < n; ++i) {
180 isl_union_pw_multi_aff *partial;
181 isl_union_pw_multi_aff *suffix_i;
183 el = isl_band_list_get_band(list, i);
184 partial = isl_band_get_partial_schedule_union_pw_multi_aff(el);
185 suffix_i = isl_band_get_suffix_schedule_union_pw_multi_aff(el);
186 suffix_i = isl_union_pw_multi_aff_flat_range_product(
188 suffix = isl_union_pw_multi_aff_add(suffix, suffix_i);
196 /* Return the schedule for the given band list.
197 * For each band in the list, the schedule is composed of the partial
198 * and suffix schedules of that band.
200 __isl_give isl_union_map *isl_band_list_get_suffix_schedule(
201 __isl_keep isl_band_list *list)
203 isl_union_pw_multi_aff *suffix;
205 suffix = isl_band_list_get_suffix_schedule_union_pw_multi_aff(list);
206 return isl_union_map_from_union_pw_multi_aff(suffix);
209 /* Return the schedule for the forest underneath the given band.
211 __isl_give isl_union_pw_multi_aff *
212 isl_band_get_suffix_schedule_union_pw_multi_aff(__isl_keep isl_band *band)
214 isl_union_pw_multi_aff *suffix;
219 if (!isl_band_has_children(band)) {
220 isl_union_set *domain;
222 suffix = isl_union_pw_multi_aff_copy(band->pma);
223 domain = isl_union_pw_multi_aff_domain(suffix);
224 suffix = isl_union_pw_multi_aff_from_domain(domain);
228 list = isl_band_get_children(band);
230 isl_band_list_get_suffix_schedule_union_pw_multi_aff(list);
231 isl_band_list_free(list);
237 /* Return the schedule for the forest underneath the given band.
239 __isl_give isl_union_map *isl_band_get_suffix_schedule(
240 __isl_keep isl_band *band)
242 isl_union_pw_multi_aff *suffix;
244 suffix = isl_band_get_suffix_schedule_union_pw_multi_aff(band);
245 return isl_union_map_from_union_pw_multi_aff(suffix);
248 __isl_give isl_printer *isl_printer_print_band(__isl_take isl_printer *p,
249 __isl_keep isl_band *band)
251 isl_union_map *prefix, *partial, *suffix;
253 prefix = isl_band_get_prefix_schedule(band);
254 partial = isl_band_get_partial_schedule(band);
255 suffix = isl_band_get_suffix_schedule(band);
257 p = isl_printer_print_str(p, "(");
258 p = isl_printer_print_union_map(p, prefix);
259 p = isl_printer_print_str(p, ",");
260 p = isl_printer_print_union_map(p, partial);
261 p = isl_printer_print_str(p, ",");
262 p = isl_printer_print_union_map(p, suffix);
263 p = isl_printer_print_str(p, ")");
265 isl_union_map_free(prefix);
266 isl_union_map_free(partial);
267 isl_union_map_free(suffix);