isl_qpolynomial_move_dims: plug memory leak and fix reordering of divs
[isl.git] / include / isl_set.h
blob1ce899ca006bb3b2fd25feac36c992ed13f2aff4
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #ifndef ISL_SET_H
11 #define ISL_SET_H
13 #include "isl_map.h"
14 #include "isl_list.h"
15 #include <isl_point.h>
17 #if defined(__cplusplus)
18 extern "C" {
19 #endif
21 /* A "basic set" is a basic map with a zero-dimensional
22 * domain.
24 struct isl_basic_set {
25 int ref;
26 #define ISL_BASIC_SET_FINAL (1 << 0)
27 #define ISL_BASIC_SET_EMPTY (1 << 1)
28 #define ISL_BASIC_SET_NO_IMPLICIT (1 << 2)
29 #define ISL_BASIC_SET_NO_REDUNDANT (1 << 3)
30 #define ISL_BASIC_SET_RATIONAL (1 << 4)
31 #define ISL_BASIC_SET_NORMALIZED (1 << 5)
32 #define ISL_BASIC_SET_NORMALIZED_DIVS (1 << 6)
33 #define ISL_BASIC_SET_ALL_EQUALITIES (1 << 7)
34 unsigned flags;
36 struct isl_ctx *ctx;
38 struct isl_dim *dim;
39 unsigned extra;
41 unsigned n_eq;
42 unsigned n_ineq;
44 size_t c_size;
45 isl_int **eq;
46 isl_int **ineq;
48 unsigned n_div;
50 isl_int **div;
52 struct isl_vec *sample;
54 struct isl_blk block;
55 struct isl_blk block2;
58 /* A "set" is a (possibly disjoint) union of basic sets.
60 * See the documentation of isl_map.
62 struct isl_set {
63 int ref;
64 #define ISL_SET_DISJOINT (1 << 0)
65 #define ISL_SET_NORMALIZED (1 << 1)
66 unsigned flags;
68 struct isl_ctx *ctx;
70 struct isl_dim *dim;
72 int n;
74 size_t size;
75 struct isl_basic_set *p[1];
78 unsigned isl_basic_set_n_dim(const struct isl_basic_set *bset);
79 unsigned isl_basic_set_n_param(const struct isl_basic_set *bset);
80 unsigned isl_basic_set_total_dim(const struct isl_basic_set *bset);
81 unsigned isl_basic_set_dim(const struct isl_basic_set *bset,
82 enum isl_dim_type type);
84 unsigned isl_set_n_dim(const struct isl_set *set);
85 unsigned isl_set_n_param(const struct isl_set *set);
86 unsigned isl_set_dim(const struct isl_set *set, enum isl_dim_type type);
88 __isl_give isl_dim *isl_basic_set_get_dim(__isl_keep isl_basic_set *bset);
89 __isl_give isl_dim *isl_set_get_dim(__isl_keep isl_set *set);
91 __isl_give isl_basic_set *isl_basic_set_set_dim_name(
92 __isl_take isl_basic_set *bset,
93 enum isl_dim_type type, unsigned pos, const char *s);
94 __isl_give isl_set *isl_set_set_dim_name(__isl_take isl_set *set,
95 enum isl_dim_type type, unsigned pos, const char *s);
97 struct isl_basic_set *isl_basic_set_alloc(struct isl_ctx *ctx,
98 unsigned nparam, unsigned dim, unsigned extra,
99 unsigned n_eq, unsigned n_ineq);
100 struct isl_basic_set *isl_basic_set_extend(struct isl_basic_set *base,
101 unsigned nparam, unsigned dim, unsigned extra,
102 unsigned n_eq, unsigned n_ineq);
103 struct isl_basic_set *isl_basic_set_extend_constraints(
104 struct isl_basic_set *base, unsigned n_eq, unsigned n_ineq);
105 struct isl_basic_set *isl_basic_set_finalize(struct isl_basic_set *bset);
106 void isl_basic_set_free(__isl_take isl_basic_set *bset);
107 __isl_give isl_basic_set *isl_basic_set_copy(__isl_keep isl_basic_set *bset);
108 struct isl_basic_set *isl_basic_set_dup(struct isl_basic_set *bset);
109 __isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_dim *dim);
110 struct isl_basic_set *isl_basic_set_empty_like(struct isl_basic_set *bset);
111 __isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_dim *dim);
112 struct isl_basic_set *isl_basic_set_universe_like(struct isl_basic_set *bset);
113 __isl_give isl_basic_set *isl_basic_set_universe_like_set(
114 __isl_keep isl_set *model);
115 struct isl_basic_set *isl_basic_set_interval(struct isl_ctx *ctx,
116 isl_int min, isl_int max);
117 struct isl_basic_set *isl_basic_set_positive_orthant(struct isl_dim *dims);
118 void isl_basic_set_dump(__isl_keep isl_basic_set *bset,
119 FILE *out, int indent);
120 struct isl_basic_set *isl_basic_set_swap_vars(
121 struct isl_basic_set *bset, unsigned n);
122 __isl_give isl_basic_set *isl_basic_set_intersect(
123 __isl_take isl_basic_set *bset1,
124 __isl_take isl_basic_set *bset2);
125 __isl_give isl_basic_set *isl_basic_set_apply(
126 __isl_take isl_basic_set *bset,
127 __isl_take isl_basic_map *bmap);
128 __isl_give isl_basic_set *isl_basic_set_affine_hull(
129 __isl_take isl_basic_set *bset);
130 __isl_give isl_basic_set *isl_basic_set_remove(__isl_take isl_basic_set *bset,
131 enum isl_dim_type type, unsigned first, unsigned n);
132 struct isl_basic_set *isl_basic_set_simplify(struct isl_basic_set *bset);
133 __isl_give isl_basic_set *isl_basic_set_detect_equalities(
134 __isl_take isl_basic_set *bset);
135 struct isl_basic_set *isl_basic_set_product(struct isl_basic_set_list *list);
137 __isl_give isl_basic_set *isl_basic_set_read_from_file(isl_ctx *ctx,
138 FILE *input, int nparam);
139 __isl_give isl_basic_set *isl_basic_set_read_from_str(isl_ctx *ctx,
140 const char *str, int nparam);
141 __isl_give isl_set *isl_set_read_from_file(isl_ctx *ctx,
142 FILE *input, int nparam);
143 __isl_give isl_set *isl_set_read_from_str(isl_ctx *ctx,
144 const char *str, int nparam);
145 __isl_give isl_printer *isl_printer_print_basic_set(
146 __isl_take isl_printer *printer, __isl_keep isl_basic_set *bset);
147 __isl_give isl_printer *isl_printer_print_set(__isl_take isl_printer *printer,
148 __isl_keep isl_set *map);
149 void isl_basic_set_print(__isl_keep isl_basic_set *bset, FILE *out, int indent,
150 const char *prefix, const char *suffix, unsigned output_format);
151 void isl_set_print(__isl_keep struct isl_set *set, FILE *out, int indent,
152 unsigned output_format);
153 __isl_give isl_basic_set *isl_basic_set_fix(__isl_take isl_basic_set *bset,
154 enum isl_dim_type type, unsigned pos, isl_int value);
155 struct isl_basic_set *isl_basic_set_fix_si(struct isl_basic_set *bset,
156 enum isl_dim_type type, unsigned pos, int value);
157 __isl_give isl_set *isl_set_fix_si(__isl_take isl_set *set,
158 enum isl_dim_type type, unsigned pos, int value);
159 __isl_give isl_set *isl_set_lower_bound_si(__isl_take isl_set *set,
160 enum isl_dim_type type, unsigned pos, int value);
162 struct isl_basic_set *isl_basic_set_from_underlying_set(
163 struct isl_basic_set *bset, struct isl_basic_set *like);
164 struct isl_set *isl_set_from_underlying_set(
165 struct isl_set *set, struct isl_basic_set *like);
166 struct isl_set *isl_set_to_underlying_set(struct isl_set *set);
168 int isl_basic_set_is_equal(
169 struct isl_basic_set *bset1, struct isl_basic_set *bset2);
171 __isl_give isl_set *isl_basic_set_partial_lexmin(
172 __isl_take isl_basic_set *bset, __isl_take isl_basic_set *dom,
173 __isl_give isl_set **empty);
174 __isl_give isl_set *isl_basic_set_partial_lexmax(
175 __isl_take isl_basic_set *bset, __isl_take isl_basic_set *dom,
176 __isl_give isl_set **empty);
177 __isl_give isl_set *isl_set_partial_lexmin(
178 __isl_take isl_set *set, __isl_take isl_set *dom,
179 __isl_give isl_set **empty);
180 __isl_give isl_set *isl_set_partial_lexmax(
181 __isl_take isl_set *set, __isl_take isl_set *dom,
182 __isl_give isl_set **empty);
183 __isl_give isl_set *isl_basic_set_lexmin(__isl_take isl_basic_set *bset);
184 __isl_give isl_set *isl_basic_set_lexmax(__isl_take isl_basic_set *bset);
185 __isl_give isl_set *isl_set_lexmin(__isl_take isl_set *set);
186 __isl_give isl_set *isl_set_lexmax(__isl_take isl_set *set);
187 __isl_give isl_set *isl_basic_set_union(
188 __isl_take isl_basic_set *bset1,
189 __isl_take isl_basic_set *bset2);
191 int isl_basic_set_compare_at(struct isl_basic_set *bset1,
192 struct isl_basic_set *bset2, int pos);
193 int isl_set_follows_at(__isl_keep isl_set *set1,
194 __isl_keep isl_set *set2, int pos);
196 int isl_basic_set_dims_get_sign(__isl_keep isl_basic_set *bset,
197 enum isl_dim_type type, unsigned pos, unsigned n, int *signs);
199 int isl_basic_set_is_universe(__isl_keep isl_basic_set *bset);
200 int isl_basic_set_fast_is_empty(__isl_keep isl_basic_set *bset);
201 int isl_basic_set_is_empty(__isl_keep isl_basic_set *bset);
202 int isl_basic_set_is_bounded(__isl_keep isl_basic_set *bset);
204 struct isl_set *isl_set_alloc(struct isl_ctx *ctx,
205 unsigned nparam, unsigned dim, int n, unsigned flags);
206 struct isl_set *isl_set_extend(struct isl_set *base,
207 unsigned nparam, unsigned dim);
208 __isl_give isl_set *isl_set_empty(__isl_take isl_dim *dim);
209 struct isl_set *isl_set_empty_like(struct isl_set *set);
210 __isl_give isl_set *isl_set_universe(__isl_take isl_dim *dim);
211 __isl_give isl_set *isl_set_universe_like(__isl_keep isl_set *model);
212 __isl_give isl_set *isl_set_add_basic_set(__isl_take isl_set *set,
213 __isl_take isl_basic_set *bset);
214 struct isl_set *isl_set_finalize(struct isl_set *set);
215 __isl_give isl_set *isl_set_copy(__isl_keep isl_set *set);
216 void isl_set_free(__isl_take isl_set *set);
217 struct isl_set *isl_set_dup(struct isl_set *set);
218 __isl_give isl_set *isl_set_from_basic_set(__isl_take isl_basic_set *bset);
219 __isl_give isl_basic_set *isl_set_sample(__isl_take isl_set *set);
220 __isl_give isl_point *isl_set_sample_point(__isl_take isl_set *set);
221 __isl_give isl_set *isl_set_detect_equalities(__isl_take isl_set *set);
222 __isl_give isl_basic_set *isl_set_affine_hull(__isl_take isl_set *set);
223 __isl_give isl_basic_set *isl_set_convex_hull(__isl_take isl_set *set);
224 __isl_give isl_basic_set *isl_set_simple_hull(__isl_take isl_set *set);
225 struct isl_basic_set *isl_set_bounded_simple_hull(struct isl_set *set);
226 __isl_give isl_set *isl_set_recession_cone(__isl_take isl_set *set);
228 struct isl_set *isl_set_union_disjoint(
229 struct isl_set *set1, struct isl_set *set2);
230 __isl_give isl_set *isl_set_union(
231 __isl_take isl_set *set1,
232 __isl_take isl_set *set2);
233 struct isl_set *isl_set_product(struct isl_set *set1, struct isl_set *set2);
234 __isl_give isl_set *isl_set_flat_product(__isl_take isl_set *set1,
235 __isl_take isl_set *set2);
236 __isl_give isl_set *isl_set_intersect(
237 __isl_take isl_set *set1,
238 __isl_take isl_set *set2);
239 __isl_give isl_set *isl_set_subtract(
240 __isl_take isl_set *set1,
241 __isl_take isl_set *set2);
242 __isl_give isl_set *isl_set_complement(__isl_take isl_set *set);
243 __isl_give isl_set *isl_set_apply(
244 __isl_take isl_set *set,
245 __isl_take isl_map *map);
246 __isl_give isl_set *isl_set_fix(__isl_take isl_set *set,
247 enum isl_dim_type type, unsigned pos, isl_int value);
248 struct isl_set *isl_set_fix_dim_si(struct isl_set *set,
249 unsigned dim, int value);
250 struct isl_set *isl_set_lower_bound_dim(struct isl_set *set,
251 unsigned dim, isl_int value);
252 __isl_give isl_set *isl_set_insert(__isl_take isl_set *set,
253 enum isl_dim_type type, unsigned pos, unsigned n);
254 __isl_give isl_basic_set *isl_basic_set_add(__isl_take isl_basic_set *bset,
255 enum isl_dim_type type, unsigned n);
256 __isl_give isl_set *isl_set_add(__isl_take isl_set *set,
257 enum isl_dim_type type, unsigned n);
258 __isl_give isl_basic_set *isl_basic_set_move_dims(__isl_take isl_basic_set *bset,
259 enum isl_dim_type dst_type, unsigned dst_pos,
260 enum isl_dim_type src_type, unsigned src_pos, unsigned n);
261 __isl_give isl_set *isl_set_move_dims(__isl_take isl_set *set,
262 enum isl_dim_type dst_type, unsigned dst_pos,
263 enum isl_dim_type src_type, unsigned src_pos, unsigned n);
264 __isl_give isl_basic_set *isl_basic_set_project_out(
265 __isl_take isl_basic_set *bset,
266 enum isl_dim_type type, unsigned first, unsigned n);
267 __isl_give isl_set *isl_set_project_out(__isl_take isl_set *set,
268 enum isl_dim_type type, unsigned first, unsigned n);
269 struct isl_basic_set *isl_basic_set_remove_dims(struct isl_basic_set *bset,
270 unsigned first, unsigned n);
271 struct isl_basic_set *isl_basic_set_remove_divs(struct isl_basic_set *bset);
272 struct isl_set *isl_set_eliminate_dims(struct isl_set *set,
273 unsigned first, unsigned n);
274 __isl_give isl_set *isl_set_remove(__isl_take isl_set *bset,
275 enum isl_dim_type type, unsigned first, unsigned n);
276 struct isl_set *isl_set_remove_dims(struct isl_set *set,
277 unsigned first, unsigned n);
278 struct isl_set *isl_set_remove_divs(struct isl_set *set);
279 __isl_give isl_set *isl_set_split_dims(__isl_take isl_set *set,
280 enum isl_dim_type type, unsigned first, unsigned n);
282 void isl_set_dump(__isl_keep isl_set *set, FILE *out, int indent);
283 struct isl_set *isl_set_swap_vars(struct isl_set *set, unsigned n);
284 int isl_set_fast_is_empty(__isl_keep isl_set *set);
285 int isl_set_fast_is_universe(__isl_keep isl_set *set);
286 int isl_set_is_empty(__isl_keep isl_set *set);
287 int isl_set_is_bounded(__isl_keep isl_set *set);
288 int isl_set_is_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
289 int isl_set_is_strict_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
290 int isl_set_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
291 int isl_set_is_singleton(__isl_keep isl_set *set);
292 int isl_set_is_box(__isl_keep isl_set *set);
293 int isl_set_has_equal_dim(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
295 __isl_give isl_set *isl_set_sum(__isl_take isl_set *set1,
296 __isl_take isl_set *set2);
297 __isl_give isl_set *isl_set_neg(__isl_take isl_set *set);
299 __isl_give isl_set *isl_set_make_disjoint(__isl_take isl_set *set);
300 struct isl_set *isl_basic_set_compute_divs(struct isl_basic_set *bset);
301 __isl_give isl_set *isl_set_compute_divs(__isl_take isl_set *set);
302 __isl_give isl_set *isl_set_align_divs(__isl_take isl_set *set);
304 struct isl_basic_set *isl_set_copy_basic_set(struct isl_set *set);
305 struct isl_set *isl_set_drop_basic_set(struct isl_set *set,
306 struct isl_basic_set *bset);
308 int isl_basic_set_fast_dim_is_fixed(struct isl_basic_set *bset, unsigned dim,
309 isl_int *val);
311 int isl_set_fast_dim_is_fixed(struct isl_set *set, unsigned dim, isl_int *val);
312 int isl_set_fast_dim_has_fixed_lower_bound(struct isl_set *set,
313 unsigned dim, isl_int *val);
314 int isl_set_dim_is_bounded(__isl_keep isl_set *set,
315 enum isl_dim_type type, unsigned pos);
317 __isl_give isl_basic_set *isl_basic_set_gist(__isl_take isl_basic_set *bset,
318 __isl_take isl_basic_set *context);
319 __isl_give isl_set *isl_set_gist_basic_set(__isl_take isl_set *set,
320 __isl_take isl_basic_set *context);
321 __isl_give isl_set *isl_set_gist(__isl_take isl_set *set,
322 __isl_take isl_set *context);
323 int isl_basic_set_dim_residue_class(struct isl_basic_set *bset,
324 int pos, isl_int *modulo, isl_int *residue);
325 int isl_set_dim_residue_class(struct isl_set *set,
326 int pos, isl_int *modulo, isl_int *residue);
328 __isl_give isl_set *isl_set_coalesce(__isl_take isl_set *set);
330 int isl_set_fast_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
331 int isl_set_fast_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
333 uint32_t isl_set_get_hash(struct isl_set *set);
335 int isl_set_dim_is_unique(struct isl_set *set, unsigned dim);
337 int isl_set_foreach_basic_set(__isl_keep isl_set *set,
338 int (*fn)(__isl_take isl_basic_set *bset, void *user), void *user);
340 int isl_set_foreach_point(__isl_keep isl_set *set,
341 int (*fn)(__isl_take isl_point *pnt, void *user), void *user);
342 int isl_set_count(__isl_keep isl_set *set, isl_int *count);
343 int isl_set_count_upto(__isl_keep isl_set *set, isl_int max, isl_int *count);
345 __isl_give isl_set *isl_set_from_point(__isl_take isl_point *pnt);
346 __isl_give isl_set *isl_set_box_from_points(__isl_take isl_point *pnt1,
347 __isl_take isl_point *pnt2);
349 __isl_give isl_set *isl_set_lift(__isl_take isl_set *set);
351 int isl_set_size(__isl_keep isl_set *set);
353 #if defined(__cplusplus)
355 #endif
357 #endif