2 * Copyright 2013-2014 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
10 #include <isl_schedule_band.h>
11 #include <isl_schedule_private.h>
13 isl_ctx
*isl_schedule_band_get_ctx(__isl_keep isl_schedule_band
*band
)
15 return band
? isl_multi_union_pw_aff_get_ctx(band
->mupa
) : NULL
;
18 /* Return a new uninitialized isl_schedule_band.
20 static __isl_give isl_schedule_band
*isl_schedule_band_alloc(isl_ctx
*ctx
)
22 isl_schedule_band
*band
;
24 band
= isl_calloc_type(ctx
, isl_schedule_band
);
33 /* Return a new isl_schedule_band with partial schedule "mupa".
34 * First replace "mupa" by its greatest integer part to ensure
35 * that the schedule is always integral.
36 * The band is not marked permutable and the dimensions are not
39 __isl_give isl_schedule_band
*isl_schedule_band_from_multi_union_pw_aff(
40 __isl_take isl_multi_union_pw_aff
*mupa
)
43 isl_schedule_band
*band
;
45 mupa
= isl_multi_union_pw_aff_floor(mupa
);
48 ctx
= isl_multi_union_pw_aff_get_ctx(mupa
);
49 band
= isl_schedule_band_alloc(ctx
);
53 band
->n
= isl_multi_union_pw_aff_dim(mupa
, isl_dim_set
);
54 band
->coincident
= isl_calloc_array(ctx
, int, band
->n
);
57 if (band
->n
&& !band
->coincident
)
58 return isl_schedule_band_free(band
);
62 isl_multi_union_pw_aff_free(mupa
);
66 /* Create a duplicate of the given isl_schedule_band.
68 __isl_give isl_schedule_band
*isl_schedule_band_dup(
69 __isl_keep isl_schedule_band
*band
)
73 isl_schedule_band
*dup
;
78 ctx
= isl_schedule_band_get_ctx(band
);
79 dup
= isl_schedule_band_alloc(ctx
);
84 dup
->coincident
= isl_alloc_array(ctx
, int, band
->n
);
85 if (band
->n
&& !dup
->coincident
)
86 return isl_schedule_band_free(dup
);
88 for (i
= 0; i
< band
->n
; ++i
)
89 dup
->coincident
[i
] = band
->coincident
[i
];
90 dup
->permutable
= band
->permutable
;
92 dup
->mupa
= isl_multi_union_pw_aff_copy(band
->mupa
);
94 return isl_schedule_band_free(dup
);
99 /* Return an isl_schedule_band that is equal to "band" and that has only
100 * a single reference.
102 __isl_give isl_schedule_band
*isl_schedule_band_cow(
103 __isl_take isl_schedule_band
*band
)
111 return isl_schedule_band_dup(band
);
114 /* Return a new reference to "band".
116 __isl_give isl_schedule_band
*isl_schedule_band_copy(
117 __isl_keep isl_schedule_band
*band
)
126 /* Free a reference to "band" and return NULL.
128 __isl_null isl_schedule_band
*isl_schedule_band_free(
129 __isl_take isl_schedule_band
*band
)
137 isl_multi_union_pw_aff_free(band
->mupa
);
138 free(band
->coincident
);
144 /* Return the number of scheduling dimensions in the band.
146 int isl_schedule_band_n_member(__isl_keep isl_schedule_band
*band
)
148 return band
? band
->n
: 0;
151 /* Is the given scheduling dimension coincident within the band and
152 * with respect to the coincidence constraints?
154 int isl_schedule_band_member_get_coincident(__isl_keep isl_schedule_band
*band
,
160 if (pos
< 0 || pos
>= band
->n
)
161 isl_die(isl_schedule_band_get_ctx(band
), isl_error_invalid
,
162 "invalid member position", return -1);
164 return band
->coincident
[pos
];
167 /* Mark the given scheduling dimension as being coincident or not
168 * according to "coincident".
170 __isl_give isl_schedule_band
*isl_schedule_band_member_set_coincident(
171 __isl_take isl_schedule_band
*band
, int pos
, int coincident
)
175 if (isl_schedule_band_member_get_coincident(band
, pos
) == coincident
)
177 band
= isl_schedule_band_cow(band
);
181 if (pos
< 0 || pos
>= band
->n
)
182 isl_die(isl_schedule_band_get_ctx(band
), isl_error_invalid
,
183 "invalid member position",
184 isl_schedule_band_free(band
));
186 band
->coincident
[pos
] = coincident
;
191 /* Is the schedule band mark permutable?
193 int isl_schedule_band_get_permutable(__isl_keep isl_schedule_band
*band
)
197 return band
->permutable
;
200 /* Mark the schedule band permutable or not according to "permutable"?
202 __isl_give isl_schedule_band
*isl_schedule_band_set_permutable(
203 __isl_take isl_schedule_band
*band
, int permutable
)
207 if (band
->permutable
== permutable
)
209 band
= isl_schedule_band_cow(band
);
213 band
->permutable
= permutable
;
218 /* Return the schedule of the band in isolation.
220 __isl_give isl_multi_union_pw_aff
*isl_schedule_band_get_partial_schedule(
221 __isl_keep isl_schedule_band
*band
)
223 return band
? isl_multi_union_pw_aff_copy(band
->mupa
) : NULL
;