AST generator: select unroll lower bound introducing fewest integer divisions
[isl.git] / isl_map_private.h
blob99e2e2832532fcc44ff340eddb9afee6b66439b8
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #ifndef ISL_MAP_PRIVATE_H
11 #define ISL_MAP_PRIVATE_H
13 #define isl_basic_set isl_basic_map
14 #define isl_set isl_map
15 #define isl_basic_set_list isl_basic_map_list
16 #define isl_set_list isl_map_list
17 #include <isl/list.h>
18 #include <isl/set.h>
19 #include <isl/map.h>
20 #include <isl_reordering.h>
21 #include <isl/vec.h>
22 #include <isl_blk.h>
24 /* A "basic map" is a relation between two sets of variables,
25 * called the "in" and "out" variables.
26 * A "basic set" is a basic map with a zero-dimensional
27 * domain.
29 * It is implemented as a set with two extra fields:
30 * n_in is the number of in variables
31 * n_out is the number of out variables
32 * n_in + n_out should be equal to set.dim
34 struct isl_basic_map {
35 int ref;
36 #define ISL_BASIC_MAP_FINAL (1 << 0)
37 #define ISL_BASIC_MAP_EMPTY (1 << 1)
38 #define ISL_BASIC_MAP_NO_IMPLICIT (1 << 2)
39 #define ISL_BASIC_MAP_NO_REDUNDANT (1 << 3)
40 #define ISL_BASIC_MAP_RATIONAL (1 << 4)
41 #define ISL_BASIC_MAP_NORMALIZED (1 << 5)
42 #define ISL_BASIC_MAP_NORMALIZED_DIVS (1 << 6)
43 #define ISL_BASIC_MAP_ALL_EQUALITIES (1 << 7)
44 #define ISL_BASIC_SET_FINAL (1 << 0)
45 #define ISL_BASIC_SET_EMPTY (1 << 1)
46 #define ISL_BASIC_SET_NO_IMPLICIT (1 << 2)
47 #define ISL_BASIC_SET_NO_REDUNDANT (1 << 3)
48 #define ISL_BASIC_SET_RATIONAL (1 << 4)
49 #define ISL_BASIC_SET_NORMALIZED (1 << 5)
50 #define ISL_BASIC_SET_NORMALIZED_DIVS (1 << 6)
51 #define ISL_BASIC_SET_ALL_EQUALITIES (1 << 7)
52 unsigned flags;
54 struct isl_ctx *ctx;
56 isl_space *dim;
57 unsigned extra;
59 unsigned n_eq;
60 unsigned n_ineq;
62 size_t c_size;
63 isl_int **eq;
64 isl_int **ineq;
66 unsigned n_div;
68 isl_int **div;
70 struct isl_vec *sample;
72 struct isl_blk block;
73 struct isl_blk block2;
76 #undef EL
77 #define EL isl_basic_set
79 #include <isl_list_templ.h>
81 /* A "map" is a (possibly disjoint) union of basic maps.
82 * A "set" is a (possibly disjoint) union of basic sets.
84 * Currently, the isl_set structure is identical to the isl_map structure
85 * and the library depends on this correspondence internally.
86 * However, users should not depend on this correspondence.
88 struct isl_map {
89 int ref;
90 #define ISL_MAP_DISJOINT (1 << 0)
91 #define ISL_MAP_NORMALIZED (1 << 1)
92 #define ISL_SET_DISJOINT (1 << 0)
93 #define ISL_SET_NORMALIZED (1 << 1)
94 unsigned flags;
96 struct isl_ctx *ctx;
98 isl_space *dim;
100 int n;
102 size_t size;
103 struct isl_basic_map *p[1];
106 #undef EL
107 #define EL isl_set
109 #include <isl_list_templ.h>
111 __isl_give isl_map *isl_map_realign(__isl_take isl_map *map,
112 __isl_take isl_reordering *r);
113 __isl_give isl_set *isl_set_realign(__isl_take isl_set *set,
114 __isl_take isl_reordering *r);
116 __isl_give isl_map *isl_map_reset(__isl_take isl_map *map,
117 enum isl_dim_type type);
119 __isl_give isl_basic_set *isl_basic_set_reset_space(
120 __isl_take isl_basic_set *bset, __isl_take isl_space *dim);
121 __isl_give isl_basic_map *isl_basic_map_reset_space(
122 __isl_take isl_basic_map *bmap, __isl_take isl_space *dim);
123 __isl_give isl_map *isl_map_reset_space(__isl_take isl_map *map,
124 __isl_take isl_space *dim);
126 unsigned isl_basic_map_offset(struct isl_basic_map *bmap,
127 enum isl_dim_type type);
128 unsigned isl_basic_set_offset(struct isl_basic_set *bset,
129 enum isl_dim_type type);
131 int isl_basic_map_may_be_set(__isl_keep isl_basic_map *bmap);
132 int isl_map_may_be_set(__isl_keep isl_map *map);
133 int isl_map_compatible_domain(struct isl_map *map, struct isl_set *set);
134 int isl_basic_map_compatible_domain(struct isl_basic_map *bmap,
135 struct isl_basic_set *bset);
136 int isl_basic_map_compatible_range(struct isl_basic_map *bmap,
137 struct isl_basic_set *bset);
139 struct isl_basic_map *isl_basic_map_extend_space(struct isl_basic_map *base,
140 __isl_take isl_space *dim, unsigned extra,
141 unsigned n_eq, unsigned n_ineq);
142 struct isl_basic_set *isl_basic_set_extend_space(struct isl_basic_set *base,
143 __isl_take isl_space *dim, unsigned extra,
144 unsigned n_eq, unsigned n_ineq);
145 struct isl_basic_set *isl_basic_set_add_constraints(struct isl_basic_set *bset1,
146 struct isl_basic_set *bset2, unsigned pos);
148 struct isl_map *isl_map_grow(struct isl_map *map, int n);
149 struct isl_set *isl_set_grow(struct isl_set *set, int n);
151 int isl_basic_set_contains(struct isl_basic_set *bset, struct isl_vec *vec);
152 int isl_basic_map_contains(struct isl_basic_map *bmap, struct isl_vec *vec);
154 __isl_give isl_basic_set *isl_basic_set_alloc_space(__isl_take isl_space *dim,
155 unsigned extra, unsigned n_eq, unsigned n_ineq);
156 __isl_give isl_set *isl_set_alloc_space(__isl_take isl_space *dim, int n,
157 unsigned flags);
158 __isl_give isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *dim,
159 unsigned extra, unsigned n_eq, unsigned n_ineq);
160 __isl_give isl_map *isl_map_alloc_space(__isl_take isl_space *dim, int n,
161 unsigned flags);
163 unsigned isl_basic_map_total_dim(const struct isl_basic_map *bmap);
165 int isl_basic_map_alloc_equality(struct isl_basic_map *bmap);
166 int isl_basic_set_alloc_equality(struct isl_basic_set *bset);
167 int isl_basic_set_free_inequality(struct isl_basic_set *bset, unsigned n);
168 int isl_basic_map_free_equality(struct isl_basic_map *bmap, unsigned n);
169 int isl_basic_set_free_equality(struct isl_basic_set *bset, unsigned n);
170 int isl_basic_set_alloc_inequality(struct isl_basic_set *bset);
171 int isl_basic_map_alloc_inequality(struct isl_basic_map *bmap);
172 int isl_basic_map_free_inequality(struct isl_basic_map *bmap, unsigned n);
173 int isl_basic_map_alloc_div(struct isl_basic_map *bmap);
174 int isl_basic_set_alloc_div(struct isl_basic_set *bset);
175 int isl_basic_map_free_div(struct isl_basic_map *bmap, unsigned n);
176 int isl_basic_set_free_div(struct isl_basic_set *bset, unsigned n);
177 void isl_basic_map_inequality_to_equality(
178 struct isl_basic_map *bmap, unsigned pos);
179 int isl_basic_map_drop_equality(struct isl_basic_map *bmap, unsigned pos);
180 int isl_basic_set_drop_equality(struct isl_basic_set *bset, unsigned pos);
181 int isl_basic_set_drop_inequality(struct isl_basic_set *bset, unsigned pos);
182 int isl_basic_map_drop_inequality(struct isl_basic_map *bmap, unsigned pos);
183 __isl_give isl_basic_set *isl_basic_set_add_eq(__isl_take isl_basic_set *bset,
184 isl_int *eq);
185 __isl_give isl_basic_map *isl_basic_map_add_eq(__isl_take isl_basic_map *bmap,
186 isl_int *eq);
187 __isl_give isl_basic_set *isl_basic_set_add_ineq(__isl_take isl_basic_set *bset,
188 isl_int *ineq);
189 __isl_give isl_basic_map *isl_basic_map_add_ineq(__isl_take isl_basic_map *bmap,
190 isl_int *ineq);
192 int isl_inequality_negate(struct isl_basic_map *bmap, unsigned pos);
194 struct isl_basic_set *isl_basic_set_cow(struct isl_basic_set *bset);
195 struct isl_basic_map *isl_basic_map_cow(struct isl_basic_map *bmap);
196 struct isl_set *isl_set_cow(struct isl_set *set);
197 struct isl_map *isl_map_cow(struct isl_map *map);
199 struct isl_basic_map *isl_basic_map_set_to_empty(struct isl_basic_map *bmap);
200 struct isl_basic_set *isl_basic_set_set_to_empty(struct isl_basic_set *bset);
201 struct isl_basic_set *isl_basic_set_order_divs(struct isl_basic_set *bset);
202 void isl_basic_map_swap_div(struct isl_basic_map *bmap, int a, int b);
203 struct isl_basic_map *isl_basic_map_order_divs(struct isl_basic_map *bmap);
204 __isl_give isl_map *isl_map_order_divs(__isl_take isl_map *map);
205 struct isl_basic_map *isl_basic_map_align_divs(
206 struct isl_basic_map *dst, struct isl_basic_map *src);
207 struct isl_basic_set *isl_basic_set_align_divs(
208 struct isl_basic_set *dst, struct isl_basic_set *src);
209 __isl_give isl_map *isl_map_align_divs_to_basic_map_list(
210 __isl_take isl_map *map, __isl_keep isl_basic_map_list *list);
211 __isl_give isl_basic_map_list *isl_basic_map_list_align_divs_to_basic_map(
212 __isl_take isl_basic_map_list *list, __isl_keep isl_basic_map *bmap);
213 __isl_give isl_basic_map *isl_basic_map_sort_divs(
214 __isl_take isl_basic_map *bmap);
215 __isl_give isl_map *isl_map_sort_divs(__isl_take isl_map *map);
216 struct isl_basic_map *isl_basic_map_gauss(
217 struct isl_basic_map *bmap, int *progress);
218 struct isl_basic_set *isl_basic_set_gauss(
219 struct isl_basic_set *bset, int *progress);
220 __isl_give isl_basic_set *isl_basic_set_sort_constraints(
221 __isl_take isl_basic_set *bset);
222 int isl_basic_map_plain_cmp(const __isl_keep isl_basic_map *bmap1,
223 const __isl_keep isl_basic_map *bmap2);
224 int isl_basic_map_plain_is_equal(__isl_keep isl_basic_map *bmap1,
225 __isl_keep isl_basic_map *bmap2);
226 struct isl_basic_map *isl_basic_map_normalize_constraints(
227 struct isl_basic_map *bmap);
228 struct isl_basic_set *isl_basic_set_normalize_constraints(
229 struct isl_basic_set *bset);
230 struct isl_basic_map *isl_basic_map_implicit_equalities(
231 struct isl_basic_map *bmap);
232 struct isl_basic_set *isl_basic_map_underlying_set(struct isl_basic_map *bmap);
233 __isl_give isl_basic_set *isl_basic_set_underlying_set(
234 __isl_take isl_basic_set *bset);
235 __isl_give isl_basic_set_list *isl_basic_map_list_underlying_set(
236 __isl_take isl_basic_map_list *list);
237 struct isl_set *isl_map_underlying_set(struct isl_map *map);
238 struct isl_basic_map *isl_basic_map_overlying_set(struct isl_basic_set *bset,
239 struct isl_basic_map *like);
240 __isl_give isl_basic_set *isl_basic_set_drop_constraints_involving(
241 __isl_take isl_basic_set *bset, unsigned first, unsigned n);
242 __isl_give isl_basic_set *isl_basic_set_drop(__isl_take isl_basic_set *bset,
243 enum isl_dim_type type, unsigned first, unsigned n);
244 struct isl_basic_map *isl_basic_map_drop(struct isl_basic_map *bmap,
245 enum isl_dim_type type, unsigned first, unsigned n);
246 struct isl_set *isl_set_drop(struct isl_set *set,
247 enum isl_dim_type type, unsigned first, unsigned n);
248 struct isl_basic_set *isl_basic_set_drop_dims(
249 struct isl_basic_set *bset, unsigned first, unsigned n);
250 struct isl_set *isl_set_drop_dims(
251 struct isl_set *set, unsigned first, unsigned n);
252 struct isl_map *isl_map_drop_inputs(
253 struct isl_map *map, unsigned first, unsigned n);
254 struct isl_map *isl_map_drop(struct isl_map *map,
255 enum isl_dim_type type, unsigned first, unsigned n);
257 __isl_give isl_basic_map *isl_basic_map_remove_duplicate_constraints(
258 __isl_take isl_basic_map *bmap, int *progress, int detect_divs);
260 struct isl_map *isl_map_remove_empty_parts(struct isl_map *map);
261 struct isl_set *isl_set_remove_empty_parts(struct isl_set *set);
262 __isl_give isl_map *isl_map_remove_obvious_duplicates(__isl_take isl_map *map);
264 struct isl_set *isl_set_normalize(struct isl_set *set);
266 struct isl_set *isl_set_drop_vars(
267 struct isl_set *set, unsigned first, unsigned n);
269 struct isl_basic_map *isl_basic_map_eliminate_vars(
270 struct isl_basic_map *bmap, unsigned pos, unsigned n);
271 struct isl_basic_set *isl_basic_set_eliminate_vars(
272 struct isl_basic_set *bset, unsigned pos, unsigned n);
274 __isl_give isl_map *isl_map_eliminate(__isl_take isl_map *map,
275 enum isl_dim_type type, unsigned first, unsigned n);
276 __isl_give isl_set *isl_set_eliminate(__isl_take isl_set *set,
277 enum isl_dim_type type, unsigned first, unsigned n);
279 int isl_basic_set_constraint_is_redundant(struct isl_basic_set **bset,
280 isl_int *c, isl_int *opt_n, isl_int *opt_d);
282 int isl_basic_map_add_div_constraint(__isl_keep isl_basic_map *bmap,
283 unsigned div, int sign);
284 int isl_basic_map_add_div_constraints(struct isl_basic_map *bmap, unsigned div);
285 __isl_give isl_basic_map *isl_basic_map_add_known_div_constraints(
286 __isl_take isl_basic_map *bmap);
287 struct isl_basic_map *isl_basic_map_drop_redundant_divs(
288 struct isl_basic_map *bmap);
289 struct isl_basic_set *isl_basic_set_drop_redundant_divs(
290 struct isl_basic_set *bset);
292 struct isl_basic_set *isl_basic_set_recession_cone(struct isl_basic_set *bset);
293 struct isl_basic_set *isl_basic_set_lineality_space(struct isl_basic_set *bset);
295 struct isl_basic_set *isl_basic_set_set_rational(struct isl_basic_set *bset);
296 __isl_give isl_set *isl_set_set_rational(__isl_take isl_set *set);
297 __isl_give isl_basic_map *isl_basic_map_set_rational(
298 __isl_take isl_basic_map *bmap);
299 __isl_give isl_map *isl_map_set_rational(__isl_take isl_map *map);
301 int isl_map_has_rational(__isl_keep isl_map *map);
302 int isl_set_has_rational(__isl_keep isl_set *set);
304 struct isl_mat;
306 struct isl_basic_set *isl_basic_set_preimage(struct isl_basic_set *bset,
307 struct isl_mat *mat);
308 struct isl_set *isl_set_preimage(struct isl_set *set, struct isl_mat *mat);
310 __isl_give isl_basic_set *isl_basic_set_transform_dims(
311 __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first,
312 __isl_take isl_mat *trans);
314 isl_int *isl_set_wrap_facet(__isl_keep isl_set *set,
315 isl_int *facet, isl_int *ridge);
317 int isl_basic_map_contains_point(__isl_keep isl_basic_map *bmap,
318 __isl_keep isl_point *point);
319 int isl_set_contains_point(__isl_keep isl_set *set, __isl_keep isl_point *point);
321 int isl_basic_set_vars_get_sign(__isl_keep isl_basic_set *bset,
322 unsigned first, unsigned n, int *signs);
323 int isl_set_foreach_orthant(__isl_keep isl_set *set,
324 int (*fn)(__isl_take isl_set *orthant, int *signs, void *user),
325 void *user);
327 int isl_basic_map_add_div_constraints_var(__isl_keep isl_basic_map *bmap,
328 unsigned pos, isl_int *div);
329 int isl_basic_set_add_div_constraints_var(__isl_keep isl_basic_set *bset,
330 unsigned pos, isl_int *div);
331 int isl_basic_map_is_div_constraint(__isl_keep isl_basic_map *bmap,
332 isl_int *constraint, unsigned div);
333 int isl_basic_set_is_div_constraint(__isl_keep isl_basic_set *bset,
334 isl_int *constraint, unsigned div);
336 __isl_give isl_basic_set *isl_basic_set_from_local_space(
337 __isl_take isl_local_space *ls);
338 __isl_give isl_basic_map *isl_basic_map_from_local_space(
339 __isl_take isl_local_space *ls);
340 __isl_give isl_basic_set *isl_basic_set_expand_divs(
341 __isl_take isl_basic_set *bset, __isl_take isl_mat *div, int *exp);
343 int isl_basic_map_divs_known(__isl_keep isl_basic_map *bmap);
344 __isl_give isl_mat *isl_basic_set_get_divs(__isl_keep isl_basic_set *bset);
345 __isl_give isl_mat *isl_basic_map_get_divs(__isl_keep isl_basic_map *bmap);
347 __isl_give isl_map *isl_map_inline_foreach_basic_map(__isl_take isl_map *map,
348 __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap));
350 __isl_give isl_map *isl_map_align_params_map_map_and(
351 __isl_take isl_map *map1, __isl_take isl_map *map2,
352 __isl_give isl_map *(*fn)(__isl_take isl_map *map1,
353 __isl_take isl_map *map2));
354 int isl_map_align_params_map_map_and_test(__isl_keep isl_map *map1,
355 __isl_keep isl_map *map2,
356 int (*fn)(__isl_keep isl_map *map1, __isl_keep isl_map *map2));
358 int isl_basic_map_foreach_lexopt(__isl_keep isl_basic_map *bmap, int max,
359 int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
360 void *user),
361 void *user);
362 int isl_basic_set_foreach_lexopt(__isl_keep isl_basic_set *bset, int max,
363 int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
364 void *user),
365 void *user);
367 __isl_give isl_set *isl_set_substitute(__isl_take isl_set *set,
368 enum isl_dim_type type, unsigned pos, __isl_keep isl_aff *subs);
370 __isl_give isl_set *isl_set_gist_params_basic_set(__isl_take isl_set *set,
371 __isl_take isl_basic_set *context);
373 int isl_map_compatible_range(__isl_keep isl_map *map, __isl_keep isl_set *set);
375 int isl_basic_map_plain_is_single_valued(__isl_keep isl_basic_map *bmap);
377 int isl_map_is_set(__isl_keep isl_map *map);
379 int isl_basic_set_plain_dim_is_fixed(__isl_keep isl_basic_set *bset,
380 unsigned dim, isl_int *val);
382 int isl_basic_set_dim_residue_class(struct isl_basic_set *bset,
383 int pos, isl_int *modulo, isl_int *residue);
384 int isl_set_dim_residue_class(struct isl_set *set,
385 int pos, isl_int *modulo, isl_int *residue);
387 __isl_give isl_basic_set *isl_basic_set_fix(__isl_take isl_basic_set *bset,
388 enum isl_dim_type type, unsigned pos, isl_int value);
389 __isl_give isl_set *isl_set_fix(__isl_take isl_set *set,
390 enum isl_dim_type type, unsigned pos, isl_int value);
391 int isl_map_plain_is_fixed(__isl_keep isl_map *map,
392 enum isl_dim_type type, unsigned pos, isl_int *val);
394 int isl_basic_map_output_defining_equality(__isl_keep isl_basic_map *bmap,
395 int pos);
397 __isl_give isl_basic_map_list *isl_map_get_basic_map_list(
398 __isl_keep isl_map *map);
400 __isl_give isl_map *isl_map_fixed_power(__isl_take isl_map *map, isl_int exp);
402 int isl_basic_set_count_upto(__isl_keep isl_basic_set *bset,
403 isl_int max, isl_int *count);
404 int isl_set_count_upto(__isl_keep isl_set *set, isl_int max, isl_int *count);
406 #endif