3fbb8f5c0ccf797f3330f4ae03c842e886d4121a
[isl.git] / isl_test.c
blob3fbb8f5c0ccf797f3330f4ae03c842e886d4121a
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 #include <assert.h>
11 #include <stdio.h>
12 #include <limits.h>
13 #include <isl_ctx_private.h>
14 #include <isl_map_private.h>
15 #include <isl_aff_private.h>
16 #include <isl/set.h>
17 #include <isl/flow.h>
18 #include <isl/constraint.h>
19 #include <isl/polynomial.h>
20 #include <isl/union_map.h>
21 #include <isl_factorization.h>
22 #include <isl/schedule.h>
23 #include <isl_options_private.h>
24 #include <isl/vertices.h>
25 #include <isl/ast_build.h>
27 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
29 static char *srcdir;
31 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
32 char *filename;
33 int length;
34 char *pattern = "%s/test_inputs/%s.%s";
36 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
37 + strlen(suffix) + 1;
38 filename = isl_alloc_array(ctx, char, length);
40 if (!filename)
41 return NULL;
43 sprintf(filename, pattern, srcdir, name, suffix);
45 return filename;
48 void test_parse_map(isl_ctx *ctx, const char *str)
50 isl_map *map;
52 map = isl_map_read_from_str(ctx, str);
53 assert(map);
54 isl_map_free(map);
57 int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
59 isl_map *map, *map2;
60 int equal;
62 map = isl_map_read_from_str(ctx, str);
63 map2 = isl_map_read_from_str(ctx, str2);
64 equal = isl_map_is_equal(map, map2);
65 isl_map_free(map);
66 isl_map_free(map2);
68 if (equal < 0)
69 return -1;
70 if (!equal)
71 isl_die(ctx, isl_error_unknown, "maps not equal",
72 return -1);
74 return 0;
77 void test_parse_pwqp(isl_ctx *ctx, const char *str)
79 isl_pw_qpolynomial *pwqp;
81 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
82 assert(pwqp);
83 isl_pw_qpolynomial_free(pwqp);
86 static void test_parse_pwaff(isl_ctx *ctx, const char *str)
88 isl_pw_aff *pwaff;
90 pwaff = isl_pw_aff_read_from_str(ctx, str);
91 assert(pwaff);
92 isl_pw_aff_free(pwaff);
95 int test_parse(struct isl_ctx *ctx)
97 isl_map *map, *map2;
98 const char *str, *str2;
100 str = "{ [i] -> [-i] }";
101 map = isl_map_read_from_str(ctx, str);
102 assert(map);
103 isl_map_free(map);
105 str = "{ A[i] -> L[([i/3])] }";
106 map = isl_map_read_from_str(ctx, str);
107 assert(map);
108 isl_map_free(map);
110 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
111 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
112 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
114 str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
115 str2 = "{ [x, y] : 2y >= 6 - x }";
116 if (test_parse_map_equal(ctx, str, str2) < 0)
117 return -1;
119 if (test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
120 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
121 return -1;
122 str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
123 if (test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }",
124 str) < 0)
125 return -1;
127 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
128 map = isl_map_read_from_str(ctx, str);
129 str = "{ [new, old] -> [o0, o1] : "
130 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
131 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
132 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
133 map2 = isl_map_read_from_str(ctx, str);
134 assert(isl_map_is_equal(map, map2));
135 isl_map_free(map);
136 isl_map_free(map2);
138 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
139 map = isl_map_read_from_str(ctx, str);
140 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
141 map2 = isl_map_read_from_str(ctx, str);
142 assert(isl_map_is_equal(map, map2));
143 isl_map_free(map);
144 isl_map_free(map2);
146 str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
147 str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
148 if (test_parse_map_equal(ctx, str, str2) < 0)
149 return -1;
151 str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
152 str2 = "{ [i,j] -> [min(i,j)] }";
153 if (test_parse_map_equal(ctx, str, str2) < 0)
154 return -1;
156 str = "{ [i,j] : i != j }";
157 str2 = "{ [i,j] : i < j or i > j }";
158 if (test_parse_map_equal(ctx, str, str2) < 0)
159 return -1;
161 str = "{ [i,j] : (i+1)*2 >= j }";
162 str2 = "{ [i, j] : j <= 2 + 2i }";
163 if (test_parse_map_equal(ctx, str, str2) < 0)
164 return -1;
166 str = "{ [i] -> [i > 0 ? 4 : 5] }";
167 str2 = "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
168 if (test_parse_map_equal(ctx, str, str2) < 0)
169 return -1;
171 str = "[N=2,M] -> { [i=[(M+N)/4]] }";
172 str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
173 if (test_parse_map_equal(ctx, str, str2) < 0)
174 return -1;
176 str = "{ [x] : x >= 0 }";
177 str2 = "{ [x] : x-0 >= 0 }";
178 if (test_parse_map_equal(ctx, str, str2) < 0)
179 return -1;
181 str = "{ [i] : ((i > 10)) }";
182 str2 = "{ [i] : i >= 11 }";
183 if (test_parse_map_equal(ctx, str, str2) < 0)
184 return -1;
186 str = "{ [i] -> [0] }";
187 str2 = "{ [i] -> [0 * i] }";
188 if (test_parse_map_equal(ctx, str, str2) < 0)
189 return -1;
191 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
192 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
193 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
194 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
196 if (test_parse_map_equal(ctx, "{ [a] -> [b] : (not false) }",
197 "{ [a] -> [b] : true }") < 0)
198 return -1;
200 if (test_parse_map_equal(ctx, "{ [i] : i/2 <= 5 }",
201 "{ [i] : i <= 10 }") < 0)
202 return -1;
204 if (test_parse_map_equal(ctx, "{Sym=[n] [i] : i <= n }",
205 "[n] -> { [i] : i <= n }") < 0)
206 return -1;
208 if (test_parse_map_equal(ctx, "{ [*] }", "{ [a] }") < 0)
209 return -1;
211 return 0;
214 void test_read(struct isl_ctx *ctx)
216 char *filename;
217 FILE *input;
218 struct isl_basic_set *bset1, *bset2;
219 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
221 filename = get_filename(ctx, "set", "omega");
222 assert(filename);
223 input = fopen(filename, "r");
224 assert(input);
226 bset1 = isl_basic_set_read_from_file(ctx, input);
227 bset2 = isl_basic_set_read_from_str(ctx, str);
229 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
231 isl_basic_set_free(bset1);
232 isl_basic_set_free(bset2);
233 free(filename);
235 fclose(input);
238 void test_bounded(struct isl_ctx *ctx)
240 isl_set *set;
241 int bounded;
243 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
244 bounded = isl_set_is_bounded(set);
245 assert(bounded);
246 isl_set_free(set);
248 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
249 bounded = isl_set_is_bounded(set);
250 assert(!bounded);
251 isl_set_free(set);
253 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
254 bounded = isl_set_is_bounded(set);
255 assert(!bounded);
256 isl_set_free(set);
259 /* Construct the basic set { [i] : 5 <= i <= N } */
260 void test_construction(struct isl_ctx *ctx)
262 isl_int v;
263 isl_space *dim;
264 isl_local_space *ls;
265 struct isl_basic_set *bset;
266 struct isl_constraint *c;
268 isl_int_init(v);
270 dim = isl_space_set_alloc(ctx, 1, 1);
271 bset = isl_basic_set_universe(isl_space_copy(dim));
272 ls = isl_local_space_from_space(dim);
274 c = isl_inequality_alloc(isl_local_space_copy(ls));
275 isl_int_set_si(v, -1);
276 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
277 isl_int_set_si(v, 1);
278 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
279 bset = isl_basic_set_add_constraint(bset, c);
281 c = isl_inequality_alloc(isl_local_space_copy(ls));
282 isl_int_set_si(v, 1);
283 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
284 isl_int_set_si(v, -5);
285 isl_constraint_set_constant(c, v);
286 bset = isl_basic_set_add_constraint(bset, c);
288 isl_local_space_free(ls);
289 isl_basic_set_free(bset);
291 isl_int_clear(v);
294 void test_dim(struct isl_ctx *ctx)
296 const char *str;
297 isl_map *map1, *map2;
299 map1 = isl_map_read_from_str(ctx,
300 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
301 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
302 map2 = isl_map_read_from_str(ctx,
303 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
304 assert(isl_map_is_equal(map1, map2));
305 isl_map_free(map2);
307 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
308 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
309 assert(isl_map_is_equal(map1, map2));
311 isl_map_free(map1);
312 isl_map_free(map2);
314 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
315 map1 = isl_map_read_from_str(ctx, str);
316 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
317 map2 = isl_map_read_from_str(ctx, str);
318 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
319 assert(isl_map_is_equal(map1, map2));
321 isl_map_free(map1);
322 isl_map_free(map2);
325 static int test_div(isl_ctx *ctx)
327 unsigned n;
328 const char *str;
329 int empty;
330 isl_int v;
331 isl_space *dim;
332 isl_set *set;
333 isl_local_space *ls;
334 struct isl_basic_set *bset;
335 struct isl_constraint *c;
337 isl_int_init(v);
339 /* test 1 */
340 dim = isl_space_set_alloc(ctx, 0, 3);
341 bset = isl_basic_set_universe(isl_space_copy(dim));
342 ls = isl_local_space_from_space(dim);
344 c = isl_equality_alloc(isl_local_space_copy(ls));
345 isl_int_set_si(v, -1);
346 isl_constraint_set_constant(c, v);
347 isl_int_set_si(v, 1);
348 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
349 isl_int_set_si(v, 3);
350 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
351 bset = isl_basic_set_add_constraint(bset, c);
353 c = isl_equality_alloc(isl_local_space_copy(ls));
354 isl_int_set_si(v, 1);
355 isl_constraint_set_constant(c, v);
356 isl_int_set_si(v, -1);
357 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
358 isl_int_set_si(v, 3);
359 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
360 bset = isl_basic_set_add_constraint(bset, c);
362 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
364 assert(bset && bset->n_div == 1);
365 isl_local_space_free(ls);
366 isl_basic_set_free(bset);
368 /* test 2 */
369 dim = isl_space_set_alloc(ctx, 0, 3);
370 bset = isl_basic_set_universe(isl_space_copy(dim));
371 ls = isl_local_space_from_space(dim);
373 c = isl_equality_alloc(isl_local_space_copy(ls));
374 isl_int_set_si(v, 1);
375 isl_constraint_set_constant(c, v);
376 isl_int_set_si(v, -1);
377 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
378 isl_int_set_si(v, 3);
379 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
380 bset = isl_basic_set_add_constraint(bset, c);
382 c = isl_equality_alloc(isl_local_space_copy(ls));
383 isl_int_set_si(v, -1);
384 isl_constraint_set_constant(c, v);
385 isl_int_set_si(v, 1);
386 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
387 isl_int_set_si(v, 3);
388 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
389 bset = isl_basic_set_add_constraint(bset, c);
391 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
393 assert(bset && bset->n_div == 1);
394 isl_local_space_free(ls);
395 isl_basic_set_free(bset);
397 /* test 3 */
398 dim = isl_space_set_alloc(ctx, 0, 3);
399 bset = isl_basic_set_universe(isl_space_copy(dim));
400 ls = isl_local_space_from_space(dim);
402 c = isl_equality_alloc(isl_local_space_copy(ls));
403 isl_int_set_si(v, 1);
404 isl_constraint_set_constant(c, v);
405 isl_int_set_si(v, -1);
406 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
407 isl_int_set_si(v, 3);
408 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
409 bset = isl_basic_set_add_constraint(bset, c);
411 c = isl_equality_alloc(isl_local_space_copy(ls));
412 isl_int_set_si(v, -3);
413 isl_constraint_set_constant(c, v);
414 isl_int_set_si(v, 1);
415 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
416 isl_int_set_si(v, 4);
417 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
418 bset = isl_basic_set_add_constraint(bset, c);
420 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
422 assert(bset && bset->n_div == 1);
423 isl_local_space_free(ls);
424 isl_basic_set_free(bset);
426 /* test 4 */
427 dim = isl_space_set_alloc(ctx, 0, 3);
428 bset = isl_basic_set_universe(isl_space_copy(dim));
429 ls = isl_local_space_from_space(dim);
431 c = isl_equality_alloc(isl_local_space_copy(ls));
432 isl_int_set_si(v, 2);
433 isl_constraint_set_constant(c, v);
434 isl_int_set_si(v, -1);
435 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
436 isl_int_set_si(v, 3);
437 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
438 bset = isl_basic_set_add_constraint(bset, c);
440 c = isl_equality_alloc(isl_local_space_copy(ls));
441 isl_int_set_si(v, -1);
442 isl_constraint_set_constant(c, v);
443 isl_int_set_si(v, 1);
444 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
445 isl_int_set_si(v, 6);
446 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
447 bset = isl_basic_set_add_constraint(bset, c);
449 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
451 assert(isl_basic_set_is_empty(bset));
452 isl_local_space_free(ls);
453 isl_basic_set_free(bset);
455 /* test 5 */
456 dim = isl_space_set_alloc(ctx, 0, 3);
457 bset = isl_basic_set_universe(isl_space_copy(dim));
458 ls = isl_local_space_from_space(dim);
460 c = isl_equality_alloc(isl_local_space_copy(ls));
461 isl_int_set_si(v, -1);
462 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
463 isl_int_set_si(v, 3);
464 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
465 bset = isl_basic_set_add_constraint(bset, c);
467 c = isl_equality_alloc(isl_local_space_copy(ls));
468 isl_int_set_si(v, 1);
469 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
470 isl_int_set_si(v, -3);
471 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
472 bset = isl_basic_set_add_constraint(bset, c);
474 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
476 assert(bset && bset->n_div == 0);
477 isl_basic_set_free(bset);
478 isl_local_space_free(ls);
480 /* test 6 */
481 dim = isl_space_set_alloc(ctx, 0, 3);
482 bset = isl_basic_set_universe(isl_space_copy(dim));
483 ls = isl_local_space_from_space(dim);
485 c = isl_equality_alloc(isl_local_space_copy(ls));
486 isl_int_set_si(v, -1);
487 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
488 isl_int_set_si(v, 6);
489 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
490 bset = isl_basic_set_add_constraint(bset, c);
492 c = isl_equality_alloc(isl_local_space_copy(ls));
493 isl_int_set_si(v, 1);
494 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
495 isl_int_set_si(v, -3);
496 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
497 bset = isl_basic_set_add_constraint(bset, c);
499 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
501 assert(bset && bset->n_div == 1);
502 isl_basic_set_free(bset);
503 isl_local_space_free(ls);
505 /* test 7 */
506 /* This test is a bit tricky. We set up an equality
507 * a + 3b + 3c = 6 e0
508 * Normalization of divs creates _two_ divs
509 * a = 3 e0
510 * c - b - e0 = 2 e1
511 * Afterwards e0 is removed again because it has coefficient -1
512 * and we end up with the original equality and div again.
513 * Perhaps we can avoid the introduction of this temporary div.
515 dim = isl_space_set_alloc(ctx, 0, 4);
516 bset = isl_basic_set_universe(isl_space_copy(dim));
517 ls = isl_local_space_from_space(dim);
519 c = isl_equality_alloc(isl_local_space_copy(ls));
520 isl_int_set_si(v, -1);
521 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
522 isl_int_set_si(v, -3);
523 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
524 isl_int_set_si(v, -3);
525 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
526 isl_int_set_si(v, 6);
527 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
528 bset = isl_basic_set_add_constraint(bset, c);
530 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
532 /* Test disabled for now */
534 assert(bset && bset->n_div == 1);
536 isl_local_space_free(ls);
537 isl_basic_set_free(bset);
539 /* test 8 */
540 dim = isl_space_set_alloc(ctx, 0, 5);
541 bset = isl_basic_set_universe(isl_space_copy(dim));
542 ls = isl_local_space_from_space(dim);
544 c = isl_equality_alloc(isl_local_space_copy(ls));
545 isl_int_set_si(v, -1);
546 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
547 isl_int_set_si(v, -3);
548 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
549 isl_int_set_si(v, -3);
550 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
551 isl_int_set_si(v, 6);
552 isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
553 bset = isl_basic_set_add_constraint(bset, c);
555 c = isl_equality_alloc(isl_local_space_copy(ls));
556 isl_int_set_si(v, -1);
557 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
558 isl_int_set_si(v, 1);
559 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
560 isl_int_set_si(v, 1);
561 isl_constraint_set_constant(c, v);
562 bset = isl_basic_set_add_constraint(bset, c);
564 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
566 /* Test disabled for now */
568 assert(bset && bset->n_div == 1);
570 isl_local_space_free(ls);
571 isl_basic_set_free(bset);
573 /* test 9 */
574 dim = isl_space_set_alloc(ctx, 0, 4);
575 bset = isl_basic_set_universe(isl_space_copy(dim));
576 ls = isl_local_space_from_space(dim);
578 c = isl_equality_alloc(isl_local_space_copy(ls));
579 isl_int_set_si(v, 1);
580 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
581 isl_int_set_si(v, -1);
582 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
583 isl_int_set_si(v, -2);
584 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
585 bset = isl_basic_set_add_constraint(bset, c);
587 c = isl_equality_alloc(isl_local_space_copy(ls));
588 isl_int_set_si(v, -1);
589 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
590 isl_int_set_si(v, 3);
591 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
592 isl_int_set_si(v, 2);
593 isl_constraint_set_constant(c, v);
594 bset = isl_basic_set_add_constraint(bset, c);
596 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
598 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
600 assert(!isl_basic_set_is_empty(bset));
602 isl_local_space_free(ls);
603 isl_basic_set_free(bset);
605 /* test 10 */
606 dim = isl_space_set_alloc(ctx, 0, 3);
607 bset = isl_basic_set_universe(isl_space_copy(dim));
608 ls = isl_local_space_from_space(dim);
610 c = isl_equality_alloc(isl_local_space_copy(ls));
611 isl_int_set_si(v, 1);
612 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
613 isl_int_set_si(v, -2);
614 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
615 bset = isl_basic_set_add_constraint(bset, c);
617 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
619 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
621 isl_local_space_free(ls);
622 isl_basic_set_free(bset);
624 isl_int_clear(v);
626 str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
627 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
628 set = isl_set_read_from_str(ctx, str);
629 set = isl_set_compute_divs(set);
630 isl_set_free(set);
631 if (!set)
632 return -1;
634 str = "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
635 bset = isl_basic_set_read_from_str(ctx, str);
636 n = isl_basic_set_dim(bset, isl_dim_div);
637 isl_basic_set_free(bset);
638 if (!bset)
639 return -1;
640 if (n != 0)
641 isl_die(ctx, isl_error_unknown,
642 "expecting no existentials", return -1);
644 str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
645 set = isl_set_read_from_str(ctx, str);
646 set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2);
647 set = isl_set_fix_si(set, isl_dim_set, 2, -3);
648 empty = isl_set_is_empty(set);
649 isl_set_free(set);
650 if (empty < 0)
651 return -1;
652 if (!empty)
653 isl_die(ctx, isl_error_unknown,
654 "result not as accurate as expected", return -1);
656 return 0;
659 void test_application_case(struct isl_ctx *ctx, const char *name)
661 char *filename;
662 FILE *input;
663 struct isl_basic_set *bset1, *bset2;
664 struct isl_basic_map *bmap;
666 filename = get_filename(ctx, name, "omega");
667 assert(filename);
668 input = fopen(filename, "r");
669 assert(input);
671 bset1 = isl_basic_set_read_from_file(ctx, input);
672 bmap = isl_basic_map_read_from_file(ctx, input);
674 bset1 = isl_basic_set_apply(bset1, bmap);
676 bset2 = isl_basic_set_read_from_file(ctx, input);
678 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
680 isl_basic_set_free(bset1);
681 isl_basic_set_free(bset2);
682 free(filename);
684 fclose(input);
687 void test_application(struct isl_ctx *ctx)
689 test_application_case(ctx, "application");
690 test_application_case(ctx, "application2");
693 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
695 char *filename;
696 FILE *input;
697 struct isl_basic_set *bset1, *bset2;
699 filename = get_filename(ctx, name, "polylib");
700 assert(filename);
701 input = fopen(filename, "r");
702 assert(input);
704 bset1 = isl_basic_set_read_from_file(ctx, input);
705 bset2 = isl_basic_set_read_from_file(ctx, input);
707 bset1 = isl_basic_set_affine_hull(bset1);
709 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
711 isl_basic_set_free(bset1);
712 isl_basic_set_free(bset2);
713 free(filename);
715 fclose(input);
718 int test_affine_hull(struct isl_ctx *ctx)
720 const char *str;
721 isl_set *set;
722 isl_basic_set *bset;
723 int n;
725 test_affine_hull_case(ctx, "affine2");
726 test_affine_hull_case(ctx, "affine");
727 test_affine_hull_case(ctx, "affine3");
729 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
730 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
731 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
732 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
733 set = isl_set_read_from_str(ctx, str);
734 bset = isl_set_affine_hull(set);
735 n = isl_basic_set_dim(bset, isl_dim_div);
736 isl_basic_set_free(bset);
737 if (n != 0)
738 isl_die(ctx, isl_error_unknown, "not expecting any divs",
739 return -1);
741 return 0;
744 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
746 char *filename;
747 FILE *input;
748 struct isl_basic_set *bset1, *bset2;
749 struct isl_set *set;
751 filename = get_filename(ctx, name, "polylib");
752 assert(filename);
753 input = fopen(filename, "r");
754 assert(input);
756 bset1 = isl_basic_set_read_from_file(ctx, input);
757 bset2 = isl_basic_set_read_from_file(ctx, input);
759 set = isl_basic_set_union(bset1, bset2);
760 bset1 = isl_set_convex_hull(set);
762 bset2 = isl_basic_set_read_from_file(ctx, input);
764 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
766 isl_basic_set_free(bset1);
767 isl_basic_set_free(bset2);
768 free(filename);
770 fclose(input);
773 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
775 const char *str1, *str2;
776 isl_set *set1, *set2;
777 int orig_convex = ctx->opt->convex;
778 ctx->opt->convex = convex;
780 test_convex_hull_case(ctx, "convex0");
781 test_convex_hull_case(ctx, "convex1");
782 test_convex_hull_case(ctx, "convex2");
783 test_convex_hull_case(ctx, "convex3");
784 test_convex_hull_case(ctx, "convex4");
785 test_convex_hull_case(ctx, "convex5");
786 test_convex_hull_case(ctx, "convex6");
787 test_convex_hull_case(ctx, "convex7");
788 test_convex_hull_case(ctx, "convex8");
789 test_convex_hull_case(ctx, "convex9");
790 test_convex_hull_case(ctx, "convex10");
791 test_convex_hull_case(ctx, "convex11");
792 test_convex_hull_case(ctx, "convex12");
793 test_convex_hull_case(ctx, "convex13");
794 test_convex_hull_case(ctx, "convex14");
795 test_convex_hull_case(ctx, "convex15");
797 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
798 "(i0 = 1 and i1 = 0 and i2 = 1) or "
799 "(i0 = 0 and i1 = 0 and i2 = 0) }";
800 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
801 set1 = isl_set_read_from_str(ctx, str1);
802 set2 = isl_set_read_from_str(ctx, str2);
803 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
804 assert(isl_set_is_equal(set1, set2));
805 isl_set_free(set1);
806 isl_set_free(set2);
808 ctx->opt->convex = orig_convex;
811 void test_convex_hull(struct isl_ctx *ctx)
813 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
814 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
817 void test_gist_case(struct isl_ctx *ctx, const char *name)
819 char *filename;
820 FILE *input;
821 struct isl_basic_set *bset1, *bset2;
823 filename = get_filename(ctx, name, "polylib");
824 assert(filename);
825 input = fopen(filename, "r");
826 assert(input);
828 bset1 = isl_basic_set_read_from_file(ctx, input);
829 bset2 = isl_basic_set_read_from_file(ctx, input);
831 bset1 = isl_basic_set_gist(bset1, bset2);
833 bset2 = isl_basic_set_read_from_file(ctx, input);
835 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
837 isl_basic_set_free(bset1);
838 isl_basic_set_free(bset2);
839 free(filename);
841 fclose(input);
844 void test_gist(struct isl_ctx *ctx)
846 const char *str;
847 isl_basic_set *bset1, *bset2;
849 test_gist_case(ctx, "gist1");
851 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
852 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
853 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
854 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
855 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
856 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
857 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
858 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
859 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
860 bset1 = isl_basic_set_read_from_str(ctx, str);
861 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
862 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
863 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
864 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
865 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
866 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
867 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
868 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
869 bset2 = isl_basic_set_read_from_str(ctx, str);
870 bset1 = isl_basic_set_gist(bset1, bset2);
871 assert(bset1 && bset1->n_div == 0);
872 isl_basic_set_free(bset1);
875 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
877 isl_set *set, *set2;
878 int equal;
879 int one;
881 set = isl_set_read_from_str(ctx, str);
882 set = isl_set_coalesce(set);
883 set2 = isl_set_read_from_str(ctx, str);
884 equal = isl_set_is_equal(set, set2);
885 one = set && set->n == 1;
886 isl_set_free(set);
887 isl_set_free(set2);
889 if (equal < 0)
890 return -1;
891 if (!equal)
892 isl_die(ctx, isl_error_unknown,
893 "coalesced set not equal to input", return -1);
894 if (check_one && !one)
895 isl_die(ctx, isl_error_unknown,
896 "coalesced set should not be a union", return -1);
898 return 0;
901 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
903 int r = 0;
904 int bounded;
906 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
907 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
909 if (test_coalesce_set(ctx,
910 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
911 "-x - y + 1 >= 0 and -3 <= z <= 3;"
912 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
913 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
914 "-10 <= y <= 0}", 1) < 0)
915 goto error;
916 if (test_coalesce_set(ctx,
917 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
918 goto error;
919 if (test_coalesce_set(ctx,
920 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
921 goto error;
923 if (0) {
924 error:
925 r = -1;
928 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
930 return r;
933 /* Inputs for coalescing tests.
934 * "str" is a string representation of the input set.
935 * "single_disjunct" is set if we expect the result to consist of
936 * a single disjunct.
938 struct {
939 int single_disjunct;
940 const char *str;
941 } coalesce_tests[] = {
942 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
943 "y >= x & x >= 2 & 5 >= y }" },
944 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
945 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
946 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
947 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
948 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
949 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
950 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
951 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
952 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
953 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
954 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
955 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
956 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
957 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
958 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
959 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
960 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
961 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
962 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
963 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
964 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
965 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
966 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
967 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
968 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
969 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
970 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
971 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
972 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
973 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
974 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
975 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
976 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
977 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
978 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
979 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
980 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
981 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
982 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
983 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
984 "[o0, o1, o2, o3, o4, o5, o6]] : "
985 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
986 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
987 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
988 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
989 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
990 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
991 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
992 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
993 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
994 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
995 "o6 >= i3 + i6 - o3 and M >= 0 and "
996 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
997 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
998 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
999 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1000 "(o0 = 0 and M >= 2 and N >= 3) or "
1001 "(M = 0 and o0 = 0 and N >= 3) }" },
1002 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1003 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1004 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1005 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1006 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1007 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1008 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1009 "(y = 3 and x = 1) }" },
1010 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1011 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1012 "i1 <= M and i3 <= M and i4 <= M) or "
1013 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1014 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1015 "i4 <= -1 + M) }" },
1016 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1017 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1018 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1019 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1020 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1021 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1022 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1023 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1024 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1025 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1026 { 0, "{ [a, b] : exists e : 2e = a and "
1027 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1028 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1029 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1030 "j >= 1 and j' <= i + j - i' and i >= 1; "
1031 "[1, 1, 1, 1] }" },
1032 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1033 "[i,j] : exists a : j = 3a }" },
1034 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1035 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1036 "a >= 3) or "
1037 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1038 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1039 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1040 "c <= 6 + 8a and a >= 3; "
1041 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1042 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1043 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1044 "[x,0] : 3 <= x <= 4 }" },
1045 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1046 "[x,0] : 4 <= x <= 5 }" },
1047 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1048 "[x,0] : 3 <= x <= 5 }" },
1049 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1050 "[x,0] : 3 <= x <= 4 }" },
1051 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1052 "i1 <= 0; "
1053 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1056 /* Test the functionality of isl_set_coalesce.
1057 * That is, check that the output is always equal to the input
1058 * and in some cases that the result consists of a single disjunct.
1060 static int test_coalesce(struct isl_ctx *ctx)
1062 int i;
1064 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
1065 const char *str = coalesce_tests[i].str;
1066 int check_one = coalesce_tests[i].single_disjunct;
1067 if (test_coalesce_set(ctx, str, check_one) < 0)
1068 return -1;
1071 if (test_coalesce_unbounded_wrapping(ctx) < 0)
1072 return -1;
1074 return 0;
1077 void test_closure(struct isl_ctx *ctx)
1079 const char *str;
1080 isl_set *dom;
1081 isl_map *up, *right;
1082 isl_map *map, *map2;
1083 int exact;
1085 /* COCOA example 1 */
1086 map = isl_map_read_from_str(ctx,
1087 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1088 "1 <= i and i < n and 1 <= j and j < n or "
1089 "i2 = i + 1 and j2 = j - 1 and "
1090 "1 <= i and i < n and 2 <= j and j <= n }");
1091 map = isl_map_power(map, &exact);
1092 assert(exact);
1093 isl_map_free(map);
1095 /* COCOA example 1 */
1096 map = isl_map_read_from_str(ctx,
1097 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1098 "1 <= i and i < n and 1 <= j and j < n or "
1099 "i2 = i + 1 and j2 = j - 1 and "
1100 "1 <= i and i < n and 2 <= j and j <= n }");
1101 map = isl_map_transitive_closure(map, &exact);
1102 assert(exact);
1103 map2 = isl_map_read_from_str(ctx,
1104 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1105 "1 <= i and i < n and 1 <= j and j <= n and "
1106 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1107 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1108 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1109 assert(isl_map_is_equal(map, map2));
1110 isl_map_free(map2);
1111 isl_map_free(map);
1113 map = isl_map_read_from_str(ctx,
1114 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1115 " 0 <= y and y <= n }");
1116 map = isl_map_transitive_closure(map, &exact);
1117 map2 = isl_map_read_from_str(ctx,
1118 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1119 " 0 <= y and y <= n }");
1120 assert(isl_map_is_equal(map, map2));
1121 isl_map_free(map2);
1122 isl_map_free(map);
1124 /* COCOA example 2 */
1125 map = isl_map_read_from_str(ctx,
1126 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1127 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1128 "i2 = i + 2 and j2 = j - 2 and "
1129 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1130 map = isl_map_transitive_closure(map, &exact);
1131 assert(exact);
1132 map2 = isl_map_read_from_str(ctx,
1133 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1134 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1135 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1136 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1137 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1138 assert(isl_map_is_equal(map, map2));
1139 isl_map_free(map);
1140 isl_map_free(map2);
1142 /* COCOA Fig.2 left */
1143 map = isl_map_read_from_str(ctx,
1144 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1145 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1146 "j <= n or "
1147 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1148 "j <= 2 i - 3 and j <= n - 2 or "
1149 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1150 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1151 map = isl_map_transitive_closure(map, &exact);
1152 assert(exact);
1153 isl_map_free(map);
1155 /* COCOA Fig.2 right */
1156 map = isl_map_read_from_str(ctx,
1157 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1158 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1159 "j <= n or "
1160 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1161 "j <= 2 i - 4 and j <= n - 3 or "
1162 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1163 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1164 map = isl_map_power(map, &exact);
1165 assert(exact);
1166 isl_map_free(map);
1168 /* COCOA Fig.2 right */
1169 map = isl_map_read_from_str(ctx,
1170 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1171 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1172 "j <= n or "
1173 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1174 "j <= 2 i - 4 and j <= n - 3 or "
1175 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1176 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1177 map = isl_map_transitive_closure(map, &exact);
1178 assert(exact);
1179 map2 = isl_map_read_from_str(ctx,
1180 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1181 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1182 "j <= n and 3 + i + 2 j <= 3 n and "
1183 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1184 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1185 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1186 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1187 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1188 assert(isl_map_is_equal(map, map2));
1189 isl_map_free(map2);
1190 isl_map_free(map);
1192 /* COCOA Fig.1 right */
1193 dom = isl_set_read_from_str(ctx,
1194 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1195 "2 x - 3 y + 3 >= 0 }");
1196 right = isl_map_read_from_str(ctx,
1197 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1198 up = isl_map_read_from_str(ctx,
1199 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1200 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1201 right = isl_map_intersect_range(right, isl_set_copy(dom));
1202 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1203 up = isl_map_intersect_range(up, dom);
1204 map = isl_map_union(up, right);
1205 map = isl_map_transitive_closure(map, &exact);
1206 assert(exact);
1207 map2 = isl_map_read_from_str(ctx,
1208 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1209 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1210 assert(isl_map_is_equal(map, map2));
1211 isl_map_free(map2);
1212 isl_map_free(map);
1214 /* COCOA Theorem 1 counter example */
1215 map = isl_map_read_from_str(ctx,
1216 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1217 "i2 = 1 and j2 = j or "
1218 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1219 map = isl_map_transitive_closure(map, &exact);
1220 assert(exact);
1221 isl_map_free(map);
1223 map = isl_map_read_from_str(ctx,
1224 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1225 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1226 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1227 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1228 map = isl_map_transitive_closure(map, &exact);
1229 assert(exact);
1230 isl_map_free(map);
1232 /* Kelly et al 1996, fig 12 */
1233 map = isl_map_read_from_str(ctx,
1234 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1235 "1 <= i,j,j+1 <= n or "
1236 "j = n and j2 = 1 and i2 = i + 1 and "
1237 "1 <= i,i+1 <= n }");
1238 map = isl_map_transitive_closure(map, &exact);
1239 assert(exact);
1240 map2 = isl_map_read_from_str(ctx,
1241 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1242 "1 <= i <= n and i = i2 or "
1243 "1 <= i < i2 <= n and 1 <= j <= n and "
1244 "1 <= j2 <= n }");
1245 assert(isl_map_is_equal(map, map2));
1246 isl_map_free(map2);
1247 isl_map_free(map);
1249 /* Omega's closure4 */
1250 map = isl_map_read_from_str(ctx,
1251 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1252 "1 <= x,y <= 10 or "
1253 "x2 = x + 1 and y2 = y and "
1254 "1 <= x <= 20 && 5 <= y <= 15 }");
1255 map = isl_map_transitive_closure(map, &exact);
1256 assert(exact);
1257 isl_map_free(map);
1259 map = isl_map_read_from_str(ctx,
1260 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1261 map = isl_map_transitive_closure(map, &exact);
1262 assert(!exact);
1263 map2 = isl_map_read_from_str(ctx,
1264 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1265 assert(isl_map_is_equal(map, map2));
1266 isl_map_free(map);
1267 isl_map_free(map2);
1269 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1270 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1271 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1272 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1273 map = isl_map_read_from_str(ctx, str);
1274 map = isl_map_transitive_closure(map, &exact);
1275 assert(exact);
1276 map2 = isl_map_read_from_str(ctx, str);
1277 assert(isl_map_is_equal(map, map2));
1278 isl_map_free(map);
1279 isl_map_free(map2);
1281 str = "{[0] -> [1]; [2] -> [3]}";
1282 map = isl_map_read_from_str(ctx, str);
1283 map = isl_map_transitive_closure(map, &exact);
1284 assert(exact);
1285 map2 = isl_map_read_from_str(ctx, str);
1286 assert(isl_map_is_equal(map, map2));
1287 isl_map_free(map);
1288 isl_map_free(map2);
1290 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1291 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1292 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1293 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1294 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1295 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1296 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1297 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1298 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1299 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1300 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1301 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1302 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1303 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1304 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1305 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1306 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1307 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1308 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1309 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1310 map = isl_map_read_from_str(ctx, str);
1311 map = isl_map_transitive_closure(map, NULL);
1312 assert(map);
1313 isl_map_free(map);
1316 void test_lex(struct isl_ctx *ctx)
1318 isl_space *dim;
1319 isl_map *map;
1321 dim = isl_space_set_alloc(ctx, 0, 0);
1322 map = isl_map_lex_le(dim);
1323 assert(!isl_map_is_empty(map));
1324 isl_map_free(map);
1327 static int test_lexmin(struct isl_ctx *ctx)
1329 int equal;
1330 const char *str;
1331 isl_basic_map *bmap;
1332 isl_map *map, *map2;
1333 isl_set *set;
1334 isl_set *set2;
1335 isl_pw_multi_aff *pma;
1337 str = "[p0, p1] -> { [] -> [] : "
1338 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1339 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1340 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1341 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1342 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1343 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1344 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1345 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1346 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1347 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1348 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1349 map = isl_map_read_from_str(ctx, str);
1350 map = isl_map_lexmin(map);
1351 isl_map_free(map);
1353 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1354 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1355 set = isl_set_read_from_str(ctx, str);
1356 set = isl_set_lexmax(set);
1357 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1358 set2 = isl_set_read_from_str(ctx, str);
1359 set = isl_set_intersect(set, set2);
1360 assert(!isl_set_is_empty(set));
1361 isl_set_free(set);
1363 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1364 map = isl_map_read_from_str(ctx, str);
1365 map = isl_map_lexmin(map);
1366 str = "{ [x] -> [5] : 6 <= x <= 8; "
1367 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1368 map2 = isl_map_read_from_str(ctx, str);
1369 assert(isl_map_is_equal(map, map2));
1370 isl_map_free(map);
1371 isl_map_free(map2);
1373 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1374 map = isl_map_read_from_str(ctx, str);
1375 map2 = isl_map_copy(map);
1376 map = isl_map_lexmin(map);
1377 assert(isl_map_is_equal(map, map2));
1378 isl_map_free(map);
1379 isl_map_free(map2);
1381 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1382 map = isl_map_read_from_str(ctx, str);
1383 map = isl_map_lexmin(map);
1384 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1385 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1386 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1387 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1388 map2 = isl_map_read_from_str(ctx, str);
1389 assert(isl_map_is_equal(map, map2));
1390 isl_map_free(map);
1391 isl_map_free(map2);
1393 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1394 " 8i' <= i and 8i' >= -7 + i }";
1395 bmap = isl_basic_map_read_from_str(ctx, str);
1396 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
1397 map2 = isl_map_from_pw_multi_aff(pma);
1398 map = isl_map_from_basic_map(bmap);
1399 assert(isl_map_is_equal(map, map2));
1400 isl_map_free(map);
1401 isl_map_free(map2);
1403 str = "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1404 map = isl_map_read_from_str(ctx, str);
1405 map = isl_map_lexmin(map);
1406 str = "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1407 map2 = isl_map_read_from_str(ctx, str);
1408 assert(isl_map_is_equal(map, map2));
1409 isl_map_free(map);
1410 isl_map_free(map2);
1412 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1413 " 8i' <= i and 8i' >= -7 + i }";
1414 set = isl_set_read_from_str(ctx, str);
1415 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
1416 set2 = isl_set_from_pw_multi_aff(pma);
1417 equal = isl_set_is_equal(set, set2);
1418 isl_set_free(set);
1419 isl_set_free(set2);
1420 if (equal < 0)
1421 return -1;
1422 if (!equal)
1423 isl_die(ctx, isl_error_unknown,
1424 "unexpected difference between set and "
1425 "piecewise affine expression", return -1);
1427 return 0;
1430 struct must_may {
1431 isl_map *must;
1432 isl_map *may;
1435 static int collect_must_may(__isl_take isl_map *dep, int must,
1436 void *dep_user, void *user)
1438 struct must_may *mm = (struct must_may *)user;
1440 if (must)
1441 mm->must = isl_map_union(mm->must, dep);
1442 else
1443 mm->may = isl_map_union(mm->may, dep);
1445 return 0;
1448 static int common_space(void *first, void *second)
1450 int depth = *(int *)first;
1451 return 2 * depth;
1454 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1456 isl_map *map2;
1457 int equal;
1459 if (!map)
1460 return -1;
1462 map2 = isl_map_read_from_str(map->ctx, str);
1463 equal = isl_map_is_equal(map, map2);
1464 isl_map_free(map2);
1466 return equal;
1469 static int map_check_equal(__isl_keep isl_map *map, const char *str)
1471 int equal;
1473 equal = map_is_equal(map, str);
1474 if (equal < 0)
1475 return -1;
1476 if (!equal)
1477 isl_die(isl_map_get_ctx(map), isl_error_unknown,
1478 "result not as expected", return -1);
1479 return 0;
1482 void test_dep(struct isl_ctx *ctx)
1484 const char *str;
1485 isl_space *dim;
1486 isl_map *map;
1487 isl_access_info *ai;
1488 isl_flow *flow;
1489 int depth;
1490 struct must_may mm;
1492 depth = 3;
1494 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1495 map = isl_map_read_from_str(ctx, str);
1496 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1498 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1499 map = isl_map_read_from_str(ctx, str);
1500 ai = isl_access_info_add_source(ai, map, 1, &depth);
1502 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1503 map = isl_map_read_from_str(ctx, str);
1504 ai = isl_access_info_add_source(ai, map, 1, &depth);
1506 flow = isl_access_info_compute_flow(ai);
1507 dim = isl_space_alloc(ctx, 0, 3, 3);
1508 mm.must = isl_map_empty(isl_space_copy(dim));
1509 mm.may = isl_map_empty(dim);
1511 isl_flow_foreach(flow, collect_must_may, &mm);
1513 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1514 " [1,10,0] -> [2,5,0] }";
1515 assert(map_is_equal(mm.must, str));
1516 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1517 assert(map_is_equal(mm.may, str));
1519 isl_map_free(mm.must);
1520 isl_map_free(mm.may);
1521 isl_flow_free(flow);
1524 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1525 map = isl_map_read_from_str(ctx, str);
1526 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1528 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1529 map = isl_map_read_from_str(ctx, str);
1530 ai = isl_access_info_add_source(ai, map, 1, &depth);
1532 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1533 map = isl_map_read_from_str(ctx, str);
1534 ai = isl_access_info_add_source(ai, map, 0, &depth);
1536 flow = isl_access_info_compute_flow(ai);
1537 dim = isl_space_alloc(ctx, 0, 3, 3);
1538 mm.must = isl_map_empty(isl_space_copy(dim));
1539 mm.may = isl_map_empty(dim);
1541 isl_flow_foreach(flow, collect_must_may, &mm);
1543 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1544 assert(map_is_equal(mm.must, str));
1545 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1546 assert(map_is_equal(mm.may, str));
1548 isl_map_free(mm.must);
1549 isl_map_free(mm.may);
1550 isl_flow_free(flow);
1553 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1554 map = isl_map_read_from_str(ctx, str);
1555 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1557 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1558 map = isl_map_read_from_str(ctx, str);
1559 ai = isl_access_info_add_source(ai, map, 0, &depth);
1561 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1562 map = isl_map_read_from_str(ctx, str);
1563 ai = isl_access_info_add_source(ai, map, 0, &depth);
1565 flow = isl_access_info_compute_flow(ai);
1566 dim = isl_space_alloc(ctx, 0, 3, 3);
1567 mm.must = isl_map_empty(isl_space_copy(dim));
1568 mm.may = isl_map_empty(dim);
1570 isl_flow_foreach(flow, collect_must_may, &mm);
1572 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1573 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1574 assert(map_is_equal(mm.may, str));
1575 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1576 assert(map_is_equal(mm.must, str));
1578 isl_map_free(mm.must);
1579 isl_map_free(mm.may);
1580 isl_flow_free(flow);
1583 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1584 map = isl_map_read_from_str(ctx, str);
1585 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1587 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1588 map = isl_map_read_from_str(ctx, str);
1589 ai = isl_access_info_add_source(ai, map, 0, &depth);
1591 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1592 map = isl_map_read_from_str(ctx, str);
1593 ai = isl_access_info_add_source(ai, map, 0, &depth);
1595 flow = isl_access_info_compute_flow(ai);
1596 dim = isl_space_alloc(ctx, 0, 3, 3);
1597 mm.must = isl_map_empty(isl_space_copy(dim));
1598 mm.may = isl_map_empty(dim);
1600 isl_flow_foreach(flow, collect_must_may, &mm);
1602 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1603 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1604 assert(map_is_equal(mm.may, str));
1605 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1606 assert(map_is_equal(mm.must, str));
1608 isl_map_free(mm.must);
1609 isl_map_free(mm.may);
1610 isl_flow_free(flow);
1613 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1614 map = isl_map_read_from_str(ctx, str);
1615 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1617 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1618 map = isl_map_read_from_str(ctx, str);
1619 ai = isl_access_info_add_source(ai, map, 0, &depth);
1621 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1622 map = isl_map_read_from_str(ctx, str);
1623 ai = isl_access_info_add_source(ai, map, 0, &depth);
1625 flow = isl_access_info_compute_flow(ai);
1626 dim = isl_space_alloc(ctx, 0, 3, 3);
1627 mm.must = isl_map_empty(isl_space_copy(dim));
1628 mm.may = isl_map_empty(dim);
1630 isl_flow_foreach(flow, collect_must_may, &mm);
1632 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1633 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1634 assert(map_is_equal(mm.may, str));
1635 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1636 assert(map_is_equal(mm.must, str));
1638 isl_map_free(mm.must);
1639 isl_map_free(mm.may);
1640 isl_flow_free(flow);
1643 depth = 5;
1645 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1646 map = isl_map_read_from_str(ctx, str);
1647 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1649 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1650 map = isl_map_read_from_str(ctx, str);
1651 ai = isl_access_info_add_source(ai, map, 1, &depth);
1653 flow = isl_access_info_compute_flow(ai);
1654 dim = isl_space_alloc(ctx, 0, 5, 5);
1655 mm.must = isl_map_empty(isl_space_copy(dim));
1656 mm.may = isl_map_empty(dim);
1658 isl_flow_foreach(flow, collect_must_may, &mm);
1660 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1661 assert(map_is_equal(mm.must, str));
1662 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1663 assert(map_is_equal(mm.may, str));
1665 isl_map_free(mm.must);
1666 isl_map_free(mm.may);
1667 isl_flow_free(flow);
1670 int test_sv(isl_ctx *ctx)
1672 const char *str;
1673 isl_map *map;
1674 isl_union_map *umap;
1675 int sv;
1677 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1678 map = isl_map_read_from_str(ctx, str);
1679 sv = isl_map_is_single_valued(map);
1680 isl_map_free(map);
1681 if (sv < 0)
1682 return -1;
1683 if (!sv)
1684 isl_die(ctx, isl_error_internal,
1685 "map not detected as single valued", return -1);
1687 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1688 map = isl_map_read_from_str(ctx, str);
1689 sv = isl_map_is_single_valued(map);
1690 isl_map_free(map);
1691 if (sv < 0)
1692 return -1;
1693 if (sv)
1694 isl_die(ctx, isl_error_internal,
1695 "map detected as single valued", return -1);
1697 str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1698 umap = isl_union_map_read_from_str(ctx, str);
1699 sv = isl_union_map_is_single_valued(umap);
1700 isl_union_map_free(umap);
1701 if (sv < 0)
1702 return -1;
1703 if (!sv)
1704 isl_die(ctx, isl_error_internal,
1705 "map not detected as single valued", return -1);
1707 str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1708 umap = isl_union_map_read_from_str(ctx, str);
1709 sv = isl_union_map_is_single_valued(umap);
1710 isl_union_map_free(umap);
1711 if (sv < 0)
1712 return -1;
1713 if (sv)
1714 isl_die(ctx, isl_error_internal,
1715 "map detected as single valued", return -1);
1717 return 0;
1720 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1722 isl_map *map;
1724 map = isl_map_read_from_str(ctx, str);
1725 if (bijective)
1726 assert(isl_map_is_bijective(map));
1727 else
1728 assert(!isl_map_is_bijective(map));
1729 isl_map_free(map);
1732 void test_bijective(struct isl_ctx *ctx)
1734 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1735 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1736 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1737 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1738 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1739 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1740 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1741 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1742 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1743 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1744 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1745 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1746 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1749 void test_pwqp(struct isl_ctx *ctx)
1751 const char *str;
1752 isl_set *set;
1753 isl_pw_qpolynomial *pwqp1, *pwqp2;
1755 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1756 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1758 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1759 isl_dim_in, 1, 1);
1761 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1762 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1764 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1766 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1768 isl_pw_qpolynomial_free(pwqp1);
1770 str = "{ [i] -> i }";
1771 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1772 str = "{ [k] : exists a : k = 2a }";
1773 set = isl_set_read_from_str(ctx, str);
1774 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1775 str = "{ [i] -> i }";
1776 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1778 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1780 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1782 isl_pw_qpolynomial_free(pwqp1);
1784 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1785 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1786 str = "{ [10] }";
1787 set = isl_set_read_from_str(ctx, str);
1788 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1789 str = "{ [i] -> 16 }";
1790 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1792 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1794 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1796 isl_pw_qpolynomial_free(pwqp1);
1798 str = "{ [i] -> ([(i)/2]) }";
1799 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1800 str = "{ [k] : exists a : k = 2a+1 }";
1801 set = isl_set_read_from_str(ctx, str);
1802 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1803 str = "{ [i] -> -1/2 + 1/2 * i }";
1804 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1806 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1808 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1810 isl_pw_qpolynomial_free(pwqp1);
1812 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1813 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1814 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1815 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1817 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1819 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1821 isl_pw_qpolynomial_free(pwqp1);
1823 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1824 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1825 str = "{ [x] -> x }";
1826 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1828 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1830 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1832 isl_pw_qpolynomial_free(pwqp1);
1834 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1835 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1836 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1837 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
1838 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1839 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1840 isl_pw_qpolynomial_free(pwqp1);
1843 void test_split_periods(isl_ctx *ctx)
1845 const char *str;
1846 isl_pw_qpolynomial *pwqp;
1848 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1849 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1850 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1851 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1853 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1854 assert(pwqp);
1856 isl_pw_qpolynomial_free(pwqp);
1859 void test_union(isl_ctx *ctx)
1861 const char *str;
1862 isl_union_set *uset1, *uset2;
1863 isl_union_map *umap1, *umap2;
1865 str = "{ [i] : 0 <= i <= 1 }";
1866 uset1 = isl_union_set_read_from_str(ctx, str);
1867 str = "{ [1] -> [0] }";
1868 umap1 = isl_union_map_read_from_str(ctx, str);
1870 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1871 assert(isl_union_map_is_equal(umap1, umap2));
1873 isl_union_map_free(umap1);
1874 isl_union_map_free(umap2);
1876 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1877 umap1 = isl_union_map_read_from_str(ctx, str);
1878 str = "{ A[i]; B[i] }";
1879 uset1 = isl_union_set_read_from_str(ctx, str);
1881 uset2 = isl_union_map_domain(umap1);
1883 assert(isl_union_set_is_equal(uset1, uset2));
1885 isl_union_set_free(uset1);
1886 isl_union_set_free(uset2);
1889 void test_bound(isl_ctx *ctx)
1891 const char *str;
1892 isl_pw_qpolynomial *pwqp;
1893 isl_pw_qpolynomial_fold *pwf;
1895 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
1896 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1897 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1898 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 4);
1899 isl_pw_qpolynomial_fold_free(pwf);
1901 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1902 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1903 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1904 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 1);
1905 isl_pw_qpolynomial_fold_free(pwf);
1908 void test_lift(isl_ctx *ctx)
1910 const char *str;
1911 isl_basic_map *bmap;
1912 isl_basic_set *bset;
1914 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1915 bset = isl_basic_set_read_from_str(ctx, str);
1916 bset = isl_basic_set_lift(bset);
1917 bmap = isl_basic_map_from_range(bset);
1918 bset = isl_basic_map_domain(bmap);
1919 isl_basic_set_free(bset);
1922 struct {
1923 const char *set1;
1924 const char *set2;
1925 int subset;
1926 } subset_tests[] = {
1927 { "{ [112, 0] }",
1928 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1929 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1930 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
1931 { "{ [65] }",
1932 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
1933 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
1934 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
1935 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
1936 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
1937 "256e0 <= 255i and 256e0 >= -255 + 255i and "
1938 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
1939 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
1940 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
1941 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
1942 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
1943 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
1944 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
1947 static int test_subset(isl_ctx *ctx)
1949 int i;
1950 isl_set *set1, *set2;
1951 int subset;
1953 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
1954 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
1955 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
1956 subset = isl_set_is_subset(set1, set2);
1957 isl_set_free(set1);
1958 isl_set_free(set2);
1959 if (subset < 0)
1960 return -1;
1961 if (subset != subset_tests[i].subset)
1962 isl_die(ctx, isl_error_unknown,
1963 "incorrect subset result", return -1);
1966 return 0;
1969 struct {
1970 const char *minuend;
1971 const char *subtrahend;
1972 const char *difference;
1973 } subtract_domain_tests[] = {
1974 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
1975 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
1976 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
1979 static int test_subtract(isl_ctx *ctx)
1981 int i;
1982 isl_union_map *umap1, *umap2;
1983 isl_union_set *uset;
1984 int equal;
1986 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
1987 umap1 = isl_union_map_read_from_str(ctx,
1988 subtract_domain_tests[i].minuend);
1989 uset = isl_union_set_read_from_str(ctx,
1990 subtract_domain_tests[i].subtrahend);
1991 umap2 = isl_union_map_read_from_str(ctx,
1992 subtract_domain_tests[i].difference);
1993 umap1 = isl_union_map_subtract_domain(umap1, uset);
1994 equal = isl_union_map_is_equal(umap1, umap2);
1995 isl_union_map_free(umap1);
1996 isl_union_map_free(umap2);
1997 if (equal < 0)
1998 return -1;
1999 if (!equal)
2000 isl_die(ctx, isl_error_unknown,
2001 "incorrect subtract domain result", return -1);
2004 return 0;
2007 int test_factorize(isl_ctx *ctx)
2009 const char *str;
2010 isl_basic_set *bset;
2011 isl_factorizer *f;
2013 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2014 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2015 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2016 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2017 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2018 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2019 "3i5 >= -2i0 - i2 + 3i4 }";
2020 bset = isl_basic_set_read_from_str(ctx, str);
2021 f = isl_basic_set_factorizer(bset);
2022 isl_basic_set_free(bset);
2023 isl_factorizer_free(f);
2024 if (!f)
2025 isl_die(ctx, isl_error_unknown,
2026 "failed to construct factorizer", return -1);
2028 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2029 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2030 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2031 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2032 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2033 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2034 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2035 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2036 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2037 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2038 bset = isl_basic_set_read_from_str(ctx, str);
2039 f = isl_basic_set_factorizer(bset);
2040 isl_basic_set_free(bset);
2041 isl_factorizer_free(f);
2042 if (!f)
2043 isl_die(ctx, isl_error_unknown,
2044 "failed to construct factorizer", return -1);
2046 return 0;
2049 static int check_injective(__isl_take isl_map *map, void *user)
2051 int *injective = user;
2053 *injective = isl_map_is_injective(map);
2054 isl_map_free(map);
2056 if (*injective < 0 || !*injective)
2057 return -1;
2059 return 0;
2062 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
2063 const char *r, const char *s, int tilable, int parallel)
2065 int i;
2066 isl_union_set *D;
2067 isl_union_map *W, *R, *S;
2068 isl_union_map *empty;
2069 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
2070 isl_union_map *validity, *proximity;
2071 isl_union_map *schedule;
2072 isl_union_map *test;
2073 isl_union_set *delta;
2074 isl_union_set *domain;
2075 isl_set *delta_set;
2076 isl_set *slice;
2077 isl_set *origin;
2078 isl_schedule *sched;
2079 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
2081 D = isl_union_set_read_from_str(ctx, d);
2082 W = isl_union_map_read_from_str(ctx, w);
2083 R = isl_union_map_read_from_str(ctx, r);
2084 S = isl_union_map_read_from_str(ctx, s);
2086 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
2087 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
2089 empty = isl_union_map_empty(isl_union_map_get_space(S));
2090 isl_union_map_compute_flow(isl_union_map_copy(R),
2091 isl_union_map_copy(W), empty,
2092 isl_union_map_copy(S),
2093 &dep_raw, NULL, NULL, NULL);
2094 isl_union_map_compute_flow(isl_union_map_copy(W),
2095 isl_union_map_copy(W),
2096 isl_union_map_copy(R),
2097 isl_union_map_copy(S),
2098 &dep_waw, &dep_war, NULL, NULL);
2100 dep = isl_union_map_union(dep_waw, dep_war);
2101 dep = isl_union_map_union(dep, dep_raw);
2102 validity = isl_union_map_copy(dep);
2103 proximity = isl_union_map_copy(dep);
2105 sched = isl_union_set_compute_schedule(isl_union_set_copy(D),
2106 validity, proximity);
2107 schedule = isl_schedule_get_map(sched);
2108 isl_schedule_free(sched);
2109 isl_union_map_free(W);
2110 isl_union_map_free(R);
2111 isl_union_map_free(S);
2113 is_injection = 1;
2114 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
2116 domain = isl_union_map_domain(isl_union_map_copy(schedule));
2117 is_complete = isl_union_set_is_subset(D, domain);
2118 isl_union_set_free(D);
2119 isl_union_set_free(domain);
2121 test = isl_union_map_reverse(isl_union_map_copy(schedule));
2122 test = isl_union_map_apply_range(test, dep);
2123 test = isl_union_map_apply_range(test, schedule);
2125 delta = isl_union_map_deltas(test);
2126 if (isl_union_set_n_set(delta) == 0) {
2127 is_tilable = 1;
2128 is_parallel = 1;
2129 is_nonneg = 1;
2130 isl_union_set_free(delta);
2131 } else {
2132 delta_set = isl_set_from_union_set(delta);
2134 slice = isl_set_universe(isl_set_get_space(delta_set));
2135 for (i = 0; i < tilable; ++i)
2136 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
2137 is_tilable = isl_set_is_subset(delta_set, slice);
2138 isl_set_free(slice);
2140 slice = isl_set_universe(isl_set_get_space(delta_set));
2141 for (i = 0; i < parallel; ++i)
2142 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
2143 is_parallel = isl_set_is_subset(delta_set, slice);
2144 isl_set_free(slice);
2146 origin = isl_set_universe(isl_set_get_space(delta_set));
2147 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
2148 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
2150 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
2151 delta_set = isl_set_lexmin(delta_set);
2153 is_nonneg = isl_set_is_equal(delta_set, origin);
2155 isl_set_free(origin);
2156 isl_set_free(delta_set);
2159 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
2160 is_injection < 0 || is_complete < 0)
2161 return -1;
2162 if (!is_complete)
2163 isl_die(ctx, isl_error_unknown,
2164 "generated schedule incomplete", return -1);
2165 if (!is_injection)
2166 isl_die(ctx, isl_error_unknown,
2167 "generated schedule not injective on each statement",
2168 return -1);
2169 if (!is_nonneg)
2170 isl_die(ctx, isl_error_unknown,
2171 "negative dependences in generated schedule",
2172 return -1);
2173 if (!is_tilable)
2174 isl_die(ctx, isl_error_unknown,
2175 "generated schedule not as tilable as expected",
2176 return -1);
2177 if (!is_parallel)
2178 isl_die(ctx, isl_error_unknown,
2179 "generated schedule not as parallel as expected",
2180 return -1);
2182 return 0;
2185 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
2186 const char *domain, const char *validity, const char *proximity)
2188 isl_union_set *dom;
2189 isl_union_map *dep;
2190 isl_union_map *prox;
2191 isl_schedule *schedule;
2192 isl_union_map *sched;
2194 dom = isl_union_set_read_from_str(ctx, domain);
2195 dep = isl_union_map_read_from_str(ctx, validity);
2196 prox = isl_union_map_read_from_str(ctx, proximity);
2197 schedule = isl_union_set_compute_schedule(dom, dep, prox);
2198 sched = isl_schedule_get_map(schedule);
2199 isl_schedule_free(schedule);
2201 return sched;
2204 /* Check that a schedule can be constructed on the given domain
2205 * with the given validity and proximity constraints.
2207 static int test_has_schedule(isl_ctx *ctx, const char *domain,
2208 const char *validity, const char *proximity)
2210 isl_union_map *sched;
2212 sched = compute_schedule(ctx, domain, validity, proximity);
2213 if (!sched)
2214 return -1;
2216 isl_union_map_free(sched);
2217 return 0;
2220 int test_special_schedule(isl_ctx *ctx, const char *domain,
2221 const char *validity, const char *proximity, const char *expected_sched)
2223 isl_union_map *sched1, *sched2;
2224 int equal;
2226 sched1 = compute_schedule(ctx, domain, validity, proximity);
2227 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
2229 equal = isl_union_map_is_equal(sched1, sched2);
2230 isl_union_map_free(sched1);
2231 isl_union_map_free(sched2);
2233 if (equal < 0)
2234 return -1;
2235 if (!equal)
2236 isl_die(ctx, isl_error_unknown, "unexpected schedule",
2237 return -1);
2239 return 0;
2242 int test_schedule(isl_ctx *ctx)
2244 const char *D, *W, *R, *V, *P, *S;
2246 /* Handle resulting schedule with zero bands. */
2247 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2248 return -1;
2250 /* Jacobi */
2251 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2252 W = "{ S1[t,i] -> a[t,i] }";
2253 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2254 "S1[t,i] -> a[t-1,i+1] }";
2255 S = "{ S1[t,i] -> [t,i] }";
2256 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2257 return -1;
2259 /* Fig. 5 of CC2008 */
2260 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2261 "j <= -1 + N }";
2262 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2263 "j >= 2 and j <= -1 + N }";
2264 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2265 "j >= 2 and j <= -1 + N; "
2266 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2267 "j >= 2 and j <= -1 + N }";
2268 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2269 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2270 return -1;
2272 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2273 W = "{ S1[i] -> a[i] }";
2274 R = "{ S2[i] -> a[i+1] }";
2275 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2276 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2277 return -1;
2279 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2280 W = "{ S1[i] -> a[i] }";
2281 R = "{ S2[i] -> a[9-i] }";
2282 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2283 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2284 return -1;
2286 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2287 W = "{ S1[i] -> a[i] }";
2288 R = "[N] -> { S2[i] -> a[N-1-i] }";
2289 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2290 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2291 return -1;
2293 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2294 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2295 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2296 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2297 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2298 return -1;
2300 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2301 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2302 R = "{ S2[i,j] -> a[i-1,j] }";
2303 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2304 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2305 return -1;
2307 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2308 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2309 R = "{ S2[i,j] -> a[i,j-1] }";
2310 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2311 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2312 return -1;
2314 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2315 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2316 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2317 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2318 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2319 "S_0[] -> [0, 0, 0] }";
2320 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
2321 return -1;
2322 ctx->opt->schedule_parametric = 0;
2323 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2324 return -1;
2325 ctx->opt->schedule_parametric = 1;
2327 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2328 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2329 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2330 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2331 "S4[i] -> a[i,N] }";
2332 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2333 "S4[i] -> [4,i,0] }";
2334 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2335 return -1;
2337 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2338 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2339 "j <= N }";
2340 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2341 "j <= N; "
2342 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2343 "j <= N }";
2344 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2345 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2346 return -1;
2348 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2349 " S_2[t] : t >= 0 and t <= -1 + N; "
2350 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2351 "i <= -1 + N }";
2352 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2353 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2354 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2355 "i >= 0 and i <= -1 + N }";
2356 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2357 "i >= 0 and i <= -1 + N; "
2358 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2359 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2360 " S_0[t] -> [0, t, 0] }";
2362 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2363 return -1;
2364 ctx->opt->schedule_parametric = 0;
2365 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2366 return -1;
2367 ctx->opt->schedule_parametric = 1;
2369 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2370 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2371 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
2372 return -1;
2374 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2375 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2376 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2377 "j >= 0 and j <= -1 + N; "
2378 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2379 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2380 "j >= 0 and j <= -1 + N; "
2381 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2382 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2383 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2384 return -1;
2386 D = "{ S_0[i] : i >= 0 }";
2387 W = "{ S_0[i] -> a[i] : i >= 0 }";
2388 R = "{ S_0[i] -> a[0] : i >= 0 }";
2389 S = "{ S_0[i] -> [0, i, 0] }";
2390 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2391 return -1;
2393 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2394 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2395 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2396 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2397 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2398 return -1;
2400 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2401 "k <= -1 + n and k >= 0 }";
2402 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2403 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2404 "k <= -1 + n and k >= 0; "
2405 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2406 "k <= -1 + n and k >= 0; "
2407 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2408 "k <= -1 + n and k >= 0 }";
2409 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
2410 ctx->opt->schedule_outer_zero_distance = 1;
2411 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2412 return -1;
2413 ctx->opt->schedule_outer_zero_distance = 0;
2415 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
2416 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2417 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2418 "Stmt_for_body24[i0, i1, 1, 0]:"
2419 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2420 "Stmt_for_body7[i0, i1, i2]:"
2421 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2422 "i2 <= 7 }";
2424 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
2425 "Stmt_for_body24[1, i1, i2, i3]:"
2426 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2427 "i2 >= 1;"
2428 "Stmt_for_body24[0, i1, i2, i3] -> "
2429 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2430 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2431 "i3 >= 0;"
2432 "Stmt_for_body24[0, i1, i2, i3] ->"
2433 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2434 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2435 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2436 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2437 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2438 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2439 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2440 "i1 <= 6 and i1 >= 0;"
2441 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2442 "Stmt_for_body7[i0, i1, i2] -> "
2443 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2444 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2445 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2446 "Stmt_for_body7[i0, i1, i2] -> "
2447 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2448 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2449 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2450 P = V;
2451 S = "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2452 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2453 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2455 if (test_special_schedule(ctx, D, V, P, S) < 0)
2456 return -1;
2458 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2459 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2460 "j >= 1 and j <= 7;"
2461 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2462 "j >= 1 and j <= 8 }";
2463 P = "{ }";
2464 S = "{ S_0[i, j] -> [i + j, j] }";
2465 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2466 if (test_special_schedule(ctx, D, V, P, S) < 0)
2467 return -1;
2468 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2470 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2471 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2472 "j >= 0 and j <= -1 + i }";
2473 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2474 "i <= -1 + N and j >= 0;"
2475 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2476 "i <= -2 + N }";
2477 P = "{ }";
2478 S = "{ S_0[i, j] -> [i, j] }";
2479 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2480 if (test_special_schedule(ctx, D, V, P, S) < 0)
2481 return -1;
2482 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2484 /* Test both algorithms on a case with only proximity dependences. */
2485 D = "{ S[i,j] : 0 <= i <= 10 }";
2486 V = "{ }";
2487 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2488 S = "{ S[i, j] -> [j, i] }";
2489 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2490 if (test_special_schedule(ctx, D, V, P, S) < 0)
2491 return -1;
2492 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2493 if (test_special_schedule(ctx, D, V, P, S) < 0)
2494 return -1;
2496 D = "{ A[a]; B[] }";
2497 V = "{}";
2498 P = "{ A[a] -> B[] }";
2499 if (test_has_schedule(ctx, D, V, P) < 0)
2500 return -1;
2502 return 0;
2505 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
2507 isl_union_map *umap;
2508 int test;
2510 umap = isl_union_map_read_from_str(ctx, str);
2511 test = isl_union_map_plain_is_injective(umap);
2512 isl_union_map_free(umap);
2513 if (test < 0)
2514 return -1;
2515 if (test == injective)
2516 return 0;
2517 if (injective)
2518 isl_die(ctx, isl_error_unknown,
2519 "map not detected as injective", return -1);
2520 else
2521 isl_die(ctx, isl_error_unknown,
2522 "map detected as injective", return -1);
2525 int test_injective(isl_ctx *ctx)
2527 const char *str;
2529 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2530 return -1;
2531 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
2532 return -1;
2533 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
2534 return -1;
2535 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
2536 return -1;
2537 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2538 return -1;
2539 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2540 return -1;
2541 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2542 return -1;
2543 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2544 return -1;
2546 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2547 if (test_plain_injective(ctx, str, 1))
2548 return -1;
2549 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2550 if (test_plain_injective(ctx, str, 0))
2551 return -1;
2553 return 0;
2556 static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
2558 isl_aff *aff2;
2559 int equal;
2561 if (!aff)
2562 return -1;
2564 aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
2565 equal = isl_aff_plain_is_equal(aff, aff2);
2566 isl_aff_free(aff2);
2568 return equal;
2571 static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
2573 int equal;
2575 equal = aff_plain_is_equal(aff, str);
2576 if (equal < 0)
2577 return -1;
2578 if (!equal)
2579 isl_die(isl_aff_get_ctx(aff), isl_error_unknown,
2580 "result not as expected", return -1);
2581 return 0;
2584 int test_aff(isl_ctx *ctx)
2586 const char *str;
2587 isl_set *set;
2588 isl_space *space;
2589 isl_local_space *ls;
2590 isl_aff *aff;
2591 int zero, equal;
2593 space = isl_space_set_alloc(ctx, 0, 1);
2594 ls = isl_local_space_from_space(space);
2595 aff = isl_aff_zero_on_domain(ls);
2597 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2598 aff = isl_aff_scale_down_ui(aff, 3);
2599 aff = isl_aff_floor(aff);
2600 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2601 aff = isl_aff_scale_down_ui(aff, 2);
2602 aff = isl_aff_floor(aff);
2603 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2605 str = "{ [10] }";
2606 set = isl_set_read_from_str(ctx, str);
2607 aff = isl_aff_gist(aff, set);
2609 aff = isl_aff_add_constant_si(aff, -16);
2610 zero = isl_aff_plain_is_zero(aff);
2611 isl_aff_free(aff);
2613 if (zero < 0)
2614 return -1;
2615 if (!zero)
2616 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2618 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
2619 aff = isl_aff_scale_down_ui(aff, 64);
2620 aff = isl_aff_floor(aff);
2621 equal = aff_check_plain_equal(aff, "{ [-1] }");
2622 isl_aff_free(aff);
2623 if (equal < 0)
2624 return -1;
2626 return 0;
2629 int test_dim_max(isl_ctx *ctx)
2631 int equal;
2632 const char *str;
2633 isl_set *set1, *set2;
2634 isl_set *set;
2635 isl_map *map;
2636 isl_pw_aff *pwaff;
2638 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
2639 set = isl_set_read_from_str(ctx, str);
2640 pwaff = isl_set_dim_max(set, 0);
2641 set1 = isl_set_from_pw_aff(pwaff);
2642 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2643 set2 = isl_set_read_from_str(ctx, str);
2644 equal = isl_set_is_equal(set1, set2);
2645 isl_set_free(set1);
2646 isl_set_free(set2);
2647 if (equal < 0)
2648 return -1;
2649 if (!equal)
2650 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2652 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2653 set = isl_set_read_from_str(ctx, str);
2654 pwaff = isl_set_dim_max(set, 0);
2655 set1 = isl_set_from_pw_aff(pwaff);
2656 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2657 set2 = isl_set_read_from_str(ctx, str);
2658 equal = isl_set_is_equal(set1, set2);
2659 isl_set_free(set1);
2660 isl_set_free(set2);
2661 if (equal < 0)
2662 return -1;
2663 if (!equal)
2664 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2666 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2667 set = isl_set_read_from_str(ctx, str);
2668 pwaff = isl_set_dim_max(set, 0);
2669 set1 = isl_set_from_pw_aff(pwaff);
2670 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2671 set2 = isl_set_read_from_str(ctx, str);
2672 equal = isl_set_is_equal(set1, set2);
2673 isl_set_free(set1);
2674 isl_set_free(set2);
2675 if (equal < 0)
2676 return -1;
2677 if (!equal)
2678 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2680 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2681 "0 <= i < N and 0 <= j < M }";
2682 map = isl_map_read_from_str(ctx, str);
2683 set = isl_map_range(map);
2685 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
2686 set1 = isl_set_from_pw_aff(pwaff);
2687 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
2688 set2 = isl_set_read_from_str(ctx, str);
2689 equal = isl_set_is_equal(set1, set2);
2690 isl_set_free(set1);
2691 isl_set_free(set2);
2693 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
2694 set1 = isl_set_from_pw_aff(pwaff);
2695 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
2696 set2 = isl_set_read_from_str(ctx, str);
2697 if (equal >= 0 && equal)
2698 equal = isl_set_is_equal(set1, set2);
2699 isl_set_free(set1);
2700 isl_set_free(set2);
2702 isl_set_free(set);
2704 if (equal < 0)
2705 return -1;
2706 if (!equal)
2707 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2709 /* Check that solutions are properly merged. */
2710 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
2711 "c <= -1 + n - 4a - 2b and c >= -2b and "
2712 "4a >= -4 + n and c >= 0 }";
2713 set = isl_set_read_from_str(ctx, str);
2714 pwaff = isl_set_dim_min(set, 2);
2715 set1 = isl_set_from_pw_aff(pwaff);
2716 str = "[n] -> { [(0)] : n >= 1 }";
2717 set2 = isl_set_read_from_str(ctx, str);
2718 equal = isl_set_is_equal(set1, set2);
2719 isl_set_free(set1);
2720 isl_set_free(set2);
2722 if (equal < 0)
2723 return -1;
2724 if (!equal)
2725 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2727 return 0;
2730 int test_product(isl_ctx *ctx)
2732 const char *str;
2733 isl_set *set;
2734 isl_union_set *uset1, *uset2;
2735 int ok;
2737 str = "{ A[i] }";
2738 set = isl_set_read_from_str(ctx, str);
2739 set = isl_set_product(set, isl_set_copy(set));
2740 ok = isl_set_is_wrapping(set);
2741 isl_set_free(set);
2742 if (ok < 0)
2743 return -1;
2744 if (!ok)
2745 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2747 str = "{ [] }";
2748 uset1 = isl_union_set_read_from_str(ctx, str);
2749 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
2750 str = "{ [[] -> []] }";
2751 uset2 = isl_union_set_read_from_str(ctx, str);
2752 ok = isl_union_set_is_equal(uset1, uset2);
2753 isl_union_set_free(uset1);
2754 isl_union_set_free(uset2);
2755 if (ok < 0)
2756 return -1;
2757 if (!ok)
2758 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2760 return 0;
2763 int test_equal(isl_ctx *ctx)
2765 const char *str;
2766 isl_set *set, *set2;
2767 int equal;
2769 str = "{ S_6[i] }";
2770 set = isl_set_read_from_str(ctx, str);
2771 str = "{ S_7[i] }";
2772 set2 = isl_set_read_from_str(ctx, str);
2773 equal = isl_set_is_equal(set, set2);
2774 isl_set_free(set);
2775 isl_set_free(set2);
2776 if (equal < 0)
2777 return -1;
2778 if (equal)
2779 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2781 return 0;
2784 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
2785 enum isl_dim_type type, unsigned pos, int fixed)
2787 int test;
2789 test = isl_map_plain_is_fixed(map, type, pos, NULL);
2790 isl_map_free(map);
2791 if (test < 0)
2792 return -1;
2793 if (test == fixed)
2794 return 0;
2795 if (fixed)
2796 isl_die(ctx, isl_error_unknown,
2797 "map not detected as fixed", return -1);
2798 else
2799 isl_die(ctx, isl_error_unknown,
2800 "map detected as fixed", return -1);
2803 int test_fixed(isl_ctx *ctx)
2805 const char *str;
2806 isl_map *map;
2808 str = "{ [i] -> [i] }";
2809 map = isl_map_read_from_str(ctx, str);
2810 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
2811 return -1;
2812 str = "{ [i] -> [1] }";
2813 map = isl_map_read_from_str(ctx, str);
2814 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2815 return -1;
2816 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
2817 map = isl_map_read_from_str(ctx, str);
2818 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2819 return -1;
2820 map = isl_map_read_from_str(ctx, str);
2821 map = isl_map_neg(map);
2822 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2823 return -1;
2825 return 0;
2828 int test_vertices(isl_ctx *ctx)
2830 const char *str;
2831 isl_basic_set *bset;
2832 isl_vertices *vertices;
2834 str = "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
2835 bset = isl_basic_set_read_from_str(ctx, str);
2836 vertices = isl_basic_set_compute_vertices(bset);
2837 isl_basic_set_free(bset);
2838 isl_vertices_free(vertices);
2839 if (!vertices)
2840 return -1;
2842 str = "{ A[t, i] : t = 14 and i = 1 }";
2843 bset = isl_basic_set_read_from_str(ctx, str);
2844 vertices = isl_basic_set_compute_vertices(bset);
2845 isl_basic_set_free(bset);
2846 isl_vertices_free(vertices);
2847 if (!vertices)
2848 return -1;
2850 return 0;
2853 int test_union_pw(isl_ctx *ctx)
2855 int equal;
2856 const char *str;
2857 isl_union_set *uset;
2858 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
2860 str = "{ [x] -> x^2 }";
2861 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
2862 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
2863 uset = isl_union_pw_qpolynomial_domain(upwqp1);
2864 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
2865 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
2866 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
2867 isl_union_pw_qpolynomial_free(upwqp1);
2868 isl_union_pw_qpolynomial_free(upwqp2);
2869 if (equal < 0)
2870 return -1;
2871 if (!equal)
2872 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2874 return 0;
2877 int test_output(isl_ctx *ctx)
2879 char *s;
2880 const char *str;
2881 isl_pw_aff *pa;
2882 isl_printer *p;
2883 int equal;
2885 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
2886 pa = isl_pw_aff_read_from_str(ctx, str);
2888 p = isl_printer_to_str(ctx);
2889 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
2890 p = isl_printer_print_pw_aff(p, pa);
2891 s = isl_printer_get_str(p);
2892 isl_printer_free(p);
2893 isl_pw_aff_free(pa);
2894 if (!s)
2895 equal = -1;
2896 else
2897 equal = !strcmp(s, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
2898 free(s);
2899 if (equal < 0)
2900 return -1;
2901 if (!equal)
2902 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2904 return 0;
2907 int test_sample(isl_ctx *ctx)
2909 const char *str;
2910 isl_basic_set *bset1, *bset2;
2911 int empty, subset;
2913 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
2914 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
2915 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
2916 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
2917 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
2918 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
2919 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
2920 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
2921 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
2922 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
2923 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
2924 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
2925 "d - 1073741821e and "
2926 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
2927 "3j >= 1 - a + b + 2e and "
2928 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
2929 "3i <= 4 - a + 4b - e and "
2930 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
2931 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
2932 "c <= -1 + a and 3i >= -2 - a + 3e and "
2933 "1073741822e <= 1073741823 - a + 1073741822b + c and "
2934 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
2935 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
2936 "1073741823e >= 1 + 1073741823b - d and "
2937 "3i >= 1073741823b + c - 1073741823e - f and "
2938 "3i >= 1 + 2b + e + 3g }";
2939 bset1 = isl_basic_set_read_from_str(ctx, str);
2940 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
2941 empty = isl_basic_set_is_empty(bset2);
2942 subset = isl_basic_set_is_subset(bset2, bset1);
2943 isl_basic_set_free(bset1);
2944 isl_basic_set_free(bset2);
2945 if (empty < 0 || subset < 0)
2946 return -1;
2947 if (empty)
2948 isl_die(ctx, isl_error_unknown, "point not found", return -1);
2949 if (!subset)
2950 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
2952 return 0;
2955 int test_fixed_power(isl_ctx *ctx)
2957 const char *str;
2958 isl_map *map;
2959 isl_int exp;
2960 int equal;
2962 isl_int_init(exp);
2963 str = "{ [i] -> [i + 1] }";
2964 map = isl_map_read_from_str(ctx, str);
2965 isl_int_set_si(exp, 23);
2966 map = isl_map_fixed_power(map, exp);
2967 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
2968 isl_int_clear(exp);
2969 isl_map_free(map);
2970 if (equal < 0)
2971 return -1;
2973 return 0;
2976 int test_slice(isl_ctx *ctx)
2978 const char *str;
2979 isl_map *map;
2980 int equal;
2982 str = "{ [i] -> [j] }";
2983 map = isl_map_read_from_str(ctx, str);
2984 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
2985 equal = map_check_equal(map, "{ [i] -> [i] }");
2986 isl_map_free(map);
2987 if (equal < 0)
2988 return -1;
2990 str = "{ [i] -> [j] }";
2991 map = isl_map_read_from_str(ctx, str);
2992 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
2993 equal = map_check_equal(map, "{ [i] -> [j] }");
2994 isl_map_free(map);
2995 if (equal < 0)
2996 return -1;
2998 str = "{ [i] -> [j] }";
2999 map = isl_map_read_from_str(ctx, str);
3000 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
3001 equal = map_check_equal(map, "{ [i] -> [-i] }");
3002 isl_map_free(map);
3003 if (equal < 0)
3004 return -1;
3006 str = "{ [i] -> [j] }";
3007 map = isl_map_read_from_str(ctx, str);
3008 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
3009 equal = map_check_equal(map, "{ [0] -> [j] }");
3010 isl_map_free(map);
3011 if (equal < 0)
3012 return -1;
3014 str = "{ [i] -> [j] }";
3015 map = isl_map_read_from_str(ctx, str);
3016 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
3017 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
3018 isl_map_free(map);
3019 if (equal < 0)
3020 return -1;
3022 str = "{ [i] -> [j] }";
3023 map = isl_map_read_from_str(ctx, str);
3024 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
3025 equal = map_check_equal(map, "{ [i] -> [j] : false }");
3026 isl_map_free(map);
3027 if (equal < 0)
3028 return -1;
3030 return 0;
3033 int test_eliminate(isl_ctx *ctx)
3035 const char *str;
3036 isl_map *map;
3037 int equal;
3039 str = "{ [i] -> [j] : i = 2j }";
3040 map = isl_map_read_from_str(ctx, str);
3041 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
3042 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
3043 isl_map_free(map);
3044 if (equal < 0)
3045 return -1;
3047 return 0;
3050 /* Check that isl_set_dim_residue_class detects that the values of j
3051 * in the set below are all odd and that it does not detect any spurious
3052 * strides.
3054 static int test_residue_class(isl_ctx *ctx)
3056 const char *str;
3057 isl_set *set;
3058 isl_int m, r;
3059 int res;
3061 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3062 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3063 set = isl_set_read_from_str(ctx, str);
3064 isl_int_init(m);
3065 isl_int_init(r);
3066 res = isl_set_dim_residue_class(set, 1, &m, &r);
3067 if (res >= 0 &&
3068 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
3069 isl_die(ctx, isl_error_unknown, "incorrect residue class",
3070 res = -1);
3071 isl_int_clear(r);
3072 isl_int_clear(m);
3073 isl_set_free(set);
3075 return res;
3078 int test_align_parameters(isl_ctx *ctx)
3080 const char *str;
3081 isl_space *space;
3082 isl_multi_aff *ma1, *ma2;
3083 int equal;
3085 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3086 ma1 = isl_multi_aff_read_from_str(ctx, str);
3088 space = isl_space_params_alloc(ctx, 1);
3089 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
3090 ma1 = isl_multi_aff_align_params(ma1, space);
3092 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3093 ma2 = isl_multi_aff_read_from_str(ctx, str);
3095 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
3097 isl_multi_aff_free(ma1);
3098 isl_multi_aff_free(ma2);
3100 if (equal < 0)
3101 return -1;
3102 if (!equal)
3103 isl_die(ctx, isl_error_unknown,
3104 "result not as expected", return -1);
3106 return 0;
3109 static int test_list(isl_ctx *ctx)
3111 isl_id *a, *b, *c, *d, *id;
3112 isl_id_list *list;
3113 int ok;
3115 a = isl_id_alloc(ctx, "a", NULL);
3116 b = isl_id_alloc(ctx, "b", NULL);
3117 c = isl_id_alloc(ctx, "c", NULL);
3118 d = isl_id_alloc(ctx, "d", NULL);
3120 list = isl_id_list_alloc(ctx, 4);
3121 list = isl_id_list_add(list, a);
3122 list = isl_id_list_add(list, b);
3123 list = isl_id_list_add(list, c);
3124 list = isl_id_list_add(list, d);
3125 list = isl_id_list_drop(list, 1, 1);
3127 if (isl_id_list_n_id(list) != 3) {
3128 isl_id_list_free(list);
3129 isl_die(ctx, isl_error_unknown,
3130 "unexpected number of elements in list", return -1);
3133 id = isl_id_list_get_id(list, 0);
3134 ok = id == a;
3135 isl_id_free(id);
3136 id = isl_id_list_get_id(list, 1);
3137 ok = ok && id == c;
3138 isl_id_free(id);
3139 id = isl_id_list_get_id(list, 2);
3140 ok = ok && id == d;
3141 isl_id_free(id);
3143 isl_id_list_free(list);
3145 if (!ok)
3146 isl_die(ctx, isl_error_unknown,
3147 "unexpected elements in list", return -1);
3149 return 0;
3152 const char *set_conversion_tests[] = {
3153 "[N] -> { [i] : N - 1 <= 2 i <= N }",
3154 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
3155 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3156 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3159 /* Check that converting from isl_set to isl_pw_multi_aff and back
3160 * to isl_set produces the original isl_set.
3162 static int test_set_conversion(isl_ctx *ctx)
3164 int i;
3165 const char *str;
3166 isl_set *set1, *set2;
3167 isl_pw_multi_aff *pma;
3168 int equal;
3170 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
3171 str = set_conversion_tests[i];
3172 set1 = isl_set_read_from_str(ctx, str);
3173 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
3174 set2 = isl_set_from_pw_multi_aff(pma);
3175 equal = isl_set_is_equal(set1, set2);
3176 isl_set_free(set1);
3177 isl_set_free(set2);
3179 if (equal < 0)
3180 return -1;
3181 if (!equal)
3182 isl_die(ctx, isl_error_unknown, "bad conversion",
3183 return -1);
3186 return 0;
3189 /* Check that converting from isl_map to isl_pw_multi_aff and back
3190 * to isl_map produces the original isl_map.
3192 static int test_map_conversion(isl_ctx *ctx)
3194 const char *str;
3195 isl_map *map1, *map2;
3196 isl_pw_multi_aff *pma;
3197 int equal;
3199 str = "{ [a, b, c, d] -> s0[a, b, e, f] : "
3200 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
3201 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
3202 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
3203 "9e <= -2 - 2a) }";
3204 map1 = isl_map_read_from_str(ctx, str);
3205 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
3206 map2 = isl_map_from_pw_multi_aff(pma);
3207 equal = isl_map_is_equal(map1, map2);
3208 isl_map_free(map1);
3209 isl_map_free(map2);
3211 if (equal < 0)
3212 return -1;
3213 if (!equal)
3214 isl_die(ctx, isl_error_unknown, "bad conversion", return -1);
3216 return 0;
3219 static int test_conversion(isl_ctx *ctx)
3221 if (test_set_conversion(ctx) < 0)
3222 return -1;
3223 if (test_map_conversion(ctx) < 0)
3224 return -1;
3225 return 0;
3228 /* Check that isl_basic_map_curry does not modify input.
3230 static int test_curry(isl_ctx *ctx)
3232 const char *str;
3233 isl_basic_map *bmap1, *bmap2;
3234 int equal;
3236 str = "{ [A[] -> B[]] -> C[] }";
3237 bmap1 = isl_basic_map_read_from_str(ctx, str);
3238 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
3239 equal = isl_basic_map_is_equal(bmap1, bmap2);
3240 isl_basic_map_free(bmap1);
3241 isl_basic_map_free(bmap2);
3243 if (equal < 0)
3244 return -1;
3245 if (equal)
3246 isl_die(ctx, isl_error_unknown,
3247 "curried map should not be equal to original",
3248 return -1);
3250 return 0;
3253 struct {
3254 const char *set;
3255 const char *ma;
3256 const char *res;
3257 } preimage_tests[] = {
3258 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
3259 "{ A[j,i] -> B[i,j] }",
3260 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
3261 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
3262 "{ A[a,b] -> B[a/2,b/6] }",
3263 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
3264 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
3265 "{ A[a,b] -> B[a/2,b/6] }",
3266 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
3267 "exists i,j : a = 2 i and b = 6 j }" },
3268 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
3269 "[n] -> { : 0 <= n <= 100 }" },
3270 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
3271 "{ A[a] -> B[2a] }",
3272 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
3273 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
3274 "{ A[a] -> B[([a/2])] }",
3275 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
3276 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
3277 "{ A[a] -> B[a,a,a/3] }",
3278 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
3279 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
3280 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
3283 int test_preimage(isl_ctx *ctx)
3285 int i;
3286 isl_basic_set *bset1, *bset2;
3287 isl_multi_aff *ma;
3288 int equal;
3290 for (i = 0; i < ARRAY_SIZE(preimage_tests); ++i) {
3291 bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set);
3292 ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma);
3293 bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res);
3294 bset1 = isl_basic_set_preimage_multi_aff(bset1, ma);
3295 equal = isl_basic_set_is_equal(bset1, bset2);
3296 isl_basic_set_free(bset1);
3297 isl_basic_set_free(bset2);
3298 if (equal < 0)
3299 return -1;
3300 if (!equal)
3301 isl_die(ctx, isl_error_unknown, "bad preimage",
3302 return -1);
3305 return 0;
3308 struct {
3309 const char *ma1;
3310 const char *ma;
3311 const char *res;
3312 } pullback_tests[] = {
3313 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
3314 "{ A[a,b] -> C[b + 2a] }" },
3315 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
3316 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
3317 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
3318 "{ A[a] -> C[(a)/6] }" },
3319 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
3320 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
3321 "{ A[a] -> C[(2a)/3] }" },
3322 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
3323 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
3324 "{ A[i,j] -> C[i + j, i + j] }"},
3325 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
3326 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
3327 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
3330 static int test_pullback(isl_ctx *ctx)
3332 int i;
3333 isl_multi_aff *ma1, *ma2;
3334 isl_multi_aff *ma;
3335 int equal;
3337 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
3338 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
3339 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
3340 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
3341 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
3342 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
3343 isl_multi_aff_free(ma1);
3344 isl_multi_aff_free(ma2);
3345 if (equal < 0)
3346 return -1;
3347 if (!equal)
3348 isl_die(ctx, isl_error_unknown, "bad pullback",
3349 return -1);
3352 return 0;
3355 /* Check that negation is printed correctly.
3357 static int test_ast(isl_ctx *ctx)
3359 isl_ast_expr *expr, *expr1, *expr2, *expr3;
3360 char *str;
3361 int ok;
3363 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
3364 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
3365 expr = isl_ast_expr_add(expr1, expr2);
3366 expr = isl_ast_expr_neg(expr);
3367 str = isl_ast_expr_to_str(expr);
3368 ok = str ? !strcmp(str, "-(A + B)") : -1;
3369 free(str);
3370 isl_ast_expr_free(expr);
3372 if (ok < 0)
3373 return -1;
3374 if (!ok)
3375 isl_die(ctx, isl_error_unknown,
3376 "isl_ast_expr printed incorrectly", return -1);
3378 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
3379 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
3380 expr = isl_ast_expr_add(expr1, expr2);
3381 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
3382 expr = isl_ast_expr_sub(expr3, expr);
3383 str = isl_ast_expr_to_str(expr);
3384 ok = str ? !strcmp(str, "C - (A + B)") : -1;
3385 free(str);
3386 isl_ast_expr_free(expr);
3388 if (ok < 0)
3389 return -1;
3390 if (!ok)
3391 isl_die(ctx, isl_error_unknown,
3392 "isl_ast_expr printed incorrectly", return -1);
3394 return 0;
3397 /* Internal data structure for before_for and after_for callbacks.
3399 * depth is the current depth
3400 * before is the number of times before_for has been called
3401 * after is the number of times after_for has been called
3403 struct isl_test_codegen_data {
3404 int depth;
3405 int before;
3406 int after;
3409 /* This function is called before each for loop in the AST generated
3410 * from test_ast_gen1.
3412 * Increment the number of calls and the depth.
3413 * Check that the space returned by isl_ast_build_get_schedule_space
3414 * matches the target space of the schedule returned by
3415 * isl_ast_build_get_schedule.
3416 * Return an isl_id that is checked by the corresponding call
3417 * to after_for.
3419 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
3420 void *user)
3422 struct isl_test_codegen_data *data = user;
3423 isl_ctx *ctx;
3424 isl_space *space;
3425 isl_union_map *schedule;
3426 isl_union_set *uset;
3427 isl_set *set;
3428 int empty;
3429 char name[] = "d0";
3431 ctx = isl_ast_build_get_ctx(build);
3433 if (data->before >= 3)
3434 isl_die(ctx, isl_error_unknown,
3435 "unexpected number of for nodes", return NULL);
3436 if (data->depth >= 2)
3437 isl_die(ctx, isl_error_unknown,
3438 "unexpected depth", return NULL);
3440 snprintf(name, sizeof(name), "d%d", data->depth);
3441 data->before++;
3442 data->depth++;
3444 schedule = isl_ast_build_get_schedule(build);
3445 uset = isl_union_map_range(schedule);
3446 if (!uset)
3447 return NULL;
3448 if (isl_union_set_n_set(uset) != 1) {
3449 isl_union_set_free(uset);
3450 isl_die(ctx, isl_error_unknown,
3451 "expecting single range space", return NULL);
3454 space = isl_ast_build_get_schedule_space(build);
3455 set = isl_union_set_extract_set(uset, space);
3456 isl_union_set_free(uset);
3457 empty = isl_set_is_empty(set);
3458 isl_set_free(set);
3460 if (empty < 0)
3461 return NULL;
3462 if (empty)
3463 isl_die(ctx, isl_error_unknown,
3464 "spaces don't match", return NULL);
3466 return isl_id_alloc(ctx, name, NULL);
3469 /* This function is called after each for loop in the AST generated
3470 * from test_ast_gen1.
3472 * Increment the number of calls and decrement the depth.
3473 * Check that the annotation attached to the node matches
3474 * the isl_id returned by the corresponding call to before_for.
3476 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
3477 __isl_keep isl_ast_build *build, void *user)
3479 struct isl_test_codegen_data *data = user;
3480 isl_id *id;
3481 const char *name;
3482 int valid;
3484 data->after++;
3485 data->depth--;
3487 if (data->after > data->before)
3488 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
3489 "mismatch in number of for nodes",
3490 return isl_ast_node_free(node));
3492 id = isl_ast_node_get_annotation(node);
3493 if (!id)
3494 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
3495 "missing annotation", return isl_ast_node_free(node));
3497 name = isl_id_get_name(id);
3498 valid = name && atoi(name + 1) == data->depth;
3499 isl_id_free(id);
3501 if (!valid)
3502 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
3503 "wrong annotation", return isl_ast_node_free(node));
3505 return node;
3508 /* Check that the before_each_for and after_each_for callbacks
3509 * are called for each for loop in the generated code,
3510 * that they are called in the right order and that the isl_id
3511 * returned from the before_each_for callback is attached to
3512 * the isl_ast_node passed to the corresponding after_each_for call.
3514 static int test_ast_gen1(isl_ctx *ctx)
3516 const char *str;
3517 isl_set *set;
3518 isl_union_map *schedule;
3519 isl_ast_build *build;
3520 isl_ast_node *tree;
3521 struct isl_test_codegen_data data;
3523 str = "[N] -> { : N >= 10 }";
3524 set = isl_set_read_from_str(ctx, str);
3525 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
3526 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
3527 schedule = isl_union_map_read_from_str(ctx, str);
3529 data.before = 0;
3530 data.after = 0;
3531 data.depth = 0;
3532 build = isl_ast_build_from_context(set);
3533 build = isl_ast_build_set_before_each_for(build,
3534 &before_for, &data);
3535 build = isl_ast_build_set_after_each_for(build,
3536 &after_for, &data);
3537 tree = isl_ast_build_ast_from_schedule(build, schedule);
3538 isl_ast_build_free(build);
3539 if (!tree)
3540 return -1;
3542 isl_ast_node_free(tree);
3544 if (data.before != 3 || data.after != 3)
3545 isl_die(ctx, isl_error_unknown,
3546 "unexpected number of for nodes", return -1);
3548 return 0;
3551 /* Check that the AST generator handles domains that are integrally disjoint
3552 * but not ratinoally disjoint.
3554 static int test_ast_gen2(isl_ctx *ctx)
3556 const char *str;
3557 isl_set *set;
3558 isl_union_map *schedule;
3559 isl_union_map *options;
3560 isl_ast_build *build;
3561 isl_ast_node *tree;
3563 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
3564 schedule = isl_union_map_read_from_str(ctx, str);
3565 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
3566 build = isl_ast_build_from_context(set);
3568 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
3569 options = isl_union_map_read_from_str(ctx, str);
3570 build = isl_ast_build_set_options(build, options);
3571 tree = isl_ast_build_ast_from_schedule(build, schedule);
3572 isl_ast_build_free(build);
3573 if (!tree)
3574 return -1;
3575 isl_ast_node_free(tree);
3577 return 0;
3580 /* Increment *user on each call.
3582 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
3583 __isl_keep isl_ast_build *build, void *user)
3585 int *n = user;
3587 (*n)++;
3589 return node;
3592 /* Test that unrolling tries to minimize the number of instances.
3593 * In particular, for the schedule given below, make sure it generates
3594 * 3 nodes (rather than 101).
3596 static int test_ast_gen3(isl_ctx *ctx)
3598 const char *str;
3599 isl_set *set;
3600 isl_union_map *schedule;
3601 isl_union_map *options;
3602 isl_ast_build *build;
3603 isl_ast_node *tree;
3604 int n_domain = 0;
3606 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
3607 schedule = isl_union_map_read_from_str(ctx, str);
3608 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
3610 str = "{ [i] -> unroll[0] }";
3611 options = isl_union_map_read_from_str(ctx, str);
3613 build = isl_ast_build_from_context(set);
3614 build = isl_ast_build_set_options(build, options);
3615 build = isl_ast_build_set_at_each_domain(build,
3616 &count_domains, &n_domain);
3617 tree = isl_ast_build_ast_from_schedule(build, schedule);
3618 isl_ast_build_free(build);
3619 if (!tree)
3620 return -1;
3622 isl_ast_node_free(tree);
3624 if (n_domain != 3)
3625 isl_die(ctx, isl_error_unknown,
3626 "unexpected number of for nodes", return -1);
3628 return 0;
3631 /* Check that if the ast_build_exploit_nested_bounds options is set,
3632 * we do not get an outer if node in the generated AST,
3633 * while we do get such an outer if node if the options is not set.
3635 static int test_ast_gen4(isl_ctx *ctx)
3637 const char *str;
3638 isl_set *set;
3639 isl_union_map *schedule;
3640 isl_ast_build *build;
3641 isl_ast_node *tree;
3642 enum isl_ast_node_type type;
3643 int enb;
3645 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
3646 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
3648 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
3650 schedule = isl_union_map_read_from_str(ctx, str);
3651 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
3652 build = isl_ast_build_from_context(set);
3653 tree = isl_ast_build_ast_from_schedule(build, schedule);
3654 isl_ast_build_free(build);
3655 if (!tree)
3656 return -1;
3658 type = isl_ast_node_get_type(tree);
3659 isl_ast_node_free(tree);
3661 if (type == isl_ast_node_if)
3662 isl_die(ctx, isl_error_unknown,
3663 "not expecting if node", return -1);
3665 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
3667 schedule = isl_union_map_read_from_str(ctx, str);
3668 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
3669 build = isl_ast_build_from_context(set);
3670 tree = isl_ast_build_ast_from_schedule(build, schedule);
3671 isl_ast_build_free(build);
3672 if (!tree)
3673 return -1;
3675 type = isl_ast_node_get_type(tree);
3676 isl_ast_node_free(tree);
3678 if (type != isl_ast_node_if)
3679 isl_die(ctx, isl_error_unknown,
3680 "expecting if node", return -1);
3682 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
3684 return 0;
3687 static int test_ast_gen(isl_ctx *ctx)
3689 if (test_ast_gen1(ctx) < 0)
3690 return -1;
3691 if (test_ast_gen2(ctx) < 0)
3692 return -1;
3693 if (test_ast_gen3(ctx) < 0)
3694 return -1;
3695 if (test_ast_gen4(ctx) < 0)
3696 return -1;
3697 return 0;
3700 /* Check if dropping output dimensions from an isl_pw_multi_aff
3701 * works properly.
3703 static int test_pw_multi_aff(isl_ctx *ctx)
3705 const char *str;
3706 isl_pw_multi_aff *pma1, *pma2;
3707 int equal;
3709 str = "{ [i,j] -> [i+j, 4i-j] }";
3710 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
3711 str = "{ [i,j] -> [4i-j] }";
3712 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
3714 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
3716 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
3718 isl_pw_multi_aff_free(pma1);
3719 isl_pw_multi_aff_free(pma2);
3720 if (equal < 0)
3721 return -1;
3722 if (!equal)
3723 isl_die(ctx, isl_error_unknown,
3724 "expressions not equal", return -1);
3726 return 0;
3729 /* This is a regression test for a bug where isl_basic_map_simplify
3730 * would end up in an infinite loop. In particular, we construct
3731 * an empty basic set that is not obviously empty.
3732 * isl_basic_set_is_empty marks the basic set as empty.
3733 * After projecting out i3, the variable can be dropped completely,
3734 * but isl_basic_map_simplify refrains from doing so if the basic set
3735 * is empty and would end up in an infinite loop if it didn't test
3736 * explicitly for empty basic maps in the outer loop.
3738 static int test_simplify(isl_ctx *ctx)
3740 const char *str;
3741 isl_basic_set *bset;
3742 int empty;
3744 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
3745 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
3746 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
3747 "i3 >= i2 }";
3748 bset = isl_basic_set_read_from_str(ctx, str);
3749 empty = isl_basic_set_is_empty(bset);
3750 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
3751 isl_basic_set_free(bset);
3752 if (!bset)
3753 return -1;
3754 if (!empty)
3755 isl_die(ctx, isl_error_unknown,
3756 "basic set should be empty", return -1);
3758 return 0;
3761 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
3762 * with gbr context would fail to disable the use of the shifted tableau
3763 * when transferring equalities for the input to the context, resulting
3764 * in invalid sample values.
3766 static int test_partial_lexmin(isl_ctx *ctx)
3768 const char *str;
3769 isl_basic_set *bset;
3770 isl_basic_map *bmap;
3771 isl_map *map;
3773 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
3774 bmap = isl_basic_map_read_from_str(ctx, str);
3775 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
3776 bset = isl_basic_set_read_from_str(ctx, str);
3777 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
3778 isl_map_free(map);
3780 if (!map)
3781 return -1;
3783 return 0;
3786 /* Check that the variable compression performed on the existentially
3787 * quantified variables inside isl_basic_set_compute_divs is not confused
3788 * by the implicit equalities among the parameters.
3790 static int test_compute_divs(isl_ctx *ctx)
3792 const char *str;
3793 isl_basic_set *bset;
3794 isl_set *set;
3796 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
3797 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
3798 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
3799 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
3800 bset = isl_basic_set_read_from_str(ctx, str);
3801 set = isl_basic_set_compute_divs(bset);
3802 isl_set_free(set);
3803 if (!set)
3804 return -1;
3806 return 0;
3809 struct {
3810 const char *name;
3811 int (*fn)(isl_ctx *ctx);
3812 } tests [] = {
3813 { "compute divs", &test_compute_divs },
3814 { "partial lexmin", &test_partial_lexmin },
3815 { "simplify", &test_simplify },
3816 { "curry", &test_curry },
3817 { "piecewise multi affine expressions", &test_pw_multi_aff },
3818 { "conversion", &test_conversion },
3819 { "list", &test_list },
3820 { "align parameters", &test_align_parameters },
3821 { "preimage", &test_preimage },
3822 { "pullback", &test_pullback },
3823 { "AST", &test_ast },
3824 { "AST generation", &test_ast_gen },
3825 { "eliminate", &test_eliminate },
3826 { "residue class", &test_residue_class },
3827 { "div", &test_div },
3828 { "slice", &test_slice },
3829 { "fixed power", &test_fixed_power },
3830 { "sample", &test_sample },
3831 { "output", &test_output },
3832 { "vertices", &test_vertices },
3833 { "fixed", &test_fixed },
3834 { "equal", &test_equal },
3835 { "product", &test_product },
3836 { "dim_max", &test_dim_max },
3837 { "affine", &test_aff },
3838 { "injective", &test_injective },
3839 { "schedule", &test_schedule },
3840 { "union_pw", &test_union_pw },
3841 { "parse", &test_parse },
3842 { "single-valued", &test_sv },
3843 { "affine hull", &test_affine_hull },
3844 { "coalesce", &test_coalesce },
3845 { "factorize", &test_factorize },
3846 { "subset", &test_subset },
3847 { "subtract", &test_subtract },
3848 { "lexmin", &test_lexmin },
3851 int main()
3853 int i;
3854 struct isl_ctx *ctx;
3856 srcdir = getenv("srcdir");
3857 assert(srcdir);
3859 ctx = isl_ctx_alloc();
3860 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
3861 printf("%s\n", tests[i].name);
3862 if (tests[i].fn(ctx) < 0)
3863 goto error;
3865 test_lift(ctx);
3866 test_bound(ctx);
3867 test_union(ctx);
3868 test_split_periods(ctx);
3869 test_pwqp(ctx);
3870 test_lex(ctx);
3871 test_bijective(ctx);
3872 test_dep(ctx);
3873 test_read(ctx);
3874 test_bounded(ctx);
3875 test_construction(ctx);
3876 test_dim(ctx);
3877 test_application(ctx);
3878 test_convex_hull(ctx);
3879 test_gist(ctx);
3880 test_closure(ctx);
3881 isl_ctx_free(ctx);
3882 return 0;
3883 error:
3884 isl_ctx_free(ctx);
3885 return -1;