2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
28 #include <isl_constraint_private.h>
29 #include <isl/polynomial.h>
30 #include <isl/union_set.h>
31 #include <isl/union_map.h>
32 #include <isl_factorization.h>
33 #include <isl/schedule.h>
34 #include <isl/schedule_node.h>
35 #include <isl_options_private.h>
36 #include <isl_vertices_private.h>
37 #include <isl/ast_build.h>
40 #include <isl_ast_build_expr.h>
41 #include <isl/options.h>
43 #include "isl_srcdir.c"
45 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
47 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
50 char *pattern
= "%s/test_inputs/%s.%s";
52 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
54 filename
= isl_alloc_array(ctx
, char, length
);
59 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
64 void test_parse_map(isl_ctx
*ctx
, const char *str
)
68 map
= isl_map_read_from_str(ctx
, str
);
73 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
78 map
= isl_map_read_from_str(ctx
, str
);
79 map2
= isl_map_read_from_str(ctx
, str2
);
80 equal
= isl_map_is_equal(map
, map2
);
87 isl_die(ctx
, isl_error_unknown
, "maps not equal",
93 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
95 isl_pw_qpolynomial
*pwqp
;
97 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
99 isl_pw_qpolynomial_free(pwqp
);
102 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
106 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
108 isl_pw_aff_free(pwaff
);
111 /* Check that we can read an isl_multi_val from "str" without errors.
113 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
117 mv
= isl_multi_val_read_from_str(ctx
, str
);
118 isl_multi_val_free(mv
);
123 /* String descriptions of multi piecewise affine expressions
124 * that are used for testing printing and parsing.
126 static const char *reparse_multi_pw_aff_tests
[] = {
127 "{ A[x, y] -> [] : x + y >= 0 }",
128 "{ A[x, y] -> B[] : x + y >= 0 }",
129 "{ A[x, y] -> [x] : x + y >= 0 }",
130 "[N] -> { A[x, y] -> [x] : x + y <= N }",
131 "{ A[x, y] -> [x, y] : x + y >= 0 }",
132 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
133 "[N] -> { [] : N >= 0 }",
134 "[N] -> { [] : N >= 0 }",
135 "[N] -> { [N] : N >= 0 }",
136 "[N] -> { [N, N + 1] : N >= 0 }",
137 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
138 "{ [a] -> [b = a] }",
139 "{ [a] -> [b = a] : a >= 0 }",
143 #define BASE multi_pw_aff
145 #include "check_reparse_templ.c"
146 #include "check_reparse_test_templ.c"
148 /* String descriptions that cannot be parsed
149 * as multi piecewise affine expressions.
151 static const char *parse_multi_pw_aff_fail_tests
[] = {
152 "{ [a] -> [b] : b = a }",
153 "{ [a] -> [b = a] : b >= 0 }",
156 #include "check_parse_fail_test_templ.c"
158 /* String descriptions of piecewise multi affine expressions
159 * that are used for testing printing and parsing.
161 static const char *reparse_pw_multi_aff_tests
[] = {
163 "{ [x] -> [x % 4] }",
164 "{ [x] -> [x % 4] : x mod 3 = 1 }",
165 "{ [x, x] -> [x % 4] }",
166 "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }",
167 "{ [x, x mod 2] -> [x % 4] }",
168 "{ [a] -> [a//2] : exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
172 #define BASE pw_multi_aff
174 #include "check_reparse_templ.c"
175 #include "check_reparse_test_templ.c"
177 /* Test parsing of piecewise multi affine expressions by printing
178 * the expressions and checking that parsing the output results
179 * in the same expression.
180 * Do this for an expression converted from a map with an output
181 * dimension name that is equal to an automatically generated name, and
182 * a set of expressions parsed from strings.
184 static isl_stat
test_parse_pma(isl_ctx
*ctx
)
187 isl_pw_multi_aff
*pma
;
189 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
190 pma
= isl_pw_multi_aff_from_map(map
);
191 if (check_reparse_pw_multi_aff(ctx
, pma
) < 0)
192 return isl_stat_error
;
194 if (check_reparse_pw_multi_aff_tests(ctx
) < 0)
195 return isl_stat_error
;
200 /* String descriptions that cannot be parsed
201 * as union piecewise multi affine expressions.
203 static const char *parse_union_pw_multi_aff_fail_tests
[] = {
204 "{ [a] -> [b] : b = a }",
205 "{ [a] -> [b = a] : b >= 0 }",
209 #define BASE union_pw_multi_aff
211 #include "check_parse_fail_test_templ.c"
213 /* Test parsing of union piecewise multi affine expressions.
215 * In particular, check some cases where parsing is supposed to fail.
217 static isl_stat
test_parse_upma(isl_ctx
*ctx
)
219 if (check_parse_union_pw_multi_aff_fail_tests(ctx
) < 0)
220 return isl_stat_error
;
225 /* Test parsing of multi piecewise affine expressions by printing
226 * the expressions and checking that parsing the output results
227 * in the same expression.
228 * Do this for a couple of manually constructed expressions,
229 * an expression converted from a map with an output dimension name
230 * that is equal to an automatically generated name, and
231 * a set of expressions parsed from strings.
233 * Additionally, check some cases where parsing is supposed to fail.
235 static int test_parse_mpa(isl_ctx
*ctx
)
240 isl_pw_multi_aff
*pma
;
241 isl_multi_pw_aff
*mpa
;
244 space
= isl_space_set_alloc(ctx
, 0, 0);
245 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
246 mpa
= isl_multi_pw_aff_zero(space
);
247 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
251 space
= isl_space_set_alloc(ctx
, 1, 0);
252 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
253 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
254 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
255 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
256 mpa
= isl_multi_pw_aff_zero(space
);
257 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
258 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
262 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
263 pma
= isl_pw_multi_aff_from_map(map
);
264 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma
);
265 if (check_reparse_multi_pw_aff(ctx
, mpa
) < 0)
268 if (check_reparse_multi_pw_aff_tests(ctx
) < 0)
270 if (check_parse_multi_pw_aff_fail_tests(ctx
) < 0)
276 /* String descriptions of multi union piecewise affine expressions
277 * that are used for testing printing and parsing.
279 static const char *reparse_multi_union_pw_aff_tests
[] = {
283 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
285 "[N] -> (A[] : { })",
286 "[N] -> (A[] : { : N >= 0 })",
287 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
288 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
289 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
290 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
291 "{ S[x] : x > 0; T[y] : y >= 0 })",
295 #define BASE multi_union_pw_aff
297 #include "check_reparse_templ.c"
298 #include "check_reparse_test_templ.c"
300 /* Test parsing of multi union piecewise affine expressions by printing
301 * the expressions and checking that parsing the output results
302 * in the same expression.
303 * Do this for a couple of manually constructed expressions and
304 * a set of expressions parsed from strings.
306 static int test_parse_mupa(isl_ctx
*ctx
)
309 isl_multi_union_pw_aff
*mupa
;
314 space
= isl_space_set_alloc(ctx
, 0, 0);
315 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
316 mupa
= isl_multi_union_pw_aff_zero(space
);
317 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
321 space
= isl_space_set_alloc(ctx
, 1, 0);
322 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
323 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
324 dom
= isl_set_universe(space
);
325 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
326 uset
= isl_union_set_from_set(dom
);
327 space
= isl_space_set_alloc(ctx
, 1, 0);
328 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
329 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
330 mupa
= isl_multi_union_pw_aff_zero(space
);
331 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
332 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
336 if (check_reparse_multi_union_pw_aff_tests(ctx
) < 0)
342 /* Test parsing of multi expressions.
344 static int test_parse_multi(isl_ctx
*ctx
)
346 if (test_parse_mpa(ctx
) < 0)
348 if (test_parse_mupa(ctx
) < 0)
354 /* Pairs of binary relation representations that should represent
355 * the same binary relations.
360 } parse_map_equal_tests
[] = {
361 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
362 "{ [x, y] : 2y >= 6 - x }" },
363 { "{ [x,y] : x <= min(y, 2*y+3) }",
364 "{ [x,y] : x <= y, 2*y + 3 }" },
365 { "{ [x,y] : x >= min(y, 2*y+3) }",
366 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
367 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
368 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
369 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
370 "{ [i,j] -> [min(i,j)] }" },
371 { "{ [i,j] : i != j }",
372 "{ [i,j] : i < j or i > j }" },
373 { "{ [i,j] : (i+1)*2 >= j }",
374 "{ [i, j] : j <= 2 + 2i }" },
375 { "{ [i] -> [i > 0 ? 4 : 5] }",
376 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
377 { "[N=2,M] -> { [i=[(M+N)/4]] }",
378 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
379 { "{ [x] : x >= 0 }",
380 "{ [x] : x-0 >= 0 }" },
381 { "{ [i] : ((i > 10)) }",
382 "{ [i] : i >= 11 }" },
384 "{ [i] -> [0 * i] }" },
385 { "{ [a] -> [b] : (not false) }",
386 "{ [a] -> [b] : true }" },
387 { "{ [i] : i/2 <= 5 }",
388 "{ [i] : i <= 10 }" },
389 { "{Sym=[n] [i] : i <= n }",
390 "[n] -> { [i] : i <= n }" },
393 { "{ [i] : 2*floor(i/2) = i }",
394 "{ [i] : exists a : i = 2 a }" },
395 { "{ [a] -> [b] : a = 5 implies b = 5 }",
396 "{ [a] -> [b] : a != 5 or b = 5 }" },
397 { "{ [a] -> [a - 1 : a > 0] }",
398 "{ [a] -> [a - 1] : a > 0 }" },
399 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
400 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
401 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
402 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
403 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
404 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
405 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
406 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
407 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
408 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
409 { "{ [a,b] -> [i,j] : a,b << i,j }",
410 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
411 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
412 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
413 { "{ [a,b] -> [i,j] : a,b >> i,j }",
414 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
415 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
416 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
417 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
418 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
419 "8c < n - 32a and i < n and c >= 0 and "
420 "c <= 3 and c >= -4a) }",
421 "{ [n] -> [i] : 0 <= i < n }" },
422 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
423 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
424 "{ [x] -> [] : 0 <= x <= 15 }" },
425 { "{ [x] -> [x] : }",
427 { "{ [x=4:5] -> [x + 1] }",
428 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
429 { "{ [x=4:5] -> [x + 1 : x + 1] }",
430 "{ [x=4:5] -> [x + 1] }" },
431 { "{ [x] -> [x - 1 : x + 1] }",
432 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
433 { "{ [x=4:] -> [x + 1] }",
434 "{ [x] -> [x + 1] : 4 <= x }" },
435 { "{ [x=:5] -> [x + 1] }",
436 "{ [x] -> [x + 1] : x <= 5 }" },
437 { "{ [x=:] -> [x + 1] }",
438 "{ [x] -> [x + 1] }" },
442 "{ [x, floor(x/4)] }" },
447 int test_parse(struct isl_ctx
*ctx
)
451 const char *str
, *str2
;
453 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
455 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
457 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
459 if (test_parse_multi(ctx
) < 0)
461 if (test_parse_pma(ctx
) < 0)
463 if (test_parse_upma(ctx
) < 0)
466 str
= "{ [i] -> [-i] }";
467 map
= isl_map_read_from_str(ctx
, str
);
471 str
= "{ A[i] -> L[([i/3])] }";
472 map
= isl_map_read_from_str(ctx
, str
);
476 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
477 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
478 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
480 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
481 str
= parse_map_equal_tests
[i
].map1
;
482 str2
= parse_map_equal_tests
[i
].map2
;
483 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
487 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
488 map
= isl_map_read_from_str(ctx
, str
);
489 str
= "{ [new, old] -> [o0, o1] : "
490 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
491 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
492 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
493 map2
= isl_map_read_from_str(ctx
, str
);
494 assert(isl_map_is_equal(map
, map2
));
498 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
499 map
= isl_map_read_from_str(ctx
, str
);
500 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
501 map2
= isl_map_read_from_str(ctx
, str
);
502 assert(isl_map_is_equal(map
, map2
));
506 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
507 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
508 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
509 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
510 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
515 static int test_read(isl_ctx
*ctx
)
519 isl_basic_set
*bset1
, *bset2
;
520 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
523 filename
= get_filename(ctx
, "set", "omega");
525 input
= fopen(filename
, "r");
528 bset1
= isl_basic_set_read_from_file(ctx
, input
);
529 bset2
= isl_basic_set_read_from_str(ctx
, str
);
531 equal
= isl_basic_set_is_equal(bset1
, bset2
);
533 isl_basic_set_free(bset1
);
534 isl_basic_set_free(bset2
);
542 isl_die(ctx
, isl_error_unknown
,
543 "read sets not equal", return -1);
548 static int test_bounded(isl_ctx
*ctx
)
553 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
554 bounded
= isl_set_is_bounded(set
);
560 isl_die(ctx
, isl_error_unknown
,
561 "set not considered bounded", return -1);
563 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
564 bounded
= isl_set_is_bounded(set
);
571 isl_die(ctx
, isl_error_unknown
,
572 "set considered bounded", return -1);
574 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
575 bounded
= isl_set_is_bounded(set
);
581 isl_die(ctx
, isl_error_unknown
,
582 "set considered bounded", return -1);
587 /* Construct the basic set { [i] : 5 <= i <= N } */
588 static int test_construction_1(isl_ctx
*ctx
)
595 space
= isl_space_set_alloc(ctx
, 1, 1);
596 bset
= isl_basic_set_universe(isl_space_copy(space
));
597 ls
= isl_local_space_from_space(space
);
599 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
600 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
601 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
602 bset
= isl_basic_set_add_constraint(bset
, c
);
604 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
605 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
606 c
= isl_constraint_set_constant_si(c
, -5);
607 bset
= isl_basic_set_add_constraint(bset
, c
);
609 isl_local_space_free(ls
);
610 isl_basic_set_free(bset
);
615 /* Construct the basic set { [x] : -100 <= x <= 100 }
616 * using isl_basic_set_{lower,upper}_bound_val and
617 * check that it is equal the same basic set parsed from a string.
619 static int test_construction_2(isl_ctx
*ctx
)
624 isl_basic_set
*bset1
, *bset2
;
626 v
= isl_val_int_from_si(ctx
, 100);
627 space
= isl_space_set_alloc(ctx
, 0, 1);
628 bset1
= isl_basic_set_universe(space
);
629 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
631 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
633 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
634 equal
= isl_basic_set_is_equal(bset1
, bset2
);
635 isl_basic_set_free(bset1
);
636 isl_basic_set_free(bset2
);
641 isl_die(ctx
, isl_error_unknown
,
642 "failed construction", return -1);
647 /* Basic tests for constructing basic sets.
649 static int test_construction(isl_ctx
*ctx
)
651 if (test_construction_1(ctx
) < 0)
653 if (test_construction_2(ctx
) < 0)
658 static int test_dim(isl_ctx
*ctx
)
661 isl_map
*map1
, *map2
;
664 map1
= isl_map_read_from_str(ctx
,
665 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
666 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
667 map2
= isl_map_read_from_str(ctx
,
668 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
669 equal
= isl_map_is_equal(map1
, map2
);
672 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
673 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
674 if (equal
>= 0 && equal
)
675 equal
= isl_map_is_equal(map1
, map2
);
683 isl_die(ctx
, isl_error_unknown
,
684 "unexpected result", return -1);
686 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
687 map1
= isl_map_read_from_str(ctx
, str
);
688 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
689 map2
= isl_map_read_from_str(ctx
, str
);
690 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
691 equal
= isl_map_is_equal(map1
, map2
);
698 isl_die(ctx
, isl_error_unknown
,
699 "unexpected result", return -1);
705 #define BASE multi_val
706 #include "isl_test_plain_equal_templ.c"
709 #define BASE multi_aff
710 #include "isl_test_plain_equal_templ.c"
712 /* Check that "val" is equal to the value described by "str".
713 * If "str" is "NaN", then check for a NaN value explicitly.
715 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
722 return isl_stat_error
;
724 ctx
= isl_val_get_ctx(val
);
725 res
= isl_val_read_from_str(ctx
, str
);
726 is_nan
= isl_val_is_nan(res
);
730 ok
= isl_val_is_nan(val
);
732 ok
= isl_val_eq(val
, res
);
735 return isl_stat_error
;
737 isl_die(ctx
, isl_error_unknown
,
738 "unexpected result", return isl_stat_error
);
743 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
747 { &isl_val_neg
, "0", "0" },
748 { &isl_val_abs
, "0", "0" },
749 { &isl_val_pow2
, "0", "1" },
750 { &isl_val_floor
, "0", "0" },
751 { &isl_val_ceil
, "0", "0" },
752 { &isl_val_neg
, "1", "-1" },
753 { &isl_val_neg
, "-1", "1" },
754 { &isl_val_neg
, "1/2", "-1/2" },
755 { &isl_val_neg
, "-1/2", "1/2" },
756 { &isl_val_neg
, "infty", "-infty" },
757 { &isl_val_neg
, "-infty", "infty" },
758 { &isl_val_neg
, "NaN", "NaN" },
759 { &isl_val_abs
, "1", "1" },
760 { &isl_val_abs
, "-1", "1" },
761 { &isl_val_abs
, "1/2", "1/2" },
762 { &isl_val_abs
, "-1/2", "1/2" },
763 { &isl_val_abs
, "infty", "infty" },
764 { &isl_val_abs
, "-infty", "infty" },
765 { &isl_val_abs
, "NaN", "NaN" },
766 { &isl_val_floor
, "1", "1" },
767 { &isl_val_floor
, "-1", "-1" },
768 { &isl_val_floor
, "1/2", "0" },
769 { &isl_val_floor
, "-1/2", "-1" },
770 { &isl_val_floor
, "infty", "infty" },
771 { &isl_val_floor
, "-infty", "-infty" },
772 { &isl_val_floor
, "NaN", "NaN" },
773 { &isl_val_ceil
, "1", "1" },
774 { &isl_val_ceil
, "-1", "-1" },
775 { &isl_val_ceil
, "1/2", "1" },
776 { &isl_val_ceil
, "-1/2", "0" },
777 { &isl_val_ceil
, "infty", "infty" },
778 { &isl_val_ceil
, "-infty", "-infty" },
779 { &isl_val_ceil
, "NaN", "NaN" },
780 { &isl_val_pow2
, "-3", "1/8" },
781 { &isl_val_pow2
, "-1", "1/2" },
782 { &isl_val_pow2
, "1", "2" },
783 { &isl_val_pow2
, "2", "4" },
784 { &isl_val_pow2
, "3", "8" },
785 { &isl_val_inv
, "1", "1" },
786 { &isl_val_inv
, "2", "1/2" },
787 { &isl_val_inv
, "1/2", "2" },
788 { &isl_val_inv
, "-2", "-1/2" },
789 { &isl_val_inv
, "-1/2", "-2" },
790 { &isl_val_inv
, "0", "NaN" },
791 { &isl_val_inv
, "NaN", "NaN" },
792 { &isl_val_inv
, "infty", "0" },
793 { &isl_val_inv
, "-infty", "0" },
796 /* Perform some basic tests of unary operations on isl_val objects.
798 static int test_un_val(isl_ctx
*ctx
)
802 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
804 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
807 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
808 fn
= val_un_tests
[i
].op
;
810 r
= val_check_equal(v
, val_un_tests
[i
].res
);
820 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
821 __isl_take isl_val
*v2
);
823 ['+'] = { &isl_val_add
},
824 ['-'] = { &isl_val_sub
},
825 ['*'] = { &isl_val_mul
},
826 ['/'] = { &isl_val_div
},
827 ['g'] = { &isl_val_gcd
},
828 ['m'] = { &isl_val_min
},
829 ['M'] = { &isl_val_max
},
837 } val_bin_tests
[] = {
838 { "0", '+', "0", "0" },
839 { "1", '+', "0", "1" },
840 { "1", '+', "1", "2" },
841 { "1", '-', "1", "0" },
842 { "1", '*', "1", "1" },
843 { "1", '/', "1", "1" },
844 { "2", '*', "3", "6" },
845 { "2", '*', "1/2", "1" },
846 { "2", '*', "1/3", "2/3" },
847 { "2/3", '*', "3/5", "2/5" },
848 { "2/3", '*', "7/5", "14/15" },
849 { "2", '/', "1/2", "4" },
850 { "-2", '/', "-1/2", "4" },
851 { "-2", '/', "1/2", "-4" },
852 { "2", '/', "-1/2", "-4" },
853 { "2", '/', "2", "1" },
854 { "2", '/', "3", "2/3" },
855 { "2/3", '/', "5/3", "2/5" },
856 { "2/3", '/', "5/7", "14/15" },
857 { "0", '/', "0", "NaN" },
858 { "42", '/', "0", "NaN" },
859 { "-42", '/', "0", "NaN" },
860 { "infty", '/', "0", "NaN" },
861 { "-infty", '/', "0", "NaN" },
862 { "NaN", '/', "0", "NaN" },
863 { "0", '/', "NaN", "NaN" },
864 { "42", '/', "NaN", "NaN" },
865 { "-42", '/', "NaN", "NaN" },
866 { "infty", '/', "NaN", "NaN" },
867 { "-infty", '/', "NaN", "NaN" },
868 { "NaN", '/', "NaN", "NaN" },
869 { "0", '/', "infty", "0" },
870 { "42", '/', "infty", "0" },
871 { "-42", '/', "infty", "0" },
872 { "infty", '/', "infty", "NaN" },
873 { "-infty", '/', "infty", "NaN" },
874 { "NaN", '/', "infty", "NaN" },
875 { "0", '/', "-infty", "0" },
876 { "42", '/', "-infty", "0" },
877 { "-42", '/', "-infty", "0" },
878 { "infty", '/', "-infty", "NaN" },
879 { "-infty", '/', "-infty", "NaN" },
880 { "NaN", '/', "-infty", "NaN" },
881 { "1", '-', "1/3", "2/3" },
882 { "1/3", '+', "1/2", "5/6" },
883 { "1/2", '+', "1/2", "1" },
884 { "3/4", '-', "1/4", "1/2" },
885 { "1/2", '-', "1/3", "1/6" },
886 { "infty", '+', "42", "infty" },
887 { "infty", '+', "infty", "infty" },
888 { "42", '+', "infty", "infty" },
889 { "infty", '-', "infty", "NaN" },
890 { "infty", '*', "infty", "infty" },
891 { "infty", '*', "-infty", "-infty" },
892 { "-infty", '*', "infty", "-infty" },
893 { "-infty", '*', "-infty", "infty" },
894 { "0", '*', "infty", "NaN" },
895 { "1", '*', "infty", "infty" },
896 { "infty", '*', "0", "NaN" },
897 { "infty", '*', "42", "infty" },
898 { "42", '-', "infty", "-infty" },
899 { "infty", '+', "-infty", "NaN" },
900 { "4", 'g', "6", "2" },
901 { "5", 'g', "6", "1" },
902 { "42", 'm', "3", "3" },
903 { "42", 'M', "3", "42" },
904 { "3", 'm', "42", "3" },
905 { "3", 'M', "42", "42" },
906 { "42", 'm', "infty", "42" },
907 { "42", 'M', "infty", "infty" },
908 { "42", 'm', "-infty", "-infty" },
909 { "42", 'M', "-infty", "42" },
910 { "42", 'm', "NaN", "NaN" },
911 { "42", 'M', "NaN", "NaN" },
912 { "infty", 'm', "-infty", "-infty" },
913 { "infty", 'M', "-infty", "infty" },
916 /* Perform some basic tests of binary operations on isl_val objects.
918 static int test_bin_val(isl_ctx
*ctx
)
921 isl_val
*v1
, *v2
, *res
;
922 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
923 __isl_take isl_val
*v2
);
926 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
927 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
928 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
929 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
930 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
932 if (isl_val_is_nan(res
))
933 ok
= isl_val_is_nan(v1
);
935 ok
= isl_val_eq(v1
, res
);
941 isl_die(ctx
, isl_error_unknown
,
942 "unexpected result", return -1);
948 /* Perform some basic tests on isl_val objects.
950 static int test_val(isl_ctx
*ctx
)
952 if (test_un_val(ctx
) < 0)
954 if (test_bin_val(ctx
) < 0)
959 /* Sets described using existentially quantified variables that
960 * can also be described without.
962 static const char *elimination_tests
[] = {
963 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
964 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
965 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
968 /* Check that redundant existentially quantified variables are
971 static int test_elimination(isl_ctx
*ctx
)
977 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
978 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
979 n
= isl_basic_set_dim(bset
, isl_dim_div
);
980 isl_basic_set_free(bset
);
984 isl_die(ctx
, isl_error_unknown
,
985 "expecting no existentials", return -1);
991 static int test_div(isl_ctx
*ctx
)
998 struct isl_basic_set
*bset
;
999 struct isl_constraint
*c
;
1002 space
= isl_space_set_alloc(ctx
, 0, 3);
1003 bset
= isl_basic_set_universe(isl_space_copy(space
));
1004 ls
= isl_local_space_from_space(space
);
1006 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1007 c
= isl_constraint_set_constant_si(c
, -1);
1008 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1009 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1010 bset
= isl_basic_set_add_constraint(bset
, c
);
1012 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1013 c
= isl_constraint_set_constant_si(c
, 1);
1014 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1015 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1016 bset
= isl_basic_set_add_constraint(bset
, c
);
1018 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1020 assert(bset
&& bset
->n_div
== 1);
1021 isl_local_space_free(ls
);
1022 isl_basic_set_free(bset
);
1025 space
= isl_space_set_alloc(ctx
, 0, 3);
1026 bset
= isl_basic_set_universe(isl_space_copy(space
));
1027 ls
= isl_local_space_from_space(space
);
1029 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1030 c
= isl_constraint_set_constant_si(c
, 1);
1031 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1032 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1033 bset
= isl_basic_set_add_constraint(bset
, c
);
1035 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1036 c
= isl_constraint_set_constant_si(c
, -1);
1037 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1038 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1039 bset
= isl_basic_set_add_constraint(bset
, c
);
1041 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1043 assert(bset
&& bset
->n_div
== 1);
1044 isl_local_space_free(ls
);
1045 isl_basic_set_free(bset
);
1048 space
= isl_space_set_alloc(ctx
, 0, 3);
1049 bset
= isl_basic_set_universe(isl_space_copy(space
));
1050 ls
= isl_local_space_from_space(space
);
1052 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1053 c
= isl_constraint_set_constant_si(c
, 1);
1054 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1055 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1056 bset
= isl_basic_set_add_constraint(bset
, c
);
1058 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1059 c
= isl_constraint_set_constant_si(c
, -3);
1060 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1061 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
1062 bset
= isl_basic_set_add_constraint(bset
, c
);
1064 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1066 assert(bset
&& bset
->n_div
== 1);
1067 isl_local_space_free(ls
);
1068 isl_basic_set_free(bset
);
1071 space
= isl_space_set_alloc(ctx
, 0, 3);
1072 bset
= isl_basic_set_universe(isl_space_copy(space
));
1073 ls
= isl_local_space_from_space(space
);
1075 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1076 c
= isl_constraint_set_constant_si(c
, 2);
1077 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1078 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1079 bset
= isl_basic_set_add_constraint(bset
, c
);
1081 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1082 c
= isl_constraint_set_constant_si(c
, -1);
1083 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1084 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1085 bset
= isl_basic_set_add_constraint(bset
, c
);
1087 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1089 assert(isl_basic_set_is_empty(bset
));
1090 isl_local_space_free(ls
);
1091 isl_basic_set_free(bset
);
1094 space
= isl_space_set_alloc(ctx
, 0, 3);
1095 bset
= isl_basic_set_universe(isl_space_copy(space
));
1096 ls
= isl_local_space_from_space(space
);
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
, 2, 3);
1101 bset
= isl_basic_set_add_constraint(bset
, c
);
1103 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1104 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1105 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1106 bset
= isl_basic_set_add_constraint(bset
, c
);
1108 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1110 assert(bset
&& bset
->n_div
== 0);
1111 isl_basic_set_free(bset
);
1112 isl_local_space_free(ls
);
1115 space
= isl_space_set_alloc(ctx
, 0, 3);
1116 bset
= isl_basic_set_universe(isl_space_copy(space
));
1117 ls
= isl_local_space_from_space(space
);
1119 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1120 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1121 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1122 bset
= isl_basic_set_add_constraint(bset
, c
);
1124 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1125 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1126 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1127 bset
= isl_basic_set_add_constraint(bset
, c
);
1129 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1131 assert(bset
&& bset
->n_div
== 1);
1132 isl_basic_set_free(bset
);
1133 isl_local_space_free(ls
);
1136 /* This test is a bit tricky. We set up an equality
1137 * a + 3b + 3c = 6 e0
1138 * Normalization of divs creates _two_ divs
1141 * Afterwards e0 is removed again because it has coefficient -1
1142 * and we end up with the original equality and div again.
1143 * Perhaps we can avoid the introduction of this temporary div.
1145 space
= isl_space_set_alloc(ctx
, 0, 4);
1146 bset
= isl_basic_set_universe(isl_space_copy(space
));
1147 ls
= isl_local_space_from_space(space
);
1149 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1150 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1151 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1152 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1153 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1154 bset
= isl_basic_set_add_constraint(bset
, c
);
1156 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1158 /* Test disabled for now */
1160 assert(bset && bset->n_div == 1);
1162 isl_local_space_free(ls
);
1163 isl_basic_set_free(bset
);
1166 space
= isl_space_set_alloc(ctx
, 0, 5);
1167 bset
= isl_basic_set_universe(isl_space_copy(space
));
1168 ls
= isl_local_space_from_space(space
);
1170 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1171 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1172 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1173 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1174 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1175 bset
= isl_basic_set_add_constraint(bset
, c
);
1177 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1178 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1179 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1180 c
= isl_constraint_set_constant_si(c
, 1);
1181 bset
= isl_basic_set_add_constraint(bset
, c
);
1183 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1185 /* Test disabled for now */
1187 assert(bset && bset->n_div == 1);
1189 isl_local_space_free(ls
);
1190 isl_basic_set_free(bset
);
1193 space
= isl_space_set_alloc(ctx
, 0, 4);
1194 bset
= isl_basic_set_universe(isl_space_copy(space
));
1195 ls
= isl_local_space_from_space(space
);
1197 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1198 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1199 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1200 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1201 bset
= isl_basic_set_add_constraint(bset
, c
);
1203 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1204 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1205 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1206 c
= isl_constraint_set_constant_si(c
, 2);
1207 bset
= isl_basic_set_add_constraint(bset
, c
);
1209 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1211 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1213 assert(!isl_basic_set_is_empty(bset
));
1215 isl_local_space_free(ls
);
1216 isl_basic_set_free(bset
);
1219 space
= isl_space_set_alloc(ctx
, 0, 3);
1220 bset
= isl_basic_set_universe(isl_space_copy(space
));
1221 ls
= isl_local_space_from_space(space
);
1223 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1224 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1225 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1226 bset
= isl_basic_set_add_constraint(bset
, c
);
1228 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1230 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1232 isl_local_space_free(ls
);
1233 isl_basic_set_free(bset
);
1235 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1236 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1237 set
= isl_set_read_from_str(ctx
, str
);
1238 set
= isl_set_compute_divs(set
);
1243 if (test_elimination(ctx
) < 0)
1246 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1247 set
= isl_set_read_from_str(ctx
, str
);
1248 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1249 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1250 empty
= isl_set_is_empty(set
);
1255 isl_die(ctx
, isl_error_unknown
,
1256 "result not as accurate as expected", return -1);
1261 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1265 struct isl_basic_set
*bset1
, *bset2
;
1266 struct isl_basic_map
*bmap
;
1268 filename
= get_filename(ctx
, name
, "omega");
1270 input
= fopen(filename
, "r");
1273 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1274 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1276 bset1
= isl_basic_set_apply(bset1
, bmap
);
1278 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1280 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1282 isl_basic_set_free(bset1
);
1283 isl_basic_set_free(bset2
);
1289 static int test_application(isl_ctx
*ctx
)
1291 test_application_case(ctx
, "application");
1292 test_application_case(ctx
, "application2");
1297 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1301 struct isl_basic_set
*bset1
, *bset2
;
1303 filename
= get_filename(ctx
, name
, "polylib");
1305 input
= fopen(filename
, "r");
1308 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1309 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1311 bset1
= isl_basic_set_affine_hull(bset1
);
1313 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1315 isl_basic_set_free(bset1
);
1316 isl_basic_set_free(bset2
);
1322 /* Pairs of sets and the corresponding expected results of
1323 * isl_basic_set_recession_cone.
1328 } recession_cone_tests
[] = {
1329 { "{ [i] : 0 <= i <= 10 }", "{ [0] }" },
1330 { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" },
1331 { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" },
1332 { "{ [i] : false }", "{ [i] : false }" },
1335 /* Perform some basic isl_basic_set_recession_cone tests.
1337 static int test_recession_cone(struct isl_ctx
*ctx
)
1341 for (i
= 0; i
< ARRAY_SIZE(recession_cone_tests
); ++i
) {
1343 isl_basic_set
*bset
;
1344 isl_basic_set
*cone
, *expected
;
1347 str
= recession_cone_tests
[i
].set
;
1348 bset
= isl_basic_set_read_from_str(ctx
, str
);
1349 str
= recession_cone_tests
[i
].cone
;
1350 expected
= isl_basic_set_read_from_str(ctx
, str
);
1351 cone
= isl_basic_set_recession_cone(bset
);
1352 equal
= isl_basic_set_is_equal(cone
, expected
);
1353 isl_basic_set_free(cone
);
1354 isl_basic_set_free(expected
);
1358 isl_die(ctx
, isl_error_unknown
, "unexpected cone",
1365 int test_affine_hull(struct isl_ctx
*ctx
)
1369 isl_basic_set
*bset
, *bset2
;
1373 test_affine_hull_case(ctx
, "affine2");
1374 test_affine_hull_case(ctx
, "affine");
1375 test_affine_hull_case(ctx
, "affine3");
1377 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1378 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1379 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1380 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1381 set
= isl_set_read_from_str(ctx
, str
);
1382 bset
= isl_set_affine_hull(set
);
1383 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1384 isl_basic_set_free(bset
);
1388 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1391 /* Check that isl_map_affine_hull is not confused by
1392 * the reordering of divs in isl_map_align_divs.
1394 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1395 "32e0 = b and 32e1 = c); "
1396 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1397 set
= isl_set_read_from_str(ctx
, str
);
1398 bset
= isl_set_affine_hull(set
);
1399 isl_basic_set_free(bset
);
1403 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1404 "32e2 = 31 + 31e0 }";
1405 set
= isl_set_read_from_str(ctx
, str
);
1406 bset
= isl_set_affine_hull(set
);
1407 str
= "{ [a] : exists e : a = 32 e }";
1408 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1409 subset
= isl_basic_set_is_subset(bset
, bset2
);
1410 isl_basic_set_free(bset
);
1411 isl_basic_set_free(bset2
);
1415 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1421 /* Test a special case of isl_set_plain_unshifted_simple_hull
1422 * where older versions of isl would include a redundant constraint
1424 * Check that the result does not have any constraints.
1426 static isl_stat
test_plain_unshifted_simple_hull_special(isl_ctx
*ctx
)
1429 isl_bool is_universe
;
1431 isl_basic_set
*bset
;
1433 str
= "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
1434 set
= isl_set_read_from_str(ctx
, str
);
1435 bset
= isl_set_plain_unshifted_simple_hull(set
);
1436 is_universe
= isl_basic_set_plain_is_universe(bset
);
1437 isl_basic_set_free(bset
);
1439 if (is_universe
< 0)
1440 return isl_stat_error
;
1442 isl_die(ctx
, isl_error_unknown
,
1443 "hull should not have any constraints",
1444 return isl_stat_error
);
1449 /* Inputs for simple hull tests, consisting of
1450 * the specific simple hull function, the input set and the expected result.
1453 __isl_give isl_basic_set
*(*fn
)(__isl_take isl_set
*set
);
1456 } simple_hull_tests
[] = {
1457 { &isl_set_plain_unshifted_simple_hull
,
1458 "{ [i,j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1459 "{ [i,j] : i >= 1 }" },
1460 { &isl_set_plain_unshifted_simple_hull
,
1461 "{ [n,i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1462 "(j mod 4 = 2 and k mod 6 = n) }",
1463 "{ [n,i,j,k] : j mod 4 = 2 }" },
1464 { &isl_set_unshifted_simple_hull
,
1465 "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1466 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1467 { &isl_set_simple_hull
,
1468 "{ [a, b] : b <= 0 and "
1469 "2*floor((-2*floor((b)/2))/5) >= a - floor((b)/2); "
1470 "[a, b] : a mod 2 = 0 }",
1474 /* Basic tests for various simple hull functions.
1476 static int test_various_simple_hull(isl_ctx
*ctx
)
1480 isl_basic_set
*hull
, *expected
;
1483 for (i
= 0; i
< ARRAY_SIZE(simple_hull_tests
); ++i
) {
1485 str
= simple_hull_tests
[i
].set
;
1486 set
= isl_set_read_from_str(ctx
, str
);
1487 str
= simple_hull_tests
[i
].hull
;
1488 expected
= isl_basic_set_read_from_str(ctx
, str
);
1489 hull
= simple_hull_tests
[i
].fn(set
);
1490 equal
= isl_basic_set_is_equal(hull
, expected
);
1491 isl_basic_set_free(hull
);
1492 isl_basic_set_free(expected
);
1496 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1503 static int test_simple_hull(struct isl_ctx
*ctx
)
1507 isl_basic_set
*bset
;
1510 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1511 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1512 set
= isl_set_read_from_str(ctx
, str
);
1513 bset
= isl_set_simple_hull(set
);
1514 is_empty
= isl_basic_set_is_empty(bset
);
1515 isl_basic_set_free(bset
);
1517 if (is_empty
== isl_bool_error
)
1520 if (is_empty
== isl_bool_false
)
1521 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1524 if (test_plain_unshifted_simple_hull_special(ctx
) < 0)
1526 if (test_various_simple_hull(ctx
) < 0)
1532 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1533 * "set" is the input set.
1534 * "offset" is the expected box offset.
1535 * "size" is the expected box size.
1541 } box_hull_tests
[] = {
1542 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1543 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1544 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1545 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1546 "{ S[0, -4] }", "{ S[10, 9] }" },
1547 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1548 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1549 "{ [3] }", "{ [8] }" },
1550 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1551 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1552 "[N] -> { [N] }", "{ [9] }" },
1555 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1557 static int test_box_hull(struct isl_ctx
*ctx
)
1561 for (i
= 0; i
< ARRAY_SIZE(box_hull_tests
); ++i
) {
1565 isl_multi_aff
*offset
;
1566 isl_multi_val
*size
;
1569 set
= isl_set_read_from_str(ctx
, box_hull_tests
[i
].set
);
1570 box
= isl_set_get_simple_fixed_box_hull(set
);
1571 offset
= isl_fixed_box_get_offset(box
);
1572 size
= isl_fixed_box_get_size(box
);
1573 str
= box_hull_tests
[i
].offset
;
1574 r
= multi_aff_check_plain_equal(offset
, str
);
1575 str
= box_hull_tests
[i
].size
;
1577 r
= multi_val_check_plain_equal(size
, str
);
1578 isl_multi_aff_free(offset
);
1579 isl_multi_val_free(size
);
1580 isl_fixed_box_free(box
);
1589 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1593 struct isl_basic_set
*bset1
, *bset2
;
1594 struct isl_set
*set
;
1596 filename
= get_filename(ctx
, name
, "polylib");
1598 input
= fopen(filename
, "r");
1601 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1602 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1604 set
= isl_basic_set_union(bset1
, bset2
);
1605 bset1
= isl_set_convex_hull(set
);
1607 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1609 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1611 isl_basic_set_free(bset1
);
1612 isl_basic_set_free(bset2
);
1621 } convex_hull_tests
[] = {
1622 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1623 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1624 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1625 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1626 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1627 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1628 "i2 <= 5 and i2 >= 4; "
1629 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1630 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1631 "i2 <= 5 + i0 and i2 >= i0 }" },
1632 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1633 "{ [x, y] : 1 = 0 }" },
1634 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1635 "[x, y, 0] : x >= 0 and y < 0 }",
1636 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1637 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1639 "[0, 2, 0]; [3, 1, 0] }",
1640 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1641 "5c <= 6 - a - 3b }" },
1644 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1647 int orig_convex
= ctx
->opt
->convex
;
1648 ctx
->opt
->convex
= convex
;
1650 test_convex_hull_case(ctx
, "convex0");
1651 test_convex_hull_case(ctx
, "convex1");
1652 test_convex_hull_case(ctx
, "convex2");
1653 test_convex_hull_case(ctx
, "convex3");
1654 test_convex_hull_case(ctx
, "convex4");
1655 test_convex_hull_case(ctx
, "convex5");
1656 test_convex_hull_case(ctx
, "convex6");
1657 test_convex_hull_case(ctx
, "convex7");
1658 test_convex_hull_case(ctx
, "convex8");
1659 test_convex_hull_case(ctx
, "convex9");
1660 test_convex_hull_case(ctx
, "convex10");
1661 test_convex_hull_case(ctx
, "convex11");
1662 test_convex_hull_case(ctx
, "convex12");
1663 test_convex_hull_case(ctx
, "convex13");
1664 test_convex_hull_case(ctx
, "convex14");
1665 test_convex_hull_case(ctx
, "convex15");
1667 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1668 isl_set
*set1
, *set2
;
1671 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1672 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1673 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1674 equal
= isl_set_is_equal(set1
, set2
);
1681 isl_die(ctx
, isl_error_unknown
,
1682 "unexpected convex hull", return -1);
1685 ctx
->opt
->convex
= orig_convex
;
1690 static int test_convex_hull(isl_ctx
*ctx
)
1692 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1694 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1699 /* Check that computing the gist of "map" with respect to "context"
1700 * does not make any copy of "map" get marked empty.
1701 * Earlier versions of isl would end up doing that.
1703 static isl_stat
test_gist_empty_pair(isl_ctx
*ctx
, const char *map
,
1704 const char *context
)
1706 isl_map
*m1
, *m2
, *m3
;
1707 isl_bool empty_before
, empty_after
;
1709 m1
= isl_map_read_from_str(ctx
, map
);
1710 m2
= isl_map_read_from_str(ctx
, context
);
1711 m3
= isl_map_copy(m1
);
1712 empty_before
= isl_map_is_empty(m3
);
1713 m1
= isl_map_gist(m1
, m2
);
1714 empty_after
= isl_map_is_empty(m3
);
1718 if (empty_before
< 0 || empty_after
< 0)
1719 return isl_stat_error
;
1721 isl_die(ctx
, isl_error_unknown
, "map should not be empty",
1722 return isl_stat_error
);
1724 isl_die(ctx
, isl_error_unknown
, "map should still not be empty",
1725 return isl_stat_error
);
1730 /* Check that computing a gist does not make any copy of the input
1732 * Earlier versions of isl would end up doing that on some pairs of inputs.
1734 static isl_stat
test_gist_empty(isl_ctx
*ctx
)
1736 const char *map
, *context
;
1738 map
= "{ [] -> [a, b, c] : 2b = 1 + a }";
1739 context
= "{ [] -> [a, b, c] : 2c = 2 + a }";
1740 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1741 return isl_stat_error
;
1742 map
= "{ [] -> [0, 0] }";
1743 context
= "{ [] -> [a, b] : a > b }";
1744 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1745 return isl_stat_error
;
1750 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1754 const char *context
;
1756 } plain_gist_tests
[] = {
1757 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1758 "{ [i] -> [j] : i >= 1 }",
1759 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1760 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1761 "(j mod 4 = 2 and k mod 6 = n) }",
1762 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1763 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1764 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1765 "{ [i] -> [j] : i > j }",
1766 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1769 /* Basic tests for isl_map_plain_gist_basic_map.
1771 static int test_plain_gist(isl_ctx
*ctx
)
1775 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1778 isl_map
*map
, *gist
;
1779 isl_basic_map
*context
;
1781 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1782 str
= plain_gist_tests
[i
].context
;
1783 context
= isl_basic_map_read_from_str(ctx
, str
);
1784 map
= isl_map_plain_gist_basic_map(map
, context
);
1785 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1786 equal
= isl_map_is_equal(map
, gist
);
1792 isl_die(ctx
, isl_error_unknown
,
1793 "incorrect gist result", return -1);
1799 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1803 const char *context
;
1804 } gist_fail_tests
[] = {
1805 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1806 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1807 "{ [i] : i >= 0 }" },
1810 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1811 * In particular, the user should be able to recover from the failure.
1813 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1818 on_error
= isl_options_get_on_error(ctx
);
1819 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1820 n
= ARRAY_SIZE(gist_fail_tests
);
1821 for (i
= 0; i
< n
; ++i
) {
1823 isl_basic_set
*bset
, *context
;
1825 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1826 str
= gist_fail_tests
[i
].context
;
1827 context
= isl_basic_set_read_from_str(ctx
, str
);
1828 bset
= isl_basic_set_gist(bset
, context
);
1829 isl_basic_set_free(bset
);
1833 isl_options_set_on_error(ctx
, on_error
);
1835 isl_die(ctx
, isl_error_unknown
,
1836 "operation not expected to succeed",
1837 return isl_stat_error
);
1844 const char *context
;
1848 "{ [1, b, 2 - b] : -1 <= b <= 2 }",
1850 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1851 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1852 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1853 "{ [a, b, c] : a <= 15 }" },
1854 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1855 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1856 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1857 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1858 { "{ [m, n, a, b] : a <= 2147 + n }",
1859 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1860 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1861 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1863 "{ [m, n, ku, kl] }" },
1864 { "{ [a, a, b] : a >= 10 }",
1865 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1866 "{ [a, a, b] : a >= 10 }" },
1867 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1868 "{ [0, j] : j >= 0 }" },
1869 /* Check that no constraints on i6 are introduced in the gist */
1870 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1871 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1872 "5e0 <= 381 - t1 and i4 <= 1) }",
1873 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1874 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1875 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1876 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1877 "20e0 >= 1511 - 4t1 - 5i4) }" },
1878 /* Check that no constraints on i6 are introduced in the gist */
1879 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1880 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1881 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1882 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1883 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1884 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1885 "20e1 <= 1530 - 4t1 - 5i4 and "
1886 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1887 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1888 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1889 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1890 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1891 "10e0 <= -91 + 5i4 + 4i6 and "
1892 "10e0 >= -105 + 5i4 + 4i6) }",
1893 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1894 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1895 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1896 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1897 "{ [a, b, q, p] : b >= 1 + a }",
1898 "{ [a, b, q, p] : false }" },
1899 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1900 "[n] -> { [x] : x mod 32 = 0 }",
1901 "[n] -> { [x = n] }" },
1902 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1903 "{ [x] : x mod 2 = 0 }" },
1904 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1905 "{ [x] : x mod 128 = 0 }" },
1906 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1907 "{ [x] : x mod 3200 = 0 }" },
1908 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1909 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1910 "{ [a, b, c = a] }" },
1911 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1912 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1913 "{ [a, b, c = a] : a mod 3 = 0 }" },
1914 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1915 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1917 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1918 "{ [x,y] : 1 <= y <= 3 }",
1922 /* Check that isl_set_gist behaves as expected.
1924 * For the test cases in gist_tests, besides checking that the result
1925 * is as expected, also check that applying the gist operation does
1926 * not modify the input set (an earlier version of isl would do that) and
1927 * that the test case is consistent, i.e., that the gist has the same
1928 * intersection with the context as the input set.
1930 static int test_gist(struct isl_ctx
*ctx
)
1934 isl_basic_set
*bset1
, *bset2
;
1935 isl_map
*map1
, *map2
;
1939 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1940 isl_bool equal_input
, equal_intersection
;
1941 isl_set
*set1
, *set2
, *copy
, *context
;
1943 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1944 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1945 copy
= isl_set_copy(set1
);
1946 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1947 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1948 equal
= isl_set_is_equal(set1
, set2
);
1950 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1951 equal_input
= isl_set_is_equal(set1
, copy
);
1953 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1954 set2
= isl_set_intersect(set2
, context
);
1955 equal_intersection
= isl_set_is_equal(set1
, set2
);
1958 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1961 isl_die(ctx
, isl_error_unknown
,
1962 "incorrect gist result", return -1);
1964 isl_die(ctx
, isl_error_unknown
,
1965 "gist modified input", return -1);
1967 isl_die(ctx
, isl_error_unknown
,
1968 "inconsistent gist test case", return -1);
1971 if (test_gist_fail(ctx
) < 0)
1974 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1975 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1976 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1977 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1978 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1979 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1980 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1981 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1982 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1983 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1984 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1985 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1986 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1987 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1988 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1989 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1990 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1991 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1992 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1993 bset1
= isl_basic_set_gist(bset1
, bset2
);
1994 assert(bset1
&& bset1
->n_div
== 0);
1995 isl_basic_set_free(bset1
);
1997 /* Check that the integer divisions of the second disjunct
1998 * do not spread to the first disjunct.
2000 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
2001 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
2002 "(exists (e0 = [(-1 + t1)/16], "
2003 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
2004 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
2005 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
2006 "o0 <= 4294967295 and t1 <= -1)) }";
2007 map1
= isl_map_read_from_str(ctx
, str
);
2008 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
2009 map2
= isl_map_read_from_str(ctx
, str
);
2010 map1
= isl_map_gist(map1
, map2
);
2014 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
2015 isl_map_free(map1
); return -1);
2016 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
2021 isl_die(ctx
, isl_error_unknown
, "expecting single div",
2024 if (test_gist_empty(ctx
) < 0)
2026 if (test_plain_gist(ctx
) < 0)
2032 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
2034 isl_set
*set
, *set2
;
2038 set
= isl_set_read_from_str(ctx
, str
);
2039 set
= isl_set_coalesce(set
);
2040 set2
= isl_set_read_from_str(ctx
, str
);
2041 equal
= isl_set_is_equal(set
, set2
);
2042 one
= set
&& set
->n
== 1;
2049 isl_die(ctx
, isl_error_unknown
,
2050 "coalesced set not equal to input", return -1);
2051 if (check_one
&& !one
)
2052 isl_die(ctx
, isl_error_unknown
,
2053 "coalesced set should not be a union", return -1);
2058 /* Inputs for coalescing tests with unbounded wrapping.
2059 * "str" is a string representation of the input set.
2060 * "single_disjunct" is set if we expect the result to consist of
2061 * a single disjunct.
2064 int single_disjunct
;
2066 } coalesce_unbounded_tests
[] = {
2067 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2068 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2069 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2070 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2072 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2073 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2074 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2075 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2076 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2077 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2078 { 1, "{ [0:1, 0:1]; [0, 2:3] }" },
2079 { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" },
2080 { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" },
2081 { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" },
2082 { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" },
2083 { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" },
2084 { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" },
2087 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2088 * option turned off.
2090 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
2096 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
2097 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
2099 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
2100 const char *str
= coalesce_unbounded_tests
[i
].str
;
2101 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
2102 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
2108 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
2113 /* Inputs for coalescing tests.
2114 * "str" is a string representation of the input set.
2115 * "single_disjunct" is set if we expect the result to consist of
2116 * a single disjunct.
2119 int single_disjunct
;
2121 } coalesce_tests
[] = {
2122 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2123 "y >= x & x >= 2 & 5 >= y }" },
2124 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2125 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2126 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2127 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2128 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2129 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2130 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2131 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2132 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2133 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2134 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2135 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2136 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2137 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2138 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2139 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2140 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2141 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2142 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2143 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2144 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2145 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2146 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2147 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2148 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2149 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2150 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2151 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2152 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2153 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2154 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2155 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2156 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2157 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2158 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2159 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2160 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2161 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2162 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2163 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2164 "[o0, o1, o2, o3, o4, o5, o6]] : "
2165 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2166 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2167 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2168 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2169 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2170 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2171 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2172 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2173 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2174 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2175 "o6 >= i3 + i6 - o3 and M >= 0 and "
2176 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2177 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2178 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2179 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2180 "(o0 = 0 and M >= 2 and N >= 3) or "
2181 "(M = 0 and o0 = 0 and N >= 3) }" },
2182 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2183 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2184 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2185 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2186 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2187 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2188 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2189 "(y = 3 and x = 1) }" },
2190 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2191 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2192 "i1 <= M and i3 <= M and i4 <= M) or "
2193 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2194 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2195 "i4 <= -1 + M) }" },
2196 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2197 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2198 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2199 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2200 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2201 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2202 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2203 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2204 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2205 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2206 { 0, "{ [a, b] : exists e : 2e = a and "
2207 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2208 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2209 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2210 "j >= 1 and j' <= i + j - i' and i >= 1; "
2212 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2213 "[i,j] : exists a : j = 3a }" },
2214 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2215 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2217 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2218 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2219 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2220 "c <= 6 + 8a and a >= 3; "
2221 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2222 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2223 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2224 "[x,0] : 3 <= x <= 4 }" },
2225 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2226 "[x,0] : 4 <= x <= 5 }" },
2227 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2228 "[x,0] : 3 <= x <= 5 }" },
2229 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2230 "[x,0] : 3 <= x <= 4 }" },
2231 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2233 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2234 { 1, "{ [0,0]; [1,1] }" },
2235 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2236 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2238 "[k, 0, k] : k <= 6 and k >= 1 }" },
2239 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2240 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2241 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2242 { 1, "[n] -> { [1] : n >= 0;"
2243 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2244 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2245 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2246 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2247 "2e0 <= x and 2e0 <= n);"
2248 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2250 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2251 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2252 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2254 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2255 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2257 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2258 "t1 >= 13 and t1 <= 16);"
2259 "[t1] : t1 <= 15 and t1 >= 12 }" },
2260 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2261 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2262 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2263 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2264 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2265 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2267 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2268 "(exists (e0 : 3e0 = -2 + c0)) }" },
2269 { 0, "[n, b0, t0] -> "
2270 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2271 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2272 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2273 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2274 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2275 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2276 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2277 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2278 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2279 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2280 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2281 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2282 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2283 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2284 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2285 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2286 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2287 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2288 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2289 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2290 { 0, "{ [i0, i1, i2] : "
2291 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2292 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2293 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2294 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2295 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2296 "32e0 <= 31 + i0)) or "
2298 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2299 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2300 "2*floor((c)/2) = c and 0 <= a <= 192;"
2301 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2303 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2304 "(0 <= a <= b <= n) }" },
2305 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2306 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2307 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2308 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2309 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2310 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2311 "b = 3 and 9e0 <= -19 + 2c)) }" },
2312 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2313 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2314 "(a = 4 and b = 3 and "
2315 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2316 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2317 "(b = -1 + a and 0 < a <= 3 and "
2318 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2319 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2320 "b = 3 and 9e0 <= -19 + 2c)) }" },
2321 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2323 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2325 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2326 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2327 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2328 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2329 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2330 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2331 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2332 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2333 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2334 { 1, "{ [a] : a <= 8 and "
2335 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2336 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2337 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2338 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2339 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2340 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2341 "(a < 0 and 3*floor((a)/3) < a) }" },
2342 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2343 "(a < -1 and 3*floor((a)/3) < a) }" },
2344 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2345 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2346 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2347 "or (2 <= a <= 15 and b < a)) }" },
2348 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2349 "32*floor((a)/32) < a) or a <= 15) }" },
2350 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2351 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2352 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2353 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2354 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2355 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2356 "S_0[n] : n <= m <= 2 + n }" },
2357 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2358 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2360 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2361 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2362 "2e0 < -a + 2b) }" },
2363 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2364 "[i, 0, i] : 0 <= i <= 7 }" },
2365 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2366 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2367 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2368 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2369 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2370 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2371 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2372 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2373 "a > 0 and a <= 5) }" },
2374 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2375 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2376 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2377 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2378 { 0, "{ [0:1, 0:1]; [0, 2:3] }" },
2379 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2380 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2381 { 1, "{ rat: [0:2]; rat: [1:3] }" },
2384 /* A specialized coalescing test case that would result
2385 * in a segmentation fault or a failed assertion in earlier versions of isl.
2387 static int test_coalesce_special(struct isl_ctx
*ctx
)
2390 isl_map
*map1
, *map2
;
2392 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2393 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2394 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2395 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2396 "o1 <= 239 and o1 >= 212)) or "
2397 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2398 "o1 <= 241 and o1 >= 240));"
2399 "[S_L220_OUT[] -> T7[]] -> "
2400 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2401 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2402 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2403 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2404 map1
= isl_map_read_from_str(ctx
, str
);
2405 map1
= isl_map_align_divs_internal(map1
);
2406 map1
= isl_map_coalesce(map1
);
2407 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2408 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2409 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2410 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2411 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2412 map2
= isl_map_read_from_str(ctx
, str
);
2413 map2
= isl_map_union(map2
, map1
);
2414 map2
= isl_map_align_divs_internal(map2
);
2415 map2
= isl_map_coalesce(map2
);
2423 /* Check that the union of the basic sets described by "str1" and "str2"
2424 * can be coalesced and that the result is equal to the union.
2425 * The explicit call to isl_basic_set_union prevents the implicit
2426 * equality constraints in the basic maps from being detected prior
2427 * to the call to isl_set_coalesce, at least at the point
2428 * where this function was introduced.
2430 static isl_stat
test_coalesce_union(isl_ctx
*ctx
, const char *str1
,
2433 isl_basic_set
*bset1
, *bset2
;
2434 isl_set
*set
, *set2
;
2437 bset1
= isl_basic_set_read_from_str(ctx
, str1
);
2438 bset2
= isl_basic_set_read_from_str(ctx
, str2
);
2439 set
= isl_basic_set_union(bset1
, bset2
);
2440 set
= isl_set_coalesce(set
);
2442 bset1
= isl_basic_set_read_from_str(ctx
, str1
);
2443 bset2
= isl_basic_set_read_from_str(ctx
, str2
);
2444 set2
= isl_basic_set_union(bset1
, bset2
);
2446 equal
= isl_set_is_equal(set
, set2
);
2451 return isl_stat_error
;
2453 isl_die(ctx
, isl_error_unknown
,
2454 "coalesced set not equal to input",
2455 return isl_stat_error
);
2457 return isl_stat_non_null(set
);
2460 /* A specialized coalescing test case that would result in an assertion
2461 * in an earlier version of isl. Use test_coalesce_union with
2462 * an explicit call to isl_basic_set_union to prevent the implicit
2463 * equality constraints in the first basic map from being detected prior
2464 * to the call to isl_set_coalesce, at least at the point
2465 * where this test case was introduced.
2467 static isl_stat
test_coalesce_special2(struct isl_ctx
*ctx
)
2472 str1
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2473 str2
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }";
2474 return test_coalesce_union(ctx
, str1
, str2
);
2477 /* Check that calling isl_set_coalesce does not leave other sets
2478 * that may share some information with the input to isl_set_coalesce
2479 * in an inconsistent state.
2480 * In particular, older versions of isl would modify all copies
2481 * of the basic sets in the isl_set_coalesce input in a way
2482 * that could leave them in an inconsistent state.
2483 * The result of printing any other set containing one of these
2484 * basic sets would then result in an invalid set description.
2486 static int test_coalesce_special3(isl_ctx
*ctx
)
2490 isl_set
*set1
, *set2
;
2493 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2494 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2495 set2
= isl_set_read_from_str(ctx
, str
);
2496 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2497 set1
= isl_set_coalesce(set1
);
2500 p
= isl_printer_to_str(ctx
);
2501 p
= isl_printer_print_set(p
, set2
);
2503 s
= isl_printer_get_str(p
);
2504 isl_printer_free(p
);
2505 set1
= isl_set_read_from_str(ctx
, s
);
2515 /* Check that calling isl_set_coalesce on the intersection of
2516 * the sets described by "s1" and "s2" does not leave other sets
2517 * that may share some information with the input to isl_set_coalesce
2518 * in an inconsistent state.
2519 * In particular, when isl_set_coalesce detects equality constraints,
2520 * it does not immediately perform Gaussian elimination on them,
2521 * but then it needs to ensure that it is performed at some point.
2522 * The input set has implicit equality constraints in the first disjunct.
2523 * It is constructed as an intersection, because otherwise
2524 * those equality constraints would already be detected during parsing.
2526 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2527 const char *s1
, const char *s2
)
2529 isl_set
*set1
, *set2
;
2531 set1
= isl_set_read_from_str(ctx
, s1
);
2532 set2
= isl_set_read_from_str(ctx
, s2
);
2533 set1
= isl_set_intersect(set1
, set2
);
2534 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2535 set1
= isl_set_coalesce(set1
);
2539 return isl_stat_error
;
2544 /* Check that calling isl_set_coalesce does not leave other sets
2545 * that may share some information with the input to isl_set_coalesce
2546 * in an inconsistent state, for the case where one disjunct
2547 * is a subset of the other.
2549 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2551 const char *s1
, *s2
;
2553 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2554 s2
= "{ [a, b] : -1 <= -a < b }";
2555 return test_coalesce_intersection(ctx
, s1
, s2
);
2558 /* Check that calling isl_set_coalesce does not leave other sets
2559 * that may share some information with the input to isl_set_coalesce
2560 * in an inconsistent state, for the case where two disjuncts
2563 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2565 const char *s1
, *s2
;
2567 s1
= "{ [a, b, c] : b <= 0 }";
2568 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2569 return test_coalesce_intersection(ctx
, s1
, s2
);
2572 /* Check that calling isl_set_coalesce does not leave other sets
2573 * that may share some information with the input to isl_set_coalesce
2574 * in an inconsistent state, for the case where two disjuncts
2575 * can be fused and where both disjuncts have implicit equality constraints.
2577 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2579 const char *s1
, *s2
;
2581 s1
= "{ [a, b, c] : c <= 0 }";
2582 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2583 return test_coalesce_intersection(ctx
, s1
, s2
);
2586 /* A specialized coalescing test case that would result in an assertion failure
2587 * in an earlier version of isl. Use test_coalesce_union with
2588 * an explicit call to isl_basic_set_union to prevent the implicit
2589 * equality constraints in the basic maps from being detected prior
2590 * to the call to isl_set_coalesce, at least at the point
2591 * where this test case was introduced.
2593 static isl_stat
test_coalesce_special7(isl_ctx
*ctx
)
2598 str1
= "{ [a, b, c=0:17] : a <= 7 and 2b <= 11 - a and "
2599 "c <= -7 + 2a and 2c >= - 3 + 3a - 2b }";
2600 str2
= "{ [a, b, c] : c > -15a and c >= -7 + 2a and c < 0 and "
2601 "3c <= -5 + 5a - 3b and 2b >= 11 - a }";
2602 return test_coalesce_union(ctx
, str1
, str2
);
2605 /* A specialized coalescing test case that would result in a disjunct
2606 * getting dropped in an earlier version of isl. Use test_coalesce_union with
2607 * an explicit call to isl_basic_set_union to prevent the implicit
2608 * equality constraints in the basic maps from being detected prior
2609 * to the call to isl_set_coalesce, at least at the point
2610 * where this test case was introduced.
2612 static isl_stat
test_coalesce_special8(isl_ctx
*ctx
)
2617 str1
= "{ [a, b, c] : 2c <= -a and b >= -a and b <= 5 and "
2618 "6c > -7a and 11c >= -5a - b and a <= 3 }";
2619 str2
= "{ [a, b, c] : 6c > -7a and b >= -a and b <= 5 and "
2620 "11c >= -5a - b and a >= 4 and 2b <= a and 2c <= -a }";
2621 return test_coalesce_union(ctx
, str1
, str2
);
2624 /* Test the functionality of isl_set_coalesce.
2625 * That is, check that the output is always equal to the input
2626 * and in some cases that the result consists of a single disjunct.
2628 static int test_coalesce(struct isl_ctx
*ctx
)
2632 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2633 const char *str
= coalesce_tests
[i
].str
;
2634 int check_one
= coalesce_tests
[i
].single_disjunct
;
2635 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2639 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2641 if (test_coalesce_special(ctx
) < 0)
2643 if (test_coalesce_special2(ctx
) < 0)
2645 if (test_coalesce_special3(ctx
) < 0)
2647 if (test_coalesce_special4(ctx
) < 0)
2649 if (test_coalesce_special5(ctx
) < 0)
2651 if (test_coalesce_special6(ctx
) < 0)
2653 if (test_coalesce_special7(ctx
) < 0)
2655 if (test_coalesce_special8(ctx
) < 0)
2661 /* Construct a representation of the graph on the right of Figure 1
2662 * in "Computing the Transitive Closure of a Union of
2663 * Affine Integer Tuple Relations".
2665 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2668 isl_map
*up
, *right
;
2670 dom
= isl_set_read_from_str(ctx
,
2671 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2672 "2 x - 3 y + 3 >= 0 }");
2673 right
= isl_map_read_from_str(ctx
,
2674 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2675 up
= isl_map_read_from_str(ctx
,
2676 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2677 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2678 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2679 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2680 up
= isl_map_intersect_range(up
, dom
);
2681 return isl_map_union(up
, right
);
2684 /* Construct a representation of the power of the graph
2685 * on the right of Figure 1 in "Computing the Transitive Closure of
2686 * a Union of Affine Integer Tuple Relations".
2688 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2690 return isl_map_read_from_str(ctx
,
2691 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2692 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2693 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2696 /* Construct a representation of the transitive closure of the graph
2697 * on the right of Figure 1 in "Computing the Transitive Closure of
2698 * a Union of Affine Integer Tuple Relations".
2700 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2702 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2705 static int test_closure(isl_ctx
*ctx
)
2708 isl_map
*map
, *map2
;
2709 isl_bool exact
, equal
;
2711 /* COCOA example 1 */
2712 map
= isl_map_read_from_str(ctx
,
2713 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2714 "1 <= i and i < n and 1 <= j and j < n or "
2715 "i2 = i + 1 and j2 = j - 1 and "
2716 "1 <= i and i < n and 2 <= j and j <= n }");
2717 map
= isl_map_power(map
, &exact
);
2721 /* COCOA example 1 */
2722 map
= isl_map_read_from_str(ctx
,
2723 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2724 "1 <= i and i < n and 1 <= j and j < n or "
2725 "i2 = i + 1 and j2 = j - 1 and "
2726 "1 <= i and i < n and 2 <= j and j <= n }");
2727 map
= isl_map_transitive_closure(map
, &exact
);
2729 map2
= isl_map_read_from_str(ctx
,
2730 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2731 "1 <= i and i < n and 1 <= j and j <= n and "
2732 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2733 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2734 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2735 assert(isl_map_is_equal(map
, map2
));
2739 map
= isl_map_read_from_str(ctx
,
2740 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2741 " 0 <= y and y <= n }");
2742 map
= isl_map_transitive_closure(map
, &exact
);
2743 map2
= isl_map_read_from_str(ctx
,
2744 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2745 " 0 <= y and y <= n }");
2746 assert(isl_map_is_equal(map
, map2
));
2750 /* COCOA example 2 */
2751 map
= isl_map_read_from_str(ctx
,
2752 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2753 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2754 "i2 = i + 2 and j2 = j - 2 and "
2755 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2756 map
= isl_map_transitive_closure(map
, &exact
);
2758 map2
= isl_map_read_from_str(ctx
,
2759 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2760 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2761 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2762 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2763 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2764 assert(isl_map_is_equal(map
, map2
));
2768 /* COCOA Fig.2 left */
2769 map
= isl_map_read_from_str(ctx
,
2770 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2771 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2773 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2774 "j <= 2 i - 3 and j <= n - 2 or "
2775 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2776 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2777 map
= isl_map_transitive_closure(map
, &exact
);
2781 /* COCOA Fig.2 right */
2782 map
= isl_map_read_from_str(ctx
,
2783 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2784 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2786 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2787 "j <= 2 i - 4 and j <= n - 3 or "
2788 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2789 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2790 map
= isl_map_power(map
, &exact
);
2794 /* COCOA Fig.2 right */
2795 map
= isl_map_read_from_str(ctx
,
2796 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2797 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2799 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2800 "j <= 2 i - 4 and j <= n - 3 or "
2801 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2802 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2803 map
= isl_map_transitive_closure(map
, &exact
);
2805 map2
= isl_map_read_from_str(ctx
,
2806 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2807 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2808 "j <= n and 3 + i + 2 j <= 3 n and "
2809 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2810 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2811 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2812 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2813 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2814 assert(isl_map_is_equal(map
, map2
));
2818 map
= cocoa_fig_1_right_graph(ctx
);
2819 map
= isl_map_transitive_closure(map
, &exact
);
2821 map2
= cocoa_fig_1_right_tc(ctx
);
2822 assert(isl_map_is_equal(map
, map2
));
2826 map
= cocoa_fig_1_right_graph(ctx
);
2827 map
= isl_map_power(map
, &exact
);
2828 map2
= cocoa_fig_1_right_power(ctx
);
2829 equal
= isl_map_is_equal(map
, map2
);
2835 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2837 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2839 /* COCOA Theorem 1 counter example */
2840 map
= isl_map_read_from_str(ctx
,
2841 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2842 "i2 = 1 and j2 = j or "
2843 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2844 map
= isl_map_transitive_closure(map
, &exact
);
2848 map
= isl_map_read_from_str(ctx
,
2849 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2850 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2851 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2852 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2853 map
= isl_map_transitive_closure(map
, &exact
);
2857 /* Kelly et al 1996, fig 12 */
2858 map
= isl_map_read_from_str(ctx
,
2859 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2860 "1 <= i,j,j+1 <= n or "
2861 "j = n and j2 = 1 and i2 = i + 1 and "
2862 "1 <= i,i+1 <= n }");
2863 map
= isl_map_transitive_closure(map
, &exact
);
2865 map2
= isl_map_read_from_str(ctx
,
2866 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2867 "1 <= i <= n and i = i2 or "
2868 "1 <= i < i2 <= n and 1 <= j <= n and "
2870 assert(isl_map_is_equal(map
, map2
));
2874 /* Omega's closure4 */
2875 map
= isl_map_read_from_str(ctx
,
2876 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2877 "1 <= x,y <= 10 or "
2878 "x2 = x + 1 and y2 = y and "
2879 "1 <= x <= 20 && 5 <= y <= 15 }");
2880 map
= isl_map_transitive_closure(map
, &exact
);
2884 map
= isl_map_read_from_str(ctx
,
2885 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2886 map
= isl_map_transitive_closure(map
, &exact
);
2888 map2
= isl_map_read_from_str(ctx
,
2889 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2890 assert(isl_map_is_equal(map
, map2
));
2894 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2895 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2896 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2897 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2898 map
= isl_map_read_from_str(ctx
, str
);
2899 map
= isl_map_transitive_closure(map
, &exact
);
2901 map2
= isl_map_read_from_str(ctx
, str
);
2902 assert(isl_map_is_equal(map
, map2
));
2906 str
= "{[0] -> [1]; [2] -> [3]}";
2907 map
= isl_map_read_from_str(ctx
, str
);
2908 map
= isl_map_transitive_closure(map
, &exact
);
2910 map2
= isl_map_read_from_str(ctx
, str
);
2911 assert(isl_map_is_equal(map
, map2
));
2915 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2916 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2917 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2918 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2919 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2920 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2921 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2922 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2923 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2924 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2925 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2926 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2927 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2928 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2929 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2930 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2931 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2932 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2933 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2934 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2935 map
= isl_map_read_from_str(ctx
, str
);
2936 map
= isl_map_transitive_closure(map
, NULL
);
2943 /* Check that the actual result of a boolean operation is equal
2944 * to the expected result.
2946 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2948 if (actual
!= expected
)
2949 isl_die(ctx
, isl_error_unknown
,
2950 "incorrect boolean operation", return isl_stat_error
);
2954 /* Test operations on isl_bool values.
2961 static int test_isl_bool(isl_ctx
*ctx
)
2963 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
2965 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
2967 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
2969 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
2971 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
2973 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
2975 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
2977 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
2983 static int test_lex(struct isl_ctx
*ctx
)
2989 space
= isl_space_set_alloc(ctx
, 0, 0);
2990 map
= isl_map_lex_le(space
);
2991 empty
= isl_map_is_empty(map
);
2997 isl_die(ctx
, isl_error_unknown
,
2998 "expecting non-empty result", return -1);
3003 /* Inputs for isl_map_lexmin tests.
3004 * "map" is the input and "lexmin" is the expected result.
3009 } lexmin_tests
[] = {
3010 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
3011 "{ [x] -> [5] : 6 <= x <= 8; "
3012 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
3013 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
3014 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
3015 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
3016 "{ [x] -> [y] : (4y = x and x >= 0) or "
3017 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
3018 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
3019 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
3020 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
3021 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
3022 /* Check that empty pieces are properly combined. */
3023 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
3024 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
3025 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
3026 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
3027 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
3029 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
3030 "a <= 255 and c <= 255 and d <= 255 - j and "
3031 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
3032 "247d <= 247 + k - j and 247d <= 247 + k - b and "
3033 "247d <= 247 + i and 248 - b <= 248d <= c and "
3034 "254d >= i - a + b and 254d >= -a + b and "
3035 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
3037 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
3038 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
3039 "247j >= 62738 - i and 509j <= 129795 + i and "
3040 "742j >= 188724 - i; "
3041 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
3042 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
3043 "16*floor((8 + b)/16) <= 7 + b; "
3045 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
3046 "[a] -> [b = 0] : 0 < a <= 509 }" },
3047 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
3048 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
3049 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
3052 static int test_lexmin(struct isl_ctx
*ctx
)
3057 isl_basic_map
*bmap
;
3058 isl_map
*map
, *map2
;
3061 isl_pw_multi_aff
*pma
;
3063 str
= "[p0, p1] -> { [] -> [] : "
3064 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
3065 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
3066 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
3067 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
3068 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
3069 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
3070 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
3071 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
3072 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
3073 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
3074 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
3075 map
= isl_map_read_from_str(ctx
, str
);
3076 map
= isl_map_lexmin(map
);
3081 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
3082 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
3083 set
= isl_set_read_from_str(ctx
, str
);
3084 set
= isl_set_lexmax(set
);
3085 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
3086 set2
= isl_set_read_from_str(ctx
, str
);
3087 set
= isl_set_intersect(set
, set2
);
3088 assert(!isl_set_is_empty(set
));
3091 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
3092 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
3093 map
= isl_map_lexmin(map
);
3094 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
3095 equal
= isl_map_is_equal(map
, map2
);
3102 isl_die(ctx
, isl_error_unknown
,
3103 "unexpected result", return -1);
3106 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3107 " 8i' <= i and 8i' >= -7 + i }";
3108 bmap
= isl_basic_map_read_from_str(ctx
, str
);
3109 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
3110 map2
= isl_map_from_pw_multi_aff(pma
);
3111 map
= isl_map_from_basic_map(bmap
);
3112 assert(isl_map_is_equal(map
, map2
));
3116 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3117 " 8i' <= i and 8i' >= -7 + i }";
3118 set
= isl_set_read_from_str(ctx
, str
);
3119 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
3120 set2
= isl_set_from_pw_multi_aff(pma
);
3121 equal
= isl_set_is_equal(set
, set2
);
3127 isl_die(ctx
, isl_error_unknown
,
3128 "unexpected difference between set and "
3129 "piecewise affine expression", return -1);
3134 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3135 * "pma" is the input.
3136 * "res" is the expected result.
3141 } opt_pw_tests
[] = {
3142 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3143 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3144 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3145 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3146 "{ A[10, 0, 20] }" },
3147 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3150 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3152 static isl_stat
test_pw_max(struct isl_ctx
*ctx
)
3155 isl_pw_multi_aff
*pma
;
3159 for (i
= 0; i
< ARRAY_SIZE(opt_pw_tests
); ++i
) {
3160 pma
= isl_pw_multi_aff_read_from_str(ctx
, opt_pw_tests
[i
].pma
);
3161 mv
= isl_pw_multi_aff_max_multi_val(pma
);
3162 r
= multi_val_check_plain_equal(mv
, opt_pw_tests
[i
].res
);
3163 isl_multi_val_free(mv
);
3166 return isl_stat_error
;
3172 /* A specialized isl_set_min_val test case that would return the wrong result
3173 * in earlier versions of isl.
3174 * The explicit call to isl_basic_set_union prevents the second basic set
3175 * from being determined to be empty prior to the call to isl_set_min_val,
3176 * at least at the point where this test case was introduced.
3178 static int test_min_special(isl_ctx
*ctx
)
3181 isl_basic_set
*bset1
, *bset2
;
3187 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3188 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3189 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3190 bset2
= isl_basic_set_read_from_str(ctx
, str
);
3191 set
= isl_basic_set_union(bset1
, bset2
);
3192 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
3194 res
= isl_set_min_val(set
, obj
);
3195 ok
= isl_val_cmp_si(res
, 5) == 0;
3204 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
3210 /* A specialized isl_set_min_val test case that would return an error
3211 * in earlier versions of isl.
3213 static int test_min_special2(isl_ctx
*ctx
)
3216 isl_basic_set
*bset
;
3220 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3221 bset
= isl_basic_set_read_from_str(ctx
, str
);
3223 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
3225 res
= isl_basic_set_max_val(bset
, obj
);
3227 isl_basic_set_free(bset
);
3237 /* Check that the result of isl_set_min_multi_pw_aff
3238 * on the union of the sets with string descriptions "s1" and "s2"
3239 * consists of a single expression (on a single cell).
3241 static isl_stat
check_single_expr_min(isl_ctx
*ctx
, const char *s1
,
3245 isl_set
*set1
, *set2
;
3246 isl_multi_pw_aff
*mpa
;
3247 isl_pw_multi_aff
*pma
;
3249 set1
= isl_set_read_from_str(ctx
, s1
);
3250 set2
= isl_set_read_from_str(ctx
, s2
);
3251 set1
= isl_set_union(set1
, set2
);
3252 mpa
= isl_set_min_multi_pw_aff(set1
);
3253 pma
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
3254 n
= isl_pw_multi_aff_n_piece(pma
);
3255 isl_pw_multi_aff_free(pma
);
3258 return isl_stat_error
;
3260 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
3261 return isl_stat_error
);
3265 /* A specialized isl_set_min_multi_pw_aff test that checks
3266 * that the minimum of 2N and 3N for N >= 0 is represented
3267 * by a single expression, without splitting off the special case N = 0.
3268 * Do this for both orderings.
3270 static int test_min_mpa(isl_ctx
*ctx
)
3272 const char *s1
, *s2
;
3274 s1
= "[N=0:] -> { [1, 3N:] }";
3275 s2
= "[N=0:] -> { [10, 2N:] }";
3276 if (check_single_expr_min(ctx
, s1
, s2
) < 0)
3278 if (check_single_expr_min(ctx
, s2
, s1
) < 0)
3287 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
3288 __isl_keep isl_aff
*obj
);
3291 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
3292 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
3293 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3294 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3295 &isl_set_max_val
, "30" },
3299 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3300 * In particular, check the results on non-convex inputs.
3302 static int test_min(struct isl_ctx
*ctx
)
3310 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
3311 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
3312 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
3313 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
3314 val
= opt_tests
[i
].fn(set
, obj
);
3315 ok
= isl_val_eq(res
, val
);
3324 isl_die(ctx
, isl_error_unknown
,
3325 "unexpected optimum", return -1);
3328 if (test_pw_max(ctx
) < 0)
3330 if (test_min_special(ctx
) < 0)
3332 if (test_min_special2(ctx
) < 0)
3343 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
3344 void *dep_user
, void *user
)
3346 struct must_may
*mm
= (struct must_may
*)user
;
3349 mm
->must
= isl_map_union(mm
->must
, dep
);
3351 mm
->may
= isl_map_union(mm
->may
, dep
);
3356 static int common_space(void *first
, void *second
)
3358 int depth
= *(int *)first
;
3362 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3370 map2
= isl_map_read_from_str(map
->ctx
, str
);
3371 equal
= isl_map_is_equal(map
, map2
);
3377 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3381 equal
= map_is_equal(map
, str
);
3385 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3386 "result not as expected", return -1);
3390 /* Is "set" equal to the set described by "str"?
3392 static isl_bool
set_is_equal(__isl_keep isl_set
*set
, const char *str
)
3398 return isl_bool_error
;
3400 set2
= isl_set_read_from_str(isl_set_get_ctx(set
), str
);
3401 equal
= isl_set_is_equal(set
, set2
);
3407 /* Check that "set" is equal to the set described by "str".
3409 static isl_stat
set_check_equal(__isl_keep isl_set
*set
, const char *str
)
3413 equal
= set_is_equal(set
, str
);
3415 return isl_stat_error
;
3417 isl_die(isl_set_get_ctx(set
), isl_error_unknown
,
3418 "result not as expected", return isl_stat_error
);
3422 /* Is "uset" equal to the union set described by "str"?
3424 static isl_bool
uset_is_equal(__isl_keep isl_union_set
*uset
, const char *str
)
3426 isl_union_set
*uset2
;
3430 return isl_bool_error
;
3432 uset2
= isl_union_set_read_from_str(isl_union_set_get_ctx(uset
), str
);
3433 equal
= isl_union_set_is_equal(uset
, uset2
);
3434 isl_union_set_free(uset2
);
3439 /* Check that "uset" is equal to the union set described by "str".
3441 static isl_stat
uset_check_equal(__isl_keep isl_union_set
*uset
,
3446 equal
= uset_is_equal(uset
, str
);
3448 return isl_stat_error
;
3450 isl_die(isl_union_set_get_ctx(uset
), isl_error_unknown
,
3451 "result not as expected", return isl_stat_error
);
3455 static int test_dep(struct isl_ctx
*ctx
)
3460 isl_access_info
*ai
;
3467 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3468 map
= isl_map_read_from_str(ctx
, str
);
3469 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3471 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3472 map
= isl_map_read_from_str(ctx
, str
);
3473 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3475 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3476 map
= isl_map_read_from_str(ctx
, str
);
3477 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3479 flow
= isl_access_info_compute_flow(ai
);
3480 space
= isl_space_alloc(ctx
, 0, 3, 3);
3481 mm
.must
= isl_map_empty(isl_space_copy(space
));
3482 mm
.may
= isl_map_empty(space
);
3484 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3486 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3487 " [1,10,0] -> [2,5,0] }";
3488 assert(map_is_equal(mm
.must
, str
));
3489 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3490 assert(map_is_equal(mm
.may
, str
));
3492 isl_map_free(mm
.must
);
3493 isl_map_free(mm
.may
);
3494 isl_flow_free(flow
);
3497 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3498 map
= isl_map_read_from_str(ctx
, str
);
3499 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3501 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3502 map
= isl_map_read_from_str(ctx
, str
);
3503 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3505 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3506 map
= isl_map_read_from_str(ctx
, str
);
3507 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3509 flow
= isl_access_info_compute_flow(ai
);
3510 space
= isl_space_alloc(ctx
, 0, 3, 3);
3511 mm
.must
= isl_map_empty(isl_space_copy(space
));
3512 mm
.may
= isl_map_empty(space
);
3514 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3516 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3517 assert(map_is_equal(mm
.must
, str
));
3518 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3519 assert(map_is_equal(mm
.may
, str
));
3521 isl_map_free(mm
.must
);
3522 isl_map_free(mm
.may
);
3523 isl_flow_free(flow
);
3526 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3527 map
= isl_map_read_from_str(ctx
, str
);
3528 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3530 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3531 map
= isl_map_read_from_str(ctx
, str
);
3532 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3534 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3535 map
= isl_map_read_from_str(ctx
, str
);
3536 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3538 flow
= isl_access_info_compute_flow(ai
);
3539 space
= isl_space_alloc(ctx
, 0, 3, 3);
3540 mm
.must
= isl_map_empty(isl_space_copy(space
));
3541 mm
.may
= isl_map_empty(space
);
3543 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3545 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3546 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3547 assert(map_is_equal(mm
.may
, str
));
3548 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3549 assert(map_is_equal(mm
.must
, str
));
3551 isl_map_free(mm
.must
);
3552 isl_map_free(mm
.may
);
3553 isl_flow_free(flow
);
3556 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3557 map
= isl_map_read_from_str(ctx
, str
);
3558 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3560 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3561 map
= isl_map_read_from_str(ctx
, str
);
3562 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3564 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3565 map
= isl_map_read_from_str(ctx
, str
);
3566 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3568 flow
= isl_access_info_compute_flow(ai
);
3569 space
= isl_space_alloc(ctx
, 0, 3, 3);
3570 mm
.must
= isl_map_empty(isl_space_copy(space
));
3571 mm
.may
= isl_map_empty(space
);
3573 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3575 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3576 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3577 assert(map_is_equal(mm
.may
, str
));
3578 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3579 assert(map_is_equal(mm
.must
, str
));
3581 isl_map_free(mm
.must
);
3582 isl_map_free(mm
.may
);
3583 isl_flow_free(flow
);
3586 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3587 map
= isl_map_read_from_str(ctx
, str
);
3588 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3590 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3591 map
= isl_map_read_from_str(ctx
, str
);
3592 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3594 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3595 map
= isl_map_read_from_str(ctx
, str
);
3596 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3598 flow
= isl_access_info_compute_flow(ai
);
3599 space
= isl_space_alloc(ctx
, 0, 3, 3);
3600 mm
.must
= isl_map_empty(isl_space_copy(space
));
3601 mm
.may
= isl_map_empty(space
);
3603 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3605 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3606 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3607 assert(map_is_equal(mm
.may
, str
));
3608 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3609 assert(map_is_equal(mm
.must
, str
));
3611 isl_map_free(mm
.must
);
3612 isl_map_free(mm
.may
);
3613 isl_flow_free(flow
);
3618 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3619 map
= isl_map_read_from_str(ctx
, str
);
3620 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3622 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3623 map
= isl_map_read_from_str(ctx
, str
);
3624 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3626 flow
= isl_access_info_compute_flow(ai
);
3627 space
= isl_space_alloc(ctx
, 0, 5, 5);
3628 mm
.must
= isl_map_empty(isl_space_copy(space
));
3629 mm
.may
= isl_map_empty(space
);
3631 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3633 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3634 assert(map_is_equal(mm
.must
, str
));
3635 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3636 assert(map_is_equal(mm
.may
, str
));
3638 isl_map_free(mm
.must
);
3639 isl_map_free(mm
.may
);
3640 isl_flow_free(flow
);
3645 /* Check that the dependence analysis proceeds without errors.
3646 * Earlier versions of isl would break down during the analysis
3647 * due to the use of the wrong spaces.
3649 static int test_flow(isl_ctx
*ctx
)
3652 isl_union_map
*access
, *schedule
;
3653 isl_union_map
*must_dep
, *may_dep
;
3656 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3657 access
= isl_union_map_read_from_str(ctx
, str
);
3658 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3659 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3660 "S2[] -> [1,0,0,0]; "
3661 "S3[] -> [-1,0,0,0] }";
3662 schedule
= isl_union_map_read_from_str(ctx
, str
);
3663 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3664 isl_union_map_copy(access
), schedule
,
3665 &must_dep
, &may_dep
, NULL
, NULL
);
3666 isl_union_map_free(may_dep
);
3667 isl_union_map_free(must_dep
);
3676 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3677 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3678 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3679 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3680 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3681 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3682 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3683 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3684 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3687 int test_sv(isl_ctx
*ctx
)
3689 isl_union_map
*umap
;
3693 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3694 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3695 sv
= isl_union_map_is_single_valued(umap
);
3696 isl_union_map_free(umap
);
3699 if (sv_tests
[i
].sv
&& !sv
)
3700 isl_die(ctx
, isl_error_internal
,
3701 "map not detected as single valued", return -1);
3702 if (!sv_tests
[i
].sv
&& sv
)
3703 isl_die(ctx
, isl_error_internal
,
3704 "map detected as single valued", return -1);
3713 } bijective_tests
[] = {
3714 { "[N,M]->{[i,j] -> [i]}", 0 },
3715 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3716 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3717 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3718 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3719 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3720 { "[N,M]->{[i,j] -> []}", 0 },
3721 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3722 { "[N,M]->{[i,j] -> [2i]}", 0 },
3723 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3724 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3725 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3726 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3729 static int test_bijective(struct isl_ctx
*ctx
)
3735 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3736 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3737 bijective
= isl_map_is_bijective(map
);
3741 if (bijective_tests
[i
].bijective
&& !bijective
)
3742 isl_die(ctx
, isl_error_internal
,
3743 "map not detected as bijective", return -1);
3744 if (!bijective_tests
[i
].bijective
&& bijective
)
3745 isl_die(ctx
, isl_error_internal
,
3746 "map detected as bijective", return -1);
3752 /* Inputs for isl_pw_qpolynomial_gist tests.
3753 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3759 } pwqp_gist_tests
[] = {
3760 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3761 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3762 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3763 "{ [i] -> -1/2 + 1/2 * i }" },
3764 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3765 { "{ [i] -> i^2 : i > 0; [i] -> i^2 : i < 0 }", "{ [i] : i != 0 }",
3769 /* Perform some basic isl_pw_qpolynomial_gist tests.
3771 static isl_stat
test_pwqp_gist(isl_ctx
*ctx
)
3776 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3779 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3780 str
= pwqp_gist_tests
[i
].pwqp
;
3781 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3782 str
= pwqp_gist_tests
[i
].set
;
3783 set
= isl_set_read_from_str(ctx
, str
);
3784 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3785 str
= pwqp_gist_tests
[i
].gist
;
3786 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3787 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3788 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3789 isl_pw_qpolynomial_free(pwqp1
);
3792 return isl_stat_error
;
3794 isl_die(ctx
, isl_error_unknown
,
3795 "unexpected result", return isl_stat_error
);
3801 /* Perform a basic isl_pw_qpolynomial_max test.
3803 static isl_stat
test_pwqp_max(isl_ctx
*ctx
)
3806 isl_pw_qpolynomial
*pwqp
;
3810 str
= "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3811 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3812 v
= isl_pw_qpolynomial_max(pwqp
);
3813 ok
= isl_val_cmp_si(v
, -1) == 0;
3817 return isl_stat_error
;
3819 isl_die(ctx
, isl_error_unknown
, "unexpected maximum",
3820 return isl_stat_error
);
3825 static int test_pwqp(struct isl_ctx
*ctx
)
3829 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3832 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3833 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3835 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3838 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3839 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3841 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3843 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3845 isl_pw_qpolynomial_free(pwqp1
);
3847 if (test_pwqp_gist(ctx
) < 0)
3850 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3851 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3852 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3853 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3855 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3857 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3859 isl_pw_qpolynomial_free(pwqp1
);
3861 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3862 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3863 str
= "{ [x] -> x }";
3864 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3866 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3868 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3870 isl_pw_qpolynomial_free(pwqp1
);
3872 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3873 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3874 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3875 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3876 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3877 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3878 isl_pw_qpolynomial_free(pwqp1
);
3880 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3881 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3882 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3883 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3884 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3885 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3886 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3887 isl_pw_qpolynomial_free(pwqp1
);
3888 isl_pw_qpolynomial_free(pwqp2
);
3892 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3894 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3895 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3896 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3897 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3898 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3900 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3901 isl_pw_qpolynomial_free(pwqp1
);
3902 isl_pw_qpolynomial_free(pwqp2
);
3906 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3908 if (test_pwqp_max(ctx
) < 0)
3914 static int test_split_periods(isl_ctx
*ctx
)
3917 isl_pw_qpolynomial
*pwqp
;
3919 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3920 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3921 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3922 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3924 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3926 isl_pw_qpolynomial_free(pwqp
);
3934 static int test_union(isl_ctx
*ctx
)
3937 isl_union_set
*uset1
, *uset2
;
3938 isl_union_map
*umap1
, *umap2
;
3941 str
= "{ [i] : 0 <= i <= 1 }";
3942 uset1
= isl_union_set_read_from_str(ctx
, str
);
3943 str
= "{ [1] -> [0] }";
3944 umap1
= isl_union_map_read_from_str(ctx
, str
);
3946 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3947 equal
= isl_union_map_is_equal(umap1
, umap2
);
3949 isl_union_map_free(umap1
);
3950 isl_union_map_free(umap2
);
3955 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3958 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3959 umap1
= isl_union_map_read_from_str(ctx
, str
);
3960 str
= "{ A[i]; B[i] }";
3961 uset1
= isl_union_set_read_from_str(ctx
, str
);
3963 uset2
= isl_union_map_domain(umap1
);
3965 equal
= isl_union_set_is_equal(uset1
, uset2
);
3967 isl_union_set_free(uset1
);
3968 isl_union_set_free(uset2
);
3973 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3979 /* Inputs for basic isl_pw_qpolynomial_bound tests.
3980 * "type" is the type of bound that should be computed.
3981 * "poly" is a string representation of the input.
3982 * "bound" is a string representation of the expected result.
3983 * "tight" is set if the result is expected to be tight.
3991 /* Check that computing a bound of a non-zero polynomial
3992 * over an unbounded domain does not produce a rational value.
3993 * In particular, check that the upper bound is infinity.
3995 { 0, isl_fold_max
, "{ [m, n] -> -m * n }", "{ max(infty) }" },
3996 { 1, isl_fold_max
, "{ [[a, b, c, d] -> [e]] -> 0 }",
3997 "{ [a, b, c, d] -> max(0) }" },
3998 { 1, isl_fold_max
, "{ [[x] -> [x]] -> 1 : exists a : x = 2 a }",
3999 "{ [x] -> max(1) : x mod 2 = 0 }" },
4000 { 1, isl_fold_min
, "{ [x=5:10] -> (x + 2)^2 }", "{ min(49) }" },
4001 { 1, isl_fold_max
, "{ [0:10] -> 1 }", "{ max(1) }" },
4002 { 1, isl_fold_max
, "{ [[m] -> [0:m]] -> m^2 }",
4003 "{ [m] -> max(m^2) : m >= 0 }" },
4006 /* Check that the bound computation can handle differences
4007 * in domain dimension names of the input polynomial and its domain.
4009 static isl_stat
test_bound_space(isl_ctx
*ctx
)
4013 isl_pw_qpolynomial
*pwqp
;
4014 isl_pw_qpolynomial_fold
*pwf
;
4016 str
= "{ [[c] -> [c]] }";
4017 set
= isl_set_read_from_str(ctx
, str
);
4018 str
= "{ [[a] -> [b]] -> 1 }";
4019 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4020 pwqp
= isl_pw_qpolynomial_intersect_domain(pwqp
, set
);
4021 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
4022 isl_pw_qpolynomial_fold_free(pwf
);
4024 return isl_stat_non_null(pwf
);
4027 /* Perform basic isl_pw_qpolynomial_bound tests.
4029 static int test_bound(isl_ctx
*ctx
)
4033 if (test_bound_space(ctx
) < 0)
4036 for (i
= 0; i
< ARRAY_SIZE(bound_tests
); ++i
) {
4039 isl_bool equal
, tight
;
4040 isl_pw_qpolynomial
*pwqp
;
4041 isl_pw_qpolynomial_fold
*pwf1
, *pwf2
;
4043 str
= bound_tests
[i
].poly
;
4044 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
4045 type
= bound_tests
[i
].type
;
4046 pwf1
= isl_pw_qpolynomial_bound(pwqp
, type
, &tight
);
4047 str
= bound_tests
[i
].bound
;
4048 pwf2
= isl_pw_qpolynomial_fold_read_from_str(ctx
, str
);
4049 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf1
, pwf2
);
4050 isl_pw_qpolynomial_fold_free(pwf2
);
4051 isl_pw_qpolynomial_fold_free(pwf1
);
4055 isl_die(ctx
, isl_error_unknown
,
4056 "incorrect bound result", return -1);
4057 if (bound_tests
[i
].tight
&& !tight
)
4058 isl_die(ctx
, isl_error_unknown
,
4059 "bound unexpectedly not tight", return -1);
4065 /* isl_set is defined to isl_map internally, so the corresponding elements
4066 * are isl_basic_map objects.
4070 #define EL_BASE basic_map
4071 #define SET_BASE set
4072 #include "isl_test_list_templ.c"
4076 #define EL_BASE basic_set
4077 #define SET_BASE union_set
4078 #include "isl_test_list_templ.c"
4083 #define SET_BASE union_set
4084 #include "isl_test_list_templ.c"
4088 #define EL_BASE basic_map
4089 #define SET_BASE map
4090 #include "isl_test_list_templ.c"
4095 #define SET_BASE union_map
4096 #include "isl_test_list_templ.c"
4098 /* Check that the conversion from isl objects to lists works as expected.
4100 static int test_get_list(isl_ctx
*ctx
)
4102 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
4104 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
4106 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
4108 if (test_get_list_basic_map_from_map(ctx
,
4109 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
4111 if (test_get_list_map_from_union_map(ctx
,
4112 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
4118 static int test_lift(isl_ctx
*ctx
)
4121 isl_basic_map
*bmap
;
4122 isl_basic_set
*bset
;
4124 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
4125 bset
= isl_basic_set_read_from_str(ctx
, str
);
4126 bset
= isl_basic_set_lift(bset
);
4127 bmap
= isl_basic_map_from_range(bset
);
4128 bset
= isl_basic_map_domain(bmap
);
4129 isl_basic_set_free(bset
);
4134 /* Check that isl_set_is_subset is not confused by identical
4135 * integer divisions.
4136 * The call to isl_set_normalize ensures that the equality constraints
4137 * a = b = 0 are discovered, turning e0 and e1 into identical
4138 * integer divisions. Any further simplification would remove
4139 * the duplicate integer divisions.
4141 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
4145 isl_set
*set1
, *set2
;
4147 str
= "{ [a, b, c, d] : "
4148 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4149 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4150 "e3 = floor((-d + 4*floor((d)/4))/10): "
4151 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4152 "b >= 0 and a <= 0 and b <= a) }";
4153 set1
= isl_set_read_from_str(ctx
, str
);
4154 set2
= isl_set_read_from_str(ctx
, str
);
4155 set2
= isl_set_normalize(set2
);
4157 is_subset
= isl_set_is_subset(set1
, set2
);
4163 return isl_stat_error
;
4165 isl_die(ctx
, isl_error_unknown
,
4166 "set is not considered to be a subset of itself",
4167 return isl_stat_error
);
4176 } subset_tests
[] = {
4178 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4179 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4180 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4182 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4183 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4184 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4185 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4186 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4187 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4188 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4189 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4190 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4191 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4192 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4193 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4194 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4195 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4196 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4197 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4198 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4199 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4200 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4201 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4202 "4e0 <= -57 + i0 + i1)) or "
4203 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4204 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4205 "4e0 >= -61 + i0 + i1)) or "
4206 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4207 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4210 static int test_subset(isl_ctx
*ctx
)
4213 isl_set
*set1
, *set2
;
4216 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
4219 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
4220 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
4221 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
4222 subset
= isl_set_is_subset(set1
, set2
);
4227 if (subset
!= subset_tests
[i
].subset
)
4228 isl_die(ctx
, isl_error_unknown
,
4229 "incorrect subset result", return -1);
4235 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4236 * Older versions of isl would fail on such cases.
4238 static isl_stat
test_subtract_empty(isl_ctx
*ctx
)
4243 s1
= isl_set_read_from_str(ctx
, "{ [0] }");
4244 str
= "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4245 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4246 "33e2 >= -a + 33e0 + 1056e1 and "
4247 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4248 s2
= isl_set_read_from_str(ctx
, str
);
4249 s1
= isl_set_subtract(s1
, s2
);
4252 return isl_stat_non_null(s1
);
4256 const char *minuend
;
4257 const char *subtrahend
;
4258 const char *difference
;
4259 } subtract_domain_tests
[] = {
4260 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4261 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4262 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4265 static int test_subtract(isl_ctx
*ctx
)
4268 isl_union_map
*umap1
, *umap2
;
4269 isl_union_pw_multi_aff
*upma1
, *upma2
;
4270 isl_union_set
*uset
;
4273 if (test_subtract_empty(ctx
) < 0)
4276 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4277 umap1
= isl_union_map_read_from_str(ctx
,
4278 subtract_domain_tests
[i
].minuend
);
4279 uset
= isl_union_set_read_from_str(ctx
,
4280 subtract_domain_tests
[i
].subtrahend
);
4281 umap2
= isl_union_map_read_from_str(ctx
,
4282 subtract_domain_tests
[i
].difference
);
4283 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
4284 equal
= isl_union_map_is_equal(umap1
, umap2
);
4285 isl_union_map_free(umap1
);
4286 isl_union_map_free(umap2
);
4290 isl_die(ctx
, isl_error_unknown
,
4291 "incorrect subtract domain result", return -1);
4294 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4295 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4296 subtract_domain_tests
[i
].minuend
);
4297 uset
= isl_union_set_read_from_str(ctx
,
4298 subtract_domain_tests
[i
].subtrahend
);
4299 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4300 subtract_domain_tests
[i
].difference
);
4301 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
4302 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
4303 isl_union_pw_multi_aff_free(upma1
);
4304 isl_union_pw_multi_aff_free(upma2
);
4308 isl_die(ctx
, isl_error_unknown
,
4309 "incorrect subtract domain result", return -1);
4315 /* Check that intersecting the empty basic set with another basic set
4316 * does not increase the number of constraints. In particular,
4317 * the empty basic set should maintain its canonical representation.
4319 static int test_intersect_1(isl_ctx
*ctx
)
4322 isl_basic_set
*bset1
, *bset2
;
4324 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
4325 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
4326 n1
= isl_basic_set_n_constraint(bset1
);
4327 bset1
= isl_basic_set_intersect(bset1
, bset2
);
4328 n2
= isl_basic_set_n_constraint(bset1
);
4329 isl_basic_set_free(bset1
);
4330 if (n1
< 0 || n2
< 0)
4333 isl_die(ctx
, isl_error_unknown
,
4334 "number of constraints of empty set changed",
4340 /* Check that intersecting a set with itself does not cause
4341 * an explosion in the number of disjuncts.
4343 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
4348 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
4349 for (i
= 0; i
< 100; ++i
)
4350 set
= isl_set_intersect(set
, isl_set_copy(set
));
4353 return isl_stat_error
;
4357 /* Perform some intersection tests.
4359 static int test_intersect(isl_ctx
*ctx
)
4361 if (test_intersect_1(ctx
) < 0)
4363 if (test_intersect_2(ctx
) < 0)
4369 int test_factorize(isl_ctx
*ctx
)
4372 isl_basic_set
*bset
;
4375 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4376 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4377 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4378 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4379 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4380 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4381 "3i5 >= -2i0 - i2 + 3i4 }";
4382 bset
= isl_basic_set_read_from_str(ctx
, str
);
4383 f
= isl_basic_set_factorizer(bset
);
4384 isl_basic_set_free(bset
);
4385 isl_factorizer_free(f
);
4387 isl_die(ctx
, isl_error_unknown
,
4388 "failed to construct factorizer", return -1);
4390 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4391 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4392 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4393 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4394 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4395 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4396 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4397 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4398 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4399 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4400 bset
= isl_basic_set_read_from_str(ctx
, str
);
4401 f
= isl_basic_set_factorizer(bset
);
4402 isl_basic_set_free(bset
);
4403 isl_factorizer_free(f
);
4405 isl_die(ctx
, isl_error_unknown
,
4406 "failed to construct factorizer", return -1);
4411 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
4413 int *injective
= user
;
4415 *injective
= isl_map_is_injective(map
);
4418 if (*injective
< 0 || !*injective
)
4419 return isl_stat_error
;
4424 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
4425 const char *r
, const char *s
, int tilable
, int parallel
)
4429 isl_union_map
*W
, *R
, *S
;
4430 isl_union_map
*empty
;
4431 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
4432 isl_union_map
*validity
, *proximity
, *coincidence
;
4433 isl_union_map
*schedule
;
4434 isl_union_map
*test
;
4435 isl_union_set
*delta
;
4436 isl_union_set
*domain
;
4440 isl_schedule_constraints
*sc
;
4441 isl_schedule
*sched
;
4442 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
4445 D
= isl_union_set_read_from_str(ctx
, d
);
4446 W
= isl_union_map_read_from_str(ctx
, w
);
4447 R
= isl_union_map_read_from_str(ctx
, r
);
4448 S
= isl_union_map_read_from_str(ctx
, s
);
4450 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4451 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4453 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4454 isl_union_map_compute_flow(isl_union_map_copy(R
),
4455 isl_union_map_copy(W
), empty
,
4456 isl_union_map_copy(S
),
4457 &dep_raw
, NULL
, NULL
, NULL
);
4458 isl_union_map_compute_flow(isl_union_map_copy(W
),
4459 isl_union_map_copy(W
),
4460 isl_union_map_copy(R
),
4461 isl_union_map_copy(S
),
4462 &dep_waw
, &dep_war
, NULL
, NULL
);
4464 dep
= isl_union_map_union(dep_waw
, dep_war
);
4465 dep
= isl_union_map_union(dep
, dep_raw
);
4466 validity
= isl_union_map_copy(dep
);
4467 coincidence
= isl_union_map_copy(dep
);
4468 proximity
= isl_union_map_copy(dep
);
4470 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4471 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4472 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4473 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4474 sched
= isl_schedule_constraints_compute_schedule(sc
);
4475 schedule
= isl_schedule_get_map(sched
);
4476 isl_schedule_free(sched
);
4477 isl_union_map_free(W
);
4478 isl_union_map_free(R
);
4479 isl_union_map_free(S
);
4482 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4484 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4485 is_complete
= isl_union_set_is_subset(D
, domain
);
4486 isl_union_set_free(D
);
4487 isl_union_set_free(domain
);
4489 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4490 test
= isl_union_map_apply_range(test
, dep
);
4491 test
= isl_union_map_apply_range(test
, schedule
);
4493 delta
= isl_union_map_deltas(test
);
4494 n
= isl_union_set_n_set(delta
);
4496 isl_union_set_free(delta
);
4503 isl_union_set_free(delta
);
4507 delta_set
= isl_set_from_union_set(delta
);
4509 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4510 for (i
= 0; i
< tilable
; ++i
)
4511 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4512 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4513 isl_set_free(slice
);
4515 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4516 for (i
= 0; i
< parallel
; ++i
)
4517 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4518 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4519 isl_set_free(slice
);
4521 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4522 dim
= isl_set_dim(origin
, isl_dim_set
);
4524 origin
= isl_set_free(origin
);
4525 for (i
= 0; i
< dim
; ++i
)
4526 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4528 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4529 delta_set
= isl_set_lexmin(delta_set
);
4531 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4533 isl_set_free(origin
);
4534 isl_set_free(delta_set
);
4537 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4538 is_injection
< 0 || is_complete
< 0)
4541 isl_die(ctx
, isl_error_unknown
,
4542 "generated schedule incomplete", return -1);
4544 isl_die(ctx
, isl_error_unknown
,
4545 "generated schedule not injective on each statement",
4548 isl_die(ctx
, isl_error_unknown
,
4549 "negative dependences in generated schedule",
4552 isl_die(ctx
, isl_error_unknown
,
4553 "generated schedule not as tilable as expected",
4556 isl_die(ctx
, isl_error_unknown
,
4557 "generated schedule not as parallel as expected",
4563 /* Compute a schedule for the given instance set, validity constraints,
4564 * proximity constraints and context and return a corresponding union map
4567 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4568 const char *domain
, const char *validity
, const char *proximity
,
4569 const char *context
)
4574 isl_union_map
*prox
;
4575 isl_schedule_constraints
*sc
;
4576 isl_schedule
*schedule
;
4577 isl_union_map
*sched
;
4579 con
= isl_set_read_from_str(ctx
, context
);
4580 dom
= isl_union_set_read_from_str(ctx
, domain
);
4581 dep
= isl_union_map_read_from_str(ctx
, validity
);
4582 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4583 sc
= isl_schedule_constraints_on_domain(dom
);
4584 sc
= isl_schedule_constraints_set_context(sc
, con
);
4585 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4586 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4587 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4588 sched
= isl_schedule_get_map(schedule
);
4589 isl_schedule_free(schedule
);
4594 /* Compute a schedule for the given instance set, validity constraints and
4595 * proximity constraints and return a corresponding union map representation.
4597 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4598 const char *domain
, const char *validity
, const char *proximity
)
4600 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4604 /* Check that a schedule can be constructed on the given domain
4605 * with the given validity and proximity constraints.
4607 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4608 const char *validity
, const char *proximity
)
4610 isl_union_map
*sched
;
4612 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4616 isl_union_map_free(sched
);
4620 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4621 const char *validity
, const char *proximity
, const char *expected_sched
)
4623 isl_union_map
*sched1
, *sched2
;
4626 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4627 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4629 equal
= isl_union_map_is_equal(sched1
, sched2
);
4630 isl_union_map_free(sched1
);
4631 isl_union_map_free(sched2
);
4636 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4642 /* Check that the schedule map is properly padded, i.e., that the range
4643 * lives in a single space.
4645 static int test_padded_schedule(isl_ctx
*ctx
)
4649 isl_union_map
*validity
, *proximity
;
4650 isl_schedule_constraints
*sc
;
4651 isl_schedule
*sched
;
4652 isl_union_map
*umap
;
4653 isl_union_set
*range
;
4656 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4657 D
= isl_union_set_read_from_str(ctx
, str
);
4658 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4659 proximity
= isl_union_map_copy(validity
);
4660 sc
= isl_schedule_constraints_on_domain(D
);
4661 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4662 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4663 sched
= isl_schedule_constraints_compute_schedule(sc
);
4664 umap
= isl_schedule_get_map(sched
);
4665 isl_schedule_free(sched
);
4666 range
= isl_union_map_range(umap
);
4667 set
= isl_set_from_union_set(range
);
4676 /* Check that conditional validity constraints are also taken into
4677 * account across bands.
4678 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4679 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4680 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4681 * is enforced by the rest of the schedule.
4683 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4686 isl_union_set
*domain
;
4687 isl_union_map
*validity
, *proximity
, *condition
;
4688 isl_union_map
*sink
, *source
, *dep
;
4689 isl_schedule_constraints
*sc
;
4690 isl_schedule
*schedule
;
4691 isl_union_access_info
*access
;
4692 isl_union_flow
*flow
;
4695 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4696 "A[k] : k >= 1 and k <= -1 + n; "
4697 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4698 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4699 domain
= isl_union_set_read_from_str(ctx
, str
);
4700 sc
= isl_schedule_constraints_on_domain(domain
);
4701 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4702 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4703 "D[k, i] -> C[1 + k, i] : "
4704 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4705 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4706 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4707 validity
= isl_union_map_read_from_str(ctx
, str
);
4708 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4709 str
= "[n] -> { C[k, i] -> D[k, i] : "
4710 "0 <= i <= -1 + k and k <= -1 + n }";
4711 proximity
= isl_union_map_read_from_str(ctx
, str
);
4712 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4713 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4714 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4715 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4716 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4717 condition
= isl_union_map_read_from_str(ctx
, str
);
4718 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4719 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4720 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4721 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4722 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4723 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4724 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4725 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4726 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4727 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4728 validity
= isl_union_map_read_from_str(ctx
, str
);
4729 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4731 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4732 str
= "{ D[2,0] -> [] }";
4733 sink
= isl_union_map_read_from_str(ctx
, str
);
4734 access
= isl_union_access_info_from_sink(sink
);
4735 str
= "{ C[2,1] -> [] }";
4736 source
= isl_union_map_read_from_str(ctx
, str
);
4737 access
= isl_union_access_info_set_must_source(access
, source
);
4738 access
= isl_union_access_info_set_schedule(access
, schedule
);
4739 flow
= isl_union_access_info_compute_flow(access
);
4740 dep
= isl_union_flow_get_must_dependence(flow
);
4741 isl_union_flow_free(flow
);
4742 empty
= isl_union_map_is_empty(dep
);
4743 isl_union_map_free(dep
);
4748 isl_die(ctx
, isl_error_unknown
,
4749 "conditional validity not respected", return -1);
4754 /* Check that the test for violated conditional validity constraints
4755 * is not confused by domain compression.
4756 * In particular, earlier versions of isl would apply
4757 * a schedule on the compressed domains to the original domains,
4758 * resulting in a failure to detect that the default schedule
4759 * violates the conditional validity constraints.
4761 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4765 isl_union_set
*domain
;
4766 isl_union_map
*validity
, *condition
;
4767 isl_schedule_constraints
*sc
;
4768 isl_schedule
*schedule
;
4769 isl_union_map
*umap
;
4772 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4773 domain
= isl_union_set_read_from_str(ctx
, str
);
4774 sc
= isl_schedule_constraints_on_domain(domain
);
4775 str
= "{ B[1, i] -> A[0, i + 1] }";
4776 condition
= isl_union_map_read_from_str(ctx
, str
);
4777 str
= "{ A[0, i] -> B[1, i - 1] }";
4778 validity
= isl_union_map_read_from_str(ctx
, str
);
4779 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4780 isl_union_map_copy(validity
));
4781 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4782 umap
= isl_schedule_get_map(schedule
);
4783 isl_schedule_free(schedule
);
4784 validity
= isl_union_map_apply_domain(validity
,
4785 isl_union_map_copy(umap
));
4786 validity
= isl_union_map_apply_range(validity
, umap
);
4787 map
= isl_map_from_union_map(validity
);
4788 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4789 map
= isl_map_intersect(map
, ge
);
4790 empty
= isl_map_is_empty(map
);
4796 isl_die(ctx
, isl_error_unknown
,
4797 "conditional validity constraints not satisfied",
4803 /* Input for testing of schedule construction based on
4804 * conditional constraints.
4806 * domain is the iteration domain
4807 * flow are the flow dependences, which determine the validity and
4808 * proximity constraints
4809 * condition are the conditions on the conditional validity constraints
4810 * conditional_validity are the conditional validity constraints
4811 * outer_band_n is the expected number of members in the outer band
4816 const char *condition
;
4817 const char *conditional_validity
;
4819 } live_range_tests
[] = {
4820 /* Contrived example that illustrates that we need to keep
4821 * track of tagged condition dependences and
4822 * tagged conditional validity dependences
4823 * in isl_sched_edge separately.
4824 * In particular, the conditional validity constraints on A
4825 * cannot be satisfied,
4826 * but they can be ignored because there are no corresponding
4827 * condition constraints. However, we do have an additional
4828 * conditional validity constraint that maps to the same
4829 * dependence relation
4830 * as the condition constraint on B. If we did not make a distinction
4831 * between tagged condition and tagged conditional validity
4832 * dependences, then we
4833 * could end up treating this shared dependence as an condition
4834 * constraint on A, forcing a localization of the conditions,
4835 * which is impossible.
4837 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4838 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4839 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4840 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4841 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4842 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4845 /* TACO 2013 Fig. 7 */
4846 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4847 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4848 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4849 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4850 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4851 "0 <= i < n and 0 <= j < n - 1 }",
4852 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4853 "0 <= i < n and 0 <= j < j' < n;"
4854 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4855 "0 <= i < i' < n and 0 <= j,j' < n;"
4856 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4857 "0 <= i,j,j' < n and j < j' }",
4860 /* TACO 2013 Fig. 7, without tags */
4861 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4862 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4863 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4864 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4865 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4866 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4867 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4868 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4871 /* TACO 2013 Fig. 12 */
4872 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4873 "S3[i,3] : 0 <= i <= 1 }",
4874 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4875 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4876 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4877 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4878 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4879 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4880 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4881 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4882 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4883 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4884 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4889 /* Test schedule construction based on conditional constraints.
4890 * In particular, check the number of members in the outer band node
4891 * as an indication of whether tiling is possible or not.
4893 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4896 isl_union_set
*domain
;
4897 isl_union_map
*condition
;
4898 isl_union_map
*flow
;
4899 isl_union_map
*validity
;
4900 isl_schedule_constraints
*sc
;
4901 isl_schedule
*schedule
;
4902 isl_schedule_node
*node
;
4905 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4907 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4910 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4911 domain
= isl_union_set_read_from_str(ctx
,
4912 live_range_tests
[i
].domain
);
4913 flow
= isl_union_map_read_from_str(ctx
,
4914 live_range_tests
[i
].flow
);
4915 condition
= isl_union_map_read_from_str(ctx
,
4916 live_range_tests
[i
].condition
);
4917 validity
= isl_union_map_read_from_str(ctx
,
4918 live_range_tests
[i
].conditional_validity
);
4919 sc
= isl_schedule_constraints_on_domain(domain
);
4920 sc
= isl_schedule_constraints_set_validity(sc
,
4921 isl_union_map_copy(flow
));
4922 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4923 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4924 condition
, validity
);
4925 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4926 node
= isl_schedule_get_root(schedule
);
4928 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4929 node
= isl_schedule_node_first_child(node
);
4930 n_member
= isl_schedule_node_band_n_member(node
);
4931 isl_schedule_node_free(node
);
4932 isl_schedule_free(schedule
);
4934 if (!schedule
|| n_member
< 0)
4936 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4937 isl_die(ctx
, isl_error_unknown
,
4938 "unexpected number of members in outer band",
4944 /* Check that the schedule computed for the given instance set and
4945 * dependence relation strongly satisfies the dependences.
4946 * In particular, check that no instance is scheduled before
4947 * or together with an instance on which it depends.
4948 * Earlier versions of isl would produce a schedule that
4949 * only weakly satisfies the dependences.
4951 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4953 const char *domain
, *dep
;
4954 isl_union_map
*D
, *schedule
;
4958 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4959 "A[i0] : 0 <= i0 <= 1 }";
4960 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4961 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4962 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4963 D
= isl_union_map_read_from_str(ctx
, dep
);
4964 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4965 D
= isl_union_map_apply_range(D
, schedule
);
4966 map
= isl_map_from_union_map(D
);
4967 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4968 map
= isl_map_intersect(map
, ge
);
4969 empty
= isl_map_is_empty(map
);
4975 isl_die(ctx
, isl_error_unknown
,
4976 "dependences not strongly satisfied", return -1);
4981 /* Compute a schedule for input where the instance set constraints
4982 * conflict with the context constraints.
4983 * Earlier versions of isl did not properly handle this situation.
4985 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4987 isl_union_map
*schedule
;
4988 const char *domain
, *context
;
4990 domain
= "[n] -> { A[] : n >= 0 }";
4991 context
= "[n] -> { : n < 0 }";
4992 schedule
= compute_schedule_with_context(ctx
,
4993 domain
, "{}", "{}", context
);
4994 isl_union_map_free(schedule
);
5002 /* Check that a set of schedule constraints that only allow for
5003 * a coalescing schedule still produces a schedule even if the user
5004 * request a non-coalescing schedule. Earlier versions of isl
5005 * would not handle this case correctly.
5007 static int test_coalescing_schedule(isl_ctx
*ctx
)
5009 const char *domain
, *dep
;
5012 isl_schedule_constraints
*sc
;
5013 isl_schedule
*schedule
;
5014 int treat_coalescing
;
5016 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
5017 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
5018 I
= isl_union_set_read_from_str(ctx
, domain
);
5019 D
= isl_union_map_read_from_str(ctx
, dep
);
5020 sc
= isl_schedule_constraints_on_domain(I
);
5021 sc
= isl_schedule_constraints_set_validity(sc
, D
);
5022 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5023 isl_options_set_schedule_treat_coalescing(ctx
, 1);
5024 schedule
= isl_schedule_constraints_compute_schedule(sc
);
5025 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5026 isl_schedule_free(schedule
);
5032 /* Check that the scheduler does not perform any needless
5033 * compound skewing. Earlier versions of isl would compute
5034 * schedules in terms of transformed schedule coefficients and
5035 * would not accurately keep track of the sum of the original
5036 * schedule coefficients. It could then produce the schedule
5037 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
5038 * for the input below instead of the schedule below.
5040 static int test_skewing_schedule(isl_ctx
*ctx
)
5042 const char *D
, *V
, *P
, *S
;
5044 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
5045 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
5046 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
5047 "-1 <= a-i + b-j + c-k <= 1 }";
5049 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
5051 return test_special_schedule(ctx
, D
, V
, P
, S
);
5054 int test_schedule(isl_ctx
*ctx
)
5056 const char *D
, *W
, *R
, *V
, *P
, *S
;
5057 int max_coincidence
;
5058 int treat_coalescing
;
5060 /* Handle resulting schedule with zero bands. */
5061 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
5065 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
5066 W
= "{ S1[t,i] -> a[t,i] }";
5067 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
5068 "S1[t,i] -> a[t-1,i+1] }";
5069 S
= "{ S1[t,i] -> [t,i] }";
5070 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5073 /* Fig. 5 of CC2008 */
5074 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
5076 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
5077 "j >= 2 and j <= -1 + N }";
5078 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
5079 "j >= 2 and j <= -1 + N; "
5080 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
5081 "j >= 2 and j <= -1 + N }";
5082 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5083 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5086 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
5087 W
= "{ S1[i] -> a[i] }";
5088 R
= "{ S2[i] -> a[i+1] }";
5089 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5090 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5093 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
5094 W
= "{ S1[i] -> a[i] }";
5095 R
= "{ S2[i] -> a[9-i] }";
5096 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5097 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5100 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
5101 W
= "{ S1[i] -> a[i] }";
5102 R
= "[N] -> { S2[i] -> a[N-1-i] }";
5103 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5104 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5107 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
5108 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
5109 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
5110 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
5111 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5114 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5115 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
5116 R
= "{ S2[i,j] -> a[i-1,j] }";
5117 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5118 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5121 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5122 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
5123 R
= "{ S2[i,j] -> a[i,j-1] }";
5124 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5125 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5128 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5129 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5130 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5131 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5132 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5133 "S_0[] -> [0, 0, 0] }";
5134 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
5136 ctx
->opt
->schedule_parametric
= 0;
5137 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5139 ctx
->opt
->schedule_parametric
= 1;
5141 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5142 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5143 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5144 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5145 "S4[i] -> a[i,N] }";
5146 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5147 "S4[i] -> [4,i,0] }";
5148 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
5149 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
5150 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5152 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
5154 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5155 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5157 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5159 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5161 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5162 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5165 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5166 " S_2[t] : t >= 0 and t <= -1 + N; "
5167 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5169 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5170 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5171 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5172 "i >= 0 and i <= -1 + N }";
5173 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5174 "i >= 0 and i <= -1 + N; "
5175 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5176 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5177 " S_0[t] -> [0, t, 0] }";
5179 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5181 ctx
->opt
->schedule_parametric
= 0;
5182 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5184 ctx
->opt
->schedule_parametric
= 1;
5186 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5187 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5188 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
5191 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5192 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5193 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5194 "j >= 0 and j <= -1 + N; "
5195 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5196 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5197 "j >= 0 and j <= -1 + N; "
5198 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5199 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5200 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5203 D
= "{ S_0[i] : i >= 0 }";
5204 W
= "{ S_0[i] -> a[i] : i >= 0 }";
5205 R
= "{ S_0[i] -> a[0] : i >= 0 }";
5206 S
= "{ S_0[i] -> [0, i, 0] }";
5207 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5210 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5211 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5212 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5213 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5214 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5217 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5218 "k <= -1 + n and k >= 0 }";
5219 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5220 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5221 "k <= -1 + n and k >= 0; "
5222 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5223 "k <= -1 + n and k >= 0; "
5224 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5225 "k <= -1 + n and k >= 0 }";
5226 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
5227 ctx
->opt
->schedule_outer_coincidence
= 1;
5228 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5230 ctx
->opt
->schedule_outer_coincidence
= 0;
5232 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
5233 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5234 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5235 "Stmt_for_body24[i0, i1, 1, 0]:"
5236 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5237 "Stmt_for_body7[i0, i1, i2]:"
5238 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5241 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
5242 "Stmt_for_body24[1, i1, i2, i3]:"
5243 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5245 "Stmt_for_body24[0, i1, i2, i3] -> "
5246 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5247 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5249 "Stmt_for_body24[0, i1, i2, i3] ->"
5250 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5251 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5252 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5253 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5254 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5255 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5256 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5257 "i1 <= 6 and i1 >= 0;"
5258 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5259 "Stmt_for_body7[i0, i1, i2] -> "
5260 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5261 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5262 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5263 "Stmt_for_body7[i0, i1, i2] -> "
5264 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5265 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5266 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5269 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5270 isl_options_set_schedule_treat_coalescing(ctx
, 0);
5271 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5273 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5275 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5276 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5277 "j >= 1 and j <= 7;"
5278 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5279 "j >= 1 and j <= 8 }";
5281 S
= "{ S_0[i, j] -> [i + j, i] }";
5282 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5283 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5285 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5287 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5288 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5289 "j >= 0 and j <= -1 + i }";
5290 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5291 "i <= -1 + N and j >= 0;"
5292 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5295 S
= "{ S_0[i, j] -> [i, j] }";
5296 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5297 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5299 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5301 /* Test both algorithms on a case with only proximity dependences. */
5302 D
= "{ S[i,j] : 0 <= i <= 10 }";
5304 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5305 S
= "{ S[i, j] -> [j, i] }";
5306 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5307 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5309 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5310 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5313 D
= "{ A[a]; B[] }";
5315 P
= "{ A[a] -> B[] }";
5316 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5319 if (test_padded_schedule(ctx
) < 0)
5322 /* Check that check for progress is not confused by rational
5325 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5326 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5328 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5329 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5331 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5332 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5334 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5336 /* Check that we allow schedule rows that are only non-trivial
5337 * on some full-dimensional domains.
5339 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5340 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5341 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5343 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5344 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5346 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5348 if (test_conditional_schedule_constraints(ctx
) < 0)
5351 if (test_strongly_satisfying_schedule(ctx
) < 0)
5354 if (test_conflicting_context_schedule(ctx
) < 0)
5357 if (test_coalescing_schedule(ctx
) < 0)
5359 if (test_skewing_schedule(ctx
) < 0)
5365 /* Perform scheduling tests using the whole component scheduler.
5367 static int test_schedule_whole(isl_ctx
*ctx
)
5372 whole
= isl_options_get_schedule_whole_component(ctx
);
5373 isl_options_set_schedule_whole_component(ctx
, 1);
5374 r
= test_schedule(ctx
);
5375 isl_options_set_schedule_whole_component(ctx
, whole
);
5380 /* Perform scheduling tests using the incremental scheduler.
5382 static int test_schedule_incremental(isl_ctx
*ctx
)
5387 whole
= isl_options_get_schedule_whole_component(ctx
);
5388 isl_options_set_schedule_whole_component(ctx
, 0);
5389 r
= test_schedule(ctx
);
5390 isl_options_set_schedule_whole_component(ctx
, whole
);
5395 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
5397 isl_union_map
*umap
;
5400 umap
= isl_union_map_read_from_str(ctx
, str
);
5401 test
= isl_union_map_plain_is_injective(umap
);
5402 isl_union_map_free(umap
);
5405 if (test
== injective
)
5408 isl_die(ctx
, isl_error_unknown
,
5409 "map not detected as injective", return -1);
5411 isl_die(ctx
, isl_error_unknown
,
5412 "map detected as injective", return -1);
5415 int test_injective(isl_ctx
*ctx
)
5419 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5421 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
5423 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
5425 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
5427 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5429 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5431 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5433 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5436 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5437 if (test_plain_injective(ctx
, str
, 1))
5439 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5440 if (test_plain_injective(ctx
, str
, 0))
5448 #include "isl_test_plain_equal_templ.c"
5451 #define BASE pw_multi_aff
5452 #include "isl_test_plain_equal_templ.c"
5455 #define BASE union_pw_aff
5456 #include "isl_test_plain_equal_templ.c"
5458 /* Basic tests on isl_union_pw_aff.
5460 * In particular, check that isl_union_pw_aff_aff_on_domain
5461 * aligns the parameters of the input objects and
5462 * that isl_union_pw_aff_param_on_domain_id properly
5463 * introduces the parameter.
5465 static int test_upa(isl_ctx
*ctx
)
5470 isl_union_set
*domain
;
5471 isl_union_pw_aff
*upa
;
5474 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5475 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5476 domain
= isl_union_set_read_from_str(ctx
, str
);
5477 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5478 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5479 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5480 isl_union_pw_aff_free(upa
);
5484 id
= isl_id_alloc(ctx
, "N", NULL
);
5485 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5486 domain
= isl_union_set_read_from_str(ctx
, str
);
5487 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5488 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5489 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5490 isl_union_pw_aff_free(upa
);
5498 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5499 __isl_take isl_aff
*aff2
);
5501 ['+'] = { &isl_aff_add
},
5502 ['-'] = { &isl_aff_sub
},
5503 ['*'] = { &isl_aff_mul
},
5504 ['/'] = { &isl_aff_div
},
5512 } aff_bin_tests
[] = {
5513 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5514 "{ [i] -> [2i] }" },
5515 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5517 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5518 "{ [i] -> [2i] }" },
5519 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5520 "{ [i] -> [2i] }" },
5521 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5522 "{ [i] -> [i/2] }" },
5523 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5525 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5526 "{ [i] -> [NaN] }" },
5527 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5528 "{ [i] -> [NaN] }" },
5529 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5530 "{ [i] -> [NaN] }" },
5531 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5532 "{ [i] -> [NaN] }" },
5533 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5534 "{ [i] -> [NaN] }" },
5535 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5536 "{ [i] -> [NaN] }" },
5537 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5538 "{ [i] -> [NaN] }" },
5539 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5540 "{ [i] -> [NaN] }" },
5541 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5542 "{ [i] -> [NaN] }" },
5543 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5544 "{ [i] -> [NaN] }" },
5545 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5546 "{ [i] -> [NaN] }" },
5547 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5548 "{ [i] -> [NaN] }" },
5549 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5550 "{ [i] -> [NaN] }" },
5553 /* Perform some basic tests of binary operations on isl_aff objects.
5555 static int test_bin_aff(isl_ctx
*ctx
)
5558 isl_aff
*aff1
, *aff2
, *res
;
5559 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5560 __isl_take isl_aff
*aff2
);
5563 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5564 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5565 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5566 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5567 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5568 aff1
= fn(aff1
, aff2
);
5569 if (isl_aff_is_nan(res
))
5570 ok
= isl_aff_is_nan(aff1
);
5572 ok
= isl_aff_plain_is_equal(aff1
, res
);
5578 isl_die(ctx
, isl_error_unknown
,
5579 "unexpected result", return -1);
5586 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5587 __isl_take isl_pw_aff
*pa2
);
5588 } pw_aff_bin_op
[] = {
5589 ['m'] = { &isl_pw_aff_min
},
5590 ['M'] = { &isl_pw_aff_max
},
5593 /* Inputs for binary isl_pw_aff operation tests.
5594 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5595 * defined by pw_aff_bin_op, and "res" is the expected result.
5602 } pw_aff_bin_tests
[] = {
5603 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5605 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5607 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5608 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5609 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5610 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5611 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5612 "{ [i] -> [NaN] }" },
5613 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5614 "{ [i] -> [NaN] }" },
5617 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5619 static int test_bin_pw_aff(isl_ctx
*ctx
)
5623 isl_pw_aff
*pa1
, *pa2
, *res
;
5625 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5626 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5627 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5628 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5629 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5630 if (isl_pw_aff_involves_nan(res
))
5631 ok
= isl_pw_aff_involves_nan(pa1
);
5633 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5634 isl_pw_aff_free(pa1
);
5635 isl_pw_aff_free(res
);
5639 isl_die(ctx
, isl_error_unknown
,
5640 "unexpected result", return -1);
5646 /* Inputs for basic tests of test operations on
5647 * isl_union_pw_multi_aff objects.
5648 * "fn" is the function that is being tested.
5649 * "arg" is a string description of the input.
5650 * "res" is the expected result.
5653 isl_bool (*fn
)(__isl_keep isl_union_pw_multi_aff
*upma1
);
5656 } upma_test_tests
[] = {
5657 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [1] }",
5659 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [NaN]; B[0] -> [1] }",
5661 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [NaN] }",
5663 { &isl_union_pw_multi_aff_involves_nan
,
5664 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5666 { &isl_union_pw_multi_aff_involves_locals
,
5667 "{ A[] -> [0]; B[0] -> [1] }",
5669 { &isl_union_pw_multi_aff_involves_locals
,
5670 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5672 { &isl_union_pw_multi_aff_involves_locals
,
5673 "{ A[] -> [0]; B[x] -> [x // 2] }",
5675 { &isl_union_pw_multi_aff_involves_locals
,
5676 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5680 /* Perform some basic tests of test operations on
5681 * isl_union_pw_multi_aff objects.
5683 static isl_stat
test_upma_test(isl_ctx
*ctx
)
5686 isl_union_pw_multi_aff
*upma
;
5689 for (i
= 0; i
< ARRAY_SIZE(upma_test_tests
); ++i
) {
5692 str
= upma_test_tests
[i
].arg
;
5693 upma
= isl_union_pw_multi_aff_read_from_str(ctx
, str
);
5694 res
= upma_test_tests
[i
].fn(upma
);
5695 isl_union_pw_multi_aff_free(upma
);
5697 return isl_stat_error
;
5698 if (res
!= upma_test_tests
[i
].res
)
5699 isl_die(ctx
, isl_error_unknown
,
5700 "unexpected result", return isl_stat_error
);
5707 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5708 __isl_take isl_union_pw_multi_aff
*upma1
,
5709 __isl_take isl_union_pw_multi_aff
*upma2
);
5713 } upma_bin_tests
[] = {
5714 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5715 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5716 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5717 "{ B[x] -> [2] : x >= 0 }",
5718 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5719 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5720 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5721 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5722 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5723 "D[i] -> B[2] : i >= 5 }" },
5724 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5725 "{ B[x] -> C[2] : x > 0 }",
5726 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5727 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5728 "{ B[x] -> A[2] : x >= 0 }",
5729 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5731 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5732 "{ B[x] -> C[x + 2] }",
5733 "{ D[y] -> B[2y] }",
5736 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5737 "{ [A[x] -> B[x + 1]] -> C[x + 2] }",
5738 "{ D[y] -> B[2y] }",
5741 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5742 "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5743 "{ D[y] -> A[2y] }",
5744 "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5746 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5747 "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5748 "{ D[y] -> A[2y] }",
5749 "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5752 /* Perform some basic tests of binary operations on
5753 * isl_union_pw_multi_aff objects.
5755 static int test_bin_upma(isl_ctx
*ctx
)
5758 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5761 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5762 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5763 upma_bin_tests
[i
].arg1
);
5764 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5765 upma_bin_tests
[i
].arg2
);
5766 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5767 upma_bin_tests
[i
].res
);
5768 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5769 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5770 isl_union_pw_multi_aff_free(upma1
);
5771 isl_union_pw_multi_aff_free(res
);
5775 isl_die(ctx
, isl_error_unknown
,
5776 "unexpected result", return -1);
5783 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5784 __isl_take isl_union_pw_multi_aff
*upma1
,
5785 __isl_take isl_union_pw_multi_aff
*upma2
);
5788 } upma_bin_fail_tests
[] = {
5789 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5790 "{ B[x] -> C[2] : x >= 0 }" },
5793 /* Perform some basic tests of binary operations on
5794 * isl_union_pw_multi_aff objects that are expected to fail.
5796 static int test_bin_upma_fail(isl_ctx
*ctx
)
5799 isl_union_pw_multi_aff
*upma1
, *upma2
;
5802 on_error
= isl_options_get_on_error(ctx
);
5803 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5804 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5805 for (i
= 0; i
< n
; ++i
) {
5806 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5807 upma_bin_fail_tests
[i
].arg1
);
5808 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5809 upma_bin_fail_tests
[i
].arg2
);
5810 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5811 isl_union_pw_multi_aff_free(upma1
);
5815 isl_options_set_on_error(ctx
, on_error
);
5817 isl_die(ctx
, isl_error_unknown
,
5818 "operation not expected to succeed", return -1);
5823 /* Inputs for basic tests of binary operations on
5824 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5825 * "fn" is the function that is being tested.
5826 * "arg1" and "arg2" are string descriptions of the inputs.
5827 * "res" is a string description of the expected result.
5830 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5831 __isl_take isl_union_pw_multi_aff
*upma
,
5832 __isl_take isl_union_set
*uset
);
5836 } upma_uset_tests
[] = {
5837 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5838 "{ A[i] -> B[i] }", "{ B[0] }",
5840 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain
,
5841 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5842 "{ [A[1] -> B[1]] -> C[2] }" },
5843 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5844 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5845 "{ [A[0] -> B[0]] -> C[1] }" },
5846 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5847 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5848 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5849 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5850 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5851 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5852 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5853 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5855 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5858 /* Perform some basic tests of binary operations on
5859 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5861 static isl_stat
test_upma_uset(isl_ctx
*ctx
)
5865 isl_union_pw_multi_aff
*upma
, *res
;
5866 isl_union_set
*uset
;
5868 for (i
= 0; i
< ARRAY_SIZE(upma_uset_tests
); ++i
) {
5869 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5870 upma_uset_tests
[i
].arg1
);
5871 uset
= isl_union_set_read_from_str(ctx
,
5872 upma_uset_tests
[i
].arg2
);
5873 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5874 upma_uset_tests
[i
].res
);
5875 upma
= upma_uset_tests
[i
].fn(upma
, uset
);
5876 ok
= isl_union_pw_multi_aff_plain_is_equal(upma
, res
);
5877 isl_union_pw_multi_aff_free(upma
);
5878 isl_union_pw_multi_aff_free(res
);
5880 return isl_stat_error
;
5882 isl_die(ctx
, isl_error_unknown
,
5883 "unexpected result", return isl_stat_error
);
5889 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5890 * "fn" is the function that is tested.
5891 * "arg" is a string description of the input.
5892 * "res" is a string description of the expected result.
5895 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5898 } mpa_un_tests
[] = {
5899 { &isl_multi_pw_aff_range_factor_domain
,
5900 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5901 "{ A[x] -> B[(1 : x >= 5)] }" },
5902 { &isl_multi_pw_aff_range_factor_range
,
5903 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5904 "{ A[y] -> C[(2 : y <= 10)] }" },
5905 { &isl_multi_pw_aff_range_factor_domain
,
5906 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5907 "{ A[x] -> B[(1 : x >= 5)] }" },
5908 { &isl_multi_pw_aff_range_factor_range
,
5909 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5910 "{ A[y] -> C[] }" },
5911 { &isl_multi_pw_aff_range_factor_domain
,
5912 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5913 "{ A[x] -> B[] }" },
5914 { &isl_multi_pw_aff_range_factor_range
,
5915 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5916 "{ A[y] -> C[(2 : y <= 10)] }" },
5917 { &isl_multi_pw_aff_range_factor_domain
,
5918 "{ A[x] -> [B[] -> C[]] }",
5919 "{ A[x] -> B[] }" },
5920 { &isl_multi_pw_aff_range_factor_range
,
5921 "{ A[x] -> [B[] -> C[]] }",
5922 "{ A[y] -> C[] }" },
5923 { &isl_multi_pw_aff_factor_range
,
5926 { &isl_multi_pw_aff_range_factor_domain
,
5927 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5928 "{ A[x] -> B[] : x >= 0 }" },
5929 { &isl_multi_pw_aff_range_factor_range
,
5930 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5931 "{ A[y] -> C[] : y >= 0 }" },
5932 { &isl_multi_pw_aff_factor_range
,
5933 "[N] -> { [B[] -> C[]] : N >= 0 }",
5934 "[N] -> { C[] : N >= 0 }" },
5937 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5939 static int test_un_mpa(isl_ctx
*ctx
)
5943 isl_multi_pw_aff
*mpa
, *res
;
5945 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5946 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5947 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5948 mpa
= mpa_un_tests
[i
].fn(mpa
);
5949 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5950 isl_multi_pw_aff_free(mpa
);
5951 isl_multi_pw_aff_free(res
);
5955 isl_die(ctx
, isl_error_unknown
,
5956 "unexpected result", return -1);
5962 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5963 * "fn" is the function that is tested.
5964 * "arg1" and "arg2" are string descriptions of the inputs.
5965 * "res" is a string description of the expected result.
5968 __isl_give isl_multi_pw_aff
*(*fn
)(
5969 __isl_take isl_multi_pw_aff
*mpa1
,
5970 __isl_take isl_multi_pw_aff
*mpa2
);
5974 } mpa_bin_tests
[] = {
5975 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5977 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5978 "{ A[x] -> [(x : x <= 10)] }",
5979 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5980 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5981 "{ A[x] -> [] : x <= 10 }",
5982 "{ A[x] -> [] : 5 <= x <= 10 }" },
5983 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5984 "[N] -> { A[x] -> [] : x <= N }",
5985 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5986 { &isl_multi_pw_aff_add
,
5987 "[N] -> { A[x] -> [] : x <= N }",
5988 "{ A[x] -> [] : x >= 5 }",
5989 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5990 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5991 "{ A[y] -> C[(2 : y <= 10)] }",
5992 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5993 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5994 "{ A[y] -> C[2] : y <= 10 }",
5995 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5996 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5997 "[N] -> { A[y] -> C[2] : y <= N }",
5998 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5999 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
6000 "{ A[y] -> C[2] : y <= 10 }",
6001 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
6002 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6003 "{ A[] -> [B[1] -> C[2]] }" },
6004 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6005 "{ A[] -> [B[] -> C[]] }" },
6006 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6007 "{ A[y] -> C[] : y <= 10 }",
6008 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
6009 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
6010 "{ A[x] -> B[(1 : x >= 5)] }",
6011 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
6012 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6013 "{ A[y] -> C[(2 : y <= 10)] }",
6014 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
6015 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6016 "{ A[y] -> C[] : y <= 10 }",
6017 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
6018 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
6019 "{ A[x] -> B[(1 : x >= 5)] }",
6020 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
6021 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
6022 "[N] -> { A[y] -> C[] : y <= N }",
6023 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
6024 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
6025 "{ A[x] -> B[(1 : x >= 5)] }",
6026 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
6027 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
6028 "{ A[y] -> C[] : y <= 10 }",
6029 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
6030 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
6031 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
6032 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
6033 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
6034 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6035 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
6036 "{ A[a,b] -> C[b + 2a] }" },
6037 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6038 "{ B[i,j] -> C[i + 2j] }",
6039 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6040 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
6041 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6042 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
6043 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6044 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
6045 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6046 "{ B[i,j] -> C[] }",
6047 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6048 "{ A[a,b] -> C[] }" },
6049 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6050 "{ B[i,j] -> C[] : i > j }",
6051 "{ A[a,b] -> B[b,a] }",
6052 "{ A[a,b] -> C[] : b > a }" },
6053 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6054 "{ B[i,j] -> C[] : j > 5 }",
6055 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6056 "{ A[a,b] -> C[] : b > a > 5 }" },
6057 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6058 "[N] -> { B[i,j] -> C[] : j > N }",
6059 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
6060 "[N] -> { A[a,b] -> C[] : b > a > N }" },
6061 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
6062 "[M,N] -> { B[] -> C[] : N > 5 }",
6063 "[M,N] -> { A[] -> B[] : M > N }",
6064 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
6067 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
6069 static int test_bin_mpa(isl_ctx
*ctx
)
6073 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
6075 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
6076 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
6077 mpa_bin_tests
[i
].arg1
);
6078 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
6079 mpa_bin_tests
[i
].arg2
);
6080 res
= isl_multi_pw_aff_read_from_str(ctx
,
6081 mpa_bin_tests
[i
].res
);
6082 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
6083 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
6084 isl_multi_pw_aff_free(mpa1
);
6085 isl_multi_pw_aff_free(res
);
6089 isl_die(ctx
, isl_error_unknown
,
6090 "unexpected result", return -1);
6096 /* Inputs for basic tests of unary operations on
6097 * isl_multi_union_pw_aff objects.
6098 * "fn" is the function that is tested.
6099 * "arg" is a string description of the input.
6100 * "res" is a string description of the expected result.
6103 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6104 __isl_take isl_multi_union_pw_aff
*mupa
);
6107 } mupa_un_tests
[] = {
6108 { &isl_multi_union_pw_aff_factor_range
,
6109 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
6110 "C[{ A[] -> [2] }]" },
6111 { &isl_multi_union_pw_aff_factor_range
,
6112 "[B[] -> C[{ A[] -> [2] }]]",
6113 "C[{ A[] -> [2] }]" },
6114 { &isl_multi_union_pw_aff_factor_range
,
6115 "[B[{ A[] -> [1] }] -> C[]]",
6117 { &isl_multi_union_pw_aff_factor_range
,
6120 { &isl_multi_union_pw_aff_factor_range
,
6121 "([B[] -> C[]] : { A[x] : x >= 0 })",
6122 "(C[] : { A[x] : x >= 0 })" },
6123 { &isl_multi_union_pw_aff_factor_range
,
6124 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
6125 "[N] -> (C[] : { A[x] : x <= N })" },
6126 { &isl_multi_union_pw_aff_factor_range
,
6127 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
6128 "[N] -> (C[] : { : N >= 0 })" },
6131 /* Perform some basic tests of unary operations on
6132 * isl_multi_union_pw_aff objects.
6134 static int test_un_mupa(isl_ctx
*ctx
)
6138 isl_multi_union_pw_aff
*mupa
, *res
;
6140 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
6141 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6142 mupa_un_tests
[i
].arg
);
6143 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6144 mupa_un_tests
[i
].res
);
6145 mupa
= mupa_un_tests
[i
].fn(mupa
);
6146 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6147 isl_multi_union_pw_aff_free(mupa
);
6148 isl_multi_union_pw_aff_free(res
);
6152 isl_die(ctx
, isl_error_unknown
,
6153 "unexpected result", return -1);
6159 /* Inputs for basic tests of binary operations on
6160 * isl_multi_union_pw_aff objects.
6161 * "fn" is the function that is tested.
6162 * "arg1" and "arg2" are string descriptions of the inputs.
6163 * "res" is a string description of the expected result.
6166 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6167 __isl_take isl_multi_union_pw_aff
*mupa1
,
6168 __isl_take isl_multi_union_pw_aff
*mupa2
);
6172 } mupa_bin_tests
[] = {
6173 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6174 "[{ A[] -> [3] }]" },
6175 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6176 "[{ A[] -> [-1] }]" },
6177 { &isl_multi_union_pw_aff_add
,
6178 "[{ A[] -> [1]; B[] -> [4] }]",
6179 "[{ A[] -> [2]; C[] -> [5] }]",
6180 "[{ A[] -> [3] }]" },
6181 { &isl_multi_union_pw_aff_union_add
,
6182 "[{ A[] -> [1]; B[] -> [4] }]",
6183 "[{ A[] -> [2]; C[] -> [5] }]",
6184 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6185 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6186 "[{ A[x] -> [(x)] : x <= 10 }]",
6187 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6188 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6189 "([] : { A[x] : x <= 10 })",
6190 "([] : { A[x] : 5 <= x <= 10 })" },
6191 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6192 "[N] -> ([] : { A[x] : x <= N })",
6193 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6194 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
6195 "([] : { A[x] : x <= 10 })",
6196 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6197 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6198 "[{ A[x] -> [(x)] : x <= 10 }]",
6199 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6200 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6201 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
6202 "([] : { A[x] : x <= 10 })",
6203 "([] : { A[x] })" },
6204 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
6205 "[N] -> ([] : { A[x] : x >= N })",
6206 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6207 { &isl_multi_union_pw_aff_union_add
,
6208 "[N] -> ([] : { A[] : N >= 0})",
6209 "[N] -> ([] : { A[] : N <= 0})",
6210 "[N] -> ([] : { A[] })" },
6211 { &isl_multi_union_pw_aff_union_add
,
6212 "[N] -> ([] : { A[] })",
6213 "[N] -> ([] : { : })",
6214 "[N] -> ([] : { : })" },
6215 { &isl_multi_union_pw_aff_union_add
,
6216 "[N] -> ([] : { : })",
6217 "[N] -> ([] : { A[] })",
6218 "[N] -> ([] : { : })" },
6219 { &isl_multi_union_pw_aff_union_add
,
6220 "[N] -> ([] : { : N >= 0})",
6221 "[N] -> ([] : { : N <= 0})",
6222 "[N] -> ([] : { : })" },
6223 { &isl_multi_union_pw_aff_range_product
,
6224 "B[{ A[] -> [1] }]",
6225 "C[{ A[] -> [2] }]",
6226 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6227 { &isl_multi_union_pw_aff_range_product
,
6228 "(B[] : { A[x] : x >= 5 })",
6229 "(C[] : { A[x] : x <= 10 })",
6230 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6231 { &isl_multi_union_pw_aff_range_product
,
6232 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6233 "(C[] : { A[x] : x <= 10 })",
6234 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6235 { &isl_multi_union_pw_aff_range_product
,
6236 "(C[] : { A[x] : x <= 10 })",
6237 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6238 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6239 { &isl_multi_union_pw_aff_range_product
,
6240 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6241 "[N] -> (C[] : { A[x] : x <= N })",
6242 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6243 { &isl_multi_union_pw_aff_range_product
,
6244 "[N] -> (C[] : { A[x] : x <= N })",
6245 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6246 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6247 { &isl_multi_union_pw_aff_range_product
,
6248 "B[{ A[] -> [1]; D[] -> [3] }]",
6249 "C[{ A[] -> [2] }]",
6250 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6251 { &isl_multi_union_pw_aff_range_product
,
6254 "([B[] -> C[]] : { A[x] })" },
6255 { &isl_multi_union_pw_aff_range_product
,
6258 "([B[] -> C[]] : { A[x] })" },
6261 /* Perform some basic tests of binary operations on
6262 * isl_multi_union_pw_aff objects.
6264 static int test_bin_mupa(isl_ctx
*ctx
)
6268 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
6270 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
6271 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
6272 mupa_bin_tests
[i
].arg1
);
6273 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
6274 mupa_bin_tests
[i
].arg2
);
6275 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6276 mupa_bin_tests
[i
].res
);
6277 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
6278 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
6279 isl_multi_union_pw_aff_free(mupa1
);
6280 isl_multi_union_pw_aff_free(res
);
6284 isl_die(ctx
, isl_error_unknown
,
6285 "unexpected result", return -1);
6291 /* Inputs for basic tests of binary operations on
6292 * pairs of isl_multi_union_pw_aff and isl_set objects.
6293 * "fn" is the function that is tested.
6294 * "arg1" and "arg2" are string descriptions of the inputs.
6295 * "res" is a string description of the expected result.
6298 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6299 __isl_take isl_multi_union_pw_aff
*mupa
,
6300 __isl_take isl_set
*set
);
6304 } mupa_set_tests
[] = {
6305 { &isl_multi_union_pw_aff_intersect_range
,
6306 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6307 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6308 { &isl_multi_union_pw_aff_intersect_range
,
6309 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6310 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6311 { &isl_multi_union_pw_aff_intersect_range
,
6312 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6313 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6314 { &isl_multi_union_pw_aff_intersect_range
,
6315 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6316 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6317 { &isl_multi_union_pw_aff_intersect_range
,
6318 "C[]", "{ C[] }", "C[]" },
6319 { &isl_multi_union_pw_aff_intersect_range
,
6320 "[N] -> (C[] : { : N >= 0 })",
6322 "[N] -> (C[] : { : N >= 0 })" },
6323 { &isl_multi_union_pw_aff_intersect_range
,
6324 "(C[] : { A[a,b] })",
6326 "(C[] : { A[a,b] })" },
6327 { &isl_multi_union_pw_aff_intersect_range
,
6328 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6330 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6331 { &isl_multi_union_pw_aff_intersect_range
,
6333 "[N] -> { C[] : N >= 0 }",
6334 "[N] -> (C[] : { : N >= 0 })" },
6335 { &isl_multi_union_pw_aff_intersect_range
,
6336 "(C[] : { A[a,b] })",
6337 "[N] -> { C[] : N >= 0 }",
6338 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6339 { &isl_multi_union_pw_aff_intersect_range
,
6340 "[N] -> (C[] : { : N >= 0 })",
6341 "[N] -> { C[] : N < 1024 }",
6342 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6343 { &isl_multi_union_pw_aff_intersect_params
,
6344 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6345 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6346 { &isl_multi_union_pw_aff_intersect_params
,
6347 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6348 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6349 { &isl_multi_union_pw_aff_intersect_params
,
6350 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6351 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6352 { &isl_multi_union_pw_aff_intersect_params
,
6353 "C[]", "[N] -> { : N >= 0 }",
6354 "[N] -> (C[] : { : N >= 0 })" },
6355 { &isl_multi_union_pw_aff_intersect_params
,
6356 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6357 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6358 { &isl_multi_union_pw_aff_intersect_params
,
6359 "[N] -> (C[] : { A[a,N] })", "{ : }",
6360 "[N] -> (C[] : { A[a,N] })" },
6361 { &isl_multi_union_pw_aff_intersect_params
,
6362 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6363 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6366 /* Perform some basic tests of binary operations on
6367 * pairs of isl_multi_union_pw_aff and isl_set objects.
6369 static int test_mupa_set(isl_ctx
*ctx
)
6373 isl_multi_union_pw_aff
*mupa
, *res
;
6376 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
6377 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6378 mupa_set_tests
[i
].arg1
);
6379 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
6380 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6381 mupa_set_tests
[i
].res
);
6382 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
6383 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6384 isl_multi_union_pw_aff_free(mupa
);
6385 isl_multi_union_pw_aff_free(res
);
6389 isl_die(ctx
, isl_error_unknown
,
6390 "unexpected result", return -1);
6396 /* Inputs for basic tests of binary operations on
6397 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6398 * "fn" is the function that is tested.
6399 * "arg1" and "arg2" are string descriptions of the inputs.
6400 * "res" is a string description of the expected result.
6403 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6404 __isl_take isl_multi_union_pw_aff
*mupa
,
6405 __isl_take isl_union_set
*uset
);
6409 } mupa_uset_tests
[] = {
6410 { &isl_multi_union_pw_aff_intersect_domain
,
6411 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6412 "C[{ B[i,i] -> [3i] }]" },
6413 { &isl_multi_union_pw_aff_intersect_domain
,
6414 "(C[] : { B[i,j] })", "{ B[i,i] }",
6415 "(C[] : { B[i,i] })" },
6416 { &isl_multi_union_pw_aff_intersect_domain
,
6417 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6418 "[N] -> (C[] : { B[N,N] })" },
6419 { &isl_multi_union_pw_aff_intersect_domain
,
6420 "C[]", "{ B[i,i] }",
6421 "(C[] : { B[i,i] })" },
6422 { &isl_multi_union_pw_aff_intersect_domain
,
6423 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6424 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6427 /* Perform some basic tests of binary operations on
6428 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6430 static int test_mupa_uset(isl_ctx
*ctx
)
6434 isl_multi_union_pw_aff
*mupa
, *res
;
6435 isl_union_set
*uset
;
6437 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
6438 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6439 mupa_uset_tests
[i
].arg1
);
6440 uset
= isl_union_set_read_from_str(ctx
,
6441 mupa_uset_tests
[i
].arg2
);
6442 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6443 mupa_uset_tests
[i
].res
);
6444 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
6445 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6446 isl_multi_union_pw_aff_free(mupa
);
6447 isl_multi_union_pw_aff_free(res
);
6451 isl_die(ctx
, isl_error_unknown
,
6452 "unexpected result", return -1);
6458 /* Inputs for basic tests of binary operations on
6459 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6460 * "fn" is the function that is tested.
6461 * "arg1" and "arg2" are string descriptions of the inputs.
6462 * "res" is a string description of the expected result.
6465 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6466 __isl_take isl_multi_union_pw_aff
*mupa
,
6467 __isl_take isl_multi_aff
*ma
);
6471 } mupa_ma_tests
[] = {
6472 { &isl_multi_union_pw_aff_apply_multi_aff
,
6473 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6474 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6475 "{ C[a,b] -> D[b,a] }",
6476 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6477 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6478 { &isl_multi_union_pw_aff_apply_multi_aff
,
6479 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6480 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6481 "{ C[a,b] -> D[b,a] }",
6482 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6483 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6484 { &isl_multi_union_pw_aff_apply_multi_aff
,
6485 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6486 "[N] -> { C[a] -> D[a + N] }",
6487 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6488 { &isl_multi_union_pw_aff_apply_multi_aff
,
6492 { &isl_multi_union_pw_aff_apply_multi_aff
,
6493 "[N] -> (C[] : { : N >= 0 })",
6495 "[N] -> (D[] : { : N >= 0 })" },
6496 { &isl_multi_union_pw_aff_apply_multi_aff
,
6498 "[N] -> { C[] -> D[N] }",
6499 "[N] -> D[{ [N] }]" },
6500 { &isl_multi_union_pw_aff_apply_multi_aff
,
6501 "(C[] : { A[i,j] : i >= j })",
6503 "(D[] : { A[i,j] : i >= j })" },
6504 { &isl_multi_union_pw_aff_apply_multi_aff
,
6505 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6507 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6508 { &isl_multi_union_pw_aff_apply_multi_aff
,
6509 "(C[] : { A[i,j] : i >= j })",
6510 "[N] -> { C[] -> D[N] }",
6511 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6514 /* Perform some basic tests of binary operations on
6515 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6517 static int test_mupa_ma(isl_ctx
*ctx
)
6521 isl_multi_union_pw_aff
*mupa
, *res
;
6524 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6525 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6526 mupa_ma_tests
[i
].arg1
);
6527 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6528 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6529 mupa_ma_tests
[i
].res
);
6530 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6531 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6532 isl_multi_union_pw_aff_free(mupa
);
6533 isl_multi_union_pw_aff_free(res
);
6537 isl_die(ctx
, isl_error_unknown
,
6538 "unexpected result", return -1);
6544 /* Inputs for basic tests of binary operations on
6545 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6546 * "fn" is the function that is tested.
6547 * "arg1" and "arg2" are string descriptions of the inputs.
6548 * "res" is a string description of the expected result.
6551 __isl_give isl_union_pw_aff
*(*fn
)(
6552 __isl_take isl_multi_union_pw_aff
*mupa
,
6553 __isl_take isl_pw_aff
*pa
);
6557 } mupa_pa_tests
[] = {
6558 { &isl_multi_union_pw_aff_apply_pw_aff
,
6559 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6560 "[N] -> { C[a] -> [a + N] }",
6561 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6562 { &isl_multi_union_pw_aff_apply_pw_aff
,
6563 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6564 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6565 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6566 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6567 { &isl_multi_union_pw_aff_apply_pw_aff
,
6569 "[N] -> { C[] -> [N] }",
6571 { &isl_multi_union_pw_aff_apply_pw_aff
,
6573 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6574 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6575 { &isl_multi_union_pw_aff_apply_pw_aff
,
6576 "[N] -> (C[] : { : N >= 0 })",
6577 "[N] -> { C[] -> [N] }",
6578 "[N] -> { [N] : N >= 0 }" },
6579 { &isl_multi_union_pw_aff_apply_pw_aff
,
6580 "[N] -> (C[] : { : N >= 0 })",
6581 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6582 "[N] -> { [N] : N >= 0 }" },
6583 { &isl_multi_union_pw_aff_apply_pw_aff
,
6584 "[N] -> (C[] : { : N >= 0 })",
6586 "[N] -> { [0] : N >= 0 }" },
6587 { &isl_multi_union_pw_aff_apply_pw_aff
,
6588 "(C[] : { A[i,j] : i >= j })",
6589 "[N] -> { C[] -> [N] }",
6590 "[N] -> { A[i,j] -> [N] : i >= j }" },
6591 { &isl_multi_union_pw_aff_apply_pw_aff
,
6592 "(C[] : { A[i,j] : i >= j })",
6593 "[N] -> { C[] -> [N] : N >= 0 }",
6594 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6597 /* Perform some basic tests of binary operations on
6598 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6600 static int test_mupa_pa(isl_ctx
*ctx
)
6604 isl_multi_union_pw_aff
*mupa
;
6605 isl_union_pw_aff
*upa
, *res
;
6608 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6609 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6610 mupa_pa_tests
[i
].arg1
);
6611 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6612 res
= isl_union_pw_aff_read_from_str(ctx
,
6613 mupa_pa_tests
[i
].res
);
6614 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6615 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6616 isl_union_pw_aff_free(upa
);
6617 isl_union_pw_aff_free(res
);
6621 isl_die(ctx
, isl_error_unknown
,
6622 "unexpected result", return -1);
6628 /* Inputs for basic tests of binary operations on
6629 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6630 * "fn" is the function that is tested.
6631 * "arg1" and "arg2" are string descriptions of the inputs.
6632 * "res" is a string description of the expected result.
6635 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6636 __isl_take isl_multi_union_pw_aff
*mupa
,
6637 __isl_take isl_pw_multi_aff
*pma
);
6641 } mupa_pma_tests
[] = {
6642 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6643 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6644 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6645 "{ C[a,b] -> D[b,a] }",
6646 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6647 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6648 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6649 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6650 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6651 "{ C[a,b] -> D[b,a] }",
6652 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6653 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6654 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6655 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6656 "[N] -> { C[a] -> D[a + N] }",
6657 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6658 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6659 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6660 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6661 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6662 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6663 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6664 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6665 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6666 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6667 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6668 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6669 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6670 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6671 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6675 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6676 "[N] -> (C[] : { : N >= 0 })",
6678 "[N] -> (D[] : { : N >= 0 })" },
6679 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6681 "[N] -> { C[] -> D[N] }",
6682 "[N] -> D[{ [N] }]" },
6683 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6684 "(C[] : { A[i,j] : i >= j })",
6686 "(D[] : { A[i,j] : i >= j })" },
6687 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6688 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6690 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6691 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6692 "(C[] : { A[i,j] : i >= j })",
6693 "[N] -> { C[] -> D[N] }",
6694 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6695 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6697 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6698 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6699 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6700 "[N] -> (C[] : { : N >= 0 })",
6701 "[N] -> { C[] -> D[N] }",
6702 "[N] -> D[{ [N] : N >= 0 }]" },
6703 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6704 "[N] -> (C[] : { : N >= 0 })",
6705 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6706 "[N] -> D[{ [N] : N >= 0 }]" },
6707 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6708 "[N] -> (C[] : { : N >= 0 })",
6710 "[N] -> D[{ [0] : N >= 0 }]" },
6711 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6712 "(C[] : { A[i,j] : i >= j })",
6713 "[N] -> { C[] -> D[N] : N >= 0 }",
6714 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6717 /* Perform some basic tests of binary operations on
6718 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6720 static int test_mupa_pma(isl_ctx
*ctx
)
6724 isl_multi_union_pw_aff
*mupa
, *res
;
6725 isl_pw_multi_aff
*pma
;
6727 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6728 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6729 mupa_pma_tests
[i
].arg1
);
6730 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6731 mupa_pma_tests
[i
].arg2
);
6732 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6733 mupa_pma_tests
[i
].res
);
6734 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6735 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6736 isl_multi_union_pw_aff_free(mupa
);
6737 isl_multi_union_pw_aff_free(res
);
6741 isl_die(ctx
, isl_error_unknown
,
6742 "unexpected result", return -1);
6748 /* Inputs for basic tests of binary operations on
6749 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6750 * "fn" is the function that is tested.
6751 * "arg1" and "arg2" are string descriptions of the inputs.
6752 * "res" is a string description of the expected result.
6755 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6756 __isl_take isl_multi_union_pw_aff
*mupa
,
6757 __isl_take isl_union_pw_multi_aff
*upma
);
6761 } mupa_upma_tests
[] = {
6762 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6763 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6764 "C[{ A[a,b] -> [b + 2a] }]" },
6765 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6766 "C[{ B[i,j] -> [i + 2j] }]",
6767 "{ A[a,b] -> B[b,a] : b > a }",
6768 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6769 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6770 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6771 "{ A[a,b] -> B[b,a] : b > a }",
6772 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6773 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6774 "C[{ B[i,j] -> [i + 2j] }]",
6775 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6776 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6777 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6778 "(C[] : { B[a,b] })",
6779 "{ A[a,b] -> B[b,a] }",
6780 "(C[] : { A[a,b] })" },
6781 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6782 "(C[] : { B[a,b] })",
6783 "{ B[a,b] -> A[b,a] }",
6785 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6786 "(C[] : { B[a,b] })",
6787 "{ A[a,b] -> B[b,a] : a > b }",
6788 "(C[] : { A[a,b] : a > b })" },
6789 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6790 "(C[] : { B[a,b] : a > b })",
6791 "{ A[a,b] -> B[b,a] }",
6792 "(C[] : { A[a,b] : b > a })" },
6793 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6794 "[N] -> (C[] : { B[a,b] : a > N })",
6795 "{ A[a,b] -> B[b,a] : a > b }",
6796 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6797 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6798 "(C[] : { B[a,b] : a > b })",
6799 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6800 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6801 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6803 "{ A[a,b] -> B[b,a] }",
6805 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6806 "[N] -> (C[] : { : N >= 0 })",
6807 "{ A[a,b] -> B[b,a] }",
6808 "[N] -> (C[] : { : N >= 0 })" },
6809 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6811 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6812 "[N] -> (C[] : { : N >= 0 })" },
6815 /* Perform some basic tests of binary operations on
6816 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6818 static int test_mupa_upma(isl_ctx
*ctx
)
6822 isl_multi_union_pw_aff
*mupa
, *res
;
6823 isl_union_pw_multi_aff
*upma
;
6825 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6826 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6827 mupa_upma_tests
[i
].arg1
);
6828 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6829 mupa_upma_tests
[i
].arg2
);
6830 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6831 mupa_upma_tests
[i
].res
);
6832 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6833 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6834 isl_multi_union_pw_aff_free(mupa
);
6835 isl_multi_union_pw_aff_free(res
);
6839 isl_die(ctx
, isl_error_unknown
,
6840 "unexpected result", return -1);
6846 /* Check that the input tuple of an isl_aff can be set properly.
6848 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6854 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6855 id
= isl_id_alloc(ctx
, "A", NULL
);
6856 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6857 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6860 return isl_stat_error
;
6865 /* Check that affine expressions get normalized on addition/subtraction.
6866 * In particular, check that (final) unused integer divisions get removed
6867 * such that an expression derived from expressions with integer divisions
6868 * is found to be obviously equal to one that is created directly.
6870 static isl_stat
test_aff_normalize(isl_ctx
*ctx
)
6872 isl_aff
*aff
, *aff2
;
6875 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x//2] }");
6876 aff2
= isl_aff_read_from_str(ctx
, "{ [x] -> [1 + x//2] }");
6877 aff
= isl_aff_sub(aff2
, aff
);
6878 ok
= aff_check_plain_equal(aff
, "{ [x] -> [1] }");
6884 int test_aff(isl_ctx
*ctx
)
6889 isl_local_space
*ls
;
6894 if (test_upa(ctx
) < 0)
6896 if (test_bin_aff(ctx
) < 0)
6898 if (test_bin_pw_aff(ctx
) < 0)
6900 if (test_upma_test(ctx
) < 0)
6902 if (test_bin_upma(ctx
) < 0)
6904 if (test_bin_upma_fail(ctx
) < 0)
6906 if (test_upma_uset(ctx
) < 0)
6908 if (test_un_mpa(ctx
) < 0)
6910 if (test_bin_mpa(ctx
) < 0)
6912 if (test_un_mupa(ctx
) < 0)
6914 if (test_bin_mupa(ctx
) < 0)
6916 if (test_mupa_set(ctx
) < 0)
6918 if (test_mupa_uset(ctx
) < 0)
6920 if (test_mupa_ma(ctx
) < 0)
6922 if (test_mupa_pa(ctx
) < 0)
6924 if (test_mupa_pma(ctx
) < 0)
6926 if (test_mupa_upma(ctx
) < 0)
6929 space
= isl_space_set_alloc(ctx
, 0, 1);
6930 ls
= isl_local_space_from_space(space
);
6931 aff
= isl_aff_zero_on_domain(ls
);
6933 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6934 aff
= isl_aff_scale_down_ui(aff
, 3);
6935 aff
= isl_aff_floor(aff
);
6936 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6937 aff
= isl_aff_scale_down_ui(aff
, 2);
6938 aff
= isl_aff_floor(aff
);
6939 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6942 set
= isl_set_read_from_str(ctx
, str
);
6943 aff
= isl_aff_gist(aff
, set
);
6945 aff
= isl_aff_add_constant_si(aff
, -16);
6946 zero
= isl_aff_plain_is_zero(aff
);
6952 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6954 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6955 aff
= isl_aff_scale_down_ui(aff
, 64);
6956 aff
= isl_aff_floor(aff
);
6957 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6962 if (test_aff_set_tuple_id(ctx
) < 0)
6964 if (test_aff_normalize(ctx
) < 0)
6970 /* Inputs for isl_set_bind tests.
6971 * "set" is the input set.
6972 * "tuple" is the binding tuple.
6973 * "res" is the expected result.
6980 } bind_set_tests
[] = {
6981 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6983 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6984 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6986 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6987 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6989 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6990 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6992 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6995 /* Perform basic isl_set_bind tests.
6997 static isl_stat
test_bind_set(isl_ctx
*ctx
)
7001 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
7004 isl_multi_id
*tuple
;
7007 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
7008 str
= bind_set_tests
[i
].tuple
;
7009 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7010 set
= isl_set_bind(set
, tuple
);
7011 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
7014 return isl_stat_error
;
7020 /* Inputs for isl_map_bind_domain tests.
7021 * "map" is the input map.
7022 * "tuple" is the binding tuple.
7023 * "res" is the expected result.
7029 } bind_map_domain_tests
[] = {
7030 { "{ A[M, N] -> [M + floor(N/2)] }",
7032 "[M, N] -> { [M + floor(N/2)] }" },
7033 { "{ B[N, M] -> [M + floor(N/2)] }",
7035 "[N, M] -> { [M + floor(N/2)] }" },
7036 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7038 "[M, N] -> { [M + floor(N/2)] }" },
7039 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7041 "[M, N] -> { [M + floor(N/2)] }" },
7042 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7044 "[M, N] -> { [M + floor(N/2)] }" },
7045 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7047 "[A, N, M] -> { [M + floor(N/2)] }" },
7050 /* Perform basic isl_map_bind_domain tests.
7052 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
7056 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
7060 isl_multi_id
*tuple
;
7063 str
= bind_map_domain_tests
[i
].map
;
7064 map
= isl_map_read_from_str(ctx
, str
);
7065 str
= bind_map_domain_tests
[i
].tuple
;
7066 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7067 set
= isl_map_bind_domain(map
, tuple
);
7068 str
= bind_map_domain_tests
[i
].res
;
7069 r
= set_check_equal(set
, str
);
7072 return isl_stat_error
;
7078 /* Inputs for isl_union_map_bind_range tests.
7079 * "map" is the input union map.
7080 * "tuple" is the binding tuple.
7081 * "res" is the expected result.
7087 } bind_umap_range_tests
[] = {
7088 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7090 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7091 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7094 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
7099 /* Perform basic isl_union_map_bind_range tests.
7101 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
7105 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
7107 isl_union_map
*umap
;
7108 isl_union_set
*uset
;
7109 isl_multi_id
*tuple
;
7112 str
= bind_umap_range_tests
[i
].map
;
7113 umap
= isl_union_map_read_from_str(ctx
, str
);
7114 str
= bind_umap_range_tests
[i
].tuple
;
7115 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7116 uset
= isl_union_map_bind_range(umap
, tuple
);
7117 str
= bind_umap_range_tests
[i
].res
;
7118 r
= uset_check_equal(uset
, str
);
7119 isl_union_set_free(uset
);
7121 return isl_stat_error
;
7127 /* Inputs for isl_pw_multi_aff_bind_domain tests.
7128 * "pma" is the input expression.
7129 * "tuple" is the binding tuple.
7130 * "res" is the expected result.
7136 } bind_pma_domain_tests
[] = {
7137 { "{ A[M, N] -> [M + floor(N/2)] }",
7139 "[M, N] -> { [M + floor(N/2)] }" },
7140 { "{ B[N, M] -> [M + floor(N/2)] }",
7142 "[N, M] -> { [M + floor(N/2)] }" },
7143 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7145 "[M, N] -> { [M + floor(N/2)] }" },
7146 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7148 "[M, N] -> { [M + floor(N/2)] }" },
7149 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7151 "[M, N] -> { [M + floor(N/2)] }" },
7152 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7154 "[A, N, M] -> { [M + floor(N/2)] }" },
7157 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7159 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
7163 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
7165 isl_pw_multi_aff
*pma
;
7166 isl_multi_id
*tuple
;
7169 str
= bind_pma_domain_tests
[i
].pma
;
7170 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7171 str
= bind_pma_domain_tests
[i
].tuple
;
7172 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7173 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
7174 str
= bind_pma_domain_tests
[i
].res
;
7175 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7176 isl_pw_multi_aff_free(pma
);
7178 return isl_stat_error
;
7184 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7185 * "pma" is the input expression.
7186 * "tuple" is the binding tuple.
7187 * "res" is the expected result.
7193 } bind_pma_domain_wrapped_tests
[] = {
7194 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7196 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7197 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7199 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7200 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7202 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7203 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7205 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7206 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7208 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7209 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7211 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7214 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7216 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
7220 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
7222 isl_pw_multi_aff
*pma
;
7223 isl_multi_id
*tuple
;
7226 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
7227 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7228 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
7229 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7230 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
7231 str
= bind_pma_domain_wrapped_tests
[i
].res
;
7232 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7233 isl_pw_multi_aff_free(pma
);
7235 return isl_stat_error
;
7241 /* Inputs for isl_aff_bind_id tests.
7242 * "aff" is the input expression.
7243 * "id" is the binding id.
7244 * "res" is the expected result.
7251 } bind_aff_tests
[] = {
7252 { "{ [4] }", "M", "[M = 4] -> { : }" },
7253 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7254 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7255 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7256 { "{ [NaN] }", "M", "{ : false }" },
7257 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7260 /* Perform basic isl_aff_bind_id tests.
7262 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
7266 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
7272 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
7273 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
7274 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
7275 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
7278 return isl_stat_error
;
7284 /* Inputs for isl_pw_aff_bind_id tests.
7285 * "pa" is the input expression.
7286 * "id" is the binding id.
7287 * "res" is the expected result.
7294 } bind_pa_tests
[] = {
7295 { "{ [4] }", "M", "[M = 4] -> { : }" },
7296 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7297 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7298 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7299 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7300 { "{ [NaN] }", "M", "{ : false }" },
7301 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7304 /* Perform basic isl_pw_aff_bind_id tests.
7306 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
7310 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
7316 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
7317 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
7318 res
= isl_pw_aff_bind_id(pa
, id
);
7319 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
7322 return isl_stat_error
;
7328 /* Inputs for isl_multi_union_pw_aff_bind tests.
7329 * "mupa" is the input expression.
7330 * "tuple" is the binding tuple.
7331 * "res" is the expected result.
7338 } bind_mupa_tests
[] = {
7339 { "A[{ [4] }, { [5] }]",
7341 "[M = 4, N = 5] -> { : }" },
7342 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7344 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7345 { "[M] -> A[{ [4] }, { [M + 1] }]",
7347 "[M = 4, N = 5] -> { : }" },
7350 /* Perform basic isl_multi_union_pw_aff_bind tests.
7352 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
7356 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
7358 isl_multi_union_pw_aff
*mupa
;
7360 isl_multi_id
*tuple
;
7363 str
= bind_mupa_tests
[i
].mupa
;
7364 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7365 str
= bind_mupa_tests
[i
].tuple
;
7366 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7367 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
7368 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
7369 isl_union_set_free(res
);
7371 return isl_stat_error
;
7377 /* Perform tests that reinterpret dimensions as parameters.
7379 static int test_bind(isl_ctx
*ctx
)
7381 if (test_bind_set(ctx
) < 0)
7383 if (test_bind_map_domain(ctx
) < 0)
7385 if (test_bind_umap_range(ctx
) < 0)
7387 if (test_bind_pma_domain(ctx
) < 0)
7389 if (test_bind_pma_domain_wrapped(ctx
) < 0)
7391 if (test_bind_aff(ctx
) < 0)
7393 if (test_bind_pa(ctx
) < 0)
7395 if (test_bind_mupa(ctx
) < 0)
7401 /* Inputs for isl_set_unbind_params tests.
7402 * "set" is the input parameter domain.
7403 * "tuple" is the tuple of the constructed set.
7404 * "res" is the expected result.
7410 } unbind_set_tests
[] = {
7411 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7413 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7414 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7416 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7417 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7419 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7420 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7422 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7425 /* Perform basic isl_set_unbind_params tests.
7427 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
7431 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
7434 isl_multi_id
*tuple
;
7437 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
7438 str
= unbind_set_tests
[i
].tuple
;
7439 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7440 set
= isl_set_unbind_params(set
, tuple
);
7441 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
7444 return isl_stat_error
;
7450 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7451 * "aff" is the input affine expression defined over a parameter domain.
7452 * "tuple" is the tuple of the domain that gets introduced.
7453 * "res" is the expected result.
7459 } unbind_aff_tests
[] = {
7460 { "[M, N] -> { [M + floor(N/2)] }",
7462 "{ A[M, N] -> [M + floor(N/2)] }" },
7463 { "[M, N] -> { [M + floor(N/2)] }",
7465 "{ B[N, M] -> [M + floor(N/2)] }" },
7466 { "[M, N] -> { [M + floor(N/2)] }",
7468 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7469 { "[M, N] -> { [M + floor(N/2)] }",
7470 "{ D[A, B, C, N, Z] }",
7471 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7474 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7476 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
7480 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
7483 isl_multi_id
*tuple
;
7486 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
7487 str
= unbind_aff_tests
[i
].tuple
;
7488 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7489 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
7490 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
7493 return isl_stat_error
;
7499 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7500 * "ma" is the input multi affine expression defined over a parameter domain.
7501 * "tuple" is the tuple of the domain that gets introduced.
7502 * "res" is the expected result.
7508 } unbind_multi_aff_tests
[] = {
7509 { "[M, N] -> { T[M + floor(N/2)] }",
7511 "{ A[M, N] -> T[M + floor(N/2)] }" },
7512 { "[M, N] -> { [M + floor(N/2)] }",
7514 "{ B[N, M] -> [M + floor(N/2)] }" },
7515 { "[M, N] -> { [M + floor(N/2)] }",
7517 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7518 { "[M, N] -> { [M + floor(N/2)] }",
7519 "{ D[A, B, C, N, Z] }",
7520 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7521 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7523 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7526 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7528 static isl_stat
test_unbind_multi_aff(isl_ctx
*ctx
)
7532 for (i
= 0; i
< ARRAY_SIZE(unbind_multi_aff_tests
); ++i
) {
7535 isl_multi_id
*tuple
;
7538 str
= unbind_multi_aff_tests
[i
].ma
;
7539 ma
= isl_multi_aff_read_from_str(ctx
, str
);
7540 str
= unbind_multi_aff_tests
[i
].tuple
;
7541 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7542 ma
= isl_multi_aff_unbind_params_insert_domain(ma
, tuple
);
7543 str
= unbind_multi_aff_tests
[i
].res
;
7544 r
= multi_aff_check_plain_equal(ma
, str
);
7545 isl_multi_aff_free(ma
);
7547 return isl_stat_error
;
7553 /* Perform tests that reinterpret parameters.
7555 static int test_unbind(isl_ctx
*ctx
)
7557 if (test_unbind_set(ctx
) < 0)
7559 if (test_unbind_aff(ctx
) < 0)
7561 if (test_unbind_multi_aff(ctx
) < 0)
7567 /* Check that "pa" consists of a single expression.
7569 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
7573 n
= isl_pw_aff_n_piece(pa
);
7574 isl_pw_aff_free(pa
);
7579 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
7585 /* Check that the computation below results in a single expression.
7586 * One or two expressions may result depending on which constraint
7587 * ends up being considered as redundant with respect to the other
7588 * constraints after the projection that is performed internally
7589 * by isl_set_dim_min.
7591 static int test_dim_max_1(isl_ctx
*ctx
)
7597 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7598 "-4a <= b <= 3 and b < n - 4a }";
7599 set
= isl_set_read_from_str(ctx
, str
);
7600 pa
= isl_set_dim_min(set
, 0);
7601 return check_single_piece(ctx
, pa
);
7604 /* Check that the computation below results in a single expression.
7605 * The PIP problem corresponding to these constraints has a row
7606 * that causes a split of the solution domain. The solver should
7607 * first pick rows that split off empty parts such that the actual
7608 * solution domain does not get split.
7609 * Note that the description contains some redundant constraints.
7610 * If these constraints get removed first, then the row mentioned
7611 * above does not appear in the PIP problem.
7613 static int test_dim_max_2(isl_ctx
*ctx
)
7619 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7620 "N > 0 and P >= 0 }";
7621 set
= isl_set_read_from_str(ctx
, str
);
7622 pa
= isl_set_dim_max(set
, 0);
7623 return check_single_piece(ctx
, pa
);
7626 int test_dim_max(isl_ctx
*ctx
)
7630 isl_set
*set1
, *set2
;
7635 if (test_dim_max_1(ctx
) < 0)
7637 if (test_dim_max_2(ctx
) < 0)
7640 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7641 set
= isl_set_read_from_str(ctx
, str
);
7642 pwaff
= isl_set_dim_max(set
, 0);
7643 set1
= isl_set_from_pw_aff(pwaff
);
7644 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7645 set2
= isl_set_read_from_str(ctx
, str
);
7646 equal
= isl_set_is_equal(set1
, set2
);
7652 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7654 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7655 set
= isl_set_read_from_str(ctx
, str
);
7656 pwaff
= isl_set_dim_max(set
, 0);
7657 set1
= isl_set_from_pw_aff(pwaff
);
7658 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7659 set2
= isl_set_read_from_str(ctx
, str
);
7660 equal
= isl_set_is_equal(set1
, set2
);
7666 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7668 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7669 set
= isl_set_read_from_str(ctx
, str
);
7670 pwaff
= isl_set_dim_max(set
, 0);
7671 set1
= isl_set_from_pw_aff(pwaff
);
7672 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7673 set2
= isl_set_read_from_str(ctx
, str
);
7674 equal
= isl_set_is_equal(set1
, set2
);
7680 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7682 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7683 "0 <= i < N and 0 <= j < M }";
7684 map
= isl_map_read_from_str(ctx
, str
);
7685 set
= isl_map_range(map
);
7687 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7688 set1
= isl_set_from_pw_aff(pwaff
);
7689 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7690 set2
= isl_set_read_from_str(ctx
, str
);
7691 equal
= isl_set_is_equal(set1
, set2
);
7695 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7696 set1
= isl_set_from_pw_aff(pwaff
);
7697 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7698 set2
= isl_set_read_from_str(ctx
, str
);
7699 if (equal
>= 0 && equal
)
7700 equal
= isl_set_is_equal(set1
, set2
);
7709 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7711 /* Check that solutions are properly merged. */
7712 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7713 "c <= -1 + n - 4a - 2b and c >= -2b and "
7714 "4a >= -4 + n and c >= 0 }";
7715 set
= isl_set_read_from_str(ctx
, str
);
7716 pwaff
= isl_set_dim_min(set
, 2);
7717 set1
= isl_set_from_pw_aff(pwaff
);
7718 str
= "[n] -> { [(0)] : n >= 1 }";
7719 set2
= isl_set_read_from_str(ctx
, str
);
7720 equal
= isl_set_is_equal(set1
, set2
);
7727 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7729 /* Check that empty solution lie in the right space. */
7730 str
= "[n] -> { [t,a] : 1 = 0 }";
7731 set
= isl_set_read_from_str(ctx
, str
);
7732 pwaff
= isl_set_dim_max(set
, 0);
7733 set1
= isl_set_from_pw_aff(pwaff
);
7734 str
= "[n] -> { [t] : 1 = 0 }";
7735 set2
= isl_set_read_from_str(ctx
, str
);
7736 equal
= isl_set_is_equal(set1
, set2
);
7743 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7748 /* Basic test for isl_pw_multi_aff_product.
7750 * Check that multiple pieces are properly handled.
7752 static int test_product_pma(isl_ctx
*ctx
)
7756 isl_pw_multi_aff
*pma1
, *pma2
;
7758 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7759 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7760 str
= "{ C[] -> D[] }";
7761 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7762 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7763 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7764 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7765 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7766 isl_pw_multi_aff_free(pma1
);
7773 int test_product(isl_ctx
*ctx
)
7777 isl_union_set
*uset1
, *uset2
;
7781 set
= isl_set_read_from_str(ctx
, str
);
7782 set
= isl_set_product(set
, isl_set_copy(set
));
7783 ok
= isl_set_is_wrapping(set
);
7788 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7791 uset1
= isl_union_set_read_from_str(ctx
, str
);
7792 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7793 str
= "{ [[] -> []] }";
7794 uset2
= isl_union_set_read_from_str(ctx
, str
);
7795 ok
= isl_union_set_is_equal(uset1
, uset2
);
7796 isl_union_set_free(uset1
);
7797 isl_union_set_free(uset2
);
7801 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7803 if (test_product_pma(ctx
) < 0)
7809 /* Check that two sets are not considered disjoint just because
7810 * they have a different set of (named) parameters.
7812 static int test_disjoint(isl_ctx
*ctx
)
7815 isl_set
*set
, *set2
;
7818 str
= "[n] -> { [[]->[]] }";
7819 set
= isl_set_read_from_str(ctx
, str
);
7820 str
= "{ [[]->[]] }";
7821 set2
= isl_set_read_from_str(ctx
, str
);
7822 disjoint
= isl_set_is_disjoint(set
, set2
);
7828 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7833 /* Inputs for isl_pw_multi_aff_is_equal tests.
7834 * "f1" and "f2" are the two function that need to be compared.
7835 * "equal" is the expected result.
7841 } pma_equal_tests
[] = {
7842 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7843 "[N] -> { [0] : 0 <= N <= 1 }" },
7844 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7845 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7846 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7847 "[N] -> { [0] : 0 <= N <= 1 }" },
7848 { 0, "{ [NaN] }", "{ [NaN] }" },
7851 int test_equal(isl_ctx
*ctx
)
7855 isl_set
*set
, *set2
;
7859 set
= isl_set_read_from_str(ctx
, str
);
7861 set2
= isl_set_read_from_str(ctx
, str
);
7862 equal
= isl_set_is_equal(set
, set2
);
7868 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7870 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7871 int expected
= pma_equal_tests
[i
].equal
;
7872 isl_pw_multi_aff
*f1
, *f2
;
7874 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7875 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7876 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7877 isl_pw_multi_aff_free(f1
);
7878 isl_pw_multi_aff_free(f2
);
7881 if (equal
!= expected
)
7882 isl_die(ctx
, isl_error_unknown
,
7883 "unexpected equality result", return -1);
7889 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7890 enum isl_dim_type type
, unsigned pos
, int fixed
)
7894 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7901 isl_die(ctx
, isl_error_unknown
,
7902 "map not detected as fixed", return -1);
7904 isl_die(ctx
, isl_error_unknown
,
7905 "map detected as fixed", return -1);
7908 int test_fixed(isl_ctx
*ctx
)
7913 str
= "{ [i] -> [i] }";
7914 map
= isl_map_read_from_str(ctx
, str
);
7915 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7917 str
= "{ [i] -> [1] }";
7918 map
= isl_map_read_from_str(ctx
, str
);
7919 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7921 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7922 map
= isl_map_read_from_str(ctx
, str
);
7923 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7925 map
= isl_map_read_from_str(ctx
, str
);
7926 map
= isl_map_neg(map
);
7927 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7933 struct isl_vertices_test_data
{
7936 const char *vertex
[6];
7937 } vertices_tests
[] = {
7938 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7939 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7940 { "{ A[t, i] : t = 14 and i = 1 }",
7941 1, { "{ A[14, 1] }" } },
7942 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7943 "c <= m and m <= n and m > 0 }",
7945 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7946 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7947 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7948 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7949 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7950 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7952 /* An input with implicit equality constraints among the parameters. */
7953 { "[N, M] -> { [a, b] : M >= 3 and 9 + 3M <= a <= 29 + 2N + 11M and "
7954 "2b >= M + a and 5 - 2N - M + a <= 2b <= 3 + a and "
7957 "[N, M] -> { [(21), (12)] : M = 3 and N >= 0 }",
7958 "[N, M] -> { [(61 + 2N), (32 + N)] : M = 3 and N >= 0 }",
7963 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7965 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
7967 struct isl_vertices_test_data
*data
= user
;
7970 isl_basic_set
*bset
;
7971 isl_pw_multi_aff
*pma
;
7975 ctx
= isl_vertex_get_ctx(vertex
);
7976 bset
= isl_vertex_get_domain(vertex
);
7977 ma
= isl_vertex_get_expr(vertex
);
7978 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
7980 for (i
= 0; i
< data
->n
; ++i
) {
7981 isl_pw_multi_aff
*pma_i
;
7983 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
7984 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
7985 isl_pw_multi_aff_free(pma_i
);
7987 if (equal
< 0 || equal
)
7991 isl_pw_multi_aff_free(pma
);
7992 isl_vertex_free(vertex
);
7995 return isl_stat_error
;
7997 return equal
? isl_stat_ok
: isl_stat_error
;
8000 int test_vertices(isl_ctx
*ctx
)
8004 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
8005 isl_basic_set
*bset
;
8006 isl_vertices
*vertices
;
8010 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
8011 vertices
= isl_basic_set_compute_vertices(bset
);
8012 n
= isl_vertices_get_n_vertices(vertices
);
8013 if (vertices_tests
[i
].n
!= n
)
8015 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
8016 &vertices_tests
[i
]) < 0)
8018 isl_vertices_free(vertices
);
8019 isl_basic_set_free(bset
);
8024 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
8031 /* Inputs for basic tests of unary operations on isl_union_map.
8032 * "fn" is the function that is being tested.
8033 * "arg" is a string description of the input.
8034 * "res" is a string description of the expected result.
8037 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap
);
8040 } umap_un_tests
[] = {
8041 { &isl_union_map_range_reverse
,
8042 "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
8043 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
8044 { &isl_union_map_range_reverse
,
8045 "{ A[] -> N[B[] -> C[]] }",
8046 "{ A[] -> [C[] -> B[]] }" },
8047 { &isl_union_map_range_reverse
,
8048 "{ A[] -> N[B[x] -> B[y]] }",
8049 "{ A[] -> N[B[*] -> B[*]] }" },
8052 /* Perform basic tests of unary operations on isl_union_map.
8054 static isl_stat
test_un_union_map(isl_ctx
*ctx
)
8058 for (i
= 0; i
< ARRAY_SIZE(umap_un_tests
); ++i
) {
8060 isl_union_map
*umap
, *res
;
8063 str
= umap_un_tests
[i
].arg
;
8064 umap
= isl_union_map_read_from_str(ctx
, str
);
8065 str
= umap_un_tests
[i
].res
;
8066 res
= isl_union_map_read_from_str(ctx
, str
);
8067 umap
= umap_un_tests
[i
].fn(umap
);
8068 equal
= isl_union_map_is_equal(umap
, res
);
8069 isl_union_map_free(umap
);
8070 isl_union_map_free(res
);
8072 return isl_stat_error
;
8074 isl_die(ctx
, isl_error_unknown
,
8075 "unexpected result", return isl_stat_error
);
8081 /* Inputs for basic tests of binary operations on isl_union_map.
8082 * "fn" is the function that is being tested.
8083 * "arg1" and "arg2" are string descriptions of the inputs.
8084 * "res" is a string description of the expected result.
8087 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap1
,
8088 __isl_take isl_union_map
*umap2
);
8092 } umap_bin_tests
[] = {
8093 { &isl_union_map_intersect
,
8094 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
8095 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
8096 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
8097 { &isl_union_map_intersect_domain_factor_domain
,
8098 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8099 "[N] -> { B[i] -> C[N] }",
8101 { &isl_union_map_intersect_domain_factor_domain
,
8102 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8103 "[N] -> { A[i] -> C[N] }",
8104 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8105 { &isl_union_map_intersect_domain_factor_domain
,
8106 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8107 "[N] -> { A[i] -> C[N] }",
8108 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8109 { &isl_union_map_intersect_domain_factor_range
,
8110 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8111 "[N] -> { B[i] -> C[N] }",
8112 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8113 { &isl_union_map_intersect_domain_factor_range
,
8114 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8115 "[N] -> { B[i] -> C[N] }",
8116 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8117 { &isl_union_map_intersect_domain_factor_range
,
8118 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8119 "[N] -> { A[i] -> C[N] }",
8121 { &isl_union_map_intersect_range_factor_domain
,
8122 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8123 "[N] -> { A[i] -> B[N] }",
8124 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
8125 { &isl_union_map_intersect_range_factor_domain
,
8126 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8127 "[N] -> { A[i] -> B[N] }",
8128 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
8129 { &isl_union_map_intersect_range_factor_domain
,
8130 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8131 "[N] -> { A[i] -> C[N] }",
8133 { &isl_union_map_intersect_range_factor_range
,
8134 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8135 "[N] -> { A[i] -> C[N] }",
8136 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
8137 { &isl_union_map_intersect_range_factor_range
,
8138 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8139 "[N] -> { A[i] -> C[N] }",
8140 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
8141 { &isl_union_map_intersect_range_factor_range
,
8142 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8143 "[N] -> { A[i] -> B[N] }",
8147 /* Perform basic tests of binary operations on isl_union_map.
8149 static isl_stat
test_bin_union_map(isl_ctx
*ctx
)
8153 for (i
= 0; i
< ARRAY_SIZE(umap_bin_tests
); ++i
) {
8155 isl_union_map
*umap1
, *umap2
, *res
;
8158 str
= umap_bin_tests
[i
].arg1
;
8159 umap1
= isl_union_map_read_from_str(ctx
, str
);
8160 str
= umap_bin_tests
[i
].arg2
;
8161 umap2
= isl_union_map_read_from_str(ctx
, str
);
8162 str
= umap_bin_tests
[i
].res
;
8163 res
= isl_union_map_read_from_str(ctx
, str
);
8164 umap1
= umap_bin_tests
[i
].fn(umap1
, umap2
);
8165 equal
= isl_union_map_is_equal(umap1
, res
);
8166 isl_union_map_free(umap1
);
8167 isl_union_map_free(res
);
8169 return isl_stat_error
;
8171 isl_die(ctx
, isl_error_unknown
,
8172 "unexpected result", return isl_stat_error
);
8178 /* Check that isl_union_set_contains finds space independently
8179 * of the parameters.
8181 static isl_stat
test_union_set_contains(isl_ctx
*ctx
)
8187 isl_union_set
*uset
;
8189 str
= "[N] -> { A[0:N]; B[*,*] }";
8190 uset
= isl_union_set_read_from_str(ctx
, str
);
8191 space
= isl_space_unit(ctx
);
8192 id
= isl_id_alloc(ctx
, "A", NULL
);
8193 space
= isl_space_add_named_tuple_id_ui(space
, id
, 1);
8194 ok
= isl_union_set_contains(uset
, space
);
8195 isl_space_free(space
);
8196 isl_union_set_free(uset
);
8199 return isl_stat_error
;
8201 isl_die(ctx
, isl_error_unknown
,
8202 "unexpected result", return isl_stat_error
);
8207 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8209 static int test_union_map(isl_ctx
*ctx
)
8211 if (test_un_union_map(ctx
) < 0)
8213 if (test_bin_union_map(ctx
) < 0)
8215 if (test_union_set_contains(ctx
) < 0)
8220 int test_union_pw(isl_ctx
*ctx
)
8224 isl_union_set
*uset
;
8225 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8227 str
= "{ [x] -> x^2 }";
8228 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8229 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
8230 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
8231 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
8232 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
8233 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
8234 isl_union_pw_qpolynomial_free(upwqp1
);
8235 isl_union_pw_qpolynomial_free(upwqp2
);
8239 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8244 /* Inputs for basic tests of functions that select
8245 * subparts of the domain of an isl_multi_union_pw_aff.
8246 * "fn" is the function that is tested.
8247 * "arg" is a string description of the input.
8248 * "res" is a string description of the expected result.
8251 __isl_give isl_union_set
*(*fn
)(
8252 __isl_take isl_multi_union_pw_aff
*mupa
);
8255 } un_locus_tests
[] = {
8256 { &isl_multi_union_pw_aff_zero_union_set
,
8257 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8258 "{ A[0,j]; B[0,j] }" },
8259 { &isl_multi_union_pw_aff_zero_union_set
,
8260 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8261 "{ A[i,i]; B[i,i] : i >= 0 }" },
8262 { &isl_multi_union_pw_aff_zero_union_set
,
8263 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8264 "{ A[i,j]; B[i,i] : i >= 0 }" },
8267 /* Perform some basic tests of functions that select
8268 * subparts of the domain of an isl_multi_union_pw_aff.
8270 static int test_un_locus(isl_ctx
*ctx
)
8274 isl_union_set
*uset
, *res
;
8275 isl_multi_union_pw_aff
*mupa
;
8277 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
8278 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8279 un_locus_tests
[i
].arg
);
8280 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
8281 uset
= un_locus_tests
[i
].fn(mupa
);
8282 ok
= isl_union_set_is_equal(uset
, res
);
8283 isl_union_set_free(uset
);
8284 isl_union_set_free(res
);
8288 isl_die(ctx
, isl_error_unknown
,
8289 "unexpected result", return -1);
8295 /* Inputs for basic tests of functions that select
8296 * subparts of an isl_union_map based on a relation
8297 * specified by an isl_multi_union_pw_aff.
8298 * "fn" is the function that is tested.
8299 * "arg1" and "arg2" are string descriptions of the inputs.
8300 * "res" is a string description of the expected result.
8303 __isl_give isl_union_map
*(*fn
)(
8304 __isl_take isl_union_map
*umap
,
8305 __isl_take isl_multi_union_pw_aff
*mupa
);
8309 } bin_locus_tests
[] = {
8310 { &isl_union_map_eq_at_multi_union_pw_aff
,
8311 "{ A[i,j] -> B[i',j'] }",
8312 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8313 "{ A[i,j] -> B[i,j'] }" },
8314 { &isl_union_map_eq_at_multi_union_pw_aff
,
8315 "{ A[i,j] -> B[i',j'] }",
8316 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8317 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8318 "{ A[i,j] -> B[i,j] }" },
8319 { &isl_union_map_eq_at_multi_union_pw_aff
,
8320 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8321 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8322 "{ A[i,j] -> B[i,j'] }" },
8323 { &isl_union_map_eq_at_multi_union_pw_aff
,
8324 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8325 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8326 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8327 { &isl_union_map_eq_at_multi_union_pw_aff
,
8328 "{ A[i,j] -> B[i',j'] }",
8329 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8330 "{ A[i,j] -> B[i,j'] : i > j }" },
8331 { &isl_union_map_lex_le_at_multi_union_pw_aff
,
8332 "{ A[i,j] -> B[i',j'] }",
8333 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8334 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8335 "{ A[i,j] -> B[i',j'] : i,j <<= i',j' }" },
8336 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
8337 "{ A[i,j] -> B[i',j'] }",
8338 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8339 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8340 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8341 { &isl_union_map_lex_ge_at_multi_union_pw_aff
,
8342 "{ A[i,j] -> B[i',j'] }",
8343 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8344 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8345 "{ A[i,j] -> B[i',j'] : i,j >>= i',j' }" },
8346 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
8347 "{ A[i,j] -> B[i',j'] }",
8348 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8349 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8350 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8351 { &isl_union_map_eq_at_multi_union_pw_aff
,
8352 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8353 "(F[] : { A[i,j]; B[i,j] })",
8354 "{ A[i,j] -> B[i',j'] }" },
8355 { &isl_union_map_eq_at_multi_union_pw_aff
,
8356 "{ A[i,j] -> B[i',j'] }",
8357 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8358 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8359 { &isl_union_map_eq_at_multi_union_pw_aff
,
8360 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8361 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8362 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8363 { &isl_union_map_eq_at_multi_union_pw_aff
,
8364 "{ A[i,j] -> B[i',j'] }",
8365 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8366 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8367 { &isl_union_map_eq_at_multi_union_pw_aff
,
8368 "{ A[i,j] -> B[i',j'] }",
8369 "[N] -> (F[] : { : N >= 0 })",
8370 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8373 /* Perform some basic tests of functions that select
8374 * subparts of an isl_union_map based on a relation
8375 * specified by an isl_multi_union_pw_aff.
8377 static int test_bin_locus(isl_ctx
*ctx
)
8381 isl_union_map
*umap
, *res
;
8382 isl_multi_union_pw_aff
*mupa
;
8384 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
8385 umap
= isl_union_map_read_from_str(ctx
,
8386 bin_locus_tests
[i
].arg1
);
8387 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8388 bin_locus_tests
[i
].arg2
);
8389 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
8390 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
8391 ok
= isl_union_map_is_equal(umap
, res
);
8392 isl_union_map_free(umap
);
8393 isl_union_map_free(res
);
8397 isl_die(ctx
, isl_error_unknown
,
8398 "unexpected result", return -1);
8404 /* Inputs for basic tests of functions that determine
8405 * the part of the domain where two isl_multi_aff objects
8406 * related to each other in a specific way.
8407 * "fn" is the function that is being tested.
8408 * "arg1" and "arg2" are string descriptions of the inputs.
8409 * "res" is a string description of the expected result.
8412 __isl_give isl_set
*(*fn
)(__isl_take isl_multi_aff
*ma1
,
8413 __isl_take isl_multi_aff
*ma2
);
8417 } bin_locus_ma_tests
[] = {
8418 { &isl_multi_aff_lex_le_set
, "{ [] }", "{ [] }", "{ : }" },
8419 { &isl_multi_aff_lex_lt_set
, "{ [] }", "{ [] }", "{ : false }" },
8420 { &isl_multi_aff_lex_le_set
,
8421 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8422 "{ A[i] : i <= 0 }" },
8423 { &isl_multi_aff_lex_lt_set
,
8424 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8425 "{ A[i] : i < 0 }" },
8426 { &isl_multi_aff_lex_le_set
,
8427 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8428 "{ A[i] : i <= 0 }" },
8429 { &isl_multi_aff_lex_le_set
,
8430 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8431 "{ A[i] : i <= 0 }" },
8432 { &isl_multi_aff_lex_le_set
,
8433 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8434 "{ A[i] : i < 0 }" },
8437 /* Perform some basic tests of functions that determine
8438 * the part of the domain where two isl_multi_aff objects
8439 * related to each other in a specific way.
8441 static isl_stat
test_bin_locus_ma(isl_ctx
*ctx
)
8445 for (i
= 0; i
< ARRAY_SIZE(bin_locus_ma_tests
); ++i
) {
8448 isl_multi_aff
*ma1
, *ma2
;
8451 str
= bin_locus_ma_tests
[i
].arg1
;
8452 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8453 str
= bin_locus_ma_tests
[i
].arg2
;
8454 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8455 res
= isl_set_read_from_str(ctx
, bin_locus_ma_tests
[i
].res
);
8456 set
= bin_locus_ma_tests
[i
].fn(ma1
, ma2
);
8457 ok
= isl_set_is_equal(set
, res
);
8461 return isl_stat_error
;
8463 isl_die(ctx
, isl_error_unknown
,
8464 "unexpected result", return isl_stat_error
);
8470 /* Perform basic locus tests.
8472 static int test_locus(isl_ctx
*ctx
)
8474 if (test_un_locus(ctx
) < 0)
8476 if (test_bin_locus(ctx
) < 0)
8478 if (test_bin_locus_ma(ctx
) < 0)
8483 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8484 * defined over the correct domain space.
8486 static int test_eval_1(isl_ctx
*ctx
)
8491 isl_union_pw_qpolynomial
*upwqp
;
8495 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
8496 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8498 set
= isl_set_read_from_str(ctx
, str
);
8499 pnt
= isl_set_sample_point(set
);
8500 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
8501 cmp
= isl_val_cmp_si(v
, 36);
8507 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
8512 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8514 static int test_eval_2(isl_ctx
*ctx
)
8519 isl_qpolynomial
*qp
;
8523 str
= "{ A[x] -> [x] }";
8524 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
8525 str
= "{ A[x] : false }";
8526 set
= isl_set_read_from_str(ctx
, str
);
8527 pnt
= isl_set_sample_point(set
);
8528 v
= isl_qpolynomial_eval(qp
, pnt
);
8529 ok
= isl_val_is_nan(v
);
8535 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
8540 /* Check that a polynomial (without local variables) can be evaluated
8541 * in a rational point.
8543 static isl_stat
test_eval_3(isl_ctx
*ctx
)
8545 isl_pw_qpolynomial
*pwqp
;
8550 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
8551 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
8552 v
= isl_val_read_from_str(ctx
, "1/2");
8553 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
8554 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
8555 r
= val_check_equal(v
, "1/4");
8561 /* Inputs for isl_pw_aff_eval test.
8562 * "f" is the affine function.
8563 * "p" is the point where the function should be evaluated.
8564 * "res" is the expected result.
8570 } aff_eval_tests
[] = {
8571 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8572 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8573 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8574 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8575 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8576 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8577 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8578 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8579 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8580 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8581 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8582 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8583 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8584 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8585 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8586 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8587 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8588 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8589 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8590 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8591 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8592 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8593 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8596 /* Perform basic isl_pw_aff_eval tests.
8598 static int test_eval_aff(isl_ctx
*ctx
)
8602 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
8609 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
8610 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
8611 pnt
= isl_set_sample_point(set
);
8612 v
= isl_pw_aff_eval(pa
, pnt
);
8613 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
8621 /* Perform basic evaluation tests.
8623 static int test_eval(isl_ctx
*ctx
)
8625 if (test_eval_1(ctx
) < 0)
8627 if (test_eval_2(ctx
) < 0)
8629 if (test_eval_3(ctx
) < 0)
8631 if (test_eval_aff(ctx
) < 0)
8636 /* Descriptions of sets that are tested for reparsing after printing.
8638 const char *output_tests
[] = {
8639 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8642 "{ [x] : x mod 2 = 0 }",
8643 "{ [x] : x mod 2 = 1 }",
8644 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8645 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8646 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8647 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8648 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8649 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8652 /* Check that printing a set and reparsing a set from the printed output
8653 * results in the same set.
8655 static int test_output_set(isl_ctx
*ctx
)
8659 isl_set
*set1
, *set2
;
8662 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
8663 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
8664 str
= isl_set_to_str(set1
);
8665 set2
= isl_set_read_from_str(ctx
, str
);
8667 equal
= isl_set_is_equal(set1
, set2
);
8673 isl_die(ctx
, isl_error_unknown
,
8674 "parsed output not the same", return -1);
8680 /* Check that an isl_multi_aff is printed using a consistent space.
8682 static isl_stat
test_output_ma(isl_ctx
*ctx
)
8687 isl_multi_aff
*ma
, *ma2
;
8689 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8690 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8691 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
8692 str
= isl_multi_aff_to_str(ma
);
8693 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8695 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
8696 isl_multi_aff_free(ma2
);
8697 isl_multi_aff_free(ma
);
8700 return isl_stat_error
;
8702 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8703 return isl_stat_error
);
8708 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8710 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
8715 isl_multi_pw_aff
*mpa
, *mpa2
;
8717 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8718 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8719 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
8720 str
= isl_multi_pw_aff_to_str(mpa
);
8721 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8723 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8724 isl_multi_pw_aff_free(mpa2
);
8725 isl_multi_pw_aff_free(mpa
);
8728 return isl_stat_error
;
8730 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8731 return isl_stat_error
);
8736 int test_output(isl_ctx
*ctx
)
8744 if (test_output_set(ctx
) < 0)
8746 if (test_output_ma(ctx
) < 0)
8748 if (test_output_mpa(ctx
) < 0)
8751 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8752 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8754 p
= isl_printer_to_str(ctx
);
8755 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
8756 p
= isl_printer_print_pw_aff(p
, pa
);
8757 s
= isl_printer_get_str(p
);
8758 isl_printer_free(p
);
8759 isl_pw_aff_free(pa
);
8763 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8768 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8773 int test_sample(isl_ctx
*ctx
)
8776 isl_basic_set
*bset1
, *bset2
;
8779 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8780 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8781 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8782 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8783 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8784 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8785 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8786 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8787 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8788 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8789 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8790 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8791 "d - 1073741821e and "
8792 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8793 "3j >= 1 - a + b + 2e and "
8794 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8795 "3i <= 4 - a + 4b - e and "
8796 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8797 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8798 "c <= -1 + a and 3i >= -2 - a + 3e and "
8799 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8800 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8801 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8802 "1073741823e >= 1 + 1073741823b - d and "
8803 "3i >= 1073741823b + c - 1073741823e - f and "
8804 "3i >= 1 + 2b + e + 3g }";
8805 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8806 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
8807 empty
= isl_basic_set_is_empty(bset2
);
8808 subset
= isl_basic_set_is_subset(bset2
, bset1
);
8809 isl_basic_set_free(bset1
);
8810 isl_basic_set_free(bset2
);
8811 if (empty
< 0 || subset
< 0)
8814 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
8816 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
8821 /* Perform a projection on a basic set that is known to be empty
8822 * but that has not been assigned a canonical representation.
8823 * Earlier versions of isl would run into a stack overflow
8826 static int test_empty_projection(isl_ctx
*ctx
)
8830 isl_basic_set
*bset
;
8832 str
= "{ [a, b, c, d, e, f, g, h] : 5f = 1 + 4a - b + 5c - d - 2e and "
8833 "3h = 2 + b + c and 14c >= 9 - 3a + 25b and "
8834 "4c <= 50 - 3a + 23b and 6b <= -39 + a and "
8835 "9g >= -6 + 3a + b + c and e < a + b - 2d and "
8836 "7d >= -5 + 2a + 2b and 5g >= -14 + a - 4b + d + 2e and "
8837 "9g <= -28 - 5b - 2c + 3d + 6e }";
8838 bset
= isl_basic_set_read_from_str(ctx
, str
);
8839 empty
= isl_basic_set_is_empty(bset
);
8840 bset
= isl_basic_set_params(bset
);
8841 isl_basic_set_free(bset
);
8849 int test_fixed_power(isl_ctx
*ctx
)
8856 str
= "{ [i] -> [i + 1] }";
8857 map
= isl_map_read_from_str(ctx
, str
);
8858 exp
= isl_val_int_from_si(ctx
, 23);
8859 map
= isl_map_fixed_power_val(map
, exp
);
8860 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
8868 int test_slice(isl_ctx
*ctx
)
8874 str
= "{ [i] -> [j] }";
8875 map
= isl_map_read_from_str(ctx
, str
);
8876 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8877 equal
= map_check_equal(map
, "{ [i] -> [i] }");
8882 str
= "{ [i] -> [j] }";
8883 map
= isl_map_read_from_str(ctx
, str
);
8884 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8885 equal
= map_check_equal(map
, "{ [i] -> [j] }");
8890 str
= "{ [i] -> [j] }";
8891 map
= isl_map_read_from_str(ctx
, str
);
8892 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8893 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8898 str
= "{ [i] -> [j] }";
8899 map
= isl_map_read_from_str(ctx
, str
);
8900 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8901 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8906 str
= "{ [i] -> [j] }";
8907 map
= isl_map_read_from_str(ctx
, str
);
8908 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8909 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8914 str
= "{ [i] -> [j] }";
8915 map
= isl_map_read_from_str(ctx
, str
);
8916 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8917 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8925 int test_eliminate(isl_ctx
*ctx
)
8931 str
= "{ [i] -> [j] : i = 2j }";
8932 map
= isl_map_read_from_str(ctx
, str
);
8933 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8934 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8942 /* Check basic functionality of isl_map_deltas_map.
8944 static int test_deltas_map(isl_ctx
*ctx
)
8950 str
= "{ A[i] -> A[i + 1] }";
8951 map
= isl_map_read_from_str(ctx
, str
);
8952 map
= isl_map_deltas_map(map
);
8953 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8961 /* Check that isl_set_dim_residue_class detects that the values of j
8962 * in the set below are all odd and that it does not detect any spurious
8965 static int test_residue_class(isl_ctx
*ctx
)
8972 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8973 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8974 set
= isl_set_read_from_str(ctx
, str
);
8977 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
8979 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
8980 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
8981 res
= isl_stat_error
);
8989 static int test_align_parameters_1(isl_ctx
*ctx
)
8993 isl_multi_aff
*ma1
, *ma2
;
8996 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8997 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8999 space
= isl_space_params_alloc(ctx
, 1);
9000 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
9001 ma1
= isl_multi_aff_align_params(ma1
, space
);
9003 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
9004 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
9006 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9008 isl_multi_aff_free(ma1
);
9009 isl_multi_aff_free(ma2
);
9014 isl_die(ctx
, isl_error_unknown
,
9015 "result not as expected", return -1);
9020 /* Check the isl_multi_*_from_*_list operation in case inputs
9021 * have unaligned parameters.
9022 * In particular, older versions of isl would simply fail
9023 * (without printing any error message).
9025 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
9032 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
9033 space
= isl_map_get_space(map
);
9036 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
9037 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
9038 isl_multi_aff_free(ma
);
9041 return isl_stat_error
;
9045 /* Perform basic parameter alignment tests.
9047 static int test_align_parameters(isl_ctx
*ctx
)
9049 if (test_align_parameters_1(ctx
) < 0)
9051 if (test_align_parameters_2(ctx
) < 0)
9057 /* Check that isl_*_drop_unused_params actually drops the unused parameters
9058 * by comparing the result using isl_*_plain_is_equal.
9059 * Note that this assumes that isl_*_plain_is_equal does not consider
9060 * objects that only differ by unused parameters to be equal.
9062 int test_drop_unused_parameters(isl_ctx
*ctx
)
9064 const char *str_with
, *str_without
;
9065 isl_basic_set
*bset1
, *bset2
;
9066 isl_set
*set1
, *set2
;
9067 isl_pw_aff
*pwa1
, *pwa2
;
9070 str_with
= "[n, m, o] -> { [m] }";
9071 str_without
= "[m] -> { [m] }";
9073 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
9074 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
9075 bset1
= isl_basic_set_drop_unused_params(bset1
);
9076 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
9077 isl_basic_set_free(bset1
);
9078 isl_basic_set_free(bset2
);
9083 isl_die(ctx
, isl_error_unknown
,
9084 "result not as expected", return -1);
9086 set1
= isl_set_read_from_str(ctx
, str_with
);
9087 set2
= isl_set_read_from_str(ctx
, str_without
);
9088 set1
= isl_set_drop_unused_params(set1
);
9089 equal
= isl_set_plain_is_equal(set1
, set2
);
9096 isl_die(ctx
, isl_error_unknown
,
9097 "result not as expected", return -1);
9099 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
9100 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
9101 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
9102 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
9103 isl_pw_aff_free(pwa1
);
9104 isl_pw_aff_free(pwa2
);
9109 isl_die(ctx
, isl_error_unknown
,
9110 "result not as expected", return -1);
9115 static int test_list(isl_ctx
*ctx
)
9117 isl_id
*a
, *b
, *c
, *d
, *id
;
9122 a
= isl_id_alloc(ctx
, "a", NULL
);
9123 b
= isl_id_alloc(ctx
, "b", NULL
);
9124 c
= isl_id_alloc(ctx
, "c", NULL
);
9125 d
= isl_id_alloc(ctx
, "d", NULL
);
9127 list
= isl_id_list_alloc(ctx
, 4);
9128 list
= isl_id_list_add(list
, b
);
9129 list
= isl_id_list_insert(list
, 0, a
);
9130 list
= isl_id_list_add(list
, c
);
9131 list
= isl_id_list_add(list
, d
);
9132 list
= isl_id_list_drop(list
, 1, 1);
9134 n
= isl_id_list_n_id(list
);
9138 isl_id_list_free(list
);
9139 isl_die(ctx
, isl_error_unknown
,
9140 "unexpected number of elements in list", return -1);
9143 id
= isl_id_list_get_id(list
, 0);
9146 id
= isl_id_list_get_id(list
, 1);
9149 id
= isl_id_list_get_id(list
, 2);
9153 isl_id_list_free(list
);
9156 isl_die(ctx
, isl_error_unknown
,
9157 "unexpected elements in list", return -1);
9162 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
9164 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
9169 isl_basic_set
*bset1
, *bset2
;
9171 str
= "[N] -> { A[0, N + 1] }";
9172 ma
= isl_multi_aff_read_from_str(ctx
, str
);
9173 bset1
= isl_basic_set_read_from_str(ctx
, str
);
9174 bset2
= isl_basic_set_from_multi_aff(ma
);
9175 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9176 isl_basic_set_free(bset1
);
9177 isl_basic_set_free(bset2
);
9179 return isl_stat_error
;
9181 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9182 return isl_stat_error
);
9186 const char *set_conversion_tests
[] = {
9187 "[N] -> { [i] : N - 1 <= 2 i <= N }",
9188 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
9189 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9190 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9191 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
9192 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
9193 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9194 "-3 + c <= d <= 28 + c) }",
9197 /* Check that converting from isl_set to isl_pw_multi_aff and back
9198 * to isl_set produces the original isl_set.
9200 static int test_set_conversion(isl_ctx
*ctx
)
9204 isl_set
*set1
, *set2
;
9205 isl_pw_multi_aff
*pma
;
9208 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
9209 str
= set_conversion_tests
[i
];
9210 set1
= isl_set_read_from_str(ctx
, str
);
9211 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
9212 set2
= isl_set_from_pw_multi_aff(pma
);
9213 equal
= isl_set_is_equal(set1
, set2
);
9220 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9227 const char *conversion_tests
[] = {
9228 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9229 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9230 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9231 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9233 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9234 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9235 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9238 /* Check that converting from isl_map to isl_pw_multi_aff and back
9239 * to isl_map produces the original isl_map.
9241 static int test_map_conversion(isl_ctx
*ctx
)
9244 isl_map
*map1
, *map2
;
9245 isl_pw_multi_aff
*pma
;
9248 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
9249 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
9250 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
9251 map2
= isl_map_from_pw_multi_aff(pma
);
9252 equal
= isl_map_is_equal(map1
, map2
);
9259 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9266 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9267 * to isl_multi_pw_aff and back.
9269 const char *mpa_conversion_tests
[] = {
9271 "{ [x] -> A[x] : x >= 0 }",
9272 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9273 "{ [x] -> A[x, x + 1] }",
9275 "{ [x] -> A[] : x >= 0 }",
9278 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9279 * back to isl_pw_multi_aff preserves the original meaning.
9281 static int test_mpa_conversion(isl_ctx
*ctx
)
9284 isl_pw_multi_aff
*pma1
, *pma2
;
9285 isl_multi_pw_aff
*mpa
;
9288 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
9290 str
= mpa_conversion_tests
[i
];
9291 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9292 pma2
= isl_pw_multi_aff_copy(pma1
);
9293 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
9294 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
9295 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9296 isl_pw_multi_aff_free(pma1
);
9297 isl_pw_multi_aff_free(pma2
);
9302 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9309 /* Descriptions of union maps that should be convertible
9310 * to an isl_multi_union_pw_aff.
9312 const char *umap_mupa_conversion_tests
[] = {
9313 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9314 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9315 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9316 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9318 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9319 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9320 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9321 "{ A[] -> B[0]; C[] -> B[1] }",
9322 "{ A[] -> B[]; C[] -> B[] }",
9325 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9326 * to isl_union_map produces the original isl_union_map.
9328 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
9331 isl_union_map
*umap1
, *umap2
;
9332 isl_multi_union_pw_aff
*mupa
;
9335 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
9337 str
= umap_mupa_conversion_tests
[i
];
9338 umap1
= isl_union_map_read_from_str(ctx
, str
);
9339 umap2
= isl_union_map_copy(umap1
);
9340 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
9341 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
9342 equal
= isl_union_map_is_equal(umap1
, umap2
);
9343 isl_union_map_free(umap1
);
9344 isl_union_map_free(umap2
);
9349 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9356 static int test_conversion(isl_ctx
*ctx
)
9358 if (test_ma_conversion(ctx
) < 0)
9360 if (test_set_conversion(ctx
) < 0)
9362 if (test_map_conversion(ctx
) < 0)
9364 if (test_mpa_conversion(ctx
) < 0)
9366 if (test_union_map_mupa_conversion(ctx
) < 0)
9371 /* Check that isl_basic_map_curry does not modify input.
9373 static int test_curry(isl_ctx
*ctx
)
9376 isl_basic_map
*bmap1
, *bmap2
;
9379 str
= "{ [A[] -> B[]] -> C[] }";
9380 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
9381 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
9382 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
9383 isl_basic_map_free(bmap1
);
9384 isl_basic_map_free(bmap2
);
9389 isl_die(ctx
, isl_error_unknown
,
9390 "curried map should not be equal to original",
9400 } pullback_tests
[] = {
9401 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9402 "{ A[a,b] -> C[b + 2a] }" },
9403 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9404 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9405 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9406 "{ A[a] -> C[(a)/6] }" },
9407 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9408 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9409 "{ A[a] -> C[(2a)/3] }" },
9410 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9411 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9412 "{ A[i,j] -> C[i + j, i + j] }"},
9413 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9414 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9415 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9416 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9417 "{ [i, j] -> [floor((i)/3), j] }",
9418 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9421 static int test_pullback(isl_ctx
*ctx
)
9424 isl_multi_aff
*ma1
, *ma2
;
9428 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
9429 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
9430 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
9431 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
9432 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
9433 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9434 isl_multi_aff_free(ma1
);
9435 isl_multi_aff_free(ma2
);
9439 isl_die(ctx
, isl_error_unknown
, "bad pullback",
9446 /* Check that negation is printed correctly and that equal expressions
9447 * are correctly identified.
9449 static int test_ast(isl_ctx
*ctx
)
9451 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
9455 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9456 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9457 expr
= isl_ast_expr_add(expr1
, expr2
);
9458 expr2
= isl_ast_expr_copy(expr
);
9459 expr
= isl_ast_expr_neg(expr
);
9460 expr2
= isl_ast_expr_neg(expr2
);
9461 equal
= isl_ast_expr_is_equal(expr
, expr2
);
9462 str
= isl_ast_expr_to_C_str(expr
);
9463 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
9465 isl_ast_expr_free(expr
);
9466 isl_ast_expr_free(expr2
);
9468 if (ok
< 0 || equal
< 0)
9471 isl_die(ctx
, isl_error_unknown
,
9472 "equal expressions not considered equal", return -1);
9474 isl_die(ctx
, isl_error_unknown
,
9475 "isl_ast_expr printed incorrectly", return -1);
9477 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9478 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9479 expr
= isl_ast_expr_add(expr1
, expr2
);
9480 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
9481 expr
= isl_ast_expr_sub(expr3
, expr
);
9482 str
= isl_ast_expr_to_C_str(expr
);
9483 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
9485 isl_ast_expr_free(expr
);
9490 isl_die(ctx
, isl_error_unknown
,
9491 "isl_ast_expr printed incorrectly", return -1);
9496 /* Check that isl_ast_build_expr_from_set returns a valid expression
9497 * for an empty set. Note that isl_ast_build_expr_from_set getting
9498 * called on an empty set probably indicates a bug in the caller.
9500 static int test_ast_build(isl_ctx
*ctx
)
9503 isl_ast_build
*build
;
9506 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9507 build
= isl_ast_build_from_context(set
);
9509 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
9510 expr
= isl_ast_build_expr_from_set(build
, set
);
9512 isl_ast_expr_free(expr
);
9513 isl_ast_build_free(build
);
9521 /* Internal data structure for before_for and after_for callbacks.
9523 * depth is the current depth
9524 * before is the number of times before_for has been called
9525 * after is the number of times after_for has been called
9527 struct isl_test_codegen_data
{
9533 /* This function is called before each for loop in the AST generated
9534 * from test_ast_gen1.
9536 * Increment the number of calls and the depth.
9537 * Check that the space returned by isl_ast_build_get_schedule_space
9538 * matches the target space of the schedule returned by
9539 * isl_ast_build_get_schedule.
9540 * Return an isl_id that is checked by the corresponding call
9543 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
9546 struct isl_test_codegen_data
*data
= user
;
9549 isl_union_map
*schedule
;
9550 isl_union_set
*uset
;
9556 ctx
= isl_ast_build_get_ctx(build
);
9558 if (data
->before
>= 3)
9559 isl_die(ctx
, isl_error_unknown
,
9560 "unexpected number of for nodes", return NULL
);
9561 if (data
->depth
< 0 || data
->depth
>= 2)
9562 isl_die(ctx
, isl_error_unknown
,
9563 "unexpected depth", return NULL
);
9565 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
9569 schedule
= isl_ast_build_get_schedule(build
);
9570 uset
= isl_union_map_range(schedule
);
9571 n
= isl_union_set_n_set(uset
);
9573 isl_union_set_free(uset
);
9576 isl_die(ctx
, isl_error_unknown
,
9577 "expecting single range space", return NULL
);
9580 space
= isl_ast_build_get_schedule_space(build
);
9581 set
= isl_union_set_extract_set(uset
, space
);
9582 isl_union_set_free(uset
);
9583 empty
= isl_set_is_empty(set
);
9589 isl_die(ctx
, isl_error_unknown
,
9590 "spaces don't match", return NULL
);
9592 return isl_id_alloc(ctx
, name
, NULL
);
9595 /* This function is called after each for loop in the AST generated
9596 * from test_ast_gen1.
9598 * Increment the number of calls and decrement the depth.
9599 * Check that the annotation attached to the node matches
9600 * the isl_id returned by the corresponding call to before_for.
9602 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
9603 __isl_keep isl_ast_build
*build
, void *user
)
9605 struct isl_test_codegen_data
*data
= user
;
9613 if (data
->after
> data
->before
)
9614 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9615 "mismatch in number of for nodes",
9616 return isl_ast_node_free(node
));
9618 id
= isl_ast_node_get_annotation(node
);
9620 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9621 "missing annotation", return isl_ast_node_free(node
));
9623 name
= isl_id_get_name(id
);
9624 valid
= name
&& atoi(name
+ 1) == data
->depth
;
9628 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9629 "wrong annotation", return isl_ast_node_free(node
));
9634 /* Check that the before_each_for and after_each_for callbacks
9635 * are called for each for loop in the generated code,
9636 * that they are called in the right order and that the isl_id
9637 * returned from the before_each_for callback is attached to
9638 * the isl_ast_node passed to the corresponding after_each_for call.
9640 static int test_ast_gen1(isl_ctx
*ctx
)
9644 isl_union_map
*schedule
;
9645 isl_ast_build
*build
;
9647 struct isl_test_codegen_data data
;
9649 str
= "[N] -> { : N >= 10 }";
9650 set
= isl_set_read_from_str(ctx
, str
);
9651 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9652 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9653 schedule
= isl_union_map_read_from_str(ctx
, str
);
9658 build
= isl_ast_build_from_context(set
);
9659 build
= isl_ast_build_set_before_each_for(build
,
9660 &before_for
, &data
);
9661 build
= isl_ast_build_set_after_each_for(build
,
9663 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9664 isl_ast_build_free(build
);
9668 isl_ast_node_free(tree
);
9670 if (data
.before
!= 3 || data
.after
!= 3)
9671 isl_die(ctx
, isl_error_unknown
,
9672 "unexpected number of for nodes", return -1);
9677 /* Check that the AST generator handles domains that are integrally disjoint
9678 * but not rationally disjoint.
9680 static int test_ast_gen2(isl_ctx
*ctx
)
9684 isl_union_map
*schedule
;
9685 isl_union_map
*options
;
9686 isl_ast_build
*build
;
9689 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9690 schedule
= isl_union_map_read_from_str(ctx
, str
);
9691 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9692 build
= isl_ast_build_from_context(set
);
9694 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9695 options
= isl_union_map_read_from_str(ctx
, str
);
9696 build
= isl_ast_build_set_options(build
, options
);
9697 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9698 isl_ast_build_free(build
);
9701 isl_ast_node_free(tree
);
9706 /* Increment *user on each call.
9708 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
9709 __isl_keep isl_ast_build
*build
, void *user
)
9718 /* Test that unrolling tries to minimize the number of instances.
9719 * In particular, for the schedule given below, make sure it generates
9720 * 3 nodes (rather than 101).
9722 static int test_ast_gen3(isl_ctx
*ctx
)
9726 isl_union_map
*schedule
;
9727 isl_union_map
*options
;
9728 isl_ast_build
*build
;
9732 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9733 schedule
= isl_union_map_read_from_str(ctx
, str
);
9734 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9736 str
= "{ [i] -> unroll[0] }";
9737 options
= isl_union_map_read_from_str(ctx
, str
);
9739 build
= isl_ast_build_from_context(set
);
9740 build
= isl_ast_build_set_options(build
, options
);
9741 build
= isl_ast_build_set_at_each_domain(build
,
9742 &count_domains
, &n_domain
);
9743 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9744 isl_ast_build_free(build
);
9748 isl_ast_node_free(tree
);
9751 isl_die(ctx
, isl_error_unknown
,
9752 "unexpected number of for nodes", return -1);
9757 /* Check that if the ast_build_exploit_nested_bounds options is set,
9758 * we do not get an outer if node in the generated AST,
9759 * while we do get such an outer if node if the options is not set.
9761 static int test_ast_gen4(isl_ctx
*ctx
)
9765 isl_union_map
*schedule
;
9766 isl_ast_build
*build
;
9768 enum isl_ast_node_type type
;
9771 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9772 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9774 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9776 schedule
= isl_union_map_read_from_str(ctx
, str
);
9777 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9778 build
= isl_ast_build_from_context(set
);
9779 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9780 isl_ast_build_free(build
);
9784 type
= isl_ast_node_get_type(tree
);
9785 isl_ast_node_free(tree
);
9787 if (type
== isl_ast_node_if
)
9788 isl_die(ctx
, isl_error_unknown
,
9789 "not expecting if node", return -1);
9791 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9793 schedule
= isl_union_map_read_from_str(ctx
, str
);
9794 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9795 build
= isl_ast_build_from_context(set
);
9796 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9797 isl_ast_build_free(build
);
9801 type
= isl_ast_node_get_type(tree
);
9802 isl_ast_node_free(tree
);
9804 if (type
!= isl_ast_node_if
)
9805 isl_die(ctx
, isl_error_unknown
,
9806 "expecting if node", return -1);
9808 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9813 /* This function is called for each leaf in the AST generated
9814 * from test_ast_gen5.
9816 * We finalize the AST generation by extending the outer schedule
9817 * with a zero-dimensional schedule. If this results in any for loops,
9818 * then this means that we did not pass along enough information
9819 * about the outer schedule to the inner AST generation.
9821 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9824 isl_union_map
*schedule
, *extra
;
9827 schedule
= isl_ast_build_get_schedule(build
);
9828 extra
= isl_union_map_copy(schedule
);
9829 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9830 schedule
= isl_union_map_range_product(schedule
, extra
);
9831 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9832 isl_ast_build_free(build
);
9837 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9838 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9839 "code should not contain any for loop",
9840 return isl_ast_node_free(tree
));
9845 /* Check that we do not lose any information when going back and
9846 * forth between internal and external schedule.
9848 * In particular, we create an AST where we unroll the only
9849 * non-constant dimension in the schedule. We therefore do
9850 * not expect any for loops in the AST. However, older versions
9851 * of isl would not pass along enough information about the outer
9852 * schedule when performing an inner code generation from a create_leaf
9853 * callback, resulting in the inner code generation producing a for loop.
9855 static int test_ast_gen5(isl_ctx
*ctx
)
9859 isl_union_map
*schedule
, *options
;
9860 isl_ast_build
*build
;
9863 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9864 schedule
= isl_union_map_read_from_str(ctx
, str
);
9866 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9867 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9868 options
= isl_union_map_read_from_str(ctx
, str
);
9870 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9871 build
= isl_ast_build_from_context(set
);
9872 build
= isl_ast_build_set_options(build
, options
);
9873 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9874 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9875 isl_ast_build_free(build
);
9876 isl_ast_node_free(tree
);
9883 /* Check that the expression
9885 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9887 * is not combined into
9891 * as this would result in n/2 being evaluated in parts of
9892 * the definition domain where n is not a multiple of 2.
9894 static int test_ast_expr(isl_ctx
*ctx
)
9898 isl_ast_build
*build
;
9903 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9904 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9906 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9907 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9908 build
= isl_ast_build_alloc(ctx
);
9909 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9910 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9911 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9912 isl_ast_build_free(build
);
9913 isl_ast_expr_free(expr
);
9915 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
9920 isl_die(ctx
, isl_error_unknown
,
9921 "expressions should not be combined", return -1);
9926 static int test_ast_gen(isl_ctx
*ctx
)
9928 if (test_ast_gen1(ctx
) < 0)
9930 if (test_ast_gen2(ctx
) < 0)
9932 if (test_ast_gen3(ctx
) < 0)
9934 if (test_ast_gen4(ctx
) < 0)
9936 if (test_ast_gen5(ctx
) < 0)
9938 if (test_ast_expr(ctx
) < 0)
9943 /* Check if dropping output dimensions from an isl_pw_multi_aff
9946 static int test_pw_multi_aff(isl_ctx
*ctx
)
9949 isl_pw_multi_aff
*pma1
, *pma2
;
9952 str
= "{ [i,j] -> [i+j, 4i-j] }";
9953 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9954 str
= "{ [i,j] -> [4i-j] }";
9955 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9957 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
9959 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9961 isl_pw_multi_aff_free(pma1
);
9962 isl_pw_multi_aff_free(pma2
);
9966 isl_die(ctx
, isl_error_unknown
,
9967 "expressions not equal", return -1);
9972 /* Check that we can properly parse multi piecewise affine expressions
9973 * where the piecewise affine expressions have different domains.
9975 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
9978 isl_set
*dom
, *dom2
;
9979 isl_multi_pw_aff
*mpa1
, *mpa2
;
9984 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
9985 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
9986 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
9987 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
9988 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
9989 str
= "{ [i] -> [(i : i > 0), 2i] }";
9990 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9992 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
9994 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
9995 dom
= isl_pw_aff_domain(pa
);
9996 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
9997 dom2
= isl_pw_aff_domain(pa
);
9998 equal_domain
= isl_set_is_equal(dom
, dom2
);
10001 isl_set_free(dom2
);
10002 isl_multi_pw_aff_free(mpa1
);
10003 isl_multi_pw_aff_free(mpa2
);
10008 isl_die(ctx
, isl_error_unknown
,
10009 "expressions not equal", return -1);
10011 if (equal_domain
< 0)
10014 isl_die(ctx
, isl_error_unknown
,
10015 "domains unexpectedly equal", return -1);
10020 /* Check that the dimensions in the explicit domain
10021 * of a multi piecewise affine expression are properly
10022 * taken into account.
10024 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
10027 isl_bool involves1
, involves2
, involves3
, equal
;
10028 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
10030 str
= "{ A[x,y] -> B[] : x >= y }";
10031 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10032 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
10033 mpa1
= isl_multi_pw_aff_copy(mpa
);
10035 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
10036 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
10037 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
10038 str
= "{ [a,x,y] -> B[] : x >= y }";
10039 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10040 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
10041 isl_multi_pw_aff_free(mpa2
);
10043 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
10044 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
10045 if (equal
>= 0 && equal
)
10046 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
10047 isl_multi_pw_aff_free(mpa1
);
10048 isl_multi_pw_aff_free(mpa
);
10050 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
10053 isl_die(ctx
, isl_error_unknown
,
10054 "incorrect result of dimension insertion/removal",
10055 return isl_stat_error
);
10056 if (!involves1
|| involves2
|| !involves3
)
10057 isl_die(ctx
, isl_error_unknown
,
10058 "incorrect characterization of involved dimensions",
10059 return isl_stat_error
);
10064 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
10065 * sets the explicit domain of a zero-dimensional result,
10066 * such that it can be converted to an isl_union_map.
10068 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
10071 isl_union_set
*dom
;
10073 isl_multi_union_pw_aff
*mupa
;
10074 isl_union_map
*umap
;
10076 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
10077 space
= isl_union_set_get_space(dom
);
10078 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
10079 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
10080 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
10081 isl_union_map_free(umap
);
10083 return isl_stat_error
;
10085 return isl_stat_ok
;
10088 /* String descriptions of boxes that
10089 * are used for reconstructing box maps from their lower and upper bounds.
10091 static const char *multi_pw_aff_box_tests
[] = {
10092 "{ A[x, y] -> [] : x + y >= 0 }",
10093 "[N] -> { A[x, y] -> [x] : x + y <= N }",
10094 "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
10097 /* Check that map representations of boxes can be reconstructed
10098 * from their lower and upper bounds.
10100 static isl_stat
test_multi_pw_aff_box(isl_ctx
*ctx
)
10104 for (i
= 0; i
< ARRAY_SIZE(multi_pw_aff_box_tests
); ++i
) {
10107 isl_map
*map
, *box
;
10108 isl_multi_pw_aff
*min
, *max
;
10110 str
= multi_pw_aff_box_tests
[i
];
10111 map
= isl_map_read_from_str(ctx
, str
);
10112 min
= isl_map_min_multi_pw_aff(isl_map_copy(map
));
10113 max
= isl_map_max_multi_pw_aff(isl_map_copy(map
));
10114 box
= isl_map_universe(isl_map_get_space(map
));
10115 box
= isl_map_lower_bound_multi_pw_aff(box
, min
);
10116 box
= isl_map_upper_bound_multi_pw_aff(box
, max
);
10117 equal
= isl_map_is_equal(map
, box
);
10121 return isl_stat_error
;
10123 isl_die(ctx
, isl_error_unknown
,
10124 "unexpected result", return isl_stat_error
);
10127 return isl_stat_ok
;
10130 /* Perform some tests on multi piecewise affine expressions.
10132 static int test_multi_pw_aff(isl_ctx
*ctx
)
10134 if (test_multi_pw_aff_1(ctx
) < 0)
10136 if (test_multi_pw_aff_2(ctx
) < 0)
10138 if (test_multi_pw_aff_3(ctx
) < 0)
10140 if (test_multi_pw_aff_box(ctx
) < 0)
10145 /* This is a regression test for a bug where isl_basic_map_simplify
10146 * would end up in an infinite loop. In particular, we construct
10147 * an empty basic set that is not obviously empty.
10148 * isl_basic_set_is_empty marks the basic set as empty.
10149 * After projecting out i3, the variable can be dropped completely,
10150 * but isl_basic_map_simplify refrains from doing so if the basic set
10151 * is empty and would end up in an infinite loop if it didn't test
10152 * explicitly for empty basic maps in the outer loop.
10154 static int test_simplify_1(isl_ctx
*ctx
)
10157 isl_basic_set
*bset
;
10160 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10161 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10162 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10164 bset
= isl_basic_set_read_from_str(ctx
, str
);
10165 empty
= isl_basic_set_is_empty(bset
);
10166 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
10167 isl_basic_set_free(bset
);
10171 isl_die(ctx
, isl_error_unknown
,
10172 "basic set should be empty", return -1);
10177 /* Check that the equality in the set description below
10178 * is simplified away.
10180 static int test_simplify_2(isl_ctx
*ctx
)
10183 isl_basic_set
*bset
;
10186 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10187 bset
= isl_basic_set_read_from_str(ctx
, str
);
10188 universe
= isl_basic_set_plain_is_universe(bset
);
10189 isl_basic_set_free(bset
);
10194 isl_die(ctx
, isl_error_unknown
,
10195 "equality not simplified away", return -1);
10199 /* Some simplification tests.
10201 static int test_simplify(isl_ctx
*ctx
)
10203 if (test_simplify_1(ctx
) < 0)
10205 if (test_simplify_2(ctx
) < 0)
10210 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10211 * with gbr context would fail to disable the use of the shifted tableau
10212 * when transferring equalities for the input to the context, resulting
10213 * in invalid sample values.
10215 static int test_partial_lexmin(isl_ctx
*ctx
)
10218 isl_basic_set
*bset
;
10219 isl_basic_map
*bmap
;
10222 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10223 bmap
= isl_basic_map_read_from_str(ctx
, str
);
10224 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10225 bset
= isl_basic_set_read_from_str(ctx
, str
);
10226 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
10235 /* Check that the variable compression performed on the existentially
10236 * quantified variables inside isl_basic_set_compute_divs is not confused
10237 * by the implicit equalities among the parameters.
10239 static int test_compute_divs(isl_ctx
*ctx
)
10242 isl_basic_set
*bset
;
10245 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10246 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10247 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10248 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10249 bset
= isl_basic_set_read_from_str(ctx
, str
);
10250 set
= isl_basic_set_compute_divs(bset
);
10258 /* Check that isl_schedule_get_map is not confused by a schedule tree
10259 * with divergent filter node parameters, as can result from a call
10260 * to isl_schedule_intersect_domain.
10262 static int test_schedule_tree(isl_ctx
*ctx
)
10265 isl_union_set
*uset
;
10266 isl_schedule
*sched1
, *sched2
;
10267 isl_union_map
*umap
;
10269 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
10270 sched1
= isl_schedule_from_domain(uset
);
10271 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
10272 sched2
= isl_schedule_from_domain(uset
);
10274 sched1
= isl_schedule_sequence(sched1
, sched2
);
10275 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
10276 uset
= isl_union_set_read_from_str(ctx
, str
);
10277 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
10278 umap
= isl_schedule_get_map(sched1
);
10279 isl_schedule_free(sched1
);
10280 isl_union_map_free(umap
);
10287 /* Check that a zero-dimensional prefix schedule keeps track
10288 * of the domain and outer filters.
10290 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
10294 isl_union_set
*uset
;
10295 isl_union_set_list
*filters
;
10296 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10297 isl_schedule_node
*node
;
10299 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10300 uset
= isl_union_set_read_from_str(ctx
, str
);
10301 node
= isl_schedule_node_from_domain(uset
);
10302 node
= isl_schedule_node_child(node
, 0);
10304 str
= "{ S1[i,j] : i > j }";
10305 uset
= isl_union_set_read_from_str(ctx
, str
);
10306 filters
= isl_union_set_list_from_union_set(uset
);
10307 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
10308 uset
= isl_union_set_read_from_str(ctx
, str
);
10309 filters
= isl_union_set_list_add(filters
, uset
);
10310 node
= isl_schedule_node_insert_sequence(node
, filters
);
10312 node
= isl_schedule_node_grandchild(node
, 0, 0);
10313 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
10314 str
= "([] : { S1[i,j] : i > j })";
10315 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10316 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10317 isl_multi_union_pw_aff_free(mupa2
);
10318 isl_multi_union_pw_aff_free(mupa
);
10319 isl_schedule_node_free(node
);
10324 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
10330 /* Check that the reaching domain elements and the prefix schedule
10331 * at a leaf node are the same before and after grouping.
10333 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
10338 isl_union_set
*uset
;
10339 isl_multi_union_pw_aff
*mupa
;
10340 isl_union_pw_multi_aff
*upma1
, *upma2
;
10341 isl_union_set
*domain1
, *domain2
;
10342 isl_union_map
*umap1
, *umap2
;
10343 isl_schedule_node
*node
;
10345 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10346 uset
= isl_union_set_read_from_str(ctx
, str
);
10347 node
= isl_schedule_node_from_domain(uset
);
10348 node
= isl_schedule_node_child(node
, 0);
10349 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10350 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10351 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10352 node
= isl_schedule_node_child(node
, 0);
10353 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10354 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10355 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10356 node
= isl_schedule_node_child(node
, 0);
10357 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10358 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10359 domain1
= isl_schedule_node_get_domain(node
);
10360 id
= isl_id_alloc(ctx
, "group", NULL
);
10361 node
= isl_schedule_node_parent(node
);
10362 node
= isl_schedule_node_group(node
, id
);
10363 node
= isl_schedule_node_child(node
, 0);
10364 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10365 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10366 domain2
= isl_schedule_node_get_domain(node
);
10367 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
10368 if (equal
>= 0 && equal
)
10369 equal
= isl_union_set_is_equal(domain1
, domain2
);
10370 if (equal
>= 0 && equal
)
10371 equal
= isl_union_map_is_equal(umap1
, umap2
);
10372 isl_union_map_free(umap1
);
10373 isl_union_map_free(umap2
);
10374 isl_union_set_free(domain1
);
10375 isl_union_set_free(domain2
);
10376 isl_union_pw_multi_aff_free(upma1
);
10377 isl_union_pw_multi_aff_free(upma2
);
10378 isl_schedule_node_free(node
);
10383 isl_die(ctx
, isl_error_unknown
,
10384 "expressions not equal", return -1);
10389 /* Check that we can have nested groupings and that the union map
10390 * schedule representation is the same before and after the grouping.
10391 * Note that after the grouping, the union map representation contains
10392 * the domain constraints from the ranges of the expansion nodes,
10393 * while they are missing from the union map representation of
10394 * the tree without expansion nodes.
10396 * Also check that the global expansion is as expected.
10398 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
10400 int equal
, equal_expansion
;
10403 isl_union_set
*uset
;
10404 isl_union_map
*umap1
, *umap2
;
10405 isl_union_map
*expansion1
, *expansion2
;
10406 isl_union_set_list
*filters
;
10407 isl_multi_union_pw_aff
*mupa
;
10408 isl_schedule
*schedule
;
10409 isl_schedule_node
*node
;
10411 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10412 "S3[i,j] : 0 <= i,j < 10 }";
10413 uset
= isl_union_set_read_from_str(ctx
, str
);
10414 node
= isl_schedule_node_from_domain(uset
);
10415 node
= isl_schedule_node_child(node
, 0);
10416 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10417 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10418 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10419 node
= isl_schedule_node_child(node
, 0);
10420 str
= "{ S1[i,j] }";
10421 uset
= isl_union_set_read_from_str(ctx
, str
);
10422 filters
= isl_union_set_list_from_union_set(uset
);
10423 str
= "{ S2[i,j]; S3[i,j] }";
10424 uset
= isl_union_set_read_from_str(ctx
, str
);
10425 filters
= isl_union_set_list_add(filters
, uset
);
10426 node
= isl_schedule_node_insert_sequence(node
, filters
);
10427 node
= isl_schedule_node_grandchild(node
, 1, 0);
10428 str
= "{ S2[i,j] }";
10429 uset
= isl_union_set_read_from_str(ctx
, str
);
10430 filters
= isl_union_set_list_from_union_set(uset
);
10431 str
= "{ S3[i,j] }";
10432 uset
= isl_union_set_read_from_str(ctx
, str
);
10433 filters
= isl_union_set_list_add(filters
, uset
);
10434 node
= isl_schedule_node_insert_sequence(node
, filters
);
10436 schedule
= isl_schedule_node_get_schedule(node
);
10437 umap1
= isl_schedule_get_map(schedule
);
10438 uset
= isl_schedule_get_domain(schedule
);
10439 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
10440 isl_schedule_free(schedule
);
10442 node
= isl_schedule_node_grandparent(node
);
10443 id
= isl_id_alloc(ctx
, "group1", NULL
);
10444 node
= isl_schedule_node_group(node
, id
);
10445 node
= isl_schedule_node_grandchild(node
, 1, 0);
10446 id
= isl_id_alloc(ctx
, "group2", NULL
);
10447 node
= isl_schedule_node_group(node
, id
);
10449 schedule
= isl_schedule_node_get_schedule(node
);
10450 umap2
= isl_schedule_get_map(schedule
);
10451 isl_schedule_free(schedule
);
10453 node
= isl_schedule_node_root(node
);
10454 node
= isl_schedule_node_child(node
, 0);
10455 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
10456 isl_schedule_node_free(node
);
10458 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10459 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10460 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10462 expansion2
= isl_union_map_read_from_str(ctx
, str
);
10464 equal
= isl_union_map_is_equal(umap1
, umap2
);
10465 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
10467 isl_union_map_free(umap1
);
10468 isl_union_map_free(umap2
);
10469 isl_union_map_free(expansion1
);
10470 isl_union_map_free(expansion2
);
10472 if (equal
< 0 || equal_expansion
< 0)
10475 isl_die(ctx
, isl_error_unknown
,
10476 "expressions not equal", return -1);
10477 if (!equal_expansion
)
10478 isl_die(ctx
, isl_error_unknown
,
10479 "unexpected expansion", return -1);
10484 /* Some tests for the isl_schedule_node_group function.
10486 static int test_schedule_tree_group(isl_ctx
*ctx
)
10488 if (test_schedule_tree_group_1(ctx
) < 0)
10490 if (test_schedule_tree_group_2(ctx
) < 0)
10499 { "{ rat: [i] : 0 <= i <= 10 }",
10500 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10501 { "{ rat: [i] : FALSE }",
10502 "{ rat: coefficients[[cst] -> [a]] }" },
10503 { "{ rat: [i] : }",
10504 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10505 { "{ [0:,1,2:3] }",
10506 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10507 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10508 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10509 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10510 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10511 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10512 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10513 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10514 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10515 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10516 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10523 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10524 "{ rat: [i] : 0 <= i <= 10 }" },
10525 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10527 { "{ rat: coefficients[[cst] -> [a]] }",
10528 "{ rat: [i] : FALSE }" },
10531 /* Test the basic functionality of isl_basic_set_coefficients and
10532 * isl_basic_set_solutions.
10534 static int test_dual(isl_ctx
*ctx
)
10538 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
10540 isl_basic_set
*bset1
, *bset2
;
10542 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
10543 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
10544 bset1
= isl_basic_set_coefficients(bset1
);
10545 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10546 isl_basic_set_free(bset1
);
10547 isl_basic_set_free(bset2
);
10551 isl_die(ctx
, isl_error_unknown
,
10552 "incorrect dual", return -1);
10555 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
10557 isl_basic_set
*bset1
, *bset2
;
10559 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
10560 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
10561 bset1
= isl_basic_set_solutions(bset1
);
10562 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10563 isl_basic_set_free(bset1
);
10564 isl_basic_set_free(bset2
);
10568 isl_die(ctx
, isl_error_unknown
,
10569 "incorrect dual", return -1);
10578 const char *domain
;
10579 const char *schedule
;
10584 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10585 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10587 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10588 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10590 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10591 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10593 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10594 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10596 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10597 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10599 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10600 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10602 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10603 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10605 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10606 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10610 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10611 * tile the band and then check if the tile and point bands have the
10612 * expected partial schedule.
10614 static int test_tile(isl_ctx
*ctx
)
10620 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
10621 shift
= isl_options_get_tile_shift_point_loops(ctx
);
10623 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
10627 isl_union_set
*domain
;
10628 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10629 isl_schedule_node
*node
;
10630 isl_multi_val
*sizes
;
10632 opt
= tile_tests
[i
].scale_tile
;
10633 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
10634 opt
= tile_tests
[i
].shift_point
;
10635 isl_options_set_tile_shift_point_loops(ctx
, opt
);
10637 str
= tile_tests
[i
].domain
;
10638 domain
= isl_union_set_read_from_str(ctx
, str
);
10639 node
= isl_schedule_node_from_domain(domain
);
10640 node
= isl_schedule_node_child(node
, 0);
10641 str
= tile_tests
[i
].schedule
;
10642 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10643 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10644 str
= tile_tests
[i
].sizes
;
10645 sizes
= isl_multi_val_read_from_str(ctx
, str
);
10646 node
= isl_schedule_node_band_tile(node
, sizes
);
10648 str
= tile_tests
[i
].tile
;
10649 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10650 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10651 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10652 isl_multi_union_pw_aff_free(mupa
);
10653 isl_multi_union_pw_aff_free(mupa2
);
10655 node
= isl_schedule_node_child(node
, 0);
10657 str
= tile_tests
[i
].point
;
10658 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10659 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10660 if (equal
>= 0 && equal
)
10661 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
10663 isl_multi_union_pw_aff_free(mupa
);
10664 isl_multi_union_pw_aff_free(mupa2
);
10666 isl_schedule_node_free(node
);
10671 isl_die(ctx
, isl_error_unknown
,
10672 "unexpected result", return -1);
10675 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
10676 isl_options_set_tile_shift_point_loops(ctx
, shift
);
10681 /* Check that the domain hash of a space is equal to the hash
10682 * of the domain of the space, both ignoring parameters.
10684 static int test_domain_hash(isl_ctx
*ctx
)
10688 uint32_t hash1
, hash2
;
10690 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
10691 space
= isl_map_get_space(map
);
10693 hash1
= isl_space_get_tuple_domain_hash(space
);
10694 space
= isl_space_domain(space
);
10695 hash2
= isl_space_get_tuple_hash(space
);
10696 isl_space_free(space
);
10700 if (hash1
!= hash2
)
10701 isl_die(ctx
, isl_error_unknown
,
10702 "domain hash not equal to hash of domain", return -1);
10707 /* Check that a universe basic set that is not obviously equal to the universe
10708 * is still recognized as being equal to the universe.
10710 static int test_universe(isl_ctx
*ctx
)
10713 isl_basic_set
*bset
;
10716 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10717 bset
= isl_basic_set_read_from_str(ctx
, s
);
10718 is_univ
= isl_basic_set_is_universe(bset
);
10719 isl_basic_set_free(bset
);
10724 isl_die(ctx
, isl_error_unknown
,
10725 "not recognized as universe set", return -1);
10730 /* Sets for which chambers are computed and checked.
10732 const char *chambers_tests
[] = {
10733 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10734 "z >= 0 and z <= C - y and z <= B - x - y }",
10737 /* Add the domain of "cell" to "cells".
10739 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
10741 isl_basic_set_list
**cells
= user
;
10742 isl_basic_set
*dom
;
10744 dom
= isl_cell_get_domain(cell
);
10745 isl_cell_free(cell
);
10746 *cells
= isl_basic_set_list_add(*cells
, dom
);
10748 return *cells
? isl_stat_ok
: isl_stat_error
;
10751 /* Check that the elements of "list" are pairwise disjoint.
10753 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
10758 n
= isl_basic_set_list_n_basic_set(list
);
10760 return isl_stat_error
;
10762 for (i
= 0; i
< n
; ++i
) {
10763 isl_basic_set
*bset_i
;
10765 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
10766 for (j
= i
+ 1; j
< n
; ++j
) {
10767 isl_basic_set
*bset_j
;
10770 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
10771 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
10772 isl_basic_set_free(bset_j
);
10774 isl_die(isl_basic_set_list_get_ctx(list
),
10775 isl_error_unknown
, "not disjoint",
10777 if (disjoint
< 0 || !disjoint
)
10780 isl_basic_set_free(bset_i
);
10782 return isl_stat_error
;
10785 return isl_stat_ok
;
10788 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10789 * are pairwise disjoint.
10791 static int test_chambers(isl_ctx
*ctx
)
10795 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
10796 isl_basic_set
*bset
;
10797 isl_vertices
*vertices
;
10798 isl_basic_set_list
*cells
;
10801 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
10802 vertices
= isl_basic_set_compute_vertices(bset
);
10803 cells
= isl_basic_set_list_alloc(ctx
, 0);
10804 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
10806 cells
= isl_basic_set_list_free(cells
);
10807 ok
= check_pairwise_disjoint(cells
);
10808 isl_basic_set_list_free(cells
);
10809 isl_vertices_free(vertices
);
10810 isl_basic_set_free(bset
);
10821 int (*fn
)(isl_ctx
*ctx
);
10823 { "universe", &test_universe
},
10824 { "domain hash", &test_domain_hash
},
10825 { "dual", &test_dual
},
10826 { "dependence analysis", &test_flow
},
10827 { "val", &test_val
},
10828 { "compute divs", &test_compute_divs
},
10829 { "partial lexmin", &test_partial_lexmin
},
10830 { "simplify", &test_simplify
},
10831 { "curry", &test_curry
},
10832 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10833 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10834 { "conversion", &test_conversion
},
10835 { "list", &test_list
},
10836 { "align parameters", &test_align_parameters
},
10837 { "drop unused parameters", &test_drop_unused_parameters
},
10838 { "pullback", &test_pullback
},
10839 { "AST", &test_ast
},
10840 { "AST build", &test_ast_build
},
10841 { "AST generation", &test_ast_gen
},
10842 { "eliminate", &test_eliminate
},
10843 { "deltas_map", &test_deltas_map
},
10844 { "residue class", &test_residue_class
},
10845 { "div", &test_div
},
10846 { "slice", &test_slice
},
10847 { "fixed power", &test_fixed_power
},
10848 { "sample", &test_sample
},
10849 { "empty projection", &test_empty_projection
},
10850 { "output", &test_output
},
10851 { "vertices", &test_vertices
},
10852 { "chambers", &test_chambers
},
10853 { "fixed", &test_fixed
},
10854 { "equal", &test_equal
},
10855 { "disjoint", &test_disjoint
},
10856 { "product", &test_product
},
10857 { "dim_max", &test_dim_max
},
10858 { "affine", &test_aff
},
10859 { "injective", &test_injective
},
10860 { "schedule (whole component)", &test_schedule_whole
},
10861 { "schedule (incremental)", &test_schedule_incremental
},
10862 { "schedule tree", &test_schedule_tree
},
10863 { "schedule tree prefix", &test_schedule_tree_prefix
},
10864 { "schedule tree grouping", &test_schedule_tree_group
},
10865 { "tile", &test_tile
},
10866 { "union map", &test_union_map
},
10867 { "union_pw", &test_union_pw
},
10868 { "locus", &test_locus
},
10869 { "eval", &test_eval
},
10870 { "parse", &test_parse
},
10871 { "single-valued", &test_sv
},
10872 { "recession cone", &test_recession_cone
},
10873 { "affine hull", &test_affine_hull
},
10874 { "simple_hull", &test_simple_hull
},
10875 { "box hull", &test_box_hull
},
10876 { "coalesce", &test_coalesce
},
10877 { "factorize", &test_factorize
},
10878 { "subset", &test_subset
},
10879 { "subtract", &test_subtract
},
10880 { "intersect", &test_intersect
},
10881 { "lexmin", &test_lexmin
},
10882 { "min", &test_min
},
10883 { "set lower bounds", &test_min_mpa
},
10884 { "gist", &test_gist
},
10885 { "piecewise quasi-polynomials", &test_pwqp
},
10886 { "lift", &test_lift
},
10887 { "bind parameters", &test_bind
},
10888 { "unbind parameters", &test_unbind
},
10889 { "bound", &test_bound
},
10890 { "get lists", &test_get_list
},
10891 { "union", &test_union
},
10892 { "split periods", &test_split_periods
},
10893 { "lexicographic order", &test_lex
},
10894 { "bijectivity", &test_bijective
},
10895 { "dataflow analysis", &test_dep
},
10896 { "reading", &test_read
},
10897 { "bounded", &test_bounded
},
10898 { "construction", &test_construction
},
10899 { "dimension manipulation", &test_dim
},
10900 { "map application", &test_application
},
10901 { "convex hull", &test_convex_hull
},
10902 { "transitive closure", &test_closure
},
10903 { "isl_bool", &test_isl_bool
},
10906 int main(int argc
, char **argv
)
10909 struct isl_ctx
*ctx
;
10910 struct isl_options
*options
;
10912 options
= isl_options_new_with_defaults();
10914 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10916 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
10917 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
10918 printf("%s\n", tests
[i
].name
);
10919 if (tests
[i
].fn(ctx
) < 0)