2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
28 #include <isl_constraint_private.h>
29 #include <isl/polynomial.h>
30 #include <isl/union_set.h>
31 #include <isl/union_map.h>
32 #include <isl_factorization.h>
33 #include <isl/schedule.h>
34 #include <isl/schedule_node.h>
35 #include <isl_options_private.h>
36 #include <isl_vertices_private.h>
37 #include <isl/ast_build.h>
40 #include <isl_ast_build_expr.h>
41 #include <isl/options.h>
43 #include "isl_srcdir.c"
45 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
47 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
50 char *pattern
= "%s/test_inputs/%s.%s";
52 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
54 filename
= isl_alloc_array(ctx
, char, length
);
59 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
64 void test_parse_map(isl_ctx
*ctx
, const char *str
)
68 map
= isl_map_read_from_str(ctx
, str
);
73 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
78 map
= isl_map_read_from_str(ctx
, str
);
79 map2
= isl_map_read_from_str(ctx
, str2
);
80 equal
= isl_map_is_equal(map
, map2
);
87 isl_die(ctx
, isl_error_unknown
, "maps not equal",
93 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
95 isl_pw_qpolynomial
*pwqp
;
97 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
99 isl_pw_qpolynomial_free(pwqp
);
102 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
106 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
108 isl_pw_aff_free(pwaff
);
111 /* Check that we can read an isl_multi_val from "str" without errors.
113 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
117 mv
= isl_multi_val_read_from_str(ctx
, str
);
118 isl_multi_val_free(mv
);
124 #define BASE multi_pw_aff
126 #include "check_reparse_templ.c"
129 #define BASE pw_multi_aff
131 #include "check_reparse_templ.c"
133 /* Test parsing of piecewise multi affine expressions by printing
134 * the expressions and checking that parsing the output results
135 * in the same expression.
136 * Do this for an expression converted from a map with an output
137 * dimension name that is equal to an automatically generated name.
139 static isl_stat
test_parse_pma(isl_ctx
*ctx
)
142 isl_pw_multi_aff
*pma
;
144 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
145 pma
= isl_pw_multi_aff_from_map(map
);
146 if (check_reparse_pw_multi_aff(ctx
, pma
) < 0)
147 return isl_stat_error
;
152 /* String descriptions of multi piecewise affine expressions
153 * that are used for testing printing and parsing.
155 const char *parse_multi_mpa_tests
[] = {
156 "{ A[x, y] -> [] : x + y >= 0 }",
157 "{ A[x, y] -> B[] : x + y >= 0 }",
158 "{ A[x, y] -> [x] : x + y >= 0 }",
159 "[N] -> { A[x, y] -> [x] : x + y <= N }",
160 "{ A[x, y] -> [x, y] : x + y >= 0 }",
161 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
162 "[N] -> { [] : N >= 0 }",
163 "[N] -> { [] : N >= 0 }",
164 "[N] -> { [N] : N >= 0 }",
165 "[N] -> { [N, N + 1] : N >= 0 }",
166 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
169 /* Test parsing of multi piecewise affine expressions by printing
170 * the expressions and checking that parsing the output results
171 * in the same expression.
172 * Do this for a couple of manually constructed expressions,
173 * an expression converted from a map with an output dimension name
174 * that is equal to an automatically generated name, and
175 * a set of expressions parsed from strings.
177 static int test_parse_mpa(isl_ctx
*ctx
)
183 isl_pw_multi_aff
*pma
;
184 isl_multi_pw_aff
*mpa
;
187 space
= isl_space_set_alloc(ctx
, 0, 0);
188 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
189 mpa
= isl_multi_pw_aff_zero(space
);
190 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
194 space
= isl_space_set_alloc(ctx
, 1, 0);
195 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
196 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
197 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
198 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
199 mpa
= isl_multi_pw_aff_zero(space
);
200 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
201 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
205 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
206 pma
= isl_pw_multi_aff_from_map(map
);
207 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma
);
208 if (check_reparse_multi_pw_aff(ctx
, mpa
) < 0)
211 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mpa_tests
); ++i
) {
214 str
= parse_multi_mpa_tests
[i
];
215 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
216 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
226 #define BASE multi_union_pw_aff
228 #include "check_reparse_templ.c"
230 /* String descriptions of multi union piecewise affine expressions
231 * that are used for testing printing and parsing.
233 const char *parse_multi_mupa_tests
[] = {
237 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
239 "[N] -> (A[] : { })",
240 "[N] -> (A[] : { : N >= 0 })",
241 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
242 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
243 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
244 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
245 "{ S[x] : x > 0; T[y] : y >= 0 })",
248 /* Test parsing of multi union piecewise affine expressions by printing
249 * the expressions and checking that parsing the output results
250 * in the same expression.
251 * Do this for a couple of manually constructed expressions and
252 * a set of expressions parsed from strings.
254 static int test_parse_mupa(isl_ctx
*ctx
)
258 isl_multi_union_pw_aff
*mupa
;
263 space
= isl_space_set_alloc(ctx
, 0, 0);
264 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
265 mupa
= isl_multi_union_pw_aff_zero(space
);
266 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
270 space
= isl_space_set_alloc(ctx
, 1, 0);
271 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
272 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
273 dom
= isl_set_universe(space
);
274 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
275 uset
= isl_union_set_from_set(dom
);
276 space
= isl_space_set_alloc(ctx
, 1, 0);
277 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
278 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
279 mupa
= isl_multi_union_pw_aff_zero(space
);
280 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
281 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
285 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mupa_tests
); ++i
) {
288 str
= parse_multi_mupa_tests
[i
];
289 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
290 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
298 /* Test parsing of multi expressions.
300 static int test_parse_multi(isl_ctx
*ctx
)
302 if (test_parse_mpa(ctx
) < 0)
304 if (test_parse_mupa(ctx
) < 0)
310 /* Pairs of binary relation representations that should represent
311 * the same binary relations.
316 } parse_map_equal_tests
[] = {
317 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
318 "{ [x, y] : 2y >= 6 - x }" },
319 { "{ [x,y] : x <= min(y, 2*y+3) }",
320 "{ [x,y] : x <= y, 2*y + 3 }" },
321 { "{ [x,y] : x >= min(y, 2*y+3) }",
322 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
323 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
324 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
325 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
326 "{ [i,j] -> [min(i,j)] }" },
327 { "{ [i,j] : i != j }",
328 "{ [i,j] : i < j or i > j }" },
329 { "{ [i,j] : (i+1)*2 >= j }",
330 "{ [i, j] : j <= 2 + 2i }" },
331 { "{ [i] -> [i > 0 ? 4 : 5] }",
332 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
333 { "[N=2,M] -> { [i=[(M+N)/4]] }",
334 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
335 { "{ [x] : x >= 0 }",
336 "{ [x] : x-0 >= 0 }" },
337 { "{ [i] : ((i > 10)) }",
338 "{ [i] : i >= 11 }" },
340 "{ [i] -> [0 * i] }" },
341 { "{ [a] -> [b] : (not false) }",
342 "{ [a] -> [b] : true }" },
343 { "{ [i] : i/2 <= 5 }",
344 "{ [i] : i <= 10 }" },
345 { "{Sym=[n] [i] : i <= n }",
346 "[n] -> { [i] : i <= n }" },
349 { "{ [i] : 2*floor(i/2) = i }",
350 "{ [i] : exists a : i = 2 a }" },
351 { "{ [a] -> [b] : a = 5 implies b = 5 }",
352 "{ [a] -> [b] : a != 5 or b = 5 }" },
353 { "{ [a] -> [a - 1 : a > 0] }",
354 "{ [a] -> [a - 1] : a > 0 }" },
355 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
356 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
357 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
358 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
359 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
360 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
361 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
362 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
363 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
364 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
365 { "{ [a,b] -> [i,j] : a,b << i,j }",
366 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
367 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
368 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
369 { "{ [a,b] -> [i,j] : a,b >> i,j }",
370 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
371 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
372 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
373 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
374 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
375 "8c < n - 32a and i < n and c >= 0 and "
376 "c <= 3 and c >= -4a) }",
377 "{ [n] -> [i] : 0 <= i < n }" },
378 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
379 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
380 "{ [x] -> [] : 0 <= x <= 15 }" },
381 { "{ [x] -> [x] : }",
385 int test_parse(struct isl_ctx
*ctx
)
389 const char *str
, *str2
;
391 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
393 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
395 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
397 if (test_parse_multi(ctx
) < 0)
399 if (test_parse_pma(ctx
) < 0)
402 str
= "{ [i] -> [-i] }";
403 map
= isl_map_read_from_str(ctx
, str
);
407 str
= "{ A[i] -> L[([i/3])] }";
408 map
= isl_map_read_from_str(ctx
, str
);
412 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
413 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
414 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
416 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
417 str
= parse_map_equal_tests
[i
].map1
;
418 str2
= parse_map_equal_tests
[i
].map2
;
419 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
423 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
424 map
= isl_map_read_from_str(ctx
, str
);
425 str
= "{ [new, old] -> [o0, o1] : "
426 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
427 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
428 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
429 map2
= isl_map_read_from_str(ctx
, str
);
430 assert(isl_map_is_equal(map
, map2
));
434 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
435 map
= isl_map_read_from_str(ctx
, str
);
436 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
437 map2
= isl_map_read_from_str(ctx
, str
);
438 assert(isl_map_is_equal(map
, map2
));
442 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
443 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
444 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
445 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
446 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
451 static int test_read(isl_ctx
*ctx
)
455 isl_basic_set
*bset1
, *bset2
;
456 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
459 filename
= get_filename(ctx
, "set", "omega");
461 input
= fopen(filename
, "r");
464 bset1
= isl_basic_set_read_from_file(ctx
, input
);
465 bset2
= isl_basic_set_read_from_str(ctx
, str
);
467 equal
= isl_basic_set_is_equal(bset1
, bset2
);
469 isl_basic_set_free(bset1
);
470 isl_basic_set_free(bset2
);
478 isl_die(ctx
, isl_error_unknown
,
479 "read sets not equal", return -1);
484 static int test_bounded(isl_ctx
*ctx
)
489 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
490 bounded
= isl_set_is_bounded(set
);
496 isl_die(ctx
, isl_error_unknown
,
497 "set not considered bounded", return -1);
499 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
500 bounded
= isl_set_is_bounded(set
);
507 isl_die(ctx
, isl_error_unknown
,
508 "set considered bounded", return -1);
510 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
511 bounded
= isl_set_is_bounded(set
);
517 isl_die(ctx
, isl_error_unknown
,
518 "set considered bounded", return -1);
523 /* Construct the basic set { [i] : 5 <= i <= N } */
524 static int test_construction_1(isl_ctx
*ctx
)
531 dim
= isl_space_set_alloc(ctx
, 1, 1);
532 bset
= isl_basic_set_universe(isl_space_copy(dim
));
533 ls
= isl_local_space_from_space(dim
);
535 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
536 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
537 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
538 bset
= isl_basic_set_add_constraint(bset
, c
);
540 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
541 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
542 c
= isl_constraint_set_constant_si(c
, -5);
543 bset
= isl_basic_set_add_constraint(bset
, c
);
545 isl_local_space_free(ls
);
546 isl_basic_set_free(bset
);
551 /* Construct the basic set { [x] : -100 <= x <= 100 }
552 * using isl_basic_set_{lower,upper}_bound_val and
553 * check that it is equal the same basic set parsed from a string.
555 static int test_construction_2(isl_ctx
*ctx
)
560 isl_basic_set
*bset1
, *bset2
;
562 v
= isl_val_int_from_si(ctx
, 100);
563 space
= isl_space_set_alloc(ctx
, 0, 1);
564 bset1
= isl_basic_set_universe(space
);
565 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
567 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
569 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
570 equal
= isl_basic_set_is_equal(bset1
, bset2
);
571 isl_basic_set_free(bset1
);
572 isl_basic_set_free(bset2
);
577 isl_die(ctx
, isl_error_unknown
,
578 "failed construction", return -1);
583 /* Basic tests for constructing basic sets.
585 static int test_construction(isl_ctx
*ctx
)
587 if (test_construction_1(ctx
) < 0)
589 if (test_construction_2(ctx
) < 0)
594 static int test_dim(isl_ctx
*ctx
)
597 isl_map
*map1
, *map2
;
600 map1
= isl_map_read_from_str(ctx
,
601 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
602 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
603 map2
= isl_map_read_from_str(ctx
,
604 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
605 equal
= isl_map_is_equal(map1
, map2
);
608 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
609 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
610 if (equal
>= 0 && equal
)
611 equal
= isl_map_is_equal(map1
, map2
);
619 isl_die(ctx
, isl_error_unknown
,
620 "unexpected result", return -1);
622 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
623 map1
= isl_map_read_from_str(ctx
, str
);
624 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
625 map2
= isl_map_read_from_str(ctx
, str
);
626 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
627 equal
= isl_map_is_equal(map1
, map2
);
634 isl_die(ctx
, isl_error_unknown
,
635 "unexpected result", return -1);
640 /* Check that "val" is equal to the value described by "str".
641 * If "str" is "NaN", then check for a NaN value explicitly.
643 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
650 return isl_stat_error
;
652 ctx
= isl_val_get_ctx(val
);
653 res
= isl_val_read_from_str(ctx
, str
);
654 is_nan
= isl_val_is_nan(res
);
658 ok
= isl_val_is_nan(val
);
660 ok
= isl_val_eq(val
, res
);
663 return isl_stat_error
;
665 isl_die(ctx
, isl_error_unknown
,
666 "unexpected result", return isl_stat_error
);
671 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
675 { &isl_val_neg
, "0", "0" },
676 { &isl_val_abs
, "0", "0" },
677 { &isl_val_pow2
, "0", "1" },
678 { &isl_val_floor
, "0", "0" },
679 { &isl_val_ceil
, "0", "0" },
680 { &isl_val_neg
, "1", "-1" },
681 { &isl_val_neg
, "-1", "1" },
682 { &isl_val_neg
, "1/2", "-1/2" },
683 { &isl_val_neg
, "-1/2", "1/2" },
684 { &isl_val_neg
, "infty", "-infty" },
685 { &isl_val_neg
, "-infty", "infty" },
686 { &isl_val_neg
, "NaN", "NaN" },
687 { &isl_val_abs
, "1", "1" },
688 { &isl_val_abs
, "-1", "1" },
689 { &isl_val_abs
, "1/2", "1/2" },
690 { &isl_val_abs
, "-1/2", "1/2" },
691 { &isl_val_abs
, "infty", "infty" },
692 { &isl_val_abs
, "-infty", "infty" },
693 { &isl_val_abs
, "NaN", "NaN" },
694 { &isl_val_floor
, "1", "1" },
695 { &isl_val_floor
, "-1", "-1" },
696 { &isl_val_floor
, "1/2", "0" },
697 { &isl_val_floor
, "-1/2", "-1" },
698 { &isl_val_floor
, "infty", "infty" },
699 { &isl_val_floor
, "-infty", "-infty" },
700 { &isl_val_floor
, "NaN", "NaN" },
701 { &isl_val_ceil
, "1", "1" },
702 { &isl_val_ceil
, "-1", "-1" },
703 { &isl_val_ceil
, "1/2", "1" },
704 { &isl_val_ceil
, "-1/2", "0" },
705 { &isl_val_ceil
, "infty", "infty" },
706 { &isl_val_ceil
, "-infty", "-infty" },
707 { &isl_val_ceil
, "NaN", "NaN" },
708 { &isl_val_pow2
, "-3", "1/8" },
709 { &isl_val_pow2
, "-1", "1/2" },
710 { &isl_val_pow2
, "1", "2" },
711 { &isl_val_pow2
, "2", "4" },
712 { &isl_val_pow2
, "3", "8" },
713 { &isl_val_inv
, "1", "1" },
714 { &isl_val_inv
, "2", "1/2" },
715 { &isl_val_inv
, "1/2", "2" },
716 { &isl_val_inv
, "-2", "-1/2" },
717 { &isl_val_inv
, "-1/2", "-2" },
718 { &isl_val_inv
, "0", "NaN" },
719 { &isl_val_inv
, "NaN", "NaN" },
720 { &isl_val_inv
, "infty", "0" },
721 { &isl_val_inv
, "-infty", "0" },
724 /* Perform some basic tests of unary operations on isl_val objects.
726 static int test_un_val(isl_ctx
*ctx
)
730 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
732 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
735 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
736 fn
= val_un_tests
[i
].op
;
738 r
= val_check_equal(v
, val_un_tests
[i
].res
);
748 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
749 __isl_take isl_val
*v2
);
751 ['+'] = { &isl_val_add
},
752 ['-'] = { &isl_val_sub
},
753 ['*'] = { &isl_val_mul
},
754 ['/'] = { &isl_val_div
},
755 ['g'] = { &isl_val_gcd
},
756 ['m'] = { &isl_val_min
},
757 ['M'] = { &isl_val_max
},
765 } val_bin_tests
[] = {
766 { "0", '+', "0", "0" },
767 { "1", '+', "0", "1" },
768 { "1", '+', "1", "2" },
769 { "1", '-', "1", "0" },
770 { "1", '*', "1", "1" },
771 { "1", '/', "1", "1" },
772 { "2", '*', "3", "6" },
773 { "2", '*', "1/2", "1" },
774 { "2", '*', "1/3", "2/3" },
775 { "2/3", '*', "3/5", "2/5" },
776 { "2/3", '*', "7/5", "14/15" },
777 { "2", '/', "1/2", "4" },
778 { "-2", '/', "-1/2", "4" },
779 { "-2", '/', "1/2", "-4" },
780 { "2", '/', "-1/2", "-4" },
781 { "2", '/', "2", "1" },
782 { "2", '/', "3", "2/3" },
783 { "2/3", '/', "5/3", "2/5" },
784 { "2/3", '/', "5/7", "14/15" },
785 { "0", '/', "0", "NaN" },
786 { "42", '/', "0", "NaN" },
787 { "-42", '/', "0", "NaN" },
788 { "infty", '/', "0", "NaN" },
789 { "-infty", '/', "0", "NaN" },
790 { "NaN", '/', "0", "NaN" },
791 { "0", '/', "NaN", "NaN" },
792 { "42", '/', "NaN", "NaN" },
793 { "-42", '/', "NaN", "NaN" },
794 { "infty", '/', "NaN", "NaN" },
795 { "-infty", '/', "NaN", "NaN" },
796 { "NaN", '/', "NaN", "NaN" },
797 { "0", '/', "infty", "0" },
798 { "42", '/', "infty", "0" },
799 { "-42", '/', "infty", "0" },
800 { "infty", '/', "infty", "NaN" },
801 { "-infty", '/', "infty", "NaN" },
802 { "NaN", '/', "infty", "NaN" },
803 { "0", '/', "-infty", "0" },
804 { "42", '/', "-infty", "0" },
805 { "-42", '/', "-infty", "0" },
806 { "infty", '/', "-infty", "NaN" },
807 { "-infty", '/', "-infty", "NaN" },
808 { "NaN", '/', "-infty", "NaN" },
809 { "1", '-', "1/3", "2/3" },
810 { "1/3", '+', "1/2", "5/6" },
811 { "1/2", '+', "1/2", "1" },
812 { "3/4", '-', "1/4", "1/2" },
813 { "1/2", '-', "1/3", "1/6" },
814 { "infty", '+', "42", "infty" },
815 { "infty", '+', "infty", "infty" },
816 { "42", '+', "infty", "infty" },
817 { "infty", '-', "infty", "NaN" },
818 { "infty", '*', "infty", "infty" },
819 { "infty", '*', "-infty", "-infty" },
820 { "-infty", '*', "infty", "-infty" },
821 { "-infty", '*', "-infty", "infty" },
822 { "0", '*', "infty", "NaN" },
823 { "1", '*', "infty", "infty" },
824 { "infty", '*', "0", "NaN" },
825 { "infty", '*', "42", "infty" },
826 { "42", '-', "infty", "-infty" },
827 { "infty", '+', "-infty", "NaN" },
828 { "4", 'g', "6", "2" },
829 { "5", 'g', "6", "1" },
830 { "42", 'm', "3", "3" },
831 { "42", 'M', "3", "42" },
832 { "3", 'm', "42", "3" },
833 { "3", 'M', "42", "42" },
834 { "42", 'm', "infty", "42" },
835 { "42", 'M', "infty", "infty" },
836 { "42", 'm', "-infty", "-infty" },
837 { "42", 'M', "-infty", "42" },
838 { "42", 'm', "NaN", "NaN" },
839 { "42", 'M', "NaN", "NaN" },
840 { "infty", 'm', "-infty", "-infty" },
841 { "infty", 'M', "-infty", "infty" },
844 /* Perform some basic tests of binary operations on isl_val objects.
846 static int test_bin_val(isl_ctx
*ctx
)
849 isl_val
*v1
, *v2
, *res
;
850 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
851 __isl_take isl_val
*v2
);
854 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
855 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
856 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
857 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
858 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
860 if (isl_val_is_nan(res
))
861 ok
= isl_val_is_nan(v1
);
863 ok
= isl_val_eq(v1
, res
);
869 isl_die(ctx
, isl_error_unknown
,
870 "unexpected result", return -1);
876 /* Perform some basic tests on isl_val objects.
878 static int test_val(isl_ctx
*ctx
)
880 if (test_un_val(ctx
) < 0)
882 if (test_bin_val(ctx
) < 0)
887 /* Sets described using existentially quantified variables that
888 * can also be described without.
890 static const char *elimination_tests
[] = {
891 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
892 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
893 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
896 /* Check that redundant existentially quantified variables are
899 static int test_elimination(isl_ctx
*ctx
)
905 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
906 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
907 n
= isl_basic_set_dim(bset
, isl_dim_div
);
908 isl_basic_set_free(bset
);
912 isl_die(ctx
, isl_error_unknown
,
913 "expecting no existentials", return -1);
919 static int test_div(isl_ctx
*ctx
)
926 struct isl_basic_set
*bset
;
927 struct isl_constraint
*c
;
930 dim
= isl_space_set_alloc(ctx
, 0, 3);
931 bset
= isl_basic_set_universe(isl_space_copy(dim
));
932 ls
= isl_local_space_from_space(dim
);
934 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
935 c
= isl_constraint_set_constant_si(c
, -1);
936 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
937 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
938 bset
= isl_basic_set_add_constraint(bset
, c
);
940 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
941 c
= isl_constraint_set_constant_si(c
, 1);
942 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
943 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
944 bset
= isl_basic_set_add_constraint(bset
, c
);
946 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
948 assert(bset
&& bset
->n_div
== 1);
949 isl_local_space_free(ls
);
950 isl_basic_set_free(bset
);
953 dim
= isl_space_set_alloc(ctx
, 0, 3);
954 bset
= isl_basic_set_universe(isl_space_copy(dim
));
955 ls
= isl_local_space_from_space(dim
);
957 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
958 c
= isl_constraint_set_constant_si(c
, 1);
959 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
960 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
961 bset
= isl_basic_set_add_constraint(bset
, c
);
963 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
964 c
= isl_constraint_set_constant_si(c
, -1);
965 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
966 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
967 bset
= isl_basic_set_add_constraint(bset
, c
);
969 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
971 assert(bset
&& bset
->n_div
== 1);
972 isl_local_space_free(ls
);
973 isl_basic_set_free(bset
);
976 dim
= isl_space_set_alloc(ctx
, 0, 3);
977 bset
= isl_basic_set_universe(isl_space_copy(dim
));
978 ls
= isl_local_space_from_space(dim
);
980 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
981 c
= isl_constraint_set_constant_si(c
, 1);
982 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
983 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
984 bset
= isl_basic_set_add_constraint(bset
, c
);
986 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
987 c
= isl_constraint_set_constant_si(c
, -3);
988 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
989 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
990 bset
= isl_basic_set_add_constraint(bset
, c
);
992 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
994 assert(bset
&& bset
->n_div
== 1);
995 isl_local_space_free(ls
);
996 isl_basic_set_free(bset
);
999 dim
= isl_space_set_alloc(ctx
, 0, 3);
1000 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1001 ls
= isl_local_space_from_space(dim
);
1003 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1004 c
= isl_constraint_set_constant_si(c
, 2);
1005 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1006 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1007 bset
= isl_basic_set_add_constraint(bset
, c
);
1009 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1010 c
= isl_constraint_set_constant_si(c
, -1);
1011 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1012 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1013 bset
= isl_basic_set_add_constraint(bset
, c
);
1015 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1017 assert(isl_basic_set_is_empty(bset
));
1018 isl_local_space_free(ls
);
1019 isl_basic_set_free(bset
);
1022 dim
= isl_space_set_alloc(ctx
, 0, 3);
1023 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1024 ls
= isl_local_space_from_space(dim
);
1026 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1027 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1028 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1029 bset
= isl_basic_set_add_constraint(bset
, c
);
1031 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1032 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1033 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1034 bset
= isl_basic_set_add_constraint(bset
, c
);
1036 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1038 assert(bset
&& bset
->n_div
== 0);
1039 isl_basic_set_free(bset
);
1040 isl_local_space_free(ls
);
1043 dim
= isl_space_set_alloc(ctx
, 0, 3);
1044 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1045 ls
= isl_local_space_from_space(dim
);
1047 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1048 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1049 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1050 bset
= isl_basic_set_add_constraint(bset
, c
);
1052 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1053 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1054 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1055 bset
= isl_basic_set_add_constraint(bset
, c
);
1057 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1059 assert(bset
&& bset
->n_div
== 1);
1060 isl_basic_set_free(bset
);
1061 isl_local_space_free(ls
);
1064 /* This test is a bit tricky. We set up an equality
1065 * a + 3b + 3c = 6 e0
1066 * Normalization of divs creates _two_ divs
1069 * Afterwards e0 is removed again because it has coefficient -1
1070 * and we end up with the original equality and div again.
1071 * Perhaps we can avoid the introduction of this temporary div.
1073 dim
= isl_space_set_alloc(ctx
, 0, 4);
1074 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1075 ls
= isl_local_space_from_space(dim
);
1077 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1078 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1079 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1080 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1081 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1082 bset
= isl_basic_set_add_constraint(bset
, c
);
1084 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1086 /* Test disabled for now */
1088 assert(bset && bset->n_div == 1);
1090 isl_local_space_free(ls
);
1091 isl_basic_set_free(bset
);
1094 dim
= isl_space_set_alloc(ctx
, 0, 5);
1095 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1096 ls
= isl_local_space_from_space(dim
);
1098 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1099 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1100 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1101 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1102 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1103 bset
= isl_basic_set_add_constraint(bset
, c
);
1105 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1106 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1107 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1108 c
= isl_constraint_set_constant_si(c
, 1);
1109 bset
= isl_basic_set_add_constraint(bset
, c
);
1111 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1113 /* Test disabled for now */
1115 assert(bset && bset->n_div == 1);
1117 isl_local_space_free(ls
);
1118 isl_basic_set_free(bset
);
1121 dim
= isl_space_set_alloc(ctx
, 0, 4);
1122 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1123 ls
= isl_local_space_from_space(dim
);
1125 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1126 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1127 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1128 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1129 bset
= isl_basic_set_add_constraint(bset
, c
);
1131 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1132 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1133 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1134 c
= isl_constraint_set_constant_si(c
, 2);
1135 bset
= isl_basic_set_add_constraint(bset
, c
);
1137 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1139 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1141 assert(!isl_basic_set_is_empty(bset
));
1143 isl_local_space_free(ls
);
1144 isl_basic_set_free(bset
);
1147 dim
= isl_space_set_alloc(ctx
, 0, 3);
1148 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1149 ls
= isl_local_space_from_space(dim
);
1151 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1152 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1153 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1154 bset
= isl_basic_set_add_constraint(bset
, c
);
1156 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1158 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1160 isl_local_space_free(ls
);
1161 isl_basic_set_free(bset
);
1163 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1164 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1165 set
= isl_set_read_from_str(ctx
, str
);
1166 set
= isl_set_compute_divs(set
);
1171 if (test_elimination(ctx
) < 0)
1174 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1175 set
= isl_set_read_from_str(ctx
, str
);
1176 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1177 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1178 empty
= isl_set_is_empty(set
);
1183 isl_die(ctx
, isl_error_unknown
,
1184 "result not as accurate as expected", return -1);
1189 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1193 struct isl_basic_set
*bset1
, *bset2
;
1194 struct isl_basic_map
*bmap
;
1196 filename
= get_filename(ctx
, name
, "omega");
1198 input
= fopen(filename
, "r");
1201 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1202 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1204 bset1
= isl_basic_set_apply(bset1
, bmap
);
1206 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1208 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1210 isl_basic_set_free(bset1
);
1211 isl_basic_set_free(bset2
);
1217 static int test_application(isl_ctx
*ctx
)
1219 test_application_case(ctx
, "application");
1220 test_application_case(ctx
, "application2");
1225 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1229 struct isl_basic_set
*bset1
, *bset2
;
1231 filename
= get_filename(ctx
, name
, "polylib");
1233 input
= fopen(filename
, "r");
1236 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1237 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1239 bset1
= isl_basic_set_affine_hull(bset1
);
1241 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1243 isl_basic_set_free(bset1
);
1244 isl_basic_set_free(bset2
);
1250 int test_affine_hull(struct isl_ctx
*ctx
)
1254 isl_basic_set
*bset
, *bset2
;
1258 test_affine_hull_case(ctx
, "affine2");
1259 test_affine_hull_case(ctx
, "affine");
1260 test_affine_hull_case(ctx
, "affine3");
1262 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1263 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1264 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1265 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1266 set
= isl_set_read_from_str(ctx
, str
);
1267 bset
= isl_set_affine_hull(set
);
1268 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1269 isl_basic_set_free(bset
);
1273 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1276 /* Check that isl_map_affine_hull is not confused by
1277 * the reordering of divs in isl_map_align_divs.
1279 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1280 "32e0 = b and 32e1 = c); "
1281 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1282 set
= isl_set_read_from_str(ctx
, str
);
1283 bset
= isl_set_affine_hull(set
);
1284 isl_basic_set_free(bset
);
1288 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1289 "32e2 = 31 + 31e0 }";
1290 set
= isl_set_read_from_str(ctx
, str
);
1291 bset
= isl_set_affine_hull(set
);
1292 str
= "{ [a] : exists e : a = 32 e }";
1293 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1294 subset
= isl_basic_set_is_subset(bset
, bset2
);
1295 isl_basic_set_free(bset
);
1296 isl_basic_set_free(bset2
);
1300 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1306 /* Pairs of maps and the corresponding expected results of
1307 * isl_map_plain_unshifted_simple_hull.
1312 } plain_unshifted_simple_hull_tests
[] = {
1313 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1314 "{ [i] -> [j] : i >= 1 }" },
1315 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1316 "(j mod 4 = 2 and k mod 6 = n) }",
1317 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1320 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1322 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1326 isl_basic_map
*hull
, *expected
;
1329 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1331 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1332 map
= isl_map_read_from_str(ctx
, str
);
1333 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1334 expected
= isl_basic_map_read_from_str(ctx
, str
);
1335 hull
= isl_map_plain_unshifted_simple_hull(map
);
1336 equal
= isl_basic_map_is_equal(hull
, expected
);
1337 isl_basic_map_free(hull
);
1338 isl_basic_map_free(expected
);
1342 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1349 /* Pairs of sets and the corresponding expected results of
1350 * isl_set_unshifted_simple_hull.
1355 } unshifted_simple_hull_tests
[] = {
1356 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1357 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1360 /* Basic tests for isl_set_unshifted_simple_hull.
1362 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1366 isl_basic_set
*hull
, *expected
;
1369 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1371 str
= unshifted_simple_hull_tests
[i
].set
;
1372 set
= isl_set_read_from_str(ctx
, str
);
1373 str
= unshifted_simple_hull_tests
[i
].hull
;
1374 expected
= isl_basic_set_read_from_str(ctx
, str
);
1375 hull
= isl_set_unshifted_simple_hull(set
);
1376 equal
= isl_basic_set_is_equal(hull
, expected
);
1377 isl_basic_set_free(hull
);
1378 isl_basic_set_free(expected
);
1382 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1389 static int test_simple_hull(struct isl_ctx
*ctx
)
1393 isl_basic_set
*bset
;
1396 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1397 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1398 set
= isl_set_read_from_str(ctx
, str
);
1399 bset
= isl_set_simple_hull(set
);
1400 is_empty
= isl_basic_set_is_empty(bset
);
1401 isl_basic_set_free(bset
);
1403 if (is_empty
== isl_bool_error
)
1406 if (is_empty
== isl_bool_false
)
1407 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1410 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1412 if (test_unshifted_simple_hull(ctx
) < 0)
1418 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1422 struct isl_basic_set
*bset1
, *bset2
;
1423 struct isl_set
*set
;
1425 filename
= get_filename(ctx
, name
, "polylib");
1427 input
= fopen(filename
, "r");
1430 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1431 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1433 set
= isl_basic_set_union(bset1
, bset2
);
1434 bset1
= isl_set_convex_hull(set
);
1436 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1438 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1440 isl_basic_set_free(bset1
);
1441 isl_basic_set_free(bset2
);
1450 } convex_hull_tests
[] = {
1451 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1452 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1453 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1454 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1455 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1456 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1457 "i2 <= 5 and i2 >= 4; "
1458 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1459 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1460 "i2 <= 5 + i0 and i2 >= i0 }" },
1461 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1462 "{ [x, y] : 1 = 0 }" },
1463 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1464 "[x, y, 0] : x >= 0 and y < 0 }",
1465 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1466 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1468 "[0, 2, 0]; [3, 1, 0] }",
1469 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1470 "5c <= 6 - a - 3b }" },
1473 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1476 int orig_convex
= ctx
->opt
->convex
;
1477 ctx
->opt
->convex
= convex
;
1479 test_convex_hull_case(ctx
, "convex0");
1480 test_convex_hull_case(ctx
, "convex1");
1481 test_convex_hull_case(ctx
, "convex2");
1482 test_convex_hull_case(ctx
, "convex3");
1483 test_convex_hull_case(ctx
, "convex4");
1484 test_convex_hull_case(ctx
, "convex5");
1485 test_convex_hull_case(ctx
, "convex6");
1486 test_convex_hull_case(ctx
, "convex7");
1487 test_convex_hull_case(ctx
, "convex8");
1488 test_convex_hull_case(ctx
, "convex9");
1489 test_convex_hull_case(ctx
, "convex10");
1490 test_convex_hull_case(ctx
, "convex11");
1491 test_convex_hull_case(ctx
, "convex12");
1492 test_convex_hull_case(ctx
, "convex13");
1493 test_convex_hull_case(ctx
, "convex14");
1494 test_convex_hull_case(ctx
, "convex15");
1496 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1497 isl_set
*set1
, *set2
;
1500 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1501 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1502 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1503 equal
= isl_set_is_equal(set1
, set2
);
1510 isl_die(ctx
, isl_error_unknown
,
1511 "unexpected convex hull", return -1);
1514 ctx
->opt
->convex
= orig_convex
;
1519 static int test_convex_hull(isl_ctx
*ctx
)
1521 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1523 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1528 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1532 struct isl_basic_set
*bset1
, *bset2
;
1534 filename
= get_filename(ctx
, name
, "polylib");
1536 input
= fopen(filename
, "r");
1539 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1540 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1542 bset1
= isl_basic_set_gist(bset1
, bset2
);
1544 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1546 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1548 isl_basic_set_free(bset1
);
1549 isl_basic_set_free(bset2
);
1555 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1559 const char *context
;
1561 } plain_gist_tests
[] = {
1562 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1563 "{ [i] -> [j] : i >= 1 }",
1564 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1565 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1566 "(j mod 4 = 2 and k mod 6 = n) }",
1567 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1568 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1569 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1570 "{ [i] -> [j] : i > j }",
1571 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1574 /* Basic tests for isl_map_plain_gist_basic_map.
1576 static int test_plain_gist(isl_ctx
*ctx
)
1580 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1583 isl_map
*map
, *gist
;
1584 isl_basic_map
*context
;
1586 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1587 str
= plain_gist_tests
[i
].context
;
1588 context
= isl_basic_map_read_from_str(ctx
, str
);
1589 map
= isl_map_plain_gist_basic_map(map
, context
);
1590 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1591 equal
= isl_map_is_equal(map
, gist
);
1597 isl_die(ctx
, isl_error_unknown
,
1598 "incorrect gist result", return -1);
1604 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1608 const char *context
;
1609 } gist_fail_tests
[] = {
1610 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1611 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1612 "{ [i] : i >= 0 }" },
1615 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1616 * In particular, the user should be able to recover from the failure.
1618 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1623 on_error
= isl_options_get_on_error(ctx
);
1624 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1625 n
= ARRAY_SIZE(gist_fail_tests
);
1626 for (i
= 0; i
< n
; ++i
) {
1628 isl_basic_set
*bset
, *context
;
1630 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1631 str
= gist_fail_tests
[i
].context
;
1632 context
= isl_basic_set_read_from_str(ctx
, str
);
1633 bset
= isl_basic_set_gist(bset
, context
);
1634 isl_basic_set_free(bset
);
1638 isl_options_set_on_error(ctx
, on_error
);
1640 isl_die(ctx
, isl_error_unknown
,
1641 "operation not expected to succeed",
1642 return isl_stat_error
);
1649 const char *context
;
1652 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1653 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1654 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1655 "{ [a, b, c] : a <= 15 }" },
1656 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1657 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1658 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1659 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1660 { "{ [m, n, a, b] : a <= 2147 + n }",
1661 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1662 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1663 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1665 "{ [m, n, ku, kl] }" },
1666 { "{ [a, a, b] : a >= 10 }",
1667 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1668 "{ [a, a, b] : a >= 10 }" },
1669 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1670 "{ [0, j] : j >= 0 }" },
1671 /* Check that no constraints on i6 are introduced in the gist */
1672 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1673 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1674 "5e0 <= 381 - t1 and i4 <= 1) }",
1675 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1676 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1677 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1678 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1679 "20e0 >= 1511 - 4t1 - 5i4) }" },
1680 /* Check that no constraints on i6 are introduced in the gist */
1681 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1682 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1683 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1684 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1685 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1686 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1687 "20e1 <= 1530 - 4t1 - 5i4 and "
1688 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1689 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1690 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1691 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1692 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1693 "10e0 <= -91 + 5i4 + 4i6 and "
1694 "10e0 >= -105 + 5i4 + 4i6) }",
1695 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1696 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1697 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1698 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1699 "{ [a, b, q, p] : b >= 1 + a }",
1700 "{ [a, b, q, p] : false }" },
1701 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1702 "[n] -> { [x] : x mod 32 = 0 }",
1703 "[n] -> { [x = n] }" },
1704 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1705 "{ [x] : x mod 2 = 0 }" },
1706 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1707 "{ [x] : x mod 128 = 0 }" },
1708 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1709 "{ [x] : x mod 3200 = 0 }" },
1710 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1711 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1712 "{ [a, b, c = a] }" },
1713 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1714 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1715 "{ [a, b, c = a] : a mod 3 = 0 }" },
1716 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1717 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1719 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1720 "{ [x,y] : 1 <= y <= 3 }",
1724 /* Check that isl_set_gist behaves as expected.
1726 * For the test cases in gist_tests, besides checking that the result
1727 * is as expected, also check that applying the gist operation does
1728 * not modify the input set (an earlier version of isl would do that) and
1729 * that the test case is consistent, i.e., that the gist has the same
1730 * intersection with the context as the input set.
1732 static int test_gist(struct isl_ctx
*ctx
)
1736 isl_basic_set
*bset1
, *bset2
;
1737 isl_map
*map1
, *map2
;
1741 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1742 isl_bool equal_input
, equal_intersection
;
1743 isl_set
*set1
, *set2
, *copy
, *context
;
1745 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1746 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1747 copy
= isl_set_copy(set1
);
1748 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1749 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1750 equal
= isl_set_is_equal(set1
, set2
);
1752 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1753 equal_input
= isl_set_is_equal(set1
, copy
);
1755 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1756 set2
= isl_set_intersect(set2
, context
);
1757 equal_intersection
= isl_set_is_equal(set1
, set2
);
1760 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1763 isl_die(ctx
, isl_error_unknown
,
1764 "incorrect gist result", return -1);
1766 isl_die(ctx
, isl_error_unknown
,
1767 "gist modified input", return -1);
1769 isl_die(ctx
, isl_error_unknown
,
1770 "inconsistent gist test case", return -1);
1773 if (test_gist_fail(ctx
) < 0)
1776 test_gist_case(ctx
, "gist1");
1778 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1779 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1780 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1781 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1782 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1783 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1784 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1785 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1786 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1787 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1788 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1789 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1790 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1791 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1792 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1793 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1794 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1795 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1796 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1797 bset1
= isl_basic_set_gist(bset1
, bset2
);
1798 assert(bset1
&& bset1
->n_div
== 0);
1799 isl_basic_set_free(bset1
);
1801 /* Check that the integer divisions of the second disjunct
1802 * do not spread to the first disjunct.
1804 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1805 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1806 "(exists (e0 = [(-1 + t1)/16], "
1807 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1808 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1809 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1810 "o0 <= 4294967295 and t1 <= -1)) }";
1811 map1
= isl_map_read_from_str(ctx
, str
);
1812 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1813 map2
= isl_map_read_from_str(ctx
, str
);
1814 map1
= isl_map_gist(map1
, map2
);
1818 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1819 isl_map_free(map1
); return -1);
1820 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
1825 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1828 if (test_plain_gist(ctx
) < 0)
1834 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1836 isl_set
*set
, *set2
;
1840 set
= isl_set_read_from_str(ctx
, str
);
1841 set
= isl_set_coalesce(set
);
1842 set2
= isl_set_read_from_str(ctx
, str
);
1843 equal
= isl_set_is_equal(set
, set2
);
1844 one
= set
&& set
->n
== 1;
1851 isl_die(ctx
, isl_error_unknown
,
1852 "coalesced set not equal to input", return -1);
1853 if (check_one
&& !one
)
1854 isl_die(ctx
, isl_error_unknown
,
1855 "coalesced set should not be a union", return -1);
1860 /* Inputs for coalescing tests with unbounded wrapping.
1861 * "str" is a string representation of the input set.
1862 * "single_disjunct" is set if we expect the result to consist of
1863 * a single disjunct.
1866 int single_disjunct
;
1868 } coalesce_unbounded_tests
[] = {
1869 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1870 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1871 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1872 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1874 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1875 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1876 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1877 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1880 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1881 * option turned off.
1883 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1889 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1890 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1892 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1893 const char *str
= coalesce_unbounded_tests
[i
].str
;
1894 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1895 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1901 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1906 /* Inputs for coalescing tests.
1907 * "str" is a string representation of the input set.
1908 * "single_disjunct" is set if we expect the result to consist of
1909 * a single disjunct.
1912 int single_disjunct
;
1914 } coalesce_tests
[] = {
1915 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1916 "y >= x & x >= 2 & 5 >= y }" },
1917 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1918 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1919 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1920 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1921 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1922 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1923 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1924 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1925 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1926 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1927 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1928 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1929 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1930 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1931 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1932 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1933 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1934 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1935 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1936 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1937 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1938 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1939 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1940 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1941 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1942 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1943 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1944 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1945 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1946 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1947 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1948 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1949 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1950 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1951 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1952 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1953 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1954 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1955 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1956 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1957 "[o0, o1, o2, o3, o4, o5, o6]] : "
1958 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1959 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1960 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1961 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1962 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1963 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1964 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1965 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1966 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1967 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1968 "o6 >= i3 + i6 - o3 and M >= 0 and "
1969 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1970 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1971 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1972 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1973 "(o0 = 0 and M >= 2 and N >= 3) or "
1974 "(M = 0 and o0 = 0 and N >= 3) }" },
1975 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1976 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1977 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1978 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1979 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1980 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1981 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1982 "(y = 3 and x = 1) }" },
1983 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1984 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1985 "i1 <= M and i3 <= M and i4 <= M) or "
1986 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1987 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1988 "i4 <= -1 + M) }" },
1989 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1990 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1991 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1992 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1993 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1994 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1995 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1996 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1997 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1998 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1999 { 0, "{ [a, b] : exists e : 2e = a and "
2000 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2001 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2002 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2003 "j >= 1 and j' <= i + j - i' and i >= 1; "
2005 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2006 "[i,j] : exists a : j = 3a }" },
2007 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2008 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2010 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2011 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2012 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2013 "c <= 6 + 8a and a >= 3; "
2014 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2015 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2016 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2017 "[x,0] : 3 <= x <= 4 }" },
2018 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2019 "[x,0] : 4 <= x <= 5 }" },
2020 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2021 "[x,0] : 3 <= x <= 5 }" },
2022 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2023 "[x,0] : 3 <= x <= 4 }" },
2024 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2026 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2027 { 1, "{ [0,0]; [1,1] }" },
2028 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2029 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2031 "[k, 0, k] : k <= 6 and k >= 1 }" },
2032 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2033 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2034 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2035 { 1, "[n] -> { [1] : n >= 0;"
2036 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2037 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2038 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2039 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2040 "2e0 <= x and 2e0 <= n);"
2041 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2043 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2044 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2045 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2047 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2048 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2050 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2051 "t1 >= 13 and t1 <= 16);"
2052 "[t1] : t1 <= 15 and t1 >= 12 }" },
2053 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2054 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2055 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2056 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2057 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2058 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2060 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2061 "(exists (e0 : 3e0 = -2 + c0)) }" },
2062 { 0, "[n, b0, t0] -> "
2063 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2064 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2065 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2066 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2067 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2068 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2069 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2070 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2071 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2072 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2073 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2074 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2075 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2076 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2077 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2078 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2079 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2080 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2081 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2082 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2083 { 0, "{ [i0, i1, i2] : "
2084 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2085 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2086 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2087 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2088 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2089 "32e0 <= 31 + i0)) or "
2091 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2092 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2093 "2*floor((c)/2) = c and 0 <= a <= 192;"
2094 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2096 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2097 "(0 <= a <= b <= n) }" },
2098 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2099 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2100 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2101 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2102 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2103 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2104 "b = 3 and 9e0 <= -19 + 2c)) }" },
2105 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2106 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2107 "(a = 4 and b = 3 and "
2108 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2109 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2110 "(b = -1 + a and 0 < a <= 3 and "
2111 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2112 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2113 "b = 3 and 9e0 <= -19 + 2c)) }" },
2114 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2116 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2118 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2119 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2120 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2121 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2122 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2123 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2124 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2125 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2126 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2127 { 1, "{ [a] : a <= 8 and "
2128 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2129 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2130 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2131 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2132 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2133 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2134 "(a < 0 and 3*floor((a)/3) < a) }" },
2135 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2136 "(a < -1 and 3*floor((a)/3) < a) }" },
2137 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2138 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2139 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2140 "or (2 <= a <= 15 and b < a)) }" },
2141 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2142 "32*floor((a)/32) < a) or a <= 15) }" },
2143 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2144 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2145 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2146 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2147 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2148 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2149 "S_0[n] : n <= m <= 2 + n }" },
2150 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2151 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2153 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2154 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2155 "2e0 < -a + 2b) }" },
2156 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2157 "[i, 0, i] : 0 <= i <= 7 }" },
2158 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2159 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2160 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2161 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2162 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2163 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2164 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2165 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2166 "a > 0 and a <= 5) }" },
2167 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2168 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2169 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2170 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2173 /* A specialized coalescing test case that would result
2174 * in a segmentation fault or a failed assertion in earlier versions of isl.
2176 static int test_coalesce_special(struct isl_ctx
*ctx
)
2179 isl_map
*map1
, *map2
;
2181 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2182 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2183 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2184 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2185 "o1 <= 239 and o1 >= 212)) or "
2186 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2187 "o1 <= 241 and o1 >= 240));"
2188 "[S_L220_OUT[] -> T7[]] -> "
2189 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2190 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2191 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2192 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2193 map1
= isl_map_read_from_str(ctx
, str
);
2194 map1
= isl_map_align_divs_internal(map1
);
2195 map1
= isl_map_coalesce(map1
);
2196 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2197 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2198 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2199 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2200 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2201 map2
= isl_map_read_from_str(ctx
, str
);
2202 map2
= isl_map_union(map2
, map1
);
2203 map2
= isl_map_align_divs_internal(map2
);
2204 map2
= isl_map_coalesce(map2
);
2212 /* A specialized coalescing test case that would result in an assertion
2213 * in an earlier version of isl.
2214 * The explicit call to isl_basic_set_union prevents the implicit
2215 * equality constraints in the first basic map from being detected prior
2216 * to the call to isl_set_coalesce, at least at the point
2217 * where this test case was introduced.
2219 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2222 isl_basic_set
*bset1
, *bset2
;
2225 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2226 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2227 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2228 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2229 set
= isl_basic_set_union(bset1
, bset2
);
2230 set
= isl_set_coalesce(set
);
2238 /* Check that calling isl_set_coalesce does not leave other sets
2239 * that may share some information with the input to isl_set_coalesce
2240 * in an inconsistent state.
2241 * In particular, older versions of isl would modify all copies
2242 * of the basic sets in the isl_set_coalesce input in a way
2243 * that could leave them in an inconsistent state.
2244 * The result of printing any other set containing one of these
2245 * basic sets would then result in an invalid set description.
2247 static int test_coalesce_special3(isl_ctx
*ctx
)
2251 isl_set
*set1
, *set2
;
2254 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2255 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2256 set2
= isl_set_read_from_str(ctx
, str
);
2257 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2258 set1
= isl_set_coalesce(set1
);
2261 p
= isl_printer_to_str(ctx
);
2262 p
= isl_printer_print_set(p
, set2
);
2264 s
= isl_printer_get_str(p
);
2265 isl_printer_free(p
);
2266 set1
= isl_set_read_from_str(ctx
, s
);
2276 /* Check that calling isl_set_coalesce on the intersection of
2277 * the sets described by "s1" and "s2" does not leave other sets
2278 * that may share some information with the input to isl_set_coalesce
2279 * in an inconsistent state.
2280 * In particular, when isl_set_coalesce detects equality constraints,
2281 * it does not immediately perform Gaussian elimination on them,
2282 * but then it needs to ensure that it is performed at some point.
2283 * The input set has implicit equality constraints in the first disjunct.
2284 * It is constructed as an intersection, because otherwise
2285 * those equality constraints would already be detected during parsing.
2287 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2288 const char *s1
, const char *s2
)
2290 isl_set
*set1
, *set2
;
2292 set1
= isl_set_read_from_str(ctx
, s1
);
2293 set2
= isl_set_read_from_str(ctx
, s2
);
2294 set1
= isl_set_intersect(set1
, set2
);
2295 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2296 set1
= isl_set_coalesce(set1
);
2300 return isl_stat_error
;
2305 /* Check that calling isl_set_coalesce does not leave other sets
2306 * that may share some information with the input to isl_set_coalesce
2307 * in an inconsistent state, for the case where one disjunct
2308 * is a subset of the other.
2310 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2312 const char *s1
, *s2
;
2314 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2315 s2
= "{ [a, b] : -1 <= -a < b }";
2316 return test_coalesce_intersection(ctx
, s1
, s2
);
2319 /* Check that calling isl_set_coalesce does not leave other sets
2320 * that may share some information with the input to isl_set_coalesce
2321 * in an inconsistent state, for the case where two disjuncts
2324 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2326 const char *s1
, *s2
;
2328 s1
= "{ [a, b, c] : b <= 0 }";
2329 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2330 return test_coalesce_intersection(ctx
, s1
, s2
);
2333 /* Check that calling isl_set_coalesce does not leave other sets
2334 * that may share some information with the input to isl_set_coalesce
2335 * in an inconsistent state, for the case where two disjuncts
2336 * can be fused and where both disjuncts have implicit equality constraints.
2338 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2340 const char *s1
, *s2
;
2342 s1
= "{ [a, b, c] : c <= 0 }";
2343 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2344 return test_coalesce_intersection(ctx
, s1
, s2
);
2347 /* Test the functionality of isl_set_coalesce.
2348 * That is, check that the output is always equal to the input
2349 * and in some cases that the result consists of a single disjunct.
2351 static int test_coalesce(struct isl_ctx
*ctx
)
2355 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2356 const char *str
= coalesce_tests
[i
].str
;
2357 int check_one
= coalesce_tests
[i
].single_disjunct
;
2358 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2362 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2364 if (test_coalesce_special(ctx
) < 0)
2366 if (test_coalesce_special2(ctx
) < 0)
2368 if (test_coalesce_special3(ctx
) < 0)
2370 if (test_coalesce_special4(ctx
) < 0)
2372 if (test_coalesce_special5(ctx
) < 0)
2374 if (test_coalesce_special6(ctx
) < 0)
2381 /* Construct a representation of the graph on the right of Figure 1
2382 * in "Computing the Transitive Closure of a Union of
2383 * Affine Integer Tuple Relations".
2385 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2388 isl_map
*up
, *right
;
2390 dom
= isl_set_read_from_str(ctx
,
2391 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2392 "2 x - 3 y + 3 >= 0 }");
2393 right
= isl_map_read_from_str(ctx
,
2394 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2395 up
= isl_map_read_from_str(ctx
,
2396 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2397 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2398 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2399 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2400 up
= isl_map_intersect_range(up
, dom
);
2401 return isl_map_union(up
, right
);
2404 /* Construct a representation of the power of the graph
2405 * on the right of Figure 1 in "Computing the Transitive Closure of
2406 * a Union of Affine Integer Tuple Relations".
2408 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2410 return isl_map_read_from_str(ctx
,
2411 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2412 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2413 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2416 /* Construct a representation of the transitive closure of the graph
2417 * on the right of Figure 1 in "Computing the Transitive Closure of
2418 * a Union of Affine Integer Tuple Relations".
2420 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2422 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2425 static int test_closure(isl_ctx
*ctx
)
2428 isl_map
*map
, *map2
;
2431 /* COCOA example 1 */
2432 map
= isl_map_read_from_str(ctx
,
2433 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2434 "1 <= i and i < n and 1 <= j and j < n or "
2435 "i2 = i + 1 and j2 = j - 1 and "
2436 "1 <= i and i < n and 2 <= j and j <= n }");
2437 map
= isl_map_power(map
, &exact
);
2441 /* COCOA example 1 */
2442 map
= isl_map_read_from_str(ctx
,
2443 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2444 "1 <= i and i < n and 1 <= j and j < n or "
2445 "i2 = i + 1 and j2 = j - 1 and "
2446 "1 <= i and i < n and 2 <= j and j <= n }");
2447 map
= isl_map_transitive_closure(map
, &exact
);
2449 map2
= isl_map_read_from_str(ctx
,
2450 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2451 "1 <= i and i < n and 1 <= j and j <= n and "
2452 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2453 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2454 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2455 assert(isl_map_is_equal(map
, map2
));
2459 map
= isl_map_read_from_str(ctx
,
2460 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2461 " 0 <= y and y <= n }");
2462 map
= isl_map_transitive_closure(map
, &exact
);
2463 map2
= isl_map_read_from_str(ctx
,
2464 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2465 " 0 <= y and y <= n }");
2466 assert(isl_map_is_equal(map
, map2
));
2470 /* COCOA example 2 */
2471 map
= isl_map_read_from_str(ctx
,
2472 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2473 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2474 "i2 = i + 2 and j2 = j - 2 and "
2475 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2476 map
= isl_map_transitive_closure(map
, &exact
);
2478 map2
= isl_map_read_from_str(ctx
,
2479 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2480 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2481 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2482 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2483 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2484 assert(isl_map_is_equal(map
, map2
));
2488 /* COCOA Fig.2 left */
2489 map
= isl_map_read_from_str(ctx
,
2490 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2491 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2493 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2494 "j <= 2 i - 3 and j <= n - 2 or "
2495 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2496 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2497 map
= isl_map_transitive_closure(map
, &exact
);
2501 /* COCOA Fig.2 right */
2502 map
= isl_map_read_from_str(ctx
,
2503 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2504 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2506 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2507 "j <= 2 i - 4 and j <= n - 3 or "
2508 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2509 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2510 map
= isl_map_power(map
, &exact
);
2514 /* COCOA Fig.2 right */
2515 map
= isl_map_read_from_str(ctx
,
2516 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2517 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2519 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2520 "j <= 2 i - 4 and j <= n - 3 or "
2521 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2522 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2523 map
= isl_map_transitive_closure(map
, &exact
);
2525 map2
= isl_map_read_from_str(ctx
,
2526 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2527 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2528 "j <= n and 3 + i + 2 j <= 3 n and "
2529 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2530 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2531 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2532 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2533 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2534 assert(isl_map_is_equal(map
, map2
));
2538 map
= cocoa_fig_1_right_graph(ctx
);
2539 map
= isl_map_transitive_closure(map
, &exact
);
2541 map2
= cocoa_fig_1_right_tc(ctx
);
2542 assert(isl_map_is_equal(map
, map2
));
2546 map
= cocoa_fig_1_right_graph(ctx
);
2547 map
= isl_map_power(map
, &exact
);
2548 map2
= cocoa_fig_1_right_power(ctx
);
2549 equal
= isl_map_is_equal(map
, map2
);
2555 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2557 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2559 /* COCOA Theorem 1 counter example */
2560 map
= isl_map_read_from_str(ctx
,
2561 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2562 "i2 = 1 and j2 = j or "
2563 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2564 map
= isl_map_transitive_closure(map
, &exact
);
2568 map
= isl_map_read_from_str(ctx
,
2569 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2570 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2571 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2572 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2573 map
= isl_map_transitive_closure(map
, &exact
);
2577 /* Kelly et al 1996, fig 12 */
2578 map
= isl_map_read_from_str(ctx
,
2579 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2580 "1 <= i,j,j+1 <= n or "
2581 "j = n and j2 = 1 and i2 = i + 1 and "
2582 "1 <= i,i+1 <= n }");
2583 map
= isl_map_transitive_closure(map
, &exact
);
2585 map2
= isl_map_read_from_str(ctx
,
2586 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2587 "1 <= i <= n and i = i2 or "
2588 "1 <= i < i2 <= n and 1 <= j <= n and "
2590 assert(isl_map_is_equal(map
, map2
));
2594 /* Omega's closure4 */
2595 map
= isl_map_read_from_str(ctx
,
2596 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2597 "1 <= x,y <= 10 or "
2598 "x2 = x + 1 and y2 = y and "
2599 "1 <= x <= 20 && 5 <= y <= 15 }");
2600 map
= isl_map_transitive_closure(map
, &exact
);
2604 map
= isl_map_read_from_str(ctx
,
2605 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2606 map
= isl_map_transitive_closure(map
, &exact
);
2608 map2
= isl_map_read_from_str(ctx
,
2609 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2610 assert(isl_map_is_equal(map
, map2
));
2614 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2615 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2616 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2617 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2618 map
= isl_map_read_from_str(ctx
, str
);
2619 map
= isl_map_transitive_closure(map
, &exact
);
2621 map2
= isl_map_read_from_str(ctx
, str
);
2622 assert(isl_map_is_equal(map
, map2
));
2626 str
= "{[0] -> [1]; [2] -> [3]}";
2627 map
= isl_map_read_from_str(ctx
, str
);
2628 map
= isl_map_transitive_closure(map
, &exact
);
2630 map2
= isl_map_read_from_str(ctx
, str
);
2631 assert(isl_map_is_equal(map
, map2
));
2635 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2636 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2637 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2638 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2639 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2640 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2641 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2642 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2643 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2644 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2645 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2646 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2647 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2648 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2649 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2650 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2651 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2652 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2653 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2654 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2655 map
= isl_map_read_from_str(ctx
, str
);
2656 map
= isl_map_transitive_closure(map
, NULL
);
2663 /* Check that the actual result of a boolean operation is equal
2664 * to the expected result.
2666 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2668 if (actual
!= expected
)
2669 isl_die(ctx
, isl_error_unknown
,
2670 "incorrect boolean operation", return isl_stat_error
);
2674 /* Test operations on isl_bool values.
2681 static int test_isl_bool(isl_ctx
*ctx
)
2683 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
2685 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
2687 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
2689 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
2691 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
2693 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
2695 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
2697 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
2703 static int test_lex(struct isl_ctx
*ctx
)
2709 dim
= isl_space_set_alloc(ctx
, 0, 0);
2710 map
= isl_map_lex_le(dim
);
2711 empty
= isl_map_is_empty(map
);
2717 isl_die(ctx
, isl_error_unknown
,
2718 "expecting non-empty result", return -1);
2723 /* Inputs for isl_map_lexmin tests.
2724 * "map" is the input and "lexmin" is the expected result.
2729 } lexmin_tests
[] = {
2730 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2731 "{ [x] -> [5] : 6 <= x <= 8; "
2732 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2733 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2734 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2735 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2736 "{ [x] -> [y] : (4y = x and x >= 0) or "
2737 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2738 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2739 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2740 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2741 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2742 /* Check that empty pieces are properly combined. */
2743 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2744 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2745 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2746 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2747 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2749 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2750 "a <= 255 and c <= 255 and d <= 255 - j and "
2751 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2752 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2753 "247d <= 247 + i and 248 - b <= 248d <= c and "
2754 "254d >= i - a + b and 254d >= -a + b and "
2755 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2757 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2758 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2759 "247j >= 62738 - i and 509j <= 129795 + i and "
2760 "742j >= 188724 - i; "
2761 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2762 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2763 "16*floor((8 + b)/16) <= 7 + b; "
2765 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2766 "[a] -> [b = 0] : 0 < a <= 509 }" },
2767 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2768 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2771 static int test_lexmin(struct isl_ctx
*ctx
)
2776 isl_basic_map
*bmap
;
2777 isl_map
*map
, *map2
;
2780 isl_pw_multi_aff
*pma
;
2782 str
= "[p0, p1] -> { [] -> [] : "
2783 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2784 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2785 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2786 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2787 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2788 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2789 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2790 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2791 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2792 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2793 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2794 map
= isl_map_read_from_str(ctx
, str
);
2795 map
= isl_map_lexmin(map
);
2798 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2799 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2800 set
= isl_set_read_from_str(ctx
, str
);
2801 set
= isl_set_lexmax(set
);
2802 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2803 set2
= isl_set_read_from_str(ctx
, str
);
2804 set
= isl_set_intersect(set
, set2
);
2805 assert(!isl_set_is_empty(set
));
2808 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2809 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2810 map
= isl_map_lexmin(map
);
2811 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2812 equal
= isl_map_is_equal(map
, map2
);
2819 isl_die(ctx
, isl_error_unknown
,
2820 "unexpected result", return -1);
2823 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2824 " 8i' <= i and 8i' >= -7 + i }";
2825 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2826 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2827 map2
= isl_map_from_pw_multi_aff(pma
);
2828 map
= isl_map_from_basic_map(bmap
);
2829 assert(isl_map_is_equal(map
, map2
));
2833 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2834 " 8i' <= i and 8i' >= -7 + i }";
2835 set
= isl_set_read_from_str(ctx
, str
);
2836 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2837 set2
= isl_set_from_pw_multi_aff(pma
);
2838 equal
= isl_set_is_equal(set
, set2
);
2844 isl_die(ctx
, isl_error_unknown
,
2845 "unexpected difference between set and "
2846 "piecewise affine expression", return -1);
2851 /* A specialized isl_set_min_val test case that would return the wrong result
2852 * in earlier versions of isl.
2853 * The explicit call to isl_basic_set_union prevents the second basic set
2854 * from being determined to be empty prior to the call to isl_set_min_val,
2855 * at least at the point where this test case was introduced.
2857 static int test_min_special(isl_ctx
*ctx
)
2860 isl_basic_set
*bset1
, *bset2
;
2866 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2867 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2868 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2869 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2870 set
= isl_basic_set_union(bset1
, bset2
);
2871 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2873 res
= isl_set_min_val(set
, obj
);
2874 ok
= isl_val_cmp_si(res
, 5) == 0;
2883 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2889 /* A specialized isl_set_min_val test case that would return an error
2890 * in earlier versions of isl.
2892 static int test_min_special2(isl_ctx
*ctx
)
2895 isl_basic_set
*bset
;
2899 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2900 bset
= isl_basic_set_read_from_str(ctx
, str
);
2902 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2904 res
= isl_basic_set_max_val(bset
, obj
);
2906 isl_basic_set_free(bset
);
2919 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2920 __isl_keep isl_aff
*obj
);
2923 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2924 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2925 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2926 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2927 &isl_set_max_val
, "30" },
2931 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2932 * In particular, check the results on non-convex inputs.
2934 static int test_min(struct isl_ctx
*ctx
)
2942 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2943 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2944 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2945 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2946 val
= opt_tests
[i
].fn(set
, obj
);
2947 ok
= isl_val_eq(res
, val
);
2956 isl_die(ctx
, isl_error_unknown
,
2957 "unexpected optimum", return -1);
2960 if (test_min_special(ctx
) < 0)
2962 if (test_min_special2(ctx
) < 0)
2973 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2974 void *dep_user
, void *user
)
2976 struct must_may
*mm
= (struct must_may
*)user
;
2979 mm
->must
= isl_map_union(mm
->must
, dep
);
2981 mm
->may
= isl_map_union(mm
->may
, dep
);
2986 static int common_space(void *first
, void *second
)
2988 int depth
= *(int *)first
;
2992 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3000 map2
= isl_map_read_from_str(map
->ctx
, str
);
3001 equal
= isl_map_is_equal(map
, map2
);
3007 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3011 equal
= map_is_equal(map
, str
);
3015 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3016 "result not as expected", return -1);
3020 static int test_dep(struct isl_ctx
*ctx
)
3025 isl_access_info
*ai
;
3032 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3033 map
= isl_map_read_from_str(ctx
, str
);
3034 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3036 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3037 map
= isl_map_read_from_str(ctx
, str
);
3038 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3040 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3041 map
= isl_map_read_from_str(ctx
, str
);
3042 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3044 flow
= isl_access_info_compute_flow(ai
);
3045 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3046 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3047 mm
.may
= isl_map_empty(dim
);
3049 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3051 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3052 " [1,10,0] -> [2,5,0] }";
3053 assert(map_is_equal(mm
.must
, str
));
3054 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3055 assert(map_is_equal(mm
.may
, str
));
3057 isl_map_free(mm
.must
);
3058 isl_map_free(mm
.may
);
3059 isl_flow_free(flow
);
3062 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3063 map
= isl_map_read_from_str(ctx
, str
);
3064 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3066 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3067 map
= isl_map_read_from_str(ctx
, str
);
3068 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3070 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3071 map
= isl_map_read_from_str(ctx
, str
);
3072 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3074 flow
= isl_access_info_compute_flow(ai
);
3075 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3076 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3077 mm
.may
= isl_map_empty(dim
);
3079 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3081 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3082 assert(map_is_equal(mm
.must
, str
));
3083 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3084 assert(map_is_equal(mm
.may
, str
));
3086 isl_map_free(mm
.must
);
3087 isl_map_free(mm
.may
);
3088 isl_flow_free(flow
);
3091 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3092 map
= isl_map_read_from_str(ctx
, str
);
3093 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3095 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3096 map
= isl_map_read_from_str(ctx
, str
);
3097 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3099 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3100 map
= isl_map_read_from_str(ctx
, str
);
3101 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3103 flow
= isl_access_info_compute_flow(ai
);
3104 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3105 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3106 mm
.may
= isl_map_empty(dim
);
3108 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3110 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3111 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3112 assert(map_is_equal(mm
.may
, str
));
3113 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3114 assert(map_is_equal(mm
.must
, str
));
3116 isl_map_free(mm
.must
);
3117 isl_map_free(mm
.may
);
3118 isl_flow_free(flow
);
3121 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3122 map
= isl_map_read_from_str(ctx
, str
);
3123 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3125 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3126 map
= isl_map_read_from_str(ctx
, str
);
3127 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3129 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3130 map
= isl_map_read_from_str(ctx
, str
);
3131 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3133 flow
= isl_access_info_compute_flow(ai
);
3134 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3135 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3136 mm
.may
= isl_map_empty(dim
);
3138 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3140 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3141 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3142 assert(map_is_equal(mm
.may
, str
));
3143 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3144 assert(map_is_equal(mm
.must
, str
));
3146 isl_map_free(mm
.must
);
3147 isl_map_free(mm
.may
);
3148 isl_flow_free(flow
);
3151 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3152 map
= isl_map_read_from_str(ctx
, str
);
3153 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3155 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3156 map
= isl_map_read_from_str(ctx
, str
);
3157 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3159 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3160 map
= isl_map_read_from_str(ctx
, str
);
3161 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3163 flow
= isl_access_info_compute_flow(ai
);
3164 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3165 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3166 mm
.may
= isl_map_empty(dim
);
3168 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3170 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3171 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3172 assert(map_is_equal(mm
.may
, str
));
3173 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3174 assert(map_is_equal(mm
.must
, str
));
3176 isl_map_free(mm
.must
);
3177 isl_map_free(mm
.may
);
3178 isl_flow_free(flow
);
3183 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3184 map
= isl_map_read_from_str(ctx
, str
);
3185 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3187 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3188 map
= isl_map_read_from_str(ctx
, str
);
3189 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3191 flow
= isl_access_info_compute_flow(ai
);
3192 dim
= isl_space_alloc(ctx
, 0, 5, 5);
3193 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3194 mm
.may
= isl_map_empty(dim
);
3196 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3198 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3199 assert(map_is_equal(mm
.must
, str
));
3200 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3201 assert(map_is_equal(mm
.may
, str
));
3203 isl_map_free(mm
.must
);
3204 isl_map_free(mm
.may
);
3205 isl_flow_free(flow
);
3210 /* Check that the dependence analysis proceeds without errors.
3211 * Earlier versions of isl would break down during the analysis
3212 * due to the use of the wrong spaces.
3214 static int test_flow(isl_ctx
*ctx
)
3217 isl_union_map
*access
, *schedule
;
3218 isl_union_map
*must_dep
, *may_dep
;
3221 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3222 access
= isl_union_map_read_from_str(ctx
, str
);
3223 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3224 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3225 "S2[] -> [1,0,0,0]; "
3226 "S3[] -> [-1,0,0,0] }";
3227 schedule
= isl_union_map_read_from_str(ctx
, str
);
3228 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3229 isl_union_map_copy(access
), schedule
,
3230 &must_dep
, &may_dep
, NULL
, NULL
);
3231 isl_union_map_free(may_dep
);
3232 isl_union_map_free(must_dep
);
3241 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3242 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3243 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3244 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3245 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3246 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3247 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3248 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3249 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3252 int test_sv(isl_ctx
*ctx
)
3254 isl_union_map
*umap
;
3258 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3259 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3260 sv
= isl_union_map_is_single_valued(umap
);
3261 isl_union_map_free(umap
);
3264 if (sv_tests
[i
].sv
&& !sv
)
3265 isl_die(ctx
, isl_error_internal
,
3266 "map not detected as single valued", return -1);
3267 if (!sv_tests
[i
].sv
&& sv
)
3268 isl_die(ctx
, isl_error_internal
,
3269 "map detected as single valued", return -1);
3278 } bijective_tests
[] = {
3279 { "[N,M]->{[i,j] -> [i]}", 0 },
3280 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3281 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3282 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3283 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3284 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3285 { "[N,M]->{[i,j] -> []}", 0 },
3286 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3287 { "[N,M]->{[i,j] -> [2i]}", 0 },
3288 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3289 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3290 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3291 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3294 static int test_bijective(struct isl_ctx
*ctx
)
3300 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3301 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3302 bijective
= isl_map_is_bijective(map
);
3306 if (bijective_tests
[i
].bijective
&& !bijective
)
3307 isl_die(ctx
, isl_error_internal
,
3308 "map not detected as bijective", return -1);
3309 if (!bijective_tests
[i
].bijective
&& bijective
)
3310 isl_die(ctx
, isl_error_internal
,
3311 "map detected as bijective", return -1);
3317 /* Inputs for isl_pw_qpolynomial_gist tests.
3318 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3324 } pwqp_gist_tests
[] = {
3325 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3326 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3327 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3328 "{ [i] -> -1/2 + 1/2 * i }" },
3329 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3332 static int test_pwqp(struct isl_ctx
*ctx
)
3337 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3340 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3341 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3343 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3346 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3347 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3349 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3351 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3353 isl_pw_qpolynomial_free(pwqp1
);
3355 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3356 str
= pwqp_gist_tests
[i
].pwqp
;
3357 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3358 str
= pwqp_gist_tests
[i
].set
;
3359 set
= isl_set_read_from_str(ctx
, str
);
3360 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3361 str
= pwqp_gist_tests
[i
].gist
;
3362 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3363 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3364 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3365 isl_pw_qpolynomial_free(pwqp1
);
3370 isl_die(ctx
, isl_error_unknown
,
3371 "unexpected result", return -1);
3374 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3375 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3376 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3377 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3379 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3381 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3383 isl_pw_qpolynomial_free(pwqp1
);
3385 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3386 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3387 str
= "{ [x] -> x }";
3388 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3390 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3392 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3394 isl_pw_qpolynomial_free(pwqp1
);
3396 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3397 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3398 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3399 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3400 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3401 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3402 isl_pw_qpolynomial_free(pwqp1
);
3404 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3405 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3406 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3407 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3408 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3409 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3410 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3411 isl_pw_qpolynomial_free(pwqp1
);
3412 isl_pw_qpolynomial_free(pwqp2
);
3416 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3418 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3419 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3420 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3421 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3422 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3424 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3425 isl_pw_qpolynomial_free(pwqp1
);
3426 isl_pw_qpolynomial_free(pwqp2
);
3430 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3435 static int test_split_periods(isl_ctx
*ctx
)
3438 isl_pw_qpolynomial
*pwqp
;
3440 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3441 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3442 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3443 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3445 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3447 isl_pw_qpolynomial_free(pwqp
);
3455 static int test_union(isl_ctx
*ctx
)
3458 isl_union_set
*uset1
, *uset2
;
3459 isl_union_map
*umap1
, *umap2
;
3462 str
= "{ [i] : 0 <= i <= 1 }";
3463 uset1
= isl_union_set_read_from_str(ctx
, str
);
3464 str
= "{ [1] -> [0] }";
3465 umap1
= isl_union_map_read_from_str(ctx
, str
);
3467 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3468 equal
= isl_union_map_is_equal(umap1
, umap2
);
3470 isl_union_map_free(umap1
);
3471 isl_union_map_free(umap2
);
3476 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3479 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3480 umap1
= isl_union_map_read_from_str(ctx
, str
);
3481 str
= "{ A[i]; B[i] }";
3482 uset1
= isl_union_set_read_from_str(ctx
, str
);
3484 uset2
= isl_union_map_domain(umap1
);
3486 equal
= isl_union_set_is_equal(uset1
, uset2
);
3488 isl_union_set_free(uset1
);
3489 isl_union_set_free(uset2
);
3494 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3500 /* Check that computing a bound of a non-zero polynomial over an unbounded
3501 * domain does not produce a rational value.
3502 * In particular, check that the upper bound is infinity.
3504 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3507 isl_pw_qpolynomial
*pwqp
;
3508 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3511 str
= "{ [m,n] -> -m * n }";
3512 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3513 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3515 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3516 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3517 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3518 isl_pw_qpolynomial_fold_free(pwf
);
3519 isl_pw_qpolynomial_fold_free(pwf2
);
3524 isl_die(ctx
, isl_error_unknown
,
3525 "expecting infinite polynomial bound", return -1);
3530 static int test_bound(isl_ctx
*ctx
)
3534 isl_pw_qpolynomial
*pwqp
;
3535 isl_pw_qpolynomial_fold
*pwf
;
3537 if (test_bound_unbounded_domain(ctx
) < 0)
3540 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3541 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3542 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3543 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3544 isl_pw_qpolynomial_fold_free(pwf
);
3548 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3551 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3552 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3553 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3554 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3555 isl_pw_qpolynomial_fold_free(pwf
);
3559 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3565 /* isl_set is defined to isl_map internally, so the corresponding elements
3566 * are isl_basic_map objects.
3570 #define EL_BASE basic_map
3571 #define SET_BASE set
3572 #include "isl_test_list_templ.c"
3576 #define EL_BASE basic_set
3577 #define SET_BASE union_set
3578 #include "isl_test_list_templ.c"
3583 #define SET_BASE union_set
3584 #include "isl_test_list_templ.c"
3588 #define EL_BASE basic_map
3589 #define SET_BASE map
3590 #include "isl_test_list_templ.c"
3595 #define SET_BASE union_map
3596 #include "isl_test_list_templ.c"
3598 /* Check that the conversion from isl objects to lists works as expected.
3600 static int test_get_list(isl_ctx
*ctx
)
3602 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
3604 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
3606 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
3608 if (test_get_list_basic_map_from_map(ctx
,
3609 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3611 if (test_get_list_map_from_union_map(ctx
,
3612 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3618 static int test_lift(isl_ctx
*ctx
)
3621 isl_basic_map
*bmap
;
3622 isl_basic_set
*bset
;
3624 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3625 bset
= isl_basic_set_read_from_str(ctx
, str
);
3626 bset
= isl_basic_set_lift(bset
);
3627 bmap
= isl_basic_map_from_range(bset
);
3628 bset
= isl_basic_map_domain(bmap
);
3629 isl_basic_set_free(bset
);
3634 /* Check that isl_set_is_subset is not confused by identical
3635 * integer divisions.
3636 * The call to isl_set_normalize ensures that the equality constraints
3637 * a = b = 0 are discovered, turning e0 and e1 into identical
3638 * integer divisions. Any further simplification would remove
3639 * the duplicate integer divisions.
3641 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
3645 isl_set
*set1
, *set2
;
3647 str
= "{ [a, b, c, d] : "
3648 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
3649 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
3650 "e3 = floor((-d + 4*floor((d)/4))/10): "
3651 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
3652 "b >= 0 and a <= 0 and b <= a) }";
3653 set1
= isl_set_read_from_str(ctx
, str
);
3654 set2
= isl_set_read_from_str(ctx
, str
);
3655 set2
= isl_set_normalize(set2
);
3657 is_subset
= isl_set_is_subset(set1
, set2
);
3663 return isl_stat_error
;
3665 isl_die(ctx
, isl_error_unknown
,
3666 "set is not considered to be a subset of itself",
3667 return isl_stat_error
);
3676 } subset_tests
[] = {
3678 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3679 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3680 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3682 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3683 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3684 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3685 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3686 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3687 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3688 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3689 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3690 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3691 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3692 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3693 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3694 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3695 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3696 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3697 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3698 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3699 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3700 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3701 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3702 "4e0 <= -57 + i0 + i1)) or "
3703 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3704 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3705 "4e0 >= -61 + i0 + i1)) or "
3706 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3707 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3710 static int test_subset(isl_ctx
*ctx
)
3713 isl_set
*set1
, *set2
;
3716 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
3719 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3720 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3721 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3722 subset
= isl_set_is_subset(set1
, set2
);
3727 if (subset
!= subset_tests
[i
].subset
)
3728 isl_die(ctx
, isl_error_unknown
,
3729 "incorrect subset result", return -1);
3736 const char *minuend
;
3737 const char *subtrahend
;
3738 const char *difference
;
3739 } subtract_domain_tests
[] = {
3740 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3741 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3742 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3745 static int test_subtract(isl_ctx
*ctx
)
3748 isl_union_map
*umap1
, *umap2
;
3749 isl_union_pw_multi_aff
*upma1
, *upma2
;
3750 isl_union_set
*uset
;
3753 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3754 umap1
= isl_union_map_read_from_str(ctx
,
3755 subtract_domain_tests
[i
].minuend
);
3756 uset
= isl_union_set_read_from_str(ctx
,
3757 subtract_domain_tests
[i
].subtrahend
);
3758 umap2
= isl_union_map_read_from_str(ctx
,
3759 subtract_domain_tests
[i
].difference
);
3760 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3761 equal
= isl_union_map_is_equal(umap1
, umap2
);
3762 isl_union_map_free(umap1
);
3763 isl_union_map_free(umap2
);
3767 isl_die(ctx
, isl_error_unknown
,
3768 "incorrect subtract domain result", return -1);
3771 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3772 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3773 subtract_domain_tests
[i
].minuend
);
3774 uset
= isl_union_set_read_from_str(ctx
,
3775 subtract_domain_tests
[i
].subtrahend
);
3776 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3777 subtract_domain_tests
[i
].difference
);
3778 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3779 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3780 isl_union_pw_multi_aff_free(upma1
);
3781 isl_union_pw_multi_aff_free(upma2
);
3785 isl_die(ctx
, isl_error_unknown
,
3786 "incorrect subtract domain result", return -1);
3792 /* Check that intersecting the empty basic set with another basic set
3793 * does not increase the number of constraints. In particular,
3794 * the empty basic set should maintain its canonical representation.
3796 static int test_intersect_1(isl_ctx
*ctx
)
3799 isl_basic_set
*bset1
, *bset2
;
3801 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3802 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3803 n1
= isl_basic_set_n_constraint(bset1
);
3804 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3805 n2
= isl_basic_set_n_constraint(bset1
);
3806 isl_basic_set_free(bset1
);
3807 if (n1
< 0 || n2
< 0)
3810 isl_die(ctx
, isl_error_unknown
,
3811 "number of constraints of empty set changed",
3817 /* Check that intersecting a set with itself does not cause
3818 * an explosion in the number of disjuncts.
3820 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
3825 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
3826 for (i
= 0; i
< 100; ++i
)
3827 set
= isl_set_intersect(set
, isl_set_copy(set
));
3830 return isl_stat_error
;
3834 /* Perform some intersection tests.
3836 static int test_intersect(isl_ctx
*ctx
)
3838 if (test_intersect_1(ctx
) < 0)
3840 if (test_intersect_2(ctx
) < 0)
3846 int test_factorize(isl_ctx
*ctx
)
3849 isl_basic_set
*bset
;
3852 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3853 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3854 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3855 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3856 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3857 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3858 "3i5 >= -2i0 - i2 + 3i4 }";
3859 bset
= isl_basic_set_read_from_str(ctx
, str
);
3860 f
= isl_basic_set_factorizer(bset
);
3861 isl_basic_set_free(bset
);
3862 isl_factorizer_free(f
);
3864 isl_die(ctx
, isl_error_unknown
,
3865 "failed to construct factorizer", return -1);
3867 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3868 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3869 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3870 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3871 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3872 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3873 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3874 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3875 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3876 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3877 bset
= isl_basic_set_read_from_str(ctx
, str
);
3878 f
= isl_basic_set_factorizer(bset
);
3879 isl_basic_set_free(bset
);
3880 isl_factorizer_free(f
);
3882 isl_die(ctx
, isl_error_unknown
,
3883 "failed to construct factorizer", return -1);
3888 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3890 int *injective
= user
;
3892 *injective
= isl_map_is_injective(map
);
3895 if (*injective
< 0 || !*injective
)
3896 return isl_stat_error
;
3901 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3902 const char *r
, const char *s
, int tilable
, int parallel
)
3906 isl_union_map
*W
, *R
, *S
;
3907 isl_union_map
*empty
;
3908 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3909 isl_union_map
*validity
, *proximity
, *coincidence
;
3910 isl_union_map
*schedule
;
3911 isl_union_map
*test
;
3912 isl_union_set
*delta
;
3913 isl_union_set
*domain
;
3917 isl_schedule_constraints
*sc
;
3918 isl_schedule
*sched
;
3919 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3922 D
= isl_union_set_read_from_str(ctx
, d
);
3923 W
= isl_union_map_read_from_str(ctx
, w
);
3924 R
= isl_union_map_read_from_str(ctx
, r
);
3925 S
= isl_union_map_read_from_str(ctx
, s
);
3927 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3928 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3930 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3931 isl_union_map_compute_flow(isl_union_map_copy(R
),
3932 isl_union_map_copy(W
), empty
,
3933 isl_union_map_copy(S
),
3934 &dep_raw
, NULL
, NULL
, NULL
);
3935 isl_union_map_compute_flow(isl_union_map_copy(W
),
3936 isl_union_map_copy(W
),
3937 isl_union_map_copy(R
),
3938 isl_union_map_copy(S
),
3939 &dep_waw
, &dep_war
, NULL
, NULL
);
3941 dep
= isl_union_map_union(dep_waw
, dep_war
);
3942 dep
= isl_union_map_union(dep
, dep_raw
);
3943 validity
= isl_union_map_copy(dep
);
3944 coincidence
= isl_union_map_copy(dep
);
3945 proximity
= isl_union_map_copy(dep
);
3947 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3948 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3949 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3950 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3951 sched
= isl_schedule_constraints_compute_schedule(sc
);
3952 schedule
= isl_schedule_get_map(sched
);
3953 isl_schedule_free(sched
);
3954 isl_union_map_free(W
);
3955 isl_union_map_free(R
);
3956 isl_union_map_free(S
);
3959 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3961 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3962 is_complete
= isl_union_set_is_subset(D
, domain
);
3963 isl_union_set_free(D
);
3964 isl_union_set_free(domain
);
3966 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3967 test
= isl_union_map_apply_range(test
, dep
);
3968 test
= isl_union_map_apply_range(test
, schedule
);
3970 delta
= isl_union_map_deltas(test
);
3971 n
= isl_union_set_n_set(delta
);
3973 isl_union_set_free(delta
);
3980 isl_union_set_free(delta
);
3984 delta_set
= isl_set_from_union_set(delta
);
3986 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3987 for (i
= 0; i
< tilable
; ++i
)
3988 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3989 is_tilable
= isl_set_is_subset(delta_set
, slice
);
3990 isl_set_free(slice
);
3992 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3993 for (i
= 0; i
< parallel
; ++i
)
3994 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
3995 is_parallel
= isl_set_is_subset(delta_set
, slice
);
3996 isl_set_free(slice
);
3998 origin
= isl_set_universe(isl_set_get_space(delta_set
));
3999 dim
= isl_set_dim(origin
, isl_dim_set
);
4001 origin
= isl_set_free(origin
);
4002 for (i
= 0; i
< dim
; ++i
)
4003 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4005 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4006 delta_set
= isl_set_lexmin(delta_set
);
4008 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4010 isl_set_free(origin
);
4011 isl_set_free(delta_set
);
4014 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4015 is_injection
< 0 || is_complete
< 0)
4018 isl_die(ctx
, isl_error_unknown
,
4019 "generated schedule incomplete", return -1);
4021 isl_die(ctx
, isl_error_unknown
,
4022 "generated schedule not injective on each statement",
4025 isl_die(ctx
, isl_error_unknown
,
4026 "negative dependences in generated schedule",
4029 isl_die(ctx
, isl_error_unknown
,
4030 "generated schedule not as tilable as expected",
4033 isl_die(ctx
, isl_error_unknown
,
4034 "generated schedule not as parallel as expected",
4040 /* Compute a schedule for the given instance set, validity constraints,
4041 * proximity constraints and context and return a corresponding union map
4044 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4045 const char *domain
, const char *validity
, const char *proximity
,
4046 const char *context
)
4051 isl_union_map
*prox
;
4052 isl_schedule_constraints
*sc
;
4053 isl_schedule
*schedule
;
4054 isl_union_map
*sched
;
4056 con
= isl_set_read_from_str(ctx
, context
);
4057 dom
= isl_union_set_read_from_str(ctx
, domain
);
4058 dep
= isl_union_map_read_from_str(ctx
, validity
);
4059 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4060 sc
= isl_schedule_constraints_on_domain(dom
);
4061 sc
= isl_schedule_constraints_set_context(sc
, con
);
4062 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4063 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4064 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4065 sched
= isl_schedule_get_map(schedule
);
4066 isl_schedule_free(schedule
);
4071 /* Compute a schedule for the given instance set, validity constraints and
4072 * proximity constraints and return a corresponding union map representation.
4074 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4075 const char *domain
, const char *validity
, const char *proximity
)
4077 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4081 /* Check that a schedule can be constructed on the given domain
4082 * with the given validity and proximity constraints.
4084 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4085 const char *validity
, const char *proximity
)
4087 isl_union_map
*sched
;
4089 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4093 isl_union_map_free(sched
);
4097 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4098 const char *validity
, const char *proximity
, const char *expected_sched
)
4100 isl_union_map
*sched1
, *sched2
;
4103 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4104 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4106 equal
= isl_union_map_is_equal(sched1
, sched2
);
4107 isl_union_map_free(sched1
);
4108 isl_union_map_free(sched2
);
4113 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4119 /* Check that the schedule map is properly padded, i.e., that the range
4120 * lives in a single space.
4122 static int test_padded_schedule(isl_ctx
*ctx
)
4126 isl_union_map
*validity
, *proximity
;
4127 isl_schedule_constraints
*sc
;
4128 isl_schedule
*sched
;
4129 isl_union_map
*umap
;
4130 isl_union_set
*range
;
4133 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4134 D
= isl_union_set_read_from_str(ctx
, str
);
4135 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4136 proximity
= isl_union_map_copy(validity
);
4137 sc
= isl_schedule_constraints_on_domain(D
);
4138 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4139 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4140 sched
= isl_schedule_constraints_compute_schedule(sc
);
4141 umap
= isl_schedule_get_map(sched
);
4142 isl_schedule_free(sched
);
4143 range
= isl_union_map_range(umap
);
4144 set
= isl_set_from_union_set(range
);
4153 /* Check that conditional validity constraints are also taken into
4154 * account across bands.
4155 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4156 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4157 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4158 * is enforced by the rest of the schedule.
4160 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4163 isl_union_set
*domain
;
4164 isl_union_map
*validity
, *proximity
, *condition
;
4165 isl_union_map
*sink
, *source
, *dep
;
4166 isl_schedule_constraints
*sc
;
4167 isl_schedule
*schedule
;
4168 isl_union_access_info
*access
;
4169 isl_union_flow
*flow
;
4172 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4173 "A[k] : k >= 1 and k <= -1 + n; "
4174 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4175 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4176 domain
= isl_union_set_read_from_str(ctx
, str
);
4177 sc
= isl_schedule_constraints_on_domain(domain
);
4178 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4179 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4180 "D[k, i] -> C[1 + k, i] : "
4181 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4182 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4183 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4184 validity
= isl_union_map_read_from_str(ctx
, str
);
4185 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4186 str
= "[n] -> { C[k, i] -> D[k, i] : "
4187 "0 <= i <= -1 + k and k <= -1 + n }";
4188 proximity
= isl_union_map_read_from_str(ctx
, str
);
4189 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4190 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4191 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4192 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4193 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4194 condition
= isl_union_map_read_from_str(ctx
, str
);
4195 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4196 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4197 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4198 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4199 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4200 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4201 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4202 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4203 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4204 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4205 validity
= isl_union_map_read_from_str(ctx
, str
);
4206 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4208 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4209 str
= "{ D[2,0] -> [] }";
4210 sink
= isl_union_map_read_from_str(ctx
, str
);
4211 access
= isl_union_access_info_from_sink(sink
);
4212 str
= "{ C[2,1] -> [] }";
4213 source
= isl_union_map_read_from_str(ctx
, str
);
4214 access
= isl_union_access_info_set_must_source(access
, source
);
4215 access
= isl_union_access_info_set_schedule(access
, schedule
);
4216 flow
= isl_union_access_info_compute_flow(access
);
4217 dep
= isl_union_flow_get_must_dependence(flow
);
4218 isl_union_flow_free(flow
);
4219 empty
= isl_union_map_is_empty(dep
);
4220 isl_union_map_free(dep
);
4225 isl_die(ctx
, isl_error_unknown
,
4226 "conditional validity not respected", return -1);
4231 /* Check that the test for violated conditional validity constraints
4232 * is not confused by domain compression.
4233 * In particular, earlier versions of isl would apply
4234 * a schedule on the compressed domains to the original domains,
4235 * resulting in a failure to detect that the default schedule
4236 * violates the conditional validity constraints.
4238 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4242 isl_union_set
*domain
;
4243 isl_union_map
*validity
, *condition
;
4244 isl_schedule_constraints
*sc
;
4245 isl_schedule
*schedule
;
4246 isl_union_map
*umap
;
4249 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4250 domain
= isl_union_set_read_from_str(ctx
, str
);
4251 sc
= isl_schedule_constraints_on_domain(domain
);
4252 str
= "{ B[1, i] -> A[0, i + 1] }";
4253 condition
= isl_union_map_read_from_str(ctx
, str
);
4254 str
= "{ A[0, i] -> B[1, i - 1] }";
4255 validity
= isl_union_map_read_from_str(ctx
, str
);
4256 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4257 isl_union_map_copy(validity
));
4258 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4259 umap
= isl_schedule_get_map(schedule
);
4260 isl_schedule_free(schedule
);
4261 validity
= isl_union_map_apply_domain(validity
,
4262 isl_union_map_copy(umap
));
4263 validity
= isl_union_map_apply_range(validity
, umap
);
4264 map
= isl_map_from_union_map(validity
);
4265 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4266 map
= isl_map_intersect(map
, ge
);
4267 empty
= isl_map_is_empty(map
);
4273 isl_die(ctx
, isl_error_unknown
,
4274 "conditional validity constraints not satisfied",
4280 /* Input for testing of schedule construction based on
4281 * conditional constraints.
4283 * domain is the iteration domain
4284 * flow are the flow dependences, which determine the validity and
4285 * proximity constraints
4286 * condition are the conditions on the conditional validity constraints
4287 * conditional_validity are the conditional validity constraints
4288 * outer_band_n is the expected number of members in the outer band
4293 const char *condition
;
4294 const char *conditional_validity
;
4296 } live_range_tests
[] = {
4297 /* Contrived example that illustrates that we need to keep
4298 * track of tagged condition dependences and
4299 * tagged conditional validity dependences
4300 * in isl_sched_edge separately.
4301 * In particular, the conditional validity constraints on A
4302 * cannot be satisfied,
4303 * but they can be ignored because there are no corresponding
4304 * condition constraints. However, we do have an additional
4305 * conditional validity constraint that maps to the same
4306 * dependence relation
4307 * as the condition constraint on B. If we did not make a distinction
4308 * between tagged condition and tagged conditional validity
4309 * dependences, then we
4310 * could end up treating this shared dependence as an condition
4311 * constraint on A, forcing a localization of the conditions,
4312 * which is impossible.
4314 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4315 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4316 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4317 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4318 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4319 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4322 /* TACO 2013 Fig. 7 */
4323 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4324 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4325 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4326 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4327 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4328 "0 <= i < n and 0 <= j < n - 1 }",
4329 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4330 "0 <= i < n and 0 <= j < j' < n;"
4331 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4332 "0 <= i < i' < n and 0 <= j,j' < n;"
4333 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4334 "0 <= i,j,j' < n and j < j' }",
4337 /* TACO 2013 Fig. 7, without tags */
4338 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4339 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4340 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4341 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4342 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4343 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4344 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4345 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4348 /* TACO 2013 Fig. 12 */
4349 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4350 "S3[i,3] : 0 <= i <= 1 }",
4351 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4352 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4353 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4354 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4355 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4356 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4357 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4358 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4359 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4360 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4361 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4366 /* Test schedule construction based on conditional constraints.
4367 * In particular, check the number of members in the outer band node
4368 * as an indication of whether tiling is possible or not.
4370 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4373 isl_union_set
*domain
;
4374 isl_union_map
*condition
;
4375 isl_union_map
*flow
;
4376 isl_union_map
*validity
;
4377 isl_schedule_constraints
*sc
;
4378 isl_schedule
*schedule
;
4379 isl_schedule_node
*node
;
4382 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4384 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4387 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4388 domain
= isl_union_set_read_from_str(ctx
,
4389 live_range_tests
[i
].domain
);
4390 flow
= isl_union_map_read_from_str(ctx
,
4391 live_range_tests
[i
].flow
);
4392 condition
= isl_union_map_read_from_str(ctx
,
4393 live_range_tests
[i
].condition
);
4394 validity
= isl_union_map_read_from_str(ctx
,
4395 live_range_tests
[i
].conditional_validity
);
4396 sc
= isl_schedule_constraints_on_domain(domain
);
4397 sc
= isl_schedule_constraints_set_validity(sc
,
4398 isl_union_map_copy(flow
));
4399 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4400 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4401 condition
, validity
);
4402 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4403 node
= isl_schedule_get_root(schedule
);
4405 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4406 node
= isl_schedule_node_first_child(node
);
4407 n_member
= isl_schedule_node_band_n_member(node
);
4408 isl_schedule_node_free(node
);
4409 isl_schedule_free(schedule
);
4411 if (!schedule
|| n_member
< 0)
4413 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4414 isl_die(ctx
, isl_error_unknown
,
4415 "unexpected number of members in outer band",
4421 /* Check that the schedule computed for the given instance set and
4422 * dependence relation strongly satisfies the dependences.
4423 * In particular, check that no instance is scheduled before
4424 * or together with an instance on which it depends.
4425 * Earlier versions of isl would produce a schedule that
4426 * only weakly satisfies the dependences.
4428 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4430 const char *domain
, *dep
;
4431 isl_union_map
*D
, *schedule
;
4435 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4436 "A[i0] : 0 <= i0 <= 1 }";
4437 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4438 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4439 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4440 D
= isl_union_map_read_from_str(ctx
, dep
);
4441 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4442 D
= isl_union_map_apply_range(D
, schedule
);
4443 map
= isl_map_from_union_map(D
);
4444 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4445 map
= isl_map_intersect(map
, ge
);
4446 empty
= isl_map_is_empty(map
);
4452 isl_die(ctx
, isl_error_unknown
,
4453 "dependences not strongly satisfied", return -1);
4458 /* Compute a schedule for input where the instance set constraints
4459 * conflict with the context constraints.
4460 * Earlier versions of isl did not properly handle this situation.
4462 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4464 isl_union_map
*schedule
;
4465 const char *domain
, *context
;
4467 domain
= "[n] -> { A[] : n >= 0 }";
4468 context
= "[n] -> { : n < 0 }";
4469 schedule
= compute_schedule_with_context(ctx
,
4470 domain
, "{}", "{}", context
);
4471 isl_union_map_free(schedule
);
4479 /* Check that a set of schedule constraints that only allow for
4480 * a coalescing schedule still produces a schedule even if the user
4481 * request a non-coalescing schedule. Earlier versions of isl
4482 * would not handle this case correctly.
4484 static int test_coalescing_schedule(isl_ctx
*ctx
)
4486 const char *domain
, *dep
;
4489 isl_schedule_constraints
*sc
;
4490 isl_schedule
*schedule
;
4491 int treat_coalescing
;
4493 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4494 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4495 I
= isl_union_set_read_from_str(ctx
, domain
);
4496 D
= isl_union_map_read_from_str(ctx
, dep
);
4497 sc
= isl_schedule_constraints_on_domain(I
);
4498 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4499 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4500 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4501 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4502 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4503 isl_schedule_free(schedule
);
4509 /* Check that the scheduler does not perform any needless
4510 * compound skewing. Earlier versions of isl would compute
4511 * schedules in terms of transformed schedule coefficients and
4512 * would not accurately keep track of the sum of the original
4513 * schedule coefficients. It could then produce the schedule
4514 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4515 * for the input below instead of the schedule below.
4517 static int test_skewing_schedule(isl_ctx
*ctx
)
4519 const char *D
, *V
, *P
, *S
;
4521 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4522 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4523 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4524 "-1 <= a-i + b-j + c-k <= 1 }";
4526 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4528 return test_special_schedule(ctx
, D
, V
, P
, S
);
4531 int test_schedule(isl_ctx
*ctx
)
4533 const char *D
, *W
, *R
, *V
, *P
, *S
;
4534 int max_coincidence
;
4535 int treat_coalescing
;
4537 /* Handle resulting schedule with zero bands. */
4538 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4542 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4543 W
= "{ S1[t,i] -> a[t,i] }";
4544 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4545 "S1[t,i] -> a[t-1,i+1] }";
4546 S
= "{ S1[t,i] -> [t,i] }";
4547 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4550 /* Fig. 5 of CC2008 */
4551 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4553 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4554 "j >= 2 and j <= -1 + N }";
4555 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4556 "j >= 2 and j <= -1 + N; "
4557 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4558 "j >= 2 and j <= -1 + N }";
4559 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4560 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4563 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4564 W
= "{ S1[i] -> a[i] }";
4565 R
= "{ S2[i] -> a[i+1] }";
4566 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4567 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4570 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4571 W
= "{ S1[i] -> a[i] }";
4572 R
= "{ S2[i] -> a[9-i] }";
4573 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4574 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4577 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4578 W
= "{ S1[i] -> a[i] }";
4579 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4580 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4581 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4584 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4585 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4586 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4587 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4588 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4591 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4592 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4593 R
= "{ S2[i,j] -> a[i-1,j] }";
4594 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4595 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4598 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4599 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4600 R
= "{ S2[i,j] -> a[i,j-1] }";
4601 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4602 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4605 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4606 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4607 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4608 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4609 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4610 "S_0[] -> [0, 0, 0] }";
4611 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4613 ctx
->opt
->schedule_parametric
= 0;
4614 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4616 ctx
->opt
->schedule_parametric
= 1;
4618 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4619 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4620 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4621 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4622 "S4[i] -> a[i,N] }";
4623 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4624 "S4[i] -> [4,i,0] }";
4625 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4626 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4627 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4629 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4631 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4632 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4634 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4636 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4638 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4639 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4642 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4643 " S_2[t] : t >= 0 and t <= -1 + N; "
4644 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4646 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4647 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4648 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4649 "i >= 0 and i <= -1 + N }";
4650 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4651 "i >= 0 and i <= -1 + N; "
4652 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4653 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4654 " S_0[t] -> [0, t, 0] }";
4656 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4658 ctx
->opt
->schedule_parametric
= 0;
4659 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4661 ctx
->opt
->schedule_parametric
= 1;
4663 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4664 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4665 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4668 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4669 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4670 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4671 "j >= 0 and j <= -1 + N; "
4672 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4673 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4674 "j >= 0 and j <= -1 + N; "
4675 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4676 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4677 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4680 D
= "{ S_0[i] : i >= 0 }";
4681 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4682 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4683 S
= "{ S_0[i] -> [0, i, 0] }";
4684 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4687 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4688 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4689 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4690 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4691 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4694 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4695 "k <= -1 + n and k >= 0 }";
4696 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4697 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4698 "k <= -1 + n and k >= 0; "
4699 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4700 "k <= -1 + n and k >= 0; "
4701 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4702 "k <= -1 + n and k >= 0 }";
4703 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4704 ctx
->opt
->schedule_outer_coincidence
= 1;
4705 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4707 ctx
->opt
->schedule_outer_coincidence
= 0;
4709 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4710 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4711 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4712 "Stmt_for_body24[i0, i1, 1, 0]:"
4713 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4714 "Stmt_for_body7[i0, i1, i2]:"
4715 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4718 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4719 "Stmt_for_body24[1, i1, i2, i3]:"
4720 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4722 "Stmt_for_body24[0, i1, i2, i3] -> "
4723 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4724 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4726 "Stmt_for_body24[0, i1, i2, i3] ->"
4727 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4728 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4729 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4730 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4731 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4732 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4733 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4734 "i1 <= 6 and i1 >= 0;"
4735 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4736 "Stmt_for_body7[i0, i1, i2] -> "
4737 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4738 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4739 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4740 "Stmt_for_body7[i0, i1, i2] -> "
4741 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4742 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4743 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4746 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4747 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4748 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4750 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4752 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4753 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4754 "j >= 1 and j <= 7;"
4755 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4756 "j >= 1 and j <= 8 }";
4758 S
= "{ S_0[i, j] -> [i + j, i] }";
4759 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4760 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4762 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4764 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4765 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4766 "j >= 0 and j <= -1 + i }";
4767 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4768 "i <= -1 + N and j >= 0;"
4769 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4772 S
= "{ S_0[i, j] -> [i, j] }";
4773 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4774 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4776 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4778 /* Test both algorithms on a case with only proximity dependences. */
4779 D
= "{ S[i,j] : 0 <= i <= 10 }";
4781 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4782 S
= "{ S[i, j] -> [j, i] }";
4783 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4784 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4786 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4787 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4790 D
= "{ A[a]; B[] }";
4792 P
= "{ A[a] -> B[] }";
4793 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4796 if (test_padded_schedule(ctx
) < 0)
4799 /* Check that check for progress is not confused by rational
4802 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4803 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4805 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4806 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4808 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4809 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4811 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4813 /* Check that we allow schedule rows that are only non-trivial
4814 * on some full-dimensional domains.
4816 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4817 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4818 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4820 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4821 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4823 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4825 if (test_conditional_schedule_constraints(ctx
) < 0)
4828 if (test_strongly_satisfying_schedule(ctx
) < 0)
4831 if (test_conflicting_context_schedule(ctx
) < 0)
4834 if (test_coalescing_schedule(ctx
) < 0)
4836 if (test_skewing_schedule(ctx
) < 0)
4842 /* Perform scheduling tests using the whole component scheduler.
4844 static int test_schedule_whole(isl_ctx
*ctx
)
4849 whole
= isl_options_get_schedule_whole_component(ctx
);
4850 isl_options_set_schedule_whole_component(ctx
, 1);
4851 r
= test_schedule(ctx
);
4852 isl_options_set_schedule_whole_component(ctx
, whole
);
4857 /* Perform scheduling tests using the incremental scheduler.
4859 static int test_schedule_incremental(isl_ctx
*ctx
)
4864 whole
= isl_options_get_schedule_whole_component(ctx
);
4865 isl_options_set_schedule_whole_component(ctx
, 0);
4866 r
= test_schedule(ctx
);
4867 isl_options_set_schedule_whole_component(ctx
, whole
);
4872 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4874 isl_union_map
*umap
;
4877 umap
= isl_union_map_read_from_str(ctx
, str
);
4878 test
= isl_union_map_plain_is_injective(umap
);
4879 isl_union_map_free(umap
);
4882 if (test
== injective
)
4885 isl_die(ctx
, isl_error_unknown
,
4886 "map not detected as injective", return -1);
4888 isl_die(ctx
, isl_error_unknown
,
4889 "map detected as injective", return -1);
4892 int test_injective(isl_ctx
*ctx
)
4896 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4898 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4900 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4902 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4904 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4906 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4908 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4910 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4913 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4914 if (test_plain_injective(ctx
, str
, 1))
4916 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4917 if (test_plain_injective(ctx
, str
, 0))
4923 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4931 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4932 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4938 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4942 equal
= aff_plain_is_equal(aff
, str
);
4946 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4947 "result not as expected", return -1);
4951 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4953 static isl_bool
union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff
*upa
,
4957 isl_union_pw_aff
*upa2
;
4961 return isl_bool_error
;
4963 ctx
= isl_union_pw_aff_get_ctx(upa
);
4964 upa2
= isl_union_pw_aff_read_from_str(ctx
, str
);
4965 equal
= isl_union_pw_aff_plain_is_equal(upa
, upa2
);
4966 isl_union_pw_aff_free(upa2
);
4971 /* Check that "upa" is obviously equal to the isl_union_pw_aff
4972 * represented by "str".
4974 static isl_stat
union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff
*upa
,
4979 equal
= union_pw_aff_plain_is_equal(upa
, str
);
4981 return isl_stat_error
;
4983 isl_die(isl_union_pw_aff_get_ctx(upa
), isl_error_unknown
,
4984 "result not as expected", return isl_stat_error
);
4988 /* Basic tests on isl_union_pw_aff.
4990 * In particular, check that isl_union_pw_aff_aff_on_domain
4991 * aligns the parameters of the input objects and
4992 * that isl_union_pw_aff_param_on_domain_id properly
4993 * introduces the parameter.
4995 static int test_upa(isl_ctx
*ctx
)
5000 isl_union_set
*domain
;
5001 isl_union_pw_aff
*upa
;
5004 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5005 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5006 domain
= isl_union_set_read_from_str(ctx
, str
);
5007 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5008 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5009 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5010 isl_union_pw_aff_free(upa
);
5014 id
= isl_id_alloc(ctx
, "N", NULL
);
5015 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5016 domain
= isl_union_set_read_from_str(ctx
, str
);
5017 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5018 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5019 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5020 isl_union_pw_aff_free(upa
);
5028 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5029 __isl_take isl_aff
*aff2
);
5031 ['+'] = { &isl_aff_add
},
5032 ['-'] = { &isl_aff_sub
},
5033 ['*'] = { &isl_aff_mul
},
5034 ['/'] = { &isl_aff_div
},
5042 } aff_bin_tests
[] = {
5043 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5044 "{ [i] -> [2i] }" },
5045 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5047 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5048 "{ [i] -> [2i] }" },
5049 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5050 "{ [i] -> [2i] }" },
5051 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5052 "{ [i] -> [i/2] }" },
5053 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5055 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5056 "{ [i] -> [NaN] }" },
5057 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5058 "{ [i] -> [NaN] }" },
5059 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5060 "{ [i] -> [NaN] }" },
5061 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5062 "{ [i] -> [NaN] }" },
5063 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5064 "{ [i] -> [NaN] }" },
5065 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5066 "{ [i] -> [NaN] }" },
5067 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5068 "{ [i] -> [NaN] }" },
5069 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5070 "{ [i] -> [NaN] }" },
5071 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5072 "{ [i] -> [NaN] }" },
5073 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5074 "{ [i] -> [NaN] }" },
5075 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5076 "{ [i] -> [NaN] }" },
5077 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5078 "{ [i] -> [NaN] }" },
5081 /* Perform some basic tests of binary operations on isl_aff objects.
5083 static int test_bin_aff(isl_ctx
*ctx
)
5086 isl_aff
*aff1
, *aff2
, *res
;
5087 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5088 __isl_take isl_aff
*aff2
);
5091 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5092 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5093 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5094 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5095 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5096 aff1
= fn(aff1
, aff2
);
5097 if (isl_aff_is_nan(res
))
5098 ok
= isl_aff_is_nan(aff1
);
5100 ok
= isl_aff_plain_is_equal(aff1
, res
);
5106 isl_die(ctx
, isl_error_unknown
,
5107 "unexpected result", return -1);
5114 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5115 __isl_take isl_pw_aff
*pa2
);
5116 } pw_aff_bin_op
[] = {
5117 ['m'] = { &isl_pw_aff_min
},
5118 ['M'] = { &isl_pw_aff_max
},
5121 /* Inputs for binary isl_pw_aff operation tests.
5122 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5123 * defined by pw_aff_bin_op, and "res" is the expected result.
5130 } pw_aff_bin_tests
[] = {
5131 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5133 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5135 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5136 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5137 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5138 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5139 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5140 "{ [i] -> [NaN] }" },
5141 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5142 "{ [i] -> [NaN] }" },
5145 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5147 static int test_bin_pw_aff(isl_ctx
*ctx
)
5151 isl_pw_aff
*pa1
, *pa2
, *res
;
5153 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5154 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5155 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5156 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5157 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5158 if (isl_pw_aff_involves_nan(res
))
5159 ok
= isl_pw_aff_involves_nan(pa1
);
5161 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5162 isl_pw_aff_free(pa1
);
5163 isl_pw_aff_free(res
);
5167 isl_die(ctx
, isl_error_unknown
,
5168 "unexpected result", return -1);
5175 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5176 __isl_take isl_union_pw_multi_aff
*upma1
,
5177 __isl_take isl_union_pw_multi_aff
*upma2
);
5181 } upma_bin_tests
[] = {
5182 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5183 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5184 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5185 "{ B[x] -> [2] : x >= 0 }",
5186 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5187 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5188 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5189 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5190 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5191 "D[i] -> B[2] : i >= 5 }" },
5192 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5193 "{ B[x] -> C[2] : x > 0 }",
5194 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5195 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5196 "{ B[x] -> A[2] : x >= 0 }",
5197 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5200 /* Perform some basic tests of binary operations on
5201 * isl_union_pw_multi_aff objects.
5203 static int test_bin_upma(isl_ctx
*ctx
)
5206 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5209 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5210 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5211 upma_bin_tests
[i
].arg1
);
5212 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5213 upma_bin_tests
[i
].arg2
);
5214 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5215 upma_bin_tests
[i
].res
);
5216 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5217 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5218 isl_union_pw_multi_aff_free(upma1
);
5219 isl_union_pw_multi_aff_free(res
);
5223 isl_die(ctx
, isl_error_unknown
,
5224 "unexpected result", return -1);
5231 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5232 __isl_take isl_union_pw_multi_aff
*upma1
,
5233 __isl_take isl_union_pw_multi_aff
*upma2
);
5236 } upma_bin_fail_tests
[] = {
5237 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5238 "{ B[x] -> C[2] : x >= 0 }" },
5241 /* Perform some basic tests of binary operations on
5242 * isl_union_pw_multi_aff objects that are expected to fail.
5244 static int test_bin_upma_fail(isl_ctx
*ctx
)
5247 isl_union_pw_multi_aff
*upma1
, *upma2
;
5250 on_error
= isl_options_get_on_error(ctx
);
5251 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5252 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5253 for (i
= 0; i
< n
; ++i
) {
5254 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5255 upma_bin_fail_tests
[i
].arg1
);
5256 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5257 upma_bin_fail_tests
[i
].arg2
);
5258 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5259 isl_union_pw_multi_aff_free(upma1
);
5263 isl_options_set_on_error(ctx
, on_error
);
5265 isl_die(ctx
, isl_error_unknown
,
5266 "operation not expected to succeed", return -1);
5271 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5272 * "fn" is the function that is tested.
5273 * "arg" is a string description of the input.
5274 * "res" is a string description of the expected result.
5277 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5280 } mpa_un_tests
[] = {
5281 { &isl_multi_pw_aff_range_factor_domain
,
5282 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5283 "{ A[x] -> B[(1 : x >= 5)] }" },
5284 { &isl_multi_pw_aff_range_factor_range
,
5285 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5286 "{ A[y] -> C[(2 : y <= 10)] }" },
5287 { &isl_multi_pw_aff_range_factor_domain
,
5288 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5289 "{ A[x] -> B[(1 : x >= 5)] }" },
5290 { &isl_multi_pw_aff_range_factor_range
,
5291 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5292 "{ A[y] -> C[] }" },
5293 { &isl_multi_pw_aff_range_factor_domain
,
5294 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5295 "{ A[x] -> B[] }" },
5296 { &isl_multi_pw_aff_range_factor_range
,
5297 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5298 "{ A[y] -> C[(2 : y <= 10)] }" },
5299 { &isl_multi_pw_aff_range_factor_domain
,
5300 "{ A[x] -> [B[] -> C[]] }",
5301 "{ A[x] -> B[] }" },
5302 { &isl_multi_pw_aff_range_factor_range
,
5303 "{ A[x] -> [B[] -> C[]] }",
5304 "{ A[y] -> C[] }" },
5305 { &isl_multi_pw_aff_factor_range
,
5308 { &isl_multi_pw_aff_range_factor_domain
,
5309 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5310 "{ A[x] -> B[] : x >= 0 }" },
5311 { &isl_multi_pw_aff_range_factor_range
,
5312 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5313 "{ A[y] -> C[] : y >= 0 }" },
5314 { &isl_multi_pw_aff_factor_range
,
5315 "[N] -> { [B[] -> C[]] : N >= 0 }",
5316 "[N] -> { C[] : N >= 0 }" },
5319 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5321 static int test_un_mpa(isl_ctx
*ctx
)
5325 isl_multi_pw_aff
*mpa
, *res
;
5327 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5328 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5329 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5330 mpa
= mpa_un_tests
[i
].fn(mpa
);
5331 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5332 isl_multi_pw_aff_free(mpa
);
5333 isl_multi_pw_aff_free(res
);
5337 isl_die(ctx
, isl_error_unknown
,
5338 "unexpected result", return -1);
5344 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5345 * "fn" is the function that is tested.
5346 * "arg1" and "arg2" are string descriptions of the inputs.
5347 * "res" is a string description of the expected result.
5350 __isl_give isl_multi_pw_aff
*(*fn
)(
5351 __isl_take isl_multi_pw_aff
*mpa1
,
5352 __isl_take isl_multi_pw_aff
*mpa2
);
5356 } mpa_bin_tests
[] = {
5357 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5359 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5360 "{ A[x] -> [(x : x <= 10)] }",
5361 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5362 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5363 "{ A[x] -> [] : x <= 10 }",
5364 "{ A[x] -> [] : 5 <= x <= 10 }" },
5365 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5366 "[N] -> { A[x] -> [] : x <= N }",
5367 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5368 { &isl_multi_pw_aff_add
,
5369 "[N] -> { A[x] -> [] : x <= N }",
5370 "{ A[x] -> [] : x >= 5 }",
5371 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5372 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5373 "{ A[y] -> C[(2 : y <= 10)] }",
5374 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5375 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5376 "{ A[y] -> C[2] : y <= 10 }",
5377 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5378 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5379 "[N] -> { A[y] -> C[2] : y <= N }",
5380 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5381 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5382 "{ A[y] -> C[2] : y <= 10 }",
5383 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5384 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5385 "{ A[] -> [B[1] -> C[2]] }" },
5386 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5387 "{ A[] -> [B[] -> C[]] }" },
5388 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5389 "{ A[y] -> C[] : y <= 10 }",
5390 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5391 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5392 "{ A[x] -> B[(1 : x >= 5)] }",
5393 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5394 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5395 "{ A[y] -> C[(2 : y <= 10)] }",
5396 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5397 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5398 "{ A[y] -> C[] : y <= 10 }",
5399 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5400 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5401 "{ A[x] -> B[(1 : x >= 5)] }",
5402 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5403 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5404 "[N] -> { A[y] -> C[] : y <= N }",
5405 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5406 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5407 "{ A[x] -> B[(1 : x >= 5)] }",
5408 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5409 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5410 "{ A[y] -> C[] : y <= 10 }",
5411 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5412 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5413 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5414 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5415 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5416 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5417 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5418 "{ A[a,b] -> C[b + 2a] }" },
5419 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5420 "{ B[i,j] -> C[i + 2j] }",
5421 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5422 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5423 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5424 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5425 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5426 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5427 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5428 "{ B[i,j] -> C[] }",
5429 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5430 "{ A[a,b] -> C[] }" },
5431 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5432 "{ B[i,j] -> C[] : i > j }",
5433 "{ A[a,b] -> B[b,a] }",
5434 "{ A[a,b] -> C[] : b > a }" },
5435 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5436 "{ B[i,j] -> C[] : j > 5 }",
5437 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5438 "{ A[a,b] -> C[] : b > a > 5 }" },
5439 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5440 "[N] -> { B[i,j] -> C[] : j > N }",
5441 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5442 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5443 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5444 "[M,N] -> { B[] -> C[] : N > 5 }",
5445 "[M,N] -> { A[] -> B[] : M > N }",
5446 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5449 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5451 static int test_bin_mpa(isl_ctx
*ctx
)
5455 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5457 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5458 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5459 mpa_bin_tests
[i
].arg1
);
5460 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5461 mpa_bin_tests
[i
].arg2
);
5462 res
= isl_multi_pw_aff_read_from_str(ctx
,
5463 mpa_bin_tests
[i
].res
);
5464 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5465 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5466 isl_multi_pw_aff_free(mpa1
);
5467 isl_multi_pw_aff_free(res
);
5471 isl_die(ctx
, isl_error_unknown
,
5472 "unexpected result", return -1);
5478 /* Inputs for basic tests of unary operations on
5479 * isl_multi_union_pw_aff objects.
5480 * "fn" is the function that is tested.
5481 * "arg" is a string description of the input.
5482 * "res" is a string description of the expected result.
5485 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5486 __isl_take isl_multi_union_pw_aff
*mupa
);
5489 } mupa_un_tests
[] = {
5490 { &isl_multi_union_pw_aff_factor_range
,
5491 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5492 "C[{ A[] -> [2] }]" },
5493 { &isl_multi_union_pw_aff_factor_range
,
5494 "[B[] -> C[{ A[] -> [2] }]]",
5495 "C[{ A[] -> [2] }]" },
5496 { &isl_multi_union_pw_aff_factor_range
,
5497 "[B[{ A[] -> [1] }] -> C[]]",
5499 { &isl_multi_union_pw_aff_factor_range
,
5502 { &isl_multi_union_pw_aff_factor_range
,
5503 "([B[] -> C[]] : { A[x] : x >= 0 })",
5504 "(C[] : { A[x] : x >= 0 })" },
5505 { &isl_multi_union_pw_aff_factor_range
,
5506 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5507 "[N] -> (C[] : { A[x] : x <= N })" },
5508 { &isl_multi_union_pw_aff_factor_range
,
5509 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5510 "[N] -> (C[] : { : N >= 0 })" },
5513 /* Perform some basic tests of unary operations on
5514 * isl_multi_union_pw_aff objects.
5516 static int test_un_mupa(isl_ctx
*ctx
)
5520 isl_multi_union_pw_aff
*mupa
, *res
;
5522 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5523 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5524 mupa_un_tests
[i
].arg
);
5525 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5526 mupa_un_tests
[i
].res
);
5527 mupa
= mupa_un_tests
[i
].fn(mupa
);
5528 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5529 isl_multi_union_pw_aff_free(mupa
);
5530 isl_multi_union_pw_aff_free(res
);
5534 isl_die(ctx
, isl_error_unknown
,
5535 "unexpected result", return -1);
5541 /* Inputs for basic tests of binary operations on
5542 * isl_multi_union_pw_aff objects.
5543 * "fn" is the function that is tested.
5544 * "arg1" and "arg2" are string descriptions of the inputs.
5545 * "res" is a string description of the expected result.
5548 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5549 __isl_take isl_multi_union_pw_aff
*mupa1
,
5550 __isl_take isl_multi_union_pw_aff
*mupa2
);
5554 } mupa_bin_tests
[] = {
5555 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5556 "[{ A[] -> [3] }]" },
5557 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5558 "[{ A[] -> [-1] }]" },
5559 { &isl_multi_union_pw_aff_add
,
5560 "[{ A[] -> [1]; B[] -> [4] }]",
5561 "[{ A[] -> [2]; C[] -> [5] }]",
5562 "[{ A[] -> [3] }]" },
5563 { &isl_multi_union_pw_aff_union_add
,
5564 "[{ A[] -> [1]; B[] -> [4] }]",
5565 "[{ A[] -> [2]; C[] -> [5] }]",
5566 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5567 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5568 "[{ A[x] -> [(x)] : x <= 10 }]",
5569 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5570 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5571 "([] : { A[x] : x <= 10 })",
5572 "([] : { A[x] : 5 <= x <= 10 })" },
5573 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5574 "[N] -> ([] : { A[x] : x <= N })",
5575 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5576 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5577 "([] : { A[x] : x <= 10 })",
5578 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5579 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5580 "[{ A[x] -> [(x)] : x <= 10 }]",
5581 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5582 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5583 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5584 "([] : { A[x] : x <= 10 })",
5585 "([] : { A[x] })" },
5586 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5587 "[N] -> ([] : { A[x] : x >= N })",
5588 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5589 { &isl_multi_union_pw_aff_union_add
,
5590 "[N] -> ([] : { A[] : N >= 0})",
5591 "[N] -> ([] : { A[] : N <= 0})",
5592 "[N] -> ([] : { A[] })" },
5593 { &isl_multi_union_pw_aff_union_add
,
5594 "[N] -> ([] : { A[] })",
5595 "[N] -> ([] : { : })",
5596 "[N] -> ([] : { : })" },
5597 { &isl_multi_union_pw_aff_union_add
,
5598 "[N] -> ([] : { : })",
5599 "[N] -> ([] : { A[] })",
5600 "[N] -> ([] : { : })" },
5601 { &isl_multi_union_pw_aff_union_add
,
5602 "[N] -> ([] : { : N >= 0})",
5603 "[N] -> ([] : { : N <= 0})",
5604 "[N] -> ([] : { : })" },
5605 { &isl_multi_union_pw_aff_range_product
,
5606 "B[{ A[] -> [1] }]",
5607 "C[{ A[] -> [2] }]",
5608 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5609 { &isl_multi_union_pw_aff_range_product
,
5610 "(B[] : { A[x] : x >= 5 })",
5611 "(C[] : { A[x] : x <= 10 })",
5612 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5613 { &isl_multi_union_pw_aff_range_product
,
5614 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5615 "(C[] : { A[x] : x <= 10 })",
5616 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5617 { &isl_multi_union_pw_aff_range_product
,
5618 "(C[] : { A[x] : x <= 10 })",
5619 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5620 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5621 { &isl_multi_union_pw_aff_range_product
,
5622 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5623 "[N] -> (C[] : { A[x] : x <= N })",
5624 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5625 { &isl_multi_union_pw_aff_range_product
,
5626 "[N] -> (C[] : { A[x] : x <= N })",
5627 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5628 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5629 { &isl_multi_union_pw_aff_range_product
,
5630 "B[{ A[] -> [1]; D[] -> [3] }]",
5631 "C[{ A[] -> [2] }]",
5632 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5633 { &isl_multi_union_pw_aff_range_product
,
5636 "([B[] -> C[]] : { A[x] })" },
5637 { &isl_multi_union_pw_aff_range_product
,
5640 "([B[] -> C[]] : { A[x] })" },
5643 /* Perform some basic tests of binary operations on
5644 * isl_multi_union_pw_aff objects.
5646 static int test_bin_mupa(isl_ctx
*ctx
)
5650 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
5652 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
5653 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
5654 mupa_bin_tests
[i
].arg1
);
5655 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
5656 mupa_bin_tests
[i
].arg2
);
5657 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5658 mupa_bin_tests
[i
].res
);
5659 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
5660 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
5661 isl_multi_union_pw_aff_free(mupa1
);
5662 isl_multi_union_pw_aff_free(res
);
5666 isl_die(ctx
, isl_error_unknown
,
5667 "unexpected result", return -1);
5673 /* Inputs for basic tests of binary operations on
5674 * pairs of isl_multi_union_pw_aff and isl_set objects.
5675 * "fn" is the function that is tested.
5676 * "arg1" and "arg2" are string descriptions of the inputs.
5677 * "res" is a string description of the expected result.
5680 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5681 __isl_take isl_multi_union_pw_aff
*mupa
,
5682 __isl_take isl_set
*set
);
5686 } mupa_set_tests
[] = {
5687 { &isl_multi_union_pw_aff_intersect_range
,
5688 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5689 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5690 { &isl_multi_union_pw_aff_intersect_range
,
5691 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5692 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5693 { &isl_multi_union_pw_aff_intersect_range
,
5694 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5695 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5696 { &isl_multi_union_pw_aff_intersect_range
,
5697 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5698 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5699 { &isl_multi_union_pw_aff_intersect_range
,
5700 "C[]", "{ C[] }", "C[]" },
5701 { &isl_multi_union_pw_aff_intersect_range
,
5702 "[N] -> (C[] : { : N >= 0 })",
5704 "[N] -> (C[] : { : N >= 0 })" },
5705 { &isl_multi_union_pw_aff_intersect_range
,
5706 "(C[] : { A[a,b] })",
5708 "(C[] : { A[a,b] })" },
5709 { &isl_multi_union_pw_aff_intersect_range
,
5710 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5712 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5713 { &isl_multi_union_pw_aff_intersect_range
,
5715 "[N] -> { C[] : N >= 0 }",
5716 "[N] -> (C[] : { : N >= 0 })" },
5717 { &isl_multi_union_pw_aff_intersect_range
,
5718 "(C[] : { A[a,b] })",
5719 "[N] -> { C[] : N >= 0 }",
5720 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5721 { &isl_multi_union_pw_aff_intersect_range
,
5722 "[N] -> (C[] : { : N >= 0 })",
5723 "[N] -> { C[] : N < 1024 }",
5724 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5725 { &isl_multi_union_pw_aff_intersect_params
,
5726 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5727 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5728 { &isl_multi_union_pw_aff_intersect_params
,
5729 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5730 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5731 { &isl_multi_union_pw_aff_intersect_params
,
5732 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5733 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5734 { &isl_multi_union_pw_aff_intersect_params
,
5735 "C[]", "[N] -> { : N >= 0 }",
5736 "[N] -> (C[] : { : N >= 0 })" },
5737 { &isl_multi_union_pw_aff_intersect_params
,
5738 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5739 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5740 { &isl_multi_union_pw_aff_intersect_params
,
5741 "[N] -> (C[] : { A[a,N] })", "{ : }",
5742 "[N] -> (C[] : { A[a,N] })" },
5743 { &isl_multi_union_pw_aff_intersect_params
,
5744 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5745 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5748 /* Perform some basic tests of binary operations on
5749 * pairs of isl_multi_union_pw_aff and isl_set objects.
5751 static int test_mupa_set(isl_ctx
*ctx
)
5755 isl_multi_union_pw_aff
*mupa
, *res
;
5758 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
5759 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5760 mupa_set_tests
[i
].arg1
);
5761 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
5762 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5763 mupa_set_tests
[i
].res
);
5764 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
5765 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5766 isl_multi_union_pw_aff_free(mupa
);
5767 isl_multi_union_pw_aff_free(res
);
5771 isl_die(ctx
, isl_error_unknown
,
5772 "unexpected result", return -1);
5778 /* Inputs for basic tests of binary operations on
5779 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5780 * "fn" is the function that is tested.
5781 * "arg1" and "arg2" are string descriptions of the inputs.
5782 * "res" is a string description of the expected result.
5785 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5786 __isl_take isl_multi_union_pw_aff
*mupa
,
5787 __isl_take isl_union_set
*uset
);
5791 } mupa_uset_tests
[] = {
5792 { &isl_multi_union_pw_aff_intersect_domain
,
5793 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5794 "C[{ B[i,i] -> [3i] }]" },
5795 { &isl_multi_union_pw_aff_intersect_domain
,
5796 "(C[] : { B[i,j] })", "{ B[i,i] }",
5797 "(C[] : { B[i,i] })" },
5798 { &isl_multi_union_pw_aff_intersect_domain
,
5799 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5800 "[N] -> (C[] : { B[N,N] })" },
5801 { &isl_multi_union_pw_aff_intersect_domain
,
5802 "C[]", "{ B[i,i] }",
5803 "(C[] : { B[i,i] })" },
5804 { &isl_multi_union_pw_aff_intersect_domain
,
5805 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5806 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5809 /* Perform some basic tests of binary operations on
5810 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5812 static int test_mupa_uset(isl_ctx
*ctx
)
5816 isl_multi_union_pw_aff
*mupa
, *res
;
5817 isl_union_set
*uset
;
5819 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
5820 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5821 mupa_uset_tests
[i
].arg1
);
5822 uset
= isl_union_set_read_from_str(ctx
,
5823 mupa_uset_tests
[i
].arg2
);
5824 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5825 mupa_uset_tests
[i
].res
);
5826 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
5827 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5828 isl_multi_union_pw_aff_free(mupa
);
5829 isl_multi_union_pw_aff_free(res
);
5833 isl_die(ctx
, isl_error_unknown
,
5834 "unexpected result", return -1);
5840 /* Inputs for basic tests of binary operations on
5841 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5842 * "fn" is the function that is tested.
5843 * "arg1" and "arg2" are string descriptions of the inputs.
5844 * "res" is a string description of the expected result.
5847 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5848 __isl_take isl_multi_union_pw_aff
*mupa
,
5849 __isl_take isl_multi_aff
*ma
);
5853 } mupa_ma_tests
[] = {
5854 { &isl_multi_union_pw_aff_apply_multi_aff
,
5855 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5856 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5857 "{ C[a,b] -> D[b,a] }",
5858 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5859 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5860 { &isl_multi_union_pw_aff_apply_multi_aff
,
5861 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5862 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5863 "{ C[a,b] -> D[b,a] }",
5864 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5865 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5866 { &isl_multi_union_pw_aff_apply_multi_aff
,
5867 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5868 "[N] -> { C[a] -> D[a + N] }",
5869 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5870 { &isl_multi_union_pw_aff_apply_multi_aff
,
5874 { &isl_multi_union_pw_aff_apply_multi_aff
,
5875 "[N] -> (C[] : { : N >= 0 })",
5877 "[N] -> (D[] : { : N >= 0 })" },
5878 { &isl_multi_union_pw_aff_apply_multi_aff
,
5880 "[N] -> { C[] -> D[N] }",
5881 "[N] -> D[{ [N] }]" },
5882 { &isl_multi_union_pw_aff_apply_multi_aff
,
5883 "(C[] : { A[i,j] : i >= j })",
5885 "(D[] : { A[i,j] : i >= j })" },
5886 { &isl_multi_union_pw_aff_apply_multi_aff
,
5887 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5889 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5890 { &isl_multi_union_pw_aff_apply_multi_aff
,
5891 "(C[] : { A[i,j] : i >= j })",
5892 "[N] -> { C[] -> D[N] }",
5893 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5896 /* Perform some basic tests of binary operations on
5897 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5899 static int test_mupa_ma(isl_ctx
*ctx
)
5903 isl_multi_union_pw_aff
*mupa
, *res
;
5906 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
5907 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5908 mupa_ma_tests
[i
].arg1
);
5909 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
5910 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5911 mupa_ma_tests
[i
].res
);
5912 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
5913 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5914 isl_multi_union_pw_aff_free(mupa
);
5915 isl_multi_union_pw_aff_free(res
);
5919 isl_die(ctx
, isl_error_unknown
,
5920 "unexpected result", return -1);
5926 /* Inputs for basic tests of binary operations on
5927 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5928 * "fn" is the function that is tested.
5929 * "arg1" and "arg2" are string descriptions of the inputs.
5930 * "res" is a string description of the expected result.
5933 __isl_give isl_union_pw_aff
*(*fn
)(
5934 __isl_take isl_multi_union_pw_aff
*mupa
,
5935 __isl_take isl_pw_aff
*pa
);
5939 } mupa_pa_tests
[] = {
5940 { &isl_multi_union_pw_aff_apply_pw_aff
,
5941 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5942 "[N] -> { C[a] -> [a + N] }",
5943 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5944 { &isl_multi_union_pw_aff_apply_pw_aff
,
5945 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5946 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5947 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5948 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5949 { &isl_multi_union_pw_aff_apply_pw_aff
,
5951 "[N] -> { C[] -> [N] }",
5953 { &isl_multi_union_pw_aff_apply_pw_aff
,
5955 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5956 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5957 { &isl_multi_union_pw_aff_apply_pw_aff
,
5958 "[N] -> (C[] : { : N >= 0 })",
5959 "[N] -> { C[] -> [N] }",
5960 "[N] -> { [N] : N >= 0 }" },
5961 { &isl_multi_union_pw_aff_apply_pw_aff
,
5962 "[N] -> (C[] : { : N >= 0 })",
5963 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5964 "[N] -> { [N] : N >= 0 }" },
5965 { &isl_multi_union_pw_aff_apply_pw_aff
,
5966 "[N] -> (C[] : { : N >= 0 })",
5968 "[N] -> { [0] : N >= 0 }" },
5969 { &isl_multi_union_pw_aff_apply_pw_aff
,
5970 "(C[] : { A[i,j] : i >= j })",
5971 "[N] -> { C[] -> [N] }",
5972 "[N] -> { A[i,j] -> [N] : i >= j }" },
5973 { &isl_multi_union_pw_aff_apply_pw_aff
,
5974 "(C[] : { A[i,j] : i >= j })",
5975 "[N] -> { C[] -> [N] : N >= 0 }",
5976 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
5979 /* Perform some basic tests of binary operations on
5980 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5982 static int test_mupa_pa(isl_ctx
*ctx
)
5986 isl_multi_union_pw_aff
*mupa
;
5987 isl_union_pw_aff
*upa
, *res
;
5990 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
5991 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5992 mupa_pa_tests
[i
].arg1
);
5993 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
5994 res
= isl_union_pw_aff_read_from_str(ctx
,
5995 mupa_pa_tests
[i
].res
);
5996 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
5997 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
5998 isl_union_pw_aff_free(upa
);
5999 isl_union_pw_aff_free(res
);
6003 isl_die(ctx
, isl_error_unknown
,
6004 "unexpected result", return -1);
6010 /* Inputs for basic tests of binary operations on
6011 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6012 * "fn" is the function that is tested.
6013 * "arg1" and "arg2" are string descriptions of the inputs.
6014 * "res" is a string description of the expected result.
6017 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6018 __isl_take isl_multi_union_pw_aff
*mupa
,
6019 __isl_take isl_pw_multi_aff
*pma
);
6023 } mupa_pma_tests
[] = {
6024 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6025 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6026 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6027 "{ C[a,b] -> D[b,a] }",
6028 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6029 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6030 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6031 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6032 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6033 "{ C[a,b] -> D[b,a] }",
6034 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6035 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6036 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6037 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6038 "[N] -> { C[a] -> D[a + N] }",
6039 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6040 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6041 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6042 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6043 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6044 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6045 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6046 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6047 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6048 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6049 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6050 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6051 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6052 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6053 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6057 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6058 "[N] -> (C[] : { : N >= 0 })",
6060 "[N] -> (D[] : { : N >= 0 })" },
6061 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6063 "[N] -> { C[] -> D[N] }",
6064 "[N] -> D[{ [N] }]" },
6065 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6066 "(C[] : { A[i,j] : i >= j })",
6068 "(D[] : { A[i,j] : i >= j })" },
6069 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6070 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6072 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6073 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6074 "(C[] : { A[i,j] : i >= j })",
6075 "[N] -> { C[] -> D[N] }",
6076 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6077 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6079 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6080 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6081 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6082 "[N] -> (C[] : { : N >= 0 })",
6083 "[N] -> { C[] -> D[N] }",
6084 "[N] -> D[{ [N] : N >= 0 }]" },
6085 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6086 "[N] -> (C[] : { : N >= 0 })",
6087 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6088 "[N] -> D[{ [N] : N >= 0 }]" },
6089 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6090 "[N] -> (C[] : { : N >= 0 })",
6092 "[N] -> D[{ [0] : N >= 0 }]" },
6093 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6094 "(C[] : { A[i,j] : i >= j })",
6095 "[N] -> { C[] -> D[N] : N >= 0 }",
6096 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6099 /* Perform some basic tests of binary operations on
6100 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6102 static int test_mupa_pma(isl_ctx
*ctx
)
6106 isl_multi_union_pw_aff
*mupa
, *res
;
6107 isl_pw_multi_aff
*pma
;
6109 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6110 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6111 mupa_pma_tests
[i
].arg1
);
6112 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6113 mupa_pma_tests
[i
].arg2
);
6114 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6115 mupa_pma_tests
[i
].res
);
6116 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6117 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6118 isl_multi_union_pw_aff_free(mupa
);
6119 isl_multi_union_pw_aff_free(res
);
6123 isl_die(ctx
, isl_error_unknown
,
6124 "unexpected result", return -1);
6130 /* Inputs for basic tests of binary operations on
6131 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6132 * "fn" is the function that is tested.
6133 * "arg1" and "arg2" are string descriptions of the inputs.
6134 * "res" is a string description of the expected result.
6137 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6138 __isl_take isl_multi_union_pw_aff
*mupa
,
6139 __isl_take isl_union_pw_multi_aff
*upma
);
6143 } mupa_upma_tests
[] = {
6144 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6145 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6146 "C[{ A[a,b] -> [b + 2a] }]" },
6147 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6148 "C[{ B[i,j] -> [i + 2j] }]",
6149 "{ A[a,b] -> B[b,a] : b > a }",
6150 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6151 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6152 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6153 "{ A[a,b] -> B[b,a] : b > a }",
6154 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6155 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6156 "C[{ B[i,j] -> [i + 2j] }]",
6157 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6158 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6159 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6160 "(C[] : { B[a,b] })",
6161 "{ A[a,b] -> B[b,a] }",
6162 "(C[] : { A[a,b] })" },
6163 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6164 "(C[] : { B[a,b] })",
6165 "{ B[a,b] -> A[b,a] }",
6167 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6168 "(C[] : { B[a,b] })",
6169 "{ A[a,b] -> B[b,a] : a > b }",
6170 "(C[] : { A[a,b] : a > b })" },
6171 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6172 "(C[] : { B[a,b] : a > b })",
6173 "{ A[a,b] -> B[b,a] }",
6174 "(C[] : { A[a,b] : b > a })" },
6175 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6176 "[N] -> (C[] : { B[a,b] : a > N })",
6177 "{ A[a,b] -> B[b,a] : a > b }",
6178 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6179 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6180 "(C[] : { B[a,b] : a > b })",
6181 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6182 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6183 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6185 "{ A[a,b] -> B[b,a] }",
6187 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6188 "[N] -> (C[] : { : N >= 0 })",
6189 "{ A[a,b] -> B[b,a] }",
6190 "[N] -> (C[] : { : N >= 0 })" },
6191 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6193 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6194 "[N] -> (C[] : { : N >= 0 })" },
6197 /* Perform some basic tests of binary operations on
6198 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6200 static int test_mupa_upma(isl_ctx
*ctx
)
6204 isl_multi_union_pw_aff
*mupa
, *res
;
6205 isl_union_pw_multi_aff
*upma
;
6207 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6208 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6209 mupa_upma_tests
[i
].arg1
);
6210 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6211 mupa_upma_tests
[i
].arg2
);
6212 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6213 mupa_upma_tests
[i
].res
);
6214 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6215 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6216 isl_multi_union_pw_aff_free(mupa
);
6217 isl_multi_union_pw_aff_free(res
);
6221 isl_die(ctx
, isl_error_unknown
,
6222 "unexpected result", return -1);
6228 /* Check that the input tuple of an isl_aff can be set properly.
6230 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6236 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6237 id
= isl_id_alloc(ctx
, "A", NULL
);
6238 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6239 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6242 return isl_stat_error
;
6247 int test_aff(isl_ctx
*ctx
)
6252 isl_local_space
*ls
;
6256 if (test_upa(ctx
) < 0)
6258 if (test_bin_aff(ctx
) < 0)
6260 if (test_bin_pw_aff(ctx
) < 0)
6262 if (test_bin_upma(ctx
) < 0)
6264 if (test_bin_upma_fail(ctx
) < 0)
6266 if (test_un_mpa(ctx
) < 0)
6268 if (test_bin_mpa(ctx
) < 0)
6270 if (test_un_mupa(ctx
) < 0)
6272 if (test_bin_mupa(ctx
) < 0)
6274 if (test_mupa_set(ctx
) < 0)
6276 if (test_mupa_uset(ctx
) < 0)
6278 if (test_mupa_ma(ctx
) < 0)
6280 if (test_mupa_pa(ctx
) < 0)
6282 if (test_mupa_pma(ctx
) < 0)
6284 if (test_mupa_upma(ctx
) < 0)
6287 space
= isl_space_set_alloc(ctx
, 0, 1);
6288 ls
= isl_local_space_from_space(space
);
6289 aff
= isl_aff_zero_on_domain(ls
);
6291 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6292 aff
= isl_aff_scale_down_ui(aff
, 3);
6293 aff
= isl_aff_floor(aff
);
6294 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6295 aff
= isl_aff_scale_down_ui(aff
, 2);
6296 aff
= isl_aff_floor(aff
);
6297 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6300 set
= isl_set_read_from_str(ctx
, str
);
6301 aff
= isl_aff_gist(aff
, set
);
6303 aff
= isl_aff_add_constant_si(aff
, -16);
6304 zero
= isl_aff_plain_is_zero(aff
);
6310 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6312 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6313 aff
= isl_aff_scale_down_ui(aff
, 64);
6314 aff
= isl_aff_floor(aff
);
6315 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6320 if (test_aff_set_tuple_id(ctx
) < 0)
6326 /* Check that "pa" consists of a single expression.
6328 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
6332 n
= isl_pw_aff_n_piece(pa
);
6333 isl_pw_aff_free(pa
);
6338 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
6344 /* Check that the computation below results in a single expression.
6345 * One or two expressions may result depending on which constraint
6346 * ends up being considered as redundant with respect to the other
6347 * constraints after the projection that is performed internally
6348 * by isl_set_dim_min.
6350 static int test_dim_max_1(isl_ctx
*ctx
)
6356 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6357 "-4a <= b <= 3 and b < n - 4a }";
6358 set
= isl_set_read_from_str(ctx
, str
);
6359 pa
= isl_set_dim_min(set
, 0);
6360 return check_single_piece(ctx
, pa
);
6363 /* Check that the computation below results in a single expression.
6364 * The PIP problem corresponding to these constraints has a row
6365 * that causes a split of the solution domain. The solver should
6366 * first pick rows that split off empty parts such that the actual
6367 * solution domain does not get split.
6368 * Note that the description contains some redundant constraints.
6369 * If these constraints get removed first, then the row mentioned
6370 * above does not appear in the PIP problem.
6372 static int test_dim_max_2(isl_ctx
*ctx
)
6378 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6379 "N > 0 and P >= 0 }";
6380 set
= isl_set_read_from_str(ctx
, str
);
6381 pa
= isl_set_dim_max(set
, 0);
6382 return check_single_piece(ctx
, pa
);
6385 int test_dim_max(isl_ctx
*ctx
)
6389 isl_set
*set1
, *set2
;
6394 if (test_dim_max_1(ctx
) < 0)
6396 if (test_dim_max_2(ctx
) < 0)
6399 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
6400 set
= isl_set_read_from_str(ctx
, str
);
6401 pwaff
= isl_set_dim_max(set
, 0);
6402 set1
= isl_set_from_pw_aff(pwaff
);
6403 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6404 set2
= isl_set_read_from_str(ctx
, str
);
6405 equal
= isl_set_is_equal(set1
, set2
);
6411 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6413 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6414 set
= isl_set_read_from_str(ctx
, str
);
6415 pwaff
= isl_set_dim_max(set
, 0);
6416 set1
= isl_set_from_pw_aff(pwaff
);
6417 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6418 set2
= isl_set_read_from_str(ctx
, str
);
6419 equal
= isl_set_is_equal(set1
, set2
);
6425 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6427 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6428 set
= isl_set_read_from_str(ctx
, str
);
6429 pwaff
= isl_set_dim_max(set
, 0);
6430 set1
= isl_set_from_pw_aff(pwaff
);
6431 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6432 set2
= isl_set_read_from_str(ctx
, str
);
6433 equal
= isl_set_is_equal(set1
, set2
);
6439 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6441 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6442 "0 <= i < N and 0 <= j < M }";
6443 map
= isl_map_read_from_str(ctx
, str
);
6444 set
= isl_map_range(map
);
6446 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
6447 set1
= isl_set_from_pw_aff(pwaff
);
6448 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6449 set2
= isl_set_read_from_str(ctx
, str
);
6450 equal
= isl_set_is_equal(set1
, set2
);
6454 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
6455 set1
= isl_set_from_pw_aff(pwaff
);
6456 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6457 set2
= isl_set_read_from_str(ctx
, str
);
6458 if (equal
>= 0 && equal
)
6459 equal
= isl_set_is_equal(set1
, set2
);
6468 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6470 /* Check that solutions are properly merged. */
6471 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
6472 "c <= -1 + n - 4a - 2b and c >= -2b and "
6473 "4a >= -4 + n and c >= 0 }";
6474 set
= isl_set_read_from_str(ctx
, str
);
6475 pwaff
= isl_set_dim_min(set
, 2);
6476 set1
= isl_set_from_pw_aff(pwaff
);
6477 str
= "[n] -> { [(0)] : n >= 1 }";
6478 set2
= isl_set_read_from_str(ctx
, str
);
6479 equal
= isl_set_is_equal(set1
, set2
);
6486 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6488 /* Check that empty solution lie in the right space. */
6489 str
= "[n] -> { [t,a] : 1 = 0 }";
6490 set
= isl_set_read_from_str(ctx
, str
);
6491 pwaff
= isl_set_dim_max(set
, 0);
6492 set1
= isl_set_from_pw_aff(pwaff
);
6493 str
= "[n] -> { [t] : 1 = 0 }";
6494 set2
= isl_set_read_from_str(ctx
, str
);
6495 equal
= isl_set_is_equal(set1
, set2
);
6502 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6507 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6509 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
6513 isl_pw_multi_aff
*pma2
;
6519 ctx
= isl_pw_multi_aff_get_ctx(pma
);
6520 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6521 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
6522 isl_pw_multi_aff_free(pma2
);
6527 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6528 * represented by "str".
6530 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
6535 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
6539 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
6540 "result not as expected", return -1);
6544 /* Basic test for isl_pw_multi_aff_product.
6546 * Check that multiple pieces are properly handled.
6548 static int test_product_pma(isl_ctx
*ctx
)
6552 isl_pw_multi_aff
*pma1
, *pma2
;
6554 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6555 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6556 str
= "{ C[] -> D[] }";
6557 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6558 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
6559 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6560 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6561 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
6562 isl_pw_multi_aff_free(pma1
);
6569 int test_product(isl_ctx
*ctx
)
6573 isl_union_set
*uset1
, *uset2
;
6577 set
= isl_set_read_from_str(ctx
, str
);
6578 set
= isl_set_product(set
, isl_set_copy(set
));
6579 ok
= isl_set_is_wrapping(set
);
6584 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6587 uset1
= isl_union_set_read_from_str(ctx
, str
);
6588 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
6589 str
= "{ [[] -> []] }";
6590 uset2
= isl_union_set_read_from_str(ctx
, str
);
6591 ok
= isl_union_set_is_equal(uset1
, uset2
);
6592 isl_union_set_free(uset1
);
6593 isl_union_set_free(uset2
);
6597 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6599 if (test_product_pma(ctx
) < 0)
6605 /* Check that two sets are not considered disjoint just because
6606 * they have a different set of (named) parameters.
6608 static int test_disjoint(isl_ctx
*ctx
)
6611 isl_set
*set
, *set2
;
6614 str
= "[n] -> { [[]->[]] }";
6615 set
= isl_set_read_from_str(ctx
, str
);
6616 str
= "{ [[]->[]] }";
6617 set2
= isl_set_read_from_str(ctx
, str
);
6618 disjoint
= isl_set_is_disjoint(set
, set2
);
6624 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6629 /* Inputs for isl_pw_multi_aff_is_equal tests.
6630 * "f1" and "f2" are the two function that need to be compared.
6631 * "equal" is the expected result.
6637 } pma_equal_tests
[] = {
6638 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6639 "[N] -> { [0] : 0 <= N <= 1 }" },
6640 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6641 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6642 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6643 "[N] -> { [0] : 0 <= N <= 1 }" },
6644 { 0, "{ [NaN] }", "{ [NaN] }" },
6647 int test_equal(isl_ctx
*ctx
)
6651 isl_set
*set
, *set2
;
6655 set
= isl_set_read_from_str(ctx
, str
);
6657 set2
= isl_set_read_from_str(ctx
, str
);
6658 equal
= isl_set_is_equal(set
, set2
);
6664 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6666 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
6667 int expected
= pma_equal_tests
[i
].equal
;
6668 isl_pw_multi_aff
*f1
, *f2
;
6670 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
6671 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
6672 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
6673 isl_pw_multi_aff_free(f1
);
6674 isl_pw_multi_aff_free(f2
);
6677 if (equal
!= expected
)
6678 isl_die(ctx
, isl_error_unknown
,
6679 "unexpected equality result", return -1);
6685 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
6686 enum isl_dim_type type
, unsigned pos
, int fixed
)
6690 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
6697 isl_die(ctx
, isl_error_unknown
,
6698 "map not detected as fixed", return -1);
6700 isl_die(ctx
, isl_error_unknown
,
6701 "map detected as fixed", return -1);
6704 int test_fixed(isl_ctx
*ctx
)
6709 str
= "{ [i] -> [i] }";
6710 map
= isl_map_read_from_str(ctx
, str
);
6711 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
6713 str
= "{ [i] -> [1] }";
6714 map
= isl_map_read_from_str(ctx
, str
);
6715 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6717 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6718 map
= isl_map_read_from_str(ctx
, str
);
6719 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6721 map
= isl_map_read_from_str(ctx
, str
);
6722 map
= isl_map_neg(map
);
6723 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6729 struct isl_vertices_test_data
{
6732 const char *vertex
[6];
6733 } vertices_tests
[] = {
6734 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6735 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6736 { "{ A[t, i] : t = 14 and i = 1 }",
6737 1, { "{ A[14, 1] }" } },
6738 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6739 "c <= m and m <= n and m > 0 }",
6741 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6742 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6743 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6744 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6745 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6746 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6750 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
6752 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
6754 struct isl_vertices_test_data
*data
= user
;
6757 isl_basic_set
*bset
;
6758 isl_pw_multi_aff
*pma
;
6762 ctx
= isl_vertex_get_ctx(vertex
);
6763 bset
= isl_vertex_get_domain(vertex
);
6764 ma
= isl_vertex_get_expr(vertex
);
6765 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
6767 for (i
= 0; i
< data
->n
; ++i
) {
6768 isl_pw_multi_aff
*pma_i
;
6770 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
6771 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
6772 isl_pw_multi_aff_free(pma_i
);
6774 if (equal
< 0 || equal
)
6778 isl_pw_multi_aff_free(pma
);
6779 isl_vertex_free(vertex
);
6782 return isl_stat_error
;
6784 return equal
? isl_stat_ok
: isl_stat_error
;
6787 int test_vertices(isl_ctx
*ctx
)
6791 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
6792 isl_basic_set
*bset
;
6793 isl_vertices
*vertices
;
6797 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
6798 vertices
= isl_basic_set_compute_vertices(bset
);
6799 n
= isl_vertices_get_n_vertices(vertices
);
6800 if (vertices_tests
[i
].n
!= n
)
6802 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
6803 &vertices_tests
[i
]) < 0)
6805 isl_vertices_free(vertices
);
6806 isl_basic_set_free(bset
);
6811 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
6818 int test_union_pw(isl_ctx
*ctx
)
6822 isl_union_set
*uset
;
6823 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
6825 str
= "{ [x] -> x^2 }";
6826 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6827 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
6828 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
6829 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
6830 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
6831 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
6832 isl_union_pw_qpolynomial_free(upwqp1
);
6833 isl_union_pw_qpolynomial_free(upwqp2
);
6837 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6842 /* Inputs for basic tests of functions that select
6843 * subparts of the domain of an isl_multi_union_pw_aff.
6844 * "fn" is the function that is tested.
6845 * "arg" is a string description of the input.
6846 * "res" is a string description of the expected result.
6849 __isl_give isl_union_set
*(*fn
)(
6850 __isl_take isl_multi_union_pw_aff
*mupa
);
6853 } un_locus_tests
[] = {
6854 { &isl_multi_union_pw_aff_zero_union_set
,
6855 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6856 "{ A[0,j]; B[0,j] }" },
6857 { &isl_multi_union_pw_aff_zero_union_set
,
6858 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
6859 "{ A[i,i]; B[i,i] : i >= 0 }" },
6860 { &isl_multi_union_pw_aff_zero_union_set
,
6861 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
6862 "{ A[i,j]; B[i,i] : i >= 0 }" },
6865 /* Perform some basic tests of functions that select
6866 * subparts of the domain of an isl_multi_union_pw_aff.
6868 static int test_un_locus(isl_ctx
*ctx
)
6872 isl_union_set
*uset
, *res
;
6873 isl_multi_union_pw_aff
*mupa
;
6875 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
6876 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6877 un_locus_tests
[i
].arg
);
6878 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
6879 uset
= un_locus_tests
[i
].fn(mupa
);
6880 ok
= isl_union_set_is_equal(uset
, res
);
6881 isl_union_set_free(uset
);
6882 isl_union_set_free(res
);
6886 isl_die(ctx
, isl_error_unknown
,
6887 "unexpected result", return -1);
6893 /* Inputs for basic tests of functions that select
6894 * subparts of an isl_union_map based on a relation
6895 * specified by an isl_multi_union_pw_aff.
6896 * "fn" is the function that is tested.
6897 * "arg1" and "arg2" are string descriptions of the inputs.
6898 * "res" is a string description of the expected result.
6901 __isl_give isl_union_map
*(*fn
)(
6902 __isl_take isl_union_map
*umap
,
6903 __isl_take isl_multi_union_pw_aff
*mupa
);
6907 } bin_locus_tests
[] = {
6908 { &isl_union_map_eq_at_multi_union_pw_aff
,
6909 "{ A[i,j] -> B[i',j'] }",
6910 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6911 "{ A[i,j] -> B[i,j'] }" },
6912 { &isl_union_map_eq_at_multi_union_pw_aff
,
6913 "{ A[i,j] -> B[i',j'] }",
6914 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6915 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6916 "{ A[i,j] -> B[i,j] }" },
6917 { &isl_union_map_eq_at_multi_union_pw_aff
,
6918 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6919 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6920 "{ A[i,j] -> B[i,j'] }" },
6921 { &isl_union_map_eq_at_multi_union_pw_aff
,
6922 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6923 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
6924 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
6925 { &isl_union_map_eq_at_multi_union_pw_aff
,
6926 "{ A[i,j] -> B[i',j'] }",
6927 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
6928 "{ A[i,j] -> B[i,j'] : i > j }" },
6929 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
6930 "{ A[i,j] -> B[i',j'] }",
6931 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6932 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6933 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
6934 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
6935 "{ A[i,j] -> B[i',j'] }",
6936 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6937 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6938 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
6939 { &isl_union_map_eq_at_multi_union_pw_aff
,
6940 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6941 "(F[] : { A[i,j]; B[i,j] })",
6942 "{ A[i,j] -> B[i',j'] }" },
6943 { &isl_union_map_eq_at_multi_union_pw_aff
,
6944 "{ A[i,j] -> B[i',j'] }",
6945 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6946 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
6947 { &isl_union_map_eq_at_multi_union_pw_aff
,
6948 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
6949 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6950 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
6951 { &isl_union_map_eq_at_multi_union_pw_aff
,
6952 "{ A[i,j] -> B[i',j'] }",
6953 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
6954 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
6955 { &isl_union_map_eq_at_multi_union_pw_aff
,
6956 "{ A[i,j] -> B[i',j'] }",
6957 "[N] -> (F[] : { : N >= 0 })",
6958 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
6961 /* Perform some basic tests of functions that select
6962 * subparts of an isl_union_map based on a relation
6963 * specified by an isl_multi_union_pw_aff.
6965 static int test_bin_locus(isl_ctx
*ctx
)
6969 isl_union_map
*umap
, *res
;
6970 isl_multi_union_pw_aff
*mupa
;
6972 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
6973 umap
= isl_union_map_read_from_str(ctx
,
6974 bin_locus_tests
[i
].arg1
);
6975 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6976 bin_locus_tests
[i
].arg2
);
6977 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
6978 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
6979 ok
= isl_union_map_is_equal(umap
, res
);
6980 isl_union_map_free(umap
);
6981 isl_union_map_free(res
);
6985 isl_die(ctx
, isl_error_unknown
,
6986 "unexpected result", return -1);
6992 /* Perform basic locus tests.
6994 static int test_locus(isl_ctx
*ctx
)
6996 if (test_un_locus(ctx
) < 0)
6998 if (test_bin_locus(ctx
) < 0)
7003 /* Test that isl_union_pw_qpolynomial_eval picks up the function
7004 * defined over the correct domain space.
7006 static int test_eval_1(isl_ctx
*ctx
)
7011 isl_union_pw_qpolynomial
*upwqp
;
7015 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
7016 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
7018 set
= isl_set_read_from_str(ctx
, str
);
7019 pnt
= isl_set_sample_point(set
);
7020 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
7021 cmp
= isl_val_cmp_si(v
, 36);
7027 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
7032 /* Check that isl_qpolynomial_eval handles getting called on a void point.
7034 static int test_eval_2(isl_ctx
*ctx
)
7039 isl_qpolynomial
*qp
;
7043 str
= "{ A[x] -> [x] }";
7044 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
7045 str
= "{ A[x] : false }";
7046 set
= isl_set_read_from_str(ctx
, str
);
7047 pnt
= isl_set_sample_point(set
);
7048 v
= isl_qpolynomial_eval(qp
, pnt
);
7049 ok
= isl_val_is_nan(v
);
7055 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
7060 /* Check that a polynomial (without local variables) can be evaluated
7061 * in a rational point.
7063 static isl_stat
test_eval_3(isl_ctx
*ctx
)
7065 isl_pw_qpolynomial
*pwqp
;
7070 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
7071 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
7072 v
= isl_val_read_from_str(ctx
, "1/2");
7073 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
7074 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
7075 r
= val_check_equal(v
, "1/4");
7081 /* Inputs for isl_pw_aff_eval test.
7082 * "f" is the affine function.
7083 * "p" is the point where the function should be evaluated.
7084 * "res" is the expected result.
7090 } aff_eval_tests
[] = {
7091 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
7092 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
7093 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
7094 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
7095 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
7096 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
7097 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
7098 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
7099 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
7100 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
7101 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
7102 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
7103 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
7104 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
7105 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
7106 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
7107 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
7108 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
7109 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
7110 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
7111 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
7112 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
7113 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
7116 /* Perform basic isl_pw_aff_eval tests.
7118 static int test_eval_aff(isl_ctx
*ctx
)
7122 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
7129 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
7130 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
7131 pnt
= isl_set_sample_point(set
);
7132 v
= isl_pw_aff_eval(pa
, pnt
);
7133 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
7141 /* Perform basic evaluation tests.
7143 static int test_eval(isl_ctx
*ctx
)
7145 if (test_eval_1(ctx
) < 0)
7147 if (test_eval_2(ctx
) < 0)
7149 if (test_eval_3(ctx
) < 0)
7151 if (test_eval_aff(ctx
) < 0)
7156 /* Descriptions of sets that are tested for reparsing after printing.
7158 const char *output_tests
[] = {
7159 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
7162 "{ [x] : x mod 2 = 0 }",
7163 "{ [x] : x mod 2 = 1 }",
7164 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
7165 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
7166 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7167 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7168 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
7169 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
7172 /* Check that printing a set and reparsing a set from the printed output
7173 * results in the same set.
7175 static int test_output_set(isl_ctx
*ctx
)
7179 isl_set
*set1
, *set2
;
7182 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
7183 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
7184 str
= isl_set_to_str(set1
);
7185 set2
= isl_set_read_from_str(ctx
, str
);
7187 equal
= isl_set_is_equal(set1
, set2
);
7193 isl_die(ctx
, isl_error_unknown
,
7194 "parsed output not the same", return -1);
7200 /* Check that an isl_multi_aff is printed using a consistent space.
7202 static isl_stat
test_output_ma(isl_ctx
*ctx
)
7207 isl_multi_aff
*ma
, *ma2
;
7209 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7210 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7211 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
7212 str
= isl_multi_aff_to_str(ma
);
7213 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7215 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
7216 isl_multi_aff_free(ma2
);
7217 isl_multi_aff_free(ma
);
7220 return isl_stat_error
;
7222 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7223 return isl_stat_error
);
7228 /* Check that an isl_multi_pw_aff is printed using a consistent space.
7230 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
7235 isl_multi_pw_aff
*mpa
, *mpa2
;
7237 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7238 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7239 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
7240 str
= isl_multi_pw_aff_to_str(mpa
);
7241 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
7243 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
7244 isl_multi_pw_aff_free(mpa2
);
7245 isl_multi_pw_aff_free(mpa
);
7248 return isl_stat_error
;
7250 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7251 return isl_stat_error
);
7256 int test_output(isl_ctx
*ctx
)
7264 if (test_output_set(ctx
) < 0)
7266 if (test_output_ma(ctx
) < 0)
7268 if (test_output_mpa(ctx
) < 0)
7271 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
7272 pa
= isl_pw_aff_read_from_str(ctx
, str
);
7274 p
= isl_printer_to_str(ctx
);
7275 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
7276 p
= isl_printer_print_pw_aff(p
, pa
);
7277 s
= isl_printer_get_str(p
);
7278 isl_printer_free(p
);
7279 isl_pw_aff_free(pa
);
7283 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
7288 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7293 int test_sample(isl_ctx
*ctx
)
7296 isl_basic_set
*bset1
, *bset2
;
7299 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
7300 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
7301 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
7302 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
7303 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
7304 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
7305 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
7306 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
7307 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
7308 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
7309 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
7310 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
7311 "d - 1073741821e and "
7312 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
7313 "3j >= 1 - a + b + 2e and "
7314 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
7315 "3i <= 4 - a + 4b - e and "
7316 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
7317 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
7318 "c <= -1 + a and 3i >= -2 - a + 3e and "
7319 "1073741822e <= 1073741823 - a + 1073741822b + c and "
7320 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
7321 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
7322 "1073741823e >= 1 + 1073741823b - d and "
7323 "3i >= 1073741823b + c - 1073741823e - f and "
7324 "3i >= 1 + 2b + e + 3g }";
7325 bset1
= isl_basic_set_read_from_str(ctx
, str
);
7326 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
7327 empty
= isl_basic_set_is_empty(bset2
);
7328 subset
= isl_basic_set_is_subset(bset2
, bset1
);
7329 isl_basic_set_free(bset1
);
7330 isl_basic_set_free(bset2
);
7331 if (empty
< 0 || subset
< 0)
7334 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
7336 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
7341 int test_fixed_power(isl_ctx
*ctx
)
7348 str
= "{ [i] -> [i + 1] }";
7349 map
= isl_map_read_from_str(ctx
, str
);
7350 exp
= isl_val_int_from_si(ctx
, 23);
7351 map
= isl_map_fixed_power_val(map
, exp
);
7352 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
7360 int test_slice(isl_ctx
*ctx
)
7366 str
= "{ [i] -> [j] }";
7367 map
= isl_map_read_from_str(ctx
, str
);
7368 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7369 equal
= map_check_equal(map
, "{ [i] -> [i] }");
7374 str
= "{ [i] -> [j] }";
7375 map
= isl_map_read_from_str(ctx
, str
);
7376 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7377 equal
= map_check_equal(map
, "{ [i] -> [j] }");
7382 str
= "{ [i] -> [j] }";
7383 map
= isl_map_read_from_str(ctx
, str
);
7384 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7385 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
7390 str
= "{ [i] -> [j] }";
7391 map
= isl_map_read_from_str(ctx
, str
);
7392 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7393 equal
= map_check_equal(map
, "{ [0] -> [j] }");
7398 str
= "{ [i] -> [j] }";
7399 map
= isl_map_read_from_str(ctx
, str
);
7400 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7401 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
7406 str
= "{ [i] -> [j] }";
7407 map
= isl_map_read_from_str(ctx
, str
);
7408 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7409 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
7417 int test_eliminate(isl_ctx
*ctx
)
7423 str
= "{ [i] -> [j] : i = 2j }";
7424 map
= isl_map_read_from_str(ctx
, str
);
7425 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
7426 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
7434 /* Check that isl_set_dim_residue_class detects that the values of j
7435 * in the set below are all odd and that it does not detect any spurious
7438 static int test_residue_class(isl_ctx
*ctx
)
7445 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7446 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7447 set
= isl_set_read_from_str(ctx
, str
);
7450 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
7452 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
7453 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
7454 res
= isl_stat_error
);
7462 static int test_align_parameters_1(isl_ctx
*ctx
)
7466 isl_multi_aff
*ma1
, *ma2
;
7469 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7470 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
7472 space
= isl_space_params_alloc(ctx
, 1);
7473 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
7474 ma1
= isl_multi_aff_align_params(ma1
, space
);
7476 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7477 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7479 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7481 isl_multi_aff_free(ma1
);
7482 isl_multi_aff_free(ma2
);
7487 isl_die(ctx
, isl_error_unknown
,
7488 "result not as expected", return -1);
7493 /* Check the isl_multi_*_from_*_list operation in case inputs
7494 * have unaligned parameters.
7495 * In particular, older versions of isl would simply fail
7496 * (without printing any error message).
7498 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
7505 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
7506 space
= isl_map_get_space(map
);
7509 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
7510 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
7511 isl_multi_aff_free(ma
);
7514 return isl_stat_error
;
7518 /* Perform basic parameter alignment tests.
7520 static int test_align_parameters(isl_ctx
*ctx
)
7522 if (test_align_parameters_1(ctx
) < 0)
7524 if (test_align_parameters_2(ctx
) < 0)
7530 /* Check that isl_*_drop_unused_params actually drops the unused parameters
7531 * by comparing the result using isl_*_plain_is_equal.
7532 * Note that this assumes that isl_*_plain_is_equal does not consider
7533 * objects that only differ by unused parameters to be equal.
7535 int test_drop_unused_parameters(isl_ctx
*ctx
)
7537 const char *str_with
, *str_without
;
7538 isl_basic_set
*bset1
, *bset2
;
7539 isl_set
*set1
, *set2
;
7540 isl_pw_aff
*pwa1
, *pwa2
;
7543 str_with
= "[n, m, o] -> { [m] }";
7544 str_without
= "[m] -> { [m] }";
7546 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
7547 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
7548 bset1
= isl_basic_set_drop_unused_params(bset1
);
7549 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
7550 isl_basic_set_free(bset1
);
7551 isl_basic_set_free(bset2
);
7556 isl_die(ctx
, isl_error_unknown
,
7557 "result not as expected", return -1);
7559 set1
= isl_set_read_from_str(ctx
, str_with
);
7560 set2
= isl_set_read_from_str(ctx
, str_without
);
7561 set1
= isl_set_drop_unused_params(set1
);
7562 equal
= isl_set_plain_is_equal(set1
, set2
);
7569 isl_die(ctx
, isl_error_unknown
,
7570 "result not as expected", return -1);
7572 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
7573 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
7574 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
7575 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
7576 isl_pw_aff_free(pwa1
);
7577 isl_pw_aff_free(pwa2
);
7582 isl_die(ctx
, isl_error_unknown
,
7583 "result not as expected", return -1);
7588 static int test_list(isl_ctx
*ctx
)
7590 isl_id
*a
, *b
, *c
, *d
, *id
;
7595 a
= isl_id_alloc(ctx
, "a", NULL
);
7596 b
= isl_id_alloc(ctx
, "b", NULL
);
7597 c
= isl_id_alloc(ctx
, "c", NULL
);
7598 d
= isl_id_alloc(ctx
, "d", NULL
);
7600 list
= isl_id_list_alloc(ctx
, 4);
7601 list
= isl_id_list_add(list
, b
);
7602 list
= isl_id_list_insert(list
, 0, a
);
7603 list
= isl_id_list_add(list
, c
);
7604 list
= isl_id_list_add(list
, d
);
7605 list
= isl_id_list_drop(list
, 1, 1);
7607 n
= isl_id_list_n_id(list
);
7611 isl_id_list_free(list
);
7612 isl_die(ctx
, isl_error_unknown
,
7613 "unexpected number of elements in list", return -1);
7616 id
= isl_id_list_get_id(list
, 0);
7619 id
= isl_id_list_get_id(list
, 1);
7622 id
= isl_id_list_get_id(list
, 2);
7626 isl_id_list_free(list
);
7629 isl_die(ctx
, isl_error_unknown
,
7630 "unexpected elements in list", return -1);
7635 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
7637 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
7642 isl_basic_set
*bset1
, *bset2
;
7644 str
= "[N] -> { A[0, N + 1] }";
7645 ma
= isl_multi_aff_read_from_str(ctx
, str
);
7646 bset1
= isl_basic_set_read_from_str(ctx
, str
);
7647 bset2
= isl_basic_set_from_multi_aff(ma
);
7648 equal
= isl_basic_set_is_equal(bset1
, bset2
);
7649 isl_basic_set_free(bset1
);
7650 isl_basic_set_free(bset2
);
7652 return isl_stat_error
;
7654 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7655 return isl_stat_error
);
7659 const char *set_conversion_tests
[] = {
7660 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7661 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7662 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7663 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7664 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7665 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7666 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7667 "-3 + c <= d <= 28 + c) }",
7670 /* Check that converting from isl_set to isl_pw_multi_aff and back
7671 * to isl_set produces the original isl_set.
7673 static int test_set_conversion(isl_ctx
*ctx
)
7677 isl_set
*set1
, *set2
;
7678 isl_pw_multi_aff
*pma
;
7681 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
7682 str
= set_conversion_tests
[i
];
7683 set1
= isl_set_read_from_str(ctx
, str
);
7684 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
7685 set2
= isl_set_from_pw_multi_aff(pma
);
7686 equal
= isl_set_is_equal(set1
, set2
);
7693 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7700 const char *conversion_tests
[] = {
7701 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7702 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7703 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7704 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7706 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7707 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7708 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7711 /* Check that converting from isl_map to isl_pw_multi_aff and back
7712 * to isl_map produces the original isl_map.
7714 static int test_map_conversion(isl_ctx
*ctx
)
7717 isl_map
*map1
, *map2
;
7718 isl_pw_multi_aff
*pma
;
7721 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
7722 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
7723 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
7724 map2
= isl_map_from_pw_multi_aff(pma
);
7725 equal
= isl_map_is_equal(map1
, map2
);
7732 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7739 /* Descriptions of isl_pw_multi_aff objects for testing conversion
7740 * to isl_multi_pw_aff and back.
7742 const char *mpa_conversion_tests
[] = {
7744 "{ [x] -> A[x] : x >= 0 }",
7745 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
7746 "{ [x] -> A[x, x + 1] }",
7748 "{ [x] -> A[] : x >= 0 }",
7751 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
7752 * back to isl_pw_multi_aff preserves the original meaning.
7754 static int test_mpa_conversion(isl_ctx
*ctx
)
7757 isl_pw_multi_aff
*pma1
, *pma2
;
7758 isl_multi_pw_aff
*mpa
;
7761 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
7763 str
= mpa_conversion_tests
[i
];
7764 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7765 pma2
= isl_pw_multi_aff_copy(pma1
);
7766 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
7767 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
7768 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
7769 isl_pw_multi_aff_free(pma1
);
7770 isl_pw_multi_aff_free(pma2
);
7775 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7782 /* Descriptions of union maps that should be convertible
7783 * to an isl_multi_union_pw_aff.
7785 const char *umap_mupa_conversion_tests
[] = {
7786 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7787 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7788 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7789 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7791 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7792 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7793 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7794 "{ A[] -> B[0]; C[] -> B[1] }",
7795 "{ A[] -> B[]; C[] -> B[] }",
7798 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
7799 * to isl_union_map produces the original isl_union_map.
7801 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
7804 isl_union_map
*umap1
, *umap2
;
7805 isl_multi_union_pw_aff
*mupa
;
7808 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
7810 str
= umap_mupa_conversion_tests
[i
];
7811 umap1
= isl_union_map_read_from_str(ctx
, str
);
7812 umap2
= isl_union_map_copy(umap1
);
7813 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
7814 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
7815 equal
= isl_union_map_is_equal(umap1
, umap2
);
7816 isl_union_map_free(umap1
);
7817 isl_union_map_free(umap2
);
7822 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7829 static int test_conversion(isl_ctx
*ctx
)
7831 if (test_ma_conversion(ctx
) < 0)
7833 if (test_set_conversion(ctx
) < 0)
7835 if (test_map_conversion(ctx
) < 0)
7837 if (test_mpa_conversion(ctx
) < 0)
7839 if (test_union_map_mupa_conversion(ctx
) < 0)
7844 /* Check that isl_basic_map_curry does not modify input.
7846 static int test_curry(isl_ctx
*ctx
)
7849 isl_basic_map
*bmap1
, *bmap2
;
7852 str
= "{ [A[] -> B[]] -> C[] }";
7853 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
7854 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
7855 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
7856 isl_basic_map_free(bmap1
);
7857 isl_basic_map_free(bmap2
);
7862 isl_die(ctx
, isl_error_unknown
,
7863 "curried map should not be equal to original",
7873 } preimage_tests
[] = {
7874 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
7875 "{ A[j,i] -> B[i,j] }",
7876 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
7877 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7878 "{ A[a,b] -> B[a/2,b/6] }",
7879 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
7880 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7881 "{ A[a,b] -> B[a/2,b/6] }",
7882 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
7883 "exists i,j : a = 2 i and b = 6 j }" },
7884 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
7885 "[n] -> { : 0 <= n <= 100 }" },
7886 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7887 "{ A[a] -> B[2a] }",
7888 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
7889 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7890 "{ A[a] -> B[([a/2])] }",
7891 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
7892 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
7893 "{ A[a] -> B[a,a,a/3] }",
7894 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
7895 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
7896 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
7899 static int test_preimage_basic_set(isl_ctx
*ctx
)
7902 isl_basic_set
*bset1
, *bset2
;
7906 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
7907 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
7908 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
7909 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
7910 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
7911 equal
= isl_basic_set_is_equal(bset1
, bset2
);
7912 isl_basic_set_free(bset1
);
7913 isl_basic_set_free(bset2
);
7917 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7928 } preimage_domain_tests
[] = {
7929 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
7930 "{ A[j,i] -> B[i,j] }",
7931 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
7932 { "{ B[i] -> C[i]; D[i] -> E[i] }",
7933 "{ A[i] -> B[i + 1] }",
7934 "{ A[i] -> C[i + 1] }" },
7935 { "{ B[i] -> C[i]; B[i] -> E[i] }",
7936 "{ A[i] -> B[i + 1] }",
7937 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
7938 { "{ B[i] -> C[([i/2])] }",
7939 "{ A[i] -> B[2i] }",
7940 "{ A[i] -> C[i] }" },
7941 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
7942 "{ A[i] -> B[([i/5]), ([i/7])] }",
7943 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
7944 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
7945 "[N] -> { A[] -> B[([N/5])] }",
7946 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
7947 { "{ B[i] -> C[i] : exists a : i = 5 a }",
7948 "{ A[i] -> B[2i] }",
7949 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
7950 { "{ B[i] -> C[i] : exists a : i = 2 a; "
7951 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
7952 "{ A[i] -> B[2i] }",
7953 "{ A[i] -> C[2i] }" },
7954 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
7955 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
7958 static int test_preimage_union_map(isl_ctx
*ctx
)
7961 isl_union_map
*umap1
, *umap2
;
7965 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
7966 umap1
= isl_union_map_read_from_str(ctx
,
7967 preimage_domain_tests
[i
].map
);
7968 ma
= isl_multi_aff_read_from_str(ctx
,
7969 preimage_domain_tests
[i
].ma
);
7970 umap2
= isl_union_map_read_from_str(ctx
,
7971 preimage_domain_tests
[i
].res
);
7972 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
7973 equal
= isl_union_map_is_equal(umap1
, umap2
);
7974 isl_union_map_free(umap1
);
7975 isl_union_map_free(umap2
);
7979 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7986 static int test_preimage(isl_ctx
*ctx
)
7988 if (test_preimage_basic_set(ctx
) < 0)
7990 if (test_preimage_union_map(ctx
) < 0)
8000 } pullback_tests
[] = {
8001 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
8002 "{ A[a,b] -> C[b + 2a] }" },
8003 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
8004 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
8005 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
8006 "{ A[a] -> C[(a)/6] }" },
8007 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
8008 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
8009 "{ A[a] -> C[(2a)/3] }" },
8010 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
8011 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
8012 "{ A[i,j] -> C[i + j, i + j] }"},
8013 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
8014 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
8015 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
8016 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
8017 "{ [i, j] -> [floor((i)/3), j] }",
8018 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
8021 static int test_pullback(isl_ctx
*ctx
)
8024 isl_multi_aff
*ma1
, *ma2
;
8028 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
8029 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
8030 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
8031 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
8032 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
8033 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8034 isl_multi_aff_free(ma1
);
8035 isl_multi_aff_free(ma2
);
8039 isl_die(ctx
, isl_error_unknown
, "bad pullback",
8046 /* Check that negation is printed correctly and that equal expressions
8047 * are correctly identified.
8049 static int test_ast(isl_ctx
*ctx
)
8051 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
8055 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8056 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8057 expr
= isl_ast_expr_add(expr1
, expr2
);
8058 expr2
= isl_ast_expr_copy(expr
);
8059 expr
= isl_ast_expr_neg(expr
);
8060 expr2
= isl_ast_expr_neg(expr2
);
8061 equal
= isl_ast_expr_is_equal(expr
, expr2
);
8062 str
= isl_ast_expr_to_C_str(expr
);
8063 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
8065 isl_ast_expr_free(expr
);
8066 isl_ast_expr_free(expr2
);
8068 if (ok
< 0 || equal
< 0)
8071 isl_die(ctx
, isl_error_unknown
,
8072 "equal expressions not considered equal", return -1);
8074 isl_die(ctx
, isl_error_unknown
,
8075 "isl_ast_expr printed incorrectly", return -1);
8077 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8078 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8079 expr
= isl_ast_expr_add(expr1
, expr2
);
8080 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
8081 expr
= isl_ast_expr_sub(expr3
, expr
);
8082 str
= isl_ast_expr_to_C_str(expr
);
8083 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
8085 isl_ast_expr_free(expr
);
8090 isl_die(ctx
, isl_error_unknown
,
8091 "isl_ast_expr printed incorrectly", return -1);
8096 /* Check that isl_ast_build_expr_from_set returns a valid expression
8097 * for an empty set. Note that isl_ast_build_expr_from_set getting
8098 * called on an empty set probably indicates a bug in the caller.
8100 static int test_ast_build(isl_ctx
*ctx
)
8103 isl_ast_build
*build
;
8106 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8107 build
= isl_ast_build_from_context(set
);
8109 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
8110 expr
= isl_ast_build_expr_from_set(build
, set
);
8112 isl_ast_expr_free(expr
);
8113 isl_ast_build_free(build
);
8121 /* Internal data structure for before_for and after_for callbacks.
8123 * depth is the current depth
8124 * before is the number of times before_for has been called
8125 * after is the number of times after_for has been called
8127 struct isl_test_codegen_data
{
8133 /* This function is called before each for loop in the AST generated
8134 * from test_ast_gen1.
8136 * Increment the number of calls and the depth.
8137 * Check that the space returned by isl_ast_build_get_schedule_space
8138 * matches the target space of the schedule returned by
8139 * isl_ast_build_get_schedule.
8140 * Return an isl_id that is checked by the corresponding call
8143 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
8146 struct isl_test_codegen_data
*data
= user
;
8149 isl_union_map
*schedule
;
8150 isl_union_set
*uset
;
8156 ctx
= isl_ast_build_get_ctx(build
);
8158 if (data
->before
>= 3)
8159 isl_die(ctx
, isl_error_unknown
,
8160 "unexpected number of for nodes", return NULL
);
8161 if (data
->depth
>= 2)
8162 isl_die(ctx
, isl_error_unknown
,
8163 "unexpected depth", return NULL
);
8165 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
8169 schedule
= isl_ast_build_get_schedule(build
);
8170 uset
= isl_union_map_range(schedule
);
8171 n
= isl_union_set_n_set(uset
);
8173 isl_union_set_free(uset
);
8176 isl_die(ctx
, isl_error_unknown
,
8177 "expecting single range space", return NULL
);
8180 space
= isl_ast_build_get_schedule_space(build
);
8181 set
= isl_union_set_extract_set(uset
, space
);
8182 isl_union_set_free(uset
);
8183 empty
= isl_set_is_empty(set
);
8189 isl_die(ctx
, isl_error_unknown
,
8190 "spaces don't match", return NULL
);
8192 return isl_id_alloc(ctx
, name
, NULL
);
8195 /* This function is called after each for loop in the AST generated
8196 * from test_ast_gen1.
8198 * Increment the number of calls and decrement the depth.
8199 * Check that the annotation attached to the node matches
8200 * the isl_id returned by the corresponding call to before_for.
8202 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
8203 __isl_keep isl_ast_build
*build
, void *user
)
8205 struct isl_test_codegen_data
*data
= user
;
8213 if (data
->after
> data
->before
)
8214 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8215 "mismatch in number of for nodes",
8216 return isl_ast_node_free(node
));
8218 id
= isl_ast_node_get_annotation(node
);
8220 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8221 "missing annotation", return isl_ast_node_free(node
));
8223 name
= isl_id_get_name(id
);
8224 valid
= name
&& atoi(name
+ 1) == data
->depth
;
8228 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8229 "wrong annotation", return isl_ast_node_free(node
));
8234 /* Check that the before_each_for and after_each_for callbacks
8235 * are called for each for loop in the generated code,
8236 * that they are called in the right order and that the isl_id
8237 * returned from the before_each_for callback is attached to
8238 * the isl_ast_node passed to the corresponding after_each_for call.
8240 static int test_ast_gen1(isl_ctx
*ctx
)
8244 isl_union_map
*schedule
;
8245 isl_ast_build
*build
;
8247 struct isl_test_codegen_data data
;
8249 str
= "[N] -> { : N >= 10 }";
8250 set
= isl_set_read_from_str(ctx
, str
);
8251 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
8252 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
8253 schedule
= isl_union_map_read_from_str(ctx
, str
);
8258 build
= isl_ast_build_from_context(set
);
8259 build
= isl_ast_build_set_before_each_for(build
,
8260 &before_for
, &data
);
8261 build
= isl_ast_build_set_after_each_for(build
,
8263 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8264 isl_ast_build_free(build
);
8268 isl_ast_node_free(tree
);
8270 if (data
.before
!= 3 || data
.after
!= 3)
8271 isl_die(ctx
, isl_error_unknown
,
8272 "unexpected number of for nodes", return -1);
8277 /* Check that the AST generator handles domains that are integrally disjoint
8278 * but not rationally disjoint.
8280 static int test_ast_gen2(isl_ctx
*ctx
)
8284 isl_union_map
*schedule
;
8285 isl_union_map
*options
;
8286 isl_ast_build
*build
;
8289 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
8290 schedule
= isl_union_map_read_from_str(ctx
, str
);
8291 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8292 build
= isl_ast_build_from_context(set
);
8294 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
8295 options
= isl_union_map_read_from_str(ctx
, str
);
8296 build
= isl_ast_build_set_options(build
, options
);
8297 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8298 isl_ast_build_free(build
);
8301 isl_ast_node_free(tree
);
8306 /* Increment *user on each call.
8308 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
8309 __isl_keep isl_ast_build
*build
, void *user
)
8318 /* Test that unrolling tries to minimize the number of instances.
8319 * In particular, for the schedule given below, make sure it generates
8320 * 3 nodes (rather than 101).
8322 static int test_ast_gen3(isl_ctx
*ctx
)
8326 isl_union_map
*schedule
;
8327 isl_union_map
*options
;
8328 isl_ast_build
*build
;
8332 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
8333 schedule
= isl_union_map_read_from_str(ctx
, str
);
8334 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8336 str
= "{ [i] -> unroll[0] }";
8337 options
= isl_union_map_read_from_str(ctx
, str
);
8339 build
= isl_ast_build_from_context(set
);
8340 build
= isl_ast_build_set_options(build
, options
);
8341 build
= isl_ast_build_set_at_each_domain(build
,
8342 &count_domains
, &n_domain
);
8343 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8344 isl_ast_build_free(build
);
8348 isl_ast_node_free(tree
);
8351 isl_die(ctx
, isl_error_unknown
,
8352 "unexpected number of for nodes", return -1);
8357 /* Check that if the ast_build_exploit_nested_bounds options is set,
8358 * we do not get an outer if node in the generated AST,
8359 * while we do get such an outer if node if the options is not set.
8361 static int test_ast_gen4(isl_ctx
*ctx
)
8365 isl_union_map
*schedule
;
8366 isl_ast_build
*build
;
8368 enum isl_ast_node_type type
;
8371 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
8372 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
8374 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
8376 schedule
= isl_union_map_read_from_str(ctx
, str
);
8377 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8378 build
= isl_ast_build_from_context(set
);
8379 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8380 isl_ast_build_free(build
);
8384 type
= isl_ast_node_get_type(tree
);
8385 isl_ast_node_free(tree
);
8387 if (type
== isl_ast_node_if
)
8388 isl_die(ctx
, isl_error_unknown
,
8389 "not expecting if node", return -1);
8391 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
8393 schedule
= isl_union_map_read_from_str(ctx
, str
);
8394 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8395 build
= isl_ast_build_from_context(set
);
8396 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8397 isl_ast_build_free(build
);
8401 type
= isl_ast_node_get_type(tree
);
8402 isl_ast_node_free(tree
);
8404 if (type
!= isl_ast_node_if
)
8405 isl_die(ctx
, isl_error_unknown
,
8406 "expecting if node", return -1);
8408 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
8413 /* This function is called for each leaf in the AST generated
8414 * from test_ast_gen5.
8416 * We finalize the AST generation by extending the outer schedule
8417 * with a zero-dimensional schedule. If this results in any for loops,
8418 * then this means that we did not pass along enough information
8419 * about the outer schedule to the inner AST generation.
8421 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
8424 isl_union_map
*schedule
, *extra
;
8427 schedule
= isl_ast_build_get_schedule(build
);
8428 extra
= isl_union_map_copy(schedule
);
8429 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
8430 schedule
= isl_union_map_range_product(schedule
, extra
);
8431 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8432 isl_ast_build_free(build
);
8437 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
8438 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
8439 "code should not contain any for loop",
8440 return isl_ast_node_free(tree
));
8445 /* Check that we do not lose any information when going back and
8446 * forth between internal and external schedule.
8448 * In particular, we create an AST where we unroll the only
8449 * non-constant dimension in the schedule. We therefore do
8450 * not expect any for loops in the AST. However, older versions
8451 * of isl would not pass along enough information about the outer
8452 * schedule when performing an inner code generation from a create_leaf
8453 * callback, resulting in the inner code generation producing a for loop.
8455 static int test_ast_gen5(isl_ctx
*ctx
)
8459 isl_union_map
*schedule
, *options
;
8460 isl_ast_build
*build
;
8463 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
8464 schedule
= isl_union_map_read_from_str(ctx
, str
);
8466 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
8467 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
8468 options
= isl_union_map_read_from_str(ctx
, str
);
8470 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8471 build
= isl_ast_build_from_context(set
);
8472 build
= isl_ast_build_set_options(build
, options
);
8473 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
8474 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8475 isl_ast_build_free(build
);
8476 isl_ast_node_free(tree
);
8483 /* Check that the expression
8485 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
8487 * is not combined into
8491 * as this would result in n/2 being evaluated in parts of
8492 * the definition domain where n is not a multiple of 2.
8494 static int test_ast_expr(isl_ctx
*ctx
)
8498 isl_ast_build
*build
;
8503 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
8504 isl_options_set_ast_build_detect_min_max(ctx
, 1);
8506 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
8507 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8508 build
= isl_ast_build_alloc(ctx
);
8509 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
8510 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
8511 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
8512 isl_ast_build_free(build
);
8513 isl_ast_expr_free(expr
);
8515 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
8520 isl_die(ctx
, isl_error_unknown
,
8521 "expressions should not be combined", return -1);
8526 static int test_ast_gen(isl_ctx
*ctx
)
8528 if (test_ast_gen1(ctx
) < 0)
8530 if (test_ast_gen2(ctx
) < 0)
8532 if (test_ast_gen3(ctx
) < 0)
8534 if (test_ast_gen4(ctx
) < 0)
8536 if (test_ast_gen5(ctx
) < 0)
8538 if (test_ast_expr(ctx
) < 0)
8543 /* Check if dropping output dimensions from an isl_pw_multi_aff
8546 static int test_pw_multi_aff(isl_ctx
*ctx
)
8549 isl_pw_multi_aff
*pma1
, *pma2
;
8552 str
= "{ [i,j] -> [i+j, 4i-j] }";
8553 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8554 str
= "{ [i,j] -> [4i-j] }";
8555 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8557 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
8559 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8561 isl_pw_multi_aff_free(pma1
);
8562 isl_pw_multi_aff_free(pma2
);
8566 isl_die(ctx
, isl_error_unknown
,
8567 "expressions not equal", return -1);
8572 /* Check that we can properly parse multi piecewise affine expressions
8573 * where the piecewise affine expressions have different domains.
8575 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
8578 isl_set
*dom
, *dom2
;
8579 isl_multi_pw_aff
*mpa1
, *mpa2
;
8584 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
8585 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
8586 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
8587 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
8588 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
8589 str
= "{ [i] -> [(i : i > 0), 2i] }";
8590 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8592 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
8594 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
8595 dom
= isl_pw_aff_domain(pa
);
8596 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
8597 dom2
= isl_pw_aff_domain(pa
);
8598 equal_domain
= isl_set_is_equal(dom
, dom2
);
8602 isl_multi_pw_aff_free(mpa1
);
8603 isl_multi_pw_aff_free(mpa2
);
8608 isl_die(ctx
, isl_error_unknown
,
8609 "expressions not equal", return -1);
8611 if (equal_domain
< 0)
8614 isl_die(ctx
, isl_error_unknown
,
8615 "domains unexpectedly equal", return -1);
8620 /* Check that the dimensions in the explicit domain
8621 * of a multi piecewise affine expression are properly
8622 * taken into account.
8624 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
8627 isl_bool involves1
, involves2
, involves3
, equal
;
8628 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
8630 str
= "{ A[x,y] -> B[] : x >= y }";
8631 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8632 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
8633 mpa1
= isl_multi_pw_aff_copy(mpa
);
8635 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
8636 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
8637 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
8638 str
= "{ [a,x,y] -> B[] : x >= y }";
8639 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8640 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8641 isl_multi_pw_aff_free(mpa2
);
8643 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
8644 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
8645 if (equal
>= 0 && equal
)
8646 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
8647 isl_multi_pw_aff_free(mpa1
);
8648 isl_multi_pw_aff_free(mpa
);
8650 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
8653 isl_die(ctx
, isl_error_unknown
,
8654 "incorrect result of dimension insertion/removal",
8655 return isl_stat_error
);
8656 if (!involves1
|| involves2
|| !involves3
)
8657 isl_die(ctx
, isl_error_unknown
,
8658 "incorrect characterization of involved dimensions",
8659 return isl_stat_error
);
8664 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
8665 * sets the explicit domain of a zero-dimensional result,
8666 * such that it can be converted to an isl_union_map.
8668 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
8673 isl_multi_union_pw_aff
*mupa
;
8674 isl_union_map
*umap
;
8676 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
8677 space
= isl_union_set_get_space(dom
);
8678 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
8679 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
8680 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
8681 isl_union_map_free(umap
);
8683 return isl_stat_error
;
8688 /* Perform some tests on multi piecewise affine expressions.
8690 static int test_multi_pw_aff(isl_ctx
*ctx
)
8692 if (test_multi_pw_aff_1(ctx
) < 0)
8694 if (test_multi_pw_aff_2(ctx
) < 0)
8696 if (test_multi_pw_aff_3(ctx
) < 0)
8701 /* This is a regression test for a bug where isl_basic_map_simplify
8702 * would end up in an infinite loop. In particular, we construct
8703 * an empty basic set that is not obviously empty.
8704 * isl_basic_set_is_empty marks the basic set as empty.
8705 * After projecting out i3, the variable can be dropped completely,
8706 * but isl_basic_map_simplify refrains from doing so if the basic set
8707 * is empty and would end up in an infinite loop if it didn't test
8708 * explicitly for empty basic maps in the outer loop.
8710 static int test_simplify_1(isl_ctx
*ctx
)
8713 isl_basic_set
*bset
;
8716 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8717 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8718 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8720 bset
= isl_basic_set_read_from_str(ctx
, str
);
8721 empty
= isl_basic_set_is_empty(bset
);
8722 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
8723 isl_basic_set_free(bset
);
8727 isl_die(ctx
, isl_error_unknown
,
8728 "basic set should be empty", return -1);
8733 /* Check that the equality in the set description below
8734 * is simplified away.
8736 static int test_simplify_2(isl_ctx
*ctx
)
8739 isl_basic_set
*bset
;
8742 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
8743 bset
= isl_basic_set_read_from_str(ctx
, str
);
8744 universe
= isl_basic_set_plain_is_universe(bset
);
8745 isl_basic_set_free(bset
);
8750 isl_die(ctx
, isl_error_unknown
,
8751 "equality not simplified away", return -1);
8755 /* Some simplification tests.
8757 static int test_simplify(isl_ctx
*ctx
)
8759 if (test_simplify_1(ctx
) < 0)
8761 if (test_simplify_2(ctx
) < 0)
8766 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
8767 * with gbr context would fail to disable the use of the shifted tableau
8768 * when transferring equalities for the input to the context, resulting
8769 * in invalid sample values.
8771 static int test_partial_lexmin(isl_ctx
*ctx
)
8774 isl_basic_set
*bset
;
8775 isl_basic_map
*bmap
;
8778 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
8779 bmap
= isl_basic_map_read_from_str(ctx
, str
);
8780 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
8781 bset
= isl_basic_set_read_from_str(ctx
, str
);
8782 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
8791 /* Check that the variable compression performed on the existentially
8792 * quantified variables inside isl_basic_set_compute_divs is not confused
8793 * by the implicit equalities among the parameters.
8795 static int test_compute_divs(isl_ctx
*ctx
)
8798 isl_basic_set
*bset
;
8801 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
8802 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
8803 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
8804 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
8805 bset
= isl_basic_set_read_from_str(ctx
, str
);
8806 set
= isl_basic_set_compute_divs(bset
);
8814 /* Check that isl_schedule_get_map is not confused by a schedule tree
8815 * with divergent filter node parameters, as can result from a call
8816 * to isl_schedule_intersect_domain.
8818 static int test_schedule_tree(isl_ctx
*ctx
)
8821 isl_union_set
*uset
;
8822 isl_schedule
*sched1
, *sched2
;
8823 isl_union_map
*umap
;
8825 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
8826 sched1
= isl_schedule_from_domain(uset
);
8827 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
8828 sched2
= isl_schedule_from_domain(uset
);
8830 sched1
= isl_schedule_sequence(sched1
, sched2
);
8831 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
8832 uset
= isl_union_set_read_from_str(ctx
, str
);
8833 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
8834 umap
= isl_schedule_get_map(sched1
);
8835 isl_schedule_free(sched1
);
8836 isl_union_map_free(umap
);
8843 /* Check that a zero-dimensional prefix schedule keeps track
8844 * of the domain and outer filters.
8846 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
8850 isl_union_set
*uset
;
8851 isl_union_set_list
*filters
;
8852 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8853 isl_schedule_node
*node
;
8855 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8856 uset
= isl_union_set_read_from_str(ctx
, str
);
8857 node
= isl_schedule_node_from_domain(uset
);
8858 node
= isl_schedule_node_child(node
, 0);
8860 str
= "{ S1[i,j] : i > j }";
8861 uset
= isl_union_set_read_from_str(ctx
, str
);
8862 filters
= isl_union_set_list_from_union_set(uset
);
8863 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
8864 uset
= isl_union_set_read_from_str(ctx
, str
);
8865 filters
= isl_union_set_list_add(filters
, uset
);
8866 node
= isl_schedule_node_insert_sequence(node
, filters
);
8868 node
= isl_schedule_node_child(node
, 0);
8869 node
= isl_schedule_node_child(node
, 0);
8870 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
8871 str
= "([] : { S1[i,j] : i > j })";
8872 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8873 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8874 isl_multi_union_pw_aff_free(mupa2
);
8875 isl_multi_union_pw_aff_free(mupa
);
8876 isl_schedule_node_free(node
);
8881 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
8887 /* Check that the reaching domain elements and the prefix schedule
8888 * at a leaf node are the same before and after grouping.
8890 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
8895 isl_union_set
*uset
;
8896 isl_multi_union_pw_aff
*mupa
;
8897 isl_union_pw_multi_aff
*upma1
, *upma2
;
8898 isl_union_set
*domain1
, *domain2
;
8899 isl_union_map
*umap1
, *umap2
;
8900 isl_schedule_node
*node
;
8902 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8903 uset
= isl_union_set_read_from_str(ctx
, str
);
8904 node
= isl_schedule_node_from_domain(uset
);
8905 node
= isl_schedule_node_child(node
, 0);
8906 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
8907 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8908 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8909 node
= isl_schedule_node_child(node
, 0);
8910 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
8911 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8912 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8913 node
= isl_schedule_node_child(node
, 0);
8914 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8915 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8916 domain1
= isl_schedule_node_get_domain(node
);
8917 id
= isl_id_alloc(ctx
, "group", NULL
);
8918 node
= isl_schedule_node_parent(node
);
8919 node
= isl_schedule_node_group(node
, id
);
8920 node
= isl_schedule_node_child(node
, 0);
8921 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8922 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8923 domain2
= isl_schedule_node_get_domain(node
);
8924 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
8925 if (equal
>= 0 && equal
)
8926 equal
= isl_union_set_is_equal(domain1
, domain2
);
8927 if (equal
>= 0 && equal
)
8928 equal
= isl_union_map_is_equal(umap1
, umap2
);
8929 isl_union_map_free(umap1
);
8930 isl_union_map_free(umap2
);
8931 isl_union_set_free(domain1
);
8932 isl_union_set_free(domain2
);
8933 isl_union_pw_multi_aff_free(upma1
);
8934 isl_union_pw_multi_aff_free(upma2
);
8935 isl_schedule_node_free(node
);
8940 isl_die(ctx
, isl_error_unknown
,
8941 "expressions not equal", return -1);
8946 /* Check that we can have nested groupings and that the union map
8947 * schedule representation is the same before and after the grouping.
8948 * Note that after the grouping, the union map representation contains
8949 * the domain constraints from the ranges of the expansion nodes,
8950 * while they are missing from the union map representation of
8951 * the tree without expansion nodes.
8953 * Also check that the global expansion is as expected.
8955 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
8957 int equal
, equal_expansion
;
8960 isl_union_set
*uset
;
8961 isl_union_map
*umap1
, *umap2
;
8962 isl_union_map
*expansion1
, *expansion2
;
8963 isl_union_set_list
*filters
;
8964 isl_multi_union_pw_aff
*mupa
;
8965 isl_schedule
*schedule
;
8966 isl_schedule_node
*node
;
8968 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
8969 "S3[i,j] : 0 <= i,j < 10 }";
8970 uset
= isl_union_set_read_from_str(ctx
, str
);
8971 node
= isl_schedule_node_from_domain(uset
);
8972 node
= isl_schedule_node_child(node
, 0);
8973 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
8974 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8975 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8976 node
= isl_schedule_node_child(node
, 0);
8977 str
= "{ S1[i,j] }";
8978 uset
= isl_union_set_read_from_str(ctx
, str
);
8979 filters
= isl_union_set_list_from_union_set(uset
);
8980 str
= "{ S2[i,j]; S3[i,j] }";
8981 uset
= isl_union_set_read_from_str(ctx
, str
);
8982 filters
= isl_union_set_list_add(filters
, uset
);
8983 node
= isl_schedule_node_insert_sequence(node
, filters
);
8984 node
= isl_schedule_node_child(node
, 1);
8985 node
= isl_schedule_node_child(node
, 0);
8986 str
= "{ S2[i,j] }";
8987 uset
= isl_union_set_read_from_str(ctx
, str
);
8988 filters
= isl_union_set_list_from_union_set(uset
);
8989 str
= "{ S3[i,j] }";
8990 uset
= isl_union_set_read_from_str(ctx
, str
);
8991 filters
= isl_union_set_list_add(filters
, uset
);
8992 node
= isl_schedule_node_insert_sequence(node
, filters
);
8994 schedule
= isl_schedule_node_get_schedule(node
);
8995 umap1
= isl_schedule_get_map(schedule
);
8996 uset
= isl_schedule_get_domain(schedule
);
8997 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
8998 isl_schedule_free(schedule
);
9000 node
= isl_schedule_node_parent(node
);
9001 node
= isl_schedule_node_parent(node
);
9002 id
= isl_id_alloc(ctx
, "group1", NULL
);
9003 node
= isl_schedule_node_group(node
, id
);
9004 node
= isl_schedule_node_child(node
, 1);
9005 node
= isl_schedule_node_child(node
, 0);
9006 id
= isl_id_alloc(ctx
, "group2", NULL
);
9007 node
= isl_schedule_node_group(node
, id
);
9009 schedule
= isl_schedule_node_get_schedule(node
);
9010 umap2
= isl_schedule_get_map(schedule
);
9011 isl_schedule_free(schedule
);
9013 node
= isl_schedule_node_root(node
);
9014 node
= isl_schedule_node_child(node
, 0);
9015 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
9016 isl_schedule_node_free(node
);
9018 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
9019 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
9020 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
9022 expansion2
= isl_union_map_read_from_str(ctx
, str
);
9024 equal
= isl_union_map_is_equal(umap1
, umap2
);
9025 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
9027 isl_union_map_free(umap1
);
9028 isl_union_map_free(umap2
);
9029 isl_union_map_free(expansion1
);
9030 isl_union_map_free(expansion2
);
9032 if (equal
< 0 || equal_expansion
< 0)
9035 isl_die(ctx
, isl_error_unknown
,
9036 "expressions not equal", return -1);
9037 if (!equal_expansion
)
9038 isl_die(ctx
, isl_error_unknown
,
9039 "unexpected expansion", return -1);
9044 /* Some tests for the isl_schedule_node_group function.
9046 static int test_schedule_tree_group(isl_ctx
*ctx
)
9048 if (test_schedule_tree_group_1(ctx
) < 0)
9050 if (test_schedule_tree_group_2(ctx
) < 0)
9059 { "{ rat: [i] : 0 <= i <= 10 }",
9060 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
9061 { "{ rat: [i] : FALSE }",
9062 "{ rat: coefficients[[cst] -> [a]] }" },
9064 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
9071 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
9072 "{ rat: [i] : 0 <= i <= 10 }" },
9073 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
9075 { "{ rat: coefficients[[cst] -> [a]] }",
9076 "{ rat: [i] : FALSE }" },
9079 /* Test the basic functionality of isl_basic_set_coefficients and
9080 * isl_basic_set_solutions.
9082 static int test_dual(isl_ctx
*ctx
)
9086 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
9088 isl_basic_set
*bset1
, *bset2
;
9090 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
9091 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
9092 bset1
= isl_basic_set_coefficients(bset1
);
9093 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9094 isl_basic_set_free(bset1
);
9095 isl_basic_set_free(bset2
);
9099 isl_die(ctx
, isl_error_unknown
,
9100 "incorrect dual", return -1);
9103 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
9105 isl_basic_set
*bset1
, *bset2
;
9107 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
9108 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
9109 bset1
= isl_basic_set_solutions(bset1
);
9110 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9111 isl_basic_set_free(bset1
);
9112 isl_basic_set_free(bset2
);
9116 isl_die(ctx
, isl_error_unknown
,
9117 "incorrect dual", return -1);
9127 const char *schedule
;
9132 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9133 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9135 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9136 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9138 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9139 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9141 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9142 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9144 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9145 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9147 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9148 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9150 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9151 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9153 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9154 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9158 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
9159 * tile the band and then check if the tile and point bands have the
9160 * expected partial schedule.
9162 static int test_tile(isl_ctx
*ctx
)
9168 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
9169 shift
= isl_options_get_tile_shift_point_loops(ctx
);
9171 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
9175 isl_union_set
*domain
;
9176 isl_multi_union_pw_aff
*mupa
, *mupa2
;
9177 isl_schedule_node
*node
;
9178 isl_multi_val
*sizes
;
9180 opt
= tile_tests
[i
].scale_tile
;
9181 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
9182 opt
= tile_tests
[i
].shift_point
;
9183 isl_options_set_tile_shift_point_loops(ctx
, opt
);
9185 str
= tile_tests
[i
].domain
;
9186 domain
= isl_union_set_read_from_str(ctx
, str
);
9187 node
= isl_schedule_node_from_domain(domain
);
9188 node
= isl_schedule_node_child(node
, 0);
9189 str
= tile_tests
[i
].schedule
;
9190 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9191 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9192 str
= tile_tests
[i
].sizes
;
9193 sizes
= isl_multi_val_read_from_str(ctx
, str
);
9194 node
= isl_schedule_node_band_tile(node
, sizes
);
9196 str
= tile_tests
[i
].tile
;
9197 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9198 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9199 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
9200 isl_multi_union_pw_aff_free(mupa
);
9201 isl_multi_union_pw_aff_free(mupa2
);
9203 node
= isl_schedule_node_child(node
, 0);
9205 str
= tile_tests
[i
].point
;
9206 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9207 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9208 if (equal
>= 0 && equal
)
9209 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
9211 isl_multi_union_pw_aff_free(mupa
);
9212 isl_multi_union_pw_aff_free(mupa2
);
9214 isl_schedule_node_free(node
);
9219 isl_die(ctx
, isl_error_unknown
,
9220 "unexpected result", return -1);
9223 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
9224 isl_options_set_tile_shift_point_loops(ctx
, shift
);
9229 /* Check that the domain hash of a space is equal to the hash
9230 * of the domain of the space.
9232 static int test_domain_hash(isl_ctx
*ctx
)
9236 uint32_t hash1
, hash2
;
9238 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
9239 space
= isl_map_get_space(map
);
9241 hash1
= isl_space_get_domain_hash(space
);
9242 space
= isl_space_domain(space
);
9243 hash2
= isl_space_get_hash(space
);
9244 isl_space_free(space
);
9249 isl_die(ctx
, isl_error_unknown
,
9250 "domain hash not equal to hash of domain", return -1);
9255 /* Check that a universe basic set that is not obviously equal to the universe
9256 * is still recognized as being equal to the universe.
9258 static int test_universe(isl_ctx
*ctx
)
9261 isl_basic_set
*bset
;
9264 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
9265 bset
= isl_basic_set_read_from_str(ctx
, s
);
9266 is_univ
= isl_basic_set_is_universe(bset
);
9267 isl_basic_set_free(bset
);
9272 isl_die(ctx
, isl_error_unknown
,
9273 "not recognized as universe set", return -1);
9278 /* Sets for which chambers are computed and checked.
9280 const char *chambers_tests
[] = {
9281 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
9282 "z >= 0 and z <= C - y and z <= B - x - y }",
9285 /* Add the domain of "cell" to "cells".
9287 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
9289 isl_basic_set_list
**cells
= user
;
9292 dom
= isl_cell_get_domain(cell
);
9293 isl_cell_free(cell
);
9294 *cells
= isl_basic_set_list_add(*cells
, dom
);
9296 return *cells
? isl_stat_ok
: isl_stat_error
;
9299 /* Check that the elements of "list" are pairwise disjoint.
9301 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
9306 n
= isl_basic_set_list_n_basic_set(list
);
9308 return isl_stat_error
;
9310 for (i
= 0; i
< n
; ++i
) {
9311 isl_basic_set
*bset_i
;
9313 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
9314 for (j
= i
+ 1; j
< n
; ++j
) {
9315 isl_basic_set
*bset_j
;
9318 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
9319 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
9320 isl_basic_set_free(bset_j
);
9322 isl_die(isl_basic_set_list_get_ctx(list
),
9323 isl_error_unknown
, "not disjoint",
9325 if (disjoint
< 0 || !disjoint
)
9328 isl_basic_set_free(bset_i
);
9330 return isl_stat_error
;
9336 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
9337 * are pairwise disjoint.
9339 static int test_chambers(isl_ctx
*ctx
)
9343 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
9344 isl_basic_set
*bset
;
9345 isl_vertices
*vertices
;
9346 isl_basic_set_list
*cells
;
9349 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
9350 vertices
= isl_basic_set_compute_vertices(bset
);
9351 cells
= isl_basic_set_list_alloc(ctx
, 0);
9352 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
9354 cells
= isl_basic_set_list_free(cells
);
9355 ok
= check_pairwise_disjoint(cells
);
9356 isl_basic_set_list_free(cells
);
9357 isl_vertices_free(vertices
);
9358 isl_basic_set_free(bset
);
9369 int (*fn
)(isl_ctx
*ctx
);
9371 { "universe", &test_universe
},
9372 { "domain hash", &test_domain_hash
},
9373 { "dual", &test_dual
},
9374 { "dependence analysis", &test_flow
},
9375 { "val", &test_val
},
9376 { "compute divs", &test_compute_divs
},
9377 { "partial lexmin", &test_partial_lexmin
},
9378 { "simplify", &test_simplify
},
9379 { "curry", &test_curry
},
9380 { "piecewise multi affine expressions", &test_pw_multi_aff
},
9381 { "multi piecewise affine expressions", &test_multi_pw_aff
},
9382 { "conversion", &test_conversion
},
9383 { "list", &test_list
},
9384 { "align parameters", &test_align_parameters
},
9385 { "drop unused parameters", &test_drop_unused_parameters
},
9386 { "preimage", &test_preimage
},
9387 { "pullback", &test_pullback
},
9388 { "AST", &test_ast
},
9389 { "AST build", &test_ast_build
},
9390 { "AST generation", &test_ast_gen
},
9391 { "eliminate", &test_eliminate
},
9392 { "residue class", &test_residue_class
},
9393 { "div", &test_div
},
9394 { "slice", &test_slice
},
9395 { "fixed power", &test_fixed_power
},
9396 { "sample", &test_sample
},
9397 { "output", &test_output
},
9398 { "vertices", &test_vertices
},
9399 { "chambers", &test_chambers
},
9400 { "fixed", &test_fixed
},
9401 { "equal", &test_equal
},
9402 { "disjoint", &test_disjoint
},
9403 { "product", &test_product
},
9404 { "dim_max", &test_dim_max
},
9405 { "affine", &test_aff
},
9406 { "injective", &test_injective
},
9407 { "schedule (whole component)", &test_schedule_whole
},
9408 { "schedule (incremental)", &test_schedule_incremental
},
9409 { "schedule tree", &test_schedule_tree
},
9410 { "schedule tree prefix", &test_schedule_tree_prefix
},
9411 { "schedule tree grouping", &test_schedule_tree_group
},
9412 { "tile", &test_tile
},
9413 { "union_pw", &test_union_pw
},
9414 { "locus", &test_locus
},
9415 { "eval", &test_eval
},
9416 { "parse", &test_parse
},
9417 { "single-valued", &test_sv
},
9418 { "affine hull", &test_affine_hull
},
9419 { "simple_hull", &test_simple_hull
},
9420 { "coalesce", &test_coalesce
},
9421 { "factorize", &test_factorize
},
9422 { "subset", &test_subset
},
9423 { "subtract", &test_subtract
},
9424 { "intersect", &test_intersect
},
9425 { "lexmin", &test_lexmin
},
9426 { "min", &test_min
},
9427 { "gist", &test_gist
},
9428 { "piecewise quasi-polynomials", &test_pwqp
},
9429 { "lift", &test_lift
},
9430 { "bound", &test_bound
},
9431 { "get lists", &test_get_list
},
9432 { "union", &test_union
},
9433 { "split periods", &test_split_periods
},
9434 { "lexicographic order", &test_lex
},
9435 { "bijectivity", &test_bijective
},
9436 { "dataflow analysis", &test_dep
},
9437 { "reading", &test_read
},
9438 { "bounded", &test_bounded
},
9439 { "construction", &test_construction
},
9440 { "dimension manipulation", &test_dim
},
9441 { "map application", &test_application
},
9442 { "convex hull", &test_convex_hull
},
9443 { "transitive closure", &test_closure
},
9444 { "isl_bool", &test_isl_bool
},
9447 int main(int argc
, char **argv
)
9450 struct isl_ctx
*ctx
;
9451 struct isl_options
*options
;
9453 options
= isl_options_new_with_defaults();
9455 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
9457 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
9458 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
9459 printf("%s\n", tests
[i
].name
);
9460 if (tests
[i
].fn(ctx
) < 0)