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_1(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 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
347 isl_int_set_si(v
, 1);
348 c
= 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 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
354 isl_int_set_si(v
, -5);
355 c
= 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 /* Construct the basic set { [x] : -100 <= x <= 100 }
367 * using isl_basic_set_{lower,upper}_bound_val and
368 * check that it is equal the same basic set parsed from a string.
370 static int test_construction_2(isl_ctx
*ctx
)
375 isl_basic_set
*bset1
, *bset2
;
377 v
= isl_val_int_from_si(ctx
, 100);
378 space
= isl_space_set_alloc(ctx
, 0, 1);
379 bset1
= isl_basic_set_universe(space
);
380 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
382 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
384 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
385 equal
= isl_basic_set_is_equal(bset1
, bset2
);
386 isl_basic_set_free(bset1
);
387 isl_basic_set_free(bset2
);
392 isl_die(ctx
, isl_error_unknown
,
393 "failed construction", return -1);
398 /* Basic tests for constructing basic sets.
400 static int test_construction(isl_ctx
*ctx
)
402 if (test_construction_1(ctx
) < 0)
404 if (test_construction_2(ctx
) < 0)
409 static int test_dim(isl_ctx
*ctx
)
412 isl_map
*map1
, *map2
;
415 map1
= isl_map_read_from_str(ctx
,
416 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
417 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
418 map2
= isl_map_read_from_str(ctx
,
419 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
420 equal
= isl_map_is_equal(map1
, map2
);
423 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
424 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
425 if (equal
>= 0 && equal
)
426 equal
= isl_map_is_equal(map1
, map2
);
434 isl_die(ctx
, isl_error_unknown
,
435 "unexpected result", return -1);
437 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
438 map1
= isl_map_read_from_str(ctx
, str
);
439 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
440 map2
= isl_map_read_from_str(ctx
, str
);
441 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
442 equal
= isl_map_is_equal(map1
, map2
);
449 isl_die(ctx
, isl_error_unknown
,
450 "unexpected result", return -1);
456 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
460 { &isl_val_neg
, "0", "0" },
461 { &isl_val_abs
, "0", "0" },
462 { &isl_val_2exp
, "0", "1" },
463 { &isl_val_floor
, "0", "0" },
464 { &isl_val_ceil
, "0", "0" },
465 { &isl_val_neg
, "1", "-1" },
466 { &isl_val_neg
, "-1", "1" },
467 { &isl_val_neg
, "1/2", "-1/2" },
468 { &isl_val_neg
, "-1/2", "1/2" },
469 { &isl_val_neg
, "infty", "-infty" },
470 { &isl_val_neg
, "-infty", "infty" },
471 { &isl_val_neg
, "NaN", "NaN" },
472 { &isl_val_abs
, "1", "1" },
473 { &isl_val_abs
, "-1", "1" },
474 { &isl_val_abs
, "1/2", "1/2" },
475 { &isl_val_abs
, "-1/2", "1/2" },
476 { &isl_val_abs
, "infty", "infty" },
477 { &isl_val_abs
, "-infty", "infty" },
478 { &isl_val_abs
, "NaN", "NaN" },
479 { &isl_val_floor
, "1", "1" },
480 { &isl_val_floor
, "-1", "-1" },
481 { &isl_val_floor
, "1/2", "0" },
482 { &isl_val_floor
, "-1/2", "-1" },
483 { &isl_val_floor
, "infty", "infty" },
484 { &isl_val_floor
, "-infty", "-infty" },
485 { &isl_val_floor
, "NaN", "NaN" },
486 { &isl_val_ceil
, "1", "1" },
487 { &isl_val_ceil
, "-1", "-1" },
488 { &isl_val_ceil
, "1/2", "1" },
489 { &isl_val_ceil
, "-1/2", "0" },
490 { &isl_val_ceil
, "infty", "infty" },
491 { &isl_val_ceil
, "-infty", "-infty" },
492 { &isl_val_ceil
, "NaN", "NaN" },
493 { &isl_val_2exp
, "-3", "1/8" },
494 { &isl_val_2exp
, "-1", "1/2" },
495 { &isl_val_2exp
, "1", "2" },
496 { &isl_val_2exp
, "2", "4" },
497 { &isl_val_2exp
, "3", "8" },
498 { &isl_val_inv
, "1", "1" },
499 { &isl_val_inv
, "2", "1/2" },
500 { &isl_val_inv
, "1/2", "2" },
501 { &isl_val_inv
, "-2", "-1/2" },
502 { &isl_val_inv
, "-1/2", "-2" },
503 { &isl_val_inv
, "0", "NaN" },
504 { &isl_val_inv
, "NaN", "NaN" },
505 { &isl_val_inv
, "infty", "0" },
506 { &isl_val_inv
, "-infty", "0" },
509 /* Perform some basic tests of unary operations on isl_val objects.
511 static int test_un_val(isl_ctx
*ctx
)
515 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
518 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
519 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
520 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
521 fn
= val_un_tests
[i
].op
;
523 if (isl_val_is_nan(res
))
524 ok
= isl_val_is_nan(v
);
526 ok
= isl_val_eq(v
, res
);
532 isl_die(ctx
, isl_error_unknown
,
533 "unexpected result", return -1);
540 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
541 __isl_take isl_val
*v2
);
543 ['+'] = { &isl_val_add
},
544 ['-'] = { &isl_val_sub
},
545 ['*'] = { &isl_val_mul
},
546 ['/'] = { &isl_val_div
},
547 ['g'] = { &isl_val_gcd
},
548 ['m'] = { &isl_val_min
},
549 ['M'] = { &isl_val_max
},
557 } val_bin_tests
[] = {
558 { "0", '+', "0", "0" },
559 { "1", '+', "0", "1" },
560 { "1", '+', "1", "2" },
561 { "1", '-', "1", "0" },
562 { "1", '*', "1", "1" },
563 { "1", '/', "1", "1" },
564 { "2", '*', "3", "6" },
565 { "2", '*', "1/2", "1" },
566 { "2", '*', "1/3", "2/3" },
567 { "2/3", '*', "3/5", "2/5" },
568 { "2/3", '*', "7/5", "14/15" },
569 { "2", '/', "1/2", "4" },
570 { "-2", '/', "-1/2", "4" },
571 { "-2", '/', "1/2", "-4" },
572 { "2", '/', "-1/2", "-4" },
573 { "2", '/', "2", "1" },
574 { "2", '/', "3", "2/3" },
575 { "2/3", '/', "5/3", "2/5" },
576 { "2/3", '/', "5/7", "14/15" },
577 { "0", '/', "0", "NaN" },
578 { "42", '/', "0", "NaN" },
579 { "-42", '/', "0", "NaN" },
580 { "infty", '/', "0", "NaN" },
581 { "-infty", '/', "0", "NaN" },
582 { "NaN", '/', "0", "NaN" },
583 { "0", '/', "NaN", "NaN" },
584 { "42", '/', "NaN", "NaN" },
585 { "-42", '/', "NaN", "NaN" },
586 { "infty", '/', "NaN", "NaN" },
587 { "-infty", '/', "NaN", "NaN" },
588 { "NaN", '/', "NaN", "NaN" },
589 { "0", '/', "infty", "0" },
590 { "42", '/', "infty", "0" },
591 { "-42", '/', "infty", "0" },
592 { "infty", '/', "infty", "NaN" },
593 { "-infty", '/', "infty", "NaN" },
594 { "NaN", '/', "infty", "NaN" },
595 { "0", '/', "-infty", "0" },
596 { "42", '/', "-infty", "0" },
597 { "-42", '/', "-infty", "0" },
598 { "infty", '/', "-infty", "NaN" },
599 { "-infty", '/', "-infty", "NaN" },
600 { "NaN", '/', "-infty", "NaN" },
601 { "1", '-', "1/3", "2/3" },
602 { "1/3", '+', "1/2", "5/6" },
603 { "1/2", '+', "1/2", "1" },
604 { "3/4", '-', "1/4", "1/2" },
605 { "1/2", '-', "1/3", "1/6" },
606 { "infty", '+', "42", "infty" },
607 { "infty", '+', "infty", "infty" },
608 { "42", '+', "infty", "infty" },
609 { "infty", '-', "infty", "NaN" },
610 { "infty", '*', "infty", "infty" },
611 { "infty", '*', "-infty", "-infty" },
612 { "-infty", '*', "infty", "-infty" },
613 { "-infty", '*', "-infty", "infty" },
614 { "0", '*', "infty", "NaN" },
615 { "1", '*', "infty", "infty" },
616 { "infty", '*', "0", "NaN" },
617 { "infty", '*', "42", "infty" },
618 { "42", '-', "infty", "-infty" },
619 { "infty", '+', "-infty", "NaN" },
620 { "4", 'g', "6", "2" },
621 { "5", 'g', "6", "1" },
622 { "42", 'm', "3", "3" },
623 { "42", 'M', "3", "42" },
624 { "3", 'm', "42", "3" },
625 { "3", 'M', "42", "42" },
626 { "42", 'm', "infty", "42" },
627 { "42", 'M', "infty", "infty" },
628 { "42", 'm', "-infty", "-infty" },
629 { "42", 'M', "-infty", "42" },
630 { "42", 'm', "NaN", "NaN" },
631 { "42", 'M', "NaN", "NaN" },
632 { "infty", 'm', "-infty", "-infty" },
633 { "infty", 'M', "-infty", "infty" },
636 /* Perform some basic tests of binary operations on isl_val objects.
638 static int test_bin_val(isl_ctx
*ctx
)
641 isl_val
*v1
, *v2
, *res
;
642 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
643 __isl_take isl_val
*v2
);
646 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
647 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
648 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
649 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
650 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
652 if (isl_val_is_nan(res
))
653 ok
= isl_val_is_nan(v1
);
655 ok
= isl_val_eq(v1
, res
);
661 isl_die(ctx
, isl_error_unknown
,
662 "unexpected result", return -1);
668 /* Perform some basic tests on isl_val objects.
670 static int test_val(isl_ctx
*ctx
)
672 if (test_un_val(ctx
) < 0)
674 if (test_bin_val(ctx
) < 0)
679 /* Sets described using existentially quantified variables that
680 * can also be described without.
682 static const char *elimination_tests
[] = {
683 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
684 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
685 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
688 /* Check that redundant existentially quantified variables are
691 static int test_elimination(isl_ctx
*ctx
)
697 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
698 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
699 n
= isl_basic_set_dim(bset
, isl_dim_div
);
700 isl_basic_set_free(bset
);
704 isl_die(ctx
, isl_error_unknown
,
705 "expecting no existentials", return -1);
711 static int test_div(isl_ctx
*ctx
)
719 struct isl_basic_set
*bset
;
720 struct isl_constraint
*c
;
725 dim
= isl_space_set_alloc(ctx
, 0, 3);
726 bset
= isl_basic_set_universe(isl_space_copy(dim
));
727 ls
= isl_local_space_from_space(dim
);
729 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
730 isl_int_set_si(v
, -1);
731 c
= isl_constraint_set_constant(c
, v
);
732 isl_int_set_si(v
, 1);
733 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
734 isl_int_set_si(v
, 3);
735 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
736 bset
= isl_basic_set_add_constraint(bset
, c
);
738 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
739 isl_int_set_si(v
, 1);
740 c
= isl_constraint_set_constant(c
, v
);
741 isl_int_set_si(v
, -1);
742 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
743 isl_int_set_si(v
, 3);
744 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
745 bset
= isl_basic_set_add_constraint(bset
, c
);
747 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
749 assert(bset
&& bset
->n_div
== 1);
750 isl_local_space_free(ls
);
751 isl_basic_set_free(bset
);
754 dim
= isl_space_set_alloc(ctx
, 0, 3);
755 bset
= isl_basic_set_universe(isl_space_copy(dim
));
756 ls
= isl_local_space_from_space(dim
);
758 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
759 isl_int_set_si(v
, 1);
760 c
= isl_constraint_set_constant(c
, v
);
761 isl_int_set_si(v
, -1);
762 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
763 isl_int_set_si(v
, 3);
764 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
765 bset
= isl_basic_set_add_constraint(bset
, c
);
767 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
768 isl_int_set_si(v
, -1);
769 c
= isl_constraint_set_constant(c
, v
);
770 isl_int_set_si(v
, 1);
771 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
772 isl_int_set_si(v
, 3);
773 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
774 bset
= isl_basic_set_add_constraint(bset
, c
);
776 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
778 assert(bset
&& bset
->n_div
== 1);
779 isl_local_space_free(ls
);
780 isl_basic_set_free(bset
);
783 dim
= isl_space_set_alloc(ctx
, 0, 3);
784 bset
= isl_basic_set_universe(isl_space_copy(dim
));
785 ls
= isl_local_space_from_space(dim
);
787 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
788 isl_int_set_si(v
, 1);
789 c
= isl_constraint_set_constant(c
, v
);
790 isl_int_set_si(v
, -1);
791 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
792 isl_int_set_si(v
, 3);
793 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
794 bset
= isl_basic_set_add_constraint(bset
, c
);
796 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
797 isl_int_set_si(v
, -3);
798 c
= isl_constraint_set_constant(c
, v
);
799 isl_int_set_si(v
, 1);
800 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
801 isl_int_set_si(v
, 4);
802 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
803 bset
= isl_basic_set_add_constraint(bset
, c
);
805 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
807 assert(bset
&& bset
->n_div
== 1);
808 isl_local_space_free(ls
);
809 isl_basic_set_free(bset
);
812 dim
= isl_space_set_alloc(ctx
, 0, 3);
813 bset
= isl_basic_set_universe(isl_space_copy(dim
));
814 ls
= isl_local_space_from_space(dim
);
816 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
817 isl_int_set_si(v
, 2);
818 c
= isl_constraint_set_constant(c
, v
);
819 isl_int_set_si(v
, -1);
820 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
821 isl_int_set_si(v
, 3);
822 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
823 bset
= isl_basic_set_add_constraint(bset
, c
);
825 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
826 isl_int_set_si(v
, -1);
827 c
= isl_constraint_set_constant(c
, v
);
828 isl_int_set_si(v
, 1);
829 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
830 isl_int_set_si(v
, 6);
831 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
832 bset
= isl_basic_set_add_constraint(bset
, c
);
834 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
836 assert(isl_basic_set_is_empty(bset
));
837 isl_local_space_free(ls
);
838 isl_basic_set_free(bset
);
841 dim
= isl_space_set_alloc(ctx
, 0, 3);
842 bset
= isl_basic_set_universe(isl_space_copy(dim
));
843 ls
= isl_local_space_from_space(dim
);
845 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
846 isl_int_set_si(v
, -1);
847 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
848 isl_int_set_si(v
, 3);
849 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
850 bset
= isl_basic_set_add_constraint(bset
, c
);
852 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
853 isl_int_set_si(v
, 1);
854 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
855 isl_int_set_si(v
, -3);
856 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
857 bset
= isl_basic_set_add_constraint(bset
, c
);
859 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
861 assert(bset
&& bset
->n_div
== 0);
862 isl_basic_set_free(bset
);
863 isl_local_space_free(ls
);
866 dim
= isl_space_set_alloc(ctx
, 0, 3);
867 bset
= isl_basic_set_universe(isl_space_copy(dim
));
868 ls
= isl_local_space_from_space(dim
);
870 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
871 isl_int_set_si(v
, -1);
872 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
873 isl_int_set_si(v
, 6);
874 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
875 bset
= isl_basic_set_add_constraint(bset
, c
);
877 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
878 isl_int_set_si(v
, 1);
879 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
880 isl_int_set_si(v
, -3);
881 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
882 bset
= isl_basic_set_add_constraint(bset
, c
);
884 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
886 assert(bset
&& bset
->n_div
== 1);
887 isl_basic_set_free(bset
);
888 isl_local_space_free(ls
);
891 /* This test is a bit tricky. We set up an equality
893 * Normalization of divs creates _two_ divs
896 * Afterwards e0 is removed again because it has coefficient -1
897 * and we end up with the original equality and div again.
898 * Perhaps we can avoid the introduction of this temporary div.
900 dim
= isl_space_set_alloc(ctx
, 0, 4);
901 bset
= isl_basic_set_universe(isl_space_copy(dim
));
902 ls
= isl_local_space_from_space(dim
);
904 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
905 isl_int_set_si(v
, -1);
906 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
907 isl_int_set_si(v
, -3);
908 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
909 isl_int_set_si(v
, -3);
910 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
911 isl_int_set_si(v
, 6);
912 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
913 bset
= isl_basic_set_add_constraint(bset
, c
);
915 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
917 /* Test disabled for now */
919 assert(bset && bset->n_div == 1);
921 isl_local_space_free(ls
);
922 isl_basic_set_free(bset
);
925 dim
= isl_space_set_alloc(ctx
, 0, 5);
926 bset
= isl_basic_set_universe(isl_space_copy(dim
));
927 ls
= isl_local_space_from_space(dim
);
929 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
930 isl_int_set_si(v
, -1);
931 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
932 isl_int_set_si(v
, -3);
933 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
934 isl_int_set_si(v
, -3);
935 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
936 isl_int_set_si(v
, 6);
937 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
938 bset
= isl_basic_set_add_constraint(bset
, c
);
940 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
941 isl_int_set_si(v
, -1);
942 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
943 isl_int_set_si(v
, 1);
944 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
945 isl_int_set_si(v
, 1);
946 c
= isl_constraint_set_constant(c
, v
);
947 bset
= isl_basic_set_add_constraint(bset
, c
);
949 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
951 /* Test disabled for now */
953 assert(bset && bset->n_div == 1);
955 isl_local_space_free(ls
);
956 isl_basic_set_free(bset
);
959 dim
= isl_space_set_alloc(ctx
, 0, 4);
960 bset
= isl_basic_set_universe(isl_space_copy(dim
));
961 ls
= isl_local_space_from_space(dim
);
963 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
964 isl_int_set_si(v
, 1);
965 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
966 isl_int_set_si(v
, -1);
967 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
968 isl_int_set_si(v
, -2);
969 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
970 bset
= isl_basic_set_add_constraint(bset
, c
);
972 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
973 isl_int_set_si(v
, -1);
974 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
975 isl_int_set_si(v
, 3);
976 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
977 isl_int_set_si(v
, 2);
978 c
= isl_constraint_set_constant(c
, v
);
979 bset
= isl_basic_set_add_constraint(bset
, c
);
981 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
983 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
985 assert(!isl_basic_set_is_empty(bset
));
987 isl_local_space_free(ls
);
988 isl_basic_set_free(bset
);
991 dim
= isl_space_set_alloc(ctx
, 0, 3);
992 bset
= isl_basic_set_universe(isl_space_copy(dim
));
993 ls
= isl_local_space_from_space(dim
);
995 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
996 isl_int_set_si(v
, 1);
997 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
998 isl_int_set_si(v
, -2);
999 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
1000 bset
= isl_basic_set_add_constraint(bset
, c
);
1002 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1004 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1006 isl_local_space_free(ls
);
1007 isl_basic_set_free(bset
);
1011 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1012 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1013 set
= isl_set_read_from_str(ctx
, str
);
1014 set
= isl_set_compute_divs(set
);
1019 if (test_elimination(ctx
) < 0)
1022 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1023 set
= isl_set_read_from_str(ctx
, str
);
1024 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1025 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1026 empty
= isl_set_is_empty(set
);
1031 isl_die(ctx
, isl_error_unknown
,
1032 "result not as accurate as expected", return -1);
1037 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1041 struct isl_basic_set
*bset1
, *bset2
;
1042 struct isl_basic_map
*bmap
;
1044 filename
= get_filename(ctx
, name
, "omega");
1046 input
= fopen(filename
, "r");
1049 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1050 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1052 bset1
= isl_basic_set_apply(bset1
, bmap
);
1054 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1056 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1058 isl_basic_set_free(bset1
);
1059 isl_basic_set_free(bset2
);
1065 static int test_application(isl_ctx
*ctx
)
1067 test_application_case(ctx
, "application");
1068 test_application_case(ctx
, "application2");
1073 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1077 struct isl_basic_set
*bset1
, *bset2
;
1079 filename
= get_filename(ctx
, name
, "polylib");
1081 input
= fopen(filename
, "r");
1084 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1085 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1087 bset1
= isl_basic_set_affine_hull(bset1
);
1089 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1091 isl_basic_set_free(bset1
);
1092 isl_basic_set_free(bset2
);
1098 int test_affine_hull(struct isl_ctx
*ctx
)
1102 isl_basic_set
*bset
, *bset2
;
1106 test_affine_hull_case(ctx
, "affine2");
1107 test_affine_hull_case(ctx
, "affine");
1108 test_affine_hull_case(ctx
, "affine3");
1110 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1111 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1112 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1113 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1114 set
= isl_set_read_from_str(ctx
, str
);
1115 bset
= isl_set_affine_hull(set
);
1116 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1117 isl_basic_set_free(bset
);
1119 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1122 /* Check that isl_map_affine_hull is not confused by
1123 * the reordering of divs in isl_map_align_divs.
1125 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1126 "32e0 = b and 32e1 = c); "
1127 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1128 set
= isl_set_read_from_str(ctx
, str
);
1129 bset
= isl_set_affine_hull(set
);
1130 isl_basic_set_free(bset
);
1134 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1135 "32e2 = 31 + 31e0 }";
1136 set
= isl_set_read_from_str(ctx
, str
);
1137 bset
= isl_set_affine_hull(set
);
1138 str
= "{ [a] : exists e : a = 32 e }";
1139 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1140 subset
= isl_basic_set_is_subset(bset
, bset2
);
1141 isl_basic_set_free(bset
);
1142 isl_basic_set_free(bset2
);
1146 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1152 /* Pairs of maps and the corresponding expected results of
1153 * isl_map_plain_unshifted_simple_hull.
1158 } plain_unshifted_simple_hull_tests
[] = {
1159 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1160 "{ [i] -> [j] : i >= 1 }" },
1161 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1162 "(j mod 4 = 2 and k mod 6 = n) }",
1163 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1166 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1168 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1172 isl_basic_map
*hull
, *expected
;
1175 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1177 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1178 map
= isl_map_read_from_str(ctx
, str
);
1179 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1180 expected
= isl_basic_map_read_from_str(ctx
, str
);
1181 hull
= isl_map_plain_unshifted_simple_hull(map
);
1182 equal
= isl_basic_map_is_equal(hull
, expected
);
1183 isl_basic_map_free(hull
);
1184 isl_basic_map_free(expected
);
1188 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1195 /* Pairs of sets and the corresponding expected results of
1196 * isl_set_unshifted_simple_hull.
1201 } unshifted_simple_hull_tests
[] = {
1202 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1203 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1206 /* Basic tests for isl_set_unshifted_simple_hull.
1208 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1212 isl_basic_set
*hull
, *expected
;
1215 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1217 str
= unshifted_simple_hull_tests
[i
].set
;
1218 set
= isl_set_read_from_str(ctx
, str
);
1219 str
= unshifted_simple_hull_tests
[i
].hull
;
1220 expected
= isl_basic_set_read_from_str(ctx
, str
);
1221 hull
= isl_set_unshifted_simple_hull(set
);
1222 equal
= isl_basic_set_is_equal(hull
, expected
);
1223 isl_basic_set_free(hull
);
1224 isl_basic_set_free(expected
);
1228 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1235 static int test_simple_hull(struct isl_ctx
*ctx
)
1239 isl_basic_set
*bset
;
1242 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1243 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1244 set
= isl_set_read_from_str(ctx
, str
);
1245 bset
= isl_set_simple_hull(set
);
1246 is_empty
= isl_basic_set_is_empty(bset
);
1247 isl_basic_set_free(bset
);
1249 if (is_empty
== isl_bool_error
)
1252 if (is_empty
== isl_bool_false
)
1253 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1256 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1258 if (test_unshifted_simple_hull(ctx
) < 0)
1264 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1268 struct isl_basic_set
*bset1
, *bset2
;
1269 struct isl_set
*set
;
1271 filename
= get_filename(ctx
, name
, "polylib");
1273 input
= fopen(filename
, "r");
1276 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1277 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1279 set
= isl_basic_set_union(bset1
, bset2
);
1280 bset1
= isl_set_convex_hull(set
);
1282 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1284 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1286 isl_basic_set_free(bset1
);
1287 isl_basic_set_free(bset2
);
1296 } convex_hull_tests
[] = {
1297 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1298 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1299 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1300 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1301 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1302 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1303 "i2 <= 5 and i2 >= 4; "
1304 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1305 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1306 "i2 <= 5 + i0 and i2 >= i0 }" },
1307 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1308 "{ [x, y] : 1 = 0 }" },
1309 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1310 "[x, y, 0] : x >= 0 and y < 0 }",
1311 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1314 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1317 int orig_convex
= ctx
->opt
->convex
;
1318 ctx
->opt
->convex
= convex
;
1320 test_convex_hull_case(ctx
, "convex0");
1321 test_convex_hull_case(ctx
, "convex1");
1322 test_convex_hull_case(ctx
, "convex2");
1323 test_convex_hull_case(ctx
, "convex3");
1324 test_convex_hull_case(ctx
, "convex4");
1325 test_convex_hull_case(ctx
, "convex5");
1326 test_convex_hull_case(ctx
, "convex6");
1327 test_convex_hull_case(ctx
, "convex7");
1328 test_convex_hull_case(ctx
, "convex8");
1329 test_convex_hull_case(ctx
, "convex9");
1330 test_convex_hull_case(ctx
, "convex10");
1331 test_convex_hull_case(ctx
, "convex11");
1332 test_convex_hull_case(ctx
, "convex12");
1333 test_convex_hull_case(ctx
, "convex13");
1334 test_convex_hull_case(ctx
, "convex14");
1335 test_convex_hull_case(ctx
, "convex15");
1337 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1338 isl_set
*set1
, *set2
;
1341 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1342 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1343 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1344 equal
= isl_set_is_equal(set1
, set2
);
1351 isl_die(ctx
, isl_error_unknown
,
1352 "unexpected convex hull", return -1);
1355 ctx
->opt
->convex
= orig_convex
;
1360 static int test_convex_hull(isl_ctx
*ctx
)
1362 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1364 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1369 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1373 struct isl_basic_set
*bset1
, *bset2
;
1375 filename
= get_filename(ctx
, name
, "polylib");
1377 input
= fopen(filename
, "r");
1380 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1381 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1383 bset1
= isl_basic_set_gist(bset1
, bset2
);
1385 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1387 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1389 isl_basic_set_free(bset1
);
1390 isl_basic_set_free(bset2
);
1396 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1400 const char *context
;
1402 } plain_gist_tests
[] = {
1403 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1404 "{ [i] -> [j] : i >= 1 }",
1405 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1406 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1407 "(j mod 4 = 2 and k mod 6 = n) }",
1408 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1409 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1410 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1411 "{ [i] -> [j] : i > j }",
1412 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1415 /* Basic tests for isl_map_plain_gist_basic_map.
1417 static int test_plain_gist(isl_ctx
*ctx
)
1421 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1424 isl_map
*map
, *gist
;
1425 isl_basic_map
*context
;
1427 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1428 str
= plain_gist_tests
[i
].context
;
1429 context
= isl_basic_map_read_from_str(ctx
, str
);
1430 map
= isl_map_plain_gist_basic_map(map
, context
);
1431 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1432 equal
= isl_map_is_equal(map
, gist
);
1438 isl_die(ctx
, isl_error_unknown
,
1439 "incorrect gist result", return -1);
1447 const char *context
;
1450 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1451 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1452 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1453 "{ [a, b, c] : a <= 15 }" },
1454 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1455 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1456 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1457 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1458 { "{ [m, n, a, b] : a <= 2147 + n }",
1459 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1460 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1461 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1463 "{ [m, n, ku, kl] }" },
1464 { "{ [a, a, b] : a >= 10 }",
1465 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1466 "{ [a, a, b] : a >= 10 }" },
1467 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1468 "{ [0, j] : j >= 0 }" },
1469 /* Check that no constraints on i6 are introduced in the gist */
1470 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1471 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1472 "5e0 <= 381 - t1 and i4 <= 1) }",
1473 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1474 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1475 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1476 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1477 "20e0 >= 1511 - 4t1 - 5i4) }" },
1478 /* Check that no constraints on i6 are introduced in the gist */
1479 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1480 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1481 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1482 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1483 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1484 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1485 "20e1 <= 1530 - 4t1 - 5i4 and "
1486 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1487 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1488 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1489 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1490 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1491 "10e0 <= -91 + 5i4 + 4i6 and "
1492 "10e0 >= -105 + 5i4 + 4i6) }",
1493 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1494 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1495 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1496 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1497 "{ [a, b, q, p] : b >= 1 + a }",
1498 "{ [a, b, q, p] : false }" },
1499 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1500 "[n] -> { [x] : x mod 32 = 0 }",
1501 "[n] -> { [x = n] }" },
1502 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1503 "{ [x] : x mod 2 = 0 }" },
1504 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1505 "{ [x] : x mod 128 = 0 }" },
1506 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1507 "{ [x] : x mod 3200 = 0 }" },
1508 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1509 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1510 "{ [a, b, c = a] }" },
1511 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1512 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1513 "{ [a, b, c = a] : a mod 3 = 0 }" },
1514 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1515 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1517 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1518 "{ [x,y] : 1 <= y <= 3 }",
1522 /* Check that isl_set_gist behaves as expected.
1524 * For the test cases in gist_tests, besides checking that the result
1525 * is as expected, also check that applying the gist operation does
1526 * not modify the input set (an earlier version of isl would do that) and
1527 * that the test case is consistent, i.e., that the gist has the same
1528 * intersection with the context as the input set.
1530 static int test_gist(struct isl_ctx
*ctx
)
1534 isl_basic_set
*bset1
, *bset2
;
1535 isl_map
*map1
, *map2
;
1538 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1539 int equal_input
, equal_intersection
;
1540 isl_set
*set1
, *set2
, *copy
, *context
;
1542 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1543 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1544 copy
= isl_set_copy(set1
);
1545 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1546 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1547 equal
= isl_set_is_equal(set1
, set2
);
1549 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1550 equal_input
= isl_set_is_equal(set1
, copy
);
1552 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1553 set2
= isl_set_intersect(set2
, context
);
1554 equal_intersection
= isl_set_is_equal(set1
, set2
);
1557 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1560 isl_die(ctx
, isl_error_unknown
,
1561 "incorrect gist result", return -1);
1563 isl_die(ctx
, isl_error_unknown
,
1564 "gist modified input", return -1);
1566 isl_die(ctx
, isl_error_unknown
,
1567 "inconsistent gist test case", return -1);
1570 test_gist_case(ctx
, "gist1");
1572 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1573 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1574 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1575 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1576 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1577 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1578 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1579 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1580 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1581 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1582 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1583 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1584 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1585 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1586 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1587 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1588 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1589 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1590 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1591 bset1
= isl_basic_set_gist(bset1
, bset2
);
1592 assert(bset1
&& bset1
->n_div
== 0);
1593 isl_basic_set_free(bset1
);
1595 /* Check that the integer divisions of the second disjunct
1596 * do not spread to the first disjunct.
1598 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1599 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1600 "(exists (e0 = [(-1 + t1)/16], "
1601 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1602 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1603 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1604 "o0 <= 4294967295 and t1 <= -1)) }";
1605 map1
= isl_map_read_from_str(ctx
, str
);
1606 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1607 map2
= isl_map_read_from_str(ctx
, str
);
1608 map1
= isl_map_gist(map1
, map2
);
1612 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1613 isl_map_free(map1
); return -1);
1614 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1615 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1616 isl_map_free(map1
); return -1);
1619 if (test_plain_gist(ctx
) < 0)
1625 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1627 isl_set
*set
, *set2
;
1631 set
= isl_set_read_from_str(ctx
, str
);
1632 set
= isl_set_coalesce(set
);
1633 set2
= isl_set_read_from_str(ctx
, str
);
1634 equal
= isl_set_is_equal(set
, set2
);
1635 one
= set
&& set
->n
== 1;
1642 isl_die(ctx
, isl_error_unknown
,
1643 "coalesced set not equal to input", return -1);
1644 if (check_one
&& !one
)
1645 isl_die(ctx
, isl_error_unknown
,
1646 "coalesced set should not be a union", return -1);
1651 /* Inputs for coalescing tests with unbounded wrapping.
1652 * "str" is a string representation of the input set.
1653 * "single_disjunct" is set if we expect the result to consist of
1654 * a single disjunct.
1657 int single_disjunct
;
1659 } coalesce_unbounded_tests
[] = {
1660 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1661 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1662 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1663 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1665 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1666 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1667 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1668 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1671 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1672 * option turned off.
1674 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1680 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1681 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1683 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1684 const char *str
= coalesce_unbounded_tests
[i
].str
;
1685 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1686 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1692 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1697 /* Inputs for coalescing tests.
1698 * "str" is a string representation of the input set.
1699 * "single_disjunct" is set if we expect the result to consist of
1700 * a single disjunct.
1703 int single_disjunct
;
1705 } coalesce_tests
[] = {
1706 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1707 "y >= x & x >= 2 & 5 >= y }" },
1708 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1709 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1710 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1711 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1712 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1713 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1714 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1715 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1716 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1717 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1718 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1719 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1720 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1721 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1722 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1723 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1724 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1725 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1726 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1727 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1728 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1729 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1730 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1731 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1732 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1733 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1734 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1735 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1736 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1737 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1738 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1739 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1740 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1741 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1742 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1743 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1744 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1745 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1746 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1747 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1748 "[o0, o1, o2, o3, o4, o5, o6]] : "
1749 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1750 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1751 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1752 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1753 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1754 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1755 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1756 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1757 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1758 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1759 "o6 >= i3 + i6 - o3 and M >= 0 and "
1760 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1761 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1762 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1763 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1764 "(o0 = 0 and M >= 2 and N >= 3) or "
1765 "(M = 0 and o0 = 0 and N >= 3) }" },
1766 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1767 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1768 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1769 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1770 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1771 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1772 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1773 "(y = 3 and x = 1) }" },
1774 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1775 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1776 "i1 <= M and i3 <= M and i4 <= M) or "
1777 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1778 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1779 "i4 <= -1 + M) }" },
1780 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1781 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1782 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1783 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1784 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1785 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1786 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1787 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1788 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1789 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1790 { 0, "{ [a, b] : exists e : 2e = a and "
1791 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1792 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1793 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1794 "j >= 1 and j' <= i + j - i' and i >= 1; "
1796 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1797 "[i,j] : exists a : j = 3a }" },
1798 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1799 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1801 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1802 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1803 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1804 "c <= 6 + 8a and a >= 3; "
1805 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1806 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1807 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1808 "[x,0] : 3 <= x <= 4 }" },
1809 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1810 "[x,0] : 4 <= x <= 5 }" },
1811 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1812 "[x,0] : 3 <= x <= 5 }" },
1813 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1814 "[x,0] : 3 <= x <= 4 }" },
1815 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1817 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1818 { 1, "{ [0,0]; [1,1] }" },
1819 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1820 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1822 "[k, 0, k] : k <= 6 and k >= 1 }" },
1823 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1824 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1825 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1826 { 1, "[n] -> { [1] : n >= 0;"
1827 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1828 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1829 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1830 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1831 "2e0 <= x and 2e0 <= n);"
1832 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1834 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1835 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1836 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1838 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1839 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1841 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1842 "t1 >= 13 and t1 <= 16);"
1843 "[t1] : t1 <= 15 and t1 >= 12 }" },
1844 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1845 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1846 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1847 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1848 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1849 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1851 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1852 "(exists (e0 : 3e0 = -2 + c0)) }" },
1853 { 0, "[n, b0, t0] -> "
1854 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1855 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1856 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1857 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1858 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
1859 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
1860 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
1861 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
1862 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1863 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1864 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1865 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
1866 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
1867 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
1868 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
1869 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
1870 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
1871 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
1872 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
1873 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
1874 { 0, "{ [i0, i1, i2] : "
1875 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
1876 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
1877 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
1878 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
1879 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
1880 "32e0 <= 31 + i0)) or "
1882 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
1883 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
1884 "2*floor((c)/2) = c and 0 <= a <= 192;"
1885 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
1887 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
1888 "(0 <= a <= b <= n) }" },
1889 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
1890 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
1891 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
1892 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
1893 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1894 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
1895 "b = 3 and 9e0 <= -19 + 2c)) }" },
1896 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
1897 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1898 "(a = 4 and b = 3 and "
1899 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
1900 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
1901 "(b = -1 + a and 0 < a <= 3 and "
1902 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1903 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
1904 "b = 3 and 9e0 <= -19 + 2c)) }" },
1905 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
1907 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
1909 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
1910 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
1911 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
1912 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
1913 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
1914 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
1915 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
1916 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
1917 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
1918 { 1, "{ [a] : a <= 8 and "
1919 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
1920 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
1921 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
1922 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
1923 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
1924 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
1925 "(a < 0 and 3*floor((a)/3) < a) }" },
1926 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
1927 "(a < -1 and 3*floor((a)/3) < a) }" },
1928 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
1929 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
1930 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
1931 "or (2 <= a <= 15 and b < a)) }" },
1932 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
1933 "32*floor((a)/32) < a) or a <= 15) }" },
1934 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
1935 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
1936 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
1937 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
1938 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
1939 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
1940 "S_0[n] : n <= m <= 2 + n }" },
1941 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
1942 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
1944 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
1945 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
1946 "2e0 < -a + 2b) }" },
1947 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
1948 "[i, 0, i] : 0 <= i <= 7 }" },
1951 /* A specialized coalescing test case that would result
1952 * in a segmentation fault or a failed assertion in earlier versions of isl.
1954 static int test_coalesce_special(struct isl_ctx
*ctx
)
1957 isl_map
*map1
, *map2
;
1959 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1960 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
1961 "(y = 201 and o1 <= 239 and o1 >= 212) or "
1962 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
1963 "o1 <= 239 and o1 >= 212)) or "
1964 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
1965 "o1 <= 241 and o1 >= 240));"
1966 "[S_L220_OUT[] -> T7[]] -> "
1967 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
1968 "(y = 2 and o1 <= 241 and o1 >= 212) or "
1969 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
1970 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
1971 map1
= isl_map_read_from_str(ctx
, str
);
1972 map1
= isl_map_align_divs_internal(map1
);
1973 map1
= isl_map_coalesce(map1
);
1974 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1975 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
1976 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
1977 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
1978 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
1979 map2
= isl_map_read_from_str(ctx
, str
);
1980 map2
= isl_map_union(map2
, map1
);
1981 map2
= isl_map_align_divs_internal(map2
);
1982 map2
= isl_map_coalesce(map2
);
1990 /* A specialized coalescing test case that would result in an assertion
1991 * in an earlier version of isl.
1992 * The explicit call to isl_basic_set_union prevents the implicit
1993 * equality constraints in the first basic map from being detected prior
1994 * to the call to isl_set_coalesce, at least at the point
1995 * where this test case was introduced.
1997 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2000 isl_basic_set
*bset1
, *bset2
;
2003 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2004 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2005 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2006 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2007 set
= isl_basic_set_union(bset1
, bset2
);
2008 set
= isl_set_coalesce(set
);
2016 /* Check that calling isl_set_coalesce does not leave other sets
2017 * that may share some information with the input to isl_set_coalesce
2018 * in an inconsistent state.
2019 * In particular, older versions of isl would modify all copies
2020 * of the basic sets in the isl_set_coalesce input in a way
2021 * that could leave them in an inconsistent state.
2022 * The result of printing any other set containing one of these
2023 * basic sets would then result in an invalid set description.
2025 static int test_coalesce_special3(isl_ctx
*ctx
)
2029 isl_set
*set1
, *set2
;
2032 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2033 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2034 set2
= isl_set_read_from_str(ctx
, str
);
2035 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2036 set1
= isl_set_coalesce(set1
);
2039 p
= isl_printer_to_str(ctx
);
2040 p
= isl_printer_print_set(p
, set2
);
2042 s
= isl_printer_get_str(p
);
2043 isl_printer_free(p
);
2044 set1
= isl_set_read_from_str(ctx
, s
);
2054 /* Test the functionality of isl_set_coalesce.
2055 * That is, check that the output is always equal to the input
2056 * and in some cases that the result consists of a single disjunct.
2058 static int test_coalesce(struct isl_ctx
*ctx
)
2062 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2063 const char *str
= coalesce_tests
[i
].str
;
2064 int check_one
= coalesce_tests
[i
].single_disjunct
;
2065 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2069 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2071 if (test_coalesce_special(ctx
) < 0)
2073 if (test_coalesce_special2(ctx
) < 0)
2075 if (test_coalesce_special3(ctx
) < 0)
2081 /* Construct a representation of the graph on the right of Figure 1
2082 * in "Computing the Transitive Closure of a Union of
2083 * Affine Integer Tuple Relations".
2085 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2088 isl_map
*up
, *right
;
2090 dom
= isl_set_read_from_str(ctx
,
2091 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2092 "2 x - 3 y + 3 >= 0 }");
2093 right
= isl_map_read_from_str(ctx
,
2094 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2095 up
= isl_map_read_from_str(ctx
,
2096 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2097 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2098 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2099 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2100 up
= isl_map_intersect_range(up
, dom
);
2101 return isl_map_union(up
, right
);
2104 /* Construct a representation of the power of the graph
2105 * on the right of Figure 1 in "Computing the Transitive Closure of
2106 * a Union of Affine Integer Tuple Relations".
2108 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2110 return isl_map_read_from_str(ctx
,
2111 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2112 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2113 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2116 /* Construct a representation of the transitive closure of the graph
2117 * on the right of Figure 1 in "Computing the Transitive Closure of
2118 * a Union of Affine Integer Tuple Relations".
2120 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2122 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2125 static int test_closure(isl_ctx
*ctx
)
2128 isl_map
*map
, *map2
;
2131 /* COCOA example 1 */
2132 map
= isl_map_read_from_str(ctx
,
2133 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2134 "1 <= i and i < n and 1 <= j and j < n or "
2135 "i2 = i + 1 and j2 = j - 1 and "
2136 "1 <= i and i < n and 2 <= j and j <= n }");
2137 map
= isl_map_power(map
, &exact
);
2141 /* COCOA example 1 */
2142 map
= isl_map_read_from_str(ctx
,
2143 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2144 "1 <= i and i < n and 1 <= j and j < n or "
2145 "i2 = i + 1 and j2 = j - 1 and "
2146 "1 <= i and i < n and 2 <= j and j <= n }");
2147 map
= isl_map_transitive_closure(map
, &exact
);
2149 map2
= isl_map_read_from_str(ctx
,
2150 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2151 "1 <= i and i < n and 1 <= j and j <= n and "
2152 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2153 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2154 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2155 assert(isl_map_is_equal(map
, map2
));
2159 map
= isl_map_read_from_str(ctx
,
2160 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2161 " 0 <= y and y <= n }");
2162 map
= isl_map_transitive_closure(map
, &exact
);
2163 map2
= isl_map_read_from_str(ctx
,
2164 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2165 " 0 <= y and y <= n }");
2166 assert(isl_map_is_equal(map
, map2
));
2170 /* COCOA example 2 */
2171 map
= isl_map_read_from_str(ctx
,
2172 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2173 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2174 "i2 = i + 2 and j2 = j - 2 and "
2175 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2176 map
= isl_map_transitive_closure(map
, &exact
);
2178 map2
= isl_map_read_from_str(ctx
,
2179 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2180 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2181 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2182 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2183 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2184 assert(isl_map_is_equal(map
, map2
));
2188 /* COCOA Fig.2 left */
2189 map
= isl_map_read_from_str(ctx
,
2190 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2191 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2193 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2194 "j <= 2 i - 3 and j <= n - 2 or "
2195 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2196 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2197 map
= isl_map_transitive_closure(map
, &exact
);
2201 /* COCOA Fig.2 right */
2202 map
= isl_map_read_from_str(ctx
,
2203 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2204 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2206 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2207 "j <= 2 i - 4 and j <= n - 3 or "
2208 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2209 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2210 map
= isl_map_power(map
, &exact
);
2214 /* COCOA Fig.2 right */
2215 map
= isl_map_read_from_str(ctx
,
2216 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2217 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2219 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2220 "j <= 2 i - 4 and j <= n - 3 or "
2221 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2222 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2223 map
= isl_map_transitive_closure(map
, &exact
);
2225 map2
= isl_map_read_from_str(ctx
,
2226 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2227 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2228 "j <= n and 3 + i + 2 j <= 3 n and "
2229 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2230 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2231 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2232 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2233 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2234 assert(isl_map_is_equal(map
, map2
));
2238 map
= cocoa_fig_1_right_graph(ctx
);
2239 map
= isl_map_transitive_closure(map
, &exact
);
2241 map2
= cocoa_fig_1_right_tc(ctx
);
2242 assert(isl_map_is_equal(map
, map2
));
2246 map
= cocoa_fig_1_right_graph(ctx
);
2247 map
= isl_map_power(map
, &exact
);
2248 map2
= cocoa_fig_1_right_power(ctx
);
2249 equal
= isl_map_is_equal(map
, map2
);
2255 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2257 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2259 /* COCOA Theorem 1 counter example */
2260 map
= isl_map_read_from_str(ctx
,
2261 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2262 "i2 = 1 and j2 = j or "
2263 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2264 map
= isl_map_transitive_closure(map
, &exact
);
2268 map
= isl_map_read_from_str(ctx
,
2269 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2270 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2271 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2272 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2273 map
= isl_map_transitive_closure(map
, &exact
);
2277 /* Kelly et al 1996, fig 12 */
2278 map
= isl_map_read_from_str(ctx
,
2279 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2280 "1 <= i,j,j+1 <= n or "
2281 "j = n and j2 = 1 and i2 = i + 1 and "
2282 "1 <= i,i+1 <= n }");
2283 map
= isl_map_transitive_closure(map
, &exact
);
2285 map2
= isl_map_read_from_str(ctx
,
2286 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2287 "1 <= i <= n and i = i2 or "
2288 "1 <= i < i2 <= n and 1 <= j <= n and "
2290 assert(isl_map_is_equal(map
, map2
));
2294 /* Omega's closure4 */
2295 map
= isl_map_read_from_str(ctx
,
2296 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2297 "1 <= x,y <= 10 or "
2298 "x2 = x + 1 and y2 = y and "
2299 "1 <= x <= 20 && 5 <= y <= 15 }");
2300 map
= isl_map_transitive_closure(map
, &exact
);
2304 map
= isl_map_read_from_str(ctx
,
2305 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2306 map
= isl_map_transitive_closure(map
, &exact
);
2308 map2
= isl_map_read_from_str(ctx
,
2309 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2310 assert(isl_map_is_equal(map
, map2
));
2314 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2315 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2316 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2317 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2318 map
= isl_map_read_from_str(ctx
, str
);
2319 map
= isl_map_transitive_closure(map
, &exact
);
2321 map2
= isl_map_read_from_str(ctx
, str
);
2322 assert(isl_map_is_equal(map
, map2
));
2326 str
= "{[0] -> [1]; [2] -> [3]}";
2327 map
= isl_map_read_from_str(ctx
, str
);
2328 map
= isl_map_transitive_closure(map
, &exact
);
2330 map2
= isl_map_read_from_str(ctx
, str
);
2331 assert(isl_map_is_equal(map
, map2
));
2335 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2336 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2337 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2338 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2339 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2340 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2341 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2342 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2343 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2344 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2345 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2346 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2347 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2348 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2349 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2350 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2351 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2352 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2353 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2354 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2355 map
= isl_map_read_from_str(ctx
, str
);
2356 map
= isl_map_transitive_closure(map
, NULL
);
2363 static int test_lex(struct isl_ctx
*ctx
)
2369 dim
= isl_space_set_alloc(ctx
, 0, 0);
2370 map
= isl_map_lex_le(dim
);
2371 empty
= isl_map_is_empty(map
);
2377 isl_die(ctx
, isl_error_unknown
,
2378 "expecting non-empty result", return -1);
2383 /* Inputs for isl_map_lexmin tests.
2384 * "map" is the input and "lexmin" is the expected result.
2389 } lexmin_tests
[] = {
2390 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2391 "{ [x] -> [5] : 6 <= x <= 8; "
2392 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2393 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2394 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2395 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2396 "{ [x] -> [y] : (4y = x and x >= 0) or "
2397 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2398 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2399 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2400 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2401 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2402 /* Check that empty pieces are properly combined. */
2403 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2404 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2405 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2406 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2407 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2409 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2410 "a <= 255 and c <= 255 and d <= 255 - j and "
2411 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2412 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2413 "247d <= 247 + i and 248 - b <= 248d <= c and "
2414 "254d >= i - a + b and 254d >= -a + b and "
2415 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2417 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2418 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2419 "247j >= 62738 - i and 509j <= 129795 + i and "
2420 "742j >= 188724 - i; "
2421 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2422 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2423 "16*floor((8 + b)/16) <= 7 + b; "
2425 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2426 "[a] -> [b = 0] : 0 < a <= 509 }" },
2427 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2428 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2431 static int test_lexmin(struct isl_ctx
*ctx
)
2436 isl_basic_map
*bmap
;
2437 isl_map
*map
, *map2
;
2440 isl_pw_multi_aff
*pma
;
2442 str
= "[p0, p1] -> { [] -> [] : "
2443 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2444 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2445 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2446 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2447 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2448 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2449 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2450 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2451 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2452 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2453 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2454 map
= isl_map_read_from_str(ctx
, str
);
2455 map
= isl_map_lexmin(map
);
2458 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2459 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2460 set
= isl_set_read_from_str(ctx
, str
);
2461 set
= isl_set_lexmax(set
);
2462 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2463 set2
= isl_set_read_from_str(ctx
, str
);
2464 set
= isl_set_intersect(set
, set2
);
2465 assert(!isl_set_is_empty(set
));
2468 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2469 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2470 map
= isl_map_lexmin(map
);
2471 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2472 equal
= isl_map_is_equal(map
, map2
);
2479 isl_die(ctx
, isl_error_unknown
,
2480 "unexpected result", return -1);
2483 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2484 " 8i' <= i and 8i' >= -7 + i }";
2485 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2486 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2487 map2
= isl_map_from_pw_multi_aff(pma
);
2488 map
= isl_map_from_basic_map(bmap
);
2489 assert(isl_map_is_equal(map
, map2
));
2493 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2494 " 8i' <= i and 8i' >= -7 + i }";
2495 set
= isl_set_read_from_str(ctx
, str
);
2496 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2497 set2
= isl_set_from_pw_multi_aff(pma
);
2498 equal
= isl_set_is_equal(set
, set2
);
2504 isl_die(ctx
, isl_error_unknown
,
2505 "unexpected difference between set and "
2506 "piecewise affine expression", return -1);
2511 /* A specialized isl_set_min_val test case that would return the wrong result
2512 * in earlier versions of isl.
2513 * The explicit call to isl_basic_set_union prevents the second basic set
2514 * from being determined to be empty prior to the call to isl_set_min_val,
2515 * at least at the point where this test case was introduced.
2517 static int test_min_special(isl_ctx
*ctx
)
2520 isl_basic_set
*bset1
, *bset2
;
2526 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2527 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2528 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2529 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2530 set
= isl_basic_set_union(bset1
, bset2
);
2531 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2533 res
= isl_set_min_val(set
, obj
);
2534 ok
= isl_val_cmp_si(res
, 5) == 0;
2543 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2549 /* A specialized isl_set_min_val test case that would return an error
2550 * in earlier versions of isl.
2552 static int test_min_special2(isl_ctx
*ctx
)
2555 isl_basic_set
*bset
;
2559 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2560 bset
= isl_basic_set_read_from_str(ctx
, str
);
2562 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2564 res
= isl_basic_set_max_val(bset
, obj
);
2566 isl_basic_set_free(bset
);
2579 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2580 __isl_keep isl_aff
*obj
);
2583 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2584 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2585 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2586 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2587 &isl_set_max_val
, "30" },
2591 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2592 * In particular, check the results on non-convex inputs.
2594 static int test_min(struct isl_ctx
*ctx
)
2602 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2603 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2604 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2605 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2606 val
= opt_tests
[i
].fn(set
, obj
);
2607 ok
= isl_val_eq(res
, val
);
2616 isl_die(ctx
, isl_error_unknown
,
2617 "unexpected optimum", return -1);
2620 if (test_min_special(ctx
) < 0)
2622 if (test_min_special2(ctx
) < 0)
2633 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2634 void *dep_user
, void *user
)
2636 struct must_may
*mm
= (struct must_may
*)user
;
2639 mm
->must
= isl_map_union(mm
->must
, dep
);
2641 mm
->may
= isl_map_union(mm
->may
, dep
);
2646 static int common_space(void *first
, void *second
)
2648 int depth
= *(int *)first
;
2652 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2660 map2
= isl_map_read_from_str(map
->ctx
, str
);
2661 equal
= isl_map_is_equal(map
, map2
);
2667 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2671 equal
= map_is_equal(map
, str
);
2675 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2676 "result not as expected", return -1);
2680 static int test_dep(struct isl_ctx
*ctx
)
2685 isl_access_info
*ai
;
2692 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2693 map
= isl_map_read_from_str(ctx
, str
);
2694 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2696 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2697 map
= isl_map_read_from_str(ctx
, str
);
2698 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2700 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2701 map
= isl_map_read_from_str(ctx
, str
);
2702 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2704 flow
= isl_access_info_compute_flow(ai
);
2705 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2706 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2707 mm
.may
= isl_map_empty(dim
);
2709 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2711 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2712 " [1,10,0] -> [2,5,0] }";
2713 assert(map_is_equal(mm
.must
, str
));
2714 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2715 assert(map_is_equal(mm
.may
, str
));
2717 isl_map_free(mm
.must
);
2718 isl_map_free(mm
.may
);
2719 isl_flow_free(flow
);
2722 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2723 map
= isl_map_read_from_str(ctx
, str
);
2724 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2726 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2727 map
= isl_map_read_from_str(ctx
, str
);
2728 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2730 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2731 map
= isl_map_read_from_str(ctx
, str
);
2732 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2734 flow
= isl_access_info_compute_flow(ai
);
2735 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2736 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2737 mm
.may
= isl_map_empty(dim
);
2739 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2741 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2742 assert(map_is_equal(mm
.must
, str
));
2743 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2744 assert(map_is_equal(mm
.may
, str
));
2746 isl_map_free(mm
.must
);
2747 isl_map_free(mm
.may
);
2748 isl_flow_free(flow
);
2751 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2752 map
= isl_map_read_from_str(ctx
, str
);
2753 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2755 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2756 map
= isl_map_read_from_str(ctx
, str
);
2757 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2759 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2760 map
= isl_map_read_from_str(ctx
, str
);
2761 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2763 flow
= isl_access_info_compute_flow(ai
);
2764 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2765 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2766 mm
.may
= isl_map_empty(dim
);
2768 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2770 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2771 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2772 assert(map_is_equal(mm
.may
, str
));
2773 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2774 assert(map_is_equal(mm
.must
, str
));
2776 isl_map_free(mm
.must
);
2777 isl_map_free(mm
.may
);
2778 isl_flow_free(flow
);
2781 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2782 map
= isl_map_read_from_str(ctx
, str
);
2783 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2785 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2786 map
= isl_map_read_from_str(ctx
, str
);
2787 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2789 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2790 map
= isl_map_read_from_str(ctx
, str
);
2791 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2793 flow
= isl_access_info_compute_flow(ai
);
2794 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2795 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2796 mm
.may
= isl_map_empty(dim
);
2798 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2800 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2801 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2802 assert(map_is_equal(mm
.may
, str
));
2803 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2804 assert(map_is_equal(mm
.must
, str
));
2806 isl_map_free(mm
.must
);
2807 isl_map_free(mm
.may
);
2808 isl_flow_free(flow
);
2811 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2812 map
= isl_map_read_from_str(ctx
, str
);
2813 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2815 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2816 map
= isl_map_read_from_str(ctx
, str
);
2817 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2819 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2820 map
= isl_map_read_from_str(ctx
, str
);
2821 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2823 flow
= isl_access_info_compute_flow(ai
);
2824 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2825 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2826 mm
.may
= isl_map_empty(dim
);
2828 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2830 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2831 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2832 assert(map_is_equal(mm
.may
, str
));
2833 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2834 assert(map_is_equal(mm
.must
, str
));
2836 isl_map_free(mm
.must
);
2837 isl_map_free(mm
.may
);
2838 isl_flow_free(flow
);
2843 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2844 map
= isl_map_read_from_str(ctx
, str
);
2845 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2847 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2848 map
= isl_map_read_from_str(ctx
, str
);
2849 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2851 flow
= isl_access_info_compute_flow(ai
);
2852 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2853 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2854 mm
.may
= isl_map_empty(dim
);
2856 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2858 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2859 assert(map_is_equal(mm
.must
, str
));
2860 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2861 assert(map_is_equal(mm
.may
, str
));
2863 isl_map_free(mm
.must
);
2864 isl_map_free(mm
.may
);
2865 isl_flow_free(flow
);
2870 /* Check that the dependence analysis proceeds without errors.
2871 * Earlier versions of isl would break down during the analysis
2872 * due to the use of the wrong spaces.
2874 static int test_flow(isl_ctx
*ctx
)
2877 isl_union_map
*access
, *schedule
;
2878 isl_union_map
*must_dep
, *may_dep
;
2881 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2882 access
= isl_union_map_read_from_str(ctx
, str
);
2883 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2884 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2885 "S2[] -> [1,0,0,0]; "
2886 "S3[] -> [-1,0,0,0] }";
2887 schedule
= isl_union_map_read_from_str(ctx
, str
);
2888 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2889 isl_union_map_copy(access
), schedule
,
2890 &must_dep
, &may_dep
, NULL
, NULL
);
2891 isl_union_map_free(may_dep
);
2892 isl_union_map_free(must_dep
);
2901 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2902 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2903 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2904 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2905 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2906 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2907 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2908 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2909 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2912 int test_sv(isl_ctx
*ctx
)
2914 isl_union_map
*umap
;
2918 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2919 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2920 sv
= isl_union_map_is_single_valued(umap
);
2921 isl_union_map_free(umap
);
2924 if (sv_tests
[i
].sv
&& !sv
)
2925 isl_die(ctx
, isl_error_internal
,
2926 "map not detected as single valued", return -1);
2927 if (!sv_tests
[i
].sv
&& sv
)
2928 isl_die(ctx
, isl_error_internal
,
2929 "map detected as single valued", return -1);
2938 } bijective_tests
[] = {
2939 { "[N,M]->{[i,j] -> [i]}", 0 },
2940 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
2941 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
2942 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
2943 { "[N,M]->{[i,j] -> [j,i]}", 1 },
2944 { "[N,M]->{[i,j] -> [i+j]}", 0 },
2945 { "[N,M]->{[i,j] -> []}", 0 },
2946 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
2947 { "[N,M]->{[i,j] -> [2i]}", 0 },
2948 { "[N,M]->{[i,j] -> [i,i]}", 0 },
2949 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
2950 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
2951 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
2954 static int test_bijective(struct isl_ctx
*ctx
)
2960 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
2961 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
2962 bijective
= isl_map_is_bijective(map
);
2966 if (bijective_tests
[i
].bijective
&& !bijective
)
2967 isl_die(ctx
, isl_error_internal
,
2968 "map not detected as bijective", return -1);
2969 if (!bijective_tests
[i
].bijective
&& bijective
)
2970 isl_die(ctx
, isl_error_internal
,
2971 "map detected as bijective", return -1);
2977 /* Inputs for isl_pw_qpolynomial_gist tests.
2978 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2984 } pwqp_gist_tests
[] = {
2985 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2986 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2987 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2988 "{ [i] -> -1/2 + 1/2 * i }" },
2989 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2992 static int test_pwqp(struct isl_ctx
*ctx
)
2997 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3000 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3001 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3003 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3006 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3007 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3009 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3011 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3013 isl_pw_qpolynomial_free(pwqp1
);
3015 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3016 str
= pwqp_gist_tests
[i
].pwqp
;
3017 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3018 str
= pwqp_gist_tests
[i
].set
;
3019 set
= isl_set_read_from_str(ctx
, str
);
3020 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3021 str
= pwqp_gist_tests
[i
].gist
;
3022 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3023 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3024 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3025 isl_pw_qpolynomial_free(pwqp1
);
3030 isl_die(ctx
, isl_error_unknown
,
3031 "unexpected result", return -1);
3034 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3035 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3036 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3037 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3039 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3041 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3043 isl_pw_qpolynomial_free(pwqp1
);
3045 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3046 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3047 str
= "{ [x] -> x }";
3048 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3050 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3052 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3054 isl_pw_qpolynomial_free(pwqp1
);
3056 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3057 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3058 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3059 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3060 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3061 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3062 isl_pw_qpolynomial_free(pwqp1
);
3064 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3065 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3066 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3067 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3068 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3069 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3070 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3071 isl_pw_qpolynomial_free(pwqp1
);
3072 isl_pw_qpolynomial_free(pwqp2
);
3076 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3078 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3079 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3080 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3081 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3082 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3084 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3085 isl_pw_qpolynomial_free(pwqp1
);
3086 isl_pw_qpolynomial_free(pwqp2
);
3090 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3095 static int test_split_periods(isl_ctx
*ctx
)
3098 isl_pw_qpolynomial
*pwqp
;
3100 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3101 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3102 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3103 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3105 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3107 isl_pw_qpolynomial_free(pwqp
);
3115 static int test_union(isl_ctx
*ctx
)
3118 isl_union_set
*uset1
, *uset2
;
3119 isl_union_map
*umap1
, *umap2
;
3122 str
= "{ [i] : 0 <= i <= 1 }";
3123 uset1
= isl_union_set_read_from_str(ctx
, str
);
3124 str
= "{ [1] -> [0] }";
3125 umap1
= isl_union_map_read_from_str(ctx
, str
);
3127 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3128 equal
= isl_union_map_is_equal(umap1
, umap2
);
3130 isl_union_map_free(umap1
);
3131 isl_union_map_free(umap2
);
3136 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3139 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3140 umap1
= isl_union_map_read_from_str(ctx
, str
);
3141 str
= "{ A[i]; B[i] }";
3142 uset1
= isl_union_set_read_from_str(ctx
, str
);
3144 uset2
= isl_union_map_domain(umap1
);
3146 equal
= isl_union_set_is_equal(uset1
, uset2
);
3148 isl_union_set_free(uset1
);
3149 isl_union_set_free(uset2
);
3154 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3160 /* Check that computing a bound of a non-zero polynomial over an unbounded
3161 * domain does not produce a rational value.
3162 * In particular, check that the upper bound is infinity.
3164 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3167 isl_pw_qpolynomial
*pwqp
;
3168 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3171 str
= "{ [m,n] -> -m * n }";
3172 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3173 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3175 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3176 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3177 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3178 isl_pw_qpolynomial_fold_free(pwf
);
3179 isl_pw_qpolynomial_fold_free(pwf2
);
3184 isl_die(ctx
, isl_error_unknown
,
3185 "expecting infinite polynomial bound", return -1);
3190 static int test_bound(isl_ctx
*ctx
)
3194 isl_pw_qpolynomial
*pwqp
;
3195 isl_pw_qpolynomial_fold
*pwf
;
3197 if (test_bound_unbounded_domain(ctx
) < 0)
3200 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3201 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3202 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3203 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3204 isl_pw_qpolynomial_fold_free(pwf
);
3206 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3209 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3210 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3211 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3212 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3213 isl_pw_qpolynomial_fold_free(pwf
);
3215 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3221 static int test_lift(isl_ctx
*ctx
)
3224 isl_basic_map
*bmap
;
3225 isl_basic_set
*bset
;
3227 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3228 bset
= isl_basic_set_read_from_str(ctx
, str
);
3229 bset
= isl_basic_set_lift(bset
);
3230 bmap
= isl_basic_map_from_range(bset
);
3231 bset
= isl_basic_map_domain(bmap
);
3232 isl_basic_set_free(bset
);
3241 } subset_tests
[] = {
3243 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3244 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3245 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3247 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3248 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3249 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3250 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3251 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3252 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3253 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3254 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3255 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3256 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3257 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3258 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3259 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3260 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3261 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3262 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3263 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3264 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3265 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3266 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3267 "4e0 <= -57 + i0 + i1)) or "
3268 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3269 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3270 "4e0 >= -61 + i0 + i1)) or "
3271 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3272 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3275 static int test_subset(isl_ctx
*ctx
)
3278 isl_set
*set1
, *set2
;
3281 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3282 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3283 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3284 subset
= isl_set_is_subset(set1
, set2
);
3289 if (subset
!= subset_tests
[i
].subset
)
3290 isl_die(ctx
, isl_error_unknown
,
3291 "incorrect subset result", return -1);
3298 const char *minuend
;
3299 const char *subtrahend
;
3300 const char *difference
;
3301 } subtract_domain_tests
[] = {
3302 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3303 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3304 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3307 static int test_subtract(isl_ctx
*ctx
)
3310 isl_union_map
*umap1
, *umap2
;
3311 isl_union_pw_multi_aff
*upma1
, *upma2
;
3312 isl_union_set
*uset
;
3315 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3316 umap1
= isl_union_map_read_from_str(ctx
,
3317 subtract_domain_tests
[i
].minuend
);
3318 uset
= isl_union_set_read_from_str(ctx
,
3319 subtract_domain_tests
[i
].subtrahend
);
3320 umap2
= isl_union_map_read_from_str(ctx
,
3321 subtract_domain_tests
[i
].difference
);
3322 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3323 equal
= isl_union_map_is_equal(umap1
, umap2
);
3324 isl_union_map_free(umap1
);
3325 isl_union_map_free(umap2
);
3329 isl_die(ctx
, isl_error_unknown
,
3330 "incorrect subtract domain result", return -1);
3333 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3334 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3335 subtract_domain_tests
[i
].minuend
);
3336 uset
= isl_union_set_read_from_str(ctx
,
3337 subtract_domain_tests
[i
].subtrahend
);
3338 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3339 subtract_domain_tests
[i
].difference
);
3340 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3341 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3342 isl_union_pw_multi_aff_free(upma1
);
3343 isl_union_pw_multi_aff_free(upma2
);
3347 isl_die(ctx
, isl_error_unknown
,
3348 "incorrect subtract domain result", return -1);
3354 /* Check that intersecting the empty basic set with another basic set
3355 * does not increase the number of constraints. In particular,
3356 * the empty basic set should maintain its canonical representation.
3358 static int test_intersect(isl_ctx
*ctx
)
3361 isl_basic_set
*bset1
, *bset2
;
3363 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3364 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3365 n1
= isl_basic_set_n_constraint(bset1
);
3366 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3367 n2
= isl_basic_set_n_constraint(bset1
);
3368 isl_basic_set_free(bset1
);
3372 isl_die(ctx
, isl_error_unknown
,
3373 "number of constraints of empty set changed",
3379 int test_factorize(isl_ctx
*ctx
)
3382 isl_basic_set
*bset
;
3385 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3386 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3387 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3388 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3389 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3390 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3391 "3i5 >= -2i0 - i2 + 3i4 }";
3392 bset
= isl_basic_set_read_from_str(ctx
, str
);
3393 f
= isl_basic_set_factorizer(bset
);
3394 isl_basic_set_free(bset
);
3395 isl_factorizer_free(f
);
3397 isl_die(ctx
, isl_error_unknown
,
3398 "failed to construct factorizer", return -1);
3400 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3401 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3402 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3403 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3404 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3405 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3406 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3407 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3408 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3409 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3410 bset
= isl_basic_set_read_from_str(ctx
, str
);
3411 f
= isl_basic_set_factorizer(bset
);
3412 isl_basic_set_free(bset
);
3413 isl_factorizer_free(f
);
3415 isl_die(ctx
, isl_error_unknown
,
3416 "failed to construct factorizer", return -1);
3421 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3423 int *injective
= user
;
3425 *injective
= isl_map_is_injective(map
);
3428 if (*injective
< 0 || !*injective
)
3429 return isl_stat_error
;
3434 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3435 const char *r
, const char *s
, int tilable
, int parallel
)
3439 isl_union_map
*W
, *R
, *S
;
3440 isl_union_map
*empty
;
3441 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3442 isl_union_map
*validity
, *proximity
, *coincidence
;
3443 isl_union_map
*schedule
;
3444 isl_union_map
*test
;
3445 isl_union_set
*delta
;
3446 isl_union_set
*domain
;
3450 isl_schedule_constraints
*sc
;
3451 isl_schedule
*sched
;
3452 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3454 D
= isl_union_set_read_from_str(ctx
, d
);
3455 W
= isl_union_map_read_from_str(ctx
, w
);
3456 R
= isl_union_map_read_from_str(ctx
, r
);
3457 S
= isl_union_map_read_from_str(ctx
, s
);
3459 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3460 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3462 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3463 isl_union_map_compute_flow(isl_union_map_copy(R
),
3464 isl_union_map_copy(W
), empty
,
3465 isl_union_map_copy(S
),
3466 &dep_raw
, NULL
, NULL
, NULL
);
3467 isl_union_map_compute_flow(isl_union_map_copy(W
),
3468 isl_union_map_copy(W
),
3469 isl_union_map_copy(R
),
3470 isl_union_map_copy(S
),
3471 &dep_waw
, &dep_war
, NULL
, NULL
);
3473 dep
= isl_union_map_union(dep_waw
, dep_war
);
3474 dep
= isl_union_map_union(dep
, dep_raw
);
3475 validity
= isl_union_map_copy(dep
);
3476 coincidence
= isl_union_map_copy(dep
);
3477 proximity
= isl_union_map_copy(dep
);
3479 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3480 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3481 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3482 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3483 sched
= isl_schedule_constraints_compute_schedule(sc
);
3484 schedule
= isl_schedule_get_map(sched
);
3485 isl_schedule_free(sched
);
3486 isl_union_map_free(W
);
3487 isl_union_map_free(R
);
3488 isl_union_map_free(S
);
3491 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3493 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3494 is_complete
= isl_union_set_is_subset(D
, domain
);
3495 isl_union_set_free(D
);
3496 isl_union_set_free(domain
);
3498 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3499 test
= isl_union_map_apply_range(test
, dep
);
3500 test
= isl_union_map_apply_range(test
, schedule
);
3502 delta
= isl_union_map_deltas(test
);
3503 if (isl_union_set_n_set(delta
) == 0) {
3507 isl_union_set_free(delta
);
3509 delta_set
= isl_set_from_union_set(delta
);
3511 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3512 for (i
= 0; i
< tilable
; ++i
)
3513 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3514 is_tilable
= isl_set_is_subset(delta_set
, slice
);
3515 isl_set_free(slice
);
3517 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3518 for (i
= 0; i
< parallel
; ++i
)
3519 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
3520 is_parallel
= isl_set_is_subset(delta_set
, slice
);
3521 isl_set_free(slice
);
3523 origin
= isl_set_universe(isl_set_get_space(delta_set
));
3524 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
3525 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
3527 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
3528 delta_set
= isl_set_lexmin(delta_set
);
3530 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
3532 isl_set_free(origin
);
3533 isl_set_free(delta_set
);
3536 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
3537 is_injection
< 0 || is_complete
< 0)
3540 isl_die(ctx
, isl_error_unknown
,
3541 "generated schedule incomplete", return -1);
3543 isl_die(ctx
, isl_error_unknown
,
3544 "generated schedule not injective on each statement",
3547 isl_die(ctx
, isl_error_unknown
,
3548 "negative dependences in generated schedule",
3551 isl_die(ctx
, isl_error_unknown
,
3552 "generated schedule not as tilable as expected",
3555 isl_die(ctx
, isl_error_unknown
,
3556 "generated schedule not as parallel as expected",
3562 /* Compute a schedule for the given instance set, validity constraints,
3563 * proximity constraints and context and return a corresponding union map
3566 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
3567 const char *domain
, const char *validity
, const char *proximity
,
3568 const char *context
)
3573 isl_union_map
*prox
;
3574 isl_schedule_constraints
*sc
;
3575 isl_schedule
*schedule
;
3576 isl_union_map
*sched
;
3578 con
= isl_set_read_from_str(ctx
, context
);
3579 dom
= isl_union_set_read_from_str(ctx
, domain
);
3580 dep
= isl_union_map_read_from_str(ctx
, validity
);
3581 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3582 sc
= isl_schedule_constraints_on_domain(dom
);
3583 sc
= isl_schedule_constraints_set_context(sc
, con
);
3584 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3585 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3586 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3587 sched
= isl_schedule_get_map(schedule
);
3588 isl_schedule_free(schedule
);
3593 /* Compute a schedule for the given instance set, validity constraints and
3594 * proximity constraints and return a corresponding union map representation.
3596 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3597 const char *domain
, const char *validity
, const char *proximity
)
3599 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
3603 /* Check that a schedule can be constructed on the given domain
3604 * with the given validity and proximity constraints.
3606 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3607 const char *validity
, const char *proximity
)
3609 isl_union_map
*sched
;
3611 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3615 isl_union_map_free(sched
);
3619 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3620 const char *validity
, const char *proximity
, const char *expected_sched
)
3622 isl_union_map
*sched1
, *sched2
;
3625 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3626 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3628 equal
= isl_union_map_is_equal(sched1
, sched2
);
3629 isl_union_map_free(sched1
);
3630 isl_union_map_free(sched2
);
3635 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3641 /* Check that the schedule map is properly padded, even after being
3642 * reconstructed from the band forest.
3644 static int test_padded_schedule(isl_ctx
*ctx
)
3648 isl_union_map
*validity
, *proximity
;
3649 isl_schedule_constraints
*sc
;
3650 isl_schedule
*sched
;
3651 isl_union_map
*map1
, *map2
;
3652 isl_band_list
*list
;
3655 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3656 D
= isl_union_set_read_from_str(ctx
, str
);
3657 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3658 proximity
= isl_union_map_copy(validity
);
3659 sc
= isl_schedule_constraints_on_domain(D
);
3660 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3661 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3662 sched
= isl_schedule_constraints_compute_schedule(sc
);
3663 map1
= isl_schedule_get_map(sched
);
3664 list
= isl_schedule_get_band_forest(sched
);
3665 isl_band_list_free(list
);
3666 map2
= isl_schedule_get_map(sched
);
3667 isl_schedule_free(sched
);
3668 equal
= isl_union_map_is_equal(map1
, map2
);
3669 isl_union_map_free(map1
);
3670 isl_union_map_free(map2
);
3675 isl_die(ctx
, isl_error_unknown
,
3676 "reconstructed schedule map not the same as original",
3682 /* Check that conditional validity constraints are also taken into
3683 * account across bands.
3684 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3685 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3686 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3687 * is enforced by the rest of the schedule.
3689 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3692 isl_union_set
*domain
;
3693 isl_union_map
*validity
, *proximity
, *condition
;
3694 isl_union_map
*sink
, *source
, *dep
;
3695 isl_schedule_constraints
*sc
;
3696 isl_schedule
*schedule
;
3697 isl_union_access_info
*access
;
3698 isl_union_flow
*flow
;
3701 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3702 "A[k] : k >= 1 and k <= -1 + n; "
3703 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3704 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3705 domain
= isl_union_set_read_from_str(ctx
, str
);
3706 sc
= isl_schedule_constraints_on_domain(domain
);
3707 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3708 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3709 "D[k, i] -> C[1 + k, i] : "
3710 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3711 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3712 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3713 validity
= isl_union_map_read_from_str(ctx
, str
);
3714 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3715 str
= "[n] -> { C[k, i] -> D[k, i] : "
3716 "0 <= i <= -1 + k and k <= -1 + n }";
3717 proximity
= isl_union_map_read_from_str(ctx
, str
);
3718 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3719 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3720 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3721 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3722 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3723 condition
= isl_union_map_read_from_str(ctx
, str
);
3724 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3725 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3726 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3727 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3728 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3729 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3730 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3731 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3732 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3733 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3734 validity
= isl_union_map_read_from_str(ctx
, str
);
3735 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3737 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3738 str
= "{ D[2,0] -> [] }";
3739 sink
= isl_union_map_read_from_str(ctx
, str
);
3740 access
= isl_union_access_info_from_sink(sink
);
3741 str
= "{ C[2,1] -> [] }";
3742 source
= isl_union_map_read_from_str(ctx
, str
);
3743 access
= isl_union_access_info_set_must_source(access
, source
);
3744 access
= isl_union_access_info_set_schedule(access
, schedule
);
3745 flow
= isl_union_access_info_compute_flow(access
);
3746 dep
= isl_union_flow_get_must_dependence(flow
);
3747 isl_union_flow_free(flow
);
3748 empty
= isl_union_map_is_empty(dep
);
3749 isl_union_map_free(dep
);
3754 isl_die(ctx
, isl_error_unknown
,
3755 "conditional validity not respected", return -1);
3760 /* Check that the test for violated conditional validity constraints
3761 * is not confused by domain compression.
3762 * In particular, earlier versions of isl would apply
3763 * a schedule on the compressed domains to the original domains,
3764 * resulting in a failure to detect that the default schedule
3765 * violates the conditional validity constraints.
3767 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
3771 isl_union_set
*domain
;
3772 isl_union_map
*validity
, *condition
;
3773 isl_schedule_constraints
*sc
;
3774 isl_schedule
*schedule
;
3775 isl_union_map
*umap
;
3778 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
3779 domain
= isl_union_set_read_from_str(ctx
, str
);
3780 sc
= isl_schedule_constraints_on_domain(domain
);
3781 str
= "{ B[1, i] -> A[0, i + 1] }";
3782 condition
= isl_union_map_read_from_str(ctx
, str
);
3783 str
= "{ A[0, i] -> B[1, i - 1] }";
3784 validity
= isl_union_map_read_from_str(ctx
, str
);
3785 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3786 isl_union_map_copy(validity
));
3787 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3788 umap
= isl_schedule_get_map(schedule
);
3789 isl_schedule_free(schedule
);
3790 validity
= isl_union_map_apply_domain(validity
,
3791 isl_union_map_copy(umap
));
3792 validity
= isl_union_map_apply_range(validity
, umap
);
3793 map
= isl_map_from_union_map(validity
);
3794 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3795 map
= isl_map_intersect(map
, ge
);
3796 empty
= isl_map_is_empty(map
);
3802 isl_die(ctx
, isl_error_unknown
,
3803 "conditional validity constraints not satisfied",
3809 /* Input for testing of schedule construction based on
3810 * conditional constraints.
3812 * domain is the iteration domain
3813 * flow are the flow dependences, which determine the validity and
3814 * proximity constraints
3815 * condition are the conditions on the conditional validity constraints
3816 * conditional_validity are the conditional validity constraints
3817 * outer_band_n is the expected number of members in the outer band
3822 const char *condition
;
3823 const char *conditional_validity
;
3825 } live_range_tests
[] = {
3826 /* Contrived example that illustrates that we need to keep
3827 * track of tagged condition dependences and
3828 * tagged conditional validity dependences
3829 * in isl_sched_edge separately.
3830 * In particular, the conditional validity constraints on A
3831 * cannot be satisfied,
3832 * but they can be ignored because there are no corresponding
3833 * condition constraints. However, we do have an additional
3834 * conditional validity constraint that maps to the same
3835 * dependence relation
3836 * as the condition constraint on B. If we did not make a distinction
3837 * between tagged condition and tagged conditional validity
3838 * dependences, then we
3839 * could end up treating this shared dependence as an condition
3840 * constraint on A, forcing a localization of the conditions,
3841 * which is impossible.
3843 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3844 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3845 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
3846 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3847 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3848 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
3851 /* TACO 2013 Fig. 7 */
3852 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3853 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3854 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3855 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
3856 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
3857 "0 <= i < n and 0 <= j < n - 1 }",
3858 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
3859 "0 <= i < n and 0 <= j < j' < n;"
3860 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
3861 "0 <= i < i' < n and 0 <= j,j' < n;"
3862 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
3863 "0 <= i,j,j' < n and j < j' }",
3866 /* TACO 2013 Fig. 7, without tags */
3867 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3868 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3869 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3870 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3871 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3872 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
3873 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
3874 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
3877 /* TACO 2013 Fig. 12 */
3878 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
3879 "S3[i,3] : 0 <= i <= 1 }",
3880 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
3881 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
3882 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
3883 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
3884 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3885 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
3886 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3887 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
3888 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
3889 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
3890 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
3895 /* Test schedule construction based on conditional constraints.
3896 * In particular, check the number of members in the outer band node
3897 * as an indication of whether tiling is possible or not.
3899 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
3902 isl_union_set
*domain
;
3903 isl_union_map
*condition
;
3904 isl_union_map
*flow
;
3905 isl_union_map
*validity
;
3906 isl_schedule_constraints
*sc
;
3907 isl_schedule
*schedule
;
3908 isl_schedule_node
*node
;
3911 if (test_special_conditional_schedule_constraints(ctx
) < 0)
3913 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
3916 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
3917 domain
= isl_union_set_read_from_str(ctx
,
3918 live_range_tests
[i
].domain
);
3919 flow
= isl_union_map_read_from_str(ctx
,
3920 live_range_tests
[i
].flow
);
3921 condition
= isl_union_map_read_from_str(ctx
,
3922 live_range_tests
[i
].condition
);
3923 validity
= isl_union_map_read_from_str(ctx
,
3924 live_range_tests
[i
].conditional_validity
);
3925 sc
= isl_schedule_constraints_on_domain(domain
);
3926 sc
= isl_schedule_constraints_set_validity(sc
,
3927 isl_union_map_copy(flow
));
3928 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
3929 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
3930 condition
, validity
);
3931 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3932 node
= isl_schedule_get_root(schedule
);
3934 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
3935 node
= isl_schedule_node_first_child(node
);
3936 n_member
= isl_schedule_node_band_n_member(node
);
3937 isl_schedule_node_free(node
);
3938 isl_schedule_free(schedule
);
3942 if (n_member
!= live_range_tests
[i
].outer_band_n
)
3943 isl_die(ctx
, isl_error_unknown
,
3944 "unexpected number of members in outer band",
3950 /* Check that the schedule computed for the given instance set and
3951 * dependence relation strongly satisfies the dependences.
3952 * In particular, check that no instance is scheduled before
3953 * or together with an instance on which it depends.
3954 * Earlier versions of isl would produce a schedule that
3955 * only weakly satisfies the dependences.
3957 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
3959 const char *domain
, *dep
;
3960 isl_union_map
*D
, *schedule
;
3964 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
3965 "A[i0] : 0 <= i0 <= 1 }";
3966 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
3967 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
3968 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
3969 D
= isl_union_map_read_from_str(ctx
, dep
);
3970 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
3971 D
= isl_union_map_apply_range(D
, schedule
);
3972 map
= isl_map_from_union_map(D
);
3973 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3974 map
= isl_map_intersect(map
, ge
);
3975 empty
= isl_map_is_empty(map
);
3981 isl_die(ctx
, isl_error_unknown
,
3982 "dependences not strongly satisfied", return -1);
3987 /* Compute a schedule for input where the instance set constraints
3988 * conflict with the context constraints.
3989 * Earlier versions of isl did not properly handle this situation.
3991 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
3993 isl_union_map
*schedule
;
3994 const char *domain
, *context
;
3996 domain
= "[n] -> { A[] : n >= 0 }";
3997 context
= "[n] -> { : n < 0 }";
3998 schedule
= compute_schedule_with_context(ctx
,
3999 domain
, "{}", "{}", context
);
4000 isl_union_map_free(schedule
);
4008 /* Check that the dependence carrying step is not confused by
4009 * a bound on the coefficient size.
4010 * In particular, force the scheduler to move to a dependence carrying
4011 * step by demanding outer coincidence and bound the size of
4012 * the coefficients. Earlier versions of isl would take this
4013 * bound into account while carrying dependences, breaking
4014 * fundamental assumptions.
4015 * On the other hand, the dependence carrying step now tries
4016 * to prevent loop coalescing by default, so check that indeed
4017 * no loop coalescing occurs by comparing the computed schedule
4018 * to the expected non-coalescing schedule.
4020 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
4022 const char *domain
, *dep
;
4025 isl_schedule_constraints
*sc
;
4026 isl_schedule
*schedule
;
4027 isl_union_map
*sched1
, *sched2
;
4030 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
4031 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
4033 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
4034 I
= isl_union_set_read_from_str(ctx
, domain
);
4035 D
= isl_union_map_read_from_str(ctx
, dep
);
4036 sc
= isl_schedule_constraints_on_domain(I
);
4037 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
4038 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
4039 isl_options_set_schedule_outer_coincidence(ctx
, 1);
4040 isl_options_set_schedule_max_coefficient(ctx
, 20);
4041 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4042 isl_options_set_schedule_max_coefficient(ctx
, -1);
4043 isl_options_set_schedule_outer_coincidence(ctx
, 0);
4044 sched1
= isl_schedule_get_map(schedule
);
4045 isl_schedule_free(schedule
);
4047 sched2
= isl_union_map_read_from_str(ctx
, "{ C[x,y] -> [x,y] }");
4048 equal
= isl_union_map_is_equal(sched1
, sched2
);
4049 isl_union_map_free(sched1
);
4050 isl_union_map_free(sched2
);
4055 isl_die(ctx
, isl_error_unknown
,
4056 "unexpected schedule", return -1);
4061 /* Check that a set of schedule constraints that only allow for
4062 * a coalescing schedule still produces a schedule even if the user
4063 * request a non-coalescing schedule. Earlier versions of isl
4064 * would not handle this case correctly.
4066 static int test_coalescing_schedule(isl_ctx
*ctx
)
4068 const char *domain
, *dep
;
4071 isl_schedule_constraints
*sc
;
4072 isl_schedule
*schedule
;
4073 int treat_coalescing
;
4075 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4076 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4077 I
= isl_union_set_read_from_str(ctx
, domain
);
4078 D
= isl_union_map_read_from_str(ctx
, dep
);
4079 sc
= isl_schedule_constraints_on_domain(I
);
4080 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4081 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4082 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4083 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4084 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4085 isl_schedule_free(schedule
);
4091 /* Check that the scheduler does not perform any needless
4092 * compound skewing. Earlier versions of isl would compute
4093 * schedules in terms of transformed schedule coefficients and
4094 * would not accurately keep track of the sum of the original
4095 * schedule coefficients. It could then produce the schedule
4096 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4097 * for the input below instead of the schedule below.
4099 static int test_skewing_schedule(isl_ctx
*ctx
)
4101 const char *D
, *V
, *P
, *S
;
4103 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4104 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4105 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4106 "-1 <= a-i + b-j + c-k <= 1 }";
4108 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4110 return test_special_schedule(ctx
, D
, V
, P
, S
);
4113 int test_schedule(isl_ctx
*ctx
)
4115 const char *D
, *W
, *R
, *V
, *P
, *S
;
4116 int max_coincidence
;
4117 int treat_coalescing
;
4119 /* Handle resulting schedule with zero bands. */
4120 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4124 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4125 W
= "{ S1[t,i] -> a[t,i] }";
4126 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4127 "S1[t,i] -> a[t-1,i+1] }";
4128 S
= "{ S1[t,i] -> [t,i] }";
4129 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4132 /* Fig. 5 of CC2008 */
4133 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4135 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4136 "j >= 2 and j <= -1 + N }";
4137 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4138 "j >= 2 and j <= -1 + N; "
4139 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4140 "j >= 2 and j <= -1 + N }";
4141 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4142 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4145 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4146 W
= "{ S1[i] -> a[i] }";
4147 R
= "{ S2[i] -> a[i+1] }";
4148 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4149 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4152 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4153 W
= "{ S1[i] -> a[i] }";
4154 R
= "{ S2[i] -> a[9-i] }";
4155 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4156 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4159 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4160 W
= "{ S1[i] -> a[i] }";
4161 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4162 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4163 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4166 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4167 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4168 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4169 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4170 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4173 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4174 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4175 R
= "{ S2[i,j] -> a[i-1,j] }";
4176 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4177 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4180 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4181 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4182 R
= "{ S2[i,j] -> a[i,j-1] }";
4183 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4184 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4187 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4188 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4189 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4190 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4191 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4192 "S_0[] -> [0, 0, 0] }";
4193 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4195 ctx
->opt
->schedule_parametric
= 0;
4196 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4198 ctx
->opt
->schedule_parametric
= 1;
4200 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4201 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4202 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4203 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4204 "S4[i] -> a[i,N] }";
4205 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4206 "S4[i] -> [4,i,0] }";
4207 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4208 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4209 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4211 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4213 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4214 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4216 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4218 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4220 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4221 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4224 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4225 " S_2[t] : t >= 0 and t <= -1 + N; "
4226 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4228 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4229 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4230 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4231 "i >= 0 and i <= -1 + N }";
4232 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4233 "i >= 0 and i <= -1 + N; "
4234 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4235 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4236 " S_0[t] -> [0, t, 0] }";
4238 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4240 ctx
->opt
->schedule_parametric
= 0;
4241 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4243 ctx
->opt
->schedule_parametric
= 1;
4245 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4246 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4247 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4250 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4251 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4252 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4253 "j >= 0 and j <= -1 + N; "
4254 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4255 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4256 "j >= 0 and j <= -1 + N; "
4257 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4258 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4259 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4262 D
= "{ S_0[i] : i >= 0 }";
4263 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4264 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4265 S
= "{ S_0[i] -> [0, i, 0] }";
4266 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4269 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4270 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4271 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4272 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4273 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4276 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4277 "k <= -1 + n and k >= 0 }";
4278 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4279 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4280 "k <= -1 + n and k >= 0; "
4281 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4282 "k <= -1 + n and k >= 0; "
4283 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4284 "k <= -1 + n and k >= 0 }";
4285 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4286 ctx
->opt
->schedule_outer_coincidence
= 1;
4287 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4289 ctx
->opt
->schedule_outer_coincidence
= 0;
4291 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4292 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4293 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4294 "Stmt_for_body24[i0, i1, 1, 0]:"
4295 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4296 "Stmt_for_body7[i0, i1, i2]:"
4297 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4300 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4301 "Stmt_for_body24[1, i1, i2, i3]:"
4302 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4304 "Stmt_for_body24[0, i1, i2, i3] -> "
4305 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4306 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4308 "Stmt_for_body24[0, i1, i2, i3] ->"
4309 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4310 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4311 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4312 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4313 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4314 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4315 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4316 "i1 <= 6 and i1 >= 0;"
4317 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4318 "Stmt_for_body7[i0, i1, i2] -> "
4319 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4320 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4321 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4322 "Stmt_for_body7[i0, i1, i2] -> "
4323 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4324 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4325 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4328 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4329 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4330 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4332 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4334 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4335 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4336 "j >= 1 and j <= 7;"
4337 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4338 "j >= 1 and j <= 8 }";
4340 S
= "{ S_0[i, j] -> [i + j, i] }";
4341 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4342 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4344 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4346 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4347 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4348 "j >= 0 and j <= -1 + i }";
4349 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4350 "i <= -1 + N and j >= 0;"
4351 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4354 S
= "{ S_0[i, j] -> [i, j] }";
4355 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4356 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4358 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4360 /* Test both algorithms on a case with only proximity dependences. */
4361 D
= "{ S[i,j] : 0 <= i <= 10 }";
4363 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4364 S
= "{ S[i, j] -> [j, i] }";
4365 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4366 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4368 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4369 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4372 D
= "{ A[a]; B[] }";
4374 P
= "{ A[a] -> B[] }";
4375 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4378 if (test_padded_schedule(ctx
) < 0)
4381 /* Check that check for progress is not confused by rational
4384 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4385 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4387 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4388 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4390 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4391 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4393 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4395 /* Check that we allow schedule rows that are only non-trivial
4396 * on some full-dimensional domains.
4398 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4399 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4400 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4402 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4403 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4405 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4407 if (test_conditional_schedule_constraints(ctx
) < 0)
4410 if (test_strongly_satisfying_schedule(ctx
) < 0)
4413 if (test_conflicting_context_schedule(ctx
) < 0)
4416 if (test_bounded_coefficients_schedule(ctx
) < 0)
4418 if (test_coalescing_schedule(ctx
) < 0)
4420 if (test_skewing_schedule(ctx
) < 0)
4426 /* Perform scheduling tests using the whole component scheduler.
4428 static int test_schedule_whole(isl_ctx
*ctx
)
4433 whole
= isl_options_get_schedule_whole_component(ctx
);
4434 isl_options_set_schedule_whole_component(ctx
, 1);
4435 r
= test_schedule(ctx
);
4436 isl_options_set_schedule_whole_component(ctx
, whole
);
4441 /* Perform scheduling tests using the incremental scheduler.
4443 static int test_schedule_incremental(isl_ctx
*ctx
)
4448 whole
= isl_options_get_schedule_whole_component(ctx
);
4449 isl_options_set_schedule_whole_component(ctx
, 0);
4450 r
= test_schedule(ctx
);
4451 isl_options_set_schedule_whole_component(ctx
, whole
);
4456 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4458 isl_union_map
*umap
;
4461 umap
= isl_union_map_read_from_str(ctx
, str
);
4462 test
= isl_union_map_plain_is_injective(umap
);
4463 isl_union_map_free(umap
);
4466 if (test
== injective
)
4469 isl_die(ctx
, isl_error_unknown
,
4470 "map not detected as injective", return -1);
4472 isl_die(ctx
, isl_error_unknown
,
4473 "map detected as injective", return -1);
4476 int test_injective(isl_ctx
*ctx
)
4480 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4482 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4484 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4486 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4488 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4490 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4492 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4494 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4497 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4498 if (test_plain_injective(ctx
, str
, 1))
4500 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4501 if (test_plain_injective(ctx
, str
, 0))
4507 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4515 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4516 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4522 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4526 equal
= aff_plain_is_equal(aff
, str
);
4530 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4531 "result not as expected", return -1);
4536 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4537 __isl_take isl_aff
*aff2
);
4539 ['+'] = { &isl_aff_add
},
4540 ['-'] = { &isl_aff_sub
},
4541 ['*'] = { &isl_aff_mul
},
4542 ['/'] = { &isl_aff_div
},
4550 } aff_bin_tests
[] = {
4551 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
4552 "{ [i] -> [2i] }" },
4553 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
4555 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
4556 "{ [i] -> [2i] }" },
4557 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
4558 "{ [i] -> [2i] }" },
4559 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
4560 "{ [i] -> [i/2] }" },
4561 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
4563 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
4564 "{ [i] -> [NaN] }" },
4565 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
4566 "{ [i] -> [NaN] }" },
4567 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
4568 "{ [i] -> [NaN] }" },
4569 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
4570 "{ [i] -> [NaN] }" },
4571 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
4572 "{ [i] -> [NaN] }" },
4573 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
4574 "{ [i] -> [NaN] }" },
4575 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
4576 "{ [i] -> [NaN] }" },
4577 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
4578 "{ [i] -> [NaN] }" },
4579 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
4580 "{ [i] -> [NaN] }" },
4581 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
4582 "{ [i] -> [NaN] }" },
4583 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
4584 "{ [i] -> [NaN] }" },
4585 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
4586 "{ [i] -> [NaN] }" },
4589 /* Perform some basic tests of binary operations on isl_aff objects.
4591 static int test_bin_aff(isl_ctx
*ctx
)
4594 isl_aff
*aff1
, *aff2
, *res
;
4595 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4596 __isl_take isl_aff
*aff2
);
4599 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
4600 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
4601 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
4602 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
4603 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
4604 aff1
= fn(aff1
, aff2
);
4605 if (isl_aff_is_nan(res
))
4606 ok
= isl_aff_is_nan(aff1
);
4608 ok
= isl_aff_plain_is_equal(aff1
, res
);
4614 isl_die(ctx
, isl_error_unknown
,
4615 "unexpected result", return -1);
4622 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
4623 __isl_take isl_pw_aff
*pa2
);
4624 } pw_aff_bin_op
[] = {
4625 ['m'] = { &isl_pw_aff_min
},
4626 ['M'] = { &isl_pw_aff_max
},
4629 /* Inputs for binary isl_pw_aff operation tests.
4630 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
4631 * defined by pw_aff_bin_op, and "res" is the expected result.
4638 } pw_aff_bin_tests
[] = {
4639 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
4641 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
4643 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
4644 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
4645 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
4646 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
4647 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
4648 "{ [i] -> [NaN] }" },
4649 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
4650 "{ [i] -> [NaN] }" },
4653 /* Perform some basic tests of binary operations on isl_pw_aff objects.
4655 static int test_bin_pw_aff(isl_ctx
*ctx
)
4659 isl_pw_aff
*pa1
, *pa2
, *res
;
4661 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
4662 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
4663 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
4664 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
4665 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
4666 if (isl_pw_aff_involves_nan(res
))
4667 ok
= isl_pw_aff_involves_nan(pa1
);
4669 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
4670 isl_pw_aff_free(pa1
);
4671 isl_pw_aff_free(res
);
4675 isl_die(ctx
, isl_error_unknown
,
4676 "unexpected result", return -1);
4683 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4684 __isl_take isl_union_pw_multi_aff
*upma1
,
4685 __isl_take isl_union_pw_multi_aff
*upma2
);
4689 } upma_bin_tests
[] = {
4690 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
4691 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
4692 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
4693 "{ B[x] -> [2] : x >= 0 }",
4694 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
4695 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
4696 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
4697 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
4698 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
4699 "D[i] -> B[2] : i >= 5 }" },
4700 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4701 "{ B[x] -> C[2] : x > 0 }",
4702 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
4703 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4704 "{ B[x] -> A[2] : x >= 0 }",
4705 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
4708 /* Perform some basic tests of binary operations on
4709 * isl_union_pw_multi_aff objects.
4711 static int test_bin_upma(isl_ctx
*ctx
)
4714 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
4717 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
4718 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4719 upma_bin_tests
[i
].arg1
);
4720 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4721 upma_bin_tests
[i
].arg2
);
4722 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
4723 upma_bin_tests
[i
].res
);
4724 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
4725 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
4726 isl_union_pw_multi_aff_free(upma1
);
4727 isl_union_pw_multi_aff_free(res
);
4731 isl_die(ctx
, isl_error_unknown
,
4732 "unexpected result", return -1);
4739 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4740 __isl_take isl_union_pw_multi_aff
*upma1
,
4741 __isl_take isl_union_pw_multi_aff
*upma2
);
4744 } upma_bin_fail_tests
[] = {
4745 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4746 "{ B[x] -> C[2] : x >= 0 }" },
4749 /* Perform some basic tests of binary operations on
4750 * isl_union_pw_multi_aff objects that are expected to fail.
4752 static int test_bin_upma_fail(isl_ctx
*ctx
)
4755 isl_union_pw_multi_aff
*upma1
, *upma2
;
4758 on_error
= isl_options_get_on_error(ctx
);
4759 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
4760 n
= ARRAY_SIZE(upma_bin_fail_tests
);
4761 for (i
= 0; i
< n
; ++i
) {
4762 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4763 upma_bin_fail_tests
[i
].arg1
);
4764 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4765 upma_bin_fail_tests
[i
].arg2
);
4766 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
4767 isl_union_pw_multi_aff_free(upma1
);
4771 isl_options_set_on_error(ctx
, on_error
);
4773 isl_die(ctx
, isl_error_unknown
,
4774 "operation not expected to succeed", return -1);
4779 int test_aff(isl_ctx
*ctx
)
4784 isl_local_space
*ls
;
4788 if (test_bin_aff(ctx
) < 0)
4790 if (test_bin_pw_aff(ctx
) < 0)
4792 if (test_bin_upma(ctx
) < 0)
4794 if (test_bin_upma_fail(ctx
) < 0)
4797 space
= isl_space_set_alloc(ctx
, 0, 1);
4798 ls
= isl_local_space_from_space(space
);
4799 aff
= isl_aff_zero_on_domain(ls
);
4801 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4802 aff
= isl_aff_scale_down_ui(aff
, 3);
4803 aff
= isl_aff_floor(aff
);
4804 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4805 aff
= isl_aff_scale_down_ui(aff
, 2);
4806 aff
= isl_aff_floor(aff
);
4807 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4810 set
= isl_set_read_from_str(ctx
, str
);
4811 aff
= isl_aff_gist(aff
, set
);
4813 aff
= isl_aff_add_constant_si(aff
, -16);
4814 zero
= isl_aff_plain_is_zero(aff
);
4820 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4822 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
4823 aff
= isl_aff_scale_down_ui(aff
, 64);
4824 aff
= isl_aff_floor(aff
);
4825 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
4833 /* Check that the computation below results in a single expression.
4834 * One or two expressions may result depending on which constraint
4835 * ends up being considered as redundant with respect to the other
4836 * constraints after the projection that is performed internally
4837 * by isl_set_dim_min.
4839 static int test_dim_max_1(isl_ctx
*ctx
)
4846 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
4847 "-4a <= b <= 3 and b < n - 4a }";
4848 set
= isl_set_read_from_str(ctx
, str
);
4849 pa
= isl_set_dim_min(set
, 0);
4850 n
= isl_pw_aff_n_piece(pa
);
4851 isl_pw_aff_free(pa
);
4856 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
4862 int test_dim_max(isl_ctx
*ctx
)
4866 isl_set
*set1
, *set2
;
4871 if (test_dim_max_1(ctx
) < 0)
4874 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
4875 set
= isl_set_read_from_str(ctx
, str
);
4876 pwaff
= isl_set_dim_max(set
, 0);
4877 set1
= isl_set_from_pw_aff(pwaff
);
4878 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
4879 set2
= isl_set_read_from_str(ctx
, str
);
4880 equal
= isl_set_is_equal(set1
, set2
);
4886 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4888 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
4889 set
= isl_set_read_from_str(ctx
, str
);
4890 pwaff
= isl_set_dim_max(set
, 0);
4891 set1
= isl_set_from_pw_aff(pwaff
);
4892 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4893 set2
= isl_set_read_from_str(ctx
, str
);
4894 equal
= isl_set_is_equal(set1
, set2
);
4900 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4902 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
4903 set
= isl_set_read_from_str(ctx
, str
);
4904 pwaff
= isl_set_dim_max(set
, 0);
4905 set1
= isl_set_from_pw_aff(pwaff
);
4906 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4907 set2
= isl_set_read_from_str(ctx
, str
);
4908 equal
= isl_set_is_equal(set1
, set2
);
4914 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4916 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
4917 "0 <= i < N and 0 <= j < M }";
4918 map
= isl_map_read_from_str(ctx
, str
);
4919 set
= isl_map_range(map
);
4921 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
4922 set1
= isl_set_from_pw_aff(pwaff
);
4923 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
4924 set2
= isl_set_read_from_str(ctx
, str
);
4925 equal
= isl_set_is_equal(set1
, set2
);
4929 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
4930 set1
= isl_set_from_pw_aff(pwaff
);
4931 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
4932 set2
= isl_set_read_from_str(ctx
, str
);
4933 if (equal
>= 0 && equal
)
4934 equal
= isl_set_is_equal(set1
, set2
);
4943 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4945 /* Check that solutions are properly merged. */
4946 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
4947 "c <= -1 + n - 4a - 2b and c >= -2b and "
4948 "4a >= -4 + n and c >= 0 }";
4949 set
= isl_set_read_from_str(ctx
, str
);
4950 pwaff
= isl_set_dim_min(set
, 2);
4951 set1
= isl_set_from_pw_aff(pwaff
);
4952 str
= "[n] -> { [(0)] : n >= 1 }";
4953 set2
= isl_set_read_from_str(ctx
, str
);
4954 equal
= isl_set_is_equal(set1
, set2
);
4961 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4963 /* Check that empty solution lie in the right space. */
4964 str
= "[n] -> { [t,a] : 1 = 0 }";
4965 set
= isl_set_read_from_str(ctx
, str
);
4966 pwaff
= isl_set_dim_max(set
, 0);
4967 set1
= isl_set_from_pw_aff(pwaff
);
4968 str
= "[n] -> { [t] : 1 = 0 }";
4969 set2
= isl_set_read_from_str(ctx
, str
);
4970 equal
= isl_set_is_equal(set1
, set2
);
4977 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4982 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
4984 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
4988 isl_pw_multi_aff
*pma2
;
4994 ctx
= isl_pw_multi_aff_get_ctx(pma
);
4995 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4996 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
4997 isl_pw_multi_aff_free(pma2
);
5002 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
5003 * represented by "str".
5005 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
5010 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
5014 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
5015 "result not as expected", return -1);
5019 /* Basic test for isl_pw_multi_aff_product.
5021 * Check that multiple pieces are properly handled.
5023 static int test_product_pma(isl_ctx
*ctx
)
5027 isl_pw_multi_aff
*pma1
, *pma2
;
5029 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
5030 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5031 str
= "{ C[] -> D[] }";
5032 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5033 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
5034 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
5035 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
5036 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
5037 isl_pw_multi_aff_free(pma1
);
5044 int test_product(isl_ctx
*ctx
)
5048 isl_union_set
*uset1
, *uset2
;
5052 set
= isl_set_read_from_str(ctx
, str
);
5053 set
= isl_set_product(set
, isl_set_copy(set
));
5054 ok
= isl_set_is_wrapping(set
);
5059 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5062 uset1
= isl_union_set_read_from_str(ctx
, str
);
5063 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
5064 str
= "{ [[] -> []] }";
5065 uset2
= isl_union_set_read_from_str(ctx
, str
);
5066 ok
= isl_union_set_is_equal(uset1
, uset2
);
5067 isl_union_set_free(uset1
);
5068 isl_union_set_free(uset2
);
5072 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5074 if (test_product_pma(ctx
) < 0)
5080 /* Check that two sets are not considered disjoint just because
5081 * they have a different set of (named) parameters.
5083 static int test_disjoint(isl_ctx
*ctx
)
5086 isl_set
*set
, *set2
;
5089 str
= "[n] -> { [[]->[]] }";
5090 set
= isl_set_read_from_str(ctx
, str
);
5091 str
= "{ [[]->[]] }";
5092 set2
= isl_set_read_from_str(ctx
, str
);
5093 disjoint
= isl_set_is_disjoint(set
, set2
);
5099 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5104 /* Inputs for isl_pw_multi_aff_is_equal tests.
5105 * "f1" and "f2" are the two function that need to be compared.
5106 * "equal" is the expected result.
5112 } pma_equal_tests
[] = {
5113 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
5114 "[N] -> { [0] : 0 <= N <= 1 }" },
5115 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
5116 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
5117 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
5118 "[N] -> { [0] : 0 <= N <= 1 }" },
5119 { 0, "{ [NaN] }", "{ [NaN] }" },
5122 int test_equal(isl_ctx
*ctx
)
5126 isl_set
*set
, *set2
;
5130 set
= isl_set_read_from_str(ctx
, str
);
5132 set2
= isl_set_read_from_str(ctx
, str
);
5133 equal
= isl_set_is_equal(set
, set2
);
5139 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5141 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
5142 int expected
= pma_equal_tests
[i
].equal
;
5143 isl_pw_multi_aff
*f1
, *f2
;
5145 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
5146 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
5147 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
5148 isl_pw_multi_aff_free(f1
);
5149 isl_pw_multi_aff_free(f2
);
5152 if (equal
!= expected
)
5153 isl_die(ctx
, isl_error_unknown
,
5154 "unexpected equality result", return -1);
5160 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
5161 enum isl_dim_type type
, unsigned pos
, int fixed
)
5165 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
5172 isl_die(ctx
, isl_error_unknown
,
5173 "map not detected as fixed", return -1);
5175 isl_die(ctx
, isl_error_unknown
,
5176 "map detected as fixed", return -1);
5179 int test_fixed(isl_ctx
*ctx
)
5184 str
= "{ [i] -> [i] }";
5185 map
= isl_map_read_from_str(ctx
, str
);
5186 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
5188 str
= "{ [i] -> [1] }";
5189 map
= isl_map_read_from_str(ctx
, str
);
5190 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
5192 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
5193 map
= isl_map_read_from_str(ctx
, str
);
5194 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
5196 map
= isl_map_read_from_str(ctx
, str
);
5197 map
= isl_map_neg(map
);
5198 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
5204 struct isl_vertices_test_data
{
5207 const char *vertex
[6];
5208 } vertices_tests
[] = {
5209 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
5210 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
5211 { "{ A[t, i] : t = 14 and i = 1 }",
5212 1, { "{ A[14, 1] }" } },
5213 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
5214 "c <= m and m <= n and m > 0 }",
5216 "[n, m] -> { [n, m, m] : 0 < m <= n }",
5217 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
5218 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
5219 "[n, m] -> { [m, m, m] : 0 < m <= n }",
5220 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
5221 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
5225 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
5227 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
5229 struct isl_vertices_test_data
*data
= user
;
5232 isl_basic_set
*bset
;
5233 isl_pw_multi_aff
*pma
;
5237 ctx
= isl_vertex_get_ctx(vertex
);
5238 bset
= isl_vertex_get_domain(vertex
);
5239 ma
= isl_vertex_get_expr(vertex
);
5240 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
5242 for (i
= 0; i
< data
->n
; ++i
) {
5243 isl_pw_multi_aff
*pma_i
;
5245 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
5246 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
5247 isl_pw_multi_aff_free(pma_i
);
5249 if (equal
< 0 || equal
)
5253 isl_pw_multi_aff_free(pma
);
5254 isl_vertex_free(vertex
);
5257 return isl_stat_error
;
5259 return equal
? isl_stat_ok
: isl_stat_error
;
5262 int test_vertices(isl_ctx
*ctx
)
5266 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
5267 isl_basic_set
*bset
;
5268 isl_vertices
*vertices
;
5272 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
5273 vertices
= isl_basic_set_compute_vertices(bset
);
5274 n
= isl_vertices_get_n_vertices(vertices
);
5275 if (vertices_tests
[i
].n
!= n
)
5277 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
5278 &vertices_tests
[i
]) < 0)
5280 isl_vertices_free(vertices
);
5281 isl_basic_set_free(bset
);
5286 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
5293 int test_union_pw(isl_ctx
*ctx
)
5297 isl_union_set
*uset
;
5298 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
5300 str
= "{ [x] -> x^2 }";
5301 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
5302 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
5303 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
5304 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
5305 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
5306 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
5307 isl_union_pw_qpolynomial_free(upwqp1
);
5308 isl_union_pw_qpolynomial_free(upwqp2
);
5312 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5317 /* Test that isl_union_pw_qpolynomial_eval picks up the function
5318 * defined over the correct domain space.
5320 static int test_eval_1(isl_ctx
*ctx
)
5325 isl_union_pw_qpolynomial
*upwqp
;
5329 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
5330 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
5332 set
= isl_set_read_from_str(ctx
, str
);
5333 pnt
= isl_set_sample_point(set
);
5334 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
5335 cmp
= isl_val_cmp_si(v
, 36);
5341 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
5346 /* Check that isl_qpolynomial_eval handles getting called on a void point.
5348 static int test_eval_2(isl_ctx
*ctx
)
5353 isl_qpolynomial
*qp
;
5357 str
= "{ A[x] -> [x] }";
5358 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
5359 str
= "{ A[x] : false }";
5360 set
= isl_set_read_from_str(ctx
, str
);
5361 pnt
= isl_set_sample_point(set
);
5362 v
= isl_qpolynomial_eval(qp
, pnt
);
5363 ok
= isl_val_is_nan(v
);
5369 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
5374 /* Perform basic polynomial evaluation tests.
5376 static int test_eval(isl_ctx
*ctx
)
5378 if (test_eval_1(ctx
) < 0)
5380 if (test_eval_2(ctx
) < 0)
5385 /* Descriptions of sets that are tested for reparsing after printing.
5387 const char *output_tests
[] = {
5388 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
5391 /* Check that printing a set and reparsing a set from the printed output
5392 * results in the same set.
5394 static int test_output_set(isl_ctx
*ctx
)
5398 isl_set
*set1
, *set2
;
5401 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
5402 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
5403 str
= isl_set_to_str(set1
);
5404 set2
= isl_set_read_from_str(ctx
, str
);
5406 equal
= isl_set_is_equal(set1
, set2
);
5412 isl_die(ctx
, isl_error_unknown
,
5413 "parsed output not the same", return -1);
5419 int test_output(isl_ctx
*ctx
)
5427 if (test_output_set(ctx
) < 0)
5430 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
5431 pa
= isl_pw_aff_read_from_str(ctx
, str
);
5433 p
= isl_printer_to_str(ctx
);
5434 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
5435 p
= isl_printer_print_pw_aff(p
, pa
);
5436 s
= isl_printer_get_str(p
);
5437 isl_printer_free(p
);
5438 isl_pw_aff_free(pa
);
5442 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
5447 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5452 int test_sample(isl_ctx
*ctx
)
5455 isl_basic_set
*bset1
, *bset2
;
5458 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
5459 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
5460 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
5461 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
5462 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
5463 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
5464 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
5465 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
5466 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
5467 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
5468 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
5469 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
5470 "d - 1073741821e and "
5471 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
5472 "3j >= 1 - a + b + 2e and "
5473 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
5474 "3i <= 4 - a + 4b - e and "
5475 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
5476 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
5477 "c <= -1 + a and 3i >= -2 - a + 3e and "
5478 "1073741822e <= 1073741823 - a + 1073741822b + c and "
5479 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
5480 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
5481 "1073741823e >= 1 + 1073741823b - d and "
5482 "3i >= 1073741823b + c - 1073741823e - f and "
5483 "3i >= 1 + 2b + e + 3g }";
5484 bset1
= isl_basic_set_read_from_str(ctx
, str
);
5485 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
5486 empty
= isl_basic_set_is_empty(bset2
);
5487 subset
= isl_basic_set_is_subset(bset2
, bset1
);
5488 isl_basic_set_free(bset1
);
5489 isl_basic_set_free(bset2
);
5490 if (empty
< 0 || subset
< 0)
5493 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
5495 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
5500 int test_fixed_power(isl_ctx
*ctx
)
5508 str
= "{ [i] -> [i + 1] }";
5509 map
= isl_map_read_from_str(ctx
, str
);
5510 isl_int_set_si(exp
, 23);
5511 map
= isl_map_fixed_power(map
, exp
);
5512 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
5521 int test_slice(isl_ctx
*ctx
)
5527 str
= "{ [i] -> [j] }";
5528 map
= isl_map_read_from_str(ctx
, str
);
5529 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5530 equal
= map_check_equal(map
, "{ [i] -> [i] }");
5535 str
= "{ [i] -> [j] }";
5536 map
= isl_map_read_from_str(ctx
, str
);
5537 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5538 equal
= map_check_equal(map
, "{ [i] -> [j] }");
5543 str
= "{ [i] -> [j] }";
5544 map
= isl_map_read_from_str(ctx
, str
);
5545 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5546 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
5551 str
= "{ [i] -> [j] }";
5552 map
= isl_map_read_from_str(ctx
, str
);
5553 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5554 equal
= map_check_equal(map
, "{ [0] -> [j] }");
5559 str
= "{ [i] -> [j] }";
5560 map
= isl_map_read_from_str(ctx
, str
);
5561 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5562 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
5567 str
= "{ [i] -> [j] }";
5568 map
= isl_map_read_from_str(ctx
, str
);
5569 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5570 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
5578 int test_eliminate(isl_ctx
*ctx
)
5584 str
= "{ [i] -> [j] : i = 2j }";
5585 map
= isl_map_read_from_str(ctx
, str
);
5586 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
5587 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
5595 /* Check that isl_set_dim_residue_class detects that the values of j
5596 * in the set below are all odd and that it does not detect any spurious
5599 static int test_residue_class(isl_ctx
*ctx
)
5606 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
5607 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
5608 set
= isl_set_read_from_str(ctx
, str
);
5611 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
5613 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
5614 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
5615 res
= isl_stat_error
);
5623 int test_align_parameters(isl_ctx
*ctx
)
5627 isl_multi_aff
*ma1
, *ma2
;
5630 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
5631 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
5633 space
= isl_space_params_alloc(ctx
, 1);
5634 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
5635 ma1
= isl_multi_aff_align_params(ma1
, space
);
5637 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
5638 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
5640 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
5642 isl_multi_aff_free(ma1
);
5643 isl_multi_aff_free(ma2
);
5648 isl_die(ctx
, isl_error_unknown
,
5649 "result not as expected", return -1);
5654 static int test_list(isl_ctx
*ctx
)
5656 isl_id
*a
, *b
, *c
, *d
, *id
;
5660 a
= isl_id_alloc(ctx
, "a", NULL
);
5661 b
= isl_id_alloc(ctx
, "b", NULL
);
5662 c
= isl_id_alloc(ctx
, "c", NULL
);
5663 d
= isl_id_alloc(ctx
, "d", NULL
);
5665 list
= isl_id_list_alloc(ctx
, 4);
5666 list
= isl_id_list_add(list
, b
);
5667 list
= isl_id_list_insert(list
, 0, a
);
5668 list
= isl_id_list_add(list
, c
);
5669 list
= isl_id_list_add(list
, d
);
5670 list
= isl_id_list_drop(list
, 1, 1);
5672 if (isl_id_list_n_id(list
) != 3) {
5673 isl_id_list_free(list
);
5674 isl_die(ctx
, isl_error_unknown
,
5675 "unexpected number of elements in list", return -1);
5678 id
= isl_id_list_get_id(list
, 0);
5681 id
= isl_id_list_get_id(list
, 1);
5684 id
= isl_id_list_get_id(list
, 2);
5688 isl_id_list_free(list
);
5691 isl_die(ctx
, isl_error_unknown
,
5692 "unexpected elements in list", return -1);
5697 const char *set_conversion_tests
[] = {
5698 "[N] -> { [i] : N - 1 <= 2 i <= N }",
5699 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
5700 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
5701 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
5702 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
5703 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
5704 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
5705 "-3 + c <= d <= 28 + c) }",
5708 /* Check that converting from isl_set to isl_pw_multi_aff and back
5709 * to isl_set produces the original isl_set.
5711 static int test_set_conversion(isl_ctx
*ctx
)
5715 isl_set
*set1
, *set2
;
5716 isl_pw_multi_aff
*pma
;
5719 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
5720 str
= set_conversion_tests
[i
];
5721 set1
= isl_set_read_from_str(ctx
, str
);
5722 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
5723 set2
= isl_set_from_pw_multi_aff(pma
);
5724 equal
= isl_set_is_equal(set1
, set2
);
5731 isl_die(ctx
, isl_error_unknown
, "bad conversion",
5738 const char *conversion_tests
[] = {
5739 "{ [a, b, c, d] -> s0[a, b, e, f] : "
5740 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
5741 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
5742 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
5744 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
5745 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
5746 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
5749 /* Check that converting from isl_map to isl_pw_multi_aff and back
5750 * to isl_map produces the original isl_map.
5752 static int test_map_conversion(isl_ctx
*ctx
)
5755 isl_map
*map1
, *map2
;
5756 isl_pw_multi_aff
*pma
;
5759 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
5760 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
5761 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
5762 map2
= isl_map_from_pw_multi_aff(pma
);
5763 equal
= isl_map_is_equal(map1
, map2
);
5770 isl_die(ctx
, isl_error_unknown
, "bad conversion",
5777 static int test_conversion(isl_ctx
*ctx
)
5779 if (test_set_conversion(ctx
) < 0)
5781 if (test_map_conversion(ctx
) < 0)
5786 /* Check that isl_basic_map_curry does not modify input.
5788 static int test_curry(isl_ctx
*ctx
)
5791 isl_basic_map
*bmap1
, *bmap2
;
5794 str
= "{ [A[] -> B[]] -> C[] }";
5795 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
5796 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
5797 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
5798 isl_basic_map_free(bmap1
);
5799 isl_basic_map_free(bmap2
);
5804 isl_die(ctx
, isl_error_unknown
,
5805 "curried map should not be equal to original",
5815 } preimage_tests
[] = {
5816 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
5817 "{ A[j,i] -> B[i,j] }",
5818 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
5819 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
5820 "{ A[a,b] -> B[a/2,b/6] }",
5821 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
5822 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
5823 "{ A[a,b] -> B[a/2,b/6] }",
5824 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
5825 "exists i,j : a = 2 i and b = 6 j }" },
5826 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
5827 "[n] -> { : 0 <= n <= 100 }" },
5828 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
5829 "{ A[a] -> B[2a] }",
5830 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
5831 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
5832 "{ A[a] -> B[([a/2])] }",
5833 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
5834 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
5835 "{ A[a] -> B[a,a,a/3] }",
5836 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
5837 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
5838 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
5841 static int test_preimage_basic_set(isl_ctx
*ctx
)
5844 isl_basic_set
*bset1
, *bset2
;
5848 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
5849 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
5850 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
5851 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
5852 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
5853 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5854 isl_basic_set_free(bset1
);
5855 isl_basic_set_free(bset2
);
5859 isl_die(ctx
, isl_error_unknown
, "bad preimage",
5870 } preimage_domain_tests
[] = {
5871 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
5872 "{ A[j,i] -> B[i,j] }",
5873 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
5874 { "{ B[i] -> C[i]; D[i] -> E[i] }",
5875 "{ A[i] -> B[i + 1] }",
5876 "{ A[i] -> C[i + 1] }" },
5877 { "{ B[i] -> C[i]; B[i] -> E[i] }",
5878 "{ A[i] -> B[i + 1] }",
5879 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
5880 { "{ B[i] -> C[([i/2])] }",
5881 "{ A[i] -> B[2i] }",
5882 "{ A[i] -> C[i] }" },
5883 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
5884 "{ A[i] -> B[([i/5]), ([i/7])] }",
5885 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
5886 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
5887 "[N] -> { A[] -> B[([N/5])] }",
5888 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
5889 { "{ B[i] -> C[i] : exists a : i = 5 a }",
5890 "{ A[i] -> B[2i] }",
5891 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
5892 { "{ B[i] -> C[i] : exists a : i = 2 a; "
5893 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
5894 "{ A[i] -> B[2i] }",
5895 "{ A[i] -> C[2i] }" },
5896 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
5897 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
5900 static int test_preimage_union_map(isl_ctx
*ctx
)
5903 isl_union_map
*umap1
, *umap2
;
5907 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
5908 umap1
= isl_union_map_read_from_str(ctx
,
5909 preimage_domain_tests
[i
].map
);
5910 ma
= isl_multi_aff_read_from_str(ctx
,
5911 preimage_domain_tests
[i
].ma
);
5912 umap2
= isl_union_map_read_from_str(ctx
,
5913 preimage_domain_tests
[i
].res
);
5914 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
5915 equal
= isl_union_map_is_equal(umap1
, umap2
);
5916 isl_union_map_free(umap1
);
5917 isl_union_map_free(umap2
);
5921 isl_die(ctx
, isl_error_unknown
, "bad preimage",
5928 static int test_preimage(isl_ctx
*ctx
)
5930 if (test_preimage_basic_set(ctx
) < 0)
5932 if (test_preimage_union_map(ctx
) < 0)
5942 } pullback_tests
[] = {
5943 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
5944 "{ A[a,b] -> C[b + 2a] }" },
5945 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
5946 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
5947 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
5948 "{ A[a] -> C[(a)/6] }" },
5949 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
5950 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
5951 "{ A[a] -> C[(2a)/3] }" },
5952 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
5953 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
5954 "{ A[i,j] -> C[i + j, i + j] }"},
5955 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
5956 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
5957 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
5958 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
5959 "{ [i, j] -> [floor((i)/3), j] }",
5960 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
5963 static int test_pullback(isl_ctx
*ctx
)
5966 isl_multi_aff
*ma1
, *ma2
;
5970 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
5971 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
5972 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
5973 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
5974 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
5975 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
5976 isl_multi_aff_free(ma1
);
5977 isl_multi_aff_free(ma2
);
5981 isl_die(ctx
, isl_error_unknown
, "bad pullback",
5988 /* Check that negation is printed correctly and that equal expressions
5989 * are correctly identified.
5991 static int test_ast(isl_ctx
*ctx
)
5993 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
5997 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
5998 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
5999 expr
= isl_ast_expr_add(expr1
, expr2
);
6000 expr2
= isl_ast_expr_copy(expr
);
6001 expr
= isl_ast_expr_neg(expr
);
6002 expr2
= isl_ast_expr_neg(expr2
);
6003 equal
= isl_ast_expr_is_equal(expr
, expr2
);
6004 str
= isl_ast_expr_to_C_str(expr
);
6005 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
6007 isl_ast_expr_free(expr
);
6008 isl_ast_expr_free(expr2
);
6010 if (ok
< 0 || equal
< 0)
6013 isl_die(ctx
, isl_error_unknown
,
6014 "equal expressions not considered equal", return -1);
6016 isl_die(ctx
, isl_error_unknown
,
6017 "isl_ast_expr printed incorrectly", return -1);
6019 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
6020 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
6021 expr
= isl_ast_expr_add(expr1
, expr2
);
6022 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
6023 expr
= isl_ast_expr_sub(expr3
, expr
);
6024 str
= isl_ast_expr_to_C_str(expr
);
6025 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
6027 isl_ast_expr_free(expr
);
6032 isl_die(ctx
, isl_error_unknown
,
6033 "isl_ast_expr printed incorrectly", return -1);
6038 /* Check that isl_ast_build_expr_from_set returns a valid expression
6039 * for an empty set. Note that isl_ast_build_expr_from_set getting
6040 * called on an empty set probably indicates a bug in the caller.
6042 static int test_ast_build(isl_ctx
*ctx
)
6045 isl_ast_build
*build
;
6048 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6049 build
= isl_ast_build_from_context(set
);
6051 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
6052 expr
= isl_ast_build_expr_from_set(build
, set
);
6054 isl_ast_expr_free(expr
);
6055 isl_ast_build_free(build
);
6063 /* Internal data structure for before_for and after_for callbacks.
6065 * depth is the current depth
6066 * before is the number of times before_for has been called
6067 * after is the number of times after_for has been called
6069 struct isl_test_codegen_data
{
6075 /* This function is called before each for loop in the AST generated
6076 * from test_ast_gen1.
6078 * Increment the number of calls and the depth.
6079 * Check that the space returned by isl_ast_build_get_schedule_space
6080 * matches the target space of the schedule returned by
6081 * isl_ast_build_get_schedule.
6082 * Return an isl_id that is checked by the corresponding call
6085 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
6088 struct isl_test_codegen_data
*data
= user
;
6091 isl_union_map
*schedule
;
6092 isl_union_set
*uset
;
6097 ctx
= isl_ast_build_get_ctx(build
);
6099 if (data
->before
>= 3)
6100 isl_die(ctx
, isl_error_unknown
,
6101 "unexpected number of for nodes", return NULL
);
6102 if (data
->depth
>= 2)
6103 isl_die(ctx
, isl_error_unknown
,
6104 "unexpected depth", return NULL
);
6106 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
6110 schedule
= isl_ast_build_get_schedule(build
);
6111 uset
= isl_union_map_range(schedule
);
6114 if (isl_union_set_n_set(uset
) != 1) {
6115 isl_union_set_free(uset
);
6116 isl_die(ctx
, isl_error_unknown
,
6117 "expecting single range space", return NULL
);
6120 space
= isl_ast_build_get_schedule_space(build
);
6121 set
= isl_union_set_extract_set(uset
, space
);
6122 isl_union_set_free(uset
);
6123 empty
= isl_set_is_empty(set
);
6129 isl_die(ctx
, isl_error_unknown
,
6130 "spaces don't match", return NULL
);
6132 return isl_id_alloc(ctx
, name
, NULL
);
6135 /* This function is called after each for loop in the AST generated
6136 * from test_ast_gen1.
6138 * Increment the number of calls and decrement the depth.
6139 * Check that the annotation attached to the node matches
6140 * the isl_id returned by the corresponding call to before_for.
6142 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
6143 __isl_keep isl_ast_build
*build
, void *user
)
6145 struct isl_test_codegen_data
*data
= user
;
6153 if (data
->after
> data
->before
)
6154 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
6155 "mismatch in number of for nodes",
6156 return isl_ast_node_free(node
));
6158 id
= isl_ast_node_get_annotation(node
);
6160 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
6161 "missing annotation", return isl_ast_node_free(node
));
6163 name
= isl_id_get_name(id
);
6164 valid
= name
&& atoi(name
+ 1) == data
->depth
;
6168 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
6169 "wrong annotation", return isl_ast_node_free(node
));
6174 /* Check that the before_each_for and after_each_for callbacks
6175 * are called for each for loop in the generated code,
6176 * that they are called in the right order and that the isl_id
6177 * returned from the before_each_for callback is attached to
6178 * the isl_ast_node passed to the corresponding after_each_for call.
6180 static int test_ast_gen1(isl_ctx
*ctx
)
6184 isl_union_map
*schedule
;
6185 isl_ast_build
*build
;
6187 struct isl_test_codegen_data data
;
6189 str
= "[N] -> { : N >= 10 }";
6190 set
= isl_set_read_from_str(ctx
, str
);
6191 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
6192 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
6193 schedule
= isl_union_map_read_from_str(ctx
, str
);
6198 build
= isl_ast_build_from_context(set
);
6199 build
= isl_ast_build_set_before_each_for(build
,
6200 &before_for
, &data
);
6201 build
= isl_ast_build_set_after_each_for(build
,
6203 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6204 isl_ast_build_free(build
);
6208 isl_ast_node_free(tree
);
6210 if (data
.before
!= 3 || data
.after
!= 3)
6211 isl_die(ctx
, isl_error_unknown
,
6212 "unexpected number of for nodes", return -1);
6217 /* Check that the AST generator handles domains that are integrally disjoint
6218 * but not rationally disjoint.
6220 static int test_ast_gen2(isl_ctx
*ctx
)
6224 isl_union_map
*schedule
;
6225 isl_union_map
*options
;
6226 isl_ast_build
*build
;
6229 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
6230 schedule
= isl_union_map_read_from_str(ctx
, str
);
6231 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6232 build
= isl_ast_build_from_context(set
);
6234 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
6235 options
= isl_union_map_read_from_str(ctx
, str
);
6236 build
= isl_ast_build_set_options(build
, options
);
6237 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6238 isl_ast_build_free(build
);
6241 isl_ast_node_free(tree
);
6246 /* Increment *user on each call.
6248 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
6249 __isl_keep isl_ast_build
*build
, void *user
)
6258 /* Test that unrolling tries to minimize the number of instances.
6259 * In particular, for the schedule given below, make sure it generates
6260 * 3 nodes (rather than 101).
6262 static int test_ast_gen3(isl_ctx
*ctx
)
6266 isl_union_map
*schedule
;
6267 isl_union_map
*options
;
6268 isl_ast_build
*build
;
6272 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
6273 schedule
= isl_union_map_read_from_str(ctx
, str
);
6274 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6276 str
= "{ [i] -> unroll[0] }";
6277 options
= isl_union_map_read_from_str(ctx
, str
);
6279 build
= isl_ast_build_from_context(set
);
6280 build
= isl_ast_build_set_options(build
, options
);
6281 build
= isl_ast_build_set_at_each_domain(build
,
6282 &count_domains
, &n_domain
);
6283 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6284 isl_ast_build_free(build
);
6288 isl_ast_node_free(tree
);
6291 isl_die(ctx
, isl_error_unknown
,
6292 "unexpected number of for nodes", return -1);
6297 /* Check that if the ast_build_exploit_nested_bounds options is set,
6298 * we do not get an outer if node in the generated AST,
6299 * while we do get such an outer if node if the options is not set.
6301 static int test_ast_gen4(isl_ctx
*ctx
)
6305 isl_union_map
*schedule
;
6306 isl_ast_build
*build
;
6308 enum isl_ast_node_type type
;
6311 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
6312 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
6314 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
6316 schedule
= isl_union_map_read_from_str(ctx
, str
);
6317 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6318 build
= isl_ast_build_from_context(set
);
6319 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6320 isl_ast_build_free(build
);
6324 type
= isl_ast_node_get_type(tree
);
6325 isl_ast_node_free(tree
);
6327 if (type
== isl_ast_node_if
)
6328 isl_die(ctx
, isl_error_unknown
,
6329 "not expecting if node", return -1);
6331 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
6333 schedule
= isl_union_map_read_from_str(ctx
, str
);
6334 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6335 build
= isl_ast_build_from_context(set
);
6336 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6337 isl_ast_build_free(build
);
6341 type
= isl_ast_node_get_type(tree
);
6342 isl_ast_node_free(tree
);
6344 if (type
!= isl_ast_node_if
)
6345 isl_die(ctx
, isl_error_unknown
,
6346 "expecting if node", return -1);
6348 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
6353 /* This function is called for each leaf in the AST generated
6354 * from test_ast_gen5.
6356 * We finalize the AST generation by extending the outer schedule
6357 * with a zero-dimensional schedule. If this results in any for loops,
6358 * then this means that we did not pass along enough information
6359 * about the outer schedule to the inner AST generation.
6361 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
6364 isl_union_map
*schedule
, *extra
;
6367 schedule
= isl_ast_build_get_schedule(build
);
6368 extra
= isl_union_map_copy(schedule
);
6369 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
6370 schedule
= isl_union_map_range_product(schedule
, extra
);
6371 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6372 isl_ast_build_free(build
);
6377 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
6378 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
6379 "code should not contain any for loop",
6380 return isl_ast_node_free(tree
));
6385 /* Check that we do not lose any information when going back and
6386 * forth between internal and external schedule.
6388 * In particular, we create an AST where we unroll the only
6389 * non-constant dimension in the schedule. We therefore do
6390 * not expect any for loops in the AST. However, older versions
6391 * of isl would not pass along enough information about the outer
6392 * schedule when performing an inner code generation from a create_leaf
6393 * callback, resulting in the inner code generation producing a for loop.
6395 static int test_ast_gen5(isl_ctx
*ctx
)
6399 isl_union_map
*schedule
, *options
;
6400 isl_ast_build
*build
;
6403 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
6404 schedule
= isl_union_map_read_from_str(ctx
, str
);
6406 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
6407 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
6408 options
= isl_union_map_read_from_str(ctx
, str
);
6410 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6411 build
= isl_ast_build_from_context(set
);
6412 build
= isl_ast_build_set_options(build
, options
);
6413 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
6414 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6415 isl_ast_build_free(build
);
6416 isl_ast_node_free(tree
);
6423 /* Check that the expression
6425 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
6427 * is not combined into
6431 * as this would result in n/2 being evaluated in parts of
6432 * the definition domain where n is not a multiple of 2.
6434 static int test_ast_expr(isl_ctx
*ctx
)
6438 isl_ast_build
*build
;
6443 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
6444 isl_options_set_ast_build_detect_min_max(ctx
, 1);
6446 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
6447 pa
= isl_pw_aff_read_from_str(ctx
, str
);
6448 build
= isl_ast_build_alloc(ctx
);
6449 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
6450 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
6451 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
6452 isl_ast_build_free(build
);
6453 isl_ast_expr_free(expr
);
6455 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
6460 isl_die(ctx
, isl_error_unknown
,
6461 "expressions should not be combined", return -1);
6466 static int test_ast_gen(isl_ctx
*ctx
)
6468 if (test_ast_gen1(ctx
) < 0)
6470 if (test_ast_gen2(ctx
) < 0)
6472 if (test_ast_gen3(ctx
) < 0)
6474 if (test_ast_gen4(ctx
) < 0)
6476 if (test_ast_gen5(ctx
) < 0)
6478 if (test_ast_expr(ctx
) < 0)
6483 /* Check if dropping output dimensions from an isl_pw_multi_aff
6486 static int test_pw_multi_aff(isl_ctx
*ctx
)
6489 isl_pw_multi_aff
*pma1
, *pma2
;
6492 str
= "{ [i,j] -> [i+j, 4i-j] }";
6493 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6494 str
= "{ [i,j] -> [4i-j] }";
6495 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6497 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
6499 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
6501 isl_pw_multi_aff_free(pma1
);
6502 isl_pw_multi_aff_free(pma2
);
6506 isl_die(ctx
, isl_error_unknown
,
6507 "expressions not equal", return -1);
6512 /* Check that we can properly parse multi piecewise affine expressions
6513 * where the piecewise affine expressions have different domains.
6515 static int test_multi_pw_aff(isl_ctx
*ctx
)
6518 isl_set
*dom
, *dom2
;
6519 isl_multi_pw_aff
*mpa1
, *mpa2
;
6524 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
6525 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
6526 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
6527 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
6528 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
6529 str
= "{ [i] -> [(i : i > 0), 2i] }";
6530 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
6532 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
6534 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
6535 dom
= isl_pw_aff_domain(pa
);
6536 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
6537 dom2
= isl_pw_aff_domain(pa
);
6538 equal_domain
= isl_set_is_equal(dom
, dom2
);
6542 isl_multi_pw_aff_free(mpa1
);
6543 isl_multi_pw_aff_free(mpa2
);
6548 isl_die(ctx
, isl_error_unknown
,
6549 "expressions not equal", return -1);
6551 if (equal_domain
< 0)
6554 isl_die(ctx
, isl_error_unknown
,
6555 "domains unexpectedly equal", return -1);
6560 /* This is a regression test for a bug where isl_basic_map_simplify
6561 * would end up in an infinite loop. In particular, we construct
6562 * an empty basic set that is not obviously empty.
6563 * isl_basic_set_is_empty marks the basic set as empty.
6564 * After projecting out i3, the variable can be dropped completely,
6565 * but isl_basic_map_simplify refrains from doing so if the basic set
6566 * is empty and would end up in an infinite loop if it didn't test
6567 * explicitly for empty basic maps in the outer loop.
6569 static int test_simplify_1(isl_ctx
*ctx
)
6572 isl_basic_set
*bset
;
6575 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
6576 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
6577 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
6579 bset
= isl_basic_set_read_from_str(ctx
, str
);
6580 empty
= isl_basic_set_is_empty(bset
);
6581 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
6582 isl_basic_set_free(bset
);
6586 isl_die(ctx
, isl_error_unknown
,
6587 "basic set should be empty", return -1);
6592 /* Check that the equality in the set description below
6593 * is simplified away.
6595 static int test_simplify_2(isl_ctx
*ctx
)
6598 isl_basic_set
*bset
;
6601 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
6602 bset
= isl_basic_set_read_from_str(ctx
, str
);
6603 universe
= isl_basic_set_plain_is_universe(bset
);
6604 isl_basic_set_free(bset
);
6609 isl_die(ctx
, isl_error_unknown
,
6610 "equality not simplified away", return -1);
6614 /* Some simplification tests.
6616 static int test_simplify(isl_ctx
*ctx
)
6618 if (test_simplify_1(ctx
) < 0)
6620 if (test_simplify_2(ctx
) < 0)
6625 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
6626 * with gbr context would fail to disable the use of the shifted tableau
6627 * when transferring equalities for the input to the context, resulting
6628 * in invalid sample values.
6630 static int test_partial_lexmin(isl_ctx
*ctx
)
6633 isl_basic_set
*bset
;
6634 isl_basic_map
*bmap
;
6637 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
6638 bmap
= isl_basic_map_read_from_str(ctx
, str
);
6639 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
6640 bset
= isl_basic_set_read_from_str(ctx
, str
);
6641 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
6650 /* Check that the variable compression performed on the existentially
6651 * quantified variables inside isl_basic_set_compute_divs is not confused
6652 * by the implicit equalities among the parameters.
6654 static int test_compute_divs(isl_ctx
*ctx
)
6657 isl_basic_set
*bset
;
6660 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
6661 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
6662 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
6663 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
6664 bset
= isl_basic_set_read_from_str(ctx
, str
);
6665 set
= isl_basic_set_compute_divs(bset
);
6673 /* Check that the reaching domain elements and the prefix schedule
6674 * at a leaf node are the same before and after grouping.
6676 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
6681 isl_union_set
*uset
;
6682 isl_multi_union_pw_aff
*mupa
;
6683 isl_union_pw_multi_aff
*upma1
, *upma2
;
6684 isl_union_set
*domain1
, *domain2
;
6685 isl_union_map
*umap1
, *umap2
;
6686 isl_schedule_node
*node
;
6688 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
6689 uset
= isl_union_set_read_from_str(ctx
, str
);
6690 node
= isl_schedule_node_from_domain(uset
);
6691 node
= isl_schedule_node_child(node
, 0);
6692 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
6693 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6694 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6695 node
= isl_schedule_node_child(node
, 0);
6696 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
6697 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6698 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6699 node
= isl_schedule_node_child(node
, 0);
6700 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
6701 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
6702 domain1
= isl_schedule_node_get_domain(node
);
6703 id
= isl_id_alloc(ctx
, "group", NULL
);
6704 node
= isl_schedule_node_parent(node
);
6705 node
= isl_schedule_node_group(node
, id
);
6706 node
= isl_schedule_node_child(node
, 0);
6707 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
6708 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
6709 domain2
= isl_schedule_node_get_domain(node
);
6710 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
6711 if (equal
>= 0 && equal
)
6712 equal
= isl_union_set_is_equal(domain1
, domain2
);
6713 if (equal
>= 0 && equal
)
6714 equal
= isl_union_map_is_equal(umap1
, umap2
);
6715 isl_union_map_free(umap1
);
6716 isl_union_map_free(umap2
);
6717 isl_union_set_free(domain1
);
6718 isl_union_set_free(domain2
);
6719 isl_union_pw_multi_aff_free(upma1
);
6720 isl_union_pw_multi_aff_free(upma2
);
6721 isl_schedule_node_free(node
);
6726 isl_die(ctx
, isl_error_unknown
,
6727 "expressions not equal", return -1);
6732 /* Check that we can have nested groupings and that the union map
6733 * schedule representation is the same before and after the grouping.
6734 * Note that after the grouping, the union map representation contains
6735 * the domain constraints from the ranges of the expansion nodes,
6736 * while they are missing from the union map representation of
6737 * the tree without expansion nodes.
6739 * Also check that the global expansion is as expected.
6741 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
6743 int equal
, equal_expansion
;
6746 isl_union_set
*uset
;
6747 isl_union_map
*umap1
, *umap2
;
6748 isl_union_map
*expansion1
, *expansion2
;
6749 isl_union_set_list
*filters
;
6750 isl_multi_union_pw_aff
*mupa
;
6751 isl_schedule
*schedule
;
6752 isl_schedule_node
*node
;
6754 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
6755 "S3[i,j] : 0 <= i,j < 10 }";
6756 uset
= isl_union_set_read_from_str(ctx
, str
);
6757 node
= isl_schedule_node_from_domain(uset
);
6758 node
= isl_schedule_node_child(node
, 0);
6759 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
6760 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6761 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6762 node
= isl_schedule_node_child(node
, 0);
6763 str
= "{ S1[i,j] }";
6764 uset
= isl_union_set_read_from_str(ctx
, str
);
6765 filters
= isl_union_set_list_from_union_set(uset
);
6766 str
= "{ S2[i,j]; S3[i,j] }";
6767 uset
= isl_union_set_read_from_str(ctx
, str
);
6768 filters
= isl_union_set_list_add(filters
, uset
);
6769 node
= isl_schedule_node_insert_sequence(node
, filters
);
6770 node
= isl_schedule_node_child(node
, 1);
6771 node
= isl_schedule_node_child(node
, 0);
6772 str
= "{ S2[i,j] }";
6773 uset
= isl_union_set_read_from_str(ctx
, str
);
6774 filters
= isl_union_set_list_from_union_set(uset
);
6775 str
= "{ S3[i,j] }";
6776 uset
= isl_union_set_read_from_str(ctx
, str
);
6777 filters
= isl_union_set_list_add(filters
, uset
);
6778 node
= isl_schedule_node_insert_sequence(node
, filters
);
6780 schedule
= isl_schedule_node_get_schedule(node
);
6781 umap1
= isl_schedule_get_map(schedule
);
6782 uset
= isl_schedule_get_domain(schedule
);
6783 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
6784 isl_schedule_free(schedule
);
6786 node
= isl_schedule_node_parent(node
);
6787 node
= isl_schedule_node_parent(node
);
6788 id
= isl_id_alloc(ctx
, "group1", NULL
);
6789 node
= isl_schedule_node_group(node
, id
);
6790 node
= isl_schedule_node_child(node
, 1);
6791 node
= isl_schedule_node_child(node
, 0);
6792 id
= isl_id_alloc(ctx
, "group2", NULL
);
6793 node
= isl_schedule_node_group(node
, id
);
6795 schedule
= isl_schedule_node_get_schedule(node
);
6796 umap2
= isl_schedule_get_map(schedule
);
6797 isl_schedule_free(schedule
);
6799 node
= isl_schedule_node_root(node
);
6800 node
= isl_schedule_node_child(node
, 0);
6801 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
6802 isl_schedule_node_free(node
);
6804 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
6805 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
6806 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
6808 expansion2
= isl_union_map_read_from_str(ctx
, str
);
6810 equal
= isl_union_map_is_equal(umap1
, umap2
);
6811 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
6813 isl_union_map_free(umap1
);
6814 isl_union_map_free(umap2
);
6815 isl_union_map_free(expansion1
);
6816 isl_union_map_free(expansion2
);
6818 if (equal
< 0 || equal_expansion
< 0)
6821 isl_die(ctx
, isl_error_unknown
,
6822 "expressions not equal", return -1);
6823 if (!equal_expansion
)
6824 isl_die(ctx
, isl_error_unknown
,
6825 "unexpected expansion", return -1);
6830 /* Some tests for the isl_schedule_node_group function.
6832 static int test_schedule_tree_group(isl_ctx
*ctx
)
6834 if (test_schedule_tree_group_1(ctx
) < 0)
6836 if (test_schedule_tree_group_2(ctx
) < 0)
6845 { "{ rat: [i] : 0 <= i <= 10 }",
6846 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
6847 { "{ rat: [i] : FALSE }",
6848 "{ rat: coefficients[[cst] -> [a]] }" },
6850 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
6857 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
6858 "{ rat: [i] : 0 <= i <= 10 }" },
6859 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
6861 { "{ rat: coefficients[[cst] -> [a]] }",
6862 "{ rat: [i] : FALSE }" },
6865 /* Test the basic functionality of isl_basic_set_coefficients and
6866 * isl_basic_set_solutions.
6868 static int test_dual(isl_ctx
*ctx
)
6872 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
6874 isl_basic_set
*bset1
, *bset2
;
6876 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
6877 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
6878 bset1
= isl_basic_set_coefficients(bset1
);
6879 equal
= isl_basic_set_is_equal(bset1
, bset2
);
6880 isl_basic_set_free(bset1
);
6881 isl_basic_set_free(bset2
);
6885 isl_die(ctx
, isl_error_unknown
,
6886 "incorrect dual", return -1);
6889 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
6891 isl_basic_set
*bset1
, *bset2
;
6893 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
6894 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
6895 bset1
= isl_basic_set_solutions(bset1
);
6896 equal
= isl_basic_set_is_equal(bset1
, bset2
);
6897 isl_basic_set_free(bset1
);
6898 isl_basic_set_free(bset2
);
6902 isl_die(ctx
, isl_error_unknown
,
6903 "incorrect dual", return -1);
6913 const char *schedule
;
6918 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
6919 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6921 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
6922 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6924 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
6925 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6927 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
6928 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6930 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
6931 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6933 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
6934 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
6936 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
6937 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6939 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
6940 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
6944 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
6945 * tile the band and then check if the tile and point bands have the
6946 * expected partial schedule.
6948 static int test_tile(isl_ctx
*ctx
)
6954 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
6955 shift
= isl_options_get_tile_shift_point_loops(ctx
);
6957 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
6961 isl_union_set
*domain
;
6962 isl_multi_union_pw_aff
*mupa
, *mupa2
;
6963 isl_schedule_node
*node
;
6964 isl_multi_val
*sizes
;
6966 opt
= tile_tests
[i
].scale_tile
;
6967 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
6968 opt
= tile_tests
[i
].shift_point
;
6969 isl_options_set_tile_shift_point_loops(ctx
, opt
);
6971 str
= tile_tests
[i
].domain
;
6972 domain
= isl_union_set_read_from_str(ctx
, str
);
6973 node
= isl_schedule_node_from_domain(domain
);
6974 node
= isl_schedule_node_child(node
, 0);
6975 str
= tile_tests
[i
].schedule
;
6976 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6977 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6978 str
= tile_tests
[i
].sizes
;
6979 sizes
= isl_multi_val_read_from_str(ctx
, str
);
6980 node
= isl_schedule_node_band_tile(node
, sizes
);
6982 str
= tile_tests
[i
].tile
;
6983 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6984 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
6985 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
6986 isl_multi_union_pw_aff_free(mupa
);
6987 isl_multi_union_pw_aff_free(mupa2
);
6989 node
= isl_schedule_node_child(node
, 0);
6991 str
= tile_tests
[i
].point
;
6992 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6993 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
6994 if (equal
>= 0 && equal
)
6995 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
6997 isl_multi_union_pw_aff_free(mupa
);
6998 isl_multi_union_pw_aff_free(mupa2
);
7000 isl_schedule_node_free(node
);
7005 isl_die(ctx
, isl_error_unknown
,
7006 "unexpected result", return -1);
7009 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
7010 isl_options_set_tile_shift_point_loops(ctx
, shift
);
7015 /* Check that the domain hash of a space is equal to the hash
7016 * of the domain of the space.
7018 static int test_domain_hash(isl_ctx
*ctx
)
7022 uint32_t hash1
, hash2
;
7024 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
7025 space
= isl_map_get_space(map
);
7027 hash1
= isl_space_get_domain_hash(space
);
7028 space
= isl_space_domain(space
);
7029 hash2
= isl_space_get_hash(space
);
7030 isl_space_free(space
);
7035 isl_die(ctx
, isl_error_unknown
,
7036 "domain hash not equal to hash of domain", return -1);
7041 /* Check that a universe basic set that is not obviously equal to the universe
7042 * is still recognized as being equal to the universe.
7044 static int test_universe(isl_ctx
*ctx
)
7047 isl_basic_set
*bset
;
7050 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
7051 bset
= isl_basic_set_read_from_str(ctx
, s
);
7052 is_univ
= isl_basic_set_is_universe(bset
);
7053 isl_basic_set_free(bset
);
7058 isl_die(ctx
, isl_error_unknown
,
7059 "not recognized as universe set", return -1);
7064 /* Sets for which chambers are computed and checked.
7066 const char *chambers_tests
[] = {
7067 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
7068 "z >= 0 and z <= C - y and z <= B - x - y }",
7071 /* Add the domain of "cell" to "cells".
7073 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
7075 isl_basic_set_list
**cells
= user
;
7078 dom
= isl_cell_get_domain(cell
);
7079 isl_cell_free(cell
);
7080 *cells
= isl_basic_set_list_add(*cells
, dom
);
7082 return *cells
? isl_stat_ok
: isl_stat_error
;
7085 /* Check that the elements of "list" are pairwise disjoint.
7087 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
7092 return isl_stat_error
;
7094 n
= isl_basic_set_list_n_basic_set(list
);
7095 for (i
= 0; i
< n
; ++i
) {
7096 isl_basic_set
*bset_i
;
7098 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
7099 for (j
= i
+ 1; j
< n
; ++j
) {
7100 isl_basic_set
*bset_j
;
7103 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
7104 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
7105 isl_basic_set_free(bset_j
);
7107 isl_die(isl_basic_set_list_get_ctx(list
),
7108 isl_error_unknown
, "not disjoint",
7110 if (disjoint
< 0 || !disjoint
)
7113 isl_basic_set_free(bset_i
);
7115 return isl_stat_error
;
7121 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
7122 * are pairwise disjoint.
7124 static int test_chambers(isl_ctx
*ctx
)
7128 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
7129 isl_basic_set
*bset
;
7130 isl_vertices
*vertices
;
7131 isl_basic_set_list
*cells
;
7134 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
7135 vertices
= isl_basic_set_compute_vertices(bset
);
7136 cells
= isl_basic_set_list_alloc(ctx
, 0);
7137 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
7139 cells
= isl_basic_set_list_free(cells
);
7140 ok
= check_pairwise_disjoint(cells
);
7141 isl_basic_set_list_free(cells
);
7142 isl_vertices_free(vertices
);
7143 isl_basic_set_free(bset
);
7154 int (*fn
)(isl_ctx
*ctx
);
7156 { "universe", &test_universe
},
7157 { "domain hash", &test_domain_hash
},
7158 { "dual", &test_dual
},
7159 { "dependence analysis", &test_flow
},
7160 { "val", &test_val
},
7161 { "compute divs", &test_compute_divs
},
7162 { "partial lexmin", &test_partial_lexmin
},
7163 { "simplify", &test_simplify
},
7164 { "curry", &test_curry
},
7165 { "piecewise multi affine expressions", &test_pw_multi_aff
},
7166 { "multi piecewise affine expressions", &test_multi_pw_aff
},
7167 { "conversion", &test_conversion
},
7168 { "list", &test_list
},
7169 { "align parameters", &test_align_parameters
},
7170 { "preimage", &test_preimage
},
7171 { "pullback", &test_pullback
},
7172 { "AST", &test_ast
},
7173 { "AST build", &test_ast_build
},
7174 { "AST generation", &test_ast_gen
},
7175 { "eliminate", &test_eliminate
},
7176 { "residue class", &test_residue_class
},
7177 { "div", &test_div
},
7178 { "slice", &test_slice
},
7179 { "fixed power", &test_fixed_power
},
7180 { "sample", &test_sample
},
7181 { "output", &test_output
},
7182 { "vertices", &test_vertices
},
7183 { "chambers", &test_chambers
},
7184 { "fixed", &test_fixed
},
7185 { "equal", &test_equal
},
7186 { "disjoint", &test_disjoint
},
7187 { "product", &test_product
},
7188 { "dim_max", &test_dim_max
},
7189 { "affine", &test_aff
},
7190 { "injective", &test_injective
},
7191 { "schedule (whole component)", &test_schedule_whole
},
7192 { "schedule (incremental)", &test_schedule_incremental
},
7193 { "schedule tree grouping", &test_schedule_tree_group
},
7194 { "tile", &test_tile
},
7195 { "union_pw", &test_union_pw
},
7196 { "eval", &test_eval
},
7197 { "parse", &test_parse
},
7198 { "single-valued", &test_sv
},
7199 { "affine hull", &test_affine_hull
},
7200 { "simple_hull", &test_simple_hull
},
7201 { "coalesce", &test_coalesce
},
7202 { "factorize", &test_factorize
},
7203 { "subset", &test_subset
},
7204 { "subtract", &test_subtract
},
7205 { "intersect", &test_intersect
},
7206 { "lexmin", &test_lexmin
},
7207 { "min", &test_min
},
7208 { "gist", &test_gist
},
7209 { "piecewise quasi-polynomials", &test_pwqp
},
7210 { "lift", &test_lift
},
7211 { "bound", &test_bound
},
7212 { "union", &test_union
},
7213 { "split periods", &test_split_periods
},
7214 { "lexicographic order", &test_lex
},
7215 { "bijectivity", &test_bijective
},
7216 { "dataflow analysis", &test_dep
},
7217 { "reading", &test_read
},
7218 { "bounded", &test_bounded
},
7219 { "construction", &test_construction
},
7220 { "dimension manipulation", &test_dim
},
7221 { "map application", &test_application
},
7222 { "convex hull", &test_convex_hull
},
7223 { "transitive closure", &test_closure
},
7226 int main(int argc
, char **argv
)
7229 struct isl_ctx
*ctx
;
7230 struct isl_options
*options
;
7232 options
= isl_options_new_with_defaults();
7234 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
7236 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
7237 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
7238 printf("%s\n", tests
[i
].name
);
7239 if (tests
[i
].fn(ctx
) < 0)