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>
28 #include <isl_constraint_private.h>
29 #include <isl/polynomial.h>
30 #include <isl/union_set.h>
31 #include <isl/union_map.h>
32 #include <isl_factorization.h>
33 #include <isl/schedule.h>
34 #include <isl/schedule_node.h>
35 #include <isl_options_private.h>
36 #include <isl_vertices_private.h>
37 #include <isl/ast_build.h>
40 #include <isl_ast_build_expr.h>
41 #include <isl/options.h>
43 #include "isl_srcdir.c"
45 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
47 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
50 char *pattern
= "%s/test_inputs/%s.%s";
52 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
54 filename
= isl_alloc_array(ctx
, char, length
);
59 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
64 void test_parse_map(isl_ctx
*ctx
, const char *str
)
68 map
= isl_map_read_from_str(ctx
, str
);
73 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
78 map
= isl_map_read_from_str(ctx
, str
);
79 map2
= isl_map_read_from_str(ctx
, str2
);
80 equal
= isl_map_is_equal(map
, map2
);
87 isl_die(ctx
, isl_error_unknown
, "maps not equal",
93 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
95 isl_pw_qpolynomial
*pwqp
;
97 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
99 isl_pw_qpolynomial_free(pwqp
);
102 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
106 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
108 isl_pw_aff_free(pwaff
);
111 /* Check that we can read an isl_multi_val from "str" without errors.
113 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
117 mv
= isl_multi_val_read_from_str(ctx
, str
);
118 isl_multi_val_free(mv
);
123 /* String descriptions of multi piecewise affine expressions
124 * that are used for testing printing and parsing.
126 static const char *reparse_multi_pw_aff_tests
[] = {
127 "{ A[x, y] -> [] : x + y >= 0 }",
128 "{ A[x, y] -> B[] : x + y >= 0 }",
129 "{ A[x, y] -> [x] : x + y >= 0 }",
130 "[N] -> { A[x, y] -> [x] : x + y <= N }",
131 "{ A[x, y] -> [x, y] : x + y >= 0 }",
132 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
133 "[N] -> { [] : N >= 0 }",
134 "[N] -> { [] : N >= 0 }",
135 "[N] -> { [N] : N >= 0 }",
136 "[N] -> { [N, N + 1] : N >= 0 }",
137 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
138 "{ [a] -> [b = a] }",
139 "{ [a] -> [b = a] : a >= 0 }",
143 #define BASE multi_pw_aff
145 #include "check_reparse_templ.c"
146 #include "check_reparse_test_templ.c"
148 /* String descriptions that cannot be parsed
149 * as multi piecewise affine expressions.
151 static const char *parse_multi_pw_aff_fail_tests
[] = {
152 "{ [a] -> [b] : b = a }",
153 "{ [a] -> [b = a] : b >= 0 }",
156 #include "check_parse_fail_test_templ.c"
158 /* String descriptions of piecewise multi affine expressions
159 * that are used for testing printing and parsing.
161 static const char *reparse_pw_multi_aff_tests
[] = {
163 "{ [x] -> [x % 4] }",
164 "{ [x] -> [x % 4] : x mod 3 = 1 }",
165 "{ [x, x] -> [x % 4] }",
166 "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }",
167 "{ [x, x mod 2] -> [x % 4] }",
171 #define BASE pw_multi_aff
173 #include "check_reparse_templ.c"
174 #include "check_reparse_test_templ.c"
176 /* Test parsing of piecewise multi affine expressions by printing
177 * the expressions and checking that parsing the output results
178 * in the same expression.
179 * Do this for an expression converted from a map with an output
180 * dimension name that is equal to an automatically generated name, and
181 * a set of expressions parsed from strings.
183 static isl_stat
test_parse_pma(isl_ctx
*ctx
)
186 isl_pw_multi_aff
*pma
;
188 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
189 pma
= isl_pw_multi_aff_from_map(map
);
190 if (check_reparse_pw_multi_aff(ctx
, pma
) < 0)
191 return isl_stat_error
;
193 if (check_reparse_pw_multi_aff_tests(ctx
) < 0)
194 return isl_stat_error
;
199 /* String descriptions that cannot be parsed
200 * as union piecewise multi affine expressions.
202 static const char *parse_union_pw_multi_aff_fail_tests
[] = {
203 "{ [a] -> [b] : b = a }",
204 "{ [a] -> [b = a] : b >= 0 }",
208 #define BASE union_pw_multi_aff
210 #include "check_parse_fail_test_templ.c"
212 /* Test parsing of union piecewise multi affine expressions.
214 * In particular, check some cases where parsing is supposed to fail.
216 static isl_stat
test_parse_upma(isl_ctx
*ctx
)
218 if (check_parse_union_pw_multi_aff_fail_tests(ctx
) < 0)
219 return isl_stat_error
;
224 /* Test parsing of multi piecewise affine expressions by printing
225 * the expressions and checking that parsing the output results
226 * in the same expression.
227 * Do this for a couple of manually constructed expressions,
228 * an expression converted from a map with an output dimension name
229 * that is equal to an automatically generated name, and
230 * a set of expressions parsed from strings.
232 * Additionally, check some cases where parsing is supposed to fail.
234 static int test_parse_mpa(isl_ctx
*ctx
)
239 isl_pw_multi_aff
*pma
;
240 isl_multi_pw_aff
*mpa
;
243 space
= isl_space_set_alloc(ctx
, 0, 0);
244 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
245 mpa
= isl_multi_pw_aff_zero(space
);
246 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
250 space
= isl_space_set_alloc(ctx
, 1, 0);
251 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
252 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
253 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
254 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
255 mpa
= isl_multi_pw_aff_zero(space
);
256 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
257 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
261 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
262 pma
= isl_pw_multi_aff_from_map(map
);
263 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma
);
264 if (check_reparse_multi_pw_aff(ctx
, mpa
) < 0)
267 if (check_reparse_multi_pw_aff_tests(ctx
) < 0)
269 if (check_parse_multi_pw_aff_fail_tests(ctx
) < 0)
275 /* String descriptions of multi union piecewise affine expressions
276 * that are used for testing printing and parsing.
278 static const char *reparse_multi_union_pw_aff_tests
[] = {
282 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
284 "[N] -> (A[] : { })",
285 "[N] -> (A[] : { : N >= 0 })",
286 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
287 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
288 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
289 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
290 "{ S[x] : x > 0; T[y] : y >= 0 })",
294 #define BASE multi_union_pw_aff
296 #include "check_reparse_templ.c"
297 #include "check_reparse_test_templ.c"
299 /* Test parsing of multi union piecewise affine expressions by printing
300 * the expressions and checking that parsing the output results
301 * in the same expression.
302 * Do this for a couple of manually constructed expressions and
303 * a set of expressions parsed from strings.
305 static int test_parse_mupa(isl_ctx
*ctx
)
308 isl_multi_union_pw_aff
*mupa
;
313 space
= isl_space_set_alloc(ctx
, 0, 0);
314 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
315 mupa
= isl_multi_union_pw_aff_zero(space
);
316 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
320 space
= isl_space_set_alloc(ctx
, 1, 0);
321 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
322 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
323 dom
= isl_set_universe(space
);
324 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
325 uset
= isl_union_set_from_set(dom
);
326 space
= isl_space_set_alloc(ctx
, 1, 0);
327 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
328 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
329 mupa
= isl_multi_union_pw_aff_zero(space
);
330 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
331 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
335 if (check_reparse_multi_union_pw_aff_tests(ctx
) < 0)
341 /* Test parsing of multi expressions.
343 static int test_parse_multi(isl_ctx
*ctx
)
345 if (test_parse_mpa(ctx
) < 0)
347 if (test_parse_mupa(ctx
) < 0)
353 /* Pairs of binary relation representations that should represent
354 * the same binary relations.
359 } parse_map_equal_tests
[] = {
360 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
361 "{ [x, y] : 2y >= 6 - x }" },
362 { "{ [x,y] : x <= min(y, 2*y+3) }",
363 "{ [x,y] : x <= y, 2*y + 3 }" },
364 { "{ [x,y] : x >= min(y, 2*y+3) }",
365 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
366 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
367 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
368 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
369 "{ [i,j] -> [min(i,j)] }" },
370 { "{ [i,j] : i != j }",
371 "{ [i,j] : i < j or i > j }" },
372 { "{ [i,j] : (i+1)*2 >= j }",
373 "{ [i, j] : j <= 2 + 2i }" },
374 { "{ [i] -> [i > 0 ? 4 : 5] }",
375 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
376 { "[N=2,M] -> { [i=[(M+N)/4]] }",
377 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
378 { "{ [x] : x >= 0 }",
379 "{ [x] : x-0 >= 0 }" },
380 { "{ [i] : ((i > 10)) }",
381 "{ [i] : i >= 11 }" },
383 "{ [i] -> [0 * i] }" },
384 { "{ [a] -> [b] : (not false) }",
385 "{ [a] -> [b] : true }" },
386 { "{ [i] : i/2 <= 5 }",
387 "{ [i] : i <= 10 }" },
388 { "{Sym=[n] [i] : i <= n }",
389 "[n] -> { [i] : i <= n }" },
392 { "{ [i] : 2*floor(i/2) = i }",
393 "{ [i] : exists a : i = 2 a }" },
394 { "{ [a] -> [b] : a = 5 implies b = 5 }",
395 "{ [a] -> [b] : a != 5 or b = 5 }" },
396 { "{ [a] -> [a - 1 : a > 0] }",
397 "{ [a] -> [a - 1] : a > 0 }" },
398 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
399 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
400 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
401 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
402 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
403 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
404 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
405 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
406 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
407 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
408 { "{ [a,b] -> [i,j] : a,b << i,j }",
409 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
410 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
411 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
412 { "{ [a,b] -> [i,j] : a,b >> i,j }",
413 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
414 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
415 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
416 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
417 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
418 "8c < n - 32a and i < n and c >= 0 and "
419 "c <= 3 and c >= -4a) }",
420 "{ [n] -> [i] : 0 <= i < n }" },
421 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
422 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
423 "{ [x] -> [] : 0 <= x <= 15 }" },
424 { "{ [x] -> [x] : }",
426 { "{ [x=4:5] -> [x + 1] }",
427 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
428 { "{ [x=4:5] -> [x + 1 : x + 1] }",
429 "{ [x=4:5] -> [x + 1] }" },
430 { "{ [x] -> [x - 1 : x + 1] }",
431 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
432 { "{ [x=4:] -> [x + 1] }",
433 "{ [x] -> [x + 1] : 4 <= x }" },
434 { "{ [x=:5] -> [x + 1] }",
435 "{ [x] -> [x + 1] : x <= 5 }" },
436 { "{ [x=:] -> [x + 1] }",
437 "{ [x] -> [x + 1] }" },
441 "{ [x, floor(x/4)] }" },
446 int test_parse(struct isl_ctx
*ctx
)
450 const char *str
, *str2
;
452 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
454 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
456 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
458 if (test_parse_multi(ctx
) < 0)
460 if (test_parse_pma(ctx
) < 0)
462 if (test_parse_upma(ctx
) < 0)
465 str
= "{ [i] -> [-i] }";
466 map
= isl_map_read_from_str(ctx
, str
);
470 str
= "{ A[i] -> L[([i/3])] }";
471 map
= isl_map_read_from_str(ctx
, str
);
475 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
476 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
477 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
479 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
480 str
= parse_map_equal_tests
[i
].map1
;
481 str2
= parse_map_equal_tests
[i
].map2
;
482 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
486 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
487 map
= isl_map_read_from_str(ctx
, str
);
488 str
= "{ [new, old] -> [o0, o1] : "
489 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
490 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
491 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
492 map2
= isl_map_read_from_str(ctx
, str
);
493 assert(isl_map_is_equal(map
, map2
));
497 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
498 map
= isl_map_read_from_str(ctx
, str
);
499 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
500 map2
= isl_map_read_from_str(ctx
, str
);
501 assert(isl_map_is_equal(map
, map2
));
505 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
506 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
507 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
508 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
509 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
514 static int test_read(isl_ctx
*ctx
)
518 isl_basic_set
*bset1
, *bset2
;
519 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
522 filename
= get_filename(ctx
, "set", "omega");
524 input
= fopen(filename
, "r");
527 bset1
= isl_basic_set_read_from_file(ctx
, input
);
528 bset2
= isl_basic_set_read_from_str(ctx
, str
);
530 equal
= isl_basic_set_is_equal(bset1
, bset2
);
532 isl_basic_set_free(bset1
);
533 isl_basic_set_free(bset2
);
541 isl_die(ctx
, isl_error_unknown
,
542 "read sets not equal", return -1);
547 static int test_bounded(isl_ctx
*ctx
)
552 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
553 bounded
= isl_set_is_bounded(set
);
559 isl_die(ctx
, isl_error_unknown
,
560 "set not considered bounded", return -1);
562 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
563 bounded
= isl_set_is_bounded(set
);
570 isl_die(ctx
, isl_error_unknown
,
571 "set considered bounded", return -1);
573 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
574 bounded
= isl_set_is_bounded(set
);
580 isl_die(ctx
, isl_error_unknown
,
581 "set considered bounded", return -1);
586 /* Construct the basic set { [i] : 5 <= i <= N } */
587 static int test_construction_1(isl_ctx
*ctx
)
594 space
= isl_space_set_alloc(ctx
, 1, 1);
595 bset
= isl_basic_set_universe(isl_space_copy(space
));
596 ls
= isl_local_space_from_space(space
);
598 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
599 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
600 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
601 bset
= isl_basic_set_add_constraint(bset
, c
);
603 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
604 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
605 c
= isl_constraint_set_constant_si(c
, -5);
606 bset
= isl_basic_set_add_constraint(bset
, c
);
608 isl_local_space_free(ls
);
609 isl_basic_set_free(bset
);
614 /* Construct the basic set { [x] : -100 <= x <= 100 }
615 * using isl_basic_set_{lower,upper}_bound_val and
616 * check that it is equal the same basic set parsed from a string.
618 static int test_construction_2(isl_ctx
*ctx
)
623 isl_basic_set
*bset1
, *bset2
;
625 v
= isl_val_int_from_si(ctx
, 100);
626 space
= isl_space_set_alloc(ctx
, 0, 1);
627 bset1
= isl_basic_set_universe(space
);
628 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
630 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
632 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
633 equal
= isl_basic_set_is_equal(bset1
, bset2
);
634 isl_basic_set_free(bset1
);
635 isl_basic_set_free(bset2
);
640 isl_die(ctx
, isl_error_unknown
,
641 "failed construction", return -1);
646 /* Basic tests for constructing basic sets.
648 static int test_construction(isl_ctx
*ctx
)
650 if (test_construction_1(ctx
) < 0)
652 if (test_construction_2(ctx
) < 0)
657 static int test_dim(isl_ctx
*ctx
)
660 isl_map
*map1
, *map2
;
663 map1
= isl_map_read_from_str(ctx
,
664 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
665 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
666 map2
= isl_map_read_from_str(ctx
,
667 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
668 equal
= isl_map_is_equal(map1
, map2
);
671 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
672 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
673 if (equal
>= 0 && equal
)
674 equal
= isl_map_is_equal(map1
, map2
);
682 isl_die(ctx
, isl_error_unknown
,
683 "unexpected result", return -1);
685 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
686 map1
= isl_map_read_from_str(ctx
, str
);
687 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
688 map2
= isl_map_read_from_str(ctx
, str
);
689 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
690 equal
= isl_map_is_equal(map1
, map2
);
697 isl_die(ctx
, isl_error_unknown
,
698 "unexpected result", return -1);
704 #define BASE multi_val
705 #include "isl_test_plain_equal_templ.c"
708 #define BASE multi_aff
709 #include "isl_test_plain_equal_templ.c"
711 /* Check that "val" is equal to the value described by "str".
712 * If "str" is "NaN", then check for a NaN value explicitly.
714 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
721 return isl_stat_error
;
723 ctx
= isl_val_get_ctx(val
);
724 res
= isl_val_read_from_str(ctx
, str
);
725 is_nan
= isl_val_is_nan(res
);
729 ok
= isl_val_is_nan(val
);
731 ok
= isl_val_eq(val
, res
);
734 return isl_stat_error
;
736 isl_die(ctx
, isl_error_unknown
,
737 "unexpected result", return isl_stat_error
);
742 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
746 { &isl_val_neg
, "0", "0" },
747 { &isl_val_abs
, "0", "0" },
748 { &isl_val_pow2
, "0", "1" },
749 { &isl_val_floor
, "0", "0" },
750 { &isl_val_ceil
, "0", "0" },
751 { &isl_val_neg
, "1", "-1" },
752 { &isl_val_neg
, "-1", "1" },
753 { &isl_val_neg
, "1/2", "-1/2" },
754 { &isl_val_neg
, "-1/2", "1/2" },
755 { &isl_val_neg
, "infty", "-infty" },
756 { &isl_val_neg
, "-infty", "infty" },
757 { &isl_val_neg
, "NaN", "NaN" },
758 { &isl_val_abs
, "1", "1" },
759 { &isl_val_abs
, "-1", "1" },
760 { &isl_val_abs
, "1/2", "1/2" },
761 { &isl_val_abs
, "-1/2", "1/2" },
762 { &isl_val_abs
, "infty", "infty" },
763 { &isl_val_abs
, "-infty", "infty" },
764 { &isl_val_abs
, "NaN", "NaN" },
765 { &isl_val_floor
, "1", "1" },
766 { &isl_val_floor
, "-1", "-1" },
767 { &isl_val_floor
, "1/2", "0" },
768 { &isl_val_floor
, "-1/2", "-1" },
769 { &isl_val_floor
, "infty", "infty" },
770 { &isl_val_floor
, "-infty", "-infty" },
771 { &isl_val_floor
, "NaN", "NaN" },
772 { &isl_val_ceil
, "1", "1" },
773 { &isl_val_ceil
, "-1", "-1" },
774 { &isl_val_ceil
, "1/2", "1" },
775 { &isl_val_ceil
, "-1/2", "0" },
776 { &isl_val_ceil
, "infty", "infty" },
777 { &isl_val_ceil
, "-infty", "-infty" },
778 { &isl_val_ceil
, "NaN", "NaN" },
779 { &isl_val_pow2
, "-3", "1/8" },
780 { &isl_val_pow2
, "-1", "1/2" },
781 { &isl_val_pow2
, "1", "2" },
782 { &isl_val_pow2
, "2", "4" },
783 { &isl_val_pow2
, "3", "8" },
784 { &isl_val_inv
, "1", "1" },
785 { &isl_val_inv
, "2", "1/2" },
786 { &isl_val_inv
, "1/2", "2" },
787 { &isl_val_inv
, "-2", "-1/2" },
788 { &isl_val_inv
, "-1/2", "-2" },
789 { &isl_val_inv
, "0", "NaN" },
790 { &isl_val_inv
, "NaN", "NaN" },
791 { &isl_val_inv
, "infty", "0" },
792 { &isl_val_inv
, "-infty", "0" },
795 /* Perform some basic tests of unary operations on isl_val objects.
797 static int test_un_val(isl_ctx
*ctx
)
801 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
803 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
806 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
807 fn
= val_un_tests
[i
].op
;
809 r
= val_check_equal(v
, val_un_tests
[i
].res
);
819 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
820 __isl_take isl_val
*v2
);
822 ['+'] = { &isl_val_add
},
823 ['-'] = { &isl_val_sub
},
824 ['*'] = { &isl_val_mul
},
825 ['/'] = { &isl_val_div
},
826 ['g'] = { &isl_val_gcd
},
827 ['m'] = { &isl_val_min
},
828 ['M'] = { &isl_val_max
},
836 } val_bin_tests
[] = {
837 { "0", '+', "0", "0" },
838 { "1", '+', "0", "1" },
839 { "1", '+', "1", "2" },
840 { "1", '-', "1", "0" },
841 { "1", '*', "1", "1" },
842 { "1", '/', "1", "1" },
843 { "2", '*', "3", "6" },
844 { "2", '*', "1/2", "1" },
845 { "2", '*', "1/3", "2/3" },
846 { "2/3", '*', "3/5", "2/5" },
847 { "2/3", '*', "7/5", "14/15" },
848 { "2", '/', "1/2", "4" },
849 { "-2", '/', "-1/2", "4" },
850 { "-2", '/', "1/2", "-4" },
851 { "2", '/', "-1/2", "-4" },
852 { "2", '/', "2", "1" },
853 { "2", '/', "3", "2/3" },
854 { "2/3", '/', "5/3", "2/5" },
855 { "2/3", '/', "5/7", "14/15" },
856 { "0", '/', "0", "NaN" },
857 { "42", '/', "0", "NaN" },
858 { "-42", '/', "0", "NaN" },
859 { "infty", '/', "0", "NaN" },
860 { "-infty", '/', "0", "NaN" },
861 { "NaN", '/', "0", "NaN" },
862 { "0", '/', "NaN", "NaN" },
863 { "42", '/', "NaN", "NaN" },
864 { "-42", '/', "NaN", "NaN" },
865 { "infty", '/', "NaN", "NaN" },
866 { "-infty", '/', "NaN", "NaN" },
867 { "NaN", '/', "NaN", "NaN" },
868 { "0", '/', "infty", "0" },
869 { "42", '/', "infty", "0" },
870 { "-42", '/', "infty", "0" },
871 { "infty", '/', "infty", "NaN" },
872 { "-infty", '/', "infty", "NaN" },
873 { "NaN", '/', "infty", "NaN" },
874 { "0", '/', "-infty", "0" },
875 { "42", '/', "-infty", "0" },
876 { "-42", '/', "-infty", "0" },
877 { "infty", '/', "-infty", "NaN" },
878 { "-infty", '/', "-infty", "NaN" },
879 { "NaN", '/', "-infty", "NaN" },
880 { "1", '-', "1/3", "2/3" },
881 { "1/3", '+', "1/2", "5/6" },
882 { "1/2", '+', "1/2", "1" },
883 { "3/4", '-', "1/4", "1/2" },
884 { "1/2", '-', "1/3", "1/6" },
885 { "infty", '+', "42", "infty" },
886 { "infty", '+', "infty", "infty" },
887 { "42", '+', "infty", "infty" },
888 { "infty", '-', "infty", "NaN" },
889 { "infty", '*', "infty", "infty" },
890 { "infty", '*', "-infty", "-infty" },
891 { "-infty", '*', "infty", "-infty" },
892 { "-infty", '*', "-infty", "infty" },
893 { "0", '*', "infty", "NaN" },
894 { "1", '*', "infty", "infty" },
895 { "infty", '*', "0", "NaN" },
896 { "infty", '*', "42", "infty" },
897 { "42", '-', "infty", "-infty" },
898 { "infty", '+', "-infty", "NaN" },
899 { "4", 'g', "6", "2" },
900 { "5", 'g', "6", "1" },
901 { "42", 'm', "3", "3" },
902 { "42", 'M', "3", "42" },
903 { "3", 'm', "42", "3" },
904 { "3", 'M', "42", "42" },
905 { "42", 'm', "infty", "42" },
906 { "42", 'M', "infty", "infty" },
907 { "42", 'm', "-infty", "-infty" },
908 { "42", 'M', "-infty", "42" },
909 { "42", 'm', "NaN", "NaN" },
910 { "42", 'M', "NaN", "NaN" },
911 { "infty", 'm', "-infty", "-infty" },
912 { "infty", 'M', "-infty", "infty" },
915 /* Perform some basic tests of binary operations on isl_val objects.
917 static int test_bin_val(isl_ctx
*ctx
)
920 isl_val
*v1
, *v2
, *res
;
921 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
922 __isl_take isl_val
*v2
);
925 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
926 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
927 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
928 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
929 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
931 if (isl_val_is_nan(res
))
932 ok
= isl_val_is_nan(v1
);
934 ok
= isl_val_eq(v1
, res
);
940 isl_die(ctx
, isl_error_unknown
,
941 "unexpected result", return -1);
947 /* Perform some basic tests on isl_val objects.
949 static int test_val(isl_ctx
*ctx
)
951 if (test_un_val(ctx
) < 0)
953 if (test_bin_val(ctx
) < 0)
958 /* Sets described using existentially quantified variables that
959 * can also be described without.
961 static const char *elimination_tests
[] = {
962 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
963 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
964 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
967 /* Check that redundant existentially quantified variables are
970 static int test_elimination(isl_ctx
*ctx
)
976 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
977 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
978 n
= isl_basic_set_dim(bset
, isl_dim_div
);
979 isl_basic_set_free(bset
);
983 isl_die(ctx
, isl_error_unknown
,
984 "expecting no existentials", return -1);
990 static int test_div(isl_ctx
*ctx
)
997 struct isl_basic_set
*bset
;
998 struct isl_constraint
*c
;
1001 space
= isl_space_set_alloc(ctx
, 0, 3);
1002 bset
= isl_basic_set_universe(isl_space_copy(space
));
1003 ls
= isl_local_space_from_space(space
);
1005 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1006 c
= isl_constraint_set_constant_si(c
, -1);
1007 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1008 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1009 bset
= isl_basic_set_add_constraint(bset
, c
);
1011 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1012 c
= isl_constraint_set_constant_si(c
, 1);
1013 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1014 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1015 bset
= isl_basic_set_add_constraint(bset
, c
);
1017 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1019 assert(bset
&& bset
->n_div
== 1);
1020 isl_local_space_free(ls
);
1021 isl_basic_set_free(bset
);
1024 space
= isl_space_set_alloc(ctx
, 0, 3);
1025 bset
= isl_basic_set_universe(isl_space_copy(space
));
1026 ls
= isl_local_space_from_space(space
);
1028 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1029 c
= isl_constraint_set_constant_si(c
, 1);
1030 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1031 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1032 bset
= isl_basic_set_add_constraint(bset
, c
);
1034 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1035 c
= isl_constraint_set_constant_si(c
, -1);
1036 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1037 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1038 bset
= isl_basic_set_add_constraint(bset
, c
);
1040 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1042 assert(bset
&& bset
->n_div
== 1);
1043 isl_local_space_free(ls
);
1044 isl_basic_set_free(bset
);
1047 space
= isl_space_set_alloc(ctx
, 0, 3);
1048 bset
= isl_basic_set_universe(isl_space_copy(space
));
1049 ls
= isl_local_space_from_space(space
);
1051 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1052 c
= isl_constraint_set_constant_si(c
, 1);
1053 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1054 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1055 bset
= isl_basic_set_add_constraint(bset
, c
);
1057 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1058 c
= isl_constraint_set_constant_si(c
, -3);
1059 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1060 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
1061 bset
= isl_basic_set_add_constraint(bset
, c
);
1063 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1065 assert(bset
&& bset
->n_div
== 1);
1066 isl_local_space_free(ls
);
1067 isl_basic_set_free(bset
);
1070 space
= isl_space_set_alloc(ctx
, 0, 3);
1071 bset
= isl_basic_set_universe(isl_space_copy(space
));
1072 ls
= isl_local_space_from_space(space
);
1074 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1075 c
= isl_constraint_set_constant_si(c
, 2);
1076 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1077 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1078 bset
= isl_basic_set_add_constraint(bset
, c
);
1080 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1081 c
= isl_constraint_set_constant_si(c
, -1);
1082 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1083 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1084 bset
= isl_basic_set_add_constraint(bset
, c
);
1086 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1088 assert(isl_basic_set_is_empty(bset
));
1089 isl_local_space_free(ls
);
1090 isl_basic_set_free(bset
);
1093 space
= isl_space_set_alloc(ctx
, 0, 3);
1094 bset
= isl_basic_set_universe(isl_space_copy(space
));
1095 ls
= isl_local_space_from_space(space
);
1097 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1098 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1099 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1100 bset
= isl_basic_set_add_constraint(bset
, c
);
1102 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1103 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1104 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1105 bset
= isl_basic_set_add_constraint(bset
, c
);
1107 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1109 assert(bset
&& bset
->n_div
== 0);
1110 isl_basic_set_free(bset
);
1111 isl_local_space_free(ls
);
1114 space
= isl_space_set_alloc(ctx
, 0, 3);
1115 bset
= isl_basic_set_universe(isl_space_copy(space
));
1116 ls
= isl_local_space_from_space(space
);
1118 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1119 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1120 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1121 bset
= isl_basic_set_add_constraint(bset
, c
);
1123 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1124 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1125 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1126 bset
= isl_basic_set_add_constraint(bset
, c
);
1128 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1130 assert(bset
&& bset
->n_div
== 1);
1131 isl_basic_set_free(bset
);
1132 isl_local_space_free(ls
);
1135 /* This test is a bit tricky. We set up an equality
1136 * a + 3b + 3c = 6 e0
1137 * Normalization of divs creates _two_ divs
1140 * Afterwards e0 is removed again because it has coefficient -1
1141 * and we end up with the original equality and div again.
1142 * Perhaps we can avoid the introduction of this temporary div.
1144 space
= isl_space_set_alloc(ctx
, 0, 4);
1145 bset
= isl_basic_set_universe(isl_space_copy(space
));
1146 ls
= isl_local_space_from_space(space
);
1148 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1149 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1150 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1151 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1152 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1153 bset
= isl_basic_set_add_constraint(bset
, c
);
1155 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1157 /* Test disabled for now */
1159 assert(bset && bset->n_div == 1);
1161 isl_local_space_free(ls
);
1162 isl_basic_set_free(bset
);
1165 space
= isl_space_set_alloc(ctx
, 0, 5);
1166 bset
= isl_basic_set_universe(isl_space_copy(space
));
1167 ls
= isl_local_space_from_space(space
);
1169 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1170 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1171 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1172 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1173 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1174 bset
= isl_basic_set_add_constraint(bset
, c
);
1176 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1177 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1178 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1179 c
= isl_constraint_set_constant_si(c
, 1);
1180 bset
= isl_basic_set_add_constraint(bset
, c
);
1182 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1184 /* Test disabled for now */
1186 assert(bset && bset->n_div == 1);
1188 isl_local_space_free(ls
);
1189 isl_basic_set_free(bset
);
1192 space
= isl_space_set_alloc(ctx
, 0, 4);
1193 bset
= isl_basic_set_universe(isl_space_copy(space
));
1194 ls
= isl_local_space_from_space(space
);
1196 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1197 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1198 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1199 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1200 bset
= isl_basic_set_add_constraint(bset
, c
);
1202 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1203 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1204 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1205 c
= isl_constraint_set_constant_si(c
, 2);
1206 bset
= isl_basic_set_add_constraint(bset
, c
);
1208 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1210 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1212 assert(!isl_basic_set_is_empty(bset
));
1214 isl_local_space_free(ls
);
1215 isl_basic_set_free(bset
);
1218 space
= isl_space_set_alloc(ctx
, 0, 3);
1219 bset
= isl_basic_set_universe(isl_space_copy(space
));
1220 ls
= isl_local_space_from_space(space
);
1222 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1223 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1224 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1225 bset
= isl_basic_set_add_constraint(bset
, c
);
1227 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1229 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1231 isl_local_space_free(ls
);
1232 isl_basic_set_free(bset
);
1234 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1235 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1236 set
= isl_set_read_from_str(ctx
, str
);
1237 set
= isl_set_compute_divs(set
);
1242 if (test_elimination(ctx
) < 0)
1245 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1246 set
= isl_set_read_from_str(ctx
, str
);
1247 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1248 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1249 empty
= isl_set_is_empty(set
);
1254 isl_die(ctx
, isl_error_unknown
,
1255 "result not as accurate as expected", return -1);
1260 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1264 struct isl_basic_set
*bset1
, *bset2
;
1265 struct isl_basic_map
*bmap
;
1267 filename
= get_filename(ctx
, name
, "omega");
1269 input
= fopen(filename
, "r");
1272 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1273 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1275 bset1
= isl_basic_set_apply(bset1
, bmap
);
1277 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1279 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1281 isl_basic_set_free(bset1
);
1282 isl_basic_set_free(bset2
);
1288 static int test_application(isl_ctx
*ctx
)
1290 test_application_case(ctx
, "application");
1291 test_application_case(ctx
, "application2");
1296 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1300 struct isl_basic_set
*bset1
, *bset2
;
1302 filename
= get_filename(ctx
, name
, "polylib");
1304 input
= fopen(filename
, "r");
1307 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1308 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1310 bset1
= isl_basic_set_affine_hull(bset1
);
1312 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1314 isl_basic_set_free(bset1
);
1315 isl_basic_set_free(bset2
);
1321 /* Pairs of sets and the corresponding expected results of
1322 * isl_basic_set_recession_cone.
1327 } recession_cone_tests
[] = {
1328 { "{ [i] : 0 <= i <= 10 }", "{ [0] }" },
1329 { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" },
1330 { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" },
1331 { "{ [i] : false }", "{ [i] : false }" },
1334 /* Perform some basic isl_basic_set_recession_cone tests.
1336 static int test_recession_cone(struct isl_ctx
*ctx
)
1340 for (i
= 0; i
< ARRAY_SIZE(recession_cone_tests
); ++i
) {
1342 isl_basic_set
*bset
;
1343 isl_basic_set
*cone
, *expected
;
1346 str
= recession_cone_tests
[i
].set
;
1347 bset
= isl_basic_set_read_from_str(ctx
, str
);
1348 str
= recession_cone_tests
[i
].cone
;
1349 expected
= isl_basic_set_read_from_str(ctx
, str
);
1350 cone
= isl_basic_set_recession_cone(bset
);
1351 equal
= isl_basic_set_is_equal(cone
, expected
);
1352 isl_basic_set_free(cone
);
1353 isl_basic_set_free(expected
);
1357 isl_die(ctx
, isl_error_unknown
, "unexpected cone",
1364 int test_affine_hull(struct isl_ctx
*ctx
)
1368 isl_basic_set
*bset
, *bset2
;
1372 test_affine_hull_case(ctx
, "affine2");
1373 test_affine_hull_case(ctx
, "affine");
1374 test_affine_hull_case(ctx
, "affine3");
1376 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1377 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1378 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1379 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1380 set
= isl_set_read_from_str(ctx
, str
);
1381 bset
= isl_set_affine_hull(set
);
1382 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1383 isl_basic_set_free(bset
);
1387 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1390 /* Check that isl_map_affine_hull is not confused by
1391 * the reordering of divs in isl_map_align_divs.
1393 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1394 "32e0 = b and 32e1 = c); "
1395 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1396 set
= isl_set_read_from_str(ctx
, str
);
1397 bset
= isl_set_affine_hull(set
);
1398 isl_basic_set_free(bset
);
1402 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1403 "32e2 = 31 + 31e0 }";
1404 set
= isl_set_read_from_str(ctx
, str
);
1405 bset
= isl_set_affine_hull(set
);
1406 str
= "{ [a] : exists e : a = 32 e }";
1407 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1408 subset
= isl_basic_set_is_subset(bset
, bset2
);
1409 isl_basic_set_free(bset
);
1410 isl_basic_set_free(bset2
);
1414 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1420 /* Test a special case of isl_set_plain_unshifted_simple_hull
1421 * where older versions of isl would include a redundant constraint
1423 * Check that the result does not have any constraints.
1425 static isl_stat
test_plain_unshifted_simple_hull_special(isl_ctx
*ctx
)
1428 isl_bool is_universe
;
1430 isl_basic_set
*bset
;
1432 str
= "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
1433 set
= isl_set_read_from_str(ctx
, str
);
1434 bset
= isl_set_plain_unshifted_simple_hull(set
);
1435 is_universe
= isl_basic_set_plain_is_universe(bset
);
1436 isl_basic_set_free(bset
);
1438 if (is_universe
< 0)
1439 return isl_stat_error
;
1441 isl_die(ctx
, isl_error_unknown
,
1442 "hull should not have any constraints",
1443 return isl_stat_error
);
1448 /* Inputs for simple hull tests, consisting of
1449 * the specific simple hull function, the input set and the expected result.
1452 __isl_give isl_basic_set
*(*fn
)(__isl_take isl_set
*set
);
1455 } simple_hull_tests
[] = {
1456 { &isl_set_plain_unshifted_simple_hull
,
1457 "{ [i,j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1458 "{ [i,j] : i >= 1 }" },
1459 { &isl_set_plain_unshifted_simple_hull
,
1460 "{ [n,i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1461 "(j mod 4 = 2 and k mod 6 = n) }",
1462 "{ [n,i,j,k] : j mod 4 = 2 }" },
1463 { &isl_set_unshifted_simple_hull
,
1464 "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1465 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1466 { &isl_set_simple_hull
,
1467 "{ [a, b] : b <= 0 and "
1468 "2*floor((-2*floor((b)/2))/5) >= a - floor((b)/2); "
1469 "[a, b] : a mod 2 = 0 }",
1473 /* Basic tests for various simple hull functions.
1475 static int test_various_simple_hull(isl_ctx
*ctx
)
1479 isl_basic_set
*hull
, *expected
;
1482 for (i
= 0; i
< ARRAY_SIZE(simple_hull_tests
); ++i
) {
1484 str
= simple_hull_tests
[i
].set
;
1485 set
= isl_set_read_from_str(ctx
, str
);
1486 str
= simple_hull_tests
[i
].hull
;
1487 expected
= isl_basic_set_read_from_str(ctx
, str
);
1488 hull
= simple_hull_tests
[i
].fn(set
);
1489 equal
= isl_basic_set_is_equal(hull
, expected
);
1490 isl_basic_set_free(hull
);
1491 isl_basic_set_free(expected
);
1495 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1502 static int test_simple_hull(struct isl_ctx
*ctx
)
1506 isl_basic_set
*bset
;
1509 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1510 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1511 set
= isl_set_read_from_str(ctx
, str
);
1512 bset
= isl_set_simple_hull(set
);
1513 is_empty
= isl_basic_set_is_empty(bset
);
1514 isl_basic_set_free(bset
);
1516 if (is_empty
== isl_bool_error
)
1519 if (is_empty
== isl_bool_false
)
1520 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1523 if (test_plain_unshifted_simple_hull_special(ctx
) < 0)
1525 if (test_various_simple_hull(ctx
) < 0)
1531 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1532 * "set" is the input set.
1533 * "offset" is the expected box offset.
1534 * "size" is the expected box size.
1540 } box_hull_tests
[] = {
1541 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1542 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1543 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1544 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1545 "{ S[0, -4] }", "{ S[10, 9] }" },
1546 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1547 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1548 "{ [3] }", "{ [8] }" },
1549 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1550 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1551 "[N] -> { [N] }", "{ [9] }" },
1554 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1556 static int test_box_hull(struct isl_ctx
*ctx
)
1560 for (i
= 0; i
< ARRAY_SIZE(box_hull_tests
); ++i
) {
1564 isl_multi_aff
*offset
;
1565 isl_multi_val
*size
;
1568 set
= isl_set_read_from_str(ctx
, box_hull_tests
[i
].set
);
1569 box
= isl_set_get_simple_fixed_box_hull(set
);
1570 offset
= isl_fixed_box_get_offset(box
);
1571 size
= isl_fixed_box_get_size(box
);
1572 str
= box_hull_tests
[i
].offset
;
1573 r
= multi_aff_check_plain_equal(offset
, str
);
1574 str
= box_hull_tests
[i
].size
;
1576 r
= multi_val_check_plain_equal(size
, str
);
1577 isl_multi_aff_free(offset
);
1578 isl_multi_val_free(size
);
1579 isl_fixed_box_free(box
);
1588 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1592 struct isl_basic_set
*bset1
, *bset2
;
1593 struct isl_set
*set
;
1595 filename
= get_filename(ctx
, name
, "polylib");
1597 input
= fopen(filename
, "r");
1600 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1601 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1603 set
= isl_basic_set_union(bset1
, bset2
);
1604 bset1
= isl_set_convex_hull(set
);
1606 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1608 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1610 isl_basic_set_free(bset1
);
1611 isl_basic_set_free(bset2
);
1620 } convex_hull_tests
[] = {
1621 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1622 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1623 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1624 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1625 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1626 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1627 "i2 <= 5 and i2 >= 4; "
1628 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1629 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1630 "i2 <= 5 + i0 and i2 >= i0 }" },
1631 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1632 "{ [x, y] : 1 = 0 }" },
1633 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1634 "[x, y, 0] : x >= 0 and y < 0 }",
1635 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1636 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1638 "[0, 2, 0]; [3, 1, 0] }",
1639 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1640 "5c <= 6 - a - 3b }" },
1643 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1646 int orig_convex
= ctx
->opt
->convex
;
1647 ctx
->opt
->convex
= convex
;
1649 test_convex_hull_case(ctx
, "convex0");
1650 test_convex_hull_case(ctx
, "convex1");
1651 test_convex_hull_case(ctx
, "convex2");
1652 test_convex_hull_case(ctx
, "convex3");
1653 test_convex_hull_case(ctx
, "convex4");
1654 test_convex_hull_case(ctx
, "convex5");
1655 test_convex_hull_case(ctx
, "convex6");
1656 test_convex_hull_case(ctx
, "convex7");
1657 test_convex_hull_case(ctx
, "convex8");
1658 test_convex_hull_case(ctx
, "convex9");
1659 test_convex_hull_case(ctx
, "convex10");
1660 test_convex_hull_case(ctx
, "convex11");
1661 test_convex_hull_case(ctx
, "convex12");
1662 test_convex_hull_case(ctx
, "convex13");
1663 test_convex_hull_case(ctx
, "convex14");
1664 test_convex_hull_case(ctx
, "convex15");
1666 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1667 isl_set
*set1
, *set2
;
1670 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1671 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1672 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1673 equal
= isl_set_is_equal(set1
, set2
);
1680 isl_die(ctx
, isl_error_unknown
,
1681 "unexpected convex hull", return -1);
1684 ctx
->opt
->convex
= orig_convex
;
1689 static int test_convex_hull(isl_ctx
*ctx
)
1691 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1693 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1698 /* Check that computing the gist of "map" with respect to "context"
1699 * does not make any copy of "map" get marked empty.
1700 * Earlier versions of isl would end up doing that.
1702 static isl_stat
test_gist_empty_pair(isl_ctx
*ctx
, const char *map
,
1703 const char *context
)
1705 isl_map
*m1
, *m2
, *m3
;
1706 isl_bool empty_before
, empty_after
;
1708 m1
= isl_map_read_from_str(ctx
, map
);
1709 m2
= isl_map_read_from_str(ctx
, context
);
1710 m3
= isl_map_copy(m1
);
1711 empty_before
= isl_map_is_empty(m3
);
1712 m1
= isl_map_gist(m1
, m2
);
1713 empty_after
= isl_map_is_empty(m3
);
1717 if (empty_before
< 0 || empty_after
< 0)
1718 return isl_stat_error
;
1720 isl_die(ctx
, isl_error_unknown
, "map should not be empty",
1721 return isl_stat_error
);
1723 isl_die(ctx
, isl_error_unknown
, "map should still not be empty",
1724 return isl_stat_error
);
1729 /* Check that computing a gist does not make any copy of the input
1731 * Earlier versions of isl would end up doing that on some pairs of inputs.
1733 static isl_stat
test_gist_empty(isl_ctx
*ctx
)
1735 const char *map
, *context
;
1737 map
= "{ [] -> [a, b, c] : 2b = 1 + a }";
1738 context
= "{ [] -> [a, b, c] : 2c = 2 + a }";
1739 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1740 return isl_stat_error
;
1741 map
= "{ [] -> [0, 0] }";
1742 context
= "{ [] -> [a, b] : a > b }";
1743 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1744 return isl_stat_error
;
1749 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1753 const char *context
;
1755 } plain_gist_tests
[] = {
1756 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1757 "{ [i] -> [j] : i >= 1 }",
1758 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1759 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1760 "(j mod 4 = 2 and k mod 6 = n) }",
1761 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1762 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1763 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1764 "{ [i] -> [j] : i > j }",
1765 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1768 /* Basic tests for isl_map_plain_gist_basic_map.
1770 static int test_plain_gist(isl_ctx
*ctx
)
1774 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1777 isl_map
*map
, *gist
;
1778 isl_basic_map
*context
;
1780 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1781 str
= plain_gist_tests
[i
].context
;
1782 context
= isl_basic_map_read_from_str(ctx
, str
);
1783 map
= isl_map_plain_gist_basic_map(map
, context
);
1784 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1785 equal
= isl_map_is_equal(map
, gist
);
1791 isl_die(ctx
, isl_error_unknown
,
1792 "incorrect gist result", return -1);
1798 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1802 const char *context
;
1803 } gist_fail_tests
[] = {
1804 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1805 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1806 "{ [i] : i >= 0 }" },
1809 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1810 * In particular, the user should be able to recover from the failure.
1812 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1817 on_error
= isl_options_get_on_error(ctx
);
1818 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1819 n
= ARRAY_SIZE(gist_fail_tests
);
1820 for (i
= 0; i
< n
; ++i
) {
1822 isl_basic_set
*bset
, *context
;
1824 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1825 str
= gist_fail_tests
[i
].context
;
1826 context
= isl_basic_set_read_from_str(ctx
, str
);
1827 bset
= isl_basic_set_gist(bset
, context
);
1828 isl_basic_set_free(bset
);
1832 isl_options_set_on_error(ctx
, on_error
);
1834 isl_die(ctx
, isl_error_unknown
,
1835 "operation not expected to succeed",
1836 return isl_stat_error
);
1843 const char *context
;
1847 "{ [1, b, 2 - b] : -1 <= b <= 2 }",
1849 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1850 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1851 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1852 "{ [a, b, c] : a <= 15 }" },
1853 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1854 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1855 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1856 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1857 { "{ [m, n, a, b] : a <= 2147 + n }",
1858 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1859 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1860 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1862 "{ [m, n, ku, kl] }" },
1863 { "{ [a, a, b] : a >= 10 }",
1864 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1865 "{ [a, a, b] : a >= 10 }" },
1866 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1867 "{ [0, j] : j >= 0 }" },
1868 /* Check that no constraints on i6 are introduced in the gist */
1869 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1870 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1871 "5e0 <= 381 - t1 and i4 <= 1) }",
1872 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1873 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1874 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1875 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1876 "20e0 >= 1511 - 4t1 - 5i4) }" },
1877 /* Check that no constraints on i6 are introduced in the gist */
1878 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1879 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1880 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1881 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1882 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1883 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1884 "20e1 <= 1530 - 4t1 - 5i4 and "
1885 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1886 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1887 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1888 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1889 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1890 "10e0 <= -91 + 5i4 + 4i6 and "
1891 "10e0 >= -105 + 5i4 + 4i6) }",
1892 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1893 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1894 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1895 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1896 "{ [a, b, q, p] : b >= 1 + a }",
1897 "{ [a, b, q, p] : false }" },
1898 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1899 "[n] -> { [x] : x mod 32 = 0 }",
1900 "[n] -> { [x = n] }" },
1901 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1902 "{ [x] : x mod 2 = 0 }" },
1903 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1904 "{ [x] : x mod 128 = 0 }" },
1905 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1906 "{ [x] : x mod 3200 = 0 }" },
1907 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1908 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1909 "{ [a, b, c = a] }" },
1910 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1911 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1912 "{ [a, b, c = a] : a mod 3 = 0 }" },
1913 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1914 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1916 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1917 "{ [x,y] : 1 <= y <= 3 }",
1921 /* Check that isl_set_gist behaves as expected.
1923 * For the test cases in gist_tests, besides checking that the result
1924 * is as expected, also check that applying the gist operation does
1925 * not modify the input set (an earlier version of isl would do that) and
1926 * that the test case is consistent, i.e., that the gist has the same
1927 * intersection with the context as the input set.
1929 static int test_gist(struct isl_ctx
*ctx
)
1933 isl_basic_set
*bset1
, *bset2
;
1934 isl_map
*map1
, *map2
;
1938 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1939 isl_bool equal_input
, equal_intersection
;
1940 isl_set
*set1
, *set2
, *copy
, *context
;
1942 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1943 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1944 copy
= isl_set_copy(set1
);
1945 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1946 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1947 equal
= isl_set_is_equal(set1
, set2
);
1949 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1950 equal_input
= isl_set_is_equal(set1
, copy
);
1952 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1953 set2
= isl_set_intersect(set2
, context
);
1954 equal_intersection
= isl_set_is_equal(set1
, set2
);
1957 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1960 isl_die(ctx
, isl_error_unknown
,
1961 "incorrect gist result", return -1);
1963 isl_die(ctx
, isl_error_unknown
,
1964 "gist modified input", return -1);
1966 isl_die(ctx
, isl_error_unknown
,
1967 "inconsistent gist test case", return -1);
1970 if (test_gist_fail(ctx
) < 0)
1973 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1974 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1975 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1976 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1977 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1978 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1979 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1980 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1981 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1982 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1983 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1984 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1985 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1986 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1987 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1988 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1989 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1990 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1991 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1992 bset1
= isl_basic_set_gist(bset1
, bset2
);
1993 assert(bset1
&& bset1
->n_div
== 0);
1994 isl_basic_set_free(bset1
);
1996 /* Check that the integer divisions of the second disjunct
1997 * do not spread to the first disjunct.
1999 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
2000 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
2001 "(exists (e0 = [(-1 + t1)/16], "
2002 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
2003 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
2004 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
2005 "o0 <= 4294967295 and t1 <= -1)) }";
2006 map1
= isl_map_read_from_str(ctx
, str
);
2007 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
2008 map2
= isl_map_read_from_str(ctx
, str
);
2009 map1
= isl_map_gist(map1
, map2
);
2013 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
2014 isl_map_free(map1
); return -1);
2015 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
2020 isl_die(ctx
, isl_error_unknown
, "expecting single div",
2023 if (test_gist_empty(ctx
) < 0)
2025 if (test_plain_gist(ctx
) < 0)
2031 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
2033 isl_set
*set
, *set2
;
2037 set
= isl_set_read_from_str(ctx
, str
);
2038 set
= isl_set_coalesce(set
);
2039 set2
= isl_set_read_from_str(ctx
, str
);
2040 equal
= isl_set_is_equal(set
, set2
);
2041 one
= set
&& set
->n
== 1;
2048 isl_die(ctx
, isl_error_unknown
,
2049 "coalesced set not equal to input", return -1);
2050 if (check_one
&& !one
)
2051 isl_die(ctx
, isl_error_unknown
,
2052 "coalesced set should not be a union", return -1);
2057 /* Inputs for coalescing tests with unbounded wrapping.
2058 * "str" is a string representation of the input set.
2059 * "single_disjunct" is set if we expect the result to consist of
2060 * a single disjunct.
2063 int single_disjunct
;
2065 } coalesce_unbounded_tests
[] = {
2066 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2067 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2068 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2069 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2071 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2072 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2073 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2074 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2075 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2076 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2077 { 1, "{ [0:1, 0:1]; [0, 2:3] }" },
2078 { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" },
2079 { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" },
2080 { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" },
2081 { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" },
2082 { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" },
2083 { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" },
2086 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2087 * option turned off.
2089 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
2095 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
2096 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
2098 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
2099 const char *str
= coalesce_unbounded_tests
[i
].str
;
2100 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
2101 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
2107 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
2112 /* Inputs for coalescing tests.
2113 * "str" is a string representation of the input set.
2114 * "single_disjunct" is set if we expect the result to consist of
2115 * a single disjunct.
2118 int single_disjunct
;
2120 } coalesce_tests
[] = {
2121 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2122 "y >= x & x >= 2 & 5 >= y }" },
2123 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2124 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2125 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2126 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2127 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2128 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2129 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2130 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2131 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2132 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2133 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2134 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2135 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2136 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2137 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2138 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2139 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2140 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2141 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2142 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2143 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2144 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2145 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2146 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2147 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2148 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2149 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2150 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2151 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2152 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2153 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2154 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2155 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2156 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2157 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2158 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2159 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2160 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2161 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2162 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2163 "[o0, o1, o2, o3, o4, o5, o6]] : "
2164 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2165 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2166 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2167 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2168 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2169 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2170 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2171 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2172 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2173 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2174 "o6 >= i3 + i6 - o3 and M >= 0 and "
2175 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2176 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2177 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2178 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2179 "(o0 = 0 and M >= 2 and N >= 3) or "
2180 "(M = 0 and o0 = 0 and N >= 3) }" },
2181 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2182 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2183 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2184 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2185 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2186 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2187 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2188 "(y = 3 and x = 1) }" },
2189 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2190 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2191 "i1 <= M and i3 <= M and i4 <= M) or "
2192 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2193 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2194 "i4 <= -1 + M) }" },
2195 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2196 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2197 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2198 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2199 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2200 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2201 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2202 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2203 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2204 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2205 { 0, "{ [a, b] : exists e : 2e = a and "
2206 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2207 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2208 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2209 "j >= 1 and j' <= i + j - i' and i >= 1; "
2211 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2212 "[i,j] : exists a : j = 3a }" },
2213 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2214 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2216 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2217 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2218 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2219 "c <= 6 + 8a and a >= 3; "
2220 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2221 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2222 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2223 "[x,0] : 3 <= x <= 4 }" },
2224 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2225 "[x,0] : 4 <= x <= 5 }" },
2226 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2227 "[x,0] : 3 <= x <= 5 }" },
2228 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2229 "[x,0] : 3 <= x <= 4 }" },
2230 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2232 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2233 { 1, "{ [0,0]; [1,1] }" },
2234 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2235 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2237 "[k, 0, k] : k <= 6 and k >= 1 }" },
2238 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2239 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2240 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2241 { 1, "[n] -> { [1] : n >= 0;"
2242 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2243 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2244 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2245 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2246 "2e0 <= x and 2e0 <= n);"
2247 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2249 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2250 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2251 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2253 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2254 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2256 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2257 "t1 >= 13 and t1 <= 16);"
2258 "[t1] : t1 <= 15 and t1 >= 12 }" },
2259 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2260 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2261 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2262 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2263 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2264 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2266 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2267 "(exists (e0 : 3e0 = -2 + c0)) }" },
2268 { 0, "[n, b0, t0] -> "
2269 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2270 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2271 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2272 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2273 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2274 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2275 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2276 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2277 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2278 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2279 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2280 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2281 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2282 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2283 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2284 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2285 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2286 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2287 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2288 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2289 { 0, "{ [i0, i1, i2] : "
2290 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2291 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2292 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2293 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2294 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2295 "32e0 <= 31 + i0)) or "
2297 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2298 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2299 "2*floor((c)/2) = c and 0 <= a <= 192;"
2300 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2302 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2303 "(0 <= a <= b <= n) }" },
2304 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2305 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2306 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2307 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2308 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2309 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2310 "b = 3 and 9e0 <= -19 + 2c)) }" },
2311 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2312 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2313 "(a = 4 and b = 3 and "
2314 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2315 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2316 "(b = -1 + a and 0 < a <= 3 and "
2317 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2318 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2319 "b = 3 and 9e0 <= -19 + 2c)) }" },
2320 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2322 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2324 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2325 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2326 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2327 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2328 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2329 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2330 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2331 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2332 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2333 { 1, "{ [a] : a <= 8 and "
2334 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2335 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2336 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2337 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2338 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2339 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2340 "(a < 0 and 3*floor((a)/3) < a) }" },
2341 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2342 "(a < -1 and 3*floor((a)/3) < a) }" },
2343 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2344 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2345 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2346 "or (2 <= a <= 15 and b < a)) }" },
2347 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2348 "32*floor((a)/32) < a) or a <= 15) }" },
2349 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2350 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2351 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2352 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2353 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2354 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2355 "S_0[n] : n <= m <= 2 + n }" },
2356 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2357 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2359 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2360 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2361 "2e0 < -a + 2b) }" },
2362 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2363 "[i, 0, i] : 0 <= i <= 7 }" },
2364 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2365 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2366 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2367 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2368 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2369 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2370 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2371 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2372 "a > 0 and a <= 5) }" },
2373 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2374 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2375 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2376 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2377 { 0, "{ [0:1, 0:1]; [0, 2:3] }" },
2378 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2379 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2380 { 1, "{ rat: [0:2]; rat: [1:3] }" },
2383 /* A specialized coalescing test case that would result
2384 * in a segmentation fault or a failed assertion in earlier versions of isl.
2386 static int test_coalesce_special(struct isl_ctx
*ctx
)
2389 isl_map
*map1
, *map2
;
2391 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2392 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2393 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2394 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2395 "o1 <= 239 and o1 >= 212)) or "
2396 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2397 "o1 <= 241 and o1 >= 240));"
2398 "[S_L220_OUT[] -> T7[]] -> "
2399 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2400 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2401 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2402 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2403 map1
= isl_map_read_from_str(ctx
, str
);
2404 map1
= isl_map_align_divs_internal(map1
);
2405 map1
= isl_map_coalesce(map1
);
2406 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2407 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2408 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2409 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2410 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2411 map2
= isl_map_read_from_str(ctx
, str
);
2412 map2
= isl_map_union(map2
, map1
);
2413 map2
= isl_map_align_divs_internal(map2
);
2414 map2
= isl_map_coalesce(map2
);
2422 /* Check that the union of the basic sets described by "str1" and "str2"
2423 * can be coalesced and that the result is equal to the union.
2424 * The explicit call to isl_basic_set_union prevents the implicit
2425 * equality constraints in the basic maps from being detected prior
2426 * to the call to isl_set_coalesce, at least at the point
2427 * where this function was introduced.
2429 static isl_stat
test_coalesce_union(isl_ctx
*ctx
, const char *str1
,
2432 isl_basic_set
*bset1
, *bset2
;
2433 isl_set
*set
, *set2
;
2436 bset1
= isl_basic_set_read_from_str(ctx
, str1
);
2437 bset2
= isl_basic_set_read_from_str(ctx
, str2
);
2438 set
= isl_basic_set_union(bset1
, bset2
);
2439 set
= isl_set_coalesce(set
);
2441 bset1
= isl_basic_set_read_from_str(ctx
, str1
);
2442 bset2
= isl_basic_set_read_from_str(ctx
, str2
);
2443 set2
= isl_basic_set_union(bset1
, bset2
);
2445 equal
= isl_set_is_equal(set
, set2
);
2450 return isl_stat_error
;
2452 isl_die(ctx
, isl_error_unknown
,
2453 "coalesced set not equal to input",
2454 return isl_stat_error
);
2456 return isl_stat_non_null(set
);
2459 /* A specialized coalescing test case that would result in an assertion
2460 * in an earlier version of isl. Use test_coalesce_union with
2461 * an explicit call to isl_basic_set_union to prevent the implicit
2462 * equality constraints in the first basic map from being detected prior
2463 * to the call to isl_set_coalesce, at least at the point
2464 * where this test case was introduced.
2466 static isl_stat
test_coalesce_special2(struct isl_ctx
*ctx
)
2471 str1
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2472 str2
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }";
2473 return test_coalesce_union(ctx
, str1
, str2
);
2476 /* Check that calling isl_set_coalesce does not leave other sets
2477 * that may share some information with the input to isl_set_coalesce
2478 * in an inconsistent state.
2479 * In particular, older versions of isl would modify all copies
2480 * of the basic sets in the isl_set_coalesce input in a way
2481 * that could leave them in an inconsistent state.
2482 * The result of printing any other set containing one of these
2483 * basic sets would then result in an invalid set description.
2485 static int test_coalesce_special3(isl_ctx
*ctx
)
2489 isl_set
*set1
, *set2
;
2492 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2493 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2494 set2
= isl_set_read_from_str(ctx
, str
);
2495 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2496 set1
= isl_set_coalesce(set1
);
2499 p
= isl_printer_to_str(ctx
);
2500 p
= isl_printer_print_set(p
, set2
);
2502 s
= isl_printer_get_str(p
);
2503 isl_printer_free(p
);
2504 set1
= isl_set_read_from_str(ctx
, s
);
2514 /* Check that calling isl_set_coalesce on the intersection of
2515 * the sets described by "s1" and "s2" does not leave other sets
2516 * that may share some information with the input to isl_set_coalesce
2517 * in an inconsistent state.
2518 * In particular, when isl_set_coalesce detects equality constraints,
2519 * it does not immediately perform Gaussian elimination on them,
2520 * but then it needs to ensure that it is performed at some point.
2521 * The input set has implicit equality constraints in the first disjunct.
2522 * It is constructed as an intersection, because otherwise
2523 * those equality constraints would already be detected during parsing.
2525 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2526 const char *s1
, const char *s2
)
2528 isl_set
*set1
, *set2
;
2530 set1
= isl_set_read_from_str(ctx
, s1
);
2531 set2
= isl_set_read_from_str(ctx
, s2
);
2532 set1
= isl_set_intersect(set1
, set2
);
2533 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2534 set1
= isl_set_coalesce(set1
);
2538 return isl_stat_error
;
2543 /* Check that calling isl_set_coalesce does not leave other sets
2544 * that may share some information with the input to isl_set_coalesce
2545 * in an inconsistent state, for the case where one disjunct
2546 * is a subset of the other.
2548 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2550 const char *s1
, *s2
;
2552 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2553 s2
= "{ [a, b] : -1 <= -a < b }";
2554 return test_coalesce_intersection(ctx
, s1
, s2
);
2557 /* Check that calling isl_set_coalesce does not leave other sets
2558 * that may share some information with the input to isl_set_coalesce
2559 * in an inconsistent state, for the case where two disjuncts
2562 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2564 const char *s1
, *s2
;
2566 s1
= "{ [a, b, c] : b <= 0 }";
2567 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2568 return test_coalesce_intersection(ctx
, s1
, s2
);
2571 /* Check that calling isl_set_coalesce does not leave other sets
2572 * that may share some information with the input to isl_set_coalesce
2573 * in an inconsistent state, for the case where two disjuncts
2574 * can be fused and where both disjuncts have implicit equality constraints.
2576 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2578 const char *s1
, *s2
;
2580 s1
= "{ [a, b, c] : c <= 0 }";
2581 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2582 return test_coalesce_intersection(ctx
, s1
, s2
);
2585 /* A specialized coalescing test case that would result in an assertion failure
2586 * in an earlier version of isl. Use test_coalesce_union with
2587 * an explicit call to isl_basic_set_union to prevent the implicit
2588 * equality constraints in the basic maps from being detected prior
2589 * to the call to isl_set_coalesce, at least at the point
2590 * where this test case was introduced.
2592 static isl_stat
test_coalesce_special7(isl_ctx
*ctx
)
2597 str1
= "{ [a, b, c=0:17] : a <= 7 and 2b <= 11 - a and "
2598 "c <= -7 + 2a and 2c >= - 3 + 3a - 2b }";
2599 str2
= "{ [a, b, c] : c > -15a and c >= -7 + 2a and c < 0 and "
2600 "3c <= -5 + 5a - 3b and 2b >= 11 - a }";
2601 return test_coalesce_union(ctx
, str1
, str2
);
2604 /* A specialized coalescing test case that would result in a disjunct
2605 * getting dropped in an earlier version of isl. Use test_coalesce_union with
2606 * an explicit call to isl_basic_set_union to prevent the implicit
2607 * equality constraints in the basic maps from being detected prior
2608 * to the call to isl_set_coalesce, at least at the point
2609 * where this test case was introduced.
2611 static isl_stat
test_coalesce_special8(isl_ctx
*ctx
)
2616 str1
= "{ [a, b, c] : 2c <= -a and b >= -a and b <= 5 and "
2617 "6c > -7a and 11c >= -5a - b and a <= 3 }";
2618 str2
= "{ [a, b, c] : 6c > -7a and b >= -a and b <= 5 and "
2619 "11c >= -5a - b and a >= 4 and 2b <= a and 2c <= -a }";
2620 return test_coalesce_union(ctx
, str1
, str2
);
2623 /* Test the functionality of isl_set_coalesce.
2624 * That is, check that the output is always equal to the input
2625 * and in some cases that the result consists of a single disjunct.
2627 static int test_coalesce(struct isl_ctx
*ctx
)
2631 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2632 const char *str
= coalesce_tests
[i
].str
;
2633 int check_one
= coalesce_tests
[i
].single_disjunct
;
2634 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2638 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2640 if (test_coalesce_special(ctx
) < 0)
2642 if (test_coalesce_special2(ctx
) < 0)
2644 if (test_coalesce_special3(ctx
) < 0)
2646 if (test_coalesce_special4(ctx
) < 0)
2648 if (test_coalesce_special5(ctx
) < 0)
2650 if (test_coalesce_special6(ctx
) < 0)
2652 if (test_coalesce_special7(ctx
) < 0)
2654 if (test_coalesce_special8(ctx
) < 0)
2660 /* Construct a representation of the graph on the right of Figure 1
2661 * in "Computing the Transitive Closure of a Union of
2662 * Affine Integer Tuple Relations".
2664 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2667 isl_map
*up
, *right
;
2669 dom
= isl_set_read_from_str(ctx
,
2670 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2671 "2 x - 3 y + 3 >= 0 }");
2672 right
= isl_map_read_from_str(ctx
,
2673 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2674 up
= isl_map_read_from_str(ctx
,
2675 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2676 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2677 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2678 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2679 up
= isl_map_intersect_range(up
, dom
);
2680 return isl_map_union(up
, right
);
2683 /* Construct a representation of the power of the graph
2684 * on the right of Figure 1 in "Computing the Transitive Closure of
2685 * a Union of Affine Integer Tuple Relations".
2687 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2689 return isl_map_read_from_str(ctx
,
2690 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2691 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2692 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2695 /* Construct a representation of the transitive closure of the graph
2696 * on the right of Figure 1 in "Computing the Transitive Closure of
2697 * a Union of Affine Integer Tuple Relations".
2699 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2701 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2704 static int test_closure(isl_ctx
*ctx
)
2707 isl_map
*map
, *map2
;
2708 isl_bool exact
, equal
;
2710 /* COCOA example 1 */
2711 map
= isl_map_read_from_str(ctx
,
2712 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2713 "1 <= i and i < n and 1 <= j and j < n or "
2714 "i2 = i + 1 and j2 = j - 1 and "
2715 "1 <= i and i < n and 2 <= j and j <= n }");
2716 map
= isl_map_power(map
, &exact
);
2720 /* COCOA example 1 */
2721 map
= isl_map_read_from_str(ctx
,
2722 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2723 "1 <= i and i < n and 1 <= j and j < n or "
2724 "i2 = i + 1 and j2 = j - 1 and "
2725 "1 <= i and i < n and 2 <= j and j <= n }");
2726 map
= isl_map_transitive_closure(map
, &exact
);
2728 map2
= isl_map_read_from_str(ctx
,
2729 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2730 "1 <= i and i < n and 1 <= j and j <= n and "
2731 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2732 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2733 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2734 assert(isl_map_is_equal(map
, map2
));
2738 map
= isl_map_read_from_str(ctx
,
2739 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2740 " 0 <= y and y <= n }");
2741 map
= isl_map_transitive_closure(map
, &exact
);
2742 map2
= isl_map_read_from_str(ctx
,
2743 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2744 " 0 <= y and y <= n }");
2745 assert(isl_map_is_equal(map
, map2
));
2749 /* COCOA example 2 */
2750 map
= isl_map_read_from_str(ctx
,
2751 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2752 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2753 "i2 = i + 2 and j2 = j - 2 and "
2754 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2755 map
= isl_map_transitive_closure(map
, &exact
);
2757 map2
= isl_map_read_from_str(ctx
,
2758 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2759 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2760 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2761 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2762 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2763 assert(isl_map_is_equal(map
, map2
));
2767 /* COCOA Fig.2 left */
2768 map
= isl_map_read_from_str(ctx
,
2769 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2770 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2772 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2773 "j <= 2 i - 3 and j <= n - 2 or "
2774 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2775 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2776 map
= isl_map_transitive_closure(map
, &exact
);
2780 /* COCOA Fig.2 right */
2781 map
= isl_map_read_from_str(ctx
,
2782 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2783 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2785 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2786 "j <= 2 i - 4 and j <= n - 3 or "
2787 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2788 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2789 map
= isl_map_power(map
, &exact
);
2793 /* COCOA Fig.2 right */
2794 map
= isl_map_read_from_str(ctx
,
2795 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2796 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2798 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2799 "j <= 2 i - 4 and j <= n - 3 or "
2800 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2801 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2802 map
= isl_map_transitive_closure(map
, &exact
);
2804 map2
= isl_map_read_from_str(ctx
,
2805 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2806 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2807 "j <= n and 3 + i + 2 j <= 3 n and "
2808 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2809 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2810 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2811 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2812 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2813 assert(isl_map_is_equal(map
, map2
));
2817 map
= cocoa_fig_1_right_graph(ctx
);
2818 map
= isl_map_transitive_closure(map
, &exact
);
2820 map2
= cocoa_fig_1_right_tc(ctx
);
2821 assert(isl_map_is_equal(map
, map2
));
2825 map
= cocoa_fig_1_right_graph(ctx
);
2826 map
= isl_map_power(map
, &exact
);
2827 map2
= cocoa_fig_1_right_power(ctx
);
2828 equal
= isl_map_is_equal(map
, map2
);
2834 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2836 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2838 /* COCOA Theorem 1 counter example */
2839 map
= isl_map_read_from_str(ctx
,
2840 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2841 "i2 = 1 and j2 = j or "
2842 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2843 map
= isl_map_transitive_closure(map
, &exact
);
2847 map
= isl_map_read_from_str(ctx
,
2848 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2849 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2850 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2851 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2852 map
= isl_map_transitive_closure(map
, &exact
);
2856 /* Kelly et al 1996, fig 12 */
2857 map
= isl_map_read_from_str(ctx
,
2858 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2859 "1 <= i,j,j+1 <= n or "
2860 "j = n and j2 = 1 and i2 = i + 1 and "
2861 "1 <= i,i+1 <= n }");
2862 map
= isl_map_transitive_closure(map
, &exact
);
2864 map2
= isl_map_read_from_str(ctx
,
2865 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2866 "1 <= i <= n and i = i2 or "
2867 "1 <= i < i2 <= n and 1 <= j <= n and "
2869 assert(isl_map_is_equal(map
, map2
));
2873 /* Omega's closure4 */
2874 map
= isl_map_read_from_str(ctx
,
2875 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2876 "1 <= x,y <= 10 or "
2877 "x2 = x + 1 and y2 = y and "
2878 "1 <= x <= 20 && 5 <= y <= 15 }");
2879 map
= isl_map_transitive_closure(map
, &exact
);
2883 map
= isl_map_read_from_str(ctx
,
2884 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2885 map
= isl_map_transitive_closure(map
, &exact
);
2887 map2
= isl_map_read_from_str(ctx
,
2888 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2889 assert(isl_map_is_equal(map
, map2
));
2893 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2894 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2895 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2896 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2897 map
= isl_map_read_from_str(ctx
, str
);
2898 map
= isl_map_transitive_closure(map
, &exact
);
2900 map2
= isl_map_read_from_str(ctx
, str
);
2901 assert(isl_map_is_equal(map
, map2
));
2905 str
= "{[0] -> [1]; [2] -> [3]}";
2906 map
= isl_map_read_from_str(ctx
, str
);
2907 map
= isl_map_transitive_closure(map
, &exact
);
2909 map2
= isl_map_read_from_str(ctx
, str
);
2910 assert(isl_map_is_equal(map
, map2
));
2914 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2915 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2916 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2917 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2918 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2919 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2920 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2921 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2922 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2923 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2924 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2925 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2926 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2927 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2928 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2929 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2930 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2931 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2932 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2933 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2934 map
= isl_map_read_from_str(ctx
, str
);
2935 map
= isl_map_transitive_closure(map
, NULL
);
2942 /* Check that the actual result of a boolean operation is equal
2943 * to the expected result.
2945 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2947 if (actual
!= expected
)
2948 isl_die(ctx
, isl_error_unknown
,
2949 "incorrect boolean operation", return isl_stat_error
);
2953 /* Test operations on isl_bool values.
2960 static int test_isl_bool(isl_ctx
*ctx
)
2962 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
2964 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
2966 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
2968 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
2970 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
2972 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
2974 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
2976 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
2982 static int test_lex(struct isl_ctx
*ctx
)
2988 space
= isl_space_set_alloc(ctx
, 0, 0);
2989 map
= isl_map_lex_le(space
);
2990 empty
= isl_map_is_empty(map
);
2996 isl_die(ctx
, isl_error_unknown
,
2997 "expecting non-empty result", return -1);
3002 /* Inputs for isl_map_lexmin tests.
3003 * "map" is the input and "lexmin" is the expected result.
3008 } lexmin_tests
[] = {
3009 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
3010 "{ [x] -> [5] : 6 <= x <= 8; "
3011 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
3012 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
3013 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
3014 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
3015 "{ [x] -> [y] : (4y = x and x >= 0) or "
3016 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
3017 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
3018 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
3019 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
3020 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
3021 /* Check that empty pieces are properly combined. */
3022 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
3023 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
3024 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
3025 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
3026 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
3028 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
3029 "a <= 255 and c <= 255 and d <= 255 - j and "
3030 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
3031 "247d <= 247 + k - j and 247d <= 247 + k - b and "
3032 "247d <= 247 + i and 248 - b <= 248d <= c and "
3033 "254d >= i - a + b and 254d >= -a + b and "
3034 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
3036 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
3037 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
3038 "247j >= 62738 - i and 509j <= 129795 + i and "
3039 "742j >= 188724 - i; "
3040 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
3041 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
3042 "16*floor((8 + b)/16) <= 7 + b; "
3044 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
3045 "[a] -> [b = 0] : 0 < a <= 509 }" },
3046 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
3047 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
3048 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
3051 static int test_lexmin(struct isl_ctx
*ctx
)
3056 isl_basic_map
*bmap
;
3057 isl_map
*map
, *map2
;
3060 isl_pw_multi_aff
*pma
;
3062 str
= "[p0, p1] -> { [] -> [] : "
3063 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
3064 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
3065 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
3066 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
3067 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
3068 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
3069 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
3070 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
3071 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
3072 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
3073 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
3074 map
= isl_map_read_from_str(ctx
, str
);
3075 map
= isl_map_lexmin(map
);
3080 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
3081 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
3082 set
= isl_set_read_from_str(ctx
, str
);
3083 set
= isl_set_lexmax(set
);
3084 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
3085 set2
= isl_set_read_from_str(ctx
, str
);
3086 set
= isl_set_intersect(set
, set2
);
3087 assert(!isl_set_is_empty(set
));
3090 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
3091 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
3092 map
= isl_map_lexmin(map
);
3093 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
3094 equal
= isl_map_is_equal(map
, map2
);
3101 isl_die(ctx
, isl_error_unknown
,
3102 "unexpected result", return -1);
3105 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3106 " 8i' <= i and 8i' >= -7 + i }";
3107 bmap
= isl_basic_map_read_from_str(ctx
, str
);
3108 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
3109 map2
= isl_map_from_pw_multi_aff(pma
);
3110 map
= isl_map_from_basic_map(bmap
);
3111 assert(isl_map_is_equal(map
, map2
));
3115 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3116 " 8i' <= i and 8i' >= -7 + i }";
3117 set
= isl_set_read_from_str(ctx
, str
);
3118 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
3119 set2
= isl_set_from_pw_multi_aff(pma
);
3120 equal
= isl_set_is_equal(set
, set2
);
3126 isl_die(ctx
, isl_error_unknown
,
3127 "unexpected difference between set and "
3128 "piecewise affine expression", return -1);
3133 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3134 * "pma" is the input.
3135 * "res" is the expected result.
3140 } opt_pw_tests
[] = {
3141 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3142 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3143 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3144 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3145 "{ A[10, 0, 20] }" },
3146 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3149 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3151 static isl_stat
test_pw_max(struct isl_ctx
*ctx
)
3154 isl_pw_multi_aff
*pma
;
3158 for (i
= 0; i
< ARRAY_SIZE(opt_pw_tests
); ++i
) {
3159 pma
= isl_pw_multi_aff_read_from_str(ctx
, opt_pw_tests
[i
].pma
);
3160 mv
= isl_pw_multi_aff_max_multi_val(pma
);
3161 r
= multi_val_check_plain_equal(mv
, opt_pw_tests
[i
].res
);
3162 isl_multi_val_free(mv
);
3165 return isl_stat_error
;
3171 /* A specialized isl_set_min_val test case that would return the wrong result
3172 * in earlier versions of isl.
3173 * The explicit call to isl_basic_set_union prevents the second basic set
3174 * from being determined to be empty prior to the call to isl_set_min_val,
3175 * at least at the point where this test case was introduced.
3177 static int test_min_special(isl_ctx
*ctx
)
3180 isl_basic_set
*bset1
, *bset2
;
3186 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3187 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3188 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3189 bset2
= isl_basic_set_read_from_str(ctx
, str
);
3190 set
= isl_basic_set_union(bset1
, bset2
);
3191 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
3193 res
= isl_set_min_val(set
, obj
);
3194 ok
= isl_val_cmp_si(res
, 5) == 0;
3203 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
3209 /* A specialized isl_set_min_val test case that would return an error
3210 * in earlier versions of isl.
3212 static int test_min_special2(isl_ctx
*ctx
)
3215 isl_basic_set
*bset
;
3219 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3220 bset
= isl_basic_set_read_from_str(ctx
, str
);
3222 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
3224 res
= isl_basic_set_max_val(bset
, obj
);
3226 isl_basic_set_free(bset
);
3236 /* Check that the result of isl_set_min_multi_pw_aff
3237 * on the union of the sets with string descriptions "s1" and "s2"
3238 * consists of a single expression (on a single cell).
3240 static isl_stat
check_single_expr_min(isl_ctx
*ctx
, const char *s1
,
3244 isl_set
*set1
, *set2
;
3245 isl_multi_pw_aff
*mpa
;
3246 isl_pw_multi_aff
*pma
;
3248 set1
= isl_set_read_from_str(ctx
, s1
);
3249 set2
= isl_set_read_from_str(ctx
, s2
);
3250 set1
= isl_set_union(set1
, set2
);
3251 mpa
= isl_set_min_multi_pw_aff(set1
);
3252 pma
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
3253 n
= isl_pw_multi_aff_n_piece(pma
);
3254 isl_pw_multi_aff_free(pma
);
3257 return isl_stat_error
;
3259 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
3260 return isl_stat_error
);
3264 /* A specialized isl_set_min_multi_pw_aff test that checks
3265 * that the minimum of 2N and 3N for N >= 0 is represented
3266 * by a single expression, without splitting off the special case N = 0.
3267 * Do this for both orderings.
3269 static int test_min_mpa(isl_ctx
*ctx
)
3271 const char *s1
, *s2
;
3273 s1
= "[N=0:] -> { [1, 3N:] }";
3274 s2
= "[N=0:] -> { [10, 2N:] }";
3275 if (check_single_expr_min(ctx
, s1
, s2
) < 0)
3277 if (check_single_expr_min(ctx
, s2
, s1
) < 0)
3286 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
3287 __isl_keep isl_aff
*obj
);
3290 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
3291 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
3292 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3293 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3294 &isl_set_max_val
, "30" },
3298 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3299 * In particular, check the results on non-convex inputs.
3301 static int test_min(struct isl_ctx
*ctx
)
3309 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
3310 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
3311 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
3312 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
3313 val
= opt_tests
[i
].fn(set
, obj
);
3314 ok
= isl_val_eq(res
, val
);
3323 isl_die(ctx
, isl_error_unknown
,
3324 "unexpected optimum", return -1);
3327 if (test_pw_max(ctx
) < 0)
3329 if (test_min_special(ctx
) < 0)
3331 if (test_min_special2(ctx
) < 0)
3342 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
3343 void *dep_user
, void *user
)
3345 struct must_may
*mm
= (struct must_may
*)user
;
3348 mm
->must
= isl_map_union(mm
->must
, dep
);
3350 mm
->may
= isl_map_union(mm
->may
, dep
);
3355 static int common_space(void *first
, void *second
)
3357 int depth
= *(int *)first
;
3361 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3369 map2
= isl_map_read_from_str(map
->ctx
, str
);
3370 equal
= isl_map_is_equal(map
, map2
);
3376 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3380 equal
= map_is_equal(map
, str
);
3384 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3385 "result not as expected", return -1);
3389 /* Is "set" equal to the set described by "str"?
3391 static isl_bool
set_is_equal(__isl_keep isl_set
*set
, const char *str
)
3397 return isl_bool_error
;
3399 set2
= isl_set_read_from_str(isl_set_get_ctx(set
), str
);
3400 equal
= isl_set_is_equal(set
, set2
);
3406 /* Check that "set" is equal to the set described by "str".
3408 static isl_stat
set_check_equal(__isl_keep isl_set
*set
, const char *str
)
3412 equal
= set_is_equal(set
, str
);
3414 return isl_stat_error
;
3416 isl_die(isl_set_get_ctx(set
), isl_error_unknown
,
3417 "result not as expected", return isl_stat_error
);
3421 /* Is "uset" equal to the union set described by "str"?
3423 static isl_bool
uset_is_equal(__isl_keep isl_union_set
*uset
, const char *str
)
3425 isl_union_set
*uset2
;
3429 return isl_bool_error
;
3431 uset2
= isl_union_set_read_from_str(isl_union_set_get_ctx(uset
), str
);
3432 equal
= isl_union_set_is_equal(uset
, uset2
);
3433 isl_union_set_free(uset2
);
3438 /* Check that "uset" is equal to the union set described by "str".
3440 static isl_stat
uset_check_equal(__isl_keep isl_union_set
*uset
,
3445 equal
= uset_is_equal(uset
, str
);
3447 return isl_stat_error
;
3449 isl_die(isl_union_set_get_ctx(uset
), isl_error_unknown
,
3450 "result not as expected", return isl_stat_error
);
3454 static int test_dep(struct isl_ctx
*ctx
)
3459 isl_access_info
*ai
;
3466 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3467 map
= isl_map_read_from_str(ctx
, str
);
3468 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3470 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3471 map
= isl_map_read_from_str(ctx
, str
);
3472 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3474 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3475 map
= isl_map_read_from_str(ctx
, str
);
3476 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3478 flow
= isl_access_info_compute_flow(ai
);
3479 space
= isl_space_alloc(ctx
, 0, 3, 3);
3480 mm
.must
= isl_map_empty(isl_space_copy(space
));
3481 mm
.may
= isl_map_empty(space
);
3483 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3485 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3486 " [1,10,0] -> [2,5,0] }";
3487 assert(map_is_equal(mm
.must
, str
));
3488 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3489 assert(map_is_equal(mm
.may
, str
));
3491 isl_map_free(mm
.must
);
3492 isl_map_free(mm
.may
);
3493 isl_flow_free(flow
);
3496 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3497 map
= isl_map_read_from_str(ctx
, str
);
3498 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3500 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3501 map
= isl_map_read_from_str(ctx
, str
);
3502 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3504 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3505 map
= isl_map_read_from_str(ctx
, str
);
3506 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3508 flow
= isl_access_info_compute_flow(ai
);
3509 space
= isl_space_alloc(ctx
, 0, 3, 3);
3510 mm
.must
= isl_map_empty(isl_space_copy(space
));
3511 mm
.may
= isl_map_empty(space
);
3513 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3515 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3516 assert(map_is_equal(mm
.must
, str
));
3517 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3518 assert(map_is_equal(mm
.may
, str
));
3520 isl_map_free(mm
.must
);
3521 isl_map_free(mm
.may
);
3522 isl_flow_free(flow
);
3525 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3526 map
= isl_map_read_from_str(ctx
, str
);
3527 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3529 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3530 map
= isl_map_read_from_str(ctx
, str
);
3531 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3533 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3534 map
= isl_map_read_from_str(ctx
, str
);
3535 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3537 flow
= isl_access_info_compute_flow(ai
);
3538 space
= isl_space_alloc(ctx
, 0, 3, 3);
3539 mm
.must
= isl_map_empty(isl_space_copy(space
));
3540 mm
.may
= isl_map_empty(space
);
3542 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3544 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3545 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3546 assert(map_is_equal(mm
.may
, str
));
3547 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3548 assert(map_is_equal(mm
.must
, str
));
3550 isl_map_free(mm
.must
);
3551 isl_map_free(mm
.may
);
3552 isl_flow_free(flow
);
3555 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3556 map
= isl_map_read_from_str(ctx
, str
);
3557 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3559 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3560 map
= isl_map_read_from_str(ctx
, str
);
3561 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3563 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3564 map
= isl_map_read_from_str(ctx
, str
);
3565 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3567 flow
= isl_access_info_compute_flow(ai
);
3568 space
= isl_space_alloc(ctx
, 0, 3, 3);
3569 mm
.must
= isl_map_empty(isl_space_copy(space
));
3570 mm
.may
= isl_map_empty(space
);
3572 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3574 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3575 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3576 assert(map_is_equal(mm
.may
, str
));
3577 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3578 assert(map_is_equal(mm
.must
, str
));
3580 isl_map_free(mm
.must
);
3581 isl_map_free(mm
.may
);
3582 isl_flow_free(flow
);
3585 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3586 map
= isl_map_read_from_str(ctx
, str
);
3587 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3589 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3590 map
= isl_map_read_from_str(ctx
, str
);
3591 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3593 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3594 map
= isl_map_read_from_str(ctx
, str
);
3595 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3597 flow
= isl_access_info_compute_flow(ai
);
3598 space
= isl_space_alloc(ctx
, 0, 3, 3);
3599 mm
.must
= isl_map_empty(isl_space_copy(space
));
3600 mm
.may
= isl_map_empty(space
);
3602 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3604 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3605 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3606 assert(map_is_equal(mm
.may
, str
));
3607 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3608 assert(map_is_equal(mm
.must
, str
));
3610 isl_map_free(mm
.must
);
3611 isl_map_free(mm
.may
);
3612 isl_flow_free(flow
);
3617 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3618 map
= isl_map_read_from_str(ctx
, str
);
3619 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3621 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3622 map
= isl_map_read_from_str(ctx
, str
);
3623 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3625 flow
= isl_access_info_compute_flow(ai
);
3626 space
= isl_space_alloc(ctx
, 0, 5, 5);
3627 mm
.must
= isl_map_empty(isl_space_copy(space
));
3628 mm
.may
= isl_map_empty(space
);
3630 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3632 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3633 assert(map_is_equal(mm
.must
, str
));
3634 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3635 assert(map_is_equal(mm
.may
, str
));
3637 isl_map_free(mm
.must
);
3638 isl_map_free(mm
.may
);
3639 isl_flow_free(flow
);
3644 /* Check that the dependence analysis proceeds without errors.
3645 * Earlier versions of isl would break down during the analysis
3646 * due to the use of the wrong spaces.
3648 static int test_flow(isl_ctx
*ctx
)
3651 isl_union_map
*access
, *schedule
;
3652 isl_union_map
*must_dep
, *may_dep
;
3655 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3656 access
= isl_union_map_read_from_str(ctx
, str
);
3657 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3658 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3659 "S2[] -> [1,0,0,0]; "
3660 "S3[] -> [-1,0,0,0] }";
3661 schedule
= isl_union_map_read_from_str(ctx
, str
);
3662 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3663 isl_union_map_copy(access
), schedule
,
3664 &must_dep
, &may_dep
, NULL
, NULL
);
3665 isl_union_map_free(may_dep
);
3666 isl_union_map_free(must_dep
);
3675 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3676 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3677 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3678 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3679 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3680 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3681 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3682 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3683 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3686 int test_sv(isl_ctx
*ctx
)
3688 isl_union_map
*umap
;
3692 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3693 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3694 sv
= isl_union_map_is_single_valued(umap
);
3695 isl_union_map_free(umap
);
3698 if (sv_tests
[i
].sv
&& !sv
)
3699 isl_die(ctx
, isl_error_internal
,
3700 "map not detected as single valued", return -1);
3701 if (!sv_tests
[i
].sv
&& sv
)
3702 isl_die(ctx
, isl_error_internal
,
3703 "map detected as single valued", return -1);
3712 } bijective_tests
[] = {
3713 { "[N,M]->{[i,j] -> [i]}", 0 },
3714 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3715 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3716 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3717 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3718 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3719 { "[N,M]->{[i,j] -> []}", 0 },
3720 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3721 { "[N,M]->{[i,j] -> [2i]}", 0 },
3722 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3723 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3724 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3725 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3728 static int test_bijective(struct isl_ctx
*ctx
)
3734 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3735 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3736 bijective
= isl_map_is_bijective(map
);
3740 if (bijective_tests
[i
].bijective
&& !bijective
)
3741 isl_die(ctx
, isl_error_internal
,
3742 "map not detected as bijective", return -1);
3743 if (!bijective_tests
[i
].bijective
&& bijective
)
3744 isl_die(ctx
, isl_error_internal
,
3745 "map detected as bijective", return -1);
3751 /* Inputs for isl_pw_qpolynomial_gist tests.
3752 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3758 } pwqp_gist_tests
[] = {
3759 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3760 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3761 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3762 "{ [i] -> -1/2 + 1/2 * i }" },
3763 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3764 { "{ [i] -> i^2 : i > 0; [i] -> i^2 : i < 0 }", "{ [i] : i != 0 }",
3768 /* Perform some basic isl_pw_qpolynomial_gist tests.
3770 static isl_stat
test_pwqp_gist(isl_ctx
*ctx
)
3775 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3778 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3779 str
= pwqp_gist_tests
[i
].pwqp
;
3780 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3781 str
= pwqp_gist_tests
[i
].set
;
3782 set
= isl_set_read_from_str(ctx
, str
);
3783 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3784 str
= pwqp_gist_tests
[i
].gist
;
3785 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3786 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3787 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3788 isl_pw_qpolynomial_free(pwqp1
);
3791 return isl_stat_error
;
3793 isl_die(ctx
, isl_error_unknown
,
3794 "unexpected result", return isl_stat_error
);
3800 /* Perform a basic isl_pw_qpolynomial_max test.
3802 static isl_stat
test_pwqp_max(isl_ctx
*ctx
)
3805 isl_pw_qpolynomial
*pwqp
;
3809 str
= "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3810 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3811 v
= isl_pw_qpolynomial_max(pwqp
);
3812 ok
= isl_val_cmp_si(v
, -1) == 0;
3816 return isl_stat_error
;
3818 isl_die(ctx
, isl_error_unknown
, "unexpected maximum",
3819 return isl_stat_error
);
3824 static int test_pwqp(struct isl_ctx
*ctx
)
3828 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3831 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3832 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3834 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3837 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3838 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3840 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3842 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3844 isl_pw_qpolynomial_free(pwqp1
);
3846 if (test_pwqp_gist(ctx
) < 0)
3849 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3850 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3851 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3852 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3854 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3856 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3858 isl_pw_qpolynomial_free(pwqp1
);
3860 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3861 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3862 str
= "{ [x] -> x }";
3863 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3865 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3867 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3869 isl_pw_qpolynomial_free(pwqp1
);
3871 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3872 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3873 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3874 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3875 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3876 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3877 isl_pw_qpolynomial_free(pwqp1
);
3879 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3880 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3881 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3882 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3883 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3884 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3885 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3886 isl_pw_qpolynomial_free(pwqp1
);
3887 isl_pw_qpolynomial_free(pwqp2
);
3891 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3893 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3894 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3895 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3896 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3897 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3899 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3900 isl_pw_qpolynomial_free(pwqp1
);
3901 isl_pw_qpolynomial_free(pwqp2
);
3905 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3907 if (test_pwqp_max(ctx
) < 0)
3913 static int test_split_periods(isl_ctx
*ctx
)
3916 isl_pw_qpolynomial
*pwqp
;
3918 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3919 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3920 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3921 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3923 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3925 isl_pw_qpolynomial_free(pwqp
);
3933 static int test_union(isl_ctx
*ctx
)
3936 isl_union_set
*uset1
, *uset2
;
3937 isl_union_map
*umap1
, *umap2
;
3940 str
= "{ [i] : 0 <= i <= 1 }";
3941 uset1
= isl_union_set_read_from_str(ctx
, str
);
3942 str
= "{ [1] -> [0] }";
3943 umap1
= isl_union_map_read_from_str(ctx
, str
);
3945 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3946 equal
= isl_union_map_is_equal(umap1
, umap2
);
3948 isl_union_map_free(umap1
);
3949 isl_union_map_free(umap2
);
3954 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3957 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3958 umap1
= isl_union_map_read_from_str(ctx
, str
);
3959 str
= "{ A[i]; B[i] }";
3960 uset1
= isl_union_set_read_from_str(ctx
, str
);
3962 uset2
= isl_union_map_domain(umap1
);
3964 equal
= isl_union_set_is_equal(uset1
, uset2
);
3966 isl_union_set_free(uset1
);
3967 isl_union_set_free(uset2
);
3972 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3978 /* Inputs for basic isl_pw_qpolynomial_bound tests.
3979 * "type" is the type of bound that should be computed.
3980 * "poly" is a string representation of the input.
3981 * "bound" is a string representation of the expected result.
3982 * "tight" is set if the result is expected to be tight.
3990 /* Check that computing a bound of a non-zero polynomial
3991 * over an unbounded domain does not produce a rational value.
3992 * In particular, check that the upper bound is infinity.
3994 { 0, isl_fold_max
, "{ [m, n] -> -m * n }", "{ max(infty) }" },
3995 { 1, isl_fold_max
, "{ [[a, b, c, d] -> [e]] -> 0 }",
3996 "{ [a, b, c, d] -> max(0) }" },
3997 { 1, isl_fold_max
, "{ [[x] -> [x]] -> 1 : exists a : x = 2 a }",
3998 "{ [x] -> max(1) : x mod 2 = 0 }" },
3999 { 1, isl_fold_min
, "{ [x=5:10] -> (x + 2)^2 }", "{ min(49) }" },
4000 { 1, isl_fold_max
, "{ [0:10] -> 1 }", "{ max(1) }" },
4001 { 1, isl_fold_max
, "{ [[m] -> [0:m]] -> m^2 }",
4002 "{ [m] -> max(m^2) : m >= 0 }" },
4005 /* Check that the bound computation can handle differences
4006 * in domain dimension names of the input polynomial and its domain.
4008 static isl_stat
test_bound_space(isl_ctx
*ctx
)
4012 isl_pw_qpolynomial
*pwqp
;
4013 isl_pw_qpolynomial_fold
*pwf
;
4015 str
= "{ [[c] -> [c]] }";
4016 set
= isl_set_read_from_str(ctx
, str
);
4017 str
= "{ [[a] -> [b]] -> 1 }";
4018 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4019 pwqp
= isl_pw_qpolynomial_intersect_domain(pwqp
, set
);
4020 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
4021 isl_pw_qpolynomial_fold_free(pwf
);
4023 return isl_stat_non_null(pwf
);
4026 /* Perform basic isl_pw_qpolynomial_bound tests.
4028 static int test_bound(isl_ctx
*ctx
)
4032 if (test_bound_space(ctx
) < 0)
4035 for (i
= 0; i
< ARRAY_SIZE(bound_tests
); ++i
) {
4038 isl_bool equal
, tight
;
4039 isl_pw_qpolynomial
*pwqp
;
4040 isl_pw_qpolynomial_fold
*pwf1
, *pwf2
;
4042 str
= bound_tests
[i
].poly
;
4043 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4044 type
= bound_tests
[i
].type
;
4045 pwf1
= isl_pw_qpolynomial_bound(pwqp
, type
, &tight
);
4046 str
= bound_tests
[i
].bound
;
4047 pwf2
= isl_pw_qpolynomial_fold_read_from_str(ctx
, str
);
4048 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf1
, pwf2
);
4049 isl_pw_qpolynomial_fold_free(pwf2
);
4050 isl_pw_qpolynomial_fold_free(pwf1
);
4054 isl_die(ctx
, isl_error_unknown
,
4055 "incorrect bound result", return -1);
4056 if (bound_tests
[i
].tight
&& !tight
)
4057 isl_die(ctx
, isl_error_unknown
,
4058 "bound unexpectedly not tight", return -1);
4064 /* isl_set is defined to isl_map internally, so the corresponding elements
4065 * are isl_basic_map objects.
4069 #define EL_BASE basic_map
4070 #define SET_BASE set
4071 #include "isl_test_list_templ.c"
4075 #define EL_BASE basic_set
4076 #define SET_BASE union_set
4077 #include "isl_test_list_templ.c"
4082 #define SET_BASE union_set
4083 #include "isl_test_list_templ.c"
4087 #define EL_BASE basic_map
4088 #define SET_BASE map
4089 #include "isl_test_list_templ.c"
4094 #define SET_BASE union_map
4095 #include "isl_test_list_templ.c"
4097 /* Check that the conversion from isl objects to lists works as expected.
4099 static int test_get_list(isl_ctx
*ctx
)
4101 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
4103 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
4105 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
4107 if (test_get_list_basic_map_from_map(ctx
,
4108 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
4110 if (test_get_list_map_from_union_map(ctx
,
4111 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
4117 static int test_lift(isl_ctx
*ctx
)
4120 isl_basic_map
*bmap
;
4121 isl_basic_set
*bset
;
4123 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
4124 bset
= isl_basic_set_read_from_str(ctx
, str
);
4125 bset
= isl_basic_set_lift(bset
);
4126 bmap
= isl_basic_map_from_range(bset
);
4127 bset
= isl_basic_map_domain(bmap
);
4128 isl_basic_set_free(bset
);
4133 /* Check that isl_set_is_subset is not confused by identical
4134 * integer divisions.
4135 * The call to isl_set_normalize ensures that the equality constraints
4136 * a = b = 0 are discovered, turning e0 and e1 into identical
4137 * integer divisions. Any further simplification would remove
4138 * the duplicate integer divisions.
4140 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
4144 isl_set
*set1
, *set2
;
4146 str
= "{ [a, b, c, d] : "
4147 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4148 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4149 "e3 = floor((-d + 4*floor((d)/4))/10): "
4150 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4151 "b >= 0 and a <= 0 and b <= a) }";
4152 set1
= isl_set_read_from_str(ctx
, str
);
4153 set2
= isl_set_read_from_str(ctx
, str
);
4154 set2
= isl_set_normalize(set2
);
4156 is_subset
= isl_set_is_subset(set1
, set2
);
4162 return isl_stat_error
;
4164 isl_die(ctx
, isl_error_unknown
,
4165 "set is not considered to be a subset of itself",
4166 return isl_stat_error
);
4175 } subset_tests
[] = {
4177 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4178 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4179 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4181 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4182 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4183 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4184 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4185 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4186 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4187 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4188 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4189 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4190 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4191 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4192 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4193 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4194 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4195 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4196 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4197 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4198 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4199 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4200 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4201 "4e0 <= -57 + i0 + i1)) or "
4202 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4203 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4204 "4e0 >= -61 + i0 + i1)) or "
4205 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4206 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4209 static int test_subset(isl_ctx
*ctx
)
4212 isl_set
*set1
, *set2
;
4215 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
4218 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
4219 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
4220 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
4221 subset
= isl_set_is_subset(set1
, set2
);
4226 if (subset
!= subset_tests
[i
].subset
)
4227 isl_die(ctx
, isl_error_unknown
,
4228 "incorrect subset result", return -1);
4234 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4235 * Older versions of isl would fail on such cases.
4237 static isl_stat
test_subtract_empty(isl_ctx
*ctx
)
4242 s1
= isl_set_read_from_str(ctx
, "{ [0] }");
4243 str
= "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4244 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4245 "33e2 >= -a + 33e0 + 1056e1 and "
4246 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4247 s2
= isl_set_read_from_str(ctx
, str
);
4248 s1
= isl_set_subtract(s1
, s2
);
4251 return isl_stat_non_null(s1
);
4255 const char *minuend
;
4256 const char *subtrahend
;
4257 const char *difference
;
4258 } subtract_domain_tests
[] = {
4259 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4260 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4261 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4264 static int test_subtract(isl_ctx
*ctx
)
4267 isl_union_map
*umap1
, *umap2
;
4268 isl_union_pw_multi_aff
*upma1
, *upma2
;
4269 isl_union_set
*uset
;
4272 if (test_subtract_empty(ctx
) < 0)
4275 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4276 umap1
= isl_union_map_read_from_str(ctx
,
4277 subtract_domain_tests
[i
].minuend
);
4278 uset
= isl_union_set_read_from_str(ctx
,
4279 subtract_domain_tests
[i
].subtrahend
);
4280 umap2
= isl_union_map_read_from_str(ctx
,
4281 subtract_domain_tests
[i
].difference
);
4282 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
4283 equal
= isl_union_map_is_equal(umap1
, umap2
);
4284 isl_union_map_free(umap1
);
4285 isl_union_map_free(umap2
);
4289 isl_die(ctx
, isl_error_unknown
,
4290 "incorrect subtract domain result", return -1);
4293 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4294 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4295 subtract_domain_tests
[i
].minuend
);
4296 uset
= isl_union_set_read_from_str(ctx
,
4297 subtract_domain_tests
[i
].subtrahend
);
4298 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4299 subtract_domain_tests
[i
].difference
);
4300 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
4301 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
4302 isl_union_pw_multi_aff_free(upma1
);
4303 isl_union_pw_multi_aff_free(upma2
);
4307 isl_die(ctx
, isl_error_unknown
,
4308 "incorrect subtract domain result", return -1);
4314 /* Check that intersecting the empty basic set with another basic set
4315 * does not increase the number of constraints. In particular,
4316 * the empty basic set should maintain its canonical representation.
4318 static int test_intersect_1(isl_ctx
*ctx
)
4321 isl_basic_set
*bset1
, *bset2
;
4323 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
4324 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
4325 n1
= isl_basic_set_n_constraint(bset1
);
4326 bset1
= isl_basic_set_intersect(bset1
, bset2
);
4327 n2
= isl_basic_set_n_constraint(bset1
);
4328 isl_basic_set_free(bset1
);
4329 if (n1
< 0 || n2
< 0)
4332 isl_die(ctx
, isl_error_unknown
,
4333 "number of constraints of empty set changed",
4339 /* Check that intersecting a set with itself does not cause
4340 * an explosion in the number of disjuncts.
4342 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
4347 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
4348 for (i
= 0; i
< 100; ++i
)
4349 set
= isl_set_intersect(set
, isl_set_copy(set
));
4352 return isl_stat_error
;
4356 /* Perform some intersection tests.
4358 static int test_intersect(isl_ctx
*ctx
)
4360 if (test_intersect_1(ctx
) < 0)
4362 if (test_intersect_2(ctx
) < 0)
4368 int test_factorize(isl_ctx
*ctx
)
4371 isl_basic_set
*bset
;
4374 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4375 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4376 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4377 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4378 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4379 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4380 "3i5 >= -2i0 - i2 + 3i4 }";
4381 bset
= isl_basic_set_read_from_str(ctx
, str
);
4382 f
= isl_basic_set_factorizer(bset
);
4383 isl_basic_set_free(bset
);
4384 isl_factorizer_free(f
);
4386 isl_die(ctx
, isl_error_unknown
,
4387 "failed to construct factorizer", return -1);
4389 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4390 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4391 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4392 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4393 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4394 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4395 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4396 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4397 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4398 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4399 bset
= isl_basic_set_read_from_str(ctx
, str
);
4400 f
= isl_basic_set_factorizer(bset
);
4401 isl_basic_set_free(bset
);
4402 isl_factorizer_free(f
);
4404 isl_die(ctx
, isl_error_unknown
,
4405 "failed to construct factorizer", return -1);
4410 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
4412 int *injective
= user
;
4414 *injective
= isl_map_is_injective(map
);
4417 if (*injective
< 0 || !*injective
)
4418 return isl_stat_error
;
4423 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
4424 const char *r
, const char *s
, int tilable
, int parallel
)
4428 isl_union_map
*W
, *R
, *S
;
4429 isl_union_map
*empty
;
4430 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
4431 isl_union_map
*validity
, *proximity
, *coincidence
;
4432 isl_union_map
*schedule
;
4433 isl_union_map
*test
;
4434 isl_union_set
*delta
;
4435 isl_union_set
*domain
;
4439 isl_schedule_constraints
*sc
;
4440 isl_schedule
*sched
;
4441 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
4444 D
= isl_union_set_read_from_str(ctx
, d
);
4445 W
= isl_union_map_read_from_str(ctx
, w
);
4446 R
= isl_union_map_read_from_str(ctx
, r
);
4447 S
= isl_union_map_read_from_str(ctx
, s
);
4449 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4450 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4452 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4453 isl_union_map_compute_flow(isl_union_map_copy(R
),
4454 isl_union_map_copy(W
), empty
,
4455 isl_union_map_copy(S
),
4456 &dep_raw
, NULL
, NULL
, NULL
);
4457 isl_union_map_compute_flow(isl_union_map_copy(W
),
4458 isl_union_map_copy(W
),
4459 isl_union_map_copy(R
),
4460 isl_union_map_copy(S
),
4461 &dep_waw
, &dep_war
, NULL
, NULL
);
4463 dep
= isl_union_map_union(dep_waw
, dep_war
);
4464 dep
= isl_union_map_union(dep
, dep_raw
);
4465 validity
= isl_union_map_copy(dep
);
4466 coincidence
= isl_union_map_copy(dep
);
4467 proximity
= isl_union_map_copy(dep
);
4469 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4470 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4471 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4472 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4473 sched
= isl_schedule_constraints_compute_schedule(sc
);
4474 schedule
= isl_schedule_get_map(sched
);
4475 isl_schedule_free(sched
);
4476 isl_union_map_free(W
);
4477 isl_union_map_free(R
);
4478 isl_union_map_free(S
);
4481 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4483 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4484 is_complete
= isl_union_set_is_subset(D
, domain
);
4485 isl_union_set_free(D
);
4486 isl_union_set_free(domain
);
4488 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4489 test
= isl_union_map_apply_range(test
, dep
);
4490 test
= isl_union_map_apply_range(test
, schedule
);
4492 delta
= isl_union_map_deltas(test
);
4493 n
= isl_union_set_n_set(delta
);
4495 isl_union_set_free(delta
);
4502 isl_union_set_free(delta
);
4506 delta_set
= isl_set_from_union_set(delta
);
4508 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4509 for (i
= 0; i
< tilable
; ++i
)
4510 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4511 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4512 isl_set_free(slice
);
4514 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4515 for (i
= 0; i
< parallel
; ++i
)
4516 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4517 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4518 isl_set_free(slice
);
4520 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4521 dim
= isl_set_dim(origin
, isl_dim_set
);
4523 origin
= isl_set_free(origin
);
4524 for (i
= 0; i
< dim
; ++i
)
4525 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4527 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4528 delta_set
= isl_set_lexmin(delta_set
);
4530 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4532 isl_set_free(origin
);
4533 isl_set_free(delta_set
);
4536 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4537 is_injection
< 0 || is_complete
< 0)
4540 isl_die(ctx
, isl_error_unknown
,
4541 "generated schedule incomplete", return -1);
4543 isl_die(ctx
, isl_error_unknown
,
4544 "generated schedule not injective on each statement",
4547 isl_die(ctx
, isl_error_unknown
,
4548 "negative dependences in generated schedule",
4551 isl_die(ctx
, isl_error_unknown
,
4552 "generated schedule not as tilable as expected",
4555 isl_die(ctx
, isl_error_unknown
,
4556 "generated schedule not as parallel as expected",
4562 /* Compute a schedule for the given instance set, validity constraints,
4563 * proximity constraints and context and return a corresponding union map
4566 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4567 const char *domain
, const char *validity
, const char *proximity
,
4568 const char *context
)
4573 isl_union_map
*prox
;
4574 isl_schedule_constraints
*sc
;
4575 isl_schedule
*schedule
;
4576 isl_union_map
*sched
;
4578 con
= isl_set_read_from_str(ctx
, context
);
4579 dom
= isl_union_set_read_from_str(ctx
, domain
);
4580 dep
= isl_union_map_read_from_str(ctx
, validity
);
4581 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4582 sc
= isl_schedule_constraints_on_domain(dom
);
4583 sc
= isl_schedule_constraints_set_context(sc
, con
);
4584 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4585 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4586 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4587 sched
= isl_schedule_get_map(schedule
);
4588 isl_schedule_free(schedule
);
4593 /* Compute a schedule for the given instance set, validity constraints and
4594 * proximity constraints and return a corresponding union map representation.
4596 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4597 const char *domain
, const char *validity
, const char *proximity
)
4599 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4603 /* Check that a schedule can be constructed on the given domain
4604 * with the given validity and proximity constraints.
4606 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4607 const char *validity
, const char *proximity
)
4609 isl_union_map
*sched
;
4611 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4615 isl_union_map_free(sched
);
4619 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4620 const char *validity
, const char *proximity
, const char *expected_sched
)
4622 isl_union_map
*sched1
, *sched2
;
4625 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4626 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4628 equal
= isl_union_map_is_equal(sched1
, sched2
);
4629 isl_union_map_free(sched1
);
4630 isl_union_map_free(sched2
);
4635 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4641 /* Check that the schedule map is properly padded, i.e., that the range
4642 * lives in a single space.
4644 static int test_padded_schedule(isl_ctx
*ctx
)
4648 isl_union_map
*validity
, *proximity
;
4649 isl_schedule_constraints
*sc
;
4650 isl_schedule
*sched
;
4651 isl_union_map
*umap
;
4652 isl_union_set
*range
;
4655 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4656 D
= isl_union_set_read_from_str(ctx
, str
);
4657 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4658 proximity
= isl_union_map_copy(validity
);
4659 sc
= isl_schedule_constraints_on_domain(D
);
4660 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4661 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4662 sched
= isl_schedule_constraints_compute_schedule(sc
);
4663 umap
= isl_schedule_get_map(sched
);
4664 isl_schedule_free(sched
);
4665 range
= isl_union_map_range(umap
);
4666 set
= isl_set_from_union_set(range
);
4675 /* Check that conditional validity constraints are also taken into
4676 * account across bands.
4677 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4678 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4679 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4680 * is enforced by the rest of the schedule.
4682 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4685 isl_union_set
*domain
;
4686 isl_union_map
*validity
, *proximity
, *condition
;
4687 isl_union_map
*sink
, *source
, *dep
;
4688 isl_schedule_constraints
*sc
;
4689 isl_schedule
*schedule
;
4690 isl_union_access_info
*access
;
4691 isl_union_flow
*flow
;
4694 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4695 "A[k] : k >= 1 and k <= -1 + n; "
4696 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4697 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4698 domain
= isl_union_set_read_from_str(ctx
, str
);
4699 sc
= isl_schedule_constraints_on_domain(domain
);
4700 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4701 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4702 "D[k, i] -> C[1 + k, i] : "
4703 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4704 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4705 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4706 validity
= isl_union_map_read_from_str(ctx
, str
);
4707 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4708 str
= "[n] -> { C[k, i] -> D[k, i] : "
4709 "0 <= i <= -1 + k and k <= -1 + n }";
4710 proximity
= isl_union_map_read_from_str(ctx
, str
);
4711 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4712 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4713 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4714 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4715 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4716 condition
= isl_union_map_read_from_str(ctx
, str
);
4717 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4718 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4719 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4720 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4721 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4722 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4723 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4724 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4725 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4726 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4727 validity
= isl_union_map_read_from_str(ctx
, str
);
4728 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4730 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4731 str
= "{ D[2,0] -> [] }";
4732 sink
= isl_union_map_read_from_str(ctx
, str
);
4733 access
= isl_union_access_info_from_sink(sink
);
4734 str
= "{ C[2,1] -> [] }";
4735 source
= isl_union_map_read_from_str(ctx
, str
);
4736 access
= isl_union_access_info_set_must_source(access
, source
);
4737 access
= isl_union_access_info_set_schedule(access
, schedule
);
4738 flow
= isl_union_access_info_compute_flow(access
);
4739 dep
= isl_union_flow_get_must_dependence(flow
);
4740 isl_union_flow_free(flow
);
4741 empty
= isl_union_map_is_empty(dep
);
4742 isl_union_map_free(dep
);
4747 isl_die(ctx
, isl_error_unknown
,
4748 "conditional validity not respected", return -1);
4753 /* Check that the test for violated conditional validity constraints
4754 * is not confused by domain compression.
4755 * In particular, earlier versions of isl would apply
4756 * a schedule on the compressed domains to the original domains,
4757 * resulting in a failure to detect that the default schedule
4758 * violates the conditional validity constraints.
4760 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4764 isl_union_set
*domain
;
4765 isl_union_map
*validity
, *condition
;
4766 isl_schedule_constraints
*sc
;
4767 isl_schedule
*schedule
;
4768 isl_union_map
*umap
;
4771 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4772 domain
= isl_union_set_read_from_str(ctx
, str
);
4773 sc
= isl_schedule_constraints_on_domain(domain
);
4774 str
= "{ B[1, i] -> A[0, i + 1] }";
4775 condition
= isl_union_map_read_from_str(ctx
, str
);
4776 str
= "{ A[0, i] -> B[1, i - 1] }";
4777 validity
= isl_union_map_read_from_str(ctx
, str
);
4778 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4779 isl_union_map_copy(validity
));
4780 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4781 umap
= isl_schedule_get_map(schedule
);
4782 isl_schedule_free(schedule
);
4783 validity
= isl_union_map_apply_domain(validity
,
4784 isl_union_map_copy(umap
));
4785 validity
= isl_union_map_apply_range(validity
, umap
);
4786 map
= isl_map_from_union_map(validity
);
4787 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4788 map
= isl_map_intersect(map
, ge
);
4789 empty
= isl_map_is_empty(map
);
4795 isl_die(ctx
, isl_error_unknown
,
4796 "conditional validity constraints not satisfied",
4802 /* Input for testing of schedule construction based on
4803 * conditional constraints.
4805 * domain is the iteration domain
4806 * flow are the flow dependences, which determine the validity and
4807 * proximity constraints
4808 * condition are the conditions on the conditional validity constraints
4809 * conditional_validity are the conditional validity constraints
4810 * outer_band_n is the expected number of members in the outer band
4815 const char *condition
;
4816 const char *conditional_validity
;
4818 } live_range_tests
[] = {
4819 /* Contrived example that illustrates that we need to keep
4820 * track of tagged condition dependences and
4821 * tagged conditional validity dependences
4822 * in isl_sched_edge separately.
4823 * In particular, the conditional validity constraints on A
4824 * cannot be satisfied,
4825 * but they can be ignored because there are no corresponding
4826 * condition constraints. However, we do have an additional
4827 * conditional validity constraint that maps to the same
4828 * dependence relation
4829 * as the condition constraint on B. If we did not make a distinction
4830 * between tagged condition and tagged conditional validity
4831 * dependences, then we
4832 * could end up treating this shared dependence as an condition
4833 * constraint on A, forcing a localization of the conditions,
4834 * which is impossible.
4836 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4837 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4838 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4839 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4840 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4841 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4844 /* TACO 2013 Fig. 7 */
4845 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4846 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4847 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4848 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4849 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4850 "0 <= i < n and 0 <= j < n - 1 }",
4851 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4852 "0 <= i < n and 0 <= j < j' < n;"
4853 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4854 "0 <= i < i' < n and 0 <= j,j' < n;"
4855 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4856 "0 <= i,j,j' < n and j < j' }",
4859 /* TACO 2013 Fig. 7, without tags */
4860 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4861 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4862 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4863 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4864 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4865 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4866 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4867 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4870 /* TACO 2013 Fig. 12 */
4871 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4872 "S3[i,3] : 0 <= i <= 1 }",
4873 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4874 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4875 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4876 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4877 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4878 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4879 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4880 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4881 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4882 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4883 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4888 /* Test schedule construction based on conditional constraints.
4889 * In particular, check the number of members in the outer band node
4890 * as an indication of whether tiling is possible or not.
4892 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4895 isl_union_set
*domain
;
4896 isl_union_map
*condition
;
4897 isl_union_map
*flow
;
4898 isl_union_map
*validity
;
4899 isl_schedule_constraints
*sc
;
4900 isl_schedule
*schedule
;
4901 isl_schedule_node
*node
;
4904 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4906 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4909 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4910 domain
= isl_union_set_read_from_str(ctx
,
4911 live_range_tests
[i
].domain
);
4912 flow
= isl_union_map_read_from_str(ctx
,
4913 live_range_tests
[i
].flow
);
4914 condition
= isl_union_map_read_from_str(ctx
,
4915 live_range_tests
[i
].condition
);
4916 validity
= isl_union_map_read_from_str(ctx
,
4917 live_range_tests
[i
].conditional_validity
);
4918 sc
= isl_schedule_constraints_on_domain(domain
);
4919 sc
= isl_schedule_constraints_set_validity(sc
,
4920 isl_union_map_copy(flow
));
4921 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4922 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4923 condition
, validity
);
4924 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4925 node
= isl_schedule_get_root(schedule
);
4927 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4928 node
= isl_schedule_node_first_child(node
);
4929 n_member
= isl_schedule_node_band_n_member(node
);
4930 isl_schedule_node_free(node
);
4931 isl_schedule_free(schedule
);
4933 if (!schedule
|| n_member
< 0)
4935 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4936 isl_die(ctx
, isl_error_unknown
,
4937 "unexpected number of members in outer band",
4943 /* Check that the schedule computed for the given instance set and
4944 * dependence relation strongly satisfies the dependences.
4945 * In particular, check that no instance is scheduled before
4946 * or together with an instance on which it depends.
4947 * Earlier versions of isl would produce a schedule that
4948 * only weakly satisfies the dependences.
4950 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4952 const char *domain
, *dep
;
4953 isl_union_map
*D
, *schedule
;
4957 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4958 "A[i0] : 0 <= i0 <= 1 }";
4959 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4960 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4961 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4962 D
= isl_union_map_read_from_str(ctx
, dep
);
4963 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4964 D
= isl_union_map_apply_range(D
, schedule
);
4965 map
= isl_map_from_union_map(D
);
4966 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4967 map
= isl_map_intersect(map
, ge
);
4968 empty
= isl_map_is_empty(map
);
4974 isl_die(ctx
, isl_error_unknown
,
4975 "dependences not strongly satisfied", return -1);
4980 /* Compute a schedule for input where the instance set constraints
4981 * conflict with the context constraints.
4982 * Earlier versions of isl did not properly handle this situation.
4984 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4986 isl_union_map
*schedule
;
4987 const char *domain
, *context
;
4989 domain
= "[n] -> { A[] : n >= 0 }";
4990 context
= "[n] -> { : n < 0 }";
4991 schedule
= compute_schedule_with_context(ctx
,
4992 domain
, "{}", "{}", context
);
4993 isl_union_map_free(schedule
);
5001 /* Check that a set of schedule constraints that only allow for
5002 * a coalescing schedule still produces a schedule even if the user
5003 * request a non-coalescing schedule. Earlier versions of isl
5004 * would not handle this case correctly.
5006 static int test_coalescing_schedule(isl_ctx
*ctx
)
5008 const char *domain
, *dep
;
5011 isl_schedule_constraints
*sc
;
5012 isl_schedule
*schedule
;
5013 int treat_coalescing
;
5015 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
5016 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
5017 I
= isl_union_set_read_from_str(ctx
, domain
);
5018 D
= isl_union_map_read_from_str(ctx
, dep
);
5019 sc
= isl_schedule_constraints_on_domain(I
);
5020 sc
= isl_schedule_constraints_set_validity(sc
, D
);
5021 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5022 isl_options_set_schedule_treat_coalescing(ctx
, 1);
5023 schedule
= isl_schedule_constraints_compute_schedule(sc
);
5024 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5025 isl_schedule_free(schedule
);
5031 /* Check that the scheduler does not perform any needless
5032 * compound skewing. Earlier versions of isl would compute
5033 * schedules in terms of transformed schedule coefficients and
5034 * would not accurately keep track of the sum of the original
5035 * schedule coefficients. It could then produce the schedule
5036 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
5037 * for the input below instead of the schedule below.
5039 static int test_skewing_schedule(isl_ctx
*ctx
)
5041 const char *D
, *V
, *P
, *S
;
5043 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
5044 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
5045 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
5046 "-1 <= a-i + b-j + c-k <= 1 }";
5048 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
5050 return test_special_schedule(ctx
, D
, V
, P
, S
);
5053 int test_schedule(isl_ctx
*ctx
)
5055 const char *D
, *W
, *R
, *V
, *P
, *S
;
5056 int max_coincidence
;
5057 int treat_coalescing
;
5059 /* Handle resulting schedule with zero bands. */
5060 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
5064 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
5065 W
= "{ S1[t,i] -> a[t,i] }";
5066 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
5067 "S1[t,i] -> a[t-1,i+1] }";
5068 S
= "{ S1[t,i] -> [t,i] }";
5069 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5072 /* Fig. 5 of CC2008 */
5073 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
5075 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
5076 "j >= 2 and j <= -1 + N }";
5077 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
5078 "j >= 2 and j <= -1 + N; "
5079 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
5080 "j >= 2 and j <= -1 + N }";
5081 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5082 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5085 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
5086 W
= "{ S1[i] -> a[i] }";
5087 R
= "{ S2[i] -> a[i+1] }";
5088 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5089 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5092 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
5093 W
= "{ S1[i] -> a[i] }";
5094 R
= "{ S2[i] -> a[9-i] }";
5095 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5096 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5099 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
5100 W
= "{ S1[i] -> a[i] }";
5101 R
= "[N] -> { S2[i] -> a[N-1-i] }";
5102 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5103 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5106 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
5107 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
5108 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
5109 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
5110 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5113 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5114 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
5115 R
= "{ S2[i,j] -> a[i-1,j] }";
5116 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5117 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5120 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5121 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
5122 R
= "{ S2[i,j] -> a[i,j-1] }";
5123 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5124 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5127 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5128 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5129 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5130 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5131 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5132 "S_0[] -> [0, 0, 0] }";
5133 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
5135 ctx
->opt
->schedule_parametric
= 0;
5136 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5138 ctx
->opt
->schedule_parametric
= 1;
5140 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5141 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5142 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5143 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5144 "S4[i] -> a[i,N] }";
5145 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5146 "S4[i] -> [4,i,0] }";
5147 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
5148 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
5149 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5151 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
5153 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5154 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5156 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5158 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5160 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5161 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5164 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5165 " S_2[t] : t >= 0 and t <= -1 + N; "
5166 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5168 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5169 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5170 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5171 "i >= 0 and i <= -1 + N }";
5172 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5173 "i >= 0 and i <= -1 + N; "
5174 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5175 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5176 " S_0[t] -> [0, t, 0] }";
5178 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5180 ctx
->opt
->schedule_parametric
= 0;
5181 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5183 ctx
->opt
->schedule_parametric
= 1;
5185 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5186 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5187 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
5190 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5191 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5192 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5193 "j >= 0 and j <= -1 + N; "
5194 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5195 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5196 "j >= 0 and j <= -1 + N; "
5197 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5198 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5199 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5202 D
= "{ S_0[i] : i >= 0 }";
5203 W
= "{ S_0[i] -> a[i] : i >= 0 }";
5204 R
= "{ S_0[i] -> a[0] : i >= 0 }";
5205 S
= "{ S_0[i] -> [0, i, 0] }";
5206 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5209 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5210 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5211 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5212 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5213 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5216 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5217 "k <= -1 + n and k >= 0 }";
5218 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5219 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5220 "k <= -1 + n and k >= 0; "
5221 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5222 "k <= -1 + n and k >= 0; "
5223 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5224 "k <= -1 + n and k >= 0 }";
5225 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
5226 ctx
->opt
->schedule_outer_coincidence
= 1;
5227 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5229 ctx
->opt
->schedule_outer_coincidence
= 0;
5231 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
5232 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5233 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5234 "Stmt_for_body24[i0, i1, 1, 0]:"
5235 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5236 "Stmt_for_body7[i0, i1, i2]:"
5237 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5240 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
5241 "Stmt_for_body24[1, i1, i2, i3]:"
5242 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5244 "Stmt_for_body24[0, i1, i2, i3] -> "
5245 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5246 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5248 "Stmt_for_body24[0, i1, i2, i3] ->"
5249 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5250 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5251 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5252 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5253 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5254 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5255 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5256 "i1 <= 6 and i1 >= 0;"
5257 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5258 "Stmt_for_body7[i0, i1, i2] -> "
5259 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5260 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5261 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5262 "Stmt_for_body7[i0, i1, i2] -> "
5263 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5264 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5265 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5268 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5269 isl_options_set_schedule_treat_coalescing(ctx
, 0);
5270 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5272 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5274 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5275 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5276 "j >= 1 and j <= 7;"
5277 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5278 "j >= 1 and j <= 8 }";
5280 S
= "{ S_0[i, j] -> [i + j, i] }";
5281 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5282 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5284 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5286 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5287 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5288 "j >= 0 and j <= -1 + i }";
5289 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5290 "i <= -1 + N and j >= 0;"
5291 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5294 S
= "{ S_0[i, j] -> [i, j] }";
5295 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5296 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5298 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5300 /* Test both algorithms on a case with only proximity dependences. */
5301 D
= "{ S[i,j] : 0 <= i <= 10 }";
5303 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5304 S
= "{ S[i, j] -> [j, i] }";
5305 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5306 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5308 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5309 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5312 D
= "{ A[a]; B[] }";
5314 P
= "{ A[a] -> B[] }";
5315 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5318 if (test_padded_schedule(ctx
) < 0)
5321 /* Check that check for progress is not confused by rational
5324 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5325 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5327 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5328 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5330 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5331 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5333 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5335 /* Check that we allow schedule rows that are only non-trivial
5336 * on some full-dimensional domains.
5338 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5339 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5340 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5342 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5343 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5345 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5347 if (test_conditional_schedule_constraints(ctx
) < 0)
5350 if (test_strongly_satisfying_schedule(ctx
) < 0)
5353 if (test_conflicting_context_schedule(ctx
) < 0)
5356 if (test_coalescing_schedule(ctx
) < 0)
5358 if (test_skewing_schedule(ctx
) < 0)
5364 /* Perform scheduling tests using the whole component scheduler.
5366 static int test_schedule_whole(isl_ctx
*ctx
)
5371 whole
= isl_options_get_schedule_whole_component(ctx
);
5372 isl_options_set_schedule_whole_component(ctx
, 1);
5373 r
= test_schedule(ctx
);
5374 isl_options_set_schedule_whole_component(ctx
, whole
);
5379 /* Perform scheduling tests using the incremental scheduler.
5381 static int test_schedule_incremental(isl_ctx
*ctx
)
5386 whole
= isl_options_get_schedule_whole_component(ctx
);
5387 isl_options_set_schedule_whole_component(ctx
, 0);
5388 r
= test_schedule(ctx
);
5389 isl_options_set_schedule_whole_component(ctx
, whole
);
5394 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
5396 isl_union_map
*umap
;
5399 umap
= isl_union_map_read_from_str(ctx
, str
);
5400 test
= isl_union_map_plain_is_injective(umap
);
5401 isl_union_map_free(umap
);
5404 if (test
== injective
)
5407 isl_die(ctx
, isl_error_unknown
,
5408 "map not detected as injective", return -1);
5410 isl_die(ctx
, isl_error_unknown
,
5411 "map detected as injective", return -1);
5414 int test_injective(isl_ctx
*ctx
)
5418 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5420 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
5422 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
5424 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
5426 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5428 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5430 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5432 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5435 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5436 if (test_plain_injective(ctx
, str
, 1))
5438 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5439 if (test_plain_injective(ctx
, str
, 0))
5447 #include "isl_test_plain_equal_templ.c"
5450 #define BASE pw_multi_aff
5451 #include "isl_test_plain_equal_templ.c"
5454 #define BASE union_pw_aff
5455 #include "isl_test_plain_equal_templ.c"
5457 /* Basic tests on isl_union_pw_aff.
5459 * In particular, check that isl_union_pw_aff_aff_on_domain
5460 * aligns the parameters of the input objects and
5461 * that isl_union_pw_aff_param_on_domain_id properly
5462 * introduces the parameter.
5464 static int test_upa(isl_ctx
*ctx
)
5469 isl_union_set
*domain
;
5470 isl_union_pw_aff
*upa
;
5473 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5474 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5475 domain
= isl_union_set_read_from_str(ctx
, str
);
5476 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5477 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5478 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5479 isl_union_pw_aff_free(upa
);
5483 id
= isl_id_alloc(ctx
, "N", NULL
);
5484 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5485 domain
= isl_union_set_read_from_str(ctx
, str
);
5486 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5487 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5488 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5489 isl_union_pw_aff_free(upa
);
5497 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5498 __isl_take isl_aff
*aff2
);
5500 ['+'] = { &isl_aff_add
},
5501 ['-'] = { &isl_aff_sub
},
5502 ['*'] = { &isl_aff_mul
},
5503 ['/'] = { &isl_aff_div
},
5511 } aff_bin_tests
[] = {
5512 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5513 "{ [i] -> [2i] }" },
5514 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5516 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5517 "{ [i] -> [2i] }" },
5518 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5519 "{ [i] -> [2i] }" },
5520 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5521 "{ [i] -> [i/2] }" },
5522 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5524 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5525 "{ [i] -> [NaN] }" },
5526 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5527 "{ [i] -> [NaN] }" },
5528 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5529 "{ [i] -> [NaN] }" },
5530 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5531 "{ [i] -> [NaN] }" },
5532 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5533 "{ [i] -> [NaN] }" },
5534 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5535 "{ [i] -> [NaN] }" },
5536 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5537 "{ [i] -> [NaN] }" },
5538 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5539 "{ [i] -> [NaN] }" },
5540 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5541 "{ [i] -> [NaN] }" },
5542 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5543 "{ [i] -> [NaN] }" },
5544 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5545 "{ [i] -> [NaN] }" },
5546 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5547 "{ [i] -> [NaN] }" },
5548 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5549 "{ [i] -> [NaN] }" },
5552 /* Perform some basic tests of binary operations on isl_aff objects.
5554 static int test_bin_aff(isl_ctx
*ctx
)
5557 isl_aff
*aff1
, *aff2
, *res
;
5558 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5559 __isl_take isl_aff
*aff2
);
5562 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5563 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5564 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5565 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5566 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5567 aff1
= fn(aff1
, aff2
);
5568 if (isl_aff_is_nan(res
))
5569 ok
= isl_aff_is_nan(aff1
);
5571 ok
= isl_aff_plain_is_equal(aff1
, res
);
5577 isl_die(ctx
, isl_error_unknown
,
5578 "unexpected result", return -1);
5585 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5586 __isl_take isl_pw_aff
*pa2
);
5587 } pw_aff_bin_op
[] = {
5588 ['m'] = { &isl_pw_aff_min
},
5589 ['M'] = { &isl_pw_aff_max
},
5592 /* Inputs for binary isl_pw_aff operation tests.
5593 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5594 * defined by pw_aff_bin_op, and "res" is the expected result.
5601 } pw_aff_bin_tests
[] = {
5602 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5604 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5606 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5607 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5608 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5609 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5610 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5611 "{ [i] -> [NaN] }" },
5612 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5613 "{ [i] -> [NaN] }" },
5616 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5618 static int test_bin_pw_aff(isl_ctx
*ctx
)
5622 isl_pw_aff
*pa1
, *pa2
, *res
;
5624 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5625 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5626 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5627 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5628 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5629 if (isl_pw_aff_involves_nan(res
))
5630 ok
= isl_pw_aff_involves_nan(pa1
);
5632 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5633 isl_pw_aff_free(pa1
);
5634 isl_pw_aff_free(res
);
5638 isl_die(ctx
, isl_error_unknown
,
5639 "unexpected result", return -1);
5645 /* Inputs for basic tests of test operations on
5646 * isl_union_pw_multi_aff objects.
5647 * "fn" is the function that is being tested.
5648 * "arg" is a string description of the input.
5649 * "res" is the expected result.
5652 isl_bool (*fn
)(__isl_keep isl_union_pw_multi_aff
*upma1
);
5655 } upma_test_tests
[] = {
5656 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [1] }",
5658 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [NaN]; B[0] -> [1] }",
5660 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [NaN] }",
5662 { &isl_union_pw_multi_aff_involves_nan
,
5663 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5665 { &isl_union_pw_multi_aff_involves_locals
,
5666 "{ A[] -> [0]; B[0] -> [1] }",
5668 { &isl_union_pw_multi_aff_involves_locals
,
5669 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5671 { &isl_union_pw_multi_aff_involves_locals
,
5672 "{ A[] -> [0]; B[x] -> [x // 2] }",
5674 { &isl_union_pw_multi_aff_involves_locals
,
5675 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5679 /* Perform some basic tests of test operations on
5680 * isl_union_pw_multi_aff objects.
5682 static isl_stat
test_upma_test(isl_ctx
*ctx
)
5685 isl_union_pw_multi_aff
*upma
;
5688 for (i
= 0; i
< ARRAY_SIZE(upma_test_tests
); ++i
) {
5691 str
= upma_test_tests
[i
].arg
;
5692 upma
= isl_union_pw_multi_aff_read_from_str(ctx
, str
);
5693 res
= upma_test_tests
[i
].fn(upma
);
5694 isl_union_pw_multi_aff_free(upma
);
5696 return isl_stat_error
;
5697 if (res
!= upma_test_tests
[i
].res
)
5698 isl_die(ctx
, isl_error_unknown
,
5699 "unexpected result", return isl_stat_error
);
5706 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5707 __isl_take isl_union_pw_multi_aff
*upma1
,
5708 __isl_take isl_union_pw_multi_aff
*upma2
);
5712 } upma_bin_tests
[] = {
5713 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5714 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5715 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5716 "{ B[x] -> [2] : x >= 0 }",
5717 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5718 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5719 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5720 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5721 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5722 "D[i] -> B[2] : i >= 5 }" },
5723 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5724 "{ B[x] -> C[2] : x > 0 }",
5725 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5726 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5727 "{ B[x] -> A[2] : x >= 0 }",
5728 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5730 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5731 "{ B[x] -> C[x + 2] }",
5732 "{ D[y] -> B[2y] }",
5735 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5736 "{ [A[x] -> B[x + 1]] -> C[x + 2] }",
5737 "{ D[y] -> B[2y] }",
5740 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5741 "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5742 "{ D[y] -> A[2y] }",
5743 "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5745 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5746 "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5747 "{ D[y] -> A[2y] }",
5748 "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5751 /* Perform some basic tests of binary operations on
5752 * isl_union_pw_multi_aff objects.
5754 static int test_bin_upma(isl_ctx
*ctx
)
5757 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5760 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5761 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5762 upma_bin_tests
[i
].arg1
);
5763 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5764 upma_bin_tests
[i
].arg2
);
5765 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5766 upma_bin_tests
[i
].res
);
5767 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5768 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5769 isl_union_pw_multi_aff_free(upma1
);
5770 isl_union_pw_multi_aff_free(res
);
5774 isl_die(ctx
, isl_error_unknown
,
5775 "unexpected result", return -1);
5782 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5783 __isl_take isl_union_pw_multi_aff
*upma1
,
5784 __isl_take isl_union_pw_multi_aff
*upma2
);
5787 } upma_bin_fail_tests
[] = {
5788 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5789 "{ B[x] -> C[2] : x >= 0 }" },
5792 /* Perform some basic tests of binary operations on
5793 * isl_union_pw_multi_aff objects that are expected to fail.
5795 static int test_bin_upma_fail(isl_ctx
*ctx
)
5798 isl_union_pw_multi_aff
*upma1
, *upma2
;
5801 on_error
= isl_options_get_on_error(ctx
);
5802 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5803 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5804 for (i
= 0; i
< n
; ++i
) {
5805 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5806 upma_bin_fail_tests
[i
].arg1
);
5807 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5808 upma_bin_fail_tests
[i
].arg2
);
5809 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5810 isl_union_pw_multi_aff_free(upma1
);
5814 isl_options_set_on_error(ctx
, on_error
);
5816 isl_die(ctx
, isl_error_unknown
,
5817 "operation not expected to succeed", return -1);
5822 /* Inputs for basic tests of binary operations on
5823 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5824 * "fn" is the function that is being tested.
5825 * "arg1" and "arg2" are string descriptions of the inputs.
5826 * "res" is a string description of the expected result.
5829 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5830 __isl_take isl_union_pw_multi_aff
*upma
,
5831 __isl_take isl_union_set
*uset
);
5835 } upma_uset_tests
[] = {
5836 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5837 "{ A[i] -> B[i] }", "{ B[0] }",
5839 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain
,
5840 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5841 "{ [A[1] -> B[1]] -> C[2] }" },
5842 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5843 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5844 "{ [A[0] -> B[0]] -> C[1] }" },
5845 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5846 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5847 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5848 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5849 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5850 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5851 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5852 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5854 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5857 /* Perform some basic tests of binary operations on
5858 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5860 static isl_stat
test_upma_uset(isl_ctx
*ctx
)
5864 isl_union_pw_multi_aff
*upma
, *res
;
5865 isl_union_set
*uset
;
5867 for (i
= 0; i
< ARRAY_SIZE(upma_uset_tests
); ++i
) {
5868 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5869 upma_uset_tests
[i
].arg1
);
5870 uset
= isl_union_set_read_from_str(ctx
,
5871 upma_uset_tests
[i
].arg2
);
5872 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5873 upma_uset_tests
[i
].res
);
5874 upma
= upma_uset_tests
[i
].fn(upma
, uset
);
5875 ok
= isl_union_pw_multi_aff_plain_is_equal(upma
, res
);
5876 isl_union_pw_multi_aff_free(upma
);
5877 isl_union_pw_multi_aff_free(res
);
5879 return isl_stat_error
;
5881 isl_die(ctx
, isl_error_unknown
,
5882 "unexpected result", return isl_stat_error
);
5888 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5889 * "fn" is the function that is tested.
5890 * "arg" is a string description of the input.
5891 * "res" is a string description of the expected result.
5894 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5897 } mpa_un_tests
[] = {
5898 { &isl_multi_pw_aff_range_factor_domain
,
5899 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5900 "{ A[x] -> B[(1 : x >= 5)] }" },
5901 { &isl_multi_pw_aff_range_factor_range
,
5902 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5903 "{ A[y] -> C[(2 : y <= 10)] }" },
5904 { &isl_multi_pw_aff_range_factor_domain
,
5905 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5906 "{ A[x] -> B[(1 : x >= 5)] }" },
5907 { &isl_multi_pw_aff_range_factor_range
,
5908 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5909 "{ A[y] -> C[] }" },
5910 { &isl_multi_pw_aff_range_factor_domain
,
5911 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5912 "{ A[x] -> B[] }" },
5913 { &isl_multi_pw_aff_range_factor_range
,
5914 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5915 "{ A[y] -> C[(2 : y <= 10)] }" },
5916 { &isl_multi_pw_aff_range_factor_domain
,
5917 "{ A[x] -> [B[] -> C[]] }",
5918 "{ A[x] -> B[] }" },
5919 { &isl_multi_pw_aff_range_factor_range
,
5920 "{ A[x] -> [B[] -> C[]] }",
5921 "{ A[y] -> C[] }" },
5922 { &isl_multi_pw_aff_factor_range
,
5925 { &isl_multi_pw_aff_range_factor_domain
,
5926 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5927 "{ A[x] -> B[] : x >= 0 }" },
5928 { &isl_multi_pw_aff_range_factor_range
,
5929 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5930 "{ A[y] -> C[] : y >= 0 }" },
5931 { &isl_multi_pw_aff_factor_range
,
5932 "[N] -> { [B[] -> C[]] : N >= 0 }",
5933 "[N] -> { C[] : N >= 0 }" },
5936 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5938 static int test_un_mpa(isl_ctx
*ctx
)
5942 isl_multi_pw_aff
*mpa
, *res
;
5944 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5945 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5946 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5947 mpa
= mpa_un_tests
[i
].fn(mpa
);
5948 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5949 isl_multi_pw_aff_free(mpa
);
5950 isl_multi_pw_aff_free(res
);
5954 isl_die(ctx
, isl_error_unknown
,
5955 "unexpected result", return -1);
5961 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5962 * "fn" is the function that is tested.
5963 * "arg1" and "arg2" are string descriptions of the inputs.
5964 * "res" is a string description of the expected result.
5967 __isl_give isl_multi_pw_aff
*(*fn
)(
5968 __isl_take isl_multi_pw_aff
*mpa1
,
5969 __isl_take isl_multi_pw_aff
*mpa2
);
5973 } mpa_bin_tests
[] = {
5974 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5976 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5977 "{ A[x] -> [(x : x <= 10)] }",
5978 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5979 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5980 "{ A[x] -> [] : x <= 10 }",
5981 "{ A[x] -> [] : 5 <= x <= 10 }" },
5982 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5983 "[N] -> { A[x] -> [] : x <= N }",
5984 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5985 { &isl_multi_pw_aff_add
,
5986 "[N] -> { A[x] -> [] : x <= N }",
5987 "{ A[x] -> [] : x >= 5 }",
5988 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5989 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5990 "{ A[y] -> C[(2 : y <= 10)] }",
5991 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5992 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5993 "{ A[y] -> C[2] : y <= 10 }",
5994 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5995 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5996 "[N] -> { A[y] -> C[2] : y <= N }",
5997 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5998 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5999 "{ A[y] -> C[2] : y <= 10 }",
6000 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
6001 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6002 "{ A[] -> [B[1] -> C[2]] }" },
6003 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6004 "{ A[] -> [B[] -> C[]] }" },
6005 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6006 "{ A[y] -> C[] : y <= 10 }",
6007 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
6008 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
6009 "{ A[x] -> B[(1 : x >= 5)] }",
6010 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
6011 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6012 "{ A[y] -> C[(2 : y <= 10)] }",
6013 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
6014 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6015 "{ A[y] -> C[] : y <= 10 }",
6016 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
6017 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
6018 "{ A[x] -> B[(1 : x >= 5)] }",
6019 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
6020 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6021 "[N] -> { A[y] -> C[] : y <= N }",
6022 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
6023 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
6024 "{ A[x] -> B[(1 : x >= 5)] }",
6025 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
6026 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
6027 "{ A[y] -> C[] : y <= 10 }",
6028 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
6029 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6030 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
6031 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6032 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
6033 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6034 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
6035 "{ A[a,b] -> C[b + 2a] }" },
6036 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6037 "{ B[i,j] -> C[i + 2j] }",
6038 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6039 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
6040 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6041 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
6042 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6043 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
6044 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6045 "{ B[i,j] -> C[] }",
6046 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6047 "{ A[a,b] -> C[] }" },
6048 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6049 "{ B[i,j] -> C[] : i > j }",
6050 "{ A[a,b] -> B[b,a] }",
6051 "{ A[a,b] -> C[] : b > a }" },
6052 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6053 "{ B[i,j] -> C[] : j > 5 }",
6054 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6055 "{ A[a,b] -> C[] : b > a > 5 }" },
6056 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6057 "[N] -> { B[i,j] -> C[] : j > N }",
6058 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6059 "[N] -> { A[a,b] -> C[] : b > a > N }" },
6060 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6061 "[M,N] -> { B[] -> C[] : N > 5 }",
6062 "[M,N] -> { A[] -> B[] : M > N }",
6063 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
6066 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
6068 static int test_bin_mpa(isl_ctx
*ctx
)
6072 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
6074 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
6075 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
6076 mpa_bin_tests
[i
].arg1
);
6077 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
6078 mpa_bin_tests
[i
].arg2
);
6079 res
= isl_multi_pw_aff_read_from_str(ctx
,
6080 mpa_bin_tests
[i
].res
);
6081 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
6082 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
6083 isl_multi_pw_aff_free(mpa1
);
6084 isl_multi_pw_aff_free(res
);
6088 isl_die(ctx
, isl_error_unknown
,
6089 "unexpected result", return -1);
6095 /* Inputs for basic tests of unary operations on
6096 * isl_multi_union_pw_aff objects.
6097 * "fn" is the function that is tested.
6098 * "arg" is a string description of the input.
6099 * "res" is a string description of the expected result.
6102 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6103 __isl_take isl_multi_union_pw_aff
*mupa
);
6106 } mupa_un_tests
[] = {
6107 { &isl_multi_union_pw_aff_factor_range
,
6108 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
6109 "C[{ A[] -> [2] }]" },
6110 { &isl_multi_union_pw_aff_factor_range
,
6111 "[B[] -> C[{ A[] -> [2] }]]",
6112 "C[{ A[] -> [2] }]" },
6113 { &isl_multi_union_pw_aff_factor_range
,
6114 "[B[{ A[] -> [1] }] -> C[]]",
6116 { &isl_multi_union_pw_aff_factor_range
,
6119 { &isl_multi_union_pw_aff_factor_range
,
6120 "([B[] -> C[]] : { A[x] : x >= 0 })",
6121 "(C[] : { A[x] : x >= 0 })" },
6122 { &isl_multi_union_pw_aff_factor_range
,
6123 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
6124 "[N] -> (C[] : { A[x] : x <= N })" },
6125 { &isl_multi_union_pw_aff_factor_range
,
6126 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
6127 "[N] -> (C[] : { : N >= 0 })" },
6130 /* Perform some basic tests of unary operations on
6131 * isl_multi_union_pw_aff objects.
6133 static int test_un_mupa(isl_ctx
*ctx
)
6137 isl_multi_union_pw_aff
*mupa
, *res
;
6139 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
6140 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6141 mupa_un_tests
[i
].arg
);
6142 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6143 mupa_un_tests
[i
].res
);
6144 mupa
= mupa_un_tests
[i
].fn(mupa
);
6145 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6146 isl_multi_union_pw_aff_free(mupa
);
6147 isl_multi_union_pw_aff_free(res
);
6151 isl_die(ctx
, isl_error_unknown
,
6152 "unexpected result", return -1);
6158 /* Inputs for basic tests of binary operations on
6159 * isl_multi_union_pw_aff objects.
6160 * "fn" is the function that is tested.
6161 * "arg1" and "arg2" are string descriptions of the inputs.
6162 * "res" is a string description of the expected result.
6165 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6166 __isl_take isl_multi_union_pw_aff
*mupa1
,
6167 __isl_take isl_multi_union_pw_aff
*mupa2
);
6171 } mupa_bin_tests
[] = {
6172 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6173 "[{ A[] -> [3] }]" },
6174 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6175 "[{ A[] -> [-1] }]" },
6176 { &isl_multi_union_pw_aff_add
,
6177 "[{ A[] -> [1]; B[] -> [4] }]",
6178 "[{ A[] -> [2]; C[] -> [5] }]",
6179 "[{ A[] -> [3] }]" },
6180 { &isl_multi_union_pw_aff_union_add
,
6181 "[{ A[] -> [1]; B[] -> [4] }]",
6182 "[{ A[] -> [2]; C[] -> [5] }]",
6183 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6184 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6185 "[{ A[x] -> [(x)] : x <= 10 }]",
6186 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6187 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6188 "([] : { A[x] : x <= 10 })",
6189 "([] : { A[x] : 5 <= x <= 10 })" },
6190 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6191 "[N] -> ([] : { A[x] : x <= N })",
6192 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6193 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
6194 "([] : { A[x] : x <= 10 })",
6195 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6196 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6197 "[{ A[x] -> [(x)] : x <= 10 }]",
6198 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6199 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6200 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
6201 "([] : { A[x] : x <= 10 })",
6202 "([] : { A[x] })" },
6203 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
6204 "[N] -> ([] : { A[x] : x >= N })",
6205 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6206 { &isl_multi_union_pw_aff_union_add
,
6207 "[N] -> ([] : { A[] : N >= 0})",
6208 "[N] -> ([] : { A[] : N <= 0})",
6209 "[N] -> ([] : { A[] })" },
6210 { &isl_multi_union_pw_aff_union_add
,
6211 "[N] -> ([] : { A[] })",
6212 "[N] -> ([] : { : })",
6213 "[N] -> ([] : { : })" },
6214 { &isl_multi_union_pw_aff_union_add
,
6215 "[N] -> ([] : { : })",
6216 "[N] -> ([] : { A[] })",
6217 "[N] -> ([] : { : })" },
6218 { &isl_multi_union_pw_aff_union_add
,
6219 "[N] -> ([] : { : N >= 0})",
6220 "[N] -> ([] : { : N <= 0})",
6221 "[N] -> ([] : { : })" },
6222 { &isl_multi_union_pw_aff_range_product
,
6223 "B[{ A[] -> [1] }]",
6224 "C[{ A[] -> [2] }]",
6225 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6226 { &isl_multi_union_pw_aff_range_product
,
6227 "(B[] : { A[x] : x >= 5 })",
6228 "(C[] : { A[x] : x <= 10 })",
6229 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6230 { &isl_multi_union_pw_aff_range_product
,
6231 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6232 "(C[] : { A[x] : x <= 10 })",
6233 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6234 { &isl_multi_union_pw_aff_range_product
,
6235 "(C[] : { A[x] : x <= 10 })",
6236 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6237 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6238 { &isl_multi_union_pw_aff_range_product
,
6239 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6240 "[N] -> (C[] : { A[x] : x <= N })",
6241 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6242 { &isl_multi_union_pw_aff_range_product
,
6243 "[N] -> (C[] : { A[x] : x <= N })",
6244 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6245 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6246 { &isl_multi_union_pw_aff_range_product
,
6247 "B[{ A[] -> [1]; D[] -> [3] }]",
6248 "C[{ A[] -> [2] }]",
6249 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6250 { &isl_multi_union_pw_aff_range_product
,
6253 "([B[] -> C[]] : { A[x] })" },
6254 { &isl_multi_union_pw_aff_range_product
,
6257 "([B[] -> C[]] : { A[x] })" },
6260 /* Perform some basic tests of binary operations on
6261 * isl_multi_union_pw_aff objects.
6263 static int test_bin_mupa(isl_ctx
*ctx
)
6267 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
6269 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
6270 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
6271 mupa_bin_tests
[i
].arg1
);
6272 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
6273 mupa_bin_tests
[i
].arg2
);
6274 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6275 mupa_bin_tests
[i
].res
);
6276 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
6277 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
6278 isl_multi_union_pw_aff_free(mupa1
);
6279 isl_multi_union_pw_aff_free(res
);
6283 isl_die(ctx
, isl_error_unknown
,
6284 "unexpected result", return -1);
6290 /* Inputs for basic tests of binary operations on
6291 * pairs of isl_multi_union_pw_aff and isl_set objects.
6292 * "fn" is the function that is tested.
6293 * "arg1" and "arg2" are string descriptions of the inputs.
6294 * "res" is a string description of the expected result.
6297 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6298 __isl_take isl_multi_union_pw_aff
*mupa
,
6299 __isl_take isl_set
*set
);
6303 } mupa_set_tests
[] = {
6304 { &isl_multi_union_pw_aff_intersect_range
,
6305 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6306 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6307 { &isl_multi_union_pw_aff_intersect_range
,
6308 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6309 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6310 { &isl_multi_union_pw_aff_intersect_range
,
6311 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6312 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6313 { &isl_multi_union_pw_aff_intersect_range
,
6314 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6315 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6316 { &isl_multi_union_pw_aff_intersect_range
,
6317 "C[]", "{ C[] }", "C[]" },
6318 { &isl_multi_union_pw_aff_intersect_range
,
6319 "[N] -> (C[] : { : N >= 0 })",
6321 "[N] -> (C[] : { : N >= 0 })" },
6322 { &isl_multi_union_pw_aff_intersect_range
,
6323 "(C[] : { A[a,b] })",
6325 "(C[] : { A[a,b] })" },
6326 { &isl_multi_union_pw_aff_intersect_range
,
6327 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6329 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6330 { &isl_multi_union_pw_aff_intersect_range
,
6332 "[N] -> { C[] : N >= 0 }",
6333 "[N] -> (C[] : { : N >= 0 })" },
6334 { &isl_multi_union_pw_aff_intersect_range
,
6335 "(C[] : { A[a,b] })",
6336 "[N] -> { C[] : N >= 0 }",
6337 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6338 { &isl_multi_union_pw_aff_intersect_range
,
6339 "[N] -> (C[] : { : N >= 0 })",
6340 "[N] -> { C[] : N < 1024 }",
6341 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6342 { &isl_multi_union_pw_aff_intersect_params
,
6343 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6344 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6345 { &isl_multi_union_pw_aff_intersect_params
,
6346 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6347 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6348 { &isl_multi_union_pw_aff_intersect_params
,
6349 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6350 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6351 { &isl_multi_union_pw_aff_intersect_params
,
6352 "C[]", "[N] -> { : N >= 0 }",
6353 "[N] -> (C[] : { : N >= 0 })" },
6354 { &isl_multi_union_pw_aff_intersect_params
,
6355 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6356 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6357 { &isl_multi_union_pw_aff_intersect_params
,
6358 "[N] -> (C[] : { A[a,N] })", "{ : }",
6359 "[N] -> (C[] : { A[a,N] })" },
6360 { &isl_multi_union_pw_aff_intersect_params
,
6361 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6362 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6365 /* Perform some basic tests of binary operations on
6366 * pairs of isl_multi_union_pw_aff and isl_set objects.
6368 static int test_mupa_set(isl_ctx
*ctx
)
6372 isl_multi_union_pw_aff
*mupa
, *res
;
6375 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
6376 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6377 mupa_set_tests
[i
].arg1
);
6378 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
6379 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6380 mupa_set_tests
[i
].res
);
6381 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
6382 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6383 isl_multi_union_pw_aff_free(mupa
);
6384 isl_multi_union_pw_aff_free(res
);
6388 isl_die(ctx
, isl_error_unknown
,
6389 "unexpected result", return -1);
6395 /* Inputs for basic tests of binary operations on
6396 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6397 * "fn" is the function that is tested.
6398 * "arg1" and "arg2" are string descriptions of the inputs.
6399 * "res" is a string description of the expected result.
6402 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6403 __isl_take isl_multi_union_pw_aff
*mupa
,
6404 __isl_take isl_union_set
*uset
);
6408 } mupa_uset_tests
[] = {
6409 { &isl_multi_union_pw_aff_intersect_domain
,
6410 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6411 "C[{ B[i,i] -> [3i] }]" },
6412 { &isl_multi_union_pw_aff_intersect_domain
,
6413 "(C[] : { B[i,j] })", "{ B[i,i] }",
6414 "(C[] : { B[i,i] })" },
6415 { &isl_multi_union_pw_aff_intersect_domain
,
6416 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6417 "[N] -> (C[] : { B[N,N] })" },
6418 { &isl_multi_union_pw_aff_intersect_domain
,
6419 "C[]", "{ B[i,i] }",
6420 "(C[] : { B[i,i] })" },
6421 { &isl_multi_union_pw_aff_intersect_domain
,
6422 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6423 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6426 /* Perform some basic tests of binary operations on
6427 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6429 static int test_mupa_uset(isl_ctx
*ctx
)
6433 isl_multi_union_pw_aff
*mupa
, *res
;
6434 isl_union_set
*uset
;
6436 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
6437 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6438 mupa_uset_tests
[i
].arg1
);
6439 uset
= isl_union_set_read_from_str(ctx
,
6440 mupa_uset_tests
[i
].arg2
);
6441 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6442 mupa_uset_tests
[i
].res
);
6443 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
6444 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6445 isl_multi_union_pw_aff_free(mupa
);
6446 isl_multi_union_pw_aff_free(res
);
6450 isl_die(ctx
, isl_error_unknown
,
6451 "unexpected result", return -1);
6457 /* Inputs for basic tests of binary operations on
6458 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6459 * "fn" is the function that is tested.
6460 * "arg1" and "arg2" are string descriptions of the inputs.
6461 * "res" is a string description of the expected result.
6464 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6465 __isl_take isl_multi_union_pw_aff
*mupa
,
6466 __isl_take isl_multi_aff
*ma
);
6470 } mupa_ma_tests
[] = {
6471 { &isl_multi_union_pw_aff_apply_multi_aff
,
6472 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6473 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6474 "{ C[a,b] -> D[b,a] }",
6475 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6476 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6477 { &isl_multi_union_pw_aff_apply_multi_aff
,
6478 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6479 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6480 "{ C[a,b] -> D[b,a] }",
6481 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6482 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6483 { &isl_multi_union_pw_aff_apply_multi_aff
,
6484 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6485 "[N] -> { C[a] -> D[a + N] }",
6486 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6487 { &isl_multi_union_pw_aff_apply_multi_aff
,
6491 { &isl_multi_union_pw_aff_apply_multi_aff
,
6492 "[N] -> (C[] : { : N >= 0 })",
6494 "[N] -> (D[] : { : N >= 0 })" },
6495 { &isl_multi_union_pw_aff_apply_multi_aff
,
6497 "[N] -> { C[] -> D[N] }",
6498 "[N] -> D[{ [N] }]" },
6499 { &isl_multi_union_pw_aff_apply_multi_aff
,
6500 "(C[] : { A[i,j] : i >= j })",
6502 "(D[] : { A[i,j] : i >= j })" },
6503 { &isl_multi_union_pw_aff_apply_multi_aff
,
6504 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6506 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6507 { &isl_multi_union_pw_aff_apply_multi_aff
,
6508 "(C[] : { A[i,j] : i >= j })",
6509 "[N] -> { C[] -> D[N] }",
6510 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6513 /* Perform some basic tests of binary operations on
6514 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6516 static int test_mupa_ma(isl_ctx
*ctx
)
6520 isl_multi_union_pw_aff
*mupa
, *res
;
6523 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6524 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6525 mupa_ma_tests
[i
].arg1
);
6526 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6527 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6528 mupa_ma_tests
[i
].res
);
6529 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6530 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6531 isl_multi_union_pw_aff_free(mupa
);
6532 isl_multi_union_pw_aff_free(res
);
6536 isl_die(ctx
, isl_error_unknown
,
6537 "unexpected result", return -1);
6543 /* Inputs for basic tests of binary operations on
6544 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6545 * "fn" is the function that is tested.
6546 * "arg1" and "arg2" are string descriptions of the inputs.
6547 * "res" is a string description of the expected result.
6550 __isl_give isl_union_pw_aff
*(*fn
)(
6551 __isl_take isl_multi_union_pw_aff
*mupa
,
6552 __isl_take isl_pw_aff
*pa
);
6556 } mupa_pa_tests
[] = {
6557 { &isl_multi_union_pw_aff_apply_pw_aff
,
6558 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6559 "[N] -> { C[a] -> [a + N] }",
6560 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6561 { &isl_multi_union_pw_aff_apply_pw_aff
,
6562 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6563 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6564 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6565 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6566 { &isl_multi_union_pw_aff_apply_pw_aff
,
6568 "[N] -> { C[] -> [N] }",
6570 { &isl_multi_union_pw_aff_apply_pw_aff
,
6572 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6573 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6574 { &isl_multi_union_pw_aff_apply_pw_aff
,
6575 "[N] -> (C[] : { : N >= 0 })",
6576 "[N] -> { C[] -> [N] }",
6577 "[N] -> { [N] : N >= 0 }" },
6578 { &isl_multi_union_pw_aff_apply_pw_aff
,
6579 "[N] -> (C[] : { : N >= 0 })",
6580 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6581 "[N] -> { [N] : N >= 0 }" },
6582 { &isl_multi_union_pw_aff_apply_pw_aff
,
6583 "[N] -> (C[] : { : N >= 0 })",
6585 "[N] -> { [0] : N >= 0 }" },
6586 { &isl_multi_union_pw_aff_apply_pw_aff
,
6587 "(C[] : { A[i,j] : i >= j })",
6588 "[N] -> { C[] -> [N] }",
6589 "[N] -> { A[i,j] -> [N] : i >= j }" },
6590 { &isl_multi_union_pw_aff_apply_pw_aff
,
6591 "(C[] : { A[i,j] : i >= j })",
6592 "[N] -> { C[] -> [N] : N >= 0 }",
6593 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6596 /* Perform some basic tests of binary operations on
6597 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6599 static int test_mupa_pa(isl_ctx
*ctx
)
6603 isl_multi_union_pw_aff
*mupa
;
6604 isl_union_pw_aff
*upa
, *res
;
6607 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6608 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6609 mupa_pa_tests
[i
].arg1
);
6610 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6611 res
= isl_union_pw_aff_read_from_str(ctx
,
6612 mupa_pa_tests
[i
].res
);
6613 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6614 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6615 isl_union_pw_aff_free(upa
);
6616 isl_union_pw_aff_free(res
);
6620 isl_die(ctx
, isl_error_unknown
,
6621 "unexpected result", return -1);
6627 /* Inputs for basic tests of binary operations on
6628 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6629 * "fn" is the function that is tested.
6630 * "arg1" and "arg2" are string descriptions of the inputs.
6631 * "res" is a string description of the expected result.
6634 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6635 __isl_take isl_multi_union_pw_aff
*mupa
,
6636 __isl_take isl_pw_multi_aff
*pma
);
6640 } mupa_pma_tests
[] = {
6641 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6642 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6643 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6644 "{ C[a,b] -> D[b,a] }",
6645 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6646 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6647 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6648 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6649 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6650 "{ C[a,b] -> D[b,a] }",
6651 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6652 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6653 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6654 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6655 "[N] -> { C[a] -> D[a + N] }",
6656 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6657 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6658 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6659 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6660 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6661 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6662 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6663 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6664 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6665 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6666 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6667 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6668 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6669 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6670 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6674 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6675 "[N] -> (C[] : { : N >= 0 })",
6677 "[N] -> (D[] : { : N >= 0 })" },
6678 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6680 "[N] -> { C[] -> D[N] }",
6681 "[N] -> D[{ [N] }]" },
6682 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6683 "(C[] : { A[i,j] : i >= j })",
6685 "(D[] : { A[i,j] : i >= j })" },
6686 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6687 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6689 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6690 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6691 "(C[] : { A[i,j] : i >= j })",
6692 "[N] -> { C[] -> D[N] }",
6693 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6694 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6696 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6697 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6698 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6699 "[N] -> (C[] : { : N >= 0 })",
6700 "[N] -> { C[] -> D[N] }",
6701 "[N] -> D[{ [N] : N >= 0 }]" },
6702 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6703 "[N] -> (C[] : { : N >= 0 })",
6704 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6705 "[N] -> D[{ [N] : N >= 0 }]" },
6706 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6707 "[N] -> (C[] : { : N >= 0 })",
6709 "[N] -> D[{ [0] : N >= 0 }]" },
6710 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6711 "(C[] : { A[i,j] : i >= j })",
6712 "[N] -> { C[] -> D[N] : N >= 0 }",
6713 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6716 /* Perform some basic tests of binary operations on
6717 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6719 static int test_mupa_pma(isl_ctx
*ctx
)
6723 isl_multi_union_pw_aff
*mupa
, *res
;
6724 isl_pw_multi_aff
*pma
;
6726 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6727 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6728 mupa_pma_tests
[i
].arg1
);
6729 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6730 mupa_pma_tests
[i
].arg2
);
6731 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6732 mupa_pma_tests
[i
].res
);
6733 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6734 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6735 isl_multi_union_pw_aff_free(mupa
);
6736 isl_multi_union_pw_aff_free(res
);
6740 isl_die(ctx
, isl_error_unknown
,
6741 "unexpected result", return -1);
6747 /* Inputs for basic tests of binary operations on
6748 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6749 * "fn" is the function that is tested.
6750 * "arg1" and "arg2" are string descriptions of the inputs.
6751 * "res" is a string description of the expected result.
6754 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6755 __isl_take isl_multi_union_pw_aff
*mupa
,
6756 __isl_take isl_union_pw_multi_aff
*upma
);
6760 } mupa_upma_tests
[] = {
6761 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6762 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6763 "C[{ A[a,b] -> [b + 2a] }]" },
6764 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6765 "C[{ B[i,j] -> [i + 2j] }]",
6766 "{ A[a,b] -> B[b,a] : b > a }",
6767 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6768 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6769 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6770 "{ A[a,b] -> B[b,a] : b > a }",
6771 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6772 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6773 "C[{ B[i,j] -> [i + 2j] }]",
6774 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6775 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6776 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6777 "(C[] : { B[a,b] })",
6778 "{ A[a,b] -> B[b,a] }",
6779 "(C[] : { A[a,b] })" },
6780 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6781 "(C[] : { B[a,b] })",
6782 "{ B[a,b] -> A[b,a] }",
6784 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6785 "(C[] : { B[a,b] })",
6786 "{ A[a,b] -> B[b,a] : a > b }",
6787 "(C[] : { A[a,b] : a > b })" },
6788 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6789 "(C[] : { B[a,b] : a > b })",
6790 "{ A[a,b] -> B[b,a] }",
6791 "(C[] : { A[a,b] : b > a })" },
6792 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6793 "[N] -> (C[] : { B[a,b] : a > N })",
6794 "{ A[a,b] -> B[b,a] : a > b }",
6795 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6796 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6797 "(C[] : { B[a,b] : a > b })",
6798 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6799 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6800 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6802 "{ A[a,b] -> B[b,a] }",
6804 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6805 "[N] -> (C[] : { : N >= 0 })",
6806 "{ A[a,b] -> B[b,a] }",
6807 "[N] -> (C[] : { : N >= 0 })" },
6808 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6810 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6811 "[N] -> (C[] : { : N >= 0 })" },
6814 /* Perform some basic tests of binary operations on
6815 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6817 static int test_mupa_upma(isl_ctx
*ctx
)
6821 isl_multi_union_pw_aff
*mupa
, *res
;
6822 isl_union_pw_multi_aff
*upma
;
6824 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6825 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6826 mupa_upma_tests
[i
].arg1
);
6827 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6828 mupa_upma_tests
[i
].arg2
);
6829 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6830 mupa_upma_tests
[i
].res
);
6831 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6832 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6833 isl_multi_union_pw_aff_free(mupa
);
6834 isl_multi_union_pw_aff_free(res
);
6838 isl_die(ctx
, isl_error_unknown
,
6839 "unexpected result", return -1);
6845 /* Check that the input tuple of an isl_aff can be set properly.
6847 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6853 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6854 id
= isl_id_alloc(ctx
, "A", NULL
);
6855 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6856 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6859 return isl_stat_error
;
6864 /* Check that affine expressions get normalized on addition/subtraction.
6865 * In particular, check that (final) unused integer divisions get removed
6866 * such that an expression derived from expressions with integer divisions
6867 * is found to be obviously equal to one that is created directly.
6869 static isl_stat
test_aff_normalize(isl_ctx
*ctx
)
6871 isl_aff
*aff
, *aff2
;
6874 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x//2] }");
6875 aff2
= isl_aff_read_from_str(ctx
, "{ [x] -> [1 + x//2] }");
6876 aff
= isl_aff_sub(aff2
, aff
);
6877 ok
= aff_check_plain_equal(aff
, "{ [x] -> [1] }");
6883 int test_aff(isl_ctx
*ctx
)
6888 isl_local_space
*ls
;
6893 if (test_upa(ctx
) < 0)
6895 if (test_bin_aff(ctx
) < 0)
6897 if (test_bin_pw_aff(ctx
) < 0)
6899 if (test_upma_test(ctx
) < 0)
6901 if (test_bin_upma(ctx
) < 0)
6903 if (test_bin_upma_fail(ctx
) < 0)
6905 if (test_upma_uset(ctx
) < 0)
6907 if (test_un_mpa(ctx
) < 0)
6909 if (test_bin_mpa(ctx
) < 0)
6911 if (test_un_mupa(ctx
) < 0)
6913 if (test_bin_mupa(ctx
) < 0)
6915 if (test_mupa_set(ctx
) < 0)
6917 if (test_mupa_uset(ctx
) < 0)
6919 if (test_mupa_ma(ctx
) < 0)
6921 if (test_mupa_pa(ctx
) < 0)
6923 if (test_mupa_pma(ctx
) < 0)
6925 if (test_mupa_upma(ctx
) < 0)
6928 space
= isl_space_set_alloc(ctx
, 0, 1);
6929 ls
= isl_local_space_from_space(space
);
6930 aff
= isl_aff_zero_on_domain(ls
);
6932 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6933 aff
= isl_aff_scale_down_ui(aff
, 3);
6934 aff
= isl_aff_floor(aff
);
6935 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6936 aff
= isl_aff_scale_down_ui(aff
, 2);
6937 aff
= isl_aff_floor(aff
);
6938 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6941 set
= isl_set_read_from_str(ctx
, str
);
6942 aff
= isl_aff_gist(aff
, set
);
6944 aff
= isl_aff_add_constant_si(aff
, -16);
6945 zero
= isl_aff_plain_is_zero(aff
);
6951 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6953 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6954 aff
= isl_aff_scale_down_ui(aff
, 64);
6955 aff
= isl_aff_floor(aff
);
6956 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6961 if (test_aff_set_tuple_id(ctx
) < 0)
6963 if (test_aff_normalize(ctx
) < 0)
6969 /* Inputs for isl_set_bind tests.
6970 * "set" is the input set.
6971 * "tuple" is the binding tuple.
6972 * "res" is the expected result.
6979 } bind_set_tests
[] = {
6980 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6982 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6983 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6985 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6986 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6988 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6989 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6991 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6994 /* Perform basic isl_set_bind tests.
6996 static isl_stat
test_bind_set(isl_ctx
*ctx
)
7000 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
7003 isl_multi_id
*tuple
;
7006 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
7007 str
= bind_set_tests
[i
].tuple
;
7008 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7009 set
= isl_set_bind(set
, tuple
);
7010 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
7013 return isl_stat_error
;
7019 /* Inputs for isl_map_bind_domain tests.
7020 * "map" is the input map.
7021 * "tuple" is the binding tuple.
7022 * "res" is the expected result.
7028 } bind_map_domain_tests
[] = {
7029 { "{ A[M, N] -> [M + floor(N/2)] }",
7031 "[M, N] -> { [M + floor(N/2)] }" },
7032 { "{ B[N, M] -> [M + floor(N/2)] }",
7034 "[N, M] -> { [M + floor(N/2)] }" },
7035 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7037 "[M, N] -> { [M + floor(N/2)] }" },
7038 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7040 "[M, N] -> { [M + floor(N/2)] }" },
7041 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7043 "[M, N] -> { [M + floor(N/2)] }" },
7044 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7046 "[A, N, M] -> { [M + floor(N/2)] }" },
7049 /* Perform basic isl_map_bind_domain tests.
7051 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
7055 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
7059 isl_multi_id
*tuple
;
7062 str
= bind_map_domain_tests
[i
].map
;
7063 map
= isl_map_read_from_str(ctx
, str
);
7064 str
= bind_map_domain_tests
[i
].tuple
;
7065 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7066 set
= isl_map_bind_domain(map
, tuple
);
7067 str
= bind_map_domain_tests
[i
].res
;
7068 r
= set_check_equal(set
, str
);
7071 return isl_stat_error
;
7077 /* Inputs for isl_union_map_bind_range tests.
7078 * "map" is the input union map.
7079 * "tuple" is the binding tuple.
7080 * "res" is the expected result.
7086 } bind_umap_range_tests
[] = {
7087 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7089 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7090 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7093 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
7098 /* Perform basic isl_union_map_bind_range tests.
7100 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
7104 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
7106 isl_union_map
*umap
;
7107 isl_union_set
*uset
;
7108 isl_multi_id
*tuple
;
7111 str
= bind_umap_range_tests
[i
].map
;
7112 umap
= isl_union_map_read_from_str(ctx
, str
);
7113 str
= bind_umap_range_tests
[i
].tuple
;
7114 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7115 uset
= isl_union_map_bind_range(umap
, tuple
);
7116 str
= bind_umap_range_tests
[i
].res
;
7117 r
= uset_check_equal(uset
, str
);
7118 isl_union_set_free(uset
);
7120 return isl_stat_error
;
7126 /* Inputs for isl_pw_multi_aff_bind_domain tests.
7127 * "pma" is the input expression.
7128 * "tuple" is the binding tuple.
7129 * "res" is the expected result.
7135 } bind_pma_domain_tests
[] = {
7136 { "{ A[M, N] -> [M + floor(N/2)] }",
7138 "[M, N] -> { [M + floor(N/2)] }" },
7139 { "{ B[N, M] -> [M + floor(N/2)] }",
7141 "[N, M] -> { [M + floor(N/2)] }" },
7142 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7144 "[M, N] -> { [M + floor(N/2)] }" },
7145 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7147 "[M, N] -> { [M + floor(N/2)] }" },
7148 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7150 "[M, N] -> { [M + floor(N/2)] }" },
7151 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7153 "[A, N, M] -> { [M + floor(N/2)] }" },
7156 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7158 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
7162 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
7164 isl_pw_multi_aff
*pma
;
7165 isl_multi_id
*tuple
;
7168 str
= bind_pma_domain_tests
[i
].pma
;
7169 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7170 str
= bind_pma_domain_tests
[i
].tuple
;
7171 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7172 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
7173 str
= bind_pma_domain_tests
[i
].res
;
7174 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7175 isl_pw_multi_aff_free(pma
);
7177 return isl_stat_error
;
7183 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7184 * "pma" is the input expression.
7185 * "tuple" is the binding tuple.
7186 * "res" is the expected result.
7192 } bind_pma_domain_wrapped_tests
[] = {
7193 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7195 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7196 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7198 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7199 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7201 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7202 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7204 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7205 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7207 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7208 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7210 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7213 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7215 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
7219 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
7221 isl_pw_multi_aff
*pma
;
7222 isl_multi_id
*tuple
;
7225 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
7226 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7227 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
7228 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7229 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
7230 str
= bind_pma_domain_wrapped_tests
[i
].res
;
7231 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7232 isl_pw_multi_aff_free(pma
);
7234 return isl_stat_error
;
7240 /* Inputs for isl_aff_bind_id tests.
7241 * "aff" is the input expression.
7242 * "id" is the binding id.
7243 * "res" is the expected result.
7250 } bind_aff_tests
[] = {
7251 { "{ [4] }", "M", "[M = 4] -> { : }" },
7252 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7253 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7254 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7255 { "{ [NaN] }", "M", "{ : false }" },
7256 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7259 /* Perform basic isl_aff_bind_id tests.
7261 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
7265 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
7271 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
7272 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
7273 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
7274 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
7277 return isl_stat_error
;
7283 /* Inputs for isl_pw_aff_bind_id tests.
7284 * "pa" is the input expression.
7285 * "id" is the binding id.
7286 * "res" is the expected result.
7293 } bind_pa_tests
[] = {
7294 { "{ [4] }", "M", "[M = 4] -> { : }" },
7295 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7296 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7297 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7298 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7299 { "{ [NaN] }", "M", "{ : false }" },
7300 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7303 /* Perform basic isl_pw_aff_bind_id tests.
7305 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
7309 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
7315 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
7316 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
7317 res
= isl_pw_aff_bind_id(pa
, id
);
7318 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
7321 return isl_stat_error
;
7327 /* Inputs for isl_multi_union_pw_aff_bind tests.
7328 * "mupa" is the input expression.
7329 * "tuple" is the binding tuple.
7330 * "res" is the expected result.
7337 } bind_mupa_tests
[] = {
7338 { "A[{ [4] }, { [5] }]",
7340 "[M = 4, N = 5] -> { : }" },
7341 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7343 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7344 { "[M] -> A[{ [4] }, { [M + 1] }]",
7346 "[M = 4, N = 5] -> { : }" },
7349 /* Perform basic isl_multi_union_pw_aff_bind tests.
7351 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
7355 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
7357 isl_multi_union_pw_aff
*mupa
;
7359 isl_multi_id
*tuple
;
7362 str
= bind_mupa_tests
[i
].mupa
;
7363 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7364 str
= bind_mupa_tests
[i
].tuple
;
7365 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7366 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
7367 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
7368 isl_union_set_free(res
);
7370 return isl_stat_error
;
7376 /* Perform tests that reinterpret dimensions as parameters.
7378 static int test_bind(isl_ctx
*ctx
)
7380 if (test_bind_set(ctx
) < 0)
7382 if (test_bind_map_domain(ctx
) < 0)
7384 if (test_bind_umap_range(ctx
) < 0)
7386 if (test_bind_pma_domain(ctx
) < 0)
7388 if (test_bind_pma_domain_wrapped(ctx
) < 0)
7390 if (test_bind_aff(ctx
) < 0)
7392 if (test_bind_pa(ctx
) < 0)
7394 if (test_bind_mupa(ctx
) < 0)
7400 /* Inputs for isl_set_unbind_params tests.
7401 * "set" is the input parameter domain.
7402 * "tuple" is the tuple of the constructed set.
7403 * "res" is the expected result.
7409 } unbind_set_tests
[] = {
7410 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7412 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7413 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7415 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7416 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7418 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7419 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7421 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7424 /* Perform basic isl_set_unbind_params tests.
7426 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
7430 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
7433 isl_multi_id
*tuple
;
7436 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
7437 str
= unbind_set_tests
[i
].tuple
;
7438 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7439 set
= isl_set_unbind_params(set
, tuple
);
7440 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
7443 return isl_stat_error
;
7449 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7450 * "aff" is the input affine expression defined over a parameter domain.
7451 * "tuple" is the tuple of the domain that gets introduced.
7452 * "res" is the expected result.
7458 } unbind_aff_tests
[] = {
7459 { "[M, N] -> { [M + floor(N/2)] }",
7461 "{ A[M, N] -> [M + floor(N/2)] }" },
7462 { "[M, N] -> { [M + floor(N/2)] }",
7464 "{ B[N, M] -> [M + floor(N/2)] }" },
7465 { "[M, N] -> { [M + floor(N/2)] }",
7467 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7468 { "[M, N] -> { [M + floor(N/2)] }",
7469 "{ D[A, B, C, N, Z] }",
7470 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7473 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7475 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
7479 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
7482 isl_multi_id
*tuple
;
7485 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
7486 str
= unbind_aff_tests
[i
].tuple
;
7487 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7488 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
7489 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
7492 return isl_stat_error
;
7498 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7499 * "ma" is the input multi affine expression defined over a parameter domain.
7500 * "tuple" is the tuple of the domain that gets introduced.
7501 * "res" is the expected result.
7507 } unbind_multi_aff_tests
[] = {
7508 { "[M, N] -> { T[M + floor(N/2)] }",
7510 "{ A[M, N] -> T[M + floor(N/2)] }" },
7511 { "[M, N] -> { [M + floor(N/2)] }",
7513 "{ B[N, M] -> [M + floor(N/2)] }" },
7514 { "[M, N] -> { [M + floor(N/2)] }",
7516 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7517 { "[M, N] -> { [M + floor(N/2)] }",
7518 "{ D[A, B, C, N, Z] }",
7519 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7520 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7522 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7525 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7527 static isl_stat
test_unbind_multi_aff(isl_ctx
*ctx
)
7531 for (i
= 0; i
< ARRAY_SIZE(unbind_multi_aff_tests
); ++i
) {
7534 isl_multi_id
*tuple
;
7537 str
= unbind_multi_aff_tests
[i
].ma
;
7538 ma
= isl_multi_aff_read_from_str(ctx
, str
);
7539 str
= unbind_multi_aff_tests
[i
].tuple
;
7540 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7541 ma
= isl_multi_aff_unbind_params_insert_domain(ma
, tuple
);
7542 str
= unbind_multi_aff_tests
[i
].res
;
7543 r
= multi_aff_check_plain_equal(ma
, str
);
7544 isl_multi_aff_free(ma
);
7546 return isl_stat_error
;
7552 /* Perform tests that reinterpret parameters.
7554 static int test_unbind(isl_ctx
*ctx
)
7556 if (test_unbind_set(ctx
) < 0)
7558 if (test_unbind_aff(ctx
) < 0)
7560 if (test_unbind_multi_aff(ctx
) < 0)
7566 /* Check that "pa" consists of a single expression.
7568 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
7572 n
= isl_pw_aff_n_piece(pa
);
7573 isl_pw_aff_free(pa
);
7578 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
7584 /* Check that the computation below results in a single expression.
7585 * One or two expressions may result depending on which constraint
7586 * ends up being considered as redundant with respect to the other
7587 * constraints after the projection that is performed internally
7588 * by isl_set_dim_min.
7590 static int test_dim_max_1(isl_ctx
*ctx
)
7596 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7597 "-4a <= b <= 3 and b < n - 4a }";
7598 set
= isl_set_read_from_str(ctx
, str
);
7599 pa
= isl_set_dim_min(set
, 0);
7600 return check_single_piece(ctx
, pa
);
7603 /* Check that the computation below results in a single expression.
7604 * The PIP problem corresponding to these constraints has a row
7605 * that causes a split of the solution domain. The solver should
7606 * first pick rows that split off empty parts such that the actual
7607 * solution domain does not get split.
7608 * Note that the description contains some redundant constraints.
7609 * If these constraints get removed first, then the row mentioned
7610 * above does not appear in the PIP problem.
7612 static int test_dim_max_2(isl_ctx
*ctx
)
7618 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7619 "N > 0 and P >= 0 }";
7620 set
= isl_set_read_from_str(ctx
, str
);
7621 pa
= isl_set_dim_max(set
, 0);
7622 return check_single_piece(ctx
, pa
);
7625 int test_dim_max(isl_ctx
*ctx
)
7629 isl_set
*set1
, *set2
;
7634 if (test_dim_max_1(ctx
) < 0)
7636 if (test_dim_max_2(ctx
) < 0)
7639 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7640 set
= isl_set_read_from_str(ctx
, str
);
7641 pwaff
= isl_set_dim_max(set
, 0);
7642 set1
= isl_set_from_pw_aff(pwaff
);
7643 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7644 set2
= isl_set_read_from_str(ctx
, str
);
7645 equal
= isl_set_is_equal(set1
, set2
);
7651 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7653 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7654 set
= isl_set_read_from_str(ctx
, str
);
7655 pwaff
= isl_set_dim_max(set
, 0);
7656 set1
= isl_set_from_pw_aff(pwaff
);
7657 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7658 set2
= isl_set_read_from_str(ctx
, str
);
7659 equal
= isl_set_is_equal(set1
, set2
);
7665 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7667 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7668 set
= isl_set_read_from_str(ctx
, str
);
7669 pwaff
= isl_set_dim_max(set
, 0);
7670 set1
= isl_set_from_pw_aff(pwaff
);
7671 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7672 set2
= isl_set_read_from_str(ctx
, str
);
7673 equal
= isl_set_is_equal(set1
, set2
);
7679 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7681 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7682 "0 <= i < N and 0 <= j < M }";
7683 map
= isl_map_read_from_str(ctx
, str
);
7684 set
= isl_map_range(map
);
7686 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7687 set1
= isl_set_from_pw_aff(pwaff
);
7688 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7689 set2
= isl_set_read_from_str(ctx
, str
);
7690 equal
= isl_set_is_equal(set1
, set2
);
7694 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7695 set1
= isl_set_from_pw_aff(pwaff
);
7696 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7697 set2
= isl_set_read_from_str(ctx
, str
);
7698 if (equal
>= 0 && equal
)
7699 equal
= isl_set_is_equal(set1
, set2
);
7708 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7710 /* Check that solutions are properly merged. */
7711 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7712 "c <= -1 + n - 4a - 2b and c >= -2b and "
7713 "4a >= -4 + n and c >= 0 }";
7714 set
= isl_set_read_from_str(ctx
, str
);
7715 pwaff
= isl_set_dim_min(set
, 2);
7716 set1
= isl_set_from_pw_aff(pwaff
);
7717 str
= "[n] -> { [(0)] : n >= 1 }";
7718 set2
= isl_set_read_from_str(ctx
, str
);
7719 equal
= isl_set_is_equal(set1
, set2
);
7726 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7728 /* Check that empty solution lie in the right space. */
7729 str
= "[n] -> { [t,a] : 1 = 0 }";
7730 set
= isl_set_read_from_str(ctx
, str
);
7731 pwaff
= isl_set_dim_max(set
, 0);
7732 set1
= isl_set_from_pw_aff(pwaff
);
7733 str
= "[n] -> { [t] : 1 = 0 }";
7734 set2
= isl_set_read_from_str(ctx
, str
);
7735 equal
= isl_set_is_equal(set1
, set2
);
7742 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7747 /* Basic test for isl_pw_multi_aff_product.
7749 * Check that multiple pieces are properly handled.
7751 static int test_product_pma(isl_ctx
*ctx
)
7755 isl_pw_multi_aff
*pma1
, *pma2
;
7757 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7758 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7759 str
= "{ C[] -> D[] }";
7760 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7761 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7762 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7763 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7764 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7765 isl_pw_multi_aff_free(pma1
);
7772 int test_product(isl_ctx
*ctx
)
7776 isl_union_set
*uset1
, *uset2
;
7780 set
= isl_set_read_from_str(ctx
, str
);
7781 set
= isl_set_product(set
, isl_set_copy(set
));
7782 ok
= isl_set_is_wrapping(set
);
7787 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7790 uset1
= isl_union_set_read_from_str(ctx
, str
);
7791 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7792 str
= "{ [[] -> []] }";
7793 uset2
= isl_union_set_read_from_str(ctx
, str
);
7794 ok
= isl_union_set_is_equal(uset1
, uset2
);
7795 isl_union_set_free(uset1
);
7796 isl_union_set_free(uset2
);
7800 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7802 if (test_product_pma(ctx
) < 0)
7808 /* Check that two sets are not considered disjoint just because
7809 * they have a different set of (named) parameters.
7811 static int test_disjoint(isl_ctx
*ctx
)
7814 isl_set
*set
, *set2
;
7817 str
= "[n] -> { [[]->[]] }";
7818 set
= isl_set_read_from_str(ctx
, str
);
7819 str
= "{ [[]->[]] }";
7820 set2
= isl_set_read_from_str(ctx
, str
);
7821 disjoint
= isl_set_is_disjoint(set
, set2
);
7827 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7832 /* Inputs for isl_pw_multi_aff_is_equal tests.
7833 * "f1" and "f2" are the two function that need to be compared.
7834 * "equal" is the expected result.
7840 } pma_equal_tests
[] = {
7841 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7842 "[N] -> { [0] : 0 <= N <= 1 }" },
7843 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7844 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7845 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7846 "[N] -> { [0] : 0 <= N <= 1 }" },
7847 { 0, "{ [NaN] }", "{ [NaN] }" },
7850 int test_equal(isl_ctx
*ctx
)
7854 isl_set
*set
, *set2
;
7858 set
= isl_set_read_from_str(ctx
, str
);
7860 set2
= isl_set_read_from_str(ctx
, str
);
7861 equal
= isl_set_is_equal(set
, set2
);
7867 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7869 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7870 int expected
= pma_equal_tests
[i
].equal
;
7871 isl_pw_multi_aff
*f1
, *f2
;
7873 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7874 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7875 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7876 isl_pw_multi_aff_free(f1
);
7877 isl_pw_multi_aff_free(f2
);
7880 if (equal
!= expected
)
7881 isl_die(ctx
, isl_error_unknown
,
7882 "unexpected equality result", return -1);
7888 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7889 enum isl_dim_type type
, unsigned pos
, int fixed
)
7893 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7900 isl_die(ctx
, isl_error_unknown
,
7901 "map not detected as fixed", return -1);
7903 isl_die(ctx
, isl_error_unknown
,
7904 "map detected as fixed", return -1);
7907 int test_fixed(isl_ctx
*ctx
)
7912 str
= "{ [i] -> [i] }";
7913 map
= isl_map_read_from_str(ctx
, str
);
7914 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7916 str
= "{ [i] -> [1] }";
7917 map
= isl_map_read_from_str(ctx
, str
);
7918 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7920 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7921 map
= isl_map_read_from_str(ctx
, str
);
7922 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7924 map
= isl_map_read_from_str(ctx
, str
);
7925 map
= isl_map_neg(map
);
7926 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7932 struct isl_vertices_test_data
{
7935 const char *vertex
[6];
7936 } vertices_tests
[] = {
7937 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7938 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7939 { "{ A[t, i] : t = 14 and i = 1 }",
7940 1, { "{ A[14, 1] }" } },
7941 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7942 "c <= m and m <= n and m > 0 }",
7944 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7945 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7946 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7947 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7948 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7949 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7951 /* An input with implicit equality constraints among the parameters. */
7952 { "[N, M] -> { [a, b] : M >= 3 and 9 + 3M <= a <= 29 + 2N + 11M and "
7953 "2b >= M + a and 5 - 2N - M + a <= 2b <= 3 + a and "
7956 "[N, M] -> { [(21), (12)] : M = 3 and N >= 0 }",
7957 "[N, M] -> { [(61 + 2N), (32 + N)] : M = 3 and N >= 0 }",
7962 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7964 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
7966 struct isl_vertices_test_data
*data
= user
;
7969 isl_basic_set
*bset
;
7970 isl_pw_multi_aff
*pma
;
7974 ctx
= isl_vertex_get_ctx(vertex
);
7975 bset
= isl_vertex_get_domain(vertex
);
7976 ma
= isl_vertex_get_expr(vertex
);
7977 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
7979 for (i
= 0; i
< data
->n
; ++i
) {
7980 isl_pw_multi_aff
*pma_i
;
7982 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
7983 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
7984 isl_pw_multi_aff_free(pma_i
);
7986 if (equal
< 0 || equal
)
7990 isl_pw_multi_aff_free(pma
);
7991 isl_vertex_free(vertex
);
7994 return isl_stat_error
;
7996 return equal
? isl_stat_ok
: isl_stat_error
;
7999 int test_vertices(isl_ctx
*ctx
)
8003 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
8004 isl_basic_set
*bset
;
8005 isl_vertices
*vertices
;
8009 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
8010 vertices
= isl_basic_set_compute_vertices(bset
);
8011 n
= isl_vertices_get_n_vertices(vertices
);
8012 if (vertices_tests
[i
].n
!= n
)
8014 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
8015 &vertices_tests
[i
]) < 0)
8017 isl_vertices_free(vertices
);
8018 isl_basic_set_free(bset
);
8023 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
8030 /* Inputs for basic tests of unary operations on isl_union_map.
8031 * "fn" is the function that is being tested.
8032 * "arg" is a string description of the input.
8033 * "res" is a string description of the expected result.
8036 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap
);
8039 } umap_un_tests
[] = {
8040 { &isl_union_map_range_reverse
,
8041 "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
8042 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
8043 { &isl_union_map_range_reverse
,
8044 "{ A[] -> N[B[] -> C[]] }",
8045 "{ A[] -> [C[] -> B[]] }" },
8046 { &isl_union_map_range_reverse
,
8047 "{ A[] -> N[B[x] -> B[y]] }",
8048 "{ A[] -> N[B[*] -> B[*]] }" },
8051 /* Perform basic tests of unary operations on isl_union_map.
8053 static isl_stat
test_un_union_map(isl_ctx
*ctx
)
8057 for (i
= 0; i
< ARRAY_SIZE(umap_un_tests
); ++i
) {
8059 isl_union_map
*umap
, *res
;
8062 str
= umap_un_tests
[i
].arg
;
8063 umap
= isl_union_map_read_from_str(ctx
, str
);
8064 str
= umap_un_tests
[i
].res
;
8065 res
= isl_union_map_read_from_str(ctx
, str
);
8066 umap
= umap_un_tests
[i
].fn(umap
);
8067 equal
= isl_union_map_is_equal(umap
, res
);
8068 isl_union_map_free(umap
);
8069 isl_union_map_free(res
);
8071 return isl_stat_error
;
8073 isl_die(ctx
, isl_error_unknown
,
8074 "unexpected result", return isl_stat_error
);
8080 /* Inputs for basic tests of binary operations on isl_union_map.
8081 * "fn" is the function that is being tested.
8082 * "arg1" and "arg2" are string descriptions of the inputs.
8083 * "res" is a string description of the expected result.
8086 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap1
,
8087 __isl_take isl_union_map
*umap2
);
8091 } umap_bin_tests
[] = {
8092 { &isl_union_map_intersect
,
8093 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
8094 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
8095 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
8096 { &isl_union_map_intersect_domain_factor_domain
,
8097 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8098 "[N] -> { B[i] -> C[N] }",
8100 { &isl_union_map_intersect_domain_factor_domain
,
8101 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8102 "[N] -> { A[i] -> C[N] }",
8103 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8104 { &isl_union_map_intersect_domain_factor_domain
,
8105 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8106 "[N] -> { A[i] -> C[N] }",
8107 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8108 { &isl_union_map_intersect_domain_factor_range
,
8109 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8110 "[N] -> { B[i] -> C[N] }",
8111 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8112 { &isl_union_map_intersect_domain_factor_range
,
8113 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8114 "[N] -> { B[i] -> C[N] }",
8115 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8116 { &isl_union_map_intersect_domain_factor_range
,
8117 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8118 "[N] -> { A[i] -> C[N] }",
8120 { &isl_union_map_intersect_range_factor_domain
,
8121 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8122 "[N] -> { A[i] -> B[N] }",
8123 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
8124 { &isl_union_map_intersect_range_factor_domain
,
8125 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8126 "[N] -> { A[i] -> B[N] }",
8127 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
8128 { &isl_union_map_intersect_range_factor_domain
,
8129 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8130 "[N] -> { A[i] -> C[N] }",
8132 { &isl_union_map_intersect_range_factor_range
,
8133 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8134 "[N] -> { A[i] -> C[N] }",
8135 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
8136 { &isl_union_map_intersect_range_factor_range
,
8137 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8138 "[N] -> { A[i] -> C[N] }",
8139 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
8140 { &isl_union_map_intersect_range_factor_range
,
8141 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8142 "[N] -> { A[i] -> B[N] }",
8146 /* Perform basic tests of binary operations on isl_union_map.
8148 static isl_stat
test_bin_union_map(isl_ctx
*ctx
)
8152 for (i
= 0; i
< ARRAY_SIZE(umap_bin_tests
); ++i
) {
8154 isl_union_map
*umap1
, *umap2
, *res
;
8157 str
= umap_bin_tests
[i
].arg1
;
8158 umap1
= isl_union_map_read_from_str(ctx
, str
);
8159 str
= umap_bin_tests
[i
].arg2
;
8160 umap2
= isl_union_map_read_from_str(ctx
, str
);
8161 str
= umap_bin_tests
[i
].res
;
8162 res
= isl_union_map_read_from_str(ctx
, str
);
8163 umap1
= umap_bin_tests
[i
].fn(umap1
, umap2
);
8164 equal
= isl_union_map_is_equal(umap1
, res
);
8165 isl_union_map_free(umap1
);
8166 isl_union_map_free(res
);
8168 return isl_stat_error
;
8170 isl_die(ctx
, isl_error_unknown
,
8171 "unexpected result", return isl_stat_error
);
8177 /* Check that isl_union_set_contains finds space independently
8178 * of the parameters.
8180 static isl_stat
test_union_set_contains(isl_ctx
*ctx
)
8186 isl_union_set
*uset
;
8188 str
= "[N] -> { A[0:N]; B[*,*] }";
8189 uset
= isl_union_set_read_from_str(ctx
, str
);
8190 space
= isl_space_unit(ctx
);
8191 id
= isl_id_alloc(ctx
, "A", NULL
);
8192 space
= isl_space_add_named_tuple_id_ui(space
, id
, 1);
8193 ok
= isl_union_set_contains(uset
, space
);
8194 isl_space_free(space
);
8195 isl_union_set_free(uset
);
8198 return isl_stat_error
;
8200 isl_die(ctx
, isl_error_unknown
,
8201 "unexpected result", return isl_stat_error
);
8206 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8208 static int test_union_map(isl_ctx
*ctx
)
8210 if (test_un_union_map(ctx
) < 0)
8212 if (test_bin_union_map(ctx
) < 0)
8214 if (test_union_set_contains(ctx
) < 0)
8219 int test_union_pw(isl_ctx
*ctx
)
8223 isl_union_set
*uset
;
8224 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8226 str
= "{ [x] -> x^2 }";
8227 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8228 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
8229 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
8230 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
8231 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
8232 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
8233 isl_union_pw_qpolynomial_free(upwqp1
);
8234 isl_union_pw_qpolynomial_free(upwqp2
);
8238 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8243 /* Inputs for basic tests of functions that select
8244 * subparts of the domain of an isl_multi_union_pw_aff.
8245 * "fn" is the function that is tested.
8246 * "arg" is a string description of the input.
8247 * "res" is a string description of the expected result.
8250 __isl_give isl_union_set
*(*fn
)(
8251 __isl_take isl_multi_union_pw_aff
*mupa
);
8254 } un_locus_tests
[] = {
8255 { &isl_multi_union_pw_aff_zero_union_set
,
8256 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8257 "{ A[0,j]; B[0,j] }" },
8258 { &isl_multi_union_pw_aff_zero_union_set
,
8259 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8260 "{ A[i,i]; B[i,i] : i >= 0 }" },
8261 { &isl_multi_union_pw_aff_zero_union_set
,
8262 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8263 "{ A[i,j]; B[i,i] : i >= 0 }" },
8266 /* Perform some basic tests of functions that select
8267 * subparts of the domain of an isl_multi_union_pw_aff.
8269 static int test_un_locus(isl_ctx
*ctx
)
8273 isl_union_set
*uset
, *res
;
8274 isl_multi_union_pw_aff
*mupa
;
8276 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
8277 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8278 un_locus_tests
[i
].arg
);
8279 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
8280 uset
= un_locus_tests
[i
].fn(mupa
);
8281 ok
= isl_union_set_is_equal(uset
, res
);
8282 isl_union_set_free(uset
);
8283 isl_union_set_free(res
);
8287 isl_die(ctx
, isl_error_unknown
,
8288 "unexpected result", return -1);
8294 /* Inputs for basic tests of functions that select
8295 * subparts of an isl_union_map based on a relation
8296 * specified by an isl_multi_union_pw_aff.
8297 * "fn" is the function that is tested.
8298 * "arg1" and "arg2" are string descriptions of the inputs.
8299 * "res" is a string description of the expected result.
8302 __isl_give isl_union_map
*(*fn
)(
8303 __isl_take isl_union_map
*umap
,
8304 __isl_take isl_multi_union_pw_aff
*mupa
);
8308 } bin_locus_tests
[] = {
8309 { &isl_union_map_eq_at_multi_union_pw_aff
,
8310 "{ A[i,j] -> B[i',j'] }",
8311 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8312 "{ A[i,j] -> B[i,j'] }" },
8313 { &isl_union_map_eq_at_multi_union_pw_aff
,
8314 "{ A[i,j] -> B[i',j'] }",
8315 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8316 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8317 "{ A[i,j] -> B[i,j] }" },
8318 { &isl_union_map_eq_at_multi_union_pw_aff
,
8319 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8320 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8321 "{ A[i,j] -> B[i,j'] }" },
8322 { &isl_union_map_eq_at_multi_union_pw_aff
,
8323 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8324 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8325 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8326 { &isl_union_map_eq_at_multi_union_pw_aff
,
8327 "{ A[i,j] -> B[i',j'] }",
8328 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8329 "{ A[i,j] -> B[i,j'] : i > j }" },
8330 { &isl_union_map_lex_le_at_multi_union_pw_aff
,
8331 "{ A[i,j] -> B[i',j'] }",
8332 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8333 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8334 "{ A[i,j] -> B[i',j'] : i,j <<= i',j' }" },
8335 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
8336 "{ A[i,j] -> B[i',j'] }",
8337 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8338 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8339 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8340 { &isl_union_map_lex_ge_at_multi_union_pw_aff
,
8341 "{ A[i,j] -> B[i',j'] }",
8342 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8343 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8344 "{ A[i,j] -> B[i',j'] : i,j >>= i',j' }" },
8345 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
8346 "{ A[i,j] -> B[i',j'] }",
8347 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8348 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8349 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8350 { &isl_union_map_eq_at_multi_union_pw_aff
,
8351 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8352 "(F[] : { A[i,j]; B[i,j] })",
8353 "{ A[i,j] -> B[i',j'] }" },
8354 { &isl_union_map_eq_at_multi_union_pw_aff
,
8355 "{ A[i,j] -> B[i',j'] }",
8356 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8357 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8358 { &isl_union_map_eq_at_multi_union_pw_aff
,
8359 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8360 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8361 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8362 { &isl_union_map_eq_at_multi_union_pw_aff
,
8363 "{ A[i,j] -> B[i',j'] }",
8364 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8365 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8366 { &isl_union_map_eq_at_multi_union_pw_aff
,
8367 "{ A[i,j] -> B[i',j'] }",
8368 "[N] -> (F[] : { : N >= 0 })",
8369 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8372 /* Perform some basic tests of functions that select
8373 * subparts of an isl_union_map based on a relation
8374 * specified by an isl_multi_union_pw_aff.
8376 static int test_bin_locus(isl_ctx
*ctx
)
8380 isl_union_map
*umap
, *res
;
8381 isl_multi_union_pw_aff
*mupa
;
8383 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
8384 umap
= isl_union_map_read_from_str(ctx
,
8385 bin_locus_tests
[i
].arg1
);
8386 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8387 bin_locus_tests
[i
].arg2
);
8388 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
8389 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
8390 ok
= isl_union_map_is_equal(umap
, res
);
8391 isl_union_map_free(umap
);
8392 isl_union_map_free(res
);
8396 isl_die(ctx
, isl_error_unknown
,
8397 "unexpected result", return -1);
8403 /* Inputs for basic tests of functions that determine
8404 * the part of the domain where two isl_multi_aff objects
8405 * related to each other in a specific way.
8406 * "fn" is the function that is being tested.
8407 * "arg1" and "arg2" are string descriptions of the inputs.
8408 * "res" is a string description of the expected result.
8411 __isl_give isl_set
*(*fn
)(__isl_take isl_multi_aff
*ma1
,
8412 __isl_take isl_multi_aff
*ma2
);
8416 } bin_locus_ma_tests
[] = {
8417 { &isl_multi_aff_lex_le_set
, "{ [] }", "{ [] }", "{ : }" },
8418 { &isl_multi_aff_lex_lt_set
, "{ [] }", "{ [] }", "{ : false }" },
8419 { &isl_multi_aff_lex_le_set
,
8420 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8421 "{ A[i] : i <= 0 }" },
8422 { &isl_multi_aff_lex_lt_set
,
8423 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8424 "{ A[i] : i < 0 }" },
8425 { &isl_multi_aff_lex_le_set
,
8426 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8427 "{ A[i] : i <= 0 }" },
8428 { &isl_multi_aff_lex_le_set
,
8429 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8430 "{ A[i] : i <= 0 }" },
8431 { &isl_multi_aff_lex_le_set
,
8432 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8433 "{ A[i] : i < 0 }" },
8436 /* Perform some basic tests of functions that determine
8437 * the part of the domain where two isl_multi_aff objects
8438 * related to each other in a specific way.
8440 static isl_stat
test_bin_locus_ma(isl_ctx
*ctx
)
8444 for (i
= 0; i
< ARRAY_SIZE(bin_locus_ma_tests
); ++i
) {
8447 isl_multi_aff
*ma1
, *ma2
;
8450 str
= bin_locus_ma_tests
[i
].arg1
;
8451 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8452 str
= bin_locus_ma_tests
[i
].arg2
;
8453 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8454 res
= isl_set_read_from_str(ctx
, bin_locus_ma_tests
[i
].res
);
8455 set
= bin_locus_ma_tests
[i
].fn(ma1
, ma2
);
8456 ok
= isl_set_is_equal(set
, res
);
8460 return isl_stat_error
;
8462 isl_die(ctx
, isl_error_unknown
,
8463 "unexpected result", return isl_stat_error
);
8469 /* Perform basic locus tests.
8471 static int test_locus(isl_ctx
*ctx
)
8473 if (test_un_locus(ctx
) < 0)
8475 if (test_bin_locus(ctx
) < 0)
8477 if (test_bin_locus_ma(ctx
) < 0)
8482 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8483 * defined over the correct domain space.
8485 static int test_eval_1(isl_ctx
*ctx
)
8490 isl_union_pw_qpolynomial
*upwqp
;
8494 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
8495 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8497 set
= isl_set_read_from_str(ctx
, str
);
8498 pnt
= isl_set_sample_point(set
);
8499 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
8500 cmp
= isl_val_cmp_si(v
, 36);
8506 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
8511 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8513 static int test_eval_2(isl_ctx
*ctx
)
8518 isl_qpolynomial
*qp
;
8522 str
= "{ A[x] -> [x] }";
8523 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
8524 str
= "{ A[x] : false }";
8525 set
= isl_set_read_from_str(ctx
, str
);
8526 pnt
= isl_set_sample_point(set
);
8527 v
= isl_qpolynomial_eval(qp
, pnt
);
8528 ok
= isl_val_is_nan(v
);
8534 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
8539 /* Check that a polynomial (without local variables) can be evaluated
8540 * in a rational point.
8542 static isl_stat
test_eval_3(isl_ctx
*ctx
)
8544 isl_pw_qpolynomial
*pwqp
;
8549 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
8550 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
8551 v
= isl_val_read_from_str(ctx
, "1/2");
8552 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
8553 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
8554 r
= val_check_equal(v
, "1/4");
8560 /* Inputs for isl_pw_aff_eval test.
8561 * "f" is the affine function.
8562 * "p" is the point where the function should be evaluated.
8563 * "res" is the expected result.
8569 } aff_eval_tests
[] = {
8570 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8571 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8572 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8573 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8574 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8575 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8576 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8577 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8578 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8579 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8580 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8581 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8582 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8583 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8584 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8585 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8586 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8587 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8588 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8589 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8590 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8591 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8592 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8595 /* Perform basic isl_pw_aff_eval tests.
8597 static int test_eval_aff(isl_ctx
*ctx
)
8601 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
8608 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
8609 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
8610 pnt
= isl_set_sample_point(set
);
8611 v
= isl_pw_aff_eval(pa
, pnt
);
8612 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
8620 /* Perform basic evaluation tests.
8622 static int test_eval(isl_ctx
*ctx
)
8624 if (test_eval_1(ctx
) < 0)
8626 if (test_eval_2(ctx
) < 0)
8628 if (test_eval_3(ctx
) < 0)
8630 if (test_eval_aff(ctx
) < 0)
8635 /* Descriptions of sets that are tested for reparsing after printing.
8637 const char *output_tests
[] = {
8638 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8641 "{ [x] : x mod 2 = 0 }",
8642 "{ [x] : x mod 2 = 1 }",
8643 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8644 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8645 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8646 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8647 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8648 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8651 /* Check that printing a set and reparsing a set from the printed output
8652 * results in the same set.
8654 static int test_output_set(isl_ctx
*ctx
)
8658 isl_set
*set1
, *set2
;
8661 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
8662 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
8663 str
= isl_set_to_str(set1
);
8664 set2
= isl_set_read_from_str(ctx
, str
);
8666 equal
= isl_set_is_equal(set1
, set2
);
8672 isl_die(ctx
, isl_error_unknown
,
8673 "parsed output not the same", return -1);
8679 /* Check that an isl_multi_aff is printed using a consistent space.
8681 static isl_stat
test_output_ma(isl_ctx
*ctx
)
8686 isl_multi_aff
*ma
, *ma2
;
8688 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8689 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8690 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
8691 str
= isl_multi_aff_to_str(ma
);
8692 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8694 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
8695 isl_multi_aff_free(ma2
);
8696 isl_multi_aff_free(ma
);
8699 return isl_stat_error
;
8701 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8702 return isl_stat_error
);
8707 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8709 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
8714 isl_multi_pw_aff
*mpa
, *mpa2
;
8716 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8717 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8718 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
8719 str
= isl_multi_pw_aff_to_str(mpa
);
8720 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8722 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8723 isl_multi_pw_aff_free(mpa2
);
8724 isl_multi_pw_aff_free(mpa
);
8727 return isl_stat_error
;
8729 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8730 return isl_stat_error
);
8735 int test_output(isl_ctx
*ctx
)
8743 if (test_output_set(ctx
) < 0)
8745 if (test_output_ma(ctx
) < 0)
8747 if (test_output_mpa(ctx
) < 0)
8750 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8751 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8753 p
= isl_printer_to_str(ctx
);
8754 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
8755 p
= isl_printer_print_pw_aff(p
, pa
);
8756 s
= isl_printer_get_str(p
);
8757 isl_printer_free(p
);
8758 isl_pw_aff_free(pa
);
8762 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8767 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8772 int test_sample(isl_ctx
*ctx
)
8775 isl_basic_set
*bset1
, *bset2
;
8778 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8779 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8780 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8781 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8782 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8783 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8784 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8785 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8786 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8787 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8788 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8789 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8790 "d - 1073741821e and "
8791 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8792 "3j >= 1 - a + b + 2e and "
8793 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8794 "3i <= 4 - a + 4b - e and "
8795 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8796 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8797 "c <= -1 + a and 3i >= -2 - a + 3e and "
8798 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8799 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8800 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8801 "1073741823e >= 1 + 1073741823b - d and "
8802 "3i >= 1073741823b + c - 1073741823e - f and "
8803 "3i >= 1 + 2b + e + 3g }";
8804 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8805 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
8806 empty
= isl_basic_set_is_empty(bset2
);
8807 subset
= isl_basic_set_is_subset(bset2
, bset1
);
8808 isl_basic_set_free(bset1
);
8809 isl_basic_set_free(bset2
);
8810 if (empty
< 0 || subset
< 0)
8813 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
8815 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
8820 /* Perform a projection on a basic set that is known to be empty
8821 * but that has not been assigned a canonical representation.
8822 * Earlier versions of isl would run into a stack overflow
8825 static int test_empty_projection(isl_ctx
*ctx
)
8829 isl_basic_set
*bset
;
8831 str
= "{ [a, b, c, d, e, f, g, h] : 5f = 1 + 4a - b + 5c - d - 2e and "
8832 "3h = 2 + b + c and 14c >= 9 - 3a + 25b and "
8833 "4c <= 50 - 3a + 23b and 6b <= -39 + a and "
8834 "9g >= -6 + 3a + b + c and e < a + b - 2d and "
8835 "7d >= -5 + 2a + 2b and 5g >= -14 + a - 4b + d + 2e and "
8836 "9g <= -28 - 5b - 2c + 3d + 6e }";
8837 bset
= isl_basic_set_read_from_str(ctx
, str
);
8838 empty
= isl_basic_set_is_empty(bset
);
8839 bset
= isl_basic_set_params(bset
);
8840 isl_basic_set_free(bset
);
8848 int test_fixed_power(isl_ctx
*ctx
)
8855 str
= "{ [i] -> [i + 1] }";
8856 map
= isl_map_read_from_str(ctx
, str
);
8857 exp
= isl_val_int_from_si(ctx
, 23);
8858 map
= isl_map_fixed_power_val(map
, exp
);
8859 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
8867 int test_slice(isl_ctx
*ctx
)
8873 str
= "{ [i] -> [j] }";
8874 map
= isl_map_read_from_str(ctx
, str
);
8875 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8876 equal
= map_check_equal(map
, "{ [i] -> [i] }");
8881 str
= "{ [i] -> [j] }";
8882 map
= isl_map_read_from_str(ctx
, str
);
8883 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8884 equal
= map_check_equal(map
, "{ [i] -> [j] }");
8889 str
= "{ [i] -> [j] }";
8890 map
= isl_map_read_from_str(ctx
, str
);
8891 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8892 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8897 str
= "{ [i] -> [j] }";
8898 map
= isl_map_read_from_str(ctx
, str
);
8899 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8900 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8905 str
= "{ [i] -> [j] }";
8906 map
= isl_map_read_from_str(ctx
, str
);
8907 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8908 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8913 str
= "{ [i] -> [j] }";
8914 map
= isl_map_read_from_str(ctx
, str
);
8915 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8916 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8924 int test_eliminate(isl_ctx
*ctx
)
8930 str
= "{ [i] -> [j] : i = 2j }";
8931 map
= isl_map_read_from_str(ctx
, str
);
8932 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8933 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8941 /* Check basic functionality of isl_map_deltas_map.
8943 static int test_deltas_map(isl_ctx
*ctx
)
8949 str
= "{ A[i] -> A[i + 1] }";
8950 map
= isl_map_read_from_str(ctx
, str
);
8951 map
= isl_map_deltas_map(map
);
8952 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8960 /* Check that isl_set_dim_residue_class detects that the values of j
8961 * in the set below are all odd and that it does not detect any spurious
8964 static int test_residue_class(isl_ctx
*ctx
)
8971 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8972 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8973 set
= isl_set_read_from_str(ctx
, str
);
8976 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
8978 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
8979 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
8980 res
= isl_stat_error
);
8988 static int test_align_parameters_1(isl_ctx
*ctx
)
8992 isl_multi_aff
*ma1
, *ma2
;
8995 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8996 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8998 space
= isl_space_params_alloc(ctx
, 1);
8999 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
9000 ma1
= isl_multi_aff_align_params(ma1
, space
);
9002 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
9003 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
9005 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9007 isl_multi_aff_free(ma1
);
9008 isl_multi_aff_free(ma2
);
9013 isl_die(ctx
, isl_error_unknown
,
9014 "result not as expected", return -1);
9019 /* Check the isl_multi_*_from_*_list operation in case inputs
9020 * have unaligned parameters.
9021 * In particular, older versions of isl would simply fail
9022 * (without printing any error message).
9024 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
9031 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
9032 space
= isl_map_get_space(map
);
9035 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
9036 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
9037 isl_multi_aff_free(ma
);
9040 return isl_stat_error
;
9044 /* Perform basic parameter alignment tests.
9046 static int test_align_parameters(isl_ctx
*ctx
)
9048 if (test_align_parameters_1(ctx
) < 0)
9050 if (test_align_parameters_2(ctx
) < 0)
9056 /* Check that isl_*_drop_unused_params actually drops the unused parameters
9057 * by comparing the result using isl_*_plain_is_equal.
9058 * Note that this assumes that isl_*_plain_is_equal does not consider
9059 * objects that only differ by unused parameters to be equal.
9061 int test_drop_unused_parameters(isl_ctx
*ctx
)
9063 const char *str_with
, *str_without
;
9064 isl_basic_set
*bset1
, *bset2
;
9065 isl_set
*set1
, *set2
;
9066 isl_pw_aff
*pwa1
, *pwa2
;
9069 str_with
= "[n, m, o] -> { [m] }";
9070 str_without
= "[m] -> { [m] }";
9072 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
9073 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
9074 bset1
= isl_basic_set_drop_unused_params(bset1
);
9075 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
9076 isl_basic_set_free(bset1
);
9077 isl_basic_set_free(bset2
);
9082 isl_die(ctx
, isl_error_unknown
,
9083 "result not as expected", return -1);
9085 set1
= isl_set_read_from_str(ctx
, str_with
);
9086 set2
= isl_set_read_from_str(ctx
, str_without
);
9087 set1
= isl_set_drop_unused_params(set1
);
9088 equal
= isl_set_plain_is_equal(set1
, set2
);
9095 isl_die(ctx
, isl_error_unknown
,
9096 "result not as expected", return -1);
9098 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
9099 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
9100 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
9101 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
9102 isl_pw_aff_free(pwa1
);
9103 isl_pw_aff_free(pwa2
);
9108 isl_die(ctx
, isl_error_unknown
,
9109 "result not as expected", return -1);
9114 static int test_list(isl_ctx
*ctx
)
9116 isl_id
*a
, *b
, *c
, *d
, *id
;
9121 a
= isl_id_alloc(ctx
, "a", NULL
);
9122 b
= isl_id_alloc(ctx
, "b", NULL
);
9123 c
= isl_id_alloc(ctx
, "c", NULL
);
9124 d
= isl_id_alloc(ctx
, "d", NULL
);
9126 list
= isl_id_list_alloc(ctx
, 4);
9127 list
= isl_id_list_add(list
, b
);
9128 list
= isl_id_list_insert(list
, 0, a
);
9129 list
= isl_id_list_add(list
, c
);
9130 list
= isl_id_list_add(list
, d
);
9131 list
= isl_id_list_drop(list
, 1, 1);
9133 n
= isl_id_list_n_id(list
);
9137 isl_id_list_free(list
);
9138 isl_die(ctx
, isl_error_unknown
,
9139 "unexpected number of elements in list", return -1);
9142 id
= isl_id_list_get_id(list
, 0);
9145 id
= isl_id_list_get_id(list
, 1);
9148 id
= isl_id_list_get_id(list
, 2);
9152 isl_id_list_free(list
);
9155 isl_die(ctx
, isl_error_unknown
,
9156 "unexpected elements in list", return -1);
9161 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
9163 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
9168 isl_basic_set
*bset1
, *bset2
;
9170 str
= "[N] -> { A[0, N + 1] }";
9171 ma
= isl_multi_aff_read_from_str(ctx
, str
);
9172 bset1
= isl_basic_set_read_from_str(ctx
, str
);
9173 bset2
= isl_basic_set_from_multi_aff(ma
);
9174 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9175 isl_basic_set_free(bset1
);
9176 isl_basic_set_free(bset2
);
9178 return isl_stat_error
;
9180 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9181 return isl_stat_error
);
9185 const char *set_conversion_tests
[] = {
9186 "[N] -> { [i] : N - 1 <= 2 i <= N }",
9187 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
9188 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9189 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9190 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
9191 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
9192 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9193 "-3 + c <= d <= 28 + c) }",
9196 /* Check that converting from isl_set to isl_pw_multi_aff and back
9197 * to isl_set produces the original isl_set.
9199 static int test_set_conversion(isl_ctx
*ctx
)
9203 isl_set
*set1
, *set2
;
9204 isl_pw_multi_aff
*pma
;
9207 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
9208 str
= set_conversion_tests
[i
];
9209 set1
= isl_set_read_from_str(ctx
, str
);
9210 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
9211 set2
= isl_set_from_pw_multi_aff(pma
);
9212 equal
= isl_set_is_equal(set1
, set2
);
9219 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9226 const char *conversion_tests
[] = {
9227 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9228 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9229 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9230 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9232 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9233 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9234 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9237 /* Check that converting from isl_map to isl_pw_multi_aff and back
9238 * to isl_map produces the original isl_map.
9240 static int test_map_conversion(isl_ctx
*ctx
)
9243 isl_map
*map1
, *map2
;
9244 isl_pw_multi_aff
*pma
;
9247 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
9248 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
9249 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
9250 map2
= isl_map_from_pw_multi_aff(pma
);
9251 equal
= isl_map_is_equal(map1
, map2
);
9258 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9265 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9266 * to isl_multi_pw_aff and back.
9268 const char *mpa_conversion_tests
[] = {
9270 "{ [x] -> A[x] : x >= 0 }",
9271 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9272 "{ [x] -> A[x, x + 1] }",
9274 "{ [x] -> A[] : x >= 0 }",
9277 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9278 * back to isl_pw_multi_aff preserves the original meaning.
9280 static int test_mpa_conversion(isl_ctx
*ctx
)
9283 isl_pw_multi_aff
*pma1
, *pma2
;
9284 isl_multi_pw_aff
*mpa
;
9287 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
9289 str
= mpa_conversion_tests
[i
];
9290 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9291 pma2
= isl_pw_multi_aff_copy(pma1
);
9292 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
9293 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
9294 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9295 isl_pw_multi_aff_free(pma1
);
9296 isl_pw_multi_aff_free(pma2
);
9301 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9308 /* Descriptions of union maps that should be convertible
9309 * to an isl_multi_union_pw_aff.
9311 const char *umap_mupa_conversion_tests
[] = {
9312 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9313 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9314 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9315 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9317 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9318 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9319 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9320 "{ A[] -> B[0]; C[] -> B[1] }",
9321 "{ A[] -> B[]; C[] -> B[] }",
9324 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9325 * to isl_union_map produces the original isl_union_map.
9327 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
9330 isl_union_map
*umap1
, *umap2
;
9331 isl_multi_union_pw_aff
*mupa
;
9334 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
9336 str
= umap_mupa_conversion_tests
[i
];
9337 umap1
= isl_union_map_read_from_str(ctx
, str
);
9338 umap2
= isl_union_map_copy(umap1
);
9339 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
9340 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
9341 equal
= isl_union_map_is_equal(umap1
, umap2
);
9342 isl_union_map_free(umap1
);
9343 isl_union_map_free(umap2
);
9348 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9355 static int test_conversion(isl_ctx
*ctx
)
9357 if (test_ma_conversion(ctx
) < 0)
9359 if (test_set_conversion(ctx
) < 0)
9361 if (test_map_conversion(ctx
) < 0)
9363 if (test_mpa_conversion(ctx
) < 0)
9365 if (test_union_map_mupa_conversion(ctx
) < 0)
9370 /* Check that isl_basic_map_curry does not modify input.
9372 static int test_curry(isl_ctx
*ctx
)
9375 isl_basic_map
*bmap1
, *bmap2
;
9378 str
= "{ [A[] -> B[]] -> C[] }";
9379 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
9380 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
9381 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
9382 isl_basic_map_free(bmap1
);
9383 isl_basic_map_free(bmap2
);
9388 isl_die(ctx
, isl_error_unknown
,
9389 "curried map should not be equal to original",
9399 } pullback_tests
[] = {
9400 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9401 "{ A[a,b] -> C[b + 2a] }" },
9402 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9403 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9404 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9405 "{ A[a] -> C[(a)/6] }" },
9406 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9407 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9408 "{ A[a] -> C[(2a)/3] }" },
9409 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9410 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9411 "{ A[i,j] -> C[i + j, i + j] }"},
9412 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9413 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9414 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9415 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9416 "{ [i, j] -> [floor((i)/3), j] }",
9417 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9420 static int test_pullback(isl_ctx
*ctx
)
9423 isl_multi_aff
*ma1
, *ma2
;
9427 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
9428 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
9429 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
9430 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
9431 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
9432 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9433 isl_multi_aff_free(ma1
);
9434 isl_multi_aff_free(ma2
);
9438 isl_die(ctx
, isl_error_unknown
, "bad pullback",
9445 /* Check that negation is printed correctly and that equal expressions
9446 * are correctly identified.
9448 static int test_ast(isl_ctx
*ctx
)
9450 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
9454 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9455 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9456 expr
= isl_ast_expr_add(expr1
, expr2
);
9457 expr2
= isl_ast_expr_copy(expr
);
9458 expr
= isl_ast_expr_neg(expr
);
9459 expr2
= isl_ast_expr_neg(expr2
);
9460 equal
= isl_ast_expr_is_equal(expr
, expr2
);
9461 str
= isl_ast_expr_to_C_str(expr
);
9462 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
9464 isl_ast_expr_free(expr
);
9465 isl_ast_expr_free(expr2
);
9467 if (ok
< 0 || equal
< 0)
9470 isl_die(ctx
, isl_error_unknown
,
9471 "equal expressions not considered equal", return -1);
9473 isl_die(ctx
, isl_error_unknown
,
9474 "isl_ast_expr printed incorrectly", return -1);
9476 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9477 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9478 expr
= isl_ast_expr_add(expr1
, expr2
);
9479 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
9480 expr
= isl_ast_expr_sub(expr3
, expr
);
9481 str
= isl_ast_expr_to_C_str(expr
);
9482 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
9484 isl_ast_expr_free(expr
);
9489 isl_die(ctx
, isl_error_unknown
,
9490 "isl_ast_expr printed incorrectly", return -1);
9495 /* Check that isl_ast_build_expr_from_set returns a valid expression
9496 * for an empty set. Note that isl_ast_build_expr_from_set getting
9497 * called on an empty set probably indicates a bug in the caller.
9499 static int test_ast_build(isl_ctx
*ctx
)
9502 isl_ast_build
*build
;
9505 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9506 build
= isl_ast_build_from_context(set
);
9508 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
9509 expr
= isl_ast_build_expr_from_set(build
, set
);
9511 isl_ast_expr_free(expr
);
9512 isl_ast_build_free(build
);
9520 /* Internal data structure for before_for and after_for callbacks.
9522 * depth is the current depth
9523 * before is the number of times before_for has been called
9524 * after is the number of times after_for has been called
9526 struct isl_test_codegen_data
{
9532 /* This function is called before each for loop in the AST generated
9533 * from test_ast_gen1.
9535 * Increment the number of calls and the depth.
9536 * Check that the space returned by isl_ast_build_get_schedule_space
9537 * matches the target space of the schedule returned by
9538 * isl_ast_build_get_schedule.
9539 * Return an isl_id that is checked by the corresponding call
9542 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
9545 struct isl_test_codegen_data
*data
= user
;
9548 isl_union_map
*schedule
;
9549 isl_union_set
*uset
;
9555 ctx
= isl_ast_build_get_ctx(build
);
9557 if (data
->before
>= 3)
9558 isl_die(ctx
, isl_error_unknown
,
9559 "unexpected number of for nodes", return NULL
);
9560 if (data
->depth
< 0 || data
->depth
>= 2)
9561 isl_die(ctx
, isl_error_unknown
,
9562 "unexpected depth", return NULL
);
9564 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
9568 schedule
= isl_ast_build_get_schedule(build
);
9569 uset
= isl_union_map_range(schedule
);
9570 n
= isl_union_set_n_set(uset
);
9572 isl_union_set_free(uset
);
9575 isl_die(ctx
, isl_error_unknown
,
9576 "expecting single range space", return NULL
);
9579 space
= isl_ast_build_get_schedule_space(build
);
9580 set
= isl_union_set_extract_set(uset
, space
);
9581 isl_union_set_free(uset
);
9582 empty
= isl_set_is_empty(set
);
9588 isl_die(ctx
, isl_error_unknown
,
9589 "spaces don't match", return NULL
);
9591 return isl_id_alloc(ctx
, name
, NULL
);
9594 /* This function is called after each for loop in the AST generated
9595 * from test_ast_gen1.
9597 * Increment the number of calls and decrement the depth.
9598 * Check that the annotation attached to the node matches
9599 * the isl_id returned by the corresponding call to before_for.
9601 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
9602 __isl_keep isl_ast_build
*build
, void *user
)
9604 struct isl_test_codegen_data
*data
= user
;
9612 if (data
->after
> data
->before
)
9613 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9614 "mismatch in number of for nodes",
9615 return isl_ast_node_free(node
));
9617 id
= isl_ast_node_get_annotation(node
);
9619 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9620 "missing annotation", return isl_ast_node_free(node
));
9622 name
= isl_id_get_name(id
);
9623 valid
= name
&& atoi(name
+ 1) == data
->depth
;
9627 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9628 "wrong annotation", return isl_ast_node_free(node
));
9633 /* Check that the before_each_for and after_each_for callbacks
9634 * are called for each for loop in the generated code,
9635 * that they are called in the right order and that the isl_id
9636 * returned from the before_each_for callback is attached to
9637 * the isl_ast_node passed to the corresponding after_each_for call.
9639 static int test_ast_gen1(isl_ctx
*ctx
)
9643 isl_union_map
*schedule
;
9644 isl_ast_build
*build
;
9646 struct isl_test_codegen_data data
;
9648 str
= "[N] -> { : N >= 10 }";
9649 set
= isl_set_read_from_str(ctx
, str
);
9650 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9651 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9652 schedule
= isl_union_map_read_from_str(ctx
, str
);
9657 build
= isl_ast_build_from_context(set
);
9658 build
= isl_ast_build_set_before_each_for(build
,
9659 &before_for
, &data
);
9660 build
= isl_ast_build_set_after_each_for(build
,
9662 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9663 isl_ast_build_free(build
);
9667 isl_ast_node_free(tree
);
9669 if (data
.before
!= 3 || data
.after
!= 3)
9670 isl_die(ctx
, isl_error_unknown
,
9671 "unexpected number of for nodes", return -1);
9676 /* Check that the AST generator handles domains that are integrally disjoint
9677 * but not rationally disjoint.
9679 static int test_ast_gen2(isl_ctx
*ctx
)
9683 isl_union_map
*schedule
;
9684 isl_union_map
*options
;
9685 isl_ast_build
*build
;
9688 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9689 schedule
= isl_union_map_read_from_str(ctx
, str
);
9690 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9691 build
= isl_ast_build_from_context(set
);
9693 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9694 options
= isl_union_map_read_from_str(ctx
, str
);
9695 build
= isl_ast_build_set_options(build
, options
);
9696 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9697 isl_ast_build_free(build
);
9700 isl_ast_node_free(tree
);
9705 /* Increment *user on each call.
9707 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
9708 __isl_keep isl_ast_build
*build
, void *user
)
9717 /* Test that unrolling tries to minimize the number of instances.
9718 * In particular, for the schedule given below, make sure it generates
9719 * 3 nodes (rather than 101).
9721 static int test_ast_gen3(isl_ctx
*ctx
)
9725 isl_union_map
*schedule
;
9726 isl_union_map
*options
;
9727 isl_ast_build
*build
;
9731 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9732 schedule
= isl_union_map_read_from_str(ctx
, str
);
9733 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9735 str
= "{ [i] -> unroll[0] }";
9736 options
= isl_union_map_read_from_str(ctx
, str
);
9738 build
= isl_ast_build_from_context(set
);
9739 build
= isl_ast_build_set_options(build
, options
);
9740 build
= isl_ast_build_set_at_each_domain(build
,
9741 &count_domains
, &n_domain
);
9742 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9743 isl_ast_build_free(build
);
9747 isl_ast_node_free(tree
);
9750 isl_die(ctx
, isl_error_unknown
,
9751 "unexpected number of for nodes", return -1);
9756 /* Check that if the ast_build_exploit_nested_bounds options is set,
9757 * we do not get an outer if node in the generated AST,
9758 * while we do get such an outer if node if the options is not set.
9760 static int test_ast_gen4(isl_ctx
*ctx
)
9764 isl_union_map
*schedule
;
9765 isl_ast_build
*build
;
9767 enum isl_ast_node_type type
;
9770 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9771 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9773 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9775 schedule
= isl_union_map_read_from_str(ctx
, str
);
9776 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9777 build
= isl_ast_build_from_context(set
);
9778 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9779 isl_ast_build_free(build
);
9783 type
= isl_ast_node_get_type(tree
);
9784 isl_ast_node_free(tree
);
9786 if (type
== isl_ast_node_if
)
9787 isl_die(ctx
, isl_error_unknown
,
9788 "not expecting if node", return -1);
9790 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9792 schedule
= isl_union_map_read_from_str(ctx
, str
);
9793 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9794 build
= isl_ast_build_from_context(set
);
9795 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9796 isl_ast_build_free(build
);
9800 type
= isl_ast_node_get_type(tree
);
9801 isl_ast_node_free(tree
);
9803 if (type
!= isl_ast_node_if
)
9804 isl_die(ctx
, isl_error_unknown
,
9805 "expecting if node", return -1);
9807 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9812 /* This function is called for each leaf in the AST generated
9813 * from test_ast_gen5.
9815 * We finalize the AST generation by extending the outer schedule
9816 * with a zero-dimensional schedule. If this results in any for loops,
9817 * then this means that we did not pass along enough information
9818 * about the outer schedule to the inner AST generation.
9820 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9823 isl_union_map
*schedule
, *extra
;
9826 schedule
= isl_ast_build_get_schedule(build
);
9827 extra
= isl_union_map_copy(schedule
);
9828 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9829 schedule
= isl_union_map_range_product(schedule
, extra
);
9830 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9831 isl_ast_build_free(build
);
9836 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9837 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9838 "code should not contain any for loop",
9839 return isl_ast_node_free(tree
));
9844 /* Check that we do not lose any information when going back and
9845 * forth between internal and external schedule.
9847 * In particular, we create an AST where we unroll the only
9848 * non-constant dimension in the schedule. We therefore do
9849 * not expect any for loops in the AST. However, older versions
9850 * of isl would not pass along enough information about the outer
9851 * schedule when performing an inner code generation from a create_leaf
9852 * callback, resulting in the inner code generation producing a for loop.
9854 static int test_ast_gen5(isl_ctx
*ctx
)
9858 isl_union_map
*schedule
, *options
;
9859 isl_ast_build
*build
;
9862 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9863 schedule
= isl_union_map_read_from_str(ctx
, str
);
9865 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9866 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9867 options
= isl_union_map_read_from_str(ctx
, str
);
9869 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9870 build
= isl_ast_build_from_context(set
);
9871 build
= isl_ast_build_set_options(build
, options
);
9872 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9873 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9874 isl_ast_build_free(build
);
9875 isl_ast_node_free(tree
);
9882 /* Check that the expression
9884 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9886 * is not combined into
9890 * as this would result in n/2 being evaluated in parts of
9891 * the definition domain where n is not a multiple of 2.
9893 static int test_ast_expr(isl_ctx
*ctx
)
9897 isl_ast_build
*build
;
9902 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9903 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9905 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9906 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9907 build
= isl_ast_build_alloc(ctx
);
9908 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9909 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9910 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9911 isl_ast_build_free(build
);
9912 isl_ast_expr_free(expr
);
9914 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
9919 isl_die(ctx
, isl_error_unknown
,
9920 "expressions should not be combined", return -1);
9925 static int test_ast_gen(isl_ctx
*ctx
)
9927 if (test_ast_gen1(ctx
) < 0)
9929 if (test_ast_gen2(ctx
) < 0)
9931 if (test_ast_gen3(ctx
) < 0)
9933 if (test_ast_gen4(ctx
) < 0)
9935 if (test_ast_gen5(ctx
) < 0)
9937 if (test_ast_expr(ctx
) < 0)
9942 /* Check if dropping output dimensions from an isl_pw_multi_aff
9945 static int test_pw_multi_aff(isl_ctx
*ctx
)
9948 isl_pw_multi_aff
*pma1
, *pma2
;
9951 str
= "{ [i,j] -> [i+j, 4i-j] }";
9952 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9953 str
= "{ [i,j] -> [4i-j] }";
9954 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9956 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
9958 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9960 isl_pw_multi_aff_free(pma1
);
9961 isl_pw_multi_aff_free(pma2
);
9965 isl_die(ctx
, isl_error_unknown
,
9966 "expressions not equal", return -1);
9971 /* Check that we can properly parse multi piecewise affine expressions
9972 * where the piecewise affine expressions have different domains.
9974 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
9977 isl_set
*dom
, *dom2
;
9978 isl_multi_pw_aff
*mpa1
, *mpa2
;
9983 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
9984 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
9985 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
9986 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
9987 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
9988 str
= "{ [i] -> [(i : i > 0), 2i] }";
9989 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9991 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
9993 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
9994 dom
= isl_pw_aff_domain(pa
);
9995 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
9996 dom2
= isl_pw_aff_domain(pa
);
9997 equal_domain
= isl_set_is_equal(dom
, dom2
);
10000 isl_set_free(dom2
);
10001 isl_multi_pw_aff_free(mpa1
);
10002 isl_multi_pw_aff_free(mpa2
);
10007 isl_die(ctx
, isl_error_unknown
,
10008 "expressions not equal", return -1);
10010 if (equal_domain
< 0)
10013 isl_die(ctx
, isl_error_unknown
,
10014 "domains unexpectedly equal", return -1);
10019 /* Check that the dimensions in the explicit domain
10020 * of a multi piecewise affine expression are properly
10021 * taken into account.
10023 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
10026 isl_bool involves1
, involves2
, involves3
, equal
;
10027 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
10029 str
= "{ A[x,y] -> B[] : x >= y }";
10030 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10031 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
10032 mpa1
= isl_multi_pw_aff_copy(mpa
);
10034 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
10035 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
10036 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
10037 str
= "{ [a,x,y] -> B[] : x >= y }";
10038 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10039 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
10040 isl_multi_pw_aff_free(mpa2
);
10042 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
10043 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
10044 if (equal
>= 0 && equal
)
10045 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
10046 isl_multi_pw_aff_free(mpa1
);
10047 isl_multi_pw_aff_free(mpa
);
10049 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
10052 isl_die(ctx
, isl_error_unknown
,
10053 "incorrect result of dimension insertion/removal",
10054 return isl_stat_error
);
10055 if (!involves1
|| involves2
|| !involves3
)
10056 isl_die(ctx
, isl_error_unknown
,
10057 "incorrect characterization of involved dimensions",
10058 return isl_stat_error
);
10063 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
10064 * sets the explicit domain of a zero-dimensional result,
10065 * such that it can be converted to an isl_union_map.
10067 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
10070 isl_union_set
*dom
;
10072 isl_multi_union_pw_aff
*mupa
;
10073 isl_union_map
*umap
;
10075 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
10076 space
= isl_union_set_get_space(dom
);
10077 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
10078 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
10079 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
10080 isl_union_map_free(umap
);
10082 return isl_stat_error
;
10084 return isl_stat_ok
;
10087 /* String descriptions of boxes that
10088 * are used for reconstructing box maps from their lower and upper bounds.
10090 static const char *multi_pw_aff_box_tests
[] = {
10091 "{ A[x, y] -> [] : x + y >= 0 }",
10092 "[N] -> { A[x, y] -> [x] : x + y <= N }",
10093 "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
10096 /* Check that map representations of boxes can be reconstructed
10097 * from their lower and upper bounds.
10099 static isl_stat
test_multi_pw_aff_box(isl_ctx
*ctx
)
10103 for (i
= 0; i
< ARRAY_SIZE(multi_pw_aff_box_tests
); ++i
) {
10106 isl_map
*map
, *box
;
10107 isl_multi_pw_aff
*min
, *max
;
10109 str
= multi_pw_aff_box_tests
[i
];
10110 map
= isl_map_read_from_str(ctx
, str
);
10111 min
= isl_map_min_multi_pw_aff(isl_map_copy(map
));
10112 max
= isl_map_max_multi_pw_aff(isl_map_copy(map
));
10113 box
= isl_map_universe(isl_map_get_space(map
));
10114 box
= isl_map_lower_bound_multi_pw_aff(box
, min
);
10115 box
= isl_map_upper_bound_multi_pw_aff(box
, max
);
10116 equal
= isl_map_is_equal(map
, box
);
10120 return isl_stat_error
;
10122 isl_die(ctx
, isl_error_unknown
,
10123 "unexpected result", return isl_stat_error
);
10126 return isl_stat_ok
;
10129 /* Perform some tests on multi piecewise affine expressions.
10131 static int test_multi_pw_aff(isl_ctx
*ctx
)
10133 if (test_multi_pw_aff_1(ctx
) < 0)
10135 if (test_multi_pw_aff_2(ctx
) < 0)
10137 if (test_multi_pw_aff_3(ctx
) < 0)
10139 if (test_multi_pw_aff_box(ctx
) < 0)
10144 /* This is a regression test for a bug where isl_basic_map_simplify
10145 * would end up in an infinite loop. In particular, we construct
10146 * an empty basic set that is not obviously empty.
10147 * isl_basic_set_is_empty marks the basic set as empty.
10148 * After projecting out i3, the variable can be dropped completely,
10149 * but isl_basic_map_simplify refrains from doing so if the basic set
10150 * is empty and would end up in an infinite loop if it didn't test
10151 * explicitly for empty basic maps in the outer loop.
10153 static int test_simplify_1(isl_ctx
*ctx
)
10156 isl_basic_set
*bset
;
10159 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10160 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10161 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10163 bset
= isl_basic_set_read_from_str(ctx
, str
);
10164 empty
= isl_basic_set_is_empty(bset
);
10165 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
10166 isl_basic_set_free(bset
);
10170 isl_die(ctx
, isl_error_unknown
,
10171 "basic set should be empty", return -1);
10176 /* Check that the equality in the set description below
10177 * is simplified away.
10179 static int test_simplify_2(isl_ctx
*ctx
)
10182 isl_basic_set
*bset
;
10185 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10186 bset
= isl_basic_set_read_from_str(ctx
, str
);
10187 universe
= isl_basic_set_plain_is_universe(bset
);
10188 isl_basic_set_free(bset
);
10193 isl_die(ctx
, isl_error_unknown
,
10194 "equality not simplified away", return -1);
10198 /* Some simplification tests.
10200 static int test_simplify(isl_ctx
*ctx
)
10202 if (test_simplify_1(ctx
) < 0)
10204 if (test_simplify_2(ctx
) < 0)
10209 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10210 * with gbr context would fail to disable the use of the shifted tableau
10211 * when transferring equalities for the input to the context, resulting
10212 * in invalid sample values.
10214 static int test_partial_lexmin(isl_ctx
*ctx
)
10217 isl_basic_set
*bset
;
10218 isl_basic_map
*bmap
;
10221 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10222 bmap
= isl_basic_map_read_from_str(ctx
, str
);
10223 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10224 bset
= isl_basic_set_read_from_str(ctx
, str
);
10225 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
10234 /* Check that the variable compression performed on the existentially
10235 * quantified variables inside isl_basic_set_compute_divs is not confused
10236 * by the implicit equalities among the parameters.
10238 static int test_compute_divs(isl_ctx
*ctx
)
10241 isl_basic_set
*bset
;
10244 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10245 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10246 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10247 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10248 bset
= isl_basic_set_read_from_str(ctx
, str
);
10249 set
= isl_basic_set_compute_divs(bset
);
10257 /* Check that isl_schedule_get_map is not confused by a schedule tree
10258 * with divergent filter node parameters, as can result from a call
10259 * to isl_schedule_intersect_domain.
10261 static int test_schedule_tree(isl_ctx
*ctx
)
10264 isl_union_set
*uset
;
10265 isl_schedule
*sched1
, *sched2
;
10266 isl_union_map
*umap
;
10268 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
10269 sched1
= isl_schedule_from_domain(uset
);
10270 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
10271 sched2
= isl_schedule_from_domain(uset
);
10273 sched1
= isl_schedule_sequence(sched1
, sched2
);
10274 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
10275 uset
= isl_union_set_read_from_str(ctx
, str
);
10276 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
10277 umap
= isl_schedule_get_map(sched1
);
10278 isl_schedule_free(sched1
);
10279 isl_union_map_free(umap
);
10286 /* Check that a zero-dimensional prefix schedule keeps track
10287 * of the domain and outer filters.
10289 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
10293 isl_union_set
*uset
;
10294 isl_union_set_list
*filters
;
10295 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10296 isl_schedule_node
*node
;
10298 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10299 uset
= isl_union_set_read_from_str(ctx
, str
);
10300 node
= isl_schedule_node_from_domain(uset
);
10301 node
= isl_schedule_node_child(node
, 0);
10303 str
= "{ S1[i,j] : i > j }";
10304 uset
= isl_union_set_read_from_str(ctx
, str
);
10305 filters
= isl_union_set_list_from_union_set(uset
);
10306 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
10307 uset
= isl_union_set_read_from_str(ctx
, str
);
10308 filters
= isl_union_set_list_add(filters
, uset
);
10309 node
= isl_schedule_node_insert_sequence(node
, filters
);
10311 node
= isl_schedule_node_child(node
, 0);
10312 node
= isl_schedule_node_child(node
, 0);
10313 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
10314 str
= "([] : { S1[i,j] : i > j })";
10315 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10316 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10317 isl_multi_union_pw_aff_free(mupa2
);
10318 isl_multi_union_pw_aff_free(mupa
);
10319 isl_schedule_node_free(node
);
10324 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
10330 /* Check that the reaching domain elements and the prefix schedule
10331 * at a leaf node are the same before and after grouping.
10333 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
10338 isl_union_set
*uset
;
10339 isl_multi_union_pw_aff
*mupa
;
10340 isl_union_pw_multi_aff
*upma1
, *upma2
;
10341 isl_union_set
*domain1
, *domain2
;
10342 isl_union_map
*umap1
, *umap2
;
10343 isl_schedule_node
*node
;
10345 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10346 uset
= isl_union_set_read_from_str(ctx
, str
);
10347 node
= isl_schedule_node_from_domain(uset
);
10348 node
= isl_schedule_node_child(node
, 0);
10349 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10350 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10351 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10352 node
= isl_schedule_node_child(node
, 0);
10353 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10354 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10355 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10356 node
= isl_schedule_node_child(node
, 0);
10357 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10358 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10359 domain1
= isl_schedule_node_get_domain(node
);
10360 id
= isl_id_alloc(ctx
, "group", NULL
);
10361 node
= isl_schedule_node_parent(node
);
10362 node
= isl_schedule_node_group(node
, id
);
10363 node
= isl_schedule_node_child(node
, 0);
10364 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10365 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10366 domain2
= isl_schedule_node_get_domain(node
);
10367 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
10368 if (equal
>= 0 && equal
)
10369 equal
= isl_union_set_is_equal(domain1
, domain2
);
10370 if (equal
>= 0 && equal
)
10371 equal
= isl_union_map_is_equal(umap1
, umap2
);
10372 isl_union_map_free(umap1
);
10373 isl_union_map_free(umap2
);
10374 isl_union_set_free(domain1
);
10375 isl_union_set_free(domain2
);
10376 isl_union_pw_multi_aff_free(upma1
);
10377 isl_union_pw_multi_aff_free(upma2
);
10378 isl_schedule_node_free(node
);
10383 isl_die(ctx
, isl_error_unknown
,
10384 "expressions not equal", return -1);
10389 /* Check that we can have nested groupings and that the union map
10390 * schedule representation is the same before and after the grouping.
10391 * Note that after the grouping, the union map representation contains
10392 * the domain constraints from the ranges of the expansion nodes,
10393 * while they are missing from the union map representation of
10394 * the tree without expansion nodes.
10396 * Also check that the global expansion is as expected.
10398 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
10400 int equal
, equal_expansion
;
10403 isl_union_set
*uset
;
10404 isl_union_map
*umap1
, *umap2
;
10405 isl_union_map
*expansion1
, *expansion2
;
10406 isl_union_set_list
*filters
;
10407 isl_multi_union_pw_aff
*mupa
;
10408 isl_schedule
*schedule
;
10409 isl_schedule_node
*node
;
10411 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10412 "S3[i,j] : 0 <= i,j < 10 }";
10413 uset
= isl_union_set_read_from_str(ctx
, str
);
10414 node
= isl_schedule_node_from_domain(uset
);
10415 node
= isl_schedule_node_child(node
, 0);
10416 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10417 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10418 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10419 node
= isl_schedule_node_child(node
, 0);
10420 str
= "{ S1[i,j] }";
10421 uset
= isl_union_set_read_from_str(ctx
, str
);
10422 filters
= isl_union_set_list_from_union_set(uset
);
10423 str
= "{ S2[i,j]; S3[i,j] }";
10424 uset
= isl_union_set_read_from_str(ctx
, str
);
10425 filters
= isl_union_set_list_add(filters
, uset
);
10426 node
= isl_schedule_node_insert_sequence(node
, filters
);
10427 node
= isl_schedule_node_child(node
, 1);
10428 node
= isl_schedule_node_child(node
, 0);
10429 str
= "{ S2[i,j] }";
10430 uset
= isl_union_set_read_from_str(ctx
, str
);
10431 filters
= isl_union_set_list_from_union_set(uset
);
10432 str
= "{ S3[i,j] }";
10433 uset
= isl_union_set_read_from_str(ctx
, str
);
10434 filters
= isl_union_set_list_add(filters
, uset
);
10435 node
= isl_schedule_node_insert_sequence(node
, filters
);
10437 schedule
= isl_schedule_node_get_schedule(node
);
10438 umap1
= isl_schedule_get_map(schedule
);
10439 uset
= isl_schedule_get_domain(schedule
);
10440 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
10441 isl_schedule_free(schedule
);
10443 node
= isl_schedule_node_parent(node
);
10444 node
= isl_schedule_node_parent(node
);
10445 id
= isl_id_alloc(ctx
, "group1", NULL
);
10446 node
= isl_schedule_node_group(node
, id
);
10447 node
= isl_schedule_node_child(node
, 1);
10448 node
= isl_schedule_node_child(node
, 0);
10449 id
= isl_id_alloc(ctx
, "group2", NULL
);
10450 node
= isl_schedule_node_group(node
, id
);
10452 schedule
= isl_schedule_node_get_schedule(node
);
10453 umap2
= isl_schedule_get_map(schedule
);
10454 isl_schedule_free(schedule
);
10456 node
= isl_schedule_node_root(node
);
10457 node
= isl_schedule_node_child(node
, 0);
10458 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
10459 isl_schedule_node_free(node
);
10461 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10462 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10463 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10465 expansion2
= isl_union_map_read_from_str(ctx
, str
);
10467 equal
= isl_union_map_is_equal(umap1
, umap2
);
10468 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
10470 isl_union_map_free(umap1
);
10471 isl_union_map_free(umap2
);
10472 isl_union_map_free(expansion1
);
10473 isl_union_map_free(expansion2
);
10475 if (equal
< 0 || equal_expansion
< 0)
10478 isl_die(ctx
, isl_error_unknown
,
10479 "expressions not equal", return -1);
10480 if (!equal_expansion
)
10481 isl_die(ctx
, isl_error_unknown
,
10482 "unexpected expansion", return -1);
10487 /* Some tests for the isl_schedule_node_group function.
10489 static int test_schedule_tree_group(isl_ctx
*ctx
)
10491 if (test_schedule_tree_group_1(ctx
) < 0)
10493 if (test_schedule_tree_group_2(ctx
) < 0)
10502 { "{ rat: [i] : 0 <= i <= 10 }",
10503 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10504 { "{ rat: [i] : FALSE }",
10505 "{ rat: coefficients[[cst] -> [a]] }" },
10506 { "{ rat: [i] : }",
10507 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10508 { "{ [0:,1,2:3] }",
10509 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10510 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10511 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10512 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10513 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10514 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10515 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10516 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10517 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10518 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10519 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10526 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10527 "{ rat: [i] : 0 <= i <= 10 }" },
10528 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10530 { "{ rat: coefficients[[cst] -> [a]] }",
10531 "{ rat: [i] : FALSE }" },
10534 /* Test the basic functionality of isl_basic_set_coefficients and
10535 * isl_basic_set_solutions.
10537 static int test_dual(isl_ctx
*ctx
)
10541 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
10543 isl_basic_set
*bset1
, *bset2
;
10545 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
10546 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
10547 bset1
= isl_basic_set_coefficients(bset1
);
10548 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10549 isl_basic_set_free(bset1
);
10550 isl_basic_set_free(bset2
);
10554 isl_die(ctx
, isl_error_unknown
,
10555 "incorrect dual", return -1);
10558 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
10560 isl_basic_set
*bset1
, *bset2
;
10562 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
10563 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
10564 bset1
= isl_basic_set_solutions(bset1
);
10565 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10566 isl_basic_set_free(bset1
);
10567 isl_basic_set_free(bset2
);
10571 isl_die(ctx
, isl_error_unknown
,
10572 "incorrect dual", return -1);
10581 const char *domain
;
10582 const char *schedule
;
10587 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10588 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10590 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10591 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10593 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10594 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10596 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10597 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10599 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10600 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10602 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10603 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10605 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10606 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10608 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10609 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10613 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10614 * tile the band and then check if the tile and point bands have the
10615 * expected partial schedule.
10617 static int test_tile(isl_ctx
*ctx
)
10623 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
10624 shift
= isl_options_get_tile_shift_point_loops(ctx
);
10626 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
10630 isl_union_set
*domain
;
10631 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10632 isl_schedule_node
*node
;
10633 isl_multi_val
*sizes
;
10635 opt
= tile_tests
[i
].scale_tile
;
10636 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
10637 opt
= tile_tests
[i
].shift_point
;
10638 isl_options_set_tile_shift_point_loops(ctx
, opt
);
10640 str
= tile_tests
[i
].domain
;
10641 domain
= isl_union_set_read_from_str(ctx
, str
);
10642 node
= isl_schedule_node_from_domain(domain
);
10643 node
= isl_schedule_node_child(node
, 0);
10644 str
= tile_tests
[i
].schedule
;
10645 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10646 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10647 str
= tile_tests
[i
].sizes
;
10648 sizes
= isl_multi_val_read_from_str(ctx
, str
);
10649 node
= isl_schedule_node_band_tile(node
, sizes
);
10651 str
= tile_tests
[i
].tile
;
10652 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10653 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10654 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10655 isl_multi_union_pw_aff_free(mupa
);
10656 isl_multi_union_pw_aff_free(mupa2
);
10658 node
= isl_schedule_node_child(node
, 0);
10660 str
= tile_tests
[i
].point
;
10661 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10662 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10663 if (equal
>= 0 && equal
)
10664 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
10666 isl_multi_union_pw_aff_free(mupa
);
10667 isl_multi_union_pw_aff_free(mupa2
);
10669 isl_schedule_node_free(node
);
10674 isl_die(ctx
, isl_error_unknown
,
10675 "unexpected result", return -1);
10678 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
10679 isl_options_set_tile_shift_point_loops(ctx
, shift
);
10684 /* Check that the domain hash of a space is equal to the hash
10685 * of the domain of the space, both ignoring parameters.
10687 static int test_domain_hash(isl_ctx
*ctx
)
10691 uint32_t hash1
, hash2
;
10693 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
10694 space
= isl_map_get_space(map
);
10696 hash1
= isl_space_get_tuple_domain_hash(space
);
10697 space
= isl_space_domain(space
);
10698 hash2
= isl_space_get_tuple_hash(space
);
10699 isl_space_free(space
);
10703 if (hash1
!= hash2
)
10704 isl_die(ctx
, isl_error_unknown
,
10705 "domain hash not equal to hash of domain", return -1);
10710 /* Check that a universe basic set that is not obviously equal to the universe
10711 * is still recognized as being equal to the universe.
10713 static int test_universe(isl_ctx
*ctx
)
10716 isl_basic_set
*bset
;
10719 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10720 bset
= isl_basic_set_read_from_str(ctx
, s
);
10721 is_univ
= isl_basic_set_is_universe(bset
);
10722 isl_basic_set_free(bset
);
10727 isl_die(ctx
, isl_error_unknown
,
10728 "not recognized as universe set", return -1);
10733 /* Sets for which chambers are computed and checked.
10735 const char *chambers_tests
[] = {
10736 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10737 "z >= 0 and z <= C - y and z <= B - x - y }",
10740 /* Add the domain of "cell" to "cells".
10742 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
10744 isl_basic_set_list
**cells
= user
;
10745 isl_basic_set
*dom
;
10747 dom
= isl_cell_get_domain(cell
);
10748 isl_cell_free(cell
);
10749 *cells
= isl_basic_set_list_add(*cells
, dom
);
10751 return *cells
? isl_stat_ok
: isl_stat_error
;
10754 /* Check that the elements of "list" are pairwise disjoint.
10756 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
10761 n
= isl_basic_set_list_n_basic_set(list
);
10763 return isl_stat_error
;
10765 for (i
= 0; i
< n
; ++i
) {
10766 isl_basic_set
*bset_i
;
10768 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
10769 for (j
= i
+ 1; j
< n
; ++j
) {
10770 isl_basic_set
*bset_j
;
10773 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
10774 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
10775 isl_basic_set_free(bset_j
);
10777 isl_die(isl_basic_set_list_get_ctx(list
),
10778 isl_error_unknown
, "not disjoint",
10780 if (disjoint
< 0 || !disjoint
)
10783 isl_basic_set_free(bset_i
);
10785 return isl_stat_error
;
10788 return isl_stat_ok
;
10791 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10792 * are pairwise disjoint.
10794 static int test_chambers(isl_ctx
*ctx
)
10798 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
10799 isl_basic_set
*bset
;
10800 isl_vertices
*vertices
;
10801 isl_basic_set_list
*cells
;
10804 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
10805 vertices
= isl_basic_set_compute_vertices(bset
);
10806 cells
= isl_basic_set_list_alloc(ctx
, 0);
10807 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
10809 cells
= isl_basic_set_list_free(cells
);
10810 ok
= check_pairwise_disjoint(cells
);
10811 isl_basic_set_list_free(cells
);
10812 isl_vertices_free(vertices
);
10813 isl_basic_set_free(bset
);
10824 int (*fn
)(isl_ctx
*ctx
);
10826 { "universe", &test_universe
},
10827 { "domain hash", &test_domain_hash
},
10828 { "dual", &test_dual
},
10829 { "dependence analysis", &test_flow
},
10830 { "val", &test_val
},
10831 { "compute divs", &test_compute_divs
},
10832 { "partial lexmin", &test_partial_lexmin
},
10833 { "simplify", &test_simplify
},
10834 { "curry", &test_curry
},
10835 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10836 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10837 { "conversion", &test_conversion
},
10838 { "list", &test_list
},
10839 { "align parameters", &test_align_parameters
},
10840 { "drop unused parameters", &test_drop_unused_parameters
},
10841 { "pullback", &test_pullback
},
10842 { "AST", &test_ast
},
10843 { "AST build", &test_ast_build
},
10844 { "AST generation", &test_ast_gen
},
10845 { "eliminate", &test_eliminate
},
10846 { "deltas_map", &test_deltas_map
},
10847 { "residue class", &test_residue_class
},
10848 { "div", &test_div
},
10849 { "slice", &test_slice
},
10850 { "fixed power", &test_fixed_power
},
10851 { "sample", &test_sample
},
10852 { "empty projection", &test_empty_projection
},
10853 { "output", &test_output
},
10854 { "vertices", &test_vertices
},
10855 { "chambers", &test_chambers
},
10856 { "fixed", &test_fixed
},
10857 { "equal", &test_equal
},
10858 { "disjoint", &test_disjoint
},
10859 { "product", &test_product
},
10860 { "dim_max", &test_dim_max
},
10861 { "affine", &test_aff
},
10862 { "injective", &test_injective
},
10863 { "schedule (whole component)", &test_schedule_whole
},
10864 { "schedule (incremental)", &test_schedule_incremental
},
10865 { "schedule tree", &test_schedule_tree
},
10866 { "schedule tree prefix", &test_schedule_tree_prefix
},
10867 { "schedule tree grouping", &test_schedule_tree_group
},
10868 { "tile", &test_tile
},
10869 { "union map", &test_union_map
},
10870 { "union_pw", &test_union_pw
},
10871 { "locus", &test_locus
},
10872 { "eval", &test_eval
},
10873 { "parse", &test_parse
},
10874 { "single-valued", &test_sv
},
10875 { "recession cone", &test_recession_cone
},
10876 { "affine hull", &test_affine_hull
},
10877 { "simple_hull", &test_simple_hull
},
10878 { "box hull", &test_box_hull
},
10879 { "coalesce", &test_coalesce
},
10880 { "factorize", &test_factorize
},
10881 { "subset", &test_subset
},
10882 { "subtract", &test_subtract
},
10883 { "intersect", &test_intersect
},
10884 { "lexmin", &test_lexmin
},
10885 { "min", &test_min
},
10886 { "set lower bounds", &test_min_mpa
},
10887 { "gist", &test_gist
},
10888 { "piecewise quasi-polynomials", &test_pwqp
},
10889 { "lift", &test_lift
},
10890 { "bind parameters", &test_bind
},
10891 { "unbind parameters", &test_unbind
},
10892 { "bound", &test_bound
},
10893 { "get lists", &test_get_list
},
10894 { "union", &test_union
},
10895 { "split periods", &test_split_periods
},
10896 { "lexicographic order", &test_lex
},
10897 { "bijectivity", &test_bijective
},
10898 { "dataflow analysis", &test_dep
},
10899 { "reading", &test_read
},
10900 { "bounded", &test_bounded
},
10901 { "construction", &test_construction
},
10902 { "dimension manipulation", &test_dim
},
10903 { "map application", &test_application
},
10904 { "convex hull", &test_convex_hull
},
10905 { "transitive closure", &test_closure
},
10906 { "isl_bool", &test_isl_bool
},
10909 int main(int argc
, char **argv
)
10912 struct isl_ctx
*ctx
;
10913 struct isl_options
*options
;
10915 options
= isl_options_new_with_defaults();
10917 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10919 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
10920 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
10921 printf("%s\n", tests
[i
].name
);
10922 if (tests
[i
].fn(ctx
) < 0)