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
13 #include <isl_ctx_private.h>
14 #include <isl_map_private.h>
15 #include <isl_aff_private.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>
28 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
32 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
35 char *pattern = "%s/test_inputs/%s.%s";
37 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
39 filename = isl_alloc_array(ctx, char, length);
44 sprintf(filename, pattern, srcdir, name, suffix);
49 void test_parse_map(isl_ctx *ctx, const char *str)
53 map = isl_map_read_from_str(ctx, str);
58 int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
63 map = isl_map_read_from_str(ctx, str);
64 map2 = isl_map_read_from_str(ctx, str2);
65 equal = isl_map_is_equal(map, map2);
72 isl_die(ctx, isl_error_unknown, "maps not equal",
78 void test_parse_pwqp(isl_ctx *ctx, const char *str)
80 isl_pw_qpolynomial *pwqp;
82 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
84 isl_pw_qpolynomial_free(pwqp);
87 static void test_parse_pwaff(isl_ctx *ctx, const char *str)
91 pwaff = isl_pw_aff_read_from_str(ctx, str);
93 isl_pw_aff_free(pwaff);
96 int test_parse(struct isl_ctx *ctx)
99 const char *str, *str2;
101 str = "{ [i] -> [-i] }";
102 map = isl_map_read_from_str(ctx, str);
106 str = "{ A[i] -> L[([i/3])] }";
107 map = isl_map_read_from_str(ctx, str);
111 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
112 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
113 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
115 str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
116 str2 = "{ [x, y] : 2y >= 6 - x }";
117 if (test_parse_map_equal(ctx, str, str2) < 0)
120 if (test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
121 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
123 str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
124 if (test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }",
128 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
129 map = isl_map_read_from_str(ctx, str);
130 str = "{ [new, old] -> [o0, o1] : "
131 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
132 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
133 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
134 map2 = isl_map_read_from_str(ctx, str);
135 assert(isl_map_is_equal(map, map2));
139 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
140 map = isl_map_read_from_str(ctx, str);
141 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
142 map2 = isl_map_read_from_str(ctx, str);
143 assert(isl_map_is_equal(map, map2));
147 str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
148 str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
149 if (test_parse_map_equal(ctx, str, str2) < 0)
152 str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
153 str2 = "{ [i,j] -> [min(i,j)] }";
154 if (test_parse_map_equal(ctx, str, str2) < 0)
157 str = "{ [i,j] : i != j }";
158 str2 = "{ [i,j] : i < j or i > j }";
159 if (test_parse_map_equal(ctx, str, str2) < 0)
162 str = "{ [i,j] : (i+1)*2 >= j }";
163 str2 = "{ [i, j] : j <= 2 + 2i }";
164 if (test_parse_map_equal(ctx, str, str2) < 0)
167 str = "{ [i] -> [i > 0 ? 4 : 5] }";
168 str2 = "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
169 if (test_parse_map_equal(ctx, str, str2) < 0)
172 str = "[N=2,M] -> { [i=[(M+N)/4]] }";
173 str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
174 if (test_parse_map_equal(ctx, str, str2) < 0)
177 str = "{ [x] : x >= 0 }";
178 str2 = "{ [x] : x-0 >= 0 }";
179 if (test_parse_map_equal(ctx, str, str2) < 0)
182 str = "{ [i] : ((i > 10)) }";
183 str2 = "{ [i] : i >= 11 }";
184 if (test_parse_map_equal(ctx, str, str2) < 0)
187 str = "{ [i] -> [0] }";
188 str2 = "{ [i] -> [0 * i] }";
189 if (test_parse_map_equal(ctx, str, str2) < 0)
192 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
193 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
194 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
195 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
197 if (test_parse_map_equal(ctx, "{ [a] -> [b] : (not false) }",
198 "{ [a] -> [b] : true }") < 0)
201 if (test_parse_map_equal(ctx, "{ [i] : i/2 <= 5 }",
202 "{ [i] : i <= 10 }") < 0)
205 if (test_parse_map_equal(ctx, "{Sym=[n] [i] : i <= n }",
206 "[n] -> { [i] : i <= n }") < 0)
209 if (test_parse_map_equal(ctx, "{ [*] }", "{ [a] }") < 0)
212 if (test_parse_map_equal(ctx, "{ [i] : 2*floor(i/2) = i }",
213 "{ [i] : exists a : i = 2 a }") < 0)
219 void test_read(struct isl_ctx *ctx)
223 struct isl_basic_set *bset1, *bset2;
224 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
226 filename = get_filename(ctx, "set", "omega");
228 input = fopen(filename, "r");
231 bset1 = isl_basic_set_read_from_file(ctx, input);
232 bset2 = isl_basic_set_read_from_str(ctx, str);
234 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
236 isl_basic_set_free(bset1);
237 isl_basic_set_free(bset2);
243 void test_bounded(struct isl_ctx *ctx)
248 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
249 bounded = isl_set_is_bounded(set);
253 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
254 bounded = isl_set_is_bounded(set);
258 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
259 bounded = isl_set_is_bounded(set);
264 /* Construct the basic set { [i] : 5 <= i <= N } */
265 void test_construction(struct isl_ctx *ctx)
270 struct isl_basic_set *bset;
271 struct isl_constraint *c;
275 dim = isl_space_set_alloc(ctx, 1, 1);
276 bset = isl_basic_set_universe(isl_space_copy(dim));
277 ls = isl_local_space_from_space(dim);
279 c = isl_inequality_alloc(isl_local_space_copy(ls));
280 isl_int_set_si(v, -1);
281 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
282 isl_int_set_si(v, 1);
283 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
284 bset = isl_basic_set_add_constraint(bset, c);
286 c = isl_inequality_alloc(isl_local_space_copy(ls));
287 isl_int_set_si(v, 1);
288 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
289 isl_int_set_si(v, -5);
290 isl_constraint_set_constant(c, v);
291 bset = isl_basic_set_add_constraint(bset, c);
293 isl_local_space_free(ls);
294 isl_basic_set_free(bset);
299 void test_dim(struct isl_ctx *ctx)
302 isl_map *map1, *map2;
304 map1 = isl_map_read_from_str(ctx,
305 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
306 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
307 map2 = isl_map_read_from_str(ctx,
308 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
309 assert(isl_map_is_equal(map1, map2));
312 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
313 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
314 assert(isl_map_is_equal(map1, map2));
319 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
320 map1 = isl_map_read_from_str(ctx, str);
321 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
322 map2 = isl_map_read_from_str(ctx, str);
323 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
324 assert(isl_map_is_equal(map1, map2));
331 __isl_give isl_val *(*op)(__isl_take isl_val *v);
335 { &isl_val_neg, "0", "0" },
336 { &isl_val_abs, "0", "0" },
337 { &isl_val_2exp, "0", "1" },
338 { &isl_val_floor, "0", "0" },
339 { &isl_val_ceil, "0", "0" },
340 { &isl_val_neg, "1", "-1" },
341 { &isl_val_neg, "-1", "1" },
342 { &isl_val_neg, "1/2", "-1/2" },
343 { &isl_val_neg, "-1/2", "1/2" },
344 { &isl_val_neg, "infty", "-infty" },
345 { &isl_val_neg, "-infty", "infty" },
346 { &isl_val_neg, "NaN", "NaN" },
347 { &isl_val_abs, "1", "1" },
348 { &isl_val_abs, "-1", "1" },
349 { &isl_val_abs, "1/2", "1/2" },
350 { &isl_val_abs, "-1/2", "1/2" },
351 { &isl_val_abs, "infty", "infty" },
352 { &isl_val_abs, "-infty", "infty" },
353 { &isl_val_abs, "NaN", "NaN" },
354 { &isl_val_floor, "1", "1" },
355 { &isl_val_floor, "-1", "-1" },
356 { &isl_val_floor, "1/2", "0" },
357 { &isl_val_floor, "-1/2", "-1" },
358 { &isl_val_floor, "infty", "infty" },
359 { &isl_val_floor, "-infty", "-infty" },
360 { &isl_val_floor, "NaN", "NaN" },
361 { &isl_val_ceil, "1", "1" },
362 { &isl_val_ceil, "-1", "-1" },
363 { &isl_val_ceil, "1/2", "1" },
364 { &isl_val_ceil, "-1/2", "0" },
365 { &isl_val_ceil, "infty", "infty" },
366 { &isl_val_ceil, "-infty", "-infty" },
367 { &isl_val_ceil, "NaN", "NaN" },
368 { &isl_val_2exp, "-3", "1/8" },
369 { &isl_val_2exp, "-1", "1/2" },
370 { &isl_val_2exp, "1", "2" },
371 { &isl_val_2exp, "2", "4" },
372 { &isl_val_2exp, "3", "8" },
375 /* Perform some basic tests of unary operations on isl_val objects.
377 static int test_un_val(isl_ctx *ctx)
381 __isl_give isl_val *(*fn)(__isl_take isl_val *v);
384 for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) {
385 v = isl_val_read_from_str(ctx, val_un_tests[i].arg);
386 res = isl_val_read_from_str(ctx, val_un_tests[i].res);
387 fn = val_un_tests[i].op;
389 if (isl_val_is_nan(res))
390 ok = isl_val_is_nan(v);
392 ok = isl_val_eq(v, res);
398 isl_die(ctx, isl_error_unknown,
399 "unexpected result", return -1);
406 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
407 __isl_take isl_val *v2);
409 ['+'] = { &isl_val_add },
410 ['-'] = { &isl_val_sub },
411 ['*'] = { &isl_val_mul },
412 ['/'] = { &isl_val_div },
413 ['g'] = { &isl_val_gcd },
414 ['m'] = { &isl_val_min },
415 ['M'] = { &isl_val_max },
423 } val_bin_tests[] = {
424 { "0", '+', "0", "0" },
425 { "1", '+', "0", "1" },
426 { "1", '+', "1", "2" },
427 { "1", '-', "1", "0" },
428 { "1", '*', "1", "1" },
429 { "1", '/', "1", "1" },
430 { "2", '*', "3", "6" },
431 { "2", '*', "1/2", "1" },
432 { "2", '*', "1/3", "2/3" },
433 { "2/3", '*', "3/5", "2/5" },
434 { "2/3", '*', "7/5", "14/15" },
435 { "2", '/', "1/2", "4" },
436 { "-2", '/', "-1/2", "4" },
437 { "-2", '/', "1/2", "-4" },
438 { "2", '/', "-1/2", "-4" },
439 { "2", '/', "2", "1" },
440 { "2", '/', "3", "2/3" },
441 { "2/3", '/', "5/3", "2/5" },
442 { "2/3", '/', "5/7", "14/15" },
443 { "0", '/', "0", "NaN" },
444 { "42", '/', "0", "NaN" },
445 { "-42", '/', "0", "NaN" },
446 { "infty", '/', "0", "NaN" },
447 { "-infty", '/', "0", "NaN" },
448 { "NaN", '/', "0", "NaN" },
449 { "0", '/', "NaN", "NaN" },
450 { "42", '/', "NaN", "NaN" },
451 { "-42", '/', "NaN", "NaN" },
452 { "infty", '/', "NaN", "NaN" },
453 { "-infty", '/', "NaN", "NaN" },
454 { "NaN", '/', "NaN", "NaN" },
455 { "0", '/', "infty", "0" },
456 { "42", '/', "infty", "0" },
457 { "-42", '/', "infty", "0" },
458 { "infty", '/', "infty", "NaN" },
459 { "-infty", '/', "infty", "NaN" },
460 { "NaN", '/', "infty", "NaN" },
461 { "0", '/', "-infty", "0" },
462 { "42", '/', "-infty", "0" },
463 { "-42", '/', "-infty", "0" },
464 { "infty", '/', "-infty", "NaN" },
465 { "-infty", '/', "-infty", "NaN" },
466 { "NaN", '/', "-infty", "NaN" },
467 { "1", '-', "1/3", "2/3" },
468 { "1/3", '+', "1/2", "5/6" },
469 { "1/2", '+', "1/2", "1" },
470 { "3/4", '-', "1/4", "1/2" },
471 { "1/2", '-', "1/3", "1/6" },
472 { "infty", '+', "42", "infty" },
473 { "infty", '+', "infty", "infty" },
474 { "42", '+', "infty", "infty" },
475 { "infty", '-', "infty", "NaN" },
476 { "infty", '*', "infty", "infty" },
477 { "infty", '*', "-infty", "-infty" },
478 { "-infty", '*', "infty", "-infty" },
479 { "-infty", '*', "-infty", "infty" },
480 { "0", '*', "infty", "NaN" },
481 { "1", '*', "infty", "infty" },
482 { "infty", '*', "0", "NaN" },
483 { "infty", '*', "42", "infty" },
484 { "42", '-', "infty", "-infty" },
485 { "infty", '+', "-infty", "NaN" },
486 { "4", 'g', "6", "2" },
487 { "5", 'g', "6", "1" },
488 { "42", 'm', "3", "3" },
489 { "42", 'M', "3", "42" },
490 { "3", 'm', "42", "3" },
491 { "3", 'M', "42", "42" },
492 { "42", 'm', "infty", "42" },
493 { "42", 'M', "infty", "infty" },
494 { "42", 'm', "-infty", "-infty" },
495 { "42", 'M', "-infty", "42" },
496 { "42", 'm', "NaN", "NaN" },
497 { "42", 'M', "NaN", "NaN" },
498 { "infty", 'm', "-infty", "-infty" },
499 { "infty", 'M', "-infty", "infty" },
502 /* Perform some basic tests of binary operations on isl_val objects.
504 static int test_bin_val(isl_ctx *ctx)
507 isl_val *v1, *v2, *res;
508 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
509 __isl_take isl_val *v2);
512 for (i = 0; i < ARRAY_SIZE(val_bin_tests); ++i) {
513 v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1);
514 v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2);
515 res = isl_val_read_from_str(ctx, val_bin_tests[i].res);
516 fn = val_bin_op[val_bin_tests[i].op].fn;
518 if (isl_val_is_nan(res))
519 ok = isl_val_is_nan(v1);
521 ok = isl_val_eq(v1, res);
527 isl_die(ctx, isl_error_unknown,
528 "unexpected result", return -1);
534 /* Perform some basic tests on isl_val objects.
536 static int test_val(isl_ctx *ctx)
538 if (test_un_val(ctx) < 0)
540 if (test_bin_val(ctx) < 0)
545 static int test_div(isl_ctx *ctx)
554 struct isl_basic_set *bset;
555 struct isl_constraint *c;
560 dim = isl_space_set_alloc(ctx, 0, 3);
561 bset = isl_basic_set_universe(isl_space_copy(dim));
562 ls = isl_local_space_from_space(dim);
564 c = isl_equality_alloc(isl_local_space_copy(ls));
565 isl_int_set_si(v, -1);
566 isl_constraint_set_constant(c, v);
567 isl_int_set_si(v, 1);
568 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
569 isl_int_set_si(v, 3);
570 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
571 bset = isl_basic_set_add_constraint(bset, c);
573 c = isl_equality_alloc(isl_local_space_copy(ls));
574 isl_int_set_si(v, 1);
575 isl_constraint_set_constant(c, v);
576 isl_int_set_si(v, -1);
577 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
578 isl_int_set_si(v, 3);
579 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
580 bset = isl_basic_set_add_constraint(bset, c);
582 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
584 assert(bset && bset->n_div == 1);
585 isl_local_space_free(ls);
586 isl_basic_set_free(bset);
589 dim = isl_space_set_alloc(ctx, 0, 3);
590 bset = isl_basic_set_universe(isl_space_copy(dim));
591 ls = isl_local_space_from_space(dim);
593 c = isl_equality_alloc(isl_local_space_copy(ls));
594 isl_int_set_si(v, 1);
595 isl_constraint_set_constant(c, v);
596 isl_int_set_si(v, -1);
597 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
598 isl_int_set_si(v, 3);
599 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
600 bset = isl_basic_set_add_constraint(bset, c);
602 c = isl_equality_alloc(isl_local_space_copy(ls));
603 isl_int_set_si(v, -1);
604 isl_constraint_set_constant(c, v);
605 isl_int_set_si(v, 1);
606 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
607 isl_int_set_si(v, 3);
608 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
609 bset = isl_basic_set_add_constraint(bset, c);
611 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
613 assert(bset && bset->n_div == 1);
614 isl_local_space_free(ls);
615 isl_basic_set_free(bset);
618 dim = isl_space_set_alloc(ctx, 0, 3);
619 bset = isl_basic_set_universe(isl_space_copy(dim));
620 ls = isl_local_space_from_space(dim);
622 c = isl_equality_alloc(isl_local_space_copy(ls));
623 isl_int_set_si(v, 1);
624 isl_constraint_set_constant(c, v);
625 isl_int_set_si(v, -1);
626 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
627 isl_int_set_si(v, 3);
628 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
629 bset = isl_basic_set_add_constraint(bset, c);
631 c = isl_equality_alloc(isl_local_space_copy(ls));
632 isl_int_set_si(v, -3);
633 isl_constraint_set_constant(c, v);
634 isl_int_set_si(v, 1);
635 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
636 isl_int_set_si(v, 4);
637 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
638 bset = isl_basic_set_add_constraint(bset, c);
640 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
642 assert(bset && bset->n_div == 1);
643 isl_local_space_free(ls);
644 isl_basic_set_free(bset);
647 dim = isl_space_set_alloc(ctx, 0, 3);
648 bset = isl_basic_set_universe(isl_space_copy(dim));
649 ls = isl_local_space_from_space(dim);
651 c = isl_equality_alloc(isl_local_space_copy(ls));
652 isl_int_set_si(v, 2);
653 isl_constraint_set_constant(c, v);
654 isl_int_set_si(v, -1);
655 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
656 isl_int_set_si(v, 3);
657 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
658 bset = isl_basic_set_add_constraint(bset, c);
660 c = isl_equality_alloc(isl_local_space_copy(ls));
661 isl_int_set_si(v, -1);
662 isl_constraint_set_constant(c, v);
663 isl_int_set_si(v, 1);
664 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
665 isl_int_set_si(v, 6);
666 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
667 bset = isl_basic_set_add_constraint(bset, c);
669 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
671 assert(isl_basic_set_is_empty(bset));
672 isl_local_space_free(ls);
673 isl_basic_set_free(bset);
676 dim = isl_space_set_alloc(ctx, 0, 3);
677 bset = isl_basic_set_universe(isl_space_copy(dim));
678 ls = isl_local_space_from_space(dim);
680 c = isl_equality_alloc(isl_local_space_copy(ls));
681 isl_int_set_si(v, -1);
682 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
683 isl_int_set_si(v, 3);
684 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
685 bset = isl_basic_set_add_constraint(bset, c);
687 c = isl_equality_alloc(isl_local_space_copy(ls));
688 isl_int_set_si(v, 1);
689 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
690 isl_int_set_si(v, -3);
691 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
692 bset = isl_basic_set_add_constraint(bset, c);
694 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
696 assert(bset && bset->n_div == 0);
697 isl_basic_set_free(bset);
698 isl_local_space_free(ls);
701 dim = isl_space_set_alloc(ctx, 0, 3);
702 bset = isl_basic_set_universe(isl_space_copy(dim));
703 ls = isl_local_space_from_space(dim);
705 c = isl_equality_alloc(isl_local_space_copy(ls));
706 isl_int_set_si(v, -1);
707 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
708 isl_int_set_si(v, 6);
709 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
710 bset = isl_basic_set_add_constraint(bset, c);
712 c = isl_equality_alloc(isl_local_space_copy(ls));
713 isl_int_set_si(v, 1);
714 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
715 isl_int_set_si(v, -3);
716 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
717 bset = isl_basic_set_add_constraint(bset, c);
719 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
721 assert(bset && bset->n_div == 1);
722 isl_basic_set_free(bset);
723 isl_local_space_free(ls);
726 /* This test is a bit tricky. We set up an equality
728 * Normalization of divs creates _two_ divs
731 * Afterwards e0 is removed again because it has coefficient -1
732 * and we end up with the original equality and div again.
733 * Perhaps we can avoid the introduction of this temporary div.
735 dim = isl_space_set_alloc(ctx, 0, 4);
736 bset = isl_basic_set_universe(isl_space_copy(dim));
737 ls = isl_local_space_from_space(dim);
739 c = isl_equality_alloc(isl_local_space_copy(ls));
740 isl_int_set_si(v, -1);
741 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
742 isl_int_set_si(v, -3);
743 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
744 isl_int_set_si(v, -3);
745 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
746 isl_int_set_si(v, 6);
747 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
748 bset = isl_basic_set_add_constraint(bset, c);
750 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
752 /* Test disabled for now */
754 assert(bset && bset->n_div == 1);
756 isl_local_space_free(ls);
757 isl_basic_set_free(bset);
760 dim = isl_space_set_alloc(ctx, 0, 5);
761 bset = isl_basic_set_universe(isl_space_copy(dim));
762 ls = isl_local_space_from_space(dim);
764 c = isl_equality_alloc(isl_local_space_copy(ls));
765 isl_int_set_si(v, -1);
766 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
767 isl_int_set_si(v, -3);
768 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
769 isl_int_set_si(v, -3);
770 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
771 isl_int_set_si(v, 6);
772 isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
773 bset = isl_basic_set_add_constraint(bset, c);
775 c = isl_equality_alloc(isl_local_space_copy(ls));
776 isl_int_set_si(v, -1);
777 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
778 isl_int_set_si(v, 1);
779 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
780 isl_int_set_si(v, 1);
781 isl_constraint_set_constant(c, v);
782 bset = isl_basic_set_add_constraint(bset, c);
784 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
786 /* Test disabled for now */
788 assert(bset && bset->n_div == 1);
790 isl_local_space_free(ls);
791 isl_basic_set_free(bset);
794 dim = isl_space_set_alloc(ctx, 0, 4);
795 bset = isl_basic_set_universe(isl_space_copy(dim));
796 ls = isl_local_space_from_space(dim);
798 c = isl_equality_alloc(isl_local_space_copy(ls));
799 isl_int_set_si(v, 1);
800 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
801 isl_int_set_si(v, -1);
802 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
803 isl_int_set_si(v, -2);
804 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
805 bset = isl_basic_set_add_constraint(bset, c);
807 c = isl_equality_alloc(isl_local_space_copy(ls));
808 isl_int_set_si(v, -1);
809 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
810 isl_int_set_si(v, 3);
811 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
812 isl_int_set_si(v, 2);
813 isl_constraint_set_constant(c, v);
814 bset = isl_basic_set_add_constraint(bset, c);
816 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
818 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
820 assert(!isl_basic_set_is_empty(bset));
822 isl_local_space_free(ls);
823 isl_basic_set_free(bset);
826 dim = isl_space_set_alloc(ctx, 0, 3);
827 bset = isl_basic_set_universe(isl_space_copy(dim));
828 ls = isl_local_space_from_space(dim);
830 c = isl_equality_alloc(isl_local_space_copy(ls));
831 isl_int_set_si(v, 1);
832 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
833 isl_int_set_si(v, -2);
834 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
835 bset = isl_basic_set_add_constraint(bset, c);
837 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
839 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
841 isl_local_space_free(ls);
842 isl_basic_set_free(bset);
846 str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
847 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
848 set = isl_set_read_from_str(ctx, str);
849 set = isl_set_compute_divs(set);
854 str = "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
855 bset = isl_basic_set_read_from_str(ctx, str);
856 n = isl_basic_set_dim(bset, isl_dim_div);
857 isl_basic_set_free(bset);
861 isl_die(ctx, isl_error_unknown,
862 "expecting no existentials", return -1);
864 str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
865 set = isl_set_read_from_str(ctx, str);
866 set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2);
867 set = isl_set_fix_si(set, isl_dim_set, 2, -3);
868 empty = isl_set_is_empty(set);
873 isl_die(ctx, isl_error_unknown,
874 "result not as accurate as expected", return -1);
879 void test_application_case(struct isl_ctx *ctx, const char *name)
883 struct isl_basic_set *bset1, *bset2;
884 struct isl_basic_map *bmap;
886 filename = get_filename(ctx, name, "omega");
888 input = fopen(filename, "r");
891 bset1 = isl_basic_set_read_from_file(ctx, input);
892 bmap = isl_basic_map_read_from_file(ctx, input);
894 bset1 = isl_basic_set_apply(bset1, bmap);
896 bset2 = isl_basic_set_read_from_file(ctx, input);
898 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
900 isl_basic_set_free(bset1);
901 isl_basic_set_free(bset2);
907 void test_application(struct isl_ctx *ctx)
909 test_application_case(ctx, "application");
910 test_application_case(ctx, "application2");
913 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
917 struct isl_basic_set *bset1, *bset2;
919 filename = get_filename(ctx, name, "polylib");
921 input = fopen(filename, "r");
924 bset1 = isl_basic_set_read_from_file(ctx, input);
925 bset2 = isl_basic_set_read_from_file(ctx, input);
927 bset1 = isl_basic_set_affine_hull(bset1);
929 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
931 isl_basic_set_free(bset1);
932 isl_basic_set_free(bset2);
938 int test_affine_hull(struct isl_ctx *ctx)
942 isl_basic_set *bset, *bset2;
946 test_affine_hull_case(ctx, "affine2");
947 test_affine_hull_case(ctx, "affine");
948 test_affine_hull_case(ctx, "affine3");
950 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
951 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
952 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
953 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
954 set = isl_set_read_from_str(ctx, str);
955 bset = isl_set_affine_hull(set);
956 n = isl_basic_set_dim(bset, isl_dim_div);
957 isl_basic_set_free(bset);
959 isl_die(ctx, isl_error_unknown, "not expecting any divs",
962 /* Check that isl_map_affine_hull is not confused by
963 * the reordering of divs in isl_map_align_divs.
965 str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
966 "32e0 = b and 32e1 = c); "
967 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
968 set = isl_set_read_from_str(ctx, str);
969 bset = isl_set_affine_hull(set);
970 isl_basic_set_free(bset);
974 str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
975 "32e2 = 31 + 31e0 }";
976 set = isl_set_read_from_str(ctx, str);
977 bset = isl_set_affine_hull(set);
978 str = "{ [a] : exists e : a = 32 e }";
979 bset2 = isl_basic_set_read_from_str(ctx, str);
980 subset = isl_basic_set_is_subset(bset, bset2);
981 isl_basic_set_free(bset);
982 isl_basic_set_free(bset2);
986 isl_die(ctx, isl_error_unknown, "not as accurate as expected",
992 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
996 struct isl_basic_set *bset1, *bset2;
999 filename = get_filename(ctx, name, "polylib");
1001 input = fopen(filename, "r");
1004 bset1 = isl_basic_set_read_from_file(ctx, input);
1005 bset2 = isl_basic_set_read_from_file(ctx, input);
1007 set = isl_basic_set_union(bset1, bset2);
1008 bset1 = isl_set_convex_hull(set);
1010 bset2 = isl_basic_set_read_from_file(ctx, input);
1012 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1014 isl_basic_set_free(bset1);
1015 isl_basic_set_free(bset2);
1021 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
1023 const char *str1, *str2;
1024 isl_set *set1, *set2;
1025 int orig_convex = ctx->opt->convex;
1026 ctx->opt->convex = convex;
1028 test_convex_hull_case(ctx, "convex0");
1029 test_convex_hull_case(ctx, "convex1");
1030 test_convex_hull_case(ctx, "convex2");
1031 test_convex_hull_case(ctx, "convex3");
1032 test_convex_hull_case(ctx, "convex4");
1033 test_convex_hull_case(ctx, "convex5");
1034 test_convex_hull_case(ctx, "convex6");
1035 test_convex_hull_case(ctx, "convex7");
1036 test_convex_hull_case(ctx, "convex8");
1037 test_convex_hull_case(ctx, "convex9");
1038 test_convex_hull_case(ctx, "convex10");
1039 test_convex_hull_case(ctx, "convex11");
1040 test_convex_hull_case(ctx, "convex12");
1041 test_convex_hull_case(ctx, "convex13");
1042 test_convex_hull_case(ctx, "convex14");
1043 test_convex_hull_case(ctx, "convex15");
1045 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1046 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1047 "(i0 = 0 and i1 = 0 and i2 = 0) }";
1048 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
1049 set1 = isl_set_read_from_str(ctx, str1);
1050 set2 = isl_set_read_from_str(ctx, str2);
1051 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
1052 assert(isl_set_is_equal(set1, set2));
1056 ctx->opt->convex = orig_convex;
1059 void test_convex_hull(struct isl_ctx *ctx)
1061 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
1062 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
1065 void test_gist_case(struct isl_ctx *ctx, const char *name)
1069 struct isl_basic_set *bset1, *bset2;
1071 filename = get_filename(ctx, name, "polylib");
1073 input = fopen(filename, "r");
1076 bset1 = isl_basic_set_read_from_file(ctx, input);
1077 bset2 = isl_basic_set_read_from_file(ctx, input);
1079 bset1 = isl_basic_set_gist(bset1, bset2);
1081 bset2 = isl_basic_set_read_from_file(ctx, input);
1083 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1085 isl_basic_set_free(bset1);
1086 isl_basic_set_free(bset2);
1092 void test_gist(struct isl_ctx *ctx)
1095 isl_basic_set *bset1, *bset2;
1097 test_gist_case(ctx, "gist1");
1099 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1100 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1101 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1102 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1103 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1104 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1105 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1106 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1107 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1108 bset1 = isl_basic_set_read_from_str(ctx, str);
1109 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1110 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1111 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1112 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1113 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1114 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1115 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1116 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1117 bset2 = isl_basic_set_read_from_str(ctx, str);
1118 bset1 = isl_basic_set_gist(bset1, bset2);
1119 assert(bset1 && bset1->n_div == 0);
1120 isl_basic_set_free(bset1);
1123 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
1125 isl_set *set, *set2;
1129 set = isl_set_read_from_str(ctx, str);
1130 set = isl_set_coalesce(set);
1131 set2 = isl_set_read_from_str(ctx, str);
1132 equal = isl_set_is_equal(set, set2);
1133 one = set && set->n == 1;
1140 isl_die(ctx, isl_error_unknown,
1141 "coalesced set not equal to input", return -1);
1142 if (check_one && !one)
1143 isl_die(ctx, isl_error_unknown,
1144 "coalesced set should not be a union", return -1);
1149 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
1154 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
1155 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
1157 if (test_coalesce_set(ctx,
1158 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1159 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1160 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1161 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1162 "-10 <= y <= 0}", 1) < 0)
1164 if (test_coalesce_set(ctx,
1165 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1167 if (test_coalesce_set(ctx,
1168 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1176 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
1181 /* Inputs for coalescing tests.
1182 * "str" is a string representation of the input set.
1183 * "single_disjunct" is set if we expect the result to consist of
1184 * a single disjunct.
1187 int single_disjunct;
1189 } coalesce_tests[] = {
1190 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1191 "y >= x & x >= 2 & 5 >= y }" },
1192 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1193 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1194 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1195 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1196 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1197 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1198 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1199 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1200 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1201 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1202 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1203 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1204 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1205 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1206 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1207 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1208 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1209 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1210 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1211 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1212 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1213 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1214 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1215 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1216 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1217 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1218 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1219 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1220 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1221 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1222 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1223 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1224 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1225 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1226 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1227 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1228 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1229 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1230 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1231 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1232 "[o0, o1, o2, o3, o4, o5, o6]] : "
1233 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1234 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1235 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1236 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1237 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1238 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1239 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1240 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1241 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1242 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1243 "o6 >= i3 + i6 - o3 and M >= 0 and "
1244 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1245 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1246 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1247 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1248 "(o0 = 0 and M >= 2 and N >= 3) or "
1249 "(M = 0 and o0 = 0 and N >= 3) }" },
1250 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1251 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1252 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1253 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1254 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1255 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1256 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1257 "(y = 3 and x = 1) }" },
1258 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1259 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1260 "i1 <= M and i3 <= M and i4 <= M) or "
1261 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1262 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1263 "i4 <= -1 + M) }" },
1264 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1265 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1266 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1267 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1268 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1269 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1270 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1271 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1272 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1273 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1274 { 0, "{ [a, b] : exists e : 2e = a and "
1275 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1276 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1277 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1278 "j >= 1 and j' <= i + j - i' and i >= 1; "
1280 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1281 "[i,j] : exists a : j = 3a }" },
1282 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1283 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1285 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1286 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1287 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1288 "c <= 6 + 8a and a >= 3; "
1289 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1290 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1291 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1292 "[x,0] : 3 <= x <= 4 }" },
1293 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1294 "[x,0] : 4 <= x <= 5 }" },
1295 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1296 "[x,0] : 3 <= x <= 5 }" },
1297 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1298 "[x,0] : 3 <= x <= 4 }" },
1299 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1301 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1304 /* Test the functionality of isl_set_coalesce.
1305 * That is, check that the output is always equal to the input
1306 * and in some cases that the result consists of a single disjunct.
1308 static int test_coalesce(struct isl_ctx *ctx)
1312 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
1313 const char *str = coalesce_tests[i].str;
1314 int check_one = coalesce_tests[i].single_disjunct;
1315 if (test_coalesce_set(ctx, str, check_one) < 0)
1319 if (test_coalesce_unbounded_wrapping(ctx) < 0)
1325 void test_closure(struct isl_ctx *ctx)
1329 isl_map *up, *right;
1330 isl_map *map, *map2;
1333 /* COCOA example 1 */
1334 map = isl_map_read_from_str(ctx,
1335 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1336 "1 <= i and i < n and 1 <= j and j < n or "
1337 "i2 = i + 1 and j2 = j - 1 and "
1338 "1 <= i and i < n and 2 <= j and j <= n }");
1339 map = isl_map_power(map, &exact);
1343 /* COCOA example 1 */
1344 map = isl_map_read_from_str(ctx,
1345 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1346 "1 <= i and i < n and 1 <= j and j < n or "
1347 "i2 = i + 1 and j2 = j - 1 and "
1348 "1 <= i and i < n and 2 <= j and j <= n }");
1349 map = isl_map_transitive_closure(map, &exact);
1351 map2 = isl_map_read_from_str(ctx,
1352 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1353 "1 <= i and i < n and 1 <= j and j <= n and "
1354 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1355 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1356 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1357 assert(isl_map_is_equal(map, map2));
1361 map = isl_map_read_from_str(ctx,
1362 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1363 " 0 <= y and y <= n }");
1364 map = isl_map_transitive_closure(map, &exact);
1365 map2 = isl_map_read_from_str(ctx,
1366 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1367 " 0 <= y and y <= n }");
1368 assert(isl_map_is_equal(map, map2));
1372 /* COCOA example 2 */
1373 map = isl_map_read_from_str(ctx,
1374 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1375 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1376 "i2 = i + 2 and j2 = j - 2 and "
1377 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1378 map = isl_map_transitive_closure(map, &exact);
1380 map2 = isl_map_read_from_str(ctx,
1381 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1382 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1383 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1384 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1385 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1386 assert(isl_map_is_equal(map, map2));
1390 /* COCOA Fig.2 left */
1391 map = isl_map_read_from_str(ctx,
1392 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1393 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1395 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1396 "j <= 2 i - 3 and j <= n - 2 or "
1397 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1398 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1399 map = isl_map_transitive_closure(map, &exact);
1403 /* COCOA Fig.2 right */
1404 map = isl_map_read_from_str(ctx,
1405 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1406 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1408 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1409 "j <= 2 i - 4 and j <= n - 3 or "
1410 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1411 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1412 map = isl_map_power(map, &exact);
1416 /* COCOA Fig.2 right */
1417 map = isl_map_read_from_str(ctx,
1418 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1419 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1421 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1422 "j <= 2 i - 4 and j <= n - 3 or "
1423 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1424 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1425 map = isl_map_transitive_closure(map, &exact);
1427 map2 = isl_map_read_from_str(ctx,
1428 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1429 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1430 "j <= n and 3 + i + 2 j <= 3 n and "
1431 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1432 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1433 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1434 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1435 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1436 assert(isl_map_is_equal(map, map2));
1440 /* COCOA Fig.1 right */
1441 dom = isl_set_read_from_str(ctx,
1442 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1443 "2 x - 3 y + 3 >= 0 }");
1444 right = isl_map_read_from_str(ctx,
1445 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1446 up = isl_map_read_from_str(ctx,
1447 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1448 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1449 right = isl_map_intersect_range(right, isl_set_copy(dom));
1450 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1451 up = isl_map_intersect_range(up, dom);
1452 map = isl_map_union(up, right);
1453 map = isl_map_transitive_closure(map, &exact);
1455 map2 = isl_map_read_from_str(ctx,
1456 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1457 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1458 assert(isl_map_is_equal(map, map2));
1462 /* COCOA Theorem 1 counter example */
1463 map = isl_map_read_from_str(ctx,
1464 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1465 "i2 = 1 and j2 = j or "
1466 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1467 map = isl_map_transitive_closure(map, &exact);
1471 map = isl_map_read_from_str(ctx,
1472 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1473 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1474 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1475 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1476 map = isl_map_transitive_closure(map, &exact);
1480 /* Kelly et al 1996, fig 12 */
1481 map = isl_map_read_from_str(ctx,
1482 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1483 "1 <= i,j,j+1 <= n or "
1484 "j = n and j2 = 1 and i2 = i + 1 and "
1485 "1 <= i,i+1 <= n }");
1486 map = isl_map_transitive_closure(map, &exact);
1488 map2 = isl_map_read_from_str(ctx,
1489 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1490 "1 <= i <= n and i = i2 or "
1491 "1 <= i < i2 <= n and 1 <= j <= n and "
1493 assert(isl_map_is_equal(map, map2));
1497 /* Omega's closure4 */
1498 map = isl_map_read_from_str(ctx,
1499 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1500 "1 <= x,y <= 10 or "
1501 "x2 = x + 1 and y2 = y and "
1502 "1 <= x <= 20 && 5 <= y <= 15 }");
1503 map = isl_map_transitive_closure(map, &exact);
1507 map = isl_map_read_from_str(ctx,
1508 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1509 map = isl_map_transitive_closure(map, &exact);
1511 map2 = isl_map_read_from_str(ctx,
1512 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1513 assert(isl_map_is_equal(map, map2));
1517 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1518 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1519 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1520 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1521 map = isl_map_read_from_str(ctx, str);
1522 map = isl_map_transitive_closure(map, &exact);
1524 map2 = isl_map_read_from_str(ctx, str);
1525 assert(isl_map_is_equal(map, map2));
1529 str = "{[0] -> [1]; [2] -> [3]}";
1530 map = isl_map_read_from_str(ctx, str);
1531 map = isl_map_transitive_closure(map, &exact);
1533 map2 = isl_map_read_from_str(ctx, str);
1534 assert(isl_map_is_equal(map, map2));
1538 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1539 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1540 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1541 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1542 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1543 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1544 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1545 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1546 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1547 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1548 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1549 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1550 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1551 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1552 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1553 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1554 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1555 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1556 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1557 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1558 map = isl_map_read_from_str(ctx, str);
1559 map = isl_map_transitive_closure(map, NULL);
1564 void test_lex(struct isl_ctx *ctx)
1569 dim = isl_space_set_alloc(ctx, 0, 0);
1570 map = isl_map_lex_le(dim);
1571 assert(!isl_map_is_empty(map));
1575 static int test_lexmin(struct isl_ctx *ctx)
1579 isl_basic_map *bmap;
1580 isl_map *map, *map2;
1583 isl_pw_multi_aff *pma;
1585 str = "[p0, p1] -> { [] -> [] : "
1586 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1587 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1588 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1589 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1590 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1591 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1592 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1593 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1594 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1595 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1596 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1597 map = isl_map_read_from_str(ctx, str);
1598 map = isl_map_lexmin(map);
1601 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1602 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1603 set = isl_set_read_from_str(ctx, str);
1604 set = isl_set_lexmax(set);
1605 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1606 set2 = isl_set_read_from_str(ctx, str);
1607 set = isl_set_intersect(set, set2);
1608 assert(!isl_set_is_empty(set));
1611 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1612 map = isl_map_read_from_str(ctx, str);
1613 map = isl_map_lexmin(map);
1614 str = "{ [x] -> [5] : 6 <= x <= 8; "
1615 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1616 map2 = isl_map_read_from_str(ctx, str);
1617 assert(isl_map_is_equal(map, map2));
1621 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1622 map = isl_map_read_from_str(ctx, str);
1623 map2 = isl_map_copy(map);
1624 map = isl_map_lexmin(map);
1625 assert(isl_map_is_equal(map, map2));
1629 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1630 map = isl_map_read_from_str(ctx, str);
1631 map = isl_map_lexmin(map);
1632 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1633 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1634 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1635 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1636 map2 = isl_map_read_from_str(ctx, str);
1637 assert(isl_map_is_equal(map, map2));
1641 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1642 " 8i' <= i and 8i' >= -7 + i }";
1643 bmap = isl_basic_map_read_from_str(ctx, str);
1644 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
1645 map2 = isl_map_from_pw_multi_aff(pma);
1646 map = isl_map_from_basic_map(bmap);
1647 assert(isl_map_is_equal(map, map2));
1651 str = "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1652 map = isl_map_read_from_str(ctx, str);
1653 map = isl_map_lexmin(map);
1654 str = "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1655 map2 = isl_map_read_from_str(ctx, str);
1656 assert(isl_map_is_equal(map, map2));
1660 /* Check that empty pieces are properly combined. */
1661 str = "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1662 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1663 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1664 map = isl_map_read_from_str(ctx, str);
1665 map = isl_map_lexmin(map);
1666 str = "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1667 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1669 map2 = isl_map_read_from_str(ctx, str);
1670 assert(isl_map_is_equal(map, map2));
1674 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1675 " 8i' <= i and 8i' >= -7 + i }";
1676 set = isl_set_read_from_str(ctx, str);
1677 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
1678 set2 = isl_set_from_pw_multi_aff(pma);
1679 equal = isl_set_is_equal(set, set2);
1685 isl_die(ctx, isl_error_unknown,
1686 "unexpected difference between set and "
1687 "piecewise affine expression", return -1);
1697 static int collect_must_may(__isl_take isl_map *dep, int must,
1698 void *dep_user, void *user)
1700 struct must_may *mm = (struct must_may *)user;
1703 mm->must = isl_map_union(mm->must, dep);
1705 mm->may = isl_map_union(mm->may, dep);
1710 static int common_space(void *first, void *second)
1712 int depth = *(int *)first;
1716 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1724 map2 = isl_map_read_from_str(map->ctx, str);
1725 equal = isl_map_is_equal(map, map2);
1731 static int map_check_equal(__isl_keep isl_map *map, const char *str)
1735 equal = map_is_equal(map, str);
1739 isl_die(isl_map_get_ctx(map), isl_error_unknown,
1740 "result not as expected", return -1);
1744 void test_dep(struct isl_ctx *ctx)
1749 isl_access_info *ai;
1756 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1757 map = isl_map_read_from_str(ctx, str);
1758 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1760 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1761 map = isl_map_read_from_str(ctx, str);
1762 ai = isl_access_info_add_source(ai, map, 1, &depth);
1764 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1765 map = isl_map_read_from_str(ctx, str);
1766 ai = isl_access_info_add_source(ai, map, 1, &depth);
1768 flow = isl_access_info_compute_flow(ai);
1769 dim = isl_space_alloc(ctx, 0, 3, 3);
1770 mm.must = isl_map_empty(isl_space_copy(dim));
1771 mm.may = isl_map_empty(dim);
1773 isl_flow_foreach(flow, collect_must_may, &mm);
1775 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1776 " [1,10,0] -> [2,5,0] }";
1777 assert(map_is_equal(mm.must, str));
1778 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1779 assert(map_is_equal(mm.may, str));
1781 isl_map_free(mm.must);
1782 isl_map_free(mm.may);
1783 isl_flow_free(flow);
1786 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1787 map = isl_map_read_from_str(ctx, str);
1788 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1790 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1791 map = isl_map_read_from_str(ctx, str);
1792 ai = isl_access_info_add_source(ai, map, 1, &depth);
1794 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1795 map = isl_map_read_from_str(ctx, str);
1796 ai = isl_access_info_add_source(ai, map, 0, &depth);
1798 flow = isl_access_info_compute_flow(ai);
1799 dim = isl_space_alloc(ctx, 0, 3, 3);
1800 mm.must = isl_map_empty(isl_space_copy(dim));
1801 mm.may = isl_map_empty(dim);
1803 isl_flow_foreach(flow, collect_must_may, &mm);
1805 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1806 assert(map_is_equal(mm.must, str));
1807 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1808 assert(map_is_equal(mm.may, str));
1810 isl_map_free(mm.must);
1811 isl_map_free(mm.may);
1812 isl_flow_free(flow);
1815 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1816 map = isl_map_read_from_str(ctx, str);
1817 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1819 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1820 map = isl_map_read_from_str(ctx, str);
1821 ai = isl_access_info_add_source(ai, map, 0, &depth);
1823 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1824 map = isl_map_read_from_str(ctx, str);
1825 ai = isl_access_info_add_source(ai, map, 0, &depth);
1827 flow = isl_access_info_compute_flow(ai);
1828 dim = isl_space_alloc(ctx, 0, 3, 3);
1829 mm.must = isl_map_empty(isl_space_copy(dim));
1830 mm.may = isl_map_empty(dim);
1832 isl_flow_foreach(flow, collect_must_may, &mm);
1834 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1835 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1836 assert(map_is_equal(mm.may, str));
1837 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1838 assert(map_is_equal(mm.must, str));
1840 isl_map_free(mm.must);
1841 isl_map_free(mm.may);
1842 isl_flow_free(flow);
1845 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1846 map = isl_map_read_from_str(ctx, str);
1847 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1849 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1850 map = isl_map_read_from_str(ctx, str);
1851 ai = isl_access_info_add_source(ai, map, 0, &depth);
1853 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1854 map = isl_map_read_from_str(ctx, str);
1855 ai = isl_access_info_add_source(ai, map, 0, &depth);
1857 flow = isl_access_info_compute_flow(ai);
1858 dim = isl_space_alloc(ctx, 0, 3, 3);
1859 mm.must = isl_map_empty(isl_space_copy(dim));
1860 mm.may = isl_map_empty(dim);
1862 isl_flow_foreach(flow, collect_must_may, &mm);
1864 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1865 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1866 assert(map_is_equal(mm.may, str));
1867 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1868 assert(map_is_equal(mm.must, str));
1870 isl_map_free(mm.must);
1871 isl_map_free(mm.may);
1872 isl_flow_free(flow);
1875 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1876 map = isl_map_read_from_str(ctx, str);
1877 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1879 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1880 map = isl_map_read_from_str(ctx, str);
1881 ai = isl_access_info_add_source(ai, map, 0, &depth);
1883 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1884 map = isl_map_read_from_str(ctx, str);
1885 ai = isl_access_info_add_source(ai, map, 0, &depth);
1887 flow = isl_access_info_compute_flow(ai);
1888 dim = isl_space_alloc(ctx, 0, 3, 3);
1889 mm.must = isl_map_empty(isl_space_copy(dim));
1890 mm.may = isl_map_empty(dim);
1892 isl_flow_foreach(flow, collect_must_may, &mm);
1894 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1895 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1896 assert(map_is_equal(mm.may, str));
1897 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1898 assert(map_is_equal(mm.must, str));
1900 isl_map_free(mm.must);
1901 isl_map_free(mm.may);
1902 isl_flow_free(flow);
1907 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1908 map = isl_map_read_from_str(ctx, str);
1909 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1911 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1912 map = isl_map_read_from_str(ctx, str);
1913 ai = isl_access_info_add_source(ai, map, 1, &depth);
1915 flow = isl_access_info_compute_flow(ai);
1916 dim = isl_space_alloc(ctx, 0, 5, 5);
1917 mm.must = isl_map_empty(isl_space_copy(dim));
1918 mm.may = isl_map_empty(dim);
1920 isl_flow_foreach(flow, collect_must_may, &mm);
1922 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1923 assert(map_is_equal(mm.must, str));
1924 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1925 assert(map_is_equal(mm.may, str));
1927 isl_map_free(mm.must);
1928 isl_map_free(mm.may);
1929 isl_flow_free(flow);
1932 int test_sv(isl_ctx *ctx)
1936 isl_union_map *umap;
1939 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1940 map = isl_map_read_from_str(ctx, str);
1941 sv = isl_map_is_single_valued(map);
1946 isl_die(ctx, isl_error_internal,
1947 "map not detected as single valued", return -1);
1949 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1950 map = isl_map_read_from_str(ctx, str);
1951 sv = isl_map_is_single_valued(map);
1956 isl_die(ctx, isl_error_internal,
1957 "map detected as single valued", return -1);
1959 str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1960 umap = isl_union_map_read_from_str(ctx, str);
1961 sv = isl_union_map_is_single_valued(umap);
1962 isl_union_map_free(umap);
1966 isl_die(ctx, isl_error_internal,
1967 "map not detected as single valued", return -1);
1969 str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1970 umap = isl_union_map_read_from_str(ctx, str);
1971 sv = isl_union_map_is_single_valued(umap);
1972 isl_union_map_free(umap);
1976 isl_die(ctx, isl_error_internal,
1977 "map detected as single valued", return -1);
1982 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1986 map = isl_map_read_from_str(ctx, str);
1988 assert(isl_map_is_bijective(map));
1990 assert(!isl_map_is_bijective(map));
1994 void test_bijective(struct isl_ctx *ctx)
1996 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1997 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1998 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1999 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2000 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
2001 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
2002 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
2003 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2004 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
2005 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
2006 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
2007 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
2008 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2011 static int test_pwqp(struct isl_ctx *ctx)
2015 isl_pw_qpolynomial *pwqp1, *pwqp2;
2018 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2019 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2021 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
2024 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2025 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2027 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2029 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2031 isl_pw_qpolynomial_free(pwqp1);
2033 str = "{ [i] -> i }";
2034 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2035 str = "{ [k] : exists a : k = 2a }";
2036 set = isl_set_read_from_str(ctx, str);
2037 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
2038 str = "{ [i] -> i }";
2039 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2041 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2043 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2045 isl_pw_qpolynomial_free(pwqp1);
2047 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
2048 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2050 set = isl_set_read_from_str(ctx, str);
2051 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
2052 str = "{ [i] -> 16 }";
2053 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2055 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2057 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2059 isl_pw_qpolynomial_free(pwqp1);
2061 str = "{ [i] -> ([(i)/2]) }";
2062 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2063 str = "{ [k] : exists a : k = 2a+1 }";
2064 set = isl_set_read_from_str(ctx, str);
2065 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
2066 str = "{ [i] -> -1/2 + 1/2 * i }";
2067 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2069 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2071 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2073 isl_pw_qpolynomial_free(pwqp1);
2075 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
2076 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2077 str = "{ [i] -> ([(2 * [i/2])/5]) }";
2078 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2080 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2082 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2084 isl_pw_qpolynomial_free(pwqp1);
2086 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
2087 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2088 str = "{ [x] -> x }";
2089 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2091 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2093 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2095 isl_pw_qpolynomial_free(pwqp1);
2097 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2098 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2099 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2100 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
2101 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2102 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2103 isl_pw_qpolynomial_free(pwqp1);
2105 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2106 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2107 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2108 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2109 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
2110 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
2111 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
2112 isl_pw_qpolynomial_free(pwqp1);
2113 isl_pw_qpolynomial_free(pwqp2);
2117 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2119 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2120 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2121 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2122 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2123 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
2125 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
2126 isl_pw_qpolynomial_free(pwqp1);
2127 isl_pw_qpolynomial_free(pwqp2);
2131 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2136 void test_split_periods(isl_ctx *ctx)
2139 isl_pw_qpolynomial *pwqp;
2141 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2142 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2143 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2144 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
2146 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
2149 isl_pw_qpolynomial_free(pwqp);
2152 void test_union(isl_ctx *ctx)
2155 isl_union_set *uset1, *uset2;
2156 isl_union_map *umap1, *umap2;
2158 str = "{ [i] : 0 <= i <= 1 }";
2159 uset1 = isl_union_set_read_from_str(ctx, str);
2160 str = "{ [1] -> [0] }";
2161 umap1 = isl_union_map_read_from_str(ctx, str);
2163 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
2164 assert(isl_union_map_is_equal(umap1, umap2));
2166 isl_union_map_free(umap1);
2167 isl_union_map_free(umap2);
2169 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2170 umap1 = isl_union_map_read_from_str(ctx, str);
2171 str = "{ A[i]; B[i] }";
2172 uset1 = isl_union_set_read_from_str(ctx, str);
2174 uset2 = isl_union_map_domain(umap1);
2176 assert(isl_union_set_is_equal(uset1, uset2));
2178 isl_union_set_free(uset1);
2179 isl_union_set_free(uset2);
2182 void test_bound(isl_ctx *ctx)
2185 isl_pw_qpolynomial *pwqp;
2186 isl_pw_qpolynomial_fold *pwf;
2188 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
2189 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
2190 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
2191 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 4);
2192 isl_pw_qpolynomial_fold_free(pwf);
2194 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2195 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
2196 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
2197 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 1);
2198 isl_pw_qpolynomial_fold_free(pwf);
2201 void test_lift(isl_ctx *ctx)
2204 isl_basic_map *bmap;
2205 isl_basic_set *bset;
2207 str = "{ [i0] : exists e0 : i0 = 4e0 }";
2208 bset = isl_basic_set_read_from_str(ctx, str);
2209 bset = isl_basic_set_lift(bset);
2210 bmap = isl_basic_map_from_range(bset);
2211 bset = isl_basic_map_domain(bmap);
2212 isl_basic_set_free(bset);
2219 } subset_tests[] = {
2221 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2222 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2223 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2225 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2226 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2227 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2228 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2229 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2230 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2231 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2232 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2233 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2234 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2235 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2236 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2237 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2240 static int test_subset(isl_ctx *ctx)
2243 isl_set *set1, *set2;
2246 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
2247 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
2248 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
2249 subset = isl_set_is_subset(set1, set2);
2254 if (subset != subset_tests[i].subset)
2255 isl_die(ctx, isl_error_unknown,
2256 "incorrect subset result", return -1);
2263 const char *minuend;
2264 const char *subtrahend;
2265 const char *difference;
2266 } subtract_domain_tests[] = {
2267 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2268 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2269 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2272 static int test_subtract(isl_ctx *ctx)
2275 isl_union_map *umap1, *umap2;
2276 isl_union_set *uset;
2279 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
2280 umap1 = isl_union_map_read_from_str(ctx,
2281 subtract_domain_tests[i].minuend);
2282 uset = isl_union_set_read_from_str(ctx,
2283 subtract_domain_tests[i].subtrahend);
2284 umap2 = isl_union_map_read_from_str(ctx,
2285 subtract_domain_tests[i].difference);
2286 umap1 = isl_union_map_subtract_domain(umap1, uset);
2287 equal = isl_union_map_is_equal(umap1, umap2);
2288 isl_union_map_free(umap1);
2289 isl_union_map_free(umap2);
2293 isl_die(ctx, isl_error_unknown,
2294 "incorrect subtract domain result", return -1);
2300 int test_factorize(isl_ctx *ctx)
2303 isl_basic_set *bset;
2306 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2307 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2308 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2309 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2310 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2311 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2312 "3i5 >= -2i0 - i2 + 3i4 }";
2313 bset = isl_basic_set_read_from_str(ctx, str);
2314 f = isl_basic_set_factorizer(bset);
2315 isl_basic_set_free(bset);
2316 isl_factorizer_free(f);
2318 isl_die(ctx, isl_error_unknown,
2319 "failed to construct factorizer", return -1);
2321 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2322 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2323 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2324 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2325 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2326 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2327 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2328 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2329 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2330 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2331 bset = isl_basic_set_read_from_str(ctx, str);
2332 f = isl_basic_set_factorizer(bset);
2333 isl_basic_set_free(bset);
2334 isl_factorizer_free(f);
2336 isl_die(ctx, isl_error_unknown,
2337 "failed to construct factorizer", return -1);
2342 static int check_injective(__isl_take isl_map *map, void *user)
2344 int *injective = user;
2346 *injective = isl_map_is_injective(map);
2349 if (*injective < 0 || !*injective)
2355 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
2356 const char *r, const char *s, int tilable, int parallel)
2360 isl_union_map *W, *R, *S;
2361 isl_union_map *empty;
2362 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
2363 isl_union_map *validity, *proximity;
2364 isl_union_map *schedule;
2365 isl_union_map *test;
2366 isl_union_set *delta;
2367 isl_union_set *domain;
2371 isl_schedule *sched;
2372 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
2374 D = isl_union_set_read_from_str(ctx, d);
2375 W = isl_union_map_read_from_str(ctx, w);
2376 R = isl_union_map_read_from_str(ctx, r);
2377 S = isl_union_map_read_from_str(ctx, s);
2379 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
2380 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
2382 empty = isl_union_map_empty(isl_union_map_get_space(S));
2383 isl_union_map_compute_flow(isl_union_map_copy(R),
2384 isl_union_map_copy(W), empty,
2385 isl_union_map_copy(S),
2386 &dep_raw, NULL, NULL, NULL);
2387 isl_union_map_compute_flow(isl_union_map_copy(W),
2388 isl_union_map_copy(W),
2389 isl_union_map_copy(R),
2390 isl_union_map_copy(S),
2391 &dep_waw, &dep_war, NULL, NULL);
2393 dep = isl_union_map_union(dep_waw, dep_war);
2394 dep = isl_union_map_union(dep, dep_raw);
2395 validity = isl_union_map_copy(dep);
2396 proximity = isl_union_map_copy(dep);
2398 sched = isl_union_set_compute_schedule(isl_union_set_copy(D),
2399 validity, proximity);
2400 schedule = isl_schedule_get_map(sched);
2401 isl_schedule_free(sched);
2402 isl_union_map_free(W);
2403 isl_union_map_free(R);
2404 isl_union_map_free(S);
2407 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
2409 domain = isl_union_map_domain(isl_union_map_copy(schedule));
2410 is_complete = isl_union_set_is_subset(D, domain);
2411 isl_union_set_free(D);
2412 isl_union_set_free(domain);
2414 test = isl_union_map_reverse(isl_union_map_copy(schedule));
2415 test = isl_union_map_apply_range(test, dep);
2416 test = isl_union_map_apply_range(test, schedule);
2418 delta = isl_union_map_deltas(test);
2419 if (isl_union_set_n_set(delta) == 0) {
2423 isl_union_set_free(delta);
2425 delta_set = isl_set_from_union_set(delta);
2427 slice = isl_set_universe(isl_set_get_space(delta_set));
2428 for (i = 0; i < tilable; ++i)
2429 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
2430 is_tilable = isl_set_is_subset(delta_set, slice);
2431 isl_set_free(slice);
2433 slice = isl_set_universe(isl_set_get_space(delta_set));
2434 for (i = 0; i < parallel; ++i)
2435 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
2436 is_parallel = isl_set_is_subset(delta_set, slice);
2437 isl_set_free(slice);
2439 origin = isl_set_universe(isl_set_get_space(delta_set));
2440 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
2441 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
2443 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
2444 delta_set = isl_set_lexmin(delta_set);
2446 is_nonneg = isl_set_is_equal(delta_set, origin);
2448 isl_set_free(origin);
2449 isl_set_free(delta_set);
2452 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
2453 is_injection < 0 || is_complete < 0)
2456 isl_die(ctx, isl_error_unknown,
2457 "generated schedule incomplete", return -1);
2459 isl_die(ctx, isl_error_unknown,
2460 "generated schedule not injective on each statement",
2463 isl_die(ctx, isl_error_unknown,
2464 "negative dependences in generated schedule",
2467 isl_die(ctx, isl_error_unknown,
2468 "generated schedule not as tilable as expected",
2471 isl_die(ctx, isl_error_unknown,
2472 "generated schedule not as parallel as expected",
2478 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
2479 const char *domain, const char *validity, const char *proximity)
2483 isl_union_map *prox;
2484 isl_schedule *schedule;
2485 isl_union_map *sched;
2487 dom = isl_union_set_read_from_str(ctx, domain);
2488 dep = isl_union_map_read_from_str(ctx, validity);
2489 prox = isl_union_map_read_from_str(ctx, proximity);
2490 schedule = isl_union_set_compute_schedule(dom, dep, prox);
2491 sched = isl_schedule_get_map(schedule);
2492 isl_schedule_free(schedule);
2497 /* Check that a schedule can be constructed on the given domain
2498 * with the given validity and proximity constraints.
2500 static int test_has_schedule(isl_ctx *ctx, const char *domain,
2501 const char *validity, const char *proximity)
2503 isl_union_map *sched;
2505 sched = compute_schedule(ctx, domain, validity, proximity);
2509 isl_union_map_free(sched);
2513 int test_special_schedule(isl_ctx *ctx, const char *domain,
2514 const char *validity, const char *proximity, const char *expected_sched)
2516 isl_union_map *sched1, *sched2;
2519 sched1 = compute_schedule(ctx, domain, validity, proximity);
2520 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
2522 equal = isl_union_map_is_equal(sched1, sched2);
2523 isl_union_map_free(sched1);
2524 isl_union_map_free(sched2);
2529 isl_die(ctx, isl_error_unknown, "unexpected schedule",
2535 /* Check that the schedule map is properly padded, even after being
2536 * reconstructed from the band forest.
2538 static int test_padded_schedule(isl_ctx *ctx)
2542 isl_union_map *validity, *proximity;
2543 isl_schedule *sched;
2544 isl_union_map *map1, *map2;
2545 isl_band_list *list;
2548 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2549 D = isl_union_set_read_from_str(ctx, str);
2550 validity = isl_union_map_empty(isl_union_set_get_space(D));
2551 proximity = isl_union_map_copy(validity);
2552 sched = isl_union_set_compute_schedule(D, validity, proximity);
2553 map1 = isl_schedule_get_map(sched);
2554 list = isl_schedule_get_band_forest(sched);
2555 isl_band_list_free(list);
2556 map2 = isl_schedule_get_map(sched);
2557 isl_schedule_free(sched);
2558 equal = isl_union_map_is_equal(map1, map2);
2559 isl_union_map_free(map1);
2560 isl_union_map_free(map2);
2565 isl_die(ctx, isl_error_unknown,
2566 "reconstructed schedule map not the same as original",
2572 int test_schedule(isl_ctx *ctx)
2574 const char *D, *W, *R, *V, *P, *S;
2576 /* Handle resulting schedule with zero bands. */
2577 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2581 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2582 W = "{ S1[t,i] -> a[t,i] }";
2583 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2584 "S1[t,i] -> a[t-1,i+1] }";
2585 S = "{ S1[t,i] -> [t,i] }";
2586 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2589 /* Fig. 5 of CC2008 */
2590 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2592 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2593 "j >= 2 and j <= -1 + N }";
2594 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2595 "j >= 2 and j <= -1 + N; "
2596 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2597 "j >= 2 and j <= -1 + N }";
2598 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2599 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2602 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2603 W = "{ S1[i] -> a[i] }";
2604 R = "{ S2[i] -> a[i+1] }";
2605 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2606 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2609 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2610 W = "{ S1[i] -> a[i] }";
2611 R = "{ S2[i] -> a[9-i] }";
2612 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2613 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2616 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2617 W = "{ S1[i] -> a[i] }";
2618 R = "[N] -> { S2[i] -> a[N-1-i] }";
2619 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2620 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2623 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2624 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2625 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2626 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2627 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2630 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2631 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2632 R = "{ S2[i,j] -> a[i-1,j] }";
2633 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2634 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2637 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2638 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2639 R = "{ S2[i,j] -> a[i,j-1] }";
2640 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2641 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2644 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2645 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2646 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2647 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2648 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2649 "S_0[] -> [0, 0, 0] }";
2650 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
2652 ctx->opt->schedule_parametric = 0;
2653 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2655 ctx->opt->schedule_parametric = 1;
2657 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2658 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2659 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2660 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2661 "S4[i] -> a[i,N] }";
2662 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2663 "S4[i] -> [4,i,0] }";
2664 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2667 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2668 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2670 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2672 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2674 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2675 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2678 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2679 " S_2[t] : t >= 0 and t <= -1 + N; "
2680 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2682 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2683 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2684 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2685 "i >= 0 and i <= -1 + N }";
2686 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2687 "i >= 0 and i <= -1 + N; "
2688 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2689 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2690 " S_0[t] -> [0, t, 0] }";
2692 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2694 ctx->opt->schedule_parametric = 0;
2695 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2697 ctx->opt->schedule_parametric = 1;
2699 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2700 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2701 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
2704 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2705 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2706 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2707 "j >= 0 and j <= -1 + N; "
2708 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2709 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2710 "j >= 0 and j <= -1 + N; "
2711 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2712 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2713 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2716 D = "{ S_0[i] : i >= 0 }";
2717 W = "{ S_0[i] -> a[i] : i >= 0 }";
2718 R = "{ S_0[i] -> a[0] : i >= 0 }";
2719 S = "{ S_0[i] -> [0, i, 0] }";
2720 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2723 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2724 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2725 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2726 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2727 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2730 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2731 "k <= -1 + n and k >= 0 }";
2732 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2733 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2734 "k <= -1 + n and k >= 0; "
2735 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2736 "k <= -1 + n and k >= 0; "
2737 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2738 "k <= -1 + n and k >= 0 }";
2739 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
2740 ctx->opt->schedule_outer_zero_distance = 1;
2741 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2743 ctx->opt->schedule_outer_zero_distance = 0;
2745 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
2746 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2747 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2748 "Stmt_for_body24[i0, i1, 1, 0]:"
2749 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2750 "Stmt_for_body7[i0, i1, i2]:"
2751 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2754 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
2755 "Stmt_for_body24[1, i1, i2, i3]:"
2756 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2758 "Stmt_for_body24[0, i1, i2, i3] -> "
2759 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2760 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2762 "Stmt_for_body24[0, i1, i2, i3] ->"
2763 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2764 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2765 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2766 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2767 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2768 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2769 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2770 "i1 <= 6 and i1 >= 0;"
2771 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2772 "Stmt_for_body7[i0, i1, i2] -> "
2773 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2774 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2775 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2776 "Stmt_for_body7[i0, i1, i2] -> "
2777 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2778 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2779 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2781 S = "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2782 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2783 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2785 if (test_special_schedule(ctx, D, V, P, S) < 0)
2788 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2789 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2790 "j >= 1 and j <= 7;"
2791 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2792 "j >= 1 and j <= 8 }";
2794 S = "{ S_0[i, j] -> [i + j, j] }";
2795 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2796 if (test_special_schedule(ctx, D, V, P, S) < 0)
2798 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2800 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2801 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2802 "j >= 0 and j <= -1 + i }";
2803 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2804 "i <= -1 + N and j >= 0;"
2805 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2808 S = "{ S_0[i, j] -> [i, j] }";
2809 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2810 if (test_special_schedule(ctx, D, V, P, S) < 0)
2812 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2814 /* Test both algorithms on a case with only proximity dependences. */
2815 D = "{ S[i,j] : 0 <= i <= 10 }";
2817 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2818 S = "{ S[i, j] -> [j, i] }";
2819 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2820 if (test_special_schedule(ctx, D, V, P, S) < 0)
2822 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2823 if (test_special_schedule(ctx, D, V, P, S) < 0)
2826 D = "{ A[a]; B[] }";
2828 P = "{ A[a] -> B[] }";
2829 if (test_has_schedule(ctx, D, V, P) < 0)
2832 if (test_padded_schedule(ctx) < 0)
2835 /* Check that check for progress is not confused by rational
2838 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
2839 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
2841 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
2842 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
2844 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2845 if (test_has_schedule(ctx, D, V, P) < 0)
2847 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2852 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
2854 isl_union_map *umap;
2857 umap = isl_union_map_read_from_str(ctx, str);
2858 test = isl_union_map_plain_is_injective(umap);
2859 isl_union_map_free(umap);
2862 if (test == injective)
2865 isl_die(ctx, isl_error_unknown,
2866 "map not detected as injective", return -1);
2868 isl_die(ctx, isl_error_unknown,
2869 "map detected as injective", return -1);
2872 int test_injective(isl_ctx *ctx)
2876 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2878 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
2880 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
2882 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
2884 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2886 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2888 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2890 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2893 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2894 if (test_plain_injective(ctx, str, 1))
2896 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2897 if (test_plain_injective(ctx, str, 0))
2903 static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
2911 aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
2912 equal = isl_aff_plain_is_equal(aff, aff2);
2918 static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
2922 equal = aff_plain_is_equal(aff, str);
2926 isl_die(isl_aff_get_ctx(aff), isl_error_unknown,
2927 "result not as expected", return -1);
2931 int test_aff(isl_ctx *ctx)
2936 isl_local_space *ls;
2940 space = isl_space_set_alloc(ctx, 0, 1);
2941 ls = isl_local_space_from_space(space);
2942 aff = isl_aff_zero_on_domain(ls);
2944 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2945 aff = isl_aff_scale_down_ui(aff, 3);
2946 aff = isl_aff_floor(aff);
2947 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2948 aff = isl_aff_scale_down_ui(aff, 2);
2949 aff = isl_aff_floor(aff);
2950 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2953 set = isl_set_read_from_str(ctx, str);
2954 aff = isl_aff_gist(aff, set);
2956 aff = isl_aff_add_constant_si(aff, -16);
2957 zero = isl_aff_plain_is_zero(aff);
2963 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2965 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
2966 aff = isl_aff_scale_down_ui(aff, 64);
2967 aff = isl_aff_floor(aff);
2968 equal = aff_check_plain_equal(aff, "{ [-1] }");
2976 int test_dim_max(isl_ctx *ctx)
2980 isl_set *set1, *set2;
2985 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
2986 set = isl_set_read_from_str(ctx, str);
2987 pwaff = isl_set_dim_max(set, 0);
2988 set1 = isl_set_from_pw_aff(pwaff);
2989 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2990 set2 = isl_set_read_from_str(ctx, str);
2991 equal = isl_set_is_equal(set1, set2);
2997 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2999 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3000 set = isl_set_read_from_str(ctx, str);
3001 pwaff = isl_set_dim_max(set, 0);
3002 set1 = isl_set_from_pw_aff(pwaff);
3003 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3004 set2 = isl_set_read_from_str(ctx, str);
3005 equal = isl_set_is_equal(set1, set2);
3011 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3013 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3014 set = isl_set_read_from_str(ctx, str);
3015 pwaff = isl_set_dim_max(set, 0);
3016 set1 = isl_set_from_pw_aff(pwaff);
3017 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3018 set2 = isl_set_read_from_str(ctx, str);
3019 equal = isl_set_is_equal(set1, set2);
3025 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3027 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3028 "0 <= i < N and 0 <= j < M }";
3029 map = isl_map_read_from_str(ctx, str);
3030 set = isl_map_range(map);
3032 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
3033 set1 = isl_set_from_pw_aff(pwaff);
3034 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3035 set2 = isl_set_read_from_str(ctx, str);
3036 equal = isl_set_is_equal(set1, set2);
3040 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
3041 set1 = isl_set_from_pw_aff(pwaff);
3042 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3043 set2 = isl_set_read_from_str(ctx, str);
3044 if (equal >= 0 && equal)
3045 equal = isl_set_is_equal(set1, set2);
3054 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3056 /* Check that solutions are properly merged. */
3057 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
3058 "c <= -1 + n - 4a - 2b and c >= -2b and "
3059 "4a >= -4 + n and c >= 0 }";
3060 set = isl_set_read_from_str(ctx, str);
3061 pwaff = isl_set_dim_min(set, 2);
3062 set1 = isl_set_from_pw_aff(pwaff);
3063 str = "[n] -> { [(0)] : n >= 1 }";
3064 set2 = isl_set_read_from_str(ctx, str);
3065 equal = isl_set_is_equal(set1, set2);
3072 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3077 int test_product(isl_ctx *ctx)
3081 isl_union_set *uset1, *uset2;
3085 set = isl_set_read_from_str(ctx, str);
3086 set = isl_set_product(set, isl_set_copy(set));
3087 ok = isl_set_is_wrapping(set);
3092 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3095 uset1 = isl_union_set_read_from_str(ctx, str);
3096 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
3097 str = "{ [[] -> []] }";
3098 uset2 = isl_union_set_read_from_str(ctx, str);
3099 ok = isl_union_set_is_equal(uset1, uset2);
3100 isl_union_set_free(uset1);
3101 isl_union_set_free(uset2);
3105 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3110 int test_equal(isl_ctx *ctx)
3113 isl_set *set, *set2;
3117 set = isl_set_read_from_str(ctx, str);
3119 set2 = isl_set_read_from_str(ctx, str);
3120 equal = isl_set_is_equal(set, set2);
3126 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3131 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
3132 enum isl_dim_type type, unsigned pos, int fixed)
3136 test = isl_map_plain_is_fixed(map, type, pos, NULL);
3143 isl_die(ctx, isl_error_unknown,
3144 "map not detected as fixed", return -1);
3146 isl_die(ctx, isl_error_unknown,
3147 "map detected as fixed", return -1);
3150 int test_fixed(isl_ctx *ctx)
3155 str = "{ [i] -> [i] }";
3156 map = isl_map_read_from_str(ctx, str);
3157 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
3159 str = "{ [i] -> [1] }";
3160 map = isl_map_read_from_str(ctx, str);
3161 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
3163 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3164 map = isl_map_read_from_str(ctx, str);
3165 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
3167 map = isl_map_read_from_str(ctx, str);
3168 map = isl_map_neg(map);
3169 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
3175 int test_vertices(isl_ctx *ctx)
3178 isl_basic_set *bset;
3179 isl_vertices *vertices;
3181 str = "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
3182 bset = isl_basic_set_read_from_str(ctx, str);
3183 vertices = isl_basic_set_compute_vertices(bset);
3184 isl_basic_set_free(bset);
3185 isl_vertices_free(vertices);
3189 str = "{ A[t, i] : t = 14 and i = 1 }";
3190 bset = isl_basic_set_read_from_str(ctx, str);
3191 vertices = isl_basic_set_compute_vertices(bset);
3192 isl_basic_set_free(bset);
3193 isl_vertices_free(vertices);
3200 int test_union_pw(isl_ctx *ctx)
3204 isl_union_set *uset;
3205 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
3207 str = "{ [x] -> x^2 }";
3208 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
3209 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
3210 uset = isl_union_pw_qpolynomial_domain(upwqp1);
3211 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
3212 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
3213 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
3214 isl_union_pw_qpolynomial_free(upwqp1);
3215 isl_union_pw_qpolynomial_free(upwqp2);
3219 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3224 int test_output(isl_ctx *ctx)
3232 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3233 pa = isl_pw_aff_read_from_str(ctx, str);
3235 p = isl_printer_to_str(ctx);
3236 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
3237 p = isl_printer_print_pw_aff(p, pa);
3238 s = isl_printer_get_str(p);
3239 isl_printer_free(p);
3240 isl_pw_aff_free(pa);
3244 equal = !strcmp(s, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
3249 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3254 int test_sample(isl_ctx *ctx)
3257 isl_basic_set *bset1, *bset2;
3260 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3261 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3262 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3263 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3264 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3265 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3266 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3267 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3268 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3269 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3270 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3271 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3272 "d - 1073741821e and "
3273 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3274 "3j >= 1 - a + b + 2e and "
3275 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3276 "3i <= 4 - a + 4b - e and "
3277 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3278 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3279 "c <= -1 + a and 3i >= -2 - a + 3e and "
3280 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3281 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3282 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3283 "1073741823e >= 1 + 1073741823b - d and "
3284 "3i >= 1073741823b + c - 1073741823e - f and "
3285 "3i >= 1 + 2b + e + 3g }";
3286 bset1 = isl_basic_set_read_from_str(ctx, str);
3287 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
3288 empty = isl_basic_set_is_empty(bset2);
3289 subset = isl_basic_set_is_subset(bset2, bset1);
3290 isl_basic_set_free(bset1);
3291 isl_basic_set_free(bset2);
3292 if (empty < 0 || subset < 0)
3295 isl_die(ctx, isl_error_unknown, "point not found", return -1);
3297 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
3302 int test_fixed_power(isl_ctx *ctx)
3310 str = "{ [i] -> [i + 1] }";
3311 map = isl_map_read_from_str(ctx, str);
3312 isl_int_set_si(exp, 23);
3313 map = isl_map_fixed_power(map, exp);
3314 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
3323 int test_slice(isl_ctx *ctx)
3329 str = "{ [i] -> [j] }";
3330 map = isl_map_read_from_str(ctx, str);
3331 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
3332 equal = map_check_equal(map, "{ [i] -> [i] }");
3337 str = "{ [i] -> [j] }";
3338 map = isl_map_read_from_str(ctx, str);
3339 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
3340 equal = map_check_equal(map, "{ [i] -> [j] }");
3345 str = "{ [i] -> [j] }";
3346 map = isl_map_read_from_str(ctx, str);
3347 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
3348 equal = map_check_equal(map, "{ [i] -> [-i] }");
3353 str = "{ [i] -> [j] }";
3354 map = isl_map_read_from_str(ctx, str);
3355 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
3356 equal = map_check_equal(map, "{ [0] -> [j] }");
3361 str = "{ [i] -> [j] }";
3362 map = isl_map_read_from_str(ctx, str);
3363 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
3364 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
3369 str = "{ [i] -> [j] }";
3370 map = isl_map_read_from_str(ctx, str);
3371 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
3372 equal = map_check_equal(map, "{ [i] -> [j] : false }");
3380 int test_eliminate(isl_ctx *ctx)
3386 str = "{ [i] -> [j] : i = 2j }";
3387 map = isl_map_read_from_str(ctx, str);
3388 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
3389 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
3397 /* Check that isl_set_dim_residue_class detects that the values of j
3398 * in the set below are all odd and that it does not detect any spurious
3401 static int test_residue_class(isl_ctx *ctx)
3408 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3409 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3410 set = isl_set_read_from_str(ctx, str);
3413 res = isl_set_dim_residue_class(set, 1, &m, &r);
3415 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
3416 isl_die(ctx, isl_error_unknown, "incorrect residue class",
3425 int test_align_parameters(isl_ctx *ctx)
3429 isl_multi_aff *ma1, *ma2;
3432 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3433 ma1 = isl_multi_aff_read_from_str(ctx, str);
3435 space = isl_space_params_alloc(ctx, 1);
3436 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
3437 ma1 = isl_multi_aff_align_params(ma1, space);
3439 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3440 ma2 = isl_multi_aff_read_from_str(ctx, str);
3442 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
3444 isl_multi_aff_free(ma1);
3445 isl_multi_aff_free(ma2);
3450 isl_die(ctx, isl_error_unknown,
3451 "result not as expected", return -1);
3456 static int test_list(isl_ctx *ctx)
3458 isl_id *a, *b, *c, *d, *id;
3462 a = isl_id_alloc(ctx, "a", NULL);
3463 b = isl_id_alloc(ctx, "b", NULL);
3464 c = isl_id_alloc(ctx, "c", NULL);
3465 d = isl_id_alloc(ctx, "d", NULL);
3467 list = isl_id_list_alloc(ctx, 4);
3468 list = isl_id_list_add(list, a);
3469 list = isl_id_list_add(list, b);
3470 list = isl_id_list_add(list, c);
3471 list = isl_id_list_add(list, d);
3472 list = isl_id_list_drop(list, 1, 1);
3474 if (isl_id_list_n_id(list) != 3) {
3475 isl_id_list_free(list);
3476 isl_die(ctx, isl_error_unknown,
3477 "unexpected number of elements in list", return -1);
3480 id = isl_id_list_get_id(list, 0);
3483 id = isl_id_list_get_id(list, 1);
3486 id = isl_id_list_get_id(list, 2);
3490 isl_id_list_free(list);
3493 isl_die(ctx, isl_error_unknown,
3494 "unexpected elements in list", return -1);
3499 const char *set_conversion_tests[] = {
3500 "[N] -> { [i] : N - 1 <= 2 i <= N }",
3501 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
3502 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3503 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3506 /* Check that converting from isl_set to isl_pw_multi_aff and back
3507 * to isl_set produces the original isl_set.
3509 static int test_set_conversion(isl_ctx *ctx)
3513 isl_set *set1, *set2;
3514 isl_pw_multi_aff *pma;
3517 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
3518 str = set_conversion_tests[i];
3519 set1 = isl_set_read_from_str(ctx, str);
3520 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
3521 set2 = isl_set_from_pw_multi_aff(pma);
3522 equal = isl_set_is_equal(set1, set2);
3529 isl_die(ctx, isl_error_unknown, "bad conversion",
3536 /* Check that converting from isl_map to isl_pw_multi_aff and back
3537 * to isl_map produces the original isl_map.
3539 static int test_map_conversion(isl_ctx *ctx)
3542 isl_map *map1, *map2;
3543 isl_pw_multi_aff *pma;
3546 str = "{ [a, b, c, d] -> s0[a, b, e, f] : "
3547 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
3548 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
3549 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
3551 map1 = isl_map_read_from_str(ctx, str);
3552 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
3553 map2 = isl_map_from_pw_multi_aff(pma);
3554 equal = isl_map_is_equal(map1, map2);
3561 isl_die(ctx, isl_error_unknown, "bad conversion", return -1);
3566 static int test_conversion(isl_ctx *ctx)
3568 if (test_set_conversion(ctx) < 0)
3570 if (test_map_conversion(ctx) < 0)
3575 /* Check that isl_basic_map_curry does not modify input.
3577 static int test_curry(isl_ctx *ctx)
3580 isl_basic_map *bmap1, *bmap2;
3583 str = "{ [A[] -> B[]] -> C[] }";
3584 bmap1 = isl_basic_map_read_from_str(ctx, str);
3585 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
3586 equal = isl_basic_map_is_equal(bmap1, bmap2);
3587 isl_basic_map_free(bmap1);
3588 isl_basic_map_free(bmap2);
3593 isl_die(ctx, isl_error_unknown,
3594 "curried map should not be equal to original",
3604 } preimage_tests[] = {
3605 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
3606 "{ A[j,i] -> B[i,j] }",
3607 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
3608 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
3609 "{ A[a,b] -> B[a/2,b/6] }",
3610 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
3611 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
3612 "{ A[a,b] -> B[a/2,b/6] }",
3613 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
3614 "exists i,j : a = 2 i and b = 6 j }" },
3615 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
3616 "[n] -> { : 0 <= n <= 100 }" },
3617 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
3618 "{ A[a] -> B[2a] }",
3619 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
3620 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
3621 "{ A[a] -> B[([a/2])] }",
3622 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
3623 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
3624 "{ A[a] -> B[a,a,a/3] }",
3625 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
3626 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
3627 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
3630 static int test_preimage_basic_set(isl_ctx *ctx)
3633 isl_basic_set *bset1, *bset2;
3637 for (i = 0; i < ARRAY_SIZE(preimage_tests); ++i) {
3638 bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set);
3639 ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma);
3640 bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res);
3641 bset1 = isl_basic_set_preimage_multi_aff(bset1, ma);
3642 equal = isl_basic_set_is_equal(bset1, bset2);
3643 isl_basic_set_free(bset1);
3644 isl_basic_set_free(bset2);
3648 isl_die(ctx, isl_error_unknown, "bad preimage",
3659 } preimage_domain_tests[] = {
3660 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
3661 "{ A[j,i] -> B[i,j] }",
3662 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
3663 { "{ B[i] -> C[i]; D[i] -> E[i] }",
3664 "{ A[i] -> B[i + 1] }",
3665 "{ A[i] -> C[i + 1] }" },
3666 { "{ B[i] -> C[i]; B[i] -> E[i] }",
3667 "{ A[i] -> B[i + 1] }",
3668 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
3669 { "{ B[i] -> C[([i/2])] }",
3670 "{ A[i] -> B[2i] }",
3671 "{ A[i] -> C[i] }" },
3672 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
3673 "{ A[i] -> B[([i/5]), ([i/7])] }",
3674 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
3675 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
3676 "[N] -> { A[] -> B[([N/5])] }",
3677 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
3678 { "{ B[i] -> C[i] : exists a : i = 5 a }",
3679 "{ A[i] -> B[2i] }",
3680 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
3681 { "{ B[i] -> C[i] : exists a : i = 2 a; "
3682 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
3683 "{ A[i] -> B[2i] }",
3684 "{ A[i] -> C[2i] }" },
3687 static int test_preimage_union_map(isl_ctx *ctx)
3690 isl_union_map *umap1, *umap2;
3694 for (i = 0; i < ARRAY_SIZE(preimage_domain_tests); ++i) {
3695 umap1 = isl_union_map_read_from_str(ctx,
3696 preimage_domain_tests[i].map);
3697 ma = isl_multi_aff_read_from_str(ctx,
3698 preimage_domain_tests[i].ma);
3699 umap2 = isl_union_map_read_from_str(ctx,
3700 preimage_domain_tests[i].res);
3701 umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma);
3702 equal = isl_union_map_is_equal(umap1, umap2);
3703 isl_union_map_free(umap1);
3704 isl_union_map_free(umap2);
3708 isl_die(ctx, isl_error_unknown, "bad preimage",
3715 static int test_preimage(isl_ctx *ctx)
3717 if (test_preimage_basic_set(ctx) < 0)
3719 if (test_preimage_union_map(ctx) < 0)
3729 } pullback_tests[] = {
3730 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
3731 "{ A[a,b] -> C[b + 2a] }" },
3732 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
3733 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
3734 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
3735 "{ A[a] -> C[(a)/6] }" },
3736 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
3737 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
3738 "{ A[a] -> C[(2a)/3] }" },
3739 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
3740 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
3741 "{ A[i,j] -> C[i + j, i + j] }"},
3742 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
3743 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
3744 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
3747 static int test_pullback(isl_ctx *ctx)
3750 isl_multi_aff *ma1, *ma2;
3754 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
3755 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
3756 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
3757 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
3758 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
3759 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
3760 isl_multi_aff_free(ma1);
3761 isl_multi_aff_free(ma2);
3765 isl_die(ctx, isl_error_unknown, "bad pullback",
3772 /* Check that negation is printed correctly.
3774 static int test_ast(isl_ctx *ctx)
3776 isl_ast_expr *expr, *expr1, *expr2, *expr3;
3780 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
3781 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
3782 expr = isl_ast_expr_add(expr1, expr2);
3783 expr = isl_ast_expr_neg(expr);
3784 str = isl_ast_expr_to_str(expr);
3785 ok = str ? !strcmp(str, "-(A + B)") : -1;
3787 isl_ast_expr_free(expr);
3792 isl_die(ctx, isl_error_unknown,
3793 "isl_ast_expr printed incorrectly", return -1);
3795 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
3796 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
3797 expr = isl_ast_expr_add(expr1, expr2);
3798 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
3799 expr = isl_ast_expr_sub(expr3, expr);
3800 str = isl_ast_expr_to_str(expr);
3801 ok = str ? !strcmp(str, "C - (A + B)") : -1;
3803 isl_ast_expr_free(expr);
3808 isl_die(ctx, isl_error_unknown,
3809 "isl_ast_expr printed incorrectly", return -1);
3814 /* Internal data structure for before_for and after_for callbacks.
3816 * depth is the current depth
3817 * before is the number of times before_for has been called
3818 * after is the number of times after_for has been called
3820 struct isl_test_codegen_data {
3826 /* This function is called before each for loop in the AST generated
3827 * from test_ast_gen1.
3829 * Increment the number of calls and the depth.
3830 * Check that the space returned by isl_ast_build_get_schedule_space
3831 * matches the target space of the schedule returned by
3832 * isl_ast_build_get_schedule.
3833 * Return an isl_id that is checked by the corresponding call
3836 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
3839 struct isl_test_codegen_data *data = user;
3842 isl_union_map *schedule;
3843 isl_union_set *uset;
3848 ctx = isl_ast_build_get_ctx(build);
3850 if (data->before >= 3)
3851 isl_die(ctx, isl_error_unknown,
3852 "unexpected number of for nodes", return NULL);
3853 if (data->depth >= 2)
3854 isl_die(ctx, isl_error_unknown,
3855 "unexpected depth", return NULL);
3857 snprintf(name, sizeof(name), "d%d", data->depth);
3861 schedule = isl_ast_build_get_schedule(build);
3862 uset = isl_union_map_range(schedule);
3865 if (isl_union_set_n_set(uset) != 1) {
3866 isl_union_set_free(uset);
3867 isl_die(ctx, isl_error_unknown,
3868 "expecting single range space", return NULL);
3871 space = isl_ast_build_get_schedule_space(build);
3872 set = isl_union_set_extract_set(uset, space);
3873 isl_union_set_free(uset);
3874 empty = isl_set_is_empty(set);
3880 isl_die(ctx, isl_error_unknown,
3881 "spaces don't match", return NULL);
3883 return isl_id_alloc(ctx, name, NULL);
3886 /* This function is called after each for loop in the AST generated
3887 * from test_ast_gen1.
3889 * Increment the number of calls and decrement the depth.
3890 * Check that the annotation attached to the node matches
3891 * the isl_id returned by the corresponding call to before_for.
3893 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
3894 __isl_keep isl_ast_build *build, void *user)
3896 struct isl_test_codegen_data *data = user;
3904 if (data->after > data->before)
3905 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
3906 "mismatch in number of for nodes",
3907 return isl_ast_node_free(node));
3909 id = isl_ast_node_get_annotation(node);
3911 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
3912 "missing annotation", return isl_ast_node_free(node));
3914 name = isl_id_get_name(id);
3915 valid = name && atoi(name + 1) == data->depth;
3919 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
3920 "wrong annotation", return isl_ast_node_free(node));
3925 /* Check that the before_each_for and after_each_for callbacks
3926 * are called for each for loop in the generated code,
3927 * that they are called in the right order and that the isl_id
3928 * returned from the before_each_for callback is attached to
3929 * the isl_ast_node passed to the corresponding after_each_for call.
3931 static int test_ast_gen1(isl_ctx *ctx)
3935 isl_union_map *schedule;
3936 isl_ast_build *build;
3938 struct isl_test_codegen_data data;
3940 str = "[N] -> { : N >= 10 }";
3941 set = isl_set_read_from_str(ctx, str);
3942 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
3943 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
3944 schedule = isl_union_map_read_from_str(ctx, str);
3949 build = isl_ast_build_from_context(set);
3950 build = isl_ast_build_set_before_each_for(build,
3951 &before_for, &data);
3952 build = isl_ast_build_set_after_each_for(build,
3954 tree = isl_ast_build_ast_from_schedule(build, schedule);
3955 isl_ast_build_free(build);
3959 isl_ast_node_free(tree);
3961 if (data.before != 3 || data.after != 3)
3962 isl_die(ctx, isl_error_unknown,
3963 "unexpected number of for nodes", return -1);
3968 /* Check that the AST generator handles domains that are integrally disjoint
3969 * but not ratinoally disjoint.
3971 static int test_ast_gen2(isl_ctx *ctx)
3975 isl_union_map *schedule;
3976 isl_union_map *options;
3977 isl_ast_build *build;
3980 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
3981 schedule = isl_union_map_read_from_str(ctx, str);
3982 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
3983 build = isl_ast_build_from_context(set);
3985 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
3986 options = isl_union_map_read_from_str(ctx, str);
3987 build = isl_ast_build_set_options(build, options);
3988 tree = isl_ast_build_ast_from_schedule(build, schedule);
3989 isl_ast_build_free(build);
3992 isl_ast_node_free(tree);
3997 /* Increment *user on each call.
3999 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
4000 __isl_keep isl_ast_build *build, void *user)
4009 /* Test that unrolling tries to minimize the number of instances.
4010 * In particular, for the schedule given below, make sure it generates
4011 * 3 nodes (rather than 101).
4013 static int test_ast_gen3(isl_ctx *ctx)
4017 isl_union_map *schedule;
4018 isl_union_map *options;
4019 isl_ast_build *build;
4023 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4024 schedule = isl_union_map_read_from_str(ctx, str);
4025 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4027 str = "{ [i] -> unroll[0] }";
4028 options = isl_union_map_read_from_str(ctx, str);
4030 build = isl_ast_build_from_context(set);
4031 build = isl_ast_build_set_options(build, options);
4032 build = isl_ast_build_set_at_each_domain(build,
4033 &count_domains, &n_domain);
4034 tree = isl_ast_build_ast_from_schedule(build, schedule);
4035 isl_ast_build_free(build);
4039 isl_ast_node_free(tree);
4042 isl_die(ctx, isl_error_unknown,
4043 "unexpected number of for nodes", return -1);
4048 /* Check that if the ast_build_exploit_nested_bounds options is set,
4049 * we do not get an outer if node in the generated AST,
4050 * while we do get such an outer if node if the options is not set.
4052 static int test_ast_gen4(isl_ctx *ctx)
4056 isl_union_map *schedule;
4057 isl_ast_build *build;
4059 enum isl_ast_node_type type;
4062 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
4063 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4065 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
4067 schedule = isl_union_map_read_from_str(ctx, str);
4068 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4069 build = isl_ast_build_from_context(set);
4070 tree = isl_ast_build_ast_from_schedule(build, schedule);
4071 isl_ast_build_free(build);
4075 type = isl_ast_node_get_type(tree);
4076 isl_ast_node_free(tree);
4078 if (type == isl_ast_node_if)
4079 isl_die(ctx, isl_error_unknown,
4080 "not expecting if node", return -1);
4082 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
4084 schedule = isl_union_map_read_from_str(ctx, str);
4085 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4086 build = isl_ast_build_from_context(set);
4087 tree = isl_ast_build_ast_from_schedule(build, schedule);
4088 isl_ast_build_free(build);
4092 type = isl_ast_node_get_type(tree);
4093 isl_ast_node_free(tree);
4095 if (type != isl_ast_node_if)
4096 isl_die(ctx, isl_error_unknown,
4097 "expecting if node", return -1);
4099 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
4104 /* This function is called for each leaf in the AST generated
4105 * from test_ast_gen5.
4107 * We finalize the AST generation by extending the outer schedule
4108 * with a zero-dimensional schedule. If this results in any for loops,
4109 * then this means that we did not pass along enough information
4110 * about the outer schedule to the inner AST generation.
4112 static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
4115 isl_union_map *schedule, *extra;
4118 schedule = isl_ast_build_get_schedule(build);
4119 extra = isl_union_map_copy(schedule);
4120 extra = isl_union_map_from_domain(isl_union_map_domain(extra));
4121 schedule = isl_union_map_range_product(schedule, extra);
4122 tree = isl_ast_build_ast_from_schedule(build, schedule);
4123 isl_ast_build_free(build);
4128 if (isl_ast_node_get_type(tree) == isl_ast_node_for)
4129 isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
4130 "code should not contain any for loop",
4131 return isl_ast_node_free(tree));
4136 /* Check that we do not lose any information when going back and
4137 * forth between internal and external schedule.
4139 * In particular, we create an AST where we unroll the only
4140 * non-constant dimension in the schedule. We therefore do
4141 * not expect any for loops in the AST. However, older versions
4142 * of isl would not pass along enough information about the outer
4143 * schedule when performing an inner code generation from a create_leaf
4144 * callback, resulting in the inner code generation producing a for loop.
4146 static int test_ast_gen5(isl_ctx *ctx)
4150 isl_union_map *schedule, *options;
4151 isl_ast_build *build;
4154 str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4155 schedule = isl_union_map_read_from_str(ctx, str);
4157 str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4158 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4159 options = isl_union_map_read_from_str(ctx, str);
4161 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4162 build = isl_ast_build_from_context(set);
4163 build = isl_ast_build_set_options(build, options);
4164 build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
4165 tree = isl_ast_build_ast_from_schedule(build, schedule);
4166 isl_ast_build_free(build);
4167 isl_ast_node_free(tree);
4174 static int test_ast_gen(isl_ctx *ctx)
4176 if (test_ast_gen1(ctx) < 0)
4178 if (test_ast_gen2(ctx) < 0)
4180 if (test_ast_gen3(ctx) < 0)
4182 if (test_ast_gen4(ctx) < 0)
4184 if (test_ast_gen5(ctx) < 0)
4189 /* Check if dropping output dimensions from an isl_pw_multi_aff
4192 static int test_pw_multi_aff(isl_ctx *ctx)
4195 isl_pw_multi_aff *pma1, *pma2;
4198 str = "{ [i,j] -> [i+j, 4i-j] }";
4199 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
4200 str = "{ [i,j] -> [4i-j] }";
4201 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
4203 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
4205 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
4207 isl_pw_multi_aff_free(pma1);
4208 isl_pw_multi_aff_free(pma2);
4212 isl_die(ctx, isl_error_unknown,
4213 "expressions not equal", return -1);
4218 /* This is a regression test for a bug where isl_basic_map_simplify
4219 * would end up in an infinite loop. In particular, we construct
4220 * an empty basic set that is not obviously empty.
4221 * isl_basic_set_is_empty marks the basic set as empty.
4222 * After projecting out i3, the variable can be dropped completely,
4223 * but isl_basic_map_simplify refrains from doing so if the basic set
4224 * is empty and would end up in an infinite loop if it didn't test
4225 * explicitly for empty basic maps in the outer loop.
4227 static int test_simplify(isl_ctx *ctx)
4230 isl_basic_set *bset;
4233 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4234 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4235 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4237 bset = isl_basic_set_read_from_str(ctx, str);
4238 empty = isl_basic_set_is_empty(bset);
4239 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
4240 isl_basic_set_free(bset);
4244 isl_die(ctx, isl_error_unknown,
4245 "basic set should be empty", return -1);
4250 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4251 * with gbr context would fail to disable the use of the shifted tableau
4252 * when transferring equalities for the input to the context, resulting
4253 * in invalid sample values.
4255 static int test_partial_lexmin(isl_ctx *ctx)
4258 isl_basic_set *bset;
4259 isl_basic_map *bmap;
4262 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4263 bmap = isl_basic_map_read_from_str(ctx, str);
4264 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4265 bset = isl_basic_set_read_from_str(ctx, str);
4266 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
4275 /* Check that the variable compression performed on the existentially
4276 * quantified variables inside isl_basic_set_compute_divs is not confused
4277 * by the implicit equalities among the parameters.
4279 static int test_compute_divs(isl_ctx *ctx)
4282 isl_basic_set *bset;
4285 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4286 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4287 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4288 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4289 bset = isl_basic_set_read_from_str(ctx, str);
4290 set = isl_basic_set_compute_divs(bset);
4300 int (*fn)(isl_ctx *ctx);
4302 { "val", &test_val },
4303 { "compute divs", &test_compute_divs },
4304 { "partial lexmin", &test_partial_lexmin },
4305 { "simplify", &test_simplify },
4306 { "curry", &test_curry },
4307 { "piecewise multi affine expressions", &test_pw_multi_aff },
4308 { "conversion", &test_conversion },
4309 { "list", &test_list },
4310 { "align parameters", &test_align_parameters },
4311 { "preimage", &test_preimage },
4312 { "pullback", &test_pullback },
4313 { "AST", &test_ast },
4314 { "AST generation", &test_ast_gen },
4315 { "eliminate", &test_eliminate },
4316 { "residue class", &test_residue_class },
4317 { "div", &test_div },
4318 { "slice", &test_slice },
4319 { "fixed power", &test_fixed_power },
4320 { "sample", &test_sample },
4321 { "output", &test_output },
4322 { "vertices", &test_vertices },
4323 { "fixed", &test_fixed },
4324 { "equal", &test_equal },
4325 { "product", &test_product },
4326 { "dim_max", &test_dim_max },
4327 { "affine", &test_aff },
4328 { "injective", &test_injective },
4329 { "schedule", &test_schedule },
4330 { "union_pw", &test_union_pw },
4331 { "parse", &test_parse },
4332 { "single-valued", &test_sv },
4333 { "affine hull", &test_affine_hull },
4334 { "coalesce", &test_coalesce },
4335 { "factorize", &test_factorize },
4336 { "subset", &test_subset },
4337 { "subtract", &test_subtract },
4338 { "lexmin", &test_lexmin },
4339 { "piecewise quasi-polynomials", &test_pwqp },
4345 struct isl_ctx *ctx;
4347 srcdir = getenv("srcdir");
4350 ctx = isl_ctx_alloc();
4351 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
4352 printf("%s\n", tests[i].name);
4353 if (tests[i].fn(ctx) < 0)
4359 test_split_periods(ctx);
4361 test_bijective(ctx);
4365 test_construction(ctx);
4367 test_application(ctx);
4368 test_convex_hull(ctx);