2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
6 * Copyright 2022 Cerebras Systems
8 * Use of this software is governed by the MIT license
10 * Written by Sven Verdoolaege, K.U.Leuven, Departement
11 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
12 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
13 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
14 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
15 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
16 * B.P. 105 - 78153 Le Chesnay, France
17 * and Cerebras Systems, 1237 E Arques Ave, Sunnyvale, CA, USA
23 #include <isl_ctx_private.h>
24 #include <isl_map_private.h>
25 #include <isl_aff_private.h>
26 #include <isl_space_private.h>
30 #include <isl_constraint_private.h>
31 #include <isl/polynomial.h>
32 #include <isl/union_set.h>
33 #include <isl/union_map.h>
34 #include <isl_factorization.h>
35 #include <isl/schedule.h>
36 #include <isl/schedule_node.h>
37 #include <isl_options_private.h>
38 #include <isl_vertices_private.h>
39 #include <isl/ast_build.h>
42 #include <isl_ast_build_expr.h>
43 #include <isl/options.h>
45 #include "isl_srcdir.c"
47 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
49 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
52 char *pattern
= "%s/test_inputs/%s.%s";
54 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
56 filename
= isl_alloc_array(ctx
, char, length
);
61 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
66 void test_parse_map(isl_ctx
*ctx
, const char *str
)
70 map
= isl_map_read_from_str(ctx
, str
);
75 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
80 map
= isl_map_read_from_str(ctx
, str
);
81 map2
= isl_map_read_from_str(ctx
, str2
);
82 equal
= isl_map_is_equal(map
, map2
);
89 isl_die(ctx
, isl_error_unknown
, "maps not equal",
95 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
97 isl_pw_qpolynomial
*pwqp
;
99 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
101 isl_pw_qpolynomial_free(pwqp
);
104 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
108 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
110 isl_pw_aff_free(pwaff
);
113 /* Check that we can read an isl_multi_val from "str" without errors.
115 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
119 mv
= isl_multi_val_read_from_str(ctx
, str
);
120 isl_multi_val_free(mv
);
125 /* String descriptions of multi piecewise affine expressions
126 * that are used for testing printing and parsing.
128 static const char *reparse_multi_pw_aff_tests
[] = {
129 "{ A[x, y] -> [] : x + y >= 0 }",
130 "{ A[x, y] -> B[] : x + y >= 0 }",
131 "{ A[x, y] -> [x] : x + y >= 0 }",
132 "[N] -> { A[x, y] -> [x] : x + y <= N }",
133 "{ A[x, y] -> [x, y] : x + y >= 0 }",
134 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
135 "[N] -> { [] : N >= 0 }",
136 "[N] -> { [] : N >= 0 }",
137 "[N] -> { [N] : N >= 0 }",
138 "[N] -> { [N, N + 1] : N >= 0 }",
139 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
140 "{ [a] -> [b = a] }",
141 "{ [a] -> [b = a] : a >= 0 }",
145 #define BASE multi_pw_aff
147 #include "check_reparse_templ.c"
148 #include "check_reparse_test_templ.c"
150 /* String descriptions that cannot be parsed
151 * as multi piecewise affine expressions.
153 static const char *parse_multi_pw_aff_fail_tests
[] = {
154 "{ [a] -> [b] : b = a }",
155 "{ [a] -> [b = a] : b >= 0 }",
158 #include "check_parse_fail_test_templ.c"
160 /* String descriptions of piecewise multi affine expressions
161 * that are used for testing printing and parsing.
163 static const char *reparse_pw_multi_aff_tests
[] = {
165 "{ [x] -> [x % 4] }",
166 "{ [x] -> [x % 4] : x mod 3 = 1 }",
167 "{ [x, x] -> [x % 4] }",
168 "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }",
169 "{ [x, x mod 2] -> [x % 4] }",
170 "{ [a] -> [a//2] : exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
171 "{ [a, b] -> [(2*floor((a)/8) + floor((b)/6))] }",
175 #define BASE pw_multi_aff
177 #include "check_reparse_templ.c"
178 #include "check_reparse_test_templ.c"
180 /* Test parsing of piecewise multi affine expressions by printing
181 * the expressions and checking that parsing the output results
182 * in the same expression.
183 * Do this for an expression converted from a map with an output
184 * dimension name that is equal to an automatically generated name, and
185 * a set of expressions parsed from strings.
187 static isl_stat
test_parse_pma(isl_ctx
*ctx
)
190 isl_pw_multi_aff
*pma
;
192 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
193 pma
= isl_pw_multi_aff_from_map(map
);
194 if (check_reparse_pw_multi_aff(ctx
, pma
) < 0)
195 return isl_stat_error
;
197 if (check_reparse_pw_multi_aff_tests(ctx
) < 0)
198 return isl_stat_error
;
203 /* String descriptions that cannot be parsed
204 * as union piecewise multi affine expressions.
206 static const char *parse_union_pw_multi_aff_fail_tests
[] = {
207 "{ [a] -> [b] : b = a }",
208 "{ [a] -> [b = a] : b >= 0 }",
212 #define BASE union_pw_multi_aff
214 #include "check_parse_fail_test_templ.c"
216 /* Test parsing of union piecewise multi affine expressions.
218 * In particular, check some cases where parsing is supposed to fail.
220 static isl_stat
test_parse_upma(isl_ctx
*ctx
)
222 if (check_parse_union_pw_multi_aff_fail_tests(ctx
) < 0)
223 return isl_stat_error
;
228 /* Test parsing of multi piecewise affine expressions by printing
229 * the expressions and checking that parsing the output results
230 * in the same expression.
231 * Do this for a couple of manually constructed expressions,
232 * an expression converted from a map with an output dimension name
233 * that is equal to an automatically generated name, and
234 * a set of expressions parsed from strings.
236 * Additionally, check some cases where parsing is supposed to fail.
238 static int test_parse_mpa(isl_ctx
*ctx
)
243 isl_pw_multi_aff
*pma
;
244 isl_multi_pw_aff
*mpa
;
247 space
= isl_space_set_alloc(ctx
, 0, 0);
248 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
249 mpa
= isl_multi_pw_aff_zero(space
);
250 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
254 space
= isl_space_set_alloc(ctx
, 1, 0);
255 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
256 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
257 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
258 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
259 mpa
= isl_multi_pw_aff_zero(space
);
260 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
261 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
265 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
266 pma
= isl_pw_multi_aff_from_map(map
);
267 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma
);
268 if (check_reparse_multi_pw_aff(ctx
, mpa
) < 0)
271 if (check_reparse_multi_pw_aff_tests(ctx
) < 0)
273 if (check_parse_multi_pw_aff_fail_tests(ctx
) < 0)
279 /* String descriptions of multi union piecewise affine expressions
280 * that are used for testing printing and parsing.
282 static const char *reparse_multi_union_pw_aff_tests
[] = {
286 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
288 "[N] -> (A[] : { })",
289 "[N] -> (A[] : { : N >= 0 })",
290 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
291 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
292 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
293 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
294 "{ S[x] : x > 0; T[y] : y >= 0 })",
298 #define BASE multi_union_pw_aff
300 #include "check_reparse_templ.c"
301 #include "check_reparse_test_templ.c"
303 /* Test parsing of multi union piecewise affine expressions by printing
304 * the expressions and checking that parsing the output results
305 * in the same expression.
306 * Do this for a couple of manually constructed expressions and
307 * a set of expressions parsed from strings.
309 static int test_parse_mupa(isl_ctx
*ctx
)
312 isl_multi_union_pw_aff
*mupa
;
317 space
= isl_space_set_alloc(ctx
, 0, 0);
318 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
319 mupa
= isl_multi_union_pw_aff_zero(space
);
320 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
324 space
= isl_space_set_alloc(ctx
, 1, 0);
325 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
326 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
327 dom
= isl_set_universe(space
);
328 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
329 uset
= isl_union_set_from_set(dom
);
330 space
= isl_space_set_alloc(ctx
, 1, 0);
331 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
332 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
333 mupa
= isl_multi_union_pw_aff_zero(space
);
334 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
335 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
339 if (check_reparse_multi_union_pw_aff_tests(ctx
) < 0)
345 /* Test parsing of multi expressions.
347 static int test_parse_multi(isl_ctx
*ctx
)
349 if (test_parse_mpa(ctx
) < 0)
351 if (test_parse_mupa(ctx
) < 0)
357 /* Pairs of binary relation representations that should represent
358 * the same binary relations.
363 } parse_map_equal_tests
[] = {
364 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
365 "{ [x, y] : 2y >= 6 - x }" },
366 { "{ [x,y] : x <= min(y, 2*y+3) }",
367 "{ [x,y] : x <= y, 2*y + 3 }" },
368 { "{ [x,y] : x >= min(y, 2*y+3) }",
369 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
370 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
371 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
372 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
373 "{ [i,j] -> [min(i,j)] }" },
374 { "{ [i,j] : i != j }",
375 "{ [i,j] : i < j or i > j }" },
376 { "{ [i,j] : (i+1)*2 >= j }",
377 "{ [i, j] : j <= 2 + 2i }" },
378 { "{ [i] -> [i > 0 ? 4 : 5] }",
379 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
380 { "[N=2,M] -> { [i=[(M+N)/4]] }",
381 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
382 { "{ [x] : x >= 0 }",
383 "{ [x] : x-0 >= 0 }" },
384 { "{ [i] : ((i > 10)) }",
385 "{ [i] : i >= 11 }" },
387 "{ [i] -> [0 * i] }" },
388 { "{ [a] -> [b] : (not false) }",
389 "{ [a] -> [b] : true }" },
390 { "{ [i] : i/2 <= 5 }",
391 "{ [i] : i <= 10 }" },
392 { "{Sym=[n] [i] : i <= n }",
393 "[n] -> { [i] : i <= n }" },
396 { "{ [i] : 2*floor(i/2) = i }",
397 "{ [i] : exists a : i = 2 a }" },
398 { "{ [a] -> [b] : a = 5 implies b = 5 }",
399 "{ [a] -> [b] : a != 5 or b = 5 }" },
400 { "{ [a] -> [a - 1 : a > 0] }",
401 "{ [a] -> [a - 1] : a > 0 }" },
402 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
403 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : 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] -> [(a * 2 : a >= 0); 0 : a < 0] }",
409 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
410 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
411 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
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 { "{ [a,b] -> [i,j] : a,b >> i,j }",
417 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
418 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
419 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
420 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
421 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
422 "8c < n - 32a and i < n and c >= 0 and "
423 "c <= 3 and c >= -4a) }",
424 "{ [n] -> [i] : 0 <= i < n }" },
425 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
426 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
427 "{ [x] -> [] : 0 <= x <= 15 }" },
428 { "{ [x] -> [x] : }",
430 { "{ [x=4:5] -> [x + 1] }",
431 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
432 { "{ [x=4:5] -> [x + 1 : x + 1] }",
433 "{ [x=4:5] -> [x + 1] }" },
434 { "{ [x] -> [x - 1 : x + 1] }",
435 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
436 { "{ [x=4:] -> [x + 1] }",
437 "{ [x] -> [x + 1] : 4 <= x }" },
438 { "{ [x=:5] -> [x + 1] }",
439 "{ [x] -> [x + 1] : x <= 5 }" },
440 { "{ [x=:] -> [x + 1] }",
441 "{ [x] -> [x + 1] }" },
445 "{ [x, floor(x/4)] }" },
460 { "{ [-2^2:2^2-1] }",
466 { "[a, b, c, d] -> { [max(a,b,c,d)] }",
467 "[a, b, c, d] -> { [a] : b < a and c < a and d < a; "
468 "[b] : b >= a and c < b and d < b; "
469 "[c] : c >= a and c >= b and d < c; "
470 "[d] : d >= a and d >= b and d >= c }" },
471 { "[a, b, c, d] -> { [min(a,b,c,d)] }",
472 "[a, b, c, d] -> { [a] : b >= a and c >= a and d >= a; "
473 "[b] : b < a and c >= b and d >= b; "
474 "[c] : c < b and c < a and d >= c; "
475 "[d] : d < c and d < b and d < a }" },
478 int test_parse(struct isl_ctx
*ctx
)
482 const char *str
, *str2
;
484 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
486 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
488 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
490 if (test_parse_multi(ctx
) < 0)
492 if (test_parse_pma(ctx
) < 0)
494 if (test_parse_upma(ctx
) < 0)
497 str
= "{ [i] -> [-i] }";
498 map
= isl_map_read_from_str(ctx
, str
);
502 str
= "{ A[i] -> L[([i/3])] }";
503 map
= isl_map_read_from_str(ctx
, str
);
507 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
508 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
509 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
511 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
512 str
= parse_map_equal_tests
[i
].map1
;
513 str2
= parse_map_equal_tests
[i
].map2
;
514 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
518 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
519 map
= isl_map_read_from_str(ctx
, str
);
520 str
= "{ [new, old] -> [o0, o1] : "
521 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
522 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
523 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
524 map2
= isl_map_read_from_str(ctx
, str
);
525 assert(isl_map_is_equal(map
, map2
));
529 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
530 map
= isl_map_read_from_str(ctx
, str
);
531 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
532 map2
= isl_map_read_from_str(ctx
, str
);
533 assert(isl_map_is_equal(map
, map2
));
537 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
538 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
539 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
540 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
541 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
546 static int test_read(isl_ctx
*ctx
)
550 isl_basic_set
*bset1
, *bset2
;
551 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
554 filename
= get_filename(ctx
, "set", "omega");
556 input
= fopen(filename
, "r");
559 bset1
= isl_basic_set_read_from_file(ctx
, input
);
560 bset2
= isl_basic_set_read_from_str(ctx
, str
);
562 equal
= isl_basic_set_is_equal(bset1
, bset2
);
564 isl_basic_set_free(bset1
);
565 isl_basic_set_free(bset2
);
573 isl_die(ctx
, isl_error_unknown
,
574 "read sets not equal", return -1);
579 static int test_bounded(isl_ctx
*ctx
)
584 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
585 bounded
= isl_set_is_bounded(set
);
591 isl_die(ctx
, isl_error_unknown
,
592 "set not considered bounded", return -1);
594 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
595 bounded
= isl_set_is_bounded(set
);
602 isl_die(ctx
, isl_error_unknown
,
603 "set considered bounded", return -1);
605 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
606 bounded
= isl_set_is_bounded(set
);
612 isl_die(ctx
, isl_error_unknown
,
613 "set considered bounded", return -1);
618 /* Construct the basic set { [i] : 5 <= i <= N } */
619 static int test_construction_1(isl_ctx
*ctx
)
626 space
= isl_space_set_alloc(ctx
, 1, 1);
627 bset
= isl_basic_set_universe(isl_space_copy(space
));
628 ls
= isl_local_space_from_space(space
);
630 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
631 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
632 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
633 bset
= isl_basic_set_add_constraint(bset
, c
);
635 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
636 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
637 c
= isl_constraint_set_constant_si(c
, -5);
638 bset
= isl_basic_set_add_constraint(bset
, c
);
640 isl_local_space_free(ls
);
641 isl_basic_set_free(bset
);
646 /* Construct the basic set { [x] : -100 <= x <= 100 }
647 * using isl_basic_set_{lower,upper}_bound_val and
648 * check that it is equal the same basic set parsed from a string.
650 static int test_construction_2(isl_ctx
*ctx
)
655 isl_basic_set
*bset1
, *bset2
;
657 v
= isl_val_int_from_si(ctx
, 100);
658 space
= isl_space_set_alloc(ctx
, 0, 1);
659 bset1
= isl_basic_set_universe(space
);
660 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
662 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
664 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
665 equal
= isl_basic_set_is_equal(bset1
, bset2
);
666 isl_basic_set_free(bset1
);
667 isl_basic_set_free(bset2
);
672 isl_die(ctx
, isl_error_unknown
,
673 "failed construction", return -1);
678 /* Basic tests for constructing basic sets.
680 static int test_construction(isl_ctx
*ctx
)
682 if (test_construction_1(ctx
) < 0)
684 if (test_construction_2(ctx
) < 0)
689 static int test_dim(isl_ctx
*ctx
)
692 isl_map
*map1
, *map2
;
695 map1
= isl_map_read_from_str(ctx
,
696 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
697 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
698 map2
= isl_map_read_from_str(ctx
,
699 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
700 equal
= isl_map_is_equal(map1
, map2
);
703 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
704 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
705 if (equal
>= 0 && equal
)
706 equal
= isl_map_is_equal(map1
, map2
);
714 isl_die(ctx
, isl_error_unknown
,
715 "unexpected result", return -1);
717 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
718 map1
= isl_map_read_from_str(ctx
, str
);
719 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
720 map2
= isl_map_read_from_str(ctx
, str
);
721 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
722 equal
= isl_map_is_equal(map1
, map2
);
729 isl_die(ctx
, isl_error_unknown
,
730 "unexpected result", return -1);
736 #define BASE multi_val
737 #include "isl_test_plain_equal_templ.c"
740 #define BASE multi_aff
741 #include "isl_test_plain_equal_templ.c"
743 /* Check that "val" is equal to the value described by "str".
744 * If "str" is "NaN", then check for a NaN value explicitly.
746 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
753 return isl_stat_error
;
755 ctx
= isl_val_get_ctx(val
);
756 res
= isl_val_read_from_str(ctx
, str
);
757 is_nan
= isl_val_is_nan(res
);
761 ok
= isl_val_is_nan(val
);
763 ok
= isl_val_eq(val
, res
);
766 return isl_stat_error
;
768 isl_die(ctx
, isl_error_unknown
,
769 "unexpected result", return isl_stat_error
);
774 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
778 { &isl_val_neg
, "0", "0" },
779 { &isl_val_abs
, "0", "0" },
780 { &isl_val_pow2
, "0", "1" },
781 { &isl_val_floor
, "0", "0" },
782 { &isl_val_ceil
, "0", "0" },
783 { &isl_val_neg
, "1", "-1" },
784 { &isl_val_neg
, "-1", "1" },
785 { &isl_val_neg
, "1/2", "-1/2" },
786 { &isl_val_neg
, "-1/2", "1/2" },
787 { &isl_val_neg
, "infty", "-infty" },
788 { &isl_val_neg
, "-infty", "infty" },
789 { &isl_val_neg
, "NaN", "NaN" },
790 { &isl_val_abs
, "1", "1" },
791 { &isl_val_abs
, "-1", "1" },
792 { &isl_val_abs
, "1/2", "1/2" },
793 { &isl_val_abs
, "-1/2", "1/2" },
794 { &isl_val_abs
, "infty", "infty" },
795 { &isl_val_abs
, "-infty", "infty" },
796 { &isl_val_abs
, "NaN", "NaN" },
797 { &isl_val_floor
, "1", "1" },
798 { &isl_val_floor
, "-1", "-1" },
799 { &isl_val_floor
, "1/2", "0" },
800 { &isl_val_floor
, "-1/2", "-1" },
801 { &isl_val_floor
, "infty", "infty" },
802 { &isl_val_floor
, "-infty", "-infty" },
803 { &isl_val_floor
, "NaN", "NaN" },
804 { &isl_val_ceil
, "1", "1" },
805 { &isl_val_ceil
, "-1", "-1" },
806 { &isl_val_ceil
, "1/2", "1" },
807 { &isl_val_ceil
, "-1/2", "0" },
808 { &isl_val_ceil
, "infty", "infty" },
809 { &isl_val_ceil
, "-infty", "-infty" },
810 { &isl_val_ceil
, "NaN", "NaN" },
811 { &isl_val_pow2
, "-3", "1/8" },
812 { &isl_val_pow2
, "-1", "1/2" },
813 { &isl_val_pow2
, "1", "2" },
814 { &isl_val_pow2
, "2", "4" },
815 { &isl_val_pow2
, "3", "8" },
816 { &isl_val_inv
, "1", "1" },
817 { &isl_val_inv
, "2", "1/2" },
818 { &isl_val_inv
, "1/2", "2" },
819 { &isl_val_inv
, "-2", "-1/2" },
820 { &isl_val_inv
, "-1/2", "-2" },
821 { &isl_val_inv
, "0", "NaN" },
822 { &isl_val_inv
, "NaN", "NaN" },
823 { &isl_val_inv
, "infty", "0" },
824 { &isl_val_inv
, "-infty", "0" },
827 /* Perform some basic tests of unary operations on isl_val objects.
829 static int test_un_val(isl_ctx
*ctx
)
833 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
835 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
838 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
839 fn
= val_un_tests
[i
].op
;
841 r
= val_check_equal(v
, val_un_tests
[i
].res
);
851 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
852 __isl_take isl_val
*v2
);
854 ['+'] = { &isl_val_add
},
855 ['-'] = { &isl_val_sub
},
856 ['*'] = { &isl_val_mul
},
857 ['/'] = { &isl_val_div
},
858 ['g'] = { &isl_val_gcd
},
859 ['m'] = { &isl_val_min
},
860 ['M'] = { &isl_val_max
},
868 } val_bin_tests
[] = {
869 { "0", '+', "0", "0" },
870 { "1", '+', "0", "1" },
871 { "1", '+', "1", "2" },
872 { "1", '-', "1", "0" },
873 { "1", '*', "1", "1" },
874 { "1", '/', "1", "1" },
875 { "2", '*', "3", "6" },
876 { "2", '*', "1/2", "1" },
877 { "2", '*', "1/3", "2/3" },
878 { "2/3", '*', "3/5", "2/5" },
879 { "2/3", '*', "7/5", "14/15" },
880 { "2", '/', "1/2", "4" },
881 { "-2", '/', "-1/2", "4" },
882 { "-2", '/', "1/2", "-4" },
883 { "2", '/', "-1/2", "-4" },
884 { "2", '/', "2", "1" },
885 { "2", '/', "3", "2/3" },
886 { "2/3", '/', "5/3", "2/5" },
887 { "2/3", '/', "5/7", "14/15" },
888 { "0", '/', "0", "NaN" },
889 { "42", '/', "0", "NaN" },
890 { "-42", '/', "0", "NaN" },
891 { "infty", '/', "0", "NaN" },
892 { "-infty", '/', "0", "NaN" },
893 { "NaN", '/', "0", "NaN" },
894 { "0", '/', "NaN", "NaN" },
895 { "42", '/', "NaN", "NaN" },
896 { "-42", '/', "NaN", "NaN" },
897 { "infty", '/', "NaN", "NaN" },
898 { "-infty", '/', "NaN", "NaN" },
899 { "NaN", '/', "NaN", "NaN" },
900 { "0", '/', "infty", "0" },
901 { "42", '/', "infty", "0" },
902 { "-42", '/', "infty", "0" },
903 { "infty", '/', "infty", "NaN" },
904 { "-infty", '/', "infty", "NaN" },
905 { "NaN", '/', "infty", "NaN" },
906 { "0", '/', "-infty", "0" },
907 { "42", '/', "-infty", "0" },
908 { "-42", '/', "-infty", "0" },
909 { "infty", '/', "-infty", "NaN" },
910 { "-infty", '/', "-infty", "NaN" },
911 { "NaN", '/', "-infty", "NaN" },
912 { "1", '-', "1/3", "2/3" },
913 { "1/3", '+', "1/2", "5/6" },
914 { "1/2", '+', "1/2", "1" },
915 { "3/4", '-', "1/4", "1/2" },
916 { "1/2", '-', "1/3", "1/6" },
917 { "infty", '+', "42", "infty" },
918 { "infty", '+', "infty", "infty" },
919 { "42", '+', "infty", "infty" },
920 { "infty", '-', "infty", "NaN" },
921 { "infty", '*', "infty", "infty" },
922 { "infty", '*', "-infty", "-infty" },
923 { "-infty", '*', "infty", "-infty" },
924 { "-infty", '*', "-infty", "infty" },
925 { "0", '*', "infty", "NaN" },
926 { "1", '*', "infty", "infty" },
927 { "infty", '*', "0", "NaN" },
928 { "infty", '*', "42", "infty" },
929 { "42", '-', "infty", "-infty" },
930 { "infty", '+', "-infty", "NaN" },
931 { "4", 'g', "6", "2" },
932 { "5", 'g', "6", "1" },
933 { "42", 'm', "3", "3" },
934 { "42", 'M', "3", "42" },
935 { "3", 'm', "42", "3" },
936 { "3", 'M', "42", "42" },
937 { "42", 'm', "infty", "42" },
938 { "42", 'M', "infty", "infty" },
939 { "42", 'm', "-infty", "-infty" },
940 { "42", 'M', "-infty", "42" },
941 { "42", 'm', "NaN", "NaN" },
942 { "42", 'M', "NaN", "NaN" },
943 { "infty", 'm', "-infty", "-infty" },
944 { "infty", 'M', "-infty", "infty" },
947 /* Perform some basic tests of binary operations on isl_val objects.
949 static int test_bin_val(isl_ctx
*ctx
)
952 isl_val
*v1
, *v2
, *res
;
953 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
954 __isl_take isl_val
*v2
);
957 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
958 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
959 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
960 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
961 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
963 if (isl_val_is_nan(res
))
964 ok
= isl_val_is_nan(v1
);
966 ok
= isl_val_eq(v1
, res
);
972 isl_die(ctx
, isl_error_unknown
,
973 "unexpected result", return -1);
979 /* Perform some basic tests on isl_val objects.
981 static int test_val(isl_ctx
*ctx
)
983 if (test_un_val(ctx
) < 0)
985 if (test_bin_val(ctx
) < 0)
990 /* Sets described using existentially quantified variables that
991 * can also be described without.
993 static const char *elimination_tests
[] = {
994 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
995 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
996 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
999 /* Check that redundant existentially quantified variables are
1002 static int test_elimination(isl_ctx
*ctx
)
1006 isl_basic_set
*bset
;
1008 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
1009 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
1010 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1011 isl_basic_set_free(bset
);
1015 isl_die(ctx
, isl_error_unknown
,
1016 "expecting no existentials", return -1);
1022 static int test_div(isl_ctx
*ctx
)
1028 isl_local_space
*ls
;
1029 struct isl_basic_set
*bset
;
1030 struct isl_constraint
*c
;
1033 space
= isl_space_set_alloc(ctx
, 0, 3);
1034 bset
= isl_basic_set_universe(isl_space_copy(space
));
1035 ls
= isl_local_space_from_space(space
);
1037 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1038 c
= isl_constraint_set_constant_si(c
, -1);
1039 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1040 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1041 bset
= isl_basic_set_add_constraint(bset
, c
);
1043 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1044 c
= isl_constraint_set_constant_si(c
, 1);
1045 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1046 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1047 bset
= isl_basic_set_add_constraint(bset
, c
);
1049 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1051 assert(bset
&& bset
->n_div
== 1);
1052 isl_local_space_free(ls
);
1053 isl_basic_set_free(bset
);
1056 space
= isl_space_set_alloc(ctx
, 0, 3);
1057 bset
= isl_basic_set_universe(isl_space_copy(space
));
1058 ls
= isl_local_space_from_space(space
);
1060 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1061 c
= isl_constraint_set_constant_si(c
, 1);
1062 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1063 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1064 bset
= isl_basic_set_add_constraint(bset
, c
);
1066 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1067 c
= isl_constraint_set_constant_si(c
, -1);
1068 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1069 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1070 bset
= isl_basic_set_add_constraint(bset
, c
);
1072 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1074 assert(bset
&& bset
->n_div
== 1);
1075 isl_local_space_free(ls
);
1076 isl_basic_set_free(bset
);
1079 space
= isl_space_set_alloc(ctx
, 0, 3);
1080 bset
= isl_basic_set_universe(isl_space_copy(space
));
1081 ls
= isl_local_space_from_space(space
);
1083 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1084 c
= isl_constraint_set_constant_si(c
, 1);
1085 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1086 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1087 bset
= isl_basic_set_add_constraint(bset
, c
);
1089 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1090 c
= isl_constraint_set_constant_si(c
, -3);
1091 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1092 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
1093 bset
= isl_basic_set_add_constraint(bset
, c
);
1095 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1097 assert(bset
&& bset
->n_div
== 1);
1098 isl_local_space_free(ls
);
1099 isl_basic_set_free(bset
);
1102 space
= isl_space_set_alloc(ctx
, 0, 3);
1103 bset
= isl_basic_set_universe(isl_space_copy(space
));
1104 ls
= isl_local_space_from_space(space
);
1106 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1107 c
= isl_constraint_set_constant_si(c
, 2);
1108 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1109 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1110 bset
= isl_basic_set_add_constraint(bset
, c
);
1112 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1113 c
= isl_constraint_set_constant_si(c
, -1);
1114 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1115 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1116 bset
= isl_basic_set_add_constraint(bset
, c
);
1118 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1120 assert(isl_basic_set_is_empty(bset
));
1121 isl_local_space_free(ls
);
1122 isl_basic_set_free(bset
);
1125 space
= isl_space_set_alloc(ctx
, 0, 3);
1126 bset
= isl_basic_set_universe(isl_space_copy(space
));
1127 ls
= isl_local_space_from_space(space
);
1129 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1130 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1131 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1132 bset
= isl_basic_set_add_constraint(bset
, c
);
1134 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1135 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1136 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1137 bset
= isl_basic_set_add_constraint(bset
, c
);
1139 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1141 assert(bset
&& bset
->n_div
== 0);
1142 isl_basic_set_free(bset
);
1143 isl_local_space_free(ls
);
1146 space
= isl_space_set_alloc(ctx
, 0, 3);
1147 bset
= isl_basic_set_universe(isl_space_copy(space
));
1148 ls
= isl_local_space_from_space(space
);
1150 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1151 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1152 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1153 bset
= isl_basic_set_add_constraint(bset
, c
);
1155 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1156 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1157 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1158 bset
= isl_basic_set_add_constraint(bset
, c
);
1160 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1162 assert(bset
&& bset
->n_div
== 1);
1163 isl_basic_set_free(bset
);
1164 isl_local_space_free(ls
);
1167 /* This test is a bit tricky. We set up an equality
1168 * a + 3b + 3c = 6 e0
1169 * Normalization of divs creates _two_ divs
1172 * Afterwards e0 is removed again because it has coefficient -1
1173 * and we end up with the original equality and div again.
1174 * Perhaps we can avoid the introduction of this temporary div.
1176 space
= isl_space_set_alloc(ctx
, 0, 4);
1177 bset
= isl_basic_set_universe(isl_space_copy(space
));
1178 ls
= isl_local_space_from_space(space
);
1180 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1181 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1182 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1183 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1184 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1185 bset
= isl_basic_set_add_constraint(bset
, c
);
1187 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1189 /* Test disabled for now */
1191 assert(bset && bset->n_div == 1);
1193 isl_local_space_free(ls
);
1194 isl_basic_set_free(bset
);
1197 space
= isl_space_set_alloc(ctx
, 0, 5);
1198 bset
= isl_basic_set_universe(isl_space_copy(space
));
1199 ls
= isl_local_space_from_space(space
);
1201 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1202 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1203 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1204 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1205 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1206 bset
= isl_basic_set_add_constraint(bset
, c
);
1208 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1209 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1210 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1211 c
= isl_constraint_set_constant_si(c
, 1);
1212 bset
= isl_basic_set_add_constraint(bset
, c
);
1214 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1216 /* Test disabled for now */
1218 assert(bset && bset->n_div == 1);
1220 isl_local_space_free(ls
);
1221 isl_basic_set_free(bset
);
1224 space
= isl_space_set_alloc(ctx
, 0, 4);
1225 bset
= isl_basic_set_universe(isl_space_copy(space
));
1226 ls
= isl_local_space_from_space(space
);
1228 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1229 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1230 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1231 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1232 bset
= isl_basic_set_add_constraint(bset
, c
);
1234 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1235 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1236 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1237 c
= isl_constraint_set_constant_si(c
, 2);
1238 bset
= isl_basic_set_add_constraint(bset
, c
);
1240 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1242 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1244 assert(!isl_basic_set_is_empty(bset
));
1246 isl_local_space_free(ls
);
1247 isl_basic_set_free(bset
);
1250 space
= isl_space_set_alloc(ctx
, 0, 3);
1251 bset
= isl_basic_set_universe(isl_space_copy(space
));
1252 ls
= isl_local_space_from_space(space
);
1254 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1255 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1256 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1257 bset
= isl_basic_set_add_constraint(bset
, c
);
1259 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1261 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1263 isl_local_space_free(ls
);
1264 isl_basic_set_free(bset
);
1266 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1267 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1268 set
= isl_set_read_from_str(ctx
, str
);
1269 set
= isl_set_compute_divs(set
);
1274 if (test_elimination(ctx
) < 0)
1277 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1278 set
= isl_set_read_from_str(ctx
, str
);
1279 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1280 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1281 empty
= isl_set_is_empty(set
);
1286 isl_die(ctx
, isl_error_unknown
,
1287 "result not as accurate as expected", return -1);
1292 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1296 struct isl_basic_set
*bset1
, *bset2
;
1297 struct isl_basic_map
*bmap
;
1299 filename
= get_filename(ctx
, name
, "omega");
1301 input
= fopen(filename
, "r");
1304 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1305 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1307 bset1
= isl_basic_set_apply(bset1
, bmap
);
1309 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1311 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1313 isl_basic_set_free(bset1
);
1314 isl_basic_set_free(bset2
);
1320 static int test_application(isl_ctx
*ctx
)
1322 test_application_case(ctx
, "application");
1323 test_application_case(ctx
, "application2");
1328 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1332 struct isl_basic_set
*bset1
, *bset2
;
1334 filename
= get_filename(ctx
, name
, "polylib");
1336 input
= fopen(filename
, "r");
1339 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1340 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1342 bset1
= isl_basic_set_affine_hull(bset1
);
1344 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1346 isl_basic_set_free(bset1
);
1347 isl_basic_set_free(bset2
);
1353 /* Pairs of sets and the corresponding expected results of
1354 * isl_basic_set_recession_cone.
1359 } recession_cone_tests
[] = {
1360 { "{ [i] : 0 <= i <= 10 }", "{ [0] }" },
1361 { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" },
1362 { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" },
1363 { "{ [i] : false }", "{ [i] : false }" },
1366 /* Perform some basic isl_basic_set_recession_cone tests.
1368 static int test_recession_cone(struct isl_ctx
*ctx
)
1372 for (i
= 0; i
< ARRAY_SIZE(recession_cone_tests
); ++i
) {
1374 isl_basic_set
*bset
;
1375 isl_basic_set
*cone
, *expected
;
1378 str
= recession_cone_tests
[i
].set
;
1379 bset
= isl_basic_set_read_from_str(ctx
, str
);
1380 str
= recession_cone_tests
[i
].cone
;
1381 expected
= isl_basic_set_read_from_str(ctx
, str
);
1382 cone
= isl_basic_set_recession_cone(bset
);
1383 equal
= isl_basic_set_is_equal(cone
, expected
);
1384 isl_basic_set_free(cone
);
1385 isl_basic_set_free(expected
);
1389 isl_die(ctx
, isl_error_unknown
, "unexpected cone",
1396 int test_affine_hull(struct isl_ctx
*ctx
)
1400 isl_basic_set
*bset
, *bset2
;
1404 test_affine_hull_case(ctx
, "affine2");
1405 test_affine_hull_case(ctx
, "affine");
1406 test_affine_hull_case(ctx
, "affine3");
1408 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1409 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1410 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1411 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1412 set
= isl_set_read_from_str(ctx
, str
);
1413 bset
= isl_set_affine_hull(set
);
1414 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1415 isl_basic_set_free(bset
);
1419 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1422 /* Check that isl_map_affine_hull is not confused by
1423 * the reordering of divs in isl_map_align_divs.
1425 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1426 "32e0 = b and 32e1 = c); "
1427 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1428 set
= isl_set_read_from_str(ctx
, str
);
1429 bset
= isl_set_affine_hull(set
);
1430 isl_basic_set_free(bset
);
1434 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1435 "32e2 = 31 + 31e0 }";
1436 set
= isl_set_read_from_str(ctx
, str
);
1437 bset
= isl_set_affine_hull(set
);
1438 str
= "{ [a] : exists e : a = 32 e }";
1439 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1440 subset
= isl_basic_set_is_subset(bset
, bset2
);
1441 isl_basic_set_free(bset
);
1442 isl_basic_set_free(bset2
);
1446 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1452 /* Test a special case of isl_set_plain_unshifted_simple_hull
1453 * where older versions of isl would include a redundant constraint
1455 * Check that the result does not have any constraints.
1457 static isl_stat
test_plain_unshifted_simple_hull_special(isl_ctx
*ctx
)
1460 isl_bool is_universe
;
1462 isl_basic_set
*bset
;
1464 str
= "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
1465 set
= isl_set_read_from_str(ctx
, str
);
1466 bset
= isl_set_plain_unshifted_simple_hull(set
);
1467 is_universe
= isl_basic_set_plain_is_universe(bset
);
1468 isl_basic_set_free(bset
);
1470 if (is_universe
< 0)
1471 return isl_stat_error
;
1473 isl_die(ctx
, isl_error_unknown
,
1474 "hull should not have any constraints",
1475 return isl_stat_error
);
1480 /* Inputs for simple hull tests, consisting of
1481 * the specific simple hull function, the input set and the expected result.
1484 __isl_give isl_basic_set
*(*fn
)(__isl_take isl_set
*set
);
1487 } simple_hull_tests
[] = {
1488 { &isl_set_plain_unshifted_simple_hull
,
1489 "{ [i,j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1490 "{ [i,j] : i >= 1 }" },
1491 { &isl_set_plain_unshifted_simple_hull
,
1492 "{ [n,i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1493 "(j mod 4 = 2 and k mod 6 = n) }",
1494 "{ [n,i,j,k] : j mod 4 = 2 }" },
1495 { &isl_set_unshifted_simple_hull
,
1496 "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1497 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1498 { &isl_set_simple_hull
,
1499 "{ [a, b] : b <= 0 and "
1500 "2*floor((-2*floor((b)/2))/5) >= a - floor((b)/2); "
1501 "[a, b] : a mod 2 = 0 }",
1505 /* Basic tests for various simple hull functions.
1507 static int test_various_simple_hull(isl_ctx
*ctx
)
1511 isl_basic_set
*hull
, *expected
;
1514 for (i
= 0; i
< ARRAY_SIZE(simple_hull_tests
); ++i
) {
1516 str
= simple_hull_tests
[i
].set
;
1517 set
= isl_set_read_from_str(ctx
, str
);
1518 str
= simple_hull_tests
[i
].hull
;
1519 expected
= isl_basic_set_read_from_str(ctx
, str
);
1520 hull
= simple_hull_tests
[i
].fn(set
);
1521 equal
= isl_basic_set_is_equal(hull
, expected
);
1522 isl_basic_set_free(hull
);
1523 isl_basic_set_free(expected
);
1527 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1534 static int test_simple_hull(struct isl_ctx
*ctx
)
1538 isl_basic_set
*bset
;
1541 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1542 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1543 set
= isl_set_read_from_str(ctx
, str
);
1544 bset
= isl_set_simple_hull(set
);
1545 is_empty
= isl_basic_set_is_empty(bset
);
1546 isl_basic_set_free(bset
);
1548 if (is_empty
== isl_bool_error
)
1551 if (is_empty
== isl_bool_false
)
1552 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1555 if (test_plain_unshifted_simple_hull_special(ctx
) < 0)
1557 if (test_various_simple_hull(ctx
) < 0)
1563 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1564 * "set" is the input set.
1565 * "offset" is the expected box offset.
1566 * "size" is the expected box size.
1572 } box_hull_tests
[] = {
1573 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1574 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1575 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1576 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1577 "{ S[0, -4] }", "{ S[10, 9] }" },
1578 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1579 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1580 "{ [3] }", "{ [8] }" },
1581 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1582 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1583 "[N] -> { [N] }", "{ [9] }" },
1586 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1588 static int test_box_hull(struct isl_ctx
*ctx
)
1592 for (i
= 0; i
< ARRAY_SIZE(box_hull_tests
); ++i
) {
1596 isl_multi_aff
*offset
;
1597 isl_multi_val
*size
;
1600 set
= isl_set_read_from_str(ctx
, box_hull_tests
[i
].set
);
1601 box
= isl_set_get_simple_fixed_box_hull(set
);
1602 offset
= isl_fixed_box_get_offset(box
);
1603 size
= isl_fixed_box_get_size(box
);
1604 str
= box_hull_tests
[i
].offset
;
1605 r
= multi_aff_check_plain_equal(offset
, str
);
1606 str
= box_hull_tests
[i
].size
;
1608 r
= multi_val_check_plain_equal(size
, str
);
1609 isl_multi_aff_free(offset
);
1610 isl_multi_val_free(size
);
1611 isl_fixed_box_free(box
);
1620 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1624 struct isl_basic_set
*bset1
, *bset2
;
1625 struct isl_set
*set
;
1627 filename
= get_filename(ctx
, name
, "polylib");
1629 input
= fopen(filename
, "r");
1632 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1633 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1635 set
= isl_basic_set_union(bset1
, bset2
);
1636 bset1
= isl_set_convex_hull(set
);
1638 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1640 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1642 isl_basic_set_free(bset1
);
1643 isl_basic_set_free(bset2
);
1652 } convex_hull_tests
[] = {
1653 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1654 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1655 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1656 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1657 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1658 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1659 "i2 <= 5 and i2 >= 4; "
1660 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1661 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1662 "i2 <= 5 + i0 and i2 >= i0 }" },
1663 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1664 "{ [x, y] : 1 = 0 }" },
1665 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1666 "[x, y, 0] : x >= 0 and y < 0 }",
1667 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1668 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1670 "[0, 2, 0]; [3, 1, 0] }",
1671 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1672 "5c <= 6 - a - 3b }" },
1675 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1678 int orig_convex
= ctx
->opt
->convex
;
1679 ctx
->opt
->convex
= convex
;
1681 test_convex_hull_case(ctx
, "convex0");
1682 test_convex_hull_case(ctx
, "convex1");
1683 test_convex_hull_case(ctx
, "convex2");
1684 test_convex_hull_case(ctx
, "convex3");
1685 test_convex_hull_case(ctx
, "convex4");
1686 test_convex_hull_case(ctx
, "convex5");
1687 test_convex_hull_case(ctx
, "convex6");
1688 test_convex_hull_case(ctx
, "convex7");
1689 test_convex_hull_case(ctx
, "convex8");
1690 test_convex_hull_case(ctx
, "convex9");
1691 test_convex_hull_case(ctx
, "convex10");
1692 test_convex_hull_case(ctx
, "convex11");
1693 test_convex_hull_case(ctx
, "convex12");
1694 test_convex_hull_case(ctx
, "convex13");
1695 test_convex_hull_case(ctx
, "convex14");
1696 test_convex_hull_case(ctx
, "convex15");
1698 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1699 isl_set
*set1
, *set2
;
1702 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1703 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1704 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1705 equal
= isl_set_is_equal(set1
, set2
);
1712 isl_die(ctx
, isl_error_unknown
,
1713 "unexpected convex hull", return -1);
1716 ctx
->opt
->convex
= orig_convex
;
1721 static int test_convex_hull(isl_ctx
*ctx
)
1723 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1725 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1730 /* Check that computing the gist of "map" with respect to "context"
1731 * does not make any copy of "map" get marked empty.
1732 * Earlier versions of isl would end up doing that.
1734 static isl_stat
test_gist_empty_pair(isl_ctx
*ctx
, const char *map
,
1735 const char *context
)
1737 isl_map
*m1
, *m2
, *m3
;
1738 isl_bool empty_before
, empty_after
;
1740 m1
= isl_map_read_from_str(ctx
, map
);
1741 m2
= isl_map_read_from_str(ctx
, context
);
1742 m3
= isl_map_copy(m1
);
1743 empty_before
= isl_map_is_empty(m3
);
1744 m1
= isl_map_gist(m1
, m2
);
1745 empty_after
= isl_map_is_empty(m3
);
1749 if (empty_before
< 0 || empty_after
< 0)
1750 return isl_stat_error
;
1752 isl_die(ctx
, isl_error_unknown
, "map should not be empty",
1753 return isl_stat_error
);
1755 isl_die(ctx
, isl_error_unknown
, "map should still not be empty",
1756 return isl_stat_error
);
1761 /* Check that computing a gist does not make any copy of the input
1763 * Earlier versions of isl would end up doing that on some pairs of inputs.
1765 static isl_stat
test_gist_empty(isl_ctx
*ctx
)
1767 const char *map
, *context
;
1769 map
= "{ [] -> [a, b, c] : 2b = 1 + a }";
1770 context
= "{ [] -> [a, b, c] : 2c = 2 + a }";
1771 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1772 return isl_stat_error
;
1773 map
= "{ [] -> [0, 0] }";
1774 context
= "{ [] -> [a, b] : a > b }";
1775 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1776 return isl_stat_error
;
1781 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1785 const char *context
;
1787 } plain_gist_tests
[] = {
1788 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1789 "{ [i] -> [j] : i >= 1 }",
1790 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1791 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1792 "(j mod 4 = 2 and k mod 6 = n) }",
1793 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1794 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1795 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1796 "{ [i] -> [j] : i > j }",
1797 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1800 /* Basic tests for isl_map_plain_gist_basic_map.
1802 static int test_plain_gist(isl_ctx
*ctx
)
1806 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1809 isl_map
*map
, *gist
;
1810 isl_basic_map
*context
;
1812 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1813 str
= plain_gist_tests
[i
].context
;
1814 context
= isl_basic_map_read_from_str(ctx
, str
);
1815 map
= isl_map_plain_gist_basic_map(map
, context
);
1816 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1817 equal
= isl_map_is_equal(map
, gist
);
1823 isl_die(ctx
, isl_error_unknown
,
1824 "incorrect gist result", return -1);
1830 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1834 const char *context
;
1835 } gist_fail_tests
[] = {
1836 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1837 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1838 "{ [i] : i >= 0 }" },
1841 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1842 * In particular, the user should be able to recover from the failure.
1844 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1849 on_error
= isl_options_get_on_error(ctx
);
1850 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1851 n
= ARRAY_SIZE(gist_fail_tests
);
1852 for (i
= 0; i
< n
; ++i
) {
1854 isl_basic_set
*bset
, *context
;
1856 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1857 str
= gist_fail_tests
[i
].context
;
1858 context
= isl_basic_set_read_from_str(ctx
, str
);
1859 bset
= isl_basic_set_gist(bset
, context
);
1860 isl_basic_set_free(bset
);
1864 isl_options_set_on_error(ctx
, on_error
);
1866 isl_die(ctx
, isl_error_unknown
,
1867 "operation not expected to succeed",
1868 return isl_stat_error
);
1875 const char *context
;
1879 "{ [1, b, 2 - b] : -1 <= b <= 2 }",
1881 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1882 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1883 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1884 "{ [a, b, c] : a <= 15 }" },
1885 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1886 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1887 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1888 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1889 { "{ [m, n, a, b] : a <= 2147 + n }",
1890 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1891 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1892 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1894 "{ [m, n, ku, kl] }" },
1895 { "{ [a, a, b] : a >= 10 }",
1896 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1897 "{ [a, a, b] : a >= 10 }" },
1898 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1899 "{ [0, j] : j >= 0 }" },
1900 /* Check that no constraints on i6 are introduced in the gist */
1901 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1902 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1903 "5e0 <= 381 - t1 and i4 <= 1) }",
1904 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1905 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1906 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1907 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1908 "20e0 >= 1511 - 4t1 - 5i4) }" },
1909 /* Check that no constraints on i6 are introduced in the gist */
1910 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1911 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1912 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1913 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1914 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1915 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1916 "20e1 <= 1530 - 4t1 - 5i4 and "
1917 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1918 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1919 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1920 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1921 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1922 "10e0 <= -91 + 5i4 + 4i6 and "
1923 "10e0 >= -105 + 5i4 + 4i6) }",
1924 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1925 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1926 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1927 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1928 "{ [a, b, q, p] : b >= 1 + a }",
1929 "{ [a, b, q, p] : false }" },
1930 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1931 "[n] -> { [x] : x mod 32 = 0 }",
1932 "[n] -> { [x = n] }" },
1933 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1934 "{ [x] : x mod 2 = 0 }" },
1935 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1936 "{ [x] : x mod 128 = 0 }" },
1937 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1938 "{ [x] : x mod 3200 = 0 }" },
1939 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1940 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1941 "{ [a, b, c = a] }" },
1942 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1943 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1944 "{ [a, b, c = a] : a mod 3 = 0 }" },
1945 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1946 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1948 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1949 "{ [x,y] : 1 <= y <= 3 }",
1953 /* Check that isl_set_gist behaves as expected.
1955 * For the test cases in gist_tests, besides checking that the result
1956 * is as expected, also check that applying the gist operation does
1957 * not modify the input set (an earlier version of isl would do that) and
1958 * that the test case is consistent, i.e., that the gist has the same
1959 * intersection with the context as the input set.
1961 static int test_gist(struct isl_ctx
*ctx
)
1965 isl_basic_set
*bset1
, *bset2
;
1966 isl_map
*map1
, *map2
;
1970 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1971 isl_bool equal_input
, equal_intersection
;
1972 isl_set
*set1
, *set2
, *copy
, *context
;
1974 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1975 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1976 copy
= isl_set_copy(set1
);
1977 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1978 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1979 equal
= isl_set_is_equal(set1
, set2
);
1981 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1982 equal_input
= isl_set_is_equal(set1
, copy
);
1984 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1985 set2
= isl_set_intersect(set2
, context
);
1986 equal_intersection
= isl_set_is_equal(set1
, set2
);
1989 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1992 isl_die(ctx
, isl_error_unknown
,
1993 "incorrect gist result", return -1);
1995 isl_die(ctx
, isl_error_unknown
,
1996 "gist modified input", return -1);
1998 isl_die(ctx
, isl_error_unknown
,
1999 "inconsistent gist test case", return -1);
2002 if (test_gist_fail(ctx
) < 0)
2005 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
2006 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
2007 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
2008 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
2009 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
2010 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
2011 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
2012 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
2013 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
2014 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2015 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
2016 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
2017 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
2018 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
2019 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
2020 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
2021 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
2022 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
2023 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2024 bset1
= isl_basic_set_gist(bset1
, bset2
);
2025 assert(bset1
&& bset1
->n_div
== 0);
2026 isl_basic_set_free(bset1
);
2028 /* Check that the integer divisions of the second disjunct
2029 * do not spread to the first disjunct.
2031 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
2032 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
2033 "(exists (e0 = [(-1 + t1)/16], "
2034 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
2035 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
2036 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
2037 "o0 <= 4294967295 and t1 <= -1)) }";
2038 map1
= isl_map_read_from_str(ctx
, str
);
2039 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
2040 map2
= isl_map_read_from_str(ctx
, str
);
2041 map1
= isl_map_gist(map1
, map2
);
2045 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
2046 isl_map_free(map1
); return -1);
2047 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
2052 isl_die(ctx
, isl_error_unknown
, "expecting single div",
2055 if (test_gist_empty(ctx
) < 0)
2057 if (test_plain_gist(ctx
) < 0)
2063 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
2065 isl_set
*set
, *set2
;
2069 set
= isl_set_read_from_str(ctx
, str
);
2070 set
= isl_set_coalesce(set
);
2071 set2
= isl_set_read_from_str(ctx
, str
);
2072 equal
= isl_set_is_equal(set
, set2
);
2073 one
= set
&& set
->n
== 1;
2080 isl_die(ctx
, isl_error_unknown
,
2081 "coalesced set not equal to input", return -1);
2082 if (check_one
&& !one
)
2083 isl_die(ctx
, isl_error_unknown
,
2084 "coalesced set should not be a union", return -1);
2089 /* Inputs for coalescing tests with unbounded wrapping.
2090 * "str" is a string representation of the input set.
2091 * "single_disjunct" is set if we expect the result to consist of
2092 * a single disjunct.
2095 int single_disjunct
;
2097 } coalesce_unbounded_tests
[] = {
2098 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2099 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2100 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2101 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2103 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2104 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2105 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2106 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2107 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2108 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2109 { 1, "{ [0:1, 0:1]; [0, 2:3] }" },
2110 { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" },
2111 { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" },
2112 { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" },
2113 { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" },
2114 { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" },
2115 { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" },
2118 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2119 * option turned off.
2121 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
2127 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
2128 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
2130 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
2131 const char *str
= coalesce_unbounded_tests
[i
].str
;
2132 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
2133 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
2139 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
2144 /* Inputs for coalescing tests.
2145 * "str" is a string representation of the input set.
2146 * "single_disjunct" is set if we expect the result to consist of
2147 * a single disjunct.
2150 int single_disjunct
;
2152 } coalesce_tests
[] = {
2153 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2154 "y >= x & x >= 2 & 5 >= y }" },
2155 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2156 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2157 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2158 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2159 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2160 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2161 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2162 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2163 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2164 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2165 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2166 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2167 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2168 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2169 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2170 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2171 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2172 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2173 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2174 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2175 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2176 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2177 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2178 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2179 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2180 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2181 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2182 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2183 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2184 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2185 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2186 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2187 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2188 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2189 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2190 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2191 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2192 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2193 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2194 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2195 "[o0, o1, o2, o3, o4, o5, o6]] : "
2196 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2197 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2198 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2199 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2200 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2201 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2202 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2203 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2204 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2205 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2206 "o6 >= i3 + i6 - o3 and M >= 0 and "
2207 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2208 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2209 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2210 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2211 "(o0 = 0 and M >= 2 and N >= 3) or "
2212 "(M = 0 and o0 = 0 and N >= 3) }" },
2213 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2214 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2215 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2216 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2217 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2218 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2219 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2220 "(y = 3 and x = 1) }" },
2221 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2222 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2223 "i1 <= M and i3 <= M and i4 <= M) or "
2224 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2225 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2226 "i4 <= -1 + M) }" },
2227 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2228 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2229 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2230 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2231 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2232 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2233 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2234 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2235 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2236 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2237 { 0, "{ [a, b] : exists e : 2e = a and "
2238 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2239 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2240 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2241 "j >= 1 and j' <= i + j - i' and i >= 1; "
2243 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2244 "[i,j] : exists a : j = 3a }" },
2245 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2246 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2248 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2249 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2250 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2251 "c <= 6 + 8a and a >= 3; "
2252 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2253 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2254 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2255 "[x,0] : 3 <= x <= 4 }" },
2256 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2257 "[x,0] : 4 <= x <= 5 }" },
2258 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2259 "[x,0] : 3 <= x <= 5 }" },
2260 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2261 "[x,0] : 3 <= x <= 4 }" },
2262 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2264 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2265 { 1, "{ [0,0]; [1,1] }" },
2266 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2267 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2269 "[k, 0, k] : k <= 6 and k >= 1 }" },
2270 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2271 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2272 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2273 { 1, "[n] -> { [1] : n >= 0;"
2274 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2275 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2276 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2277 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2278 "2e0 <= x and 2e0 <= n);"
2279 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2281 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2282 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2283 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2285 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2286 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2288 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2289 "t1 >= 13 and t1 <= 16);"
2290 "[t1] : t1 <= 15 and t1 >= 12 }" },
2291 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2292 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2293 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2294 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2295 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2296 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2298 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2299 "(exists (e0 : 3e0 = -2 + c0)) }" },
2300 { 0, "[n, b0, t0] -> "
2301 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2302 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2303 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2304 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2305 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2306 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2307 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2308 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2309 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2310 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2311 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2312 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2313 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2314 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2315 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2316 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2317 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2318 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2319 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2320 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2321 { 0, "{ [i0, i1, i2] : "
2322 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2323 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2324 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2325 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2326 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2327 "32e0 <= 31 + i0)) or "
2329 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2330 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2331 "2*floor((c)/2) = c and 0 <= a <= 192;"
2332 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2334 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2335 "(0 <= a <= b <= n) }" },
2336 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2337 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2338 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2339 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2340 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2341 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2342 "b = 3 and 9e0 <= -19 + 2c)) }" },
2343 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2344 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2345 "(a = 4 and b = 3 and "
2346 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2347 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2348 "(b = -1 + a and 0 < a <= 3 and "
2349 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2350 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2351 "b = 3 and 9e0 <= -19 + 2c)) }" },
2352 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2354 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2356 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2357 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2358 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2359 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2360 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2361 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2362 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2363 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2364 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2365 { 1, "{ [a] : a <= 8 and "
2366 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2367 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2368 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2369 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2370 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2371 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2372 "(a < 0 and 3*floor((a)/3) < a) }" },
2373 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2374 "(a < -1 and 3*floor((a)/3) < a) }" },
2375 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2376 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2377 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2378 "or (2 <= a <= 15 and b < a)) }" },
2379 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2380 "32*floor((a)/32) < a) or a <= 15) }" },
2381 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2382 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2383 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2384 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2385 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2386 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2387 "S_0[n] : n <= m <= 2 + n }" },
2388 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2389 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2391 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2392 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2393 "2e0 < -a + 2b) }" },
2394 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2395 "[i, 0, i] : 0 <= i <= 7 }" },
2396 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2397 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2398 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2399 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2400 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2401 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2402 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2403 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2404 "a > 0 and a <= 5) }" },
2405 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2406 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2407 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2408 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2409 { 0, "{ [0:1, 0:1]; [0, 2:3] }" },
2410 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2411 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2412 { 1, "{ rat: [0:2]; rat: [1:3] }" },
2413 { 1, "{ [a] : 0 < a <= 341 or "
2414 "(0 < a <= 700 and 360*floor(a/360) >= -340 + a) }" },
2415 { 0, "{ [a] : 0 < a <= 341 or "
2416 "(0 < a <= 701 and 360*floor(a/360) >= -340 + a) }" },
2419 /* A specialized coalescing test case that would result
2420 * in a segmentation fault or a failed assertion in earlier versions of isl.
2422 static int test_coalesce_special(struct isl_ctx
*ctx
)
2425 isl_map
*map1
, *map2
;
2427 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2428 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2429 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2430 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2431 "o1 <= 239 and o1 >= 212)) or "
2432 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2433 "o1 <= 241 and o1 >= 240));"
2434 "[S_L220_OUT[] -> T7[]] -> "
2435 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2436 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2437 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2438 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2439 map1
= isl_map_read_from_str(ctx
, str
);
2440 map1
= isl_map_align_divs_internal(map1
);
2441 map1
= isl_map_coalesce(map1
);
2442 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2443 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2444 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2445 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2446 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2447 map2
= isl_map_read_from_str(ctx
, str
);
2448 map2
= isl_map_union(map2
, map1
);
2449 map2
= isl_map_align_divs_internal(map2
);
2450 map2
= isl_map_coalesce(map2
);
2458 /* Check that the union of the basic sets described by "str1" and "str2"
2459 * can be coalesced and that the result is equal to the union.
2460 * The explicit call to isl_basic_set_union prevents the implicit
2461 * equality constraints in the basic maps from being detected prior
2462 * to the call to isl_set_coalesce, at least at the point
2463 * where this function was introduced.
2465 static isl_stat
test_coalesce_union(isl_ctx
*ctx
, const char *str1
,
2468 isl_basic_set
*bset1
, *bset2
;
2469 isl_set
*set
, *set2
;
2472 bset1
= isl_basic_set_read_from_str(ctx
, str1
);
2473 bset2
= isl_basic_set_read_from_str(ctx
, str2
);
2474 set
= isl_basic_set_union(bset1
, bset2
);
2475 set
= isl_set_coalesce(set
);
2477 bset1
= isl_basic_set_read_from_str(ctx
, str1
);
2478 bset2
= isl_basic_set_read_from_str(ctx
, str2
);
2479 set2
= isl_basic_set_union(bset1
, bset2
);
2481 equal
= isl_set_is_equal(set
, set2
);
2486 return isl_stat_error
;
2488 isl_die(ctx
, isl_error_unknown
,
2489 "coalesced set not equal to input",
2490 return isl_stat_error
);
2492 return isl_stat_non_null(set
);
2495 /* A specialized coalescing test case that would result in an assertion
2496 * in an earlier version of isl. Use test_coalesce_union with
2497 * an explicit call to isl_basic_set_union to prevent the implicit
2498 * equality constraints in the first basic map from being detected prior
2499 * to the call to isl_set_coalesce, at least at the point
2500 * where this test case was introduced.
2502 static isl_stat
test_coalesce_special2(struct isl_ctx
*ctx
)
2507 str1
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2508 str2
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }";
2509 return test_coalesce_union(ctx
, str1
, str2
);
2512 /* Check that calling isl_set_coalesce does not leave other sets
2513 * that may share some information with the input to isl_set_coalesce
2514 * in an inconsistent state.
2515 * In particular, older versions of isl would modify all copies
2516 * of the basic sets in the isl_set_coalesce input in a way
2517 * that could leave them in an inconsistent state.
2518 * The result of printing any other set containing one of these
2519 * basic sets would then result in an invalid set description.
2521 static int test_coalesce_special3(isl_ctx
*ctx
)
2525 isl_set
*set1
, *set2
;
2528 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2529 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2530 set2
= isl_set_read_from_str(ctx
, str
);
2531 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2532 set1
= isl_set_coalesce(set1
);
2535 p
= isl_printer_to_str(ctx
);
2536 p
= isl_printer_print_set(p
, set2
);
2538 s
= isl_printer_get_str(p
);
2539 isl_printer_free(p
);
2540 set1
= isl_set_read_from_str(ctx
, s
);
2550 /* Check that calling isl_set_coalesce on the intersection of
2551 * the sets described by "s1" and "s2" does not leave other sets
2552 * that may share some information with the input to isl_set_coalesce
2553 * in an inconsistent state.
2554 * In particular, when isl_set_coalesce detects equality constraints,
2555 * it does not immediately perform Gaussian elimination on them,
2556 * but then it needs to ensure that it is performed at some point.
2557 * The input set has implicit equality constraints in the first disjunct.
2558 * It is constructed as an intersection, because otherwise
2559 * those equality constraints would already be detected during parsing.
2561 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2562 const char *s1
, const char *s2
)
2564 isl_set
*set1
, *set2
;
2566 set1
= isl_set_read_from_str(ctx
, s1
);
2567 set2
= isl_set_read_from_str(ctx
, s2
);
2568 set1
= isl_set_intersect(set1
, set2
);
2569 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2570 set1
= isl_set_coalesce(set1
);
2574 return isl_stat_error
;
2579 /* Check that calling isl_set_coalesce does not leave other sets
2580 * that may share some information with the input to isl_set_coalesce
2581 * in an inconsistent state, for the case where one disjunct
2582 * is a subset of the other.
2584 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2586 const char *s1
, *s2
;
2588 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2589 s2
= "{ [a, b] : -1 <= -a < b }";
2590 return test_coalesce_intersection(ctx
, s1
, s2
);
2593 /* Check that calling isl_set_coalesce does not leave other sets
2594 * that may share some information with the input to isl_set_coalesce
2595 * in an inconsistent state, for the case where two disjuncts
2598 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2600 const char *s1
, *s2
;
2602 s1
= "{ [a, b, c] : b <= 0 }";
2603 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2604 return test_coalesce_intersection(ctx
, s1
, s2
);
2607 /* Check that calling isl_set_coalesce does not leave other sets
2608 * that may share some information with the input to isl_set_coalesce
2609 * in an inconsistent state, for the case where two disjuncts
2610 * can be fused and where both disjuncts have implicit equality constraints.
2612 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2614 const char *s1
, *s2
;
2616 s1
= "{ [a, b, c] : c <= 0 }";
2617 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2618 return test_coalesce_intersection(ctx
, s1
, s2
);
2621 /* A specialized coalescing test case that would result in an assertion failure
2622 * in an earlier version of isl. Use test_coalesce_union with
2623 * an explicit call to isl_basic_set_union to prevent the implicit
2624 * equality constraints in the basic maps from being detected prior
2625 * to the call to isl_set_coalesce, at least at the point
2626 * where this test case was introduced.
2628 static isl_stat
test_coalesce_special7(isl_ctx
*ctx
)
2633 str1
= "{ [a, b, c=0:17] : a <= 7 and 2b <= 11 - a and "
2634 "c <= -7 + 2a and 2c >= - 3 + 3a - 2b }";
2635 str2
= "{ [a, b, c] : c > -15a and c >= -7 + 2a and c < 0 and "
2636 "3c <= -5 + 5a - 3b and 2b >= 11 - a }";
2637 return test_coalesce_union(ctx
, str1
, str2
);
2640 /* A specialized coalescing test case that would result in a disjunct
2641 * getting dropped in an earlier version of isl. Use test_coalesce_union with
2642 * an explicit call to isl_basic_set_union to prevent the implicit
2643 * equality constraints in the basic maps from being detected prior
2644 * to the call to isl_set_coalesce, at least at the point
2645 * where this test case was introduced.
2647 static isl_stat
test_coalesce_special8(isl_ctx
*ctx
)
2652 str1
= "{ [a, b, c] : 2c <= -a and b >= -a and b <= 5 and "
2653 "6c > -7a and 11c >= -5a - b and a <= 3 }";
2654 str2
= "{ [a, b, c] : 6c > -7a and b >= -a and b <= 5 and "
2655 "11c >= -5a - b and a >= 4 and 2b <= a and 2c <= -a }";
2656 return test_coalesce_union(ctx
, str1
, str2
);
2659 /* Test the functionality of isl_set_coalesce.
2660 * That is, check that the output is always equal to the input
2661 * and in some cases that the result consists of a single disjunct.
2663 static int test_coalesce(struct isl_ctx
*ctx
)
2667 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2668 const char *str
= coalesce_tests
[i
].str
;
2669 int check_one
= coalesce_tests
[i
].single_disjunct
;
2670 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2674 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2676 if (test_coalesce_special(ctx
) < 0)
2678 if (test_coalesce_special2(ctx
) < 0)
2680 if (test_coalesce_special3(ctx
) < 0)
2682 if (test_coalesce_special4(ctx
) < 0)
2684 if (test_coalesce_special5(ctx
) < 0)
2686 if (test_coalesce_special6(ctx
) < 0)
2688 if (test_coalesce_special7(ctx
) < 0)
2690 if (test_coalesce_special8(ctx
) < 0)
2696 /* Construct a representation of the graph on the right of Figure 1
2697 * in "Computing the Transitive Closure of a Union of
2698 * Affine Integer Tuple Relations".
2700 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2703 isl_map
*up
, *right
;
2705 dom
= isl_set_read_from_str(ctx
,
2706 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2707 "2 x - 3 y + 3 >= 0 }");
2708 right
= isl_map_read_from_str(ctx
,
2709 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2710 up
= isl_map_read_from_str(ctx
,
2711 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2712 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2713 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2714 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2715 up
= isl_map_intersect_range(up
, dom
);
2716 return isl_map_union(up
, right
);
2719 /* Construct a representation of the power of the graph
2720 * on the right of Figure 1 in "Computing the Transitive Closure of
2721 * a Union of Affine Integer Tuple Relations".
2723 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2725 return isl_map_read_from_str(ctx
,
2726 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2727 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2728 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2731 /* Construct a representation of the transitive closure of the graph
2732 * on the right of Figure 1 in "Computing the Transitive Closure of
2733 * a Union of Affine Integer Tuple Relations".
2735 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2737 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2740 static int test_closure(isl_ctx
*ctx
)
2743 isl_map
*map
, *map2
;
2744 isl_bool exact
, equal
;
2746 /* COCOA example 1 */
2747 map
= isl_map_read_from_str(ctx
,
2748 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2749 "1 <= i and i < n and 1 <= j and j < n or "
2750 "i2 = i + 1 and j2 = j - 1 and "
2751 "1 <= i and i < n and 2 <= j and j <= n }");
2752 map
= isl_map_power(map
, &exact
);
2756 /* COCOA example 1 */
2757 map
= isl_map_read_from_str(ctx
,
2758 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2759 "1 <= i and i < n and 1 <= j and j < n or "
2760 "i2 = i + 1 and j2 = j - 1 and "
2761 "1 <= i and i < n and 2 <= j and j <= n }");
2762 map
= isl_map_transitive_closure(map
, &exact
);
2764 map2
= isl_map_read_from_str(ctx
,
2765 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2766 "1 <= i and i < n and 1 <= j and j <= n and "
2767 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2768 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2769 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2770 assert(isl_map_is_equal(map
, map2
));
2774 map
= isl_map_read_from_str(ctx
,
2775 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2776 " 0 <= y and y <= n }");
2777 map
= isl_map_transitive_closure(map
, &exact
);
2778 map2
= isl_map_read_from_str(ctx
,
2779 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2780 " 0 <= y and y <= n }");
2781 assert(isl_map_is_equal(map
, map2
));
2785 /* COCOA example 2 */
2786 map
= isl_map_read_from_str(ctx
,
2787 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2788 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2789 "i2 = i + 2 and j2 = j - 2 and "
2790 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2791 map
= isl_map_transitive_closure(map
, &exact
);
2793 map2
= isl_map_read_from_str(ctx
,
2794 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2795 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2796 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2797 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2798 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2799 assert(isl_map_is_equal(map
, map2
));
2803 /* COCOA Fig.2 left */
2804 map
= isl_map_read_from_str(ctx
,
2805 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2806 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2808 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2809 "j <= 2 i - 3 and j <= n - 2 or "
2810 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2811 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2812 map
= isl_map_transitive_closure(map
, &exact
);
2816 /* COCOA Fig.2 right */
2817 map
= isl_map_read_from_str(ctx
,
2818 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2819 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2821 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2822 "j <= 2 i - 4 and j <= n - 3 or "
2823 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2824 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2825 map
= isl_map_power(map
, &exact
);
2829 /* COCOA Fig.2 right */
2830 map
= isl_map_read_from_str(ctx
,
2831 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2832 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2834 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2835 "j <= 2 i - 4 and j <= n - 3 or "
2836 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2837 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2838 map
= isl_map_transitive_closure(map
, &exact
);
2840 map2
= isl_map_read_from_str(ctx
,
2841 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2842 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2843 "j <= n and 3 + i + 2 j <= 3 n and "
2844 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2845 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2846 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2847 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2848 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2849 assert(isl_map_is_equal(map
, map2
));
2853 map
= cocoa_fig_1_right_graph(ctx
);
2854 map
= isl_map_transitive_closure(map
, &exact
);
2856 map2
= cocoa_fig_1_right_tc(ctx
);
2857 assert(isl_map_is_equal(map
, map2
));
2861 map
= cocoa_fig_1_right_graph(ctx
);
2862 map
= isl_map_power(map
, &exact
);
2863 map2
= cocoa_fig_1_right_power(ctx
);
2864 equal
= isl_map_is_equal(map
, map2
);
2870 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2872 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2874 /* COCOA Theorem 1 counter example */
2875 map
= isl_map_read_from_str(ctx
,
2876 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2877 "i2 = 1 and j2 = j or "
2878 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2879 map
= isl_map_transitive_closure(map
, &exact
);
2883 map
= isl_map_read_from_str(ctx
,
2884 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2885 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2886 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2887 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2888 map
= isl_map_transitive_closure(map
, &exact
);
2892 /* Kelly et al 1996, fig 12 */
2893 map
= isl_map_read_from_str(ctx
,
2894 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2895 "1 <= i,j,j+1 <= n or "
2896 "j = n and j2 = 1 and i2 = i + 1 and "
2897 "1 <= i,i+1 <= n }");
2898 map
= isl_map_transitive_closure(map
, &exact
);
2900 map2
= isl_map_read_from_str(ctx
,
2901 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2902 "1 <= i <= n and i = i2 or "
2903 "1 <= i < i2 <= n and 1 <= j <= n and "
2905 assert(isl_map_is_equal(map
, map2
));
2909 /* Omega's closure4 */
2910 map
= isl_map_read_from_str(ctx
,
2911 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2912 "1 <= x,y <= 10 or "
2913 "x2 = x + 1 and y2 = y and "
2914 "1 <= x <= 20 && 5 <= y <= 15 }");
2915 map
= isl_map_transitive_closure(map
, &exact
);
2919 map
= isl_map_read_from_str(ctx
,
2920 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2921 map
= isl_map_transitive_closure(map
, &exact
);
2923 map2
= isl_map_read_from_str(ctx
,
2924 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2925 assert(isl_map_is_equal(map
, map2
));
2929 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2930 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2931 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2932 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2933 map
= isl_map_read_from_str(ctx
, str
);
2934 map
= isl_map_transitive_closure(map
, &exact
);
2936 map2
= isl_map_read_from_str(ctx
, str
);
2937 assert(isl_map_is_equal(map
, map2
));
2941 str
= "{[0] -> [1]; [2] -> [3]}";
2942 map
= isl_map_read_from_str(ctx
, str
);
2943 map
= isl_map_transitive_closure(map
, &exact
);
2945 map2
= isl_map_read_from_str(ctx
, str
);
2946 assert(isl_map_is_equal(map
, map2
));
2950 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2951 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2952 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2953 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2954 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2955 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2956 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2957 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2958 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2959 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2960 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2961 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2962 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2963 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2964 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2965 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2966 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2967 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2968 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2969 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2970 map
= isl_map_read_from_str(ctx
, str
);
2971 map
= isl_map_transitive_closure(map
, NULL
);
2978 /* Check that the actual result of a boolean operation is equal
2979 * to the expected result.
2981 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2983 if (actual
!= expected
)
2984 isl_die(ctx
, isl_error_unknown
,
2985 "incorrect boolean operation", return isl_stat_error
);
2989 /* Test operations on isl_bool values.
2996 static int test_isl_bool(isl_ctx
*ctx
)
2998 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
3000 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
3002 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
3004 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
3006 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
3008 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
3010 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
3012 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
3018 static int test_lex(struct isl_ctx
*ctx
)
3024 space
= isl_space_set_alloc(ctx
, 0, 0);
3025 map
= isl_map_lex_le(space
);
3026 empty
= isl_map_is_empty(map
);
3032 isl_die(ctx
, isl_error_unknown
,
3033 "expecting non-empty result", return -1);
3038 /* Inputs for isl_map_lexmin tests.
3039 * "map" is the input and "lexmin" is the expected result.
3044 } lexmin_tests
[] = {
3045 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
3046 "{ [x] -> [5] : 6 <= x <= 8; "
3047 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
3048 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
3049 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
3050 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
3051 "{ [x] -> [y] : (4y = x and x >= 0) or "
3052 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
3053 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
3054 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
3055 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
3056 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
3057 /* Check that empty pieces are properly combined. */
3058 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
3059 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
3060 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
3061 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
3062 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
3064 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
3065 "a <= 255 and c <= 255 and d <= 255 - j and "
3066 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
3067 "247d <= 247 + k - j and 247d <= 247 + k - b and "
3068 "247d <= 247 + i and 248 - b <= 248d <= c and "
3069 "254d >= i - a + b and 254d >= -a + b and "
3070 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
3072 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
3073 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
3074 "247j >= 62738 - i and 509j <= 129795 + i and "
3075 "742j >= 188724 - i; "
3076 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
3077 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
3078 "16*floor((8 + b)/16) <= 7 + b; "
3080 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
3081 "[a] -> [b = 0] : 0 < a <= 509 }" },
3082 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
3083 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
3084 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
3087 static int test_lexmin(struct isl_ctx
*ctx
)
3092 isl_basic_map
*bmap
;
3093 isl_map
*map
, *map2
;
3096 isl_pw_multi_aff
*pma
;
3098 str
= "[p0, p1] -> { [] -> [] : "
3099 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
3100 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
3101 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
3102 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
3103 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
3104 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
3105 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
3106 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
3107 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
3108 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
3109 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
3110 map
= isl_map_read_from_str(ctx
, str
);
3111 map
= isl_map_lexmin(map
);
3116 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
3117 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
3118 set
= isl_set_read_from_str(ctx
, str
);
3119 set
= isl_set_lexmax(set
);
3120 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
3121 set2
= isl_set_read_from_str(ctx
, str
);
3122 set
= isl_set_intersect(set
, set2
);
3123 assert(!isl_set_is_empty(set
));
3126 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
3127 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
3128 map
= isl_map_lexmin(map
);
3129 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
3130 equal
= isl_map_is_equal(map
, map2
);
3137 isl_die(ctx
, isl_error_unknown
,
3138 "unexpected result", return -1);
3141 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3142 " 8i' <= i and 8i' >= -7 + i }";
3143 bmap
= isl_basic_map_read_from_str(ctx
, str
);
3144 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
3145 map2
= isl_map_from_pw_multi_aff(pma
);
3146 map
= isl_map_from_basic_map(bmap
);
3147 assert(isl_map_is_equal(map
, map2
));
3151 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3152 " 8i' <= i and 8i' >= -7 + i }";
3153 set
= isl_set_read_from_str(ctx
, str
);
3154 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
3155 set2
= isl_set_from_pw_multi_aff(pma
);
3156 equal
= isl_set_is_equal(set
, set2
);
3162 isl_die(ctx
, isl_error_unknown
,
3163 "unexpected difference between set and "
3164 "piecewise affine expression", return -1);
3169 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3170 * "pma" is the input.
3171 * "res" is the expected result.
3176 } opt_pw_tests
[] = {
3177 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3178 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3179 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3180 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3181 "{ A[10, 0, 20] }" },
3182 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3185 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3187 static isl_stat
test_pw_max(struct isl_ctx
*ctx
)
3190 isl_pw_multi_aff
*pma
;
3194 for (i
= 0; i
< ARRAY_SIZE(opt_pw_tests
); ++i
) {
3195 pma
= isl_pw_multi_aff_read_from_str(ctx
, opt_pw_tests
[i
].pma
);
3196 mv
= isl_pw_multi_aff_max_multi_val(pma
);
3197 r
= multi_val_check_plain_equal(mv
, opt_pw_tests
[i
].res
);
3198 isl_multi_val_free(mv
);
3201 return isl_stat_error
;
3207 /* A specialized isl_set_min_val test case that would return the wrong result
3208 * in earlier versions of isl.
3209 * The explicit call to isl_basic_set_union prevents the second basic set
3210 * from being determined to be empty prior to the call to isl_set_min_val,
3211 * at least at the point where this test case was introduced.
3213 static int test_min_special(isl_ctx
*ctx
)
3216 isl_basic_set
*bset1
, *bset2
;
3222 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3223 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3224 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3225 bset2
= isl_basic_set_read_from_str(ctx
, str
);
3226 set
= isl_basic_set_union(bset1
, bset2
);
3227 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
3229 res
= isl_set_min_val(set
, obj
);
3230 ok
= isl_val_cmp_si(res
, 5) == 0;
3239 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
3245 /* A specialized isl_set_min_val test case that would return an error
3246 * in earlier versions of isl.
3248 static int test_min_special2(isl_ctx
*ctx
)
3251 isl_basic_set
*bset
;
3255 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3256 bset
= isl_basic_set_read_from_str(ctx
, str
);
3258 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
3260 res
= isl_basic_set_max_val(bset
, obj
);
3262 isl_basic_set_free(bset
);
3272 /* Check that the result of isl_set_min_multi_pw_aff
3273 * on the union of the sets with string descriptions "s1" and "s2"
3274 * consists of a single expression (on a single cell).
3276 static isl_stat
check_single_expr_min(isl_ctx
*ctx
, const char *s1
,
3280 isl_set
*set1
, *set2
;
3281 isl_multi_pw_aff
*mpa
;
3282 isl_pw_multi_aff
*pma
;
3284 set1
= isl_set_read_from_str(ctx
, s1
);
3285 set2
= isl_set_read_from_str(ctx
, s2
);
3286 set1
= isl_set_union(set1
, set2
);
3287 mpa
= isl_set_min_multi_pw_aff(set1
);
3288 pma
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
3289 n
= isl_pw_multi_aff_n_piece(pma
);
3290 isl_pw_multi_aff_free(pma
);
3293 return isl_stat_error
;
3295 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
3296 return isl_stat_error
);
3300 /* A specialized isl_set_min_multi_pw_aff test that checks
3301 * that the minimum of 2N and 3N for N >= 0 is represented
3302 * by a single expression, without splitting off the special case N = 0.
3303 * Do this for both orderings.
3305 static int test_min_mpa(isl_ctx
*ctx
)
3307 const char *s1
, *s2
;
3309 s1
= "[N=0:] -> { [1, 3N:] }";
3310 s2
= "[N=0:] -> { [10, 2N:] }";
3311 if (check_single_expr_min(ctx
, s1
, s2
) < 0)
3313 if (check_single_expr_min(ctx
, s2
, s1
) < 0)
3322 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
3323 __isl_keep isl_aff
*obj
);
3326 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
3327 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
3328 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3329 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3330 &isl_set_max_val
, "30" },
3334 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3335 * In particular, check the results on non-convex inputs.
3337 static int test_min(struct isl_ctx
*ctx
)
3345 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
3346 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
3347 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
3348 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
3349 val
= opt_tests
[i
].fn(set
, obj
);
3350 ok
= isl_val_eq(res
, val
);
3359 isl_die(ctx
, isl_error_unknown
,
3360 "unexpected optimum", return -1);
3363 if (test_pw_max(ctx
) < 0)
3365 if (test_min_special(ctx
) < 0)
3367 if (test_min_special2(ctx
) < 0)
3378 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
3379 void *dep_user
, void *user
)
3381 struct must_may
*mm
= (struct must_may
*)user
;
3384 mm
->must
= isl_map_union(mm
->must
, dep
);
3386 mm
->may
= isl_map_union(mm
->may
, dep
);
3391 static int common_space(void *first
, void *second
)
3393 int depth
= *(int *)first
;
3397 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3405 map2
= isl_map_read_from_str(map
->ctx
, str
);
3406 equal
= isl_map_is_equal(map
, map2
);
3412 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3416 equal
= map_is_equal(map
, str
);
3420 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3421 "result not as expected", return -1);
3425 /* Is "set" equal to the set described by "str"?
3427 static isl_bool
set_is_equal(__isl_keep isl_set
*set
, const char *str
)
3433 return isl_bool_error
;
3435 set2
= isl_set_read_from_str(isl_set_get_ctx(set
), str
);
3436 equal
= isl_set_is_equal(set
, set2
);
3442 /* Check that "set" is equal to the set described by "str".
3444 static isl_stat
set_check_equal(__isl_keep isl_set
*set
, const char *str
)
3448 equal
= set_is_equal(set
, str
);
3450 return isl_stat_error
;
3452 isl_die(isl_set_get_ctx(set
), isl_error_unknown
,
3453 "result not as expected", return isl_stat_error
);
3457 /* Is "uset" equal to the union set described by "str"?
3459 static isl_bool
uset_is_equal(__isl_keep isl_union_set
*uset
, const char *str
)
3461 isl_union_set
*uset2
;
3465 return isl_bool_error
;
3467 uset2
= isl_union_set_read_from_str(isl_union_set_get_ctx(uset
), str
);
3468 equal
= isl_union_set_is_equal(uset
, uset2
);
3469 isl_union_set_free(uset2
);
3474 /* Check that "uset" is equal to the union set described by "str".
3476 static isl_stat
uset_check_equal(__isl_keep isl_union_set
*uset
,
3481 equal
= uset_is_equal(uset
, str
);
3483 return isl_stat_error
;
3485 isl_die(isl_union_set_get_ctx(uset
), isl_error_unknown
,
3486 "result not as expected", return isl_stat_error
);
3490 static int test_dep(struct isl_ctx
*ctx
)
3495 isl_access_info
*ai
;
3502 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3503 map
= isl_map_read_from_str(ctx
, str
);
3504 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3506 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3507 map
= isl_map_read_from_str(ctx
, str
);
3508 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3510 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3511 map
= isl_map_read_from_str(ctx
, str
);
3512 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3514 flow
= isl_access_info_compute_flow(ai
);
3515 space
= isl_space_alloc(ctx
, 0, 3, 3);
3516 mm
.must
= isl_map_empty(isl_space_copy(space
));
3517 mm
.may
= isl_map_empty(space
);
3519 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3521 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3522 " [1,10,0] -> [2,5,0] }";
3523 assert(map_is_equal(mm
.must
, str
));
3524 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3525 assert(map_is_equal(mm
.may
, str
));
3527 isl_map_free(mm
.must
);
3528 isl_map_free(mm
.may
);
3529 isl_flow_free(flow
);
3532 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3533 map
= isl_map_read_from_str(ctx
, str
);
3534 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3536 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3537 map
= isl_map_read_from_str(ctx
, str
);
3538 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3540 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3541 map
= isl_map_read_from_str(ctx
, str
);
3542 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3544 flow
= isl_access_info_compute_flow(ai
);
3545 space
= isl_space_alloc(ctx
, 0, 3, 3);
3546 mm
.must
= isl_map_empty(isl_space_copy(space
));
3547 mm
.may
= isl_map_empty(space
);
3549 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3551 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3552 assert(map_is_equal(mm
.must
, str
));
3553 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3554 assert(map_is_equal(mm
.may
, str
));
3556 isl_map_free(mm
.must
);
3557 isl_map_free(mm
.may
);
3558 isl_flow_free(flow
);
3561 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3562 map
= isl_map_read_from_str(ctx
, str
);
3563 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3565 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3566 map
= isl_map_read_from_str(ctx
, str
);
3567 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3569 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3570 map
= isl_map_read_from_str(ctx
, str
);
3571 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3573 flow
= isl_access_info_compute_flow(ai
);
3574 space
= isl_space_alloc(ctx
, 0, 3, 3);
3575 mm
.must
= isl_map_empty(isl_space_copy(space
));
3576 mm
.may
= isl_map_empty(space
);
3578 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3580 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3581 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3582 assert(map_is_equal(mm
.may
, str
));
3583 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3584 assert(map_is_equal(mm
.must
, str
));
3586 isl_map_free(mm
.must
);
3587 isl_map_free(mm
.may
);
3588 isl_flow_free(flow
);
3591 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3592 map
= isl_map_read_from_str(ctx
, str
);
3593 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3595 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3596 map
= isl_map_read_from_str(ctx
, str
);
3597 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3599 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3600 map
= isl_map_read_from_str(ctx
, str
);
3601 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3603 flow
= isl_access_info_compute_flow(ai
);
3604 space
= isl_space_alloc(ctx
, 0, 3, 3);
3605 mm
.must
= isl_map_empty(isl_space_copy(space
));
3606 mm
.may
= isl_map_empty(space
);
3608 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3610 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3611 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3612 assert(map_is_equal(mm
.may
, str
));
3613 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3614 assert(map_is_equal(mm
.must
, str
));
3616 isl_map_free(mm
.must
);
3617 isl_map_free(mm
.may
);
3618 isl_flow_free(flow
);
3621 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3622 map
= isl_map_read_from_str(ctx
, str
);
3623 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3625 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3626 map
= isl_map_read_from_str(ctx
, str
);
3627 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3629 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3630 map
= isl_map_read_from_str(ctx
, str
);
3631 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3633 flow
= isl_access_info_compute_flow(ai
);
3634 space
= isl_space_alloc(ctx
, 0, 3, 3);
3635 mm
.must
= isl_map_empty(isl_space_copy(space
));
3636 mm
.may
= isl_map_empty(space
);
3638 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3640 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3641 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3642 assert(map_is_equal(mm
.may
, str
));
3643 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3644 assert(map_is_equal(mm
.must
, str
));
3646 isl_map_free(mm
.must
);
3647 isl_map_free(mm
.may
);
3648 isl_flow_free(flow
);
3653 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3654 map
= isl_map_read_from_str(ctx
, str
);
3655 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3657 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3658 map
= isl_map_read_from_str(ctx
, str
);
3659 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3661 flow
= isl_access_info_compute_flow(ai
);
3662 space
= isl_space_alloc(ctx
, 0, 5, 5);
3663 mm
.must
= isl_map_empty(isl_space_copy(space
));
3664 mm
.may
= isl_map_empty(space
);
3666 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3668 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3669 assert(map_is_equal(mm
.must
, str
));
3670 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3671 assert(map_is_equal(mm
.may
, str
));
3673 isl_map_free(mm
.must
);
3674 isl_map_free(mm
.may
);
3675 isl_flow_free(flow
);
3680 /* Check that the dependence analysis proceeds without errors.
3681 * Earlier versions of isl would break down during the analysis
3682 * due to the use of the wrong spaces.
3684 static int test_flow(isl_ctx
*ctx
)
3687 isl_union_map
*access
, *schedule
;
3688 isl_union_map
*must_dep
, *may_dep
;
3691 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3692 access
= isl_union_map_read_from_str(ctx
, str
);
3693 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3694 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3695 "S2[] -> [1,0,0,0]; "
3696 "S3[] -> [-1,0,0,0] }";
3697 schedule
= isl_union_map_read_from_str(ctx
, str
);
3698 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3699 isl_union_map_copy(access
), schedule
,
3700 &must_dep
, &may_dep
, NULL
, NULL
);
3701 isl_union_map_free(may_dep
);
3702 isl_union_map_free(must_dep
);
3711 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3712 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3713 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3714 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3715 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3716 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3717 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3718 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3719 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3722 int test_sv(isl_ctx
*ctx
)
3724 isl_union_map
*umap
;
3728 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3729 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3730 sv
= isl_union_map_is_single_valued(umap
);
3731 isl_union_map_free(umap
);
3734 if (sv_tests
[i
].sv
&& !sv
)
3735 isl_die(ctx
, isl_error_internal
,
3736 "map not detected as single valued", return -1);
3737 if (!sv_tests
[i
].sv
&& sv
)
3738 isl_die(ctx
, isl_error_internal
,
3739 "map detected as single valued", return -1);
3748 } bijective_tests
[] = {
3749 { "[N,M]->{[i,j] -> [i]}", 0 },
3750 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3751 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3752 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3753 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3754 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3755 { "[N,M]->{[i,j] -> []}", 0 },
3756 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3757 { "[N,M]->{[i,j] -> [2i]}", 0 },
3758 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3759 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3760 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3761 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3764 static int test_bijective(struct isl_ctx
*ctx
)
3770 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3771 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3772 bijective
= isl_map_is_bijective(map
);
3776 if (bijective_tests
[i
].bijective
&& !bijective
)
3777 isl_die(ctx
, isl_error_internal
,
3778 "map not detected as bijective", return -1);
3779 if (!bijective_tests
[i
].bijective
&& bijective
)
3780 isl_die(ctx
, isl_error_internal
,
3781 "map detected as bijective", return -1);
3787 /* Inputs for isl_pw_qpolynomial_gist tests.
3788 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3794 } pwqp_gist_tests
[] = {
3795 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3796 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3797 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3798 "{ [i] -> -1/2 + 1/2 * i }" },
3799 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3800 { "{ [i] -> i^2 : i > 0; [i] -> i^2 : i < 0 }", "{ [i] : i != 0 }",
3804 /* Perform some basic isl_pw_qpolynomial_gist tests.
3806 static isl_stat
test_pwqp_gist(isl_ctx
*ctx
)
3811 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3814 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3815 str
= pwqp_gist_tests
[i
].pwqp
;
3816 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3817 str
= pwqp_gist_tests
[i
].set
;
3818 set
= isl_set_read_from_str(ctx
, str
);
3819 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3820 str
= pwqp_gist_tests
[i
].gist
;
3821 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3822 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3823 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3824 isl_pw_qpolynomial_free(pwqp1
);
3827 return isl_stat_error
;
3829 isl_die(ctx
, isl_error_unknown
,
3830 "unexpected result", return isl_stat_error
);
3836 /* Perform a basic isl_pw_qpolynomial_max test.
3838 static isl_stat
test_pwqp_max(isl_ctx
*ctx
)
3841 isl_pw_qpolynomial
*pwqp
;
3845 str
= "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3846 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3847 v
= isl_pw_qpolynomial_max(pwqp
);
3848 ok
= isl_val_cmp_si(v
, -1) == 0;
3852 return isl_stat_error
;
3854 isl_die(ctx
, isl_error_unknown
, "unexpected maximum",
3855 return isl_stat_error
);
3860 static int test_pwqp(struct isl_ctx
*ctx
)
3864 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3867 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3868 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3870 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3873 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3874 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3876 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3878 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3880 isl_pw_qpolynomial_free(pwqp1
);
3882 if (test_pwqp_gist(ctx
) < 0)
3885 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3886 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3887 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3888 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3890 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3892 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3894 isl_pw_qpolynomial_free(pwqp1
);
3896 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3897 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3898 str
= "{ [x] -> x }";
3899 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3901 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3903 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3905 isl_pw_qpolynomial_free(pwqp1
);
3907 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3908 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3909 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3910 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3911 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3912 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3913 isl_pw_qpolynomial_free(pwqp1
);
3915 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3916 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3917 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3918 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3919 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3920 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3921 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3922 isl_pw_qpolynomial_free(pwqp1
);
3923 isl_pw_qpolynomial_free(pwqp2
);
3927 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3929 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3930 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3931 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3932 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3933 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3935 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3936 isl_pw_qpolynomial_free(pwqp1
);
3937 isl_pw_qpolynomial_free(pwqp2
);
3941 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3943 if (test_pwqp_max(ctx
) < 0)
3949 static int test_split_periods(isl_ctx
*ctx
)
3952 isl_pw_qpolynomial
*pwqp
;
3954 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3955 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3956 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3957 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3959 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3961 isl_pw_qpolynomial_free(pwqp
);
3969 static int test_union(isl_ctx
*ctx
)
3972 isl_union_set
*uset1
, *uset2
;
3973 isl_union_map
*umap1
, *umap2
;
3976 str
= "{ [i] : 0 <= i <= 1 }";
3977 uset1
= isl_union_set_read_from_str(ctx
, str
);
3978 str
= "{ [1] -> [0] }";
3979 umap1
= isl_union_map_read_from_str(ctx
, str
);
3981 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3982 equal
= isl_union_map_is_equal(umap1
, umap2
);
3984 isl_union_map_free(umap1
);
3985 isl_union_map_free(umap2
);
3990 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3993 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3994 umap1
= isl_union_map_read_from_str(ctx
, str
);
3995 str
= "{ A[i]; B[i] }";
3996 uset1
= isl_union_set_read_from_str(ctx
, str
);
3998 uset2
= isl_union_map_domain(umap1
);
4000 equal
= isl_union_set_is_equal(uset1
, uset2
);
4002 isl_union_set_free(uset1
);
4003 isl_union_set_free(uset2
);
4008 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
4014 /* Inputs for basic isl_pw_qpolynomial_bound tests.
4015 * "type" is the type of bound that should be computed.
4016 * "poly" is a string representation of the input.
4017 * "bound" is a string representation of the expected result.
4018 * "tight" is set if the result is expected to be tight.
4026 /* Check that computing a bound of a non-zero polynomial
4027 * over an unbounded domain does not produce a rational value.
4028 * In particular, check that the upper bound is infinity.
4030 { 0, isl_fold_max
, "{ [m, n] -> -m * n }", "{ max(infty) }" },
4031 { 1, isl_fold_max
, "{ [[a, b, c, d] -> [e]] -> 0 }",
4032 "{ [a, b, c, d] -> max(0) }" },
4033 { 1, isl_fold_max
, "{ [[x] -> [x]] -> 1 : exists a : x = 2 a }",
4034 "{ [x] -> max(1) : x mod 2 = 0 }" },
4035 { 1, isl_fold_min
, "{ [x=5:10] -> (x + 2)^2 }", "{ min(49) }" },
4036 { 1, isl_fold_max
, "{ [0:10] -> 1 }", "{ max(1) }" },
4037 { 1, isl_fold_max
, "{ [[m] -> [0:m]] -> m^2 }",
4038 "{ [m] -> max(m^2) : m >= 0 }" },
4041 /* Check that the bound computation can handle differences
4042 * in domain dimension names of the input polynomial and its domain.
4044 static isl_stat
test_bound_space(isl_ctx
*ctx
)
4048 isl_pw_qpolynomial
*pwqp
;
4049 isl_pw_qpolynomial_fold
*pwf
;
4051 str
= "{ [[c] -> [c]] }";
4052 set
= isl_set_read_from_str(ctx
, str
);
4053 str
= "{ [[a] -> [b]] -> 1 }";
4054 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4055 pwqp
= isl_pw_qpolynomial_intersect_domain(pwqp
, set
);
4056 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
4057 isl_pw_qpolynomial_fold_free(pwf
);
4059 return isl_stat_non_null(pwf
);
4062 /* Perform basic isl_pw_qpolynomial_bound tests.
4064 static int test_bound(isl_ctx
*ctx
)
4068 if (test_bound_space(ctx
) < 0)
4071 for (i
= 0; i
< ARRAY_SIZE(bound_tests
); ++i
) {
4074 isl_bool equal
, tight
;
4075 isl_pw_qpolynomial
*pwqp
;
4076 isl_pw_qpolynomial_fold
*pwf1
, *pwf2
;
4078 str
= bound_tests
[i
].poly
;
4079 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4080 type
= bound_tests
[i
].type
;
4081 pwf1
= isl_pw_qpolynomial_bound(pwqp
, type
, &tight
);
4082 str
= bound_tests
[i
].bound
;
4083 pwf2
= isl_pw_qpolynomial_fold_read_from_str(ctx
, str
);
4084 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf1
, pwf2
);
4085 isl_pw_qpolynomial_fold_free(pwf2
);
4086 isl_pw_qpolynomial_fold_free(pwf1
);
4090 isl_die(ctx
, isl_error_unknown
,
4091 "incorrect bound result", return -1);
4092 if (bound_tests
[i
].tight
&& !tight
)
4093 isl_die(ctx
, isl_error_unknown
,
4094 "bound unexpectedly not tight", return -1);
4100 /* isl_set is defined to isl_map internally, so the corresponding elements
4101 * are isl_basic_map objects.
4105 #define EL_BASE basic_map
4106 #define SET_BASE set
4107 #include "isl_test_list_templ.c"
4111 #define EL_BASE basic_set
4112 #define SET_BASE union_set
4113 #include "isl_test_list_templ.c"
4118 #define SET_BASE union_set
4119 #include "isl_test_list_templ.c"
4123 #define EL_BASE basic_map
4124 #define SET_BASE map
4125 #include "isl_test_list_templ.c"
4130 #define SET_BASE union_map
4131 #include "isl_test_list_templ.c"
4133 /* Check that the conversion from isl objects to lists works as expected.
4135 static int test_get_list(isl_ctx
*ctx
)
4137 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
4139 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
4141 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
4143 if (test_get_list_basic_map_from_map(ctx
,
4144 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
4146 if (test_get_list_map_from_union_map(ctx
,
4147 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
4153 static int test_lift(isl_ctx
*ctx
)
4156 isl_basic_map
*bmap
;
4157 isl_basic_set
*bset
;
4159 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
4160 bset
= isl_basic_set_read_from_str(ctx
, str
);
4161 bset
= isl_basic_set_lift(bset
);
4162 bmap
= isl_basic_map_from_range(bset
);
4163 bset
= isl_basic_map_domain(bmap
);
4164 isl_basic_set_free(bset
);
4169 /* Check that isl_set_is_subset is not confused by identical
4170 * integer divisions.
4171 * The call to isl_set_normalize ensures that the equality constraints
4172 * a = b = 0 are discovered, turning e0 and e1 into identical
4173 * integer divisions. Any further simplification would remove
4174 * the duplicate integer divisions.
4176 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
4180 isl_set
*set1
, *set2
;
4182 str
= "{ [a, b, c, d] : "
4183 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4184 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4185 "e3 = floor((-d + 4*floor((d)/4))/10): "
4186 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4187 "b >= 0 and a <= 0 and b <= a) }";
4188 set1
= isl_set_read_from_str(ctx
, str
);
4189 set2
= isl_set_read_from_str(ctx
, str
);
4190 set2
= isl_set_normalize(set2
);
4192 is_subset
= isl_set_is_subset(set1
, set2
);
4198 return isl_stat_error
;
4200 isl_die(ctx
, isl_error_unknown
,
4201 "set is not considered to be a subset of itself",
4202 return isl_stat_error
);
4211 } subset_tests
[] = {
4213 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4214 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4215 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4217 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4218 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4219 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4220 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4221 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4222 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4223 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4224 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4225 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4226 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4227 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4228 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4229 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4230 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4231 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4232 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4233 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4234 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4235 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4236 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4237 "4e0 <= -57 + i0 + i1)) or "
4238 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4239 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4240 "4e0 >= -61 + i0 + i1)) or "
4241 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4242 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4245 static int test_subset(isl_ctx
*ctx
)
4248 isl_set
*set1
, *set2
;
4251 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
4254 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
4255 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
4256 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
4257 subset
= isl_set_is_subset(set1
, set2
);
4262 if (subset
!= subset_tests
[i
].subset
)
4263 isl_die(ctx
, isl_error_unknown
,
4264 "incorrect subset result", return -1);
4270 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4271 * Older versions of isl would fail on such cases.
4273 static isl_stat
test_subtract_empty(isl_ctx
*ctx
)
4278 s1
= isl_set_read_from_str(ctx
, "{ [0] }");
4279 str
= "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4280 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4281 "33e2 >= -a + 33e0 + 1056e1 and "
4282 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4283 s2
= isl_set_read_from_str(ctx
, str
);
4284 s1
= isl_set_subtract(s1
, s2
);
4287 return isl_stat_non_null(s1
);
4291 const char *minuend
;
4292 const char *subtrahend
;
4293 const char *difference
;
4294 } subtract_domain_tests
[] = {
4295 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4296 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4297 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4300 static int test_subtract(isl_ctx
*ctx
)
4303 isl_union_map
*umap1
, *umap2
;
4304 isl_union_pw_multi_aff
*upma1
, *upma2
;
4305 isl_union_set
*uset
;
4308 if (test_subtract_empty(ctx
) < 0)
4311 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4312 umap1
= isl_union_map_read_from_str(ctx
,
4313 subtract_domain_tests
[i
].minuend
);
4314 uset
= isl_union_set_read_from_str(ctx
,
4315 subtract_domain_tests
[i
].subtrahend
);
4316 umap2
= isl_union_map_read_from_str(ctx
,
4317 subtract_domain_tests
[i
].difference
);
4318 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
4319 equal
= isl_union_map_is_equal(umap1
, umap2
);
4320 isl_union_map_free(umap1
);
4321 isl_union_map_free(umap2
);
4325 isl_die(ctx
, isl_error_unknown
,
4326 "incorrect subtract domain result", return -1);
4329 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4330 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4331 subtract_domain_tests
[i
].minuend
);
4332 uset
= isl_union_set_read_from_str(ctx
,
4333 subtract_domain_tests
[i
].subtrahend
);
4334 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4335 subtract_domain_tests
[i
].difference
);
4336 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
4337 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
4338 isl_union_pw_multi_aff_free(upma1
);
4339 isl_union_pw_multi_aff_free(upma2
);
4343 isl_die(ctx
, isl_error_unknown
,
4344 "incorrect subtract domain result", return -1);
4350 /* Check that intersecting the empty basic set with another basic set
4351 * does not increase the number of constraints. In particular,
4352 * the empty basic set should maintain its canonical representation.
4354 static int test_intersect_1(isl_ctx
*ctx
)
4357 isl_basic_set
*bset1
, *bset2
;
4359 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
4360 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
4361 n1
= isl_basic_set_n_constraint(bset1
);
4362 bset1
= isl_basic_set_intersect(bset1
, bset2
);
4363 n2
= isl_basic_set_n_constraint(bset1
);
4364 isl_basic_set_free(bset1
);
4365 if (n1
< 0 || n2
< 0)
4368 isl_die(ctx
, isl_error_unknown
,
4369 "number of constraints of empty set changed",
4375 /* Check that intersecting a set with itself does not cause
4376 * an explosion in the number of disjuncts.
4378 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
4383 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
4384 for (i
= 0; i
< 100; ++i
)
4385 set
= isl_set_intersect(set
, isl_set_copy(set
));
4388 return isl_stat_error
;
4392 /* Perform some intersection tests.
4394 static int test_intersect(isl_ctx
*ctx
)
4396 if (test_intersect_1(ctx
) < 0)
4398 if (test_intersect_2(ctx
) < 0)
4404 int test_factorize(isl_ctx
*ctx
)
4407 isl_basic_set
*bset
;
4410 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4411 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4412 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4413 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4414 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4415 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4416 "3i5 >= -2i0 - i2 + 3i4 }";
4417 bset
= isl_basic_set_read_from_str(ctx
, str
);
4418 f
= isl_basic_set_factorizer(bset
);
4419 isl_basic_set_free(bset
);
4420 isl_factorizer_free(f
);
4422 isl_die(ctx
, isl_error_unknown
,
4423 "failed to construct factorizer", return -1);
4425 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4426 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4427 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4428 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4429 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4430 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4431 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4432 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4433 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4434 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4435 bset
= isl_basic_set_read_from_str(ctx
, str
);
4436 f
= isl_basic_set_factorizer(bset
);
4437 isl_basic_set_free(bset
);
4438 isl_factorizer_free(f
);
4440 isl_die(ctx
, isl_error_unknown
,
4441 "failed to construct factorizer", return -1);
4446 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
4448 int *injective
= user
;
4450 *injective
= isl_map_is_injective(map
);
4453 if (*injective
< 0 || !*injective
)
4454 return isl_stat_error
;
4459 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
4460 const char *r
, const char *s
, int tilable
, int parallel
)
4464 isl_union_map
*W
, *R
, *S
;
4465 isl_union_map
*empty
;
4466 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
4467 isl_union_map
*validity
, *proximity
, *coincidence
;
4468 isl_union_map
*schedule
;
4469 isl_union_map
*test
;
4470 isl_union_set
*delta
;
4471 isl_union_set
*domain
;
4475 isl_schedule_constraints
*sc
;
4476 isl_schedule
*sched
;
4477 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
4480 D
= isl_union_set_read_from_str(ctx
, d
);
4481 W
= isl_union_map_read_from_str(ctx
, w
);
4482 R
= isl_union_map_read_from_str(ctx
, r
);
4483 S
= isl_union_map_read_from_str(ctx
, s
);
4485 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4486 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4488 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4489 isl_union_map_compute_flow(isl_union_map_copy(R
),
4490 isl_union_map_copy(W
), empty
,
4491 isl_union_map_copy(S
),
4492 &dep_raw
, NULL
, NULL
, NULL
);
4493 isl_union_map_compute_flow(isl_union_map_copy(W
),
4494 isl_union_map_copy(W
),
4495 isl_union_map_copy(R
),
4496 isl_union_map_copy(S
),
4497 &dep_waw
, &dep_war
, NULL
, NULL
);
4499 dep
= isl_union_map_union(dep_waw
, dep_war
);
4500 dep
= isl_union_map_union(dep
, dep_raw
);
4501 validity
= isl_union_map_copy(dep
);
4502 coincidence
= isl_union_map_copy(dep
);
4503 proximity
= isl_union_map_copy(dep
);
4505 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4506 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4507 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4508 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4509 sched
= isl_schedule_constraints_compute_schedule(sc
);
4510 schedule
= isl_schedule_get_map(sched
);
4511 isl_schedule_free(sched
);
4512 isl_union_map_free(W
);
4513 isl_union_map_free(R
);
4514 isl_union_map_free(S
);
4517 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4519 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4520 is_complete
= isl_union_set_is_subset(D
, domain
);
4521 isl_union_set_free(D
);
4522 isl_union_set_free(domain
);
4524 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4525 test
= isl_union_map_apply_range(test
, dep
);
4526 test
= isl_union_map_apply_range(test
, schedule
);
4528 delta
= isl_union_map_deltas(test
);
4529 n
= isl_union_set_n_set(delta
);
4531 isl_union_set_free(delta
);
4538 isl_union_set_free(delta
);
4542 delta_set
= isl_set_from_union_set(delta
);
4544 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4545 for (i
= 0; i
< tilable
; ++i
)
4546 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4547 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4548 isl_set_free(slice
);
4550 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4551 for (i
= 0; i
< parallel
; ++i
)
4552 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4553 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4554 isl_set_free(slice
);
4556 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4557 dim
= isl_set_dim(origin
, isl_dim_set
);
4559 origin
= isl_set_free(origin
);
4560 for (i
= 0; i
< dim
; ++i
)
4561 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4563 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4564 delta_set
= isl_set_lexmin(delta_set
);
4566 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4568 isl_set_free(origin
);
4569 isl_set_free(delta_set
);
4572 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4573 is_injection
< 0 || is_complete
< 0)
4576 isl_die(ctx
, isl_error_unknown
,
4577 "generated schedule incomplete", return -1);
4579 isl_die(ctx
, isl_error_unknown
,
4580 "generated schedule not injective on each statement",
4583 isl_die(ctx
, isl_error_unknown
,
4584 "negative dependences in generated schedule",
4587 isl_die(ctx
, isl_error_unknown
,
4588 "generated schedule not as tilable as expected",
4591 isl_die(ctx
, isl_error_unknown
,
4592 "generated schedule not as parallel as expected",
4598 /* Compute a schedule for the given instance set, validity constraints,
4599 * proximity constraints and context and return a corresponding union map
4602 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4603 const char *domain
, const char *validity
, const char *proximity
,
4604 const char *context
)
4609 isl_union_map
*prox
;
4610 isl_schedule_constraints
*sc
;
4611 isl_schedule
*schedule
;
4612 isl_union_map
*sched
;
4614 con
= isl_set_read_from_str(ctx
, context
);
4615 dom
= isl_union_set_read_from_str(ctx
, domain
);
4616 dep
= isl_union_map_read_from_str(ctx
, validity
);
4617 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4618 sc
= isl_schedule_constraints_on_domain(dom
);
4619 sc
= isl_schedule_constraints_set_context(sc
, con
);
4620 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4621 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4622 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4623 sched
= isl_schedule_get_map(schedule
);
4624 isl_schedule_free(schedule
);
4629 /* Compute a schedule for the given instance set, validity constraints and
4630 * proximity constraints and return a corresponding union map representation.
4632 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4633 const char *domain
, const char *validity
, const char *proximity
)
4635 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4639 /* Check that a schedule can be constructed on the given domain
4640 * with the given validity and proximity constraints.
4642 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4643 const char *validity
, const char *proximity
)
4645 isl_union_map
*sched
;
4647 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4651 isl_union_map_free(sched
);
4655 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4656 const char *validity
, const char *proximity
, const char *expected_sched
)
4658 isl_union_map
*sched1
, *sched2
;
4661 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4662 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4664 equal
= isl_union_map_is_equal(sched1
, sched2
);
4665 isl_union_map_free(sched1
);
4666 isl_union_map_free(sched2
);
4671 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4677 /* Check that the schedule map is properly padded, i.e., that the range
4678 * lives in a single space.
4680 static int test_padded_schedule(isl_ctx
*ctx
)
4684 isl_union_map
*validity
, *proximity
;
4685 isl_schedule_constraints
*sc
;
4686 isl_schedule
*sched
;
4687 isl_union_map
*umap
;
4688 isl_union_set
*range
;
4691 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4692 D
= isl_union_set_read_from_str(ctx
, str
);
4693 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4694 proximity
= isl_union_map_copy(validity
);
4695 sc
= isl_schedule_constraints_on_domain(D
);
4696 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4697 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4698 sched
= isl_schedule_constraints_compute_schedule(sc
);
4699 umap
= isl_schedule_get_map(sched
);
4700 isl_schedule_free(sched
);
4701 range
= isl_union_map_range(umap
);
4702 set
= isl_set_from_union_set(range
);
4711 /* Check that conditional validity constraints are also taken into
4712 * account across bands.
4713 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4714 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4715 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4716 * is enforced by the rest of the schedule.
4718 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4721 isl_union_set
*domain
;
4722 isl_union_map
*validity
, *proximity
, *condition
;
4723 isl_union_map
*sink
, *source
, *dep
;
4724 isl_schedule_constraints
*sc
;
4725 isl_schedule
*schedule
;
4726 isl_union_access_info
*access
;
4727 isl_union_flow
*flow
;
4730 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4731 "A[k] : k >= 1 and k <= -1 + n; "
4732 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4733 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4734 domain
= isl_union_set_read_from_str(ctx
, str
);
4735 sc
= isl_schedule_constraints_on_domain(domain
);
4736 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4737 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4738 "D[k, i] -> C[1 + k, i] : "
4739 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4740 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4741 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4742 validity
= isl_union_map_read_from_str(ctx
, str
);
4743 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4744 str
= "[n] -> { C[k, i] -> D[k, i] : "
4745 "0 <= i <= -1 + k and k <= -1 + n }";
4746 proximity
= isl_union_map_read_from_str(ctx
, str
);
4747 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4748 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4749 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4750 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4751 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4752 condition
= isl_union_map_read_from_str(ctx
, str
);
4753 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4754 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4755 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4756 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4757 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4758 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4759 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4760 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4761 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4762 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4763 validity
= isl_union_map_read_from_str(ctx
, str
);
4764 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4766 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4767 str
= "{ D[2,0] -> [] }";
4768 sink
= isl_union_map_read_from_str(ctx
, str
);
4769 access
= isl_union_access_info_from_sink(sink
);
4770 str
= "{ C[2,1] -> [] }";
4771 source
= isl_union_map_read_from_str(ctx
, str
);
4772 access
= isl_union_access_info_set_must_source(access
, source
);
4773 access
= isl_union_access_info_set_schedule(access
, schedule
);
4774 flow
= isl_union_access_info_compute_flow(access
);
4775 dep
= isl_union_flow_get_must_dependence(flow
);
4776 isl_union_flow_free(flow
);
4777 empty
= isl_union_map_is_empty(dep
);
4778 isl_union_map_free(dep
);
4783 isl_die(ctx
, isl_error_unknown
,
4784 "conditional validity not respected", return -1);
4789 /* Check that the test for violated conditional validity constraints
4790 * is not confused by domain compression.
4791 * In particular, earlier versions of isl would apply
4792 * a schedule on the compressed domains to the original domains,
4793 * resulting in a failure to detect that the default schedule
4794 * violates the conditional validity constraints.
4796 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4800 isl_union_set
*domain
;
4801 isl_union_map
*validity
, *condition
;
4802 isl_schedule_constraints
*sc
;
4803 isl_schedule
*schedule
;
4804 isl_union_map
*umap
;
4807 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4808 domain
= isl_union_set_read_from_str(ctx
, str
);
4809 sc
= isl_schedule_constraints_on_domain(domain
);
4810 str
= "{ B[1, i] -> A[0, i + 1] }";
4811 condition
= isl_union_map_read_from_str(ctx
, str
);
4812 str
= "{ A[0, i] -> B[1, i - 1] }";
4813 validity
= isl_union_map_read_from_str(ctx
, str
);
4814 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4815 isl_union_map_copy(validity
));
4816 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4817 umap
= isl_schedule_get_map(schedule
);
4818 isl_schedule_free(schedule
);
4819 validity
= isl_union_map_apply_domain(validity
,
4820 isl_union_map_copy(umap
));
4821 validity
= isl_union_map_apply_range(validity
, umap
);
4822 map
= isl_map_from_union_map(validity
);
4823 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4824 map
= isl_map_intersect(map
, ge
);
4825 empty
= isl_map_is_empty(map
);
4831 isl_die(ctx
, isl_error_unknown
,
4832 "conditional validity constraints not satisfied",
4838 /* Input for testing of schedule construction based on
4839 * conditional constraints.
4841 * domain is the iteration domain
4842 * flow are the flow dependences, which determine the validity and
4843 * proximity constraints
4844 * condition are the conditions on the conditional validity constraints
4845 * conditional_validity are the conditional validity constraints
4846 * outer_band_n is the expected number of members in the outer band
4851 const char *condition
;
4852 const char *conditional_validity
;
4854 } live_range_tests
[] = {
4855 /* Contrived example that illustrates that we need to keep
4856 * track of tagged condition dependences and
4857 * tagged conditional validity dependences
4858 * in isl_sched_edge separately.
4859 * In particular, the conditional validity constraints on A
4860 * cannot be satisfied,
4861 * but they can be ignored because there are no corresponding
4862 * condition constraints. However, we do have an additional
4863 * conditional validity constraint that maps to the same
4864 * dependence relation
4865 * as the condition constraint on B. If we did not make a distinction
4866 * between tagged condition and tagged conditional validity
4867 * dependences, then we
4868 * could end up treating this shared dependence as an condition
4869 * constraint on A, forcing a localization of the conditions,
4870 * which is impossible.
4872 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4873 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4874 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4875 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4876 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4877 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4880 /* TACO 2013 Fig. 7 */
4881 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4882 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4883 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4884 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4885 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4886 "0 <= i < n and 0 <= j < n - 1 }",
4887 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4888 "0 <= i < n and 0 <= j < j' < n;"
4889 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4890 "0 <= i < i' < n and 0 <= j,j' < n;"
4891 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4892 "0 <= i,j,j' < n and j < j' }",
4895 /* TACO 2013 Fig. 7, without tags */
4896 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4897 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4898 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4899 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4900 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4901 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4902 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4903 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4906 /* TACO 2013 Fig. 12 */
4907 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4908 "S3[i,3] : 0 <= i <= 1 }",
4909 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4910 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4911 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4912 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4913 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4914 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4915 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4916 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4917 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4918 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4919 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4924 /* Test schedule construction based on conditional constraints.
4925 * In particular, check the number of members in the outer band node
4926 * as an indication of whether tiling is possible or not.
4928 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4931 isl_union_set
*domain
;
4932 isl_union_map
*condition
;
4933 isl_union_map
*flow
;
4934 isl_union_map
*validity
;
4935 isl_schedule_constraints
*sc
;
4936 isl_schedule
*schedule
;
4937 isl_schedule_node
*node
;
4940 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4942 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4945 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4946 domain
= isl_union_set_read_from_str(ctx
,
4947 live_range_tests
[i
].domain
);
4948 flow
= isl_union_map_read_from_str(ctx
,
4949 live_range_tests
[i
].flow
);
4950 condition
= isl_union_map_read_from_str(ctx
,
4951 live_range_tests
[i
].condition
);
4952 validity
= isl_union_map_read_from_str(ctx
,
4953 live_range_tests
[i
].conditional_validity
);
4954 sc
= isl_schedule_constraints_on_domain(domain
);
4955 sc
= isl_schedule_constraints_set_validity(sc
,
4956 isl_union_map_copy(flow
));
4957 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4958 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4959 condition
, validity
);
4960 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4961 node
= isl_schedule_get_root(schedule
);
4963 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4964 node
= isl_schedule_node_first_child(node
);
4965 n_member
= isl_schedule_node_band_n_member(node
);
4966 isl_schedule_node_free(node
);
4967 isl_schedule_free(schedule
);
4969 if (!schedule
|| n_member
< 0)
4971 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4972 isl_die(ctx
, isl_error_unknown
,
4973 "unexpected number of members in outer band",
4979 /* Check that the schedule computed for the given instance set and
4980 * dependence relation strongly satisfies the dependences.
4981 * In particular, check that no instance is scheduled before
4982 * or together with an instance on which it depends.
4983 * Earlier versions of isl would produce a schedule that
4984 * only weakly satisfies the dependences.
4986 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4988 const char *domain
, *dep
;
4989 isl_union_map
*D
, *schedule
;
4993 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4994 "A[i0] : 0 <= i0 <= 1 }";
4995 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4996 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4997 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4998 D
= isl_union_map_read_from_str(ctx
, dep
);
4999 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
5000 D
= isl_union_map_apply_range(D
, schedule
);
5001 map
= isl_map_from_union_map(D
);
5002 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
5003 map
= isl_map_intersect(map
, ge
);
5004 empty
= isl_map_is_empty(map
);
5010 isl_die(ctx
, isl_error_unknown
,
5011 "dependences not strongly satisfied", return -1);
5016 /* Compute a schedule for input where the instance set constraints
5017 * conflict with the context constraints.
5018 * Earlier versions of isl did not properly handle this situation.
5020 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
5022 isl_union_map
*schedule
;
5023 const char *domain
, *context
;
5025 domain
= "[n] -> { A[] : n >= 0 }";
5026 context
= "[n] -> { : n < 0 }";
5027 schedule
= compute_schedule_with_context(ctx
,
5028 domain
, "{}", "{}", context
);
5029 isl_union_map_free(schedule
);
5037 /* Check that a set of schedule constraints that only allow for
5038 * a coalescing schedule still produces a schedule even if the user
5039 * request a non-coalescing schedule. Earlier versions of isl
5040 * would not handle this case correctly.
5042 static int test_coalescing_schedule(isl_ctx
*ctx
)
5044 const char *domain
, *dep
;
5047 isl_schedule_constraints
*sc
;
5048 isl_schedule
*schedule
;
5049 int treat_coalescing
;
5051 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
5052 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
5053 I
= isl_union_set_read_from_str(ctx
, domain
);
5054 D
= isl_union_map_read_from_str(ctx
, dep
);
5055 sc
= isl_schedule_constraints_on_domain(I
);
5056 sc
= isl_schedule_constraints_set_validity(sc
, D
);
5057 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5058 isl_options_set_schedule_treat_coalescing(ctx
, 1);
5059 schedule
= isl_schedule_constraints_compute_schedule(sc
);
5060 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5061 isl_schedule_free(schedule
);
5067 /* Check that the scheduler does not perform any needless
5068 * compound skewing. Earlier versions of isl would compute
5069 * schedules in terms of transformed schedule coefficients and
5070 * would not accurately keep track of the sum of the original
5071 * schedule coefficients. It could then produce the schedule
5072 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
5073 * for the input below instead of the schedule below.
5075 static int test_skewing_schedule(isl_ctx
*ctx
)
5077 const char *D
, *V
, *P
, *S
;
5079 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
5080 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
5081 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
5082 "-1 <= a-i + b-j + c-k <= 1 }";
5084 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
5086 return test_special_schedule(ctx
, D
, V
, P
, S
);
5089 int test_schedule(isl_ctx
*ctx
)
5091 const char *D
, *W
, *R
, *V
, *P
, *S
;
5092 int max_coincidence
;
5093 int treat_coalescing
;
5095 /* Handle resulting schedule with zero bands. */
5096 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
5100 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
5101 W
= "{ S1[t,i] -> a[t,i] }";
5102 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
5103 "S1[t,i] -> a[t-1,i+1] }";
5104 S
= "{ S1[t,i] -> [t,i] }";
5105 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5108 /* Fig. 5 of CC2008 */
5109 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
5111 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
5112 "j >= 2 and j <= -1 + N }";
5113 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
5114 "j >= 2 and j <= -1 + N; "
5115 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
5116 "j >= 2 and j <= -1 + N }";
5117 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5118 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5121 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
5122 W
= "{ S1[i] -> a[i] }";
5123 R
= "{ S2[i] -> a[i+1] }";
5124 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5125 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5128 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
5129 W
= "{ S1[i] -> a[i] }";
5130 R
= "{ S2[i] -> a[9-i] }";
5131 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5132 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5135 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
5136 W
= "{ S1[i] -> a[i] }";
5137 R
= "[N] -> { S2[i] -> a[N-1-i] }";
5138 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5139 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5142 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
5143 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
5144 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
5145 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
5146 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5149 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5150 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
5151 R
= "{ S2[i,j] -> a[i-1,j] }";
5152 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5153 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5156 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5157 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
5158 R
= "{ S2[i,j] -> a[i,j-1] }";
5159 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5160 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5163 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5164 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5165 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5166 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5167 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5168 "S_0[] -> [0, 0, 0] }";
5169 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
5171 ctx
->opt
->schedule_parametric
= 0;
5172 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5174 ctx
->opt
->schedule_parametric
= 1;
5176 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5177 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5178 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5179 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5180 "S4[i] -> a[i,N] }";
5181 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5182 "S4[i] -> [4,i,0] }";
5183 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
5184 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
5185 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5187 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
5189 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5190 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5192 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5194 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5196 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5197 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5200 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5201 " S_2[t] : t >= 0 and t <= -1 + N; "
5202 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5204 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5205 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5206 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5207 "i >= 0 and i <= -1 + N }";
5208 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5209 "i >= 0 and i <= -1 + N; "
5210 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5211 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5212 " S_0[t] -> [0, t, 0] }";
5214 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5216 ctx
->opt
->schedule_parametric
= 0;
5217 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5219 ctx
->opt
->schedule_parametric
= 1;
5221 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5222 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5223 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
5226 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5227 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5228 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5229 "j >= 0 and j <= -1 + N; "
5230 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5231 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5232 "j >= 0 and j <= -1 + N; "
5233 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5234 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5235 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5238 D
= "{ S_0[i] : i >= 0 }";
5239 W
= "{ S_0[i] -> a[i] : i >= 0 }";
5240 R
= "{ S_0[i] -> a[0] : i >= 0 }";
5241 S
= "{ S_0[i] -> [0, i, 0] }";
5242 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5245 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5246 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5247 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5248 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5249 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5252 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5253 "k <= -1 + n and k >= 0 }";
5254 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5255 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5256 "k <= -1 + n and k >= 0; "
5257 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5258 "k <= -1 + n and k >= 0; "
5259 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5260 "k <= -1 + n and k >= 0 }";
5261 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
5262 ctx
->opt
->schedule_outer_coincidence
= 1;
5263 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5265 ctx
->opt
->schedule_outer_coincidence
= 0;
5267 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
5268 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5269 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5270 "Stmt_for_body24[i0, i1, 1, 0]:"
5271 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5272 "Stmt_for_body7[i0, i1, i2]:"
5273 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5276 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
5277 "Stmt_for_body24[1, i1, i2, i3]:"
5278 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5280 "Stmt_for_body24[0, i1, i2, i3] -> "
5281 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5282 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5284 "Stmt_for_body24[0, i1, i2, i3] ->"
5285 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5286 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5287 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5288 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5289 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5290 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5291 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5292 "i1 <= 6 and i1 >= 0;"
5293 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5294 "Stmt_for_body7[i0, i1, i2] -> "
5295 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5296 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5297 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5298 "Stmt_for_body7[i0, i1, i2] -> "
5299 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5300 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5301 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5304 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5305 isl_options_set_schedule_treat_coalescing(ctx
, 0);
5306 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5308 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5310 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5311 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5312 "j >= 1 and j <= 7;"
5313 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5314 "j >= 1 and j <= 8 }";
5316 S
= "{ S_0[i, j] -> [i + j, i] }";
5317 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5318 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5320 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5322 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5323 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5324 "j >= 0 and j <= -1 + i }";
5325 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5326 "i <= -1 + N and j >= 0;"
5327 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5330 S
= "{ S_0[i, j] -> [i, j] }";
5331 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5332 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5334 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5336 /* Test both algorithms on a case with only proximity dependences. */
5337 D
= "{ S[i,j] : 0 <= i <= 10 }";
5339 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5340 S
= "{ S[i, j] -> [j, i] }";
5341 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5342 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5344 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5345 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5348 D
= "{ A[a]; B[] }";
5350 P
= "{ A[a] -> B[] }";
5351 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5354 if (test_padded_schedule(ctx
) < 0)
5357 /* Check that check for progress is not confused by rational
5360 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5361 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5363 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5364 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5366 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5367 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5369 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5371 /* Check that we allow schedule rows that are only non-trivial
5372 * on some full-dimensional domains.
5374 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5375 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5376 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5378 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5379 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5381 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5383 if (test_conditional_schedule_constraints(ctx
) < 0)
5386 if (test_strongly_satisfying_schedule(ctx
) < 0)
5389 if (test_conflicting_context_schedule(ctx
) < 0)
5392 if (test_coalescing_schedule(ctx
) < 0)
5394 if (test_skewing_schedule(ctx
) < 0)
5400 /* Perform scheduling tests using the whole component scheduler.
5402 static int test_schedule_whole(isl_ctx
*ctx
)
5407 whole
= isl_options_get_schedule_whole_component(ctx
);
5408 isl_options_set_schedule_whole_component(ctx
, 1);
5409 r
= test_schedule(ctx
);
5410 isl_options_set_schedule_whole_component(ctx
, whole
);
5415 /* Perform scheduling tests using the incremental scheduler.
5417 static int test_schedule_incremental(isl_ctx
*ctx
)
5422 whole
= isl_options_get_schedule_whole_component(ctx
);
5423 isl_options_set_schedule_whole_component(ctx
, 0);
5424 r
= test_schedule(ctx
);
5425 isl_options_set_schedule_whole_component(ctx
, whole
);
5430 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
5432 isl_union_map
*umap
;
5435 umap
= isl_union_map_read_from_str(ctx
, str
);
5436 test
= isl_union_map_plain_is_injective(umap
);
5437 isl_union_map_free(umap
);
5440 if (test
== injective
)
5443 isl_die(ctx
, isl_error_unknown
,
5444 "map not detected as injective", return -1);
5446 isl_die(ctx
, isl_error_unknown
,
5447 "map detected as injective", return -1);
5450 int test_injective(isl_ctx
*ctx
)
5454 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5456 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
5458 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
5460 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
5462 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5464 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5466 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5468 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5471 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5472 if (test_plain_injective(ctx
, str
, 1))
5474 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5475 if (test_plain_injective(ctx
, str
, 0))
5483 #include "isl_test_plain_equal_templ.c"
5486 #define BASE pw_multi_aff
5487 #include "isl_test_plain_equal_templ.c"
5490 #define BASE union_pw_aff
5491 #include "isl_test_plain_equal_templ.c"
5493 /* Basic tests on isl_union_pw_aff.
5495 * In particular, check that isl_union_pw_aff_aff_on_domain
5496 * aligns the parameters of the input objects and
5497 * that isl_union_pw_aff_param_on_domain_id properly
5498 * introduces the parameter.
5500 static int test_upa(isl_ctx
*ctx
)
5505 isl_union_set
*domain
;
5506 isl_union_pw_aff
*upa
;
5509 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5510 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5511 domain
= isl_union_set_read_from_str(ctx
, str
);
5512 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5513 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5514 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5515 isl_union_pw_aff_free(upa
);
5519 id
= isl_id_alloc(ctx
, "N", NULL
);
5520 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5521 domain
= isl_union_set_read_from_str(ctx
, str
);
5522 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5523 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5524 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5525 isl_union_pw_aff_free(upa
);
5533 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5534 __isl_take isl_aff
*aff2
);
5536 ['+'] = { &isl_aff_add
},
5537 ['-'] = { &isl_aff_sub
},
5538 ['*'] = { &isl_aff_mul
},
5539 ['/'] = { &isl_aff_div
},
5547 } aff_bin_tests
[] = {
5548 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5549 "{ [i] -> [2i] }" },
5550 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5552 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5553 "{ [i] -> [2i] }" },
5554 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5555 "{ [i] -> [2i] }" },
5556 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5557 "{ [i] -> [i/2] }" },
5558 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5560 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5561 "{ [i] -> [NaN] }" },
5562 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5563 "{ [i] -> [NaN] }" },
5564 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5565 "{ [i] -> [NaN] }" },
5566 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5567 "{ [i] -> [NaN] }" },
5568 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5569 "{ [i] -> [NaN] }" },
5570 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5571 "{ [i] -> [NaN] }" },
5572 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5573 "{ [i] -> [NaN] }" },
5574 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5575 "{ [i] -> [NaN] }" },
5576 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5577 "{ [i] -> [NaN] }" },
5578 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5579 "{ [i] -> [NaN] }" },
5580 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5581 "{ [i] -> [NaN] }" },
5582 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5583 "{ [i] -> [NaN] }" },
5584 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5585 "{ [i] -> [NaN] }" },
5588 /* Perform some basic tests of binary operations on isl_aff objects.
5590 static int test_bin_aff(isl_ctx
*ctx
)
5593 isl_aff
*aff1
, *aff2
, *res
;
5594 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5595 __isl_take isl_aff
*aff2
);
5598 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5599 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5600 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5601 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5602 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5603 aff1
= fn(aff1
, aff2
);
5604 if (isl_aff_is_nan(res
))
5605 ok
= isl_aff_is_nan(aff1
);
5607 ok
= isl_aff_plain_is_equal(aff1
, res
);
5613 isl_die(ctx
, isl_error_unknown
,
5614 "unexpected result", return -1);
5621 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5622 __isl_take isl_pw_aff
*pa2
);
5623 } pw_aff_bin_op
[] = {
5624 ['m'] = { &isl_pw_aff_min
},
5625 ['M'] = { &isl_pw_aff_max
},
5628 /* Inputs for binary isl_pw_aff operation tests.
5629 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5630 * defined by pw_aff_bin_op, and "res" is the expected result.
5637 } pw_aff_bin_tests
[] = {
5638 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5640 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5642 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5643 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5644 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5645 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5646 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5647 "{ [i] -> [NaN] }" },
5648 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5649 "{ [i] -> [NaN] }" },
5652 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5654 static int test_bin_pw_aff(isl_ctx
*ctx
)
5658 isl_pw_aff
*pa1
, *pa2
, *res
;
5660 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5661 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5662 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5663 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5664 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5665 if (isl_pw_aff_involves_nan(res
))
5666 ok
= isl_pw_aff_involves_nan(pa1
);
5668 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5669 isl_pw_aff_free(pa1
);
5670 isl_pw_aff_free(res
);
5674 isl_die(ctx
, isl_error_unknown
,
5675 "unexpected result", return -1);
5681 /* Inputs for basic tests of test operations on
5682 * isl_union_pw_multi_aff objects.
5683 * "fn" is the function that is being tested.
5684 * "arg" is a string description of the input.
5685 * "res" is the expected result.
5688 isl_bool (*fn
)(__isl_keep isl_union_pw_multi_aff
*upma1
);
5691 } upma_test_tests
[] = {
5692 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [1] }",
5694 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [NaN]; B[0] -> [1] }",
5696 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [NaN] }",
5698 { &isl_union_pw_multi_aff_involves_nan
,
5699 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5701 { &isl_union_pw_multi_aff_involves_locals
,
5702 "{ A[] -> [0]; B[0] -> [1] }",
5704 { &isl_union_pw_multi_aff_involves_locals
,
5705 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5707 { &isl_union_pw_multi_aff_involves_locals
,
5708 "{ A[] -> [0]; B[x] -> [x // 2] }",
5710 { &isl_union_pw_multi_aff_involves_locals
,
5711 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5715 /* Perform some basic tests of test operations on
5716 * isl_union_pw_multi_aff objects.
5718 static isl_stat
test_upma_test(isl_ctx
*ctx
)
5721 isl_union_pw_multi_aff
*upma
;
5724 for (i
= 0; i
< ARRAY_SIZE(upma_test_tests
); ++i
) {
5727 str
= upma_test_tests
[i
].arg
;
5728 upma
= isl_union_pw_multi_aff_read_from_str(ctx
, str
);
5729 res
= upma_test_tests
[i
].fn(upma
);
5730 isl_union_pw_multi_aff_free(upma
);
5732 return isl_stat_error
;
5733 if (res
!= upma_test_tests
[i
].res
)
5734 isl_die(ctx
, isl_error_unknown
,
5735 "unexpected result", return isl_stat_error
);
5742 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5743 __isl_take isl_union_pw_multi_aff
*upma1
,
5744 __isl_take isl_union_pw_multi_aff
*upma2
);
5748 } upma_bin_tests
[] = {
5749 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5750 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5751 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5752 "{ B[x] -> [2] : x >= 0 }",
5753 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5754 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5755 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5756 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5757 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5758 "D[i] -> B[2] : i >= 5 }" },
5759 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5760 "{ B[x] -> C[2] : x > 0 }",
5761 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5762 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5763 "{ B[x] -> A[2] : x >= 0 }",
5764 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5766 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5767 "{ B[x] -> C[x + 2] }",
5768 "{ D[y] -> B[2y] }",
5771 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5772 "{ [A[x] -> B[x + 1]] -> C[x + 2] }",
5773 "{ D[y] -> B[2y] }",
5776 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5777 "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5778 "{ D[y] -> A[2y] }",
5779 "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5781 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5782 "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5783 "{ D[y] -> A[2y] }",
5784 "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5787 /* Perform some basic tests of binary operations on
5788 * isl_union_pw_multi_aff objects.
5790 static int test_bin_upma(isl_ctx
*ctx
)
5793 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5796 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5797 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5798 upma_bin_tests
[i
].arg1
);
5799 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5800 upma_bin_tests
[i
].arg2
);
5801 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5802 upma_bin_tests
[i
].res
);
5803 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5804 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5805 isl_union_pw_multi_aff_free(upma1
);
5806 isl_union_pw_multi_aff_free(res
);
5810 isl_die(ctx
, isl_error_unknown
,
5811 "unexpected result", return -1);
5818 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5819 __isl_take isl_union_pw_multi_aff
*upma1
,
5820 __isl_take isl_union_pw_multi_aff
*upma2
);
5823 } upma_bin_fail_tests
[] = {
5824 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5825 "{ B[x] -> C[2] : x >= 0 }" },
5828 /* Perform some basic tests of binary operations on
5829 * isl_union_pw_multi_aff objects that are expected to fail.
5831 static int test_bin_upma_fail(isl_ctx
*ctx
)
5834 isl_union_pw_multi_aff
*upma1
, *upma2
;
5837 on_error
= isl_options_get_on_error(ctx
);
5838 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5839 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5840 for (i
= 0; i
< n
; ++i
) {
5841 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5842 upma_bin_fail_tests
[i
].arg1
);
5843 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5844 upma_bin_fail_tests
[i
].arg2
);
5845 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5846 isl_union_pw_multi_aff_free(upma1
);
5850 isl_options_set_on_error(ctx
, on_error
);
5852 isl_die(ctx
, isl_error_unknown
,
5853 "operation not expected to succeed", return -1);
5858 /* Inputs for basic tests of binary operations on
5859 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5860 * "fn" is the function that is being tested.
5861 * "arg1" and "arg2" are string descriptions of the inputs.
5862 * "res" is a string description of the expected result.
5865 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5866 __isl_take isl_union_pw_multi_aff
*upma
,
5867 __isl_take isl_union_set
*uset
);
5871 } upma_uset_tests
[] = {
5872 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5873 "{ A[i] -> B[i] }", "{ B[0] }",
5875 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain
,
5876 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5877 "{ [A[1] -> B[1]] -> C[2] }" },
5878 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5879 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5880 "{ [A[0] -> B[0]] -> C[1] }" },
5881 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5882 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5883 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5884 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5885 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5886 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5887 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5888 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5890 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5893 /* Perform some basic tests of binary operations on
5894 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5896 static isl_stat
test_upma_uset(isl_ctx
*ctx
)
5900 isl_union_pw_multi_aff
*upma
, *res
;
5901 isl_union_set
*uset
;
5903 for (i
= 0; i
< ARRAY_SIZE(upma_uset_tests
); ++i
) {
5904 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5905 upma_uset_tests
[i
].arg1
);
5906 uset
= isl_union_set_read_from_str(ctx
,
5907 upma_uset_tests
[i
].arg2
);
5908 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5909 upma_uset_tests
[i
].res
);
5910 upma
= upma_uset_tests
[i
].fn(upma
, uset
);
5911 ok
= isl_union_pw_multi_aff_plain_is_equal(upma
, res
);
5912 isl_union_pw_multi_aff_free(upma
);
5913 isl_union_pw_multi_aff_free(res
);
5915 return isl_stat_error
;
5917 isl_die(ctx
, isl_error_unknown
,
5918 "unexpected result", return isl_stat_error
);
5924 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5925 * "fn" is the function that is tested.
5926 * "arg" is a string description of the input.
5927 * "res" is a string description of the expected result.
5930 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5933 } mpa_un_tests
[] = {
5934 { &isl_multi_pw_aff_range_factor_domain
,
5935 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5936 "{ A[x] -> B[(1 : x >= 5)] }" },
5937 { &isl_multi_pw_aff_range_factor_range
,
5938 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5939 "{ A[y] -> C[(2 : y <= 10)] }" },
5940 { &isl_multi_pw_aff_range_factor_domain
,
5941 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5942 "{ A[x] -> B[(1 : x >= 5)] }" },
5943 { &isl_multi_pw_aff_range_factor_range
,
5944 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5945 "{ A[y] -> C[] }" },
5946 { &isl_multi_pw_aff_range_factor_domain
,
5947 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5948 "{ A[x] -> B[] }" },
5949 { &isl_multi_pw_aff_range_factor_range
,
5950 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5951 "{ A[y] -> C[(2 : y <= 10)] }" },
5952 { &isl_multi_pw_aff_range_factor_domain
,
5953 "{ A[x] -> [B[] -> C[]] }",
5954 "{ A[x] -> B[] }" },
5955 { &isl_multi_pw_aff_range_factor_range
,
5956 "{ A[x] -> [B[] -> C[]] }",
5957 "{ A[y] -> C[] }" },
5958 { &isl_multi_pw_aff_factor_range
,
5961 { &isl_multi_pw_aff_range_factor_domain
,
5962 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5963 "{ A[x] -> B[] : x >= 0 }" },
5964 { &isl_multi_pw_aff_range_factor_range
,
5965 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5966 "{ A[y] -> C[] : y >= 0 }" },
5967 { &isl_multi_pw_aff_factor_range
,
5968 "[N] -> { [B[] -> C[]] : N >= 0 }",
5969 "[N] -> { C[] : N >= 0 }" },
5972 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5974 static int test_un_mpa(isl_ctx
*ctx
)
5978 isl_multi_pw_aff
*mpa
, *res
;
5980 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5981 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5982 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5983 mpa
= mpa_un_tests
[i
].fn(mpa
);
5984 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5985 isl_multi_pw_aff_free(mpa
);
5986 isl_multi_pw_aff_free(res
);
5990 isl_die(ctx
, isl_error_unknown
,
5991 "unexpected result", return -1);
5997 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5998 * "fn" is the function that is tested.
5999 * "arg1" and "arg2" are string descriptions of the inputs.
6000 * "res" is a string description of the expected result.
6003 __isl_give isl_multi_pw_aff
*(*fn
)(
6004 __isl_take isl_multi_pw_aff
*mpa1
,
6005 __isl_take isl_multi_pw_aff
*mpa2
);
6009 } mpa_bin_tests
[] = {
6010 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
6012 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
6013 "{ A[x] -> [(x : x <= 10)] }",
6014 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
6015 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
6016 "{ A[x] -> [] : x <= 10 }",
6017 "{ A[x] -> [] : 5 <= x <= 10 }" },
6018 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
6019 "[N] -> { A[x] -> [] : x <= N }",
6020 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
6021 { &isl_multi_pw_aff_add
,
6022 "[N] -> { A[x] -> [] : x <= N }",
6023 "{ A[x] -> [] : x >= 5 }",
6024 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
6025 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6026 "{ A[y] -> C[(2 : y <= 10)] }",
6027 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
6028 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
6029 "{ A[y] -> C[2] : y <= 10 }",
6030 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
6031 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
6032 "[N] -> { A[y] -> C[2] : y <= N }",
6033 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
6034 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
6035 "{ A[y] -> C[2] : y <= 10 }",
6036 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
6037 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6038 "{ A[] -> [B[1] -> C[2]] }" },
6039 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6040 "{ A[] -> [B[] -> C[]] }" },
6041 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6042 "{ A[y] -> C[] : y <= 10 }",
6043 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
6044 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
6045 "{ A[x] -> B[(1 : x >= 5)] }",
6046 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
6047 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6048 "{ A[y] -> C[(2 : y <= 10)] }",
6049 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
6050 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6051 "{ A[y] -> C[] : y <= 10 }",
6052 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
6053 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
6054 "{ A[x] -> B[(1 : x >= 5)] }",
6055 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
6056 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6057 "[N] -> { A[y] -> C[] : y <= N }",
6058 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
6059 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
6060 "{ A[x] -> B[(1 : x >= 5)] }",
6061 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
6062 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
6063 "{ A[y] -> C[] : y <= 10 }",
6064 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
6065 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6066 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
6067 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6068 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
6069 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6070 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
6071 "{ A[a,b] -> C[b + 2a] }" },
6072 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6073 "{ B[i,j] -> C[i + 2j] }",
6074 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6075 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
6076 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6077 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
6078 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6079 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
6080 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6081 "{ B[i,j] -> C[] }",
6082 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6083 "{ A[a,b] -> C[] }" },
6084 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6085 "{ B[i,j] -> C[] : i > j }",
6086 "{ A[a,b] -> B[b,a] }",
6087 "{ A[a,b] -> C[] : b > a }" },
6088 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6089 "{ B[i,j] -> C[] : j > 5 }",
6090 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6091 "{ A[a,b] -> C[] : b > a > 5 }" },
6092 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6093 "[N] -> { B[i,j] -> C[] : j > N }",
6094 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6095 "[N] -> { A[a,b] -> C[] : b > a > N }" },
6096 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6097 "[M,N] -> { B[] -> C[] : N > 5 }",
6098 "[M,N] -> { A[] -> B[] : M > N }",
6099 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
6102 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
6104 static int test_bin_mpa(isl_ctx
*ctx
)
6108 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
6110 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
6111 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
6112 mpa_bin_tests
[i
].arg1
);
6113 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
6114 mpa_bin_tests
[i
].arg2
);
6115 res
= isl_multi_pw_aff_read_from_str(ctx
,
6116 mpa_bin_tests
[i
].res
);
6117 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
6118 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
6119 isl_multi_pw_aff_free(mpa1
);
6120 isl_multi_pw_aff_free(res
);
6124 isl_die(ctx
, isl_error_unknown
,
6125 "unexpected result", return -1);
6131 /* Inputs for basic tests of unary operations on
6132 * isl_multi_union_pw_aff objects.
6133 * "fn" is the function that is tested.
6134 * "arg" is a string description of the input.
6135 * "res" is a string description of the expected result.
6138 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6139 __isl_take isl_multi_union_pw_aff
*mupa
);
6142 } mupa_un_tests
[] = {
6143 { &isl_multi_union_pw_aff_factor_range
,
6144 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
6145 "C[{ A[] -> [2] }]" },
6146 { &isl_multi_union_pw_aff_factor_range
,
6147 "[B[] -> C[{ A[] -> [2] }]]",
6148 "C[{ A[] -> [2] }]" },
6149 { &isl_multi_union_pw_aff_factor_range
,
6150 "[B[{ A[] -> [1] }] -> C[]]",
6152 { &isl_multi_union_pw_aff_factor_range
,
6155 { &isl_multi_union_pw_aff_factor_range
,
6156 "([B[] -> C[]] : { A[x] : x >= 0 })",
6157 "(C[] : { A[x] : x >= 0 })" },
6158 { &isl_multi_union_pw_aff_factor_range
,
6159 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
6160 "[N] -> (C[] : { A[x] : x <= N })" },
6161 { &isl_multi_union_pw_aff_factor_range
,
6162 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
6163 "[N] -> (C[] : { : N >= 0 })" },
6166 /* Perform some basic tests of unary operations on
6167 * isl_multi_union_pw_aff objects.
6169 static int test_un_mupa(isl_ctx
*ctx
)
6173 isl_multi_union_pw_aff
*mupa
, *res
;
6175 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
6176 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6177 mupa_un_tests
[i
].arg
);
6178 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6179 mupa_un_tests
[i
].res
);
6180 mupa
= mupa_un_tests
[i
].fn(mupa
);
6181 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6182 isl_multi_union_pw_aff_free(mupa
);
6183 isl_multi_union_pw_aff_free(res
);
6187 isl_die(ctx
, isl_error_unknown
,
6188 "unexpected result", return -1);
6194 /* Inputs for basic tests of binary operations on
6195 * isl_multi_union_pw_aff objects.
6196 * "fn" is the function that is tested.
6197 * "arg1" and "arg2" are string descriptions of the inputs.
6198 * "res" is a string description of the expected result.
6201 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6202 __isl_take isl_multi_union_pw_aff
*mupa1
,
6203 __isl_take isl_multi_union_pw_aff
*mupa2
);
6207 } mupa_bin_tests
[] = {
6208 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6209 "[{ A[] -> [3] }]" },
6210 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6211 "[{ A[] -> [-1] }]" },
6212 { &isl_multi_union_pw_aff_add
,
6213 "[{ A[] -> [1]; B[] -> [4] }]",
6214 "[{ A[] -> [2]; C[] -> [5] }]",
6215 "[{ A[] -> [3] }]" },
6216 { &isl_multi_union_pw_aff_union_add
,
6217 "[{ A[] -> [1]; B[] -> [4] }]",
6218 "[{ A[] -> [2]; C[] -> [5] }]",
6219 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6220 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6221 "[{ A[x] -> [(x)] : x <= 10 }]",
6222 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6223 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6224 "([] : { A[x] : x <= 10 })",
6225 "([] : { A[x] : 5 <= x <= 10 })" },
6226 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6227 "[N] -> ([] : { A[x] : x <= N })",
6228 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6229 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
6230 "([] : { A[x] : x <= 10 })",
6231 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6232 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6233 "[{ A[x] -> [(x)] : x <= 10 }]",
6234 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6235 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6236 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
6237 "([] : { A[x] : x <= 10 })",
6238 "([] : { A[x] })" },
6239 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
6240 "[N] -> ([] : { A[x] : x >= N })",
6241 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6242 { &isl_multi_union_pw_aff_union_add
,
6243 "[N] -> ([] : { A[] : N >= 0})",
6244 "[N] -> ([] : { A[] : N <= 0})",
6245 "[N] -> ([] : { A[] })" },
6246 { &isl_multi_union_pw_aff_union_add
,
6247 "[N] -> ([] : { A[] })",
6248 "[N] -> ([] : { : })",
6249 "[N] -> ([] : { : })" },
6250 { &isl_multi_union_pw_aff_union_add
,
6251 "[N] -> ([] : { : })",
6252 "[N] -> ([] : { A[] })",
6253 "[N] -> ([] : { : })" },
6254 { &isl_multi_union_pw_aff_union_add
,
6255 "[N] -> ([] : { : N >= 0})",
6256 "[N] -> ([] : { : N <= 0})",
6257 "[N] -> ([] : { : })" },
6258 { &isl_multi_union_pw_aff_range_product
,
6259 "B[{ A[] -> [1] }]",
6260 "C[{ A[] -> [2] }]",
6261 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6262 { &isl_multi_union_pw_aff_range_product
,
6263 "(B[] : { A[x] : x >= 5 })",
6264 "(C[] : { A[x] : x <= 10 })",
6265 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6266 { &isl_multi_union_pw_aff_range_product
,
6267 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6268 "(C[] : { A[x] : x <= 10 })",
6269 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6270 { &isl_multi_union_pw_aff_range_product
,
6271 "(C[] : { A[x] : x <= 10 })",
6272 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6273 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6274 { &isl_multi_union_pw_aff_range_product
,
6275 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6276 "[N] -> (C[] : { A[x] : x <= N })",
6277 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6278 { &isl_multi_union_pw_aff_range_product
,
6279 "[N] -> (C[] : { A[x] : x <= N })",
6280 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6281 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6282 { &isl_multi_union_pw_aff_range_product
,
6283 "B[{ A[] -> [1]; D[] -> [3] }]",
6284 "C[{ A[] -> [2] }]",
6285 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6286 { &isl_multi_union_pw_aff_range_product
,
6289 "([B[] -> C[]] : { A[x] })" },
6290 { &isl_multi_union_pw_aff_range_product
,
6293 "([B[] -> C[]] : { A[x] })" },
6296 /* Perform some basic tests of binary operations on
6297 * isl_multi_union_pw_aff objects.
6299 static int test_bin_mupa(isl_ctx
*ctx
)
6303 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
6305 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
6306 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
6307 mupa_bin_tests
[i
].arg1
);
6308 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
6309 mupa_bin_tests
[i
].arg2
);
6310 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6311 mupa_bin_tests
[i
].res
);
6312 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
6313 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
6314 isl_multi_union_pw_aff_free(mupa1
);
6315 isl_multi_union_pw_aff_free(res
);
6319 isl_die(ctx
, isl_error_unknown
,
6320 "unexpected result", return -1);
6326 /* Inputs for basic tests of binary operations on
6327 * pairs of isl_multi_union_pw_aff and isl_set objects.
6328 * "fn" is the function that is tested.
6329 * "arg1" and "arg2" are string descriptions of the inputs.
6330 * "res" is a string description of the expected result.
6333 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6334 __isl_take isl_multi_union_pw_aff
*mupa
,
6335 __isl_take isl_set
*set
);
6339 } mupa_set_tests
[] = {
6340 { &isl_multi_union_pw_aff_intersect_range
,
6341 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6342 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6343 { &isl_multi_union_pw_aff_intersect_range
,
6344 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6345 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6346 { &isl_multi_union_pw_aff_intersect_range
,
6347 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6348 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6349 { &isl_multi_union_pw_aff_intersect_range
,
6350 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6351 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6352 { &isl_multi_union_pw_aff_intersect_range
,
6353 "C[]", "{ C[] }", "C[]" },
6354 { &isl_multi_union_pw_aff_intersect_range
,
6355 "[N] -> (C[] : { : N >= 0 })",
6357 "[N] -> (C[] : { : N >= 0 })" },
6358 { &isl_multi_union_pw_aff_intersect_range
,
6359 "(C[] : { A[a,b] })",
6361 "(C[] : { A[a,b] })" },
6362 { &isl_multi_union_pw_aff_intersect_range
,
6363 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6365 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6366 { &isl_multi_union_pw_aff_intersect_range
,
6368 "[N] -> { C[] : N >= 0 }",
6369 "[N] -> (C[] : { : N >= 0 })" },
6370 { &isl_multi_union_pw_aff_intersect_range
,
6371 "(C[] : { A[a,b] })",
6372 "[N] -> { C[] : N >= 0 }",
6373 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6374 { &isl_multi_union_pw_aff_intersect_range
,
6375 "[N] -> (C[] : { : N >= 0 })",
6376 "[N] -> { C[] : N < 1024 }",
6377 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6378 { &isl_multi_union_pw_aff_intersect_params
,
6379 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6380 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6381 { &isl_multi_union_pw_aff_intersect_params
,
6382 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6383 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6384 { &isl_multi_union_pw_aff_intersect_params
,
6385 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6386 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6387 { &isl_multi_union_pw_aff_intersect_params
,
6388 "C[]", "[N] -> { : N >= 0 }",
6389 "[N] -> (C[] : { : N >= 0 })" },
6390 { &isl_multi_union_pw_aff_intersect_params
,
6391 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6392 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6393 { &isl_multi_union_pw_aff_intersect_params
,
6394 "[N] -> (C[] : { A[a,N] })", "{ : }",
6395 "[N] -> (C[] : { A[a,N] })" },
6396 { &isl_multi_union_pw_aff_intersect_params
,
6397 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6398 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6401 /* Perform some basic tests of binary operations on
6402 * pairs of isl_multi_union_pw_aff and isl_set objects.
6404 static int test_mupa_set(isl_ctx
*ctx
)
6408 isl_multi_union_pw_aff
*mupa
, *res
;
6411 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
6412 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6413 mupa_set_tests
[i
].arg1
);
6414 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
6415 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6416 mupa_set_tests
[i
].res
);
6417 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
6418 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6419 isl_multi_union_pw_aff_free(mupa
);
6420 isl_multi_union_pw_aff_free(res
);
6424 isl_die(ctx
, isl_error_unknown
,
6425 "unexpected result", return -1);
6431 /* Inputs for basic tests of binary operations on
6432 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6433 * "fn" is the function that is tested.
6434 * "arg1" and "arg2" are string descriptions of the inputs.
6435 * "res" is a string description of the expected result.
6438 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6439 __isl_take isl_multi_union_pw_aff
*mupa
,
6440 __isl_take isl_union_set
*uset
);
6444 } mupa_uset_tests
[] = {
6445 { &isl_multi_union_pw_aff_intersect_domain
,
6446 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6447 "C[{ B[i,i] -> [3i] }]" },
6448 { &isl_multi_union_pw_aff_intersect_domain
,
6449 "(C[] : { B[i,j] })", "{ B[i,i] }",
6450 "(C[] : { B[i,i] })" },
6451 { &isl_multi_union_pw_aff_intersect_domain
,
6452 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6453 "[N] -> (C[] : { B[N,N] })" },
6454 { &isl_multi_union_pw_aff_intersect_domain
,
6455 "C[]", "{ B[i,i] }",
6456 "(C[] : { B[i,i] })" },
6457 { &isl_multi_union_pw_aff_intersect_domain
,
6458 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6459 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6462 /* Perform some basic tests of binary operations on
6463 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6465 static int test_mupa_uset(isl_ctx
*ctx
)
6469 isl_multi_union_pw_aff
*mupa
, *res
;
6470 isl_union_set
*uset
;
6472 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
6473 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6474 mupa_uset_tests
[i
].arg1
);
6475 uset
= isl_union_set_read_from_str(ctx
,
6476 mupa_uset_tests
[i
].arg2
);
6477 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6478 mupa_uset_tests
[i
].res
);
6479 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
6480 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6481 isl_multi_union_pw_aff_free(mupa
);
6482 isl_multi_union_pw_aff_free(res
);
6486 isl_die(ctx
, isl_error_unknown
,
6487 "unexpected result", return -1);
6493 /* Inputs for basic tests of binary operations on
6494 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6495 * "fn" is the function that is tested.
6496 * "arg1" and "arg2" are string descriptions of the inputs.
6497 * "res" is a string description of the expected result.
6500 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6501 __isl_take isl_multi_union_pw_aff
*mupa
,
6502 __isl_take isl_multi_aff
*ma
);
6506 } mupa_ma_tests
[] = {
6507 { &isl_multi_union_pw_aff_apply_multi_aff
,
6508 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6509 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6510 "{ C[a,b] -> D[b,a] }",
6511 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6512 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6513 { &isl_multi_union_pw_aff_apply_multi_aff
,
6514 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6515 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6516 "{ C[a,b] -> D[b,a] }",
6517 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6518 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6519 { &isl_multi_union_pw_aff_apply_multi_aff
,
6520 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6521 "[N] -> { C[a] -> D[a + N] }",
6522 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6523 { &isl_multi_union_pw_aff_apply_multi_aff
,
6527 { &isl_multi_union_pw_aff_apply_multi_aff
,
6528 "[N] -> (C[] : { : N >= 0 })",
6530 "[N] -> (D[] : { : N >= 0 })" },
6531 { &isl_multi_union_pw_aff_apply_multi_aff
,
6533 "[N] -> { C[] -> D[N] }",
6534 "[N] -> D[{ [N] }]" },
6535 { &isl_multi_union_pw_aff_apply_multi_aff
,
6536 "(C[] : { A[i,j] : i >= j })",
6538 "(D[] : { A[i,j] : i >= j })" },
6539 { &isl_multi_union_pw_aff_apply_multi_aff
,
6540 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6542 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6543 { &isl_multi_union_pw_aff_apply_multi_aff
,
6544 "(C[] : { A[i,j] : i >= j })",
6545 "[N] -> { C[] -> D[N] }",
6546 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6549 /* Perform some basic tests of binary operations on
6550 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6552 static int test_mupa_ma(isl_ctx
*ctx
)
6556 isl_multi_union_pw_aff
*mupa
, *res
;
6559 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6560 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6561 mupa_ma_tests
[i
].arg1
);
6562 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6563 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6564 mupa_ma_tests
[i
].res
);
6565 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6566 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6567 isl_multi_union_pw_aff_free(mupa
);
6568 isl_multi_union_pw_aff_free(res
);
6572 isl_die(ctx
, isl_error_unknown
,
6573 "unexpected result", return -1);
6579 /* Inputs for basic tests of binary operations on
6580 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6581 * "fn" is the function that is tested.
6582 * "arg1" and "arg2" are string descriptions of the inputs.
6583 * "res" is a string description of the expected result.
6586 __isl_give isl_union_pw_aff
*(*fn
)(
6587 __isl_take isl_multi_union_pw_aff
*mupa
,
6588 __isl_take isl_pw_aff
*pa
);
6592 } mupa_pa_tests
[] = {
6593 { &isl_multi_union_pw_aff_apply_pw_aff
,
6594 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6595 "[N] -> { C[a] -> [a + N] }",
6596 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6597 { &isl_multi_union_pw_aff_apply_pw_aff
,
6598 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6599 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6600 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6601 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6602 { &isl_multi_union_pw_aff_apply_pw_aff
,
6604 "[N] -> { C[] -> [N] }",
6606 { &isl_multi_union_pw_aff_apply_pw_aff
,
6608 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6609 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6610 { &isl_multi_union_pw_aff_apply_pw_aff
,
6611 "[N] -> (C[] : { : N >= 0 })",
6612 "[N] -> { C[] -> [N] }",
6613 "[N] -> { [N] : N >= 0 }" },
6614 { &isl_multi_union_pw_aff_apply_pw_aff
,
6615 "[N] -> (C[] : { : N >= 0 })",
6616 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6617 "[N] -> { [N] : N >= 0 }" },
6618 { &isl_multi_union_pw_aff_apply_pw_aff
,
6619 "[N] -> (C[] : { : N >= 0 })",
6621 "[N] -> { [0] : N >= 0 }" },
6622 { &isl_multi_union_pw_aff_apply_pw_aff
,
6623 "(C[] : { A[i,j] : i >= j })",
6624 "[N] -> { C[] -> [N] }",
6625 "[N] -> { A[i,j] -> [N] : i >= j }" },
6626 { &isl_multi_union_pw_aff_apply_pw_aff
,
6627 "(C[] : { A[i,j] : i >= j })",
6628 "[N] -> { C[] -> [N] : N >= 0 }",
6629 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6632 /* Perform some basic tests of binary operations on
6633 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6635 static int test_mupa_pa(isl_ctx
*ctx
)
6639 isl_multi_union_pw_aff
*mupa
;
6640 isl_union_pw_aff
*upa
, *res
;
6643 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6644 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6645 mupa_pa_tests
[i
].arg1
);
6646 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6647 res
= isl_union_pw_aff_read_from_str(ctx
,
6648 mupa_pa_tests
[i
].res
);
6649 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6650 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6651 isl_union_pw_aff_free(upa
);
6652 isl_union_pw_aff_free(res
);
6656 isl_die(ctx
, isl_error_unknown
,
6657 "unexpected result", return -1);
6663 /* Inputs for basic tests of binary operations on
6664 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6665 * "fn" is the function that is tested.
6666 * "arg1" and "arg2" are string descriptions of the inputs.
6667 * "res" is a string description of the expected result.
6670 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6671 __isl_take isl_multi_union_pw_aff
*mupa
,
6672 __isl_take isl_pw_multi_aff
*pma
);
6676 } mupa_pma_tests
[] = {
6677 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6678 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6679 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6680 "{ C[a,b] -> D[b,a] }",
6681 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6682 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6683 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6684 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6685 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6686 "{ C[a,b] -> D[b,a] }",
6687 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6688 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6689 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6690 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6691 "[N] -> { C[a] -> D[a + N] }",
6692 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6693 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6694 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6695 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6696 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6697 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6698 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6699 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6700 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6701 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6702 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6703 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6704 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6705 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6706 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6710 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6711 "[N] -> (C[] : { : N >= 0 })",
6713 "[N] -> (D[] : { : N >= 0 })" },
6714 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6716 "[N] -> { C[] -> D[N] }",
6717 "[N] -> D[{ [N] }]" },
6718 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6719 "(C[] : { A[i,j] : i >= j })",
6721 "(D[] : { A[i,j] : i >= j })" },
6722 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6723 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6725 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6726 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6727 "(C[] : { A[i,j] : i >= j })",
6728 "[N] -> { C[] -> D[N] }",
6729 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6730 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6732 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6733 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6734 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6735 "[N] -> (C[] : { : N >= 0 })",
6736 "[N] -> { C[] -> D[N] }",
6737 "[N] -> D[{ [N] : N >= 0 }]" },
6738 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6739 "[N] -> (C[] : { : N >= 0 })",
6740 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6741 "[N] -> D[{ [N] : N >= 0 }]" },
6742 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6743 "[N] -> (C[] : { : N >= 0 })",
6745 "[N] -> D[{ [0] : N >= 0 }]" },
6746 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6747 "(C[] : { A[i,j] : i >= j })",
6748 "[N] -> { C[] -> D[N] : N >= 0 }",
6749 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6752 /* Perform some basic tests of binary operations on
6753 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6755 static int test_mupa_pma(isl_ctx
*ctx
)
6759 isl_multi_union_pw_aff
*mupa
, *res
;
6760 isl_pw_multi_aff
*pma
;
6762 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6763 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6764 mupa_pma_tests
[i
].arg1
);
6765 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6766 mupa_pma_tests
[i
].arg2
);
6767 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6768 mupa_pma_tests
[i
].res
);
6769 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6770 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6771 isl_multi_union_pw_aff_free(mupa
);
6772 isl_multi_union_pw_aff_free(res
);
6776 isl_die(ctx
, isl_error_unknown
,
6777 "unexpected result", return -1);
6783 /* Inputs for basic tests of binary operations on
6784 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6785 * "fn" is the function that is tested.
6786 * "arg1" and "arg2" are string descriptions of the inputs.
6787 * "res" is a string description of the expected result.
6790 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6791 __isl_take isl_multi_union_pw_aff
*mupa
,
6792 __isl_take isl_union_pw_multi_aff
*upma
);
6796 } mupa_upma_tests
[] = {
6797 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6798 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6799 "C[{ A[a,b] -> [b + 2a] }]" },
6800 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6801 "C[{ B[i,j] -> [i + 2j] }]",
6802 "{ A[a,b] -> B[b,a] : b > a }",
6803 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6804 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6805 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6806 "{ A[a,b] -> B[b,a] : b > a }",
6807 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6808 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6809 "C[{ B[i,j] -> [i + 2j] }]",
6810 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6811 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6812 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6813 "(C[] : { B[a,b] })",
6814 "{ A[a,b] -> B[b,a] }",
6815 "(C[] : { A[a,b] })" },
6816 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6817 "(C[] : { B[a,b] })",
6818 "{ B[a,b] -> A[b,a] }",
6820 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6821 "(C[] : { B[a,b] })",
6822 "{ A[a,b] -> B[b,a] : a > b }",
6823 "(C[] : { A[a,b] : a > b })" },
6824 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6825 "(C[] : { B[a,b] : a > b })",
6826 "{ A[a,b] -> B[b,a] }",
6827 "(C[] : { A[a,b] : b > a })" },
6828 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6829 "[N] -> (C[] : { B[a,b] : a > N })",
6830 "{ A[a,b] -> B[b,a] : a > b }",
6831 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6832 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6833 "(C[] : { B[a,b] : a > b })",
6834 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6835 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6836 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6838 "{ A[a,b] -> B[b,a] }",
6840 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6841 "[N] -> (C[] : { : N >= 0 })",
6842 "{ A[a,b] -> B[b,a] }",
6843 "[N] -> (C[] : { : N >= 0 })" },
6844 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6846 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6847 "[N] -> (C[] : { : N >= 0 })" },
6850 /* Perform some basic tests of binary operations on
6851 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6853 static int test_mupa_upma(isl_ctx
*ctx
)
6857 isl_multi_union_pw_aff
*mupa
, *res
;
6858 isl_union_pw_multi_aff
*upma
;
6860 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6861 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6862 mupa_upma_tests
[i
].arg1
);
6863 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6864 mupa_upma_tests
[i
].arg2
);
6865 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6866 mupa_upma_tests
[i
].res
);
6867 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6868 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6869 isl_multi_union_pw_aff_free(mupa
);
6870 isl_multi_union_pw_aff_free(res
);
6874 isl_die(ctx
, isl_error_unknown
,
6875 "unexpected result", return -1);
6881 /* Check that the input tuple of an isl_aff can be set properly.
6883 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6889 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6890 id
= isl_id_alloc(ctx
, "A", NULL
);
6891 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6892 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6895 return isl_stat_error
;
6900 /* Check that affine expressions get normalized on addition/subtraction.
6901 * In particular, check that (final) unused integer divisions get removed
6902 * such that an expression derived from expressions with integer divisions
6903 * is found to be obviously equal to one that is created directly.
6905 static isl_stat
test_aff_normalize(isl_ctx
*ctx
)
6907 isl_aff
*aff
, *aff2
;
6910 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x//2] }");
6911 aff2
= isl_aff_read_from_str(ctx
, "{ [x] -> [1 + x//2] }");
6912 aff
= isl_aff_sub(aff2
, aff
);
6913 ok
= aff_check_plain_equal(aff
, "{ [x] -> [1] }");
6919 int test_aff(isl_ctx
*ctx
)
6924 isl_local_space
*ls
;
6929 if (test_upa(ctx
) < 0)
6931 if (test_bin_aff(ctx
) < 0)
6933 if (test_bin_pw_aff(ctx
) < 0)
6935 if (test_upma_test(ctx
) < 0)
6937 if (test_bin_upma(ctx
) < 0)
6939 if (test_bin_upma_fail(ctx
) < 0)
6941 if (test_upma_uset(ctx
) < 0)
6943 if (test_un_mpa(ctx
) < 0)
6945 if (test_bin_mpa(ctx
) < 0)
6947 if (test_un_mupa(ctx
) < 0)
6949 if (test_bin_mupa(ctx
) < 0)
6951 if (test_mupa_set(ctx
) < 0)
6953 if (test_mupa_uset(ctx
) < 0)
6955 if (test_mupa_ma(ctx
) < 0)
6957 if (test_mupa_pa(ctx
) < 0)
6959 if (test_mupa_pma(ctx
) < 0)
6961 if (test_mupa_upma(ctx
) < 0)
6964 space
= isl_space_set_alloc(ctx
, 0, 1);
6965 ls
= isl_local_space_from_space(space
);
6966 aff
= isl_aff_zero_on_domain(ls
);
6968 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6969 aff
= isl_aff_scale_down_ui(aff
, 3);
6970 aff
= isl_aff_floor(aff
);
6971 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6972 aff
= isl_aff_scale_down_ui(aff
, 2);
6973 aff
= isl_aff_floor(aff
);
6974 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6977 set
= isl_set_read_from_str(ctx
, str
);
6978 aff
= isl_aff_gist(aff
, set
);
6980 aff
= isl_aff_add_constant_si(aff
, -16);
6981 zero
= isl_aff_plain_is_zero(aff
);
6987 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6989 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6990 aff
= isl_aff_scale_down_ui(aff
, 64);
6991 aff
= isl_aff_floor(aff
);
6992 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6997 if (test_aff_set_tuple_id(ctx
) < 0)
6999 if (test_aff_normalize(ctx
) < 0)
7005 /* Inputs for isl_set_bind tests.
7006 * "set" is the input set.
7007 * "tuple" is the binding tuple.
7008 * "res" is the expected result.
7015 } bind_set_tests
[] = {
7016 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7018 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
7019 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
7021 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
7022 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
7024 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
7025 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
7027 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
7030 /* Perform basic isl_set_bind tests.
7032 static isl_stat
test_bind_set(isl_ctx
*ctx
)
7036 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
7039 isl_multi_id
*tuple
;
7042 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
7043 str
= bind_set_tests
[i
].tuple
;
7044 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7045 set
= isl_set_bind(set
, tuple
);
7046 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
7049 return isl_stat_error
;
7055 /* Inputs for isl_map_bind_domain tests.
7056 * "map" is the input map.
7057 * "tuple" is the binding tuple.
7058 * "res" is the expected result.
7064 } bind_map_domain_tests
[] = {
7065 { "{ A[M, N] -> [M + floor(N/2)] }",
7067 "[M, N] -> { [M + floor(N/2)] }" },
7068 { "{ B[N, M] -> [M + floor(N/2)] }",
7070 "[N, M] -> { [M + floor(N/2)] }" },
7071 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7073 "[M, N] -> { [M + floor(N/2)] }" },
7074 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7076 "[M, N] -> { [M + floor(N/2)] }" },
7077 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7079 "[M, N] -> { [M + floor(N/2)] }" },
7080 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7082 "[A, N, M] -> { [M + floor(N/2)] }" },
7085 /* Perform basic isl_map_bind_domain tests.
7087 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
7091 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
7095 isl_multi_id
*tuple
;
7098 str
= bind_map_domain_tests
[i
].map
;
7099 map
= isl_map_read_from_str(ctx
, str
);
7100 str
= bind_map_domain_tests
[i
].tuple
;
7101 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7102 set
= isl_map_bind_domain(map
, tuple
);
7103 str
= bind_map_domain_tests
[i
].res
;
7104 r
= set_check_equal(set
, str
);
7107 return isl_stat_error
;
7113 /* Inputs for isl_union_map_bind_range tests.
7114 * "map" is the input union map.
7115 * "tuple" is the binding tuple.
7116 * "res" is the expected result.
7122 } bind_umap_range_tests
[] = {
7123 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7125 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7126 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7129 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
7134 /* Perform basic isl_union_map_bind_range tests.
7136 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
7140 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
7142 isl_union_map
*umap
;
7143 isl_union_set
*uset
;
7144 isl_multi_id
*tuple
;
7147 str
= bind_umap_range_tests
[i
].map
;
7148 umap
= isl_union_map_read_from_str(ctx
, str
);
7149 str
= bind_umap_range_tests
[i
].tuple
;
7150 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7151 uset
= isl_union_map_bind_range(umap
, tuple
);
7152 str
= bind_umap_range_tests
[i
].res
;
7153 r
= uset_check_equal(uset
, str
);
7154 isl_union_set_free(uset
);
7156 return isl_stat_error
;
7162 /* Inputs for isl_pw_multi_aff_bind_domain tests.
7163 * "pma" is the input expression.
7164 * "tuple" is the binding tuple.
7165 * "res" is the expected result.
7171 } bind_pma_domain_tests
[] = {
7172 { "{ A[M, N] -> [M + floor(N/2)] }",
7174 "[M, N] -> { [M + floor(N/2)] }" },
7175 { "{ B[N, M] -> [M + floor(N/2)] }",
7177 "[N, M] -> { [M + floor(N/2)] }" },
7178 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7180 "[M, N] -> { [M + floor(N/2)] }" },
7181 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7183 "[M, N] -> { [M + floor(N/2)] }" },
7184 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7186 "[M, N] -> { [M + floor(N/2)] }" },
7187 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7189 "[A, N, M] -> { [M + floor(N/2)] }" },
7192 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7194 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
7198 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
7200 isl_pw_multi_aff
*pma
;
7201 isl_multi_id
*tuple
;
7204 str
= bind_pma_domain_tests
[i
].pma
;
7205 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7206 str
= bind_pma_domain_tests
[i
].tuple
;
7207 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7208 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
7209 str
= bind_pma_domain_tests
[i
].res
;
7210 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7211 isl_pw_multi_aff_free(pma
);
7213 return isl_stat_error
;
7219 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7220 * "pma" is the input expression.
7221 * "tuple" is the binding tuple.
7222 * "res" is the expected result.
7228 } bind_pma_domain_wrapped_tests
[] = {
7229 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7231 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7232 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7234 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7235 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7237 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7238 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7240 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7241 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7243 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7244 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7246 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7249 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7251 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
7255 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
7257 isl_pw_multi_aff
*pma
;
7258 isl_multi_id
*tuple
;
7261 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
7262 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7263 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
7264 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7265 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
7266 str
= bind_pma_domain_wrapped_tests
[i
].res
;
7267 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7268 isl_pw_multi_aff_free(pma
);
7270 return isl_stat_error
;
7276 /* Inputs for isl_aff_bind_id tests.
7277 * "aff" is the input expression.
7278 * "id" is the binding id.
7279 * "res" is the expected result.
7286 } bind_aff_tests
[] = {
7287 { "{ [4] }", "M", "[M = 4] -> { : }" },
7288 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7289 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7290 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7291 { "{ [NaN] }", "M", "{ : false }" },
7292 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7295 /* Perform basic isl_aff_bind_id tests.
7297 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
7301 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
7307 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
7308 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
7309 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
7310 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
7313 return isl_stat_error
;
7319 /* Inputs for isl_pw_aff_bind_id tests.
7320 * "pa" is the input expression.
7321 * "id" is the binding id.
7322 * "res" is the expected result.
7329 } bind_pa_tests
[] = {
7330 { "{ [4] }", "M", "[M = 4] -> { : }" },
7331 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7332 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7333 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7334 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7335 { "{ [NaN] }", "M", "{ : false }" },
7336 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7339 /* Perform basic isl_pw_aff_bind_id tests.
7341 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
7345 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
7351 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
7352 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
7353 res
= isl_pw_aff_bind_id(pa
, id
);
7354 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
7357 return isl_stat_error
;
7363 /* Inputs for isl_multi_union_pw_aff_bind tests.
7364 * "mupa" is the input expression.
7365 * "tuple" is the binding tuple.
7366 * "res" is the expected result.
7373 } bind_mupa_tests
[] = {
7374 { "A[{ [4] }, { [5] }]",
7376 "[M = 4, N = 5] -> { : }" },
7377 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7379 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7380 { "[M] -> A[{ [4] }, { [M + 1] }]",
7382 "[M = 4, N = 5] -> { : }" },
7385 /* Perform basic isl_multi_union_pw_aff_bind tests.
7387 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
7391 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
7393 isl_multi_union_pw_aff
*mupa
;
7395 isl_multi_id
*tuple
;
7398 str
= bind_mupa_tests
[i
].mupa
;
7399 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7400 str
= bind_mupa_tests
[i
].tuple
;
7401 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7402 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
7403 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
7404 isl_union_set_free(res
);
7406 return isl_stat_error
;
7412 /* Perform tests that reinterpret dimensions as parameters.
7414 static int test_bind(isl_ctx
*ctx
)
7416 if (test_bind_set(ctx
) < 0)
7418 if (test_bind_map_domain(ctx
) < 0)
7420 if (test_bind_umap_range(ctx
) < 0)
7422 if (test_bind_pma_domain(ctx
) < 0)
7424 if (test_bind_pma_domain_wrapped(ctx
) < 0)
7426 if (test_bind_aff(ctx
) < 0)
7428 if (test_bind_pa(ctx
) < 0)
7430 if (test_bind_mupa(ctx
) < 0)
7436 /* Inputs for isl_set_unbind_params tests.
7437 * "set" is the input parameter domain.
7438 * "tuple" is the tuple of the constructed set.
7439 * "res" is the expected result.
7445 } unbind_set_tests
[] = {
7446 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7448 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7449 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7451 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7452 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7454 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7455 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7457 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7460 /* Perform basic isl_set_unbind_params tests.
7462 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
7466 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
7469 isl_multi_id
*tuple
;
7472 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
7473 str
= unbind_set_tests
[i
].tuple
;
7474 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7475 set
= isl_set_unbind_params(set
, tuple
);
7476 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
7479 return isl_stat_error
;
7485 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7486 * "aff" is the input affine expression defined over a parameter domain.
7487 * "tuple" is the tuple of the domain that gets introduced.
7488 * "res" is the expected result.
7494 } unbind_aff_tests
[] = {
7495 { "[M, N] -> { [M + floor(N/2)] }",
7497 "{ A[M, N] -> [M + floor(N/2)] }" },
7498 { "[M, N] -> { [M + floor(N/2)] }",
7500 "{ B[N, M] -> [M + floor(N/2)] }" },
7501 { "[M, N] -> { [M + floor(N/2)] }",
7503 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7504 { "[M, N] -> { [M + floor(N/2)] }",
7505 "{ D[A, B, C, N, Z] }",
7506 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7509 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7511 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
7515 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
7518 isl_multi_id
*tuple
;
7521 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
7522 str
= unbind_aff_tests
[i
].tuple
;
7523 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7524 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
7525 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
7528 return isl_stat_error
;
7534 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7535 * "ma" is the input multi affine expression defined over a parameter domain.
7536 * "tuple" is the tuple of the domain that gets introduced.
7537 * "res" is the expected result.
7543 } unbind_multi_aff_tests
[] = {
7544 { "[M, N] -> { T[M + floor(N/2)] }",
7546 "{ A[M, N] -> T[M + floor(N/2)] }" },
7547 { "[M, N] -> { [M + floor(N/2)] }",
7549 "{ B[N, M] -> [M + floor(N/2)] }" },
7550 { "[M, N] -> { [M + floor(N/2)] }",
7552 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7553 { "[M, N] -> { [M + floor(N/2)] }",
7554 "{ D[A, B, C, N, Z] }",
7555 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7556 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7558 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7561 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7563 static isl_stat
test_unbind_multi_aff(isl_ctx
*ctx
)
7567 for (i
= 0; i
< ARRAY_SIZE(unbind_multi_aff_tests
); ++i
) {
7570 isl_multi_id
*tuple
;
7573 str
= unbind_multi_aff_tests
[i
].ma
;
7574 ma
= isl_multi_aff_read_from_str(ctx
, str
);
7575 str
= unbind_multi_aff_tests
[i
].tuple
;
7576 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7577 ma
= isl_multi_aff_unbind_params_insert_domain(ma
, tuple
);
7578 str
= unbind_multi_aff_tests
[i
].res
;
7579 r
= multi_aff_check_plain_equal(ma
, str
);
7580 isl_multi_aff_free(ma
);
7582 return isl_stat_error
;
7588 /* Perform tests that reinterpret parameters.
7590 static int test_unbind(isl_ctx
*ctx
)
7592 if (test_unbind_set(ctx
) < 0)
7594 if (test_unbind_aff(ctx
) < 0)
7596 if (test_unbind_multi_aff(ctx
) < 0)
7602 /* Check that "pa" consists of a single expression.
7604 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
7608 n
= isl_pw_aff_n_piece(pa
);
7609 isl_pw_aff_free(pa
);
7614 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
7620 /* Check that the computation below results in a single expression.
7621 * One or two expressions may result depending on which constraint
7622 * ends up being considered as redundant with respect to the other
7623 * constraints after the projection that is performed internally
7624 * by isl_set_dim_min.
7626 static int test_dim_max_1(isl_ctx
*ctx
)
7632 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7633 "-4a <= b <= 3 and b < n - 4a }";
7634 set
= isl_set_read_from_str(ctx
, str
);
7635 pa
= isl_set_dim_min(set
, 0);
7636 return check_single_piece(ctx
, pa
);
7639 /* Check that the computation below results in a single expression.
7640 * The PIP problem corresponding to these constraints has a row
7641 * that causes a split of the solution domain. The solver should
7642 * first pick rows that split off empty parts such that the actual
7643 * solution domain does not get split.
7644 * Note that the description contains some redundant constraints.
7645 * If these constraints get removed first, then the row mentioned
7646 * above does not appear in the PIP problem.
7648 static int test_dim_max_2(isl_ctx
*ctx
)
7654 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7655 "N > 0 and P >= 0 }";
7656 set
= isl_set_read_from_str(ctx
, str
);
7657 pa
= isl_set_dim_max(set
, 0);
7658 return check_single_piece(ctx
, pa
);
7661 int test_dim_max(isl_ctx
*ctx
)
7665 isl_set
*set1
, *set2
;
7670 if (test_dim_max_1(ctx
) < 0)
7672 if (test_dim_max_2(ctx
) < 0)
7675 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7676 set
= isl_set_read_from_str(ctx
, str
);
7677 pwaff
= isl_set_dim_max(set
, 0);
7678 set1
= isl_set_from_pw_aff(pwaff
);
7679 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7680 set2
= isl_set_read_from_str(ctx
, str
);
7681 equal
= isl_set_is_equal(set1
, set2
);
7687 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7689 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7690 set
= isl_set_read_from_str(ctx
, str
);
7691 pwaff
= isl_set_dim_max(set
, 0);
7692 set1
= isl_set_from_pw_aff(pwaff
);
7693 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7694 set2
= isl_set_read_from_str(ctx
, str
);
7695 equal
= isl_set_is_equal(set1
, set2
);
7701 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7703 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7704 set
= isl_set_read_from_str(ctx
, str
);
7705 pwaff
= isl_set_dim_max(set
, 0);
7706 set1
= isl_set_from_pw_aff(pwaff
);
7707 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7708 set2
= isl_set_read_from_str(ctx
, str
);
7709 equal
= isl_set_is_equal(set1
, set2
);
7715 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7717 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7718 "0 <= i < N and 0 <= j < M }";
7719 map
= isl_map_read_from_str(ctx
, str
);
7720 set
= isl_map_range(map
);
7722 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7723 set1
= isl_set_from_pw_aff(pwaff
);
7724 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7725 set2
= isl_set_read_from_str(ctx
, str
);
7726 equal
= isl_set_is_equal(set1
, set2
);
7730 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7731 set1
= isl_set_from_pw_aff(pwaff
);
7732 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7733 set2
= isl_set_read_from_str(ctx
, str
);
7734 if (equal
>= 0 && equal
)
7735 equal
= isl_set_is_equal(set1
, set2
);
7744 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7746 /* Check that solutions are properly merged. */
7747 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7748 "c <= -1 + n - 4a - 2b and c >= -2b and "
7749 "4a >= -4 + n and c >= 0 }";
7750 set
= isl_set_read_from_str(ctx
, str
);
7751 pwaff
= isl_set_dim_min(set
, 2);
7752 set1
= isl_set_from_pw_aff(pwaff
);
7753 str
= "[n] -> { [(0)] : n >= 1 }";
7754 set2
= isl_set_read_from_str(ctx
, str
);
7755 equal
= isl_set_is_equal(set1
, set2
);
7762 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7764 /* Check that empty solution lie in the right space. */
7765 str
= "[n] -> { [t,a] : 1 = 0 }";
7766 set
= isl_set_read_from_str(ctx
, str
);
7767 pwaff
= isl_set_dim_max(set
, 0);
7768 set1
= isl_set_from_pw_aff(pwaff
);
7769 str
= "[n] -> { [t] : 1 = 0 }";
7770 set2
= isl_set_read_from_str(ctx
, str
);
7771 equal
= isl_set_is_equal(set1
, set2
);
7778 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7783 /* Basic test for isl_pw_multi_aff_product.
7785 * Check that multiple pieces are properly handled.
7787 static int test_product_pma(isl_ctx
*ctx
)
7791 isl_pw_multi_aff
*pma1
, *pma2
;
7793 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7794 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7795 str
= "{ C[] -> D[] }";
7796 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7797 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7798 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7799 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7800 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7801 isl_pw_multi_aff_free(pma1
);
7808 int test_product(isl_ctx
*ctx
)
7812 isl_union_set
*uset1
, *uset2
;
7816 set
= isl_set_read_from_str(ctx
, str
);
7817 set
= isl_set_product(set
, isl_set_copy(set
));
7818 ok
= isl_set_is_wrapping(set
);
7823 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7826 uset1
= isl_union_set_read_from_str(ctx
, str
);
7827 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7828 str
= "{ [[] -> []] }";
7829 uset2
= isl_union_set_read_from_str(ctx
, str
);
7830 ok
= isl_union_set_is_equal(uset1
, uset2
);
7831 isl_union_set_free(uset1
);
7832 isl_union_set_free(uset2
);
7836 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7838 if (test_product_pma(ctx
) < 0)
7844 /* Check that two sets are not considered disjoint just because
7845 * they have a different set of (named) parameters.
7847 static int test_disjoint(isl_ctx
*ctx
)
7850 isl_set
*set
, *set2
;
7853 str
= "[n] -> { [[]->[]] }";
7854 set
= isl_set_read_from_str(ctx
, str
);
7855 str
= "{ [[]->[]] }";
7856 set2
= isl_set_read_from_str(ctx
, str
);
7857 disjoint
= isl_set_is_disjoint(set
, set2
);
7863 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7868 /* Inputs for isl_pw_multi_aff_is_equal tests.
7869 * "f1" and "f2" are the two function that need to be compared.
7870 * "equal" is the expected result.
7876 } pma_equal_tests
[] = {
7877 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7878 "[N] -> { [0] : 0 <= N <= 1 }" },
7879 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7880 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7881 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7882 "[N] -> { [0] : 0 <= N <= 1 }" },
7883 { 0, "{ [NaN] }", "{ [NaN] }" },
7886 int test_equal(isl_ctx
*ctx
)
7890 isl_set
*set
, *set2
;
7894 set
= isl_set_read_from_str(ctx
, str
);
7896 set2
= isl_set_read_from_str(ctx
, str
);
7897 equal
= isl_set_is_equal(set
, set2
);
7903 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7905 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7906 int expected
= pma_equal_tests
[i
].equal
;
7907 isl_pw_multi_aff
*f1
, *f2
;
7909 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7910 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7911 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7912 isl_pw_multi_aff_free(f1
);
7913 isl_pw_multi_aff_free(f2
);
7916 if (equal
!= expected
)
7917 isl_die(ctx
, isl_error_unknown
,
7918 "unexpected equality result", return -1);
7924 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7925 enum isl_dim_type type
, unsigned pos
, int fixed
)
7929 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7936 isl_die(ctx
, isl_error_unknown
,
7937 "map not detected as fixed", return -1);
7939 isl_die(ctx
, isl_error_unknown
,
7940 "map detected as fixed", return -1);
7943 int test_fixed(isl_ctx
*ctx
)
7948 str
= "{ [i] -> [i] }";
7949 map
= isl_map_read_from_str(ctx
, str
);
7950 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7952 str
= "{ [i] -> [1] }";
7953 map
= isl_map_read_from_str(ctx
, str
);
7954 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7956 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7957 map
= isl_map_read_from_str(ctx
, str
);
7958 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7960 map
= isl_map_read_from_str(ctx
, str
);
7961 map
= isl_map_neg(map
);
7962 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7968 struct isl_vertices_test_data
{
7971 const char *vertex
[6];
7972 } vertices_tests
[] = {
7973 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7974 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7975 { "{ A[t, i] : t = 14 and i = 1 }",
7976 1, { "{ A[14, 1] }" } },
7977 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7978 "c <= m and m <= n and m > 0 }",
7980 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7981 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7982 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7983 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7984 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7985 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7987 /* An input with implicit equality constraints among the parameters. */
7988 { "[N, M] -> { [a, b] : M >= 3 and 9 + 3M <= a <= 29 + 2N + 11M and "
7989 "2b >= M + a and 5 - 2N - M + a <= 2b <= 3 + a and "
7992 "[N, M] -> { [(21), (12)] : M = 3 and N >= 0 }",
7993 "[N, M] -> { [(61 + 2N), (32 + N)] : M = 3 and N >= 0 }",
7998 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
8000 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
8002 struct isl_vertices_test_data
*data
= user
;
8005 isl_basic_set
*bset
;
8006 isl_pw_multi_aff
*pma
;
8010 ctx
= isl_vertex_get_ctx(vertex
);
8011 bset
= isl_vertex_get_domain(vertex
);
8012 ma
= isl_vertex_get_expr(vertex
);
8013 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
8015 for (i
= 0; i
< data
->n
; ++i
) {
8016 isl_pw_multi_aff
*pma_i
;
8018 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
8019 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
8020 isl_pw_multi_aff_free(pma_i
);
8022 if (equal
< 0 || equal
)
8026 isl_pw_multi_aff_free(pma
);
8027 isl_vertex_free(vertex
);
8030 return isl_stat_error
;
8032 return equal
? isl_stat_ok
: isl_stat_error
;
8035 int test_vertices(isl_ctx
*ctx
)
8039 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
8040 isl_basic_set
*bset
;
8041 isl_vertices
*vertices
;
8045 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
8046 vertices
= isl_basic_set_compute_vertices(bset
);
8047 n
= isl_vertices_get_n_vertices(vertices
);
8048 if (vertices_tests
[i
].n
!= n
)
8050 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
8051 &vertices_tests
[i
]) < 0)
8053 isl_vertices_free(vertices
);
8054 isl_basic_set_free(bset
);
8059 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
8066 /* Inputs for basic tests of binary operations on isl_union_map.
8067 * "fn" is the function that is being tested.
8068 * "arg1" and "arg2" are string descriptions of the inputs.
8069 * "res" is a string description of the expected result.
8072 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap1
,
8073 __isl_take isl_union_map
*umap2
);
8077 } umap_bin_tests
[] = {
8078 { &isl_union_map_intersect
,
8079 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
8080 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
8081 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
8082 { &isl_union_map_intersect_domain_factor_domain
,
8083 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8084 "[N] -> { B[i] -> C[N] }",
8086 { &isl_union_map_intersect_domain_factor_domain
,
8087 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8088 "[N] -> { A[i] -> C[N] }",
8089 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8090 { &isl_union_map_intersect_domain_factor_domain
,
8091 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8092 "[N] -> { A[i] -> C[N] }",
8093 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8094 { &isl_union_map_intersect_domain_factor_range
,
8095 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8096 "[N] -> { B[i] -> C[N] }",
8097 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8098 { &isl_union_map_intersect_domain_factor_range
,
8099 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8100 "[N] -> { B[i] -> C[N] }",
8101 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8102 { &isl_union_map_intersect_domain_factor_range
,
8103 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8104 "[N] -> { A[i] -> C[N] }",
8106 { &isl_union_map_intersect_range_factor_domain
,
8107 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8108 "[N] -> { A[i] -> B[N] }",
8109 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
8110 { &isl_union_map_intersect_range_factor_domain
,
8111 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8112 "[N] -> { A[i] -> B[N] }",
8113 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
8114 { &isl_union_map_intersect_range_factor_domain
,
8115 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8116 "[N] -> { A[i] -> C[N] }",
8118 { &isl_union_map_intersect_range_factor_range
,
8119 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8120 "[N] -> { A[i] -> C[N] }",
8121 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
8122 { &isl_union_map_intersect_range_factor_range
,
8123 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8124 "[N] -> { A[i] -> C[N] }",
8125 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
8126 { &isl_union_map_intersect_range_factor_range
,
8127 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8128 "[N] -> { A[i] -> B[N] }",
8132 /* Perform basic tests of binary operations on isl_union_map.
8134 static isl_stat
test_bin_union_map(isl_ctx
*ctx
)
8138 for (i
= 0; i
< ARRAY_SIZE(umap_bin_tests
); ++i
) {
8140 isl_union_map
*umap1
, *umap2
, *res
;
8143 str
= umap_bin_tests
[i
].arg1
;
8144 umap1
= isl_union_map_read_from_str(ctx
, str
);
8145 str
= umap_bin_tests
[i
].arg2
;
8146 umap2
= isl_union_map_read_from_str(ctx
, str
);
8147 str
= umap_bin_tests
[i
].res
;
8148 res
= isl_union_map_read_from_str(ctx
, str
);
8149 umap1
= umap_bin_tests
[i
].fn(umap1
, umap2
);
8150 equal
= isl_union_map_is_equal(umap1
, res
);
8151 isl_union_map_free(umap1
);
8152 isl_union_map_free(res
);
8154 return isl_stat_error
;
8156 isl_die(ctx
, isl_error_unknown
,
8157 "unexpected result", return isl_stat_error
);
8163 /* Check that isl_union_set_contains finds space independently
8164 * of the parameters.
8166 static isl_stat
test_union_set_contains(isl_ctx
*ctx
)
8172 isl_union_set
*uset
;
8174 str
= "[N] -> { A[0:N]; B[*,*] }";
8175 uset
= isl_union_set_read_from_str(ctx
, str
);
8176 space
= isl_space_unit(ctx
);
8177 id
= isl_id_alloc(ctx
, "A", NULL
);
8178 space
= isl_space_add_named_tuple_id_ui(space
, id
, 1);
8179 ok
= isl_union_set_contains(uset
, space
);
8180 isl_space_free(space
);
8181 isl_union_set_free(uset
);
8184 return isl_stat_error
;
8186 isl_die(ctx
, isl_error_unknown
,
8187 "unexpected result", return isl_stat_error
);
8192 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8194 static int test_union_map(isl_ctx
*ctx
)
8196 if (test_bin_union_map(ctx
) < 0)
8198 if (test_union_set_contains(ctx
) < 0)
8204 #define BASE union_pw_qpolynomial
8205 #include "isl_test_plain_equal_templ.c"
8207 /* Check that the result of applying "fn" to "a" and "b"
8208 * in (obviously) equal to "res".
8210 static isl_stat
test_union_pw_op(isl_ctx
*ctx
, const char *a
, const char *b
,
8211 __isl_give isl_union_pw_qpolynomial
*(*fn
)(
8212 __isl_take isl_union_pw_qpolynomial
*upwqp1
,
8213 __isl_take isl_union_pw_qpolynomial
*upwqp2
),
8217 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8219 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, a
);
8220 upwqp2
= isl_union_pw_qpolynomial_read_from_str(ctx
, b
);
8221 upwqp1
= fn(upwqp1
, upwqp2
);
8222 r
= union_pw_qpolynomial_check_plain_equal(upwqp1
, res
);
8223 isl_union_pw_qpolynomial_free(upwqp1
);
8228 int test_union_pw(isl_ctx
*ctx
)
8233 isl_union_set
*uset
;
8234 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8237 str
= "{ [x] -> x^2 }";
8238 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8239 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
8240 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
8241 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
8242 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
8243 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
8244 isl_union_pw_qpolynomial_free(upwqp1
);
8245 isl_union_pw_qpolynomial_free(upwqp2
);
8249 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8251 a
= "{ A[x] -> x^2 : x >= 0; B[x] -> x }";
8252 b
= "{ A[x] -> x }";
8253 str
= "{ A[x] -> x^2 + x : x >= 0; A[x] -> x : x < 0; B[x] -> x }";
8254 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_add
, str
) < 0)
8256 str
= "{ A[x] -> x^2 - x : x >= 0; A[x] -> -x : x < 0; B[x] -> x }";
8257 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_sub
, str
) < 0)
8260 str
= "{ A[x] -> 0 }";
8261 a
= "{ A[x] -> 1 }";
8262 b
= "{ A[x] -> -1 }";
8263 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_add
, str
) < 0)
8265 a
= "{ A[x] -> 1 }";
8266 b
= "{ A[x] -> 1 }";
8267 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_sub
, str
) < 0)
8270 str
= "{ [A[x] -> B[y,z]] -> x^2 + y * floor(x/4) * floor(z/2); "
8272 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8273 upwqp1
= isl_union_pw_qpolynomial_domain_reverse(upwqp1
);
8274 str
= "{ [B[y,z] -> A[x]] -> x^2 + y * floor(x/4) * floor(z/2) }";
8275 r
= union_pw_qpolynomial_check_plain_equal(upwqp1
, str
);
8276 isl_union_pw_qpolynomial_free(upwqp1
);
8283 /* Inputs for basic tests of functions that select
8284 * subparts of the domain of an isl_multi_union_pw_aff.
8285 * "fn" is the function that is tested.
8286 * "arg" is a string description of the input.
8287 * "res" is a string description of the expected result.
8290 __isl_give isl_union_set
*(*fn
)(
8291 __isl_take isl_multi_union_pw_aff
*mupa
);
8294 } un_locus_tests
[] = {
8295 { &isl_multi_union_pw_aff_zero_union_set
,
8296 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8297 "{ A[0,j]; B[0,j] }" },
8298 { &isl_multi_union_pw_aff_zero_union_set
,
8299 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8300 "{ A[i,i]; B[i,i] : i >= 0 }" },
8301 { &isl_multi_union_pw_aff_zero_union_set
,
8302 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8303 "{ A[i,j]; B[i,i] : i >= 0 }" },
8306 /* Perform some basic tests of functions that select
8307 * subparts of the domain of an isl_multi_union_pw_aff.
8309 static int test_un_locus(isl_ctx
*ctx
)
8313 isl_union_set
*uset
, *res
;
8314 isl_multi_union_pw_aff
*mupa
;
8316 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
8317 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8318 un_locus_tests
[i
].arg
);
8319 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
8320 uset
= un_locus_tests
[i
].fn(mupa
);
8321 ok
= isl_union_set_is_equal(uset
, res
);
8322 isl_union_set_free(uset
);
8323 isl_union_set_free(res
);
8327 isl_die(ctx
, isl_error_unknown
,
8328 "unexpected result", return -1);
8334 /* Inputs for basic tests of functions that select
8335 * subparts of an isl_union_map based on a relation
8336 * specified by an isl_multi_union_pw_aff.
8337 * "fn" is the function that is tested.
8338 * "arg1" and "arg2" are string descriptions of the inputs.
8339 * "res" is a string description of the expected result.
8342 __isl_give isl_union_map
*(*fn
)(
8343 __isl_take isl_union_map
*umap
,
8344 __isl_take isl_multi_union_pw_aff
*mupa
);
8348 } bin_locus_tests
[] = {
8349 { &isl_union_map_eq_at_multi_union_pw_aff
,
8350 "{ A[i,j] -> B[i',j'] }",
8351 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8352 "{ A[i,j] -> B[i,j'] }" },
8353 { &isl_union_map_eq_at_multi_union_pw_aff
,
8354 "{ A[i,j] -> B[i',j'] }",
8355 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8356 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8357 "{ A[i,j] -> B[i,j] }" },
8358 { &isl_union_map_eq_at_multi_union_pw_aff
,
8359 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8360 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8361 "{ A[i,j] -> B[i,j'] }" },
8362 { &isl_union_map_eq_at_multi_union_pw_aff
,
8363 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8364 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8365 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8366 { &isl_union_map_eq_at_multi_union_pw_aff
,
8367 "{ A[i,j] -> B[i',j'] }",
8368 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8369 "{ A[i,j] -> B[i,j'] : i > j }" },
8370 { &isl_union_map_lex_le_at_multi_union_pw_aff
,
8371 "{ A[i,j] -> B[i',j'] }",
8372 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8373 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8374 "{ A[i,j] -> B[i',j'] : i,j <<= i',j' }" },
8375 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
8376 "{ A[i,j] -> B[i',j'] }",
8377 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8378 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8379 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8380 { &isl_union_map_lex_ge_at_multi_union_pw_aff
,
8381 "{ A[i,j] -> B[i',j'] }",
8382 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8383 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8384 "{ A[i,j] -> B[i',j'] : i,j >>= i',j' }" },
8385 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
8386 "{ A[i,j] -> B[i',j'] }",
8387 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8388 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8389 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8390 { &isl_union_map_eq_at_multi_union_pw_aff
,
8391 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8392 "(F[] : { A[i,j]; B[i,j] })",
8393 "{ A[i,j] -> B[i',j'] }" },
8394 { &isl_union_map_eq_at_multi_union_pw_aff
,
8395 "{ A[i,j] -> B[i',j'] }",
8396 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8397 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8398 { &isl_union_map_eq_at_multi_union_pw_aff
,
8399 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8400 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8401 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8402 { &isl_union_map_eq_at_multi_union_pw_aff
,
8403 "{ A[i,j] -> B[i',j'] }",
8404 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8405 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8406 { &isl_union_map_eq_at_multi_union_pw_aff
,
8407 "{ A[i,j] -> B[i',j'] }",
8408 "[N] -> (F[] : { : N >= 0 })",
8409 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8412 /* Perform some basic tests of functions that select
8413 * subparts of an isl_union_map based on a relation
8414 * specified by an isl_multi_union_pw_aff.
8416 static int test_bin_locus(isl_ctx
*ctx
)
8420 isl_union_map
*umap
, *res
;
8421 isl_multi_union_pw_aff
*mupa
;
8423 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
8424 umap
= isl_union_map_read_from_str(ctx
,
8425 bin_locus_tests
[i
].arg1
);
8426 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8427 bin_locus_tests
[i
].arg2
);
8428 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
8429 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
8430 ok
= isl_union_map_is_equal(umap
, res
);
8431 isl_union_map_free(umap
);
8432 isl_union_map_free(res
);
8436 isl_die(ctx
, isl_error_unknown
,
8437 "unexpected result", return -1);
8443 /* Inputs for basic tests of functions that determine
8444 * the part of the domain where two isl_multi_aff objects
8445 * related to each other in a specific way.
8446 * "fn" is the function that is being tested.
8447 * "arg1" and "arg2" are string descriptions of the inputs.
8448 * "res" is a string description of the expected result.
8451 __isl_give isl_set
*(*fn
)(__isl_take isl_multi_aff
*ma1
,
8452 __isl_take isl_multi_aff
*ma2
);
8456 } bin_locus_ma_tests
[] = {
8457 { &isl_multi_aff_lex_le_set
, "{ [] }", "{ [] }", "{ : }" },
8458 { &isl_multi_aff_lex_lt_set
, "{ [] }", "{ [] }", "{ : false }" },
8459 { &isl_multi_aff_lex_le_set
,
8460 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8461 "{ A[i] : i <= 0 }" },
8462 { &isl_multi_aff_lex_lt_set
,
8463 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8464 "{ A[i] : i < 0 }" },
8465 { &isl_multi_aff_lex_le_set
,
8466 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8467 "{ A[i] : i <= 0 }" },
8468 { &isl_multi_aff_lex_le_set
,
8469 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8470 "{ A[i] : i <= 0 }" },
8471 { &isl_multi_aff_lex_le_set
,
8472 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8473 "{ A[i] : i < 0 }" },
8476 /* Perform some basic tests of functions that determine
8477 * the part of the domain where two isl_multi_aff objects
8478 * related to each other in a specific way.
8480 static isl_stat
test_bin_locus_ma(isl_ctx
*ctx
)
8484 for (i
= 0; i
< ARRAY_SIZE(bin_locus_ma_tests
); ++i
) {
8487 isl_multi_aff
*ma1
, *ma2
;
8490 str
= bin_locus_ma_tests
[i
].arg1
;
8491 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8492 str
= bin_locus_ma_tests
[i
].arg2
;
8493 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8494 res
= isl_set_read_from_str(ctx
, bin_locus_ma_tests
[i
].res
);
8495 set
= bin_locus_ma_tests
[i
].fn(ma1
, ma2
);
8496 ok
= isl_set_is_equal(set
, res
);
8500 return isl_stat_error
;
8502 isl_die(ctx
, isl_error_unknown
,
8503 "unexpected result", return isl_stat_error
);
8509 /* Perform basic locus tests.
8511 static int test_locus(isl_ctx
*ctx
)
8513 if (test_un_locus(ctx
) < 0)
8515 if (test_bin_locus(ctx
) < 0)
8517 if (test_bin_locus_ma(ctx
) < 0)
8522 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8523 * defined over the correct domain space.
8525 static int test_eval_1(isl_ctx
*ctx
)
8530 isl_union_pw_qpolynomial
*upwqp
;
8534 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
8535 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8537 set
= isl_set_read_from_str(ctx
, str
);
8538 pnt
= isl_set_sample_point(set
);
8539 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
8540 cmp
= isl_val_cmp_si(v
, 36);
8546 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
8551 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8553 static int test_eval_2(isl_ctx
*ctx
)
8558 isl_qpolynomial
*qp
;
8562 str
= "{ A[x] -> [x] }";
8563 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
8564 str
= "{ A[x] : false }";
8565 set
= isl_set_read_from_str(ctx
, str
);
8566 pnt
= isl_set_sample_point(set
);
8567 v
= isl_qpolynomial_eval(qp
, pnt
);
8568 ok
= isl_val_is_nan(v
);
8574 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
8579 /* Check that a polynomial (without local variables) can be evaluated
8580 * in a rational point.
8582 static isl_stat
test_eval_3(isl_ctx
*ctx
)
8584 isl_pw_qpolynomial
*pwqp
;
8589 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
8590 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
8591 v
= isl_val_read_from_str(ctx
, "1/2");
8592 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
8593 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
8594 r
= val_check_equal(v
, "1/4");
8600 /* Inputs for isl_pw_aff_eval test.
8601 * "f" is the affine function.
8602 * "p" is the point where the function should be evaluated.
8603 * "res" is the expected result.
8609 } aff_eval_tests
[] = {
8610 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8611 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8612 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8613 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8614 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8615 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8616 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8617 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8618 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8619 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8620 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8621 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8622 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8623 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8624 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8625 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8626 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8627 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8628 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8629 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8630 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8631 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8632 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8633 { "[m, n] -> { [2m + 3n] }", "[n=1, m=10] -> { : }", "23" },
8636 /* Perform basic isl_pw_aff_eval tests.
8638 static int test_eval_aff(isl_ctx
*ctx
)
8642 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
8649 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
8650 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
8651 pnt
= isl_set_sample_point(set
);
8652 v
= isl_pw_aff_eval(pa
, pnt
);
8653 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
8661 /* Perform basic evaluation tests.
8663 static int test_eval(isl_ctx
*ctx
)
8665 if (test_eval_1(ctx
) < 0)
8667 if (test_eval_2(ctx
) < 0)
8669 if (test_eval_3(ctx
) < 0)
8671 if (test_eval_aff(ctx
) < 0)
8676 /* Descriptions of sets that are tested for reparsing after printing.
8678 const char *output_tests
[] = {
8679 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8682 "{ [x] : x mod 2 = 0 }",
8683 "{ [x] : x mod 2 = 1 }",
8684 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8685 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8686 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8687 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8688 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8689 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8692 /* Check that printing a set and reparsing a set from the printed output
8693 * results in the same set.
8695 static int test_output_set(isl_ctx
*ctx
)
8699 isl_set
*set1
, *set2
;
8702 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
8703 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
8704 str
= isl_set_to_str(set1
);
8705 set2
= isl_set_read_from_str(ctx
, str
);
8707 equal
= isl_set_is_equal(set1
, set2
);
8713 isl_die(ctx
, isl_error_unknown
,
8714 "parsed output not the same", return -1);
8720 /* Check that an isl_multi_aff is printed using a consistent space.
8722 static isl_stat
test_output_ma(isl_ctx
*ctx
)
8727 isl_multi_aff
*ma
, *ma2
;
8729 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8730 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8731 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
8732 str
= isl_multi_aff_to_str(ma
);
8733 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8735 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
8736 isl_multi_aff_free(ma2
);
8737 isl_multi_aff_free(ma
);
8740 return isl_stat_error
;
8742 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8743 return isl_stat_error
);
8748 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8750 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
8755 isl_multi_pw_aff
*mpa
, *mpa2
;
8757 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8758 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8759 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
8760 str
= isl_multi_pw_aff_to_str(mpa
);
8761 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8763 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8764 isl_multi_pw_aff_free(mpa2
);
8765 isl_multi_pw_aff_free(mpa
);
8768 return isl_stat_error
;
8770 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8771 return isl_stat_error
);
8776 int test_output(isl_ctx
*ctx
)
8784 if (test_output_set(ctx
) < 0)
8786 if (test_output_ma(ctx
) < 0)
8788 if (test_output_mpa(ctx
) < 0)
8791 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8792 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8794 p
= isl_printer_to_str(ctx
);
8795 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
8796 p
= isl_printer_print_pw_aff(p
, pa
);
8797 s
= isl_printer_get_str(p
);
8798 isl_printer_free(p
);
8799 isl_pw_aff_free(pa
);
8803 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8808 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8813 int test_sample(isl_ctx
*ctx
)
8816 isl_basic_set
*bset1
, *bset2
;
8819 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8820 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8821 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8822 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8823 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8824 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8825 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8826 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8827 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8828 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8829 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8830 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8831 "d - 1073741821e and "
8832 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8833 "3j >= 1 - a + b + 2e and "
8834 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8835 "3i <= 4 - a + 4b - e and "
8836 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8837 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8838 "c <= -1 + a and 3i >= -2 - a + 3e and "
8839 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8840 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8841 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8842 "1073741823e >= 1 + 1073741823b - d and "
8843 "3i >= 1073741823b + c - 1073741823e - f and "
8844 "3i >= 1 + 2b + e + 3g }";
8845 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8846 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
8847 empty
= isl_basic_set_is_empty(bset2
);
8848 subset
= isl_basic_set_is_subset(bset2
, bset1
);
8849 isl_basic_set_free(bset1
);
8850 isl_basic_set_free(bset2
);
8851 if (empty
< 0 || subset
< 0)
8854 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
8856 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
8861 /* Perform a projection on a basic set that is known to be empty
8862 * but that has not been assigned a canonical representation.
8863 * Earlier versions of isl would run into a stack overflow
8866 static int test_empty_projection(isl_ctx
*ctx
)
8870 isl_basic_set
*bset
;
8872 str
= "{ [a, b, c, d, e, f, g, h] : 5f = 1 + 4a - b + 5c - d - 2e and "
8873 "3h = 2 + b + c and 14c >= 9 - 3a + 25b and "
8874 "4c <= 50 - 3a + 23b and 6b <= -39 + a and "
8875 "9g >= -6 + 3a + b + c and e < a + b - 2d and "
8876 "7d >= -5 + 2a + 2b and 5g >= -14 + a - 4b + d + 2e and "
8877 "9g <= -28 - 5b - 2c + 3d + 6e }";
8878 bset
= isl_basic_set_read_from_str(ctx
, str
);
8879 empty
= isl_basic_set_is_empty(bset
);
8880 bset
= isl_basic_set_params(bset
);
8881 isl_basic_set_free(bset
);
8889 int test_slice(isl_ctx
*ctx
)
8895 str
= "{ [i] -> [j] }";
8896 map
= isl_map_read_from_str(ctx
, str
);
8897 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8898 equal
= map_check_equal(map
, "{ [i] -> [i] }");
8903 str
= "{ [i] -> [j] }";
8904 map
= isl_map_read_from_str(ctx
, str
);
8905 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8906 equal
= map_check_equal(map
, "{ [i] -> [j] }");
8911 str
= "{ [i] -> [j] }";
8912 map
= isl_map_read_from_str(ctx
, str
);
8913 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8914 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8919 str
= "{ [i] -> [j] }";
8920 map
= isl_map_read_from_str(ctx
, str
);
8921 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8922 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8927 str
= "{ [i] -> [j] }";
8928 map
= isl_map_read_from_str(ctx
, str
);
8929 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8930 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8935 str
= "{ [i] -> [j] }";
8936 map
= isl_map_read_from_str(ctx
, str
);
8937 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8938 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8946 int test_eliminate(isl_ctx
*ctx
)
8952 str
= "{ [i] -> [j] : i = 2j }";
8953 map
= isl_map_read_from_str(ctx
, str
);
8954 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8955 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8963 /* Check basic functionality of isl_map_deltas_map.
8965 static int test_deltas_map(isl_ctx
*ctx
)
8971 str
= "{ A[i] -> A[i + 1] }";
8972 map
= isl_map_read_from_str(ctx
, str
);
8973 map
= isl_map_deltas_map(map
);
8974 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8982 /* Check that isl_set_dim_residue_class detects that the values of j
8983 * in the set below are all odd and that it does not detect any spurious
8986 static int test_residue_class(isl_ctx
*ctx
)
8993 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8994 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8995 set
= isl_set_read_from_str(ctx
, str
);
8998 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
9000 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
9001 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
9002 res
= isl_stat_error
);
9010 static int test_align_parameters_1(isl_ctx
*ctx
)
9014 isl_multi_aff
*ma1
, *ma2
;
9017 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
9018 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
9020 space
= isl_space_params_alloc(ctx
, 1);
9021 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
9022 ma1
= isl_multi_aff_align_params(ma1
, space
);
9024 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
9025 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
9027 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9029 isl_multi_aff_free(ma1
);
9030 isl_multi_aff_free(ma2
);
9035 isl_die(ctx
, isl_error_unknown
,
9036 "result not as expected", return -1);
9041 /* Check the isl_multi_*_from_*_list operation in case inputs
9042 * have unaligned parameters.
9043 * In particular, older versions of isl would simply fail
9044 * (without printing any error message).
9046 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
9053 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
9054 space
= isl_map_get_space(map
);
9057 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
9058 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
9059 isl_multi_aff_free(ma
);
9062 return isl_stat_error
;
9066 /* Perform basic parameter alignment tests.
9068 static int test_align_parameters(isl_ctx
*ctx
)
9070 if (test_align_parameters_1(ctx
) < 0)
9072 if (test_align_parameters_2(ctx
) < 0)
9078 /* Check that isl_*_drop_unused_params actually drops the unused parameters
9079 * by comparing the result using isl_*_plain_is_equal.
9080 * Note that this assumes that isl_*_plain_is_equal does not consider
9081 * objects that only differ by unused parameters to be equal.
9083 int test_drop_unused_parameters(isl_ctx
*ctx
)
9085 const char *str_with
, *str_without
;
9086 isl_basic_set
*bset1
, *bset2
;
9087 isl_set
*set1
, *set2
;
9088 isl_pw_aff
*pwa1
, *pwa2
;
9091 str_with
= "[n, m, o] -> { [m] }";
9092 str_without
= "[m] -> { [m] }";
9094 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
9095 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
9096 bset1
= isl_basic_set_drop_unused_params(bset1
);
9097 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
9098 isl_basic_set_free(bset1
);
9099 isl_basic_set_free(bset2
);
9104 isl_die(ctx
, isl_error_unknown
,
9105 "result not as expected", return -1);
9107 set1
= isl_set_read_from_str(ctx
, str_with
);
9108 set2
= isl_set_read_from_str(ctx
, str_without
);
9109 set1
= isl_set_drop_unused_params(set1
);
9110 equal
= isl_set_plain_is_equal(set1
, set2
);
9117 isl_die(ctx
, isl_error_unknown
,
9118 "result not as expected", return -1);
9120 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
9121 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
9122 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
9123 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
9124 isl_pw_aff_free(pwa1
);
9125 isl_pw_aff_free(pwa2
);
9130 isl_die(ctx
, isl_error_unknown
,
9131 "result not as expected", return -1);
9136 static int test_list(isl_ctx
*ctx
)
9138 isl_id
*a
, *b
, *c
, *d
, *id
;
9143 a
= isl_id_alloc(ctx
, "a", NULL
);
9144 b
= isl_id_alloc(ctx
, "b", NULL
);
9145 c
= isl_id_alloc(ctx
, "c", NULL
);
9146 d
= isl_id_alloc(ctx
, "d", NULL
);
9148 list
= isl_id_list_alloc(ctx
, 4);
9149 list
= isl_id_list_add(list
, b
);
9150 list
= isl_id_list_insert(list
, 0, a
);
9151 list
= isl_id_list_add(list
, c
);
9152 list
= isl_id_list_add(list
, d
);
9153 list
= isl_id_list_drop(list
, 1, 1);
9155 n
= isl_id_list_n_id(list
);
9159 isl_id_list_free(list
);
9160 isl_die(ctx
, isl_error_unknown
,
9161 "unexpected number of elements in list", return -1);
9164 id
= isl_id_list_get_id(list
, 0);
9167 id
= isl_id_list_get_id(list
, 1);
9170 id
= isl_id_list_get_id(list
, 2);
9174 isl_id_list_free(list
);
9177 isl_die(ctx
, isl_error_unknown
,
9178 "unexpected elements in list", return -1);
9183 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
9185 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
9190 isl_basic_set
*bset1
, *bset2
;
9192 str
= "[N] -> { A[0, N + 1] }";
9193 ma
= isl_multi_aff_read_from_str(ctx
, str
);
9194 bset1
= isl_basic_set_read_from_str(ctx
, str
);
9195 bset2
= isl_basic_set_from_multi_aff(ma
);
9196 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9197 isl_basic_set_free(bset1
);
9198 isl_basic_set_free(bset2
);
9200 return isl_stat_error
;
9202 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9203 return isl_stat_error
);
9207 const char *set_conversion_tests
[] = {
9208 "[N] -> { [i] : N - 1 <= 2 i <= N }",
9209 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
9210 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9211 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9212 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
9213 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
9214 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9215 "-3 + c <= d <= 28 + c) }",
9218 /* Check that converting from isl_set to isl_pw_multi_aff and back
9219 * to isl_set produces the original isl_set.
9221 static int test_set_conversion(isl_ctx
*ctx
)
9225 isl_set
*set1
, *set2
;
9226 isl_pw_multi_aff
*pma
;
9229 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
9230 str
= set_conversion_tests
[i
];
9231 set1
= isl_set_read_from_str(ctx
, str
);
9232 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
9233 set2
= isl_set_from_pw_multi_aff(pma
);
9234 equal
= isl_set_is_equal(set1
, set2
);
9241 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9248 const char *conversion_tests
[] = {
9249 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9250 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9251 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9252 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9254 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9255 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9256 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9259 /* Check that converting from isl_map to isl_pw_multi_aff and back
9260 * to isl_map produces the original isl_map.
9262 static int test_map_conversion(isl_ctx
*ctx
)
9265 isl_map
*map1
, *map2
;
9266 isl_pw_multi_aff
*pma
;
9269 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
9270 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
9271 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
9272 map2
= isl_map_from_pw_multi_aff(pma
);
9273 equal
= isl_map_is_equal(map1
, map2
);
9280 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9287 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9288 * to isl_multi_pw_aff and back.
9290 const char *mpa_conversion_tests
[] = {
9292 "{ [x] -> A[x] : x >= 0 }",
9293 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9294 "{ [x] -> A[x, x + 1] }",
9296 "{ [x] -> A[] : x >= 0 }",
9299 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9300 * back to isl_pw_multi_aff preserves the original meaning.
9302 static int test_mpa_conversion(isl_ctx
*ctx
)
9305 isl_pw_multi_aff
*pma1
, *pma2
;
9306 isl_multi_pw_aff
*mpa
;
9309 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
9311 str
= mpa_conversion_tests
[i
];
9312 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9313 pma2
= isl_pw_multi_aff_copy(pma1
);
9314 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
9315 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
9316 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9317 isl_pw_multi_aff_free(pma1
);
9318 isl_pw_multi_aff_free(pma2
);
9323 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9330 /* Descriptions of union maps that should be convertible
9331 * to an isl_multi_union_pw_aff.
9333 const char *umap_mupa_conversion_tests
[] = {
9334 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9335 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9336 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9337 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9339 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9340 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9341 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9342 "{ A[] -> B[0]; C[] -> B[1] }",
9343 "{ A[] -> B[]; C[] -> B[] }",
9346 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9347 * to isl_union_map produces the original isl_union_map.
9349 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
9352 isl_union_map
*umap1
, *umap2
;
9353 isl_multi_union_pw_aff
*mupa
;
9356 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
9358 str
= umap_mupa_conversion_tests
[i
];
9359 umap1
= isl_union_map_read_from_str(ctx
, str
);
9360 umap2
= isl_union_map_copy(umap1
);
9361 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
9362 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
9363 equal
= isl_union_map_is_equal(umap1
, umap2
);
9364 isl_union_map_free(umap1
);
9365 isl_union_map_free(umap2
);
9370 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9377 static int test_conversion(isl_ctx
*ctx
)
9379 if (test_ma_conversion(ctx
) < 0)
9381 if (test_set_conversion(ctx
) < 0)
9383 if (test_map_conversion(ctx
) < 0)
9385 if (test_mpa_conversion(ctx
) < 0)
9387 if (test_union_map_mupa_conversion(ctx
) < 0)
9392 /* Check that isl_basic_map_curry does not modify input.
9394 static int test_curry(isl_ctx
*ctx
)
9397 isl_basic_map
*bmap1
, *bmap2
;
9400 str
= "{ [A[] -> B[]] -> C[] }";
9401 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
9402 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
9403 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
9404 isl_basic_map_free(bmap1
);
9405 isl_basic_map_free(bmap2
);
9410 isl_die(ctx
, isl_error_unknown
,
9411 "curried map should not be equal to original",
9421 } pullback_tests
[] = {
9422 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9423 "{ A[a,b] -> C[b + 2a] }" },
9424 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9425 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9426 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9427 "{ A[a] -> C[(a)/6] }" },
9428 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9429 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9430 "{ A[a] -> C[(2a)/3] }" },
9431 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9432 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9433 "{ A[i,j] -> C[i + j, i + j] }"},
9434 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9435 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9436 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9437 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9438 "{ [i, j] -> [floor((i)/3), j] }",
9439 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9442 static int test_pullback(isl_ctx
*ctx
)
9445 isl_multi_aff
*ma1
, *ma2
;
9449 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
9450 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
9451 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
9452 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
9453 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
9454 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9455 isl_multi_aff_free(ma1
);
9456 isl_multi_aff_free(ma2
);
9460 isl_die(ctx
, isl_error_unknown
, "bad pullback",
9467 /* Check that negation is printed correctly and that equal expressions
9468 * are correctly identified.
9470 static int test_ast(isl_ctx
*ctx
)
9472 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
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 expr2
= isl_ast_expr_copy(expr
);
9480 expr
= isl_ast_expr_neg(expr
);
9481 expr2
= isl_ast_expr_neg(expr2
);
9482 equal
= isl_ast_expr_is_equal(expr
, expr2
);
9483 str
= isl_ast_expr_to_C_str(expr
);
9484 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
9486 isl_ast_expr_free(expr
);
9487 isl_ast_expr_free(expr2
);
9489 if (ok
< 0 || equal
< 0)
9492 isl_die(ctx
, isl_error_unknown
,
9493 "equal expressions not considered equal", return -1);
9495 isl_die(ctx
, isl_error_unknown
,
9496 "isl_ast_expr printed incorrectly", return -1);
9498 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9499 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9500 expr
= isl_ast_expr_add(expr1
, expr2
);
9501 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
9502 expr
= isl_ast_expr_sub(expr3
, expr
);
9503 str
= isl_ast_expr_to_C_str(expr
);
9504 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
9506 isl_ast_expr_free(expr
);
9511 isl_die(ctx
, isl_error_unknown
,
9512 "isl_ast_expr printed incorrectly", return -1);
9517 /* Check that isl_ast_build_expr_from_set returns a valid expression
9518 * for an empty set. Note that isl_ast_build_expr_from_set getting
9519 * called on an empty set probably indicates a bug in the caller.
9521 static int test_ast_build(isl_ctx
*ctx
)
9524 isl_ast_build
*build
;
9527 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9528 build
= isl_ast_build_from_context(set
);
9530 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
9531 expr
= isl_ast_build_expr_from_set(build
, set
);
9533 isl_ast_expr_free(expr
);
9534 isl_ast_build_free(build
);
9542 /* Internal data structure for before_for and after_for callbacks.
9544 * depth is the current depth
9545 * before is the number of times before_for has been called
9546 * after is the number of times after_for has been called
9548 struct isl_test_codegen_data
{
9554 /* This function is called before each for loop in the AST generated
9555 * from test_ast_gen1.
9557 * Increment the number of calls and the depth.
9558 * Check that the space returned by isl_ast_build_get_schedule_space
9559 * matches the target space of the schedule returned by
9560 * isl_ast_build_get_schedule.
9561 * Return an isl_id that is checked by the corresponding call
9564 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
9567 struct isl_test_codegen_data
*data
= user
;
9570 isl_union_map
*schedule
;
9571 isl_union_set
*uset
;
9577 ctx
= isl_ast_build_get_ctx(build
);
9579 if (data
->before
>= 3)
9580 isl_die(ctx
, isl_error_unknown
,
9581 "unexpected number of for nodes", return NULL
);
9582 if (data
->depth
< 0 || data
->depth
>= 2)
9583 isl_die(ctx
, isl_error_unknown
,
9584 "unexpected depth", return NULL
);
9586 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
9590 schedule
= isl_ast_build_get_schedule(build
);
9591 uset
= isl_union_map_range(schedule
);
9592 n
= isl_union_set_n_set(uset
);
9594 isl_union_set_free(uset
);
9597 isl_die(ctx
, isl_error_unknown
,
9598 "expecting single range space", return NULL
);
9601 space
= isl_ast_build_get_schedule_space(build
);
9602 set
= isl_union_set_extract_set(uset
, space
);
9603 isl_union_set_free(uset
);
9604 empty
= isl_set_is_empty(set
);
9610 isl_die(ctx
, isl_error_unknown
,
9611 "spaces don't match", return NULL
);
9613 return isl_id_alloc(ctx
, name
, NULL
);
9616 /* This function is called after each for loop in the AST generated
9617 * from test_ast_gen1.
9619 * Increment the number of calls and decrement the depth.
9620 * Check that the annotation attached to the node matches
9621 * the isl_id returned by the corresponding call to before_for.
9623 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
9624 __isl_keep isl_ast_build
*build
, void *user
)
9626 struct isl_test_codegen_data
*data
= user
;
9634 if (data
->after
> data
->before
)
9635 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9636 "mismatch in number of for nodes",
9637 return isl_ast_node_free(node
));
9639 id
= isl_ast_node_get_annotation(node
);
9641 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9642 "missing annotation", return isl_ast_node_free(node
));
9644 name
= isl_id_get_name(id
);
9645 valid
= name
&& atoi(name
+ 1) == data
->depth
;
9649 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9650 "wrong annotation", return isl_ast_node_free(node
));
9655 /* This function is called after node in the AST generated
9656 * from test_ast_gen1.
9658 * Increment the count in "user" if this is a for node and
9659 * return true to indicate that descendant should also be visited.
9661 static isl_bool
count_for(__isl_keep isl_ast_node
*node
, void *user
)
9665 if (isl_ast_node_get_type(node
) == isl_ast_node_for
)
9668 return isl_bool_true
;
9671 /* If "node" is a block node, then replace it by its first child.
9673 static __isl_give isl_ast_node
*select_first(__isl_take isl_ast_node
*node
,
9676 isl_ast_node_list
*children
;
9677 isl_ast_node
*child
;
9679 if (isl_ast_node_get_type(node
) != isl_ast_node_block
)
9682 children
= isl_ast_node_block_get_children(node
);
9683 child
= isl_ast_node_list_get_at(children
, 0);
9684 isl_ast_node_list_free(children
);
9685 isl_ast_node_free(node
);
9690 /* Check that the before_each_for and after_each_for callbacks
9691 * are called for each for loop in the generated code,
9692 * that they are called in the right order and that the isl_id
9693 * returned from the before_each_for callback is attached to
9694 * the isl_ast_node passed to the corresponding after_each_for call.
9696 * Additionally, check the basic functionality of
9697 * isl_ast_node_foreach_descendant_top_down by counting the number
9698 * of for loops in the resulting AST,
9699 * as well as that of isl_ast_node_map_descendant_bottom_up
9700 * by replacing the block node by its first child and
9701 * counting the number of for loops again.
9703 static isl_stat
test_ast_gen1(isl_ctx
*ctx
)
9706 int modified_count
= 0;
9709 isl_union_map
*schedule
;
9710 isl_ast_build
*build
;
9712 struct isl_test_codegen_data data
;
9714 str
= "[N] -> { : N >= 10 }";
9715 set
= isl_set_read_from_str(ctx
, str
);
9716 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9717 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9718 schedule
= isl_union_map_read_from_str(ctx
, str
);
9723 build
= isl_ast_build_from_context(set
);
9724 build
= isl_ast_build_set_before_each_for(build
,
9725 &before_for
, &data
);
9726 build
= isl_ast_build_set_after_each_for(build
,
9728 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9729 isl_ast_build_free(build
);
9731 if (isl_ast_node_foreach_descendant_top_down(tree
,
9732 &count_for
, &count
) < 0)
9733 tree
= isl_ast_node_free(tree
);
9735 tree
= isl_ast_node_map_descendant_bottom_up(tree
, &select_first
, NULL
);
9737 if (isl_ast_node_foreach_descendant_top_down(tree
, &count_for
,
9738 &modified_count
) < 0)
9739 tree
= isl_ast_node_free(tree
);
9742 return isl_stat_error
;
9744 isl_ast_node_free(tree
);
9746 if (data
.before
!= 3 || data
.after
!= 3 || count
!= 3)
9747 isl_die(ctx
, isl_error_unknown
,
9748 "unexpected number of for nodes",
9749 return isl_stat_error
);
9751 if (modified_count
!= 2)
9752 isl_die(ctx
, isl_error_unknown
,
9753 "unexpected number of for nodes after changes",
9754 return isl_stat_error
);
9759 /* Check that the AST generator handles domains that are integrally disjoint
9760 * but not rationally disjoint.
9762 static int test_ast_gen2(isl_ctx
*ctx
)
9766 isl_union_map
*schedule
;
9767 isl_union_map
*options
;
9768 isl_ast_build
*build
;
9771 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9772 schedule
= isl_union_map_read_from_str(ctx
, str
);
9773 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9774 build
= isl_ast_build_from_context(set
);
9776 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9777 options
= isl_union_map_read_from_str(ctx
, str
);
9778 build
= isl_ast_build_set_options(build
, options
);
9779 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9780 isl_ast_build_free(build
);
9783 isl_ast_node_free(tree
);
9788 /* Increment *user on each call.
9790 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
9791 __isl_keep isl_ast_build
*build
, void *user
)
9800 /* Test that unrolling tries to minimize the number of instances.
9801 * In particular, for the schedule given below, make sure it generates
9802 * 3 nodes (rather than 101).
9804 static int test_ast_gen3(isl_ctx
*ctx
)
9808 isl_union_map
*schedule
;
9809 isl_union_map
*options
;
9810 isl_ast_build
*build
;
9814 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9815 schedule
= isl_union_map_read_from_str(ctx
, str
);
9816 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9818 str
= "{ [i] -> unroll[0] }";
9819 options
= isl_union_map_read_from_str(ctx
, str
);
9821 build
= isl_ast_build_from_context(set
);
9822 build
= isl_ast_build_set_options(build
, options
);
9823 build
= isl_ast_build_set_at_each_domain(build
,
9824 &count_domains
, &n_domain
);
9825 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9826 isl_ast_build_free(build
);
9830 isl_ast_node_free(tree
);
9833 isl_die(ctx
, isl_error_unknown
,
9834 "unexpected number of for nodes", return -1);
9839 /* Check that if the ast_build_exploit_nested_bounds options is set,
9840 * we do not get an outer if node in the generated AST,
9841 * while we do get such an outer if node if the options is not set.
9843 static int test_ast_gen4(isl_ctx
*ctx
)
9847 isl_union_map
*schedule
;
9848 isl_ast_build
*build
;
9850 enum isl_ast_node_type type
;
9853 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9854 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9856 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9858 schedule
= isl_union_map_read_from_str(ctx
, str
);
9859 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9860 build
= isl_ast_build_from_context(set
);
9861 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9862 isl_ast_build_free(build
);
9866 type
= isl_ast_node_get_type(tree
);
9867 isl_ast_node_free(tree
);
9869 if (type
== isl_ast_node_if
)
9870 isl_die(ctx
, isl_error_unknown
,
9871 "not expecting if node", return -1);
9873 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9875 schedule
= isl_union_map_read_from_str(ctx
, str
);
9876 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9877 build
= isl_ast_build_from_context(set
);
9878 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9879 isl_ast_build_free(build
);
9883 type
= isl_ast_node_get_type(tree
);
9884 isl_ast_node_free(tree
);
9886 if (type
!= isl_ast_node_if
)
9887 isl_die(ctx
, isl_error_unknown
,
9888 "expecting if node", return -1);
9890 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9895 /* This function is called for each leaf in the AST generated
9896 * from test_ast_gen5.
9898 * We finalize the AST generation by extending the outer schedule
9899 * with a zero-dimensional schedule. If this results in any for loops,
9900 * then this means that we did not pass along enough information
9901 * about the outer schedule to the inner AST generation.
9903 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9906 isl_union_map
*schedule
, *extra
;
9909 schedule
= isl_ast_build_get_schedule(build
);
9910 extra
= isl_union_map_copy(schedule
);
9911 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9912 schedule
= isl_union_map_range_product(schedule
, extra
);
9913 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9914 isl_ast_build_free(build
);
9919 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9920 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9921 "code should not contain any for loop",
9922 return isl_ast_node_free(tree
));
9927 /* Check that we do not lose any information when going back and
9928 * forth between internal and external schedule.
9930 * In particular, we create an AST where we unroll the only
9931 * non-constant dimension in the schedule. We therefore do
9932 * not expect any for loops in the AST. However, older versions
9933 * of isl would not pass along enough information about the outer
9934 * schedule when performing an inner code generation from a create_leaf
9935 * callback, resulting in the inner code generation producing a for loop.
9937 static int test_ast_gen5(isl_ctx
*ctx
)
9941 isl_union_map
*schedule
, *options
;
9942 isl_ast_build
*build
;
9945 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9946 schedule
= isl_union_map_read_from_str(ctx
, str
);
9948 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9949 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9950 options
= isl_union_map_read_from_str(ctx
, str
);
9952 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9953 build
= isl_ast_build_from_context(set
);
9954 build
= isl_ast_build_set_options(build
, options
);
9955 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9956 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9957 isl_ast_build_free(build
);
9958 isl_ast_node_free(tree
);
9965 /* Check that the expression
9967 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9969 * is not combined into
9973 * as this would result in n/2 being evaluated in parts of
9974 * the definition domain where n is not a multiple of 2.
9976 static int test_ast_expr(isl_ctx
*ctx
)
9980 isl_ast_build
*build
;
9985 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9986 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9988 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9989 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9990 build
= isl_ast_build_alloc(ctx
);
9991 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9992 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9993 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9994 isl_ast_build_free(build
);
9995 isl_ast_expr_free(expr
);
9997 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
10002 isl_die(ctx
, isl_error_unknown
,
10003 "expressions should not be combined", return -1);
10008 static int test_ast_gen(isl_ctx
*ctx
)
10010 if (test_ast_gen1(ctx
) < 0)
10012 if (test_ast_gen2(ctx
) < 0)
10014 if (test_ast_gen3(ctx
) < 0)
10016 if (test_ast_gen4(ctx
) < 0)
10018 if (test_ast_gen5(ctx
) < 0)
10020 if (test_ast_expr(ctx
) < 0)
10025 /* Check if dropping output dimensions from an isl_pw_multi_aff
10028 static int test_pw_multi_aff(isl_ctx
*ctx
)
10031 isl_pw_multi_aff
*pma1
, *pma2
;
10034 str
= "{ [i,j] -> [i+j, 4i-j] }";
10035 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
10036 str
= "{ [i,j] -> [4i-j] }";
10037 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
10039 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
10041 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
10043 isl_pw_multi_aff_free(pma1
);
10044 isl_pw_multi_aff_free(pma2
);
10048 isl_die(ctx
, isl_error_unknown
,
10049 "expressions not equal", return -1);
10054 /* Check that we can properly parse multi piecewise affine expressions
10055 * where the piecewise affine expressions have different domains.
10057 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
10060 isl_set
*dom
, *dom2
;
10061 isl_multi_pw_aff
*mpa1
, *mpa2
;
10066 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
10067 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
10068 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
10069 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
10070 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
10071 str
= "{ [i] -> [(i : i > 0), 2i] }";
10072 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10074 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
10076 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
10077 dom
= isl_pw_aff_domain(pa
);
10078 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
10079 dom2
= isl_pw_aff_domain(pa
);
10080 equal_domain
= isl_set_is_equal(dom
, dom2
);
10083 isl_set_free(dom2
);
10084 isl_multi_pw_aff_free(mpa1
);
10085 isl_multi_pw_aff_free(mpa2
);
10090 isl_die(ctx
, isl_error_unknown
,
10091 "expressions not equal", return -1);
10093 if (equal_domain
< 0)
10096 isl_die(ctx
, isl_error_unknown
,
10097 "domains unexpectedly equal", return -1);
10102 /* Check that the dimensions in the explicit domain
10103 * of a multi piecewise affine expression are properly
10104 * taken into account.
10106 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
10109 isl_bool involves1
, involves2
, involves3
, equal
;
10110 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
10112 str
= "{ A[x,y] -> B[] : x >= y }";
10113 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10114 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
10115 mpa1
= isl_multi_pw_aff_copy(mpa
);
10117 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
10118 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
10119 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
10120 str
= "{ [a,x,y] -> B[] : x >= y }";
10121 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10122 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
10123 isl_multi_pw_aff_free(mpa2
);
10125 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
10126 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
10127 if (equal
>= 0 && equal
)
10128 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
10129 isl_multi_pw_aff_free(mpa1
);
10130 isl_multi_pw_aff_free(mpa
);
10132 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
10135 isl_die(ctx
, isl_error_unknown
,
10136 "incorrect result of dimension insertion/removal",
10137 return isl_stat_error
);
10138 if (!involves1
|| involves2
|| !involves3
)
10139 isl_die(ctx
, isl_error_unknown
,
10140 "incorrect characterization of involved dimensions",
10141 return isl_stat_error
);
10146 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
10147 * sets the explicit domain of a zero-dimensional result,
10148 * such that it can be converted to an isl_union_map.
10150 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
10153 isl_union_set
*dom
;
10155 isl_multi_union_pw_aff
*mupa
;
10156 isl_union_map
*umap
;
10158 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
10159 space
= isl_union_set_get_space(dom
);
10160 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
10161 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
10162 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
10163 isl_union_map_free(umap
);
10165 return isl_stat_error
;
10167 return isl_stat_ok
;
10170 /* String descriptions of boxes that
10171 * are used for reconstructing box maps from their lower and upper bounds.
10173 static const char *multi_pw_aff_box_tests
[] = {
10174 "{ A[x, y] -> [] : x + y >= 0 }",
10175 "[N] -> { A[x, y] -> [x] : x + y <= N }",
10176 "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
10179 /* Check that map representations of boxes can be reconstructed
10180 * from their lower and upper bounds.
10182 static isl_stat
test_multi_pw_aff_box(isl_ctx
*ctx
)
10186 for (i
= 0; i
< ARRAY_SIZE(multi_pw_aff_box_tests
); ++i
) {
10189 isl_map
*map
, *box
;
10190 isl_multi_pw_aff
*min
, *max
;
10192 str
= multi_pw_aff_box_tests
[i
];
10193 map
= isl_map_read_from_str(ctx
, str
);
10194 min
= isl_map_min_multi_pw_aff(isl_map_copy(map
));
10195 max
= isl_map_max_multi_pw_aff(isl_map_copy(map
));
10196 box
= isl_map_universe(isl_map_get_space(map
));
10197 box
= isl_map_lower_bound_multi_pw_aff(box
, min
);
10198 box
= isl_map_upper_bound_multi_pw_aff(box
, max
);
10199 equal
= isl_map_is_equal(map
, box
);
10203 return isl_stat_error
;
10205 isl_die(ctx
, isl_error_unknown
,
10206 "unexpected result", return isl_stat_error
);
10209 return isl_stat_ok
;
10212 /* Perform some tests on multi piecewise affine expressions.
10214 static int test_multi_pw_aff(isl_ctx
*ctx
)
10216 if (test_multi_pw_aff_1(ctx
) < 0)
10218 if (test_multi_pw_aff_2(ctx
) < 0)
10220 if (test_multi_pw_aff_3(ctx
) < 0)
10222 if (test_multi_pw_aff_box(ctx
) < 0)
10227 /* This is a regression test for a bug where isl_basic_map_simplify
10228 * would end up in an infinite loop. In particular, we construct
10229 * an empty basic set that is not obviously empty.
10230 * isl_basic_set_is_empty marks the basic set as empty.
10231 * After projecting out i3, the variable can be dropped completely,
10232 * but isl_basic_map_simplify refrains from doing so if the basic set
10233 * is empty and would end up in an infinite loop if it didn't test
10234 * explicitly for empty basic maps in the outer loop.
10236 static int test_simplify_1(isl_ctx
*ctx
)
10239 isl_basic_set
*bset
;
10242 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10243 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10244 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10246 bset
= isl_basic_set_read_from_str(ctx
, str
);
10247 empty
= isl_basic_set_is_empty(bset
);
10248 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
10249 isl_basic_set_free(bset
);
10253 isl_die(ctx
, isl_error_unknown
,
10254 "basic set should be empty", return -1);
10259 /* Check that the equality in the set description below
10260 * is simplified away.
10262 static int test_simplify_2(isl_ctx
*ctx
)
10265 isl_basic_set
*bset
;
10268 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10269 bset
= isl_basic_set_read_from_str(ctx
, str
);
10270 universe
= isl_basic_set_plain_is_universe(bset
);
10271 isl_basic_set_free(bset
);
10276 isl_die(ctx
, isl_error_unknown
,
10277 "equality not simplified away", return -1);
10281 /* Some simplification tests.
10283 static int test_simplify(isl_ctx
*ctx
)
10285 if (test_simplify_1(ctx
) < 0)
10287 if (test_simplify_2(ctx
) < 0)
10292 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10293 * with gbr context would fail to disable the use of the shifted tableau
10294 * when transferring equalities for the input to the context, resulting
10295 * in invalid sample values.
10297 static int test_partial_lexmin(isl_ctx
*ctx
)
10300 isl_basic_set
*bset
;
10301 isl_basic_map
*bmap
;
10304 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10305 bmap
= isl_basic_map_read_from_str(ctx
, str
);
10306 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10307 bset
= isl_basic_set_read_from_str(ctx
, str
);
10308 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
10317 /* Check that the variable compression performed on the existentially
10318 * quantified variables inside isl_basic_set_compute_divs is not confused
10319 * by the implicit equalities among the parameters.
10321 static int test_compute_divs(isl_ctx
*ctx
)
10324 isl_basic_set
*bset
;
10327 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10328 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10329 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10330 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10331 bset
= isl_basic_set_read_from_str(ctx
, str
);
10332 set
= isl_basic_set_compute_divs(bset
);
10340 /* Check that isl_schedule_get_map is not confused by a schedule tree
10341 * with divergent filter node parameters, as can result from a call
10342 * to isl_schedule_intersect_domain.
10344 static int test_schedule_tree(isl_ctx
*ctx
)
10347 isl_union_set
*uset
;
10348 isl_schedule
*sched1
, *sched2
;
10349 isl_union_map
*umap
;
10351 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
10352 sched1
= isl_schedule_from_domain(uset
);
10353 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
10354 sched2
= isl_schedule_from_domain(uset
);
10356 sched1
= isl_schedule_sequence(sched1
, sched2
);
10357 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
10358 uset
= isl_union_set_read_from_str(ctx
, str
);
10359 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
10360 umap
= isl_schedule_get_map(sched1
);
10361 isl_schedule_free(sched1
);
10362 isl_union_map_free(umap
);
10369 /* Check that a zero-dimensional prefix schedule keeps track
10370 * of the domain and outer filters.
10372 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
10376 isl_union_set
*uset
;
10377 isl_union_set_list
*filters
;
10378 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10379 isl_schedule_node
*node
;
10381 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10382 uset
= isl_union_set_read_from_str(ctx
, str
);
10383 node
= isl_schedule_node_from_domain(uset
);
10384 node
= isl_schedule_node_child(node
, 0);
10386 str
= "{ S1[i,j] : i > j }";
10387 uset
= isl_union_set_read_from_str(ctx
, str
);
10388 filters
= isl_union_set_list_from_union_set(uset
);
10389 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
10390 uset
= isl_union_set_read_from_str(ctx
, str
);
10391 filters
= isl_union_set_list_add(filters
, uset
);
10392 node
= isl_schedule_node_insert_sequence(node
, filters
);
10394 node
= isl_schedule_node_grandchild(node
, 0, 0);
10395 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
10396 str
= "([] : { S1[i,j] : i > j })";
10397 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10398 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10399 isl_multi_union_pw_aff_free(mupa2
);
10400 isl_multi_union_pw_aff_free(mupa
);
10401 isl_schedule_node_free(node
);
10406 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
10412 /* Check that the reaching domain elements and the prefix schedule
10413 * at a leaf node are the same before and after grouping.
10415 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
10420 isl_union_set
*uset
;
10421 isl_multi_union_pw_aff
*mupa
;
10422 isl_union_pw_multi_aff
*upma1
, *upma2
;
10423 isl_union_set
*domain1
, *domain2
;
10424 isl_union_map
*umap1
, *umap2
;
10425 isl_schedule_node
*node
;
10427 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10428 uset
= isl_union_set_read_from_str(ctx
, str
);
10429 node
= isl_schedule_node_from_domain(uset
);
10430 node
= isl_schedule_node_child(node
, 0);
10431 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10432 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10433 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10434 node
= isl_schedule_node_child(node
, 0);
10435 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10436 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10437 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10438 node
= isl_schedule_node_child(node
, 0);
10439 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10440 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10441 domain1
= isl_schedule_node_get_domain(node
);
10442 id
= isl_id_alloc(ctx
, "group", NULL
);
10443 node
= isl_schedule_node_parent(node
);
10444 node
= isl_schedule_node_group(node
, id
);
10445 node
= isl_schedule_node_child(node
, 0);
10446 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10447 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10448 domain2
= isl_schedule_node_get_domain(node
);
10449 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
10450 if (equal
>= 0 && equal
)
10451 equal
= isl_union_set_is_equal(domain1
, domain2
);
10452 if (equal
>= 0 && equal
)
10453 equal
= isl_union_map_is_equal(umap1
, umap2
);
10454 isl_union_map_free(umap1
);
10455 isl_union_map_free(umap2
);
10456 isl_union_set_free(domain1
);
10457 isl_union_set_free(domain2
);
10458 isl_union_pw_multi_aff_free(upma1
);
10459 isl_union_pw_multi_aff_free(upma2
);
10460 isl_schedule_node_free(node
);
10465 isl_die(ctx
, isl_error_unknown
,
10466 "expressions not equal", return -1);
10471 /* Check that we can have nested groupings and that the union map
10472 * schedule representation is the same before and after the grouping.
10473 * Note that after the grouping, the union map representation contains
10474 * the domain constraints from the ranges of the expansion nodes,
10475 * while they are missing from the union map representation of
10476 * the tree without expansion nodes.
10478 * Also check that the global expansion is as expected.
10480 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
10482 int equal
, equal_expansion
;
10485 isl_union_set
*uset
;
10486 isl_union_map
*umap1
, *umap2
;
10487 isl_union_map
*expansion1
, *expansion2
;
10488 isl_union_set_list
*filters
;
10489 isl_multi_union_pw_aff
*mupa
;
10490 isl_schedule
*schedule
;
10491 isl_schedule_node
*node
;
10493 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10494 "S3[i,j] : 0 <= i,j < 10 }";
10495 uset
= isl_union_set_read_from_str(ctx
, str
);
10496 node
= isl_schedule_node_from_domain(uset
);
10497 node
= isl_schedule_node_child(node
, 0);
10498 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10499 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10500 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10501 node
= isl_schedule_node_child(node
, 0);
10502 str
= "{ S1[i,j] }";
10503 uset
= isl_union_set_read_from_str(ctx
, str
);
10504 filters
= isl_union_set_list_from_union_set(uset
);
10505 str
= "{ S2[i,j]; S3[i,j] }";
10506 uset
= isl_union_set_read_from_str(ctx
, str
);
10507 filters
= isl_union_set_list_add(filters
, uset
);
10508 node
= isl_schedule_node_insert_sequence(node
, filters
);
10509 node
= isl_schedule_node_grandchild(node
, 1, 0);
10510 str
= "{ S2[i,j] }";
10511 uset
= isl_union_set_read_from_str(ctx
, str
);
10512 filters
= isl_union_set_list_from_union_set(uset
);
10513 str
= "{ S3[i,j] }";
10514 uset
= isl_union_set_read_from_str(ctx
, str
);
10515 filters
= isl_union_set_list_add(filters
, uset
);
10516 node
= isl_schedule_node_insert_sequence(node
, filters
);
10518 schedule
= isl_schedule_node_get_schedule(node
);
10519 umap1
= isl_schedule_get_map(schedule
);
10520 uset
= isl_schedule_get_domain(schedule
);
10521 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
10522 isl_schedule_free(schedule
);
10524 node
= isl_schedule_node_grandparent(node
);
10525 id
= isl_id_alloc(ctx
, "group1", NULL
);
10526 node
= isl_schedule_node_group(node
, id
);
10527 node
= isl_schedule_node_grandchild(node
, 1, 0);
10528 id
= isl_id_alloc(ctx
, "group2", NULL
);
10529 node
= isl_schedule_node_group(node
, id
);
10531 schedule
= isl_schedule_node_get_schedule(node
);
10532 umap2
= isl_schedule_get_map(schedule
);
10533 isl_schedule_free(schedule
);
10535 node
= isl_schedule_node_root(node
);
10536 node
= isl_schedule_node_child(node
, 0);
10537 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
10538 isl_schedule_node_free(node
);
10540 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10541 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10542 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10544 expansion2
= isl_union_map_read_from_str(ctx
, str
);
10546 equal
= isl_union_map_is_equal(umap1
, umap2
);
10547 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
10549 isl_union_map_free(umap1
);
10550 isl_union_map_free(umap2
);
10551 isl_union_map_free(expansion1
);
10552 isl_union_map_free(expansion2
);
10554 if (equal
< 0 || equal_expansion
< 0)
10557 isl_die(ctx
, isl_error_unknown
,
10558 "expressions not equal", return -1);
10559 if (!equal_expansion
)
10560 isl_die(ctx
, isl_error_unknown
,
10561 "unexpected expansion", return -1);
10566 /* Some tests for the isl_schedule_node_group function.
10568 static int test_schedule_tree_group(isl_ctx
*ctx
)
10570 if (test_schedule_tree_group_1(ctx
) < 0)
10572 if (test_schedule_tree_group_2(ctx
) < 0)
10581 { "{ rat: [i] : 0 <= i <= 10 }",
10582 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10583 { "{ rat: [i] : FALSE }",
10584 "{ rat: coefficients[[cst] -> [a]] }" },
10585 { "{ rat: [i] : }",
10586 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10587 { "{ [0:,1,2:3] }",
10588 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10589 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10590 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10591 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10592 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10593 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10594 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10595 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10596 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10597 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10598 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10605 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10606 "{ rat: [i] : 0 <= i <= 10 }" },
10607 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10609 { "{ rat: coefficients[[cst] -> [a]] }",
10610 "{ rat: [i] : FALSE }" },
10613 /* Test the basic functionality of isl_basic_set_coefficients and
10614 * isl_basic_set_solutions.
10616 static int test_dual(isl_ctx
*ctx
)
10620 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
10622 isl_basic_set
*bset1
, *bset2
;
10624 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
10625 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
10626 bset1
= isl_basic_set_coefficients(bset1
);
10627 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10628 isl_basic_set_free(bset1
);
10629 isl_basic_set_free(bset2
);
10633 isl_die(ctx
, isl_error_unknown
,
10634 "incorrect dual", return -1);
10637 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
10639 isl_basic_set
*bset1
, *bset2
;
10641 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
10642 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
10643 bset1
= isl_basic_set_solutions(bset1
);
10644 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10645 isl_basic_set_free(bset1
);
10646 isl_basic_set_free(bset2
);
10650 isl_die(ctx
, isl_error_unknown
,
10651 "incorrect dual", return -1);
10660 const char *domain
;
10661 const char *schedule
;
10666 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10667 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10669 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10670 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10672 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10673 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10675 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10676 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10678 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10679 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10681 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10682 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10684 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10685 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10687 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10688 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10692 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10693 * tile the band and then check if the tile and point bands have the
10694 * expected partial schedule.
10696 static int test_tile(isl_ctx
*ctx
)
10702 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
10703 shift
= isl_options_get_tile_shift_point_loops(ctx
);
10705 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
10709 isl_union_set
*domain
;
10710 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10711 isl_schedule_node
*node
;
10712 isl_multi_val
*sizes
;
10714 opt
= tile_tests
[i
].scale_tile
;
10715 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
10716 opt
= tile_tests
[i
].shift_point
;
10717 isl_options_set_tile_shift_point_loops(ctx
, opt
);
10719 str
= tile_tests
[i
].domain
;
10720 domain
= isl_union_set_read_from_str(ctx
, str
);
10721 node
= isl_schedule_node_from_domain(domain
);
10722 node
= isl_schedule_node_child(node
, 0);
10723 str
= tile_tests
[i
].schedule
;
10724 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10725 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10726 str
= tile_tests
[i
].sizes
;
10727 sizes
= isl_multi_val_read_from_str(ctx
, str
);
10728 node
= isl_schedule_node_band_tile(node
, sizes
);
10730 str
= tile_tests
[i
].tile
;
10731 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10732 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10733 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10734 isl_multi_union_pw_aff_free(mupa
);
10735 isl_multi_union_pw_aff_free(mupa2
);
10737 node
= isl_schedule_node_child(node
, 0);
10739 str
= tile_tests
[i
].point
;
10740 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10741 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10742 if (equal
>= 0 && equal
)
10743 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
10745 isl_multi_union_pw_aff_free(mupa
);
10746 isl_multi_union_pw_aff_free(mupa2
);
10748 isl_schedule_node_free(node
);
10753 isl_die(ctx
, isl_error_unknown
,
10754 "unexpected result", return -1);
10757 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
10758 isl_options_set_tile_shift_point_loops(ctx
, shift
);
10763 /* Check that the domain hash of a space is equal to the hash
10764 * of the domain of the space, both ignoring parameters.
10766 static int test_domain_hash(isl_ctx
*ctx
)
10770 uint32_t hash1
, hash2
;
10772 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
10773 space
= isl_map_get_space(map
);
10775 hash1
= isl_space_get_tuple_domain_hash(space
);
10776 space
= isl_space_domain(space
);
10777 hash2
= isl_space_get_tuple_hash(space
);
10778 isl_space_free(space
);
10782 if (hash1
!= hash2
)
10783 isl_die(ctx
, isl_error_unknown
,
10784 "domain hash not equal to hash of domain", return -1);
10789 /* Check that a universe basic set that is not obviously equal to the universe
10790 * is still recognized as being equal to the universe.
10792 static int test_universe(isl_ctx
*ctx
)
10795 isl_basic_set
*bset
;
10798 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10799 bset
= isl_basic_set_read_from_str(ctx
, s
);
10800 is_univ
= isl_basic_set_is_universe(bset
);
10801 isl_basic_set_free(bset
);
10806 isl_die(ctx
, isl_error_unknown
,
10807 "not recognized as universe set", return -1);
10812 /* Sets for which chambers are computed and checked.
10814 const char *chambers_tests
[] = {
10815 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10816 "z >= 0 and z <= C - y and z <= B - x - y }",
10819 /* Add the domain of "cell" to "cells".
10821 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
10823 isl_basic_set_list
**cells
= user
;
10824 isl_basic_set
*dom
;
10826 dom
= isl_cell_get_domain(cell
);
10827 isl_cell_free(cell
);
10828 *cells
= isl_basic_set_list_add(*cells
, dom
);
10830 return *cells
? isl_stat_ok
: isl_stat_error
;
10833 /* Check that the elements of "list" are pairwise disjoint.
10835 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
10840 n
= isl_basic_set_list_n_basic_set(list
);
10842 return isl_stat_error
;
10844 for (i
= 0; i
< n
; ++i
) {
10845 isl_basic_set
*bset_i
;
10847 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
10848 for (j
= i
+ 1; j
< n
; ++j
) {
10849 isl_basic_set
*bset_j
;
10852 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
10853 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
10854 isl_basic_set_free(bset_j
);
10856 isl_die(isl_basic_set_list_get_ctx(list
),
10857 isl_error_unknown
, "not disjoint",
10859 if (disjoint
< 0 || !disjoint
)
10862 isl_basic_set_free(bset_i
);
10864 return isl_stat_error
;
10867 return isl_stat_ok
;
10870 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10871 * are pairwise disjoint.
10873 static int test_chambers(isl_ctx
*ctx
)
10877 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
10878 isl_basic_set
*bset
;
10879 isl_vertices
*vertices
;
10880 isl_basic_set_list
*cells
;
10883 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
10884 vertices
= isl_basic_set_compute_vertices(bset
);
10885 cells
= isl_basic_set_list_alloc(ctx
, 0);
10886 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
10888 cells
= isl_basic_set_list_free(cells
);
10889 ok
= check_pairwise_disjoint(cells
);
10890 isl_basic_set_list_free(cells
);
10891 isl_vertices_free(vertices
);
10892 isl_basic_set_free(bset
);
10903 int (*fn
)(isl_ctx
*ctx
);
10905 { "universe", &test_universe
},
10906 { "domain hash", &test_domain_hash
},
10907 { "dual", &test_dual
},
10908 { "dependence analysis", &test_flow
},
10909 { "val", &test_val
},
10910 { "compute divs", &test_compute_divs
},
10911 { "partial lexmin", &test_partial_lexmin
},
10912 { "simplify", &test_simplify
},
10913 { "curry", &test_curry
},
10914 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10915 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10916 { "conversion", &test_conversion
},
10917 { "list", &test_list
},
10918 { "align parameters", &test_align_parameters
},
10919 { "drop unused parameters", &test_drop_unused_parameters
},
10920 { "pullback", &test_pullback
},
10921 { "AST", &test_ast
},
10922 { "AST build", &test_ast_build
},
10923 { "AST generation", &test_ast_gen
},
10924 { "eliminate", &test_eliminate
},
10925 { "deltas_map", &test_deltas_map
},
10926 { "residue class", &test_residue_class
},
10927 { "div", &test_div
},
10928 { "slice", &test_slice
},
10929 { "sample", &test_sample
},
10930 { "empty projection", &test_empty_projection
},
10931 { "output", &test_output
},
10932 { "vertices", &test_vertices
},
10933 { "chambers", &test_chambers
},
10934 { "fixed", &test_fixed
},
10935 { "equal", &test_equal
},
10936 { "disjoint", &test_disjoint
},
10937 { "product", &test_product
},
10938 { "dim_max", &test_dim_max
},
10939 { "affine", &test_aff
},
10940 { "injective", &test_injective
},
10941 { "schedule (whole component)", &test_schedule_whole
},
10942 { "schedule (incremental)", &test_schedule_incremental
},
10943 { "schedule tree", &test_schedule_tree
},
10944 { "schedule tree prefix", &test_schedule_tree_prefix
},
10945 { "schedule tree grouping", &test_schedule_tree_group
},
10946 { "tile", &test_tile
},
10947 { "union map", &test_union_map
},
10948 { "union_pw", &test_union_pw
},
10949 { "locus", &test_locus
},
10950 { "eval", &test_eval
},
10951 { "parse", &test_parse
},
10952 { "single-valued", &test_sv
},
10953 { "recession cone", &test_recession_cone
},
10954 { "affine hull", &test_affine_hull
},
10955 { "simple_hull", &test_simple_hull
},
10956 { "box hull", &test_box_hull
},
10957 { "coalesce", &test_coalesce
},
10958 { "factorize", &test_factorize
},
10959 { "subset", &test_subset
},
10960 { "subtract", &test_subtract
},
10961 { "intersect", &test_intersect
},
10962 { "lexmin", &test_lexmin
},
10963 { "min", &test_min
},
10964 { "set lower bounds", &test_min_mpa
},
10965 { "gist", &test_gist
},
10966 { "piecewise quasi-polynomials", &test_pwqp
},
10967 { "lift", &test_lift
},
10968 { "bind parameters", &test_bind
},
10969 { "unbind parameters", &test_unbind
},
10970 { "bound", &test_bound
},
10971 { "get lists", &test_get_list
},
10972 { "union", &test_union
},
10973 { "split periods", &test_split_periods
},
10974 { "lexicographic order", &test_lex
},
10975 { "bijectivity", &test_bijective
},
10976 { "dataflow analysis", &test_dep
},
10977 { "reading", &test_read
},
10978 { "bounded", &test_bounded
},
10979 { "construction", &test_construction
},
10980 { "dimension manipulation", &test_dim
},
10981 { "map application", &test_application
},
10982 { "convex hull", &test_convex_hull
},
10983 { "transitive closure", &test_closure
},
10984 { "isl_bool", &test_isl_bool
},
10987 int main(int argc
, char **argv
)
10990 struct isl_ctx
*ctx
;
10991 struct isl_options
*options
;
10993 options
= isl_options_new_with_defaults();
10995 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10997 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
10998 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
10999 printf("%s\n", tests
[i
].name
);
11000 if (tests
[i
].fn(ctx
) < 0)