2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
27 #include <isl_constraint_private.h>
28 #include <isl/polynomial.h>
29 #include <isl/union_set.h>
30 #include <isl/union_map.h>
31 #include <isl_factorization.h>
32 #include <isl/schedule.h>
33 #include <isl/schedule_node.h>
34 #include <isl_options_private.h>
35 #include <isl_vertices_private.h>
36 #include <isl/ast_build.h>
39 #include <isl_ast_build_expr.h>
40 #include <isl/options.h>
42 #include "isl_srcdir.c"
44 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
46 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
49 char *pattern
= "%s/test_inputs/%s.%s";
51 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
53 filename
= isl_alloc_array(ctx
, char, length
);
58 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
63 void test_parse_map(isl_ctx
*ctx
, const char *str
)
67 map
= isl_map_read_from_str(ctx
, str
);
72 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
77 map
= isl_map_read_from_str(ctx
, str
);
78 map2
= isl_map_read_from_str(ctx
, str2
);
79 equal
= isl_map_is_equal(map
, map2
);
86 isl_die(ctx
, isl_error_unknown
, "maps not equal",
92 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
94 isl_pw_qpolynomial
*pwqp
;
96 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
98 isl_pw_qpolynomial_free(pwqp
);
101 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
105 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
107 isl_pw_aff_free(pwaff
);
110 /* Check that we can read an isl_multi_val from "str" without errors.
112 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
116 mv
= isl_multi_val_read_from_str(ctx
, str
);
117 isl_multi_val_free(mv
);
122 /* Pairs of binary relation representations that should represent
123 * the same binary relations.
128 } parse_map_equal_tests
[] = {
129 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
130 "{ [x, y] : 2y >= 6 - x }" },
131 { "{ [x,y] : x <= min(y, 2*y+3) }",
132 "{ [x,y] : x <= y, 2*y + 3 }" },
133 { "{ [x,y] : x >= min(y, 2*y+3) }",
134 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
135 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
136 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
137 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
138 "{ [i,j] -> [min(i,j)] }" },
139 { "{ [i,j] : i != j }",
140 "{ [i,j] : i < j or i > j }" },
141 { "{ [i,j] : (i+1)*2 >= j }",
142 "{ [i, j] : j <= 2 + 2i }" },
143 { "{ [i] -> [i > 0 ? 4 : 5] }",
144 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
145 { "[N=2,M] -> { [i=[(M+N)/4]] }",
146 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
147 { "{ [x] : x >= 0 }",
148 "{ [x] : x-0 >= 0 }" },
149 { "{ [i] : ((i > 10)) }",
150 "{ [i] : i >= 11 }" },
152 "{ [i] -> [0 * i] }" },
153 { "{ [a] -> [b] : (not false) }",
154 "{ [a] -> [b] : true }" },
155 { "{ [i] : i/2 <= 5 }",
156 "{ [i] : i <= 10 }" },
157 { "{Sym=[n] [i] : i <= n }",
158 "[n] -> { [i] : i <= n }" },
161 { "{ [i] : 2*floor(i/2) = i }",
162 "{ [i] : exists a : i = 2 a }" },
163 { "{ [a] -> [b] : a = 5 implies b = 5 }",
164 "{ [a] -> [b] : a != 5 or b = 5 }" },
165 { "{ [a] -> [a - 1 : a > 0] }",
166 "{ [a] -> [a - 1] : a > 0 }" },
167 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
168 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
169 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
170 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
171 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
172 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
173 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
174 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
175 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
176 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
177 { "{ [a,b] -> [i,j] : a,b << i,j }",
178 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
179 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
180 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
181 { "{ [a,b] -> [i,j] : a,b >> i,j }",
182 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
183 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
184 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
185 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
186 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
187 "8c < n - 32a and i < n and c >= 0 and "
188 "c <= 3 and c >= -4a) }",
189 "{ [n] -> [i] : 0 <= i < n }" },
190 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
191 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
192 "{ [x] -> [] : 0 <= x <= 15 }" },
195 int test_parse(struct isl_ctx
*ctx
)
199 const char *str
, *str2
;
201 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
203 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
205 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
208 str
= "{ [i] -> [-i] }";
209 map
= isl_map_read_from_str(ctx
, str
);
213 str
= "{ A[i] -> L[([i/3])] }";
214 map
= isl_map_read_from_str(ctx
, str
);
218 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
219 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
220 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
222 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
223 str
= parse_map_equal_tests
[i
].map1
;
224 str2
= parse_map_equal_tests
[i
].map2
;
225 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
229 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
230 map
= isl_map_read_from_str(ctx
, str
);
231 str
= "{ [new, old] -> [o0, o1] : "
232 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
233 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
234 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
235 map2
= isl_map_read_from_str(ctx
, str
);
236 assert(isl_map_is_equal(map
, map2
));
240 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
241 map
= isl_map_read_from_str(ctx
, str
);
242 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
243 map2
= isl_map_read_from_str(ctx
, str
);
244 assert(isl_map_is_equal(map
, map2
));
248 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
249 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
250 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
251 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
252 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
257 static int test_read(isl_ctx
*ctx
)
261 isl_basic_set
*bset1
, *bset2
;
262 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
265 filename
= get_filename(ctx
, "set", "omega");
267 input
= fopen(filename
, "r");
270 bset1
= isl_basic_set_read_from_file(ctx
, input
);
271 bset2
= isl_basic_set_read_from_str(ctx
, str
);
273 equal
= isl_basic_set_is_equal(bset1
, bset2
);
275 isl_basic_set_free(bset1
);
276 isl_basic_set_free(bset2
);
284 isl_die(ctx
, isl_error_unknown
,
285 "read sets not equal", return -1);
290 static int test_bounded(isl_ctx
*ctx
)
295 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
296 bounded
= isl_set_is_bounded(set
);
302 isl_die(ctx
, isl_error_unknown
,
303 "set not considered bounded", return -1);
305 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
306 bounded
= isl_set_is_bounded(set
);
313 isl_die(ctx
, isl_error_unknown
,
314 "set considered bounded", return -1);
316 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
317 bounded
= isl_set_is_bounded(set
);
323 isl_die(ctx
, isl_error_unknown
,
324 "set considered bounded", return -1);
329 /* Construct the basic set { [i] : 5 <= i <= N } */
330 static int test_construction(isl_ctx
*ctx
)
340 dim
= isl_space_set_alloc(ctx
, 1, 1);
341 bset
= isl_basic_set_universe(isl_space_copy(dim
));
342 ls
= isl_local_space_from_space(dim
);
344 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
345 isl_int_set_si(v
, -1);
346 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
347 isl_int_set_si(v
, 1);
348 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
349 bset
= isl_basic_set_add_constraint(bset
, c
);
351 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
352 isl_int_set_si(v
, 1);
353 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
354 isl_int_set_si(v
, -5);
355 isl_constraint_set_constant(c
, v
);
356 bset
= isl_basic_set_add_constraint(bset
, c
);
358 isl_local_space_free(ls
);
359 isl_basic_set_free(bset
);
366 static int test_dim(isl_ctx
*ctx
)
369 isl_map
*map1
, *map2
;
372 map1
= isl_map_read_from_str(ctx
,
373 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
374 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
375 map2
= isl_map_read_from_str(ctx
,
376 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
377 equal
= isl_map_is_equal(map1
, map2
);
380 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
381 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
382 if (equal
>= 0 && equal
)
383 equal
= isl_map_is_equal(map1
, map2
);
391 isl_die(ctx
, isl_error_unknown
,
392 "unexpected result", return -1);
394 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
395 map1
= isl_map_read_from_str(ctx
, str
);
396 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
397 map2
= isl_map_read_from_str(ctx
, str
);
398 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
399 equal
= isl_map_is_equal(map1
, map2
);
406 isl_die(ctx
, isl_error_unknown
,
407 "unexpected result", return -1);
413 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
417 { &isl_val_neg
, "0", "0" },
418 { &isl_val_abs
, "0", "0" },
419 { &isl_val_2exp
, "0", "1" },
420 { &isl_val_floor
, "0", "0" },
421 { &isl_val_ceil
, "0", "0" },
422 { &isl_val_neg
, "1", "-1" },
423 { &isl_val_neg
, "-1", "1" },
424 { &isl_val_neg
, "1/2", "-1/2" },
425 { &isl_val_neg
, "-1/2", "1/2" },
426 { &isl_val_neg
, "infty", "-infty" },
427 { &isl_val_neg
, "-infty", "infty" },
428 { &isl_val_neg
, "NaN", "NaN" },
429 { &isl_val_abs
, "1", "1" },
430 { &isl_val_abs
, "-1", "1" },
431 { &isl_val_abs
, "1/2", "1/2" },
432 { &isl_val_abs
, "-1/2", "1/2" },
433 { &isl_val_abs
, "infty", "infty" },
434 { &isl_val_abs
, "-infty", "infty" },
435 { &isl_val_abs
, "NaN", "NaN" },
436 { &isl_val_floor
, "1", "1" },
437 { &isl_val_floor
, "-1", "-1" },
438 { &isl_val_floor
, "1/2", "0" },
439 { &isl_val_floor
, "-1/2", "-1" },
440 { &isl_val_floor
, "infty", "infty" },
441 { &isl_val_floor
, "-infty", "-infty" },
442 { &isl_val_floor
, "NaN", "NaN" },
443 { &isl_val_ceil
, "1", "1" },
444 { &isl_val_ceil
, "-1", "-1" },
445 { &isl_val_ceil
, "1/2", "1" },
446 { &isl_val_ceil
, "-1/2", "0" },
447 { &isl_val_ceil
, "infty", "infty" },
448 { &isl_val_ceil
, "-infty", "-infty" },
449 { &isl_val_ceil
, "NaN", "NaN" },
450 { &isl_val_2exp
, "-3", "1/8" },
451 { &isl_val_2exp
, "-1", "1/2" },
452 { &isl_val_2exp
, "1", "2" },
453 { &isl_val_2exp
, "2", "4" },
454 { &isl_val_2exp
, "3", "8" },
455 { &isl_val_inv
, "1", "1" },
456 { &isl_val_inv
, "2", "1/2" },
457 { &isl_val_inv
, "1/2", "2" },
458 { &isl_val_inv
, "-2", "-1/2" },
459 { &isl_val_inv
, "-1/2", "-2" },
460 { &isl_val_inv
, "0", "NaN" },
461 { &isl_val_inv
, "NaN", "NaN" },
462 { &isl_val_inv
, "infty", "0" },
463 { &isl_val_inv
, "-infty", "0" },
466 /* Perform some basic tests of unary operations on isl_val objects.
468 static int test_un_val(isl_ctx
*ctx
)
472 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
475 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
476 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
477 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
478 fn
= val_un_tests
[i
].op
;
480 if (isl_val_is_nan(res
))
481 ok
= isl_val_is_nan(v
);
483 ok
= isl_val_eq(v
, res
);
489 isl_die(ctx
, isl_error_unknown
,
490 "unexpected result", return -1);
497 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
498 __isl_take isl_val
*v2
);
500 ['+'] = { &isl_val_add
},
501 ['-'] = { &isl_val_sub
},
502 ['*'] = { &isl_val_mul
},
503 ['/'] = { &isl_val_div
},
504 ['g'] = { &isl_val_gcd
},
505 ['m'] = { &isl_val_min
},
506 ['M'] = { &isl_val_max
},
514 } val_bin_tests
[] = {
515 { "0", '+', "0", "0" },
516 { "1", '+', "0", "1" },
517 { "1", '+', "1", "2" },
518 { "1", '-', "1", "0" },
519 { "1", '*', "1", "1" },
520 { "1", '/', "1", "1" },
521 { "2", '*', "3", "6" },
522 { "2", '*', "1/2", "1" },
523 { "2", '*', "1/3", "2/3" },
524 { "2/3", '*', "3/5", "2/5" },
525 { "2/3", '*', "7/5", "14/15" },
526 { "2", '/', "1/2", "4" },
527 { "-2", '/', "-1/2", "4" },
528 { "-2", '/', "1/2", "-4" },
529 { "2", '/', "-1/2", "-4" },
530 { "2", '/', "2", "1" },
531 { "2", '/', "3", "2/3" },
532 { "2/3", '/', "5/3", "2/5" },
533 { "2/3", '/', "5/7", "14/15" },
534 { "0", '/', "0", "NaN" },
535 { "42", '/', "0", "NaN" },
536 { "-42", '/', "0", "NaN" },
537 { "infty", '/', "0", "NaN" },
538 { "-infty", '/', "0", "NaN" },
539 { "NaN", '/', "0", "NaN" },
540 { "0", '/', "NaN", "NaN" },
541 { "42", '/', "NaN", "NaN" },
542 { "-42", '/', "NaN", "NaN" },
543 { "infty", '/', "NaN", "NaN" },
544 { "-infty", '/', "NaN", "NaN" },
545 { "NaN", '/', "NaN", "NaN" },
546 { "0", '/', "infty", "0" },
547 { "42", '/', "infty", "0" },
548 { "-42", '/', "infty", "0" },
549 { "infty", '/', "infty", "NaN" },
550 { "-infty", '/', "infty", "NaN" },
551 { "NaN", '/', "infty", "NaN" },
552 { "0", '/', "-infty", "0" },
553 { "42", '/', "-infty", "0" },
554 { "-42", '/', "-infty", "0" },
555 { "infty", '/', "-infty", "NaN" },
556 { "-infty", '/', "-infty", "NaN" },
557 { "NaN", '/', "-infty", "NaN" },
558 { "1", '-', "1/3", "2/3" },
559 { "1/3", '+', "1/2", "5/6" },
560 { "1/2", '+', "1/2", "1" },
561 { "3/4", '-', "1/4", "1/2" },
562 { "1/2", '-', "1/3", "1/6" },
563 { "infty", '+', "42", "infty" },
564 { "infty", '+', "infty", "infty" },
565 { "42", '+', "infty", "infty" },
566 { "infty", '-', "infty", "NaN" },
567 { "infty", '*', "infty", "infty" },
568 { "infty", '*', "-infty", "-infty" },
569 { "-infty", '*', "infty", "-infty" },
570 { "-infty", '*', "-infty", "infty" },
571 { "0", '*', "infty", "NaN" },
572 { "1", '*', "infty", "infty" },
573 { "infty", '*', "0", "NaN" },
574 { "infty", '*', "42", "infty" },
575 { "42", '-', "infty", "-infty" },
576 { "infty", '+', "-infty", "NaN" },
577 { "4", 'g', "6", "2" },
578 { "5", 'g', "6", "1" },
579 { "42", 'm', "3", "3" },
580 { "42", 'M', "3", "42" },
581 { "3", 'm', "42", "3" },
582 { "3", 'M', "42", "42" },
583 { "42", 'm', "infty", "42" },
584 { "42", 'M', "infty", "infty" },
585 { "42", 'm', "-infty", "-infty" },
586 { "42", 'M', "-infty", "42" },
587 { "42", 'm', "NaN", "NaN" },
588 { "42", 'M', "NaN", "NaN" },
589 { "infty", 'm', "-infty", "-infty" },
590 { "infty", 'M', "-infty", "infty" },
593 /* Perform some basic tests of binary operations on isl_val objects.
595 static int test_bin_val(isl_ctx
*ctx
)
598 isl_val
*v1
, *v2
, *res
;
599 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
600 __isl_take isl_val
*v2
);
603 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
604 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
605 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
606 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
607 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
609 if (isl_val_is_nan(res
))
610 ok
= isl_val_is_nan(v1
);
612 ok
= isl_val_eq(v1
, res
);
618 isl_die(ctx
, isl_error_unknown
,
619 "unexpected result", return -1);
625 /* Perform some basic tests on isl_val objects.
627 static int test_val(isl_ctx
*ctx
)
629 if (test_un_val(ctx
) < 0)
631 if (test_bin_val(ctx
) < 0)
636 /* Sets described using existentially quantified variables that
637 * can also be described without.
639 static const char *elimination_tests
[] = {
640 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
641 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
642 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
645 /* Check that redundant existentially quantified variables are
648 static int test_elimination(isl_ctx
*ctx
)
654 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
655 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
656 n
= isl_basic_set_dim(bset
, isl_dim_div
);
657 isl_basic_set_free(bset
);
661 isl_die(ctx
, isl_error_unknown
,
662 "expecting no existentials", return -1);
668 static int test_div(isl_ctx
*ctx
)
676 struct isl_basic_set
*bset
;
677 struct isl_constraint
*c
;
682 dim
= isl_space_set_alloc(ctx
, 0, 3);
683 bset
= isl_basic_set_universe(isl_space_copy(dim
));
684 ls
= isl_local_space_from_space(dim
);
686 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
687 isl_int_set_si(v
, -1);
688 isl_constraint_set_constant(c
, v
);
689 isl_int_set_si(v
, 1);
690 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
691 isl_int_set_si(v
, 3);
692 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
693 bset
= isl_basic_set_add_constraint(bset
, c
);
695 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
696 isl_int_set_si(v
, 1);
697 isl_constraint_set_constant(c
, v
);
698 isl_int_set_si(v
, -1);
699 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
700 isl_int_set_si(v
, 3);
701 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
702 bset
= isl_basic_set_add_constraint(bset
, c
);
704 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
706 assert(bset
&& bset
->n_div
== 1);
707 isl_local_space_free(ls
);
708 isl_basic_set_free(bset
);
711 dim
= isl_space_set_alloc(ctx
, 0, 3);
712 bset
= isl_basic_set_universe(isl_space_copy(dim
));
713 ls
= isl_local_space_from_space(dim
);
715 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
716 isl_int_set_si(v
, 1);
717 isl_constraint_set_constant(c
, v
);
718 isl_int_set_si(v
, -1);
719 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
720 isl_int_set_si(v
, 3);
721 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
722 bset
= isl_basic_set_add_constraint(bset
, c
);
724 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
725 isl_int_set_si(v
, -1);
726 isl_constraint_set_constant(c
, v
);
727 isl_int_set_si(v
, 1);
728 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
729 isl_int_set_si(v
, 3);
730 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
731 bset
= isl_basic_set_add_constraint(bset
, c
);
733 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
735 assert(bset
&& bset
->n_div
== 1);
736 isl_local_space_free(ls
);
737 isl_basic_set_free(bset
);
740 dim
= isl_space_set_alloc(ctx
, 0, 3);
741 bset
= isl_basic_set_universe(isl_space_copy(dim
));
742 ls
= isl_local_space_from_space(dim
);
744 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
745 isl_int_set_si(v
, 1);
746 isl_constraint_set_constant(c
, v
);
747 isl_int_set_si(v
, -1);
748 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
749 isl_int_set_si(v
, 3);
750 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
751 bset
= isl_basic_set_add_constraint(bset
, c
);
753 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
754 isl_int_set_si(v
, -3);
755 isl_constraint_set_constant(c
, v
);
756 isl_int_set_si(v
, 1);
757 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
758 isl_int_set_si(v
, 4);
759 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
760 bset
= isl_basic_set_add_constraint(bset
, c
);
762 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
764 assert(bset
&& bset
->n_div
== 1);
765 isl_local_space_free(ls
);
766 isl_basic_set_free(bset
);
769 dim
= isl_space_set_alloc(ctx
, 0, 3);
770 bset
= isl_basic_set_universe(isl_space_copy(dim
));
771 ls
= isl_local_space_from_space(dim
);
773 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
774 isl_int_set_si(v
, 2);
775 isl_constraint_set_constant(c
, v
);
776 isl_int_set_si(v
, -1);
777 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
778 isl_int_set_si(v
, 3);
779 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
780 bset
= isl_basic_set_add_constraint(bset
, c
);
782 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
783 isl_int_set_si(v
, -1);
784 isl_constraint_set_constant(c
, v
);
785 isl_int_set_si(v
, 1);
786 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
787 isl_int_set_si(v
, 6);
788 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
789 bset
= isl_basic_set_add_constraint(bset
, c
);
791 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
793 assert(isl_basic_set_is_empty(bset
));
794 isl_local_space_free(ls
);
795 isl_basic_set_free(bset
);
798 dim
= isl_space_set_alloc(ctx
, 0, 3);
799 bset
= isl_basic_set_universe(isl_space_copy(dim
));
800 ls
= isl_local_space_from_space(dim
);
802 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
803 isl_int_set_si(v
, -1);
804 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
805 isl_int_set_si(v
, 3);
806 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
807 bset
= isl_basic_set_add_constraint(bset
, c
);
809 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
810 isl_int_set_si(v
, 1);
811 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
812 isl_int_set_si(v
, -3);
813 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
814 bset
= isl_basic_set_add_constraint(bset
, c
);
816 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
818 assert(bset
&& bset
->n_div
== 0);
819 isl_basic_set_free(bset
);
820 isl_local_space_free(ls
);
823 dim
= isl_space_set_alloc(ctx
, 0, 3);
824 bset
= isl_basic_set_universe(isl_space_copy(dim
));
825 ls
= isl_local_space_from_space(dim
);
827 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
828 isl_int_set_si(v
, -1);
829 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
830 isl_int_set_si(v
, 6);
831 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
832 bset
= isl_basic_set_add_constraint(bset
, c
);
834 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
835 isl_int_set_si(v
, 1);
836 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
837 isl_int_set_si(v
, -3);
838 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
839 bset
= isl_basic_set_add_constraint(bset
, c
);
841 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
843 assert(bset
&& bset
->n_div
== 1);
844 isl_basic_set_free(bset
);
845 isl_local_space_free(ls
);
848 /* This test is a bit tricky. We set up an equality
850 * Normalization of divs creates _two_ divs
853 * Afterwards e0 is removed again because it has coefficient -1
854 * and we end up with the original equality and div again.
855 * Perhaps we can avoid the introduction of this temporary div.
857 dim
= isl_space_set_alloc(ctx
, 0, 4);
858 bset
= isl_basic_set_universe(isl_space_copy(dim
));
859 ls
= isl_local_space_from_space(dim
);
861 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
862 isl_int_set_si(v
, -1);
863 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
864 isl_int_set_si(v
, -3);
865 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
866 isl_int_set_si(v
, -3);
867 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
868 isl_int_set_si(v
, 6);
869 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
870 bset
= isl_basic_set_add_constraint(bset
, c
);
872 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
874 /* Test disabled for now */
876 assert(bset && bset->n_div == 1);
878 isl_local_space_free(ls
);
879 isl_basic_set_free(bset
);
882 dim
= isl_space_set_alloc(ctx
, 0, 5);
883 bset
= isl_basic_set_universe(isl_space_copy(dim
));
884 ls
= isl_local_space_from_space(dim
);
886 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
887 isl_int_set_si(v
, -1);
888 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
889 isl_int_set_si(v
, -3);
890 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
891 isl_int_set_si(v
, -3);
892 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
893 isl_int_set_si(v
, 6);
894 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
895 bset
= isl_basic_set_add_constraint(bset
, c
);
897 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
898 isl_int_set_si(v
, -1);
899 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
900 isl_int_set_si(v
, 1);
901 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
902 isl_int_set_si(v
, 1);
903 isl_constraint_set_constant(c
, v
);
904 bset
= isl_basic_set_add_constraint(bset
, c
);
906 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
908 /* Test disabled for now */
910 assert(bset && bset->n_div == 1);
912 isl_local_space_free(ls
);
913 isl_basic_set_free(bset
);
916 dim
= isl_space_set_alloc(ctx
, 0, 4);
917 bset
= isl_basic_set_universe(isl_space_copy(dim
));
918 ls
= isl_local_space_from_space(dim
);
920 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
921 isl_int_set_si(v
, 1);
922 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
923 isl_int_set_si(v
, -1);
924 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
925 isl_int_set_si(v
, -2);
926 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
927 bset
= isl_basic_set_add_constraint(bset
, c
);
929 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
930 isl_int_set_si(v
, -1);
931 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
932 isl_int_set_si(v
, 3);
933 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
934 isl_int_set_si(v
, 2);
935 isl_constraint_set_constant(c
, v
);
936 bset
= isl_basic_set_add_constraint(bset
, c
);
938 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
940 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
942 assert(!isl_basic_set_is_empty(bset
));
944 isl_local_space_free(ls
);
945 isl_basic_set_free(bset
);
948 dim
= isl_space_set_alloc(ctx
, 0, 3);
949 bset
= isl_basic_set_universe(isl_space_copy(dim
));
950 ls
= isl_local_space_from_space(dim
);
952 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
953 isl_int_set_si(v
, 1);
954 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
955 isl_int_set_si(v
, -2);
956 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
957 bset
= isl_basic_set_add_constraint(bset
, c
);
959 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
961 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
963 isl_local_space_free(ls
);
964 isl_basic_set_free(bset
);
968 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
969 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
970 set
= isl_set_read_from_str(ctx
, str
);
971 set
= isl_set_compute_divs(set
);
976 if (test_elimination(ctx
) < 0)
979 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
980 set
= isl_set_read_from_str(ctx
, str
);
981 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
982 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
983 empty
= isl_set_is_empty(set
);
988 isl_die(ctx
, isl_error_unknown
,
989 "result not as accurate as expected", return -1);
994 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
998 struct isl_basic_set
*bset1
, *bset2
;
999 struct isl_basic_map
*bmap
;
1001 filename
= get_filename(ctx
, name
, "omega");
1003 input
= fopen(filename
, "r");
1006 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1007 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1009 bset1
= isl_basic_set_apply(bset1
, bmap
);
1011 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1013 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1015 isl_basic_set_free(bset1
);
1016 isl_basic_set_free(bset2
);
1022 static int test_application(isl_ctx
*ctx
)
1024 test_application_case(ctx
, "application");
1025 test_application_case(ctx
, "application2");
1030 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1034 struct isl_basic_set
*bset1
, *bset2
;
1036 filename
= get_filename(ctx
, name
, "polylib");
1038 input
= fopen(filename
, "r");
1041 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1042 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1044 bset1
= isl_basic_set_affine_hull(bset1
);
1046 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1048 isl_basic_set_free(bset1
);
1049 isl_basic_set_free(bset2
);
1055 int test_affine_hull(struct isl_ctx
*ctx
)
1059 isl_basic_set
*bset
, *bset2
;
1063 test_affine_hull_case(ctx
, "affine2");
1064 test_affine_hull_case(ctx
, "affine");
1065 test_affine_hull_case(ctx
, "affine3");
1067 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1068 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1069 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1070 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1071 set
= isl_set_read_from_str(ctx
, str
);
1072 bset
= isl_set_affine_hull(set
);
1073 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1074 isl_basic_set_free(bset
);
1076 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1079 /* Check that isl_map_affine_hull is not confused by
1080 * the reordering of divs in isl_map_align_divs.
1082 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1083 "32e0 = b and 32e1 = c); "
1084 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1085 set
= isl_set_read_from_str(ctx
, str
);
1086 bset
= isl_set_affine_hull(set
);
1087 isl_basic_set_free(bset
);
1091 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1092 "32e2 = 31 + 31e0 }";
1093 set
= isl_set_read_from_str(ctx
, str
);
1094 bset
= isl_set_affine_hull(set
);
1095 str
= "{ [a] : exists e : a = 32 e }";
1096 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1097 subset
= isl_basic_set_is_subset(bset
, bset2
);
1098 isl_basic_set_free(bset
);
1099 isl_basic_set_free(bset2
);
1103 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1109 /* Pairs of maps and the corresponding expected results of
1110 * isl_map_plain_unshifted_simple_hull.
1115 } plain_unshifted_simple_hull_tests
[] = {
1116 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1117 "{ [i] -> [j] : i >= 1 }" },
1118 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1119 "(j mod 4 = 2 and k mod 6 = n) }",
1120 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1123 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1125 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1129 isl_basic_map
*hull
, *expected
;
1132 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1134 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1135 map
= isl_map_read_from_str(ctx
, str
);
1136 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1137 expected
= isl_basic_map_read_from_str(ctx
, str
);
1138 hull
= isl_map_plain_unshifted_simple_hull(map
);
1139 equal
= isl_basic_map_is_equal(hull
, expected
);
1140 isl_basic_map_free(hull
);
1141 isl_basic_map_free(expected
);
1145 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1152 /* Pairs of sets and the corresponding expected results of
1153 * isl_set_unshifted_simple_hull.
1158 } unshifted_simple_hull_tests
[] = {
1159 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1160 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1163 /* Basic tests for isl_set_unshifted_simple_hull.
1165 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1169 isl_basic_set
*hull
, *expected
;
1172 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1174 str
= unshifted_simple_hull_tests
[i
].set
;
1175 set
= isl_set_read_from_str(ctx
, str
);
1176 str
= unshifted_simple_hull_tests
[i
].hull
;
1177 expected
= isl_basic_set_read_from_str(ctx
, str
);
1178 hull
= isl_set_unshifted_simple_hull(set
);
1179 equal
= isl_basic_set_is_equal(hull
, expected
);
1180 isl_basic_set_free(hull
);
1181 isl_basic_set_free(expected
);
1185 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1192 static int test_simple_hull(struct isl_ctx
*ctx
)
1196 isl_basic_set
*bset
;
1199 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1200 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1201 set
= isl_set_read_from_str(ctx
, str
);
1202 bset
= isl_set_simple_hull(set
);
1203 is_empty
= isl_basic_set_is_empty(bset
);
1204 isl_basic_set_free(bset
);
1206 if (is_empty
== isl_bool_error
)
1209 if (is_empty
== isl_bool_false
)
1210 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1213 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1215 if (test_unshifted_simple_hull(ctx
) < 0)
1221 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1225 struct isl_basic_set
*bset1
, *bset2
;
1226 struct isl_set
*set
;
1228 filename
= get_filename(ctx
, name
, "polylib");
1230 input
= fopen(filename
, "r");
1233 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1234 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1236 set
= isl_basic_set_union(bset1
, bset2
);
1237 bset1
= isl_set_convex_hull(set
);
1239 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1241 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1243 isl_basic_set_free(bset1
);
1244 isl_basic_set_free(bset2
);
1253 } convex_hull_tests
[] = {
1254 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1255 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1256 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1257 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1258 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1259 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1260 "i2 <= 5 and i2 >= 4; "
1261 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1262 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1263 "i2 <= 5 + i0 and i2 >= i0 }" },
1264 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1265 "{ [x, y] : 1 = 0 }" },
1266 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1267 "[x, y, 0] : x >= 0 and y < 0 }",
1268 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1271 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1274 int orig_convex
= ctx
->opt
->convex
;
1275 ctx
->opt
->convex
= convex
;
1277 test_convex_hull_case(ctx
, "convex0");
1278 test_convex_hull_case(ctx
, "convex1");
1279 test_convex_hull_case(ctx
, "convex2");
1280 test_convex_hull_case(ctx
, "convex3");
1281 test_convex_hull_case(ctx
, "convex4");
1282 test_convex_hull_case(ctx
, "convex5");
1283 test_convex_hull_case(ctx
, "convex6");
1284 test_convex_hull_case(ctx
, "convex7");
1285 test_convex_hull_case(ctx
, "convex8");
1286 test_convex_hull_case(ctx
, "convex9");
1287 test_convex_hull_case(ctx
, "convex10");
1288 test_convex_hull_case(ctx
, "convex11");
1289 test_convex_hull_case(ctx
, "convex12");
1290 test_convex_hull_case(ctx
, "convex13");
1291 test_convex_hull_case(ctx
, "convex14");
1292 test_convex_hull_case(ctx
, "convex15");
1294 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1295 isl_set
*set1
, *set2
;
1298 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1299 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1300 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1301 equal
= isl_set_is_equal(set1
, set2
);
1308 isl_die(ctx
, isl_error_unknown
,
1309 "unexpected convex hull", return -1);
1312 ctx
->opt
->convex
= orig_convex
;
1317 static int test_convex_hull(isl_ctx
*ctx
)
1319 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1321 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1326 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1330 struct isl_basic_set
*bset1
, *bset2
;
1332 filename
= get_filename(ctx
, name
, "polylib");
1334 input
= fopen(filename
, "r");
1337 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1338 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1340 bset1
= isl_basic_set_gist(bset1
, bset2
);
1342 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1344 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1346 isl_basic_set_free(bset1
);
1347 isl_basic_set_free(bset2
);
1353 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1357 const char *context
;
1359 } plain_gist_tests
[] = {
1360 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1361 "{ [i] -> [j] : i >= 1 }",
1362 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1363 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1364 "(j mod 4 = 2 and k mod 6 = n) }",
1365 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1366 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1367 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1368 "{ [i] -> [j] : i > j }",
1369 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1372 /* Basic tests for isl_map_plain_gist_basic_map.
1374 static int test_plain_gist(isl_ctx
*ctx
)
1378 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1381 isl_map
*map
, *gist
;
1382 isl_basic_map
*context
;
1384 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1385 str
= plain_gist_tests
[i
].context
;
1386 context
= isl_basic_map_read_from_str(ctx
, str
);
1387 map
= isl_map_plain_gist_basic_map(map
, context
);
1388 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1389 equal
= isl_map_is_equal(map
, gist
);
1395 isl_die(ctx
, isl_error_unknown
,
1396 "incorrect gist result", return -1);
1404 const char *context
;
1407 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1408 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1409 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1410 "{ [a, b, c] : a <= 15 }" },
1411 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1412 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1413 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1414 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1415 { "{ [m, n, a, b] : a <= 2147 + n }",
1416 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1417 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1418 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1420 "{ [m, n, ku, kl] }" },
1421 { "{ [a, a, b] : a >= 10 }",
1422 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1423 "{ [a, a, b] : a >= 10 }" },
1424 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1425 "{ [0, j] : j >= 0 }" },
1426 /* Check that no constraints on i6 are introduced in the gist */
1427 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1428 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1429 "5e0 <= 381 - t1 and i4 <= 1) }",
1430 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1431 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1432 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1433 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1434 "20e0 >= 1511 - 4t1 - 5i4) }" },
1435 /* Check that no constraints on i6 are introduced in the gist */
1436 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1437 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1438 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1439 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1440 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1441 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1442 "20e1 <= 1530 - 4t1 - 5i4 and "
1443 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1444 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1445 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1446 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1447 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1448 "10e0 <= -91 + 5i4 + 4i6 and "
1449 "10e0 >= -105 + 5i4 + 4i6) }",
1450 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1451 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1452 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1453 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1454 "{ [a, b, q, p] : b >= 1 + a }",
1455 "{ [a, b, q, p] : false }" },
1456 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1457 "[n] -> { [x] : x mod 32 = 0 }",
1458 "[n] -> { [x = n] }" },
1459 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1460 "{ [x] : x mod 2 = 0 }" },
1461 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1462 "{ [x] : x mod 128 = 0 }" },
1463 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1464 "{ [x] : x mod 3200 = 0 }" },
1465 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1466 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1467 "{ [a, b, c = a] }" },
1468 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1469 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1470 "{ [a, b, c = a] : a mod 3 = 0 }" },
1471 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1472 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1474 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1475 "{ [x,y] : 1 <= y <= 3 }",
1479 /* Check that isl_set_gist behaves as expected.
1481 * For the test cases in gist_tests, besides checking that the result
1482 * is as expected, also check that applying the gist operation does
1483 * not modify the input set (an earlier version of isl would do that) and
1484 * that the test case is consistent, i.e., that the gist has the same
1485 * intersection with the context as the input set.
1487 static int test_gist(struct isl_ctx
*ctx
)
1491 isl_basic_set
*bset1
, *bset2
;
1492 isl_map
*map1
, *map2
;
1495 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1496 int equal_input
, equal_intersection
;
1497 isl_set
*set1
, *set2
, *copy
, *context
;
1499 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1500 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1501 copy
= isl_set_copy(set1
);
1502 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1503 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1504 equal
= isl_set_is_equal(set1
, set2
);
1506 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1507 equal_input
= isl_set_is_equal(set1
, copy
);
1509 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1510 set2
= isl_set_intersect(set2
, context
);
1511 equal_intersection
= isl_set_is_equal(set1
, set2
);
1514 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1517 isl_die(ctx
, isl_error_unknown
,
1518 "incorrect gist result", return -1);
1520 isl_die(ctx
, isl_error_unknown
,
1521 "gist modified input", return -1);
1523 isl_die(ctx
, isl_error_unknown
,
1524 "inconsistent gist test case", return -1);
1527 test_gist_case(ctx
, "gist1");
1529 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1530 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1531 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1532 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1533 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1534 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1535 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1536 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1537 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1538 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1539 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1540 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1541 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1542 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1543 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1544 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1545 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1546 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1547 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1548 bset1
= isl_basic_set_gist(bset1
, bset2
);
1549 assert(bset1
&& bset1
->n_div
== 0);
1550 isl_basic_set_free(bset1
);
1552 /* Check that the integer divisions of the second disjunct
1553 * do not spread to the first disjunct.
1555 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1556 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1557 "(exists (e0 = [(-1 + t1)/16], "
1558 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1559 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1560 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1561 "o0 <= 4294967295 and t1 <= -1)) }";
1562 map1
= isl_map_read_from_str(ctx
, str
);
1563 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1564 map2
= isl_map_read_from_str(ctx
, str
);
1565 map1
= isl_map_gist(map1
, map2
);
1569 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1570 isl_map_free(map1
); return -1);
1571 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1572 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1573 isl_map_free(map1
); return -1);
1576 if (test_plain_gist(ctx
) < 0)
1582 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1584 isl_set
*set
, *set2
;
1588 set
= isl_set_read_from_str(ctx
, str
);
1589 set
= isl_set_coalesce(set
);
1590 set2
= isl_set_read_from_str(ctx
, str
);
1591 equal
= isl_set_is_equal(set
, set2
);
1592 one
= set
&& set
->n
== 1;
1599 isl_die(ctx
, isl_error_unknown
,
1600 "coalesced set not equal to input", return -1);
1601 if (check_one
&& !one
)
1602 isl_die(ctx
, isl_error_unknown
,
1603 "coalesced set should not be a union", return -1);
1608 /* Inputs for coalescing tests with unbounded wrapping.
1609 * "str" is a string representation of the input set.
1610 * "single_disjunct" is set if we expect the result to consist of
1611 * a single disjunct.
1614 int single_disjunct
;
1616 } coalesce_unbounded_tests
[] = {
1617 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1618 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1619 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1620 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1622 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1623 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1624 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1625 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1628 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1629 * option turned off.
1631 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1637 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1638 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1640 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1641 const char *str
= coalesce_unbounded_tests
[i
].str
;
1642 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1643 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1649 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1654 /* Inputs for coalescing tests.
1655 * "str" is a string representation of the input set.
1656 * "single_disjunct" is set if we expect the result to consist of
1657 * a single disjunct.
1660 int single_disjunct
;
1662 } coalesce_tests
[] = {
1663 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1664 "y >= x & x >= 2 & 5 >= y }" },
1665 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1666 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1667 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1668 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1669 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1670 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1671 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1672 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1673 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1674 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1675 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1676 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1677 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1678 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1679 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1680 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1681 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1682 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1683 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1684 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1685 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1686 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1687 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1688 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1689 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1690 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1691 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1692 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1693 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1694 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1695 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1696 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1697 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1698 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1699 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1700 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1701 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1702 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1703 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1704 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1705 "[o0, o1, o2, o3, o4, o5, o6]] : "
1706 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1707 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1708 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1709 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1710 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1711 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1712 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1713 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1714 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1715 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1716 "o6 >= i3 + i6 - o3 and M >= 0 and "
1717 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1718 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1719 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1720 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1721 "(o0 = 0 and M >= 2 and N >= 3) or "
1722 "(M = 0 and o0 = 0 and N >= 3) }" },
1723 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1724 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1725 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1726 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1727 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1728 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1729 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1730 "(y = 3 and x = 1) }" },
1731 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1732 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1733 "i1 <= M and i3 <= M and i4 <= M) or "
1734 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1735 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1736 "i4 <= -1 + M) }" },
1737 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1738 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1739 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1740 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1741 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1742 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1743 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1744 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1745 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1746 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1747 { 0, "{ [a, b] : exists e : 2e = a and "
1748 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1749 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1750 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1751 "j >= 1 and j' <= i + j - i' and i >= 1; "
1753 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1754 "[i,j] : exists a : j = 3a }" },
1755 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1756 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1758 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1759 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1760 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1761 "c <= 6 + 8a and a >= 3; "
1762 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1763 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1764 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1765 "[x,0] : 3 <= x <= 4 }" },
1766 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1767 "[x,0] : 4 <= x <= 5 }" },
1768 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1769 "[x,0] : 3 <= x <= 5 }" },
1770 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1771 "[x,0] : 3 <= x <= 4 }" },
1772 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1774 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1775 { 1, "{ [0,0]; [1,1] }" },
1776 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1777 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1779 "[k, 0, k] : k <= 6 and k >= 1 }" },
1780 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1781 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1782 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1783 { 1, "[n] -> { [1] : n >= 0;"
1784 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1785 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1786 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1787 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1788 "2e0 <= x and 2e0 <= n);"
1789 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1791 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1792 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1793 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1795 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1796 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1798 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1799 "t1 >= 13 and t1 <= 16);"
1800 "[t1] : t1 <= 15 and t1 >= 12 }" },
1801 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1802 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1803 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1804 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1805 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1806 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1808 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1809 "(exists (e0 : 3e0 = -2 + c0)) }" },
1810 { 0, "[n, b0, t0] -> "
1811 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1812 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1813 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1814 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1815 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
1816 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
1817 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
1818 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
1819 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1820 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1821 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1822 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
1823 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
1824 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
1825 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
1826 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
1827 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
1828 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
1829 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
1830 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
1831 { 0, "{ [i0, i1, i2] : "
1832 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
1833 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
1834 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
1835 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
1836 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
1837 "32e0 <= 31 + i0)) or "
1839 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
1840 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
1841 "2*floor((c)/2) = c and 0 <= a <= 192;"
1842 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
1844 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
1845 "(0 <= a <= b <= n) }" },
1846 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
1847 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
1848 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
1849 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
1850 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1851 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
1852 "b = 3 and 9e0 <= -19 + 2c)) }" },
1853 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
1854 "(b = -1 + a and 0 < a <= 3 and "
1855 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1856 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
1857 "b = 3 and 9e0 <= -19 + 2c)) }" },
1858 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
1860 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
1862 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
1863 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
1864 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
1865 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
1866 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
1867 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
1868 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
1869 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
1870 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
1871 { 1, "{ [a] : a <= 8 and "
1872 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
1873 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
1874 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
1875 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
1876 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
1877 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
1878 "(a < 0 and 3*floor((a)/3) < a) }" },
1879 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
1880 "(a < -1 and 3*floor((a)/3) < a) }" },
1881 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
1882 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
1883 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
1884 "or (2 <= a <= 15 and b < a)) }" },
1885 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
1886 "32*floor((a)/32) < a) or a <= 15) }" },
1887 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
1888 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
1889 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
1890 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
1891 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
1892 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
1893 "S_0[n] : n <= m <= 2 + n }" },
1896 /* A specialized coalescing test case that would result
1897 * in a segmentation fault or a failed assertion in earlier versions of isl.
1899 static int test_coalesce_special(struct isl_ctx
*ctx
)
1902 isl_map
*map1
, *map2
;
1904 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1905 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
1906 "(y = 201 and o1 <= 239 and o1 >= 212) or "
1907 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
1908 "o1 <= 239 and o1 >= 212)) or "
1909 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
1910 "o1 <= 241 and o1 >= 240));"
1911 "[S_L220_OUT[] -> T7[]] -> "
1912 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
1913 "(y = 2 and o1 <= 241 and o1 >= 212) or "
1914 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
1915 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
1916 map1
= isl_map_read_from_str(ctx
, str
);
1917 map1
= isl_map_align_divs(map1
);
1918 map1
= isl_map_coalesce(map1
);
1919 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1920 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
1921 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
1922 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
1923 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
1924 map2
= isl_map_read_from_str(ctx
, str
);
1925 map2
= isl_map_union(map2
, map1
);
1926 map2
= isl_map_align_divs(map2
);
1927 map2
= isl_map_coalesce(map2
);
1935 /* A specialized coalescing test case that would result in an assertion
1936 * in an earlier version of isl.
1937 * The explicit call to isl_basic_set_union prevents the implicit
1938 * equality constraints in the first basic map from being detected prior
1939 * to the call to isl_set_coalesce, at least at the point
1940 * where this test case was introduced.
1942 static int test_coalesce_special2(struct isl_ctx
*ctx
)
1945 isl_basic_set
*bset1
, *bset2
;
1948 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
1949 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1950 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
1951 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1952 set
= isl_basic_set_union(bset1
, bset2
);
1953 set
= isl_set_coalesce(set
);
1961 /* Test the functionality of isl_set_coalesce.
1962 * That is, check that the output is always equal to the input
1963 * and in some cases that the result consists of a single disjunct.
1965 static int test_coalesce(struct isl_ctx
*ctx
)
1969 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1970 const char *str
= coalesce_tests
[i
].str
;
1971 int check_one
= coalesce_tests
[i
].single_disjunct
;
1972 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1976 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1978 if (test_coalesce_special(ctx
) < 0)
1980 if (test_coalesce_special2(ctx
) < 0)
1986 /* Construct a representation of the graph on the right of Figure 1
1987 * in "Computing the Transitive Closure of a Union of
1988 * Affine Integer Tuple Relations".
1990 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
1993 isl_map
*up
, *right
;
1995 dom
= isl_set_read_from_str(ctx
,
1996 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1997 "2 x - 3 y + 3 >= 0 }");
1998 right
= isl_map_read_from_str(ctx
,
1999 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2000 up
= isl_map_read_from_str(ctx
,
2001 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2002 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2003 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2004 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2005 up
= isl_map_intersect_range(up
, dom
);
2006 return isl_map_union(up
, right
);
2009 /* Construct a representation of the power of the graph
2010 * on the right of Figure 1 in "Computing the Transitive Closure of
2011 * a Union of Affine Integer Tuple Relations".
2013 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2015 return isl_map_read_from_str(ctx
,
2016 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2017 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2018 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2021 /* Construct a representation of the transitive closure of the graph
2022 * on the right of Figure 1 in "Computing the Transitive Closure of
2023 * a Union of Affine Integer Tuple Relations".
2025 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2027 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2030 static int test_closure(isl_ctx
*ctx
)
2033 isl_map
*map
, *map2
;
2036 /* COCOA example 1 */
2037 map
= isl_map_read_from_str(ctx
,
2038 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2039 "1 <= i and i < n and 1 <= j and j < n or "
2040 "i2 = i + 1 and j2 = j - 1 and "
2041 "1 <= i and i < n and 2 <= j and j <= n }");
2042 map
= isl_map_power(map
, &exact
);
2046 /* COCOA example 1 */
2047 map
= isl_map_read_from_str(ctx
,
2048 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2049 "1 <= i and i < n and 1 <= j and j < n or "
2050 "i2 = i + 1 and j2 = j - 1 and "
2051 "1 <= i and i < n and 2 <= j and j <= n }");
2052 map
= isl_map_transitive_closure(map
, &exact
);
2054 map2
= isl_map_read_from_str(ctx
,
2055 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2056 "1 <= i and i < n and 1 <= j and j <= n and "
2057 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2058 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2059 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2060 assert(isl_map_is_equal(map
, map2
));
2064 map
= isl_map_read_from_str(ctx
,
2065 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2066 " 0 <= y and y <= n }");
2067 map
= isl_map_transitive_closure(map
, &exact
);
2068 map2
= isl_map_read_from_str(ctx
,
2069 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2070 " 0 <= y and y <= n }");
2071 assert(isl_map_is_equal(map
, map2
));
2075 /* COCOA example 2 */
2076 map
= isl_map_read_from_str(ctx
,
2077 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2078 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2079 "i2 = i + 2 and j2 = j - 2 and "
2080 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2081 map
= isl_map_transitive_closure(map
, &exact
);
2083 map2
= isl_map_read_from_str(ctx
,
2084 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2085 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2086 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2087 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2088 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2089 assert(isl_map_is_equal(map
, map2
));
2093 /* COCOA Fig.2 left */
2094 map
= isl_map_read_from_str(ctx
,
2095 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2096 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2098 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2099 "j <= 2 i - 3 and j <= n - 2 or "
2100 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2101 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2102 map
= isl_map_transitive_closure(map
, &exact
);
2106 /* COCOA Fig.2 right */
2107 map
= isl_map_read_from_str(ctx
,
2108 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2109 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2111 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2112 "j <= 2 i - 4 and j <= n - 3 or "
2113 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2114 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2115 map
= isl_map_power(map
, &exact
);
2119 /* COCOA Fig.2 right */
2120 map
= isl_map_read_from_str(ctx
,
2121 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2122 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2124 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2125 "j <= 2 i - 4 and j <= n - 3 or "
2126 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2127 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2128 map
= isl_map_transitive_closure(map
, &exact
);
2130 map2
= isl_map_read_from_str(ctx
,
2131 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2132 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2133 "j <= n and 3 + i + 2 j <= 3 n and "
2134 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2135 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2136 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2137 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2138 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2139 assert(isl_map_is_equal(map
, map2
));
2143 map
= cocoa_fig_1_right_graph(ctx
);
2144 map
= isl_map_transitive_closure(map
, &exact
);
2146 map2
= cocoa_fig_1_right_tc(ctx
);
2147 assert(isl_map_is_equal(map
, map2
));
2151 map
= cocoa_fig_1_right_graph(ctx
);
2152 map
= isl_map_power(map
, &exact
);
2153 map2
= cocoa_fig_1_right_power(ctx
);
2154 equal
= isl_map_is_equal(map
, map2
);
2160 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2162 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2164 /* COCOA Theorem 1 counter example */
2165 map
= isl_map_read_from_str(ctx
,
2166 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2167 "i2 = 1 and j2 = j or "
2168 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2169 map
= isl_map_transitive_closure(map
, &exact
);
2173 map
= isl_map_read_from_str(ctx
,
2174 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2175 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2176 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2177 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2178 map
= isl_map_transitive_closure(map
, &exact
);
2182 /* Kelly et al 1996, fig 12 */
2183 map
= isl_map_read_from_str(ctx
,
2184 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2185 "1 <= i,j,j+1 <= n or "
2186 "j = n and j2 = 1 and i2 = i + 1 and "
2187 "1 <= i,i+1 <= n }");
2188 map
= isl_map_transitive_closure(map
, &exact
);
2190 map2
= isl_map_read_from_str(ctx
,
2191 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2192 "1 <= i <= n and i = i2 or "
2193 "1 <= i < i2 <= n and 1 <= j <= n and "
2195 assert(isl_map_is_equal(map
, map2
));
2199 /* Omega's closure4 */
2200 map
= isl_map_read_from_str(ctx
,
2201 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2202 "1 <= x,y <= 10 or "
2203 "x2 = x + 1 and y2 = y and "
2204 "1 <= x <= 20 && 5 <= y <= 15 }");
2205 map
= isl_map_transitive_closure(map
, &exact
);
2209 map
= isl_map_read_from_str(ctx
,
2210 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2211 map
= isl_map_transitive_closure(map
, &exact
);
2213 map2
= isl_map_read_from_str(ctx
,
2214 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2215 assert(isl_map_is_equal(map
, map2
));
2219 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2220 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2221 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2222 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2223 map
= isl_map_read_from_str(ctx
, str
);
2224 map
= isl_map_transitive_closure(map
, &exact
);
2226 map2
= isl_map_read_from_str(ctx
, str
);
2227 assert(isl_map_is_equal(map
, map2
));
2231 str
= "{[0] -> [1]; [2] -> [3]}";
2232 map
= isl_map_read_from_str(ctx
, str
);
2233 map
= isl_map_transitive_closure(map
, &exact
);
2235 map2
= isl_map_read_from_str(ctx
, str
);
2236 assert(isl_map_is_equal(map
, map2
));
2240 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2241 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2242 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2243 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2244 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2245 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2246 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2247 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2248 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2249 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2250 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2251 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2252 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2253 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2254 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2255 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2256 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2257 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2258 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2259 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2260 map
= isl_map_read_from_str(ctx
, str
);
2261 map
= isl_map_transitive_closure(map
, NULL
);
2268 static int test_lex(struct isl_ctx
*ctx
)
2274 dim
= isl_space_set_alloc(ctx
, 0, 0);
2275 map
= isl_map_lex_le(dim
);
2276 empty
= isl_map_is_empty(map
);
2282 isl_die(ctx
, isl_error_unknown
,
2283 "expecting non-empty result", return -1);
2288 /* Inputs for isl_map_lexmin tests.
2289 * "map" is the input and "lexmin" is the expected result.
2294 } lexmin_tests
[] = {
2295 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2296 "{ [x] -> [5] : 6 <= x <= 8; "
2297 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2298 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2299 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2300 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2301 "{ [x] -> [y] : (4y = x and x >= 0) or "
2302 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2303 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2304 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2305 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2306 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2307 /* Check that empty pieces are properly combined. */
2308 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2309 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2310 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2311 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2312 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2314 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2315 "a <= 255 and c <= 255 and d <= 255 - j and "
2316 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2317 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2318 "247d <= 247 + i and 248 - b <= 248d <= c and "
2319 "254d >= i - a + b and 254d >= -a + b and "
2320 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2322 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2323 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2324 "247j >= 62738 - i and 509j <= 129795 + i and "
2325 "742j >= 188724 - i; "
2326 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2327 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2328 "16*floor((8 + b)/16) <= 7 + b; "
2330 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2331 "[a] -> [b = 0] : 0 < a <= 509 }" },
2332 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2333 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2336 static int test_lexmin(struct isl_ctx
*ctx
)
2341 isl_basic_map
*bmap
;
2342 isl_map
*map
, *map2
;
2345 isl_pw_multi_aff
*pma
;
2347 str
= "[p0, p1] -> { [] -> [] : "
2348 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2349 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2350 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2351 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2352 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2353 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2354 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2355 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2356 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2357 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2358 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2359 map
= isl_map_read_from_str(ctx
, str
);
2360 map
= isl_map_lexmin(map
);
2363 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2364 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2365 set
= isl_set_read_from_str(ctx
, str
);
2366 set
= isl_set_lexmax(set
);
2367 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2368 set2
= isl_set_read_from_str(ctx
, str
);
2369 set
= isl_set_intersect(set
, set2
);
2370 assert(!isl_set_is_empty(set
));
2373 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2374 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2375 map
= isl_map_lexmin(map
);
2376 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2377 equal
= isl_map_is_equal(map
, map2
);
2384 isl_die(ctx
, isl_error_unknown
,
2385 "unexpected result", return -1);
2388 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2389 " 8i' <= i and 8i' >= -7 + i }";
2390 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2391 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2392 map2
= isl_map_from_pw_multi_aff(pma
);
2393 map
= isl_map_from_basic_map(bmap
);
2394 assert(isl_map_is_equal(map
, map2
));
2398 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2399 " 8i' <= i and 8i' >= -7 + i }";
2400 set
= isl_set_read_from_str(ctx
, str
);
2401 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2402 set2
= isl_set_from_pw_multi_aff(pma
);
2403 equal
= isl_set_is_equal(set
, set2
);
2409 isl_die(ctx
, isl_error_unknown
,
2410 "unexpected difference between set and "
2411 "piecewise affine expression", return -1);
2416 /* A specialized isl_set_min_val test case that would return the wrong result
2417 * in earlier versions of isl.
2418 * The explicit call to isl_basic_set_union prevents the second basic set
2419 * from being determined to be empty prior to the call to isl_set_min_val,
2420 * at least at the point where this test case was introduced.
2422 static int test_min_special(isl_ctx
*ctx
)
2425 isl_basic_set
*bset1
, *bset2
;
2431 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2432 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2433 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2434 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2435 set
= isl_basic_set_union(bset1
, bset2
);
2436 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2438 res
= isl_set_min_val(set
, obj
);
2439 ok
= isl_val_cmp_si(res
, 5) == 0;
2448 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2454 /* A specialized isl_set_min_val test case that would return an error
2455 * in earlier versions of isl.
2457 static int test_min_special2(isl_ctx
*ctx
)
2460 isl_basic_set
*bset
;
2464 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2465 bset
= isl_basic_set_read_from_str(ctx
, str
);
2467 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2469 res
= isl_basic_set_max_val(bset
, obj
);
2471 isl_basic_set_free(bset
);
2484 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2485 __isl_keep isl_aff
*obj
);
2488 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2489 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2490 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2491 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2492 &isl_set_max_val
, "30" },
2496 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2497 * In particular, check the results on non-convex inputs.
2499 static int test_min(struct isl_ctx
*ctx
)
2507 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2508 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2509 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2510 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2511 val
= opt_tests
[i
].fn(set
, obj
);
2512 ok
= isl_val_eq(res
, val
);
2521 isl_die(ctx
, isl_error_unknown
,
2522 "unexpected optimum", return -1);
2525 if (test_min_special(ctx
) < 0)
2527 if (test_min_special2(ctx
) < 0)
2538 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2539 void *dep_user
, void *user
)
2541 struct must_may
*mm
= (struct must_may
*)user
;
2544 mm
->must
= isl_map_union(mm
->must
, dep
);
2546 mm
->may
= isl_map_union(mm
->may
, dep
);
2551 static int common_space(void *first
, void *second
)
2553 int depth
= *(int *)first
;
2557 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2565 map2
= isl_map_read_from_str(map
->ctx
, str
);
2566 equal
= isl_map_is_equal(map
, map2
);
2572 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2576 equal
= map_is_equal(map
, str
);
2580 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2581 "result not as expected", return -1);
2585 static int test_dep(struct isl_ctx
*ctx
)
2590 isl_access_info
*ai
;
2597 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2598 map
= isl_map_read_from_str(ctx
, str
);
2599 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2601 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2602 map
= isl_map_read_from_str(ctx
, str
);
2603 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2605 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2606 map
= isl_map_read_from_str(ctx
, str
);
2607 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2609 flow
= isl_access_info_compute_flow(ai
);
2610 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2611 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2612 mm
.may
= isl_map_empty(dim
);
2614 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2616 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2617 " [1,10,0] -> [2,5,0] }";
2618 assert(map_is_equal(mm
.must
, str
));
2619 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2620 assert(map_is_equal(mm
.may
, str
));
2622 isl_map_free(mm
.must
);
2623 isl_map_free(mm
.may
);
2624 isl_flow_free(flow
);
2627 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2628 map
= isl_map_read_from_str(ctx
, str
);
2629 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2631 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2632 map
= isl_map_read_from_str(ctx
, str
);
2633 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2635 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2636 map
= isl_map_read_from_str(ctx
, str
);
2637 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2639 flow
= isl_access_info_compute_flow(ai
);
2640 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2641 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2642 mm
.may
= isl_map_empty(dim
);
2644 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2646 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2647 assert(map_is_equal(mm
.must
, str
));
2648 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2649 assert(map_is_equal(mm
.may
, str
));
2651 isl_map_free(mm
.must
);
2652 isl_map_free(mm
.may
);
2653 isl_flow_free(flow
);
2656 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2657 map
= isl_map_read_from_str(ctx
, str
);
2658 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2660 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2661 map
= isl_map_read_from_str(ctx
, str
);
2662 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2664 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2665 map
= isl_map_read_from_str(ctx
, str
);
2666 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2668 flow
= isl_access_info_compute_flow(ai
);
2669 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2670 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2671 mm
.may
= isl_map_empty(dim
);
2673 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2675 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2676 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2677 assert(map_is_equal(mm
.may
, str
));
2678 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2679 assert(map_is_equal(mm
.must
, str
));
2681 isl_map_free(mm
.must
);
2682 isl_map_free(mm
.may
);
2683 isl_flow_free(flow
);
2686 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2687 map
= isl_map_read_from_str(ctx
, str
);
2688 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2690 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2691 map
= isl_map_read_from_str(ctx
, str
);
2692 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2694 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2695 map
= isl_map_read_from_str(ctx
, str
);
2696 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2698 flow
= isl_access_info_compute_flow(ai
);
2699 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2700 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2701 mm
.may
= isl_map_empty(dim
);
2703 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2705 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2706 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2707 assert(map_is_equal(mm
.may
, str
));
2708 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2709 assert(map_is_equal(mm
.must
, str
));
2711 isl_map_free(mm
.must
);
2712 isl_map_free(mm
.may
);
2713 isl_flow_free(flow
);
2716 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2717 map
= isl_map_read_from_str(ctx
, str
);
2718 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2720 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2721 map
= isl_map_read_from_str(ctx
, str
);
2722 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2724 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2725 map
= isl_map_read_from_str(ctx
, str
);
2726 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2728 flow
= isl_access_info_compute_flow(ai
);
2729 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2730 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2731 mm
.may
= isl_map_empty(dim
);
2733 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2735 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2736 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2737 assert(map_is_equal(mm
.may
, str
));
2738 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2739 assert(map_is_equal(mm
.must
, str
));
2741 isl_map_free(mm
.must
);
2742 isl_map_free(mm
.may
);
2743 isl_flow_free(flow
);
2748 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2749 map
= isl_map_read_from_str(ctx
, str
);
2750 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2752 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2753 map
= isl_map_read_from_str(ctx
, str
);
2754 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2756 flow
= isl_access_info_compute_flow(ai
);
2757 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2758 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2759 mm
.may
= isl_map_empty(dim
);
2761 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2763 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2764 assert(map_is_equal(mm
.must
, str
));
2765 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2766 assert(map_is_equal(mm
.may
, str
));
2768 isl_map_free(mm
.must
);
2769 isl_map_free(mm
.may
);
2770 isl_flow_free(flow
);
2775 /* Check that the dependence analysis proceeds without errors.
2776 * Earlier versions of isl would break down during the analysis
2777 * due to the use of the wrong spaces.
2779 static int test_flow(isl_ctx
*ctx
)
2782 isl_union_map
*access
, *schedule
;
2783 isl_union_map
*must_dep
, *may_dep
;
2786 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2787 access
= isl_union_map_read_from_str(ctx
, str
);
2788 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2789 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2790 "S2[] -> [1,0,0,0]; "
2791 "S3[] -> [-1,0,0,0] }";
2792 schedule
= isl_union_map_read_from_str(ctx
, str
);
2793 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2794 isl_union_map_copy(access
), schedule
,
2795 &must_dep
, &may_dep
, NULL
, NULL
);
2796 isl_union_map_free(may_dep
);
2797 isl_union_map_free(must_dep
);
2806 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2807 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2808 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2809 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2810 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2811 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2812 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2813 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2814 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2817 int test_sv(isl_ctx
*ctx
)
2819 isl_union_map
*umap
;
2823 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2824 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2825 sv
= isl_union_map_is_single_valued(umap
);
2826 isl_union_map_free(umap
);
2829 if (sv_tests
[i
].sv
&& !sv
)
2830 isl_die(ctx
, isl_error_internal
,
2831 "map not detected as single valued", return -1);
2832 if (!sv_tests
[i
].sv
&& sv
)
2833 isl_die(ctx
, isl_error_internal
,
2834 "map detected as single valued", return -1);
2843 } bijective_tests
[] = {
2844 { "[N,M]->{[i,j] -> [i]}", 0 },
2845 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
2846 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
2847 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
2848 { "[N,M]->{[i,j] -> [j,i]}", 1 },
2849 { "[N,M]->{[i,j] -> [i+j]}", 0 },
2850 { "[N,M]->{[i,j] -> []}", 0 },
2851 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
2852 { "[N,M]->{[i,j] -> [2i]}", 0 },
2853 { "[N,M]->{[i,j] -> [i,i]}", 0 },
2854 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
2855 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
2856 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
2859 static int test_bijective(struct isl_ctx
*ctx
)
2865 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
2866 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
2867 bijective
= isl_map_is_bijective(map
);
2871 if (bijective_tests
[i
].bijective
&& !bijective
)
2872 isl_die(ctx
, isl_error_internal
,
2873 "map not detected as bijective", return -1);
2874 if (!bijective_tests
[i
].bijective
&& bijective
)
2875 isl_die(ctx
, isl_error_internal
,
2876 "map detected as bijective", return -1);
2882 /* Inputs for isl_pw_qpolynomial_gist tests.
2883 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2889 } pwqp_gist_tests
[] = {
2890 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2891 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2892 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2893 "{ [i] -> -1/2 + 1/2 * i }" },
2894 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2897 static int test_pwqp(struct isl_ctx
*ctx
)
2902 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2905 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2906 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2908 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2911 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2912 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2914 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2916 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2918 isl_pw_qpolynomial_free(pwqp1
);
2920 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
2921 str
= pwqp_gist_tests
[i
].pwqp
;
2922 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2923 str
= pwqp_gist_tests
[i
].set
;
2924 set
= isl_set_read_from_str(ctx
, str
);
2925 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2926 str
= pwqp_gist_tests
[i
].gist
;
2927 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2928 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2929 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
2930 isl_pw_qpolynomial_free(pwqp1
);
2935 isl_die(ctx
, isl_error_unknown
,
2936 "unexpected result", return -1);
2939 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2940 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2941 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2942 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2944 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2946 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2948 isl_pw_qpolynomial_free(pwqp1
);
2950 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2951 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2952 str
= "{ [x] -> x }";
2953 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2955 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2957 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2959 isl_pw_qpolynomial_free(pwqp1
);
2961 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2962 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2963 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2964 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2965 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2966 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2967 isl_pw_qpolynomial_free(pwqp1
);
2969 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2970 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2971 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2972 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2973 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2974 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2975 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2976 isl_pw_qpolynomial_free(pwqp1
);
2977 isl_pw_qpolynomial_free(pwqp2
);
2981 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2983 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2984 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2985 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2986 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2987 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2989 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2990 isl_pw_qpolynomial_free(pwqp1
);
2991 isl_pw_qpolynomial_free(pwqp2
);
2995 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3000 static int test_split_periods(isl_ctx
*ctx
)
3003 isl_pw_qpolynomial
*pwqp
;
3005 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3006 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3007 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3008 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3010 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3012 isl_pw_qpolynomial_free(pwqp
);
3020 static int test_union(isl_ctx
*ctx
)
3023 isl_union_set
*uset1
, *uset2
;
3024 isl_union_map
*umap1
, *umap2
;
3027 str
= "{ [i] : 0 <= i <= 1 }";
3028 uset1
= isl_union_set_read_from_str(ctx
, str
);
3029 str
= "{ [1] -> [0] }";
3030 umap1
= isl_union_map_read_from_str(ctx
, str
);
3032 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3033 equal
= isl_union_map_is_equal(umap1
, umap2
);
3035 isl_union_map_free(umap1
);
3036 isl_union_map_free(umap2
);
3041 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3044 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3045 umap1
= isl_union_map_read_from_str(ctx
, str
);
3046 str
= "{ A[i]; B[i] }";
3047 uset1
= isl_union_set_read_from_str(ctx
, str
);
3049 uset2
= isl_union_map_domain(umap1
);
3051 equal
= isl_union_set_is_equal(uset1
, uset2
);
3053 isl_union_set_free(uset1
);
3054 isl_union_set_free(uset2
);
3059 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3065 /* Check that computing a bound of a non-zero polynomial over an unbounded
3066 * domain does not produce a rational value.
3067 * In particular, check that the upper bound is infinity.
3069 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3072 isl_pw_qpolynomial
*pwqp
;
3073 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3076 str
= "{ [m,n] -> -m * n }";
3077 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3078 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3080 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3081 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3082 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3083 isl_pw_qpolynomial_fold_free(pwf
);
3084 isl_pw_qpolynomial_fold_free(pwf2
);
3089 isl_die(ctx
, isl_error_unknown
,
3090 "expecting infinite polynomial bound", return -1);
3095 static int test_bound(isl_ctx
*ctx
)
3099 isl_pw_qpolynomial
*pwqp
;
3100 isl_pw_qpolynomial_fold
*pwf
;
3102 if (test_bound_unbounded_domain(ctx
) < 0)
3105 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3106 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3107 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3108 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3109 isl_pw_qpolynomial_fold_free(pwf
);
3111 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3114 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3115 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3116 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3117 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3118 isl_pw_qpolynomial_fold_free(pwf
);
3120 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3126 static int test_lift(isl_ctx
*ctx
)
3129 isl_basic_map
*bmap
;
3130 isl_basic_set
*bset
;
3132 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3133 bset
= isl_basic_set_read_from_str(ctx
, str
);
3134 bset
= isl_basic_set_lift(bset
);
3135 bmap
= isl_basic_map_from_range(bset
);
3136 bset
= isl_basic_map_domain(bmap
);
3137 isl_basic_set_free(bset
);
3146 } subset_tests
[] = {
3148 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3149 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3150 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3152 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3153 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3154 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3155 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3156 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3157 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3158 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3159 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3160 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3161 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3162 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3163 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3164 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3165 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3166 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3167 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3168 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3169 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3170 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3171 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3172 "4e0 <= -57 + i0 + i1)) or "
3173 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3174 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3175 "4e0 >= -61 + i0 + i1)) or "
3176 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3177 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3180 static int test_subset(isl_ctx
*ctx
)
3183 isl_set
*set1
, *set2
;
3186 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3187 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3188 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3189 subset
= isl_set_is_subset(set1
, set2
);
3194 if (subset
!= subset_tests
[i
].subset
)
3195 isl_die(ctx
, isl_error_unknown
,
3196 "incorrect subset result", return -1);
3203 const char *minuend
;
3204 const char *subtrahend
;
3205 const char *difference
;
3206 } subtract_domain_tests
[] = {
3207 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3208 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3209 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3212 static int test_subtract(isl_ctx
*ctx
)
3215 isl_union_map
*umap1
, *umap2
;
3216 isl_union_pw_multi_aff
*upma1
, *upma2
;
3217 isl_union_set
*uset
;
3220 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3221 umap1
= isl_union_map_read_from_str(ctx
,
3222 subtract_domain_tests
[i
].minuend
);
3223 uset
= isl_union_set_read_from_str(ctx
,
3224 subtract_domain_tests
[i
].subtrahend
);
3225 umap2
= isl_union_map_read_from_str(ctx
,
3226 subtract_domain_tests
[i
].difference
);
3227 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3228 equal
= isl_union_map_is_equal(umap1
, umap2
);
3229 isl_union_map_free(umap1
);
3230 isl_union_map_free(umap2
);
3234 isl_die(ctx
, isl_error_unknown
,
3235 "incorrect subtract domain result", return -1);
3238 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3239 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3240 subtract_domain_tests
[i
].minuend
);
3241 uset
= isl_union_set_read_from_str(ctx
,
3242 subtract_domain_tests
[i
].subtrahend
);
3243 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3244 subtract_domain_tests
[i
].difference
);
3245 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3246 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3247 isl_union_pw_multi_aff_free(upma1
);
3248 isl_union_pw_multi_aff_free(upma2
);
3252 isl_die(ctx
, isl_error_unknown
,
3253 "incorrect subtract domain result", return -1);
3259 /* Check that intersecting the empty basic set with another basic set
3260 * does not increase the number of constraints. In particular,
3261 * the empty basic set should maintain its canonical representation.
3263 static int test_intersect(isl_ctx
*ctx
)
3266 isl_basic_set
*bset1
, *bset2
;
3268 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3269 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3270 n1
= isl_basic_set_n_constraint(bset1
);
3271 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3272 n2
= isl_basic_set_n_constraint(bset1
);
3273 isl_basic_set_free(bset1
);
3277 isl_die(ctx
, isl_error_unknown
,
3278 "number of constraints of empty set changed",
3284 int test_factorize(isl_ctx
*ctx
)
3287 isl_basic_set
*bset
;
3290 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3291 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3292 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3293 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3294 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3295 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3296 "3i5 >= -2i0 - i2 + 3i4 }";
3297 bset
= isl_basic_set_read_from_str(ctx
, str
);
3298 f
= isl_basic_set_factorizer(bset
);
3299 isl_basic_set_free(bset
);
3300 isl_factorizer_free(f
);
3302 isl_die(ctx
, isl_error_unknown
,
3303 "failed to construct factorizer", return -1);
3305 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3306 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3307 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3308 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3309 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3310 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3311 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3312 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3313 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3314 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3315 bset
= isl_basic_set_read_from_str(ctx
, str
);
3316 f
= isl_basic_set_factorizer(bset
);
3317 isl_basic_set_free(bset
);
3318 isl_factorizer_free(f
);
3320 isl_die(ctx
, isl_error_unknown
,
3321 "failed to construct factorizer", return -1);
3326 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3328 int *injective
= user
;
3330 *injective
= isl_map_is_injective(map
);
3333 if (*injective
< 0 || !*injective
)
3334 return isl_stat_error
;
3339 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3340 const char *r
, const char *s
, int tilable
, int parallel
)
3344 isl_union_map
*W
, *R
, *S
;
3345 isl_union_map
*empty
;
3346 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3347 isl_union_map
*validity
, *proximity
, *coincidence
;
3348 isl_union_map
*schedule
;
3349 isl_union_map
*test
;
3350 isl_union_set
*delta
;
3351 isl_union_set
*domain
;
3355 isl_schedule_constraints
*sc
;
3356 isl_schedule
*sched
;
3357 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3359 D
= isl_union_set_read_from_str(ctx
, d
);
3360 W
= isl_union_map_read_from_str(ctx
, w
);
3361 R
= isl_union_map_read_from_str(ctx
, r
);
3362 S
= isl_union_map_read_from_str(ctx
, s
);
3364 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3365 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3367 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3368 isl_union_map_compute_flow(isl_union_map_copy(R
),
3369 isl_union_map_copy(W
), empty
,
3370 isl_union_map_copy(S
),
3371 &dep_raw
, NULL
, NULL
, NULL
);
3372 isl_union_map_compute_flow(isl_union_map_copy(W
),
3373 isl_union_map_copy(W
),
3374 isl_union_map_copy(R
),
3375 isl_union_map_copy(S
),
3376 &dep_waw
, &dep_war
, NULL
, NULL
);
3378 dep
= isl_union_map_union(dep_waw
, dep_war
);
3379 dep
= isl_union_map_union(dep
, dep_raw
);
3380 validity
= isl_union_map_copy(dep
);
3381 coincidence
= isl_union_map_copy(dep
);
3382 proximity
= isl_union_map_copy(dep
);
3384 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3385 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3386 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3387 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3388 sched
= isl_schedule_constraints_compute_schedule(sc
);
3389 schedule
= isl_schedule_get_map(sched
);
3390 isl_schedule_free(sched
);
3391 isl_union_map_free(W
);
3392 isl_union_map_free(R
);
3393 isl_union_map_free(S
);
3396 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3398 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3399 is_complete
= isl_union_set_is_subset(D
, domain
);
3400 isl_union_set_free(D
);
3401 isl_union_set_free(domain
);
3403 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3404 test
= isl_union_map_apply_range(test
, dep
);
3405 test
= isl_union_map_apply_range(test
, schedule
);
3407 delta
= isl_union_map_deltas(test
);
3408 if (isl_union_set_n_set(delta
) == 0) {
3412 isl_union_set_free(delta
);
3414 delta_set
= isl_set_from_union_set(delta
);
3416 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3417 for (i
= 0; i
< tilable
; ++i
)
3418 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3419 is_tilable
= isl_set_is_subset(delta_set
, slice
);
3420 isl_set_free(slice
);
3422 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3423 for (i
= 0; i
< parallel
; ++i
)
3424 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
3425 is_parallel
= isl_set_is_subset(delta_set
, slice
);
3426 isl_set_free(slice
);
3428 origin
= isl_set_universe(isl_set_get_space(delta_set
));
3429 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
3430 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
3432 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
3433 delta_set
= isl_set_lexmin(delta_set
);
3435 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
3437 isl_set_free(origin
);
3438 isl_set_free(delta_set
);
3441 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
3442 is_injection
< 0 || is_complete
< 0)
3445 isl_die(ctx
, isl_error_unknown
,
3446 "generated schedule incomplete", return -1);
3448 isl_die(ctx
, isl_error_unknown
,
3449 "generated schedule not injective on each statement",
3452 isl_die(ctx
, isl_error_unknown
,
3453 "negative dependences in generated schedule",
3456 isl_die(ctx
, isl_error_unknown
,
3457 "generated schedule not as tilable as expected",
3460 isl_die(ctx
, isl_error_unknown
,
3461 "generated schedule not as parallel as expected",
3467 /* Compute a schedule for the given instance set, validity constraints,
3468 * proximity constraints and context and return a corresponding union map
3471 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
3472 const char *domain
, const char *validity
, const char *proximity
,
3473 const char *context
)
3478 isl_union_map
*prox
;
3479 isl_schedule_constraints
*sc
;
3480 isl_schedule
*schedule
;
3481 isl_union_map
*sched
;
3483 con
= isl_set_read_from_str(ctx
, context
);
3484 dom
= isl_union_set_read_from_str(ctx
, domain
);
3485 dep
= isl_union_map_read_from_str(ctx
, validity
);
3486 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3487 sc
= isl_schedule_constraints_on_domain(dom
);
3488 sc
= isl_schedule_constraints_set_context(sc
, con
);
3489 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3490 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3491 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3492 sched
= isl_schedule_get_map(schedule
);
3493 isl_schedule_free(schedule
);
3498 /* Compute a schedule for the given instance set, validity constraints and
3499 * proximity constraints and return a corresponding union map representation.
3501 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3502 const char *domain
, const char *validity
, const char *proximity
)
3504 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
3508 /* Check that a schedule can be constructed on the given domain
3509 * with the given validity and proximity constraints.
3511 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3512 const char *validity
, const char *proximity
)
3514 isl_union_map
*sched
;
3516 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3520 isl_union_map_free(sched
);
3524 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3525 const char *validity
, const char *proximity
, const char *expected_sched
)
3527 isl_union_map
*sched1
, *sched2
;
3530 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3531 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3533 equal
= isl_union_map_is_equal(sched1
, sched2
);
3534 isl_union_map_free(sched1
);
3535 isl_union_map_free(sched2
);
3540 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3546 /* Check that the schedule map is properly padded, even after being
3547 * reconstructed from the band forest.
3549 static int test_padded_schedule(isl_ctx
*ctx
)
3553 isl_union_map
*validity
, *proximity
;
3554 isl_schedule_constraints
*sc
;
3555 isl_schedule
*sched
;
3556 isl_union_map
*map1
, *map2
;
3557 isl_band_list
*list
;
3560 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3561 D
= isl_union_set_read_from_str(ctx
, str
);
3562 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3563 proximity
= isl_union_map_copy(validity
);
3564 sc
= isl_schedule_constraints_on_domain(D
);
3565 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3566 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3567 sched
= isl_schedule_constraints_compute_schedule(sc
);
3568 map1
= isl_schedule_get_map(sched
);
3569 list
= isl_schedule_get_band_forest(sched
);
3570 isl_band_list_free(list
);
3571 map2
= isl_schedule_get_map(sched
);
3572 isl_schedule_free(sched
);
3573 equal
= isl_union_map_is_equal(map1
, map2
);
3574 isl_union_map_free(map1
);
3575 isl_union_map_free(map2
);
3580 isl_die(ctx
, isl_error_unknown
,
3581 "reconstructed schedule map not the same as original",
3587 /* Check that conditional validity constraints are also taken into
3588 * account across bands.
3589 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3590 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3591 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3592 * is enforced by the rest of the schedule.
3594 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3597 isl_union_set
*domain
;
3598 isl_union_map
*validity
, *proximity
, *condition
;
3599 isl_union_map
*sink
, *source
, *dep
;
3600 isl_schedule_constraints
*sc
;
3601 isl_schedule
*schedule
;
3602 isl_union_access_info
*access
;
3603 isl_union_flow
*flow
;
3606 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3607 "A[k] : k >= 1 and k <= -1 + n; "
3608 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3609 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3610 domain
= isl_union_set_read_from_str(ctx
, str
);
3611 sc
= isl_schedule_constraints_on_domain(domain
);
3612 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3613 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3614 "D[k, i] -> C[1 + k, i] : "
3615 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3616 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3617 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3618 validity
= isl_union_map_read_from_str(ctx
, str
);
3619 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3620 str
= "[n] -> { C[k, i] -> D[k, i] : "
3621 "0 <= i <= -1 + k and k <= -1 + n }";
3622 proximity
= isl_union_map_read_from_str(ctx
, str
);
3623 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3624 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3625 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3626 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3627 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3628 condition
= isl_union_map_read_from_str(ctx
, str
);
3629 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3630 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3631 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3632 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3633 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3634 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3635 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3636 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3637 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3638 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3639 validity
= isl_union_map_read_from_str(ctx
, str
);
3640 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3642 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3643 str
= "{ D[2,0] -> [] }";
3644 sink
= isl_union_map_read_from_str(ctx
, str
);
3645 access
= isl_union_access_info_from_sink(sink
);
3646 str
= "{ C[2,1] -> [] }";
3647 source
= isl_union_map_read_from_str(ctx
, str
);
3648 access
= isl_union_access_info_set_must_source(access
, source
);
3649 access
= isl_union_access_info_set_schedule(access
, schedule
);
3650 flow
= isl_union_access_info_compute_flow(access
);
3651 dep
= isl_union_flow_get_must_dependence(flow
);
3652 isl_union_flow_free(flow
);
3653 empty
= isl_union_map_is_empty(dep
);
3654 isl_union_map_free(dep
);
3659 isl_die(ctx
, isl_error_unknown
,
3660 "conditional validity not respected", return -1);
3665 /* Input for testing of schedule construction based on
3666 * conditional constraints.
3668 * domain is the iteration domain
3669 * flow are the flow dependences, which determine the validity and
3670 * proximity constraints
3671 * condition are the conditions on the conditional validity constraints
3672 * conditional_validity are the conditional validity constraints
3673 * outer_band_n is the expected number of members in the outer band
3678 const char *condition
;
3679 const char *conditional_validity
;
3681 } live_range_tests
[] = {
3682 /* Contrived example that illustrates that we need to keep
3683 * track of tagged condition dependences and
3684 * tagged conditional validity dependences
3685 * in isl_sched_edge separately.
3686 * In particular, the conditional validity constraints on A
3687 * cannot be satisfied,
3688 * but they can be ignored because there are no corresponding
3689 * condition constraints. However, we do have an additional
3690 * conditional validity constraint that maps to the same
3691 * dependence relation
3692 * as the condition constraint on B. If we did not make a distinction
3693 * between tagged condition and tagged conditional validity
3694 * dependences, then we
3695 * could end up treating this shared dependence as an condition
3696 * constraint on A, forcing a localization of the conditions,
3697 * which is impossible.
3699 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3700 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3701 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
3702 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3703 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3704 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
3707 /* TACO 2013 Fig. 7 */
3708 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3709 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3710 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3711 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
3712 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
3713 "0 <= i < n and 0 <= j < n - 1 }",
3714 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
3715 "0 <= i < n and 0 <= j < j' < n;"
3716 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
3717 "0 <= i < i' < n and 0 <= j,j' < n;"
3718 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
3719 "0 <= i,j,j' < n and j < j' }",
3722 /* TACO 2013 Fig. 7, without tags */
3723 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3724 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3725 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3726 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3727 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3728 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
3729 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
3730 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
3733 /* TACO 2013 Fig. 12 */
3734 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
3735 "S3[i,3] : 0 <= i <= 1 }",
3736 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
3737 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
3738 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
3739 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
3740 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3741 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
3742 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3743 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
3744 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
3745 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
3746 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
3751 /* Test schedule construction based on conditional constraints.
3752 * In particular, check the number of members in the outer band node
3753 * as an indication of whether tiling is possible or not.
3755 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
3758 isl_union_set
*domain
;
3759 isl_union_map
*condition
;
3760 isl_union_map
*flow
;
3761 isl_union_map
*validity
;
3762 isl_schedule_constraints
*sc
;
3763 isl_schedule
*schedule
;
3764 isl_schedule_node
*node
;
3767 if (test_special_conditional_schedule_constraints(ctx
) < 0)
3770 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
3771 domain
= isl_union_set_read_from_str(ctx
,
3772 live_range_tests
[i
].domain
);
3773 flow
= isl_union_map_read_from_str(ctx
,
3774 live_range_tests
[i
].flow
);
3775 condition
= isl_union_map_read_from_str(ctx
,
3776 live_range_tests
[i
].condition
);
3777 validity
= isl_union_map_read_from_str(ctx
,
3778 live_range_tests
[i
].conditional_validity
);
3779 sc
= isl_schedule_constraints_on_domain(domain
);
3780 sc
= isl_schedule_constraints_set_validity(sc
,
3781 isl_union_map_copy(flow
));
3782 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
3783 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
3784 condition
, validity
);
3785 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3786 node
= isl_schedule_get_root(schedule
);
3788 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
3789 node
= isl_schedule_node_first_child(node
);
3790 n_member
= isl_schedule_node_band_n_member(node
);
3791 isl_schedule_node_free(node
);
3792 isl_schedule_free(schedule
);
3796 if (n_member
!= live_range_tests
[i
].outer_band_n
)
3797 isl_die(ctx
, isl_error_unknown
,
3798 "unexpected number of members in outer band",
3804 /* Check that the schedule computed for the given instance set and
3805 * dependence relation strongly satisfies the dependences.
3806 * In particular, check that no instance is scheduled before
3807 * or together with an instance on which it depends.
3808 * Earlier versions of isl would produce a schedule that
3809 * only weakly satisfies the dependences.
3811 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
3813 const char *domain
, *dep
;
3814 isl_union_map
*D
, *schedule
;
3818 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
3819 "A[i0] : 0 <= i0 <= 1 }";
3820 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
3821 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
3822 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
3823 D
= isl_union_map_read_from_str(ctx
, dep
);
3824 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
3825 D
= isl_union_map_apply_range(D
, schedule
);
3826 map
= isl_map_from_union_map(D
);
3827 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3828 map
= isl_map_intersect(map
, ge
);
3829 empty
= isl_map_is_empty(map
);
3835 isl_die(ctx
, isl_error_unknown
,
3836 "dependences not strongly satisfied", return -1);
3841 /* Compute a schedule for input where the instance set constraints
3842 * conflict with the context constraints.
3843 * Earlier versions of isl did not properly handle this situation.
3845 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
3847 isl_union_map
*schedule
;
3848 const char *domain
, *context
;
3850 domain
= "[n] -> { A[] : n >= 0 }";
3851 context
= "[n] -> { : n < 0 }";
3852 schedule
= compute_schedule_with_context(ctx
,
3853 domain
, "{}", "{}", context
);
3854 isl_union_map_free(schedule
);
3862 /* Check that the dependence carrying step is not confused by
3863 * a bound on the coefficient size.
3864 * In particular, force the scheduler to move to a dependence carrying
3865 * step by demanding outer coincidence and bound the size of
3866 * the coefficients. Earlier versions of isl would take this
3867 * bound into account while carrying dependences, breaking
3868 * fundamental assumptions.
3869 * On the other hand, the dependence carrying step now tries
3870 * to prevent loop coalescing by default, so check that indeed
3871 * no loop coalescing occurs by comparing the computed schedule
3872 * to the expected non-coalescing schedule.
3874 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
3876 const char *domain
, *dep
;
3879 isl_schedule_constraints
*sc
;
3880 isl_schedule
*schedule
;
3881 isl_union_map
*sched1
, *sched2
;
3884 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
3885 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
3887 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
3888 I
= isl_union_set_read_from_str(ctx
, domain
);
3889 D
= isl_union_map_read_from_str(ctx
, dep
);
3890 sc
= isl_schedule_constraints_on_domain(I
);
3891 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
3892 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
3893 isl_options_set_schedule_outer_coincidence(ctx
, 1);
3894 isl_options_set_schedule_max_coefficient(ctx
, 20);
3895 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3896 isl_options_set_schedule_max_coefficient(ctx
, -1);
3897 isl_options_set_schedule_outer_coincidence(ctx
, 0);
3898 sched1
= isl_schedule_get_map(schedule
);
3899 isl_schedule_free(schedule
);
3901 sched2
= isl_union_map_read_from_str(ctx
, "{ C[x,y] -> [x,y] }");
3902 equal
= isl_union_map_is_equal(sched1
, sched2
);
3903 isl_union_map_free(sched1
);
3904 isl_union_map_free(sched2
);
3909 isl_die(ctx
, isl_error_unknown
,
3910 "unexpected schedule", return -1);
3915 /* Check that a set of schedule constraints that only allow for
3916 * a coalescing schedule still produces a schedule even if the user
3917 * request a non-coalescing schedule. Earlier versions of isl
3918 * would not handle this case correctly.
3920 static int test_coalescing_schedule(isl_ctx
*ctx
)
3922 const char *domain
, *dep
;
3925 isl_schedule_constraints
*sc
;
3926 isl_schedule
*schedule
;
3927 int treat_coalescing
;
3929 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
3930 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
3931 I
= isl_union_set_read_from_str(ctx
, domain
);
3932 D
= isl_union_map_read_from_str(ctx
, dep
);
3933 sc
= isl_schedule_constraints_on_domain(I
);
3934 sc
= isl_schedule_constraints_set_validity(sc
, D
);
3935 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
3936 isl_options_set_schedule_treat_coalescing(ctx
, 1);
3937 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3938 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
3939 isl_schedule_free(schedule
);
3945 int test_schedule(isl_ctx
*ctx
)
3947 const char *D
, *W
, *R
, *V
, *P
, *S
;
3948 int max_coincidence
;
3949 int treat_coalescing
;
3951 /* Handle resulting schedule with zero bands. */
3952 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
3956 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
3957 W
= "{ S1[t,i] -> a[t,i] }";
3958 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
3959 "S1[t,i] -> a[t-1,i+1] }";
3960 S
= "{ S1[t,i] -> [t,i] }";
3961 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3964 /* Fig. 5 of CC2008 */
3965 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
3967 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
3968 "j >= 2 and j <= -1 + N }";
3969 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
3970 "j >= 2 and j <= -1 + N; "
3971 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
3972 "j >= 2 and j <= -1 + N }";
3973 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3974 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3977 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
3978 W
= "{ S1[i] -> a[i] }";
3979 R
= "{ S2[i] -> a[i+1] }";
3980 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3981 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3984 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
3985 W
= "{ S1[i] -> a[i] }";
3986 R
= "{ S2[i] -> a[9-i] }";
3987 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3988 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3991 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
3992 W
= "{ S1[i] -> a[i] }";
3993 R
= "[N] -> { S2[i] -> a[N-1-i] }";
3994 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3995 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3998 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
3999 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4000 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4001 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4002 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4005 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4006 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4007 R
= "{ S2[i,j] -> a[i-1,j] }";
4008 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4009 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4012 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4013 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4014 R
= "{ S2[i,j] -> a[i,j-1] }";
4015 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4016 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4019 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4020 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4021 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4022 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4023 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4024 "S_0[] -> [0, 0, 0] }";
4025 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4027 ctx
->opt
->schedule_parametric
= 0;
4028 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4030 ctx
->opt
->schedule_parametric
= 1;
4032 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4033 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4034 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4035 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4036 "S4[i] -> a[i,N] }";
4037 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4038 "S4[i] -> [4,i,0] }";
4039 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4040 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4041 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4043 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4045 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4046 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4048 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4050 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4052 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4053 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4056 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4057 " S_2[t] : t >= 0 and t <= -1 + N; "
4058 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4060 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4061 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4062 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4063 "i >= 0 and i <= -1 + N }";
4064 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4065 "i >= 0 and i <= -1 + N; "
4066 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4067 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4068 " S_0[t] -> [0, t, 0] }";
4070 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4072 ctx
->opt
->schedule_parametric
= 0;
4073 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4075 ctx
->opt
->schedule_parametric
= 1;
4077 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4078 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4079 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4082 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4083 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4084 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4085 "j >= 0 and j <= -1 + N; "
4086 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4087 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4088 "j >= 0 and j <= -1 + N; "
4089 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4090 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4091 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4094 D
= "{ S_0[i] : i >= 0 }";
4095 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4096 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4097 S
= "{ S_0[i] -> [0, i, 0] }";
4098 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4101 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4102 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4103 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4104 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4105 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4108 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4109 "k <= -1 + n and k >= 0 }";
4110 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4111 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4112 "k <= -1 + n and k >= 0; "
4113 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4114 "k <= -1 + n and k >= 0; "
4115 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4116 "k <= -1 + n and k >= 0 }";
4117 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4118 ctx
->opt
->schedule_outer_coincidence
= 1;
4119 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4121 ctx
->opt
->schedule_outer_coincidence
= 0;
4123 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4124 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4125 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4126 "Stmt_for_body24[i0, i1, 1, 0]:"
4127 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4128 "Stmt_for_body7[i0, i1, i2]:"
4129 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4132 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4133 "Stmt_for_body24[1, i1, i2, i3]:"
4134 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4136 "Stmt_for_body24[0, i1, i2, i3] -> "
4137 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4138 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4140 "Stmt_for_body24[0, i1, i2, i3] ->"
4141 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4142 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4143 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4144 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4145 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4146 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4147 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4148 "i1 <= 6 and i1 >= 0;"
4149 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4150 "Stmt_for_body7[i0, i1, i2] -> "
4151 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4152 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4153 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4154 "Stmt_for_body7[i0, i1, i2] -> "
4155 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4156 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4157 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4159 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
4160 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
4161 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
4163 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4164 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4165 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4167 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4169 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4170 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4171 "j >= 1 and j <= 7;"
4172 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4173 "j >= 1 and j <= 8 }";
4175 S
= "{ S_0[i, j] -> [i + j, j] }";
4176 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4177 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4179 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4181 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4182 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4183 "j >= 0 and j <= -1 + i }";
4184 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4185 "i <= -1 + N and j >= 0;"
4186 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4189 S
= "{ S_0[i, j] -> [i, j] }";
4190 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4191 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4193 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4195 /* Test both algorithms on a case with only proximity dependences. */
4196 D
= "{ S[i,j] : 0 <= i <= 10 }";
4198 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4199 S
= "{ S[i, j] -> [j, i] }";
4200 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4201 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4203 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4204 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4207 D
= "{ A[a]; B[] }";
4209 P
= "{ A[a] -> B[] }";
4210 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4213 if (test_padded_schedule(ctx
) < 0)
4216 /* Check that check for progress is not confused by rational
4219 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4220 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4222 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4223 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4225 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4226 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4228 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4230 /* Check that we allow schedule rows that are only non-trivial
4231 * on some full-dimensional domains.
4233 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4234 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4235 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4237 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4238 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4240 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4242 if (test_conditional_schedule_constraints(ctx
) < 0)
4245 if (test_strongly_satisfying_schedule(ctx
) < 0)
4248 if (test_conflicting_context_schedule(ctx
) < 0)
4251 if (test_bounded_coefficients_schedule(ctx
) < 0)
4253 if (test_coalescing_schedule(ctx
) < 0)
4259 /* Perform scheduling tests using the whole component scheduler.
4261 static int test_schedule_whole(isl_ctx
*ctx
)
4266 whole
= isl_options_get_schedule_whole_component(ctx
);
4267 isl_options_set_schedule_whole_component(ctx
, 1);
4268 r
= test_schedule(ctx
);
4269 isl_options_set_schedule_whole_component(ctx
, whole
);
4274 /* Perform scheduling tests using the incremental scheduler.
4276 static int test_schedule_incremental(isl_ctx
*ctx
)
4281 whole
= isl_options_get_schedule_whole_component(ctx
);
4282 isl_options_set_schedule_whole_component(ctx
, 0);
4283 r
= test_schedule(ctx
);
4284 isl_options_set_schedule_whole_component(ctx
, whole
);
4289 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4291 isl_union_map
*umap
;
4294 umap
= isl_union_map_read_from_str(ctx
, str
);
4295 test
= isl_union_map_plain_is_injective(umap
);
4296 isl_union_map_free(umap
);
4299 if (test
== injective
)
4302 isl_die(ctx
, isl_error_unknown
,
4303 "map not detected as injective", return -1);
4305 isl_die(ctx
, isl_error_unknown
,
4306 "map detected as injective", return -1);
4309 int test_injective(isl_ctx
*ctx
)
4313 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4315 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4317 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4319 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4321 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4323 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4325 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4327 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4330 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4331 if (test_plain_injective(ctx
, str
, 1))
4333 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4334 if (test_plain_injective(ctx
, str
, 0))
4340 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4348 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4349 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4355 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4359 equal
= aff_plain_is_equal(aff
, str
);
4363 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4364 "result not as expected", return -1);
4369 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4370 __isl_take isl_aff
*aff2
);
4372 ['+'] = { &isl_aff_add
},
4373 ['-'] = { &isl_aff_sub
},
4374 ['*'] = { &isl_aff_mul
},
4375 ['/'] = { &isl_aff_div
},
4383 } aff_bin_tests
[] = {
4384 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
4385 "{ [i] -> [2i] }" },
4386 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
4388 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
4389 "{ [i] -> [2i] }" },
4390 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
4391 "{ [i] -> [2i] }" },
4392 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
4393 "{ [i] -> [i/2] }" },
4394 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
4396 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
4397 "{ [i] -> [NaN] }" },
4398 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
4399 "{ [i] -> [NaN] }" },
4400 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
4401 "{ [i] -> [NaN] }" },
4402 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
4403 "{ [i] -> [NaN] }" },
4404 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
4405 "{ [i] -> [NaN] }" },
4406 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
4407 "{ [i] -> [NaN] }" },
4408 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
4409 "{ [i] -> [NaN] }" },
4410 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
4411 "{ [i] -> [NaN] }" },
4412 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
4413 "{ [i] -> [NaN] }" },
4414 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
4415 "{ [i] -> [NaN] }" },
4416 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
4417 "{ [i] -> [NaN] }" },
4418 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
4419 "{ [i] -> [NaN] }" },
4422 /* Perform some basic tests of binary operations on isl_aff objects.
4424 static int test_bin_aff(isl_ctx
*ctx
)
4427 isl_aff
*aff1
, *aff2
, *res
;
4428 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4429 __isl_take isl_aff
*aff2
);
4432 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
4433 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
4434 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
4435 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
4436 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
4437 aff1
= fn(aff1
, aff2
);
4438 if (isl_aff_is_nan(res
))
4439 ok
= isl_aff_is_nan(aff1
);
4441 ok
= isl_aff_plain_is_equal(aff1
, res
);
4447 isl_die(ctx
, isl_error_unknown
,
4448 "unexpected result", return -1);
4455 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4456 __isl_take isl_union_pw_multi_aff
*upma1
,
4457 __isl_take isl_union_pw_multi_aff
*upma2
);
4461 } upma_bin_tests
[] = {
4462 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
4463 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
4464 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
4465 "{ B[x] -> [2] : x >= 0 }",
4466 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
4467 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
4468 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
4469 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
4470 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
4471 "D[i] -> B[2] : i >= 5 }" },
4472 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4473 "{ B[x] -> C[2] : x > 0 }",
4474 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
4475 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4476 "{ B[x] -> A[2] : x >= 0 }",
4477 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
4480 /* Perform some basic tests of binary operations on
4481 * isl_union_pw_multi_aff objects.
4483 static int test_bin_upma(isl_ctx
*ctx
)
4486 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
4489 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
4490 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4491 upma_bin_tests
[i
].arg1
);
4492 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4493 upma_bin_tests
[i
].arg2
);
4494 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
4495 upma_bin_tests
[i
].res
);
4496 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
4497 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
4498 isl_union_pw_multi_aff_free(upma1
);
4499 isl_union_pw_multi_aff_free(res
);
4503 isl_die(ctx
, isl_error_unknown
,
4504 "unexpected result", return -1);
4511 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4512 __isl_take isl_union_pw_multi_aff
*upma1
,
4513 __isl_take isl_union_pw_multi_aff
*upma2
);
4516 } upma_bin_fail_tests
[] = {
4517 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4518 "{ B[x] -> C[2] : x >= 0 }" },
4521 /* Perform some basic tests of binary operations on
4522 * isl_union_pw_multi_aff objects that are expected to fail.
4524 static int test_bin_upma_fail(isl_ctx
*ctx
)
4527 isl_union_pw_multi_aff
*upma1
, *upma2
;
4530 on_error
= isl_options_get_on_error(ctx
);
4531 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
4532 n
= ARRAY_SIZE(upma_bin_fail_tests
);
4533 for (i
= 0; i
< n
; ++i
) {
4534 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4535 upma_bin_fail_tests
[i
].arg1
);
4536 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4537 upma_bin_fail_tests
[i
].arg2
);
4538 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
4539 isl_union_pw_multi_aff_free(upma1
);
4543 isl_options_set_on_error(ctx
, on_error
);
4545 isl_die(ctx
, isl_error_unknown
,
4546 "operation not expected to succeed", return -1);
4551 int test_aff(isl_ctx
*ctx
)
4556 isl_local_space
*ls
;
4560 if (test_bin_aff(ctx
) < 0)
4562 if (test_bin_upma(ctx
) < 0)
4564 if (test_bin_upma_fail(ctx
) < 0)
4567 space
= isl_space_set_alloc(ctx
, 0, 1);
4568 ls
= isl_local_space_from_space(space
);
4569 aff
= isl_aff_zero_on_domain(ls
);
4571 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4572 aff
= isl_aff_scale_down_ui(aff
, 3);
4573 aff
= isl_aff_floor(aff
);
4574 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4575 aff
= isl_aff_scale_down_ui(aff
, 2);
4576 aff
= isl_aff_floor(aff
);
4577 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4580 set
= isl_set_read_from_str(ctx
, str
);
4581 aff
= isl_aff_gist(aff
, set
);
4583 aff
= isl_aff_add_constant_si(aff
, -16);
4584 zero
= isl_aff_plain_is_zero(aff
);
4590 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4592 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
4593 aff
= isl_aff_scale_down_ui(aff
, 64);
4594 aff
= isl_aff_floor(aff
);
4595 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
4603 /* Check that the computation below results in a single expression.
4604 * One or two expressions may result depending on which constraint
4605 * ends up being considered as redundant with respect to the other
4606 * constraints after the projection that is performed internally
4607 * by isl_set_dim_min.
4609 static int test_dim_max_1(isl_ctx
*ctx
)
4616 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
4617 "-4a <= b <= 3 and b < n - 4a }";
4618 set
= isl_set_read_from_str(ctx
, str
);
4619 pa
= isl_set_dim_min(set
, 0);
4620 n
= isl_pw_aff_n_piece(pa
);
4621 isl_pw_aff_free(pa
);
4626 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
4632 int test_dim_max(isl_ctx
*ctx
)
4636 isl_set
*set1
, *set2
;
4641 if (test_dim_max_1(ctx
) < 0)
4644 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
4645 set
= isl_set_read_from_str(ctx
, str
);
4646 pwaff
= isl_set_dim_max(set
, 0);
4647 set1
= isl_set_from_pw_aff(pwaff
);
4648 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
4649 set2
= isl_set_read_from_str(ctx
, str
);
4650 equal
= isl_set_is_equal(set1
, set2
);
4656 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4658 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
4659 set
= isl_set_read_from_str(ctx
, str
);
4660 pwaff
= isl_set_dim_max(set
, 0);
4661 set1
= isl_set_from_pw_aff(pwaff
);
4662 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4663 set2
= isl_set_read_from_str(ctx
, str
);
4664 equal
= isl_set_is_equal(set1
, set2
);
4670 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4672 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
4673 set
= isl_set_read_from_str(ctx
, str
);
4674 pwaff
= isl_set_dim_max(set
, 0);
4675 set1
= isl_set_from_pw_aff(pwaff
);
4676 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4677 set2
= isl_set_read_from_str(ctx
, str
);
4678 equal
= isl_set_is_equal(set1
, set2
);
4684 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4686 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
4687 "0 <= i < N and 0 <= j < M }";
4688 map
= isl_map_read_from_str(ctx
, str
);
4689 set
= isl_map_range(map
);
4691 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
4692 set1
= isl_set_from_pw_aff(pwaff
);
4693 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
4694 set2
= isl_set_read_from_str(ctx
, str
);
4695 equal
= isl_set_is_equal(set1
, set2
);
4699 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
4700 set1
= isl_set_from_pw_aff(pwaff
);
4701 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
4702 set2
= isl_set_read_from_str(ctx
, str
);
4703 if (equal
>= 0 && equal
)
4704 equal
= isl_set_is_equal(set1
, set2
);
4713 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4715 /* Check that solutions are properly merged. */
4716 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
4717 "c <= -1 + n - 4a - 2b and c >= -2b and "
4718 "4a >= -4 + n and c >= 0 }";
4719 set
= isl_set_read_from_str(ctx
, str
);
4720 pwaff
= isl_set_dim_min(set
, 2);
4721 set1
= isl_set_from_pw_aff(pwaff
);
4722 str
= "[n] -> { [(0)] : n >= 1 }";
4723 set2
= isl_set_read_from_str(ctx
, str
);
4724 equal
= isl_set_is_equal(set1
, set2
);
4731 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4733 /* Check that empty solution lie in the right space. */
4734 str
= "[n] -> { [t,a] : 1 = 0 }";
4735 set
= isl_set_read_from_str(ctx
, str
);
4736 pwaff
= isl_set_dim_max(set
, 0);
4737 set1
= isl_set_from_pw_aff(pwaff
);
4738 str
= "[n] -> { [t] : 1 = 0 }";
4739 set2
= isl_set_read_from_str(ctx
, str
);
4740 equal
= isl_set_is_equal(set1
, set2
);
4747 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4752 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
4754 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
4758 isl_pw_multi_aff
*pma2
;
4764 ctx
= isl_pw_multi_aff_get_ctx(pma
);
4765 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4766 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
4767 isl_pw_multi_aff_free(pma2
);
4772 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
4773 * represented by "str".
4775 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
4780 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
4784 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
4785 "result not as expected", return -1);
4789 /* Basic test for isl_pw_multi_aff_product.
4791 * Check that multiple pieces are properly handled.
4793 static int test_product_pma(isl_ctx
*ctx
)
4797 isl_pw_multi_aff
*pma1
, *pma2
;
4799 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
4800 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4801 str
= "{ C[] -> D[] }";
4802 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4803 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
4804 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
4805 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
4806 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
4807 isl_pw_multi_aff_free(pma1
);
4814 int test_product(isl_ctx
*ctx
)
4818 isl_union_set
*uset1
, *uset2
;
4822 set
= isl_set_read_from_str(ctx
, str
);
4823 set
= isl_set_product(set
, isl_set_copy(set
));
4824 ok
= isl_set_is_wrapping(set
);
4829 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4832 uset1
= isl_union_set_read_from_str(ctx
, str
);
4833 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
4834 str
= "{ [[] -> []] }";
4835 uset2
= isl_union_set_read_from_str(ctx
, str
);
4836 ok
= isl_union_set_is_equal(uset1
, uset2
);
4837 isl_union_set_free(uset1
);
4838 isl_union_set_free(uset2
);
4842 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4844 if (test_product_pma(ctx
) < 0)
4850 /* Check that two sets are not considered disjoint just because
4851 * they have a different set of (named) parameters.
4853 static int test_disjoint(isl_ctx
*ctx
)
4856 isl_set
*set
, *set2
;
4859 str
= "[n] -> { [[]->[]] }";
4860 set
= isl_set_read_from_str(ctx
, str
);
4861 str
= "{ [[]->[]] }";
4862 set2
= isl_set_read_from_str(ctx
, str
);
4863 disjoint
= isl_set_is_disjoint(set
, set2
);
4869 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4874 int test_equal(isl_ctx
*ctx
)
4877 isl_set
*set
, *set2
;
4881 set
= isl_set_read_from_str(ctx
, str
);
4883 set2
= isl_set_read_from_str(ctx
, str
);
4884 equal
= isl_set_is_equal(set
, set2
);
4890 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4895 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
4896 enum isl_dim_type type
, unsigned pos
, int fixed
)
4900 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
4907 isl_die(ctx
, isl_error_unknown
,
4908 "map not detected as fixed", return -1);
4910 isl_die(ctx
, isl_error_unknown
,
4911 "map detected as fixed", return -1);
4914 int test_fixed(isl_ctx
*ctx
)
4919 str
= "{ [i] -> [i] }";
4920 map
= isl_map_read_from_str(ctx
, str
);
4921 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
4923 str
= "{ [i] -> [1] }";
4924 map
= isl_map_read_from_str(ctx
, str
);
4925 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4927 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
4928 map
= isl_map_read_from_str(ctx
, str
);
4929 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4931 map
= isl_map_read_from_str(ctx
, str
);
4932 map
= isl_map_neg(map
);
4933 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4939 struct isl_vertices_test_data
{
4942 const char *vertex
[6];
4943 } vertices_tests
[] = {
4944 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
4945 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
4946 { "{ A[t, i] : t = 14 and i = 1 }",
4947 1, { "{ A[14, 1] }" } },
4948 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
4949 "c <= m and m <= n and m > 0 }",
4951 "[n, m] -> { [n, m, m] : 0 < m <= n }",
4952 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
4953 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
4954 "[n, m] -> { [m, m, m] : 0 < m <= n }",
4955 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
4956 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
4960 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
4962 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
4964 struct isl_vertices_test_data
*data
= user
;
4967 isl_basic_set
*bset
;
4968 isl_pw_multi_aff
*pma
;
4972 ctx
= isl_vertex_get_ctx(vertex
);
4973 bset
= isl_vertex_get_domain(vertex
);
4974 ma
= isl_vertex_get_expr(vertex
);
4975 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
4977 for (i
= 0; i
< data
->n
; ++i
) {
4978 isl_pw_multi_aff
*pma_i
;
4980 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
4981 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
4982 isl_pw_multi_aff_free(pma_i
);
4984 if (equal
< 0 || equal
)
4988 isl_pw_multi_aff_free(pma
);
4989 isl_vertex_free(vertex
);
4992 return isl_stat_error
;
4994 return equal
? isl_stat_ok
: isl_stat_error
;
4997 int test_vertices(isl_ctx
*ctx
)
5001 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
5002 isl_basic_set
*bset
;
5003 isl_vertices
*vertices
;
5007 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
5008 vertices
= isl_basic_set_compute_vertices(bset
);
5009 n
= isl_vertices_get_n_vertices(vertices
);
5010 if (vertices_tests
[i
].n
!= n
)
5012 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
5013 &vertices_tests
[i
]) < 0)
5015 isl_vertices_free(vertices
);
5016 isl_basic_set_free(bset
);
5021 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
5028 int test_union_pw(isl_ctx
*ctx
)
5032 isl_union_set
*uset
;
5033 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
5035 str
= "{ [x] -> x^2 }";
5036 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
5037 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
5038 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
5039 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
5040 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
5041 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
5042 isl_union_pw_qpolynomial_free(upwqp1
);
5043 isl_union_pw_qpolynomial_free(upwqp2
);
5047 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5052 /* Test that isl_union_pw_qpolynomial_eval picks up the function
5053 * defined over the correct domain space.
5055 static int test_eval_1(isl_ctx
*ctx
)
5060 isl_union_pw_qpolynomial
*upwqp
;
5064 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
5065 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
5067 set
= isl_set_read_from_str(ctx
, str
);
5068 pnt
= isl_set_sample_point(set
);
5069 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
5070 cmp
= isl_val_cmp_si(v
, 36);
5076 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
5081 /* Check that isl_qpolynomial_eval handles getting called on a void point.
5083 static int test_eval_2(isl_ctx
*ctx
)
5088 isl_qpolynomial
*qp
;
5092 str
= "{ A[x] -> [x] }";
5093 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
5094 str
= "{ A[x] : false }";
5095 set
= isl_set_read_from_str(ctx
, str
);
5096 pnt
= isl_set_sample_point(set
);
5097 v
= isl_qpolynomial_eval(qp
, pnt
);
5098 ok
= isl_val_is_nan(v
);
5104 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
5109 /* Perform basic polynomial evaluation tests.
5111 static int test_eval(isl_ctx
*ctx
)
5113 if (test_eval_1(ctx
) < 0)
5115 if (test_eval_2(ctx
) < 0)
5120 /* Descriptions of sets that are tested for reparsing after printing.
5122 const char *output_tests
[] = {
5123 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
5126 /* Check that printing a set and reparsing a set from the printed output
5127 * results in the same set.
5129 static int test_output_set(isl_ctx
*ctx
)
5133 isl_set
*set1
, *set2
;
5136 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
5137 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
5138 str
= isl_set_to_str(set1
);
5139 set2
= isl_set_read_from_str(ctx
, str
);
5141 equal
= isl_set_is_equal(set1
, set2
);
5147 isl_die(ctx
, isl_error_unknown
,
5148 "parsed output not the same", return -1);
5154 int test_output(isl_ctx
*ctx
)
5162 if (test_output_set(ctx
) < 0)
5165 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
5166 pa
= isl_pw_aff_read_from_str(ctx
, str
);
5168 p
= isl_printer_to_str(ctx
);
5169 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
5170 p
= isl_printer_print_pw_aff(p
, pa
);
5171 s
= isl_printer_get_str(p
);
5172 isl_printer_free(p
);
5173 isl_pw_aff_free(pa
);
5177 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
5182 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5187 int test_sample(isl_ctx
*ctx
)
5190 isl_basic_set
*bset1
, *bset2
;
5193 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
5194 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
5195 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
5196 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
5197 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
5198 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
5199 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
5200 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
5201 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
5202 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
5203 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
5204 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
5205 "d - 1073741821e and "
5206 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
5207 "3j >= 1 - a + b + 2e and "
5208 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
5209 "3i <= 4 - a + 4b - e and "
5210 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
5211 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
5212 "c <= -1 + a and 3i >= -2 - a + 3e and "
5213 "1073741822e <= 1073741823 - a + 1073741822b + c and "
5214 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
5215 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
5216 "1073741823e >= 1 + 1073741823b - d and "
5217 "3i >= 1073741823b + c - 1073741823e - f and "
5218 "3i >= 1 + 2b + e + 3g }";
5219 bset1
= isl_basic_set_read_from_str(ctx
, str
);
5220 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
5221 empty
= isl_basic_set_is_empty(bset2
);
5222 subset
= isl_basic_set_is_subset(bset2
, bset1
);
5223 isl_basic_set_free(bset1
);
5224 isl_basic_set_free(bset2
);
5225 if (empty
< 0 || subset
< 0)
5228 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
5230 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
5235 int test_fixed_power(isl_ctx
*ctx
)
5243 str
= "{ [i] -> [i + 1] }";
5244 map
= isl_map_read_from_str(ctx
, str
);
5245 isl_int_set_si(exp
, 23);
5246 map
= isl_map_fixed_power(map
, exp
);
5247 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
5256 int test_slice(isl_ctx
*ctx
)
5262 str
= "{ [i] -> [j] }";
5263 map
= isl_map_read_from_str(ctx
, str
);
5264 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5265 equal
= map_check_equal(map
, "{ [i] -> [i] }");
5270 str
= "{ [i] -> [j] }";
5271 map
= isl_map_read_from_str(ctx
, str
);
5272 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5273 equal
= map_check_equal(map
, "{ [i] -> [j] }");
5278 str
= "{ [i] -> [j] }";
5279 map
= isl_map_read_from_str(ctx
, str
);
5280 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5281 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
5286 str
= "{ [i] -> [j] }";
5287 map
= isl_map_read_from_str(ctx
, str
);
5288 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5289 equal
= map_check_equal(map
, "{ [0] -> [j] }");
5294 str
= "{ [i] -> [j] }";
5295 map
= isl_map_read_from_str(ctx
, str
);
5296 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5297 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
5302 str
= "{ [i] -> [j] }";
5303 map
= isl_map_read_from_str(ctx
, str
);
5304 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5305 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
5313 int test_eliminate(isl_ctx
*ctx
)
5319 str
= "{ [i] -> [j] : i = 2j }";
5320 map
= isl_map_read_from_str(ctx
, str
);
5321 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
5322 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
5330 /* Check that isl_set_dim_residue_class detects that the values of j
5331 * in the set below are all odd and that it does not detect any spurious
5334 static int test_residue_class(isl_ctx
*ctx
)
5341 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
5342 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
5343 set
= isl_set_read_from_str(ctx
, str
);
5346 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
5348 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
5349 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
5358 int test_align_parameters(isl_ctx
*ctx
)
5362 isl_multi_aff
*ma1
, *ma2
;
5365 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
5366 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
5368 space
= isl_space_params_alloc(ctx
, 1);
5369 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
5370 ma1
= isl_multi_aff_align_params(ma1
, space
);
5372 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
5373 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
5375 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
5377 isl_multi_aff_free(ma1
);
5378 isl_multi_aff_free(ma2
);
5383 isl_die(ctx
, isl_error_unknown
,
5384 "result not as expected", return -1);
5389 static int test_list(isl_ctx
*ctx
)
5391 isl_id
*a
, *b
, *c
, *d
, *id
;
5395 a
= isl_id_alloc(ctx
, "a", NULL
);
5396 b
= isl_id_alloc(ctx
, "b", NULL
);
5397 c
= isl_id_alloc(ctx
, "c", NULL
);
5398 d
= isl_id_alloc(ctx
, "d", NULL
);
5400 list
= isl_id_list_alloc(ctx
, 4);
5401 list
= isl_id_list_add(list
, a
);
5402 list
= isl_id_list_add(list
, b
);
5403 list
= isl_id_list_add(list
, c
);
5404 list
= isl_id_list_add(list
, d
);
5405 list
= isl_id_list_drop(list
, 1, 1);
5407 if (isl_id_list_n_id(list
) != 3) {
5408 isl_id_list_free(list
);
5409 isl_die(ctx
, isl_error_unknown
,
5410 "unexpected number of elements in list", return -1);
5413 id
= isl_id_list_get_id(list
, 0);
5416 id
= isl_id_list_get_id(list
, 1);
5419 id
= isl_id_list_get_id(list
, 2);
5423 isl_id_list_free(list
);
5426 isl_die(ctx
, isl_error_unknown
,
5427 "unexpected elements in list", return -1);
5432 const char *set_conversion_tests
[] = {
5433 "[N] -> { [i] : N - 1 <= 2 i <= N }",
5434 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
5435 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
5436 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
5437 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
5438 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
5439 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
5440 "-3 + c <= d <= 28 + c) }",
5443 /* Check that converting from isl_set to isl_pw_multi_aff and back
5444 * to isl_set produces the original isl_set.
5446 static int test_set_conversion(isl_ctx
*ctx
)
5450 isl_set
*set1
, *set2
;
5451 isl_pw_multi_aff
*pma
;
5454 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
5455 str
= set_conversion_tests
[i
];
5456 set1
= isl_set_read_from_str(ctx
, str
);
5457 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
5458 set2
= isl_set_from_pw_multi_aff(pma
);
5459 equal
= isl_set_is_equal(set1
, set2
);
5466 isl_die(ctx
, isl_error_unknown
, "bad conversion",
5473 const char *conversion_tests
[] = {
5474 "{ [a, b, c, d] -> s0[a, b, e, f] : "
5475 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
5476 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
5477 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
5479 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
5480 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
5481 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
5484 /* Check that converting from isl_map to isl_pw_multi_aff and back
5485 * to isl_map produces the original isl_map.
5487 static int test_map_conversion(isl_ctx
*ctx
)
5490 isl_map
*map1
, *map2
;
5491 isl_pw_multi_aff
*pma
;
5494 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
5495 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
5496 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
5497 map2
= isl_map_from_pw_multi_aff(pma
);
5498 equal
= isl_map_is_equal(map1
, map2
);
5505 isl_die(ctx
, isl_error_unknown
, "bad conversion",
5512 static int test_conversion(isl_ctx
*ctx
)
5514 if (test_set_conversion(ctx
) < 0)
5516 if (test_map_conversion(ctx
) < 0)
5521 /* Check that isl_basic_map_curry does not modify input.
5523 static int test_curry(isl_ctx
*ctx
)
5526 isl_basic_map
*bmap1
, *bmap2
;
5529 str
= "{ [A[] -> B[]] -> C[] }";
5530 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
5531 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
5532 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
5533 isl_basic_map_free(bmap1
);
5534 isl_basic_map_free(bmap2
);
5539 isl_die(ctx
, isl_error_unknown
,
5540 "curried map should not be equal to original",
5550 } preimage_tests
[] = {
5551 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
5552 "{ A[j,i] -> B[i,j] }",
5553 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
5554 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
5555 "{ A[a,b] -> B[a/2,b/6] }",
5556 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
5557 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
5558 "{ A[a,b] -> B[a/2,b/6] }",
5559 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
5560 "exists i,j : a = 2 i and b = 6 j }" },
5561 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
5562 "[n] -> { : 0 <= n <= 100 }" },
5563 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
5564 "{ A[a] -> B[2a] }",
5565 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
5566 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
5567 "{ A[a] -> B[([a/2])] }",
5568 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
5569 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
5570 "{ A[a] -> B[a,a,a/3] }",
5571 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
5572 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
5573 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
5576 static int test_preimage_basic_set(isl_ctx
*ctx
)
5579 isl_basic_set
*bset1
, *bset2
;
5583 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
5584 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
5585 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
5586 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
5587 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
5588 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5589 isl_basic_set_free(bset1
);
5590 isl_basic_set_free(bset2
);
5594 isl_die(ctx
, isl_error_unknown
, "bad preimage",
5605 } preimage_domain_tests
[] = {
5606 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
5607 "{ A[j,i] -> B[i,j] }",
5608 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
5609 { "{ B[i] -> C[i]; D[i] -> E[i] }",
5610 "{ A[i] -> B[i + 1] }",
5611 "{ A[i] -> C[i + 1] }" },
5612 { "{ B[i] -> C[i]; B[i] -> E[i] }",
5613 "{ A[i] -> B[i + 1] }",
5614 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
5615 { "{ B[i] -> C[([i/2])] }",
5616 "{ A[i] -> B[2i] }",
5617 "{ A[i] -> C[i] }" },
5618 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
5619 "{ A[i] -> B[([i/5]), ([i/7])] }",
5620 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
5621 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
5622 "[N] -> { A[] -> B[([N/5])] }",
5623 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
5624 { "{ B[i] -> C[i] : exists a : i = 5 a }",
5625 "{ A[i] -> B[2i] }",
5626 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
5627 { "{ B[i] -> C[i] : exists a : i = 2 a; "
5628 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
5629 "{ A[i] -> B[2i] }",
5630 "{ A[i] -> C[2i] }" },
5631 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
5632 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
5635 static int test_preimage_union_map(isl_ctx
*ctx
)
5638 isl_union_map
*umap1
, *umap2
;
5642 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
5643 umap1
= isl_union_map_read_from_str(ctx
,
5644 preimage_domain_tests
[i
].map
);
5645 ma
= isl_multi_aff_read_from_str(ctx
,
5646 preimage_domain_tests
[i
].ma
);
5647 umap2
= isl_union_map_read_from_str(ctx
,
5648 preimage_domain_tests
[i
].res
);
5649 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
5650 equal
= isl_union_map_is_equal(umap1
, umap2
);
5651 isl_union_map_free(umap1
);
5652 isl_union_map_free(umap2
);
5656 isl_die(ctx
, isl_error_unknown
, "bad preimage",
5663 static int test_preimage(isl_ctx
*ctx
)
5665 if (test_preimage_basic_set(ctx
) < 0)
5667 if (test_preimage_union_map(ctx
) < 0)
5677 } pullback_tests
[] = {
5678 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
5679 "{ A[a,b] -> C[b + 2a] }" },
5680 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
5681 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
5682 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
5683 "{ A[a] -> C[(a)/6] }" },
5684 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
5685 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
5686 "{ A[a] -> C[(2a)/3] }" },
5687 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
5688 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
5689 "{ A[i,j] -> C[i + j, i + j] }"},
5690 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
5691 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
5692 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
5693 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
5694 "{ [i, j] -> [floor((i)/3), j] }",
5695 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
5698 static int test_pullback(isl_ctx
*ctx
)
5701 isl_multi_aff
*ma1
, *ma2
;
5705 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
5706 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
5707 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
5708 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
5709 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
5710 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
5711 isl_multi_aff_free(ma1
);
5712 isl_multi_aff_free(ma2
);
5716 isl_die(ctx
, isl_error_unknown
, "bad pullback",
5723 /* Check that negation is printed correctly and that equal expressions
5724 * are correctly identified.
5726 static int test_ast(isl_ctx
*ctx
)
5728 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
5732 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
5733 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
5734 expr
= isl_ast_expr_add(expr1
, expr2
);
5735 expr2
= isl_ast_expr_copy(expr
);
5736 expr
= isl_ast_expr_neg(expr
);
5737 expr2
= isl_ast_expr_neg(expr2
);
5738 equal
= isl_ast_expr_is_equal(expr
, expr2
);
5739 str
= isl_ast_expr_to_C_str(expr
);
5740 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
5742 isl_ast_expr_free(expr
);
5743 isl_ast_expr_free(expr2
);
5745 if (ok
< 0 || equal
< 0)
5748 isl_die(ctx
, isl_error_unknown
,
5749 "equal expressions not considered equal", return -1);
5751 isl_die(ctx
, isl_error_unknown
,
5752 "isl_ast_expr printed incorrectly", return -1);
5754 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
5755 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
5756 expr
= isl_ast_expr_add(expr1
, expr2
);
5757 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
5758 expr
= isl_ast_expr_sub(expr3
, expr
);
5759 str
= isl_ast_expr_to_C_str(expr
);
5760 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
5762 isl_ast_expr_free(expr
);
5767 isl_die(ctx
, isl_error_unknown
,
5768 "isl_ast_expr printed incorrectly", return -1);
5773 /* Check that isl_ast_build_expr_from_set returns a valid expression
5774 * for an empty set. Note that isl_ast_build_expr_from_set getting
5775 * called on an empty set probably indicates a bug in the caller.
5777 static int test_ast_build(isl_ctx
*ctx
)
5780 isl_ast_build
*build
;
5783 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5784 build
= isl_ast_build_from_context(set
);
5786 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
5787 expr
= isl_ast_build_expr_from_set(build
, set
);
5789 isl_ast_expr_free(expr
);
5790 isl_ast_build_free(build
);
5798 /* Internal data structure for before_for and after_for callbacks.
5800 * depth is the current depth
5801 * before is the number of times before_for has been called
5802 * after is the number of times after_for has been called
5804 struct isl_test_codegen_data
{
5810 /* This function is called before each for loop in the AST generated
5811 * from test_ast_gen1.
5813 * Increment the number of calls and the depth.
5814 * Check that the space returned by isl_ast_build_get_schedule_space
5815 * matches the target space of the schedule returned by
5816 * isl_ast_build_get_schedule.
5817 * Return an isl_id that is checked by the corresponding call
5820 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
5823 struct isl_test_codegen_data
*data
= user
;
5826 isl_union_map
*schedule
;
5827 isl_union_set
*uset
;
5832 ctx
= isl_ast_build_get_ctx(build
);
5834 if (data
->before
>= 3)
5835 isl_die(ctx
, isl_error_unknown
,
5836 "unexpected number of for nodes", return NULL
);
5837 if (data
->depth
>= 2)
5838 isl_die(ctx
, isl_error_unknown
,
5839 "unexpected depth", return NULL
);
5841 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
5845 schedule
= isl_ast_build_get_schedule(build
);
5846 uset
= isl_union_map_range(schedule
);
5849 if (isl_union_set_n_set(uset
) != 1) {
5850 isl_union_set_free(uset
);
5851 isl_die(ctx
, isl_error_unknown
,
5852 "expecting single range space", return NULL
);
5855 space
= isl_ast_build_get_schedule_space(build
);
5856 set
= isl_union_set_extract_set(uset
, space
);
5857 isl_union_set_free(uset
);
5858 empty
= isl_set_is_empty(set
);
5864 isl_die(ctx
, isl_error_unknown
,
5865 "spaces don't match", return NULL
);
5867 return isl_id_alloc(ctx
, name
, NULL
);
5870 /* This function is called after each for loop in the AST generated
5871 * from test_ast_gen1.
5873 * Increment the number of calls and decrement the depth.
5874 * Check that the annotation attached to the node matches
5875 * the isl_id returned by the corresponding call to before_for.
5877 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
5878 __isl_keep isl_ast_build
*build
, void *user
)
5880 struct isl_test_codegen_data
*data
= user
;
5888 if (data
->after
> data
->before
)
5889 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5890 "mismatch in number of for nodes",
5891 return isl_ast_node_free(node
));
5893 id
= isl_ast_node_get_annotation(node
);
5895 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5896 "missing annotation", return isl_ast_node_free(node
));
5898 name
= isl_id_get_name(id
);
5899 valid
= name
&& atoi(name
+ 1) == data
->depth
;
5903 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5904 "wrong annotation", return isl_ast_node_free(node
));
5909 /* Check that the before_each_for and after_each_for callbacks
5910 * are called for each for loop in the generated code,
5911 * that they are called in the right order and that the isl_id
5912 * returned from the before_each_for callback is attached to
5913 * the isl_ast_node passed to the corresponding after_each_for call.
5915 static int test_ast_gen1(isl_ctx
*ctx
)
5919 isl_union_map
*schedule
;
5920 isl_ast_build
*build
;
5922 struct isl_test_codegen_data data
;
5924 str
= "[N] -> { : N >= 10 }";
5925 set
= isl_set_read_from_str(ctx
, str
);
5926 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
5927 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
5928 schedule
= isl_union_map_read_from_str(ctx
, str
);
5933 build
= isl_ast_build_from_context(set
);
5934 build
= isl_ast_build_set_before_each_for(build
,
5935 &before_for
, &data
);
5936 build
= isl_ast_build_set_after_each_for(build
,
5938 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5939 isl_ast_build_free(build
);
5943 isl_ast_node_free(tree
);
5945 if (data
.before
!= 3 || data
.after
!= 3)
5946 isl_die(ctx
, isl_error_unknown
,
5947 "unexpected number of for nodes", return -1);
5952 /* Check that the AST generator handles domains that are integrally disjoint
5953 * but not rationally disjoint.
5955 static int test_ast_gen2(isl_ctx
*ctx
)
5959 isl_union_map
*schedule
;
5960 isl_union_map
*options
;
5961 isl_ast_build
*build
;
5964 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
5965 schedule
= isl_union_map_read_from_str(ctx
, str
);
5966 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5967 build
= isl_ast_build_from_context(set
);
5969 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
5970 options
= isl_union_map_read_from_str(ctx
, str
);
5971 build
= isl_ast_build_set_options(build
, options
);
5972 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5973 isl_ast_build_free(build
);
5976 isl_ast_node_free(tree
);
5981 /* Increment *user on each call.
5983 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
5984 __isl_keep isl_ast_build
*build
, void *user
)
5993 /* Test that unrolling tries to minimize the number of instances.
5994 * In particular, for the schedule given below, make sure it generates
5995 * 3 nodes (rather than 101).
5997 static int test_ast_gen3(isl_ctx
*ctx
)
6001 isl_union_map
*schedule
;
6002 isl_union_map
*options
;
6003 isl_ast_build
*build
;
6007 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
6008 schedule
= isl_union_map_read_from_str(ctx
, str
);
6009 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6011 str
= "{ [i] -> unroll[0] }";
6012 options
= isl_union_map_read_from_str(ctx
, str
);
6014 build
= isl_ast_build_from_context(set
);
6015 build
= isl_ast_build_set_options(build
, options
);
6016 build
= isl_ast_build_set_at_each_domain(build
,
6017 &count_domains
, &n_domain
);
6018 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6019 isl_ast_build_free(build
);
6023 isl_ast_node_free(tree
);
6026 isl_die(ctx
, isl_error_unknown
,
6027 "unexpected number of for nodes", return -1);
6032 /* Check that if the ast_build_exploit_nested_bounds options is set,
6033 * we do not get an outer if node in the generated AST,
6034 * while we do get such an outer if node if the options is not set.
6036 static int test_ast_gen4(isl_ctx
*ctx
)
6040 isl_union_map
*schedule
;
6041 isl_ast_build
*build
;
6043 enum isl_ast_node_type type
;
6046 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
6047 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
6049 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
6051 schedule
= isl_union_map_read_from_str(ctx
, str
);
6052 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6053 build
= isl_ast_build_from_context(set
);
6054 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6055 isl_ast_build_free(build
);
6059 type
= isl_ast_node_get_type(tree
);
6060 isl_ast_node_free(tree
);
6062 if (type
== isl_ast_node_if
)
6063 isl_die(ctx
, isl_error_unknown
,
6064 "not expecting if node", return -1);
6066 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
6068 schedule
= isl_union_map_read_from_str(ctx
, str
);
6069 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6070 build
= isl_ast_build_from_context(set
);
6071 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6072 isl_ast_build_free(build
);
6076 type
= isl_ast_node_get_type(tree
);
6077 isl_ast_node_free(tree
);
6079 if (type
!= isl_ast_node_if
)
6080 isl_die(ctx
, isl_error_unknown
,
6081 "expecting if node", return -1);
6083 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
6088 /* This function is called for each leaf in the AST generated
6089 * from test_ast_gen5.
6091 * We finalize the AST generation by extending the outer schedule
6092 * with a zero-dimensional schedule. If this results in any for loops,
6093 * then this means that we did not pass along enough information
6094 * about the outer schedule to the inner AST generation.
6096 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
6099 isl_union_map
*schedule
, *extra
;
6102 schedule
= isl_ast_build_get_schedule(build
);
6103 extra
= isl_union_map_copy(schedule
);
6104 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
6105 schedule
= isl_union_map_range_product(schedule
, extra
);
6106 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6107 isl_ast_build_free(build
);
6112 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
6113 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
6114 "code should not contain any for loop",
6115 return isl_ast_node_free(tree
));
6120 /* Check that we do not lose any information when going back and
6121 * forth between internal and external schedule.
6123 * In particular, we create an AST where we unroll the only
6124 * non-constant dimension in the schedule. We therefore do
6125 * not expect any for loops in the AST. However, older versions
6126 * of isl would not pass along enough information about the outer
6127 * schedule when performing an inner code generation from a create_leaf
6128 * callback, resulting in the inner code generation producing a for loop.
6130 static int test_ast_gen5(isl_ctx
*ctx
)
6134 isl_union_map
*schedule
, *options
;
6135 isl_ast_build
*build
;
6138 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
6139 schedule
= isl_union_map_read_from_str(ctx
, str
);
6141 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
6142 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
6143 options
= isl_union_map_read_from_str(ctx
, str
);
6145 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6146 build
= isl_ast_build_from_context(set
);
6147 build
= isl_ast_build_set_options(build
, options
);
6148 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
6149 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6150 isl_ast_build_free(build
);
6151 isl_ast_node_free(tree
);
6158 /* Check that the expression
6160 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
6162 * is not combined into
6166 * as this would result in n/2 being evaluated in parts of
6167 * the definition domain where n is not a multiple of 2.
6169 static int test_ast_expr(isl_ctx
*ctx
)
6173 isl_ast_build
*build
;
6178 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
6179 isl_options_set_ast_build_detect_min_max(ctx
, 1);
6181 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
6182 pa
= isl_pw_aff_read_from_str(ctx
, str
);
6183 build
= isl_ast_build_alloc(ctx
);
6184 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
6185 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
6186 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
6187 isl_ast_build_free(build
);
6188 isl_ast_expr_free(expr
);
6190 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
6195 isl_die(ctx
, isl_error_unknown
,
6196 "expressions should not be combined", return -1);
6201 static int test_ast_gen(isl_ctx
*ctx
)
6203 if (test_ast_gen1(ctx
) < 0)
6205 if (test_ast_gen2(ctx
) < 0)
6207 if (test_ast_gen3(ctx
) < 0)
6209 if (test_ast_gen4(ctx
) < 0)
6211 if (test_ast_gen5(ctx
) < 0)
6213 if (test_ast_expr(ctx
) < 0)
6218 /* Check if dropping output dimensions from an isl_pw_multi_aff
6221 static int test_pw_multi_aff(isl_ctx
*ctx
)
6224 isl_pw_multi_aff
*pma1
, *pma2
;
6227 str
= "{ [i,j] -> [i+j, 4i-j] }";
6228 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6229 str
= "{ [i,j] -> [4i-j] }";
6230 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6232 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
6234 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
6236 isl_pw_multi_aff_free(pma1
);
6237 isl_pw_multi_aff_free(pma2
);
6241 isl_die(ctx
, isl_error_unknown
,
6242 "expressions not equal", return -1);
6247 /* Check that we can properly parse multi piecewise affine expressions
6248 * where the piecewise affine expressions have different domains.
6250 static int test_multi_pw_aff(isl_ctx
*ctx
)
6253 isl_set
*dom
, *dom2
;
6254 isl_multi_pw_aff
*mpa1
, *mpa2
;
6259 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
6260 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
6261 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
6262 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
6263 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
6264 str
= "{ [i] -> [(i : i > 0), 2i] }";
6265 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
6267 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
6269 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
6270 dom
= isl_pw_aff_domain(pa
);
6271 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
6272 dom2
= isl_pw_aff_domain(pa
);
6273 equal_domain
= isl_set_is_equal(dom
, dom2
);
6277 isl_multi_pw_aff_free(mpa1
);
6278 isl_multi_pw_aff_free(mpa2
);
6283 isl_die(ctx
, isl_error_unknown
,
6284 "expressions not equal", return -1);
6286 if (equal_domain
< 0)
6289 isl_die(ctx
, isl_error_unknown
,
6290 "domains unexpectedly equal", return -1);
6295 /* This is a regression test for a bug where isl_basic_map_simplify
6296 * would end up in an infinite loop. In particular, we construct
6297 * an empty basic set that is not obviously empty.
6298 * isl_basic_set_is_empty marks the basic set as empty.
6299 * After projecting out i3, the variable can be dropped completely,
6300 * but isl_basic_map_simplify refrains from doing so if the basic set
6301 * is empty and would end up in an infinite loop if it didn't test
6302 * explicitly for empty basic maps in the outer loop.
6304 static int test_simplify_1(isl_ctx
*ctx
)
6307 isl_basic_set
*bset
;
6310 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
6311 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
6312 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
6314 bset
= isl_basic_set_read_from_str(ctx
, str
);
6315 empty
= isl_basic_set_is_empty(bset
);
6316 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
6317 isl_basic_set_free(bset
);
6321 isl_die(ctx
, isl_error_unknown
,
6322 "basic set should be empty", return -1);
6327 /* Check that the equality in the set description below
6328 * is simplified away.
6330 static int test_simplify_2(isl_ctx
*ctx
)
6333 isl_basic_set
*bset
;
6336 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
6337 bset
= isl_basic_set_read_from_str(ctx
, str
);
6338 universe
= isl_basic_set_plain_is_universe(bset
);
6339 isl_basic_set_free(bset
);
6344 isl_die(ctx
, isl_error_unknown
,
6345 "equality not simplified away", return -1);
6349 /* Some simplification tests.
6351 static int test_simplify(isl_ctx
*ctx
)
6353 if (test_simplify_1(ctx
) < 0)
6355 if (test_simplify_2(ctx
) < 0)
6360 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
6361 * with gbr context would fail to disable the use of the shifted tableau
6362 * when transferring equalities for the input to the context, resulting
6363 * in invalid sample values.
6365 static int test_partial_lexmin(isl_ctx
*ctx
)
6368 isl_basic_set
*bset
;
6369 isl_basic_map
*bmap
;
6372 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
6373 bmap
= isl_basic_map_read_from_str(ctx
, str
);
6374 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
6375 bset
= isl_basic_set_read_from_str(ctx
, str
);
6376 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
6385 /* Check that the variable compression performed on the existentially
6386 * quantified variables inside isl_basic_set_compute_divs is not confused
6387 * by the implicit equalities among the parameters.
6389 static int test_compute_divs(isl_ctx
*ctx
)
6392 isl_basic_set
*bset
;
6395 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
6396 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
6397 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
6398 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
6399 bset
= isl_basic_set_read_from_str(ctx
, str
);
6400 set
= isl_basic_set_compute_divs(bset
);
6408 /* Check that the reaching domain elements and the prefix schedule
6409 * at a leaf node are the same before and after grouping.
6411 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
6416 isl_union_set
*uset
;
6417 isl_multi_union_pw_aff
*mupa
;
6418 isl_union_pw_multi_aff
*upma1
, *upma2
;
6419 isl_union_set
*domain1
, *domain2
;
6420 isl_union_map
*umap1
, *umap2
;
6421 isl_schedule_node
*node
;
6423 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
6424 uset
= isl_union_set_read_from_str(ctx
, str
);
6425 node
= isl_schedule_node_from_domain(uset
);
6426 node
= isl_schedule_node_child(node
, 0);
6427 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
6428 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6429 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6430 node
= isl_schedule_node_child(node
, 0);
6431 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
6432 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6433 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6434 node
= isl_schedule_node_child(node
, 0);
6435 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
6436 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
6437 domain1
= isl_schedule_node_get_domain(node
);
6438 id
= isl_id_alloc(ctx
, "group", NULL
);
6439 node
= isl_schedule_node_parent(node
);
6440 node
= isl_schedule_node_group(node
, id
);
6441 node
= isl_schedule_node_child(node
, 0);
6442 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
6443 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
6444 domain2
= isl_schedule_node_get_domain(node
);
6445 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
6446 if (equal
>= 0 && equal
)
6447 equal
= isl_union_set_is_equal(domain1
, domain2
);
6448 if (equal
>= 0 && equal
)
6449 equal
= isl_union_map_is_equal(umap1
, umap2
);
6450 isl_union_map_free(umap1
);
6451 isl_union_map_free(umap2
);
6452 isl_union_set_free(domain1
);
6453 isl_union_set_free(domain2
);
6454 isl_union_pw_multi_aff_free(upma1
);
6455 isl_union_pw_multi_aff_free(upma2
);
6456 isl_schedule_node_free(node
);
6461 isl_die(ctx
, isl_error_unknown
,
6462 "expressions not equal", return -1);
6467 /* Check that we can have nested groupings and that the union map
6468 * schedule representation is the same before and after the grouping.
6469 * Note that after the grouping, the union map representation contains
6470 * the domain constraints from the ranges of the expansion nodes,
6471 * while they are missing from the union map representation of
6472 * the tree without expansion nodes.
6474 * Also check that the global expansion is as expected.
6476 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
6478 int equal
, equal_expansion
;
6481 isl_union_set
*uset
;
6482 isl_union_map
*umap1
, *umap2
;
6483 isl_union_map
*expansion1
, *expansion2
;
6484 isl_union_set_list
*filters
;
6485 isl_multi_union_pw_aff
*mupa
;
6486 isl_schedule
*schedule
;
6487 isl_schedule_node
*node
;
6489 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
6490 "S3[i,j] : 0 <= i,j < 10 }";
6491 uset
= isl_union_set_read_from_str(ctx
, str
);
6492 node
= isl_schedule_node_from_domain(uset
);
6493 node
= isl_schedule_node_child(node
, 0);
6494 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
6495 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6496 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6497 node
= isl_schedule_node_child(node
, 0);
6498 str
= "{ S1[i,j] }";
6499 uset
= isl_union_set_read_from_str(ctx
, str
);
6500 filters
= isl_union_set_list_from_union_set(uset
);
6501 str
= "{ S2[i,j]; S3[i,j] }";
6502 uset
= isl_union_set_read_from_str(ctx
, str
);
6503 filters
= isl_union_set_list_add(filters
, uset
);
6504 node
= isl_schedule_node_insert_sequence(node
, filters
);
6505 node
= isl_schedule_node_child(node
, 1);
6506 node
= isl_schedule_node_child(node
, 0);
6507 str
= "{ S2[i,j] }";
6508 uset
= isl_union_set_read_from_str(ctx
, str
);
6509 filters
= isl_union_set_list_from_union_set(uset
);
6510 str
= "{ S3[i,j] }";
6511 uset
= isl_union_set_read_from_str(ctx
, str
);
6512 filters
= isl_union_set_list_add(filters
, uset
);
6513 node
= isl_schedule_node_insert_sequence(node
, filters
);
6515 schedule
= isl_schedule_node_get_schedule(node
);
6516 umap1
= isl_schedule_get_map(schedule
);
6517 uset
= isl_schedule_get_domain(schedule
);
6518 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
6519 isl_schedule_free(schedule
);
6521 node
= isl_schedule_node_parent(node
);
6522 node
= isl_schedule_node_parent(node
);
6523 id
= isl_id_alloc(ctx
, "group1", NULL
);
6524 node
= isl_schedule_node_group(node
, id
);
6525 node
= isl_schedule_node_child(node
, 1);
6526 node
= isl_schedule_node_child(node
, 0);
6527 id
= isl_id_alloc(ctx
, "group2", NULL
);
6528 node
= isl_schedule_node_group(node
, id
);
6530 schedule
= isl_schedule_node_get_schedule(node
);
6531 umap2
= isl_schedule_get_map(schedule
);
6532 isl_schedule_free(schedule
);
6534 node
= isl_schedule_node_root(node
);
6535 node
= isl_schedule_node_child(node
, 0);
6536 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
6537 isl_schedule_node_free(node
);
6539 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
6540 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
6541 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
6543 expansion2
= isl_union_map_read_from_str(ctx
, str
);
6545 equal
= isl_union_map_is_equal(umap1
, umap2
);
6546 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
6548 isl_union_map_free(umap1
);
6549 isl_union_map_free(umap2
);
6550 isl_union_map_free(expansion1
);
6551 isl_union_map_free(expansion2
);
6553 if (equal
< 0 || equal_expansion
< 0)
6556 isl_die(ctx
, isl_error_unknown
,
6557 "expressions not equal", return -1);
6558 if (!equal_expansion
)
6559 isl_die(ctx
, isl_error_unknown
,
6560 "unexpected expansion", return -1);
6565 /* Some tests for the isl_schedule_node_group function.
6567 static int test_schedule_tree_group(isl_ctx
*ctx
)
6569 if (test_schedule_tree_group_1(ctx
) < 0)
6571 if (test_schedule_tree_group_2(ctx
) < 0)
6580 { "{ rat: [i] : 0 <= i <= 10 }",
6581 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
6582 { "{ rat: [i] : FALSE }",
6583 "{ rat: coefficients[[cst] -> [a]] }" },
6585 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
6592 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
6593 "{ rat: [i] : 0 <= i <= 10 }" },
6594 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
6596 { "{ rat: coefficients[[cst] -> [a]] }",
6597 "{ rat: [i] : FALSE }" },
6600 /* Test the basic functionality of isl_basic_set_coefficients and
6601 * isl_basic_set_solutions.
6603 static int test_dual(isl_ctx
*ctx
)
6607 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
6609 isl_basic_set
*bset1
, *bset2
;
6611 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
6612 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
6613 bset1
= isl_basic_set_coefficients(bset1
);
6614 equal
= isl_basic_set_is_equal(bset1
, bset2
);
6615 isl_basic_set_free(bset1
);
6616 isl_basic_set_free(bset2
);
6620 isl_die(ctx
, isl_error_unknown
,
6621 "incorrect dual", return -1);
6624 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
6626 isl_basic_set
*bset1
, *bset2
;
6628 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
6629 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
6630 bset1
= isl_basic_set_solutions(bset1
);
6631 equal
= isl_basic_set_is_equal(bset1
, bset2
);
6632 isl_basic_set_free(bset1
);
6633 isl_basic_set_free(bset2
);
6637 isl_die(ctx
, isl_error_unknown
,
6638 "incorrect dual", return -1);
6648 const char *schedule
;
6653 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
6654 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6656 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
6657 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6659 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
6660 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6662 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
6663 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6665 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
6666 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6668 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
6669 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
6671 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
6672 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6674 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
6675 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
6679 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
6680 * tile the band and then check if the tile and point bands have the
6681 * expected partial schedule.
6683 static int test_tile(isl_ctx
*ctx
)
6689 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
6690 shift
= isl_options_get_tile_shift_point_loops(ctx
);
6692 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
6696 isl_union_set
*domain
;
6697 isl_multi_union_pw_aff
*mupa
, *mupa2
;
6698 isl_schedule_node
*node
;
6699 isl_multi_val
*sizes
;
6701 opt
= tile_tests
[i
].scale_tile
;
6702 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
6703 opt
= tile_tests
[i
].shift_point
;
6704 isl_options_set_tile_shift_point_loops(ctx
, opt
);
6706 str
= tile_tests
[i
].domain
;
6707 domain
= isl_union_set_read_from_str(ctx
, str
);
6708 node
= isl_schedule_node_from_domain(domain
);
6709 node
= isl_schedule_node_child(node
, 0);
6710 str
= tile_tests
[i
].schedule
;
6711 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6712 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6713 str
= tile_tests
[i
].sizes
;
6714 sizes
= isl_multi_val_read_from_str(ctx
, str
);
6715 node
= isl_schedule_node_band_tile(node
, sizes
);
6717 str
= tile_tests
[i
].tile
;
6718 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6719 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
6720 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
6721 isl_multi_union_pw_aff_free(mupa
);
6722 isl_multi_union_pw_aff_free(mupa2
);
6724 node
= isl_schedule_node_child(node
, 0);
6726 str
= tile_tests
[i
].point
;
6727 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6728 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
6729 if (equal
>= 0 && equal
)
6730 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
6732 isl_multi_union_pw_aff_free(mupa
);
6733 isl_multi_union_pw_aff_free(mupa2
);
6735 isl_schedule_node_free(node
);
6740 isl_die(ctx
, isl_error_unknown
,
6741 "unexpected result", return -1);
6744 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
6745 isl_options_set_tile_shift_point_loops(ctx
, shift
);
6750 /* Check that the domain hash of a space is equal to the hash
6751 * of the domain of the space.
6753 static int test_domain_hash(isl_ctx
*ctx
)
6757 uint32_t hash1
, hash2
;
6759 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
6760 space
= isl_map_get_space(map
);
6762 hash1
= isl_space_get_domain_hash(space
);
6763 space
= isl_space_domain(space
);
6764 hash2
= isl_space_get_hash(space
);
6765 isl_space_free(space
);
6770 isl_die(ctx
, isl_error_unknown
,
6771 "domain hash not equal to hash of domain", return -1);
6776 /* Check that a universe basic set that is not obviously equal to the universe
6777 * is still recognized as being equal to the universe.
6779 static int test_universe(isl_ctx
*ctx
)
6782 isl_basic_set
*bset
;
6785 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
6786 bset
= isl_basic_set_read_from_str(ctx
, s
);
6787 is_univ
= isl_basic_set_is_universe(bset
);
6788 isl_basic_set_free(bset
);
6793 isl_die(ctx
, isl_error_unknown
,
6794 "not recognized as universe set", return -1);
6799 /* Sets for which chambers are computed and checked.
6801 const char *chambers_tests
[] = {
6802 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
6803 "z >= 0 and z <= C - y and z <= B - x - y }",
6806 /* Add the domain of "cell" to "cells".
6808 static int add_cell(__isl_take isl_cell
*cell
, void *user
)
6810 isl_basic_set_list
**cells
= user
;
6813 dom
= isl_cell_get_domain(cell
);
6814 isl_cell_free(cell
);
6815 *cells
= isl_basic_set_list_add(*cells
, dom
);
6817 return *cells
? 0 : -1;
6820 /* Check that the elements of "list" are pairwise disjoint.
6822 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
6827 return isl_stat_error
;
6829 n
= isl_basic_set_list_n_basic_set(list
);
6830 for (i
= 0; i
< n
; ++i
) {
6831 isl_basic_set
*bset_i
;
6833 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
6834 for (j
= i
+ 1; j
< n
; ++j
) {
6835 isl_basic_set
*bset_j
;
6838 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
6839 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
6840 isl_basic_set_free(bset_j
);
6842 isl_die(isl_basic_set_list_get_ctx(list
),
6843 isl_error_unknown
, "not disjoint",
6845 if (disjoint
< 0 || !disjoint
)
6848 isl_basic_set_free(bset_i
);
6850 return isl_stat_error
;
6856 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
6857 * are pairwise disjoint.
6859 static int test_chambers(isl_ctx
*ctx
)
6863 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
6864 isl_basic_set
*bset
;
6865 isl_vertices
*vertices
;
6866 isl_basic_set_list
*cells
;
6869 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
6870 vertices
= isl_basic_set_compute_vertices(bset
);
6871 cells
= isl_basic_set_list_alloc(ctx
, 0);
6872 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
6874 cells
= isl_basic_set_list_free(cells
);
6875 ok
= check_pairwise_disjoint(cells
);
6876 isl_basic_set_list_free(cells
);
6877 isl_vertices_free(vertices
);
6878 isl_basic_set_free(bset
);
6889 int (*fn
)(isl_ctx
*ctx
);
6891 { "universe", &test_universe
},
6892 { "domain hash", &test_domain_hash
},
6893 { "dual", &test_dual
},
6894 { "dependence analysis", &test_flow
},
6895 { "val", &test_val
},
6896 { "compute divs", &test_compute_divs
},
6897 { "partial lexmin", &test_partial_lexmin
},
6898 { "simplify", &test_simplify
},
6899 { "curry", &test_curry
},
6900 { "piecewise multi affine expressions", &test_pw_multi_aff
},
6901 { "multi piecewise affine expressions", &test_multi_pw_aff
},
6902 { "conversion", &test_conversion
},
6903 { "list", &test_list
},
6904 { "align parameters", &test_align_parameters
},
6905 { "preimage", &test_preimage
},
6906 { "pullback", &test_pullback
},
6907 { "AST", &test_ast
},
6908 { "AST build", &test_ast_build
},
6909 { "AST generation", &test_ast_gen
},
6910 { "eliminate", &test_eliminate
},
6911 { "residue class", &test_residue_class
},
6912 { "div", &test_div
},
6913 { "slice", &test_slice
},
6914 { "fixed power", &test_fixed_power
},
6915 { "sample", &test_sample
},
6916 { "output", &test_output
},
6917 { "vertices", &test_vertices
},
6918 { "chambers", &test_chambers
},
6919 { "fixed", &test_fixed
},
6920 { "equal", &test_equal
},
6921 { "disjoint", &test_disjoint
},
6922 { "product", &test_product
},
6923 { "dim_max", &test_dim_max
},
6924 { "affine", &test_aff
},
6925 { "injective", &test_injective
},
6926 { "schedule (whole component)", &test_schedule_whole
},
6927 { "schedule (incremental)", &test_schedule_incremental
},
6928 { "schedule tree grouping", &test_schedule_tree_group
},
6929 { "tile", &test_tile
},
6930 { "union_pw", &test_union_pw
},
6931 { "eval", &test_eval
},
6932 { "parse", &test_parse
},
6933 { "single-valued", &test_sv
},
6934 { "affine hull", &test_affine_hull
},
6935 { "simple_hull", &test_simple_hull
},
6936 { "coalesce", &test_coalesce
},
6937 { "factorize", &test_factorize
},
6938 { "subset", &test_subset
},
6939 { "subtract", &test_subtract
},
6940 { "intersect", &test_intersect
},
6941 { "lexmin", &test_lexmin
},
6942 { "min", &test_min
},
6943 { "gist", &test_gist
},
6944 { "piecewise quasi-polynomials", &test_pwqp
},
6945 { "lift", &test_lift
},
6946 { "bound", &test_bound
},
6947 { "union", &test_union
},
6948 { "split periods", &test_split_periods
},
6949 { "lexicographic order", &test_lex
},
6950 { "bijectivity", &test_bijective
},
6951 { "dataflow analysis", &test_dep
},
6952 { "reading", &test_read
},
6953 { "bounded", &test_bounded
},
6954 { "construction", &test_construction
},
6955 { "dimension manipulation", &test_dim
},
6956 { "map application", &test_application
},
6957 { "convex hull", &test_convex_hull
},
6958 { "transitive closure", &test_closure
},
6961 int main(int argc
, char **argv
)
6964 struct isl_ctx
*ctx
;
6965 struct isl_options
*options
;
6967 options
= isl_options_new_with_defaults();
6969 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
6971 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
6972 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
6973 printf("%s\n", tests
[i
].name
);
6974 if (tests
[i
].fn(ctx
) < 0)