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 }" },
4039 { 1, isl_fold_max
, "{ [[a=0:1] -> [b=0:1]] -> (floor((a + b)/2)) }",
4040 "{ [a=0:1] -> max(a) }" },
4043 /* Check that the bound computation can handle differences
4044 * in domain dimension names of the input polynomial and its domain.
4046 static isl_stat
test_bound_space(isl_ctx
*ctx
)
4050 isl_pw_qpolynomial
*pwqp
;
4051 isl_pw_qpolynomial_fold
*pwf
;
4053 str
= "{ [[c] -> [c]] }";
4054 set
= isl_set_read_from_str(ctx
, str
);
4055 str
= "{ [[a] -> [b]] -> 1 }";
4056 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4057 pwqp
= isl_pw_qpolynomial_intersect_domain(pwqp
, set
);
4058 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
4059 isl_pw_qpolynomial_fold_free(pwf
);
4061 return isl_stat_non_null(pwf
);
4064 /* Perform basic isl_pw_qpolynomial_bound tests.
4066 static int test_bound(isl_ctx
*ctx
)
4070 if (test_bound_space(ctx
) < 0)
4073 for (i
= 0; i
< ARRAY_SIZE(bound_tests
); ++i
) {
4076 isl_bool equal
, tight
;
4077 isl_pw_qpolynomial
*pwqp
;
4078 isl_pw_qpolynomial_fold
*pwf1
, *pwf2
;
4080 str
= bound_tests
[i
].poly
;
4081 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4082 type
= bound_tests
[i
].type
;
4083 pwf1
= isl_pw_qpolynomial_bound(pwqp
, type
, &tight
);
4084 str
= bound_tests
[i
].bound
;
4085 pwf2
= isl_pw_qpolynomial_fold_read_from_str(ctx
, str
);
4086 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf1
, pwf2
);
4087 isl_pw_qpolynomial_fold_free(pwf2
);
4088 isl_pw_qpolynomial_fold_free(pwf1
);
4092 isl_die(ctx
, isl_error_unknown
,
4093 "incorrect bound result", return -1);
4094 if (bound_tests
[i
].tight
&& !tight
)
4095 isl_die(ctx
, isl_error_unknown
,
4096 "bound unexpectedly not tight", return -1);
4102 /* isl_set is defined to isl_map internally, so the corresponding elements
4103 * are isl_basic_map objects.
4107 #define EL_BASE basic_map
4108 #define SET_BASE set
4109 #include "isl_test_list_templ.c"
4113 #define EL_BASE basic_set
4114 #define SET_BASE union_set
4115 #include "isl_test_list_templ.c"
4120 #define SET_BASE union_set
4121 #include "isl_test_list_templ.c"
4125 #define EL_BASE basic_map
4126 #define SET_BASE map
4127 #include "isl_test_list_templ.c"
4132 #define SET_BASE union_map
4133 #include "isl_test_list_templ.c"
4135 /* Check that the conversion from isl objects to lists works as expected.
4137 static int test_get_list(isl_ctx
*ctx
)
4139 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
4141 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
4143 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
4145 if (test_get_list_basic_map_from_map(ctx
,
4146 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
4148 if (test_get_list_map_from_union_map(ctx
,
4149 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
4155 static int test_lift(isl_ctx
*ctx
)
4158 isl_basic_map
*bmap
;
4159 isl_basic_set
*bset
;
4161 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
4162 bset
= isl_basic_set_read_from_str(ctx
, str
);
4163 bset
= isl_basic_set_lift(bset
);
4164 bmap
= isl_basic_map_from_range(bset
);
4165 bset
= isl_basic_map_domain(bmap
);
4166 isl_basic_set_free(bset
);
4171 /* Check that isl_set_is_subset is not confused by identical
4172 * integer divisions.
4173 * The call to isl_set_normalize ensures that the equality constraints
4174 * a = b = 0 are discovered, turning e0 and e1 into identical
4175 * integer divisions. Any further simplification would remove
4176 * the duplicate integer divisions.
4178 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
4182 isl_set
*set1
, *set2
;
4184 str
= "{ [a, b, c, d] : "
4185 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4186 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4187 "e3 = floor((-d + 4*floor((d)/4))/10): "
4188 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4189 "b >= 0 and a <= 0 and b <= a) }";
4190 set1
= isl_set_read_from_str(ctx
, str
);
4191 set2
= isl_set_read_from_str(ctx
, str
);
4192 set2
= isl_set_normalize(set2
);
4194 is_subset
= isl_set_is_subset(set1
, set2
);
4200 return isl_stat_error
;
4202 isl_die(ctx
, isl_error_unknown
,
4203 "set is not considered to be a subset of itself",
4204 return isl_stat_error
);
4213 } subset_tests
[] = {
4215 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4216 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4217 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4219 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4220 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4221 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4222 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4223 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4224 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4225 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4226 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4227 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4228 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4229 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4230 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4231 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4232 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4233 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4234 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4235 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4236 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4237 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4238 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4239 "4e0 <= -57 + i0 + i1)) or "
4240 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4241 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4242 "4e0 >= -61 + i0 + i1)) or "
4243 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4244 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4247 static int test_subset(isl_ctx
*ctx
)
4250 isl_set
*set1
, *set2
;
4253 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
4256 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
4257 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
4258 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
4259 subset
= isl_set_is_subset(set1
, set2
);
4264 if (subset
!= subset_tests
[i
].subset
)
4265 isl_die(ctx
, isl_error_unknown
,
4266 "incorrect subset result", return -1);
4272 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4273 * Older versions of isl would fail on such cases.
4275 static isl_stat
test_subtract_empty(isl_ctx
*ctx
)
4280 s1
= isl_set_read_from_str(ctx
, "{ [0] }");
4281 str
= "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4282 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4283 "33e2 >= -a + 33e0 + 1056e1 and "
4284 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4285 s2
= isl_set_read_from_str(ctx
, str
);
4286 s1
= isl_set_subtract(s1
, s2
);
4289 return isl_stat_non_null(s1
);
4293 const char *minuend
;
4294 const char *subtrahend
;
4295 const char *difference
;
4296 } subtract_domain_tests
[] = {
4297 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4298 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4299 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4302 static int test_subtract(isl_ctx
*ctx
)
4305 isl_union_map
*umap1
, *umap2
;
4306 isl_union_pw_multi_aff
*upma1
, *upma2
;
4307 isl_union_set
*uset
;
4310 if (test_subtract_empty(ctx
) < 0)
4313 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4314 umap1
= isl_union_map_read_from_str(ctx
,
4315 subtract_domain_tests
[i
].minuend
);
4316 uset
= isl_union_set_read_from_str(ctx
,
4317 subtract_domain_tests
[i
].subtrahend
);
4318 umap2
= isl_union_map_read_from_str(ctx
,
4319 subtract_domain_tests
[i
].difference
);
4320 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
4321 equal
= isl_union_map_is_equal(umap1
, umap2
);
4322 isl_union_map_free(umap1
);
4323 isl_union_map_free(umap2
);
4327 isl_die(ctx
, isl_error_unknown
,
4328 "incorrect subtract domain result", return -1);
4331 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4332 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4333 subtract_domain_tests
[i
].minuend
);
4334 uset
= isl_union_set_read_from_str(ctx
,
4335 subtract_domain_tests
[i
].subtrahend
);
4336 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4337 subtract_domain_tests
[i
].difference
);
4338 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
4339 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
4340 isl_union_pw_multi_aff_free(upma1
);
4341 isl_union_pw_multi_aff_free(upma2
);
4345 isl_die(ctx
, isl_error_unknown
,
4346 "incorrect subtract domain result", return -1);
4352 /* Check that intersecting the empty basic set with another basic set
4353 * does not increase the number of constraints. In particular,
4354 * the empty basic set should maintain its canonical representation.
4356 static int test_intersect_1(isl_ctx
*ctx
)
4359 isl_basic_set
*bset1
, *bset2
;
4361 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
4362 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
4363 n1
= isl_basic_set_n_constraint(bset1
);
4364 bset1
= isl_basic_set_intersect(bset1
, bset2
);
4365 n2
= isl_basic_set_n_constraint(bset1
);
4366 isl_basic_set_free(bset1
);
4367 if (n1
< 0 || n2
< 0)
4370 isl_die(ctx
, isl_error_unknown
,
4371 "number of constraints of empty set changed",
4377 /* Check that intersecting a set with itself does not cause
4378 * an explosion in the number of disjuncts.
4380 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
4385 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
4386 for (i
= 0; i
< 100; ++i
)
4387 set
= isl_set_intersect(set
, isl_set_copy(set
));
4390 return isl_stat_error
;
4394 /* Perform some intersection tests.
4396 static int test_intersect(isl_ctx
*ctx
)
4398 if (test_intersect_1(ctx
) < 0)
4400 if (test_intersect_2(ctx
) < 0)
4406 int test_factorize(isl_ctx
*ctx
)
4409 isl_basic_set
*bset
;
4412 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4413 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4414 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4415 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4416 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4417 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4418 "3i5 >= -2i0 - i2 + 3i4 }";
4419 bset
= isl_basic_set_read_from_str(ctx
, str
);
4420 f
= isl_basic_set_factorizer(bset
);
4421 isl_basic_set_free(bset
);
4422 isl_factorizer_free(f
);
4424 isl_die(ctx
, isl_error_unknown
,
4425 "failed to construct factorizer", return -1);
4427 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4428 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4429 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4430 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4431 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4432 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4433 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4434 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4435 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4436 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4437 bset
= isl_basic_set_read_from_str(ctx
, str
);
4438 f
= isl_basic_set_factorizer(bset
);
4439 isl_basic_set_free(bset
);
4440 isl_factorizer_free(f
);
4442 isl_die(ctx
, isl_error_unknown
,
4443 "failed to construct factorizer", return -1);
4448 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
4450 int *injective
= user
;
4452 *injective
= isl_map_is_injective(map
);
4455 if (*injective
< 0 || !*injective
)
4456 return isl_stat_error
;
4461 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
4462 const char *r
, const char *s
, int tilable
, int parallel
)
4466 isl_union_map
*W
, *R
, *S
;
4467 isl_union_map
*empty
;
4468 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
4469 isl_union_map
*validity
, *proximity
, *coincidence
;
4470 isl_union_map
*schedule
;
4471 isl_union_map
*test
;
4472 isl_union_set
*delta
;
4473 isl_union_set
*domain
;
4477 isl_schedule_constraints
*sc
;
4478 isl_schedule
*sched
;
4479 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
4482 D
= isl_union_set_read_from_str(ctx
, d
);
4483 W
= isl_union_map_read_from_str(ctx
, w
);
4484 R
= isl_union_map_read_from_str(ctx
, r
);
4485 S
= isl_union_map_read_from_str(ctx
, s
);
4487 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4488 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4490 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4491 isl_union_map_compute_flow(isl_union_map_copy(R
),
4492 isl_union_map_copy(W
), empty
,
4493 isl_union_map_copy(S
),
4494 &dep_raw
, NULL
, NULL
, NULL
);
4495 isl_union_map_compute_flow(isl_union_map_copy(W
),
4496 isl_union_map_copy(W
),
4497 isl_union_map_copy(R
),
4498 isl_union_map_copy(S
),
4499 &dep_waw
, &dep_war
, NULL
, NULL
);
4501 dep
= isl_union_map_union(dep_waw
, dep_war
);
4502 dep
= isl_union_map_union(dep
, dep_raw
);
4503 validity
= isl_union_map_copy(dep
);
4504 coincidence
= isl_union_map_copy(dep
);
4505 proximity
= isl_union_map_copy(dep
);
4507 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4508 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4509 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4510 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4511 sched
= isl_schedule_constraints_compute_schedule(sc
);
4512 schedule
= isl_schedule_get_map(sched
);
4513 isl_schedule_free(sched
);
4514 isl_union_map_free(W
);
4515 isl_union_map_free(R
);
4516 isl_union_map_free(S
);
4519 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4521 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4522 is_complete
= isl_union_set_is_subset(D
, domain
);
4523 isl_union_set_free(D
);
4524 isl_union_set_free(domain
);
4526 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4527 test
= isl_union_map_apply_range(test
, dep
);
4528 test
= isl_union_map_apply_range(test
, schedule
);
4530 delta
= isl_union_map_deltas(test
);
4531 n
= isl_union_set_n_set(delta
);
4533 isl_union_set_free(delta
);
4540 isl_union_set_free(delta
);
4544 delta_set
= isl_set_from_union_set(delta
);
4546 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4547 for (i
= 0; i
< tilable
; ++i
)
4548 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4549 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4550 isl_set_free(slice
);
4552 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4553 for (i
= 0; i
< parallel
; ++i
)
4554 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4555 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4556 isl_set_free(slice
);
4558 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4559 dim
= isl_set_dim(origin
, isl_dim_set
);
4561 origin
= isl_set_free(origin
);
4562 for (i
= 0; i
< dim
; ++i
)
4563 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4565 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4566 delta_set
= isl_set_lexmin(delta_set
);
4568 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4570 isl_set_free(origin
);
4571 isl_set_free(delta_set
);
4574 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4575 is_injection
< 0 || is_complete
< 0)
4578 isl_die(ctx
, isl_error_unknown
,
4579 "generated schedule incomplete", return -1);
4581 isl_die(ctx
, isl_error_unknown
,
4582 "generated schedule not injective on each statement",
4585 isl_die(ctx
, isl_error_unknown
,
4586 "negative dependences in generated schedule",
4589 isl_die(ctx
, isl_error_unknown
,
4590 "generated schedule not as tilable as expected",
4593 isl_die(ctx
, isl_error_unknown
,
4594 "generated schedule not as parallel as expected",
4600 /* Compute a schedule for the given instance set, validity constraints,
4601 * proximity constraints and context and return a corresponding union map
4604 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4605 const char *domain
, const char *validity
, const char *proximity
,
4606 const char *context
)
4611 isl_union_map
*prox
;
4612 isl_schedule_constraints
*sc
;
4613 isl_schedule
*schedule
;
4614 isl_union_map
*sched
;
4616 con
= isl_set_read_from_str(ctx
, context
);
4617 dom
= isl_union_set_read_from_str(ctx
, domain
);
4618 dep
= isl_union_map_read_from_str(ctx
, validity
);
4619 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4620 sc
= isl_schedule_constraints_on_domain(dom
);
4621 sc
= isl_schedule_constraints_set_context(sc
, con
);
4622 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4623 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4624 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4625 sched
= isl_schedule_get_map(schedule
);
4626 isl_schedule_free(schedule
);
4631 /* Compute a schedule for the given instance set, validity constraints and
4632 * proximity constraints and return a corresponding union map representation.
4634 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4635 const char *domain
, const char *validity
, const char *proximity
)
4637 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4641 /* Check that a schedule can be constructed on the given domain
4642 * with the given validity and proximity constraints.
4644 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4645 const char *validity
, const char *proximity
)
4647 isl_union_map
*sched
;
4649 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4653 isl_union_map_free(sched
);
4657 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4658 const char *validity
, const char *proximity
, const char *expected_sched
)
4660 isl_union_map
*sched1
, *sched2
;
4663 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4664 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4666 equal
= isl_union_map_is_equal(sched1
, sched2
);
4667 isl_union_map_free(sched1
);
4668 isl_union_map_free(sched2
);
4673 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4679 /* Check that the schedule map is properly padded, i.e., that the range
4680 * lives in a single space.
4682 static int test_padded_schedule(isl_ctx
*ctx
)
4686 isl_union_map
*validity
, *proximity
;
4687 isl_schedule_constraints
*sc
;
4688 isl_schedule
*sched
;
4689 isl_union_map
*umap
;
4690 isl_union_set
*range
;
4693 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4694 D
= isl_union_set_read_from_str(ctx
, str
);
4695 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4696 proximity
= isl_union_map_copy(validity
);
4697 sc
= isl_schedule_constraints_on_domain(D
);
4698 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4699 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4700 sched
= isl_schedule_constraints_compute_schedule(sc
);
4701 umap
= isl_schedule_get_map(sched
);
4702 isl_schedule_free(sched
);
4703 range
= isl_union_map_range(umap
);
4704 set
= isl_set_from_union_set(range
);
4713 /* Check that conditional validity constraints are also taken into
4714 * account across bands.
4715 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4716 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4717 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4718 * is enforced by the rest of the schedule.
4720 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4723 isl_union_set
*domain
;
4724 isl_union_map
*validity
, *proximity
, *condition
;
4725 isl_union_map
*sink
, *source
, *dep
;
4726 isl_schedule_constraints
*sc
;
4727 isl_schedule
*schedule
;
4728 isl_union_access_info
*access
;
4729 isl_union_flow
*flow
;
4732 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4733 "A[k] : k >= 1 and k <= -1 + n; "
4734 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4735 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4736 domain
= isl_union_set_read_from_str(ctx
, str
);
4737 sc
= isl_schedule_constraints_on_domain(domain
);
4738 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4739 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4740 "D[k, i] -> C[1 + k, i] : "
4741 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4742 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4743 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4744 validity
= isl_union_map_read_from_str(ctx
, str
);
4745 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4746 str
= "[n] -> { C[k, i] -> D[k, i] : "
4747 "0 <= i <= -1 + k and k <= -1 + n }";
4748 proximity
= isl_union_map_read_from_str(ctx
, str
);
4749 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4750 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4751 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4752 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4753 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4754 condition
= isl_union_map_read_from_str(ctx
, str
);
4755 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4756 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4757 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4758 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4759 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4760 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4761 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4762 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4763 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4764 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4765 validity
= isl_union_map_read_from_str(ctx
, str
);
4766 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4768 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4769 str
= "{ D[2,0] -> [] }";
4770 sink
= isl_union_map_read_from_str(ctx
, str
);
4771 access
= isl_union_access_info_from_sink(sink
);
4772 str
= "{ C[2,1] -> [] }";
4773 source
= isl_union_map_read_from_str(ctx
, str
);
4774 access
= isl_union_access_info_set_must_source(access
, source
);
4775 access
= isl_union_access_info_set_schedule(access
, schedule
);
4776 flow
= isl_union_access_info_compute_flow(access
);
4777 dep
= isl_union_flow_get_must_dependence(flow
);
4778 isl_union_flow_free(flow
);
4779 empty
= isl_union_map_is_empty(dep
);
4780 isl_union_map_free(dep
);
4785 isl_die(ctx
, isl_error_unknown
,
4786 "conditional validity not respected", return -1);
4791 /* Check that the test for violated conditional validity constraints
4792 * is not confused by domain compression.
4793 * In particular, earlier versions of isl would apply
4794 * a schedule on the compressed domains to the original domains,
4795 * resulting in a failure to detect that the default schedule
4796 * violates the conditional validity constraints.
4798 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4802 isl_union_set
*domain
;
4803 isl_union_map
*validity
, *condition
;
4804 isl_schedule_constraints
*sc
;
4805 isl_schedule
*schedule
;
4806 isl_union_map
*umap
;
4809 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4810 domain
= isl_union_set_read_from_str(ctx
, str
);
4811 sc
= isl_schedule_constraints_on_domain(domain
);
4812 str
= "{ B[1, i] -> A[0, i + 1] }";
4813 condition
= isl_union_map_read_from_str(ctx
, str
);
4814 str
= "{ A[0, i] -> B[1, i - 1] }";
4815 validity
= isl_union_map_read_from_str(ctx
, str
);
4816 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4817 isl_union_map_copy(validity
));
4818 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4819 umap
= isl_schedule_get_map(schedule
);
4820 isl_schedule_free(schedule
);
4821 validity
= isl_union_map_apply_domain(validity
,
4822 isl_union_map_copy(umap
));
4823 validity
= isl_union_map_apply_range(validity
, umap
);
4824 map
= isl_map_from_union_map(validity
);
4825 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4826 map
= isl_map_intersect(map
, ge
);
4827 empty
= isl_map_is_empty(map
);
4833 isl_die(ctx
, isl_error_unknown
,
4834 "conditional validity constraints not satisfied",
4840 /* Input for testing of schedule construction based on
4841 * conditional constraints.
4843 * domain is the iteration domain
4844 * flow are the flow dependences, which determine the validity and
4845 * proximity constraints
4846 * condition are the conditions on the conditional validity constraints
4847 * conditional_validity are the conditional validity constraints
4848 * outer_band_n is the expected number of members in the outer band
4853 const char *condition
;
4854 const char *conditional_validity
;
4856 } live_range_tests
[] = {
4857 /* Contrived example that illustrates that we need to keep
4858 * track of tagged condition dependences and
4859 * tagged conditional validity dependences
4860 * in isl_sched_edge separately.
4861 * In particular, the conditional validity constraints on A
4862 * cannot be satisfied,
4863 * but they can be ignored because there are no corresponding
4864 * condition constraints. However, we do have an additional
4865 * conditional validity constraint that maps to the same
4866 * dependence relation
4867 * as the condition constraint on B. If we did not make a distinction
4868 * between tagged condition and tagged conditional validity
4869 * dependences, then we
4870 * could end up treating this shared dependence as an condition
4871 * constraint on A, forcing a localization of the conditions,
4872 * which is impossible.
4874 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4875 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4876 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4877 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4878 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4879 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4882 /* TACO 2013 Fig. 7 */
4883 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4884 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4885 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4886 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4887 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4888 "0 <= i < n and 0 <= j < n - 1 }",
4889 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4890 "0 <= i < n and 0 <= j < j' < n;"
4891 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4892 "0 <= i < i' < n and 0 <= j,j' < n;"
4893 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4894 "0 <= i,j,j' < n and j < j' }",
4897 /* TACO 2013 Fig. 7, without tags */
4898 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
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] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4902 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4903 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4904 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4905 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4908 /* TACO 2013 Fig. 12 */
4909 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4910 "S3[i,3] : 0 <= i <= 1 }",
4911 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4912 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4913 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4914 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4915 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4916 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4917 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4918 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4919 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4920 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4921 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4926 /* Test schedule construction based on conditional constraints.
4927 * In particular, check the number of members in the outer band node
4928 * as an indication of whether tiling is possible or not.
4930 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4933 isl_union_set
*domain
;
4934 isl_union_map
*condition
;
4935 isl_union_map
*flow
;
4936 isl_union_map
*validity
;
4937 isl_schedule_constraints
*sc
;
4938 isl_schedule
*schedule
;
4939 isl_schedule_node
*node
;
4942 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4944 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4947 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4948 domain
= isl_union_set_read_from_str(ctx
,
4949 live_range_tests
[i
].domain
);
4950 flow
= isl_union_map_read_from_str(ctx
,
4951 live_range_tests
[i
].flow
);
4952 condition
= isl_union_map_read_from_str(ctx
,
4953 live_range_tests
[i
].condition
);
4954 validity
= isl_union_map_read_from_str(ctx
,
4955 live_range_tests
[i
].conditional_validity
);
4956 sc
= isl_schedule_constraints_on_domain(domain
);
4957 sc
= isl_schedule_constraints_set_validity(sc
,
4958 isl_union_map_copy(flow
));
4959 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4960 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4961 condition
, validity
);
4962 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4963 node
= isl_schedule_get_root(schedule
);
4965 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4966 node
= isl_schedule_node_first_child(node
);
4967 n_member
= isl_schedule_node_band_n_member(node
);
4968 isl_schedule_node_free(node
);
4969 isl_schedule_free(schedule
);
4971 if (!schedule
|| n_member
< 0)
4973 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4974 isl_die(ctx
, isl_error_unknown
,
4975 "unexpected number of members in outer band",
4981 /* Check that the schedule computed for the given instance set and
4982 * dependence relation strongly satisfies the dependences.
4983 * In particular, check that no instance is scheduled before
4984 * or together with an instance on which it depends.
4985 * Earlier versions of isl would produce a schedule that
4986 * only weakly satisfies the dependences.
4988 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4990 const char *domain
, *dep
;
4991 isl_union_map
*D
, *schedule
;
4995 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4996 "A[i0] : 0 <= i0 <= 1 }";
4997 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4998 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4999 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
5000 D
= isl_union_map_read_from_str(ctx
, dep
);
5001 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
5002 D
= isl_union_map_apply_range(D
, schedule
);
5003 map
= isl_map_from_union_map(D
);
5004 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
5005 map
= isl_map_intersect(map
, ge
);
5006 empty
= isl_map_is_empty(map
);
5012 isl_die(ctx
, isl_error_unknown
,
5013 "dependences not strongly satisfied", return -1);
5018 /* Compute a schedule for input where the instance set constraints
5019 * conflict with the context constraints.
5020 * Earlier versions of isl did not properly handle this situation.
5022 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
5024 isl_union_map
*schedule
;
5025 const char *domain
, *context
;
5027 domain
= "[n] -> { A[] : n >= 0 }";
5028 context
= "[n] -> { : n < 0 }";
5029 schedule
= compute_schedule_with_context(ctx
,
5030 domain
, "{}", "{}", context
);
5031 isl_union_map_free(schedule
);
5039 /* Check that a set of schedule constraints that only allow for
5040 * a coalescing schedule still produces a schedule even if the user
5041 * request a non-coalescing schedule. Earlier versions of isl
5042 * would not handle this case correctly.
5044 static int test_coalescing_schedule(isl_ctx
*ctx
)
5046 const char *domain
, *dep
;
5049 isl_schedule_constraints
*sc
;
5050 isl_schedule
*schedule
;
5051 int treat_coalescing
;
5053 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
5054 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
5055 I
= isl_union_set_read_from_str(ctx
, domain
);
5056 D
= isl_union_map_read_from_str(ctx
, dep
);
5057 sc
= isl_schedule_constraints_on_domain(I
);
5058 sc
= isl_schedule_constraints_set_validity(sc
, D
);
5059 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5060 isl_options_set_schedule_treat_coalescing(ctx
, 1);
5061 schedule
= isl_schedule_constraints_compute_schedule(sc
);
5062 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5063 isl_schedule_free(schedule
);
5069 /* Check that the scheduler does not perform any needless
5070 * compound skewing. Earlier versions of isl would compute
5071 * schedules in terms of transformed schedule coefficients and
5072 * would not accurately keep track of the sum of the original
5073 * schedule coefficients. It could then produce the schedule
5074 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
5075 * for the input below instead of the schedule below.
5077 static int test_skewing_schedule(isl_ctx
*ctx
)
5079 const char *D
, *V
, *P
, *S
;
5081 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
5082 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
5083 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
5084 "-1 <= a-i + b-j + c-k <= 1 }";
5086 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
5088 return test_special_schedule(ctx
, D
, V
, P
, S
);
5091 int test_schedule(isl_ctx
*ctx
)
5093 const char *D
, *W
, *R
, *V
, *P
, *S
;
5094 int max_coincidence
;
5095 int treat_coalescing
;
5097 /* Handle resulting schedule with zero bands. */
5098 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
5102 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
5103 W
= "{ S1[t,i] -> a[t,i] }";
5104 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
5105 "S1[t,i] -> a[t-1,i+1] }";
5106 S
= "{ S1[t,i] -> [t,i] }";
5107 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5110 /* Fig. 5 of CC2008 */
5111 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
5113 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
5114 "j >= 2 and j <= -1 + N }";
5115 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
5116 "j >= 2 and j <= -1 + N; "
5117 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
5118 "j >= 2 and j <= -1 + N }";
5119 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5120 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5123 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
5124 W
= "{ S1[i] -> a[i] }";
5125 R
= "{ S2[i] -> a[i+1] }";
5126 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5127 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5130 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
5131 W
= "{ S1[i] -> a[i] }";
5132 R
= "{ S2[i] -> a[9-i] }";
5133 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5134 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5137 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
5138 W
= "{ S1[i] -> a[i] }";
5139 R
= "[N] -> { S2[i] -> a[N-1-i] }";
5140 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5141 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5144 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
5145 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
5146 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
5147 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
5148 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5151 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5152 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
5153 R
= "{ S2[i,j] -> a[i-1,j] }";
5154 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5155 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5158 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5159 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
5160 R
= "{ S2[i,j] -> a[i,j-1] }";
5161 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5162 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5165 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5166 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5167 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5168 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5169 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5170 "S_0[] -> [0, 0, 0] }";
5171 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
5173 ctx
->opt
->schedule_parametric
= 0;
5174 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5176 ctx
->opt
->schedule_parametric
= 1;
5178 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5179 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5180 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5181 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5182 "S4[i] -> a[i,N] }";
5183 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5184 "S4[i] -> [4,i,0] }";
5185 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
5186 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
5187 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5189 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
5191 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5192 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5194 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5196 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5198 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5199 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5202 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5203 " S_2[t] : t >= 0 and t <= -1 + N; "
5204 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5206 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5207 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5208 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5209 "i >= 0 and i <= -1 + N }";
5210 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5211 "i >= 0 and i <= -1 + N; "
5212 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5213 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5214 " S_0[t] -> [0, t, 0] }";
5216 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5218 ctx
->opt
->schedule_parametric
= 0;
5219 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5221 ctx
->opt
->schedule_parametric
= 1;
5223 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5224 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5225 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
5228 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5229 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5230 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5231 "j >= 0 and j <= -1 + N; "
5232 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5233 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5234 "j >= 0 and j <= -1 + N; "
5235 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5236 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5237 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5240 D
= "{ S_0[i] : i >= 0 }";
5241 W
= "{ S_0[i] -> a[i] : i >= 0 }";
5242 R
= "{ S_0[i] -> a[0] : i >= 0 }";
5243 S
= "{ S_0[i] -> [0, i, 0] }";
5244 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5247 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5248 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5249 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5250 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5251 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5254 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5255 "k <= -1 + n and k >= 0 }";
5256 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5257 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5258 "k <= -1 + n and k >= 0; "
5259 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5260 "k <= -1 + n and k >= 0; "
5261 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5262 "k <= -1 + n and k >= 0 }";
5263 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
5264 ctx
->opt
->schedule_outer_coincidence
= 1;
5265 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5267 ctx
->opt
->schedule_outer_coincidence
= 0;
5269 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
5270 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5271 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5272 "Stmt_for_body24[i0, i1, 1, 0]:"
5273 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5274 "Stmt_for_body7[i0, i1, i2]:"
5275 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5278 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
5279 "Stmt_for_body24[1, i1, i2, i3]:"
5280 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5282 "Stmt_for_body24[0, i1, i2, i3] -> "
5283 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5284 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5286 "Stmt_for_body24[0, i1, i2, i3] ->"
5287 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5288 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5289 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5290 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5291 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5292 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5293 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5294 "i1 <= 6 and i1 >= 0;"
5295 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5296 "Stmt_for_body7[i0, i1, i2] -> "
5297 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5298 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5299 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5300 "Stmt_for_body7[i0, i1, i2] -> "
5301 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5302 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5303 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5306 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5307 isl_options_set_schedule_treat_coalescing(ctx
, 0);
5308 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5310 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5312 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5313 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5314 "j >= 1 and j <= 7;"
5315 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5316 "j >= 1 and j <= 8 }";
5318 S
= "{ S_0[i, j] -> [i + j, i] }";
5319 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5320 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5322 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5324 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5325 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5326 "j >= 0 and j <= -1 + i }";
5327 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5328 "i <= -1 + N and j >= 0;"
5329 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5332 S
= "{ S_0[i, j] -> [i, j] }";
5333 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5334 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5336 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5338 /* Test both algorithms on a case with only proximity dependences. */
5339 D
= "{ S[i,j] : 0 <= i <= 10 }";
5341 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5342 S
= "{ S[i, j] -> [j, i] }";
5343 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5344 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5346 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5347 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5350 D
= "{ A[a]; B[] }";
5352 P
= "{ A[a] -> B[] }";
5353 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5356 if (test_padded_schedule(ctx
) < 0)
5359 /* Check that check for progress is not confused by rational
5362 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5363 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5365 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5366 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5368 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5369 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5371 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5373 /* Check that we allow schedule rows that are only non-trivial
5374 * on some full-dimensional domains.
5376 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5377 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5378 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5380 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5381 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5383 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5385 if (test_conditional_schedule_constraints(ctx
) < 0)
5388 if (test_strongly_satisfying_schedule(ctx
) < 0)
5391 if (test_conflicting_context_schedule(ctx
) < 0)
5394 if (test_coalescing_schedule(ctx
) < 0)
5396 if (test_skewing_schedule(ctx
) < 0)
5402 /* Perform scheduling tests using the whole component scheduler.
5404 static int test_schedule_whole(isl_ctx
*ctx
)
5409 whole
= isl_options_get_schedule_whole_component(ctx
);
5410 isl_options_set_schedule_whole_component(ctx
, 1);
5411 r
= test_schedule(ctx
);
5412 isl_options_set_schedule_whole_component(ctx
, whole
);
5417 /* Perform scheduling tests using the incremental scheduler.
5419 static int test_schedule_incremental(isl_ctx
*ctx
)
5424 whole
= isl_options_get_schedule_whole_component(ctx
);
5425 isl_options_set_schedule_whole_component(ctx
, 0);
5426 r
= test_schedule(ctx
);
5427 isl_options_set_schedule_whole_component(ctx
, whole
);
5432 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
5434 isl_union_map
*umap
;
5437 umap
= isl_union_map_read_from_str(ctx
, str
);
5438 test
= isl_union_map_plain_is_injective(umap
);
5439 isl_union_map_free(umap
);
5442 if (test
== injective
)
5445 isl_die(ctx
, isl_error_unknown
,
5446 "map not detected as injective", return -1);
5448 isl_die(ctx
, isl_error_unknown
,
5449 "map detected as injective", return -1);
5452 int test_injective(isl_ctx
*ctx
)
5456 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5458 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
5460 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
5462 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
5464 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5466 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5468 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5470 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5473 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5474 if (test_plain_injective(ctx
, str
, 1))
5476 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5477 if (test_plain_injective(ctx
, str
, 0))
5485 #include "isl_test_plain_equal_templ.c"
5488 #define BASE pw_multi_aff
5489 #include "isl_test_plain_equal_templ.c"
5492 #define BASE union_pw_aff
5493 #include "isl_test_plain_equal_templ.c"
5495 /* Basic tests on isl_union_pw_aff.
5497 * In particular, check that isl_union_pw_aff_aff_on_domain
5498 * aligns the parameters of the input objects and
5499 * that isl_union_pw_aff_param_on_domain_id properly
5500 * introduces the parameter.
5502 static int test_upa(isl_ctx
*ctx
)
5507 isl_union_set
*domain
;
5508 isl_union_pw_aff
*upa
;
5511 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5512 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5513 domain
= isl_union_set_read_from_str(ctx
, str
);
5514 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5515 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5516 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5517 isl_union_pw_aff_free(upa
);
5521 id
= isl_id_alloc(ctx
, "N", NULL
);
5522 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5523 domain
= isl_union_set_read_from_str(ctx
, str
);
5524 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5525 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5526 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5527 isl_union_pw_aff_free(upa
);
5535 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5536 __isl_take isl_aff
*aff2
);
5538 ['+'] = { &isl_aff_add
},
5539 ['-'] = { &isl_aff_sub
},
5540 ['*'] = { &isl_aff_mul
},
5541 ['/'] = { &isl_aff_div
},
5549 } aff_bin_tests
[] = {
5550 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5551 "{ [i] -> [2i] }" },
5552 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5554 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5555 "{ [i] -> [2i] }" },
5556 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5557 "{ [i] -> [2i] }" },
5558 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5559 "{ [i] -> [i/2] }" },
5560 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5562 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5563 "{ [i] -> [NaN] }" },
5564 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5565 "{ [i] -> [NaN] }" },
5566 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5567 "{ [i] -> [NaN] }" },
5568 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5569 "{ [i] -> [NaN] }" },
5570 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5571 "{ [i] -> [NaN] }" },
5572 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5573 "{ [i] -> [NaN] }" },
5574 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5575 "{ [i] -> [NaN] }" },
5576 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5577 "{ [i] -> [NaN] }" },
5578 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5579 "{ [i] -> [NaN] }" },
5580 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5581 "{ [i] -> [NaN] }" },
5582 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5583 "{ [i] -> [NaN] }" },
5584 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5585 "{ [i] -> [NaN] }" },
5586 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5587 "{ [i] -> [NaN] }" },
5590 /* Perform some basic tests of binary operations on isl_aff objects.
5592 static int test_bin_aff(isl_ctx
*ctx
)
5595 isl_aff
*aff1
, *aff2
, *res
;
5596 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5597 __isl_take isl_aff
*aff2
);
5600 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5601 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5602 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5603 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5604 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5605 aff1
= fn(aff1
, aff2
);
5606 if (isl_aff_is_nan(res
))
5607 ok
= isl_aff_is_nan(aff1
);
5609 ok
= isl_aff_plain_is_equal(aff1
, res
);
5615 isl_die(ctx
, isl_error_unknown
,
5616 "unexpected result", return -1);
5623 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5624 __isl_take isl_pw_aff
*pa2
);
5625 } pw_aff_bin_op
[] = {
5626 ['m'] = { &isl_pw_aff_min
},
5627 ['M'] = { &isl_pw_aff_max
},
5630 /* Inputs for binary isl_pw_aff operation tests.
5631 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5632 * defined by pw_aff_bin_op, and "res" is the expected result.
5639 } pw_aff_bin_tests
[] = {
5640 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5642 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5644 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5645 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5646 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5647 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5648 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5649 "{ [i] -> [NaN] }" },
5650 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5651 "{ [i] -> [NaN] }" },
5654 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5656 static int test_bin_pw_aff(isl_ctx
*ctx
)
5660 isl_pw_aff
*pa1
, *pa2
, *res
;
5662 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5663 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5664 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5665 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5666 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5667 if (isl_pw_aff_involves_nan(res
))
5668 ok
= isl_pw_aff_involves_nan(pa1
);
5670 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5671 isl_pw_aff_free(pa1
);
5672 isl_pw_aff_free(res
);
5676 isl_die(ctx
, isl_error_unknown
,
5677 "unexpected result", return -1);
5683 /* Inputs for basic tests of test operations on
5684 * isl_union_pw_multi_aff objects.
5685 * "fn" is the function that is being tested.
5686 * "arg" is a string description of the input.
5687 * "res" is the expected result.
5690 isl_bool (*fn
)(__isl_keep isl_union_pw_multi_aff
*upma1
);
5693 } upma_test_tests
[] = {
5694 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [1] }",
5696 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [NaN]; B[0] -> [1] }",
5698 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [NaN] }",
5700 { &isl_union_pw_multi_aff_involves_nan
,
5701 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5703 { &isl_union_pw_multi_aff_involves_locals
,
5704 "{ A[] -> [0]; B[0] -> [1] }",
5706 { &isl_union_pw_multi_aff_involves_locals
,
5707 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5709 { &isl_union_pw_multi_aff_involves_locals
,
5710 "{ A[] -> [0]; B[x] -> [x // 2] }",
5712 { &isl_union_pw_multi_aff_involves_locals
,
5713 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5717 /* Perform some basic tests of test operations on
5718 * isl_union_pw_multi_aff objects.
5720 static isl_stat
test_upma_test(isl_ctx
*ctx
)
5723 isl_union_pw_multi_aff
*upma
;
5726 for (i
= 0; i
< ARRAY_SIZE(upma_test_tests
); ++i
) {
5729 str
= upma_test_tests
[i
].arg
;
5730 upma
= isl_union_pw_multi_aff_read_from_str(ctx
, str
);
5731 res
= upma_test_tests
[i
].fn(upma
);
5732 isl_union_pw_multi_aff_free(upma
);
5734 return isl_stat_error
;
5735 if (res
!= upma_test_tests
[i
].res
)
5736 isl_die(ctx
, isl_error_unknown
,
5737 "unexpected result", return isl_stat_error
);
5744 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5745 __isl_take isl_union_pw_multi_aff
*upma1
,
5746 __isl_take isl_union_pw_multi_aff
*upma2
);
5750 } upma_bin_tests
[] = {
5751 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5752 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5753 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5754 "{ B[x] -> [2] : x >= 0 }",
5755 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5756 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5757 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5758 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5759 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5760 "D[i] -> B[2] : i >= 5 }" },
5761 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5762 "{ B[x] -> C[2] : x > 0 }",
5763 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5764 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5765 "{ B[x] -> A[2] : x >= 0 }",
5766 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5768 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5769 "{ B[x] -> C[x + 2] }",
5770 "{ D[y] -> B[2y] }",
5773 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5774 "{ [A[x] -> B[x + 1]] -> C[x + 2] }",
5775 "{ D[y] -> B[2y] }",
5778 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5779 "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5780 "{ D[y] -> A[2y] }",
5781 "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5783 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5784 "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5785 "{ D[y] -> A[2y] }",
5786 "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5789 /* Perform some basic tests of binary operations on
5790 * isl_union_pw_multi_aff objects.
5792 static int test_bin_upma(isl_ctx
*ctx
)
5795 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5798 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5799 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5800 upma_bin_tests
[i
].arg1
);
5801 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5802 upma_bin_tests
[i
].arg2
);
5803 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5804 upma_bin_tests
[i
].res
);
5805 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5806 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5807 isl_union_pw_multi_aff_free(upma1
);
5808 isl_union_pw_multi_aff_free(res
);
5812 isl_die(ctx
, isl_error_unknown
,
5813 "unexpected result", return -1);
5820 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5821 __isl_take isl_union_pw_multi_aff
*upma1
,
5822 __isl_take isl_union_pw_multi_aff
*upma2
);
5825 } upma_bin_fail_tests
[] = {
5826 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5827 "{ B[x] -> C[2] : x >= 0 }" },
5830 /* Perform some basic tests of binary operations on
5831 * isl_union_pw_multi_aff objects that are expected to fail.
5833 static int test_bin_upma_fail(isl_ctx
*ctx
)
5836 isl_union_pw_multi_aff
*upma1
, *upma2
;
5839 on_error
= isl_options_get_on_error(ctx
);
5840 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5841 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5842 for (i
= 0; i
< n
; ++i
) {
5843 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5844 upma_bin_fail_tests
[i
].arg1
);
5845 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5846 upma_bin_fail_tests
[i
].arg2
);
5847 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5848 isl_union_pw_multi_aff_free(upma1
);
5852 isl_options_set_on_error(ctx
, on_error
);
5854 isl_die(ctx
, isl_error_unknown
,
5855 "operation not expected to succeed", return -1);
5860 /* Inputs for basic tests of binary operations on
5861 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5862 * "fn" is the function that is being tested.
5863 * "arg1" and "arg2" are string descriptions of the inputs.
5864 * "res" is a string description of the expected result.
5867 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5868 __isl_take isl_union_pw_multi_aff
*upma
,
5869 __isl_take isl_union_set
*uset
);
5873 } upma_uset_tests
[] = {
5874 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5875 "{ A[i] -> B[i] }", "{ B[0] }",
5877 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain
,
5878 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5879 "{ [A[1] -> B[1]] -> C[2] }" },
5880 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5881 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5882 "{ [A[0] -> B[0]] -> C[1] }" },
5883 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5884 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5885 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5886 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5887 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5888 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5889 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5890 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5892 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5895 /* Perform some basic tests of binary operations on
5896 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5898 static isl_stat
test_upma_uset(isl_ctx
*ctx
)
5902 isl_union_pw_multi_aff
*upma
, *res
;
5903 isl_union_set
*uset
;
5905 for (i
= 0; i
< ARRAY_SIZE(upma_uset_tests
); ++i
) {
5906 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5907 upma_uset_tests
[i
].arg1
);
5908 uset
= isl_union_set_read_from_str(ctx
,
5909 upma_uset_tests
[i
].arg2
);
5910 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5911 upma_uset_tests
[i
].res
);
5912 upma
= upma_uset_tests
[i
].fn(upma
, uset
);
5913 ok
= isl_union_pw_multi_aff_plain_is_equal(upma
, res
);
5914 isl_union_pw_multi_aff_free(upma
);
5915 isl_union_pw_multi_aff_free(res
);
5917 return isl_stat_error
;
5919 isl_die(ctx
, isl_error_unknown
,
5920 "unexpected result", return isl_stat_error
);
5926 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5927 * "fn" is the function that is tested.
5928 * "arg" is a string description of the input.
5929 * "res" is a string description of the expected result.
5932 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5935 } mpa_un_tests
[] = {
5936 { &isl_multi_pw_aff_range_factor_domain
,
5937 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5938 "{ A[x] -> B[(1 : x >= 5)] }" },
5939 { &isl_multi_pw_aff_range_factor_range
,
5940 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5941 "{ A[y] -> C[(2 : y <= 10)] }" },
5942 { &isl_multi_pw_aff_range_factor_domain
,
5943 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5944 "{ A[x] -> B[(1 : x >= 5)] }" },
5945 { &isl_multi_pw_aff_range_factor_range
,
5946 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5947 "{ A[y] -> C[] }" },
5948 { &isl_multi_pw_aff_range_factor_domain
,
5949 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5950 "{ A[x] -> B[] }" },
5951 { &isl_multi_pw_aff_range_factor_range
,
5952 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5953 "{ A[y] -> C[(2 : y <= 10)] }" },
5954 { &isl_multi_pw_aff_range_factor_domain
,
5955 "{ A[x] -> [B[] -> C[]] }",
5956 "{ A[x] -> B[] }" },
5957 { &isl_multi_pw_aff_range_factor_range
,
5958 "{ A[x] -> [B[] -> C[]] }",
5959 "{ A[y] -> C[] }" },
5960 { &isl_multi_pw_aff_factor_range
,
5963 { &isl_multi_pw_aff_range_factor_domain
,
5964 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5965 "{ A[x] -> B[] : x >= 0 }" },
5966 { &isl_multi_pw_aff_range_factor_range
,
5967 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5968 "{ A[y] -> C[] : y >= 0 }" },
5969 { &isl_multi_pw_aff_factor_range
,
5970 "[N] -> { [B[] -> C[]] : N >= 0 }",
5971 "[N] -> { C[] : N >= 0 }" },
5974 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5976 static int test_un_mpa(isl_ctx
*ctx
)
5980 isl_multi_pw_aff
*mpa
, *res
;
5982 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5983 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5984 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5985 mpa
= mpa_un_tests
[i
].fn(mpa
);
5986 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5987 isl_multi_pw_aff_free(mpa
);
5988 isl_multi_pw_aff_free(res
);
5992 isl_die(ctx
, isl_error_unknown
,
5993 "unexpected result", return -1);
5999 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
6000 * "fn" is the function that is tested.
6001 * "arg1" and "arg2" are string descriptions of the inputs.
6002 * "res" is a string description of the expected result.
6005 __isl_give isl_multi_pw_aff
*(*fn
)(
6006 __isl_take isl_multi_pw_aff
*mpa1
,
6007 __isl_take isl_multi_pw_aff
*mpa2
);
6011 } mpa_bin_tests
[] = {
6012 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
6014 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
6015 "{ A[x] -> [(x : x <= 10)] }",
6016 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
6017 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
6018 "{ A[x] -> [] : x <= 10 }",
6019 "{ A[x] -> [] : 5 <= x <= 10 }" },
6020 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
6021 "[N] -> { A[x] -> [] : x <= N }",
6022 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
6023 { &isl_multi_pw_aff_add
,
6024 "[N] -> { A[x] -> [] : x <= N }",
6025 "{ A[x] -> [] : x >= 5 }",
6026 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
6027 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6028 "{ A[y] -> C[(2 : y <= 10)] }",
6029 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
6030 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
6031 "{ A[y] -> C[2] : y <= 10 }",
6032 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
6033 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
6034 "[N] -> { A[y] -> C[2] : y <= N }",
6035 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
6036 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
6037 "{ A[y] -> C[2] : y <= 10 }",
6038 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
6039 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6040 "{ A[] -> [B[1] -> C[2]] }" },
6041 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6042 "{ A[] -> [B[] -> C[]] }" },
6043 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6044 "{ A[y] -> C[] : y <= 10 }",
6045 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
6046 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
6047 "{ A[x] -> B[(1 : x >= 5)] }",
6048 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
6049 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6050 "{ A[y] -> C[(2 : y <= 10)] }",
6051 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
6052 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6053 "{ A[y] -> C[] : y <= 10 }",
6054 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
6055 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
6056 "{ A[x] -> B[(1 : x >= 5)] }",
6057 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
6058 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6059 "[N] -> { A[y] -> C[] : y <= N }",
6060 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
6061 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
6062 "{ A[x] -> B[(1 : x >= 5)] }",
6063 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
6064 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
6065 "{ A[y] -> C[] : y <= 10 }",
6066 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
6067 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6068 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
6069 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6070 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
6071 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6072 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
6073 "{ A[a,b] -> C[b + 2a] }" },
6074 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6075 "{ B[i,j] -> C[i + 2j] }",
6076 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6077 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
6078 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6079 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
6080 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6081 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
6082 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6083 "{ B[i,j] -> C[] }",
6084 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6085 "{ A[a,b] -> C[] }" },
6086 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6087 "{ B[i,j] -> C[] : i > j }",
6088 "{ A[a,b] -> B[b,a] }",
6089 "{ A[a,b] -> C[] : b > a }" },
6090 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6091 "{ B[i,j] -> C[] : j > 5 }",
6092 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6093 "{ A[a,b] -> C[] : b > a > 5 }" },
6094 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6095 "[N] -> { B[i,j] -> C[] : j > N }",
6096 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6097 "[N] -> { A[a,b] -> C[] : b > a > N }" },
6098 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6099 "[M,N] -> { B[] -> C[] : N > 5 }",
6100 "[M,N] -> { A[] -> B[] : M > N }",
6101 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
6104 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
6106 static int test_bin_mpa(isl_ctx
*ctx
)
6110 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
6112 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
6113 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
6114 mpa_bin_tests
[i
].arg1
);
6115 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
6116 mpa_bin_tests
[i
].arg2
);
6117 res
= isl_multi_pw_aff_read_from_str(ctx
,
6118 mpa_bin_tests
[i
].res
);
6119 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
6120 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
6121 isl_multi_pw_aff_free(mpa1
);
6122 isl_multi_pw_aff_free(res
);
6126 isl_die(ctx
, isl_error_unknown
,
6127 "unexpected result", return -1);
6133 /* Inputs for basic tests of unary operations on
6134 * isl_multi_union_pw_aff objects.
6135 * "fn" is the function that is tested.
6136 * "arg" is a string description of the input.
6137 * "res" is a string description of the expected result.
6140 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6141 __isl_take isl_multi_union_pw_aff
*mupa
);
6144 } mupa_un_tests
[] = {
6145 { &isl_multi_union_pw_aff_factor_range
,
6146 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
6147 "C[{ A[] -> [2] }]" },
6148 { &isl_multi_union_pw_aff_factor_range
,
6149 "[B[] -> C[{ A[] -> [2] }]]",
6150 "C[{ A[] -> [2] }]" },
6151 { &isl_multi_union_pw_aff_factor_range
,
6152 "[B[{ A[] -> [1] }] -> C[]]",
6154 { &isl_multi_union_pw_aff_factor_range
,
6157 { &isl_multi_union_pw_aff_factor_range
,
6158 "([B[] -> C[]] : { A[x] : x >= 0 })",
6159 "(C[] : { A[x] : x >= 0 })" },
6160 { &isl_multi_union_pw_aff_factor_range
,
6161 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
6162 "[N] -> (C[] : { A[x] : x <= N })" },
6163 { &isl_multi_union_pw_aff_factor_range
,
6164 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
6165 "[N] -> (C[] : { : N >= 0 })" },
6168 /* Perform some basic tests of unary operations on
6169 * isl_multi_union_pw_aff objects.
6171 static int test_un_mupa(isl_ctx
*ctx
)
6175 isl_multi_union_pw_aff
*mupa
, *res
;
6177 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
6178 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6179 mupa_un_tests
[i
].arg
);
6180 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6181 mupa_un_tests
[i
].res
);
6182 mupa
= mupa_un_tests
[i
].fn(mupa
);
6183 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6184 isl_multi_union_pw_aff_free(mupa
);
6185 isl_multi_union_pw_aff_free(res
);
6189 isl_die(ctx
, isl_error_unknown
,
6190 "unexpected result", return -1);
6196 /* Inputs for basic tests of binary operations on
6197 * isl_multi_union_pw_aff objects.
6198 * "fn" is the function that is tested.
6199 * "arg1" and "arg2" are string descriptions of the inputs.
6200 * "res" is a string description of the expected result.
6203 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6204 __isl_take isl_multi_union_pw_aff
*mupa1
,
6205 __isl_take isl_multi_union_pw_aff
*mupa2
);
6209 } mupa_bin_tests
[] = {
6210 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6211 "[{ A[] -> [3] }]" },
6212 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6213 "[{ A[] -> [-1] }]" },
6214 { &isl_multi_union_pw_aff_add
,
6215 "[{ A[] -> [1]; B[] -> [4] }]",
6216 "[{ A[] -> [2]; C[] -> [5] }]",
6217 "[{ A[] -> [3] }]" },
6218 { &isl_multi_union_pw_aff_union_add
,
6219 "[{ A[] -> [1]; B[] -> [4] }]",
6220 "[{ A[] -> [2]; C[] -> [5] }]",
6221 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6222 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6223 "[{ A[x] -> [(x)] : x <= 10 }]",
6224 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6225 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6226 "([] : { A[x] : x <= 10 })",
6227 "([] : { A[x] : 5 <= x <= 10 })" },
6228 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6229 "[N] -> ([] : { A[x] : x <= N })",
6230 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6231 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
6232 "([] : { A[x] : x <= 10 })",
6233 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6234 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6235 "[{ A[x] -> [(x)] : x <= 10 }]",
6236 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6237 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6238 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
6239 "([] : { A[x] : x <= 10 })",
6240 "([] : { A[x] })" },
6241 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
6242 "[N] -> ([] : { A[x] : x >= N })",
6243 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6244 { &isl_multi_union_pw_aff_union_add
,
6245 "[N] -> ([] : { A[] : N >= 0})",
6246 "[N] -> ([] : { A[] : N <= 0})",
6247 "[N] -> ([] : { A[] })" },
6248 { &isl_multi_union_pw_aff_union_add
,
6249 "[N] -> ([] : { A[] })",
6250 "[N] -> ([] : { : })",
6251 "[N] -> ([] : { : })" },
6252 { &isl_multi_union_pw_aff_union_add
,
6253 "[N] -> ([] : { : })",
6254 "[N] -> ([] : { A[] })",
6255 "[N] -> ([] : { : })" },
6256 { &isl_multi_union_pw_aff_union_add
,
6257 "[N] -> ([] : { : N >= 0})",
6258 "[N] -> ([] : { : N <= 0})",
6259 "[N] -> ([] : { : })" },
6260 { &isl_multi_union_pw_aff_range_product
,
6261 "B[{ A[] -> [1] }]",
6262 "C[{ A[] -> [2] }]",
6263 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6264 { &isl_multi_union_pw_aff_range_product
,
6265 "(B[] : { A[x] : x >= 5 })",
6266 "(C[] : { A[x] : x <= 10 })",
6267 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6268 { &isl_multi_union_pw_aff_range_product
,
6269 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6270 "(C[] : { A[x] : x <= 10 })",
6271 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6272 { &isl_multi_union_pw_aff_range_product
,
6273 "(C[] : { A[x] : x <= 10 })",
6274 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6275 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6276 { &isl_multi_union_pw_aff_range_product
,
6277 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6278 "[N] -> (C[] : { A[x] : x <= N })",
6279 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6280 { &isl_multi_union_pw_aff_range_product
,
6281 "[N] -> (C[] : { A[x] : x <= N })",
6282 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6283 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6284 { &isl_multi_union_pw_aff_range_product
,
6285 "B[{ A[] -> [1]; D[] -> [3] }]",
6286 "C[{ A[] -> [2] }]",
6287 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6288 { &isl_multi_union_pw_aff_range_product
,
6291 "([B[] -> C[]] : { A[x] })" },
6292 { &isl_multi_union_pw_aff_range_product
,
6295 "([B[] -> C[]] : { A[x] })" },
6298 /* Perform some basic tests of binary operations on
6299 * isl_multi_union_pw_aff objects.
6301 static int test_bin_mupa(isl_ctx
*ctx
)
6305 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
6307 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
6308 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
6309 mupa_bin_tests
[i
].arg1
);
6310 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
6311 mupa_bin_tests
[i
].arg2
);
6312 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6313 mupa_bin_tests
[i
].res
);
6314 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
6315 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
6316 isl_multi_union_pw_aff_free(mupa1
);
6317 isl_multi_union_pw_aff_free(res
);
6321 isl_die(ctx
, isl_error_unknown
,
6322 "unexpected result", return -1);
6328 /* Inputs for basic tests of binary operations on
6329 * pairs of isl_multi_union_pw_aff and isl_set objects.
6330 * "fn" is the function that is tested.
6331 * "arg1" and "arg2" are string descriptions of the inputs.
6332 * "res" is a string description of the expected result.
6335 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6336 __isl_take isl_multi_union_pw_aff
*mupa
,
6337 __isl_take isl_set
*set
);
6341 } mupa_set_tests
[] = {
6342 { &isl_multi_union_pw_aff_intersect_range
,
6343 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6344 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6345 { &isl_multi_union_pw_aff_intersect_range
,
6346 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6347 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6348 { &isl_multi_union_pw_aff_intersect_range
,
6349 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6350 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6351 { &isl_multi_union_pw_aff_intersect_range
,
6352 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6353 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6354 { &isl_multi_union_pw_aff_intersect_range
,
6355 "C[]", "{ C[] }", "C[]" },
6356 { &isl_multi_union_pw_aff_intersect_range
,
6357 "[N] -> (C[] : { : N >= 0 })",
6359 "[N] -> (C[] : { : N >= 0 })" },
6360 { &isl_multi_union_pw_aff_intersect_range
,
6361 "(C[] : { A[a,b] })",
6363 "(C[] : { A[a,b] })" },
6364 { &isl_multi_union_pw_aff_intersect_range
,
6365 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6367 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6368 { &isl_multi_union_pw_aff_intersect_range
,
6370 "[N] -> { C[] : N >= 0 }",
6371 "[N] -> (C[] : { : N >= 0 })" },
6372 { &isl_multi_union_pw_aff_intersect_range
,
6373 "(C[] : { A[a,b] })",
6374 "[N] -> { C[] : N >= 0 }",
6375 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6376 { &isl_multi_union_pw_aff_intersect_range
,
6377 "[N] -> (C[] : { : N >= 0 })",
6378 "[N] -> { C[] : N < 1024 }",
6379 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6380 { &isl_multi_union_pw_aff_intersect_params
,
6381 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6382 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6383 { &isl_multi_union_pw_aff_intersect_params
,
6384 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6385 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6386 { &isl_multi_union_pw_aff_intersect_params
,
6387 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6388 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6389 { &isl_multi_union_pw_aff_intersect_params
,
6390 "C[]", "[N] -> { : N >= 0 }",
6391 "[N] -> (C[] : { : N >= 0 })" },
6392 { &isl_multi_union_pw_aff_intersect_params
,
6393 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6394 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6395 { &isl_multi_union_pw_aff_intersect_params
,
6396 "[N] -> (C[] : { A[a,N] })", "{ : }",
6397 "[N] -> (C[] : { A[a,N] })" },
6398 { &isl_multi_union_pw_aff_intersect_params
,
6399 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6400 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6403 /* Perform some basic tests of binary operations on
6404 * pairs of isl_multi_union_pw_aff and isl_set objects.
6406 static int test_mupa_set(isl_ctx
*ctx
)
6410 isl_multi_union_pw_aff
*mupa
, *res
;
6413 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
6414 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6415 mupa_set_tests
[i
].arg1
);
6416 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
6417 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6418 mupa_set_tests
[i
].res
);
6419 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
6420 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6421 isl_multi_union_pw_aff_free(mupa
);
6422 isl_multi_union_pw_aff_free(res
);
6426 isl_die(ctx
, isl_error_unknown
,
6427 "unexpected result", return -1);
6433 /* Inputs for basic tests of binary operations on
6434 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6435 * "fn" is the function that is tested.
6436 * "arg1" and "arg2" are string descriptions of the inputs.
6437 * "res" is a string description of the expected result.
6440 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6441 __isl_take isl_multi_union_pw_aff
*mupa
,
6442 __isl_take isl_union_set
*uset
);
6446 } mupa_uset_tests
[] = {
6447 { &isl_multi_union_pw_aff_intersect_domain
,
6448 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6449 "C[{ B[i,i] -> [3i] }]" },
6450 { &isl_multi_union_pw_aff_intersect_domain
,
6451 "(C[] : { B[i,j] })", "{ B[i,i] }",
6452 "(C[] : { B[i,i] })" },
6453 { &isl_multi_union_pw_aff_intersect_domain
,
6454 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6455 "[N] -> (C[] : { B[N,N] })" },
6456 { &isl_multi_union_pw_aff_intersect_domain
,
6457 "C[]", "{ B[i,i] }",
6458 "(C[] : { B[i,i] })" },
6459 { &isl_multi_union_pw_aff_intersect_domain
,
6460 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6461 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6464 /* Perform some basic tests of binary operations on
6465 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6467 static int test_mupa_uset(isl_ctx
*ctx
)
6471 isl_multi_union_pw_aff
*mupa
, *res
;
6472 isl_union_set
*uset
;
6474 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
6475 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6476 mupa_uset_tests
[i
].arg1
);
6477 uset
= isl_union_set_read_from_str(ctx
,
6478 mupa_uset_tests
[i
].arg2
);
6479 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6480 mupa_uset_tests
[i
].res
);
6481 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
6482 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6483 isl_multi_union_pw_aff_free(mupa
);
6484 isl_multi_union_pw_aff_free(res
);
6488 isl_die(ctx
, isl_error_unknown
,
6489 "unexpected result", return -1);
6495 /* Inputs for basic tests of binary operations on
6496 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6497 * "fn" is the function that is tested.
6498 * "arg1" and "arg2" are string descriptions of the inputs.
6499 * "res" is a string description of the expected result.
6502 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6503 __isl_take isl_multi_union_pw_aff
*mupa
,
6504 __isl_take isl_multi_aff
*ma
);
6508 } mupa_ma_tests
[] = {
6509 { &isl_multi_union_pw_aff_apply_multi_aff
,
6510 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6511 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6512 "{ C[a,b] -> D[b,a] }",
6513 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6514 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6515 { &isl_multi_union_pw_aff_apply_multi_aff
,
6516 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6517 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6518 "{ C[a,b] -> D[b,a] }",
6519 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6520 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6521 { &isl_multi_union_pw_aff_apply_multi_aff
,
6522 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6523 "[N] -> { C[a] -> D[a + N] }",
6524 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6525 { &isl_multi_union_pw_aff_apply_multi_aff
,
6529 { &isl_multi_union_pw_aff_apply_multi_aff
,
6530 "[N] -> (C[] : { : N >= 0 })",
6532 "[N] -> (D[] : { : N >= 0 })" },
6533 { &isl_multi_union_pw_aff_apply_multi_aff
,
6535 "[N] -> { C[] -> D[N] }",
6536 "[N] -> D[{ [N] }]" },
6537 { &isl_multi_union_pw_aff_apply_multi_aff
,
6538 "(C[] : { A[i,j] : i >= j })",
6540 "(D[] : { A[i,j] : i >= j })" },
6541 { &isl_multi_union_pw_aff_apply_multi_aff
,
6542 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6544 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6545 { &isl_multi_union_pw_aff_apply_multi_aff
,
6546 "(C[] : { A[i,j] : i >= j })",
6547 "[N] -> { C[] -> D[N] }",
6548 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6551 /* Perform some basic tests of binary operations on
6552 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6554 static int test_mupa_ma(isl_ctx
*ctx
)
6558 isl_multi_union_pw_aff
*mupa
, *res
;
6561 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6562 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6563 mupa_ma_tests
[i
].arg1
);
6564 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6565 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6566 mupa_ma_tests
[i
].res
);
6567 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6568 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6569 isl_multi_union_pw_aff_free(mupa
);
6570 isl_multi_union_pw_aff_free(res
);
6574 isl_die(ctx
, isl_error_unknown
,
6575 "unexpected result", return -1);
6581 /* Inputs for basic tests of binary operations on
6582 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6583 * "fn" is the function that is tested.
6584 * "arg1" and "arg2" are string descriptions of the inputs.
6585 * "res" is a string description of the expected result.
6588 __isl_give isl_union_pw_aff
*(*fn
)(
6589 __isl_take isl_multi_union_pw_aff
*mupa
,
6590 __isl_take isl_pw_aff
*pa
);
6594 } mupa_pa_tests
[] = {
6595 { &isl_multi_union_pw_aff_apply_pw_aff
,
6596 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6597 "[N] -> { C[a] -> [a + N] }",
6598 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6599 { &isl_multi_union_pw_aff_apply_pw_aff
,
6600 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6601 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6602 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6603 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6604 { &isl_multi_union_pw_aff_apply_pw_aff
,
6606 "[N] -> { C[] -> [N] }",
6608 { &isl_multi_union_pw_aff_apply_pw_aff
,
6610 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6611 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6612 { &isl_multi_union_pw_aff_apply_pw_aff
,
6613 "[N] -> (C[] : { : N >= 0 })",
6614 "[N] -> { C[] -> [N] }",
6615 "[N] -> { [N] : N >= 0 }" },
6616 { &isl_multi_union_pw_aff_apply_pw_aff
,
6617 "[N] -> (C[] : { : N >= 0 })",
6618 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6619 "[N] -> { [N] : N >= 0 }" },
6620 { &isl_multi_union_pw_aff_apply_pw_aff
,
6621 "[N] -> (C[] : { : N >= 0 })",
6623 "[N] -> { [0] : N >= 0 }" },
6624 { &isl_multi_union_pw_aff_apply_pw_aff
,
6625 "(C[] : { A[i,j] : i >= j })",
6626 "[N] -> { C[] -> [N] }",
6627 "[N] -> { A[i,j] -> [N] : i >= j }" },
6628 { &isl_multi_union_pw_aff_apply_pw_aff
,
6629 "(C[] : { A[i,j] : i >= j })",
6630 "[N] -> { C[] -> [N] : N >= 0 }",
6631 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6634 /* Perform some basic tests of binary operations on
6635 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6637 static int test_mupa_pa(isl_ctx
*ctx
)
6641 isl_multi_union_pw_aff
*mupa
;
6642 isl_union_pw_aff
*upa
, *res
;
6645 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6646 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6647 mupa_pa_tests
[i
].arg1
);
6648 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6649 res
= isl_union_pw_aff_read_from_str(ctx
,
6650 mupa_pa_tests
[i
].res
);
6651 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6652 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6653 isl_union_pw_aff_free(upa
);
6654 isl_union_pw_aff_free(res
);
6658 isl_die(ctx
, isl_error_unknown
,
6659 "unexpected result", return -1);
6665 /* Inputs for basic tests of binary operations on
6666 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6667 * "fn" is the function that is tested.
6668 * "arg1" and "arg2" are string descriptions of the inputs.
6669 * "res" is a string description of the expected result.
6672 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6673 __isl_take isl_multi_union_pw_aff
*mupa
,
6674 __isl_take isl_pw_multi_aff
*pma
);
6678 } mupa_pma_tests
[] = {
6679 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6680 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6681 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6682 "{ C[a,b] -> D[b,a] }",
6683 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6684 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6685 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6686 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6687 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6688 "{ C[a,b] -> D[b,a] }",
6689 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6690 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6691 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6692 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6693 "[N] -> { C[a] -> D[a + N] }",
6694 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6695 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6696 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6697 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6698 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6699 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6700 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6701 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6702 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6703 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6704 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6705 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6706 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6707 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6708 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6712 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6713 "[N] -> (C[] : { : N >= 0 })",
6715 "[N] -> (D[] : { : N >= 0 })" },
6716 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6718 "[N] -> { C[] -> D[N] }",
6719 "[N] -> D[{ [N] }]" },
6720 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6721 "(C[] : { A[i,j] : i >= j })",
6723 "(D[] : { A[i,j] : i >= j })" },
6724 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6725 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6727 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6728 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6729 "(C[] : { A[i,j] : i >= j })",
6730 "[N] -> { C[] -> D[N] }",
6731 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6732 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6734 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6735 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6736 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6737 "[N] -> (C[] : { : N >= 0 })",
6738 "[N] -> { C[] -> D[N] }",
6739 "[N] -> D[{ [N] : N >= 0 }]" },
6740 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6741 "[N] -> (C[] : { : N >= 0 })",
6742 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6743 "[N] -> D[{ [N] : N >= 0 }]" },
6744 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6745 "[N] -> (C[] : { : N >= 0 })",
6747 "[N] -> D[{ [0] : N >= 0 }]" },
6748 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6749 "(C[] : { A[i,j] : i >= j })",
6750 "[N] -> { C[] -> D[N] : N >= 0 }",
6751 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6754 /* Perform some basic tests of binary operations on
6755 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6757 static int test_mupa_pma(isl_ctx
*ctx
)
6761 isl_multi_union_pw_aff
*mupa
, *res
;
6762 isl_pw_multi_aff
*pma
;
6764 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6765 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6766 mupa_pma_tests
[i
].arg1
);
6767 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6768 mupa_pma_tests
[i
].arg2
);
6769 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6770 mupa_pma_tests
[i
].res
);
6771 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6772 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6773 isl_multi_union_pw_aff_free(mupa
);
6774 isl_multi_union_pw_aff_free(res
);
6778 isl_die(ctx
, isl_error_unknown
,
6779 "unexpected result", return -1);
6785 /* Inputs for basic tests of binary operations on
6786 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6787 * "fn" is the function that is tested.
6788 * "arg1" and "arg2" are string descriptions of the inputs.
6789 * "res" is a string description of the expected result.
6792 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6793 __isl_take isl_multi_union_pw_aff
*mupa
,
6794 __isl_take isl_union_pw_multi_aff
*upma
);
6798 } mupa_upma_tests
[] = {
6799 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6800 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6801 "C[{ A[a,b] -> [b + 2a] }]" },
6802 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6803 "C[{ B[i,j] -> [i + 2j] }]",
6804 "{ A[a,b] -> B[b,a] : b > a }",
6805 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6806 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6807 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6808 "{ A[a,b] -> B[b,a] : b > a }",
6809 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6810 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6811 "C[{ B[i,j] -> [i + 2j] }]",
6812 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6813 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6814 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6815 "(C[] : { B[a,b] })",
6816 "{ A[a,b] -> B[b,a] }",
6817 "(C[] : { A[a,b] })" },
6818 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6819 "(C[] : { B[a,b] })",
6820 "{ B[a,b] -> A[b,a] }",
6822 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6823 "(C[] : { B[a,b] })",
6824 "{ A[a,b] -> B[b,a] : a > b }",
6825 "(C[] : { A[a,b] : a > b })" },
6826 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6827 "(C[] : { B[a,b] : a > b })",
6828 "{ A[a,b] -> B[b,a] }",
6829 "(C[] : { A[a,b] : b > a })" },
6830 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6831 "[N] -> (C[] : { B[a,b] : a > N })",
6832 "{ A[a,b] -> B[b,a] : a > b }",
6833 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6834 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6835 "(C[] : { B[a,b] : a > b })",
6836 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6837 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6838 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6840 "{ A[a,b] -> B[b,a] }",
6842 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6843 "[N] -> (C[] : { : N >= 0 })",
6844 "{ A[a,b] -> B[b,a] }",
6845 "[N] -> (C[] : { : N >= 0 })" },
6846 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6848 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6849 "[N] -> (C[] : { : N >= 0 })" },
6852 /* Perform some basic tests of binary operations on
6853 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6855 static int test_mupa_upma(isl_ctx
*ctx
)
6859 isl_multi_union_pw_aff
*mupa
, *res
;
6860 isl_union_pw_multi_aff
*upma
;
6862 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6863 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6864 mupa_upma_tests
[i
].arg1
);
6865 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6866 mupa_upma_tests
[i
].arg2
);
6867 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6868 mupa_upma_tests
[i
].res
);
6869 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6870 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6871 isl_multi_union_pw_aff_free(mupa
);
6872 isl_multi_union_pw_aff_free(res
);
6876 isl_die(ctx
, isl_error_unknown
,
6877 "unexpected result", return -1);
6883 /* Check that the input tuple of an isl_aff can be set properly.
6885 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6891 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6892 id
= isl_id_alloc(ctx
, "A", NULL
);
6893 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6894 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6897 return isl_stat_error
;
6902 /* Check that affine expressions get normalized on addition/subtraction.
6903 * In particular, check that (final) unused integer divisions get removed
6904 * such that an expression derived from expressions with integer divisions
6905 * is found to be obviously equal to one that is created directly.
6907 static isl_stat
test_aff_normalize(isl_ctx
*ctx
)
6909 isl_aff
*aff
, *aff2
;
6912 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x//2] }");
6913 aff2
= isl_aff_read_from_str(ctx
, "{ [x] -> [1 + x//2] }");
6914 aff
= isl_aff_sub(aff2
, aff
);
6915 ok
= aff_check_plain_equal(aff
, "{ [x] -> [1] }");
6921 int test_aff(isl_ctx
*ctx
)
6926 isl_local_space
*ls
;
6931 if (test_upa(ctx
) < 0)
6933 if (test_bin_aff(ctx
) < 0)
6935 if (test_bin_pw_aff(ctx
) < 0)
6937 if (test_upma_test(ctx
) < 0)
6939 if (test_bin_upma(ctx
) < 0)
6941 if (test_bin_upma_fail(ctx
) < 0)
6943 if (test_upma_uset(ctx
) < 0)
6945 if (test_un_mpa(ctx
) < 0)
6947 if (test_bin_mpa(ctx
) < 0)
6949 if (test_un_mupa(ctx
) < 0)
6951 if (test_bin_mupa(ctx
) < 0)
6953 if (test_mupa_set(ctx
) < 0)
6955 if (test_mupa_uset(ctx
) < 0)
6957 if (test_mupa_ma(ctx
) < 0)
6959 if (test_mupa_pa(ctx
) < 0)
6961 if (test_mupa_pma(ctx
) < 0)
6963 if (test_mupa_upma(ctx
) < 0)
6966 space
= isl_space_set_alloc(ctx
, 0, 1);
6967 ls
= isl_local_space_from_space(space
);
6968 aff
= isl_aff_zero_on_domain(ls
);
6970 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6971 aff
= isl_aff_scale_down_ui(aff
, 3);
6972 aff
= isl_aff_floor(aff
);
6973 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6974 aff
= isl_aff_scale_down_ui(aff
, 2);
6975 aff
= isl_aff_floor(aff
);
6976 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6979 set
= isl_set_read_from_str(ctx
, str
);
6980 aff
= isl_aff_gist(aff
, set
);
6982 aff
= isl_aff_add_constant_si(aff
, -16);
6983 zero
= isl_aff_plain_is_zero(aff
);
6989 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6991 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6992 aff
= isl_aff_scale_down_ui(aff
, 64);
6993 aff
= isl_aff_floor(aff
);
6994 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6999 if (test_aff_set_tuple_id(ctx
) < 0)
7001 if (test_aff_normalize(ctx
) < 0)
7007 /* Inputs for isl_set_bind tests.
7008 * "set" is the input set.
7009 * "tuple" is the binding tuple.
7010 * "res" is the expected result.
7017 } bind_set_tests
[] = {
7018 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7020 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
7021 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
7023 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
7024 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
7026 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
7027 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
7029 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
7032 /* Perform basic isl_set_bind tests.
7034 static isl_stat
test_bind_set(isl_ctx
*ctx
)
7038 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
7041 isl_multi_id
*tuple
;
7044 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
7045 str
= bind_set_tests
[i
].tuple
;
7046 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7047 set
= isl_set_bind(set
, tuple
);
7048 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
7051 return isl_stat_error
;
7057 /* Inputs for isl_map_bind_domain tests.
7058 * "map" is the input map.
7059 * "tuple" is the binding tuple.
7060 * "res" is the expected result.
7066 } bind_map_domain_tests
[] = {
7067 { "{ A[M, N] -> [M + floor(N/2)] }",
7069 "[M, N] -> { [M + floor(N/2)] }" },
7070 { "{ B[N, M] -> [M + floor(N/2)] }",
7072 "[N, M] -> { [M + floor(N/2)] }" },
7073 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7075 "[M, N] -> { [M + floor(N/2)] }" },
7076 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7078 "[M, N] -> { [M + floor(N/2)] }" },
7079 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7081 "[M, N] -> { [M + floor(N/2)] }" },
7082 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7084 "[A, N, M] -> { [M + floor(N/2)] }" },
7087 /* Perform basic isl_map_bind_domain tests.
7089 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
7093 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
7097 isl_multi_id
*tuple
;
7100 str
= bind_map_domain_tests
[i
].map
;
7101 map
= isl_map_read_from_str(ctx
, str
);
7102 str
= bind_map_domain_tests
[i
].tuple
;
7103 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7104 set
= isl_map_bind_domain(map
, tuple
);
7105 str
= bind_map_domain_tests
[i
].res
;
7106 r
= set_check_equal(set
, str
);
7109 return isl_stat_error
;
7115 /* Inputs for isl_union_map_bind_range tests.
7116 * "map" is the input union map.
7117 * "tuple" is the binding tuple.
7118 * "res" is the expected result.
7124 } bind_umap_range_tests
[] = {
7125 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7127 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7128 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7131 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
7136 /* Perform basic isl_union_map_bind_range tests.
7138 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
7142 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
7144 isl_union_map
*umap
;
7145 isl_union_set
*uset
;
7146 isl_multi_id
*tuple
;
7149 str
= bind_umap_range_tests
[i
].map
;
7150 umap
= isl_union_map_read_from_str(ctx
, str
);
7151 str
= bind_umap_range_tests
[i
].tuple
;
7152 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7153 uset
= isl_union_map_bind_range(umap
, tuple
);
7154 str
= bind_umap_range_tests
[i
].res
;
7155 r
= uset_check_equal(uset
, str
);
7156 isl_union_set_free(uset
);
7158 return isl_stat_error
;
7164 /* Inputs for isl_pw_multi_aff_bind_domain tests.
7165 * "pma" is the input expression.
7166 * "tuple" is the binding tuple.
7167 * "res" is the expected result.
7173 } bind_pma_domain_tests
[] = {
7174 { "{ A[M, N] -> [M + floor(N/2)] }",
7176 "[M, N] -> { [M + floor(N/2)] }" },
7177 { "{ B[N, M] -> [M + floor(N/2)] }",
7179 "[N, M] -> { [M + floor(N/2)] }" },
7180 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7182 "[M, N] -> { [M + floor(N/2)] }" },
7183 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7185 "[M, N] -> { [M + floor(N/2)] }" },
7186 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7188 "[M, N] -> { [M + floor(N/2)] }" },
7189 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7191 "[A, N, M] -> { [M + floor(N/2)] }" },
7194 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7196 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
7200 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
7202 isl_pw_multi_aff
*pma
;
7203 isl_multi_id
*tuple
;
7206 str
= bind_pma_domain_tests
[i
].pma
;
7207 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7208 str
= bind_pma_domain_tests
[i
].tuple
;
7209 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7210 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
7211 str
= bind_pma_domain_tests
[i
].res
;
7212 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7213 isl_pw_multi_aff_free(pma
);
7215 return isl_stat_error
;
7221 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7222 * "pma" is the input expression.
7223 * "tuple" is the binding tuple.
7224 * "res" is the expected result.
7230 } bind_pma_domain_wrapped_tests
[] = {
7231 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7233 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7234 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7236 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7237 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7239 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7240 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7242 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7243 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7245 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7246 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7248 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7251 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7253 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
7257 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
7259 isl_pw_multi_aff
*pma
;
7260 isl_multi_id
*tuple
;
7263 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
7264 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7265 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
7266 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7267 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
7268 str
= bind_pma_domain_wrapped_tests
[i
].res
;
7269 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7270 isl_pw_multi_aff_free(pma
);
7272 return isl_stat_error
;
7278 /* Inputs for isl_aff_bind_id tests.
7279 * "aff" is the input expression.
7280 * "id" is the binding id.
7281 * "res" is the expected result.
7288 } bind_aff_tests
[] = {
7289 { "{ [4] }", "M", "[M = 4] -> { : }" },
7290 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7291 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7292 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7293 { "{ [NaN] }", "M", "{ : false }" },
7294 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7297 /* Perform basic isl_aff_bind_id tests.
7299 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
7303 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
7309 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
7310 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
7311 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
7312 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
7315 return isl_stat_error
;
7321 /* Inputs for isl_pw_aff_bind_id tests.
7322 * "pa" is the input expression.
7323 * "id" is the binding id.
7324 * "res" is the expected result.
7331 } bind_pa_tests
[] = {
7332 { "{ [4] }", "M", "[M = 4] -> { : }" },
7333 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7334 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7335 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7336 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7337 { "{ [NaN] }", "M", "{ : false }" },
7338 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7341 /* Perform basic isl_pw_aff_bind_id tests.
7343 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
7347 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
7353 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
7354 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
7355 res
= isl_pw_aff_bind_id(pa
, id
);
7356 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
7359 return isl_stat_error
;
7365 /* Inputs for isl_multi_union_pw_aff_bind tests.
7366 * "mupa" is the input expression.
7367 * "tuple" is the binding tuple.
7368 * "res" is the expected result.
7375 } bind_mupa_tests
[] = {
7376 { "A[{ [4] }, { [5] }]",
7378 "[M = 4, N = 5] -> { : }" },
7379 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7381 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7382 { "[M] -> A[{ [4] }, { [M + 1] }]",
7384 "[M = 4, N = 5] -> { : }" },
7387 /* Perform basic isl_multi_union_pw_aff_bind tests.
7389 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
7393 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
7395 isl_multi_union_pw_aff
*mupa
;
7397 isl_multi_id
*tuple
;
7400 str
= bind_mupa_tests
[i
].mupa
;
7401 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7402 str
= bind_mupa_tests
[i
].tuple
;
7403 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7404 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
7405 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
7406 isl_union_set_free(res
);
7408 return isl_stat_error
;
7414 /* Perform tests that reinterpret dimensions as parameters.
7416 static int test_bind(isl_ctx
*ctx
)
7418 if (test_bind_set(ctx
) < 0)
7420 if (test_bind_map_domain(ctx
) < 0)
7422 if (test_bind_umap_range(ctx
) < 0)
7424 if (test_bind_pma_domain(ctx
) < 0)
7426 if (test_bind_pma_domain_wrapped(ctx
) < 0)
7428 if (test_bind_aff(ctx
) < 0)
7430 if (test_bind_pa(ctx
) < 0)
7432 if (test_bind_mupa(ctx
) < 0)
7438 /* Inputs for isl_set_unbind_params tests.
7439 * "set" is the input parameter domain.
7440 * "tuple" is the tuple of the constructed set.
7441 * "res" is the expected result.
7447 } unbind_set_tests
[] = {
7448 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7450 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7451 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7453 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7454 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7456 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7457 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7459 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7462 /* Perform basic isl_set_unbind_params tests.
7464 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
7468 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
7471 isl_multi_id
*tuple
;
7474 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
7475 str
= unbind_set_tests
[i
].tuple
;
7476 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7477 set
= isl_set_unbind_params(set
, tuple
);
7478 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
7481 return isl_stat_error
;
7487 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7488 * "aff" is the input affine expression defined over a parameter domain.
7489 * "tuple" is the tuple of the domain that gets introduced.
7490 * "res" is the expected result.
7496 } unbind_aff_tests
[] = {
7497 { "[M, N] -> { [M + floor(N/2)] }",
7499 "{ A[M, N] -> [M + floor(N/2)] }" },
7500 { "[M, N] -> { [M + floor(N/2)] }",
7502 "{ B[N, M] -> [M + floor(N/2)] }" },
7503 { "[M, N] -> { [M + floor(N/2)] }",
7505 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7506 { "[M, N] -> { [M + floor(N/2)] }",
7507 "{ D[A, B, C, N, Z] }",
7508 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7511 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7513 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
7517 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
7520 isl_multi_id
*tuple
;
7523 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
7524 str
= unbind_aff_tests
[i
].tuple
;
7525 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7526 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
7527 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
7530 return isl_stat_error
;
7536 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7537 * "ma" is the input multi affine expression defined over a parameter domain.
7538 * "tuple" is the tuple of the domain that gets introduced.
7539 * "res" is the expected result.
7545 } unbind_multi_aff_tests
[] = {
7546 { "[M, N] -> { T[M + floor(N/2)] }",
7548 "{ A[M, N] -> T[M + floor(N/2)] }" },
7549 { "[M, N] -> { [M + floor(N/2)] }",
7551 "{ B[N, M] -> [M + floor(N/2)] }" },
7552 { "[M, N] -> { [M + floor(N/2)] }",
7554 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7555 { "[M, N] -> { [M + floor(N/2)] }",
7556 "{ D[A, B, C, N, Z] }",
7557 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7558 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7560 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7563 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7565 static isl_stat
test_unbind_multi_aff(isl_ctx
*ctx
)
7569 for (i
= 0; i
< ARRAY_SIZE(unbind_multi_aff_tests
); ++i
) {
7572 isl_multi_id
*tuple
;
7575 str
= unbind_multi_aff_tests
[i
].ma
;
7576 ma
= isl_multi_aff_read_from_str(ctx
, str
);
7577 str
= unbind_multi_aff_tests
[i
].tuple
;
7578 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7579 ma
= isl_multi_aff_unbind_params_insert_domain(ma
, tuple
);
7580 str
= unbind_multi_aff_tests
[i
].res
;
7581 r
= multi_aff_check_plain_equal(ma
, str
);
7582 isl_multi_aff_free(ma
);
7584 return isl_stat_error
;
7590 /* Perform tests that reinterpret parameters.
7592 static int test_unbind(isl_ctx
*ctx
)
7594 if (test_unbind_set(ctx
) < 0)
7596 if (test_unbind_aff(ctx
) < 0)
7598 if (test_unbind_multi_aff(ctx
) < 0)
7604 /* Check that "pa" consists of a single expression.
7606 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
7610 n
= isl_pw_aff_n_piece(pa
);
7611 isl_pw_aff_free(pa
);
7616 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
7622 /* Check that the computation below results in a single expression.
7623 * One or two expressions may result depending on which constraint
7624 * ends up being considered as redundant with respect to the other
7625 * constraints after the projection that is performed internally
7626 * by isl_set_dim_min.
7628 static int test_dim_max_1(isl_ctx
*ctx
)
7634 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7635 "-4a <= b <= 3 and b < n - 4a }";
7636 set
= isl_set_read_from_str(ctx
, str
);
7637 pa
= isl_set_dim_min(set
, 0);
7638 return check_single_piece(ctx
, pa
);
7641 /* Check that the computation below results in a single expression.
7642 * The PIP problem corresponding to these constraints has a row
7643 * that causes a split of the solution domain. The solver should
7644 * first pick rows that split off empty parts such that the actual
7645 * solution domain does not get split.
7646 * Note that the description contains some redundant constraints.
7647 * If these constraints get removed first, then the row mentioned
7648 * above does not appear in the PIP problem.
7650 static int test_dim_max_2(isl_ctx
*ctx
)
7656 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7657 "N > 0 and P >= 0 }";
7658 set
= isl_set_read_from_str(ctx
, str
);
7659 pa
= isl_set_dim_max(set
, 0);
7660 return check_single_piece(ctx
, pa
);
7663 int test_dim_max(isl_ctx
*ctx
)
7667 isl_set
*set1
, *set2
;
7672 if (test_dim_max_1(ctx
) < 0)
7674 if (test_dim_max_2(ctx
) < 0)
7677 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7678 set
= isl_set_read_from_str(ctx
, str
);
7679 pwaff
= isl_set_dim_max(set
, 0);
7680 set1
= isl_set_from_pw_aff(pwaff
);
7681 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7682 set2
= isl_set_read_from_str(ctx
, str
);
7683 equal
= isl_set_is_equal(set1
, set2
);
7689 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7691 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7692 set
= isl_set_read_from_str(ctx
, str
);
7693 pwaff
= isl_set_dim_max(set
, 0);
7694 set1
= isl_set_from_pw_aff(pwaff
);
7695 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7696 set2
= isl_set_read_from_str(ctx
, str
);
7697 equal
= isl_set_is_equal(set1
, set2
);
7703 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7705 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7706 set
= isl_set_read_from_str(ctx
, str
);
7707 pwaff
= isl_set_dim_max(set
, 0);
7708 set1
= isl_set_from_pw_aff(pwaff
);
7709 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7710 set2
= isl_set_read_from_str(ctx
, str
);
7711 equal
= isl_set_is_equal(set1
, set2
);
7717 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7719 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7720 "0 <= i < N and 0 <= j < M }";
7721 map
= isl_map_read_from_str(ctx
, str
);
7722 set
= isl_map_range(map
);
7724 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7725 set1
= isl_set_from_pw_aff(pwaff
);
7726 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7727 set2
= isl_set_read_from_str(ctx
, str
);
7728 equal
= isl_set_is_equal(set1
, set2
);
7732 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7733 set1
= isl_set_from_pw_aff(pwaff
);
7734 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7735 set2
= isl_set_read_from_str(ctx
, str
);
7736 if (equal
>= 0 && equal
)
7737 equal
= isl_set_is_equal(set1
, set2
);
7746 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7748 /* Check that solutions are properly merged. */
7749 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7750 "c <= -1 + n - 4a - 2b and c >= -2b and "
7751 "4a >= -4 + n and c >= 0 }";
7752 set
= isl_set_read_from_str(ctx
, str
);
7753 pwaff
= isl_set_dim_min(set
, 2);
7754 set1
= isl_set_from_pw_aff(pwaff
);
7755 str
= "[n] -> { [(0)] : n >= 1 }";
7756 set2
= isl_set_read_from_str(ctx
, str
);
7757 equal
= isl_set_is_equal(set1
, set2
);
7764 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7766 /* Check that empty solution lie in the right space. */
7767 str
= "[n] -> { [t,a] : 1 = 0 }";
7768 set
= isl_set_read_from_str(ctx
, str
);
7769 pwaff
= isl_set_dim_max(set
, 0);
7770 set1
= isl_set_from_pw_aff(pwaff
);
7771 str
= "[n] -> { [t] : 1 = 0 }";
7772 set2
= isl_set_read_from_str(ctx
, str
);
7773 equal
= isl_set_is_equal(set1
, set2
);
7780 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7785 /* Basic test for isl_pw_multi_aff_product.
7787 * Check that multiple pieces are properly handled.
7789 static int test_product_pma(isl_ctx
*ctx
)
7793 isl_pw_multi_aff
*pma1
, *pma2
;
7795 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7796 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7797 str
= "{ C[] -> D[] }";
7798 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7799 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7800 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7801 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7802 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7803 isl_pw_multi_aff_free(pma1
);
7810 int test_product(isl_ctx
*ctx
)
7814 isl_union_set
*uset1
, *uset2
;
7818 set
= isl_set_read_from_str(ctx
, str
);
7819 set
= isl_set_product(set
, isl_set_copy(set
));
7820 ok
= isl_set_is_wrapping(set
);
7825 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7828 uset1
= isl_union_set_read_from_str(ctx
, str
);
7829 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7830 str
= "{ [[] -> []] }";
7831 uset2
= isl_union_set_read_from_str(ctx
, str
);
7832 ok
= isl_union_set_is_equal(uset1
, uset2
);
7833 isl_union_set_free(uset1
);
7834 isl_union_set_free(uset2
);
7838 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7840 if (test_product_pma(ctx
) < 0)
7846 /* Check that two sets are not considered disjoint just because
7847 * they have a different set of (named) parameters.
7849 static int test_disjoint(isl_ctx
*ctx
)
7852 isl_set
*set
, *set2
;
7855 str
= "[n] -> { [[]->[]] }";
7856 set
= isl_set_read_from_str(ctx
, str
);
7857 str
= "{ [[]->[]] }";
7858 set2
= isl_set_read_from_str(ctx
, str
);
7859 disjoint
= isl_set_is_disjoint(set
, set2
);
7865 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7870 /* Inputs for isl_pw_multi_aff_is_equal tests.
7871 * "f1" and "f2" are the two function that need to be compared.
7872 * "equal" is the expected result.
7878 } pma_equal_tests
[] = {
7879 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7880 "[N] -> { [0] : 0 <= N <= 1 }" },
7881 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7882 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7883 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7884 "[N] -> { [0] : 0 <= N <= 1 }" },
7885 { 0, "{ [NaN] }", "{ [NaN] }" },
7888 int test_equal(isl_ctx
*ctx
)
7892 isl_set
*set
, *set2
;
7896 set
= isl_set_read_from_str(ctx
, str
);
7898 set2
= isl_set_read_from_str(ctx
, str
);
7899 equal
= isl_set_is_equal(set
, set2
);
7905 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7907 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7908 int expected
= pma_equal_tests
[i
].equal
;
7909 isl_pw_multi_aff
*f1
, *f2
;
7911 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7912 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7913 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7914 isl_pw_multi_aff_free(f1
);
7915 isl_pw_multi_aff_free(f2
);
7918 if (equal
!= expected
)
7919 isl_die(ctx
, isl_error_unknown
,
7920 "unexpected equality result", return -1);
7926 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7927 enum isl_dim_type type
, unsigned pos
, int fixed
)
7931 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7938 isl_die(ctx
, isl_error_unknown
,
7939 "map not detected as fixed", return -1);
7941 isl_die(ctx
, isl_error_unknown
,
7942 "map detected as fixed", return -1);
7945 int test_fixed(isl_ctx
*ctx
)
7950 str
= "{ [i] -> [i] }";
7951 map
= isl_map_read_from_str(ctx
, str
);
7952 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7954 str
= "{ [i] -> [1] }";
7955 map
= isl_map_read_from_str(ctx
, str
);
7956 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7958 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7959 map
= isl_map_read_from_str(ctx
, str
);
7960 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7962 map
= isl_map_read_from_str(ctx
, str
);
7963 map
= isl_map_neg(map
);
7964 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7970 struct isl_vertices_test_data
{
7973 const char *vertex
[6];
7974 } vertices_tests
[] = {
7975 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7976 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7977 { "{ A[t, i] : t = 14 and i = 1 }",
7978 1, { "{ A[14, 1] }" } },
7979 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7980 "c <= m and m <= n and m > 0 }",
7982 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7983 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7984 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7985 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7986 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7987 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7989 /* An input with implicit equality constraints among the parameters. */
7990 { "[N, M] -> { [a, b] : M >= 3 and 9 + 3M <= a <= 29 + 2N + 11M and "
7991 "2b >= M + a and 5 - 2N - M + a <= 2b <= 3 + a and "
7994 "[N, M] -> { [(21), (12)] : M = 3 and N >= 0 }",
7995 "[N, M] -> { [(61 + 2N), (32 + N)] : M = 3 and N >= 0 }",
8000 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
8002 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
8004 struct isl_vertices_test_data
*data
= user
;
8007 isl_basic_set
*bset
;
8008 isl_pw_multi_aff
*pma
;
8012 ctx
= isl_vertex_get_ctx(vertex
);
8013 bset
= isl_vertex_get_domain(vertex
);
8014 ma
= isl_vertex_get_expr(vertex
);
8015 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
8017 for (i
= 0; i
< data
->n
; ++i
) {
8018 isl_pw_multi_aff
*pma_i
;
8020 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
8021 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
8022 isl_pw_multi_aff_free(pma_i
);
8024 if (equal
< 0 || equal
)
8028 isl_pw_multi_aff_free(pma
);
8029 isl_vertex_free(vertex
);
8032 return isl_stat_error
;
8034 return equal
? isl_stat_ok
: isl_stat_error
;
8037 int test_vertices(isl_ctx
*ctx
)
8041 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
8042 isl_basic_set
*bset
;
8043 isl_vertices
*vertices
;
8047 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
8048 vertices
= isl_basic_set_compute_vertices(bset
);
8049 n
= isl_vertices_get_n_vertices(vertices
);
8050 if (vertices_tests
[i
].n
!= n
)
8052 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
8053 &vertices_tests
[i
]) < 0)
8055 isl_vertices_free(vertices
);
8056 isl_basic_set_free(bset
);
8061 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
8068 /* Inputs for basic tests of binary operations on isl_union_map.
8069 * "fn" is the function that is being tested.
8070 * "arg1" and "arg2" are string descriptions of the inputs.
8071 * "res" is a string description of the expected result.
8074 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap1
,
8075 __isl_take isl_union_map
*umap2
);
8079 } umap_bin_tests
[] = {
8080 { &isl_union_map_intersect
,
8081 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
8082 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
8083 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
8084 { &isl_union_map_intersect_domain_factor_domain
,
8085 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8086 "[N] -> { B[i] -> C[N] }",
8088 { &isl_union_map_intersect_domain_factor_domain
,
8089 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8090 "[N] -> { A[i] -> C[N] }",
8091 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8092 { &isl_union_map_intersect_domain_factor_domain
,
8093 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8094 "[N] -> { A[i] -> C[N] }",
8095 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8096 { &isl_union_map_intersect_domain_factor_range
,
8097 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8098 "[N] -> { B[i] -> C[N] }",
8099 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8100 { &isl_union_map_intersect_domain_factor_range
,
8101 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8102 "[N] -> { B[i] -> C[N] }",
8103 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8104 { &isl_union_map_intersect_domain_factor_range
,
8105 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8106 "[N] -> { A[i] -> C[N] }",
8108 { &isl_union_map_intersect_range_factor_domain
,
8109 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8110 "[N] -> { A[i] -> B[N] }",
8111 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
8112 { &isl_union_map_intersect_range_factor_domain
,
8113 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8114 "[N] -> { A[i] -> B[N] }",
8115 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
8116 { &isl_union_map_intersect_range_factor_domain
,
8117 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8118 "[N] -> { A[i] -> C[N] }",
8120 { &isl_union_map_intersect_range_factor_range
,
8121 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8122 "[N] -> { A[i] -> C[N] }",
8123 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
8124 { &isl_union_map_intersect_range_factor_range
,
8125 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8126 "[N] -> { A[i] -> C[N] }",
8127 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
8128 { &isl_union_map_intersect_range_factor_range
,
8129 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8130 "[N] -> { A[i] -> B[N] }",
8134 /* Perform basic tests of binary operations on isl_union_map.
8136 static isl_stat
test_bin_union_map(isl_ctx
*ctx
)
8140 for (i
= 0; i
< ARRAY_SIZE(umap_bin_tests
); ++i
) {
8142 isl_union_map
*umap1
, *umap2
, *res
;
8145 str
= umap_bin_tests
[i
].arg1
;
8146 umap1
= isl_union_map_read_from_str(ctx
, str
);
8147 str
= umap_bin_tests
[i
].arg2
;
8148 umap2
= isl_union_map_read_from_str(ctx
, str
);
8149 str
= umap_bin_tests
[i
].res
;
8150 res
= isl_union_map_read_from_str(ctx
, str
);
8151 umap1
= umap_bin_tests
[i
].fn(umap1
, umap2
);
8152 equal
= isl_union_map_is_equal(umap1
, res
);
8153 isl_union_map_free(umap1
);
8154 isl_union_map_free(res
);
8156 return isl_stat_error
;
8158 isl_die(ctx
, isl_error_unknown
,
8159 "unexpected result", return isl_stat_error
);
8165 /* Check that isl_union_set_contains finds space independently
8166 * of the parameters.
8168 static isl_stat
test_union_set_contains(isl_ctx
*ctx
)
8174 isl_union_set
*uset
;
8176 str
= "[N] -> { A[0:N]; B[*,*] }";
8177 uset
= isl_union_set_read_from_str(ctx
, str
);
8178 space
= isl_space_unit(ctx
);
8179 id
= isl_id_alloc(ctx
, "A", NULL
);
8180 space
= isl_space_add_named_tuple_id_ui(space
, id
, 1);
8181 ok
= isl_union_set_contains(uset
, space
);
8182 isl_space_free(space
);
8183 isl_union_set_free(uset
);
8186 return isl_stat_error
;
8188 isl_die(ctx
, isl_error_unknown
,
8189 "unexpected result", return isl_stat_error
);
8194 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8196 static int test_union_map(isl_ctx
*ctx
)
8198 if (test_bin_union_map(ctx
) < 0)
8200 if (test_union_set_contains(ctx
) < 0)
8206 #define BASE union_pw_qpolynomial
8207 #include "isl_test_plain_equal_templ.c"
8209 /* Check that the result of applying "fn" to "a" and "b"
8210 * in (obviously) equal to "res".
8212 static isl_stat
test_union_pw_op(isl_ctx
*ctx
, const char *a
, const char *b
,
8213 __isl_give isl_union_pw_qpolynomial
*(*fn
)(
8214 __isl_take isl_union_pw_qpolynomial
*upwqp1
,
8215 __isl_take isl_union_pw_qpolynomial
*upwqp2
),
8219 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8221 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, a
);
8222 upwqp2
= isl_union_pw_qpolynomial_read_from_str(ctx
, b
);
8223 upwqp1
= fn(upwqp1
, upwqp2
);
8224 r
= union_pw_qpolynomial_check_plain_equal(upwqp1
, res
);
8225 isl_union_pw_qpolynomial_free(upwqp1
);
8230 int test_union_pw(isl_ctx
*ctx
)
8235 isl_union_set
*uset
;
8236 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8239 str
= "{ [x] -> x^2 }";
8240 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8241 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
8242 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
8243 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
8244 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
8245 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
8246 isl_union_pw_qpolynomial_free(upwqp1
);
8247 isl_union_pw_qpolynomial_free(upwqp2
);
8251 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8253 a
= "{ A[x] -> x^2 : x >= 0; B[x] -> x }";
8254 b
= "{ A[x] -> x }";
8255 str
= "{ A[x] -> x^2 + x : x >= 0; A[x] -> x : x < 0; B[x] -> x }";
8256 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_add
, str
) < 0)
8258 str
= "{ A[x] -> x^2 - x : x >= 0; A[x] -> -x : x < 0; B[x] -> x }";
8259 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_sub
, str
) < 0)
8262 str
= "{ A[x] -> 0 }";
8263 a
= "{ A[x] -> 1 }";
8264 b
= "{ A[x] -> -1 }";
8265 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_add
, str
) < 0)
8267 a
= "{ A[x] -> 1 }";
8268 b
= "{ A[x] -> 1 }";
8269 if (test_union_pw_op(ctx
, a
, b
, &isl_union_pw_qpolynomial_sub
, str
) < 0)
8272 str
= "{ [A[x] -> B[y,z]] -> x^2 + y * floor(x/4) * floor(z/2); "
8274 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8275 upwqp1
= isl_union_pw_qpolynomial_domain_reverse(upwqp1
);
8276 str
= "{ [B[y,z] -> A[x]] -> x^2 + y * floor(x/4) * floor(z/2) }";
8277 r
= union_pw_qpolynomial_check_plain_equal(upwqp1
, str
);
8278 isl_union_pw_qpolynomial_free(upwqp1
);
8285 /* Inputs for basic tests of functions that select
8286 * subparts of the domain of an isl_multi_union_pw_aff.
8287 * "fn" is the function that is tested.
8288 * "arg" is a string description of the input.
8289 * "res" is a string description of the expected result.
8292 __isl_give isl_union_set
*(*fn
)(
8293 __isl_take isl_multi_union_pw_aff
*mupa
);
8296 } un_locus_tests
[] = {
8297 { &isl_multi_union_pw_aff_zero_union_set
,
8298 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8299 "{ A[0,j]; B[0,j] }" },
8300 { &isl_multi_union_pw_aff_zero_union_set
,
8301 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8302 "{ A[i,i]; B[i,i] : i >= 0 }" },
8303 { &isl_multi_union_pw_aff_zero_union_set
,
8304 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8305 "{ A[i,j]; B[i,i] : i >= 0 }" },
8308 /* Perform some basic tests of functions that select
8309 * subparts of the domain of an isl_multi_union_pw_aff.
8311 static int test_un_locus(isl_ctx
*ctx
)
8315 isl_union_set
*uset
, *res
;
8316 isl_multi_union_pw_aff
*mupa
;
8318 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
8319 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8320 un_locus_tests
[i
].arg
);
8321 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
8322 uset
= un_locus_tests
[i
].fn(mupa
);
8323 ok
= isl_union_set_is_equal(uset
, res
);
8324 isl_union_set_free(uset
);
8325 isl_union_set_free(res
);
8329 isl_die(ctx
, isl_error_unknown
,
8330 "unexpected result", return -1);
8336 /* Inputs for basic tests of functions that select
8337 * subparts of an isl_union_map based on a relation
8338 * specified by an isl_multi_union_pw_aff.
8339 * "fn" is the function that is tested.
8340 * "arg1" and "arg2" are string descriptions of the inputs.
8341 * "res" is a string description of the expected result.
8344 __isl_give isl_union_map
*(*fn
)(
8345 __isl_take isl_union_map
*umap
,
8346 __isl_take isl_multi_union_pw_aff
*mupa
);
8350 } bin_locus_tests
[] = {
8351 { &isl_union_map_eq_at_multi_union_pw_aff
,
8352 "{ A[i,j] -> B[i',j'] }",
8353 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8354 "{ A[i,j] -> B[i,j'] }" },
8355 { &isl_union_map_eq_at_multi_union_pw_aff
,
8356 "{ A[i,j] -> B[i',j'] }",
8357 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8358 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8359 "{ A[i,j] -> B[i,j] }" },
8360 { &isl_union_map_eq_at_multi_union_pw_aff
,
8361 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8362 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8363 "{ A[i,j] -> B[i,j'] }" },
8364 { &isl_union_map_eq_at_multi_union_pw_aff
,
8365 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8366 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8367 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8368 { &isl_union_map_eq_at_multi_union_pw_aff
,
8369 "{ A[i,j] -> B[i',j'] }",
8370 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8371 "{ A[i,j] -> B[i,j'] : i > j }" },
8372 { &isl_union_map_lex_le_at_multi_union_pw_aff
,
8373 "{ A[i,j] -> B[i',j'] }",
8374 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8375 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8376 "{ A[i,j] -> B[i',j'] : i,j <<= i',j' }" },
8377 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
8378 "{ A[i,j] -> B[i',j'] }",
8379 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8380 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8381 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8382 { &isl_union_map_lex_ge_at_multi_union_pw_aff
,
8383 "{ A[i,j] -> B[i',j'] }",
8384 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8385 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8386 "{ A[i,j] -> B[i',j'] : i,j >>= i',j' }" },
8387 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
8388 "{ A[i,j] -> B[i',j'] }",
8389 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8390 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8391 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8392 { &isl_union_map_eq_at_multi_union_pw_aff
,
8393 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8394 "(F[] : { A[i,j]; B[i,j] })",
8395 "{ A[i,j] -> B[i',j'] }" },
8396 { &isl_union_map_eq_at_multi_union_pw_aff
,
8397 "{ A[i,j] -> B[i',j'] }",
8398 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8399 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8400 { &isl_union_map_eq_at_multi_union_pw_aff
,
8401 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8402 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8403 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8404 { &isl_union_map_eq_at_multi_union_pw_aff
,
8405 "{ A[i,j] -> B[i',j'] }",
8406 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8407 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8408 { &isl_union_map_eq_at_multi_union_pw_aff
,
8409 "{ A[i,j] -> B[i',j'] }",
8410 "[N] -> (F[] : { : N >= 0 })",
8411 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8414 /* Perform some basic tests of functions that select
8415 * subparts of an isl_union_map based on a relation
8416 * specified by an isl_multi_union_pw_aff.
8418 static int test_bin_locus(isl_ctx
*ctx
)
8422 isl_union_map
*umap
, *res
;
8423 isl_multi_union_pw_aff
*mupa
;
8425 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
8426 umap
= isl_union_map_read_from_str(ctx
,
8427 bin_locus_tests
[i
].arg1
);
8428 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8429 bin_locus_tests
[i
].arg2
);
8430 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
8431 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
8432 ok
= isl_union_map_is_equal(umap
, res
);
8433 isl_union_map_free(umap
);
8434 isl_union_map_free(res
);
8438 isl_die(ctx
, isl_error_unknown
,
8439 "unexpected result", return -1);
8445 /* Inputs for basic tests of functions that determine
8446 * the part of the domain where two isl_multi_aff objects
8447 * related to each other in a specific way.
8448 * "fn" is the function that is being tested.
8449 * "arg1" and "arg2" are string descriptions of the inputs.
8450 * "res" is a string description of the expected result.
8453 __isl_give isl_set
*(*fn
)(__isl_take isl_multi_aff
*ma1
,
8454 __isl_take isl_multi_aff
*ma2
);
8458 } bin_locus_ma_tests
[] = {
8459 { &isl_multi_aff_lex_le_set
, "{ [] }", "{ [] }", "{ : }" },
8460 { &isl_multi_aff_lex_lt_set
, "{ [] }", "{ [] }", "{ : false }" },
8461 { &isl_multi_aff_lex_le_set
,
8462 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8463 "{ A[i] : i <= 0 }" },
8464 { &isl_multi_aff_lex_lt_set
,
8465 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8466 "{ A[i] : i < 0 }" },
8467 { &isl_multi_aff_lex_le_set
,
8468 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8469 "{ A[i] : i <= 0 }" },
8470 { &isl_multi_aff_lex_le_set
,
8471 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8472 "{ A[i] : i <= 0 }" },
8473 { &isl_multi_aff_lex_le_set
,
8474 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8475 "{ A[i] : i < 0 }" },
8478 /* Perform some basic tests of functions that determine
8479 * the part of the domain where two isl_multi_aff objects
8480 * related to each other in a specific way.
8482 static isl_stat
test_bin_locus_ma(isl_ctx
*ctx
)
8486 for (i
= 0; i
< ARRAY_SIZE(bin_locus_ma_tests
); ++i
) {
8489 isl_multi_aff
*ma1
, *ma2
;
8492 str
= bin_locus_ma_tests
[i
].arg1
;
8493 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8494 str
= bin_locus_ma_tests
[i
].arg2
;
8495 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8496 res
= isl_set_read_from_str(ctx
, bin_locus_ma_tests
[i
].res
);
8497 set
= bin_locus_ma_tests
[i
].fn(ma1
, ma2
);
8498 ok
= isl_set_is_equal(set
, res
);
8502 return isl_stat_error
;
8504 isl_die(ctx
, isl_error_unknown
,
8505 "unexpected result", return isl_stat_error
);
8511 /* Perform basic locus tests.
8513 static int test_locus(isl_ctx
*ctx
)
8515 if (test_un_locus(ctx
) < 0)
8517 if (test_bin_locus(ctx
) < 0)
8519 if (test_bin_locus_ma(ctx
) < 0)
8524 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8525 * defined over the correct domain space.
8527 static int test_eval_1(isl_ctx
*ctx
)
8532 isl_union_pw_qpolynomial
*upwqp
;
8536 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
8537 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8539 set
= isl_set_read_from_str(ctx
, str
);
8540 pnt
= isl_set_sample_point(set
);
8541 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
8542 cmp
= isl_val_cmp_si(v
, 36);
8548 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
8553 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8555 static int test_eval_2(isl_ctx
*ctx
)
8560 isl_qpolynomial
*qp
;
8564 str
= "{ A[x] -> [x] }";
8565 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
8566 str
= "{ A[x] : false }";
8567 set
= isl_set_read_from_str(ctx
, str
);
8568 pnt
= isl_set_sample_point(set
);
8569 v
= isl_qpolynomial_eval(qp
, pnt
);
8570 ok
= isl_val_is_nan(v
);
8576 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
8581 /* Check that a polynomial (without local variables) can be evaluated
8582 * in a rational point.
8584 static isl_stat
test_eval_3(isl_ctx
*ctx
)
8586 isl_pw_qpolynomial
*pwqp
;
8591 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
8592 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
8593 v
= isl_val_read_from_str(ctx
, "1/2");
8594 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
8595 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
8596 r
= val_check_equal(v
, "1/4");
8602 /* Inputs for isl_pw_aff_eval test.
8603 * "f" is the affine function.
8604 * "p" is the point where the function should be evaluated.
8605 * "res" is the expected result.
8611 } aff_eval_tests
[] = {
8612 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8613 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8614 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8615 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8616 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8617 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8618 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8619 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8620 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8621 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8622 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8623 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8624 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8625 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8626 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8627 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8628 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8629 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8630 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8631 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8632 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8633 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8634 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8635 { "[m, n] -> { [2m + 3n] }", "[n=1, m=10] -> { : }", "23" },
8638 /* Perform basic isl_pw_aff_eval tests.
8640 static int test_eval_aff(isl_ctx
*ctx
)
8644 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
8651 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
8652 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
8653 pnt
= isl_set_sample_point(set
);
8654 v
= isl_pw_aff_eval(pa
, pnt
);
8655 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
8663 /* Perform basic evaluation tests.
8665 static int test_eval(isl_ctx
*ctx
)
8667 if (test_eval_1(ctx
) < 0)
8669 if (test_eval_2(ctx
) < 0)
8671 if (test_eval_3(ctx
) < 0)
8673 if (test_eval_aff(ctx
) < 0)
8678 /* Descriptions of sets that are tested for reparsing after printing.
8680 const char *output_tests
[] = {
8681 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8684 "{ [x] : x mod 2 = 0 }",
8685 "{ [x] : x mod 2 = 1 }",
8686 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8687 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8688 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8689 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8690 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8691 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8694 /* Check that printing a set and reparsing a set from the printed output
8695 * results in the same set.
8697 static int test_output_set(isl_ctx
*ctx
)
8701 isl_set
*set1
, *set2
;
8704 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
8705 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
8706 str
= isl_set_to_str(set1
);
8707 set2
= isl_set_read_from_str(ctx
, str
);
8709 equal
= isl_set_is_equal(set1
, set2
);
8715 isl_die(ctx
, isl_error_unknown
,
8716 "parsed output not the same", return -1);
8722 /* Check that an isl_multi_aff is printed using a consistent space.
8724 static isl_stat
test_output_ma(isl_ctx
*ctx
)
8729 isl_multi_aff
*ma
, *ma2
;
8731 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8732 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8733 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
8734 str
= isl_multi_aff_to_str(ma
);
8735 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8737 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
8738 isl_multi_aff_free(ma2
);
8739 isl_multi_aff_free(ma
);
8742 return isl_stat_error
;
8744 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8745 return isl_stat_error
);
8750 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8752 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
8757 isl_multi_pw_aff
*mpa
, *mpa2
;
8759 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8760 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8761 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
8762 str
= isl_multi_pw_aff_to_str(mpa
);
8763 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8765 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8766 isl_multi_pw_aff_free(mpa2
);
8767 isl_multi_pw_aff_free(mpa
);
8770 return isl_stat_error
;
8772 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8773 return isl_stat_error
);
8778 int test_output(isl_ctx
*ctx
)
8786 if (test_output_set(ctx
) < 0)
8788 if (test_output_ma(ctx
) < 0)
8790 if (test_output_mpa(ctx
) < 0)
8793 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8794 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8796 p
= isl_printer_to_str(ctx
);
8797 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
8798 p
= isl_printer_print_pw_aff(p
, pa
);
8799 s
= isl_printer_get_str(p
);
8800 isl_printer_free(p
);
8801 isl_pw_aff_free(pa
);
8805 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8810 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8815 int test_sample(isl_ctx
*ctx
)
8818 isl_basic_set
*bset1
, *bset2
;
8821 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8822 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8823 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8824 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8825 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8826 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8827 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8828 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8829 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8830 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8831 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8832 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8833 "d - 1073741821e and "
8834 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8835 "3j >= 1 - a + b + 2e and "
8836 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8837 "3i <= 4 - a + 4b - e and "
8838 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8839 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8840 "c <= -1 + a and 3i >= -2 - a + 3e and "
8841 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8842 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8843 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8844 "1073741823e >= 1 + 1073741823b - d and "
8845 "3i >= 1073741823b + c - 1073741823e - f and "
8846 "3i >= 1 + 2b + e + 3g }";
8847 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8848 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
8849 empty
= isl_basic_set_is_empty(bset2
);
8850 subset
= isl_basic_set_is_subset(bset2
, bset1
);
8851 isl_basic_set_free(bset1
);
8852 isl_basic_set_free(bset2
);
8853 if (empty
< 0 || subset
< 0)
8856 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
8858 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
8863 /* Perform a projection on a basic set that is known to be empty
8864 * but that has not been assigned a canonical representation.
8865 * Earlier versions of isl would run into a stack overflow
8868 static int test_empty_projection(isl_ctx
*ctx
)
8872 isl_basic_set
*bset
;
8874 str
= "{ [a, b, c, d, e, f, g, h] : 5f = 1 + 4a - b + 5c - d - 2e and "
8875 "3h = 2 + b + c and 14c >= 9 - 3a + 25b and "
8876 "4c <= 50 - 3a + 23b and 6b <= -39 + a and "
8877 "9g >= -6 + 3a + b + c and e < a + b - 2d and "
8878 "7d >= -5 + 2a + 2b and 5g >= -14 + a - 4b + d + 2e and "
8879 "9g <= -28 - 5b - 2c + 3d + 6e }";
8880 bset
= isl_basic_set_read_from_str(ctx
, str
);
8881 empty
= isl_basic_set_is_empty(bset
);
8882 bset
= isl_basic_set_params(bset
);
8883 isl_basic_set_free(bset
);
8891 int test_slice(isl_ctx
*ctx
)
8897 str
= "{ [i] -> [j] }";
8898 map
= isl_map_read_from_str(ctx
, str
);
8899 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8900 equal
= map_check_equal(map
, "{ [i] -> [i] }");
8905 str
= "{ [i] -> [j] }";
8906 map
= isl_map_read_from_str(ctx
, str
);
8907 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8908 equal
= map_check_equal(map
, "{ [i] -> [j] }");
8913 str
= "{ [i] -> [j] }";
8914 map
= isl_map_read_from_str(ctx
, str
);
8915 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8916 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8921 str
= "{ [i] -> [j] }";
8922 map
= isl_map_read_from_str(ctx
, str
);
8923 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8924 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8929 str
= "{ [i] -> [j] }";
8930 map
= isl_map_read_from_str(ctx
, str
);
8931 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8932 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8937 str
= "{ [i] -> [j] }";
8938 map
= isl_map_read_from_str(ctx
, str
);
8939 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8940 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8948 int test_eliminate(isl_ctx
*ctx
)
8954 str
= "{ [i] -> [j] : i = 2j }";
8955 map
= isl_map_read_from_str(ctx
, str
);
8956 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8957 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8965 /* Check basic functionality of isl_map_deltas_map.
8967 static int test_deltas_map(isl_ctx
*ctx
)
8973 str
= "{ A[i] -> A[i + 1] }";
8974 map
= isl_map_read_from_str(ctx
, str
);
8975 map
= isl_map_deltas_map(map
);
8976 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8984 /* Check that isl_set_dim_residue_class detects that the values of j
8985 * in the set below are all odd and that it does not detect any spurious
8988 static int test_residue_class(isl_ctx
*ctx
)
8995 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8996 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8997 set
= isl_set_read_from_str(ctx
, str
);
9000 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
9002 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
9003 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
9004 res
= isl_stat_error
);
9012 static int test_align_parameters_1(isl_ctx
*ctx
)
9016 isl_multi_aff
*ma1
, *ma2
;
9019 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
9020 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
9022 space
= isl_space_params_alloc(ctx
, 1);
9023 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
9024 ma1
= isl_multi_aff_align_params(ma1
, space
);
9026 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
9027 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
9029 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9031 isl_multi_aff_free(ma1
);
9032 isl_multi_aff_free(ma2
);
9037 isl_die(ctx
, isl_error_unknown
,
9038 "result not as expected", return -1);
9043 /* Check the isl_multi_*_from_*_list operation in case inputs
9044 * have unaligned parameters.
9045 * In particular, older versions of isl would simply fail
9046 * (without printing any error message).
9048 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
9055 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
9056 space
= isl_map_get_space(map
);
9059 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
9060 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
9061 isl_multi_aff_free(ma
);
9064 return isl_stat_error
;
9068 /* Perform basic parameter alignment tests.
9070 static int test_align_parameters(isl_ctx
*ctx
)
9072 if (test_align_parameters_1(ctx
) < 0)
9074 if (test_align_parameters_2(ctx
) < 0)
9080 /* Check that isl_*_drop_unused_params actually drops the unused parameters
9081 * by comparing the result using isl_*_plain_is_equal.
9082 * Note that this assumes that isl_*_plain_is_equal does not consider
9083 * objects that only differ by unused parameters to be equal.
9085 int test_drop_unused_parameters(isl_ctx
*ctx
)
9087 const char *str_with
, *str_without
;
9088 isl_basic_set
*bset1
, *bset2
;
9089 isl_set
*set1
, *set2
;
9090 isl_pw_aff
*pwa1
, *pwa2
;
9093 str_with
= "[n, m, o] -> { [m] }";
9094 str_without
= "[m] -> { [m] }";
9096 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
9097 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
9098 bset1
= isl_basic_set_drop_unused_params(bset1
);
9099 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
9100 isl_basic_set_free(bset1
);
9101 isl_basic_set_free(bset2
);
9106 isl_die(ctx
, isl_error_unknown
,
9107 "result not as expected", return -1);
9109 set1
= isl_set_read_from_str(ctx
, str_with
);
9110 set2
= isl_set_read_from_str(ctx
, str_without
);
9111 set1
= isl_set_drop_unused_params(set1
);
9112 equal
= isl_set_plain_is_equal(set1
, set2
);
9119 isl_die(ctx
, isl_error_unknown
,
9120 "result not as expected", return -1);
9122 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
9123 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
9124 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
9125 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
9126 isl_pw_aff_free(pwa1
);
9127 isl_pw_aff_free(pwa2
);
9132 isl_die(ctx
, isl_error_unknown
,
9133 "result not as expected", return -1);
9138 static int test_list(isl_ctx
*ctx
)
9140 isl_id
*a
, *b
, *c
, *d
, *id
;
9145 a
= isl_id_alloc(ctx
, "a", NULL
);
9146 b
= isl_id_alloc(ctx
, "b", NULL
);
9147 c
= isl_id_alloc(ctx
, "c", NULL
);
9148 d
= isl_id_alloc(ctx
, "d", NULL
);
9150 list
= isl_id_list_alloc(ctx
, 4);
9151 list
= isl_id_list_add(list
, b
);
9152 list
= isl_id_list_insert(list
, 0, a
);
9153 list
= isl_id_list_add(list
, c
);
9154 list
= isl_id_list_add(list
, d
);
9155 list
= isl_id_list_drop(list
, 1, 1);
9157 n
= isl_id_list_n_id(list
);
9161 isl_id_list_free(list
);
9162 isl_die(ctx
, isl_error_unknown
,
9163 "unexpected number of elements in list", return -1);
9166 id
= isl_id_list_get_id(list
, 0);
9169 id
= isl_id_list_get_id(list
, 1);
9172 id
= isl_id_list_get_id(list
, 2);
9176 isl_id_list_free(list
);
9179 isl_die(ctx
, isl_error_unknown
,
9180 "unexpected elements in list", return -1);
9185 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
9187 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
9192 isl_basic_set
*bset1
, *bset2
;
9194 str
= "[N] -> { A[0, N + 1] }";
9195 ma
= isl_multi_aff_read_from_str(ctx
, str
);
9196 bset1
= isl_basic_set_read_from_str(ctx
, str
);
9197 bset2
= isl_basic_set_from_multi_aff(ma
);
9198 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9199 isl_basic_set_free(bset1
);
9200 isl_basic_set_free(bset2
);
9202 return isl_stat_error
;
9204 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9205 return isl_stat_error
);
9209 const char *set_conversion_tests
[] = {
9210 "[N] -> { [i] : N - 1 <= 2 i <= N }",
9211 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
9212 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9213 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9214 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
9215 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
9216 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9217 "-3 + c <= d <= 28 + c) }",
9220 /* Check that converting from isl_set to isl_pw_multi_aff and back
9221 * to isl_set produces the original isl_set.
9223 static int test_set_conversion(isl_ctx
*ctx
)
9227 isl_set
*set1
, *set2
;
9228 isl_pw_multi_aff
*pma
;
9231 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
9232 str
= set_conversion_tests
[i
];
9233 set1
= isl_set_read_from_str(ctx
, str
);
9234 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
9235 set2
= isl_set_from_pw_multi_aff(pma
);
9236 equal
= isl_set_is_equal(set1
, set2
);
9243 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9250 const char *conversion_tests
[] = {
9251 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9252 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9253 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9254 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9256 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9257 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9258 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9261 /* Check that converting from isl_map to isl_pw_multi_aff and back
9262 * to isl_map produces the original isl_map.
9264 static int test_map_conversion(isl_ctx
*ctx
)
9267 isl_map
*map1
, *map2
;
9268 isl_pw_multi_aff
*pma
;
9271 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
9272 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
9273 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
9274 map2
= isl_map_from_pw_multi_aff(pma
);
9275 equal
= isl_map_is_equal(map1
, map2
);
9282 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9289 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9290 * to isl_multi_pw_aff and back.
9292 const char *mpa_conversion_tests
[] = {
9294 "{ [x] -> A[x] : x >= 0 }",
9295 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9296 "{ [x] -> A[x, x + 1] }",
9298 "{ [x] -> A[] : x >= 0 }",
9301 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9302 * back to isl_pw_multi_aff preserves the original meaning.
9304 static int test_mpa_conversion(isl_ctx
*ctx
)
9307 isl_pw_multi_aff
*pma1
, *pma2
;
9308 isl_multi_pw_aff
*mpa
;
9311 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
9313 str
= mpa_conversion_tests
[i
];
9314 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9315 pma2
= isl_pw_multi_aff_copy(pma1
);
9316 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
9317 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
9318 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9319 isl_pw_multi_aff_free(pma1
);
9320 isl_pw_multi_aff_free(pma2
);
9325 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9332 /* Descriptions of union maps that should be convertible
9333 * to an isl_multi_union_pw_aff.
9335 const char *umap_mupa_conversion_tests
[] = {
9336 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9337 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9338 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9339 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9341 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9342 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9343 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9344 "{ A[] -> B[0]; C[] -> B[1] }",
9345 "{ A[] -> B[]; C[] -> B[] }",
9348 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9349 * to isl_union_map produces the original isl_union_map.
9351 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
9354 isl_union_map
*umap1
, *umap2
;
9355 isl_multi_union_pw_aff
*mupa
;
9358 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
9360 str
= umap_mupa_conversion_tests
[i
];
9361 umap1
= isl_union_map_read_from_str(ctx
, str
);
9362 umap2
= isl_union_map_copy(umap1
);
9363 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
9364 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
9365 equal
= isl_union_map_is_equal(umap1
, umap2
);
9366 isl_union_map_free(umap1
);
9367 isl_union_map_free(umap2
);
9372 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9379 static int test_conversion(isl_ctx
*ctx
)
9381 if (test_ma_conversion(ctx
) < 0)
9383 if (test_set_conversion(ctx
) < 0)
9385 if (test_map_conversion(ctx
) < 0)
9387 if (test_mpa_conversion(ctx
) < 0)
9389 if (test_union_map_mupa_conversion(ctx
) < 0)
9394 /* Check that isl_basic_map_curry does not modify input.
9396 static int test_curry(isl_ctx
*ctx
)
9399 isl_basic_map
*bmap1
, *bmap2
;
9402 str
= "{ [A[] -> B[]] -> C[] }";
9403 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
9404 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
9405 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
9406 isl_basic_map_free(bmap1
);
9407 isl_basic_map_free(bmap2
);
9412 isl_die(ctx
, isl_error_unknown
,
9413 "curried map should not be equal to original",
9423 } pullback_tests
[] = {
9424 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9425 "{ A[a,b] -> C[b + 2a] }" },
9426 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9427 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9428 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9429 "{ A[a] -> C[(a)/6] }" },
9430 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9431 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9432 "{ A[a] -> C[(2a)/3] }" },
9433 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9434 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9435 "{ A[i,j] -> C[i + j, i + j] }"},
9436 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9437 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9438 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9439 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9440 "{ [i, j] -> [floor((i)/3), j] }",
9441 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9444 static int test_pullback(isl_ctx
*ctx
)
9447 isl_multi_aff
*ma1
, *ma2
;
9451 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
9452 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
9453 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
9454 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
9455 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
9456 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9457 isl_multi_aff_free(ma1
);
9458 isl_multi_aff_free(ma2
);
9462 isl_die(ctx
, isl_error_unknown
, "bad pullback",
9469 /* Check that negation is printed correctly and that equal expressions
9470 * are correctly identified.
9472 static int test_ast(isl_ctx
*ctx
)
9474 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
9478 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9479 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9480 expr
= isl_ast_expr_add(expr1
, expr2
);
9481 expr2
= isl_ast_expr_copy(expr
);
9482 expr
= isl_ast_expr_neg(expr
);
9483 expr2
= isl_ast_expr_neg(expr2
);
9484 equal
= isl_ast_expr_is_equal(expr
, expr2
);
9485 str
= isl_ast_expr_to_C_str(expr
);
9486 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
9488 isl_ast_expr_free(expr
);
9489 isl_ast_expr_free(expr2
);
9491 if (ok
< 0 || equal
< 0)
9494 isl_die(ctx
, isl_error_unknown
,
9495 "equal expressions not considered equal", return -1);
9497 isl_die(ctx
, isl_error_unknown
,
9498 "isl_ast_expr printed incorrectly", return -1);
9500 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9501 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9502 expr
= isl_ast_expr_add(expr1
, expr2
);
9503 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
9504 expr
= isl_ast_expr_sub(expr3
, expr
);
9505 str
= isl_ast_expr_to_C_str(expr
);
9506 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
9508 isl_ast_expr_free(expr
);
9513 isl_die(ctx
, isl_error_unknown
,
9514 "isl_ast_expr printed incorrectly", return -1);
9519 /* Check that isl_ast_build_expr_from_set returns a valid expression
9520 * for an empty set. Note that isl_ast_build_expr_from_set getting
9521 * called on an empty set probably indicates a bug in the caller.
9523 static int test_ast_build(isl_ctx
*ctx
)
9526 isl_ast_build
*build
;
9529 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9530 build
= isl_ast_build_from_context(set
);
9532 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
9533 expr
= isl_ast_build_expr_from_set(build
, set
);
9535 isl_ast_expr_free(expr
);
9536 isl_ast_build_free(build
);
9544 /* Internal data structure for before_for and after_for callbacks.
9546 * depth is the current depth
9547 * before is the number of times before_for has been called
9548 * after is the number of times after_for has been called
9550 struct isl_test_codegen_data
{
9556 /* This function is called before each for loop in the AST generated
9557 * from test_ast_gen1.
9559 * Increment the number of calls and the depth.
9560 * Check that the space returned by isl_ast_build_get_schedule_space
9561 * matches the target space of the schedule returned by
9562 * isl_ast_build_get_schedule.
9563 * Return an isl_id that is checked by the corresponding call
9566 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
9569 struct isl_test_codegen_data
*data
= user
;
9572 isl_union_map
*schedule
;
9573 isl_union_set
*uset
;
9579 ctx
= isl_ast_build_get_ctx(build
);
9581 if (data
->before
>= 3)
9582 isl_die(ctx
, isl_error_unknown
,
9583 "unexpected number of for nodes", return NULL
);
9584 if (data
->depth
< 0 || data
->depth
>= 2)
9585 isl_die(ctx
, isl_error_unknown
,
9586 "unexpected depth", return NULL
);
9588 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
9592 schedule
= isl_ast_build_get_schedule(build
);
9593 uset
= isl_union_map_range(schedule
);
9594 n
= isl_union_set_n_set(uset
);
9596 isl_union_set_free(uset
);
9599 isl_die(ctx
, isl_error_unknown
,
9600 "expecting single range space", return NULL
);
9603 space
= isl_ast_build_get_schedule_space(build
);
9604 set
= isl_union_set_extract_set(uset
, space
);
9605 isl_union_set_free(uset
);
9606 empty
= isl_set_is_empty(set
);
9612 isl_die(ctx
, isl_error_unknown
,
9613 "spaces don't match", return NULL
);
9615 return isl_id_alloc(ctx
, name
, NULL
);
9618 /* This function is called after each for loop in the AST generated
9619 * from test_ast_gen1.
9621 * Increment the number of calls and decrement the depth.
9622 * Check that the annotation attached to the node matches
9623 * the isl_id returned by the corresponding call to before_for.
9625 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
9626 __isl_keep isl_ast_build
*build
, void *user
)
9628 struct isl_test_codegen_data
*data
= user
;
9636 if (data
->after
> data
->before
)
9637 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9638 "mismatch in number of for nodes",
9639 return isl_ast_node_free(node
));
9641 id
= isl_ast_node_get_annotation(node
);
9643 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9644 "missing annotation", return isl_ast_node_free(node
));
9646 name
= isl_id_get_name(id
);
9647 valid
= name
&& atoi(name
+ 1) == data
->depth
;
9651 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9652 "wrong annotation", return isl_ast_node_free(node
));
9657 /* This function is called after node in the AST generated
9658 * from test_ast_gen1.
9660 * Increment the count in "user" if this is a for node and
9661 * return true to indicate that descendant should also be visited.
9663 static isl_bool
count_for(__isl_keep isl_ast_node
*node
, void *user
)
9667 if (isl_ast_node_get_type(node
) == isl_ast_node_for
)
9670 return isl_bool_true
;
9673 /* If "node" is a block node, then replace it by its first child.
9675 static __isl_give isl_ast_node
*select_first(__isl_take isl_ast_node
*node
,
9678 isl_ast_node_list
*children
;
9679 isl_ast_node
*child
;
9681 if (isl_ast_node_get_type(node
) != isl_ast_node_block
)
9684 children
= isl_ast_node_block_get_children(node
);
9685 child
= isl_ast_node_list_get_at(children
, 0);
9686 isl_ast_node_list_free(children
);
9687 isl_ast_node_free(node
);
9692 /* Check that the before_each_for and after_each_for callbacks
9693 * are called for each for loop in the generated code,
9694 * that they are called in the right order and that the isl_id
9695 * returned from the before_each_for callback is attached to
9696 * the isl_ast_node passed to the corresponding after_each_for call.
9698 * Additionally, check the basic functionality of
9699 * isl_ast_node_foreach_descendant_top_down by counting the number
9700 * of for loops in the resulting AST,
9701 * as well as that of isl_ast_node_map_descendant_bottom_up
9702 * by replacing the block node by its first child and
9703 * counting the number of for loops again.
9705 static isl_stat
test_ast_gen1(isl_ctx
*ctx
)
9708 int modified_count
= 0;
9711 isl_union_map
*schedule
;
9712 isl_ast_build
*build
;
9714 struct isl_test_codegen_data data
;
9716 str
= "[N] -> { : N >= 10 }";
9717 set
= isl_set_read_from_str(ctx
, str
);
9718 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9719 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9720 schedule
= isl_union_map_read_from_str(ctx
, str
);
9725 build
= isl_ast_build_from_context(set
);
9726 build
= isl_ast_build_set_before_each_for(build
,
9727 &before_for
, &data
);
9728 build
= isl_ast_build_set_after_each_for(build
,
9730 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9731 isl_ast_build_free(build
);
9733 if (isl_ast_node_foreach_descendant_top_down(tree
,
9734 &count_for
, &count
) < 0)
9735 tree
= isl_ast_node_free(tree
);
9737 tree
= isl_ast_node_map_descendant_bottom_up(tree
, &select_first
, NULL
);
9739 if (isl_ast_node_foreach_descendant_top_down(tree
, &count_for
,
9740 &modified_count
) < 0)
9741 tree
= isl_ast_node_free(tree
);
9744 return isl_stat_error
;
9746 isl_ast_node_free(tree
);
9748 if (data
.before
!= 3 || data
.after
!= 3 || count
!= 3)
9749 isl_die(ctx
, isl_error_unknown
,
9750 "unexpected number of for nodes",
9751 return isl_stat_error
);
9753 if (modified_count
!= 2)
9754 isl_die(ctx
, isl_error_unknown
,
9755 "unexpected number of for nodes after changes",
9756 return isl_stat_error
);
9761 /* Check that the AST generator handles domains that are integrally disjoint
9762 * but not rationally disjoint.
9764 static int test_ast_gen2(isl_ctx
*ctx
)
9768 isl_union_map
*schedule
;
9769 isl_union_map
*options
;
9770 isl_ast_build
*build
;
9773 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9774 schedule
= isl_union_map_read_from_str(ctx
, str
);
9775 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9776 build
= isl_ast_build_from_context(set
);
9778 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9779 options
= isl_union_map_read_from_str(ctx
, str
);
9780 build
= isl_ast_build_set_options(build
, options
);
9781 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9782 isl_ast_build_free(build
);
9785 isl_ast_node_free(tree
);
9790 /* Increment *user on each call.
9792 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
9793 __isl_keep isl_ast_build
*build
, void *user
)
9802 /* Test that unrolling tries to minimize the number of instances.
9803 * In particular, for the schedule given below, make sure it generates
9804 * 3 nodes (rather than 101).
9806 static int test_ast_gen3(isl_ctx
*ctx
)
9810 isl_union_map
*schedule
;
9811 isl_union_map
*options
;
9812 isl_ast_build
*build
;
9816 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9817 schedule
= isl_union_map_read_from_str(ctx
, str
);
9818 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9820 str
= "{ [i] -> unroll[0] }";
9821 options
= isl_union_map_read_from_str(ctx
, str
);
9823 build
= isl_ast_build_from_context(set
);
9824 build
= isl_ast_build_set_options(build
, options
);
9825 build
= isl_ast_build_set_at_each_domain(build
,
9826 &count_domains
, &n_domain
);
9827 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9828 isl_ast_build_free(build
);
9832 isl_ast_node_free(tree
);
9835 isl_die(ctx
, isl_error_unknown
,
9836 "unexpected number of for nodes", return -1);
9841 /* Check that if the ast_build_exploit_nested_bounds options is set,
9842 * we do not get an outer if node in the generated AST,
9843 * while we do get such an outer if node if the options is not set.
9845 static int test_ast_gen4(isl_ctx
*ctx
)
9849 isl_union_map
*schedule
;
9850 isl_ast_build
*build
;
9852 enum isl_ast_node_type type
;
9855 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9856 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9858 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9860 schedule
= isl_union_map_read_from_str(ctx
, str
);
9861 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9862 build
= isl_ast_build_from_context(set
);
9863 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9864 isl_ast_build_free(build
);
9868 type
= isl_ast_node_get_type(tree
);
9869 isl_ast_node_free(tree
);
9871 if (type
== isl_ast_node_if
)
9872 isl_die(ctx
, isl_error_unknown
,
9873 "not expecting if node", return -1);
9875 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9877 schedule
= isl_union_map_read_from_str(ctx
, str
);
9878 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9879 build
= isl_ast_build_from_context(set
);
9880 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9881 isl_ast_build_free(build
);
9885 type
= isl_ast_node_get_type(tree
);
9886 isl_ast_node_free(tree
);
9888 if (type
!= isl_ast_node_if
)
9889 isl_die(ctx
, isl_error_unknown
,
9890 "expecting if node", return -1);
9892 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9897 /* This function is called for each leaf in the AST generated
9898 * from test_ast_gen5.
9900 * We finalize the AST generation by extending the outer schedule
9901 * with a zero-dimensional schedule. If this results in any for loops,
9902 * then this means that we did not pass along enough information
9903 * about the outer schedule to the inner AST generation.
9905 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9908 isl_union_map
*schedule
, *extra
;
9911 schedule
= isl_ast_build_get_schedule(build
);
9912 extra
= isl_union_map_copy(schedule
);
9913 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9914 schedule
= isl_union_map_range_product(schedule
, extra
);
9915 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9916 isl_ast_build_free(build
);
9921 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9922 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9923 "code should not contain any for loop",
9924 return isl_ast_node_free(tree
));
9929 /* Check that we do not lose any information when going back and
9930 * forth between internal and external schedule.
9932 * In particular, we create an AST where we unroll the only
9933 * non-constant dimension in the schedule. We therefore do
9934 * not expect any for loops in the AST. However, older versions
9935 * of isl would not pass along enough information about the outer
9936 * schedule when performing an inner code generation from a create_leaf
9937 * callback, resulting in the inner code generation producing a for loop.
9939 static int test_ast_gen5(isl_ctx
*ctx
)
9943 isl_union_map
*schedule
, *options
;
9944 isl_ast_build
*build
;
9947 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9948 schedule
= isl_union_map_read_from_str(ctx
, str
);
9950 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9951 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9952 options
= isl_union_map_read_from_str(ctx
, str
);
9954 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9955 build
= isl_ast_build_from_context(set
);
9956 build
= isl_ast_build_set_options(build
, options
);
9957 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9958 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9959 isl_ast_build_free(build
);
9960 isl_ast_node_free(tree
);
9967 /* Check that the expression
9969 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9971 * is not combined into
9975 * as this would result in n/2 being evaluated in parts of
9976 * the definition domain where n is not a multiple of 2.
9978 static int test_ast_expr(isl_ctx
*ctx
)
9982 isl_ast_build
*build
;
9987 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9988 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9990 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9991 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9992 build
= isl_ast_build_alloc(ctx
);
9993 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9994 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9995 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9996 isl_ast_build_free(build
);
9997 isl_ast_expr_free(expr
);
9999 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
10004 isl_die(ctx
, isl_error_unknown
,
10005 "expressions should not be combined", return -1);
10010 static int test_ast_gen(isl_ctx
*ctx
)
10012 if (test_ast_gen1(ctx
) < 0)
10014 if (test_ast_gen2(ctx
) < 0)
10016 if (test_ast_gen3(ctx
) < 0)
10018 if (test_ast_gen4(ctx
) < 0)
10020 if (test_ast_gen5(ctx
) < 0)
10022 if (test_ast_expr(ctx
) < 0)
10027 /* Check if dropping output dimensions from an isl_pw_multi_aff
10030 static int test_pw_multi_aff(isl_ctx
*ctx
)
10033 isl_pw_multi_aff
*pma1
, *pma2
;
10036 str
= "{ [i,j] -> [i+j, 4i-j] }";
10037 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
10038 str
= "{ [i,j] -> [4i-j] }";
10039 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
10041 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
10043 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
10045 isl_pw_multi_aff_free(pma1
);
10046 isl_pw_multi_aff_free(pma2
);
10050 isl_die(ctx
, isl_error_unknown
,
10051 "expressions not equal", return -1);
10056 /* Check that we can properly parse multi piecewise affine expressions
10057 * where the piecewise affine expressions have different domains.
10059 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
10062 isl_set
*dom
, *dom2
;
10063 isl_multi_pw_aff
*mpa1
, *mpa2
;
10068 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
10069 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
10070 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
10071 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
10072 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
10073 str
= "{ [i] -> [(i : i > 0), 2i] }";
10074 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10076 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
10078 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
10079 dom
= isl_pw_aff_domain(pa
);
10080 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
10081 dom2
= isl_pw_aff_domain(pa
);
10082 equal_domain
= isl_set_is_equal(dom
, dom2
);
10085 isl_set_free(dom2
);
10086 isl_multi_pw_aff_free(mpa1
);
10087 isl_multi_pw_aff_free(mpa2
);
10092 isl_die(ctx
, isl_error_unknown
,
10093 "expressions not equal", return -1);
10095 if (equal_domain
< 0)
10098 isl_die(ctx
, isl_error_unknown
,
10099 "domains unexpectedly equal", return -1);
10104 /* Check that the dimensions in the explicit domain
10105 * of a multi piecewise affine expression are properly
10106 * taken into account.
10108 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
10111 isl_bool involves1
, involves2
, involves3
, equal
;
10112 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
10114 str
= "{ A[x,y] -> B[] : x >= y }";
10115 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10116 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
10117 mpa1
= isl_multi_pw_aff_copy(mpa
);
10119 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
10120 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
10121 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
10122 str
= "{ [a,x,y] -> B[] : x >= y }";
10123 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10124 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
10125 isl_multi_pw_aff_free(mpa2
);
10127 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
10128 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
10129 if (equal
>= 0 && equal
)
10130 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
10131 isl_multi_pw_aff_free(mpa1
);
10132 isl_multi_pw_aff_free(mpa
);
10134 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
10137 isl_die(ctx
, isl_error_unknown
,
10138 "incorrect result of dimension insertion/removal",
10139 return isl_stat_error
);
10140 if (!involves1
|| involves2
|| !involves3
)
10141 isl_die(ctx
, isl_error_unknown
,
10142 "incorrect characterization of involved dimensions",
10143 return isl_stat_error
);
10148 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
10149 * sets the explicit domain of a zero-dimensional result,
10150 * such that it can be converted to an isl_union_map.
10152 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
10155 isl_union_set
*dom
;
10157 isl_multi_union_pw_aff
*mupa
;
10158 isl_union_map
*umap
;
10160 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
10161 space
= isl_union_set_get_space(dom
);
10162 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
10163 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
10164 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
10165 isl_union_map_free(umap
);
10167 return isl_stat_error
;
10169 return isl_stat_ok
;
10172 /* String descriptions of boxes that
10173 * are used for reconstructing box maps from their lower and upper bounds.
10175 static const char *multi_pw_aff_box_tests
[] = {
10176 "{ A[x, y] -> [] : x + y >= 0 }",
10177 "[N] -> { A[x, y] -> [x] : x + y <= N }",
10178 "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
10181 /* Check that map representations of boxes can be reconstructed
10182 * from their lower and upper bounds.
10184 static isl_stat
test_multi_pw_aff_box(isl_ctx
*ctx
)
10188 for (i
= 0; i
< ARRAY_SIZE(multi_pw_aff_box_tests
); ++i
) {
10191 isl_map
*map
, *box
;
10192 isl_multi_pw_aff
*min
, *max
;
10194 str
= multi_pw_aff_box_tests
[i
];
10195 map
= isl_map_read_from_str(ctx
, str
);
10196 min
= isl_map_min_multi_pw_aff(isl_map_copy(map
));
10197 max
= isl_map_max_multi_pw_aff(isl_map_copy(map
));
10198 box
= isl_map_universe(isl_map_get_space(map
));
10199 box
= isl_map_lower_bound_multi_pw_aff(box
, min
);
10200 box
= isl_map_upper_bound_multi_pw_aff(box
, max
);
10201 equal
= isl_map_is_equal(map
, box
);
10205 return isl_stat_error
;
10207 isl_die(ctx
, isl_error_unknown
,
10208 "unexpected result", return isl_stat_error
);
10211 return isl_stat_ok
;
10214 /* Perform some tests on multi piecewise affine expressions.
10216 static int test_multi_pw_aff(isl_ctx
*ctx
)
10218 if (test_multi_pw_aff_1(ctx
) < 0)
10220 if (test_multi_pw_aff_2(ctx
) < 0)
10222 if (test_multi_pw_aff_3(ctx
) < 0)
10224 if (test_multi_pw_aff_box(ctx
) < 0)
10229 /* This is a regression test for a bug where isl_basic_map_simplify
10230 * would end up in an infinite loop. In particular, we construct
10231 * an empty basic set that is not obviously empty.
10232 * isl_basic_set_is_empty marks the basic set as empty.
10233 * After projecting out i3, the variable can be dropped completely,
10234 * but isl_basic_map_simplify refrains from doing so if the basic set
10235 * is empty and would end up in an infinite loop if it didn't test
10236 * explicitly for empty basic maps in the outer loop.
10238 static int test_simplify_1(isl_ctx
*ctx
)
10241 isl_basic_set
*bset
;
10244 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10245 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10246 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10248 bset
= isl_basic_set_read_from_str(ctx
, str
);
10249 empty
= isl_basic_set_is_empty(bset
);
10250 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
10251 isl_basic_set_free(bset
);
10255 isl_die(ctx
, isl_error_unknown
,
10256 "basic set should be empty", return -1);
10261 /* Check that the equality in the set description below
10262 * is simplified away.
10264 static int test_simplify_2(isl_ctx
*ctx
)
10267 isl_basic_set
*bset
;
10270 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10271 bset
= isl_basic_set_read_from_str(ctx
, str
);
10272 universe
= isl_basic_set_plain_is_universe(bset
);
10273 isl_basic_set_free(bset
);
10278 isl_die(ctx
, isl_error_unknown
,
10279 "equality not simplified away", return -1);
10283 /* Some simplification tests.
10285 static int test_simplify(isl_ctx
*ctx
)
10287 if (test_simplify_1(ctx
) < 0)
10289 if (test_simplify_2(ctx
) < 0)
10294 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10295 * with gbr context would fail to disable the use of the shifted tableau
10296 * when transferring equalities for the input to the context, resulting
10297 * in invalid sample values.
10299 static int test_partial_lexmin(isl_ctx
*ctx
)
10302 isl_basic_set
*bset
;
10303 isl_basic_map
*bmap
;
10306 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10307 bmap
= isl_basic_map_read_from_str(ctx
, str
);
10308 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10309 bset
= isl_basic_set_read_from_str(ctx
, str
);
10310 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
10319 /* Check that the variable compression performed on the existentially
10320 * quantified variables inside isl_basic_set_compute_divs is not confused
10321 * by the implicit equalities among the parameters.
10323 static int test_compute_divs(isl_ctx
*ctx
)
10326 isl_basic_set
*bset
;
10329 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10330 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10331 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10332 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10333 bset
= isl_basic_set_read_from_str(ctx
, str
);
10334 set
= isl_basic_set_compute_divs(bset
);
10342 /* Check that isl_schedule_get_map is not confused by a schedule tree
10343 * with divergent filter node parameters, as can result from a call
10344 * to isl_schedule_intersect_domain.
10346 static int test_schedule_tree(isl_ctx
*ctx
)
10349 isl_union_set
*uset
;
10350 isl_schedule
*sched1
, *sched2
;
10351 isl_union_map
*umap
;
10353 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
10354 sched1
= isl_schedule_from_domain(uset
);
10355 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
10356 sched2
= isl_schedule_from_domain(uset
);
10358 sched1
= isl_schedule_sequence(sched1
, sched2
);
10359 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
10360 uset
= isl_union_set_read_from_str(ctx
, str
);
10361 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
10362 umap
= isl_schedule_get_map(sched1
);
10363 isl_schedule_free(sched1
);
10364 isl_union_map_free(umap
);
10371 /* Check that a zero-dimensional prefix schedule keeps track
10372 * of the domain and outer filters.
10374 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
10378 isl_union_set
*uset
;
10379 isl_union_set_list
*filters
;
10380 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10381 isl_schedule_node
*node
;
10383 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10384 uset
= isl_union_set_read_from_str(ctx
, str
);
10385 node
= isl_schedule_node_from_domain(uset
);
10386 node
= isl_schedule_node_child(node
, 0);
10388 str
= "{ S1[i,j] : i > j }";
10389 uset
= isl_union_set_read_from_str(ctx
, str
);
10390 filters
= isl_union_set_list_from_union_set(uset
);
10391 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
10392 uset
= isl_union_set_read_from_str(ctx
, str
);
10393 filters
= isl_union_set_list_add(filters
, uset
);
10394 node
= isl_schedule_node_insert_sequence(node
, filters
);
10396 node
= isl_schedule_node_grandchild(node
, 0, 0);
10397 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
10398 str
= "([] : { S1[i,j] : i > j })";
10399 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10400 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10401 isl_multi_union_pw_aff_free(mupa2
);
10402 isl_multi_union_pw_aff_free(mupa
);
10403 isl_schedule_node_free(node
);
10408 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
10414 /* Check that the reaching domain elements and the prefix schedule
10415 * at a leaf node are the same before and after grouping.
10417 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
10422 isl_union_set
*uset
;
10423 isl_multi_union_pw_aff
*mupa
;
10424 isl_union_pw_multi_aff
*upma1
, *upma2
;
10425 isl_union_set
*domain1
, *domain2
;
10426 isl_union_map
*umap1
, *umap2
;
10427 isl_schedule_node
*node
;
10429 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10430 uset
= isl_union_set_read_from_str(ctx
, str
);
10431 node
= isl_schedule_node_from_domain(uset
);
10432 node
= isl_schedule_node_child(node
, 0);
10433 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10434 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10435 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10436 node
= isl_schedule_node_child(node
, 0);
10437 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10438 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10439 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10440 node
= isl_schedule_node_child(node
, 0);
10441 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10442 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10443 domain1
= isl_schedule_node_get_domain(node
);
10444 id
= isl_id_alloc(ctx
, "group", NULL
);
10445 node
= isl_schedule_node_parent(node
);
10446 node
= isl_schedule_node_group(node
, id
);
10447 node
= isl_schedule_node_child(node
, 0);
10448 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10449 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10450 domain2
= isl_schedule_node_get_domain(node
);
10451 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
10452 if (equal
>= 0 && equal
)
10453 equal
= isl_union_set_is_equal(domain1
, domain2
);
10454 if (equal
>= 0 && equal
)
10455 equal
= isl_union_map_is_equal(umap1
, umap2
);
10456 isl_union_map_free(umap1
);
10457 isl_union_map_free(umap2
);
10458 isl_union_set_free(domain1
);
10459 isl_union_set_free(domain2
);
10460 isl_union_pw_multi_aff_free(upma1
);
10461 isl_union_pw_multi_aff_free(upma2
);
10462 isl_schedule_node_free(node
);
10467 isl_die(ctx
, isl_error_unknown
,
10468 "expressions not equal", return -1);
10473 /* Check that we can have nested groupings and that the union map
10474 * schedule representation is the same before and after the grouping.
10475 * Note that after the grouping, the union map representation contains
10476 * the domain constraints from the ranges of the expansion nodes,
10477 * while they are missing from the union map representation of
10478 * the tree without expansion nodes.
10480 * Also check that the global expansion is as expected.
10482 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
10484 int equal
, equal_expansion
;
10487 isl_union_set
*uset
;
10488 isl_union_map
*umap1
, *umap2
;
10489 isl_union_map
*expansion1
, *expansion2
;
10490 isl_union_set_list
*filters
;
10491 isl_multi_union_pw_aff
*mupa
;
10492 isl_schedule
*schedule
;
10493 isl_schedule_node
*node
;
10495 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10496 "S3[i,j] : 0 <= i,j < 10 }";
10497 uset
= isl_union_set_read_from_str(ctx
, str
);
10498 node
= isl_schedule_node_from_domain(uset
);
10499 node
= isl_schedule_node_child(node
, 0);
10500 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10501 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10502 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10503 node
= isl_schedule_node_child(node
, 0);
10504 str
= "{ S1[i,j] }";
10505 uset
= isl_union_set_read_from_str(ctx
, str
);
10506 filters
= isl_union_set_list_from_union_set(uset
);
10507 str
= "{ S2[i,j]; S3[i,j] }";
10508 uset
= isl_union_set_read_from_str(ctx
, str
);
10509 filters
= isl_union_set_list_add(filters
, uset
);
10510 node
= isl_schedule_node_insert_sequence(node
, filters
);
10511 node
= isl_schedule_node_grandchild(node
, 1, 0);
10512 str
= "{ S2[i,j] }";
10513 uset
= isl_union_set_read_from_str(ctx
, str
);
10514 filters
= isl_union_set_list_from_union_set(uset
);
10515 str
= "{ S3[i,j] }";
10516 uset
= isl_union_set_read_from_str(ctx
, str
);
10517 filters
= isl_union_set_list_add(filters
, uset
);
10518 node
= isl_schedule_node_insert_sequence(node
, filters
);
10520 schedule
= isl_schedule_node_get_schedule(node
);
10521 umap1
= isl_schedule_get_map(schedule
);
10522 uset
= isl_schedule_get_domain(schedule
);
10523 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
10524 isl_schedule_free(schedule
);
10526 node
= isl_schedule_node_grandparent(node
);
10527 id
= isl_id_alloc(ctx
, "group1", NULL
);
10528 node
= isl_schedule_node_group(node
, id
);
10529 node
= isl_schedule_node_grandchild(node
, 1, 0);
10530 id
= isl_id_alloc(ctx
, "group2", NULL
);
10531 node
= isl_schedule_node_group(node
, id
);
10533 schedule
= isl_schedule_node_get_schedule(node
);
10534 umap2
= isl_schedule_get_map(schedule
);
10535 isl_schedule_free(schedule
);
10537 node
= isl_schedule_node_root(node
);
10538 node
= isl_schedule_node_child(node
, 0);
10539 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
10540 isl_schedule_node_free(node
);
10542 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10543 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10544 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10546 expansion2
= isl_union_map_read_from_str(ctx
, str
);
10548 equal
= isl_union_map_is_equal(umap1
, umap2
);
10549 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
10551 isl_union_map_free(umap1
);
10552 isl_union_map_free(umap2
);
10553 isl_union_map_free(expansion1
);
10554 isl_union_map_free(expansion2
);
10556 if (equal
< 0 || equal_expansion
< 0)
10559 isl_die(ctx
, isl_error_unknown
,
10560 "expressions not equal", return -1);
10561 if (!equal_expansion
)
10562 isl_die(ctx
, isl_error_unknown
,
10563 "unexpected expansion", return -1);
10568 /* Some tests for the isl_schedule_node_group function.
10570 static int test_schedule_tree_group(isl_ctx
*ctx
)
10572 if (test_schedule_tree_group_1(ctx
) < 0)
10574 if (test_schedule_tree_group_2(ctx
) < 0)
10583 { "{ rat: [i] : 0 <= i <= 10 }",
10584 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10585 { "{ rat: [i] : FALSE }",
10586 "{ rat: coefficients[[cst] -> [a]] }" },
10587 { "{ rat: [i] : }",
10588 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10589 { "{ [0:,1,2:3] }",
10590 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10591 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10592 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10593 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10594 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10595 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10596 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10597 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10598 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10599 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10600 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10607 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10608 "{ rat: [i] : 0 <= i <= 10 }" },
10609 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10611 { "{ rat: coefficients[[cst] -> [a]] }",
10612 "{ rat: [i] : FALSE }" },
10615 /* Test the basic functionality of isl_basic_set_coefficients and
10616 * isl_basic_set_solutions.
10618 static int test_dual(isl_ctx
*ctx
)
10622 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
10624 isl_basic_set
*bset1
, *bset2
;
10626 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
10627 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
10628 bset1
= isl_basic_set_coefficients(bset1
);
10629 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10630 isl_basic_set_free(bset1
);
10631 isl_basic_set_free(bset2
);
10635 isl_die(ctx
, isl_error_unknown
,
10636 "incorrect dual", return -1);
10639 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
10641 isl_basic_set
*bset1
, *bset2
;
10643 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
10644 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
10645 bset1
= isl_basic_set_solutions(bset1
);
10646 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10647 isl_basic_set_free(bset1
);
10648 isl_basic_set_free(bset2
);
10652 isl_die(ctx
, isl_error_unknown
,
10653 "incorrect dual", return -1);
10662 const char *domain
;
10663 const char *schedule
;
10668 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10669 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10671 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10672 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10674 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10675 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10677 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10678 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10680 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10681 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10683 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10684 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10686 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10687 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10689 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10690 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10694 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10695 * tile the band and then check if the tile and point bands have the
10696 * expected partial schedule.
10698 static int test_tile(isl_ctx
*ctx
)
10704 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
10705 shift
= isl_options_get_tile_shift_point_loops(ctx
);
10707 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
10711 isl_union_set
*domain
;
10712 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10713 isl_schedule_node
*node
;
10714 isl_multi_val
*sizes
;
10716 opt
= tile_tests
[i
].scale_tile
;
10717 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
10718 opt
= tile_tests
[i
].shift_point
;
10719 isl_options_set_tile_shift_point_loops(ctx
, opt
);
10721 str
= tile_tests
[i
].domain
;
10722 domain
= isl_union_set_read_from_str(ctx
, str
);
10723 node
= isl_schedule_node_from_domain(domain
);
10724 node
= isl_schedule_node_child(node
, 0);
10725 str
= tile_tests
[i
].schedule
;
10726 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10727 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10728 str
= tile_tests
[i
].sizes
;
10729 sizes
= isl_multi_val_read_from_str(ctx
, str
);
10730 node
= isl_schedule_node_band_tile(node
, sizes
);
10732 str
= tile_tests
[i
].tile
;
10733 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10734 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10735 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10736 isl_multi_union_pw_aff_free(mupa
);
10737 isl_multi_union_pw_aff_free(mupa2
);
10739 node
= isl_schedule_node_child(node
, 0);
10741 str
= tile_tests
[i
].point
;
10742 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10743 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10744 if (equal
>= 0 && equal
)
10745 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
10747 isl_multi_union_pw_aff_free(mupa
);
10748 isl_multi_union_pw_aff_free(mupa2
);
10750 isl_schedule_node_free(node
);
10755 isl_die(ctx
, isl_error_unknown
,
10756 "unexpected result", return -1);
10759 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
10760 isl_options_set_tile_shift_point_loops(ctx
, shift
);
10765 /* Check that the domain hash of a space is equal to the hash
10766 * of the domain of the space, both ignoring parameters.
10768 static int test_domain_hash(isl_ctx
*ctx
)
10772 uint32_t hash1
, hash2
;
10774 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
10775 space
= isl_map_get_space(map
);
10777 hash1
= isl_space_get_tuple_domain_hash(space
);
10778 space
= isl_space_domain(space
);
10779 hash2
= isl_space_get_tuple_hash(space
);
10780 isl_space_free(space
);
10784 if (hash1
!= hash2
)
10785 isl_die(ctx
, isl_error_unknown
,
10786 "domain hash not equal to hash of domain", return -1);
10791 /* Check that a universe basic set that is not obviously equal to the universe
10792 * is still recognized as being equal to the universe.
10794 static int test_universe(isl_ctx
*ctx
)
10797 isl_basic_set
*bset
;
10800 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10801 bset
= isl_basic_set_read_from_str(ctx
, s
);
10802 is_univ
= isl_basic_set_is_universe(bset
);
10803 isl_basic_set_free(bset
);
10808 isl_die(ctx
, isl_error_unknown
,
10809 "not recognized as universe set", return -1);
10814 /* Sets for which chambers are computed and checked.
10816 const char *chambers_tests
[] = {
10817 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10818 "z >= 0 and z <= C - y and z <= B - x - y }",
10821 /* Add the domain of "cell" to "cells".
10823 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
10825 isl_basic_set_list
**cells
= user
;
10826 isl_basic_set
*dom
;
10828 dom
= isl_cell_get_domain(cell
);
10829 isl_cell_free(cell
);
10830 *cells
= isl_basic_set_list_add(*cells
, dom
);
10832 return *cells
? isl_stat_ok
: isl_stat_error
;
10835 /* Check that the elements of "list" are pairwise disjoint.
10837 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
10842 n
= isl_basic_set_list_n_basic_set(list
);
10844 return isl_stat_error
;
10846 for (i
= 0; i
< n
; ++i
) {
10847 isl_basic_set
*bset_i
;
10849 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
10850 for (j
= i
+ 1; j
< n
; ++j
) {
10851 isl_basic_set
*bset_j
;
10854 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
10855 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
10856 isl_basic_set_free(bset_j
);
10858 isl_die(isl_basic_set_list_get_ctx(list
),
10859 isl_error_unknown
, "not disjoint",
10861 if (disjoint
< 0 || !disjoint
)
10864 isl_basic_set_free(bset_i
);
10866 return isl_stat_error
;
10869 return isl_stat_ok
;
10872 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10873 * are pairwise disjoint.
10875 static int test_chambers(isl_ctx
*ctx
)
10879 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
10880 isl_basic_set
*bset
;
10881 isl_vertices
*vertices
;
10882 isl_basic_set_list
*cells
;
10885 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
10886 vertices
= isl_basic_set_compute_vertices(bset
);
10887 cells
= isl_basic_set_list_alloc(ctx
, 0);
10888 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
10890 cells
= isl_basic_set_list_free(cells
);
10891 ok
= check_pairwise_disjoint(cells
);
10892 isl_basic_set_list_free(cells
);
10893 isl_vertices_free(vertices
);
10894 isl_basic_set_free(bset
);
10905 int (*fn
)(isl_ctx
*ctx
);
10907 { "universe", &test_universe
},
10908 { "domain hash", &test_domain_hash
},
10909 { "dual", &test_dual
},
10910 { "dependence analysis", &test_flow
},
10911 { "val", &test_val
},
10912 { "compute divs", &test_compute_divs
},
10913 { "partial lexmin", &test_partial_lexmin
},
10914 { "simplify", &test_simplify
},
10915 { "curry", &test_curry
},
10916 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10917 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10918 { "conversion", &test_conversion
},
10919 { "list", &test_list
},
10920 { "align parameters", &test_align_parameters
},
10921 { "drop unused parameters", &test_drop_unused_parameters
},
10922 { "pullback", &test_pullback
},
10923 { "AST", &test_ast
},
10924 { "AST build", &test_ast_build
},
10925 { "AST generation", &test_ast_gen
},
10926 { "eliminate", &test_eliminate
},
10927 { "deltas_map", &test_deltas_map
},
10928 { "residue class", &test_residue_class
},
10929 { "div", &test_div
},
10930 { "slice", &test_slice
},
10931 { "sample", &test_sample
},
10932 { "empty projection", &test_empty_projection
},
10933 { "output", &test_output
},
10934 { "vertices", &test_vertices
},
10935 { "chambers", &test_chambers
},
10936 { "fixed", &test_fixed
},
10937 { "equal", &test_equal
},
10938 { "disjoint", &test_disjoint
},
10939 { "product", &test_product
},
10940 { "dim_max", &test_dim_max
},
10941 { "affine", &test_aff
},
10942 { "injective", &test_injective
},
10943 { "schedule (whole component)", &test_schedule_whole
},
10944 { "schedule (incremental)", &test_schedule_incremental
},
10945 { "schedule tree", &test_schedule_tree
},
10946 { "schedule tree prefix", &test_schedule_tree_prefix
},
10947 { "schedule tree grouping", &test_schedule_tree_group
},
10948 { "tile", &test_tile
},
10949 { "union map", &test_union_map
},
10950 { "union_pw", &test_union_pw
},
10951 { "locus", &test_locus
},
10952 { "eval", &test_eval
},
10953 { "parse", &test_parse
},
10954 { "single-valued", &test_sv
},
10955 { "recession cone", &test_recession_cone
},
10956 { "affine hull", &test_affine_hull
},
10957 { "simple_hull", &test_simple_hull
},
10958 { "box hull", &test_box_hull
},
10959 { "coalesce", &test_coalesce
},
10960 { "factorize", &test_factorize
},
10961 { "subset", &test_subset
},
10962 { "subtract", &test_subtract
},
10963 { "intersect", &test_intersect
},
10964 { "lexmin", &test_lexmin
},
10965 { "min", &test_min
},
10966 { "set lower bounds", &test_min_mpa
},
10967 { "gist", &test_gist
},
10968 { "piecewise quasi-polynomials", &test_pwqp
},
10969 { "lift", &test_lift
},
10970 { "bind parameters", &test_bind
},
10971 { "unbind parameters", &test_unbind
},
10972 { "bound", &test_bound
},
10973 { "get lists", &test_get_list
},
10974 { "union", &test_union
},
10975 { "split periods", &test_split_periods
},
10976 { "lexicographic order", &test_lex
},
10977 { "bijectivity", &test_bijective
},
10978 { "dataflow analysis", &test_dep
},
10979 { "reading", &test_read
},
10980 { "bounded", &test_bounded
},
10981 { "construction", &test_construction
},
10982 { "dimension manipulation", &test_dim
},
10983 { "map application", &test_application
},
10984 { "convex hull", &test_convex_hull
},
10985 { "transitive closure", &test_closure
},
10986 { "isl_bool", &test_isl_bool
},
10989 int main(int argc
, char **argv
)
10992 struct isl_ctx
*ctx
;
10993 struct isl_options
*options
;
10995 options
= isl_options_new_with_defaults();
10997 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10999 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
11000 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
11001 printf("%s\n", tests
[i
].name
);
11002 if (tests
[i
].fn(ctx
) < 0)